1 ;;; calc-lang.el --- calc language functions
3 ;; Copyright (C) 1990-1993, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This file is autoloaded from calc-ext.el.
33 ;; Declare functions which are defined elsewhere.
34 (declare-function math-compose-vector
"calccomp" (a sep prec
))
35 (declare-function math-compose-var
"calccomp" (a))
36 (declare-function math-tex-expr-is-flat
"calccomp" (a))
37 (declare-function math-read-factor
"calc-aent" ())
38 (declare-function math-read-expr-level
"calc-aent" (exp-prec &optional exp-term
))
40 ;; Declare variables which are defined elsewhere.
41 (defvar calc-lang-slash-idiv
)
42 (defvar calc-lang-allow-underscores
)
43 (defvar calc-lang-allow-percentsigns
)
44 (defvar math-comp-left-bracket
)
45 (defvar math-comp-right-bracket
)
46 (defvar math-comp-comma
)
47 (defvar math-comp-vector-prec
)
49 ;;; Alternate entry/display languages.
51 (defun calc-set-language (lang &optional option no-refresh
)
52 (setq math-expr-opers
(or (get lang
'math-oper-table
) (math-standard-ops))
53 math-expr-function-mapping
(get lang
'math-function-table
)
54 math-expr-variable-mapping
(get lang
'math-variable-table
)
55 calc-language-input-filter
(get lang
'math-input-filter
)
56 calc-language-output-filter
(get lang
'math-output-filter
)
57 calc-vector-brackets
(or (get lang
'math-vector-brackets
) "[]")
58 calc-complex-format
(get lang
'math-complex-format
)
59 calc-radix-formatter
(get lang
'math-radix-formatter
)
60 calc-function-open
(or (get lang
'math-function-open
) "(")
61 calc-function-close
(or (get lang
'math-function-close
) ")"))
63 (setq calc-language lang
64 calc-language-option option
)
65 (calc-change-mode '(calc-language calc-language-option
)
66 (list lang option
) t
)))
68 (defun calc-normal-language ()
71 (calc-set-language nil
)
72 (message "Normal language mode")))
74 (defun calc-flat-language ()
77 (calc-set-language 'flat
)
78 (message "Flat language mode (all stack entries shown on one line)")))
80 (defun calc-big-language ()
83 (calc-set-language 'big
)
84 (message "\"Big\" language mode")))
86 (defun calc-unformatted-language ()
89 (calc-set-language 'unform
)
90 (message "Unformatted language mode")))
93 (defun calc-c-language ()
96 (calc-set-language 'c
)
97 (message "`C' language mode")))
99 (put 'c
'math-oper-table
100 '( ( "u!" calcFunc-lnot -
1 1000 )
101 ( "~" calcFunc-not -
1 1000 )
102 ( "u+" ident -
1 197 )
109 ( "<<" calcFunc-lsh
170 171 )
110 ( ">>" calcFunc-rsh
170 171 )
111 ( "<" calcFunc-lt
160 161 )
112 ( ">" calcFunc-gt
160 161 )
113 ( "<=" calcFunc-leq
160 161 )
114 ( ">=" calcFunc-geq
160 161 )
115 ( "==" calcFunc-eq
150 151 )
116 ( "!=" calcFunc-neq
150 151 )
117 ( "&" calcFunc-and
140 141 )
118 ( "^" calcFunc-xor
131 130 )
119 ( "|" calcFunc-or
120 121 )
120 ( "&&" calcFunc-land
110 111 )
121 ( "||" calcFunc-lor
100 101 )
122 ( "?" (math-read-if) 91 90 )
123 ( "!!!" calcFunc-pnot -
1 88 )
124 ( "&&&" calcFunc-pand
85 86 )
125 ( "|||" calcFunc-por
75 76 )
126 ( "=" calcFunc-assign
51 50 )
127 ( ":=" calcFunc-assign
51 50 )
128 ( "::" calcFunc-condition
45 46 ))) ; should support full assignments
130 (put 'c
'math-function-table
131 '( ( acos . calcFunc-arccos
)
132 ( acosh . calcFunc-arccosh
)
133 ( asin . calcFunc-arcsin
)
134 ( asinh . calcFunc-arcsinh
)
135 ( atan . calcFunc-arctan
)
136 ( atan2 . calcFunc-arctan2
)
137 ( atanh . calcFunc-arctanh
)))
139 (put 'c
'math-variable-table
143 (put 'c
'math-vector-brackets
"{}")
145 (put 'c
'math-radix-formatter
146 (function (lambda (r s
)
147 (if (= r
16) (format "0x%s" s
)
148 (if (= r
8) (format "0%s" s
)
149 (format "%d#%s" r s
))))))
151 (put 'c
'math-compose-subscr
154 (let ((args (cdr (cdr a
))))
156 (math-compose-expr (nth 1 a
) 1000)
158 (math-compose-vector args
", " 0)
161 (add-to-list 'calc-lang-slash-idiv
'c
)
162 (add-to-list 'calc-lang-allow-underscores
'c
)
163 (add-to-list 'calc-lang-c-type-hex
'c
)
164 (add-to-list 'calc-lang-brackets-are-subscripts
'c
)
166 (defun calc-pascal-language (n)
169 (and n
(setq n
(prefix-numeric-value n
)))
170 (calc-set-language 'pascal n
)
171 (message (if (and n
(/= n
0))
173 "Pascal language mode (all uppercase)"
174 "Pascal language mode (all lowercase)")
175 "Pascal language mode"))))
177 (put 'pascal
'math-oper-table
178 '( ( "not" calcFunc-lnot -
1 1000 )
181 ( "and" calcFunc-and
190 191 )
182 ( "div" calcFunc-idiv
190 191 )
184 ( "u+" ident -
1 185 )
188 ( "or" calcFunc-or
180 181 )
189 ( "xor" calcFunc-xor
180 181 )
190 ( "shl" calcFunc-lsh
180 181 )
191 ( "shr" calcFunc-rsh
180 181 )
192 ( "in" calcFunc-in
160 161 )
193 ( "<" calcFunc-lt
160 161 )
194 ( ">" calcFunc-gt
160 161 )
195 ( "<=" calcFunc-leq
160 161 )
196 ( ">=" calcFunc-geq
160 161 )
197 ( "=" calcFunc-eq
160 161 )
198 ( "<>" calcFunc-neq
160 161 )
199 ( "!!!" calcFunc-pnot -
1 85 )
200 ( "&&&" calcFunc-pand
80 81 )
201 ( "|||" calcFunc-por
75 76 )
202 ( ":=" calcFunc-assign
51 50 )
203 ( "::" calcFunc-condition
45 46 )))
205 (put 'pascal
'math-input-filter
'calc-input-case-filter
)
206 (put 'pascal
'math-output-filter
'calc-output-case-filter
)
208 (put 'pascal
'math-radix-formatter
209 (function (lambda (r s
)
210 (if (= r
16) (format "$%s" s
)
211 (format "%d#%s" r s
)))))
213 (put 'pascal
'math-lang-read-symbol
216 "\\(\\$[0-9a-fA-F]+\\)\\($\\|[^0-9a-zA-Zα-ωΑ-Ω]\\)"
217 math-exp-str math-exp-pos
)
219 (setq math-exp-token
'number
220 math-expr-data
(math-match-substring math-exp-str
1)
221 math-exp-pos
(match-end 1)))))
223 (put 'pascal
'math-compose-subscr
226 (let ((args (cdr (cdr a
))))
227 (while (eq (car-safe (nth 1 a
)) 'calcFunc-subscr
)
228 (setq args
(append (cdr (cdr (nth 1 a
))) args
)
231 (math-compose-expr (nth 1 a
) 1000)
233 (math-compose-vector args
", " 0)
236 (add-to-list 'calc-lang-allow-underscores
'pascal
)
237 (add-to-list 'calc-lang-brackets-are-subscripts
'pascal
)
239 (defun calc-input-case-filter (str)
240 (cond ((or (null calc-language-option
) (= calc-language-option
0))
245 (defun calc-output-case-filter (str)
246 (cond ((or (null calc-language-option
) (= calc-language-option
0))
248 ((> calc-language-option
0)
254 (defun calc-fortran-language (n)
257 (and n
(setq n
(prefix-numeric-value n
)))
258 (calc-set-language 'fortran n
)
259 (message (if (and n
(/= n
0))
261 "FORTRAN language mode (all uppercase)"
262 "FORTRAN language mode (all lowercase)")
263 "FORTRAN language mode"))))
265 (put 'fortran
'math-oper-table
266 '( ( "u/" (math-parse-fortran-vector) -
1 1 )
267 ( "/" (math-parse-fortran-vector-end) 1 -
1 )
269 ( "u+" ident -
1 191 )
275 ( ".LT." calcFunc-lt
160 161 )
276 ( ".GT." calcFunc-gt
160 161 )
277 ( ".LE." calcFunc-leq
160 161 )
278 ( ".GE." calcFunc-geq
160 161 )
279 ( ".EQ." calcFunc-eq
160 161 )
280 ( ".NE." calcFunc-neq
160 161 )
281 ( ".NOT." calcFunc-lnot -
1 121 )
282 ( ".AND." calcFunc-land
110 111 )
283 ( ".OR." calcFunc-lor
100 101 )
284 ( "!!!" calcFunc-pnot -
1 85 )
285 ( "&&&" calcFunc-pand
80 81 )
286 ( "|||" calcFunc-por
75 76 )
287 ( "=" calcFunc-assign
51 50 )
288 ( ":=" calcFunc-assign
51 50 )
289 ( "::" calcFunc-condition
45 46 )))
291 (put 'fortran
'math-vector-brackets
"//")
293 (put 'fortran
'math-function-table
294 '( ( acos . calcFunc-arccos
)
295 ( acosh . calcFunc-arccosh
)
296 ( aimag . calcFunc-im
)
297 ( aint . calcFunc-ftrunc
)
298 ( asin . calcFunc-arcsin
)
299 ( asinh . calcFunc-arcsinh
)
300 ( atan . calcFunc-arctan
)
301 ( atan2 . calcFunc-arctan2
)
302 ( atanh . calcFunc-arctanh
)
303 ( conjg . calcFunc-conj
)
304 ( log . calcFunc-ln
)
305 ( nint . calcFunc-round
)
306 ( real . calcFunc-re
)))
308 (put 'fortran
'math-input-filter
'calc-input-case-filter
)
310 (put 'fortran
'math-output-filter
'calc-output-case-filter
)
312 (put 'fortran
'math-lang-read-symbol
314 (eq (string-match "\\.[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω]?\\."
315 math-exp-str math-exp-pos
) math-exp-pos
)
316 (setq math-exp-token
'punc
317 math-expr-data
(upcase (math-match-substring math-exp-str
0))
318 math-exp-pos
(match-end 0)))))
320 (put 'fortran
'math-compose-subscr
323 (let ((args (cdr (cdr a
))))
324 (while (eq (car-safe (nth 1 a
)) 'calcFunc-subscr
)
325 (setq args
(append (cdr (cdr (nth 1 a
))) args
)
328 (math-compose-expr (nth 1 a
) 1000)
330 (math-compose-vector args
", " 0)
333 (add-to-list 'calc-lang-slash-idiv
'fortran
)
334 (add-to-list 'calc-lang-allow-underscores
'fortran
)
335 (add-to-list 'calc-lang-parens-are-subscripts
'fortran
)
337 ;; The next few variables are local to math-read-exprs in calc-aent.el
338 ;; and math-read-expr in calc-ext.el, but are set in functions they call.
340 (defvar math-exp-token
)
341 (defvar math-expr-data
)
342 (defvar math-exp-old-pos
)
344 (defvar math-parsing-fortran-vector nil
)
345 (defun math-parse-fortran-vector (op)
346 (let ((math-parsing-fortran-vector '(end .
"\000")))
348 (math-read-brackets t
"]")
349 (setq math-exp-token
(car math-parsing-fortran-vector
)
350 math-expr-data
(cdr math-parsing-fortran-vector
)))))
352 (defun math-parse-fortran-vector-end (x op
)
353 (if math-parsing-fortran-vector
355 (setq math-parsing-fortran-vector
(cons math-exp-token math-expr-data
)
357 math-expr-data
"\000")
359 (throw 'syntax
"Unmatched closing `/'")))
361 (defun math-parse-fortran-subscr (sym args
)
362 (setq sym
(math-build-var-name sym
))
364 (setq sym
(list 'calcFunc-subscr sym
(car args
))
369 (defun calc-tex-language (n)
372 (and n
(setq n
(prefix-numeric-value n
)))
373 (calc-set-language 'tex n
)
375 (message "TeX language mode"))
377 (message "TeX language mode with multiline matrices"))
379 (message "TeX language mode with \\hbox{func}(\\hbox{var})"))
382 "TeX language mode with \\hbox{func}(\\hbox{var}) and multiline matrices"))
384 (message "TeX language mode with \\func(\\hbox{var})"))
387 "TeX language mode with \\func(\\hbox{var}) and multiline matrices")))))
389 (defun calc-latex-language (n)
392 (and n
(setq n
(prefix-numeric-value n
)))
393 (calc-set-language 'latex n
)
395 (message "LaTeX language mode"))
397 (message "LaTeX language mode with multiline matrices"))
399 (message "LaTeX language mode with \\text{func}(\\text{var})"))
402 "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices"))
404 (message "LaTeX language mode with \\func(\\text{var})"))
407 "LaTeX language mode with \\func(\\text{var}) and multiline matrices")))))
409 (put 'tex
'math-lang-name
"TeX")
410 (put 'latex
'math-lang-name
"LaTeX")
412 (put 'tex
'math-oper-table
413 '( ( "\\hat" calcFunc-hat -
1 950 )
414 ( "\\check" calcFunc-check -
1 950 )
415 ( "\\tilde" calcFunc-tilde -
1 950 )
416 ( "\\acute" calcFunc-acute -
1 950 )
417 ( "\\grave" calcFunc-grave -
1 950 )
418 ( "\\dot" calcFunc-dot -
1 950 )
419 ( "\\ddot" calcFunc-dotdot -
1 950 )
420 ( "\\breve" calcFunc-breve -
1 950 )
421 ( "\\bar" calcFunc-bar -
1 950 )
422 ( "\\vec" calcFunc-Vec -
1 950 )
423 ( "\\underline" calcFunc-under -
1 950 )
424 ( "u|" calcFunc-abs -
1 0 )
426 ( "\\lfloor" calcFunc-floor -
1 0 )
427 ( "\\rfloor" closing
0 -
1 )
428 ( "\\lceil" calcFunc-ceil -
1 0 )
429 ( "\\rceil" closing
0 -
1 )
430 ( "\\pm" sdev
300 300 )
431 ( "!" calcFunc-fact
210 -
1 )
433 ( "_" calcFunc-subscr
201 200 )
434 ( "u+" ident -
1 197 )
436 ( "\\times" * 191 190 )
441 ( "\\over" / 170 171 )
443 ( "\\choose" calcFunc-choose
170 171 )
444 ( "\\mod" %
170 171 )
445 ( "<" calcFunc-lt
160 161 )
446 ( ">" calcFunc-gt
160 161 )
447 ( "\\leq" calcFunc-leq
160 161 )
448 ( "\\geq" calcFunc-geq
160 161 )
449 ( "=" calcFunc-eq
160 161 )
450 ( "\\neq" calcFunc-neq
160 161 )
451 ( "\\ne" calcFunc-neq
160 161 )
452 ( "\\lnot" calcFunc-lnot -
1 121 )
453 ( "\\land" calcFunc-land
110 111 )
454 ( "\\lor" calcFunc-lor
100 101 )
455 ( "?" (math-read-if) 91 90 )
456 ( "!!!" calcFunc-pnot -
1 85 )
457 ( "&&&" calcFunc-pand
80 81 )
458 ( "|||" calcFunc-por
75 76 )
459 ( "\\gets" calcFunc-assign
51 50 )
460 ( ":=" calcFunc-assign
51 50 )
461 ( "::" calcFunc-condition
45 46 )
462 ( "\\to" calcFunc-evalto
40 41 )
463 ( "\\to" calcFunc-evalto
40 -
1 )
464 ( "=>" calcFunc-evalto
40 41 )
465 ( "=>" calcFunc-evalto
40 -
1 )))
467 (put 'tex
'math-function-table
468 '( ( \\arccos . calcFunc-arccos
)
469 ( \\arcsin . calcFunc-arcsin
)
470 ( \\arctan . calcFunc-arctan
)
471 ( \\arg . calcFunc-arg
)
472 ( \\cos . calcFunc-cos
)
473 ( \\cosh . calcFunc-cosh
)
474 ( \\cot . calcFunc-cot
)
475 ( \\coth . calcFunc-coth
)
476 ( \\csc . calcFunc-csc
)
477 ( \\det . calcFunc-det
)
478 ( \\exp . calcFunc-exp
)
479 ( \\gcd . calcFunc-gcd
)
480 ( \\ln . calcFunc-ln
)
481 ( \\log . calcFunc-log10
)
482 ( \\max . calcFunc-max
)
483 ( \\min . calcFunc-min
)
484 ( \\sec . calcFunc-sec
)
485 ( \\sin . calcFunc-sin
)
486 ( \\sinh . calcFunc-sinh
)
487 ( \\sqrt . calcFunc-sqrt
)
488 ( \\tan . calcFunc-tan
)
489 ( \\tanh . calcFunc-tanh
)
490 ( \\phi . calcFunc-totient
)
491 ( \\mu . calcFunc-moebius
)))
493 (put 'tex
'math-special-function-table
494 '((calcFunc-sum .
(math-compose-tex-sum "\\sum"))
495 (calcFunc-prod .
(math-compose-tex-sum "\\prod"))
496 (calcFunc-sqrt . math-compose-tex-sqrt
)
497 (intv . math-compose-tex-intv
)))
499 (put 'tex
'math-variable-table
502 ( \\alpha . var-alpha
)
503 ( \\beta . var-beta
)
504 ( \\gamma . var-gamma
)
505 ( \\Gamma . var-Gamma
)
506 ( \\delta . var-delta
)
507 ( \\Delta . var-Delta
)
508 ( \\epsilon . var-epsilon
)
509 ( \\varepsilon . var-varepsilon
)
510 ( \\zeta . var-zeta
)
512 ( \\theta . var-theta
)
513 ( \\vartheta . var-vartheta
)
514 ( \\Theta . var-Theta
)
515 ( \\iota . var-iota
)
516 ( \\kappa . var-kappa
)
517 ( \\lambda . var-lambda
)
518 ( \\Lambda . var-Lambda
)
524 ( \\varpi . var-varpi
)
527 ( \\varrho . var-varrho
)
528 ( \\sigma . var-sigma
)
529 ( \\sigma . var-varsigma
)
530 ( \\Sigma . var-Sigma
)
532 ( \\upsilon . var-upsilon
)
533 ( \\Upsilon . var-Upsilon
)
535 ( \\varphi . var-varphi
)
540 ( \\omega . var-omega
)
541 ( \\Omega . var-Omega
)
554 ( \\infty . var-inf
)
555 ( \\infty . var-uinf
)
556 ( \\sum .
(math-parse-tex-sum calcFunc-sum
) )
557 ( \\prod .
(math-parse-tex-sum calcFunc-prod
) )))
559 (put 'tex
'math-punc-table
564 (put 'tex
'math-complex-format
'i
)
566 (put 'tex
'math-input-filter
'math-tex-input-filter
)
568 (put 'tex
'math-matrix-formatter
571 (if (and (integerp calc-language-option
)
572 (or (= calc-language-option
0)
573 (> calc-language-option
1)
574 (< calc-language-option -
1)))
575 (append '(vleft 0 "\\matrix{")
576 (math-compose-tex-matrix (cdr a
))
578 (append '(horiz "\\matrix{ ")
579 (math-compose-tex-matrix (cdr a
))
582 (put 'tex
'math-var-formatter
'math-compose-tex-var
)
584 (put 'tex
'math-func-formatter
'math-compose-tex-func
)
586 (put 'tex
'math-dots
"\\ldots")
588 (put 'tex
'math-big-parens
'("\\left( " .
" \\right)"))
590 (put 'tex
'math-evalto
'("\\evalto " .
" \\to "))
592 (defconst math-tex-ignore-words
593 '( ("\\hbox") ("\\mbox") ("\\text") ("\\left") ("\\right")
594 ("\\,") ("\\>") ("\\:") ("\\;") ("\\!") ("\\ ")
595 ("\\quad") ("\\qquad") ("\\hfil") ("\\hfill")
596 ("\\displaystyle") ("\\textstyle") ("\\dsize") ("\\tsize")
597 ("\\scriptstyle") ("\\scriptscriptstyle") ("\\ssize") ("\\sssize")
598 ("\\rm") ("\\bf") ("\\it") ("\\sl")
599 ("\\roman") ("\\bold") ("\\italic") ("\\slanted")
600 ("\\cal") ("\\mit") ("\\Cal") ("\\Bbb") ("\\frak") ("\\goth")
602 ("\\matrix" mat
) ("\\bmatrix" mat
) ("\\pmatrix" mat
)
604 ("\\cr" punc
";") ("\\\\" punc
";") ("\\*" punc
"*")
605 ("\\{" punc
"[") ("\\}" punc
"]")))
607 (defconst math-latex-ignore-words
608 (append math-tex-ignore-words
609 '(("\\begin" begenv
))))
611 (put 'tex
'math-lang-read-symbol
613 (< math-exp-pos
(1- (length math-exp-str
)))
615 (or (string-match "\\\\hbox *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
616 math-exp-str math-exp-pos
)
617 (string-match "\\(\\\\\\([a-zA-Zα-ωΑ-Ω]+\\|[^a-zA-Zα-ωΑ-Ω]\\)\\)"
618 math-exp-str math-exp-pos
))
619 (setq math-exp-token
'symbol
620 math-exp-pos
(match-end 0)
621 math-expr-data
(math-restore-dashes
622 (math-match-substring math-exp-str
1)))
623 (let ((code (assoc math-expr-data math-latex-ignore-words
)))
627 ((eq (nth 1 code
) 'punc
)
628 (setq math-exp-token
'punc
629 math-expr-data
(nth 2 code
)))
630 ((and (eq (nth 1 code
) 'mat
)
631 (string-match " *{" math-exp-str math-exp-pos
))
632 (setq math-exp-pos
(match-end 0)
635 (let ((right (string-match "}" math-exp-str math-exp-pos
)))
637 (setq math-exp-str
(copy-sequence math-exp-str
))
638 (aset math-exp-str right ?\
]))))))))))
640 (defun math-compose-tex-matrix (a &optional ltx
)
642 (cons (append (math-compose-vector (cdr (car a
)) " & " 0)
643 (if ltx
'(" \\\\ ") '(" \\cr ")))
644 (math-compose-tex-matrix (cdr a
) ltx
))
645 (list (math-compose-vector (cdr (car a
)) " & " 0))))
647 (defun math-compose-tex-sum (a fn
)
650 (list 'horiz
(nth 1 fn
)
651 "_{" (math-compose-expr (nth 2 a
) 0)
652 "=" (math-compose-expr (nth 3 a
) 0)
653 "}^{" (math-compose-expr (nth 4 a
) 0)
654 "}{" (math-compose-expr (nth 1 a
) 0) "}"))
656 (list 'horiz
(nth 1 fn
)
657 "_{" (math-compose-expr (nth 2 a
) 0)
658 "=" (math-compose-expr (nth 3 a
) 0)
659 "}{" (math-compose-expr (nth 1 a
) 0) "}"))
661 (list 'horiz
(nth 1 fn
)
662 "_{" (math-compose-expr (nth 2 a
) 0)
663 "}{" (math-compose-expr (nth 1 a
) 0) "}"))))
665 (defun math-parse-tex-sum (f val
)
667 (or (equal math-expr-data
"_") (throw 'syntax
"Expected `_'"))
669 (setq save math-exp-old-pos
)
670 (setq low
(math-read-factor))
671 (or (eq (car-safe low
) 'calcFunc-eq
)
673 (setq math-exp-old-pos
(1+ save
))
674 (throw 'syntax
"Expected equation")))
675 (or (equal math-expr-data
"^") (throw 'syntax
"Expected `^'"))
677 (setq high
(math-read-factor))
678 (list (nth 2 f
) (math-read-factor) (nth 1 low
) (nth 2 low
) high
)))
680 (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789.
681 (while (string-match "[0-9]\\\\,[0-9]" str
)
682 (setq str
(concat (substring str
0 (1+ (match-beginning 0)))
683 (substring str
(1- (match-end 0))))))
686 (defun math-compose-tex-sqrt (a)
689 (math-compose-expr (nth 1 a
) 0)
692 (defun math-compose-tex-intv (a)
694 (if (memq (nth 1 a
) '(0 1)) "(" "[")
695 (math-compose-expr (nth 2 a
) 0)
697 (math-compose-expr (nth 3 a
) 0)
698 (if (memq (nth 1 a
) '(0 2)) ")" "]")))
700 (defun math-compose-tex-var (a prec
)
701 (if (and calc-language-option
702 (not (= calc-language-option
0))
703 (string-match "\\`[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω0-9]+\\'"
704 (symbol-name (nth 1 a
))))
705 (if (eq calc-language
'latex
)
706 (format "\\text{%s}" (symbol-name (nth 1 a
)))
707 (format "\\hbox{%s}" (symbol-name (nth 1 a
))))
708 (math-compose-var a
)))
710 (defun math-compose-tex-func (func a
)
712 (if (and calc-language-option
713 (not (= calc-language-option
0))
714 (string-match "\\`[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω0-9]+\\'" func
))
715 (if (< (prefix-numeric-value calc-language-option
) 0)
716 (setq func
(format "\\%s" func
))
717 (setq func
(if (eq calc-language
'latex
)
718 (format "\\text{%s}" func
)
719 (format "\\hbox{%s}" func
)))))
720 (cond ((or (> (length a
) 2)
721 (not (math-tex-expr-is-flat (nth 1 a
))))
722 (setq left
"\\left( "
724 ((and (eq (aref func
0) ?
\\)
726 (string-match "\\hbox{" func
)
727 (string-match "\\text{" func
)))
729 (or (Math-realp (nth 1 a
))
730 (memq (car (nth 1 a
)) '(var *))))
731 (setq left
"{" right
"}"))
732 (t (setq left calc-function-open
733 right calc-function-close
)))
736 (math-compose-vector (cdr a
) ", " 0)
739 (put 'latex
'math-oper-table
740 (append (get 'tex
'math-oper-table
)
741 '(( "\\Hat" calcFunc-Hat -
1 950 )
742 ( "\\Check" calcFunc-Check -
1 950 )
743 ( "\\Tilde" calcFunc-Tilde -
1 950 )
744 ( "\\Acute" calcFunc-Acute -
1 950 )
745 ( "\\Grave" calcFunc-Grave -
1 950 )
746 ( "\\Dot" calcFunc-Dot -
1 950 )
747 ( "\\Ddot" calcFunc-Dotdot -
1 950 )
748 ( "\\Breve" calcFunc-Breve -
1 950 )
749 ( "\\Bar" calcFunc-Bar -
1 950 )
750 ( "\\Vec" calcFunc-VEC -
1 950 )
751 ( "\\dddot" calcFunc-dddot -
1 950 )
752 ( "\\ddddot" calcFunc-ddddot -
1 950 )
753 ( "\\div" / 170 171 )
754 ( "\\le" calcFunc-leq
160 161 )
755 ( "\\leqq" calcFunc-leq
160 161 )
756 ( "\\leqsland" calcFunc-leq
160 161 )
757 ( "\\ge" calcFunc-geq
160 161 )
758 ( "\\geqq" calcFunc-geq
160 161 )
759 ( "\\geqslant" calcFunc-geq
160 161 )
760 ( "=" calcFunc-eq
160 161 )
761 ( "\\neq" calcFunc-neq
160 161 )
762 ( "\\ne" calcFunc-neq
160 161 )
763 ( "\\lnot" calcFunc-lnot -
1 121 )
764 ( "\\land" calcFunc-land
110 111 )
765 ( "\\lor" calcFunc-lor
100 101 )
766 ( "?" (math-read-if) 91 90 )
767 ( "!!!" calcFunc-pnot -
1 85 )
768 ( "&&&" calcFunc-pand
80 81 )
769 ( "|||" calcFunc-por
75 76 )
770 ( "\\gets" calcFunc-assign
51 50 )
771 ( ":=" calcFunc-assign
51 50 )
772 ( "::" calcFunc-condition
45 46 )
773 ( "\\to" calcFunc-evalto
40 41 )
774 ( "\\to" calcFunc-evalto
40 -
1 )
775 ( "=>" calcFunc-evalto
40 41 )
776 ( "=>" calcFunc-evalto
40 -
1 ))))
778 (put 'latex
'math-function-table
780 (get 'tex
'math-function-table
)
781 '(( \\frac .
(math-latex-parse-frac))
782 ( \\tfrac .
(math-latex-parse-frac))
783 ( \\dfrac .
(math-latex-parse-frac))
784 ( \\binom .
(math-latex-parse-two-args calcFunc-choose
))
785 ( \\tbinom .
(math-latex-parse-two-args calcFunc-choose
))
786 ( \\dbinom .
(math-latex-parse-two-args calcFunc-choose
))
787 ( \\phi . calcFunc-totient
)
788 ( \\mu . calcFunc-moebius
))))
790 (put 'latex
'math-special-function-table
791 '((/ .
(math-compose-latex-frac "\\frac"))
792 (calcFunc-choose .
(math-compose-latex-frac "\\binom"))
793 (calcFunc-sum .
(math-compose-tex-sum "\\sum"))
794 (calcFunc-prod .
(math-compose-tex-sum "\\prod"))
795 (calcFunc-sqrt . math-compose-tex-sqrt
)
796 (intv . math-compose-tex-intv
)))
798 (put 'latex
'math-variable-table
799 (get 'tex
'math-variable-table
))
801 (put 'latex
'math-punc-table
806 (put 'latex
'math-complex-format
'i
)
808 (put 'latex
'math-matrix-formatter
811 (if (and (integerp calc-language-option
)
812 (or (= calc-language-option
0)
813 (> calc-language-option
1)
814 (< calc-language-option -
1)))
815 (append '(vleft 0 "\\begin{pmatrix}")
816 (math-compose-tex-matrix (cdr a
) t
)
818 (append '(horiz "\\begin{pmatrix} ")
819 (math-compose-tex-matrix (cdr a
) t
)
820 '(" \\end{pmatrix}"))))))
822 (put 'latex
'math-var-formatter
'math-compose-tex-var
)
824 (put 'latex
'math-func-formatter
'math-compose-tex-func
)
826 (put 'latex
'math-dots
"\\ldots")
828 (put 'latex
'math-big-parens
'("\\left( " .
" \\right)"))
830 (put 'latex
'math-evalto
'("\\evalto " .
" \\to "))
832 (put 'latex
'math-lang-read-symbol
834 (< math-exp-pos
(1- (length math-exp-str
)))
836 (or (string-match "\\\\hbox *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
837 math-exp-str math-exp-pos
)
838 (string-match "\\\\text *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
839 math-exp-str math-exp-pos
)
840 (string-match "\\(\\\\\\([a-zA-Zα-ωΑ-Ω]+\\|[^a-zA-Zα-ωΑ-Ω]\\)\\)"
841 math-exp-str math-exp-pos
))
842 (setq math-exp-token
'symbol
843 math-exp-pos
(match-end 0)
844 math-expr-data
(math-restore-dashes
845 (math-match-substring math-exp-str
1)))
846 (let ((code (assoc math-expr-data math-tex-ignore-words
))
851 ((eq (nth 1 code
) 'punc
)
852 (setq math-exp-token
'punc
853 math-expr-data
(nth 2 code
)))
854 ((and (eq (nth 1 code
) 'begenv
)
855 (string-match " *{\\([^}]*\\)}" math-exp-str math-exp-pos
))
856 (setq math-exp-pos
(match-end 0)
857 envname
(match-string 1 math-exp-str
)
860 (cond ((or (string= envname
"matrix")
861 (string= envname
"bmatrix")
862 (string= envname
"smallmatrix")
863 (string= envname
"pmatrix"))
864 (if (string-match (concat "\\\\end{" envname
"}")
865 math-exp-str math-exp-pos
)
867 (replace-match "]" t t math-exp-str
))
868 (error "%s" (concat "No closing \\end{" envname
"}"))))))
869 ((and (eq (nth 1 code
) 'mat
)
870 (string-match " *{" math-exp-str math-exp-pos
))
871 (setq math-exp-pos
(match-end 0)
874 (let ((right (string-match "}" math-exp-str math-exp-pos
)))
876 (setq math-exp-str
(copy-sequence math-exp-str
))
877 (aset math-exp-str right ?\
]))))))))))
879 (defun math-latex-parse-frac (f val
)
881 (setq numer
(car (math-read-expr-list)))
883 (setq denom
(math-read-factor))
884 (if (and (Math-num-integerp numer
)
885 (Math-num-integerp denom
))
886 (list 'frac numer denom
)
887 (list '/ numer denom
))))
889 (defun math-latex-parse-two-args (f val
)
891 (setq first
(car (math-read-expr-list)))
893 (setq second
(math-read-factor))
894 (list (nth 2 f
) first second
)))
896 (defun math-compose-latex-frac (a fn
)
897 (list 'horiz
(nth 1 fn
) "{" (math-compose-expr (nth 1 a
) -
1)
899 (math-compose-expr (nth 2 a
) -
1)
902 (put 'latex
'math-input-filter
'math-tex-input-filter
)
904 (defun calc-eqn-language (n)
907 (calc-set-language 'eqn
)
908 (message "Eqn language mode")))
910 (put 'eqn
'math-oper-table
911 '( ( "prime" (math-parse-eqn-prime) 950 -
1 )
912 ( "prime" calcFunc-Prime
950 -
1 )
913 ( "dot" calcFunc-dot
950 -
1 )
914 ( "dotdot" calcFunc-dotdot
950 -
1 )
915 ( "hat" calcFunc-hat
950 -
1 )
916 ( "tilde" calcFunc-tilde
950 -
1 )
917 ( "vec" calcFunc-Vec
950 -
1 )
918 ( "dyad" calcFunc-dyad
950 -
1 )
919 ( "bar" calcFunc-bar
950 -
1 )
920 ( "under" calcFunc-under
950 -
1 )
921 ( "sub" calcFunc-subscr
931 930 )
923 ( "sqrt" calcFunc-sqrt -
1 910 )
925 ( "u|" calcFunc-abs -
1 0 )
927 ( "left floor" calcFunc-floor -
1 0 )
928 ( "right floor" closing
0 -
1 )
929 ( "left ceil" calcFunc-ceil -
1 0 )
930 ( "right ceil" closing
0 -
1 )
931 ( "+-" sdev
300 300 )
932 ( "!" calcFunc-fact
210 -
1 )
933 ( "u+" ident -
1 197 )
935 ( "times" * 191 190 )
942 ( "<" calcFunc-lt
160 161 )
943 ( ">" calcFunc-gt
160 161 )
944 ( "<=" calcFunc-leq
160 161 )
945 ( ">=" calcFunc-geq
160 161 )
946 ( "=" calcFunc-eq
160 161 )
947 ( "==" calcFunc-eq
160 161 )
948 ( "!=" calcFunc-neq
160 161 )
949 ( "u!" calcFunc-lnot -
1 121 )
950 ( "&&" calcFunc-land
110 111 )
951 ( "||" calcFunc-lor
100 101 )
952 ( "?" (math-read-if) 91 90 )
953 ( "!!!" calcFunc-pnot -
1 85 )
954 ( "&&&" calcFunc-pand
80 81 )
955 ( "|||" calcFunc-por
75 76 )
956 ( "<-" calcFunc-assign
51 50 )
957 ( ":=" calcFunc-assign
51 50 )
958 ( "::" calcFunc-condition
45 46 )
959 ( "->" calcFunc-evalto
40 41 )
960 ( "->" calcFunc-evalto
40 -
1 )
961 ( "=>" calcFunc-evalto
40 41 )
962 ( "=>" calcFunc-evalto
40 -
1 )))
964 (put 'eqn
'math-function-table
965 '( ( arc\ cos . calcFunc-arccos
)
966 ( arc\ cosh . calcFunc-arccosh
)
967 ( arc\ sin . calcFunc-arcsin
)
968 ( arc\ sinh . calcFunc-arcsinh
)
969 ( arc\ tan . calcFunc-arctan
)
970 ( arc\ tanh . calcFunc-arctanh
)
971 ( GAMMA . calcFunc-gamma
)
972 ( phi . calcFunc-totient
)
973 ( mu . calcFunc-moebius
)
974 ( matrix .
(math-parse-eqn-matrix) )))
976 (put 'eqn
'math-special-function-table
977 '((intv . math-compose-eqn-intv
)))
979 (put 'eqn
'math-punc-table
983 (put 'eqn
'math-variable-table
984 '( ( inf . var-uinf
)))
986 (put 'eqn
'math-complex-format
'i
)
988 (put 'eqn
'math-big-parens
'("{left ( " .
" right )}"))
990 (put 'eqn
'math-evalto
'("evalto " .
" -> "))
992 (put 'eqn
'math-matrix-formatter
995 (append '(horiz "matrix { ")
996 (math-compose-eqn-matrix
997 (cdr (math-transpose a
)))
1000 (put 'eqn
'math-var-formatter
1004 (if (and math-compose-hash-args
1005 (let ((p calc-arg-values
))
1007 (while (and p
(not (equal (car p
) a
)))
1008 (setq p
(and (eq math-compose-hash-args t
) (cdr p
))
1011 (if (eq math-compose-hash-args
1)
1014 (if (string-match ".'\\'" (symbol-name (nth 2 a
)))
1016 (list 'calcFunc-Prime
1019 (intern (substring (symbol-name (nth 1 a
)) 0 -
1))
1020 (intern (substring (symbol-name (nth 2 a
)) 0 -
1))))
1022 (symbol-name (nth 1 a
))))))))
1024 (defconst math-eqn-special-funcs
1026 calcFunc-ln calcFunc-exp
1027 calcFunc-sin calcFunc-cos calcFunc-tan
1028 calcFunc-sec calcFunc-csc calcFunc-cot
1029 calcFunc-sinh calcFunc-cosh calcFunc-tanh
1030 calcFunc-sech calcFunc-csch calcFunc-coth
1031 calcFunc-arcsin calcFunc-arccos calcFunc-arctan
1032 calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh
))
1034 (put 'eqn
'math-func-formatter
1038 (if (string-match "[^']'+\\'" func
)
1039 (let ((n (- (length func
) (match-beginning 0) 1)))
1040 (setq func
(substring func
0 (- n
)))
1041 (while (>= (setq n
(1- n
)) 0)
1042 (setq func
(concat func
" prime")))))
1043 (cond ((or (> (length a
) 2)
1044 (not (math-tex-expr-is-flat (nth 1 a
))))
1045 (setq left
"{left ( "
1049 (memq (car a
) math-eqn-special-funcs
)
1051 (or (Math-realp (nth 1 a
))
1052 (memq (car (nth 1 a
)) '(var *))))
1053 (setq left
"~{" right
"}"))
1057 (list 'horiz func left
1058 (math-compose-vector (cdr a
) " , " 0)
1061 (put 'eqn
'math-lang-read-symbol
1063 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
1064 math-exp-str math-exp-pos
)
1066 (setq math-exp-str
(copy-sequence math-exp-str
))
1067 (aset math-exp-str
(match-beginning 1) ?\
{)
1068 (if (< (match-end 1) (length math-exp-str
))
1069 (aset math-exp-str
(match-end 1) ?\
}))
1070 (math-read-token)))))
1072 (defconst math-eqn-ignore-words
1073 '( ("roman") ("bold") ("italic") ("mark") ("lineup") ("evalto")
1074 ("left" ("floor") ("ceil"))
1075 ("right" ("floor") ("ceil"))
1076 ("arc" ("sin") ("cos") ("tan") ("sinh") ("cosh") ("tanh"))
1077 ("size" n
) ("font" n
) ("fwd" n
) ("back" n
) ("up" n
) ("down" n
)
1078 ("above" punc
",")))
1080 (put 'eqn
'math-lang-adjust-words
1083 (let ((code (assoc math-expr-data math-eqn-ignore-words
)))
1087 ((consp (nth 1 code
))
1089 (if (assoc math-expr-data
(cdr code
))
1090 (setq math-expr-data
(format "%s %s"
1091 (car code
) math-expr-data
))))
1092 ((eq (nth 1 code
) 'punc
)
1093 (setq math-exp-token
'punc
1094 math-expr-data
(nth 2 code
)))
1097 (math-read-token)))))))
1099 (put 'eqn
'math-lang-read
1100 '((eq (string-match "->\\|<-\\|+-\\|\\\\dots\\|~\\|\\^"
1101 math-exp-str math-exp-pos
)
1104 (setq math-exp-token
'punc
1105 math-expr-data
(math-match-substring math-exp-str
0)
1106 math-exp-pos
(match-end 0))
1107 (and (eq (string-match "\\\\dots\\." math-exp-str math-exp-pos
)
1109 (setq math-exp-pos
(match-end 0)))
1110 (if (memq (aref math-expr-data
0) '(?~ ?^
))
1111 (math-read-token)))))
1114 (defun math-compose-eqn-matrix (a)
1117 (cond ((eq calc-matrix-just
'right
) "rcol ")
1118 ((eq calc-matrix-just
'center
) "ccol ")
1121 (list 'break math-compose-level
)
1125 (let ((math-compose-level (1+ math-compose-level
)))
1126 (math-compose-vector (cdr (car a
)) " above " 1000))
1129 (math-compose-eqn-matrix (cdr a
)))))))
1132 (defun math-parse-eqn-matrix (f sym
)
1134 (while (assoc math-expr-data
'(("ccol") ("lcol") ("rcol")))
1136 (or (equal math-expr-data calc-function-open
)
1137 (throw 'syntax
"Expected `{'"))
1139 (setq vec
(cons (cons 'vec
(math-read-expr-list)) vec
))
1140 (or (equal math-expr-data calc-function-close
)
1141 (throw 'syntax
"Expected `}'"))
1143 (or (equal math-expr-data calc-function-close
)
1144 (throw 'syntax
"Expected `}'"))
1146 (math-transpose (cons 'vec
(nreverse vec
)))))
1148 (defun math-parse-eqn-prime (x sym
)
1149 (if (eq (car-safe x
) 'var
)
1150 (if (equal math-expr-data calc-function-open
)
1153 (let ((args (if (or (equal math-expr-data calc-function-close
)
1154 (eq math-exp-token
'end
))
1156 (math-read-expr-list))))
1157 (if (not (or (equal math-expr-data calc-function-close
)
1158 (eq math-exp-token
'end
)))
1159 (throw 'syntax
"Expected `)'"))
1161 (cons (intern (format "calcFunc-%s'" (nth 1 x
))) args
)))
1163 (intern (concat (symbol-name (nth 1 x
)) "'"))
1164 (intern (concat (symbol-name (nth 2 x
)) "'"))))
1165 (list 'calcFunc-Prime x
)))
1167 (defun math-compose-eqn-intv (a)
1169 (if (memq (nth 1 a
) '(0 1)) "(" "[")
1170 (math-compose-expr (nth 2 a
) 0)
1172 (math-compose-expr (nth 3 a
) 0)
1173 (if (memq (nth 1 a
) '(0 2)) ")" "]")))
1178 (defun calc-yacas-language ()
1179 "Change the Calc language to be Yacas-like."
1182 (calc-set-language 'yacas
)
1183 (message "`Yacas' language mode")))
1185 (put 'yacas
'math-vector-brackets
"{}")
1187 (put 'yacas
'math-complex-format
'I
)
1189 (add-to-list 'calc-lang-brackets-are-subscripts
'yacas
)
1191 (put 'yacas
'math-variable-table
1192 '(( Infinity . var-inf
)
1193 ( Infinity . var-uinf
)
1194 ( Undefined . var-nan
)
1196 ( E . var-e
) ;; Not really in Yacas
1197 ( GoldenRatio . var-phi
)
1198 ( Gamma . var-gamma
)))
1200 (put 'yacas
'math-parse-table
1201 '((("Deriv(" 0 ")" 0)
1202 calcFunc-deriv
(var ArgB var-ArgB
) (var ArgA var-ArgA
))
1204 calcFunc-deriv
(var ArgB var-ArgB
) (var ArgA var-ArgA
))
1205 (("Integrate(" 0 ")" 0)
1206 calcFunc-integ
(var ArgB var-ArgB
)(var ArgA var-ArgA
))
1207 (("Integrate(" 0 "," 0 "," 0 ")" 0)
1208 calcFunc-integ
(var ArgD var-ArgD
) (var ArgA var-ArgA
)
1209 (var ArgB var-ArgB
) (var ArgC var-ArgC
))
1210 (("Subst(" 0 "," 0 ")" 0)
1211 calcFunc-subst
(var ArgC var-ArgC
) (var ArgA var-ArgA
)
1212 (var ArgB var-ArgB
))
1213 (("Taylor(" 0 "," 0 "," 0 ")" 0)
1214 calcFunc-taylor
(var ArgD var-ArgD
)
1215 (calcFunc-eq (var ArgA var-ArgA
) (var ArgB var-ArgB
))
1216 (var ArgC var-ArgC
))))
1218 (put 'yacas
'math-oper-table
1226 ("<<" calcFunc-lsh
80 80)
1227 (">>" calcFunc-rsh
80 80)
1228 ("!" calcFunc-fact
80 -
1)
1229 ("!!" calcFunc-dfact
80 -
1)
1230 ("X" calcFunc-cross
70 70)
1231 ("=" calcFunc-eq
10 10)
1232 ("!=" calcFunc-neq
10 10)
1233 ("<" calcFunc-lt
10 10)
1234 (">" calcFunc-gt
10 10)
1235 ("<=" calcFunc-leq
10 10)
1236 (">=" calcFunc-geq
10 10)
1237 ("And" calcFunc-land
5 5)
1238 ("Or" calcFunc-or
4 4)
1239 ("Not" calcFunc-lnot -
1 3)
1240 (":=" calcFunc-assign
1 1)))
1242 (put 'yacas
'math-function-table
1243 '(( Div . calcFunc-idiv
)
1244 ( Mod . calcFunc-mod
)
1245 ( Abs . calcFunc-abs
)
1246 ( Sign . calcFunc-sign
)
1247 ( Sqrt . calcFunc-sqrt
)
1248 ( Max . calcFunc-max
)
1249 ( Min . calcFunc-min
)
1250 ( Floor . calcFunc-floor
)
1251 ( Ceil . calcFunc-ceil
)
1252 ( Round . calcFunc-round
)
1253 ( Conjugate . calcFunc-conj
)
1254 ( Arg . calcFunc-arg
)
1257 ( Rationalize . calcFunc-pfrac
)
1258 ( Sin . calcFunc-sin
)
1259 ( Cos . calcFunc-cos
)
1260 ( Tan . calcFunc-tan
)
1261 ( Sec . calcFunc-sec
)
1262 ( Csc . calcFunc-csc
)
1263 ( Cot . calcFunc-cot
)
1264 ( ArcSin . calcFunc-arcsin
)
1265 ( ArcCos . calcFunc-arccos
)
1266 ( ArcTan . calcFunc-arctan
)
1267 ( Sinh . calcFunc-sinh
)
1268 ( Cosh . calcFunc-cosh
)
1269 ( Tanh . calcFunc-tanh
)
1270 ( Sech . calcFunc-sech
)
1271 ( Csch . calcFunc-csch
)
1272 ( Coth . calcFunc-coth
)
1273 ( ArcSinh . calcFunc-arcsinh
)
1274 ( ArcCosh . calcFunc-arccosh
)
1275 ( ArcTanh . calcFunc-arctanh
)
1277 ( Exp . calcFunc-exp
)
1278 ( Gamma . calcFunc-gamma
)
1279 ( Gcd . calcFunc-gcd
)
1280 ( Lcm . calcFunc-lcm
)
1281 ( Bin . calcFunc-choose
)
1282 ( Bernoulli . calcFunc-bern
)
1283 ( Euler . calcFunc-euler
)
1284 ( StirlingNumber1 . calcFunc-stir1
)
1285 ( StirlingNumber2 . calcFunc-stir2
)
1286 ( IsPrime . calcFunc-prime
)
1287 ( Factors . calcFunc-prfac
)
1288 ( NextPrime . calcFunc-nextprime
)
1289 ( Moebius . calcFunc-moebius
)
1290 ( Random . calcFunc-random
)
1291 ( Concat . calcFunc-vconcat
)
1292 ( Head . calcFunc-head
)
1293 ( Tail . calcFunc-tail
)
1294 ( Length . calcFunc-vlen
)
1295 ( Reverse . calcFunc-rev
)
1296 ( CrossProduct . calcFunc-cross
)
1297 ( Dot . calcFunc-mul
)
1298 ( DiagonalMatrix . calcFunc-diag
)
1299 ( Transpose . calcFunc-trn
)
1300 ( Inverse . calcFunc-inv
)
1301 ( Determinant . calcFunc-det
)
1302 ( Trace . calcFunc-tr
)
1303 ( RemoveDuplicates . calcFunc-rdup
)
1304 ( Union . calcFunc-vunion
)
1305 ( Intersection . calcFunc-vint
)
1306 ( Difference . calcFunc-vdiff
)
1307 ( Apply . calcFunc-apply
)
1308 ( Map . calcFunc-map
)
1309 ( Simplify . calcFunc-simplify
)
1310 ( ExpandBrackets . calcFunc-expand
)
1311 ( Solve . calcFunc-solve
)
1312 ( Degree . calcFunc-pdeg
)
1314 ( Contains .
(math-lang-switch-args calcFunc-in
))
1315 ( Sum .
(math-yacas-parse-Sum calcFunc-sum
))
1316 ( Factorize .
(math-yacas-parse-Sum calcFunc-prod
))))
1318 (put 'yacas
'math-special-function-table
1319 '(( calcFunc-sum .
(math-yacas-compose-sum "Sum"))
1320 ( calcFunc-prod .
(math-yacas-compose-sum "Factorize"))
1321 ( calcFunc-deriv .
(math-yacas-compose-deriv "Deriv"))
1322 ( calcFunc-integ .
(math-yacas-compose-deriv "Integrate"))
1323 ( calcFunc-taylor . math-yacas-compose-taylor
)
1324 ( calcFunc-in .
(math-lang-compose-switch-args "Contains"))))
1326 (put 'yacas
'math-compose-subscr
1329 (let ((args (cdr (cdr a
))))
1331 (math-compose-expr (nth 1 a
) 1000)
1333 (math-compose-vector args
", " 0)
1336 (defun math-yacas-parse-Sum (f val
)
1337 "Read in the arguments to \"Sum\" in Calc's Yacas mode."
1338 (let ((args (math-read-expr-list)))
1346 (defun math-yacas-compose-sum (a fn
)
1347 "Compose the \"Sum\" function in Calc's Yacas mode."
1351 (math-compose-expr (nth 2 a
) -
1)
1353 (math-compose-expr (nth 3 a
) -
1)
1355 (math-compose-expr (nth 4 a
) -
1)
1357 (math-compose-expr (nth 1 a
) -
1)
1360 (defun math-yacas-compose-deriv (a fn
)
1361 "Compose the \"Deriv\" function in Calc's Yacas mode."
1365 (math-compose-expr (nth 2 a
) -
1)
1370 (math-compose-expr (nth 3 a
) -
1)
1372 (math-compose-expr (nth 4 a
) -
1)
1375 (math-compose-expr (nth 1 a
) -
1)))
1377 (defun math-yacas-compose-taylor (a)
1378 "Compose the \"Taylor\" function in Calc's Yacas mode."
1381 (if (eq (car-safe (nth 2 a
)) 'calcFunc-eq
)
1382 (concat (math-compose-expr (nth 1 (nth 2 a
)) -
1)
1384 (math-compose-expr (nth 2 (nth 2 a
)) -
1))
1385 (concat (math-compose-expr (nth 2 a
) -
1) ",0"))
1387 (math-compose-expr (nth 3 a
) -
1)
1389 (math-compose-expr (nth 1 a
) -
1)))
1394 (defun calc-maxima-language ()
1395 "Change the Calc language to be Maxima-like."
1398 (calc-set-language 'maxima
)
1399 (message "`Maxima' language mode")))
1401 (put 'maxima
'math-oper-table
1411 ("!" calcFunc-fact
160 -
1)
1412 ("!!" calcFunc-dfact
160 -
1)
1413 ("=" calcFunc-eq
80 80)
1414 ("#" calcFunc-neq
80 80)
1415 ("<" calcFunc-lt
80 80)
1416 (">" calcFunc-gt
80 80)
1417 ("<=" calcFunc-leq
80 80)
1418 (">=" calcFunc-geq
80 80)
1419 ("and" calcFunc-land
65 65)
1420 ("or" calcFunc-or
60 60)
1421 ("not" calcFunc-lnot -
1 70)
1422 (":" calcFunc-assign
180 20)))
1425 (put 'maxima
'math-function-table
1427 ( abs . calcFunc-abs
)
1428 ( cabs . calcFunc-abs
)
1429 ( signum . calcFunc-sign
)
1430 ( floor . calcFunc-floor
)
1431 ( entier . calcFunc-floor
)
1432 ( fix . calcFunc-floor
)
1433 ( conjugate . calcFunc-conj
)
1434 ( carg . calcFunc-arg
)
1435 ( realpart . calcFunc-re
)
1436 ( imagpart . calcFunc-im
)
1437 ( rationalize . calcFunc-pfrac
)
1438 ( asin . calcFunc-arcsin
)
1439 ( acos . calcFunc-arccos
)
1440 ( atan . calcFunc-arctan
)
1441 ( atan2 . calcFunc-arctan2
)
1442 ( asinh . calcFunc-arcsinh
)
1443 ( acosh . calcFunc-arccosh
)
1444 ( atanh . calcFunc-arctanh
)
1445 ( log . calcFunc-ln
)
1446 ( plog . calcFunc-ln
)
1447 ( bessel_j . calcFunc-besJ
)
1448 ( bessel_y . calcFunc-besY
)
1449 ( factorial . calcFunc-fact
)
1450 ( binomial . calcFunc-choose
)
1451 ( primep . calcFunc-prime
)
1452 ( next_prime . calcFunc-nextprime
)
1453 ( prev_prime . calcFunc-prevprime
)
1454 ( append . calcFunc-vconcat
)
1455 ( rest . calcFunc-tail
)
1456 ( reverse . calcFunc-rev
)
1457 ( innerproduct . calcFunc-mul
)
1458 ( inprod . calcFunc-mul
)
1459 ( row . calcFunc-mrow
)
1460 ( columnvector . calcFunc-mcol
)
1461 ( covect . calcFunc-mcol
)
1462 ( transpose . calcFunc-trn
)
1463 ( invert . calcFunc-inv
)
1464 ( determinant . calcFunc-det
)
1465 ( mattrace . calcFunc-tr
)
1466 ( member . calcFunc-in
)
1467 ( lmax . calcFunc-vmax
)
1468 ( lmin . calcFunc-vmin
)
1469 ( distrib . calcFunc-expand
)
1470 ( partfrac . calcFunc-apart
)
1471 ( rat . calcFunc-nrat
)
1472 ( product . calcFunc-prod
)
1473 ( diff . calcFunc-deriv
)
1474 ( integrate . calcFunc-integ
)
1475 ( quotient . calcFunc-pdiv
)
1476 ( remainder . calcFunc-prem
)
1477 ( divide . calcFunc-pdivrem
)
1478 ( equal . calcFunc-eq
)
1479 ( notequal . calcFunc-neq
)
1480 ( rhs . calcFunc-rmeq
)
1481 ( subst .
(math-maxima-parse-subst))
1482 ( substitute .
(math-maxima-parse-subst))
1483 ( taylor .
(math-maxima-parse-taylor))))
1485 (defun math-maxima-parse-subst (f val
)
1486 "Read in the arguments to \"subst\" in Calc's Maxima mode."
1487 (let ((args (math-read-expr-list)))
1489 (list 'calcFunc-subst
1494 (defun math-maxima-parse-taylor (f val
)
1495 "Read in the arguments to \"taylor\" in Calc's Maxima mode."
1496 (let ((args (math-read-expr-list)))
1498 (list 'calcFunc-taylor
1505 (put 'maxima
'math-parse-table
1506 '((("if" 0 "then" 0 "else" 0)
1510 (var ArgC var-ArgC
))))
1512 (put 'maxima
'math-special-function-table
1513 '(( calcFunc-taylor . math-maxima-compose-taylor
)
1514 ( calcFunc-subst . math-maxima-compose-subst
)
1515 ( calcFunc-if . math-maxima-compose-if
)))
1517 (defun math-maxima-compose-taylor (a)
1518 "Compose the \"taylor\" function in Calc's Maxima mode."
1521 (math-compose-expr (nth 1 a
) -
1)
1523 (if (eq (car-safe (nth 2 a
)) 'calcFunc-eq
)
1524 (concat (math-compose-expr (nth 1 (nth 2 a
)) -
1)
1526 (math-compose-expr (nth 2 (nth 2 a
)) -
1))
1527 (concat (math-compose-expr (nth 2 a
) -
1) ",0"))
1529 (math-compose-expr (nth 3 a
) -
1)
1532 (defun math-maxima-compose-subst (a)
1533 "Compose the \"subst\" function in Calc's Maxima mode."
1536 (math-compose-expr (nth 2 a
) -
1)
1538 (math-compose-expr (nth 3 a
) -
1)
1540 (math-compose-expr (nth 1 a
) -
1)
1543 (defun math-maxima-compose-if (a)
1544 "Compose the \"if\" function in Calc's Maxima mode."
1547 (math-compose-expr (nth 1 a
) -
1)
1549 (math-compose-expr (nth 2 a
) -
1)
1551 (math-compose-expr (nth 3 a
) -
1)))
1553 (put 'maxima
'math-variable-table
1554 '(( infinity . var-uinf
)
1559 ( %gamma . var-gamma
)))
1561 (put 'maxima
'math-complex-format
'%i
)
1563 (add-to-list 'calc-lang-allow-underscores
'maxima
)
1565 (add-to-list 'calc-lang-allow-percentsigns
'maxima
)
1567 (add-to-list 'calc-lang-brackets-are-subscripts
'maxima
)
1569 (put 'maxima
'math-compose-subscr
1572 (let ((args (cdr (cdr a
))))
1574 (math-compose-expr (nth 1 a
) 1000)
1576 (math-compose-vector args
", " 0)
1579 (put 'maxima
'math-matrix-formatter
1584 (math-compose-vector (cdr a
)
1585 (concat math-comp-comma
" ")
1586 math-comp-vector-prec
)
1592 (defun calc-giac-language ()
1593 "Change the Calc language to be Giac-like."
1596 (calc-set-language 'giac
)
1597 (message "`Giac' language mode")))
1599 (put 'giac
'math-oper-table
1600 '( ( "[" (math-read-giac-subscr) 250 -
1 )
1606 ( "u+" ident -
1 197 )
1608 ( "!" calcFunc-fact
210 -
1 )
1609 ( ".." (math-read-maple-dots) 165 165 )
1610 ( "\\dots" (math-read-maple-dots) 165 165 )
1611 ( "intersect" calcFunc-vint
191 192 )
1612 ( "union" calcFunc-vunion
180 181 )
1613 ( "minus" calcFunc-vdiff
180 181 )
1614 ( "<" calcFunc-lt
160 160 )
1615 ( ">" calcFunc-gt
160 160 )
1616 ( "<=" calcFunc-leq
160 160 )
1617 ( ">=" calcFunc-geq
160 160 )
1618 ( "=" calcFunc-eq
160 160 )
1619 ( "==" calcFunc-eq
160 160 )
1620 ( "!=" calcFunc-neq
160 160 )
1621 ( "and" calcFunc-land
110 111 )
1622 ( "or" calcFunc-lor
100 101 )
1623 ( "&&" calcFunc-land
110 111 )
1624 ( "||" calcFunc-lor
100 101 )
1625 ( "not" calcFunc-lnot -
1 121 )
1626 ( ":=" calcFunc-assign
51 50 )))
1629 (put 'giac
'math-function-table
1630 '(( rdiv . calcFunc-div
)
1631 ( iquo . calcFunc-idiv
)
1632 ( irem . calcFunc-mod
)
1633 ( remain . calcFunc-mod
)
1634 ( floor . calcFunc-floor
)
1635 ( iPart . calcFunc-floor
)
1636 ( ceil . calcFunc-ceil
)
1637 ( ceiling . calcFunc-ceil
)
1639 ( real . calcFunc-re
)
1641 ( imag . calcFunc-im
)
1642 ( float2rational . calcFunc-pfrac
)
1643 ( exact . calcFunc-pfrac
)
1644 ( evalf . calcFunc-pfloat
)
1645 ( bitand . calcFunc-and
)
1646 ( bitor . calcFunc-or
)
1647 ( bitxor . calcFunc-xor
)
1648 ( asin . calcFunc-arcsin
)
1649 ( acos . calcFunc-arccos
)
1650 ( atan . calcFunc-arctan
)
1651 ( asinh . calcFunc-arcsinh
)
1652 ( acosh . calcFunc-arccosh
)
1653 ( atanh . calcFunc-arctanh
)
1654 ( log . calcFunc-ln
)
1655 ( logb . calcFunc-log
)
1656 ( factorial . calcFunc-fact
)
1657 ( comb . calcFunc-choose
)
1658 ( binomial . calcFunc-choose
)
1659 ( nCr . calcFunc-choose
)
1660 ( perm . calcFunc-perm
)
1661 ( nPr . calcFunc-perm
)
1662 ( bernoulli . calcFunc-bern
)
1663 ( is_prime . calcFunc-prime
)
1664 ( isprime . calcFunc-prime
)
1665 ( isPrime . calcFunc-prime
)
1666 ( ifactors . calcFunc-prfac
)
1667 ( euler . calcFunc-totient
)
1668 ( phi . calcFunc-totient
)
1669 ( rand . calcFunc-random
)
1670 ( concat . calcFunc-vconcat
)
1671 ( augment . calcFunc-vconcat
)
1672 ( mid . calcFunc-subvec
)
1673 ( length . calcFunc-length
)
1674 ( size . calcFunc-length
)
1675 ( nops . calcFunc-length
)
1676 ( SortA . calcFunc-sort
)
1677 ( SortB . calcFunc-rsort
)
1678 ( revlist . calcFunc-rev
)
1679 ( cross . calcFunc-cross
)
1680 ( crossP . calcFunc-cross
)
1681 ( crossproduct . calcFunc-cross
)
1682 ( mul . calcFunc-mul
)
1683 ( dot . calcFunc-mul
)
1684 ( dotprod . calcFunc-mul
)
1685 ( dotP . calcFunc-mul
)
1686 ( scalar_product . calcFunc-mul
)
1687 ( scalar_Product . calcFunc-mul
)
1688 ( row . calcFunc-mrow
)
1689 ( col . calcFunc-mcol
)
1690 ( dim . calcFunc-mdims
)
1691 ( tran . calcFunc-trn
)
1692 ( transpose . calcFunc-trn
)
1693 ( lu . calcFunc-lud
)
1694 ( trace . calcFunc-tr
)
1695 ( member . calcFunc-in
)
1696 ( sum . calcFunc-vsum
)
1697 ( add . calcFunc-vsum
)
1698 ( product . calcFunc-vprod
)
1699 ( mean . calcFunc-vmean
)
1700 ( median . calcFunc-vmedian
)
1701 ( stddev . calcFunc-vsdev
)
1702 ( stddevp . calcFunc-vpsdev
)
1703 ( variance . calcFunc-vpvar
)
1704 ( map . calcFunc-map
)
1705 ( apply . calcFunc-map
)
1706 ( of . calcFunc-map
)
1707 ( zip . calcFunc-map
)
1708 ( expand . calcFunc-expand
)
1709 ( fdistrib . calcFunc-expand
)
1710 ( partfrac . calcFunc-apart
)
1711 ( ratnormal . calcFunc-nrat
)
1712 ( diff . calcFunc-deriv
)
1713 ( derive . calcFunc-deriv
)
1714 ( integrate . calcFunc-integ
)
1715 ( int . calcFunc-integ
)
1716 ( Int . calcFunc-integ
)
1717 ( romberg . calcFunc-ninteg
)
1718 ( nInt . calcFunc-ninteg
)
1719 ( lcoeff . calcFunc-plead
)
1720 ( content . calcFunc-pcont
)
1721 ( primpart . calcFunc-pprim
)
1722 ( quo . calcFunc-pdiv
)
1723 ( rem . calcFunc-prem
)
1724 ( quorem . calcFunc-pdivrem
)
1725 ( divide . calcFunc-pdivrem
)
1726 ( equal . calcFunc-eq
)
1727 ( ifte . calcFunc-if
)
1728 ( not . calcFunc-lnot
)
1729 ( rhs . calcFunc-rmeq
)
1730 ( right . calcFunc-rmeq
)
1731 ( prepend .
(math-lang-switch-args calcFunc-cons
))
1732 ( contains .
(math-lang-switch-args calcFunc-in
))
1733 ( has .
(math-lang-switch-args calcFunc-refers
))))
1735 (defun math-lang-switch-args (f val
)
1736 "Read the arguments to a Calc function in reverse order.
1737 This is used for various language modes which have functions in reverse
1739 (let ((args (math-read-expr-list)))
1745 (put 'giac
'math-parse-table
1748 (var ArgA var-ArgA
))))
1750 (put 'giac
'math-special-function-table
1751 '((calcFunc-cons .
(math-lang-compose-switch-args "prepend"))
1752 (calcFunc-in .
(math-lang-compose-switch-args "contains"))
1753 (calcFunc-refers .
(math-lang-compose-switch-args "has"))
1754 (intv . math-compose-maple-intv
)))
1756 (defun math-lang-compose-switch-args (a fn
)
1757 "Compose the arguments to a Calc function in reverse order.
1758 This is used for various language modes which have functions in reverse
1760 (list 'horiz
(nth 1 fn
)
1762 (math-compose-expr (nth 2 a
) 0)
1764 (math-compose-expr (nth 1 a
) 0)
1767 (put 'giac
'math-variable-table
1768 '(( infinity . var-inf
)
1769 ( infinity . var-uinf
)))
1771 (put 'giac
'math-complex-format
'i
)
1773 (add-to-list 'calc-lang-allow-underscores
'giac
)
1775 (put 'giac
'math-compose-subscr
1778 (let ((args (cdr (cdr a
))))
1780 (math-compose-expr (nth 1 a
) 1000)
1783 (calc-normalize (list '-
(nth 2 a
) 1)) 0)
1786 (defun math-read-giac-subscr (x op
)
1787 (let ((idx (math-read-expr-level 0)))
1788 (or (equal math-expr-data
"]")
1789 (throw 'syntax
"Expected ']'"))
1791 (list 'calcFunc-subscr x
(calc-normalize (list '+ idx
1)))))
1793 (add-to-list 'calc-lang-c-type-hex
'giac
)
1796 (defun calc-mathematica-language ()
1799 (calc-set-language 'math
)
1800 (message "Mathematica language mode")))
1802 (put 'math
'math-oper-table
1803 '( ( "[[" (math-read-math-subscr) 250 -
1 )
1804 ( "!" calcFunc-fact
210 -
1 )
1805 ( "!!" calcFunc-dfact
210 -
1 )
1807 ( "u+" ident -
1 197 )
1814 ( "<" calcFunc-lt
160 161 )
1815 ( ">" calcFunc-gt
160 161 )
1816 ( "<=" calcFunc-leq
160 161 )
1817 ( ">=" calcFunc-geq
160 161 )
1818 ( "==" calcFunc-eq
150 151 )
1819 ( "!=" calcFunc-neq
150 151 )
1820 ( "u!" calcFunc-lnot -
1 121 )
1821 ( "&&" calcFunc-land
110 111 )
1822 ( "||" calcFunc-lor
100 101 )
1823 ( "!!!" calcFunc-pnot -
1 85 )
1824 ( "&&&" calcFunc-pand
80 81 )
1825 ( "|||" calcFunc-por
75 76 )
1826 ( ":=" calcFunc-assign
51 50 )
1827 ( "=" calcFunc-assign
51 50 )
1828 ( "->" calcFunc-assign
51 50 )
1829 ( ":>" calcFunc-assign
51 50 )
1830 ( "::" calcFunc-condition
45 46 )
1833 (put 'math
'math-function-table
1834 '( ( Abs . calcFunc-abs
)
1835 ( ArcCos . calcFunc-arccos
)
1836 ( ArcCosh . calcFunc-arccosh
)
1837 ( ArcSin . calcFunc-arcsin
)
1838 ( ArcSinh . calcFunc-arcsinh
)
1839 ( ArcTan . calcFunc-arctan
)
1840 ( ArcTanh . calcFunc-arctanh
)
1841 ( Arg . calcFunc-arg
)
1842 ( Binomial . calcFunc-choose
)
1843 ( Ceiling . calcFunc-ceil
)
1844 ( Conjugate . calcFunc-conj
)
1845 ( Cos . calcFunc-cos
)
1846 ( Cosh . calcFunc-cosh
)
1847 ( Cot . calcFunc-cot
)
1848 ( Coth . calcFunc-coth
)
1849 ( Csc . calcFunc-csc
)
1850 ( Csch . calcFunc-csch
)
1851 ( D . calcFunc-deriv
)
1852 ( Dt . calcFunc-tderiv
)
1853 ( Det . calcFunc-det
)
1854 ( Exp . calcFunc-exp
)
1855 ( EulerPhi . calcFunc-totient
)
1856 ( Floor . calcFunc-floor
)
1857 ( Gamma . calcFunc-gamma
)
1858 ( GCD . calcFunc-gcd
)
1859 ( If . calcFunc-if
)
1860 ( Im . calcFunc-im
)
1861 ( Inverse . calcFunc-inv
)
1862 ( Integrate . calcFunc-integ
)
1863 ( Join . calcFunc-vconcat
)
1864 ( LCM . calcFunc-lcm
)
1865 ( Log . calcFunc-ln
)
1866 ( Max . calcFunc-max
)
1867 ( Min . calcFunc-min
)
1868 ( Mod . calcFunc-mod
)
1869 ( MoebiusMu . calcFunc-moebius
)
1870 ( Random . calcFunc-random
)
1871 ( Round . calcFunc-round
)
1872 ( Re . calcFunc-re
)
1873 ( Sec . calcFunc-sec
)
1874 ( Sech . calcFunc-sech
)
1875 ( Sign . calcFunc-sign
)
1876 ( Sin . calcFunc-sin
)
1877 ( Sinh . calcFunc-sinh
)
1878 ( Sqrt . calcFunc-sqrt
)
1879 ( Tan . calcFunc-tan
)
1880 ( Tanh . calcFunc-tanh
)
1881 ( Transpose . calcFunc-trn
)
1882 ( Length . calcFunc-vlen
)
1885 (put 'math
'math-variable-table
1889 ( GoldenRatio . var-phi
)
1890 ( EulerGamma . var-gamma
)
1891 ( Infinity . var-inf
)
1892 ( ComplexInfinity . var-uinf
)
1893 ( Indeterminate . var-nan
)
1896 (put 'math
'math-vector-brackets
"{}")
1897 (put 'math
'math-complex-format
'I
)
1898 (put 'math
'math-function-open
"[")
1899 (put 'math
'math-function-close
"]")
1901 (put 'math
'math-radix-formatter
1902 (function (lambda (r s
) (format "%d^^%s" r s
))))
1904 (put 'math
'math-lang-read
1905 '((eq (string-match "\\[\\[\\|->\\|:>" math-exp-str math-exp-pos
)
1907 (setq math-exp-token
'punc
1908 math-expr-data
(math-match-substring math-exp-str
0)
1909 math-exp-pos
(match-end 0))))
1911 (put 'math
'math-compose-subscr
1915 (math-compose-expr (nth 1 a
) 1000)
1917 (math-compose-expr (nth 2 a
) 0)
1920 (defun math-read-math-subscr (x op
)
1921 (let ((idx (math-read-expr-level 0)))
1922 (or (and (equal math-expr-data
"]")
1925 (equal math-expr-data
"]")))
1926 (throw 'syntax
"Expected ']]'"))
1928 (list 'calcFunc-subscr x idx
)))
1931 (defun calc-maple-language ()
1934 (calc-set-language 'maple
)
1935 (message "Maple language mode")))
1937 (put 'maple
'math-oper-table
1938 '( ( "matrix" ident -
1 300 )
1939 ( "MATRIX" ident -
1 300 )
1940 ( "!" calcFunc-fact
210 -
1 )
1943 ( "u+" ident -
1 197 )
1947 ( "intersect" calcFunc-vint
191 192 )
1950 ( "union" calcFunc-vunion
180 181 )
1951 ( "minus" calcFunc-vdiff
180 181 )
1953 ( ".." (math-read-maple-dots) 165 165 )
1954 ( "\\dots" (math-read-maple-dots) 165 165 )
1955 ( "<" calcFunc-lt
160 160 )
1956 ( ">" calcFunc-gt
160 160 )
1957 ( "<=" calcFunc-leq
160 160 )
1958 ( ">=" calcFunc-geq
160 160 )
1959 ( "=" calcFunc-eq
160 160 )
1960 ( "<>" calcFunc-neq
160 160 )
1961 ( "not" calcFunc-lnot -
1 121 )
1962 ( "and" calcFunc-land
110 111 )
1963 ( "or" calcFunc-lor
100 101 )
1964 ( "!!!" calcFunc-pnot -
1 85 )
1965 ( "&&&" calcFunc-pand
80 81 )
1966 ( "|||" calcFunc-por
75 76 )
1967 ( ":=" calcFunc-assign
51 50 )
1968 ( "::" calcFunc-condition
45 46 )
1971 (put 'maple
'math-function-table
1972 '( ( bernoulli . calcFunc-bern
)
1973 ( binomial . calcFunc-choose
)
1974 ( diff . calcFunc-deriv
)
1975 ( GAMMA . calcFunc-gamma
)
1976 ( ifactor . calcFunc-prfac
)
1977 ( igcd . calcFunc-gcd
)
1978 ( ilcm . calcFunc-lcm
)
1979 ( int . calcFunc-integ
)
1982 ( iquo . calcFunc-idiv
)
1983 ( isprime . calcFunc-prime
)
1984 ( length . calcFunc-vlen
)
1985 ( member . calcFunc-in
)
1986 ( crossprod . calcFunc-cross
)
1987 ( inverse . calcFunc-inv
)
1988 ( trace . calcFunc-tr
)
1989 ( transpose . calcFunc-trn
)
1990 ( vectdim . calcFunc-vlen
)
1993 (put 'maple
'math-special-function-table
1994 '((intv . math-compose-maple-intv
)))
1996 (put 'maple
'math-variable-table
2000 ( infinity . var-inf
)
2001 ( infinity . var-uinf
)
2002 ( infinity . var-nan
)
2005 (put 'maple
'math-complex-format
'I
)
2007 (put 'maple
'math-matrix-formatter
2012 math-comp-left-bracket
2013 (math-compose-vector (cdr a
)
2014 (concat math-comp-comma
" ")
2015 math-comp-vector-prec
)
2016 math-comp-right-bracket
2019 (put 'maple
'math-compose-subscr
2022 (let ((args (cdr (cdr a
))))
2024 (math-compose-expr (nth 1 a
) 1000)
2026 (math-compose-vector args
", " 0)
2029 (add-to-list 'calc-lang-allow-underscores
'maple
)
2030 (add-to-list 'calc-lang-brackets-are-subscripts
'maple
)
2032 (defun math-compose-maple-intv (a)
2034 (math-compose-expr (nth 2 a
) 0)
2036 (math-compose-expr (nth 3 a
) 0)))
2038 (defun math-read-maple-dots (x op
)
2039 (list 'intv
3 x
(math-read-expr-level (nth 3 op
))))
2042 ;; The variable math-read-big-lines is local to math-read-big-expr in
2043 ;; calc-ext.el, but is used by math-read-big-rec, math-read-big-char,
2044 ;; math-read-big-emptyp, math-read-big-error and math-read-big-balance,
2045 ;; which are called (directly and indirectly) by math-read-big-expr.
2046 ;; It is also local to math-read-big-bigp in calc-ext.el, which calls
2047 ;; math-read-big-balance.
2048 (defvar math-read-big-lines
)
2050 ;; The variables math-read-big-baseline and math-read-big-h2 are
2051 ;; local to math-read-big-expr in calc-ext.el, but used by
2052 ;; math-read-big-rec.
2053 (defvar math-read-big-baseline
)
2054 (defvar math-read-big-h2
)
2056 ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2
2057 ;; are local to math-read-big-rec, but are used by math-read-big-char,
2058 ;; math-read-big-emptyp and math-read-big-balance which are called by
2059 ;; math-read-big-rec.
2060 ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el,
2061 ;; which calls math-read-big-balance.
2067 (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2
2068 &optional baseline prec short
)
2069 (or prec
(setq prec
0))
2071 ;; Clip whitespace above or below.
2072 (while (and (< math-rb-v1 math-rb-v2
)
2073 (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2
(1+ math-rb-v1
)))
2074 (setq math-rb-v1
(1+ math-rb-v1
)))
2075 (while (and (< math-rb-v1 math-rb-v2
)
2076 (math-read-big-emptyp math-rb-h1
(1- math-rb-v2
) math-rb-h2 math-rb-v2
))
2077 (setq math-rb-v2
(1- math-rb-v2
)))
2079 ;; If formula is a single line high, normal parser can handle it.
2080 (if (<= math-rb-v2
(1+ math-rb-v1
))
2081 (if (or (<= math-rb-v2 math-rb-v1
)
2082 (> math-rb-h1
(length (setq math-rb-v2
2083 (nth math-rb-v1 math-read-big-lines
)))))
2084 (math-read-big-error math-rb-h1 math-rb-v1
)
2085 (setq math-read-big-baseline math-rb-v1
2086 math-read-big-h2 math-rb-h2
2087 math-rb-v2
(nth math-rb-v1 math-read-big-lines
)
2088 math-rb-h2
(math-read-expr
2089 (substring math-rb-v2 math-rb-h1
2090 (min math-rb-h2
(length math-rb-v2
)))))
2091 (if (eq (car-safe math-rb-h2
) 'error
)
2092 (math-read-big-error (+ math-rb-h1
(nth 1 math-rb-h2
))
2093 math-rb-v1
(nth 2 math-rb-h2
))
2096 ;; Clip whitespace at left or right.
2097 (while (and (< math-rb-h1 math-rb-h2
)
2098 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) math-rb-v2
))
2099 (setq math-rb-h1
(1+ math-rb-h1
)))
2100 (while (and (< math-rb-h1 math-rb-h2
)
2101 (math-read-big-emptyp (1- math-rb-h2
) math-rb-v1 math-rb-h2 math-rb-v2
))
2102 (setq math-rb-h2
(1- math-rb-h2
)))
2104 ;; Scan to find widest left-justified "----" in the region.
2107 (lines-v1 (nthcdr math-rb-v1 math-read-big-lines
))
2111 other-char line len h
)
2112 (while (< v math-rb-v2
)
2114 len
(min math-rb-h2
(length line
)))
2115 (and (< math-rb-h1 len
)
2116 (/= (aref line math-rb-h1
) ?\
)
2117 (if (and (= (aref line math-rb-h1
) ?\-
)
2118 ;; Make sure it's not a minus sign.
2119 (or (and (< (1+ math-rb-h1
) len
)
2120 (= (aref line
(1+ math-rb-h1
)) ?\-
))
2121 (/= (math-read-big-char math-rb-h1
(1- v
)) ?\
)
2122 (/= (math-read-big-char math-rb-h1
(1+ v
)) ?\
)))
2125 (while (and (< (setq h
(1+ h
)) len
)
2126 (= (aref line h
) ?\-
)))
2130 (or other-v
(setq other-v v other-char
(aref line math-rb-h1
)))))
2134 (cond ((not (setq v other-v
))
2135 (math-read-big-error math-rb-h1 math-rb-v1
)) ; Should never happen!
2141 (let ((num (math-read-big-rec math-rb-h1 math-rb-v1 h v
))
2142 (den (math-read-big-rec math-rb-h1
(1+ v
) h math-rb-v2
)))
2143 (setq p
(if (and (math-integerp num
) (math-integerp den
))
2144 (math-make-frac num den
)
2145 (list '/ num den
)))))
2147 ;; Big radical sign.
2149 (or (= (math-read-big-char (1+ math-rb-h1
) v
) ?\|
)
2150 (math-read-big-error (1+ math-rb-h1
) v
"Malformed root sign"))
2151 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2152 (while (= (math-read-big-char (1+ math-rb-h1
) (setq v
(1- v
))) ?\|
))
2153 (or (= (math-read-big-char (setq h
(+ math-rb-h1
2)) v
) ?\_
)
2154 (math-read-big-error h v
"Malformed root sign"))
2155 (while (= (math-read-big-char (setq h
(1+ h
)) v
) ?\_
))
2156 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2157 (math-read-big-emptyp math-rb-h1
(1+ other-v
) h math-rb-v2 nil t
)
2158 (setq p
(list 'calcFunc-sqrt
(math-read-big-rec
2159 (+ math-rb-h1
2) (1+ v
)
2160 h
(1+ other-v
) baseline
))
2161 v math-read-big-baseline
))
2163 ;; Small radical sign.
2164 ((and (= other-char ?V
)
2165 (= (math-read-big-char (1+ math-rb-h1
) (1- v
)) ?\_
))
2166 (setq h
(1+ math-rb-h1
))
2167 (math-read-big-emptyp math-rb-h1 math-rb-v1 h
(1- v
) nil t
)
2168 (math-read-big-emptyp math-rb-h1
(1+ v
) h math-rb-v2 nil t
)
2169 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2170 (while (= (math-read-big-char (setq h
(1+ h
)) (1- v
)) ?\_
))
2171 (setq p
(list 'calcFunc-sqrt
(math-read-big-rec
2172 (1+ math-rb-h1
) v h
(1+ v
) t
))
2173 v math-read-big-baseline
))
2175 ;; Binomial coefficient.
2176 ((and (= other-char ?\
()
2177 (= (math-read-big-char (1+ math-rb-h1
) v
) ?\
)
2178 (= (string-match "( *)" (nth v math-read-big-lines
)
2179 math-rb-h1
) math-rb-h1
))
2180 (setq h
(match-end 0))
2181 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2182 (math-read-big-emptyp math-rb-h1
(1+ v
) (1+ math-rb-h1
) math-rb-v2 nil t
)
2183 (math-read-big-emptyp (1- h
) math-rb-v1 h v nil t
)
2184 (math-read-big-emptyp (1- h
) (1+ v
) h math-rb-v2 nil t
)
2185 (setq p
(list 'calcFunc-choose
2186 (math-read-big-rec (1+ math-rb-h1
) math-rb-v1
(1- h
) v
)
2187 (math-read-big-rec (1+ math-rb-h1
) (1+ v
)
2188 (1- h
) math-rb-v2
))))
2192 (setq p
(list 'neg
(math-read-big-rec (1+ math-rb-h1
) math-rb-v1
2193 math-rb-h2 math-rb-v2 v
250 t
))
2194 v math-read-big-baseline
2195 h math-read-big-h2
))
2199 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2200 (math-read-big-emptyp math-rb-h1
(1+ v
) (1+ math-rb-h1
) math-rb-v2 nil t
)
2201 (setq h
(math-read-big-balance (1+ math-rb-h1
) v
"(" t
))
2202 (math-read-big-emptyp (1- h
) math-rb-v1 h v nil t
)
2203 (math-read-big-emptyp (1- h
) (1+ v
) h math-rb-v2 nil t
)
2204 (let ((sep (math-read-big-char (1- h
) v
))
2209 (math-read-big-error (1- h
) v
"Expected `)'"))
2211 (setq p
(math-read-big-rec
2212 (1+ math-rb-h1
) math-rb-v1
(1- h
) math-rb-v2 v
))
2213 (setq hmid
(math-read-big-balance h v
"(")
2215 (math-read-big-rec h math-rb-v1
(1- hmid
) math-rb-v2 v
))
2218 (setq p
(cons 'intv
(cons (if (= (math-read-big-char
2223 ((= (math-read-big-char (1- h
) v
) ?\
])
2224 (math-read-big-error (1- h
) v
"Expected `)'"))
2226 (or (and (math-realp (car p
)) (math-realp (nth 1 p
)))
2227 (math-read-big-error
2228 math-rb-h1 v
"Complex components must be real"))
2229 (setq p
(cons 'cplx p
)))
2231 (or (and (math-realp (car p
)) (math-anglep (nth 1 p
)))
2232 (math-read-big-error
2233 math-rb-h1 v
"Complex components must be real"))
2234 (setq p
(cons 'polar p
)))))))
2237 ((and (= other-char ?\
[)
2238 (or (= (math-read-big-char (setq h math-rb-h1
) (1+ v
)) ?\
[)
2239 (= (math-read-big-char (setq h
(1+ h
)) v
) ?\
[)
2240 (and (= (math-read-big-char h v
) ?\
)
2241 (= (math-read-big-char (setq h
(1+ h
)) v
) ?\
[)))
2242 (= (math-read-big-char h
(1+ v
)) ?\
[))
2243 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t
)
2249 (setq h
(math-read-big-balance (1+ hleft
) v
"["))
2252 (math-read-big-error hright v
"Expected `]'"))
2254 (setq p
(cons (math-read-big-rec
2255 hleft v h
(1+ v
)) p
))
2256 (and (memq (math-read-big-char h v
) '(?\ ?\
,))
2257 (= (math-read-big-char hleft
(1+ v
)) ?\
[)))
2259 (or (= hleft math-rb-h1
)
2261 (if (= (math-read-big-char h v
) ?\
)
2263 (and (= (math-read-big-char h v
) ?\
])
2265 (math-read-big-error (1- h
) v
"Expected `]'"))
2266 (if (= (math-read-big-char h vtop
) ?\
,)
2268 (math-read-big-emptyp math-rb-h1
(1+ v
) (1- h
) math-rb-v2 nil t
)
2269 (setq v
(+ vtop
(/ (- v vtop
) 2))
2270 p
(cons 'vec
(nreverse p
)))))
2274 (math-read-big-emptyp math-rb-h1 math-rb-v1
(1+ math-rb-h1
) v nil t
)
2275 (math-read-big-emptyp math-rb-h1
(1+ v
) (1+ math-rb-h1
) math-rb-v2 nil t
)
2279 (setq widest
(math-read-big-balance h v
"[" t
))
2280 (math-read-big-emptyp (1- h
) math-rb-v1 h v nil t
)
2281 (math-read-big-emptyp (1- h
) (1+ v
) h math-rb-v2 nil t
)
2282 (setq p
(cons (math-read-big-rec
2283 h math-rb-v1
(1- widest
) math-rb-v2 v
) p
)
2285 (= (math-read-big-char (1- h
) v
) ?\
,)))
2286 (setq widest
(math-read-big-char (1- h
) v
))
2287 (if (or (memq widest
'(?\
; ?\)))
2288 (and (eq widest ?\.
) (cdr p
)))
2289 (math-read-big-error (1- h
) v
"Expected `]'"))
2292 widest
(math-read-big-balance h v
"[")
2293 p
(nconc p
(list (math-read-big-rec
2294 h math-rb-v1
(1- widest
) math-rb-v2 v
)))
2296 p
(cons 'intv
(cons (if (= (math-read-big-char (1- h
) v
)
2300 (setq p
(cons 'vec
(nreverse p
)))))
2304 (setq line
(nth v math-read-big-lines
))
2305 (string-match ">" line math-rb-h1
)
2306 (setq h
(match-end 0))
2307 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t
)
2308 (math-read-big-emptyp math-rb-h1
(1+ v
) h math-rb-v2 nil t
)
2309 (setq p
(math-read-big-rec math-rb-h1 v h
(1+ v
) v
)))
2311 ;; Variable name or function call.
2312 ((or (and (>= other-char ?a
) (<= other-char ?z
))
2313 (and (>= other-char ?A
) (<= other-char ?Z
))
2314 (and (>= other-char ?α
) (<= other-char ?ω
))
2315 (and (>= other-char ?Α
) (<= other-char ?Ω
)))
2316 (setq line
(nth v math-read-big-lines
))
2317 (string-match "\\([a-zA-Zα-ωΑ-Ω'_]+\\) *" line math-rb-h1
)
2318 (setq h
(match-end 1)
2319 widest
(match-end 0)
2320 p
(math-match-substring line
1))
2321 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t
)
2322 (math-read-big-emptyp math-rb-h1
(1+ v
) h math-rb-v2 nil t
)
2323 (if (= (math-read-big-char widest v
) ?\
()
2325 (setq line
(if (string-match "-" p
)
2327 (intern (concat "calcFunc-" p
)))
2330 (math-read-big-emptyp widest math-rb-v1 h v nil t
)
2331 (math-read-big-emptyp widest
(1+ v
) h math-rb-v2 nil t
)
2333 (setq widest
(math-read-big-balance h v
"(" t
))
2334 (math-read-big-emptyp (1- h
) math-rb-v1 h v nil t
)
2335 (math-read-big-emptyp (1- h
) (1+ v
) h math-rb-v2 nil t
)
2336 (setq p
(cons (math-read-big-rec
2337 h math-rb-v1
(1- widest
) math-rb-v2 v
) p
)
2339 (= (math-read-big-char (1- h
) v
) ?\
,)))
2340 (or (= (math-read-big-char (1- h
) v
) ?\
))
2341 (math-read-big-error (1- h
) v
"Expected `)'"))
2342 (setq p
(cons line
(nreverse p
))))
2344 (intern (math-remove-dashes p
))
2345 (if (string-match "-" p
)
2347 (intern (concat "var-" p
)))))))
2351 (setq line
(nth v math-read-big-lines
))
2352 (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line math-rb-h1
) math-rb-h1
)
2353 (math-read-big-error h v
"Expected a number"))
2354 (setq h
(match-end 0)
2355 p
(math-read-number (math-match-substring line
0)))
2356 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t
)
2357 (math-read-big-emptyp math-rb-h1
(1+ v
) h math-rb-v2 nil t
)))
2359 ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2;
2363 (math-read-big-error math-rb-h1 v
"Inconsistent baseline in formula"))
2366 ;; Look for superscripts or subscripts.
2367 (setq line
(nth baseline math-read-big-lines
)
2368 len
(min math-rb-h2
(length line
))
2370 (while (and (< widest len
)
2371 (= (aref line widest
) ?\
))
2372 (setq widest
(1+ widest
)))
2373 (and (>= widest len
) (setq widest math-rb-h2
))
2374 (if (math-read-big-emptyp h v widest math-rb-v2
)
2375 (if (math-read-big-emptyp h math-rb-v1 widest v
)
2377 (setq p
(list '^ p
(math-read-big-rec h math-rb-v1 widest v
))
2379 (if (math-read-big-emptyp h math-rb-v1 widest v
)
2380 (setq p
(list 'calcFunc-subscr p
2381 (math-read-big-rec h v widest math-rb-v2
))
2384 ;; Look for an operator name and grab additional terms.
2385 (while (and (< h len
)
2386 (if (setq widest
(and (math-read-big-emptyp
2387 h math-rb-v1
(1+ h
) v
)
2388 (math-read-big-emptyp
2389 h
(1+ v
) (1+ h
) math-rb-v2
)
2390 (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h
)
2391 (assoc (math-match-substring line
0)
2392 (math-standard-ops))))
2393 (and (>= (nth 2 widest
) prec
)
2394 (setq h
(match-end 0)))
2395 (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h
)
2397 (setq widest
'("2x" * 196 195)))))
2398 (cond ((eq (nth 3 widest
) -
1)
2399 (setq p
(list (nth 1 widest
) p
)))
2400 ((equal (car widest
) "?")
2401 (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2
2402 math-rb-v2 baseline nil t
)))
2403 (or (= (math-read-big-char math-read-big-h2 baseline
) ?\
:)
2404 (math-read-big-error math-read-big-h2 baseline
"Expected `:'"))
2405 (setq p
(list (nth 1 widest
) p y
2407 (1+ math-read-big-h2
) math-rb-v1 math-rb-h2 math-rb-v2
2408 baseline
(nth 3 widest
) t
))
2409 h math-read-big-h2
)))
2411 (setq p
(list (nth 1 widest
) p
2412 (math-read-big-rec h math-rb-v1 math-rb-h2 math-rb-v2
2413 baseline
(nth 3 widest
) t
))
2414 h math-read-big-h2
))))
2416 ;; Return all relevant information to caller.
2417 (setq math-read-big-baseline baseline
2419 (or short
(= math-read-big-h2 math-rb-h2
)
2420 (math-read-big-error h baseline
))
2423 (defun math-read-big-char (h v
)
2424 (or (and (>= h math-rb-h1
)
2428 (let ((line (nth v math-read-big-lines
)))
2434 (defun math-read-big-emptyp (eh1 ev1 eh2 ev2
&optional what error
)
2435 (and (< ev1 math-rb-v1
) (setq ev1 math-rb-v1
))
2436 (and (< eh1 math-rb-h1
) (setq eh1 math-rb-h1
))
2437 (and (> ev2 math-rb-v2
) (setq ev2 math-rb-v2
))
2438 (and (> eh2 math-rb-h2
) (setq eh2 math-rb-h2
))
2439 (or what
(setq what ?\
))
2440 (let ((p (nthcdr ev1 math-read-big-lines
))
2442 (while (and (< ev1 ev2
)
2444 (setq h
(min eh2
(length (car p
))))
2445 (while (and (>= (setq h
(1- h
)) eh1
)
2446 (= (aref (car p
) h
) what
)))
2447 (and error
(>= h eh1
)
2448 (math-read-big-error h ev1
(if (stringp error
)
2450 "Whitespace expected")))
2456 ;; math-read-big-err-msg is local to math-read-big-expr in calc-ext.el,
2457 ;; but is used by math-read-big-error which is called (indirectly) by
2458 ;; math-read-big-expr.
2459 (defvar math-read-big-err-msg
)
2461 (defun math-read-big-error (h v
&optional msg
)
2463 (p math-read-big-lines
))
2465 (setq pos
(+ pos
1 (length (car p
)))
2468 (setq h
(+ pos
(min h
(length (car p
))))
2469 math-read-big-err-msg
(list 'error h
(or msg
"Syntax error")))
2470 (throw 'syntax nil
)))
2472 (defun math-read-big-balance (h v what
&optional commas
)
2473 (let* ((line (nth v math-read-big-lines
))
2474 (len (min math-rb-h2
(length line
)))
2479 (math-read-big-error nil v
(format "Unmatched `%s'" what
))
2481 (if (memq (aref line h
) '(?\
( ?\
[))
2482 (setq count
(1+ count
))
2483 (if (if (and commas
(= count
1))
2484 (or (memq (aref line h
) '(?\
) ?\
] ?\
, ?\
;))
2485 (and (eq (aref line h
) ?\.
)
2487 (eq (aref line
(1+ h
)) ?\.
)))
2488 (memq (aref line h
) '(?\
) ?\
])))
2489 (setq count
(1- count
))))
2493 (provide 'calc-lang
)
2499 ;;; calc-lang.el ends here