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