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