root/trunk/lisp/calc/calc.el

Revision 4220, 120.1 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

Line 
1 ;;; calc.el --- the GNU Emacs calculator
2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; Keywords: convenience, extensions
9 ;; Version: 2.1
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;; Calc is split into many files.  This file is the main entry point.
31 ;; This file includes autoload commands for various other basic Calc
32 ;; facilities.  The more advanced features are based in calc-ext, which
33 ;; in turn contains autoloads for the rest of the Calc files.  This
34 ;; odd set of interactions is designed to make Calc's loading time
35 ;; be as short as possible when only simple calculations are needed.
36
37 ;; Original author's address:
38 ;;  Dave Gillespie, daveg@synaptics.com, uunet!synaptx!daveg.
39 ;;  Synaptics, Inc., 2698 Orchard Parkway, San Jose, CA 95134.
40 ;;
41 ;; The old address daveg@csvax.cs.caltech.edu will continue to
42 ;; work for the foreseeable future.
43 ;;
44 ;; Bug reports and suggestions are always welcome!  (Type M-x
45 ;; report-calc-bug to send them).
46
47 ;; All functions, macros, and Lisp variables defined here begin with one
48 ;; of the prefixes "math", "Math", or "calc", with the exceptions of
49 ;; "full-calc", "full-calc-keypad", "another-calc", "quick-calc",
50 ;; "report-calc-bug", and "defmath".  User-accessible variables begin
51 ;; with "var-".
52
53 ;;; TODO:
54
55 ;;   Fix rewrite mechanism to do less gratuitous rearrangement of terms.
56 ;;   Implement a pattern-based "refers" predicate.
57 ;;
58 ;;   Make it possible to Undo a selection command.
59 ;;   Figure out how to allow selecting rows of matrices.
60 ;;   If cursor was in selection before, move it after j n, j p, j L, etc.
61 ;;   Consider reimplementing calc-delete-selection using rewrites.
62 ;;
63 ;;   Implement line-breaking in non-flat compositions (is this desirable?).
64 ;;   Implement matrix formatting with multi-line components.
65 ;;
66 ;;   Have "Z R" define a user command based on a set of rewrite rules.
67 ;;   Support "incf" and "decf" in defmath definitions.
68 ;;   Have defmath generate calls to calc-binary-op or calc-unary-op.
69 ;;   Make some way to define algebraic functions using keyboard macros.
70 ;;
71 ;;   Allow calc-word-size=0 => Common Lisp-style signed bitwise arithmetic.
72 ;;   Consider digamma function (and thus arb. prec. Euler's gamma constant).
73 ;;   May as well make continued-fractions stuff available to the user.
74 ;;
75 ;;   How about matrix eigenvalues, SVD, pseudo-inverse, etc.?
76 ;;   Should cache matrix inverses as well as decompositions.
77 ;;   If dividing by a non-square matrix, use least-squares automatically.
78 ;;   Consider supporting matrix exponentials.
79 ;;
80 ;;   Have ninteg detect and work around singularities at the endpoints.
81 ;;   Use an adaptive subdivision algorithm for ninteg.
82 ;;   Provide nsum and nprod to go along with ninteg.
83 ;;
84 ;;   Handle TeX-mode parsing of \matrix{ ... } where ... contains braces.
85 ;;   Support AmS-TeX's \{d,t,}frac, \{d,t,}binom notations.
86 ;;   Format and parse sums and products in Eqn and Math modes.
87 ;;
88 ;;   Get math-read-big-expr to read sums, products, etc.
89 ;;   Change calc-grab-region to use math-read-big-expr.
90 ;;   Have a way to define functions using := in Embedded Mode.
91 ;;
92 ;;   Support polar plotting with GNUPLOT.
93 ;;   Make a calc-graph-histogram function.
94 ;;
95 ;;   Replace hokey formulas for complex functions with formulas designed
96 ;;      to minimize roundoff while maintaining the proper branch cuts.
97 ;;   Test accuracy of advanced math functions over whole complex plane.
98 ;;   Extend Bessel functions to provide arbitrary precision.
99 ;;   Extend advanced math functions to handle error forms and intervals.
100 ;;   Provide a better implementation for math-sin-cos-raw.
101 ;;   Provide a better implementation for math-hypot.
102 ;;   Provide a better implementation for math-make-frac.
103 ;;   Provide a better implementation for calcFunc-prfac.
104 ;;   Provide a better implementation for calcFunc-factor.
105 ;;
106 ;;   Provide more examples in the tutorial section of the manual.
107 ;;   Cover in the tutorial:  simplification modes, declarations,
108 ;;       bitwise stuff, selections, matrix mapping, financial functions.
109 ;;   Provide more Lisp programming examples in the manual.
110 ;;   Finish the Internals section of the manual (and bring it up to date).
111 ;;
112 ;;   Tim suggests adding spreadsheet-like features.
113 ;;   Implement language modes for Gnuplot, Lisp, Ada, APL, ...?
114 ;;
115 ;; For atan series, if x > tan(pi/12) (about 0.268) reduce using the identity
116 ;;   atan(x) = atan((x * sqrt(3) - 1) / (sqrt(3) + x)) + pi/6.
117 ;;
118 ;; A better integration algorithm:
119 ;;   Use breadth-first instead of depth-first search, as follows:
120 ;;      The integral cache allows unfinished integrals in symbolic notation
121 ;;      on the righthand side.  An entry with no unfinished integrals on the
122 ;;      RHS is "complete"; references to it elsewhere are replaced by the
123 ;;      integrated value.  More than one cache entry for the same integral
124 ;;      may exist, though if one becomes complete, the others may be deleted.
125 ;;      The integrator works by using every applicable rule (such as
126 ;;      substitution, parts, linearity, etc.) to generate possible righthand
127 ;;      sides, all of which are entered into the cache.  Now, as long as the
128 ;;      target integral is not complete (and the time limit has not run out)
129 ;;      choose an incomplete integral from the cache and, for every integral
130 ;;      appearing in its RHS's, add those integrals to the cache using the
131 ;;      same substitition, parts, etc. rules.  The cache should be organized
132 ;;      as a priority queue, choosing the "simplest" incomplete integral at
133 ;;      each step, or choosing randomly among equally simple integrals.
134 ;;      Simplicity equals small size, and few steps removed from the original
135 ;;      target integral.  Note that when the integrator finishes, incomplete
136 ;;      integrals can be left in the cache, so the algorithm can start where
137 ;;      it left off if another similar integral is later requested.
138 ;;   Breadth-first search would avoid the nagging problem of, e.g., whether
139 ;;   to use parts or substitution first, and which decomposition is best.
140 ;;   All are tried, and any path that diverges will quickly be put on the
141 ;;   back burner by the priority queue.
142 ;;   Note: Probably a good idea to call math-simplify-extended before
143 ;;   measuring a formula's simplicity.
144
145 ;; From: "Robert J. Chassell" <bob@rattlesnake.com>
146 ;; Subject: Re: fix for `Cannot open load file: calc-alg-3'
147 ;; To: walters@debian.org
148 ;; Date: Sat, 24 Nov 2001 21:44:21 +0000 (UTC)
149 ;;
150 ;; Could you add logistic curve fitting to the current list?
151 ;;
152 ;; (I guess the key binding for a logistic curve would have to be `s'
153 ;; since a logistic curve is an `s' curve; both `l' and `L' are already
154 ;; taken for logarithms.)
155 ;;
156 ;; Here is the current list for curve fitting;
157 ;;
158 ;;     `1'
159 ;;          Linear or multilinear.  a + b x + c y + d z.
160 ;;
161 ;;     `2-9'
162 ;;          Polynomials.  a + b x + c x^2 + d x^3.
163 ;;
164 ;;     `e'
165 ;;          Exponential.  a exp(b x) exp(c y).
166 ;;
167 ;;     `E'
168 ;;          Base-10 exponential.  a 10^(b x) 10^(c y).
169 ;;
170 ;;     `x'
171 ;;          Exponential (alternate notation).  exp(a + b x + c y).
172 ;;
173 ;;     `X'
174 ;;          Base-10 exponential (alternate).  10^(a + b x + c y).
175 ;;
176 ;;     `l'
177 ;;          Logarithmic.  a + b ln(x) + c ln(y).
178 ;;
179 ;;     `L'
180 ;;          Base-10 logarithmic.  a + b log10(x) + c log10(y).
181 ;;
182 ;;     `^'
183 ;;          General exponential.  a b^x c^y.
184 ;;
185 ;;     `p'
186 ;;          Power law.  a x^b y^c.
187 ;;
188 ;;     `q'
189 ;;          Quadratic.  a + b (x-c)^2 + d (x-e)^2.
190 ;;
191 ;;     `g'
192 ;;          Gaussian.  (a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2).
193 ;;
194 ;;
195 ;; Logistic curves are used a great deal in ecology, and in predicting
196 ;; human actions, such as use of different kinds of energy in a country
197 ;; (wood, coal, oil, natural gas, etc.) or the number of scientific
198 ;; papers a person publishes, or the number of movies made.
199 ;;
200 ;; (The less information on which to base the curve, the higher the error
201 ;; rate.  Theodore Modis ran some Monte Carlo simulations and produced
202 ;; what may be useful set of confidence levels for different amounts of
203 ;; initial information.)
204
205 ;;; Code:
206
207 (require 'calc-macs)
208
209 (defgroup calc nil
210   "GNU Calc."
211   :prefix "calc-"
212   :tag    "Calc"
213   :group  'applications)
214
215 ;;;###autoload
216 (defcustom calc-settings-file
217   (convert-standard-filename "~/.calc.el")
218   "*File in which to record permanent settings."
219   :group 'calc
220   :type '(file))
221
222 (defcustom calc-language-alist
223   '((latex-mode . latex)
224     (tex-mode   . tex)
225     (plain-tex-mode . tex)
226     (context-mode . tex)
227     (nroff-mode . eqn)
228     (pascal-mode . pascal)
229     (c-mode . c)
230     (c++-mode . c)
231     (fortran-mode . fortran)
232     (f90-mode . fortran))
233   "*Alist of major modes with appropriate Calc languages."
234   :group 'calc
235   :type '(alist :key-type (symbol :tag "Major mode")
236                 :value-type (symbol :tag "Calc language")))
237
238 (defcustom calc-embedded-announce-formula
239   "%Embed\n\\(% .*\n\\)*"
240   "*A regular expression which is sure to be followed by a calc-embedded formula."
241   :group 'calc
242   :type '(regexp))
243
244 (defcustom calc-embedded-announce-formula-alist
245   '((c++-mode     . "//Embed\n\\(// .*\n\\)*")
246     (c-mode       . "/\\*Embed\\*/\n\\(/\\* .*\\*/\n\\)*")
247     (f90-mode     . "!Embed\n\\(! .*\n\\)*")
248     (fortran-mode . "C Embed\n\\(C .*\n\\)*")
249     (html-helper-mode . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
250     (html-mode    . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
251     (nroff-mode   . "\\\\\"Embed\n\\(\\\\\" .*\n\\)*")
252     (pascal-mode  . "{Embed}\n\\({.*}\n\\)*")
253     (sgml-mode    . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
254     (xml-mode     . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
255     (texinfo-mode . "@c Embed\n\\(@c .*\n\\)*"))
256   "*Alist of major modes with appropriate values for `calc-embedded-announce-formula'."
257   :group 'calc
258   :type '(alist :key-type (symbol :tag "Major mode")
259                 :value-type (regexp :tag "Regexp to announce formula")))
260
261 (defcustom calc-embedded-open-formula
262   "\\`\\|^\n\\|\\$\\$?\\|\\\\\\[\\|^\\\\begin[^{].*\n\\|^\\\\begin{.*[^x]}.*\n\\|^@.*\n\\|^\\.EQ.*\n\\|\\\\(\\|^%\n\\|^\\.\\\\\"\n"
263   "*A regular expression for the opening delimiter of a formula used by calc-embedded."
264   :group 'calc
265   :type '(regexp))
266
267 (defcustom calc-embedded-close-formula
268   "\\'\\|\n$\\|\\$\\$?\\|\\\\]\\|^\\\\end[^{].*\n\\|^\\\\end{.*[^x]}.*\n\\|^@.*\n\\|^\\.EN.*\n\\|\\\\)\\|\n%\n\\|^\\.\\\\\"\n"
269   "*A regular expression for the closing delimiter of a formula used by calc-embedded."
270   :group 'calc
271   :type '(regexp))
272
273 (defcustom calc-embedded-open-close-formula-alist
274   nil
275   "*Alist of major modes with pairs of formula delimiters used by calc-embedded."
276   :group 'calc
277   :type '(alist :key-type (symbol :tag "Major mode")
278                 :value-type (list (regexp :tag "Opening formula delimiter")
279                                   (regexp :tag "Closing formula delimiter"))))
280
281 (defcustom calc-embedded-open-word
282   "^\\|[^-+0-9.eE]"
283   "*A regular expression for the opening delimiter of a formula used by calc-embedded-word."
284   :group 'calc
285   :type '(regexp))
286
287 (defcustom calc-embedded-close-word
288   "$\\|[^-+0-9.eE]"
289   "*A regular expression for the closing delimiter of a formula used by calc-embedded-word."
290   :group 'calc
291   :type '(regexp))
292
293 (defcustom calc-embedded-open-close-word-alist
294   nil
295   "*Alist of major modes with pairs of word delimiters used by calc-embedded."
296   :group 'calc
297   :type '(alist :key-type (symbol :tag "Major mode")
298                 :value-type (list (regexp :tag "Opening word delimiter")
299                                   (regexp :tag "Closing word delimiter"))))
300
301 (defcustom calc-embedded-open-plain
302   "%%% "
303   "*A string which is the opening delimiter for a \"plain\" formula.
304 If calc-show-plain mode is enabled, this is inserted at the front of
305 each formula."
306   :group 'calc
307   :type '(string))
308
309 (defcustom calc-embedded-close-plain
310   " %%%\n"
311   "*A string which is the closing delimiter for a \"plain\" formula.
312 See calc-embedded-open-plain."
313   :group 'calc
314   :type '(string))
315
316 (defcustom calc-embedded-open-close-plain-alist
317   '((c++-mode     "// %% "   " %%\n")
318     (c-mode       "/* %% "   " %% */\n")
319     (f90-mode     "! %% "    " %%\n")
320     (fortran-mode "C %% "    " %%\n")
321     (html-helper-mode "<!-- %% " " %% -->\n")
322     (html-mode "<!-- %% " " %% -->\n")
323     (nroff-mode   "\\\" %% " " %%\n")
324     (pascal-mode  "{%% "    " %%}\n")
325     (sgml-mode     "<!-- %% " " %% -->\n")
326     (xml-mode     "<!-- %% " " %% -->\n")
327     (texinfo-mode "@c %% "   " %%\n"))
328   "*Alist of major modes with pairs of delimiters for \"plain\" formulas."
329   :group 'calc
330   :type '(alist :key-type (symbol :tag "Major mode")
331                 :value-type (list (string :tag "Opening \"plain\" delimiter")
332                                   (string :tag "Closing \"plain\" delimiter"))))
333
334 (defcustom calc-embedded-open-new-formula
335   "\n\n"
336   "*A string which is inserted at front of formula by calc-embedded-new-formula."
337   :group 'calc
338   :type '(string))
339
340 (defcustom calc-embedded-close-new-formula
341   "\n\n"
342   "*A string which is inserted at end of formula by calc-embedded-new-formula."
343   :group 'calc
344   :type '(string))
345
346 (defcustom calc-embedded-open-close-new-formula-alist
347   nil
348   "*Alist of major modes with pairs of new formula delimiters used by calc-embedded."
349   :group 'calc
350   :type '(alist :key-type (symbol :tag "Major mode")
351                 :value-type (list (string :tag "Opening new formula delimiter")
352                                   (string :tag "Closing new formula delimiter"))))
353
354 (defcustom calc-embedded-open-mode
355   "% "
356   "*A string which should precede calc-embedded mode annotations.
357 This is not required to be present for user-written mode annotations."
358   :group 'calc
359   :type '(string))
360
361 (defcustom calc-embedded-close-mode
362   "\n"
363   "*A string which should follow calc-embedded mode annotations.
364 This is not required to be present for user-written mode annotations."
365   :group 'calc
366   :type '(string))
367
368 (defcustom calc-embedded-open-close-mode-alist
369   '((c++-mode     "// "   "\n")
370     (c-mode       "/* "   " */\n")
371     (f90-mode     "! "    "\n")
372     (fortran-mode "C "    "\n")
373     (html-helper-mode "<!-- " " -->\n")
374     (html-mode    "<!-- " " -->\n")
375     (nroff-mode   "\\\" " "\n")
376     (pascal-mode  "{ "    " }\n")
377     (sgml-mode    "<!-- " " -->\n")
378     (xml-mode     "<!-- " " -->\n")
379     (texinfo-mode "@c "   "\n"))
380   "*Alist of major modes with pairs of strings to delimit annotations."
381   :group 'calc
382   :type '(alist :key-type (symbol :tag "Major mode")
383                 :value-type (list (string :tag "Opening annotation delimiter")
384                                   (string :tag "Closing annotation delimiter"))))
385
386 (defcustom calc-gnuplot-name
387   "gnuplot"
388   "*Name of GNUPLOT program, for calc-graph features."
389   :group 'calc
390   :type '(string))
391
392 (defcustom calc-gnuplot-plot-command
393   nil
394   "*Name of command for displaying GNUPLOT output; %s = file name to print."
395   :group 'calc
396   :type '(choice (string) (sexp)))
397
398 (defcustom calc-gnuplot-print-command
399   "lp %s"
400   "*Name of command for printing GNUPLOT output; %s = file name to print."
401   :group 'calc
402   :type '(choice (string) (sexp)))
403
404 (defvar calc-bug-address "jay.p.belanger@gmail.com"
405   "Address of the maintainer of Calc, for use by `report-calc-bug'.")
406
407 (defvar calc-scan-for-dels t
408   "If t, scan keymaps to find all DEL-like keys.
409 if nil, only DEL itself is mapped to calc-pop.")
410
411 (defvar calc-stack '((top-of-stack 1 nil))
412   "Calculator stack.
413 Entries are 3-lists:  Formula, Height (in lines), Selection (or nil).")
414
415 (defvar calc-stack-top 1
416   "Index into `calc-stack' of \"top\" of stack.
417 This is 1 unless `calc-truncate-stack' has been used.")
418
419 (defvar calc-display-sci-high 0
420   "Floating-point numbers with this positive exponent or higher above the
421 current precision are displayed in scientific notation in calc-mode.")
422
423 (defvar calc-display-sci-low -3
424   "Floating-point numbers with this negative exponent or lower are displayed
425 scientific notation in calc-mode.")
426
427 (defvar calc-other-modes nil
428   "List of used-defined strings to append to Calculator mode line.")
429
430 (defvar calc-Y-help-msgs nil
431   "List of strings for Y prefix help.")
432
433 (defvar calc-loaded-settings-file nil
434   "t if `calc-settings-file' has been loaded yet.")
435
436
437 (defvar calc-mode-var-list '()
438   "List of variables used in customizing GNU Calc.")
439
440 (defmacro defcalcmodevar (var defval &optional doc)
441   `(progn
442      (defvar ,var ,defval ,doc)
443      (add-to-list 'calc-mode-var-list (list (quote ,var) ,defval))))
444
445 (defun calc-mode-var-list-restore-default-values ()
446   (mapcar (function (lambda (v) (set (car v) (nth 1 v))))
447           calc-mode-var-list))
448
449 (defun calc-mode-var-list-restore-saved-values ()
450   (let ((newvarlist '()))
451     (save-excursion
452       (let (pos
453             (file (substitute-in-file-name calc-settings-file)))
454         (when (and
455                (file-regular-p file)
456                (set-buffer (find-file-noselect file))
457                (goto-char (point-min))
458                (search-forward ";;; Mode settings stored by Calc" nil t)
459                (progn
460                  (forward-line 1)
461                  (setq pos (point))
462                  (search-forward "\n;;; End of mode settings" nil t)))
463           (beginning-of-line)
464           (calc-mode-var-list-restore-default-values)
465           (eval-region pos (point))
466           (let ((varlist calc-mode-var-list))
467             (while varlist
468               (let ((var (car varlist)))
469                 (setq newvarlist
470                       (cons (list (car var) (symbol-value (car var)))
471                             newvarlist)))
472               (setq varlist (cdr varlist)))))))
473     (if newvarlist
474         (mapcar (function (lambda (v) (set (car v) (nth 1 v))))
475                 newvarlist)
476       (calc-mode-var-list-restore-default-values))))
477
478 (defcalcmodevar calc-always-load-extensions nil
479   "If non-nil, load the calc-ext module automatically when calc is loaded.")
480
481 (defcalcmodevar  calc-line-numbering t
482   "If non-nil, display line numbers in Calculator stack.")
483
484 (defcalcmodevar calc-line-breaking t
485   "If non-nil, break long values across multiple lines in Calculator stack.")
486
487 (defcalcmodevar calc-display-just nil
488   "If nil, stack display is left-justified.
489 If `right', stack display is right-justified.
490 If `center', stack display is centered.")
491
492 (defcalcmodevar calc-display-origin nil
493   "Horizontal origin of displayed stack entries.
494 In left-justified mode, this is effectively indentation.  (Default 0).
495 In right-justified mode, this is effectively window width.
496 In centered mode, center of stack entry is placed here.")
497
498 (defcalcmodevar calc-number-radix 10
499   "Radix for entry and display of numbers in calc-mode, 2-36.")
500
501 (defcalcmodevar calc-leading-zeros nil
502   "If non-nil, leading zeros are provided to pad integers to calc-word-size.")
503
504 (defcalcmodevar calc-group-digits nil
505   "If non-nil, group digits in large displayed integers by inserting spaces.
506 If an integer, group that many digits at a time.
507 If t, use 4 for binary and hex, 3 otherwise.")
508
509 (defcalcmodevar calc-group-char ","
510   "The character (in the form of a string) to be used for grouping digits.
511 This is used only when calc-group-digits mode is on.")
512
513 (defcalcmodevar calc-point-char "."
514   "The character (in the form of a string) to be used as a decimal point.")
515  
516 (defcalcmodevar calc-frac-format '(":" nil)
517   "Format of displayed fractions; a string of one or two of \":\" or \"/\".")
518
519 (defcalcmodevar calc-prefer-frac nil
520   "If non-nil, prefer fractional over floating-point results.")
521
522 (defcalcmodevar calc-hms-format "%s@ %s' %s\""
523   "Format of displayed hours-minutes-seconds angles, a format string.
524 String must contain three %s marks for hours, minutes, seconds respectively.")
525
526 (defcalcmodevar calc-date-format '((H ":" mm C SS pp " ")
527                                   Www " " Mmm " " D ", " YYYY)
528   "Format of displayed date forms.")
529
530 (defcalcmodevar calc-float-format '(float 0)
531   "Format to use for display of floating-point numbers in calc-mode.
532 Must be a list of one of the following forms:
533  (float 0)      Floating point format, display full precision.
534  (float N)      N > 0: Floating point format, at most N significant figures.
535  (float -N)     -N < 0: Floating point format, calc-internal-prec - N figs.
536  (fix N)        N >= 0: Fixed point format, N places after decimal point.
537  (sci 0)        Scientific notation, full precision.
538  (sci N)        N > 0: Scientific notation, N significant figures.
539  (sci -N)       -N < 0: Scientific notation, calc-internal-prec - N figs.
540  (eng 0)        Engineering notation, full precision.
541  (eng N)        N > 0: Engineering notation, N significant figures.
542  (eng -N)       -N < 0: Engineering notation, calc-internal-prec - N figs.")
543
544 (defcalcmodevar calc-full-float-format '(float 0)
545   "Format to use when full precision must be displayed.")
546
547 (defcalcmodevar calc-complex-format nil
548   "Format to use for display of complex numbers in calc-mode.  Must be one of:
549   nil            Use (x, y) form.
550   i              Use x + yi form.
551   j              Use x + yj form.")
552
553 (defcalcmodevar calc-complex-mode 'cplx
554   "Preferred form, either `cplx' or `polar', for complex numbers.")
555
556 (defcalcmodevar calc-infinite-mode nil
557   "If nil, 1 / 0 is left unsimplified.
558 If 0, 1 / 0 is changed to inf (zeros are considered positive).
559 Otherwise, 1 / 0 is changed to uinf (undirected infinity).")
560
561 (defcalcmodevar calc-display-strings nil
562   "If non-nil, display vectors of byte-sized integers as strings.")
563
564 (defcalcmodevar calc-matrix-just 'center
565   "If nil, vector elements are left-justified.
566 If `right', vector elements are right-justified.
567 If `center', vector elements are centered.")
568
569 (defcalcmodevar calc-break-vectors nil
570   "If non-nil, display vectors one element per line.")
571
572 (defcalcmodevar calc-full-vectors t
573   "If non-nil, display long vectors in full.  If nil, use abbreviated form.")
574
575 (defcalcmodevar calc-full-trail-vectors t
576   "If non-nil, display long vectors in full in the trail.")
577
578 (defcalcmodevar calc-vector-commas ","
579   "If non-nil, separate elements of displayed vectors with this string.")
580
581 (defcalcmodevar calc-vector-brackets "[]"
582   "If non-nil, surround displayed vectors with these characters.")
583
584 (defcalcmodevar calc-matrix-brackets '(R O)
585   "A list of code-letter symbols that control \"big\" matrix display.
586 If `R' is present, display inner brackets for matrices.
587 If `O' is present, display outer brackets for matrices (above/below).
588 If `C' is present, display outer brackets for matrices (centered).")
589
590 (defcalcmodevar calc-language nil
591   "Language or format for entry and display of stack values.  Must be one of:
592   nil           Use standard Calc notation.
593   flat          Use standard Calc notation, one-line format.
594   big           Display formulas in 2-d notation (enter w/std notation).
595   unform        Use unformatted display: add(a, mul(b,c)).
596   c             Use C language notation.
597   pascal        Use Pascal language notation.
598   fortran       Use Fortran language notation.
599   tex           Use TeX notation.
600   latex         Use LaTeX notation.
601   eqn           Use eqn notation.
602   math          Use Mathematica(tm) notation.
603   maple         Use Maple notation.")
604
605 (defcalcmodevar calc-language-option nil
606   "Numeric prefix argument for the command that set `calc-language'.")
607
608 (defcalcmodevar calc-left-label ""
609   "Label to display at left of formula.")
610
611 (defcalcmodevar calc-right-label ""
612   "Label to display at right of formula.")
613
614 (defcalcmodevar calc-word-size 32
615   "Minimum number of bits per word, if any, for binary operations in calc-mode.")
616
617 (defcalcmodevar calc-previous-modulo nil
618   "Most recently used value of M in a modulo form.")
619
620 (defcalcmodevar calc-simplify-mode nil
621   "Type of simplification applied to results.
622 If `none', results are not simplified when pushed on the stack.
623 If `num', functions are simplified only when args are constant.
624 If nil, only fast simplifications are applied.
625 If `binary', `math-clip' is applied if appropriate.
626 If `alg', `math-simplify' is applied.
627 If `ext', `math-simplify-extended' is applied.
628 If `units', `math-simplify-units' is applied.")
629
630 (defcalcmodevar calc-auto-recompute t
631   "If non-nil, recompute evalto's automatically when necessary.")
632
633 (defcalcmodevar calc-display-raw nil
634   "If non-nil, display shows unformatted Lisp exprs. (For debugging)")
635
636 (defcalcmodevar calc-internal-prec 12
637   "Number of digits of internal precision for calc-mode calculations.")
638
639 (defcalcmodevar calc-angle-mode 'deg
640   "If deg, angles are in degrees; if rad, angles are in radians.
641 If hms, angles are in degrees-minutes-seconds.")
642
643 (defcalcmodevar calc-algebraic-mode nil
644   "If non-nil, numeric entry accepts whole algebraic expressions.
645 If nil, algebraic expressions must be preceded by \"'\".")
646
647 (defcalcmodevar calc-incomplete-algebraic-mode nil
648   "Like calc-algebraic-mode except only affects ( and [ keys.")
649
650 (defcalcmodevar calc-symbolic-mode nil
651   "If non-nil, inexact numeric computations like sqrt(2) are postponed.
652 If nil, computations on numbers always yield numbers where possible.")
653
654 (defcalcmodevar calc-matrix-mode nil
655   "If `matrix', variables are assumed to be matrix-valued.
656 If a number, variables are assumed to be NxN matrices.
657 If `sqmatrix', variables are assumed to be square matrices of an unspecified size.
658 If `scalar', variables are assumed to be scalar-valued.
659 If nil, symbolic math routines make no assumptions about variables.")
660
661 (defcalcmodevar calc-shift-prefix nil
662   "If non-nil, shifted letter keys are prefix keys rather than normal meanings.")
663
664 (defcalcmodevar calc-window-height 7
665   "Initial height of Calculator window.")
666
667 (defcalcmodevar calc-display-trail t
668   "If non-nil, M-x calc creates a window to display Calculator trail.")
669
670 (defcalcmodevar calc-show-selections t
671   "If non-nil, selected sub-formulas are shown by obscuring rest of formula.
672 If nil, selected sub-formulas are highlighted by obscuring the sub-formulas.")
673
674 (defcalcmodevar calc-use-selections t
675   "If non-nil, commands operate only on selected portions of formulas.
676 If nil, selections displayed but ignored.")
677
678 (defcalcmodevar calc-assoc-selections t
679   "If non-nil, selection hides deep structure of associative formulas.")
680
681 (defcalcmodevar calc-display-working-message 'lots
682   "If non-nil, display \"Working...\" for potentially slow Calculator commands.")
683
684 (defcalcmodevar calc-auto-why 'maybe
685   "If non-nil, automatically execute a \"why\" command to explain odd results.")
686
687 (defcalcmodevar calc-timing nil
688   "If non-nil, display timing information on each slow command.")
689
690 (defcalcmodevar calc-mode-save-mode 'local)
691
692 (defcalcmodevar calc-standard-date-formats
693   '("N"
694     "<H:mm:SSpp >Www Mmm D, YYYY"
695     "D Mmm YYYY<, h:mm:SS>"
696     "Www Mmm BD< hh:mm:ss> YYYY"
697     "M/D/Y< H:mm:SSpp>"
698     "D.M.Y< h:mm:SS>"
699     "M-D-Y< H:mm:SSpp>"
700     "D-M-Y< h:mm:SS>"
701     "j<, h:mm:SS>"
702     "YYddd< hh:mm:ss>"))
703
704 (defcalcmodevar calc-autorange-units nil)
705  
706 (defcalcmodevar calc-was-keypad-mode nil)
707  
708 (defcalcmodevar calc-full-mode nil)
709
710 (defcalcmodevar calc-user-parse-tables nil)
711
712 (defcalcmodevar calc-gnuplot-default-device "default")
713
714 (defcalcmodevar calc-gnuplot-default-output "STDOUT")
715
716 (defcalcmodevar calc-gnuplot-print-device "postscript")
717  
718 (defcalcmodevar calc-gnuplot-print-output "auto")
719
720 (defcalcmodevar calc-gnuplot-geometry nil)
721
722 (defcalcmodevar calc-graph-default-resolution 15)
723
724 (defcalcmodevar calc-graph-default-resolution-3d 5)
725  
726 (defcalcmodevar calc-invocation-macro nil)
727
728 (defcalcmodevar calc-show-banner t
729   "*If non-nil, show a friendly greeting above the stack.")
730
731 (defconst calc-local-var-list '(calc-stack
732                                 calc-stack-top
733                                 calc-undo-list
734                                 calc-redo-list
735                                 calc-always-load-extensions
736                                 calc-mode-save-mode
737                                 calc-display-raw
738                                 calc-line-numbering
739                                 calc-line-breaking
740                                 calc-display-just
741                                 calc-display-origin
742                                 calc-left-label
743                                 calc-right-label
744                                 calc-auto-why
745                                 calc-algebraic-mode
746                                 calc-incomplete-algebraic-mode
747                                 calc-symbolic-mode
748                                 calc-matrix-mode
749                                 calc-inverse-flag
750                                 calc-hyperbolic-flag
751                                 calc-keep-args-flag
752                                 calc-angle-mode
753                                 calc-number-radix
754                                 calc-leading-zeros
755                                 calc-group-digits
756                                 calc-group-char
757                                 calc-point-char
758                                 calc-frac-format
759                                 calc-prefer-frac
760                                 calc-hms-format
761                                 calc-date-format
762                                 calc-standard-date-formats
763                                 calc-float-format
764                                 calc-full-float-format
765                                 calc-complex-format
766                                 calc-matrix-just
767                                 calc-full-vectors
768                                 calc-full-trail-vectors
769                                 calc-break-vectors
770                                 calc-vector-commas
771                                 calc-vector-brackets
772                                 calc-matrix-brackets
773                                 calc-complex-mode
774                                 calc-infinite-mode
775                                 calc-display-strings
776                                 calc-simplify-mode
777                                 calc-auto-recompute
778                                 calc-autorange-units
779                                 calc-show-plain
780                                 calc-show-selections
781                                 calc-use-selections
782                                 calc-assoc-selections
783                                 calc-word-size
784                                 calc-internal-prec))
785
786 (defvar calc-mode-hook nil
787   "Hook run when entering calc-mode.")
788
789 (defvar calc-trail-mode-hook nil
790   "Hook run when entering calc-trail-mode.")
791
792 (defvar calc-start-hook nil
793   "Hook run when calc is started.")
794
795 (defvar calc-end-hook nil
796   "Hook run when calc is quit.")
797
798 (defvar calc-load-hook nil
799   "Hook run when calc.el is loaded.")
800
801 (defvar calc-window-hook nil
802   "Hook called to create the Calc window.")
803
804 (defvar calc-trail-window-hook nil
805   "Hook called to create the Calc trail window.")
806
807 (defvar calc-embedded-new-buffer-hook nil
808   "Hook run when starting embedded mode in a new buffer.")
809
810 (defvar calc-embedded-new-formula-hook nil