1 ;; Calculator for GNU Emacs, part II [calc-lang.el]
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 ;; Written by Dave Gillespie, daveg@synaptics.com.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
9 ;; accepts responsibility to anyone for the consequences of using it
10 ;; or for whether it serves any particular purpose or works at all,
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
12 ;; License for full details.
14 ;; Everyone is granted permission to copy, modify and redistribute
15 ;; GNU Emacs, but only under the conditions described in the
16 ;; GNU Emacs General Public License. A copy of this license is
17 ;; supposed to have been given to you along with GNU Emacs so you
18 ;; can know your rights and responsibilities. It should be in a
19 ;; file named COPYING. Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies.
24 ;; This file is autoloaded from calc-ext.el.
29 (defun calc-Need-calc-lang () nil)
32 ;;; Alternate entry/display languages.
34 (defun calc-set-language (lang &optional option no-refresh)
35 (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers)
36 math-expr-function-mapping (get lang 'math-function-table)
37 math-expr-variable-mapping (get lang 'math-variable-table)
38 calc-language-input-filter (get lang 'math-input-filter)
39 calc-language-output-filter (get lang 'math-output-filter)
40 calc-vector-brackets (or (get lang 'math-vector-brackets) "[]")
41 calc-complex-format (get lang 'math-complex-format)
42 calc-radix-formatter (get lang 'math-radix-formatter)
43 calc-function-open (or (get lang 'math-function-open) "(")
44 calc-function-close (or (get lang 'math-function-close) ")"))
46 (setq calc-language lang
47 calc-language-option option)
48 (calc-change-mode '(calc-language calc-language-option)
49 (list lang option) t))
52 (defun calc-normal-language ()
55 (calc-set-language nil)
56 (message "Normal language mode."))
59 (defun calc-flat-language ()
62 (calc-set-language 'flat)
63 (message "Flat language mode (all stack entries shown on one line)."))
66 (defun calc-big-language ()
69 (calc-set-language 'big)
70 (message "\"Big\" language mode."))
73 (defun calc-unformatted-language ()
76 (calc-set-language 'unform)
77 (message "Unformatted language mode."))
81 (defun calc-c-language ()
84 (calc-set-language 'c)
85 (message "`C' language mode."))
88 (put 'c 'math-oper-table
89 '( ( "u+" ident -1 1000 )
91 ( "u!" calcFunc-lnot -1 1000 )
92 ( "~" calcFunc-not -1 1000 )
98 ( "<<" calcFunc-lsh 170 171 )
99 ( ">>" calcFunc-rsh 170 171 )
100 ( "<" calcFunc-lt 160 161 )
101 ( ">" calcFunc-gt 160 161 )
102 ( "<=" calcFunc-leq 160 161 )
103 ( ">=" calcFunc-geq 160 161 )
104 ( "==" calcFunc-eq 150 151 )
105 ( "!=" calcFunc-neq 150 151 )
106 ( "&" calcFunc-and 140 141 )
107 ( "^" calcFunc-xor 131 130 )
108 ( "|" calcFunc-or 120 121 )
109 ( "&&" calcFunc-land 110 111 )
110 ( "||" calcFunc-lor 100 101 )
111 ( "?" (math-read-if) 91 90 )
112 ( "!!!" calcFunc-pnot -1 88 )
113 ( "&&&" calcFunc-pand 85 86 )
114 ( "|||" calcFunc-por 75 76 )
115 ( "=" calcFunc-assign 51 50 )
116 ( ":=" calcFunc-assign 51 50 )
117 ( "::" calcFunc-condition 45 46 )
118 )) ; should support full assignments
120 (put 'c 'math-function-table
121 '( ( acos . calcFunc-arccos )
122 ( acosh . calcFunc-arccosh )
123 ( asin . calcFunc-arcsin )
124 ( asinh . calcFunc-arcsinh )
125 ( atan . calcFunc-arctan )
126 ( atan2 . calcFunc-arctan2 )
127 ( atanh . calcFunc-arctanh )
130 (put 'c 'math-variable-table
135 (put 'c 'math-vector-brackets "{}")
137 (put 'c 'math-radix-formatter
138 (function (lambda (r s)
139 (if (= r 16) (format "0x%s" s)
140 (if (= r 8) (format "0%s" s)
141 (format "%d#%s" r s))))))
144 (defun calc-pascal-language (n)
147 (and n (setq n (prefix-numeric-value n)))
148 (calc-set-language 'pascal n)
149 (message (if (and n (/= n 0))
151 "Pascal language mode (all uppercase)."
152 "Pascal language mode (all lowercase).")
153 "Pascal language mode.")))
156 (put 'pascal 'math-oper-table
157 '( ( "not" calcFunc-lnot -1 1000 )
160 ( "and" calcFunc-and 190 191 )
161 ( "div" calcFunc-idiv 190 191 )
163 ( "u+" ident -1 185 )
167 ( "or" calcFunc-or 180 181 )
168 ( "xor" calcFunc-xor 180 181 )
169 ( "shl" calcFunc-lsh 180 181 )
170 ( "shr" calcFunc-rsh 180 181 )
171 ( "in" calcFunc-in 160 161 )
172 ( "<" calcFunc-lt 160 161 )
173 ( ">" calcFunc-gt 160 161 )
174 ( "<=" calcFunc-leq 160 161 )
175 ( ">=" calcFunc-geq 160 161 )
176 ( "=" calcFunc-eq 160 161 )
177 ( "<>" calcFunc-neq 160 161 )
178 ( "!!!" calcFunc-pnot -1 85 )
179 ( "&&&" calcFunc-pand 80 81 )
180 ( "|||" calcFunc-por 75 76 )
181 ( ":=" calcFunc-assign 51 50 )
182 ( "::" calcFunc-condition 45 46 )
185 (put 'pascal 'math-input-filter 'calc-input-case-filter)
186 (put 'pascal 'math-output-filter 'calc-output-case-filter)
188 (put 'pascal 'math-radix-formatter
189 (function (lambda (r s)
190 (if (= r 16) (format "$%s" s)
191 (format "%d#%s" r s)))))
193 (defun calc-input-case-filter (str)
194 (cond ((or (null calc-language-option) (= calc-language-option 0))
200 (defun calc-output-case-filter (str)
201 (cond ((or (null calc-language-option) (= calc-language-option 0))
203 ((> calc-language-option 0)
210 (defun calc-fortran-language (n)
213 (and n (setq n (prefix-numeric-value n)))
214 (calc-set-language 'fortran n)
215 (message (if (and n (/= n 0))
217 "FORTRAN language mode (all uppercase)."
218 "FORTRAN language mode (all lowercase).")
219 "FORTRAN language mode.")))
222 (put 'fortran 'math-oper-table
223 '( ( "u/" (math-parse-fortran-vector) -1 1 )
224 ( "/" (math-parse-fortran-vector-end) 1 -1 )
226 ( "u+" ident -1 191 )
232 ( ".LT." calcFunc-lt 160 161 )
233 ( ".GT." calcFunc-gt 160 161 )
234 ( ".LE." calcFunc-leq 160 161 )
235 ( ".GE." calcFunc-geq 160 161 )
236 ( ".EQ." calcFunc-eq 160 161 )
237 ( ".NE." calcFunc-neq 160 161 )
238 ( ".NOT." calcFunc-lnot -1 121 )
239 ( ".AND." calcFunc-land 110 111 )
240 ( ".OR." calcFunc-lor 100 101 )
241 ( "!!!" calcFunc-pnot -1 85 )
242 ( "&&&" calcFunc-pand 80 81 )
243 ( "|||" calcFunc-por 75 76 )
244 ( "=" calcFunc-assign 51 50 )
245 ( ":=" calcFunc-assign 51 50 )
246 ( "::" calcFunc-condition 45 46 )
249 (put 'fortran 'math-vector-brackets "//")
251 (put 'fortran 'math-function-table
252 '( ( acos . calcFunc-arccos )
253 ( acosh . calcFunc-arccosh )
254 ( aimag . calcFunc-im )
255 ( aint . calcFunc-ftrunc )
256 ( asin . calcFunc-arcsin )
257 ( asinh . calcFunc-arcsinh )
258 ( atan . calcFunc-arctan )
259 ( atan2 . calcFunc-arctan2 )
260 ( atanh . calcFunc-arctanh )
261 ( conjg . calcFunc-conj )
262 ( log . calcFunc-ln )
263 ( nint . calcFunc-round )
264 ( real . calcFunc-re )
267 (put 'fortran 'math-input-filter 'calc-input-case-filter)
268 (put 'fortran 'math-output-filter 'calc-output-case-filter)
270 (defun math-parse-fortran-vector (op)
271 (let ((math-parsing-fortran-vector '(end . "\000")))
273 (math-read-brackets t "]")
274 (setq exp-token (car math-parsing-fortran-vector)
275 exp-data (cdr math-parsing-fortran-vector))))
278 (defun math-parse-fortran-vector-end (x op)
279 (if math-parsing-fortran-vector
281 (setq math-parsing-fortran-vector (cons exp-token exp-data)
285 (throw 'syntax "Unmatched closing `/'"))
287 (setq math-parsing-fortran-vector nil)
289 (defun math-parse-fortran-subscr (sym args)
290 (setq sym (math-build-var-name sym))
292 (setq sym (list 'calcFunc-subscr sym (car args))
298 (defun calc-tex-language (n)
301 (and n (setq n (prefix-numeric-value n)))
302 (calc-set-language 'tex n)
303 (message (if (and n (/= n 0))
305 "TeX language mode with \\hbox{func}(\\hbox{var})."
306 "TeX language mode with \\func{\\hbox{var}}.")
307 "TeX language mode.")))
310 (put 'tex 'math-oper-table
311 '( ( "u+" ident -1 1000 )
313 ( "\\hat" calcFunc-hat -1 950 )
314 ( "\\check" calcFunc-check -1 950 )
315 ( "\\tilde" calcFunc-tilde -1 950 )
316 ( "\\acute" calcFunc-acute -1 950 )
317 ( "\\grave" calcFunc-grave -1 950 )
318 ( "\\dot" calcFunc-dot -1 950 )
319 ( "\\ddot" calcFunc-dotdot -1 950 )
320 ( "\\breve" calcFunc-breve -1 950 )
321 ( "\\bar" calcFunc-bar -1 950 )
322 ( "\\vec" calcFunc-Vec -1 950 )
323 ( "\\underline" calcFunc-under -1 950 )
324 ( "u|" calcFunc-abs -1 0 )
326 ( "\\lfloor" calcFunc-floor -1 0 )
327 ( "\\rfloor" closing 0 -1 )
328 ( "\\lceil" calcFunc-ceil -1 0 )
329 ( "\\rceil" closing 0 -1 )
330 ( "\\pm" sdev 300 300 )
331 ( "!" calcFunc-fact 210 -1 )
333 ( "_" calcFunc-subscr 201 200 )
334 ( "\\times" * 191 190 )
339 ( "\\over" / 170 171 )
341 ( "\\choose" calcFunc-choose 170 171 )
342 ( "\\mod" % 170 171 )
343 ( "<" calcFunc-lt 160 161 )
344 ( ">" calcFunc-gt 160 161 )
345 ( "\\leq" calcFunc-leq 160 161 )
346 ( "\\geq" calcFunc-geq 160 161 )
347 ( "=" calcFunc-eq 160 161 )
348 ( "\\neq" calcFunc-neq 160 161 )
349 ( "\\ne" calcFunc-neq 160 161 )
350 ( "\\lnot" calcFunc-lnot -1 121 )
351 ( "\\land" calcFunc-land 110 111 )
352 ( "\\lor" calcFunc-lor 100 101 )
353 ( "?" (math-read-if) 91 90 )
354 ( "!!!" calcFunc-pnot -1 85 )
355 ( "&&&" calcFunc-pand 80 81 )
356 ( "|||" calcFunc-por 75 76 )
357 ( "\\gets" calcFunc-assign 51 50 )
358 ( ":=" calcFunc-assign 51 50 )
359 ( "::" calcFunc-condition 45 46 )
360 ( "\\to" calcFunc-evalto 40 41 )
361 ( "\\to" calcFunc-evalto 40 -1 )
362 ( "=>" calcFunc-evalto 40 41 )
363 ( "=>" calcFunc-evalto 40 -1 )
366 (put 'tex 'math-function-table
367 '( ( \\arccos . calcFunc-arccos )
368 ( \\arcsin . calcFunc-arcsin )
369 ( \\arctan . calcFunc-arctan )
370 ( \\arg . calcFunc-arg )
371 ( \\cos . calcFunc-cos )
372 ( \\cosh . calcFunc-cosh )
373 ( \\det . calcFunc-det )
374 ( \\exp . calcFunc-exp )
375 ( \\gcd . calcFunc-gcd )
376 ( \\ln . calcFunc-ln )
377 ( \\log . calcFunc-log10 )
378 ( \\max . calcFunc-max )
379 ( \\min . calcFunc-min )
380 ( \\tan . calcFunc-tan )
381 ( \\sin . calcFunc-sin )
382 ( \\sinh . calcFunc-sinh )
383 ( \\sqrt . calcFunc-sqrt )
384 ( \\tanh . calcFunc-tanh )
385 ( \\phi . calcFunc-totient )
386 ( \\mu . calcFunc-moebius )
389 (put 'tex 'math-variable-table
391 ( \\infty . var-inf )
392 ( \\infty . var-uinf )
394 ( \\gamma . var-gamma )
395 ( \\sum . (math-parse-tex-sum calcFunc-sum) )
396 ( \\prod . (math-parse-tex-sum calcFunc-prod) )
399 (put 'tex 'math-complex-format 'i)
401 (defun math-parse-tex-sum (f val)
403 (or (equal exp-data "_") (throw 'syntax "Expected `_'"))
405 (setq save exp-old-pos)
406 (setq low (math-read-factor))
407 (or (eq (car-safe low) 'calcFunc-eq)
409 (setq exp-old-pos (1+ save))
410 (throw 'syntax "Expected equation")))
411 (or (equal exp-data "^") (throw 'syntax "Expected `^'"))
413 (setq high (math-read-factor))
414 (list (nth 2 f) (math-read-factor) (nth 1 low) (nth 2 low) high))
417 (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789.
418 (while (string-match "[0-9]\\\\,[0-9]" str)
419 (setq str (concat (substring str 0 (1+ (match-beginning 0)))
420 (substring str (1- (match-end 0))))))
423 (put 'tex 'math-input-filter 'math-tex-input-filter)
426 (defun calc-eqn-language (n)
429 (calc-set-language 'eqn)
430 (message "Eqn language mode."))
433 (put 'eqn 'math-oper-table
434 '( ( "u+" ident -1 1000 )
436 ( "prime" (math-parse-eqn-prime) 950 -1 )
437 ( "prime" calcFunc-Prime 950 -1 )
438 ( "dot" calcFunc-dot 950 -1 )
439 ( "dotdot" calcFunc-dotdot 950 -1 )
440 ( "hat" calcFunc-hat 950 -1 )
441 ( "tilde" calcFunc-tilde 950 -1 )
442 ( "vec" calcFunc-Vec 950 -1 )
443 ( "dyad" calcFunc-dyad 950 -1 )
444 ( "bar" calcFunc-bar 950 -1 )
445 ( "under" calcFunc-under 950 -1 )
446 ( "sub" calcFunc-subscr 931 930 )
448 ( "sqrt" calcFunc-sqrt -1 910 )
450 ( "u|" calcFunc-abs -1 0 )
452 ( "left floor" calcFunc-floor -1 0 )
453 ( "right floor" closing 0 -1 )
454 ( "left ceil" calcFunc-ceil -1 0 )
455 ( "right ceil" closing 0 -1 )
456 ( "+-" sdev 300 300 )
457 ( "!" calcFunc-fact 210 -1 )
458 ( "times" * 191 190 )
465 ( "<" calcFunc-lt 160 161 )
466 ( ">" calcFunc-gt 160 161 )
467 ( "<=" calcFunc-leq 160 161 )
468 ( ">=" calcFunc-geq 160 161 )
469 ( "=" calcFunc-eq 160 161 )
470 ( "==" calcFunc-eq 160 161 )
471 ( "!=" calcFunc-neq 160 161 )
472 ( "u!" calcFunc-lnot -1 121 )
473 ( "&&" calcFunc-land 110 111 )
474 ( "||" calcFunc-lor 100 101 )
475 ( "?" (math-read-if) 91 90 )
476 ( "!!!" calcFunc-pnot -1 85 )
477 ( "&&&" calcFunc-pand 80 81 )
478 ( "|||" calcFunc-por 75 76 )
479 ( "<-" calcFunc-assign 51 50 )
480 ( ":=" calcFunc-assign 51 50 )
481 ( "::" calcFunc-condition 45 46 )
482 ( "->" calcFunc-evalto 40 41 )
483 ( "->" calcFunc-evalto 40 -1 )
484 ( "=>" calcFunc-evalto 40 41 )
485 ( "=>" calcFunc-evalto 40 -1 )
488 (put 'eqn 'math-function-table
489 '( ( arc\ cos . calcFunc-arccos )
490 ( arc\ cosh . calcFunc-arccosh )
491 ( arc\ sin . calcFunc-arcsin )
492 ( arc\ sinh . calcFunc-arcsinh )
493 ( arc\ tan . calcFunc-arctan )
494 ( arc\ tanh . calcFunc-arctanh )
495 ( GAMMA . calcFunc-gamma )
496 ( phi . calcFunc-totient )
497 ( mu . calcFunc-moebius )
498 ( matrix . (math-parse-eqn-matrix) )
501 (put 'eqn 'math-variable-table
502 '( ( inf . var-uinf )
505 (put 'eqn 'math-complex-format 'i)
507 (defun math-parse-eqn-matrix (f sym)
509 (while (assoc exp-data '(("ccol") ("lcol") ("rcol")))
511 (or (equal exp-data calc-function-open)
512 (throw 'syntax "Expected `{'"))
514 (setq vec (cons (cons 'vec (math-read-expr-list)) vec))
515 (or (equal exp-data calc-function-close)
516 (throw 'syntax "Expected `}'"))
518 (or (equal exp-data calc-function-close)
519 (throw 'syntax "Expected `}'"))
521 (math-transpose (cons 'vec (nreverse vec))))
524 (defun math-parse-eqn-prime (x sym)
525 (if (eq (car-safe x) 'var)
526 (if (equal exp-data calc-function-open)
529 (let ((args (if (or (equal exp-data calc-function-close)
532 (math-read-expr-list))))
533 (if (not (or (equal exp-data calc-function-close)
534 (eq exp-token 'end)))
535 (throw 'syntax "Expected `)'"))
537 (cons (intern (format "calcFunc-%s'" (nth 1 x))) args)))
539 (intern (concat (symbol-name (nth 1 x)) "'"))
540 (intern (concat (symbol-name (nth 2 x)) "'"))))
541 (list 'calcFunc-Prime x))
545 (defun calc-mathematica-language ()
548 (calc-set-language 'math)
549 (message "Mathematica language mode."))
552 (put 'math 'math-oper-table
553 '( ( "[[" (math-read-math-subscr) 250 -1 )
554 ( "!" calcFunc-fact 210 -1 )
555 ( "!!" calcFunc-dfact 210 -1 )
557 ( "u+" ident -1 197 )
564 ( "<" calcFunc-lt 160 161 )
565 ( ">" calcFunc-gt 160 161 )
566 ( "<=" calcFunc-leq 160 161 )
567 ( ">=" calcFunc-geq 160 161 )
568 ( "==" calcFunc-eq 150 151 )
569 ( "!=" calcFunc-neq 150 151 )
570 ( "u!" calcFunc-lnot -1 121 )
571 ( "&&" calcFunc-land 110 111 )
572 ( "||" calcFunc-lor 100 101 )
573 ( "!!!" calcFunc-pnot -1 85 )
574 ( "&&&" calcFunc-pand 80 81 )
575 ( "|||" calcFunc-por 75 76 )
576 ( ":=" calcFunc-assign 51 50 )
577 ( "=" calcFunc-assign 51 50 )
578 ( "->" calcFunc-assign 51 50 )
579 ( ":>" calcFunc-assign 51 50 )
580 ( "::" calcFunc-condition 45 46 )
583 (put 'math 'math-function-table
584 '( ( Abs . calcFunc-abs )
585 ( ArcCos . calcFunc-arccos )
586 ( ArcCosh . calcFunc-arccosh )
587 ( ArcSin . calcFunc-arcsin )
588 ( ArcSinh . calcFunc-arcsinh )
589 ( ArcTan . calcFunc-arctan )
590 ( ArcTanh . calcFunc-arctanh )
591 ( Arg . calcFunc-arg )
592 ( Binomial . calcFunc-choose )
593 ( Ceiling . calcFunc-ceil )
594 ( Conjugate . calcFunc-conj )
595 ( Cos . calcFunc-cos )
596 ( Cosh . calcFunc-cosh )
597 ( D . calcFunc-deriv )
598 ( Dt . calcFunc-tderiv )
599 ( Det . calcFunc-det )
600 ( Exp . calcFunc-exp )
601 ( EulerPhi . calcFunc-totient )
602 ( Floor . calcFunc-floor )
603 ( Gamma . calcFunc-gamma )
604 ( GCD . calcFunc-gcd )
607 ( Inverse . calcFunc-inv )
608 ( Integrate . calcFunc-integ )
609 ( Join . calcFunc-vconcat )
610 ( LCM . calcFunc-lcm )
611 ( Log . calcFunc-ln )
612 ( Max . calcFunc-max )
613 ( Min . calcFunc-min )
614 ( Mod . calcFunc-mod )
615 ( MoebiusMu . calcFunc-moebius )
616 ( Random . calcFunc-random )
617 ( Round . calcFunc-round )
619 ( Sign . calcFunc-sign )
620 ( Sin . calcFunc-sin )
621 ( Sinh . calcFunc-sinh )
622 ( Sqrt . calcFunc-sqrt )
623 ( Tan . calcFunc-tan )
624 ( Tanh . calcFunc-tanh )
625 ( Transpose . calcFunc-trn )
626 ( Length . calcFunc-vlen )
629 (put 'math 'math-variable-table
633 ( GoldenRatio . var-phi )
634 ( EulerGamma . var-gamma )
635 ( Infinity . var-inf )
636 ( ComplexInfinity . var-uinf )
637 ( Indeterminate . var-nan )
640 (put 'math 'math-vector-brackets "{}")
641 (put 'math 'math-complex-format 'I)
642 (put 'math 'math-function-open "[")
643 (put 'math 'math-function-close "]")
645 (put 'math 'math-radix-formatter
646 (function (lambda (r s) (format "%d^^%s" r s))))
648 (defun math-read-math-subscr (x op)
649 (let ((idx (math-read-expr-level 0)))
650 (or (and (equal exp-data "]")
653 (equal exp-data "]")))
654 (throw 'syntax "Expected ']]'"))
656 (list 'calcFunc-subscr x idx))
660 (defun calc-maple-language ()
663 (calc-set-language 'maple)
664 (message "Maple language mode."))
667 (put 'maple 'math-oper-table
668 '( ( "matrix" ident -1 300 )
669 ( "MATRIX" ident -1 300 )
670 ( "!" calcFunc-fact 210 -1 )
673 ( "u+" ident -1 197 )
677 ( "intersect" calcFunc-vint 191 192 )
680 ( "union" calcFunc-vunion 180 181 )
681 ( "minus" calcFunc-vdiff 180 181 )
683 ( ".." (math-read-maple-dots) 165 165 )
684 ( "\\dots" (math-read-maple-dots) 165 165 )
685 ( "<" calcFunc-lt 160 160 )
686 ( ">" calcFunc-gt 160 160 )
687 ( "<=" calcFunc-leq 160 160 )
688 ( ">=" calcFunc-geq 160 160 )
689 ( "=" calcFunc-eq 160 160 )
690 ( "<>" calcFunc-neq 160 160 )
691 ( "not" calcFunc-lnot -1 121 )
692 ( "and" calcFunc-land 110 111 )
693 ( "or" calcFunc-lor 100 101 )
694 ( "!!!" calcFunc-pnot -1 85 )
695 ( "&&&" calcFunc-pand 80 81 )
696 ( "|||" calcFunc-por 75 76 )
697 ( ":=" calcFunc-assign 51 50 )
698 ( "::" calcFunc-condition 45 46 )
701 (put 'maple 'math-function-table
702 '( ( bernoulli . calcFunc-bern )
703 ( binomial . calcFunc-choose )
704 ( diff . calcFunc-deriv )
705 ( GAMMA . calcFunc-gamma )
706 ( ifactor . calcFunc-prfac )
707 ( igcd . calcFunc-gcd )
708 ( ilcm . calcFunc-lcm )
709 ( int . calcFunc-integ )
712 ( iquo . calcFunc-idiv )
713 ( isprime . calcFunc-prime )
714 ( length . calcFunc-vlen )
715 ( member . calcFunc-in )
716 ( crossprod . calcFunc-cross )
717 ( inverse . calcFunc-inv )
718 ( trace . calcFunc-tr )
719 ( transpose . calcFunc-trn )
720 ( vectdim . calcFunc-vlen )
723 (put 'maple 'math-variable-table
727 ( infinity . var-inf )
728 ( infinity . var-uinf )
729 ( infinity . var-nan )
732 (put 'maple 'math-complex-format 'I)
734 (defun math-read-maple-dots (x op)
735 (list 'intv 3 x (math-read-expr-level (nth 3 op)))
742 (defun math-read-big-rec (h1 v1 h2 v2 &optional baseline prec short)
743 (or prec (setq prec 0))
745 ;; Clip whitespace above or below.
746 (while (and (< v1 v2) (math-read-big-emptyp h1 v1 h2 (1+ v1)))
748 (while (and (< v1 v2) (math-read-big-emptyp h1 (1- v2) h2 v2))
751 ;; If formula is a single line high, normal parser can handle it.
754 (> h1 (length (setq v2 (nth v1 lines)))))
755 (math-read-big-error h1 v1)
756 (setq the-baseline v1
759 h2 (math-read-expr (substring v2 h1 (min h2 (length v2)))))
760 (if (eq (car-safe h2) 'error)
761 (math-read-big-error (+ h1 (nth 1 h2)) v1 (nth 2 h2))
764 ;; Clip whitespace at left or right.
765 (while (and (< h1 h2) (math-read-big-emptyp h1 v1 (1+ h1) v2))
767 (while (and (< h1 h2) (math-read-big-emptyp (1- h2) v1 h2 v2))
770 ;; Scan to find widest left-justified "----" in the region.
773 (lines-v1 (nthcdr v1 lines))
777 other-char line len h)
780 len (min h2 (length line)))
782 (/= (aref line h1) ?\ )
783 (if (and (= (aref line h1) ?\-)
784 ;; Make sure it's not a minus sign.
785 (or (and (< (1+ h1) len) (= (aref line (1+ h1)) ?\-))
786 (/= (math-read-big-char h1 (1- v)) ?\ )
787 (/= (math-read-big-char h1 (1+ v)) ?\ )))
790 (while (and (< (setq h (1+ h)) len)
791 (= (aref line h) ?\-)))
795 (or other-v (setq other-v v other-char (aref line h1)))))
799 (cond ((not (setq v other-v))
800 (math-read-big-error h1 v1)) ; Should never happen!
806 (let ((num (math-read-big-rec h1 v1 h v))
807 (den (math-read-big-rec h1 (1+ v) h v2)))
808 (setq p (if (and (math-integerp num) (math-integerp den))
809 (math-make-frac num den)
810 (list '/ num den)))))
814 (or (= (math-read-big-char (1+ h1) v) ?\|)
815 (math-read-big-error (1+ h1) v "Malformed root sign"))
816 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
817 (while (= (math-read-big-char (1+ h1) (setq v (1- v))) ?\|))
818 (or (= (math-read-big-char (setq h (+ h1 2)) v) ?\_)
819 (math-read-big-error h v "Malformed root sign"))
820 (while (= (math-read-big-char (setq h (1+ h)) v) ?\_))
821 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
822 (math-read-big-emptyp h1 (1+ other-v) h v2 nil t)
823 (setq p (list 'calcFunc-sqrt (math-read-big-rec
825 h (1+ other-v) baseline))
828 ;; Small radical sign.
829 ((and (= other-char ?V)
830 (= (math-read-big-char (1+ h1) (1- v)) ?\_))
832 (math-read-big-emptyp h1 v1 h (1- v) nil t)
833 (math-read-big-emptyp h1 (1+ v) h v2 nil t)
834 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
835 (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_))
836 (setq p (list 'calcFunc-sqrt (math-read-big-rec
837 (1+ h1) v h (1+ v) t))
840 ;; Binomial coefficient.
841 ((and (= other-char ?\()
842 (= (math-read-big-char (1+ h1) v) ?\ )
843 (= (string-match "( *)" (nth v lines) h1) h1))
844 (setq h (match-end 0))
845 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
846 (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t)
847 (math-read-big-emptyp (1- h) v1 h v nil t)
848 (math-read-big-emptyp (1- h) (1+ v) h v2 nil t)
849 (setq p (list 'calcFunc-choose
850 (math-read-big-rec (1+ h1) v1 (1- h) v)
851 (math-read-big-rec (1+ h1) (1+ v)
856 (setq p (list 'neg (math-read-big-rec (1+ h1) v1 h2 v2 v 250 t))
862 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
863 (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t)
864 (setq h (math-read-big-balance (1+ h1) v "(" t))
865 (math-read-big-emptyp (1- h) v1 h v nil t)
866 (math-read-big-emptyp (1- h) (1+ v) h v2 nil t)
867 (let ((sep (math-read-big-char (1- h) v))
872 (math-read-big-error (1- h) v "Expected `)'"))
874 (setq p (math-read-big-rec (1+ h1) v1 (1- h) v2 v))
875 (setq hmid (math-read-big-balance h v "(")
876 p (list p (math-read-big-rec h v1 (1- hmid) v2 v))
879 (setq p (cons 'intv (cons (if (= (math-read-big-char
884 ((= (math-read-big-char (1- h) v) ?\])
885 (math-read-big-error (1- h) v "Expected `)'"))
887 (or (and (math-realp (car p)) (math-realp (nth 1 p)))
889 h1 v "Complex components must be real"))
890 (setq p (cons 'cplx p)))
892 (or (and (math-realp (car p)) (math-anglep (nth 1 p)))
894 h1 v "Complex components must be real"))
895 (setq p (cons 'polar p)))))))
898 ((and (= other-char ?\[)
899 (or (= (math-read-big-char (setq h h1) (1+ v)) ?\[)
900 (= (math-read-big-char (setq h (1+ h)) v) ?\[)
901 (and (= (math-read-big-char h v) ?\ )
902 (= (math-read-big-char (setq h (1+ h)) v) ?\[)))
903 (= (math-read-big-char h (1+ v)) ?\[))
904 (math-read-big-emptyp h1 v1 h v nil t)
910 (setq h (math-read-big-balance (1+ hleft) v "["))
913 (math-read-big-error hright v "Expected `]'"))
915 (setq p (cons (math-read-big-rec
916 hleft v h (1+ v)) p))
917 (and (memq (math-read-big-char h v) '(?\ ?\,))
918 (= (math-read-big-char hleft (1+ v)) ?\[)))
922 (if (= (math-read-big-char h v) ?\ )
924 (and (= (math-read-big-char h v) ?\])
926 (math-read-big-error (1- h) v "Expected `]'"))
927 (if (= (math-read-big-char h vtop) ?\,)
929 (math-read-big-emptyp h1 (1+ v) (1- h) v2 nil t)
930 (setq v (+ vtop (/ (- v vtop) 2))
931 p (cons 'vec (nreverse p)))))
935 (math-read-big-emptyp h1 v1 (1+ h1) v nil t)
936 (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t)
940 (setq widest (math-read-big-balance h v "[" t))
941 (math-read-big-emptyp (1- h) v1 h v nil t)
942 (math-read-big-emptyp (1- h) (1+ v) h v2 nil t)
943 (setq p (cons (math-read-big-rec
944 h v1 (1- widest) v2 v) p)
946 (= (math-read-big-char (1- h) v) ?\,)))
947 (setq widest (math-read-big-char (1- h) v))
948 (if (or (memq widest '(?\; ?\)))
949 (and (eq widest ?\.) (cdr p)))
950 (math-read-big-error (1- h) v "Expected `]'"))
953 widest (math-read-big-balance h v "[")
954 p (nconc p (list (math-read-big-big-rec
955 h v1 (1- widest) v2 v)))
957 p (cons 'intv (cons (if (= (math-read-big-char (1- h) v)
961 (setq p (cons 'vec (nreverse p)))))
965 (setq line (nth v lines))
966 (string-match ">" line h1)
967 (setq h (match-end 0))
968 (math-read-big-emptyp h1 v1 h v nil t)
969 (math-read-big-emptyp h1 (1+ v) h v2 nil t)
970 (setq p (math-read-big-rec h1 v h (1+ v) v)))
972 ;; Variable name or function call.
973 ((or (and (>= other-char ?a) (<= other-char ?z))
974 (and (>= other-char ?A) (<= other-char ?Z)))
975 (setq line (nth v lines))
976 (string-match "\\([a-zA-Z'_]+\\) *" line h1)
977 (setq h (match-end 1)
979 p (math-match-substring line 1))
980 (math-read-big-emptyp h1 v1 h v nil t)
981 (math-read-big-emptyp h1 (1+ v) h v2 nil t)
982 (if (= (math-read-big-char widest v) ?\()
984 (setq line (if (string-match "-" p)
986 (intern (concat "calcFunc-" p)))
989 (math-read-big-emptyp widest v1 h v nil t)
990 (math-read-big-emptyp widest (1+ v) h v2 nil t)
992 (setq widest (math-read-big-balance h v "(" t))
993 (math-read-big-emptyp (1- h) v1 h v nil t)
994 (math-read-big-emptyp (1- h) (1+ v) h v2 nil t)
995 (setq p (cons (math-read-big-rec
996 h v1 (1- widest) v2 v) p)
998 (= (math-read-big-char (1- h) v) ?\,)))
999 (or (= (math-read-big-char (1- h) v) ?\))
1000 (math-read-big-error (1- h) v "Expected `)'"))
1001 (setq p (cons line (nreverse p))))
1003 (intern (math-remove-dashes p))
1004 (if (string-match "-" p)
1006 (intern (concat "var-" p)))))))
1010 (setq line (nth v lines))
1011 (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 h1) h1)
1012 (math-read-big-error h v "Expected a number"))
1013 (setq h (match-end 0)
1014 p (math-read-number (math-match-substring line 0)))
1015 (math-read-big-emptyp h1 v1 h v nil t)
1016 (math-read-big-emptyp h1 (1+ v) h v2 nil t)))
1018 ;; Now left term is bounded by h1, v1, h, v2; baseline = v.
1021 (math-read-big-error h1 v "Inconsistent baseline in formula"))
1024 ;; Look for superscripts or subscripts.
1025 (setq line (nth baseline lines)
1026 len (min h2 (length line))
1028 (while (and (< widest len)
1029 (= (aref line widest) ?\ ))
1030 (setq widest (1+ widest)))
1031 (and (>= widest len) (setq widest h2))
1032 (if (math-read-big-emptyp h v widest v2)
1033 (if (math-read-big-emptyp h v1 widest v)
1035 (setq p (list '^ p (math-read-big-rec h v1 widest v))
1037 (if (math-read-big-emptyp h v1 widest v)
1038 (setq p (list 'calcFunc-subscr p
1039 (math-read-big-rec h v widest v2))
1042 ;; Look for an operator name and grab additional terms.
1043 (while (and (< h len)
1044 (if (setq widest (and (math-read-big-emptyp
1046 (math-read-big-emptyp
1048 (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h)
1049 (assoc (math-match-substring line 0)
1050 math-standard-opers)))
1051 (and (>= (nth 2 widest) prec)
1052 (setq h (match-end 0)))
1053 (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h)
1055 (setq widest '("2x" * 196 195)))))
1056 (cond ((eq (nth 3 widest) -1)
1057 (setq p (list (nth 1 widest) p)))
1058 ((equal (car widest) "?")
1059 (let ((y (math-read-big-rec h v1 h2 v2 baseline nil t)))
1060 (or (= (math-read-big-char the-h2 baseline) ?\:)
1061 (math-read-big-error the-h2 baseline "Expected `:'"))
1062 (setq p (list (nth 1 widest) p y
1063 (math-read-big-rec (1+ the-h2) v1 h2 v2
1064 baseline (nth 3 widest) t))
1067 (setq p (list (nth 1 widest) p
1068 (math-read-big-rec h v1 h2 v2
1069 baseline (nth 3 widest) t))
1072 ;; Return all relevant information to caller.
1073 (setq the-baseline baseline
1075 (or short (= the-h2 h2)
1076 (math-read-big-error h baseline))
1080 (defun math-read-big-char (h v)
1085 (let ((line (nth v lines)))
1092 (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error)
1093 (and (< ev1 v1) (setq ev1 v1))
1094 (and (< eh1 h1) (setq eh1 h1))
1095 (and (> ev2 v2) (setq ev2 v2))
1096 (and (> eh2 h2) (setq eh2 h2))
1097 (or what (setq what ?\ ))
1098 (let ((p (nthcdr ev1 lines))
1100 (while (and (< ev1 ev2)
1102 (setq h (min eh2 (length (car p))))
1103 (while (and (>= (setq h (1- h)) eh1)
1104 (= (aref (car p) h) what)))
1105 (and error (>= h eh1)
1106 (math-read-big-error h ev1 (if (stringp error)
1108 "Whitespace expected")))
1115 (defun math-read-big-error (h v &optional msg)
1119 (setq pos (+ pos 1 (length (car p)))
1122 (setq h (+ pos (min h (length (car p))))
1123 err-msg (list 'error h (or msg "Syntax error")))
1124 (throw 'syntax nil))
1127 (defun math-read-big-balance (h v what &optional commas)
1128 (let* ((line (nth v lines))
1129 (len (min h2 (length line)))
1134 (math-read-big-error h1 v (format "Unmatched `%s'" what))
1136 (if (memq (aref line h) '(?\( ?\[))
1137 (setq count (1+ count))
1138 (if (if (and commas (= count 1))
1139 (or (memq (aref line h) '(?\) ?\] ?\, ?\;))
1140 (and (eq (aref line h) ?\.)
1142 (eq (aref line (1+ h)) ?\.)))
1143 (memq (aref line h) '(?\) ?\])))
1144 (setq count (1- count))))