1 ;;; calc-lang.el --- calc language functions
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainers: D. Goel <deego@gnufans.org>
7 ;; Colin Walters <walters@debian.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
13 ;; accepts responsibility to anyone for the consequences of using it
14 ;; or for whether it serves any particular purpose or works at all,
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
16 ;; License for full details.
18 ;; Everyone is granted permission to copy, modify and redistribute
19 ;; GNU Emacs, but only under the conditions described in the
20 ;; GNU Emacs General Public License. A copy of this license is
21 ;; supposed to have been given to you along with GNU Emacs so you
22 ;; can know your rights and responsibilities. It should be in a
23 ;; file named COPYING. Among other things, the copyright notice
24 ;; and this notice must be preserved on all copies.
31 ;; This file is autoloaded from calc-ext.el.
36 (defun calc-Need-calc-lang () nil
)
39 ;;; Alternate entry/display languages.
41 (defun calc-set-language (lang &optional option no-refresh
)
42 (setq math-expr-opers
(or (get lang
'math-oper-table
) math-standard-opers
)
43 math-expr-function-mapping
(get lang
'math-function-table
)
44 math-expr-variable-mapping
(get lang
'math-variable-table
)
45 calc-language-input-filter
(get lang
'math-input-filter
)
46 calc-language-output-filter
(get lang
'math-output-filter
)
47 calc-vector-brackets
(or (get lang
'math-vector-brackets
) "[]")
48 calc-complex-format
(get lang
'math-complex-format
)
49 calc-radix-formatter
(get lang
'math-radix-formatter
)
50 calc-function-open
(or (get lang
'math-function-open
) "(")
51 calc-function-close
(or (get lang
'math-function-close
) ")"))
53 (setq calc-language lang
54 calc-language-option option
)
55 (calc-change-mode '(calc-language calc-language-option
)
56 (list lang option
) t
)))
58 (defun calc-normal-language ()
61 (calc-set-language nil
)
62 (message "Normal language mode")))
64 (defun calc-flat-language ()
67 (calc-set-language 'flat
)
68 (message "Flat language mode (all stack entries shown on one line)")))
70 (defun calc-big-language ()
73 (calc-set-language 'big
)
74 (message "\"Big\" language mode")))
76 (defun calc-unformatted-language ()
79 (calc-set-language 'unform
)
80 (message "Unformatted language mode")))
83 (defun calc-c-language ()
86 (calc-set-language 'c
)
87 (message "`C' language mode")))
89 (put 'c
'math-oper-table
90 '( ( "u+" ident -
1 1000 )
92 ( "u!" calcFunc-lnot -
1 1000 )
93 ( "~" calcFunc-not -
1 1000 )
99 ( "<<" calcFunc-lsh
170 171 )
100 ( ">>" calcFunc-rsh
170 171 )
101 ( "<" calcFunc-lt
160 161 )
102 ( ">" calcFunc-gt
160 161 )
103 ( "<=" calcFunc-leq
160 161 )
104 ( ">=" calcFunc-geq
160 161 )
105 ( "==" calcFunc-eq
150 151 )
106 ( "!=" calcFunc-neq
150 151 )
107 ( "&" calcFunc-and
140 141 )
108 ( "^" calcFunc-xor
131 130 )
109 ( "|" calcFunc-or
120 121 )
110 ( "&&" calcFunc-land
110 111 )
111 ( "||" calcFunc-lor
100 101 )
112 ( "?" (math-read-if) 91 90 )
113 ( "!!!" calcFunc-pnot -
1 88 )
114 ( "&&&" calcFunc-pand
85 86 )
115 ( "|||" calcFunc-por
75 76 )
116 ( "=" calcFunc-assign
51 50 )
117 ( ":=" calcFunc-assign
51 50 )
118 ( "::" calcFunc-condition
45 46 ))) ; 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
)))
129 (put 'c
'math-variable-table
133 (put 'c
'math-vector-brackets
"{}")
135 (put 'c
'math-radix-formatter
136 (function (lambda (r s
)
137 (if (= r
16) (format "0x%s" s
)
138 (if (= r
8) (format "0%s" s
)
139 (format "%d#%s" r s
))))))
142 (defun calc-pascal-language (n)
145 (and n
(setq n
(prefix-numeric-value n
)))
146 (calc-set-language 'pascal n
)
147 (message (if (and n
(/= n
0))
149 "Pascal language mode (all uppercase)"
150 "Pascal language mode (all lowercase)")
151 "Pascal language mode"))))
153 (put 'pascal
'math-oper-table
154 '( ( "not" calcFunc-lnot -
1 1000 )
157 ( "and" calcFunc-and
190 191 )
158 ( "div" calcFunc-idiv
190 191 )
160 ( "u+" ident -
1 185 )
164 ( "or" calcFunc-or
180 181 )
165 ( "xor" calcFunc-xor
180 181 )
166 ( "shl" calcFunc-lsh
180 181 )
167 ( "shr" calcFunc-rsh
180 181 )
168 ( "in" calcFunc-in
160 161 )
169 ( "<" calcFunc-lt
160 161 )
170 ( ">" calcFunc-gt
160 161 )
171 ( "<=" calcFunc-leq
160 161 )
172 ( ">=" calcFunc-geq
160 161 )
173 ( "=" calcFunc-eq
160 161 )
174 ( "<>" calcFunc-neq
160 161 )
175 ( "!!!" calcFunc-pnot -
1 85 )
176 ( "&&&" calcFunc-pand
80 81 )
177 ( "|||" calcFunc-por
75 76 )
178 ( ":=" calcFunc-assign
51 50 )
179 ( "::" calcFunc-condition
45 46 )))
181 (put 'pascal
'math-input-filter
'calc-input-case-filter
)
182 (put 'pascal
'math-output-filter
'calc-output-case-filter
)
184 (put 'pascal
'math-radix-formatter
185 (function (lambda (r s
)
186 (if (= r
16) (format "$%s" s
)
187 (format "%d#%s" r s
)))))
189 (defun calc-input-case-filter (str)
190 (cond ((or (null calc-language-option
) (= calc-language-option
0))
195 (defun calc-output-case-filter (str)
196 (cond ((or (null calc-language-option
) (= calc-language-option
0))
198 ((> calc-language-option
0)
204 (defun calc-fortran-language (n)
207 (and n
(setq n
(prefix-numeric-value n
)))
208 (calc-set-language 'fortran n
)
209 (message (if (and n
(/= n
0))
211 "FORTRAN language mode (all uppercase)"
212 "FORTRAN language mode (all lowercase)")
213 "FORTRAN language mode"))))
215 (put 'fortran
'math-oper-table
216 '( ( "u/" (math-parse-fortran-vector) -
1 1 )
217 ( "/" (math-parse-fortran-vector-end) 1 -
1 )
219 ( "u+" ident -
1 191 )
225 ( ".LT." calcFunc-lt
160 161 )
226 ( ".GT." calcFunc-gt
160 161 )
227 ( ".LE." calcFunc-leq
160 161 )
228 ( ".GE." calcFunc-geq
160 161 )
229 ( ".EQ." calcFunc-eq
160 161 )
230 ( ".NE." calcFunc-neq
160 161 )
231 ( ".NOT." calcFunc-lnot -
1 121 )
232 ( ".AND." calcFunc-land
110 111 )
233 ( ".OR." calcFunc-lor
100 101 )
234 ( "!!!" calcFunc-pnot -
1 85 )
235 ( "&&&" calcFunc-pand
80 81 )
236 ( "|||" calcFunc-por
75 76 )
237 ( "=" calcFunc-assign
51 50 )
238 ( ":=" calcFunc-assign
51 50 )
239 ( "::" calcFunc-condition
45 46 )))
241 (put 'fortran
'math-vector-brackets
"//")
243 (put 'fortran
'math-function-table
244 '( ( acos . calcFunc-arccos
)
245 ( acosh . calcFunc-arccosh
)
246 ( aimag . calcFunc-im
)
247 ( aint . calcFunc-ftrunc
)
248 ( asin . calcFunc-arcsin
)
249 ( asinh . calcFunc-arcsinh
)
250 ( atan . calcFunc-arctan
)
251 ( atan2 . calcFunc-arctan2
)
252 ( atanh . calcFunc-arctanh
)
253 ( conjg . calcFunc-conj
)
254 ( log . calcFunc-ln
)
255 ( nint . calcFunc-round
)
256 ( real . calcFunc-re
)))
258 (put 'fortran
'math-input-filter
'calc-input-case-filter
)
259 (put 'fortran
'math-output-filter
'calc-output-case-filter
)
261 (defvar math-parsing-fortran-vector nil
)
262 (defun math-parse-fortran-vector (op)
263 (let ((math-parsing-fortran-vector '(end .
"\000")))
265 (math-read-brackets t
"]")
266 (setq exp-token
(car math-parsing-fortran-vector
)
267 exp-data
(cdr math-parsing-fortran-vector
)))))
269 (defun math-parse-fortran-vector-end (x op
)
270 (if math-parsing-fortran-vector
272 (setq math-parsing-fortran-vector
(cons exp-token exp-data
)
276 (throw 'syntax
"Unmatched closing `/'")))
278 (defun math-parse-fortran-subscr (sym args
)
279 (setq sym
(math-build-var-name sym
))
281 (setq sym
(list 'calcFunc-subscr sym
(car args
))
286 (defun calc-tex-language (n)
289 (and n
(setq n
(prefix-numeric-value n
)))
290 (calc-set-language 'tex n
)
291 (message (if (and n
(/= n
0))
293 "TeX language mode with \\hbox{func}(\\hbox{var})"
294 "TeX language mode with \\func{\\hbox{var}}")
295 "TeX language mode"))))
297 (put 'tex
'math-oper-table
298 '( ( "u+" ident -
1 1000 )
300 ( "\\hat" calcFunc-hat -
1 950 )
301 ( "\\check" calcFunc-check -
1 950 )
302 ( "\\tilde" calcFunc-tilde -
1 950 )
303 ( "\\acute" calcFunc-acute -
1 950 )
304 ( "\\grave" calcFunc-grave -
1 950 )
305 ( "\\dot" calcFunc-dot -
1 950 )
306 ( "\\ddot" calcFunc-dotdot -
1 950 )
307 ( "\\breve" calcFunc-breve -
1 950 )
308 ( "\\bar" calcFunc-bar -
1 950 )
309 ( "\\vec" calcFunc-Vec -
1 950 )
310 ( "\\underline" calcFunc-under -
1 950 )
311 ( "u|" calcFunc-abs -
1 0 )
313 ( "\\lfloor" calcFunc-floor -
1 0 )
314 ( "\\rfloor" closing
0 -
1 )
315 ( "\\lceil" calcFunc-ceil -
1 0 )
316 ( "\\rceil" closing
0 -
1 )
317 ( "\\pm" sdev
300 300 )
318 ( "!" calcFunc-fact
210 -
1 )
320 ( "_" calcFunc-subscr
201 200 )
321 ( "\\times" * 191 190 )
326 ( "\\over" / 170 171 )
328 ( "\\choose" calcFunc-choose
170 171 )
329 ( "\\mod" %
170 171 )
330 ( "<" calcFunc-lt
160 161 )
331 ( ">" calcFunc-gt
160 161 )
332 ( "\\leq" calcFunc-leq
160 161 )
333 ( "\\geq" calcFunc-geq
160 161 )
334 ( "=" calcFunc-eq
160 161 )
335 ( "\\neq" calcFunc-neq
160 161 )
336 ( "\\ne" calcFunc-neq
160 161 )
337 ( "\\lnot" calcFunc-lnot -
1 121 )
338 ( "\\land" calcFunc-land
110 111 )
339 ( "\\lor" calcFunc-lor
100 101 )
340 ( "?" (math-read-if) 91 90 )
341 ( "!!!" calcFunc-pnot -
1 85 )
342 ( "&&&" calcFunc-pand
80 81 )
343 ( "|||" calcFunc-por
75 76 )
344 ( "\\gets" calcFunc-assign
51 50 )
345 ( ":=" calcFunc-assign
51 50 )
346 ( "::" calcFunc-condition
45 46 )
347 ( "\\to" calcFunc-evalto
40 41 )
348 ( "\\to" calcFunc-evalto
40 -
1 )
349 ( "=>" calcFunc-evalto
40 41 )
350 ( "=>" calcFunc-evalto
40 -
1 )))
352 (put 'tex
'math-function-table
353 '( ( \\arccos . calcFunc-arccos
)
354 ( \\arcsin . calcFunc-arcsin
)
355 ( \\arctan . calcFunc-arctan
)
356 ( \\arg . calcFunc-arg
)
357 ( \\cos . calcFunc-cos
)
358 ( \\cosh . calcFunc-cosh
)
359 ( \\det . calcFunc-det
)
360 ( \\exp . calcFunc-exp
)
361 ( \\gcd . calcFunc-gcd
)
362 ( \\ln . calcFunc-ln
)
363 ( \\log . calcFunc-log10
)
364 ( \\max . calcFunc-max
)
365 ( \\min . calcFunc-min
)
366 ( \\tan . calcFunc-tan
)
367 ( \\sin . calcFunc-sin
)
368 ( \\sinh . calcFunc-sinh
)
369 ( \\sqrt . calcFunc-sqrt
)
370 ( \\tanh . calcFunc-tanh
)
371 ( \\phi . calcFunc-totient
)
372 ( \\mu . calcFunc-moebius
)))
374 (put 'tex
'math-variable-table
376 ( \\infty . var-inf
)
377 ( \\infty . var-uinf
)
379 ( \\gamma . var-gamma
)
380 ( \\sum .
(math-parse-tex-sum calcFunc-sum
) )
381 ( \\prod .
(math-parse-tex-sum calcFunc-prod
) )))
383 (put 'tex
'math-complex-format
'i
)
385 (defun math-parse-tex-sum (f val
)
387 (or (equal exp-data
"_") (throw 'syntax
"Expected `_'"))
389 (setq save exp-old-pos
)
390 (setq low
(math-read-factor))
391 (or (eq (car-safe low
) 'calcFunc-eq
)
393 (setq exp-old-pos
(1+ save
))
394 (throw 'syntax
"Expected equation")))
395 (or (equal exp-data
"^") (throw 'syntax
"Expected `^'"))
397 (setq high
(math-read-factor))
398 (list (nth 2 f
) (math-read-factor) (nth 1 low
) (nth 2 low
) high
)))
400 (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789.
401 (while (string-match "[0-9]\\\\,[0-9]" str
)
402 (setq str
(concat (substring str
0 (1+ (match-beginning 0)))
403 (substring str
(1- (match-end 0))))))
405 (put 'tex
'math-input-filter
'math-tex-input-filter
)
408 (defun calc-eqn-language (n)
411 (calc-set-language 'eqn
)
412 (message "Eqn language mode")))
414 (put 'eqn
'math-oper-table
415 '( ( "u+" ident -
1 1000 )
417 ( "prime" (math-parse-eqn-prime) 950 -
1 )
418 ( "prime" calcFunc-Prime
950 -
1 )
419 ( "dot" calcFunc-dot
950 -
1 )
420 ( "dotdot" calcFunc-dotdot
950 -
1 )
421 ( "hat" calcFunc-hat
950 -
1 )
422 ( "tilde" calcFunc-tilde
950 -
1 )
423 ( "vec" calcFunc-Vec
950 -
1 )
424 ( "dyad" calcFunc-dyad
950 -
1 )
425 ( "bar" calcFunc-bar
950 -
1 )
426 ( "under" calcFunc-under
950 -
1 )
427 ( "sub" calcFunc-subscr
931 930 )
429 ( "sqrt" calcFunc-sqrt -
1 910 )
431 ( "u|" calcFunc-abs -
1 0 )
433 ( "left floor" calcFunc-floor -
1 0 )
434 ( "right floor" closing
0 -
1 )
435 ( "left ceil" calcFunc-ceil -
1 0 )
436 ( "right ceil" closing
0 -
1 )
437 ( "+-" sdev
300 300 )
438 ( "!" calcFunc-fact
210 -
1 )
439 ( "times" * 191 190 )
446 ( "<" calcFunc-lt
160 161 )
447 ( ">" calcFunc-gt
160 161 )
448 ( "<=" calcFunc-leq
160 161 )
449 ( ">=" calcFunc-geq
160 161 )
450 ( "=" calcFunc-eq
160 161 )
451 ( "==" calcFunc-eq
160 161 )
452 ( "!=" calcFunc-neq
160 161 )
453 ( "u!" calcFunc-lnot -
1 121 )
454 ( "&&" calcFunc-land
110 111 )
455 ( "||" calcFunc-lor
100 101 )
456 ( "?" (math-read-if) 91 90 )
457 ( "!!!" calcFunc-pnot -
1 85 )
458 ( "&&&" calcFunc-pand
80 81 )
459 ( "|||" calcFunc-por
75 76 )
460 ( "<-" calcFunc-assign
51 50 )
461 ( ":=" calcFunc-assign
51 50 )
462 ( "::" calcFunc-condition
45 46 )
463 ( "->" calcFunc-evalto
40 41 )
464 ( "->" calcFunc-evalto
40 -
1 )
465 ( "=>" calcFunc-evalto
40 41 )
466 ( "=>" calcFunc-evalto
40 -
1 )))
468 (put 'eqn
'math-function-table
469 '( ( arc\ cos . calcFunc-arccos
)
470 ( arc\ cosh . calcFunc-arccosh
)
471 ( arc\ sin . calcFunc-arcsin
)
472 ( arc\ sinh . calcFunc-arcsinh
)
473 ( arc\ tan . calcFunc-arctan
)
474 ( arc\ tanh . calcFunc-arctanh
)
475 ( GAMMA . calcFunc-gamma
)
476 ( phi . calcFunc-totient
)
477 ( mu . calcFunc-moebius
)
478 ( matrix .
(math-parse-eqn-matrix) )))
480 (put 'eqn
'math-variable-table
481 '( ( inf . var-uinf
)))
483 (put 'eqn
'math-complex-format
'i
)
485 (defun math-parse-eqn-matrix (f sym
)
487 (while (assoc exp-data
'(("ccol") ("lcol") ("rcol")))
489 (or (equal exp-data calc-function-open
)
490 (throw 'syntax
"Expected `{'"))
492 (setq vec
(cons (cons 'vec
(math-read-expr-list)) vec
))
493 (or (equal exp-data calc-function-close
)
494 (throw 'syntax
"Expected `}'"))
496 (or (equal exp-data calc-function-close
)
497 (throw 'syntax
"Expected `}'"))
499 (math-transpose (cons 'vec
(nreverse vec
)))))
501 (defun math-parse-eqn-prime (x sym
)
502 (if (eq (car-safe x
) 'var
)
503 (if (equal exp-data calc-function-open
)
506 (let ((args (if (or (equal exp-data calc-function-close
)
509 (math-read-expr-list))))
510 (if (not (or (equal exp-data calc-function-close
)
511 (eq exp-token
'end
)))
512 (throw 'syntax
"Expected `)'"))
514 (cons (intern (format "calcFunc-%s'" (nth 1 x
))) args
)))
516 (intern (concat (symbol-name (nth 1 x
)) "'"))
517 (intern (concat (symbol-name (nth 2 x
)) "'"))))
518 (list 'calcFunc-Prime x
)))
521 (defun calc-mathematica-language ()
524 (calc-set-language 'math
)
525 (message "Mathematica language mode")))
527 (put 'math
'math-oper-table
528 '( ( "[[" (math-read-math-subscr) 250 -
1 )
529 ( "!" calcFunc-fact
210 -
1 )
530 ( "!!" calcFunc-dfact
210 -
1 )
532 ( "u+" ident -
1 197 )
539 ( "<" calcFunc-lt
160 161 )
540 ( ">" calcFunc-gt
160 161 )
541 ( "<=" calcFunc-leq
160 161 )
542 ( ">=" calcFunc-geq
160 161 )
543 ( "==" calcFunc-eq
150 151 )
544 ( "!=" calcFunc-neq
150 151 )
545 ( "u!" calcFunc-lnot -
1 121 )
546 ( "&&" calcFunc-land
110 111 )
547 ( "||" calcFunc-lor
100 101 )
548 ( "!!!" calcFunc-pnot -
1 85 )
549 ( "&&&" calcFunc-pand
80 81 )
550 ( "|||" calcFunc-por
75 76 )
551 ( ":=" calcFunc-assign
51 50 )
552 ( "=" calcFunc-assign
51 50 )
553 ( "->" calcFunc-assign
51 50 )
554 ( ":>" calcFunc-assign
51 50 )
555 ( "::" calcFunc-condition
45 46 )
558 (put 'math
'math-function-table
559 '( ( Abs . calcFunc-abs
)
560 ( ArcCos . calcFunc-arccos
)
561 ( ArcCosh . calcFunc-arccosh
)
562 ( ArcSin . calcFunc-arcsin
)
563 ( ArcSinh . calcFunc-arcsinh
)
564 ( ArcTan . calcFunc-arctan
)
565 ( ArcTanh . calcFunc-arctanh
)
566 ( Arg . calcFunc-arg
)
567 ( Binomial . calcFunc-choose
)
568 ( Ceiling . calcFunc-ceil
)
569 ( Conjugate . calcFunc-conj
)
570 ( Cos . calcFunc-cos
)
571 ( Cosh . calcFunc-cosh
)
572 ( D . calcFunc-deriv
)
573 ( Dt . calcFunc-tderiv
)
574 ( Det . calcFunc-det
)
575 ( Exp . calcFunc-exp
)
576 ( EulerPhi . calcFunc-totient
)
577 ( Floor . calcFunc-floor
)
578 ( Gamma . calcFunc-gamma
)
579 ( GCD . calcFunc-gcd
)
582 ( Inverse . calcFunc-inv
)
583 ( Integrate . calcFunc-integ
)
584 ( Join . calcFunc-vconcat
)
585 ( LCM . calcFunc-lcm
)
586 ( Log . calcFunc-ln
)
587 ( Max . calcFunc-max
)
588 ( Min . calcFunc-min
)
589 ( Mod . calcFunc-mod
)
590 ( MoebiusMu . calcFunc-moebius
)
591 ( Random . calcFunc-random
)
592 ( Round . calcFunc-round
)
594 ( Sign . calcFunc-sign
)
595 ( Sin . calcFunc-sin
)
596 ( Sinh . calcFunc-sinh
)
597 ( Sqrt . calcFunc-sqrt
)
598 ( Tan . calcFunc-tan
)
599 ( Tanh . calcFunc-tanh
)
600 ( Transpose . calcFunc-trn
)
601 ( Length . calcFunc-vlen
)
604 (put 'math
'math-variable-table
608 ( GoldenRatio . var-phi
)
609 ( EulerGamma . var-gamma
)
610 ( Infinity . var-inf
)
611 ( ComplexInfinity . var-uinf
)
612 ( Indeterminate . var-nan
)
615 (put 'math
'math-vector-brackets
"{}")
616 (put 'math
'math-complex-format
'I
)
617 (put 'math
'math-function-open
"[")
618 (put 'math
'math-function-close
"]")
620 (put 'math
'math-radix-formatter
621 (function (lambda (r s
) (format "%d^^%s" r s
))))
623 (defun math-read-math-subscr (x op
)
624 (let ((idx (math-read-expr-level 0)))
625 (or (and (equal exp-data
"]")
628 (equal exp-data
"]")))
629 (throw 'syntax
"Expected ']]'"))
631 (list 'calcFunc-subscr x idx
)))
634 (defun calc-maple-language ()
637 (calc-set-language 'maple
)
638 (message "Maple language mode")))
640 (put 'maple
'math-oper-table
641 '( ( "matrix" ident -
1 300 )
642 ( "MATRIX" ident -
1 300 )
643 ( "!" calcFunc-fact
210 -
1 )
646 ( "u+" ident -
1 197 )
650 ( "intersect" calcFunc-vint
191 192 )
653 ( "union" calcFunc-vunion
180 181 )
654 ( "minus" calcFunc-vdiff
180 181 )
656 ( ".." (math-read-maple-dots) 165 165 )
657 ( "\\dots" (math-read-maple-dots) 165 165 )
658 ( "<" calcFunc-lt
160 160 )
659 ( ">" calcFunc-gt
160 160 )
660 ( "<=" calcFunc-leq
160 160 )
661 ( ">=" calcFunc-geq
160 160 )
662 ( "=" calcFunc-eq
160 160 )
663 ( "<>" calcFunc-neq
160 160 )
664 ( "not" calcFunc-lnot -
1 121 )
665 ( "and" calcFunc-land
110 111 )
666 ( "or" calcFunc-lor
100 101 )
667 ( "!!!" calcFunc-pnot -
1 85 )
668 ( "&&&" calcFunc-pand
80 81 )
669 ( "|||" calcFunc-por
75 76 )
670 ( ":=" calcFunc-assign
51 50 )
671 ( "::" calcFunc-condition
45 46 )
674 (put 'maple
'math-function-table
675 '( ( bernoulli . calcFunc-bern
)
676 ( binomial . calcFunc-choose
)
677 ( diff . calcFunc-deriv
)
678 ( GAMMA . calcFunc-gamma
)
679 ( ifactor . calcFunc-prfac
)
680 ( igcd . calcFunc-gcd
)
681 ( ilcm . calcFunc-lcm
)
682 ( int . calcFunc-integ
)
685 ( iquo . calcFunc-idiv
)
686 ( isprime . calcFunc-prime
)
687 ( length . calcFunc-vlen
)
688 ( member . calcFunc-in
)
689 ( crossprod . calcFunc-cross
)
690 ( inverse . calcFunc-inv
)
691 ( trace . calcFunc-tr
)
692 ( transpose . calcFunc-trn
)
693 ( vectdim . calcFunc-vlen
)
696 (put 'maple
'math-variable-table
700 ( infinity . var-inf
)
701 ( infinity . var-uinf
)
702 ( infinity . var-nan
)
705 (put 'maple
'math-complex-format
'I
)
707 (defun math-read-maple-dots (x op
)
708 (list 'intv
3 x
(math-read-expr-level (nth 3 op
))))
714 (defun math-read-big-rec (h1 v1 h2 v2
&optional baseline prec short
)
715 (or prec
(setq prec
0))
717 ;; Clip whitespace above or below.
718 (while (and (< v1 v2
) (math-read-big-emptyp h1 v1 h2
(1+ v1
)))
720 (while (and (< v1 v2
) (math-read-big-emptyp h1
(1- v2
) h2 v2
))
723 ;; If formula is a single line high, normal parser can handle it.
726 (> h1
(length (setq v2
(nth v1 lines
)))))
727 (math-read-big-error h1 v1
)
728 (setq the-baseline v1
731 h2
(math-read-expr (substring v2 h1
(min h2
(length v2
)))))
732 (if (eq (car-safe h2
) 'error
)
733 (math-read-big-error (+ h1
(nth 1 h2
)) v1
(nth 2 h2
))
736 ;; Clip whitespace at left or right.
737 (while (and (< h1 h2
) (math-read-big-emptyp h1 v1
(1+ h1
) v2
))
739 (while (and (< h1 h2
) (math-read-big-emptyp (1- h2
) v1 h2 v2
))
742 ;; Scan to find widest left-justified "----" in the region.
745 (lines-v1 (nthcdr v1 lines
))
749 other-char line len h
)
752 len
(min h2
(length line
)))
754 (/= (aref line h1
) ?\
)
755 (if (and (= (aref line h1
) ?\-
)
756 ;; Make sure it's not a minus sign.
757 (or (and (< (1+ h1
) len
) (= (aref line
(1+ h1
)) ?\-
))
758 (/= (math-read-big-char h1
(1- v
)) ?\
)
759 (/= (math-read-big-char h1
(1+ v
)) ?\
)))
762 (while (and (< (setq h
(1+ h
)) len
)
763 (= (aref line h
) ?\-
)))
767 (or other-v
(setq other-v v other-char
(aref line h1
)))))
771 (cond ((not (setq v other-v
))
772 (math-read-big-error h1 v1
)) ; Should never happen!
778 (let ((num (math-read-big-rec h1 v1 h v
))
779 (den (math-read-big-rec h1
(1+ v
) h v2
)))
780 (setq p
(if (and (math-integerp num
) (math-integerp den
))
781 (math-make-frac num den
)
782 (list '/ num den
)))))
786 (or (= (math-read-big-char (1+ h1
) v
) ?\|
)
787 (math-read-big-error (1+ h1
) v
"Malformed root sign"))
788 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
789 (while (= (math-read-big-char (1+ h1
) (setq v
(1- v
))) ?\|
))
790 (or (= (math-read-big-char (setq h
(+ h1
2)) v
) ?\_
)
791 (math-read-big-error h v
"Malformed root sign"))
792 (while (= (math-read-big-char (setq h
(1+ h
)) v
) ?\_
))
793 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
794 (math-read-big-emptyp h1
(1+ other-v
) h v2 nil t
)
795 (setq p
(list 'calcFunc-sqrt
(math-read-big-rec
797 h
(1+ other-v
) baseline
))
800 ;; Small radical sign.
801 ((and (= other-char ?V
)
802 (= (math-read-big-char (1+ h1
) (1- v
)) ?\_
))
804 (math-read-big-emptyp h1 v1 h
(1- v
) nil t
)
805 (math-read-big-emptyp h1
(1+ v
) h v2 nil t
)
806 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
807 (while (= (math-read-big-char (setq h
(1+ h
)) (1- v
)) ?\_
))
808 (setq p
(list 'calcFunc-sqrt
(math-read-big-rec
809 (1+ h1
) v h
(1+ v
) t
))
812 ;; Binomial coefficient.
813 ((and (= other-char ?\
()
814 (= (math-read-big-char (1+ h1
) v
) ?\
)
815 (= (string-match "( *)" (nth v lines
) h1
) h1
))
816 (setq h
(match-end 0))
817 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
818 (math-read-big-emptyp h1
(1+ v
) (1+ h1
) v2 nil t
)
819 (math-read-big-emptyp (1- h
) v1 h v nil t
)
820 (math-read-big-emptyp (1- h
) (1+ v
) h v2 nil t
)
821 (setq p
(list 'calcFunc-choose
822 (math-read-big-rec (1+ h1
) v1
(1- h
) v
)
823 (math-read-big-rec (1+ h1
) (1+ v
)
828 (setq p
(list 'neg
(math-read-big-rec (1+ h1
) v1 h2 v2 v
250 t
))
834 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
835 (math-read-big-emptyp h1
(1+ v
) (1+ h1
) v2 nil t
)
836 (setq h
(math-read-big-balance (1+ h1
) v
"(" t
))
837 (math-read-big-emptyp (1- h
) v1 h v nil t
)
838 (math-read-big-emptyp (1- h
) (1+ v
) h v2 nil t
)
839 (let ((sep (math-read-big-char (1- h
) v
))
844 (math-read-big-error (1- h
) v
"Expected `)'"))
846 (setq p
(math-read-big-rec (1+ h1
) v1
(1- h
) v2 v
))
847 (setq hmid
(math-read-big-balance h v
"(")
848 p
(list p
(math-read-big-rec h v1
(1- hmid
) v2 v
))
851 (setq p
(cons 'intv
(cons (if (= (math-read-big-char
856 ((= (math-read-big-char (1- h
) v
) ?\
])
857 (math-read-big-error (1- h
) v
"Expected `)'"))
859 (or (and (math-realp (car p
)) (math-realp (nth 1 p
)))
861 h1 v
"Complex components must be real"))
862 (setq p
(cons 'cplx p
)))
864 (or (and (math-realp (car p
)) (math-anglep (nth 1 p
)))
866 h1 v
"Complex components must be real"))
867 (setq p
(cons 'polar p
)))))))
870 ((and (= other-char ?\
[)
871 (or (= (math-read-big-char (setq h h1
) (1+ v
)) ?\
[)
872 (= (math-read-big-char (setq h
(1+ h
)) v
) ?\
[)
873 (and (= (math-read-big-char h v
) ?\
)
874 (= (math-read-big-char (setq h
(1+ h
)) v
) ?\
[)))
875 (= (math-read-big-char h
(1+ v
)) ?\
[))
876 (math-read-big-emptyp h1 v1 h v nil t
)
882 (setq h
(math-read-big-balance (1+ hleft
) v
"["))
885 (math-read-big-error hright v
"Expected `]'"))
887 (setq p
(cons (math-read-big-rec
888 hleft v h
(1+ v
)) p
))
889 (and (memq (math-read-big-char h v
) '(?\ ?\
,))
890 (= (math-read-big-char hleft
(1+ v
)) ?\
[)))
894 (if (= (math-read-big-char h v
) ?\
)
896 (and (= (math-read-big-char h v
) ?\
])
898 (math-read-big-error (1- h
) v
"Expected `]'"))
899 (if (= (math-read-big-char h vtop
) ?\
,)
901 (math-read-big-emptyp h1
(1+ v
) (1- h
) v2 nil t
)
902 (setq v
(+ vtop
(/ (- v vtop
) 2))
903 p
(cons 'vec
(nreverse p
)))))
907 (math-read-big-emptyp h1 v1
(1+ h1
) v nil t
)
908 (math-read-big-emptyp h1
(1+ v
) (1+ h1
) v2 nil t
)
912 (setq widest
(math-read-big-balance h v
"[" t
))
913 (math-read-big-emptyp (1- h
) v1 h v nil t
)
914 (math-read-big-emptyp (1- h
) (1+ v
) h v2 nil t
)
915 (setq p
(cons (math-read-big-rec
916 h v1
(1- widest
) v2 v
) p
)
918 (= (math-read-big-char (1- h
) v
) ?\
,)))
919 (setq widest
(math-read-big-char (1- h
) v
))
920 (if (or (memq widest
'(?\
; ?\)))
921 (and (eq widest ?\.
) (cdr p
)))
922 (math-read-big-error (1- h
) v
"Expected `]'"))
925 widest
(math-read-big-balance h v
"[")
926 p
(nconc p
(list (math-read-big-big-rec
927 h v1
(1- widest
) v2 v
)))
929 p
(cons 'intv
(cons (if (= (math-read-big-char (1- h
) v
)
933 (setq p
(cons 'vec
(nreverse p
)))))
937 (setq line
(nth v lines
))
938 (string-match ">" line h1
)
939 (setq h
(match-end 0))
940 (math-read-big-emptyp h1 v1 h v nil t
)
941 (math-read-big-emptyp h1
(1+ v
) h v2 nil t
)
942 (setq p
(math-read-big-rec h1 v h
(1+ v
) v
)))
944 ;; Variable name or function call.
945 ((or (and (>= other-char ?a
) (<= other-char ?z
))
946 (and (>= other-char ?A
) (<= other-char ?Z
)))
947 (setq line
(nth v lines
))
948 (string-match "\\([a-zA-Z'_]+\\) *" line h1
)
949 (setq h
(match-end 1)
951 p
(math-match-substring line
1))
952 (math-read-big-emptyp h1 v1 h v nil t
)
953 (math-read-big-emptyp h1
(1+ v
) h v2 nil t
)
954 (if (= (math-read-big-char widest v
) ?\
()
956 (setq line
(if (string-match "-" p
)
958 (intern (concat "calcFunc-" p
)))
961 (math-read-big-emptyp widest v1 h v nil t
)
962 (math-read-big-emptyp widest
(1+ v
) h v2 nil t
)
964 (setq widest
(math-read-big-balance h v
"(" t
))
965 (math-read-big-emptyp (1- h
) v1 h v nil t
)
966 (math-read-big-emptyp (1- h
) (1+ v
) h v2 nil t
)
967 (setq p
(cons (math-read-big-rec
968 h v1
(1- widest
) v2 v
) p
)
970 (= (math-read-big-char (1- h
) v
) ?\
,)))
971 (or (= (math-read-big-char (1- h
) v
) ?\
))
972 (math-read-big-error (1- h
) v
"Expected `)'"))
973 (setq p
(cons line
(nreverse p
))))
975 (intern (math-remove-dashes p
))
976 (if (string-match "-" p
)
978 (intern (concat "var-" p
)))))))
982 (setq line
(nth v lines
))
983 (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
)
984 (math-read-big-error h v
"Expected a number"))
985 (setq h
(match-end 0)
986 p
(math-read-number (math-match-substring line
0)))
987 (math-read-big-emptyp h1 v1 h v nil t
)
988 (math-read-big-emptyp h1
(1+ v
) h v2 nil t
)))
990 ;; Now left term is bounded by h1, v1, h, v2; baseline = v.
993 (math-read-big-error h1 v
"Inconsistent baseline in formula"))
996 ;; Look for superscripts or subscripts.
997 (setq line
(nth baseline lines
)
998 len
(min h2
(length line
))
1000 (while (and (< widest len
)
1001 (= (aref line widest
) ?\
))
1002 (setq widest
(1+ widest
)))
1003 (and (>= widest len
) (setq widest h2
))
1004 (if (math-read-big-emptyp h v widest v2
)
1005 (if (math-read-big-emptyp h v1 widest v
)
1007 (setq p
(list '^ p
(math-read-big-rec h v1 widest v
))
1009 (if (math-read-big-emptyp h v1 widest v
)
1010 (setq p
(list 'calcFunc-subscr p
1011 (math-read-big-rec h v widest v2
))
1014 ;; Look for an operator name and grab additional terms.
1015 (while (and (< h len
)
1016 (if (setq widest
(and (math-read-big-emptyp
1018 (math-read-big-emptyp
1020 (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h
)
1021 (assoc (math-match-substring line
0)
1022 math-standard-opers
)))
1023 (and (>= (nth 2 widest
) prec
)
1024 (setq h
(match-end 0)))
1025 (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h
)
1027 (setq widest
'("2x" * 196 195)))))
1028 (cond ((eq (nth 3 widest
) -
1)
1029 (setq p
(list (nth 1 widest
) p
)))
1030 ((equal (car widest
) "?")
1031 (let ((y (math-read-big-rec h v1 h2 v2 baseline nil t
)))
1032 (or (= (math-read-big-char the-h2 baseline
) ?\
:)
1033 (math-read-big-error the-h2 baseline
"Expected `:'"))
1034 (setq p
(list (nth 1 widest
) p y
1035 (math-read-big-rec (1+ the-h2
) v1 h2 v2
1036 baseline
(nth 3 widest
) t
))
1039 (setq p
(list (nth 1 widest
) p
1040 (math-read-big-rec h v1 h2 v2
1041 baseline
(nth 3 widest
) t
))
1044 ;; Return all relevant information to caller.
1045 (setq the-baseline baseline
1047 (or short
(= the-h2 h2
)
1048 (math-read-big-error h baseline
))
1051 (defun math-read-big-char (h v
)
1056 (let ((line (nth v lines
)))
1062 (defun math-read-big-emptyp (eh1 ev1 eh2 ev2
&optional what error
)
1063 (and (< ev1 v1
) (setq ev1 v1
))
1064 (and (< eh1 h1
) (setq eh1 h1
))
1065 (and (> ev2 v2
) (setq ev2 v2
))
1066 (and (> eh2 h2
) (setq eh2 h2
))
1067 (or what
(setq what ?\
))
1068 (let ((p (nthcdr ev1 lines
))
1070 (while (and (< ev1 ev2
)
1072 (setq h
(min eh2
(length (car p
))))
1073 (while (and (>= (setq h
(1- h
)) eh1
)
1074 (= (aref (car p
) h
) what
)))
1075 (and error
(>= h eh1
)
1076 (math-read-big-error h ev1
(if (stringp error
)
1078 "Whitespace expected")))
1084 (defun math-read-big-error (h v
&optional msg
)
1088 (setq pos
(+ pos
1 (length (car p
)))
1091 (setq h
(+ pos
(min h
(length (car p
))))
1092 err-msg
(list 'error h
(or msg
"Syntax error")))
1093 (throw 'syntax nil
)))
1095 (defun math-read-big-balance (h v what
&optional commas
)
1096 (let* ((line (nth v lines
))
1097 (len (min h2
(length line
)))
1102 (math-read-big-error h1 v
(format "Unmatched `%s'" what
))
1104 (if (memq (aref line h
) '(?\
( ?\
[))
1105 (setq count
(1+ count
))
1106 (if (if (and commas
(= count
1))
1107 (or (memq (aref line h
) '(?\
) ?\
] ?\
, ?\
;))
1108 (and (eq (aref line h
) ?\.
)
1110 (eq (aref line
(1+ h
)) ?\.
)))
1111 (memq (aref line h
) '(?\
) ?\
])))
1112 (setq count
(1- count
))))
1116 ;;; arch-tag: 483bfe15-f290-4fef-bb7d-ce65be687f2e
1117 ;;; calc-lang.el ends here