]> code.delx.au - gnu-emacs/blob - lisp/calc/calc-ext.el
(math-provably-realp): Fix typo.
[gnu-emacs] / lisp / calc / calc-ext.el
1 ;;; calc-ext.el --- various extension functions for Calc
2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (require 'calc)
31 (require 'calc-macs)
32
33 ;; Declare functions which are defined elsewhere.
34 (declare-function math-clip "calc-bin" (a &optional w))
35 (declare-function math-round "calc-arith" (a &optional prec))
36 (declare-function math-simplify "calc-alg" (top-expr))
37 (declare-function math-simplify-extended "calc-alg" (a))
38 (declare-function math-simplify-units "calc-units" (a))
39 (declare-function calc-set-language "calc-lang" (lang &optional option no-refresh))
40 (declare-function calc-flush-caches "calc-stuff" (&optional inhibit-msg))
41 (declare-function calc-save-modes "calc-mode" ())
42 (declare-function calc-embedded-modes-change "calc-embed" (vars))
43 (declare-function calc-embedded-var-change "calc-embed" (var &optional buf))
44 (declare-function math-mul-float "calc-arith" (a b))
45 (declare-function math-arctan-raw "calc-math" (x))
46 (declare-function math-sqrt-float "calc-math" (a &optional guess))
47 (declare-function math-exp-minus-1-raw "calc-math" (x))
48 (declare-function math-normalize-polar "calc-cplx" (a))
49 (declare-function math-normalize-hms "calc-forms" (a))
50 (declare-function math-normalize-mod "calc-forms" (a))
51 (declare-function math-make-sdev "calc-forms" (x sigma))
52 (declare-function math-make-intv "calc-forms" (mask lo hi))
53 (declare-function math-normalize-logical-op "calc-prog" (a))
54 (declare-function math-possible-signs "calc-arith" (a &optional origin))
55 (declare-function math-infinite-dir "calc-math" (a &optional inf))
56 (declare-function math-calcFunc-to-var "calc-map" (f))
57 (declare-function calc-embedded-evaluate-expr "calc-embed" (x))
58 (declare-function math-known-nonzerop "calc-arith" (a))
59 (declare-function math-read-expr-level "calc-aent" (exp-prec &optional exp-term))
60 (declare-function math-read-big-rec "calc-lang" (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2))
61 (declare-function math-read-big-balance "calc-lang" (h v what &optional commas))
62 (declare-function math-format-date "calc-forms" (math-fd-date))
63 (declare-function math-vector-is-string "calccomp" (a))
64 (declare-function math-vector-to-string "calccomp" (a &optional quoted))
65 (declare-function math-format-radix-float "calc-bin" (a prec))
66 (declare-function math-compose-expr "calccomp" (a prec))
67 (declare-function math-abs "calc-arith" (a))
68 (declare-function math-format-bignum-binary "calc-bin" (a))
69 (declare-function math-format-bignum-octal "calc-bin" (a))
70 (declare-function math-format-bignum-hex "calc-bin" (a))
71 (declare-function math-format-bignum-radix "calc-bin" (a))
72 (declare-function math-compute-max-digits "calc-bin" (w r))
73
74 (defvar math-simplifying nil)
75 (defvar math-living-dangerously nil) ; true if unsafe simplifications are okay.
76 (defvar math-integrating nil)
77
78 (defvar math-rewrite-selections nil)
79
80 (defvar math-compose-level 0)
81 (defvar math-comp-selected nil)
82 (defvar math-comp-tagged nil)
83 (defvar math-comp-sel-hpos nil)
84 (defvar math-comp-sel-vpos nil)
85 (defvar math-comp-sel-cpos nil)
86 (defvar math-compose-hash-args nil)
87
88 (defvar calc-alg-map)
89 (defvar calc-alg-esc-map)
90
91 ;;; The following was made a function so that it could be byte-compiled.
92 (defun calc-init-extensions ()
93
94 (define-key calc-mode-map ":" 'calc-fdiv)
95 (define-key calc-mode-map "\\" 'calc-idiv)
96 (define-key calc-mode-map "|" 'calc-concat)
97 (define-key calc-mode-map "!" 'calc-factorial)
98 (define-key calc-mode-map "C" 'calc-cos)
99 (define-key calc-mode-map "E" 'calc-exp)
100 (define-key calc-mode-map "H" 'calc-hyperbolic)
101 (define-key calc-mode-map "I" 'calc-inverse)
102 (define-key calc-mode-map "J" 'calc-conj)
103 (define-key calc-mode-map "L" 'calc-ln)
104 (define-key calc-mode-map "N" 'calc-eval-num)
105 (define-key calc-mode-map "P" 'calc-pi)
106 (define-key calc-mode-map "Q" 'calc-sqrt)
107 (define-key calc-mode-map "R" 'calc-round)
108 (define-key calc-mode-map "S" 'calc-sin)
109 (define-key calc-mode-map "T" 'calc-tan)
110 (define-key calc-mode-map "U" 'calc-undo)
111 (define-key calc-mode-map "X" 'calc-call-last-kbd-macro)
112 (define-key calc-mode-map "o" 'calc-realign)
113 (define-key calc-mode-map "p" 'calc-precision)
114 (define-key calc-mode-map "w" 'calc-why)
115 (define-key calc-mode-map "x" 'calc-execute-extended-command)
116 (define-key calc-mode-map "y" 'calc-copy-to-buffer)
117
118 (define-key calc-mode-map "(" 'calc-begin-complex)
119 (define-key calc-mode-map ")" 'calc-end-complex)
120 (define-key calc-mode-map "[" 'calc-begin-vector)
121 (define-key calc-mode-map "]" 'calc-end-vector)
122 (define-key calc-mode-map "," 'calc-comma)
123 (define-key calc-mode-map ";" 'calc-semi)
124 (define-key calc-mode-map "`" 'calc-edit)
125 (define-key calc-mode-map "=" 'calc-evaluate)
126 (define-key calc-mode-map "~" 'calc-num-prefix)
127 (define-key calc-mode-map "<" 'calc-scroll-left)
128 (define-key calc-mode-map ">" 'calc-scroll-right)
129 (define-key calc-mode-map "{" 'calc-scroll-down)
130 (define-key calc-mode-map "}" 'calc-scroll-up)
131 (define-key calc-mode-map "\C-k" 'calc-kill)
132 (define-key calc-mode-map "\M-k" 'calc-copy-as-kill)
133 (define-key calc-mode-map "\C-w" 'calc-kill-region)
134 (define-key calc-mode-map "\M-w" 'calc-copy-region-as-kill)
135 (define-key calc-mode-map "\C-y" 'calc-yank)
136 (define-key calc-mode-map [mouse-2] 'calc-yank)
137 (define-key calc-mode-map "\C-_" 'calc-undo)
138 (define-key calc-mode-map "\C-xu" 'calc-undo)
139 (define-key calc-mode-map "\M-\C-m" 'calc-last-args)
140
141 (define-key calc-mode-map "a" nil)
142 (define-key calc-mode-map "a?" 'calc-a-prefix-help)
143 (define-key calc-mode-map "aa" 'calc-apart)
144 (define-key calc-mode-map "ab" 'calc-substitute)
145 (define-key calc-mode-map "ac" 'calc-collect)
146 (define-key calc-mode-map "ad" 'calc-derivative)
147 (define-key calc-mode-map "ae" 'calc-simplify-extended)
148 (define-key calc-mode-map "af" 'calc-factor)
149 (define-key calc-mode-map "ag" 'calc-poly-gcd)
150 (define-key calc-mode-map "ai" 'calc-integral)
151 (define-key calc-mode-map "am" 'calc-match)
152 (define-key calc-mode-map "an" 'calc-normalize-rat)
153 (define-key calc-mode-map "ap" 'calc-poly-interp)
154 (define-key calc-mode-map "ar" 'calc-rewrite)
155 (define-key calc-mode-map "as" 'calc-simplify)
156 (define-key calc-mode-map "at" 'calc-taylor)
157 (define-key calc-mode-map "av" 'calc-alg-evaluate)
158 (define-key calc-mode-map "ax" 'calc-expand)
159 (define-key calc-mode-map "aA" 'calc-abs)
160 (define-key calc-mode-map "aF" 'calc-curve-fit)
161 (define-key calc-mode-map "aI" 'calc-num-integral)
162 (define-key calc-mode-map "aM" 'calc-map-equation)
163 (define-key calc-mode-map "aN" 'calc-find-minimum)
164 (define-key calc-mode-map "aP" 'calc-poly-roots)
165 (define-key calc-mode-map "aS" 'calc-solve-for)
166 (define-key calc-mode-map "aR" 'calc-find-root)
167 (define-key calc-mode-map "aT" 'calc-tabulate)
168 (define-key calc-mode-map "aX" 'calc-find-maximum)
169 (define-key calc-mode-map "a+" 'calc-summation)
170 (define-key calc-mode-map "a-" 'calc-alt-summation)
171 (define-key calc-mode-map "a*" 'calc-product)
172 (define-key calc-mode-map "a\\" 'calc-poly-div)
173 (define-key calc-mode-map "a%" 'calc-poly-rem)
174 (define-key calc-mode-map "a/" 'calc-poly-div-rem)
175 (define-key calc-mode-map "a=" 'calc-equal-to)
176 (define-key calc-mode-map "a#" 'calc-not-equal-to)
177 (define-key calc-mode-map "a<" 'calc-less-than)
178 (define-key calc-mode-map "a>" 'calc-greater-than)
179 (define-key calc-mode-map "a[" 'calc-less-equal)
180 (define-key calc-mode-map "a]" 'calc-greater-equal)
181 (define-key calc-mode-map "a." 'calc-remove-equal)
182 (define-key calc-mode-map "a{" 'calc-in-set)
183 (define-key calc-mode-map "a&" 'calc-logical-and)
184 (define-key calc-mode-map "a|" 'calc-logical-or)
185 (define-key calc-mode-map "a!" 'calc-logical-not)
186 (define-key calc-mode-map "a:" 'calc-logical-if)
187 (define-key calc-mode-map "a_" 'calc-subscript)
188 (define-key calc-mode-map "a\"" 'calc-expand-formula)
189
190 (define-key calc-mode-map "b" nil)
191 (define-key calc-mode-map "b?" 'calc-b-prefix-help)
192 (define-key calc-mode-map "ba" 'calc-and)
193 (define-key calc-mode-map "bc" 'calc-clip)
194 (define-key calc-mode-map "bd" 'calc-diff)
195 (define-key calc-mode-map "bl" 'calc-lshift-binary)
196 (define-key calc-mode-map "bn" 'calc-not)
197 (define-key calc-mode-map "bo" 'calc-or)
198 (define-key calc-mode-map "bp" 'calc-pack-bits)
199 (define-key calc-mode-map "br" 'calc-rshift-binary)
200 (define-key calc-mode-map "bt" 'calc-rotate-binary)
201 (define-key calc-mode-map "bu" 'calc-unpack-bits)
202 (define-key calc-mode-map "bw" 'calc-word-size)
203 (define-key calc-mode-map "bx" 'calc-xor)
204 (define-key calc-mode-map "bB" 'calc-log)
205 (define-key calc-mode-map "bD" 'calc-fin-ddb)
206 (define-key calc-mode-map "bF" 'calc-fin-fv)
207 (define-key calc-mode-map "bI" 'calc-fin-irr)
208 (define-key calc-mode-map "bL" 'calc-lshift-arith)
209 (define-key calc-mode-map "bM" 'calc-fin-pmt)
210 (define-key calc-mode-map "bN" 'calc-fin-npv)
211 (define-key calc-mode-map "bP" 'calc-fin-pv)
212 (define-key calc-mode-map "bR" 'calc-rshift-arith)
213 (define-key calc-mode-map "bS" 'calc-fin-sln)
214 (define-key calc-mode-map "bT" 'calc-fin-rate)
215 (define-key calc-mode-map "bY" 'calc-fin-syd)
216 (define-key calc-mode-map "b#" 'calc-fin-nper)
217 (define-key calc-mode-map "b%" 'calc-percent-change)
218
219 (define-key calc-mode-map "c" nil)
220 (define-key calc-mode-map "c?" 'calc-c-prefix-help)
221 (define-key calc-mode-map "cc" 'calc-clean)
222 (define-key calc-mode-map "cd" 'calc-to-degrees)
223 (define-key calc-mode-map "cf" 'calc-float)
224 (define-key calc-mode-map "ch" 'calc-to-hms)
225 (define-key calc-mode-map "cp" 'calc-polar)
226 (define-key calc-mode-map "cr" 'calc-to-radians)
227 (define-key calc-mode-map "cC" 'calc-cos)
228 (define-key calc-mode-map "cF" 'calc-fraction)
229 (define-key calc-mode-map "c%" 'calc-convert-percent)
230
231 (define-key calc-mode-map "d" nil)
232 (define-key calc-mode-map "d?" 'calc-d-prefix-help)
233 (define-key calc-mode-map "d0" 'calc-decimal-radix)
234 (define-key calc-mode-map "d2" 'calc-binary-radix)
235 (define-key calc-mode-map "d6" 'calc-hex-radix)
236 (define-key calc-mode-map "d8" 'calc-octal-radix)
237 (define-key calc-mode-map "db" 'calc-line-breaking)
238 (define-key calc-mode-map "dc" 'calc-complex-notation)
239 (define-key calc-mode-map "dd" 'calc-date-notation)
240 (define-key calc-mode-map "de" 'calc-eng-notation)
241 (define-key calc-mode-map "df" 'calc-fix-notation)
242 (define-key calc-mode-map "dg" 'calc-group-digits)
243 (define-key calc-mode-map "dh" 'calc-hms-notation)
244 (define-key calc-mode-map "di" 'calc-i-notation)
245 (define-key calc-mode-map "dj" 'calc-j-notation)
246 (define-key calc-mode-map "dl" 'calc-line-numbering)
247 (define-key calc-mode-map "dn" 'calc-normal-notation)
248 (define-key calc-mode-map "do" 'calc-over-notation)
249 (define-key calc-mode-map "dp" 'calc-show-plain)
250 (define-key calc-mode-map "dr" 'calc-radix)
251 (define-key calc-mode-map "ds" 'calc-sci-notation)
252 (define-key calc-mode-map "dt" 'calc-truncate-stack)
253 (define-key calc-mode-map "dw" 'calc-auto-why)
254 (define-key calc-mode-map "dz" 'calc-leading-zeros)
255 (define-key calc-mode-map "dB" 'calc-big-language)
256 (define-key calc-mode-map "dD" 'calc-redo)
257 (define-key calc-mode-map "dC" 'calc-c-language)
258 (define-key calc-mode-map "dE" 'calc-eqn-language)
259 (define-key calc-mode-map "dF" 'calc-fortran-language)
260 (define-key calc-mode-map "dM" 'calc-mathematica-language)
261 (define-key calc-mode-map "dN" 'calc-normal-language)
262 (define-key calc-mode-map "dO" 'calc-flat-language)
263 (define-key calc-mode-map "dP" 'calc-pascal-language)
264 (define-key calc-mode-map "dT" 'calc-tex-language)
265 (define-key calc-mode-map "dL" 'calc-latex-language)
266 (define-key calc-mode-map "dU" 'calc-unformatted-language)
267 (define-key calc-mode-map "dW" 'calc-maple-language)
268 (define-key calc-mode-map "d[" 'calc-truncate-up)
269 (define-key calc-mode-map "d]" 'calc-truncate-down)
270 (define-key calc-mode-map "d." 'calc-point-char)
271 (define-key calc-mode-map "d," 'calc-group-char)
272 (define-key calc-mode-map "d\"" 'calc-display-strings)
273 (define-key calc-mode-map "d<" 'calc-left-justify)
274 (define-key calc-mode-map "d=" 'calc-center-justify)
275 (define-key calc-mode-map "d>" 'calc-right-justify)
276 (define-key calc-mode-map "d{" 'calc-left-label)
277 (define-key calc-mode-map "d}" 'calc-right-label)
278 (define-key calc-mode-map "d'" 'calc-display-raw)
279 (define-key calc-mode-map "d " 'calc-refresh)
280 (define-key calc-mode-map "d\r" 'calc-refresh-top)
281 (define-key calc-mode-map "d@" 'calc-toggle-banner)
282
283 (define-key calc-mode-map "f" nil)
284 (define-key calc-mode-map "f?" 'calc-f-prefix-help)
285 (define-key calc-mode-map "fb" 'calc-beta)
286 (define-key calc-mode-map "fe" 'calc-erf)
287 (define-key calc-mode-map "fg" 'calc-gamma)
288 (define-key calc-mode-map "fh" 'calc-hypot)
289 (define-key calc-mode-map "fi" 'calc-im)
290 (define-key calc-mode-map "fj" 'calc-bessel-J)
291 (define-key calc-mode-map "fn" 'calc-min)
292 (define-key calc-mode-map "fr" 'calc-re)
293 (define-key calc-mode-map "fs" 'calc-sign)
294 (define-key calc-mode-map "fx" 'calc-max)
295 (define-key calc-mode-map "fy" 'calc-bessel-Y)
296 (define-key calc-mode-map "fA" 'calc-abssqr)
297 (define-key calc-mode-map "fB" 'calc-inc-beta)
298 (define-key calc-mode-map "fE" 'calc-expm1)
299 (define-key calc-mode-map "fF" 'calc-floor)
300 (define-key calc-mode-map "fG" 'calc-inc-gamma)
301 (define-key calc-mode-map "fI" 'calc-ilog)
302 (define-key calc-mode-map "fL" 'calc-lnp1)
303 (define-key calc-mode-map "fM" 'calc-mant-part)
304 (define-key calc-mode-map "fQ" 'calc-isqrt)
305 (define-key calc-mode-map "fS" 'calc-scale-float)
306 (define-key calc-mode-map "fT" 'calc-arctan2)
307 (define-key calc-mode-map "fX" 'calc-xpon-part)
308 (define-key calc-mode-map "f[" 'calc-decrement)
309 (define-key calc-mode-map "f]" 'calc-increment)
310
311 (define-key calc-mode-map "g" nil)
312 (define-key calc-mode-map "g?" 'calc-g-prefix-help)
313 (define-key calc-mode-map "ga" 'calc-graph-add)
314 (define-key calc-mode-map "gb" 'calc-graph-border)
315 (define-key calc-mode-map "gc" 'calc-graph-clear)
316 (define-key calc-mode-map "gd" 'calc-graph-delete)
317 (define-key calc-mode-map "gf" 'calc-graph-fast)
318 (define-key calc-mode-map "gg" 'calc-graph-grid)
319 (define-key calc-mode-map "gh" 'calc-graph-header)
320 (define-key calc-mode-map "gk" 'calc-graph-key)
321 (define-key calc-mode-map "gj" 'calc-graph-juggle)
322 (define-key calc-mode-map "gl" 'calc-graph-log-x)
323 (define-key calc-mode-map "gn" 'calc-graph-name)
324 (define-key calc-mode-map "gp" 'calc-graph-plot)
325 (define-key calc-mode-map "gq" 'calc-graph-quit)
326 (define-key calc-mode-map "gr" 'calc-graph-range-x)
327 (define-key calc-mode-map "gs" 'calc-graph-line-style)
328 (define-key calc-mode-map "gt" 'calc-graph-title-x)
329 (define-key calc-mode-map "gv" 'calc-graph-view-commands)
330 (define-key calc-mode-map "gx" 'calc-graph-display)
331 (define-key calc-mode-map "gz" 'calc-graph-zero-x)
332 (define-key calc-mode-map "gA" 'calc-graph-add-3d)
333 (define-key calc-mode-map "gC" 'calc-graph-command)
334 (define-key calc-mode-map "gD" 'calc-graph-device)
335 (define-key calc-mode-map "gF" 'calc-graph-fast-3d)
336 (define-key calc-mode-map "gG" 'calc-argument)
337 (define-key calc-mode-map "gH" 'calc-graph-hide)
338 (define-key calc-mode-map "gK" 'calc-graph-kill)
339 (define-key calc-mode-map "gL" 'calc-graph-log-y)
340 (define-key calc-mode-map "gN" 'calc-graph-num-points)
341 (define-key calc-mode-map "gO" 'calc-graph-output)
342 (define-key calc-mode-map "gP" 'calc-graph-print)
343 (define-key calc-mode-map "gR" 'calc-graph-range-y)
344 (define-key calc-mode-map "gS" 'calc-graph-point-style)
345 (define-key calc-mode-map "gT" 'calc-graph-title-y)
346 (define-key calc-mode-map "gV" 'calc-graph-view-trail)
347 (define-key calc-mode-map "gX" 'calc-graph-geometry)
348 (define-key calc-mode-map "gZ" 'calc-graph-zero-y)
349 (define-key calc-mode-map "g\C-l" 'calc-graph-log-z)
350 (define-key calc-mode-map "g\C-r" 'calc-graph-range-z)
351 (define-key calc-mode-map "g\C-t" 'calc-graph-title-z)
352
353 (define-key calc-mode-map "h" 'calc-help-prefix)
354
355 (define-key calc-mode-map "j" nil)
356 (define-key calc-mode-map "j?" 'calc-j-prefix-help)
357 (define-key calc-mode-map "ja" 'calc-select-additional)
358 (define-key calc-mode-map "jb" 'calc-break-selections)
359 (define-key calc-mode-map "jc" 'calc-clear-selections)
360 (define-key calc-mode-map "jd" 'calc-show-selections)
361 (define-key calc-mode-map "je" 'calc-enable-selections)
362 (define-key calc-mode-map "jl" 'calc-select-less)
363 (define-key calc-mode-map "jm" 'calc-select-more)
364 (define-key calc-mode-map "jn" 'calc-select-next)
365 (define-key calc-mode-map "jo" 'calc-select-once)
366 (define-key calc-mode-map "jp" 'calc-select-previous)
367 (define-key calc-mode-map "jr" 'calc-rewrite-selection)
368 (define-key calc-mode-map "js" 'calc-select-here)
369 (define-key calc-mode-map "jv" 'calc-sel-evaluate)
370 (define-key calc-mode-map "ju" 'calc-unselect)
371 (define-key calc-mode-map "jC" 'calc-sel-commute)
372 (define-key calc-mode-map "jD" 'calc-sel-distribute)
373 (define-key calc-mode-map "jE" 'calc-sel-jump-equals)
374 (define-key calc-mode-map "jI" 'calc-sel-isolate)
375 (define-key calc-mode-map "jJ" 'calc-conj)
376 (define-key calc-mode-map "jL" 'calc-commute-left)
377 (define-key calc-mode-map "jM" 'calc-sel-merge)
378 (define-key calc-mode-map "jN" 'calc-sel-negate)
379 (define-key calc-mode-map "jO" 'calc-select-once-maybe)
380 (define-key calc-mode-map "jR" 'calc-commute-right)
381 (define-key calc-mode-map "jS" 'calc-select-here-maybe)
382 (define-key calc-mode-map "jU" 'calc-sel-unpack)
383 (define-key calc-mode-map "j&" 'calc-sel-invert)
384 (define-key calc-mode-map "j\r" 'calc-copy-selection)
385 (define-key calc-mode-map "j\n" 'calc-copy-selection)
386 (define-key calc-mode-map "j\010" 'calc-del-selection)
387 (define-key calc-mode-map "j\177" 'calc-del-selection)
388 (define-key calc-mode-map "j'" 'calc-enter-selection)
389 (define-key calc-mode-map "j`" 'calc-edit-selection)
390 (define-key calc-mode-map "j+" 'calc-sel-add-both-sides)
391 (define-key calc-mode-map "j-" 'calc-sel-sub-both-sides)
392 (define-key calc-mode-map "j*" 'calc-sel-mult-both-sides)
393 (define-key calc-mode-map "j/" 'calc-sel-div-both-sides)
394 (define-key calc-mode-map "j\"" 'calc-sel-expand-formula)
395
396 (define-key calc-mode-map "k" nil)
397 (define-key calc-mode-map "k?" 'calc-k-prefix-help)
398 (define-key calc-mode-map "ka" 'calc-random-again)
399 (define-key calc-mode-map "kb" 'calc-bernoulli-number)
400 (define-key calc-mode-map "kc" 'calc-choose)
401 (define-key calc-mode-map "kd" 'calc-double-factorial)
402 (define-key calc-mode-map "ke" 'calc-euler-number)
403 (define-key calc-mode-map "kf" 'calc-prime-factors)
404 (define-key calc-mode-map "kg" 'calc-gcd)
405 (define-key calc-mode-map "kh" 'calc-shuffle)
406 (define-key calc-mode-map "kl" 'calc-lcm)
407 (define-key calc-mode-map "km" 'calc-moebius)
408 (define-key calc-mode-map "kn" 'calc-next-prime)
409 (define-key calc-mode-map "kp" 'calc-prime-test)
410 (define-key calc-mode-map "kr" 'calc-random)
411 (define-key calc-mode-map "ks" 'calc-stirling-number)
412 (define-key calc-mode-map "kt" 'calc-totient)
413 (define-key calc-mode-map "kB" 'calc-utpb)
414 (define-key calc-mode-map "kC" 'calc-utpc)
415 (define-key calc-mode-map "kE" 'calc-extended-gcd)
416 (define-key calc-mode-map "kF" 'calc-utpf)
417 (define-key calc-mode-map "kK" 'calc-keep-args)
418 (define-key calc-mode-map "kN" 'calc-utpn)
419 (define-key calc-mode-map "kP" 'calc-utpp)
420 (define-key calc-mode-map "kT" 'calc-utpt)
421
422 (define-key calc-mode-map "m" nil)
423 (define-key calc-mode-map "m?" 'calc-m-prefix-help)
424 (define-key calc-mode-map "ma" 'calc-algebraic-mode)
425 (define-key calc-mode-map "md" 'calc-degrees-mode)
426 (define-key calc-mode-map "me" 'calc-embedded-preserve-modes)
427 (define-key calc-mode-map "mf" 'calc-frac-mode)
428 (define-key calc-mode-map "mg" 'calc-get-modes)
429 (define-key calc-mode-map "mh" 'calc-hms-mode)
430 (define-key calc-mode-map "mi" 'calc-infinite-mode)
431 (define-key calc-mode-map "mm" 'calc-save-modes)
432 (define-key calc-mode-map "mp" 'calc-polar-mode)
433 (define-key calc-mode-map "mr" 'calc-radians-mode)
434 (define-key calc-mode-map "ms" 'calc-symbolic-mode)
435 (define-key calc-mode-map "mt" 'calc-total-algebraic-mode)
436 (define-key calc-mode-map "\emt" 'calc-total-algebraic-mode)
437 (define-key calc-mode-map "\em\et" 'calc-total-algebraic-mode)
438 (define-key calc-mode-map "mv" 'calc-matrix-mode)
439 (define-key calc-mode-map "mw" 'calc-working)
440 (define-key calc-mode-map "mx" 'calc-always-load-extensions)
441 (define-key calc-mode-map "mA" 'calc-alg-simplify-mode)
442 (define-key calc-mode-map "mB" 'calc-bin-simplify-mode)
443 (define-key calc-mode-map "mC" 'calc-auto-recompute)
444 (define-key calc-mode-map "mD" 'calc-default-simplify-mode)
445 (define-key calc-mode-map "mE" 'calc-ext-simplify-mode)
446 (define-key calc-mode-map "mF" 'calc-settings-file-name)
447 (define-key calc-mode-map "mM" 'calc-more-recursion-depth)
448 (define-key calc-mode-map "mN" 'calc-num-simplify-mode)
449 (define-key calc-mode-map "mO" 'calc-no-simplify-mode)
450 (define-key calc-mode-map "mR" 'calc-mode-record-mode)
451 (define-key calc-mode-map "mS" 'calc-shift-prefix)
452 (define-key calc-mode-map "mU" 'calc-units-simplify-mode)
453 (define-key calc-mode-map "mX" 'calc-load-everything)
454
455 (define-key calc-mode-map "r" nil)
456 (define-key calc-mode-map "r?" 'calc-r-prefix-help)
457
458 (define-key calc-mode-map "s" nil)
459 (define-key calc-mode-map "s?" 'calc-s-prefix-help)
460 (define-key calc-mode-map "sc" 'calc-copy-variable)
461 (define-key calc-mode-map "sd" 'calc-declare-variable)
462 (define-key calc-mode-map "se" 'calc-edit-variable)
463 (define-key calc-mode-map "si" 'calc-insert-variables)
464 (define-key calc-mode-map "sk" 'calc-copy-special-constant)
465 (define-key calc-mode-map "sl" 'calc-let)
466 (define-key calc-mode-map "sm" 'calc-store-map)
467 (define-key calc-mode-map "sn" 'calc-store-neg)
468 (define-key calc-mode-map "sp" 'calc-permanent-variable)
469 (define-key calc-mode-map "sr" 'calc-recall)
470 (define-key calc-mode-map "ss" 'calc-store)
471 (define-key calc-mode-map "st" 'calc-store-into)
472 (define-key calc-mode-map "su" 'calc-unstore)
473 (define-key calc-mode-map "sx" 'calc-store-exchange)
474 (define-key calc-mode-map "sA" 'calc-edit-AlgSimpRules)
475 (define-key calc-mode-map "sD" 'calc-edit-Decls)
476 (define-key calc-mode-map "sE" 'calc-edit-EvalRules)
477 (define-key calc-mode-map "sF" 'calc-edit-FitRules)
478 (define-key calc-mode-map "sG" 'calc-edit-GenCount)
479 (define-key calc-mode-map "sH" 'calc-edit-Holidays)
480 (define-key calc-mode-map "sI" 'calc-edit-IntegLimit)
481 (define-key calc-mode-map "sL" 'calc-edit-LineStyles)
482 (define-key calc-mode-map "sP" 'calc-edit-PointStyles)
483 (define-key calc-mode-map "sR" 'calc-edit-PlotRejects)
484 (define-key calc-mode-map "sS" 'calc-sin)
485 (define-key calc-mode-map "sT" 'calc-edit-TimeZone)
486 (define-key calc-mode-map "sU" 'calc-edit-Units)
487 (define-key calc-mode-map "sX" 'calc-edit-ExtSimpRules)
488 (define-key calc-mode-map "s+" 'calc-store-plus)
489 (define-key calc-mode-map "s-" 'calc-store-minus)
490 (define-key calc-mode-map "s*" 'calc-store-times)
491 (define-key calc-mode-map "s/" 'calc-store-div)
492 (define-key calc-mode-map "s^" 'calc-store-power)
493 (define-key calc-mode-map "s|" 'calc-store-concat)
494 (define-key calc-mode-map "s&" 'calc-store-inv)
495 (define-key calc-mode-map "s[" 'calc-store-decr)
496 (define-key calc-mode-map "s]" 'calc-store-incr)
497 (define-key calc-mode-map "s:" 'calc-assign)
498 (define-key calc-mode-map "s=" 'calc-evalto)
499
500 (define-key calc-mode-map "t" nil)
501 (define-key calc-mode-map "t?" 'calc-t-prefix-help)
502 (define-key calc-mode-map "tb" 'calc-trail-backward)
503 (define-key calc-mode-map "td" 'calc-trail-display)
504 (define-key calc-mode-map "tf" 'calc-trail-forward)
505 (define-key calc-mode-map "th" 'calc-trail-here)
506 (define-key calc-mode-map "ti" 'calc-trail-in)
507 (define-key calc-mode-map "tk" 'calc-trail-kill)
508 (define-key calc-mode-map "tm" 'calc-trail-marker)
509 (define-key calc-mode-map "tn" 'calc-trail-next)
510 (define-key calc-mode-map "to" 'calc-trail-out)
511 (define-key calc-mode-map "tp" 'calc-trail-previous)
512 (define-key calc-mode-map "tr" 'calc-trail-isearch-backward)
513 (define-key calc-mode-map "ts" 'calc-trail-isearch-forward)
514 (define-key calc-mode-map "ty" 'calc-trail-yank)
515 (define-key calc-mode-map "t[" 'calc-trail-first)
516 (define-key calc-mode-map "t]" 'calc-trail-last)
517 (define-key calc-mode-map "t<" 'calc-trail-scroll-left)
518 (define-key calc-mode-map "t>" 'calc-trail-scroll-right)
519 (define-key calc-mode-map "t{" 'calc-trail-backward)
520 (define-key calc-mode-map "t}" 'calc-trail-forward)
521 (define-key calc-mode-map "t." 'calc-full-trail-vectors)
522 (define-key calc-mode-map "tC" 'calc-convert-time-zones)
523 (define-key calc-mode-map "tD" 'calc-date)
524 (define-key calc-mode-map "tI" 'calc-inc-month)
525 (define-key calc-mode-map "tJ" 'calc-julian)
526 (define-key calc-mode-map "tM" 'calc-new-month)
527 (define-key calc-mode-map "tN" 'calc-now)
528 (define-key calc-mode-map "tP" 'calc-date-part)
529 (define-key calc-mode-map "tT" 'calc-tan)
530 (define-key calc-mode-map "tU" 'calc-unix-time)
531 (define-key calc-mode-map "tW" 'calc-new-week)
532 (define-key calc-mode-map "tY" 'calc-new-year)
533 (define-key calc-mode-map "tZ" 'calc-time-zone)
534 (define-key calc-mode-map "t+" 'calc-business-days-plus)
535 (define-key calc-mode-map "t-" 'calc-business-days-minus)
536
537 (define-key calc-mode-map "u" 'nil)
538 (define-key calc-mode-map "u?" 'calc-u-prefix-help)
539 (define-key calc-mode-map "ua" 'calc-autorange-units)
540 (define-key calc-mode-map "ub" 'calc-base-units)
541 (define-key calc-mode-map "uc" 'calc-convert-units)
542 (define-key calc-mode-map "ud" 'calc-define-unit)
543 (define-key calc-mode-map "ue" 'calc-explain-units)
544 (define-key calc-mode-map "ug" 'calc-get-unit-definition)
545 (define-key calc-mode-map "up" 'calc-permanent-units)
546 (define-key calc-mode-map "ur" 'calc-remove-units)
547 (define-key calc-mode-map "us" 'calc-simplify-units)
548 (define-key calc-mode-map "ut" 'calc-convert-temperature)
549 (define-key calc-mode-map "uu" 'calc-undefine-unit)
550 (define-key calc-mode-map "uv" 'calc-enter-units-table)
551 (define-key calc-mode-map "ux" 'calc-extract-units)
552 (define-key calc-mode-map "uV" 'calc-view-units-table)
553 (define-key calc-mode-map "uC" 'calc-vector-covariance)
554 (define-key calc-mode-map "uG" 'calc-vector-geometric-mean)
555 (define-key calc-mode-map "uM" 'calc-vector-mean)
556 (define-key calc-mode-map "uN" 'calc-vector-min)
557 (define-key calc-mode-map "uS" 'calc-vector-sdev)
558 (define-key calc-mode-map "uU" 'calc-undo)
559 (define-key calc-mode-map "uX" 'calc-vector-max)
560 (define-key calc-mode-map "u#" 'calc-vector-count)
561 (define-key calc-mode-map "u+" 'calc-vector-sum)
562 (define-key calc-mode-map "u*" 'calc-vector-product)
563
564 (define-key calc-mode-map "v" 'nil)
565 (define-key calc-mode-map "v?" 'calc-v-prefix-help)
566 (define-key calc-mode-map "va" 'calc-arrange-vector)
567 (define-key calc-mode-map "vb" 'calc-build-vector)
568 (define-key calc-mode-map "vc" 'calc-mcol)
569 (define-key calc-mode-map "vd" 'calc-diag)
570 (define-key calc-mode-map "ve" 'calc-expand-vector)
571 (define-key calc-mode-map "vf" 'calc-vector-find)
572 (define-key calc-mode-map "vh" 'calc-head)
573 (define-key calc-mode-map "vi" 'calc-ident)
574 (define-key calc-mode-map "vk" 'calc-cons)
575 (define-key calc-mode-map "vl" 'calc-vlength)
576 (define-key calc-mode-map "vm" 'calc-mask-vector)
577 (define-key calc-mode-map "vn" 'calc-rnorm)
578 (define-key calc-mode-map "vp" 'calc-pack)
579 (define-key calc-mode-map "vr" 'calc-mrow)
580 (define-key calc-mode-map "vs" 'calc-subvector)
581 (define-key calc-mode-map "vt" 'calc-transpose)
582 (define-key calc-mode-map "vu" 'calc-unpack)
583 (define-key calc-mode-map "vv" 'calc-reverse-vector)
584 (define-key calc-mode-map "vx" 'calc-index)
585 (define-key calc-mode-map "vA" 'calc-apply)
586 (define-key calc-mode-map "vC" 'calc-cross)
587 (define-key calc-mode-map "vD" 'calc-mdet)
588 (define-key calc-mode-map "vE" 'calc-set-enumerate)
589 (define-key calc-mode-map "vF" 'calc-set-floor)
590 (define-key calc-mode-map "vG" 'calc-grade)
591 (define-key calc-mode-map "vH" 'calc-histogram)
592 (define-key calc-mode-map "vI" 'calc-inner-product)
593 (define-key calc-mode-map "vJ" 'calc-conj-transpose)
594 (define-key calc-mode-map "vL" 'calc-mlud)
595 (define-key calc-mode-map "vM" 'calc-map)
596 (define-key calc-mode-map "vN" 'calc-cnorm)
597 (define-key calc-mode-map "vO" 'calc-outer-product)
598 (define-key calc-mode-map "vR" 'calc-reduce)
599 (define-key calc-mode-map "vS" 'calc-sort)
600 (define-key calc-mode-map "vT" 'calc-mtrace)
601 (define-key calc-mode-map "vU" 'calc-accumulate)
602 (define-key calc-mode-map "vV" 'calc-set-union)
603 (define-key calc-mode-map "vX" 'calc-set-xor)
604 (define-key calc-mode-map "v^" 'calc-set-intersect)
605 (define-key calc-mode-map "v-" 'calc-set-difference)
606 (define-key calc-mode-map "v~" 'calc-set-complement)
607 (define-key calc-mode-map "v:" 'calc-set-span)
608 (define-key calc-mode-map "v#" 'calc-set-cardinality)
609 (define-key calc-mode-map "v+" 'calc-remove-duplicates)
610 (define-key calc-mode-map "v&" 'calc-inv)
611 (define-key calc-mode-map "v<" 'calc-matrix-left-justify)
612 (define-key calc-mode-map "v=" 'calc-matrix-center-justify)
613 (define-key calc-mode-map "v>" 'calc-matrix-right-justify)
614 (define-key calc-mode-map "v." 'calc-full-vectors)
615 (define-key calc-mode-map "v/" 'calc-break-vectors)
616 (define-key calc-mode-map "v," 'calc-vector-commas)
617 (define-key calc-mode-map "v[" 'calc-vector-brackets)
618 (define-key calc-mode-map "v]" 'calc-matrix-brackets)
619 (define-key calc-mode-map "v{" 'calc-vector-braces)
620 (define-key calc-mode-map "v}" 'calc-matrix-brackets)
621 (define-key calc-mode-map "v(" 'calc-vector-parens)
622 (define-key calc-mode-map "v)" 'calc-matrix-brackets)
623 ;; We can't rely on the automatic upper->lower conversion because
624 ;; in the global map V is explicitly bound, so we need to bind it
625 ;; explicitly as well :-( --stef
626 (define-key calc-mode-map "V" (lookup-key calc-mode-map "v"))
627
628 (define-key calc-mode-map "z" 'nil)
629 (define-key calc-mode-map "z?" 'calc-z-prefix-help)
630
631 (define-key calc-mode-map "Z" 'nil)
632 (define-key calc-mode-map "Z?" 'calc-shift-Z-prefix-help)
633 (define-key calc-mode-map "ZC" 'calc-user-define-composition)
634 (define-key calc-mode-map "ZD" 'calc-user-define)
635 (define-key calc-mode-map "ZE" 'calc-user-define-edit)
636 (define-key calc-mode-map "ZF" 'calc-user-define-formula)
637 (define-key calc-mode-map "ZG" 'calc-get-user-defn)
638 (define-key calc-mode-map "ZI" 'calc-user-define-invocation)
639 (define-key calc-mode-map "ZK" 'calc-user-define-kbd-macro)
640 (define-key calc-mode-map "ZP" 'calc-user-define-permanent)
641 (define-key calc-mode-map "ZS" 'calc-edit-user-syntax)
642 (define-key calc-mode-map "ZT" 'calc-timing)
643 (define-key calc-mode-map "ZU" 'calc-user-undefine)
644 (define-key calc-mode-map "Z[" 'calc-kbd-if)
645 (define-key calc-mode-map "Z:" 'calc-kbd-else)
646 (define-key calc-mode-map "Z|" 'calc-kbd-else-if)
647 (define-key calc-mode-map "Z]" 'calc-kbd-end-if)
648 (define-key calc-mode-map "Z<" 'calc-kbd-repeat)
649 (define-key calc-mode-map "Z>" 'calc-kbd-end-repeat)
650 (define-key calc-mode-map "Z(" 'calc-kbd-for)
651 (define-key calc-mode-map "Z)" 'calc-kbd-end-for)
652 (define-key calc-mode-map "Z{" 'calc-kbd-loop)
653 (define-key calc-mode-map "Z}" 'calc-kbd-end-loop)
654 (define-key calc-mode-map "Z/" 'calc-kbd-break)
655 (define-key calc-mode-map "Z`" 'calc-kbd-push)
656 (define-key calc-mode-map "Z'" 'calc-kbd-pop)
657 (define-key calc-mode-map "Z=" 'calc-kbd-report)
658 (define-key calc-mode-map "Z#" 'calc-kbd-query)
659
660 (calc-init-prefixes)
661
662 (mapc (function
663 (lambda (x)
664 (define-key calc-mode-map (format "c%c" x) 'calc-clean-num)
665 (define-key calc-mode-map (format "j%c" x) 'calc-select-part)
666 (define-key calc-mode-map (format "r%c" x) 'calc-recall-quick)
667 (define-key calc-mode-map (format "s%c" x) 'calc-store-quick)
668 (define-key calc-mode-map (format "t%c" x) 'calc-store-into-quick)
669 (define-key calc-mode-map (format "u%c" x) 'calc-quick-units)))
670 "0123456789")
671
672 (let ((i ?A))
673 (while (<= i ?z)
674 (if (eq (car-safe (aref (nth 1 calc-mode-map) i)) 'keymap)
675 (aset (nth 1 calc-mode-map) i
676 (cons 'keymap (cons (cons ?\e (aref (nth 1 calc-mode-map) i))
677 (cdr (aref (nth 1 calc-mode-map) i))))))
678 (setq i (1+ i))))
679
680 (setq calc-alg-map (copy-keymap calc-mode-map)
681 calc-alg-esc-map (copy-keymap esc-map))
682 (let ((i 32))
683 (while (< i 127)
684 (or (memq i '(?' ?` ?= ??))
685 (aset (nth 1 calc-alg-map) i 'calc-auto-algebraic-entry))
686 (or (memq i '(?# ?x ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
687 (aset (nth 1 calc-alg-esc-map) i (aref (nth 1 calc-mode-map) i)))
688 (setq i (1+ i))))
689 (define-key calc-alg-map "\e" calc-alg-esc-map)
690 (define-key calc-alg-map "\e\t" 'calc-roll-up)
691 (define-key calc-alg-map "\e\C-m" 'calc-last-args-stub)
692 (define-key calc-alg-map "\e\177" 'calc-pop-above)
693
694 ;;;; (Autoloads here)
695 (mapc (function (lambda (x)
696 (mapcar (function (lambda (func)
697 (autoload func (car x)))) (cdr x))))
698 '(
699
700 ("calc-alg" calc-has-rules math-defsimplify
701 calc-modify-simplify-mode calcFunc-collect calcFunc-esimplify
702 calcFunc-islin calcFunc-islinnt calcFunc-lin calcFunc-linnt
703 calcFunc-simplify calcFunc-subst calcFunc-powerexpand math-beforep
704 math-build-polynomial-expr math-expand-formula math-expr-contains
705 math-expr-contains-count math-expr-depends math-expr-height
706 math-expr-subst math-expr-weight math-integer-plus math-is-linear
707 math-is-multiple math-is-polynomial math-linear-in math-multiple-of
708 math-poly-depends math-poly-mix math-poly-mul
709 math-poly-simplify math-poly-zerop math-polynomial-base
710 math-polynomial-p math-recompile-eval-rules math-simplify
711 math-simplify-exp math-simplify-extended math-simplify-sqrt
712 math-to-simple-fraction)
713
714 ("calcalg2" calcFunc-asum calcFunc-deriv
715 calcFunc-ffinv calcFunc-finv calcFunc-fsolve calcFunc-gpoly
716 calcFunc-integ calcFunc-poly calcFunc-prod calcFunc-roots
717 calcFunc-solve calcFunc-sum calcFunc-table calcFunc-taylor
718 calcFunc-tderiv math-expr-calls math-integral-q02 math-integral-q12
719 math-integral-rational-funcs math-lcm-denoms math-looks-evenp
720 math-poly-all-roots math-prod-rec math-reject-solution math-solve-eqn
721 math-solve-for math-sum-rec math-try-integral)
722
723 ("calcalg3" calcFunc-efit calcFunc-fit
724 calcFunc-fitdummy calcFunc-fitparam calcFunc-fitvar
725 calcFunc-hasfitparams calcFunc-hasfitvars calcFunc-maximize
726 calcFunc-minimize calcFunc-ninteg calcFunc-polint calcFunc-ratint
727 calcFunc-root calcFunc-wmaximize calcFunc-wminimize calcFunc-wroot
728 calcFunc-xfit math-find-minimum math-find-root math-ninteg-evaluate
729 math-ninteg-midpoint math-ninteg-romberg math-poly-interp)
730
731 ("calc-arith" calcFunc-abs calcFunc-abssqr
732 calcFunc-add calcFunc-ceil calcFunc-decr calcFunc-deven calcFunc-dimag
733 calcFunc-dint calcFunc-div calcFunc-dnatnum calcFunc-dneg
734 calcFunc-dnonneg calcFunc-dnonzero calcFunc-dnumint calcFunc-dodd
735 calcFunc-dpos calcFunc-drange calcFunc-drat calcFunc-dreal
736 calcFunc-dscalar calcFunc-fceil calcFunc-ffloor calcFunc-float
737 calcFunc-fround calcFunc-frounde calcFunc-froundu calcFunc-ftrunc
738 calcFunc-idiv calcFunc-incr calcFunc-ldiv calcFunc-mant calcFunc-max calcFunc-min
739 calcFunc-mod calcFunc-mul calcFunc-neg calcFunc-percent calcFunc-pow
740 calcFunc-relch calcFunc-round calcFunc-rounde calcFunc-roundu
741 calcFunc-scf calcFunc-sub calcFunc-xpon math-abs math-abs-approx
742 math-add-objects-fancy math-add-or-sub math-add-symb-fancy
743 math-ceiling math-combine-prod math-combine-sum math-div-by-zero
744 math-div-objects-fancy math-div-symb-fancy math-div-zero
745 math-float-fancy math-floor-fancy math-floor-special math-guess-if-neg
746 math-intv-constp math-known-evenp math-known-imagp math-known-integerp
747 math-known-matrixp math-known-negp math-known-nonnegp
748 math-known-nonposp math-known-nonzerop math-known-num-integerp
749 math-known-oddp math-known-posp math-known-realp math-known-scalarp
750 math-max math-min math-mod-fancy math-mul-float math-mul-objects-fancy
751 math-mul-or-div math-mul-symb-fancy math-mul-zero math-neg-fancy
752 math-neg-float math-okay-neg math-possible-signs math-possible-types
753 math-pow-fancy math-pow-mod math-pow-of-zero math-pow-zero
754 math-quarter-integer math-round math-setup-declarations math-sqr
755 math-sqr-float math-trunc-fancy math-trunc-special)
756
757 ("calc-bin" calcFunc-and calcFunc-ash
758 calcFunc-clip calcFunc-diff calcFunc-lsh calcFunc-not calcFunc-or
759 calcFunc-rash calcFunc-rot calcFunc-rsh calcFunc-xor math-clip
760 math-compute-max-digits math-convert-radix-digits math-float-parts
761 math-format-bignum-binary math-format-bignum-hex
762 math-format-bignum-octal math-format-bignum-radix math-format-binary
763 math-format-radix math-format-radix-float math-integer-log2
764 math-power-of-2 math-radix-float-power)
765
766 ("calc-comb" calc-report-prime-test
767 calcFunc-choose calcFunc-dfact calcFunc-egcd calcFunc-fact
768 calcFunc-gcd calcFunc-lcm calcFunc-moebius calcFunc-nextprime
769 calcFunc-perm calcFunc-prevprime calcFunc-prfac calcFunc-prime
770 calcFunc-random calcFunc-shuffle calcFunc-stir1 calcFunc-stir2
771 calcFunc-totient math-init-random-base math-member math-prime-test
772 math-random-base)
773
774 ("calccomp" calcFunc-cascent calcFunc-cdescent
775 calcFunc-cheight calcFunc-cwidth math-comp-ascent math-comp-descent
776 math-comp-height math-comp-width math-compose-expr
777 math-composition-to-string math-stack-value-offset-fancy
778 math-vector-is-string math-vector-to-string)
779
780 ("calc-cplx" calcFunc-arg calcFunc-conj
781 calcFunc-im calcFunc-polar calcFunc-re calcFunc-rect math-complex
782 math-fix-circular math-imaginary math-imaginary-i math-normalize-polar
783 math-polar math-want-polar)
784
785 ("calc-embed" calc-do-embedded
786 calc-do-embedded-activate calc-embedded-evaluate-expr
787 calc-embedded-modes-change calc-embedded-var-change
788 calc-embedded-preserve-modes)
789
790 ("calc-fin" calc-to-percentage calcFunc-ddb
791 calcFunc-fv calcFunc-fvb calcFunc-fvl calcFunc-irr calcFunc-irrb
792 calcFunc-nper calcFunc-nperb calcFunc-nperl calcFunc-npv calcFunc-npvb
793 calcFunc-pmt calcFunc-pmtb calcFunc-pv calcFunc-pvb calcFunc-pvl
794 calcFunc-rate calcFunc-rateb calcFunc-ratel calcFunc-sln calcFunc-syd)
795
796 ("calc-forms" calcFunc-badd calcFunc-bsub
797 calcFunc-date calcFunc-day calcFunc-dsadj calcFunc-hms
798 calcFunc-holiday calcFunc-hour calcFunc-incmonth calcFunc-incyear
799 calcFunc-intv calcFunc-julian calcFunc-makemod calcFunc-minute
800 calcFunc-month calcFunc-newmonth calcFunc-newweek calcFunc-newyear
801 calcFunc-now calcFunc-pwday calcFunc-sdev calcFunc-second
802 calcFunc-time calcFunc-tzconv calcFunc-tzone calcFunc-unixtime
803 calcFunc-weekday calcFunc-year calcFunc-yearday math-combine-intervals
804 math-date-parts math-date-to-dt math-div-mod math-dt-to-date
805 math-format-date math-from-business-day math-from-hms math-make-intv
806 math-make-mod math-make-sdev math-mod-intv math-normalize-hms
807 math-normalize-mod math-parse-date math-read-angle-brackets
808 math-setup-add-holidays math-setup-holidays math-setup-year-holidays
809 math-sort-intv math-to-business-day math-to-hms)
810
811 ("calc-frac" calc-add-fractions
812 calc-div-fractions calc-mul-fractions calcFunc-fdiv calcFunc-frac
813 math-make-frac)
814
815 ("calc-funcs" calc-prob-dist calcFunc-bern
816 calcFunc-besJ calcFunc-besY calcFunc-beta calcFunc-betaB
817 calcFunc-betaI calcFunc-erf calcFunc-erfc calcFunc-euler
818 calcFunc-gamma calcFunc-gammaG calcFunc-gammaP calcFunc-gammaQ
819 calcFunc-gammag calcFunc-ltpb calcFunc-ltpc calcFunc-ltpf
820 calcFunc-ltpn calcFunc-ltpp calcFunc-ltpt calcFunc-utpb calcFunc-utpc
821 calcFunc-utpf calcFunc-utpn calcFunc-utpp calcFunc-utpt
822 math-bernoulli-number math-gammap1-raw)
823
824 ("calc-graph" calc-graph-show-tty)
825
826 ("calc-incom" calc-digit-dots)
827
828 ("calc-keypd" calc-do-keypad
829 calc-keypad-x-left-click calc-keypad-x-middle-click
830 calc-keypad-x-right-click)
831
832 ("calc-lang" calc-set-language
833 math-read-big-balance math-read-big-rec)
834
835 ("calc-map" calc-get-operator calcFunc-accum
836 calcFunc-afixp calcFunc-anest calcFunc-apply calcFunc-call
837 calcFunc-fixp calcFunc-inner calcFunc-map calcFunc-mapa calcFunc-mapc
838 calcFunc-mapd calcFunc-mapeq calcFunc-mapeqp calcFunc-mapeqr
839 calcFunc-mapr calcFunc-nest calcFunc-outer calcFunc-raccum
840 calcFunc-reduce calcFunc-reducea calcFunc-reducec calcFunc-reduced
841 calcFunc-reducer calcFunc-rreduce calcFunc-rreducea calcFunc-rreducec
842 calcFunc-rreduced calcFunc-rreducer math-build-call
843 math-calcFunc-to-var math-multi-subst math-multi-subst-rec
844 math-var-to-calcFunc)
845
846 ("calc-mtx" calcFunc-det calcFunc-lud calcFunc-tr
847 math-col-matrix math-lud-solve math-matrix-inv-raw math-matrix-lud
848 math-mul-mat-vec math-mul-mats math-row-matrix)
849
850 ("calc-math" calcFunc-alog calcFunc-arccos
851 calcFunc-arccosh calcFunc-arcsin calcFunc-arcsincos calcFunc-arcsinh
852 calcFunc-arctan calcFunc-arctan2 calcFunc-arctanh calcFunc-csc
853 calcFunc-csch calcFunc-cos calcFunc-cosh calcFunc-cot calcFunc-coth
854 calcFunc-deg calcFunc-exp calcFunc-exp10 calcFunc-expm1
855 calcFunc-hypot calcFunc-ilog calcFunc-isqrt calcFunc-ln calcFunc-lnp1
856 calcFunc-log calcFunc-log10 calcFunc-nroot calcFunc-rad calcFunc-sec
857 calcFunc-sech calcFunc-sin
858 calcFunc-sincos calcFunc-sinh calcFunc-sqr calcFunc-sqrt calcFunc-tan
859 calcFunc-tanh math-arccos-raw math-arcsin-raw math-arctan-raw
860 math-arctan2-raw math-cos-raw math-cot-raw math-csc-raw
861 math-exp-minus-1-raw math-exp-raw
862 math-from-radians math-from-radians-2 math-hypot math-infinite-dir
863 math-isqrt-small math-ln-raw math-nearly-equal math-nearly-equal-float
864 math-nearly-zerop math-nearly-zerop-float math-nth-root
865 math-sin-cos-raw math-sin-raw math-sqrt math-sqrt-float math-sqrt-raw
866 math-tan-raw math-to-radians math-to-radians-2)
867
868 ("calc-mode" math-get-modes-vec)
869
870 ("calc-poly" calcFunc-apart calcFunc-expand
871 calcFunc-expandpow calcFunc-factor calcFunc-factors calcFunc-nrat
872 calcFunc-pcont calcFunc-pdeg calcFunc-pdiv calcFunc-pdivide
873 calcFunc-pdivrem calcFunc-pgcd calcFunc-plead calcFunc-pprim
874 calcFunc-prem math-accum-factors math-atomic-factorp
875 math-div-poly-const math-div-thru math-expand-power math-expand-term
876 math-factor-contains math-factor-expr math-factor-expr-part
877 math-factor-expr-try math-factor-finish math-factor-poly-coefs
878 math-factor-protect math-mul-thru math-padded-polynomial
879 math-partial-fractions math-poly-degree math-poly-deriv-coefs
880 math-poly-gcd-frac-list math-poly-modulus-rec math-ratpoly-p
881 math-to-ratpoly math-to-ratpoly-rec)
882
883 ("calc-prog" calc-default-formula-arglist
884 calc-execute-kbd-macro calc-finish-user-syntax-edit
885 calc-fix-token-name calc-fix-user-formula calc-read-parse-table
886 calc-read-parse-table-part calc-subsetp calc-write-parse-table
887 calc-write-parse-table-part calcFunc-constant calcFunc-eq calcFunc-geq
888 calcFunc-gt calcFunc-if calcFunc-in calcFunc-integer calcFunc-istrue
889 calcFunc-land calcFunc-leq calcFunc-lnot calcFunc-lor calcFunc-lt
890 calcFunc-negative calcFunc-neq calcFunc-nonvar calcFunc-real
891 calcFunc-refers calcFunc-rmeq calcFunc-typeof calcFunc-variable
892 math-body-refers-to math-break math-composite-inequalities
893 math-do-defmath math-handle-for math-handle-foreach
894 math-normalize-logical-op math-return)
895
896 ("calc-rewr" calcFunc-match calcFunc-matches
897 calcFunc-matchnot calcFunc-rewrite calcFunc-vmatches
898 math-apply-rewrites math-compile-patterns math-compile-rewrites
899 math-flatten-lands math-match-patterns math-rewrite
900 math-rewrite-heads)
901
902 ("calc-rules" calc-CommuteRules calc-DistribRules calc-FactorRules
903 calc-FitRules calc-IntegAfterRules calc-InvertRules calc-JumpRules
904 calc-MergeRules calc-NegateRules
905 calc-compile-rule-set)
906
907 ("calc-sel" calc-auto-selection
908 calc-delete-selection calc-encase-atoms calc-find-assoc-parent-formula
909 calc-find-parent-formula calc-find-sub-formula calc-prepare-selection
910 calc-preserve-point calc-replace-selections calc-replace-sub-formula
911 calc-roll-down-with-selections calc-roll-up-with-selections
912 calc-sel-error)
913
914 ("calc-stat" calc-vector-op calcFunc-agmean
915 calcFunc-vcorr calcFunc-vcount calcFunc-vcov calcFunc-vflat
916 calcFunc-vgmean calcFunc-vhmean calcFunc-vmax calcFunc-vmean
917 calcFunc-vmeane calcFunc-vmedian calcFunc-vmin calcFunc-vpcov
918 calcFunc-vprod calcFunc-vpsdev calcFunc-vpvar calcFunc-vsdev
919 calcFunc-vsum calcFunc-vvar math-flatten-many-vecs)
920
921 ("calc-store" calc-read-var-name
922 calc-store-value calc-var-name)
923
924 ("calc-stuff" calc-explain-why calcFunc-clean
925 calcFunc-pclean calcFunc-pfloat calcFunc-pfrac)
926
927 ("calc-units" calcFunc-usimplify
928 math-build-units-table math-build-units-table-buffer
929 math-check-unit-name math-convert-temperature math-convert-units
930 math-extract-units math-remove-units math-simplify-units
931 math-single-units-in-expr-p math-to-standard-units
932 math-units-in-expr-p)
933
934 ("calc-vec" calcFunc-append calcFunc-appendrev
935 calcFunc-arrange calcFunc-cnorm calcFunc-cons calcFunc-cross
936 calcFunc-ctrn calcFunc-cvec calcFunc-diag calcFunc-find
937 calcFunc-getdiag calcFunc-grade calcFunc-head calcFunc-histogram
938 calcFunc-idn calcFunc-index calcFunc-mcol calcFunc-mdims
939 calcFunc-mrcol calcFunc-mrow calcFunc-mrrow calcFunc-pack
940 calcFunc-rcons calcFunc-rdup calcFunc-rev calcFunc-rgrade
941 calcFunc-rhead calcFunc-rnorm calcFunc-rsort calcFunc-rsubvec
942 calcFunc-rtail calcFunc-sort calcFunc-subscr calcFunc-subvec
943 calcFunc-tail calcFunc-trn calcFunc-unpack calcFunc-unpackt
944 calcFunc-vcard calcFunc-vcompl calcFunc-vconcat calcFunc-vconcatrev
945 calcFunc-vdiff calcFunc-vec calcFunc-venum calcFunc-vexp
946 calcFunc-vfloor calcFunc-vint calcFunc-vlen calcFunc-vmask
947 calcFunc-vpack calcFunc-vspan calcFunc-vunion calcFunc-vunpack
948 calcFunc-vxor math-check-for-commas math-clean-set math-copy-matrix
949 math-dimension-error math-dot-product math-flatten-vector math-map-vec
950 math-map-vec-2 math-mat-col math-mimic-ident math-prepare-set
951 math-read-brackets math-reduce-cols math-reduce-vec math-transpose)
952
953 ("calc-yank" calc-alg-edit calc-clean-newlines
954 calc-do-grab-rectangle calc-do-grab-region calc-finish-stack-edit
955 calc-force-refresh calc-locate-cursor-element calc-show-edit-buffer)
956
957 ))
958
959 (mapcar (function (lambda (x)
960 (mapcar (function (lambda (cmd)
961 (autoload cmd (car x) nil t))) (cdr x))))
962 '(
963
964 ("calc-alg" calc-alg-evaluate calc-apart calc-collect calc-expand
965 calc-expand-formula calc-factor calc-normalize-rat calc-poly-div
966 calc-poly-div-rem calc-poly-gcd calc-poly-rem calc-simplify
967 calc-simplify-extended calc-substitute calc-powerexpand)
968
969 ("calcalg2" calc-alt-summation calc-derivative
970 calc-dump-integral-cache calc-integral calc-num-integral
971 calc-poly-roots calc-product calc-solve-for calc-summation
972 calc-tabulate calc-taylor)
973
974 ("calcalg3" calc-curve-fit calc-find-maximum calc-find-minimum
975 calc-find-root calc-poly-interp)
976
977 ("calc-arith" calc-abs calc-abssqr calc-ceiling calc-decrement
978 calc-floor calc-idiv calc-increment calc-mant-part calc-max calc-min
979 calc-round calc-scale-float calc-sign calc-trunc calc-xpon-part)
980
981 ("calc-bin" calc-and calc-binary-radix calc-clip calc-decimal-radix
982 calc-diff calc-hex-radix calc-leading-zeros calc-lshift-arith
983 calc-lshift-binary calc-not calc-octal-radix calc-or calc-radix
984 calc-rotate-binary calc-rshift-arith calc-rshift-binary calc-word-size
985 calc-xor)
986
987 ("calc-comb" calc-choose calc-double-factorial calc-extended-gcd
988 calc-factorial calc-gamma calc-gcd calc-lcm calc-moebius
989 calc-next-prime calc-perm calc-prev-prime calc-prime-factors
990 calc-prime-test calc-random calc-random-again calc-rrandom
991 calc-shuffle calc-totient)
992
993 ("calc-cplx" calc-argument calc-complex-notation calc-i-notation
994 calc-im calc-j-notation calc-polar calc-polar-mode calc-re)
995
996 ("calc-embed" calc-embedded-copy-formula-as-kill
997 calc-embedded-duplicate calc-embedded-edit calc-embedded-forget
998 calc-embedded-kill-formula calc-embedded-mark-formula
999 calc-embedded-new-formula calc-embedded-next calc-embedded-previous
1000 calc-embedded-select calc-embedded-update-formula calc-embedded-word
1001 calc-find-globals calc-show-plain)
1002
1003 ("calc-fin" calc-convert-percent calc-fin-ddb calc-fin-fv
1004 calc-fin-irr calc-fin-nper calc-fin-npv calc-fin-pmt calc-fin-pv
1005 calc-fin-rate calc-fin-sln calc-fin-syd calc-percent-change)
1006
1007 ("calc-forms" calc-business-days-minus calc-business-days-plus
1008 calc-convert-time-zones calc-date calc-date-notation calc-date-part
1009 calc-from-hms calc-hms-mode calc-hms-notation calc-inc-month
1010 calc-julian calc-new-month calc-new-week calc-new-year calc-now
1011 calc-time calc-time-zone calc-to-hms calc-unix-time)
1012
1013 ("calc-frac" calc-fdiv calc-frac-mode calc-fraction
1014 calc-over-notation calc-slash-notation)
1015
1016 ("calc-funcs" calc-bernoulli-number calc-bessel-J calc-bessel-Y
1017 calc-beta calc-erf calc-erfc calc-euler-number calc-inc-beta
1018 calc-inc-gamma calc-stirling-number calc-utpb calc-utpc calc-utpf
1019 calc-utpn calc-utpp calc-utpt)
1020
1021 ("calc-graph" calc-graph-add calc-graph-add-3d calc-graph-border
1022 calc-graph-clear calc-graph-command calc-graph-delete
1023 calc-graph-device calc-graph-display calc-graph-fast
1024 calc-graph-fast-3d calc-graph-geometry calc-graph-grid
1025 calc-graph-header calc-graph-hide calc-graph-juggle calc-graph-key
1026 calc-graph-kill calc-graph-line-style calc-graph-log-x
1027 calc-graph-log-y calc-graph-log-z calc-graph-name
1028 calc-graph-num-points calc-graph-output calc-graph-plot
1029 calc-graph-point-style calc-graph-print calc-graph-quit
1030 calc-graph-range-x calc-graph-range-y calc-graph-range-z
1031 calc-graph-show-dumb calc-graph-title-x calc-graph-title-y
1032 calc-graph-title-z calc-graph-view-commands calc-graph-view-trail
1033 calc-graph-zero-x calc-graph-zero-y)
1034
1035 ("calc-help" calc-a-prefix-help calc-b-prefix-help calc-c-prefix-help
1036 calc-d-prefix-help calc-describe-function calc-describe-key
1037 calc-describe-key-briefly calc-describe-variable calc-f-prefix-help
1038 calc-full-help calc-g-prefix-help calc-help-prefix
1039 calc-hyperbolic-prefix-help calc-inv-hyp-prefix-help
1040 calc-inverse-prefix-help calc-j-prefix-help calc-k-prefix-help
1041 calc-m-prefix-help calc-r-prefix-help calc-s-prefix-help
1042 calc-t-prefix-help calc-u-prefix-help calc-v-prefix-help)
1043
1044 ("calc-incom" calc-begin-complex calc-begin-vector calc-comma
1045 calc-dots calc-end-complex calc-end-vector calc-semi)
1046
1047 ("calc-keypd" calc-keypad-menu calc-keypad-menu-back
1048 calc-keypad-press)
1049
1050 ("calc-lang" calc-big-language calc-c-language calc-eqn-language
1051 calc-flat-language calc-fortran-language calc-maple-language
1052 calc-mathematica-language calc-normal-language calc-pascal-language
1053 calc-tex-language calc-latex-language calc-unformatted-language)
1054
1055 ("calc-map" calc-accumulate calc-apply calc-inner-product calc-map
1056 calc-map-equation calc-map-stack calc-outer-product calc-reduce)
1057
1058 ("calc-mtx" calc-mdet calc-mlud calc-mtrace)
1059
1060 ("calc-math" calc-arccos calc-arccosh calc-arcsin calc-arcsinh
1061 calc-arctan calc-arctan2 calc-arctanh calc-conj calc-cos calc-cosh
1062 calc-cot calc-coth calc-csc calc-csch
1063 calc-degrees-mode calc-exp calc-expm1 calc-hypot calc-ilog
1064 calc-imaginary calc-isqrt calc-ln calc-lnp1 calc-log calc-log10
1065 calc-pi calc-radians-mode calc-sec calc-sech
1066 calc-sin calc-sincos calc-sinh calc-sqrt
1067 calc-tan calc-tanh calc-to-degrees calc-to-radians)
1068
1069 ("calc-mode" calc-alg-simplify-mode calc-algebraic-mode
1070 calc-always-load-extensions calc-auto-recompute calc-auto-why
1071 calc-bin-simplify-mode calc-break-vectors calc-center-justify
1072 calc-default-simplify-mode calc-display-raw calc-eng-notation
1073 calc-ext-simplify-mode calc-fix-notation calc-full-trail-vectors
1074 calc-full-vectors calc-get-modes calc-group-char calc-group-digits
1075 calc-infinite-mode calc-left-justify calc-left-label
1076 calc-line-breaking calc-line-numbering calc-matrix-brackets
1077 calc-matrix-center-justify calc-matrix-left-justify calc-matrix-mode
1078 calc-matrix-right-justify calc-mode-record-mode calc-no-simplify-mode
1079 calc-normal-notation calc-num-simplify-mode calc-point-char
1080 calc-right-justify calc-right-label calc-save-modes calc-sci-notation
1081 calc-settings-file-name calc-shift-prefix calc-symbolic-mode
1082 calc-total-algebraic-mode calc-truncate-down calc-truncate-stack
1083 calc-truncate-up calc-units-simplify-mode calc-vector-braces
1084 calc-vector-brackets calc-vector-commas calc-vector-parens
1085 calc-working)
1086
1087 ("calc-prog" calc-call-last-kbd-macro calc-edit-user-syntax
1088 calc-equal-to calc-get-user-defn calc-greater-equal calc-greater-than
1089 calc-in-set calc-kbd-break calc-kbd-else calc-kbd-else-if
1090 calc-kbd-end-for calc-kbd-end-if calc-kbd-end-loop calc-kbd-end-repeat
1091 calc-kbd-for calc-kbd-if calc-kbd-loop calc-kbd-pop calc-kbd-push
1092 calc-kbd-query calc-kbd-repeat calc-kbd-report calc-less-equal
1093 calc-less-than calc-logical-and calc-logical-if calc-logical-not
1094 calc-logical-or calc-not-equal-to calc-pass-errors calc-remove-equal
1095 calc-timing calc-user-define calc-user-define-composition
1096 calc-user-define-edit calc-user-define-formula
1097 calc-user-define-invocation calc-user-define-kbd-macro
1098 calc-user-define-permanent calc-user-undefine)
1099
1100 ("calc-rewr" calc-match calc-rewrite calc-rewrite-selection)
1101
1102 ("calc-sel" calc-break-selections calc-clear-selections
1103 calc-copy-selection calc-del-selection calc-edit-selection
1104 calc-enable-selections calc-enter-selection calc-sel-add-both-sides
1105 calc-sel-div-both-sides calc-sel-evaluate calc-sel-expand-formula
1106 calc-sel-mult-both-sides calc-sel-sub-both-sides
1107 calc-select-additional calc-select-here calc-select-here-maybe
1108 calc-select-less calc-select-more calc-select-next calc-select-once
1109 calc-select-once-maybe calc-select-part calc-select-previous
1110 calc-show-selections calc-unselect)
1111
1112 ("calcsel2" calc-commute-left calc-commute-right calc-sel-commute
1113 calc-sel-distribute calc-sel-invert calc-sel-isolate
1114 calc-sel-jump-equals calc-sel-merge calc-sel-negate calc-sel-unpack)
1115
1116 ("calc-stat" calc-vector-correlation calc-vector-count
1117 calc-vector-covariance calc-vector-geometric-mean
1118 calc-vector-harmonic-mean calc-vector-max calc-vector-mean
1119 calc-vector-mean-error calc-vector-median calc-vector-min
1120 calc-vector-pop-covariance calc-vector-pop-sdev
1121 calc-vector-pop-variance calc-vector-product calc-vector-sdev
1122 calc-vector-sum calc-vector-variance)
1123
1124 ("calc-store" calc-assign calc-copy-special-constant
1125 calc-copy-variable calc-declare-variable
1126 calc-edit-AlgSimpRules calc-edit-Decls calc-edit-EvalRules
1127 calc-edit-ExtSimpRules calc-edit-FitRules calc-edit-GenCount
1128 calc-edit-Holidays calc-edit-IntegLimit calc-edit-LineStyles
1129 calc-edit-PlotRejects calc-edit-PointStyles calc-edit-TimeZone
1130 calc-edit-Units calc-edit-variable calc-evalto calc-insert-variables
1131 calc-let calc-permanent-variable calc-recall calc-recall-quick
1132 calc-store calc-store-concat calc-store-decr calc-store-div
1133 calc-store-exchange calc-store-incr calc-store-into
1134 calc-store-into-quick calc-store-inv calc-store-map calc-store-minus
1135 calc-store-neg calc-store-plus calc-store-power calc-store-quick
1136 calc-store-times calc-subscript calc-unstore)
1137
1138 ("calc-stuff" calc-clean calc-clean-num calc-flush-caches
1139 calc-less-recursion-depth calc-more-recursion-depth calc-num-prefix
1140 calc-version calc-why)
1141
1142 ("calc-trail" calc-trail-backward calc-trail-first calc-trail-forward
1143 calc-trail-in calc-trail-isearch-backward calc-trail-isearch-forward
1144 calc-trail-kill calc-trail-last calc-trail-marker calc-trail-next
1145 calc-trail-out calc-trail-previous calc-trail-scroll-left
1146 calc-trail-scroll-right calc-trail-yank)
1147
1148 ("calc-undo" calc-last-args calc-redo calc-undo)
1149
1150 ("calc-units" calc-autorange-units calc-base-units
1151 calc-convert-temperature calc-convert-units calc-define-unit
1152 calc-enter-units-table calc-explain-units calc-extract-units
1153 calc-get-unit-definition calc-permanent-units calc-quick-units
1154 calc-remove-units calc-simplify-units calc-undefine-unit
1155 calc-view-units-table)
1156
1157 ("calc-vec" calc-arrange-vector calc-build-vector calc-cnorm
1158 calc-conj-transpose calc-cons calc-cross calc-diag
1159 calc-display-strings calc-expand-vector calc-grade calc-head
1160 calc-histogram calc-ident calc-index calc-mask-vector calc-mcol
1161 calc-mrow calc-pack calc-pack-bits calc-remove-duplicates
1162 calc-reverse-vector calc-rnorm calc-set-cardinality
1163 calc-set-complement calc-set-difference calc-set-enumerate
1164 calc-set-floor calc-set-intersect calc-set-span calc-set-union
1165 calc-set-xor calc-sort calc-subvector calc-tail calc-transpose
1166 calc-unpack calc-unpack-bits calc-vector-find calc-vlength)
1167
1168 ("calc-yank" calc-copy-as-kill calc-copy-region-as-kill
1169 calc-copy-to-buffer calc-edit calc-edit-cancel calc-edit-mode
1170 calc-kill calc-kill-region calc-yank))))
1171
1172 (defun calc-init-prefixes ()
1173 (if calc-shift-prefix
1174 (progn
1175 (define-key calc-mode-map "A" (lookup-key calc-mode-map "a"))
1176 (define-key calc-mode-map "B" (lookup-key calc-mode-map "b"))
1177 (define-key calc-mode-map "C" (lookup-key calc-mode-map "c"))
1178 (define-key calc-mode-map "D" (lookup-key calc-mode-map "d"))
1179 (define-key calc-mode-map "F" (lookup-key calc-mode-map "f"))
1180 (define-key calc-mode-map "G" (lookup-key calc-mode-map "g"))
1181 (define-key calc-mode-map "J" (lookup-key calc-mode-map "j"))
1182 (define-key calc-mode-map "K" (lookup-key calc-mode-map "k"))
1183 (define-key calc-mode-map "M" (lookup-key calc-mode-map "m"))
1184 (define-key calc-mode-map "S" (lookup-key calc-mode-map "s"))
1185 (define-key calc-mode-map "T" (lookup-key calc-mode-map "t"))
1186 (define-key calc-mode-map "U" (lookup-key calc-mode-map "u")))
1187 (define-key calc-mode-map "A" 'calc-abs)
1188 (define-key calc-mode-map "B" 'calc-log)
1189 (define-key calc-mode-map "C" 'calc-cos)
1190 (define-key calc-mode-map "D" 'calc-redo)
1191 (define-key calc-mode-map "F" 'calc-floor)
1192 (define-key calc-mode-map "G" 'calc-argument)
1193 (define-key calc-mode-map "J" 'calc-conj)
1194 (define-key calc-mode-map "K" 'calc-keep-args)
1195 (define-key calc-mode-map "M" 'calc-more-recursion-depth)
1196 (define-key calc-mode-map "S" 'calc-sin)
1197 (define-key calc-mode-map "T" 'calc-tan)
1198 (define-key calc-mode-map "U" 'calc-undo)))
1199
1200 (calc-init-extensions)
1201
1202
1203
1204
1205 ;;;; Miscellaneous.
1206
1207 ;; calc-command-flags is declared in calc.el
1208 (defvar calc-command-flags)
1209
1210 (defun calc-clear-command-flag (f)
1211 (setq calc-command-flags (delq f calc-command-flags)))
1212
1213
1214 (defun calc-record-message (tag &rest args)
1215 (let ((msg (apply 'format args)))
1216 (message "%s" msg)
1217 (calc-record msg tag))
1218 (calc-clear-command-flag 'clear-message))
1219
1220
1221 (defun calc-normalize-fancy (val)
1222 (let ((simp (if (consp calc-simplify-mode)
1223 (car calc-simplify-mode)
1224 calc-simplify-mode)))
1225 (cond ((eq simp 'binary)
1226 (let ((s (math-normalize val)))
1227 (if (math-realp s)
1228 (math-clip (math-round s))
1229 s)))
1230 ((eq simp 'alg)
1231 (math-simplify val))
1232 ((eq simp 'ext)
1233 (math-simplify-extended val))
1234 ((eq simp 'units)
1235 (math-simplify-units val))
1236 (t ; nil, none, num
1237 (math-normalize val)))))
1238
1239
1240 (defvar calc-help-map nil)
1241
1242 (if calc-help-map
1243 nil
1244 (setq calc-help-map (make-keymap))
1245 (define-key calc-help-map "b" 'calc-describe-bindings)
1246 (define-key calc-help-map "c" 'calc-describe-key-briefly)
1247 (define-key calc-help-map "f" 'calc-describe-function)
1248 (define-key calc-help-map "h" 'calc-full-help)
1249 (define-key calc-help-map "i" 'calc-info)
1250 (define-key calc-help-map "k" 'calc-describe-key)
1251 (define-key calc-help-map "n" 'calc-view-news)
1252 (define-key calc-help-map "s" 'calc-info-summary)
1253 (define-key calc-help-map "t" 'calc-tutorial)
1254 (define-key calc-help-map "v" 'calc-describe-variable)
1255 (define-key calc-help-map "\C-c" 'calc-describe-copying)
1256 (define-key calc-help-map "\C-d" 'calc-describe-distribution)
1257 (define-key calc-help-map "\C-n" 'calc-view-news)
1258 (define-key calc-help-map "\C-w" 'calc-describe-no-warranty)
1259 (define-key calc-help-map "?" 'calc-help-for-help)
1260 (define-key calc-help-map "\C-h" 'calc-help-for-help))
1261
1262 (defvar calc-prefix-help-phase 0)
1263 (defun calc-do-prefix-help (msgs group key)
1264 (if calc-full-help-flag
1265 (list msgs group key)
1266 (if (cdr msgs)
1267 (progn
1268 (setq calc-prefix-help-phase
1269 (if (eq this-command last-command)
1270 (% (1+ calc-prefix-help-phase) (1+ (length msgs)))
1271 0))
1272 (let ((msg (nth calc-prefix-help-phase msgs)))
1273 (message "%s" (if msg
1274 (concat group ": " msg ":"
1275 (make-string
1276 (- (apply 'max (mapcar 'length msgs))
1277 (length msg)) 32)
1278 " [MORE]"
1279 (if key
1280 (concat " " (char-to-string key)
1281 "-")
1282 ""))
1283 (if key (format "%c-" key) "")))))
1284 (setq calc-prefix-help-phase 0)
1285 (if key
1286 (if msgs
1287 (message "%s: %s: %c-" group (car msgs) key)
1288 (message "%s: (none) %c-" group key))
1289 (message "%s: %s" group (car msgs))))
1290 (and key (calc-unread-command key))))
1291
1292 ;;;; Commands.
1293
1294
1295 ;;; General.
1296
1297 (defun calc-reset (arg)
1298 (interactive "P")
1299 (setq arg (if arg (prefix-numeric-value arg) nil))
1300 (cond
1301 ((and
1302 calc-embedded-info
1303 (equal (aref calc-embedded-info 0) (current-buffer))
1304 (<= (point) (aref calc-embedded-info 5))
1305 (>= (point) (aref calc-embedded-info 4)))
1306 (let ((cbuf (aref calc-embedded-info 1))
1307 (calc-embedded-quiet t))
1308 (save-window-excursion
1309 (calc-embedded nil)
1310 (set-buffer cbuf)
1311 (calc-reset arg))
1312 (calc-embedded nil)))
1313 ((eq major-mode 'calc-mode)
1314 (save-excursion
1315 (unless (and arg (> (abs arg) 0))
1316 (setq calc-stack nil))
1317 (setq calc-undo-list nil
1318 calc-redo-list nil)
1319 (let (calc-stack calc-user-parse-tables calc-standard-date-formats
1320 calc-invocation-macro)
1321 (mapc (function (lambda (v) (set v nil))) calc-local-var-list)
1322 (if (and arg (<= arg 0))
1323 (calc-mode-var-list-restore-default-values)
1324 (calc-mode-var-list-restore-saved-values)))
1325 (calc-set-language nil nil t)
1326 (calc-mode)
1327 (calc-flush-caches t)
1328 (run-hooks 'calc-reset-hook))
1329 (calc-wrapper
1330 (let ((win (get-buffer-window (current-buffer))))
1331 (calc-realign 0)
1332 ;; Adjust the window height if the window is visible, but doesn't
1333 ;; take up the whole height of the frame.
1334 (if (and
1335 win
1336 (< (window-height win) (1- (frame-height))))
1337 (let ((height (- (window-height win) 2)))
1338 (set-window-point win (point))
1339 (or (= height calc-window-height)
1340 (let ((swin (selected-window)))
1341 (select-window win)
1342 (enlarge-window (- calc-window-height height))
1343 (select-window swin)))))))
1344 (message "(Calculator reset)"))
1345 (t
1346 (message "(Not inside a Calc buffer)"))))
1347
1348 ;; What a pain; scroll-left behaves differently when called non-interactively.
1349 (defun calc-scroll-left (n)
1350 (interactive "P")
1351 (setq prefix-arg (or n (/ (window-width) 2)))
1352 (call-interactively #'scroll-left))
1353
1354 (defun calc-scroll-right (n)
1355 (interactive "P")
1356 (setq prefix-arg (or n (/ (window-width) 2)))
1357 (call-interactively #'scroll-right))
1358
1359 (defun calc-scroll-up (n)
1360 (interactive "P")
1361 (condition-case err
1362 (scroll-up (or n (/ (window-height) 2)))
1363 (error nil))
1364 (if (pos-visible-in-window-p (max 1 (- (point-max) 2)))
1365 (if (eq major-mode 'calc-mode)
1366 (calc-realign)
1367 (goto-char (point-max))
1368 (set-window-start (selected-window)
1369 (save-excursion
1370 (forward-line (- (1- (window-height))))
1371 (point)))
1372 (forward-line -1))))
1373
1374 (defun calc-scroll-down (n)
1375 (interactive "P")
1376 (or (pos-visible-in-window-p 1)
1377 (scroll-down (or n (/ (window-height) 2)))))
1378
1379
1380 (defun calc-precision (n)
1381 (interactive "NPrecision: ")
1382 (calc-wrapper
1383 (if (< (prefix-numeric-value n) 3)
1384 (error "Precision must be at least 3 digits")
1385 (calc-change-mode 'calc-internal-prec (prefix-numeric-value n)
1386 (and (memq (car calc-float-format) '(float sci eng))
1387 (< (nth 1 calc-float-format)
1388 (if (= calc-number-radix 10) 0 1))))
1389 (calc-record calc-internal-prec "prec"))
1390 (message "Floating-point precision is %d digits" calc-internal-prec)))
1391
1392
1393 (defun calc-inverse (&optional n)
1394 (interactive "P")
1395 (let* ((hyp-flag (if (or
1396 (eq major-mode 'calc-keypad-mode)
1397 (eq major-mode 'calc-trail-mode))
1398 (with-current-buffer calc-main-buffer
1399 calc-hyperbolic-flag)
1400 calc-hyperbolic-flag))
1401 (msg (if hyp-flag
1402 "Inverse Hyperbolic..."
1403 "Inverse...")))
1404 (calc-fancy-prefix 'calc-inverse-flag msg n)))
1405
1406 (defconst calc-fancy-prefix-map
1407 (let ((map (make-sparse-keymap)))
1408 (define-key map [t] 'calc-fancy-prefix-other-key)
1409 (define-key map (vector meta-prefix-char t) 'calc-fancy-prefix-other-key)
1410 (define-key map [switch-frame] nil)
1411 (define-key map [?\C-u] 'universal-argument)
1412 (define-key map [?0] 'digit-argument)
1413 (define-key map [?1] 'digit-argument)
1414 (define-key map [?2] 'digit-argument)
1415 (define-key map [?3] 'digit-argument)
1416 (define-key map [?4] 'digit-argument)
1417 (define-key map [?5] 'digit-argument)
1418 (define-key map [?6] 'digit-argument)
1419 (define-key map [?7] 'digit-argument)
1420 (define-key map [?8] 'digit-argument)
1421 (define-key map [?9] 'digit-argument)
1422 map)
1423 "Keymap used while processing calc-fancy-prefix.")
1424
1425 (defvar calc-is-keypad-press nil)
1426 (defun calc-fancy-prefix (flag msg n)
1427 (let (prefix)
1428 (calc-wrapper
1429 (calc-set-command-flag 'keep-flags)
1430 (calc-set-command-flag 'no-align)
1431 (setq prefix (set flag (not (symbol-value flag)))
1432 prefix-arg n)
1433 (message (if prefix msg "")))
1434 (and prefix
1435 (not calc-is-keypad-press)
1436 (if (boundp 'overriding-terminal-local-map)
1437 (setq overriding-terminal-local-map calc-fancy-prefix-map)
1438 (let ((event (calc-read-key t)))
1439 (if (eq (setq last-command-char (car event)) ?\C-u)
1440 (universal-argument)
1441 (if (or (not (integerp last-command-char))
1442 (and (>= last-command-char 0) (< last-command-char ? )
1443 (not (memq last-command-char '(?\e)))))
1444 (calc-wrapper)) ; clear flags if not a Calc command.
1445 (setq last-command-event (cdr event))
1446 (if (or (not (integerp last-command-char))
1447 (eq last-command-char ?-))
1448 (calc-unread-command)
1449 (digit-argument n))))))))
1450
1451 (defun calc-fancy-prefix-other-key (arg)
1452 (interactive "P")
1453 (if (and
1454 (not (eq last-command-char 'tab))
1455 (not (eq last-command-char 'M-tab))
1456 (or (not (integerp last-command-char))
1457 (and (>= last-command-char 0) (< last-command-char ? )
1458 (not (eq last-command-char meta-prefix-char)))))
1459 (calc-wrapper)) ; clear flags if not a Calc command.
1460 (setq prefix-arg arg)
1461 (calc-unread-command)
1462 (setq overriding-terminal-local-map nil))
1463
1464 (defun calc-invert-func ()
1465 (save-excursion
1466 (calc-select-buffer)
1467 (setq calc-inverse-flag (not (calc-is-inverse))
1468 calc-hyperbolic-flag (calc-is-hyperbolic)
1469 current-prefix-arg nil)))
1470
1471 (defun calc-is-inverse ()
1472 calc-inverse-flag)
1473
1474 (defun calc-hyperbolic (&optional n)
1475 (interactive "P")
1476 (let* ((inv-flag (if (or
1477 (eq major-mode 'calc-keypad-mode)
1478 (eq major-mode 'calc-trail-mode))
1479 (with-current-buffer calc-main-buffer
1480 calc-inverse-flag)
1481 calc-inverse-flag))
1482 (msg (if inv-flag
1483 "Inverse Hyperbolic..."
1484 "Hyperbolic...")))
1485 (calc-fancy-prefix 'calc-hyperbolic-flag msg n)))
1486
1487 (defun calc-hyperbolic-func ()
1488 (save-excursion
1489 (calc-select-buffer)
1490 (setq calc-inverse-flag (calc-is-inverse)
1491 calc-hyperbolic-flag (not (calc-is-hyperbolic))
1492 current-prefix-arg nil)))
1493
1494 (defun calc-is-hyperbolic ()
1495 calc-hyperbolic-flag)
1496
1497 (defun calc-keep-args (&optional n)
1498 (interactive "P")
1499 (calc-fancy-prefix 'calc-keep-args-flag "Keep args..." n))
1500
1501
1502 (defun calc-change-mode (var value &optional refresh option)
1503 (if option
1504 (setq value (if value
1505 (> (prefix-numeric-value value) 0)
1506 (not (symbol-value var)))))
1507 (or (consp var) (setq var (list var) value (list value)))
1508 (if calc-inverse-flag
1509 (let ((old nil))
1510 (or refresh (error "Not a display-mode command"))
1511 (calc-check-stack 1)
1512 (unwind-protect
1513 (let ((v var))
1514 (while v
1515 (setq old (cons (symbol-value (car v)) old))
1516 (set (car v) (car value))
1517 (setq v (cdr v)
1518 value (cdr value)))
1519 (calc-refresh-top 1)
1520 (calc-refresh-evaltos)
1521 (symbol-value (car var)))
1522 (let ((v var))
1523 (setq old (nreverse old))
1524 (while v
1525 (set (car v) (car old))
1526 (setq v (cdr v)
1527 old (cdr old)))
1528 (if (eq (car var) 'calc-language)
1529 (calc-set-language calc-language calc-language-option t)))))
1530 (let ((chg nil)
1531 (v var))
1532 (while v
1533 (or (equal (symbol-value (car v)) (car value))
1534 (progn
1535 (set (car v) (car value))
1536 (if (eq (car v) 'calc-float-format)
1537 (setq calc-full-float-format
1538 (list (if (eq (car (car value)) 'fix)
1539 'float
1540 (car (car value)))
1541 0)))
1542 (setq chg t)))
1543 (setq v (cdr v)
1544 value (cdr value)))
1545 (if chg
1546 (progn
1547 (or (and refresh (calc-do-refresh))
1548 (calc-refresh-evaltos))
1549 (and (eq calc-mode-save-mode 'save)
1550 (not (equal var '(calc-mode-save-mode)))
1551 (calc-save-modes))))
1552 (if calc-embedded-info (calc-embedded-modes-change var))
1553 (symbol-value (car var)))))
1554
1555 (defun calc-toggle-banner ()
1556 "Toggle display of the friendly greeting calc normally shows above the stack."
1557 (interactive)
1558 (setq calc-show-banner (not calc-show-banner))
1559 (calc-refresh))
1560
1561 (defun calc-refresh-top (n)
1562 (interactive "p")
1563 (calc-wrapper
1564 (cond ((< n 0)
1565 (setq n (- n))
1566 (let ((entry (calc-top n 'entry))
1567 (calc-undo-list nil) (calc-redo-list nil))
1568 (calc-pop-stack 1 n t)
1569 (calc-push-list (list (car entry)) n (list (nth 2 entry)))))
1570 ((= n 0)
1571 (calc-refresh))
1572 (t
1573 (let ((entries (calc-top-list n 1 'entry))
1574 (calc-undo-list nil) (calc-redo-list nil))
1575 (calc-pop-stack n 1 t)
1576 (calc-push-list (mapcar 'car entries)
1577 1
1578 (mapcar (function (lambda (x) (nth 2 x)))
1579 entries)))))))
1580
1581 (defvar calc-refreshing-evaltos nil)
1582 (defvar calc-no-refresh-evaltos nil)
1583 (defun calc-refresh-evaltos (&optional which-var)
1584 (and calc-any-evaltos calc-auto-recompute (not calc-no-refresh-evaltos)
1585 (let ((calc-refreshing-evaltos t)
1586 (num (calc-stack-size))
1587 (calc-undo-list nil) (calc-redo-list nil)
1588 value new-val)
1589 (while (> num 0)
1590 (setq value (calc-top num 'entry))
1591 (if (and (not (nth 2 value))
1592 (setq value (car value))
1593 (or (eq (car-safe value) 'calcFunc-evalto)
1594 (and (eq (car-safe value) 'vec)
1595 (eq (car-safe (nth 1 value)) 'calcFunc-evalto))))
1596 (progn
1597 (setq new-val (math-normalize value))
1598 (or (equal new-val value)
1599 (progn
1600 (calc-push-list (list new-val) num)
1601 (calc-pop-stack 1 (1+ num) t)))))
1602 (setq num (1- num)))))
1603 (and calc-embedded-active which-var
1604 (calc-embedded-var-change which-var)))
1605
1606 (defun calc-push (&rest vals)
1607 (calc-push-list vals))
1608
1609 (defun calc-pop-push (n &rest vals)
1610 (calc-pop-push-list n vals))
1611
1612 (defun calc-pop-push-record (n prefix &rest vals)
1613 (calc-pop-push-record-list n prefix vals))
1614
1615
1616 (defun calc-evaluate (n)
1617 (interactive "p")
1618 (calc-slow-wrapper
1619 (if (= n 0)
1620 (setq n (calc-stack-size)))
1621 (calc-with-default-simplification
1622 (if (< n 0)
1623 (calc-pop-push-record-list 1 "eval"
1624 (math-evaluate-expr (calc-top (- n)))
1625 (- n))
1626 (calc-pop-push-record-list n "eval" (mapcar 'math-evaluate-expr
1627 (calc-top-list n)))))
1628 (calc-handle-whys)))
1629
1630
1631 (defun calc-eval-num (n)
1632 (interactive "P")
1633 (calc-slow-wrapper
1634 (let* ((nn (prefix-numeric-value n))
1635 (calc-internal-prec (cond ((>= nn 3) nn)
1636 ((< nn 0) (max (+ calc-internal-prec nn)
1637 3))
1638 (t calc-internal-prec)))
1639 (calc-symbolic-mode nil))
1640 (calc-with-default-simplification
1641 (calc-pop-push-record 1 "num" (math-evaluate-expr (calc-top 1)))))
1642 (calc-handle-whys)))
1643
1644
1645 (defun calc-execute-extended-command (n)
1646 (interactive "P")
1647 (let* ((prompt (concat (calc-num-prefix-name n) "M-x "))
1648 (cmd (intern (completing-read prompt obarray 'commandp t "calc-"))))
1649 (setq prefix-arg n)
1650 (command-execute cmd)))
1651
1652
1653 (defun calc-realign (&optional num)
1654 (interactive "P")
1655 (if (and num (eq major-mode 'calc-mode))
1656 (progn
1657 (calc-check-stack num)
1658 (calc-cursor-stack-index num)
1659 (and calc-line-numbering
1660 (forward-char 4)))
1661 (if (and calc-embedded-info
1662 (eq (current-buffer) (aref calc-embedded-info 0)))
1663 (progn
1664 (goto-char (aref calc-embedded-info 2))
1665 (if (save-excursion (set-buffer (aref calc-embedded-info 1))
1666 calc-show-plain)
1667 (forward-line 1)))
1668 (calc-wrapper
1669 (if (get-buffer-window (current-buffer))
1670 (set-window-hscroll (get-buffer-window (current-buffer)) 0))))))
1671
1672 (defvar math-cache-list nil)
1673
1674 (defun calc-var-value (v)
1675 (and (symbolp v)
1676 (boundp v)
1677 (symbol-value v)
1678 (if (symbolp (symbol-value v))
1679 (set v (funcall (symbol-value v)))
1680 (if (stringp (symbol-value v))
1681 (let ((val (math-read-expr (symbol-value v))))
1682 (if (eq (car-safe val) 'error)
1683 (error "Bad format in variable contents: %s" (nth 2 val))
1684 (set v val)))
1685 (symbol-value v)))))
1686
1687 ;;; In the following table, ( OP LOPS ROPS ) means that if an OP
1688 ;;; term appears as the first argument to any LOPS term, or as the
1689 ;;; second argument to any ROPS term, then they should be treated
1690 ;;; as one large term for purposes of associative selection.
1691 (defconst calc-assoc-ops '( ( + ( + - ) ( + ) )
1692 ( - ( + - ) ( + ) )
1693 ( * ( * ) ( * ) )
1694 ( / ( / ) ( ) )
1695 ( | ( | ) ( | ) )
1696 ( calcFunc-land ( calcFunc-land )
1697 ( calcFunc-land ) )
1698 ( calcFunc-lor ( calcFunc-lor )
1699 ( calcFunc-lor ) ) ))
1700
1701
1702 (defvar var-CommuteRules 'calc-CommuteRules)
1703 (defvar var-JumpRules 'calc-JumpRules)
1704 (defvar var-DistribRules 'calc-DistribRules)
1705 (defvar var-MergeRules 'calc-MergeRules)
1706 (defvar var-NegateRules 'calc-NegateRules)
1707 (defvar var-InvertRules 'calc-InvertRules)
1708
1709
1710 (defconst calc-tweak-eqn-table '( ( calcFunc-eq calcFunc-eq calcFunc-neq )
1711 ( calcFunc-neq calcFunc-neq calcFunc-eq )
1712 ( calcFunc-lt calcFunc-gt calcFunc-geq )
1713 ( calcFunc-gt calcFunc-lt calcFunc-leq )
1714 ( calcFunc-leq calcFunc-geq calcFunc-gt )
1715 ( calcFunc-geq calcFunc-leq calcFunc-lt ) ))
1716
1717
1718
1719
1720 (defun calc-float (arg)
1721 (interactive "P")
1722 (calc-slow-wrapper
1723 (calc-unary-op "flt"
1724 (if (calc-is-hyperbolic) 'calcFunc-float 'calcFunc-pfloat)
1725 arg)))
1726
1727
1728 (defvar calc-gnuplot-process nil)
1729 (defvar calc-gnuplot-input)
1730 (defvar calc-gnuplot-buffer)
1731
1732 (defun calc-gnuplot-alive ()
1733 (and calc-gnuplot-process
1734 calc-gnuplot-buffer
1735 (buffer-name calc-gnuplot-buffer)
1736 calc-gnuplot-input
1737 (buffer-name calc-gnuplot-input)
1738 (memq (process-status calc-gnuplot-process) '(run stop))))
1739
1740
1741
1742
1743
1744 (defun calc-load-everything ()
1745 (interactive)
1746 (require 'calc-aent)
1747 (require 'calc-alg)
1748 (require 'calc-arith)
1749 (require 'calc-bin)
1750 (require 'calc-comb)
1751 (require 'calc-cplx)
1752 (require 'calc-embed)
1753 (require 'calc-fin)
1754 (require 'calc-forms)
1755 (require 'calc-frac)
1756 (require 'calc-funcs)
1757 (require 'calc-graph)
1758 (require 'calc-help)
1759 (require 'calc-incom)
1760 (require 'calc-keypd)
1761 (require 'calc-lang)
1762 (require 'calc-macs)
1763 (require 'calc-map)
1764 (require 'calc-math)
1765 (require 'calc-misc)
1766 (require 'calc-mode)
1767 (require 'calc-mtx)
1768 (require 'calc-poly)
1769 (require 'calc-prog)
1770 (require 'calc-rewr)
1771 (require 'calc-rules)
1772 (require 'calc-sel)
1773 (require 'calc-stat)
1774 (require 'calc-store)
1775 (require 'calc-stuff)
1776 (require 'calc-trail)
1777 (require 'calc-undo)
1778 (require 'calc-units)
1779 (require 'calc-vec)
1780 (require 'calc-yank)
1781 (require 'calcalg2)
1782 (require 'calcalg3)
1783 (require 'calccomp)
1784 (require 'calcsel2)
1785
1786 (message "All parts of Calc are now loaded"))
1787
1788
1789 ;;; Vector commands.
1790
1791 (defun calc-concat (arg)
1792 (interactive "P")
1793 (calc-wrapper
1794 (if (calc-is-inverse)
1795 (if (calc-is-hyperbolic)
1796 (calc-enter-result 2 "apnd" (list 'calcFunc-append
1797 (calc-top 1) (calc-top 2)))
1798 (calc-enter-result 2 "|" (list 'calcFunc-vconcat
1799 (calc-top 1) (calc-top 2))))
1800 (if (calc-is-hyperbolic)
1801 (calc-binary-op "apnd" 'calcFunc-append arg '(vec))
1802 (calc-binary-op "|" 'calcFunc-vconcat arg '(vec) nil '|)))))
1803
1804 (defun calc-append (arg)
1805 (interactive "P")
1806 (calc-hyperbolic-func)
1807 (calc-concat arg))
1808
1809
1810 (defconst calc-arg-values '( ( var ArgA var-ArgA ) ( var ArgB var-ArgB )
1811 ( var ArgC var-ArgC ) ( var ArgD var-ArgD )
1812 ( var ArgE var-ArgE ) ( var ArgF var-ArgF )
1813 ( var ArgG var-ArgG ) ( var ArgH var-ArgH )
1814 ( var ArgI var-ArgI ) ( var ArgJ var-ArgJ )
1815 ))
1816
1817 (defun calc-invent-args (n)
1818 (nreverse (nthcdr (- (length calc-arg-values) n) (reverse calc-arg-values))))
1819
1820
1821
1822
1823 ;;; User menu.
1824
1825 (defun calc-user-key-map ()
1826 (if (featurep 'xemacs)
1827 (error "User-defined keys are not supported in XEmacs"))
1828 (let ((res (cdr (lookup-key calc-mode-map "z"))))
1829 (if (eq (car (car res)) 27)
1830 (cdr res)
1831 res)))
1832
1833 (defvar calc-z-prefix-buf nil)
1834 (defvar calc-z-prefix-msgs nil)
1835
1836 (defun calc-z-prefix-help ()
1837 (interactive)
1838 (let* ((calc-z-prefix-msgs nil)
1839 (calc-z-prefix-buf "")
1840 (kmap (sort (copy-sequence (calc-user-key-map))
1841 (function (lambda (x y) (< (car x) (car y))))))
1842 (flags (apply 'logior
1843 (mapcar (function
1844 (lambda (k)
1845 (calc-user-function-classify (car k))))
1846 kmap))))
1847 (if (= (logand flags 8) 0)
1848 (calc-user-function-list kmap 7)
1849 (calc-user-function-list kmap 1)
1850 (setq calc-z-prefix-msgs (cons calc-z-prefix-buf calc-z-prefix-msgs)
1851 calc-z-prefix-buf "")
1852 (calc-user-function-list kmap 6))
1853 (if (/= flags 0)
1854 (setq calc-z-prefix-msgs (cons calc-z-prefix-buf calc-z-prefix-msgs)))
1855 (calc-do-prefix-help (nreverse calc-z-prefix-msgs) "user" ?z)))
1856
1857 (defun calc-user-function-classify (key)
1858 (cond ((/= key (downcase key)) ; upper-case
1859 (if (assq (downcase key) (calc-user-key-map)) 9 1))
1860 ((/= key (upcase key)) 2) ; lower-case
1861 ((= key ??) 0)
1862 (t 4))) ; other
1863
1864 (defun calc-user-function-list (map flags)
1865 (and map
1866 (let* ((key (car (car map)))
1867 (kind (calc-user-function-classify key))
1868 (func (cdr (car map))))
1869 (if (or (= (logand kind flags) 0)
1870 (not (symbolp func)))
1871 ()
1872 (let* ((name (symbol-name func))
1873 (name (if (string-match "\\`calc-" name)
1874 (substring name 5) name))
1875 (pos (string-match (char-to-string key) name))
1876 (desc
1877 (if (symbolp func)
1878 (if (= (logand kind 3) 0)
1879 (format "`%c' = %s" key name)
1880 (if pos
1881 (format "%s%c%s"
1882 (downcase (substring name 0 pos))
1883 (upcase key)
1884 (downcase (substring name (1+ pos))))
1885 (format "%c = %s"
1886 (upcase key)
1887 (downcase name))))
1888 (char-to-string (upcase key)))))
1889 (if (= (length calc-z-prefix-buf) 0)
1890 (setq calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1891 desc))
1892 (if (> (+ (length calc-z-prefix-buf) (length desc)) 58)
1893 (setq calc-z-prefix-msgs
1894 (cons calc-z-prefix-buf calc-z-prefix-msgs)
1895 calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1896 desc))
1897 (setq calc-z-prefix-buf (concat calc-z-prefix-buf ", " desc))))))
1898 (calc-user-function-list (cdr map) flags))))
1899
1900
1901
1902 (defun calc-shift-Z-prefix-help ()
1903 (interactive)
1904 (calc-do-prefix-help
1905 '("Define, Undefine, Formula, Kbd-macro, Edit, Get-defn"
1906 "Composition, Syntax; Invocation; Permanent; Timing"
1907 "kbd-macros: [ (if), : (else), | (else-if), ] (end-if)"
1908 "kbd-macros: < > (repeat), ( ) (for), { } (loop)"
1909 "kbd-macros: / (break)"
1910 "kbd-macros: ` (save), ' (restore)")
1911 "user" ?Z))
1912
1913
1914 ;;;; Caches.
1915
1916 (defmacro math-defcache (name init form)
1917 (let ((cache-prec (intern (concat (symbol-name name) "-cache-prec")))
1918 (cache-val (intern (concat (symbol-name name) "-cache")))
1919 (last-prec (intern (concat (symbol-name name) "-last-prec")))
1920 (last-val (intern (concat (symbol-name name) "-last"))))
1921 (list 'progn
1922 ; (list 'defvar cache-prec (if init (math-numdigs (nth 1 init)) -100))
1923 (list 'defvar cache-prec
1924 `(cond
1925 ((consp ,init) (math-numdigs (nth 1 ,init)))
1926 (,init
1927 (nth 1 (math-numdigs (eval ,init))))
1928 (t
1929 -100)))
1930 (list 'defvar cache-val
1931 `(cond
1932 ((consp ,init) ,init)
1933 (,init (eval ,init))
1934 (t ,init)))
1935 (list 'defvar last-prec -100)
1936 (list 'defvar last-val nil)
1937 (list 'setq 'math-cache-list
1938 (list 'cons
1939 (list 'quote cache-prec)
1940 (list 'cons
1941 (list 'quote last-prec)
1942 'math-cache-list)))
1943 (list 'defun
1944 name ()
1945 (list 'or
1946 (list '= last-prec 'calc-internal-prec)
1947 (list 'setq
1948 last-val
1949 (list 'math-normalize
1950 (list 'progn
1951 (list 'or
1952 (list '>= cache-prec
1953 'calc-internal-prec)
1954 (list 'setq
1955 cache-val
1956 (list 'let
1957 '((calc-internal-prec
1958 (+ calc-internal-prec
1959 4)))
1960 form)
1961 cache-prec
1962 '(+ calc-internal-prec 2)))
1963 cache-val))
1964 last-prec 'calc-internal-prec))
1965 last-val))))
1966 (put 'math-defcache 'lisp-indent-hook 2)
1967
1968 ;;; Betcha didn't know that pi = 16 atan(1/5) - 4 atan(1/239). [F] [Public]
1969 (defconst math-approx-pi
1970 (math-read-number-simple "3.141592653589793238463")
1971 "An approximation for pi.")
1972
1973 (math-defcache math-pi math-approx-pi
1974 (math-add-float (math-mul-float '(float 16 0)
1975 (math-arctan-raw '(float 2 -1)))
1976 (math-mul-float '(float -4 0)
1977 (math-arctan-raw
1978 (math-float '(frac 1 239))))))
1979
1980 (math-defcache math-two-pi nil
1981 (math-mul-float (math-pi) '(float 2 0)))
1982
1983 (math-defcache math-pi-over-2 nil
1984 (math-mul-float (math-pi) '(float 5 -1)))
1985
1986 (math-defcache math-pi-over-4 nil
1987 (math-mul-float (math-pi) '(float 25 -2)))
1988
1989 (math-defcache math-pi-over-180 nil
1990 (math-div-float (math-pi) '(float 18 1)))
1991
1992 (math-defcache math-sqrt-pi nil
1993 (math-sqrt-float (math-pi)))
1994
1995 (math-defcache math-sqrt-2 nil
1996 (math-sqrt-float '(float 2 0)))
1997
1998 (math-defcache math-sqrt-12 nil
1999 (math-sqrt-float '(float 12 0)))
2000
2001 (math-defcache math-sqrt-two-pi nil
2002 (math-sqrt-float (math-two-pi)))
2003
2004 (defconst math-approx-sqrt-e
2005 (math-read-number-simple "1.648721270700128146849")
2006 "An approximation for sqrt(3).")
2007
2008 (math-defcache math-sqrt-e math-approx-sqrt-e
2009 (math-add-float '(float 1 0) (math-exp-minus-1-raw '(float 5 -1))))
2010
2011 (math-defcache math-e nil
2012 (math-pow (math-sqrt-e) 2))
2013
2014 (math-defcache math-phi nil
2015 (math-mul-float (math-add-float (math-sqrt-raw '(float 5 0)) '(float 1 0))
2016 '(float 5 -1)))
2017
2018 (defconst math-approx-gamma-const
2019 (math-read-number-simple
2020 "0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495")
2021 "An approximation for gamma.")
2022
2023 (math-defcache math-gamma-const nil
2024 math-approx-gamma-const)
2025
2026 (defun math-half-circle (symb)
2027 (if (eq calc-angle-mode 'rad)
2028 (if symb
2029 '(var pi var-pi)
2030 (math-pi))
2031 180))
2032
2033 (defun math-full-circle (symb)
2034 (math-mul 2 (math-half-circle symb)))
2035
2036 (defun math-quarter-circle (symb)
2037 (math-div (math-half-circle symb) 2))
2038
2039 (defvar math-expand-formulas nil)
2040
2041 ;;;; Miscellaneous math routines.
2042
2043 ;;; True if A is an odd integer. [P R R] [Public]
2044 (defun math-oddp (a)
2045 (if (consp a)
2046 (and (memq (car a) '(bigpos bigneg))
2047 (= (% (nth 1 a) 2) 1))
2048 (/= (% a 2) 0)))
2049
2050 ;;; True if A is a small or big integer. [P x] [Public]
2051 (defun math-integerp (a)
2052 (or (integerp a)
2053 (memq (car-safe a) '(bigpos bigneg))))
2054
2055 ;;; True if A is (numerically) a non-negative integer. [P N] [Public]
2056 (defun math-natnump (a)
2057 (or (natnump a)
2058 (eq (car-safe a) 'bigpos)))
2059
2060 ;;; True if A is a rational (or integer). [P x] [Public]
2061 (defun math-ratp (a)
2062 (or (integerp a)
2063 (memq (car-safe a) '(bigpos bigneg frac))))
2064
2065 ;;; True if A is a real (or rational). [P x] [Public]
2066 (defun math-realp (a)
2067 (or (integerp a)
2068 (memq (car-safe a) '(bigpos bigneg frac float))))
2069
2070 ;;; True if A is a real or HMS form. [P x] [Public]
2071 (defun math-anglep (a)
2072 (or (integerp a)
2073 (memq (car-safe a) '(bigpos bigneg frac float hms))))
2074
2075 ;;; True if A is a number of any kind. [P x] [Public]
2076 (defun math-numberp (a)
2077 (or (integerp a)
2078 (memq (car-safe a) '(bigpos bigneg frac float cplx polar))))
2079
2080 ;;; True if A is a complex number or angle. [P x] [Public]
2081 (defun math-scalarp (a)
2082 (or (integerp a)
2083 (memq (car-safe a) '(bigpos bigneg frac float cplx polar hms))))
2084
2085 ;;; True if A is a vector. [P x] [Public]
2086 (defun math-vectorp (a)
2087 (eq (car-safe a) 'vec))
2088
2089 ;;; True if A is any vector or scalar data object. [P x]
2090 (defun math-objvecp (a) ; [Public]
2091 (or (integerp a)
2092 (memq (car-safe a) '(bigpos bigneg frac float cplx polar
2093 hms date sdev intv mod vec incomplete))))
2094
2095 ;;; True if A is an object not composed of sub-formulas . [P x] [Public]
2096 (defun math-primp (a)
2097 (or (integerp a)
2098 (memq (car-safe a) '(bigpos bigneg frac float cplx polar
2099 hms date mod var))))
2100
2101 ;;; True if A is numerically (but not literally) an integer. [P x] [Public]
2102 (defun math-messy-integerp (a)
2103 (cond
2104 ((eq (car-safe a) 'float) (>= (nth 2 a) 0))
2105 ((eq (car-safe a) 'frac) (Math-integerp (math-normalize a)))))
2106
2107 ;;; True if A is numerically an integer. [P x] [Public]
2108 (defun math-num-integerp (a)
2109 (or (Math-integerp a)
2110 (Math-messy-integerp a)))
2111
2112 ;;; True if A is (numerically) a non-negative integer. [P N] [Public]
2113 (defun math-num-natnump (a)
2114 (or (natnump a)
2115 (eq (car-safe a) 'bigpos)
2116 (and (eq (car-safe a) 'float)
2117 (Math-natnump (nth 1 a))
2118 (>= (nth 2 a) 0))))
2119
2120 ;;; True if A is an integer or will evaluate to an integer. [P x] [Public]
2121 (defun math-provably-integerp (a)
2122 (or (Math-integerp a)
2123 (and (memq (car-safe a) '(calcFunc-trunc
2124 calcFunc-round
2125 calcFunc-rounde
2126 calcFunc-roundu
2127 calcFunc-floor
2128 calcFunc-ceil))
2129 (= (length a) 2))))
2130
2131 ;;; True if A is a real or will evaluate to a real. [P x] [Public]
2132 (defun math-provably-realp (a)
2133 (or (Math-realp a)
2134 (math-provably-integerp a)
2135 (memq (car-safe a) '(abs arg))))
2136
2137 ;;; True if A is a non-real, complex number. [P x] [Public]
2138 (defun math-complexp (a)
2139 (memq (car-safe a) '(cplx polar)))
2140
2141 ;;; True if A is a non-real, rectangular complex number. [P x] [Public]
2142 (defun math-rect-complexp (a)
2143 (eq (car-safe a) 'cplx))
2144
2145 ;;; True if A is a non-real, polar complex number. [P x] [Public]
2146 (defun math-polar-complexp (a)
2147 (eq (car-safe a) 'polar))
2148
2149 ;;; True if A is a matrix. [P x] [Public]
2150 (defun math-matrixp (a)
2151 (and (Math-vectorp a)
2152 (Math-vectorp (nth 1 a))
2153 (cdr (nth 1 a))
2154 (let ((len (length (nth 1 a))))
2155 (setq a (cdr a))
2156 (while (and (setq a (cdr a))
2157 (Math-vectorp (car a))
2158 (= (length (car a)) len)))
2159 (null a))))
2160
2161 (defun math-matrixp-step (a len) ; [P L]
2162 (or (null a)
2163 (and (Math-vectorp (car a))
2164 (= (length (car a)) len)
2165 (math-matrixp-step (cdr a) len))))
2166
2167 ;;; True if A is a square matrix. [P V] [Public]
2168 (defun math-square-matrixp (a)
2169 (let ((dims (math-mat-dimens a)))
2170 (and (cdr dims)
2171 (= (car dims) (nth 1 dims)))))
2172
2173 ;;; True if MAT is an identity matrix.
2174 (defun math-identity-matrix-p (mat &optional mul)
2175 (if (math-square-matrixp mat)
2176 (let ((a (if mul
2177 (nth 1 (nth 1 mat))
2178 1))
2179 (n (1- (length mat)))
2180 (i 1))
2181 (while (and (<= i n)
2182 (math-ident-row-p (nth i mat) i a))
2183 (setq i (1+ i)))
2184 (if (> i n)
2185 a
2186 nil))))
2187
2188 (defun math-ident-row-p (row n &optional a)
2189 (unless a
2190 (setq a 1))
2191 (and
2192 (not (memq nil (mapcar
2193 (lambda (x) (eq x 0))
2194 (nthcdr (1+ n) row))))
2195 (not (memq nil (mapcar
2196 (lambda (x) (eq x 0))
2197 (butlast
2198 (cdr row)
2199 (- (length row) n)))))
2200 (eq (elt row n) a)))
2201
2202 ;;; True if A is any scalar data object. [P x]
2203 (defun math-objectp (a) ; [Public]
2204 (or (integerp a)
2205 (memq (car-safe a) '(bigpos bigneg frac float cplx
2206 polar hms date sdev intv mod))))
2207
2208 ;;; Verify that A is an integer and return A in integer form. [I N; - x]
2209 (defun math-check-integer (a) ; [Public]
2210 (cond ((integerp a) a) ; for speed
2211 ((math-integerp a) a)
2212 ((math-messy-integerp a)
2213 (math-trunc a))
2214 (t (math-reject-arg a 'integerp))))
2215
2216 ;;; Verify that A is a small integer and return A in integer form. [S N; - x]
2217 (defun math-check-fixnum (a &optional allow-inf) ; [Public]
2218 (cond ((integerp a) a) ; for speed
2219 ((Math-num-integerp a)
2220 (let ((a (math-trunc a)))
2221 (if (integerp a)
2222 a
2223 (if (or (Math-lessp (lsh -1 -1) a)
2224 (Math-lessp a (- (lsh -1 -1))))
2225 (math-reject-arg a 'fixnump)
2226 (math-fixnum a)))))
2227 ((and allow-inf (equal a '(var inf var-inf)))
2228 (lsh -1 -1))
2229 ((and allow-inf (equal a '(neg (var inf var-inf))))
2230 (- (lsh -1 -1)))
2231 (t (math-reject-arg a 'fixnump))))
2232
2233 ;;; Verify that A is an integer >= 0 and return A in integer form. [I N; - x]
2234 (defun math-check-natnum (a) ; [Public]
2235 (cond ((natnump a) a)
2236 ((and (not (math-negp a))
2237 (Math-num-integerp a))
2238 (math-trunc a))
2239 (t (math-reject-arg a 'natnump))))
2240
2241 ;;; Verify that A is in floating-point form, or force it to be a float. [F N]
2242 (defun math-check-float (a) ; [Public]
2243 (cond ((eq (car-safe a) 'float) a)
2244 ((Math-vectorp a) (math-map-vec 'math-check-float a))
2245 ((Math-objectp a) (math-float a))
2246 (t a)))
2247
2248 ;;; Verify that A is a constant.
2249 (defun math-check-const (a &optional exp-ok)
2250 (if (or (math-constp a)
2251 (and exp-ok math-expand-formulas))
2252 a
2253 (math-reject-arg a 'constp)))
2254
2255 ;;; Some functions for working with error forms.
2256 (defun math-get-value (x)
2257 "Get the mean value of the error form X.
2258 If X is not an error form, return X."
2259 (if (eq (car-safe x) 'sdev)
2260 (nth 1 x)
2261 x))
2262
2263 (defun math-get-sdev (x &optional one)
2264 "Get the standard deviation of the error form X.
2265 If X is not an error form, return 1."
2266 (if (eq (car-safe x) 'sdev)
2267 (nth 2 x)
2268 (if one 1 0)))
2269
2270 (defun math-contains-sdev-p (ls)
2271 "Non-nil if the list LS contains an error form."
2272 (let ((ls (if (eq (car-safe ls) 'vec) (cdr ls) ls)))
2273 (memq t (mapcar (lambda (x) (eq (car-safe x) 'sdev)) ls))))
2274
2275 ;;; Coerce integer A to be a small integer. [S I]
2276 (defun math-fixnum (a)
2277 (if (consp a)
2278 (if (cdr a)
2279 (if (eq (car a) 'bigneg)
2280 (- (math-fixnum-big (cdr a)))
2281 (math-fixnum-big (cdr a)))
2282 0)
2283 a))
2284
2285 (defun math-fixnum-big (a)
2286 (if (cdr a)
2287 (+ (car a) (* (math-fixnum-big (cdr a)) math-bignum-digit-size))
2288 (car a)))
2289
2290 (defvar math-simplify-only nil)
2291
2292 (defun math-normalize-fancy (a)
2293 (cond ((eq (car a) 'frac)
2294 (math-make-frac (math-normalize (nth 1 a))
2295 (math-normalize (nth 2 a))))
2296 ((eq (car a) 'cplx)
2297 (let ((real (math-normalize (nth 1 a)))
2298 (imag (math-normalize (nth 2 a))))
2299 (if (and (math-zerop imag)
2300 (not math-simplify-only)) ; oh, what a kludge!
2301 real
2302 (list 'cplx real imag))))
2303 ((eq (car a) 'polar)
2304 (math-normalize-polar a))
2305 ((eq (car a) 'hms)
2306 (math-normalize-hms a))
2307 ((eq (car a) 'date)
2308 (list 'date (math-normalize (nth 1 a))))
2309 ((eq (car a) 'mod)
2310 (math-normalize-mod a))
2311 ((eq (car a) 'sdev)
2312 (let ((x (math-normalize (nth 1 a)))
2313 (s (math-normalize (nth 2 a))))
2314 (if (or (and (Math-objectp x) (not (Math-scalarp x)))
2315 (and (Math-objectp s) (not (Math-scalarp s))))
2316 (list 'calcFunc-sdev x s)
2317 (math-make-sdev x s))))
2318 ((eq (car a) 'intv)
2319 (let ((mask (math-normalize (nth 1 a)))
2320 (lo (math-normalize (nth 2 a)))
2321 (hi (math-normalize (nth 3 a))))
2322 (if (if (eq (car-safe lo) 'date)
2323 (not (eq (car-safe hi) 'date))
2324 (or (and (Math-objectp lo) (not (Math-anglep lo)))
2325 (and (Math-objectp hi) (not (Math-anglep hi)))))
2326 (list 'calcFunc-intv mask lo hi)
2327 (math-make-intv mask lo hi))))
2328 ((eq (car a) 'vec)
2329 (cons 'vec (mapcar 'math-normalize (cdr a))))
2330 ((eq (car a) 'quote)
2331 (math-normalize (nth 1 a)))
2332 ((eq (car a) 'special-const)
2333 (calc-with-default-simplification
2334 (math-normalize (nth 1 a))))
2335 ((eq (car a) 'var)
2336 (cons 'var (cdr a))) ; need to re-cons for selection routines
2337 ((eq (car a) 'calcFunc-if)
2338 (math-normalize-logical-op a))
2339 ((memq (car a) '(calcFunc-lambda calcFunc-quote calcFunc-condition))
2340 (let ((calc-simplify-mode 'none))
2341 (cons (car a) (mapcar 'math-normalize (cdr a)))))
2342 ((eq (car a) 'calcFunc-evalto)
2343 (setq a (or (nth 1 a) 0))
2344 (or calc-refreshing-evaltos
2345 (setq a (let ((calc-simplify-mode 'none)) (math-normalize a))))
2346 (let ((b (if (and (eq (car-safe a) 'calcFunc-assign)
2347 (= (length a) 3))
2348 (nth 2 a)
2349 a)))
2350 (list 'calcFunc-evalto
2351 a
2352 (if (eq calc-simplify-mode 'none)
2353 (math-normalize b)
2354 (calc-with-default-simplification
2355 (math-evaluate-expr b))))))
2356 ((or (integerp (car a)) (consp (car a)))
2357 (if (null (cdr a))
2358 (math-normalize (car a))
2359 (error "Can't use multi-valued function in an expression")))))
2360
2361 ;; The variable math-normalize-a is local to math-normalize in calc.el,
2362 ;; but is used by math-normalize-nonstandard, which is called by
2363 ;; math-normalize.
2364 (defvar math-normalize-a)
2365
2366 (defun math-normalize-nonstandard ()
2367 (if (consp calc-simplify-mode)
2368 (progn
2369 (setq calc-simplify-mode 'none
2370 math-simplify-only (car-safe (cdr-safe math-normalize-a)))
2371 nil)
2372 (and (symbolp (car math-normalize-a))
2373 (or (eq calc-simplify-mode 'none)
2374 (and (eq calc-simplify-mode 'num)
2375 (let ((aptr (setq math-normalize-a
2376 (cons
2377 (car math-normalize-a)
2378 (mapcar 'math-normalize
2379 (cdr math-normalize-a))))))
2380 (while (and aptr (math-constp (car aptr)))
2381 (setq aptr (cdr aptr)))
2382 aptr)))
2383 (cons (car math-normalize-a)
2384 (mapcar 'math-normalize (cdr math-normalize-a))))))
2385
2386
2387 ;;; Normalize a bignum digit list by trimming high-end zeros. [L l]
2388 (defun math-norm-bignum (a)
2389 (let ((digs a) (last nil))
2390 (while digs
2391 (or (eq (car digs) 0) (setq last digs))
2392 (setq digs (cdr digs)))
2393 (and last
2394 (progn
2395 (setcdr last nil)
2396 a))))
2397
2398 (defun math-bignum-test (a) ; [B N; B s; b b]
2399 (if (consp a)
2400 a
2401 (math-bignum a)))
2402
2403
2404 ;;; Return 0 for zero, -1 for negative, 1 for positive. [S n] [Public]
2405 (defun calcFunc-sign (a &optional x)
2406 (let ((signs (math-possible-signs a)))
2407 (cond ((eq signs 4) (or x 1))
2408 ((eq signs 2) 0)
2409 ((eq signs 1) (if x (math-neg x) -1))
2410 ((math-looks-negp a) (math-neg (calcFunc-sign (math-neg a))))
2411 (t (calc-record-why 'realp a)
2412 (if x
2413 (list 'calcFunc-sign a x)
2414 (list 'calcFunc-sign a))))))
2415
2416 ;;; Return 0 if A is numerically equal to B, <0 if less, >0 if more.
2417 ;;; Arguments must be normalized! [S N N]
2418 (defun math-compare (a b)
2419 (cond ((equal a b)
2420 (if (and (consp a)
2421 (memq (car a) '(var neg * /))
2422 (math-infinitep a))
2423 2
2424 0))
2425 ((and (integerp a) (Math-integerp b))
2426 (if (consp b)
2427 (if (eq (car b) 'bigpos) -1 1)
2428 (if (< a b) -1 1)))
2429 ((and (eq (car-safe a) 'bigpos) (Math-integerp b))
2430 (if (eq (car-safe b) 'bigpos)
2431 (math-compare-bignum (cdr a) (cdr b))
2432 1))
2433 ((and (eq (car-safe a) 'bigneg) (Math-integerp b))
2434 (if (eq (car-safe b) 'bigneg)
2435 (math-compare-bignum (cdr b) (cdr a))
2436 -1))
2437 ((eq (car-safe a) 'frac)
2438 (if (eq (car-safe b) 'frac)
2439 (math-compare (math-mul (nth 1 a) (nth 2 b))
2440 (math-mul (nth 1 b) (nth 2 a)))
2441 (math-compare (nth 1 a) (math-mul b (nth 2 a)))))
2442 ((eq (car-safe b) 'frac)
2443 (math-compare (math-mul a (nth 2 b)) (nth 1 b)))
2444 ((and (eq (car-safe a) 'float) (eq (car-safe b) 'float))
2445 (if (math-lessp-float a b) -1 1))
2446 ((and (eq (car-safe a) 'date) (eq (car-safe b) 'date))
2447 (math-compare (nth 1 a) (nth 1 b)))
2448 ((and (or (Math-anglep a)
2449 (and (eq (car a) 'cplx) (eq (nth 2 a) 0)))
2450 (or (Math-anglep b)
2451 (and (eq (car b) 'cplx) (eq (nth 2 b) 0))))
2452 (calcFunc-sign (math-add a (math-neg b))))
2453 ((and (eq (car-safe a) 'intv)
2454 (or (Math-anglep b) (eq (car-safe b) 'date)))
2455 (let ((res (math-compare (nth 2 a) b)))
2456 (cond ((eq res 1) 1)
2457 ((and (eq res 0) (memq (nth 1 a) '(0 1))) 1)
2458 ((eq (setq res (math-compare (nth 3 a) b)) -1) -1)
2459 ((and (eq res 0) (memq (nth 1 a) '(0 2))) -1)
2460 (t 2))))
2461 ((and (eq (car-safe b) 'intv)
2462 (or (Math-anglep a) (eq (car-safe a) 'date)))
2463 (let ((res (math-compare a (nth 2 b))))
2464 (cond ((eq res -1) -1)
2465 ((and (eq res 0) (memq (nth 1 b) '(0 1))) -1)
2466 ((eq (setq res (math-compare a (nth 3 b))) 1) 1)
2467 ((and (eq res 0) (memq (nth 1 b) '(0 2))) 1)
2468 (t 2))))
2469 ((and (eq (car-safe a) 'intv) (eq (car-safe b) 'intv))
2470 (let ((res (math-compare (nth 3 a) (nth 2 b))))
2471 (cond ((eq res -1) -1)
2472 ((and (eq res 0) (or (memq (nth 1 a) '(0 2))
2473 (memq (nth 1 b) '(0 1)))) -1)
2474 ((eq (setq res (math-compare (nth 2 a) (nth 3 b))) 1) 1)
2475 ((and (eq res 0) (or (memq (nth 1 a) '(0 1))
2476 (memq (nth 1 b) '(0 2)))) 1)
2477 (t 2))))
2478 ((math-infinitep a)
2479 (if (or (equal a '(var uinf var-uinf))
2480 (equal a '(var nan var-nan)))
2481 2
2482 (let ((dira (math-infinite-dir a)))
2483 (if (math-infinitep b)
2484 (if (or (equal b '(var uinf var-uinf))
2485 (equal b '(var nan var-nan)))
2486 2
2487 (let ((dirb (math-infinite-dir b)))
2488 (cond ((and (eq dira 1) (eq dirb -1)) 1)
2489 ((and (eq dira -1) (eq dirb 1)) -1)
2490 (t 2))))
2491 (cond ((eq dira 1) 1)
2492 ((eq dira -1) -1)
2493 (t 2))))))
2494 ((math-infinitep b)
2495 (if (or (equal b '(var uinf var-uinf))
2496 (equal b '(var nan var-nan)))
2497 2
2498 (let ((dirb (math-infinite-dir b)))
2499 (cond ((eq dirb 1) -1)
2500 ((eq dirb -1) 1)
2501 (t 2)))))
2502 ((and (eq (car-safe a) 'calcFunc-exp)
2503 (eq (car-safe b) '^)
2504 (equal (nth 1 b) '(var e var-e)))
2505 (math-compare (nth 1 a) (nth 2 b)))
2506 ((and (eq (car-safe b) 'calcFunc-exp)
2507 (eq (car-safe a) '^)
2508 (equal (nth 1 a) '(var e var-e)))
2509 (math-compare (nth 2 a) (nth 1 b)))
2510 ((or (and (eq (car-safe a) 'calcFunc-sqrt)
2511 (eq (car-safe b) '^)
2512 (or (equal (nth 2 b) '(frac 1 2))
2513 (equal (nth 2 b) '(float 5 -1))))
2514 (and (eq (car-safe b) 'calcFunc-sqrt)
2515 (eq (car-safe a) '^)
2516 (or (equal (nth 2 a) '(frac 1 2))
2517 (equal (nth 2 a) '(float 5 -1)))))
2518 (math-compare (nth 1 a) (nth 1 b)))
2519 ((eq (car-safe a) 'var)
2520 2)
2521 (t
2522 (if (and (consp a) (consp b)
2523 (eq (car a) (car b))
2524 (math-compare-lists (cdr a) (cdr b)))
2525 0
2526 2))))
2527
2528 ;;; Compare two bignum digit lists, return -1 for A<B, 0 for A=B, 1 for A>B.
2529 (defun math-compare-bignum (a b) ; [S l l]
2530 (let ((res 0))
2531 (while (and a b)
2532 (if (< (car a) (car b))
2533 (setq res -1)
2534 (if (> (car a) (car b))
2535 (setq res 1)))
2536 (setq a (cdr a)
2537 b (cdr b)))
2538 (if a
2539 (progn
2540 (while (eq (car a) 0) (setq a (cdr a)))
2541 (if a 1 res))
2542 (while (eq (car b) 0) (setq b (cdr b)))
2543 (if b -1 res))))
2544
2545 (defun math-compare-lists (a b)
2546 (cond ((null a) (null b))
2547 ((null b) nil)
2548 (t (and (Math-equal (car a) (car b))
2549 (math-compare-lists (cdr a) (cdr b))))))
2550
2551 (defun math-lessp-float (a b) ; [P F F]
2552 (let ((ediff (- (nth 2 a) (nth 2 b))))
2553 (if (>= ediff 0)
2554 (if (>= ediff (+ calc-internal-prec calc-internal-prec))
2555 (if (eq (nth 1 a) 0)
2556 (Math-integer-posp (nth 1 b))
2557 (Math-integer-negp (nth 1 a)))
2558 (Math-lessp (math-scale-int (nth 1 a) ediff)
2559 (nth 1 b)))
2560 (if (>= (setq ediff (- ediff))
2561 (+ calc-internal-prec calc-internal-prec))
2562 (if (eq (nth 1 b) 0)
2563 (Math-integer-negp (nth 1 a))
2564 (Math-integer-posp (nth 1 b)))
2565 (Math-lessp (nth 1 a)
2566 (math-scale-int (nth 1 b) ediff))))))
2567
2568 ;;; True if A is numerically equal to B. [P N N] [Public]
2569 (defun math-equal (a b)
2570 (= (math-compare a b) 0))
2571
2572 ;;; True if A is numerically less than B. [P R R] [Public]
2573 (defun math-lessp (a b)
2574 (= (math-compare a b) -1))
2575
2576 ;;; True if A is numerically equal to the integer B. [P N S] [Public]
2577 ;;; B must not be a multiple of 10.
2578 (defun math-equal-int (a b)
2579 (or (eq a b)
2580 (and (eq (car-safe a) 'float)
2581 (eq (nth 1 a) b)
2582 (= (nth 2 a) 0))))
2583
2584
2585
2586
2587 ;;; Return the dimensions of a matrix as a list. [l x] [Public]
2588 (defun math-mat-dimens (m)
2589 (if (math-vectorp m)
2590 (if (math-matrixp m)
2591 (cons (1- (length m))
2592 (math-mat-dimens (nth 1 m)))
2593 (list (1- (length m))))
2594 nil))
2595
2596
2597
2598 (defun calc-binary-op-fancy (name func arg ident unary)
2599 (let ((n (prefix-numeric-value arg)))
2600 (cond ((> n 1)
2601 (calc-enter-result n
2602 name
2603 (list 'calcFunc-reduce
2604 (math-calcFunc-to-var func)
2605 (cons 'vec (calc-top-list-n n)))))
2606 ((= n 1)
2607 (if unary
2608 (calc-enter-result 1 name (list unary (calc-top-n 1)))))
2609 ((= n 0)
2610 (if ident
2611 (calc-enter-result 0 name ident)
2612 (error "Argument must be nonzero")))
2613 (t
2614 (let ((rhs (calc-top-n 1)))
2615 (calc-enter-result (- 1 n)
2616 name
2617 (mapcar (function
2618 (lambda (x)
2619 (list func x rhs)))
2620 (calc-top-list-n (- n) 2))))))))
2621
2622 (defun calc-unary-op-fancy (name func arg)
2623 (let ((n (prefix-numeric-value arg)))
2624 (if (= n 0) (setq n (calc-stack-size)))
2625 (cond ((> n 0)
2626 (calc-enter-result n
2627 name
2628 (mapcar (function
2629 (lambda (x)
2630 (list func x)))
2631 (calc-top-list-n n))))
2632 ((< n 0)
2633 (calc-enter-result 1
2634 name
2635 (list func (calc-top-n (- n)))
2636 (- n))))))
2637
2638 (defvar var-Holidays '(vec (var sat var-sat) (var sun var-sun)))
2639 (defvar var-Decls (list 'vec))
2640
2641
2642 (defun math-inexact-result ()
2643 (and calc-symbolic-mode
2644 (signal 'inexact-result nil)))
2645
2646 (defun math-overflow (&optional exp)
2647 (if (and exp (math-negp exp))
2648 (math-underflow)
2649 (signal 'math-overflow nil)))
2650
2651 (defun math-underflow ()
2652 (signal 'math-underflow nil))
2653
2654 ;;; Compute the greatest common divisor of A and B. [I I I] [Public]
2655 (defun math-gcd (a b)
2656 (cond ((not (or (consp a) (consp b)))
2657 (if (< a 0) (setq a (- a)))
2658 (if (< b 0) (setq b (- b)))
2659 (let (c)
2660 (if (< a b)
2661 (setq c b b a a c))
2662 (while (> b 0)
2663 (setq c b
2664 b (% a b)
2665 a c))
2666 a))
2667 ((eq a 0) b)
2668 ((eq b 0) a)
2669 (t
2670 (if (Math-integer-negp a) (setq a (math-neg a)))
2671 (if (Math-integer-negp b) (setq b (math-neg b)))
2672 (let (c)
2673 (if (Math-natnum-lessp a b)
2674 (setq c b b a a c))
2675 (while (and (consp a) (not (eq b 0)))
2676 (setq c b
2677 b (math-imod a b)
2678 a c))
2679 (while (> b 0)
2680 (setq c b
2681 b (% a b)
2682 a c))
2683 a))))
2684
2685
2686 ;;;; Algebra.
2687
2688 ;;; Evaluate variables in an expression.
2689 (defun math-evaluate-expr (x) ; [Public]
2690 (if calc-embedded-info
2691 (calc-embedded-evaluate-expr x)
2692 (calc-normalize (math-evaluate-expr-rec x))))
2693
2694 (defalias 'calcFunc-evalv 'math-evaluate-expr)
2695
2696 (defun calcFunc-evalvn (x &optional prec)
2697 (if prec
2698 (progn
2699 (or (math-num-integerp prec)
2700 (if (and (math-vectorp prec)
2701 (= (length prec) 2)
2702 (math-num-integerp (nth 1 prec)))
2703 (setq prec (math-add (nth 1 prec) calc-internal-prec))
2704 (math-reject-arg prec 'integerp)))
2705 (setq prec (math-trunc prec))
2706 (if (< prec 3) (setq prec 3))
2707 (if (> prec calc-internal-prec)
2708 (math-normalize
2709 (let ((calc-internal-prec prec))
2710 (calcFunc-evalvn x)))
2711 (let ((calc-internal-prec prec))
2712 (calcFunc-evalvn x))))
2713 (let ((calc-symbolic-mode nil))
2714 (math-evaluate-expr x))))
2715
2716 (defun math-evaluate-expr-rec (x)
2717 (if (consp x)
2718 (if (memq (car x) '(calcFunc-quote calcFunc-condition
2719 calcFunc-evalto calcFunc-assign))
2720 (if (and (eq (car x) 'calcFunc-assign)
2721 (= (length x) 3))
2722 (list (car x) (nth 1 x) (math-evaluate-expr-rec (nth 2 x)))
2723 x)
2724 (if (eq (car x) 'var)
2725 (if (and (calc-var-value (nth 2 x))
2726 (not (eq (car-safe (symbol-value (nth 2 x)))
2727 'incomplete)))
2728 (let ((val (symbol-value (nth 2 x))))
2729 (if (eq (car-safe val) 'special-const)
2730 (if calc-symbolic-mode
2731 x
2732 val)
2733 val))
2734 x)
2735 (if (Math-primp x)
2736 x
2737 (cons (car x) (mapcar 'math-evaluate-expr-rec (cdr x))))))
2738 x))
2739
2740 (defun math-any-floats (expr)
2741 (if (Math-primp expr)
2742 (math-floatp expr)
2743 (while (and (setq expr (cdr expr)) (not (math-any-floats (car expr)))))
2744 expr))
2745
2746 (defvar var-FactorRules 'calc-FactorRules)
2747
2748 (defvar math-mt-many nil)
2749 (defvar math-mt-func nil)
2750
2751 (defun math-map-tree (math-mt-func mmt-expr &optional math-mt-many)
2752 (or math-mt-many (setq math-mt-many 1000000))
2753 (math-map-tree-rec mmt-expr))
2754
2755 (defun math-map-tree-rec (mmt-expr)
2756 (or (= math-mt-many 0)
2757 (let ((mmt-done nil)
2758 mmt-nextval)
2759 (while (not mmt-done)
2760 (while (and (/= math-mt-many 0)
2761 (setq mmt-nextval (funcall math-mt-func mmt-expr))
2762 (not (equal mmt-expr mmt-nextval)))
2763 (setq mmt-expr mmt-nextval
2764 math-mt-many (if (> math-mt-many 0)
2765 (1- math-mt-many)
2766 (1+ math-mt-many))))
2767 (if (or (Math-primp mmt-expr)
2768 (<= math-mt-many 0))
2769 (setq mmt-done t)
2770 (setq mmt-nextval (cons (car mmt-expr)
2771 (mapcar 'math-map-tree-rec
2772 (cdr mmt-expr))))
2773 (if (equal mmt-nextval mmt-expr)
2774 (setq mmt-done t)
2775 (setq mmt-expr mmt-nextval))))))
2776 mmt-expr)
2777
2778 (defun math-is-true (expr)
2779 (if (Math-numberp expr)
2780 (not (Math-zerop expr))
2781 (math-known-nonzerop expr)))
2782
2783 (defun math-const-var (expr)
2784 (and (consp expr)
2785 (eq (car expr) 'var)
2786 (or (and (symbolp (nth 2 expr))
2787 (boundp (nth 2 expr))
2788 (eq (car-safe (symbol-value (nth 2 expr))) 'special-const))
2789 (memq (nth 2 expr) '(var-inf var-uinf var-nan)))))
2790
2791 ;; The variable math-integral-cache is originally declared in calcalg2.el,
2792 ;; but is set by math-defintegral and math-definitegral2.
2793 (defvar math-integral-cache)
2794
2795 (defmacro math-defintegral (funcs &rest code)
2796 (setq math-integral-cache nil)
2797 (append '(progn)
2798 (mapcar (function
2799 (lambda (func)
2800 (list 'put (list 'quote func) ''math-integral
2801 (list 'nconc
2802 (list 'get (list 'quote func) ''math-integral)
2803 (list 'list
2804 (list 'function
2805 (append '(lambda (u))
2806 code)))))))
2807 (if (symbolp funcs) (list funcs) funcs))))
2808 (put 'math-defintegral 'lisp-indent-hook 1)
2809
2810 (defmacro math-defintegral-2 (funcs &rest code)
2811 (setq math-integral-cache nil)
2812 (append '(progn)
2813 (mapcar (function
2814 (lambda (func)
2815 (list 'put (list 'quote func) ''math-integral-2
2816 (list 'nconc
2817 (list 'get (list 'quote func)
2818 ''math-integral-2)
2819 (list 'list
2820 (list 'function
2821 (append '(lambda (u v))
2822 code)))))))
2823 (if (symbolp funcs) (list funcs) funcs))))
2824 (put 'math-defintegral-2 'lisp-indent-hook 1)
2825
2826 (defvar var-IntegAfterRules 'calc-IntegAfterRules)
2827
2828 (defvar var-FitRules 'calc-FitRules)
2829
2830 (defvar math-poly-base-variable nil)
2831 (defvar math-poly-neg-powers nil)
2832 (defvar math-poly-mult-powers 1)
2833 (defvar math-poly-frac-powers nil)
2834 (defvar math-poly-exp-base nil)
2835
2836 (defun math-build-var-name (name)
2837 (if (stringp name)
2838 (setq name (intern name)))
2839 (if (string-match "\\`var-." (symbol-name name))
2840 (list 'var (intern (substring (symbol-name name) 4)) name)
2841 (list 'var name (intern (concat "var-" (symbol-name name))))))
2842
2843 (defvar math-simplifying-units nil)
2844 (defvar math-combining-units t)
2845
2846 ;;; Nontrivial number parsing.
2847
2848 (defun math-read-number-fancy (s)
2849 (cond
2850
2851 ;; Integer+fractions
2852 ((string-match "^\\([0-9]*\\)[:/]\\([0-9]*\\)[:/]\\([0-9]*\\)$" s)
2853 (let ((int (math-match-substring s 1))
2854 (num (math-match-substring s 2))
2855 (den (math-match-substring s 3)))
2856 (let ((int (if (> (length int) 0) (math-read-number int) 0))
2857 (num (if (> (length num) 0) (math-read-number num) 1))
2858 (den (if (> (length num) 0) (math-read-number den) 1)))
2859 (and int num den
2860 (math-integerp int) (math-integerp num) (math-integerp den)
2861 (not (math-zerop den))
2862 (list 'frac (math-add num (math-mul int den)) den)))))
2863
2864 ;; Fractions
2865 ((string-match "^\\([0-9]*\\)[:/]\\([0-9]*\\)$" s)
2866 (let ((num (math-match-substring s 1))
2867 (den (math-match-substring s 2)))
2868 (let ((num (if (> (length num) 0) (math-read-number num) 1))
2869 (den (if (> (length num) 0) (math-read-number den) 1)))
2870 (and num den (math-integerp num) (math-integerp den)
2871 (not (math-zerop den))
2872 (list 'frac num den)))))
2873
2874 ;; Modulo forms
2875 ((string-match "^\\(.*\\) *mod *\\(.*\\)$" s)
2876 (let* ((n (math-match-substring s 1))
2877 (m (math-match-substring s 2))
2878 (n (math-read-number n))
2879 (m (math-read-number m)))
2880 (and n m (math-anglep n) (math-anglep m)
2881 (list 'mod n m))))
2882
2883 ;; Error forms
2884 ((string-match "^\\(.*\\) *\\+/- *\\(.*\\)$" s)
2885 (let* ((x (math-match-substring s 1))
2886 (sigma (math-match-substring s 2))
2887 (x (math-read-number x))
2888 (sigma (math-read-number sigma)))
2889 (and x sigma (math-scalarp x) (math-anglep sigma)
2890 (list 'sdev x sigma))))
2891
2892 ;; Hours (or degrees)
2893 ((or (string-match "^\\([^#^]+\\)[@oOhH]\\(.*\\)$" s)
2894 (string-match "^\\([^#^]+\\)[dD][eE]?[gG]?\\(.*\\)$" s))
2895 (let* ((hours (math-match-substring s 1))
2896 (minsec (math-match-substring s 2))
2897 (hours (math-read-number hours))
2898 (minsec (if (> (length minsec) 0) (math-read-number minsec) 0)))
2899 (and hours minsec
2900 (math-num-integerp hours)
2901 (not (math-negp hours)) (not (math-negp minsec))
2902 (cond ((math-num-integerp minsec)
2903 (and (Math-lessp minsec 60)
2904 (list 'hms hours minsec 0)))
2905 ((and (eq (car-safe minsec) 'hms)
2906 (math-zerop (nth 1 minsec)))
2907 (math-add (list 'hms hours 0 0) minsec))
2908 (t nil)))))
2909
2910 ;; Minutes
2911 ((string-match "^\\([^'#^]+\\)[mM']\\(.*\\)$" s)
2912 (let* ((minutes (math-match-substring s 1))
2913 (seconds (math-match-substring s 2))
2914 (minutes (math-read-number minutes))
2915 (seconds (if (> (length seconds) 0) (math-read-number seconds) 0)))
2916 (and minutes seconds
2917 (math-num-integerp minutes)
2918 (not (math-negp minutes)) (not (math-negp seconds))
2919 (cond ((math-realp seconds)
2920 (and (Math-lessp minutes 60)
2921 (list 'hms 0 minutes seconds)))
2922 ((and (eq (car-safe seconds) 'hms)
2923 (math-zerop (nth 1 seconds))
2924 (math-zerop (nth 2 seconds)))
2925 (math-add (list 'hms 0 minutes 0) seconds))
2926 (t nil)))))
2927
2928 ;; Seconds
2929 ((string-match "^\\([^\"#^]+\\)[sS\"]$" s)
2930 (let ((seconds (math-read-number (math-match-substring s 1))))
2931 (and seconds (math-realp seconds)
2932 (not (math-negp seconds))
2933 (Math-lessp seconds 60)
2934 (list 'hms 0 0 seconds))))
2935
2936 ;; Integer+fraction with explicit radix
2937 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]\\)$" s)
2938 (let ((radix (string-to-number (math-match-substring s 1)))
2939 (int (math-match-substring s 3))
2940 (num (math-match-substring s 4))
2941 (den (math-match-substring s 5)))
2942 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0))
2943 (num (if (> (length num) 0) (math-read-radix num radix) 1))
2944 (den (if (> (length den) 0) (math-read-radix den radix) 1)))
2945 (and int num den (not (math-zerop den))
2946 (list 'frac
2947 (math-add num (math-mul int den))
2948 den)))))
2949
2950 ;; Fraction with explicit radix
2951 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)$" s)
2952 (let ((radix (string-to-number (math-match-substring s 1)))
2953 (num (math-match-substring s 3))
2954 (den (math-match-substring s 4)))
2955 (let ((num (if (> (length num) 0) (math-read-radix num radix) 1))
2956 (den (if (> (length den) 0) (math-read-radix den radix) 1)))
2957 (and num den (not (math-zerop den)) (list 'frac num den)))))
2958
2959 ;; Float with explicit radix and exponent
2960 ((or (string-match "^0*\\(\\([2-9]\\|1[0-4]\\)\\(#\\|\\^\\^\\)[0-9a-dA-D.]+\\)[eE]\\([-+]?[0-9]+\\)$" s)
2961 (string-match "^\\(\\([0-9]+\\)\\(#\\|\\^\\^\\)[0-9a-zA-Z.]+\\) *\\* *\\2\\.? *\\^ *\\([-+]?[0-9]+\\)$" s))
2962 (let ((radix (string-to-number (math-match-substring s 2)))
2963 (mant (math-match-substring s 1))
2964 (exp (math-match-substring s 4)))
2965 (let ((mant (math-read-number mant))
2966 (exp (math-read-number exp)))
2967 (and mant exp
2968 (math-mul mant (math-pow (math-float radix) exp))))))
2969
2970 ;; Float with explicit radix, no exponent
2971 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)\\.\\([0-9a-zA-Z]*\\)$" s)
2972 (let ((radix (string-to-number (math-match-substring s 1)))
2973 (int (math-match-substring s 3))
2974 (fracs (math-match-substring s 4)))
2975 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0))
2976 (frac (if (> (length fracs) 0) (math-read-radix fracs radix) 0))
2977 (calc-prefer-frac nil))
2978 (and int frac
2979 (math-add int (math-div frac (math-pow radix (length fracs))))))))
2980
2981 ;; Integer with explicit radix
2982 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]+\\)$" s)
2983 (math-read-radix (math-match-substring s 3)
2984 (string-to-number (math-match-substring s 1))))
2985
2986 ;; C language hexadecimal notation
2987 ((and (eq calc-language 'c)
2988 (string-match "^0[xX]\\([0-9a-fA-F]+\\)$" s))
2989 (let ((digs (math-match-substring s 1)))
2990 (math-read-radix digs 16)))
2991
2992 ;; Pascal language hexadecimal notation
2993 ((and (eq calc-language 'pascal)
2994 (string-match "^\\$\\([0-9a-fA-F]+\\)$" s))
2995 (let ((digs (math-match-substring s 1)))
2996 (math-read-radix digs 16)))
2997
2998 ;; Fraction using "/" instead of ":"
2999 ((string-match "^\\([0-9]+\\)/\\([0-9/]+\\)$" s)
3000 (math-read-number (concat (math-match-substring s 1) ":"
3001 (math-match-substring s 2))))
3002
3003 ;; Syntax error!
3004 (t nil)))
3005
3006 (defun math-read-radix (s r) ; [I X D]
3007 (setq s (upcase s))
3008 (let ((i 0)
3009 (res 0)
3010 dig)
3011 (while (and (< i (length s))
3012 (setq dig (math-read-radix-digit (elt s i)))
3013 (< dig r))
3014 (setq res (math-add (math-mul res r) dig)
3015 i (1+ i)))
3016 (and (= i (length s))
3017 res)))
3018
3019
3020
3021 ;;; Expression parsing.
3022
3023 (defvar math-expr-data)
3024
3025 (defun math-read-expr (math-exp-str)
3026 (let ((math-exp-pos 0)
3027 (math-exp-old-pos 0)
3028 (math-exp-keep-spaces nil)
3029 math-exp-token math-expr-data)
3030 (setq math-exp-str (math-read-preprocess-string math-exp-str))
3031 (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
3032 (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots"
3033 (substring math-exp-str (+ math-exp-token 2)))))
3034 (math-build-parse-table)
3035 (math-read-token)
3036 (let ((val (catch 'syntax (math-read-expr-level 0))))
3037 (if (stringp val)
3038 (list 'error math-exp-old-pos val)
3039 (if (equal math-exp-token 'end)
3040 val
3041 (list 'error math-exp-old-pos "Syntax error"))))))
3042
3043 (defun math-read-plain-expr (exp-str &optional error-check)
3044 (let* ((calc-language nil)
3045 (math-expr-opers (math-standard-ops))
3046 (val (math-read-expr exp-str)))
3047 (and error-check
3048 (eq (car-safe val) 'error)
3049 (error "%s: %s" (nth 2 val) exp-str))
3050 val))
3051
3052
3053 (defun math-read-string ()
3054 (let ((str (read-from-string (concat math-expr-data "\""))))
3055 (or (and (= (cdr str) (1+ (length math-expr-data)))
3056 (stringp (car str)))
3057 (throw 'syntax "Error in string constant"))
3058 (math-read-token)
3059 (append '(vec) (car str) nil)))
3060
3061
3062
3063 ;;; They said it couldn't be done...
3064
3065 (defun math-read-big-expr (str)
3066 (and (> (length calc-left-label) 0)
3067 (string-match (concat "^" (regexp-quote calc-left-label)) str)
3068 (setq str (concat (substring str 0 (match-beginning 0))
3069 (substring str (match-end 0)))))
3070 (and (> (length calc-right-label) 0)
3071 (string-match (concat (regexp-quote calc-right-label) " *$") str)
3072 (setq str (concat (substring str 0 (match-beginning 0))
3073 (substring str (match-end 0)))))
3074 (if (string-match "\\\\[^ \n|]" str)
3075 (if (eq calc-language 'latex)
3076 (math-read-expr str)
3077 (let ((calc-language 'latex)
3078 (calc-language-option nil)
3079 (math-expr-opers (get 'latex 'math-oper-table))
3080 (math-expr-function-mapping (get 'latex 'math-function-table))
3081 (math-expr-variable-mapping (get 'latex 'math-variable-table)))
3082 (math-read-expr str)))
3083 (let ((math-read-big-lines nil)
3084 (pos 0)
3085 (width 0)
3086 (math-read-big-err-msg nil)
3087 math-read-big-baseline math-read-big-h2
3088 new-pos p)
3089 (while (setq new-pos (string-match "\n" str pos))
3090 (setq math-read-big-lines
3091 (cons (substring str pos new-pos) math-read-big-lines)
3092 pos (1+ new-pos)))
3093 (setq math-read-big-lines
3094 (nreverse (cons (substring str pos) math-read-big-lines))
3095 p math-read-big-lines)
3096 (while p
3097 (setq width (max width (length (car p)))
3098 p (cdr p)))
3099 (if (math-read-big-bigp math-read-big-lines)
3100 (or (catch 'syntax
3101 (math-read-big-rec 0 0 width (length math-read-big-lines)))
3102 math-read-big-err-msg
3103 '(error 0 "Syntax error"))
3104 (math-read-expr str)))))
3105
3106 (defun math-read-big-bigp (math-read-big-lines)
3107 (and (cdr math-read-big-lines)
3108 (let ((matrix nil)
3109 (v 0)
3110 (height (if (> (length (car math-read-big-lines)) 0) 1 0)))
3111 (while (and (cdr math-read-big-lines)
3112 (let* ((i 0)
3113 j
3114 (l1 (car math-read-big-lines))
3115 (l2 (nth 1 math-read-big-lines))
3116 (len (min (length l1) (length l2))))
3117 (if (> (length l2) 0)
3118 (setq height (1+ height)))
3119 (while (and (< i len)
3120 (or (memq (aref l1 i) '(?\ ?\- ?\_))
3121 (memq (aref l2 i) '(?\ ?\-))
3122 (and (memq (aref l1 i) '(?\| ?\,))
3123 (= (aref l2 i) (aref l1 i)))
3124 (and (eq (aref l1 i) ?\[)
3125 (eq (aref l2 i) ?\[)
3126 (let ((math-rb-h2 (length l1)))
3127 (setq j (math-read-big-balance
3128 (1+ i) v "[")))
3129 (setq i (1- j)))))
3130 (setq i (1+ i)))
3131 (or (= i len)
3132 (and (eq (aref l1 i) ?\[)
3133 (eq (aref l2 i) ?\[)
3134 (setq matrix t)
3135 nil))))
3136 (setq math-read-big-lines (cdr math-read-big-lines)
3137 v (1+ v)))
3138 (or (and (> height 1)
3139 (not (cdr math-read-big-lines)))
3140 matrix))))
3141
3142 ;;; Nontrivial "flat" formatting.
3143
3144 (defvar math-format-hash-args nil)
3145 (defvar calc-can-abbrev-vectors nil)
3146
3147 (defun math-format-flat-expr-fancy (a prec)
3148 (cond
3149 ((eq (car a) 'incomplete)
3150 (format "<incomplete %s>" (nth 1 a)))
3151 ((eq (car a) 'vec)
3152 (if (or calc-full-trail-vectors (not calc-can-abbrev-vectors)
3153 (< (length a) 7))
3154 (concat "[" (math-format-flat-vector (cdr a) ", "
3155 (if (cdr (cdr a)) 0 1000)) "]")
3156 (concat "["
3157 (math-format-flat-expr (nth 1 a) 0) ", "
3158 (math-format-flat-expr (nth 2 a) 0) ", "
3159 (math-format-flat-expr (nth 3 a) 0) ", ..., "
3160 (math-format-flat-expr (nth (1- (length a)) a) 0) "]")))
3161 ((eq (car a) 'intv)
3162 (concat (if (memq (nth 1 a) '(0 1)) "(" "[")
3163 (math-format-flat-expr (nth 2 a) 1000)
3164 " .. "
3165 (math-format-flat-expr (nth 3 a) 1000)
3166 (if (memq (nth 1 a) '(0 2)) ")" "]")))
3167 ((eq (car a) 'date)
3168 (concat "<" (math-format-date a) ">"))
3169 ((and (eq (car a) 'calcFunc-lambda) (> (length a) 2))
3170 (let ((p (cdr a))
3171 (ap calc-arg-values)
3172 (math-format-hash-args (if (= (length a) 3) 1 t)))
3173 (while (and (cdr p) (equal (car p) (car ap)))
3174 (setq p (cdr p) ap (cdr ap)))
3175 (concat "<"
3176 (if (cdr p)
3177 (concat (math-format-flat-vector
3178 (nreverse (cdr (reverse (cdr a)))) ", " 0)
3179 " : ")
3180 "")
3181 (math-format-flat-expr (nth (1- (length a)) a) 0)
3182 ">")))
3183 ((eq (car a) 'var)
3184 (or (and math-format-hash-args
3185 (let ((p calc-arg-values) (v 1))
3186 (while (and p (not (equal (car p) a)))
3187 (setq p (and (eq math-format-hash-args t) (cdr p))
3188 v (1+ v)))
3189 (and p
3190 (if (eq math-format-hash-args 1)
3191 "#"
3192 (format "#%d" v)))))
3193 (symbol-name (nth 1 a))))
3194 ((and (memq (car a) '(calcFunc-string calcFunc-bstring))
3195 (= (length a) 2)
3196 (math-vectorp (nth 1 a))
3197 (math-vector-is-string (nth 1 a)))
3198 (concat (substring (symbol-name (car a)) 9)
3199 "(" (math-vector-to-string (nth 1 a) t) ")"))
3200 (t
3201 (let ((op (math-assq2 (car a) (math-standard-ops))))
3202 (cond ((and op (= (length a) 3))
3203 (if (> prec (min (nth 2 op) (nth 3 op)))
3204 (concat "(" (math-format-flat-expr a 0) ")")
3205 (let ((lhs (math-format-flat-expr (nth 1 a) (nth 2 op)))
3206 (rhs (math-format-flat-expr (nth 2 a) (nth 3 op))))
3207 (setq op (car op))
3208 (if (or (equal op "^") (equal op "_"))
3209 (if (= (aref lhs 0) ?-)
3210 (setq lhs (concat "(" lhs ")")))
3211 (setq op (concat " " op " ")))
3212 (concat lhs op rhs))))
3213 ((eq (car a) 'neg)
3214 (concat "-" (math-format-flat-expr (nth 1 a) 1000)))
3215 (t
3216 (concat (math-remove-dashes
3217 (if (string-match "\\`calcFunc-\\([a-zA-Z0-9']+\\)\\'"
3218 (symbol-name (car a)))
3219 (math-match-substring (symbol-name (car a)) 1)
3220 (symbol-name (car a))))
3221 "("
3222 (math-format-flat-vector (cdr a) ", " 0)
3223 ")")))))))
3224
3225 (defun math-format-flat-vector (vec sep prec)
3226 (if vec
3227 (let ((buf (math-format-flat-expr (car vec) prec)))
3228 (while (setq vec (cdr vec))
3229 (setq buf (concat buf sep (math-format-flat-expr (car vec) prec))))
3230 buf)
3231 ""))
3232
3233 (defun math-format-nice-expr (x w)
3234 (cond ((and (eq (car-safe x) 'vec)
3235 (cdr (cdr x))
3236 (let ((ops '(vec calcFunc-assign calcFunc-condition
3237 calcFunc-schedule calcFunc-iterations
3238 calcFunc-phase)))
3239 (or (memq (car-safe (nth 1 x)) ops)
3240 (memq (car-safe (nth 2 x)) ops)
3241 (memq (car-safe (nth 3 x)) ops)
3242 calc-break-vectors)))
3243 (concat "[ " (math-format-flat-vector (cdr x) ",\n " 0) " ]"))
3244 (t
3245 (let ((str (math-format-flat-expr x 0))
3246 (pos 0) p)
3247 (or (string-match "\"" str)
3248 (while (<= (setq p (+ pos w)) (length str))
3249 (while (and (> (setq p (1- p)) pos)
3250 (not (= (aref str p) ? ))))
3251 (if (> p (+ pos 5))
3252 (setq str (concat (substring str 0 p)
3253 "\n "
3254 (substring str p))
3255 pos (1+ p))
3256 (setq pos (+ pos w)))))
3257 str))))
3258
3259 (defun math-assq2 (v a)
3260 (while (and a (not (eq v (nth 1 (car a)))))
3261 (setq a (cdr a)))
3262 (car a))
3263
3264 (defun math-format-number-fancy (a prec)
3265 (cond
3266 ((eq (car a) 'float) ; non-decimal radix
3267 (if (Math-integer-negp (nth 1 a))
3268 (concat "-" (math-format-number (math-neg a)))
3269 (let ((str (if (and calc-radix-formatter
3270 (not (memq calc-language '(c pascal))))
3271 (funcall calc-radix-formatter
3272 calc-number-radix
3273 (math-format-radix-float a prec))
3274 (format "%d#%s" calc-number-radix
3275 (math-format-radix-float a prec)))))
3276 (if (and prec (> prec 191) (string-match "\\*" str))
3277 (concat "(" str ")")
3278 str))))
3279 ((eq (car a) 'frac)
3280 (setq a (math-adjust-fraction a))
3281 (if (> (length (car calc-frac-format)) 1)
3282 (if (Math-integer-negp (nth 1 a))
3283 (concat "-" (math-format-number (math-neg a)))
3284 (let ((q (math-idivmod (nth 1 a) (nth 2 a))))
3285 (concat (let ((calc-frac-format nil))
3286 (math-format-number (car q)))
3287 (substring (car calc-frac-format) 0 1)
3288 (let ((math-radix-explicit-format nil)
3289 (calc-frac-format nil))
3290 (math-format-number (cdr q)))
3291 (substring (car calc-frac-format) 1 2)
3292 (let ((math-radix-explicit-format nil)
3293 (calc-frac-format nil))
3294 (math-format-number (nth 2 a))))))
3295 (concat (let ((calc-frac-format nil))
3296 (math-format-number (nth 1 a)))
3297 (car calc-frac-format)
3298 (let ((math-radix-explicit-format nil)
3299 (calc-frac-format nil))
3300 (math-format-number (nth 2 a))))))
3301 ((eq (car a) 'cplx)
3302 (if (math-zerop (nth 2 a))
3303 (math-format-number (nth 1 a))
3304 (if (null calc-complex-format)
3305 (concat "(" (math-format-number (nth 1 a))
3306 ", " (math-format-number (nth 2 a)) ")")
3307 (if (math-zerop (nth 1 a))
3308 (if (math-equal-int (nth 2 a) 1)
3309 (symbol-name calc-complex-format)
3310 (if (math-equal-int (nth 2 a) -1)
3311 (concat "-" (symbol-name calc-complex-format))
3312 (if prec
3313 (math-compose-expr (list '* (nth 2 a) '(cplx 0 1)) prec)
3314 (concat (math-format-number (nth 2 a)) " "
3315 (symbol-name calc-complex-format)))))
3316 (if prec
3317 (math-compose-expr (list (if (math-negp (nth 2 a)) '- '+)
3318 (nth 1 a)
3319 (list 'cplx 0 (math-abs (nth 2 a))))
3320 prec)
3321 (concat (math-format-number (nth 1 a))
3322 (if (math-negp (nth 2 a)) " - " " + ")
3323 (math-format-number
3324 (list 'cplx 0 (math-abs (nth 2 a))))))))))
3325 ((eq (car a) 'polar)
3326 (concat "(" (math-format-number (nth 1 a))
3327 "; " (math-format-number (nth 2 a)) ")"))
3328 ((eq (car a) 'hms)
3329 (if (math-negp a)
3330 (concat "-" (math-format-number (math-neg a)))
3331 (let ((calc-number-radix 10)
3332 (calc-leading-zeros nil)
3333 (calc-group-digits nil))
3334 (format calc-hms-format
3335 (let ((calc-frac-format '(":" nil)))
3336 (math-format-number (nth 1 a)))
3337 (let ((calc-frac-format '(":" nil)))
3338 (math-format-number (nth 2 a)))
3339 (math-format-number (nth 3 a))))))
3340 ((eq (car a) 'intv)
3341 (concat (if (memq (nth 1 a) '(0 1)) "(" "[")
3342 (math-format-number (nth 2 a))
3343 " .. "
3344 (math-format-number (nth 3 a))
3345 (if (memq (nth 1 a) '(0 2)) ")" "]")))
3346 ((eq (car a) 'sdev)
3347 (concat (math-format-number (nth 1 a))
3348 " +/- "
3349 (math-format-number (nth 2 a))))
3350 ((eq (car a) 'vec)
3351 (math-format-flat-expr a 0))
3352 (t (format "%s" a))))
3353
3354 (defun math-adjust-fraction (a)
3355 (if (nth 1 calc-frac-format)
3356 (progn
3357 (if (Math-integerp a) (setq a (list 'frac a 1)))
3358 (let ((g (math-quotient (nth 1 calc-frac-format)
3359 (math-gcd (nth 2 a)
3360 (nth 1 calc-frac-format)))))
3361 (list 'frac (math-mul (nth 1 a) g) (math-mul (nth 2 a) g))))
3362 a))
3363
3364 (defun math-format-bignum-fancy (a) ; [X L]
3365 (let ((str (cond ((= calc-number-radix 10)
3366 (math-format-bignum-decimal a))
3367 ((= calc-number-radix 2)
3368 (math-format-bignum-binary a))
3369 ((= calc-number-radix 8)
3370 (math-format-bignum-octal a))
3371 ((= calc-number-radix 16)
3372 (math-format-bignum-hex a))
3373 (t (math-format-bignum-radix a)))))
3374 (if calc-leading-zeros
3375 (let* ((calc-internal-prec 6)
3376 (digs (math-compute-max-digits (math-abs calc-word-size)
3377 calc-number-radix))
3378 (len (length str)))
3379 (if (< len digs)
3380 (setq str (concat (make-string (- digs len) ?0) str)))))
3381 (if calc-group-digits
3382 (let ((i (length str))
3383 (g (if (integerp calc-group-digits)
3384 (math-abs calc-group-digits)
3385 (if (memq calc-number-radix '(2 16)) 4 3))))
3386 (while (> i g)
3387 (setq i (- i g)
3388 str (concat (substring str 0 i)
3389 calc-group-char
3390 (substring str i))))
3391 str))
3392 (if (and (/= calc-number-radix 10)
3393 math-radix-explicit-format)
3394 (if calc-radix-formatter
3395 (funcall calc-radix-formatter calc-number-radix str)
3396 (format "%d#%s" calc-number-radix str))
3397 str)))
3398
3399
3400 (defun math-group-float (str) ; [X X]
3401 (let* ((pt (or (string-match "[^0-9a-zA-Z]" str) (length str)))
3402 (g (if (integerp calc-group-digits) (math-abs calc-group-digits) 3))
3403 (i pt))
3404 (if (and (integerp calc-group-digits) (< calc-group-digits 0))
3405 (while (< (setq i (+ (1+ i) g)) (length str))
3406 (setq str (concat (substring str 0 i)
3407 calc-group-char
3408 (substring str i))
3409 i (+ i (1- (length calc-group-char))))))
3410 (setq i pt)
3411 (while (> i g)
3412 (setq i (- i g)
3413 str (concat (substring str 0 i)
3414 calc-group-char
3415 (substring str i))))
3416 str))
3417
3418 ;;; Users can redefine this in their .emacs files.
3419 (defvar calc-keypad-user-menu nil
3420 "If non-nil, this describes an additional menu for calc-keypad.
3421 It should contain a list of three rows.
3422 Each row should be a list of six keys.
3423 Each key should be a list of a label string, plus a Calc command name spec.
3424 A command spec is a command name symbol, a keyboard macro string, a
3425 list containing a numeric entry string, or nil.
3426 A key may contain additional specs for Inverse, Hyperbolic, and Inv+Hyp.")
3427
3428 (run-hooks 'calc-ext-load-hook)
3429
3430 (provide 'calc-ext)
3431
3432 ;;; arch-tag: 1814ba7f-a390-49dc-9e25-a5adc205e97e
3433 ;;; calc-ext.el ends here