home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / gmcalc / part14 < prev    next >
Encoding:
Text File  |  1990-06-05  |  57.7 KB  |  1,242 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@csvax.caltech.edu (David Gillespie)
  3. Subject: v13i040: Emacs Calculator 1.01, part 14/19
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 40
  7. Submitted-by: daveg@csvax.caltech.edu (David Gillespie)
  8. Archive-name: gmcalc/part14
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is part 14 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file calc.texinfo continued
  15. #
  16. CurArch=14
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file calc.texinfo"
  27. sed 's/^X//' << 'SHAR_EOF' >> calc.texinfo
  28. Xthe stack.  These line numbers are ordinarily displayed on the lefthand side
  29. Xof the window.  The @kbd{d l} (@code{calc-line-numbering}) command controls
  30. Xwhether these numbers appear.  (Line numbers may be turned off since they
  31. Xslow the Calculator down a bit and also clutter the display.)
  32. X
  33. XThe @key{RET} (or equivalent @key{SPC}) key is only required to separate
  34. Xtwo consecutive numbers.
  35. X(After all, if you typed @kbd{1 2} by themselves the Calculator
  36. Xwould enter the number 12.)  If you press @kbd{RET} or @kbd{SPC} @emph{not}
  37. Xright after typing a number, the key duplicates the number on the top of
  38. Xthe stack.  @kbd{@key{RET} *} is thus a handy way to square a number.@refill
  39. X
  40. XThe @key{DEL} key pops and throws away the top number on the stack.
  41. XThe @key{TAB} key swaps the top two objects on the stack.
  42. X@xref{Stack and Trail}, for descriptions of these and other stack-related
  43. Xcommands.@refill
  44. X
  45. X@node Numeric Entry, Algebraic Entry, Stack Basics, Introduction
  46. X@section Numeric Entry
  47. X
  48. X@kindex 0-9
  49. X@kindex #
  50. X@kindex .
  51. X@kindex @@
  52. X@kindex e
  53. X@cindex Numeric entry
  54. X@cindex Entering numbers
  55. XPressing a digit or other numeric key begins numeric entry using the
  56. Xminibuffer.  The number is pushed on the stack when you press the @key{RET}
  57. Xor @key{SPC} keys.  If you press any other non-numeric key, the number is
  58. Xpushed onto the stack and the appropriate operation is performed.  If
  59. Xyou press a numeric key which is not valid (say, a second decimal point),
  60. Xthe key is ignored.
  61. X
  62. X@cindex Minus signs
  63. X@cindex Negative numbers, entering
  64. X@kindex _
  65. XThere are three different concepts corresponding to the word ``minus,''
  66. Xtypified by @samp{a-b} (subtraction), @samp{-x}
  67. X(change-sign), and @samp{-5} (negative number).  Calc uses three
  68. Xdifferent keys for these operations, respectively:
  69. X@kbd{-}, @kbd{n}, and @kbd{_} (the underscore).  The @kbd{-} key subtracts
  70. Xthe two numbers on the top of the stack.  The @kbd{n} key changes the sign
  71. Xof the number on the top of the stack or the number currently being entered.
  72. XThe @kbd{_} key begins entry of a negative number or changes the sign of
  73. Xthe number currently being entered.  The following sequences all enter the
  74. Xnumber @samp{-5} onto the stack:  @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}},
  75. X@kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.@refill
  76. X
  77. XDuring numeric entry, the only editing key available is @kbd{DEL}.
  78. X
  79. X@node Algebraic Entry, Quick Calculator, Numeric Entry, Introduction
  80. X@section Algebraic Entry
  81. X
  82. X@kindex '
  83. X@pindex calc-algebraic-entry
  84. X@cindex Algebraic notation
  85. X@cindex Formulas, entering
  86. XCalculations can also be entered in algebraic form.  This is accomplished
  87. Xby typing the apostrophe key, @kbd{'}, followed by the expression in
  88. Xstandard format:  @kbd{@key{'} 2+3*4 @key{RET}} computes
  89. X@samp{2+(3*4)} = 14 and pushes that on the stack.  If you wish you can
  90. Xignore the RPN aspect of Calc altogether and simply enter algebraic
  91. Xexpressions in this way.  You may want to use @key{DEL} every so often to
  92. Xclear previous results off the stack.@refill
  93. X
  94. XYou can press the apostrophe key during normal numeric entry to switch
  95. Xthe half-entered number into algebraic entry mode.  One reason to do this
  96. Xwould be to use the full Emacs cursor motion and editing keys, which are
  97. Xavailable during algebraic entry but not during numeric entry.
  98. X
  99. X@kindex m a
  100. X@pindex calc-algebraic-mode
  101. X@cindex Algebraic mode
  102. XIf you prefer algebraic entry, you can use the command @kbd{m a}
  103. X(@code{calc-algebraic-mode}) to set Algebraic mode.  In this mode,
  104. Xdigits and other keys that would normally start numeric entry instead
  105. Xstart full algebraic entry; as long as your formula begins with a digit
  106. Xyou can omit the apostrophe.  Open parentheses and square brackets also
  107. Xbegin algebraic entry.  You can still do RPN calculations in this mode,
  108. Xbut you will have to press @key{RET} to terminate every number:
  109. X@kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
  110. Xthing as @kbd{2*3+4 @key{RET}}.@refill
  111. X
  112. XPressing @kbd{'} (the apostrophe) a second time re-enters the previous
  113. Xalgebraic formula.  You can then use the normal Emacs editing keys to
  114. Xmodify this formula to your liking before pressing @key{RET}.
  115. X
  116. X@kindex $
  117. X@cindex Formulas, referring to stack
  118. XWithin a formula entered from the keyboard, the symbol @kbd{$}
  119. Xrepresents the number on the top of the stack.  If an entered formula
  120. Xcontains any @kbd{$} characters, the Calculator replaces the top of
  121. Xstack with that formula rather than simply pushing the formula onto the
  122. Xstack.  Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2
  123. X@key{RET}} replaces it with 6.  Note that the @kbd{$} key always
  124. Xinitiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
  125. Xfirst character in the new formula.@refill
  126. X
  127. XHigher stack elements can be accessed from an entered formula with the
  128. Xsymbols @kbd{$$}, @kbd{$$$}, and so on.  The number of stack elements
  129. Xremoved (to be replaced by the entered values) equals the number of dollar
  130. Xsigns in the longest such symbol in the formula.  For example, @samp{$$+$$$}
  131. Xadds the second and third stack elements, replacing the top three elements
  132. Xwith the answer.  (All information about the top stack element is thus lost
  133. Xsince no single @samp{$} appears in this formula.)@refill
  134. X
  135. XIf a sequence of formulas are entered separated by commas, each formula
  136. Xis pushed onto the stack in turn.  For example, @samp{1,2,3} pushes
  137. Xthose three numbers onto the stack (leaving the 3 at the top), and
  138. X@samp{$+1,$-1} replaces a 5 on the stack with 4 followed by 6.  Also,
  139. X@samp{$,$$} exchanges the top two elements of the stack, just like the
  140. X@key{TAB} key.
  141. X
  142. X@node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction
  143. X@section ``Quick Calculator'' Mode
  144. X
  145. X@pindex quick-calc
  146. X@cindex Quick Calculator
  147. XThere is another way to invoke the Calculator if all you need to do
  148. Xis make one or two quick calculations.  Type @kbd{M-x quick-calc},
  149. Xthen type any formula as an algebraic entry.  The Calculator will
  150. Xcompute the result and display it in the echo area, without ever
  151. Xactually putting up a Calculator window.
  152. X
  153. XYou can use the @kbd{$} character in a Quick Calculator formula to
  154. Xrefer to the previous Quick Calculator result.  Older results are
  155. Xnot retained; the Quick Calculator has no effect on the full
  156. XCalculator's stack or trail.  If you compute a result and then
  157. Xforget what it was, just run @code{quick-calc} again and enter
  158. X@samp{$} as the formula.
  159. X
  160. XIf this is the first time you have used the Calculator in this Emacs
  161. Xsession, the @code{quick-calc} command will create the @code{*Calculator*}
  162. Xbuffer and perform all the usual initializations; it simply will
  163. Xrefrain from putting that buffer up in a new window.  The Quick
  164. XCalculator refers to the @code{*Calculator*} buffer for all mode
  165. Xsettings.  Thus, for example, to set the precision that the Quick
  166. XCalculator uses, simply run the full Calculator momentarily and use
  167. Xthe regular @kbd{p} command.
  168. X
  169. XPlease note that the Quick Calculator is not any faster at loading
  170. Xor computing the answer than the full Calculator; the name ``quick''
  171. Xmerely refers to the fact that it's much less hassle to use for
  172. Xsmall calculations.
  173. X
  174. XYou may wish to use @code{global-set-key} to bind @code{quick-calc}
  175. Xto some convenient keystroke.
  176. X
  177. X@node Prefix Arguments, Undo, Quick Calculator, Introduction
  178. X@section Numeric Prefix Arguments
  179. X
  180. XMany Calculator commands use numeric prefix arguments.  Some, such as
  181. X@kbd{b w} (@code{calc-word-size}), set a parameter to the value of the
  182. Xprefix argument, or display the current value if there is no prefix
  183. Xargument.  Others require an argument and prompt for a number if you
  184. Xdon't give one as a prefix.@refill
  185. X
  186. XAs a rule, stack-manipulation commands accept a numeric prefix argument
  187. Xwhich is interpreted as an index into the stack.  A positive argument
  188. Xoperates on the top @var{n} stack entries; a negative argument operates
  189. Xon the @var{n}th stack entry in isolation; and a zero argument operates
  190. Xon the entire stack.
  191. X
  192. XMost commands that perform computations (such as the arithmetic and
  193. Xscientific functions) accept a numeric prefix argument that allows the
  194. Xoperation to be applied across many stack elements.  For unary operations
  195. X(that is, functions of one argument like absolute value or complex
  196. Xconjugate), a prefix argument applies that function to the top @var{n}
  197. Xstack entries simultaneously.  For binary operations (functions of two
  198. Xarguments like addition, GCD, and vector concatenation), a positive
  199. Xprefix argument ``reduces'' the function across the top @var{n}
  200. Xstack elements (for example, @kbd{C-u 5 +} sums the top 5 stack entries;
  201. X@pxref{Reducing and Mapping}), and a negative argument maps the next-to-top
  202. X@var{n} stack elements with the top stack element as a second argument
  203. X(for example, @kbd{7 c-u -5 +} adds 7 to the top 5 stack elements).
  204. XThis feature is not available for operations which use the numeric prefix
  205. Xargument for some other purpose.
  206. X
  207. XNumeric prefixes are specified the same way as always in Emacs:  Press
  208. Xa sequence of @key{META}-digits, or press @key{ESC} followed by digits,
  209. Xor press @kbd{C-u} followed by digits.@refill
  210. X
  211. X@kindex ~
  212. X@pindex calc-num-prefix
  213. XYou can type @kbd{~} (@code{calc-num-prefix}) to pop an integer from the
  214. Xtop of the stack and enter it as the numeric prefix for the next command.
  215. XFor example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate
  216. X(silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2
  217. Xto the fourth power and set the precision to that value.@refill
  218. X
  219. XConversely, if you have typed a numeric prefix argument the @kbd{~} key
  220. Xpushes it onto the stack in the form of an integer.
  221. X
  222. X@node Undo, Error Messages, Prefix Arguments, Introduction
  223. X@section Undoing Mistakes
  224. X
  225. X@kindex U
  226. X@kindex C-_
  227. X@pindex calc-undo
  228. X@cindex Mistakes, undoing
  229. X@cindex Undoing mistakes
  230. X@cindex Errors, undoing
  231. XThe shift-@kbd{U} key (@code{calc-undo}) undoes the most recent operation.
  232. XIf that operation added or dropped objects from the stack, those objects
  233. Xare removed or restored.  If it was a @code{store} operation, you are
  234. Xqueried whether or not to restore the variable to its original value.
  235. XThe @kbd{U} key may be pressed any number of times to undo successively
  236. Xfarther back in time; with a numeric prefix argument it undoes a
  237. Xspecified number of operations.  The undo history is cleared only by the
  238. X@kbd{q} (@code{calc-quit}) command.  (Recall that @kbd{M-#} is usually
  239. Xmade synonymous with @code{calc-quit} while inside the Calculator; this
  240. Xalso clears the undo history.)
  241. X
  242. XCurrently the mode-setting commands (like @code{calc-precision}) are not
  243. Xundoable.  You can undo past a point where you changed a mode, but you
  244. Xwill need to reset the mode yourself.
  245. X
  246. X@kindex D
  247. X@pindex calc-redo
  248. X@cindex Redoing after an Undo
  249. XThe shift-@kbd{D} key (@code{calc-redo}) redoes an operation that was
  250. Xmistakenly undone.  Pressing @kbd{U} with a negative prefix argument is
  251. Xequivalent to executing @code{calc-redo}.  You can redo any number of
  252. Xtimes, up to the number of recent consecutive undo commands.  Redo
  253. Xinformation is cleared whenever you give any command that adds new undo
  254. Xinformation, i.e., if you undo, then enter a number on the stack or make
  255. Xany other change, then it will be too late to redo.
  256. X
  257. X@kindex X
  258. X@pindex calc-last-x
  259. X@cindex Last-X feature
  260. X@cindex Arguments, restoring
  261. XThe shift-@kbd{X} key (@code{calc-last-x}) is like undo in that it
  262. Xrestores the arguments of the most recent command onto the stack;
  263. Xhowever, it does not remove the result of that command.  Given a numeric
  264. Xprefix argument, this command applies to the @samp{n}th most recent
  265. Xcommand which removed items from the stack; it pushes those items back
  266. Xonto the stack.
  267. X
  268. XIt is also possible to recall previous results or inputs using the trail.
  269. X@xref{Trail Commands}.
  270. X
  271. XThe standard Emacs @kbd{C-_} undo key is recognized as a synonym for @kbd{U}.
  272. X
  273. X@node Error Messages, Multiple Calculators, Undo, Introduction
  274. X@section Error Messages
  275. X
  276. X@kindex w
  277. X@pindex calc-why
  278. X@cindex Errors, messages
  279. X@cindex Why did an error occur?
  280. XMany situations that would produce an error message in other calculators
  281. Xsimply create unsimplified formulas in the Emacs Calculator.  For example,
  282. X@kbd{1 @key{RET} 0 /} pushes the formula @samp{1 / 0}; @kbd{0 L} pushes
  283. Xthe formula @kbd{ln(0)}.  When this happens, you can use the @kbd{w}
  284. X(@code{calc-why}) command to see a brief explanation of why the formula
  285. Xcould not be simplified.  Press @kbd{w} repeatedly to see all the error
  286. Xmessages which arose from the last calculation.
  287. X
  288. X@kindex d w
  289. X@pindex calc-auto-why
  290. XThe @kbd{d w} (@code{calc-auto-why}) command turns on and off a mode in
  291. Xwhich these error messages are automatically displayed.  Sometimes these
  292. Xmessages are a nuisance; for example, @samp{sqrt(a)} will produce the
  293. Xmessage @samp{Number expected: a}.  For this reason the @kbd{d w} mode is
  294. Xoff by default.
  295. X
  296. X@node Multiple Calculators, Troubleshooting Commands, Error Messages, Introduction
  297. X@section Multiple Calculators
  298. X
  299. X@pindex another-calc
  300. XIt is possible to have any number of Calc Mode buffers at once.
  301. XUsually this is done by executing @kbd{M-x another-calc}, which
  302. Xis similar to @kbd{M-x calc} except that if a @samp{*Calculator*}
  303. Xbuffer already exists, a new, independent one with a name of the
  304. Xform @samp{*Calculator*<@var{n}>} is created.  You can also use the
  305. Xcommand @code{calc-mode} to put any buffer into Calculator mode, but
  306. Xthis would ordinarily never be done.
  307. X
  308. XThe @kbd{q} (@code{calc-quit}) command does not destroy a Calculator buffer;
  309. Xit only closes its window.  Use @kbd{M-x kill-buffer} to destroy a
  310. XCalculator buffer.
  311. X
  312. XEach Calculator buffer keeps its own stack, undo list, and mode settings
  313. Xsuch as precision, angular mode, and display formats.  In Emacs terms,
  314. Xvariables such as @code{calc-stack} are buffer-local variables.  The
  315. Xglobal default values of these variables are used only when a new
  316. XCalculator buffer is created.  The @code{calc-quit} command saves
  317. Xthe stack and mode settings of the buffer being quit as the new defaults.
  318. X
  319. XThere is only one trail buffer, @samp{*Calc Trail*}, used by all
  320. XCalculator buffers.
  321. X
  322. X@node Troubleshooting Commands, , Multiple Calculators, Introduction
  323. X@section Troubleshooting Commands
  324. X
  325. XThis section describes commands you can use in case a computation
  326. Xincorrectly fails or gives the wrong answer.
  327. X
  328. X@menu
  329. X* Recursion Depth::
  330. X* Caches::
  331. X@end menu
  332. X
  333. X@node Recursion Depth, Caches, Troubleshooting Commands, Troubleshooting Commands
  334. X@subsection Recursion Depth
  335. X
  336. X@kindex M
  337. X@pindex calc-more-recursion-depth
  338. X@pindex calc-less-recursion-depth
  339. X@cindex Recursion depth
  340. X@cindex @code{max-lisp-eval-depth}
  341. X@cindex @code{max-specpdl-size}
  342. XCalc uses recursion in many of its calculations.  Emacs Lisp keeps a
  343. Xvariable @code{max-lisp-eval-depth} which limits the amount of recursion
  344. Xpossible in an attempt to recover from program bugs.  If a calculation
  345. Xever halts incorrectly because of a
  346. X``Lisp nesting exceeds @code{max-lisp-eval-depth}'' error,
  347. Xuse the @kbd{M} command (@code{calc-more-recursion-depth}) to increase
  348. Xthis limit.@refill
  349. X
  350. XThe limit is always increased (multiplied) by a factor of two.  There is
  351. Xalso a @code{calc-less-recursion-depth} (or @kbd{x less}) command which
  352. Xdecreases this limit by a factor of two, down to a minimum value of 200.
  353. XThe default value is 1000.
  354. X
  355. XThese commands also double or halve @code{max-specpdl-size}, another
  356. Xinternal Lisp recursion limit.  The minimum value for this limit is 600.
  357. X
  358. X@node Caches, , Recursion Depth, Troubleshooting Commands
  359. X@subsection Caches
  360. X
  361. X@cindex Caches
  362. X@cindex Flushing caches
  363. XCalc saves certain values after they have been computed once.  For
  364. Xexample, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the
  365. Xconstant @samp{pi} to about 20 decimal places; if the current precision
  366. Xis greater than this, it will recompute @samp{pi} using a series
  367. Xapproximation.  This value will not need to be recomputed ever again
  368. Xunless you raise the precision still further.  Many operations such as
  369. Xlogarithms and sines make use of similarly cached values such as
  370. X@samp{pi/4} and @samp{ln(2)}.  The visible effect of caching is that
  371. Xhigh-precision computations may be especially slow the first time.
  372. XOther things cached include powers of two (for the binary arithmetic
  373. Xfunctions), matrix inverses and determinants, and symbolic integrals.
  374. X
  375. X@pindex calc-flush-caches
  376. XIf you suspect a Calculator cache has become corrupt, you can use the
  377. X@code{calc-flush-caches} command to reset all caches to the empty state.
  378. X(This should only be necessary in event of bugs in the Calculator.)
  379. X
  380. X@node Data Types, Stack and Trail, Introduction, Top
  381. X@chapter Data Types
  382. X
  383. XThis chapter discusses the various types of objects that can be placed
  384. Xon the Calculator stack, how they are displayed, and how they are
  385. Xentered.  (@xref{Data Type Formats}, for information on how these data
  386. Xtypes are represented as Lisp objects.)@refill
  387. X
  388. XIntegers, fractions, and floats are various ways of describing real
  389. Xnumbers.  HMS forms also for many purposes act as real numbers.  These
  390. Xtypes can be combined to form complex numbers, modulo forms, error forms,
  391. Xor interval forms.  (But these last four types cannot be combined with
  392. Xeach other: error forms may not contain modulo forms, for example.)
  393. XFinally, all these types of numbers may be combined into vectors,
  394. Xmatrices, or algebraic formulas.
  395. X
  396. X@menu
  397. X* Integers::                The most basic data type.
  398. X* Fractions::               This and above are called @dfn{rationals}.
  399. X* Floats::                  This and above are called @dfn{reals}.
  400. X* Complex Numbers::         This and above are called @dfn{numbers}.
  401. X* Vectors and Matrices::
  402. X* Strings::
  403. X* HMS Forms::
  404. X* Modulo Forms::
  405. X* Error Forms::
  406. X* Interval Forms::
  407. X* Incomplete Objects::
  408. X* Variables::
  409. X* Formulas::
  410. X@end menu
  411. X
  412. X@node Integers, Fractions, Data Types, Data Types
  413. X@section Integers
  414. X
  415. X@cindex Integers
  416. XThe Calculator stores integers to arbitrary precision.  Addition,
  417. Xsubtraction, and multiplication of integers always yields an exact
  418. Xinteger result.  (If the result of a division or exponentiation of
  419. Xintegers is not an integer, it is expressed in fractional or
  420. Xfloating-point form according to the current Fraction Mode.
  421. X@xref{Fraction Mode}.)
  422. X
  423. XA decimal integer is represented as an optional sign followed by a
  424. Xsequence of digits.  Grouping (@pxref{Grouping Digits}) can be used to
  425. Xinsert a comma at every third digit for display purposes, but such
  426. Xcommas are not allowed during the entry of numbers.@refill
  427. X
  428. XA non-decimal integer is represented as an optional sign, a radix
  429. Xbetween 2 and 36, a @samp{#} symbol, and one or more digits.  For radix 11
  430. Xand above, the letters A through Z (upper- or lower-case) count as
  431. Xdigits and do not terminate numeric entry mode.  @xref{Radix Modes}, for how
  432. Xto set the default radix for display of integers.  Numbers of any radix
  433. Xmay be entered at any time.  If you press @kbd{#} at the beginning of a
  434. Xnumber, the current display radix is used.@refill
  435. X
  436. X@node Fractions, Floats, Integers, Data Types
  437. X@section Fractions
  438. X
  439. X@cindex Fractions
  440. XA @dfn{fraction} is a ratio of two integers.  Fractions are traditionally
  441. Xwritten ``2/3'' but Calc uses the notation @samp{2:3}.  (The @kbd{/} key
  442. Xperforms RPN division; the following two sequences push the number
  443. X@samp{2:3} on the stack:  @kbd{2 : 3 @key{RET}}, @kbd{2 @key{RET} 3 /},
  444. Xassuming Fraction Mode has been enabled.)
  445. XWhen the Calculator produces a fractional result it always reduces it to
  446. Xsimplest form, which may in fact be an integer.@refill
  447. X
  448. XFractions may also be entered in a three-part form, where @samp{2:3:4}
  449. Xrepresents two-and-three-quarters.  @xref{Fraction Formats}, for fraction
  450. Xdisplay formats.@refill
  451. X
  452. XNon-decimal fractions are entered and displayed in the form
  453. X@samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part
  454. Xform).  The numerator and denominator always use the same radix.@refill
  455. X
  456. X@node Floats, Complex Numbers, Fractions, Data Types
  457. X@section Floats
  458. X
  459. X@cindex Floating-point numbers
  460. XA floating-point number or @dfn{float} is a number stored in scientific
  461. Xnotation.  The number of significant digits in the fractional part is
  462. Xgoverned by the current floating precision (@pxref{Precision}).  The
  463. Xexponent is stored as a Lisp integer with no overflow or underflow
  464. Xchecking; thus the safe limit is roughly 10^1000000 for large numbers,
  465. Xand 10^-1000000 for small numbers.
  466. X
  467. XIf a rational number and a float are mixed in a calculation, the result
  468. Xwill in general be expressed as a float.  Commands that require an integer
  469. Xvalue (such as @code{calc-gcd}) will also accept integer-valued floats,
  470. Xi.e., a floating-point number with nothing after the decimal point.
  471. X
  472. XFloats are identified by the presence of a decimal point and/or an
  473. Xexponent.  In general a float consists of an optional sign, digits
  474. Xincluding an optional decimal point, and an optional exponent consisting
  475. Xof an @samp{e}, an optional sign, and one to six exponent digits.
  476. XFor example, @samp{23.5e-2} is 23.5 times ten to the minus-second power,
  477. Xor 0.235.
  478. X
  479. XFloating-point numbers are normally displayed in decimal notation with
  480. Xall significant figures shown.  Exceedingly large or small numbers are
  481. Xdisplayed in scientific notation.  Various other display options are
  482. Xavailable.  @xref{Float Formats}.
  483. X
  484. X@cindex Accuracy of computations
  485. XFloating-point numbers are stored in decimal, not binary.  The result
  486. Xof each operation is rounded to the nearest value representable in the
  487. Xnumber of significant digits specified by the current precision,
  488. Xrounding away from zero in the case of a tie.  Thus (in the default
  489. Xdisplay mode) what you see is exactly what you get.  Some operations such
  490. Xas square roots and transcendental functions are performed with several
  491. Xdigits of extra precision and then rounded down, in an effort to make the
  492. Xfinal result accurate to the full requested precision.  However,
  493. Xaccuracy is not rigorously guaranteed.  If you suspect the validity of a
  494. Xresult, try doing the same calculation in a higher precision.  The
  495. XCalculator's arithmetic is not intended to be IEEE-conformant in any
  496. Xway.@refill
  497. X
  498. X@node Complex Numbers, Vectors and Matrices, Floats, Data Types
  499. X@section Complex Numbers
  500. X
  501. X@cindex Complex numbers
  502. XThere are two supported formats for complex numbers: rectangular and
  503. Xpolar.  The default format is rectangular, displayed in the form
  504. X@samp{(@var{real},@var{imag})} where @var{real} is the real part and
  505. X@var{imag} is the imaginary part, each of which may be any real number.
  506. XRectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i}
  507. Xnotation; @pxref{Complex Formats}.@refill
  508. X
  509. XPolar complex numbers are displayed in the form @samp{(@var{r};@var{theta})}
  510. Xwhere @var{r} is the nonnegative magnitude and @var{theta} is the argument
  511. Xor phase angle.  The range of @var{theta} depends on the current angular
  512. Xmode (@pxref{Angular Modes}); it is generally between -180 and +180 degrees
  513. Xor the equivalent range in radians.@refill
  514. X
  515. XComplex numbers are entered in stages using incomplete objects.
  516. X@xref{Incomplete Objects}.
  517. X
  518. XOperations on rectangular complex numbers yield rectangular complex
  519. Xresults, and similarly for polar complex numbers.  Where the two types
  520. Xare mixed, or where new complex numbers arise (as for the square root of
  521. Xa negative real), the current @dfn{Polar Mode} is used to determine the
  522. Xtype.  @xref{Polar Mode}.
  523. X
  524. XA complex result in which the imaginary part is zero (or the phase angle
  525. Xis 0 or 180 degrees or @samp{pi} radians) is automatically converted to a real
  526. Xnumber.
  527. X
  528. X@node Vectors and Matrices, Strings, Complex Numbers, Data Types
  529. X@section Vectors and Matrices
  530. X
  531. X@cindex Vectors
  532. X@cindex Plain vectors
  533. X@cindex Matrices
  534. XThe @dfn{vector} data type is flexible and general.  A vector is simply a
  535. Xlist of zero or more data objects.  When these objects are numbers, the
  536. Xwhole is a vector in the mathematical sense.  When these objects are
  537. Xthemselves vectors of equal (nonzero) length, the whole is a @dfn{matrix}.
  538. XA vector which is not a matrix is referred to here as a @dfn{plain vector}.
  539. X
  540. XA vector is displayed as a list of comma-separated values enclosed in
  541. Xsquare brackets:  @samp{[1, 2, 3]}.  Thus the following is a 2 row by
  542. X3 column matrix:  @samp{[[1, 2, 3], [4, 5, 6]]}.  Vectors, like complex
  543. Xnumbers, are entered as incomplete objects.  @xref{Incomplete Objects}.
  544. XDuring algebraic entry, vectors are entered all at once in the usual
  545. Xbrackets-and-commas form.  Matrices may be entered algebraically as nested
  546. Xvectors, or using the shortcut notation @samp{[1, 2, 3; 4, 5, 6]},
  547. Xwith rows separated by semicolons.  The commas may usually be omitted
  548. Xwhen entering vectors:  @samp{[1 2 3]}.  Curly braces may be used in
  549. Xplace of brackets: @samp{@{1, 2, 3@}}, but the commas are required in
  550. Xthis case.
  551. X
  552. XTraditional vector and matrix arithmetic is supported;
  553. X@pxref{Basic Arithmetic} and @pxref{Matrix Functions}.
  554. XMany other operations are applied to vectors element-wise.  For example,
  555. Xthe complex conjugate of a vector is a vector of the complex conjugates
  556. Xof its elements.@refill
  557. X
  558. X@node Strings, HMS Forms, Vectors and Matrices, Data Types
  559. X@section Strings
  560. X
  561. X@kindex "
  562. X@cindex Strings
  563. X@cindex Character strings
  564. XCharacter strings are not a special data type in the Calculator.
  565. XRather, a string is represented simply as a vector all of whose
  566. Xelements are integers in the range 0 to 255.  You can enter a string
  567. Xat any time by pressing the @kbd{"} key.  Quotation marks and
  568. Xbackslashes are written @samp{\"} and @samp{\\}, respectively,
  569. Xinside strings.  (In fact, all the standard Emacs Lisp conventions
  570. Xfor strings are allowed.)
  571. X
  572. X@kindex d "
  573. X@pindex calc-display-strings
  574. XStrings are normally displayed in vector-of-integers form.  The
  575. X@kbd{d "} (@code{calc-display-strings}) command toggles a mode in
  576. Xwhich any vectors of the appropriate form are displayed as quoted
  577. Xstrings instead.
  578. X
  579. XThe Calculator does not use strings in any of its built-in features.
  580. XThey are provided mainly as a convenient way to do conversions
  581. Xbetween ASCII characters and integers.
  582. X
  583. X@node HMS Forms, Modulo Forms, Strings, Data Types
  584. X@section HMS Forms
  585. X
  586. X@cindex Hours-minutes-seconds forms
  587. X@cindex Degrees-minutes-seconds forms
  588. X@dfn{HMS} stands for Hours-Minutes-Seconds; when used as an angular
  589. Xargument, the interpretation is Degrees-Minutes-Seconds.  All functions
  590. Xthat operate on angles accept HMS forms.  These are interpreted as
  591. Xdegrees regardless of the current angular mode.  It is also possible to
  592. Xuse HMS as the angular mode so that calculated angles are expressed in
  593. Xdegrees, minutes, and seconds.
  594. X
  595. XThe default format for HMS values is
  596. X@samp{@var{hours}@@ @var{mins}' @var{secs}"}.  During entry, the letters
  597. X@samp{h} (for ``hours'') or
  598. X@samp{o} (approximating the ``degrees'' symbol) are accepted as well as
  599. X@samp{@@}, @samp{m} is accepted in place of @samp{'}, and @samp{s} is
  600. Xaccepted in place of @samp{"}.
  601. XThe @var{hours} value is an integer (or integer-valued float).
  602. XThe @var{mins} value is an integer or integer-valued float between 0 and 59.
  603. XThe @var{secs} value is a real number between 0 (inclusive) and 60
  604. X(exclusive).  A positive HMS form is interpreted as @var{hours} +
  605. X@var{mins}/60 + @var{secs}/3600.  A negative HMS form is interpreted
  606. Xas - @var{hours} - @var{mins}/60 - @var{secs}/3600.
  607. XDisplay format for HMS forms is quite flexible.  @xref{HMS Formats}.@refill
  608. X
  609. XHMS forms can be added and subtracted.  When they are added to numbers,
  610. Xthe numbers are interpreted according to the current angular mode.  HMS
  611. Xforms can also be multiplied and divided by real numbers.  Dividing
  612. Xtwo HMS forms produces a real-valued ratio of the two angles.
  613. X
  614. X@pindex calc-time
  615. X@cindex Time of day
  616. XJust for kicks, @code{calc-time} pushes the current time of day on
  617. Xthe stack as an HMS form.
  618. X
  619. X@node Modulo Forms, Error Forms, HMS Forms, Data Types
  620. X@section Modulo Forms
  621. X
  622. X@cindex Modulo forms
  623. XA @dfn{modulo form} is a real number which is taken modulo (i.e., within
  624. Xan integer multiple of) some value @samp{M}.  Arithmetic modulo @samp{M}
  625. Xoften arises in number theory.  Modulo forms are written
  626. X@samp{@var{a} mod @var{M}},
  627. Xwhere @var{a} and @var{M} are real numbers or HMS forms, and
  628. X@samp{0 <= @var{a} < @var{M}}.
  629. XIn many applications @var{a} and @var{M} will be
  630. Xintegers but this is not required.@refill
  631. X
  632. XModulo forms are not to be confused with the modulo operator @samp{%}.
  633. XThe expression @samp{27 % 10} means to compute 27 modulo 10 to produce
  634. Xthe result 7.  Further computations treat this 7 as just a regular integer.
  635. XThe expression @samp{27 mod 10} produces the result @samp{7 mod 10};
  636. Xfurther computations with this value are again reduced modulo 10 so that
  637. Xthe result always lies in the desired range.
  638. X
  639. XWhen two modulo forms with identical @var{M}'s are added or multiplied,
  640. Xthe Calculator simply adds or multiplies the values, then reduces modulo
  641. X@var{M}.  If one argument is a modulo form and the other a plain number,
  642. Xthe plain number is treated like a compatible modulo form.  It is also
  643. Xpossible to raise modulo forms to powers; the result is the value raised
  644. Xto the power, then reduced modulo @var{M}.  (When all values involved
  645. Xare integers, this calculation is done much more efficiently than
  646. Xactually computing the power and then reducing.)
  647. X
  648. X@cindex Modulo division
  649. XTwo modulo forms @samp{@var{a} mod @var{M}} and @samp{@var{b} mod
  650. X@var{M}} can be divided if @var{a}, @var{b}, and @var{M} are all
  651. Xintegers.  The result is the modulo form which, when multiplied by
  652. X@samp{@var{b} mod @var{M}}, produces @samp{@var{a} mod @var{M}}.  If
  653. Xthere is no solution to this equation (which can happen only when
  654. X@var{M} is non-prime), or if any of the arguments are non-integers, the
  655. Xdivision is left in symbolic form.  Other operations, such as square
  656. Xroots, are not yet supported for modulo forms.  (Note that, although
  657. X@samp{(@var{a} mod @var{M})^.5} will compute a ``modulo square root'' in
  658. Xthe sense of reducing @samp{sqrt(@var{a})} modulo @var{M}, this is not a
  659. Xuseful definition from the number-theoretical point of view.)@refill
  660. X
  661. XTo create a modulo form during numeric entry, press the shift-@kbd{M}
  662. Xkey to enter the word @samp{mod}.  As a special convenience, pressing
  663. Xshift-@kbd{M} a second time automatically enters the value of @var{M}
  664. Xthat was most recently used before.  During algebraic entry, either
  665. Xtype @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
  666. XOnce again, pressing this a second time enters the current modulo.@refill
  667. X
  668. XIt is possible to mix HMS forms and modulo forms.  For example, an
  669. XHMS form modulo 24 could be used to manipulate clock times; an HMS
  670. Xform modulo 360 would be suitable for angles.  Making the modulo @var{M}
  671. Xalso be an HMS form eliminates troubles that would arise if the angular
  672. Xmode were inadvertently set to Radians, in which case @samp{2@@ 0' 0" mod 24}
  673. Xwould be interpreted as two degrees modulo 24 radians!
  674. X
  675. X@node Error Forms, Interval Forms, Modulo Forms, Data Types
  676. X@section Error Forms
  677. X
  678. X@cindex Error forms
  679. X@cindex Standard deviations
  680. XAn @dfn{error form} is a real number with an associated standard
  681. Xdeviation, as in @samp{2.3 +/- 0.12}.  The notation
  682. X@samp{@var{x} +/- @var{sigma}}
  683. Xstands for an uncertain value which follows a normal or
  684. XGaussian distribution of mean @var{x} and standard deviation or
  685. X``error'' @var{sigma}.  Both the mean and the error are real numbers
  686. X(or algebraic expressions which are treated like real numbers); the
  687. Xerror must be positive.  A value with zero error is converted to a
  688. Xregular number by the Calculator.@refill
  689. X
  690. XAll arithmetic and transcendental functions accept error forms as input.
  691. XOperations on the mean-value part work just like operations on regular
  692. Xnumbers.  The error part for any function @samp{f(x)} (such as @samp{sin(x)})
  693. Xis defined by the error of @samp{x} times the derivative of @samp{f}
  694. Xevaluated at the mean value of @samp{x}.  For a two-argument function
  695. X@samp{f(x,y)} (such as addition) the error is the square root of the sum
  696. Xof the squares of the errors due to @samp{x} and @samp{y}.  Note that this
  697. Xdefinition assumes the errors in @samp{x} and @samp{y} are uncorrelated.
  698. XA side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
  699. Xis not the same as @samp{(2 +/- 1)^2}; the former represents the product
  700. Xof two independent values which happen to have the same probability
  701. Xdistributions, and the product of one random value with itself.  The
  702. Xform will produce an answer with less error, since on the average the
  703. Xtwo indepdent errors can be expected to cancel out.@refill
  704. X
  705. XConsult a good text on error analysis for a discussion of the proper use
  706. Xof standard deviations.  Actual errors often are neither Gaussian-distributed
  707. Xnor uncorrelated, and the above formulas are valid only when errors
  708. Xare small.  As an example, the error arising from @samp{sin(x +/- dx)} is
  709. X@samp{dx * abs(cos(x))}.  When @samp{x} is close to zero, @samp{cos(x)} is
  710. Xclose to one so the error in the sine is close to @samp{dx}; this makes
  711. Xsense, since @samp{sin(x)} is approximately @samp{x} near zero, so a given
  712. Xerror in @samp{x} will produce about the same error in the sine.  Likewise,
  713. Xnear 90 degrees @samp{cos(x)} is nearly zero and so the computed error is
  714. Xsmall:  The sine curve is nearly flat in that region, so an error in @samp{x}
  715. Xhas relatively little effect on the value of @samp{sin(x)}.  However, consider
  716. X@samp{sin(90 +/- 1000)}.  The cosine of 90 is zero, so Calc will report
  717. Xzero error!  We get an obviously wrong result because we have violated
  718. Xthe small-error approximation underlying the error analysis.  If the error
  719. Xin @samp{x} had been small, the error in @code{sin(x)} would indeed have
  720. Xbeen negligible.@refill
  721. X
  722. XTo enter an error form during regular numeric entry, use the @samp{p}
  723. X(``plus-or-minus'') key to type the @samp{+/-} symbol.  (If you try actually
  724. Xtyping @samp{+/-} the @kbd{+} key will be interpreted as the Calculator's
  725. X@kbd{+} command!)  Within an algebraic formula, you can press @kbd{M-p} to
  726. Xtype the @samp{+/-} symbol, or type it out by hand.
  727. X
  728. XError forms and complex numbers cannot be mixed.  For example, @samp{sqrt(-9)}
  729. Xproduces the complex result @samp{(0,3)}, but @samp{sqrt(-9 +/- 1)} is left
  730. Xunevaluated by the Calculator.  However, error forms whose arguments are
  731. XHMS forms are allowed.
  732. X
  733. X@node Interval Forms, Incomplete Objects, Error Forms, Data Types
  734. X@section Interval Forms
  735. X
  736. X@cindex Interval forms
  737. XAn @dfn{interval} is a subset of consecutive real numbers.  For example,
  738. Xthe interval @samp{[2 .. 4]} represents all the numbers from 2 to 4,
  739. Xinclusive.  If you multiply it by the interval @samp{[0.5 .. 2]} you
  740. Xobtain @samp{[1 .. 6]}.  This calculation represents the fact that if
  741. Xyou multiply some number in the range @samp{[2 .. 4]} by some other
  742. Xnumber in the range @samp{[0.5 .. 2]}, your result will lie in the range
  743. Xfrom 1 to 6.  Interval arithmetic is used to get a worst-case estimate
  744. Xof the possible range of values a computation will produce, given the
  745. Xset of possible values of the input.
  746. X
  747. XCalc supports several varieties of intervals, including @dfn{closed}
  748. Xintervals of the type shown above, @dfn{open} intervals such as
  749. X@samp{(2 .. 4)}, which represents the range of numbers from 2 to 4
  750. X@emph{exclusive}, and @dfn{semi-open} intervals in which one end
  751. Xuses a round parenthesis and the other a square bracket.  In mathematical
  752. Xterms, @samp{[2 .. 4]} means @samp{2 <= x <= 4}, whereas @samp{(2 .. 4)}
  753. Xrepresents @samp{2 < x < 4}, @samp{[2 .. 4)} represents @samp{2 <= x < 4},
  754. Xand @samp{(2 .. 4]} represents @samp{2 < x <= 4}.@refill
  755. X
  756. XThe lower and upper limits of an interval must be either real numbers
  757. X(or HMS forms), or symbolic expressions which are assumed to be real-valued.
  758. XIn general the lower limit must be less than the upper limit.  A closed
  759. Xinterval containing only one value, @samp{[3 .. 3]}, is converted to a
  760. Xplain number (3) automatically.  An interval containing no values at all
  761. X(such as @samp{[3 .. 2]} or @samp{[2 .. 2)}) can be represented but is not
  762. Xguaranteed to behave well when used in arithmetic.
  763. X
  764. XIntervals are entered in the notation shown here, either as algebraic
  765. Xformulas, or using incomplete forms.  (@xref{Incomplete Objects}.)
  766. XIn algebraic formulas, multiple periods in a row are collected from
  767. Xleft to right, so that @samp{1....1e2} is interpreted as @samp{1 .. .. 1e2}
  768. X(a syntax error) rather than @samp{1. .. .1e2}.  Use spaces or type
  769. X@samp{1.0..0.1e2} to make the notation unambiguous.
  770. X
  771. XWhile it may seem that intervals and error forms are similar, they are
  772. Xbased on entirely different concepts of inexact quantities.  An error
  773. Xform @samp{x +/- sigma} means a variable is random, and its value could
  774. Xbe anything but is ``probably'' within one @code{sigma} of the mean
  775. Xvalue @code{x}.  An interval @samp{[lo .. hi]} means a variable's value
  776. Xis unknown, but guaranteed to lie in the specified range.  Error forms
  777. Xare statistical or ``average case'' approximations; interval arithmetic
  778. Xtends to produce ``worst case'' bounds on an answer.@refill
  779. X
  780. X@node Incomplete Objects, Variables, Interval Forms, Data Types
  781. X@section Incomplete Objects
  782. X
  783. X@kindex [
  784. X@kindex ]
  785. X@kindex (
  786. X@kindex )
  787. X@kindex ,
  788. X@kindex ;
  789. X@cindex Incomplete vectors
  790. X@cindex Incomplete complex numbers
  791. X@cindex Incomplete interval forms
  792. XWhen @kbd{(} or @kbd{[} is typed to begin entering a complex number or
  793. Xvector, respectively, the effect is to push an @dfn{incomplete} complex
  794. Xnumber or vector onto the stack.  The @kbd{,} key adds the value(s) at
  795. Xthe top of the stack onto the current incomplete object.  The @kbd{)}
  796. Xand @kbd{]} keys ``close'' the incomplete object after adding any values
  797. Xon the top of the stack in front of the incomplete object.
  798. X
  799. XAs a result, the sequence of keystrokes @kbd{[ 2 , 3 @key{RET} 2 * , 9 ]}
  800. Xpushes the vector @samp{[2, 6, 9]} onto the stack.  Likewise, @kbd{( 1 , 2 Q )}
  801. Xpushes the complex number @samp{(1, 1.414)} (approximately).
  802. X
  803. XIf several values lie on the stack in front of the incomplete object,
  804. Xall are collected and appended to the object.  Thus the @kbd{,} key
  805. Xis redundant:  @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}.  Some people
  806. Xprefer the equivalent @key{SPC} key to @key{RET}.@refill
  807. X
  808. XAs a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
  809. X@kbd{,} adds a zero or duplicates the preceding value in the list being
  810. Xformed.  Typing @key{DEL} during incomplete entry removes the last item
  811. Xfrom the list.
  812. X
  813. XThe @kbd{;} key is used in the same way as @kbd{,} to create polar complex
  814. Xnumbers:  @kbd{( 1 ; 2 )}.  When entering a vector, @kbd{;} is useful for
  815. Xcreating a matrix.  In particular, @kbd{[ [ 1 , 2 ; 3 , 4 ; 5 , 6 ] ]} is
  816. Xequivalent to @kbd{[ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ]}.
  817. X
  818. X@pindex calc-dots
  819. XIncomplete entry is also used to enter intervals.  For example,
  820. X@kbd{[ 2 .. 4 )} enters a semi-open interval.  Note that when you type
  821. Xthe first period, it will be interpreted as a decimal point, but when
  822. Xyou type a second period immediately afterward, it is re-interpreted as
  823. Xpart of the interval symbol.  Typing @kbd{..} corresponds to executing
  824. Xthe @code{calc-dots} command.
  825. X
  826. XIf you find incomplete entry distracting, you may wish to enter vectors
  827. Xand complex numbers as algebraic formulas by pressing the apostrophe key.
  828. X
  829. X@node Variables, Formulas, Incomplete Objects, Data Types
  830. X@section Variables
  831. X
  832. X@cindex Variables, in formulas
  833. XA @dfn{variable} is somewhere between a storage register on a conventional
  834. Xcalculator, and a variable in a programming language.  (In fact, a Calc
  835. Xvariable is really just an Emacs Lisp variable that contains a Calc number
  836. Xor formula.)  A variable's name is normally composed of letters and digits.
  837. XCalc also allows apostrophes and underscores in variable names.
  838. XThe Calc variable @code{foo} corresponds to the Emacs Lisp variable
  839. X@code{var-foo}.  The @code{calc-store} and @code{calc-recall} commands can
  840. Xbe made to use any arbitrary Lisp variable simply by backspacing over the
  841. X@samp{var-} prefix in the minibuffer.@refill
  842. X
  843. XIn a command that takes a variable name, you can either type the full
  844. Xname of a variable, or type a single digit to use one of the special
  845. Xconvenience variables @code{var-0} through @code{var-9}.  For example,
  846. X@kbd{3 s 2} stores the number 3 in variable @code{var-2}, and
  847. X@kbd{3 s foo @key{RET}} stores that number in variable @code{var-foo}.@refill
  848. X
  849. XTo push a variable itself (as opposed to the variable's value) on the
  850. Xstack, enter its name as an algebraic expression using the apostrophe
  851. X(@key{'}) key.  Variable names in algebraic formulas implicitly have
  852. X@samp{var-} prefixed to their names.  The underscore @samp{_} character
  853. Xis changed to a dash @samp{-} in variable names used in algebraic
  854. Xformulas.  If the name contains an underscore, the prefix @samp{var-} is
  855. X@emph{not} automatically added.  Thus the two formulas @samp{foo+1} and
  856. X@samp{var_foo+1} are equivalent.
  857. X
  858. X@kindex =
  859. X@pindex calc-evaluate
  860. X@cindex Evaluation of variables in a formula
  861. X@cindex Variables, evaluation
  862. X@cindex Formulas, evaluation
  863. XThe @kbd{=} (@code{calc-evaluate}) key ``evaluates'' a formula by
  864. Xreplacing all variables in the formula which have been given values by a
  865. X@code{calc-store} or @code{calc-let} command by their stored values.
  866. XOther variables are left alone.  Thus a variable that has not been
  867. Xstored acts like an abstract variable in algebra; a variable that has
  868. Xbeen stored acts more like a register in a traditional calculator.
  869. X
  870. X@cindex @code{e} variable
  871. X@cindex @code{pi} variable
  872. X@cindex @code{i} variable
  873. XA few variables are called @dfn{special constants}.  Their names are
  874. X@samp{e}, @samp{pi}, and @samp{i}.  When they are evaluated with @kbd{=},
  875. Xtheir values are calculated if necessary according to the current precision
  876. Xor complex polar mode.  If you wish to use these symbols for other purposes,
  877. Xsimply undefine or redefine them using @code{calc-store}.@refill
  878. X
  879. X@xref{Store and Recall}, for a discussion of commands dealing with variables.
  880. X
  881. X@node Formulas, , Variables, Data Types
  882. X@section Formulas
  883. X
  884. X@cindex Formulas
  885. X@cindex Operators in formulas
  886. X@cindex Precedence of operators
  887. XWhen you press the apostrophe key you may enter any expression or formula
  888. Xin algebraic form.  (Calc uses the terms ``expression'' and ``formula''
  889. Xinterchangeably.)  An expression is built up of numbers, variable names,
  890. Xand function calls, combined with various arithmetic operators.
  891. XParentheses may
  892. Xbe used to indicate grouping.  Spaces are ignored within formulas, except
  893. Xthat spaces are not permitted within variable names or numbers.
  894. XArithmetic operators, in order from highest to lowest precedence, and
  895. Xwith their equivalent function names, are:
  896. X
  897. X@display
  898. Xprefix @samp{+} and @samp{-} [@code{neg}] (as in @samp{-x})
  899. X  and prefix @samp{!} [@code{lnot}] (logical ``not,'' as in @samp{!x});
  900. X
  901. X@samp{+/-} [@code{sdev}] (the standard deviation symbol) and
  902. X  @samp{mod} [@code{makemod}] (the symbol for modulo forms);
  903. X
  904. Xpostfix @samp{!} [@code{fact}] (factorial, as in @samp{n!});
  905. X
  906. X@samp{^} [@code{pow}] (raised-to-the-power-of);
  907. X
  908. X@samp{*} [@code{mul}];
  909. X
  910. X@samp{/} [@code{div}], @samp{%} [@code{mod}] (modulo), and
  911. X  @samp{\} [@code{idiv}] (integer division);
  912. X
  913. Xinfix @samp{+} [@code{add}] and @samp{-} [@code{sub}] (as in @samp{x-y});
  914. X
  915. X@samp{|} [@code{vconcat}] (vector concatenation);
  916. X
  917. Xrelations @samp{=} [@code{eq}], @samp{!=} [@code{neq}], @samp{<} [@code{lt}], @samp{>} [@code{gt}],
  918. X  @samp{<=} [@code{leq}], and @samp{>=} [@code{geq}];
  919. X
  920. X@samp{&&} [@code{land}] (logical ``and'');
  921. X
  922. X@samp{||} [@code{lor}] (logical ``or'');
  923. X
  924. Xthe C-style ``if'' operator @samp{a?b:c} [@code{if}].
  925. X@end display
  926. X
  927. XNote that, unlike in usual computer notation, multiplication binds more
  928. Xstrongly than division:  @samp{a*b/c*d} is equivalent to @samp{(a*b)/(c*d)}.
  929. X
  930. X@cindex Multiplication, implicit
  931. X@cindex Implicit multiplication
  932. XThe multiplication sign @samp{*} may be omitted in many cases.  In particular,
  933. Xif the righthand side is a number, variable name, or parenthesized
  934. Xexpression, the @samp{*} may be omitted.  Implicit multiplication has the
  935. Xsame precedence as the explicit @samp{*} operator.  The one exception to
  936. Xthe rule is that a variable name followed by a parenthesized expression,
  937. Xas in @samp{f(x)},
  938. Xis interpreted as a function call, not an implicit @samp{*}.  In many
  939. Xcases you must use a space if you omit the @samp{*}:  @samp{2a} is the
  940. Xsame as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
  941. Xis a variable called @code{ab}, @emph{not} the product of @samp{a} and
  942. X@samp{b}!@refill
  943. X
  944. X@cindex Implicit comma in vectors
  945. XThe rules are slightly different for vectors written with square brackets.
  946. XThere, the space character is interpreted (like the comma) as a separator
  947. Xof elements of the vector.  Thus @samp{[ 2a b+c d ]} is equivalent to
  948. X@samp{[2*a, b+c, d]}, whereas @samp{2a b+c d} is equivalent to
  949. X@samp{2*a*b + c*d}.
  950. XNote that spaces around the brackets, and around explicit commas, are
  951. Xignored.  To force spaces to be interpreted as multiplication you can
  952. Xenclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
  953. Xinterpreted as @samp{[a*b, 2*c*d]}.  An implicit comma is also inserted
  954. Xbetween @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill
  955. X
  956. XVectors that contain commas (not embedded within nested parentheses or
  957. Xbrackets) do not treat spaces specially:  @samp{[a b, 2 c d]} is a vector
  958. Xof two elements.  Also, vectors entered with curly braces instead of
  959. Xsquare brackets, do not give spaces any special treatment.
  960. X
  961. X@cindex Function call notation
  962. XA function call is, e.g., @samp{sin(1+x)}.  Function names follow the same
  963. Xrules as variable names except that the default prefix @samp{calcFunc-} is
  964. Xused (instead of @samp{var-}) for the internal Lisp form.
  965. XMost mathematical Calculator commands like
  966. X@code{calc-sin} have function equivalents like @code{sin}.
  967. XIf no Lisp function is defined for a function called by a formula, the
  968. Xcall is left as it is during algebraic manipulation: @samp{f(x+y)} is
  969. Xleft alone.  Beware that many innocent-looking short names like @code{in}
  970. Xand @code{re} have predefined meanings which could surprise you; however,
  971. Xsingle letters or single letters followed by digits are always safe.
  972. X@xref{Function Index}.@refill
  973. X
  974. XIn the documentation for particular commands, the notation @kbd{H S}
  975. X(@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the
  976. Xcommand @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all
  977. Xrepresent the same operation.@refill
  978. X
  979. X@xref{Algebra}, for commands for manipulating formulas
  980. Xsymbolically.
  981. X
  982. X@node Stack and Trail, Mode Settings, Data Types, Top
  983. X@chapter Stack and Trail Commands
  984. X
  985. XThis chapter describes the Calc commands for manipulating objects in the
  986. Xstack and in the trail buffer.  (These commands operate on objects of any
  987. Xtype, such as numbers, vectors, formulas, and incomplete objects.)
  988. X
  989. X@menu
  990. X* Stack Manipulation::
  991. X* Trail Commands::
  992. X@end menu
  993. X
  994. X@node Stack Manipulation, Trail Commands, Stack and Trail, Stack and Trail
  995. X@section Stack Manipulation Commands
  996. X
  997. X@kindex RET
  998. X@kindex SPC
  999. X@pindex calc-enter
  1000. X@cindex Duplicating stack entries
  1001. XTo duplicate the top object on the stack, press @key{RET} or @key{SPC}
  1002. X(two equivalent keys for the @code{calc-enter} command).
  1003. XGiven a positive numeric prefix argument, these commands duplicate
  1004. Xseveral elements at the top of the stack.
  1005. XGiven a negative argument,
  1006. Xthese commands duplicate the specified element of the stack.
  1007. XGiven an argument of zero, they duplicate the entire stack.
  1008. XFor example, with @samp{10 20 30} on the stack,
  1009. X@key{RET} creates @samp{10 20 30 30},
  1010. X@kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30},
  1011. X@kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and
  1012. X@kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.@refill
  1013. X
  1014. X@kindex LFD
  1015. X@pindex calc-over
  1016. XThe @key{LFD} (@code{calc-over}) command (on a key marked Line-Feed if you
  1017. Xhave it, else on @kbd{C-j}) is like @code{calc-enter}
  1018. Xexcept that the sign of the numeric prefix argument is interpreted
  1019. Xoppositely.  Also, with no prefix argument the default argument is 2.
  1020. XThus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}
  1021. Xare both equivalent to @kbd{C-u - 2 @key{RET}}, producing
  1022. X@samp{10 20 30 20}.@refill
  1023. X
  1024. X@kindex DEL
  1025. X@kindex C-d
  1026. X@pindex calc-pop
  1027. X@cindex Removing stack entries
  1028. X@cindex Deleting stack entries
  1029. XTo remove the top element from the stack, press @key{DEL} (@code{calc-pop}).
  1030. XThe @kbd{C-d} key is a synonym for @key{DEL}.
  1031. X(If the top element is an incomplete object with at least one element, the
  1032. Xlast element is removed from it.)  Given a positive numeric prefix argument,
  1033. Xseveral elements are removed.  Given a negative argument, the specified
  1034. Xelement of the stack is deleted.  Given an argument of zero, the entire
  1035. Xstack is emptied.
  1036. XFor example, with @samp{10 20 30} on the stack,
  1037. X@key{DEL} creates @samp{10 20},
  1038. X@kbd{C-u 2 @key{DEL}} creates @samp{10},
  1039. X@kbd{C-u - 2 @key{DEL}} creates @samp{10 30}, and
  1040. X@kbd{C-u 0 @key{DEL}} creates an empty stack.@refill
  1041. X
  1042. X@kindex TAB
  1043. X@pindex calc-roll-down
  1044. XTo exchange the top two elements of the stack, press @key{TAB}
  1045. X(@code{calc-roll-down}).  Given a positive numeric prefix argument, the
  1046. Xspecified number of elements at the top of the stack are rotated downward.
  1047. XGiven a negative argument, the entire stack is rotated downward the specified
  1048. Xnumber of times.  Given an argument of zero, the entire stack is reversed
  1049. Xtop-for-bottom.
  1050. XFor example, with @samp{10 20 30 40 50} on the stack,
  1051. X@key{TAB} creates @samp{10 20 30 50 40},
  1052. X@kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},
  1053. X@kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and
  1054. X@kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.@refill
  1055. X
  1056. X@kindex M-TAB
  1057. X@pindex calc-roll-up
  1058. XThe command @key{M-TAB} (@code{calc-roll-up}) is analogous to @key{TAB}
  1059. Xexcept that it rotates upward instead of downward.  Also, the default
  1060. Xwith no prefix argument is to rotate the top 3 elements.
  1061. XFor example, with @samp{10 20 30 40 50} on the stack,
  1062. X@key{M-TAB} creates @samp{10 20 40 50 30},
  1063. X@kbd{C-u 4 @key{M-TAB}} creates @samp{10 30 40 50 20},
  1064. X@kbd{C-u - 2 @key{M-TAB}} creates @samp{30 40 50 10 20}, and
  1065. X@kbd{C-u 0 @key{M-TAB}} creates @samp{50 40 30 20 10}.@refill
  1066. X
  1067. X@node Trail Commands, , Stack Manipulation, Stack and Trail
  1068. X@section Trail Commands
  1069. X
  1070. X@cindex Trail buffer
  1071. XThe commands for manipulating the Calc Trail buffer are two-key sequences
  1072. Xbeginning with the @kbd{t} prefix.
  1073. X
  1074. X@kindex t d
  1075. X@pindex calc-trail-display
  1076. XThe @kbd{t d} (@code{calc-trail-display}) command turns display of the
  1077. Xtrail on and off.  Normally the trail display is toggled on if it was off,
  1078. Xoff if it was on.  With a numeric prefix of zero, this command always
  1079. Xturns the trail off; with a prefix of one, it always turns the trail on.
  1080. XThe other trail-manipulation commands described here automatically turn
  1081. Xthe trail on.  Note that when the trail is off values are still recorded
  1082. Xthere; they are simply not displayed.  To set Emacs to turn the trail
  1083. Xoff by default, turn it off with @kbd{t d}, then save the mode settings
  1084. Xwith @kbd{m m} (@code{calc-save-modes}).
  1085. X
  1086. X@kindex t i
  1087. X@pindex calc-trail-in
  1088. X@kindex t o
  1089. X@pindex calc-trail-out
  1090. XThe @kbd{t i} (@code{calc-trail-in}) and @kbd{t o}
  1091. X(@code{calc-trail-out}) commands switch the cursor into and out of the
  1092. XCalc Trail window.  In practice they are rarely used, since the commands
  1093. Xshown below are a more convenient way to move around in the
  1094. Xtrail, and they work ``by remote control'' when the cursor is still
  1095. Xin the Calculator window.@refill
  1096. X
  1097. X@cindex Trail pointer
  1098. XThere is a @dfn{trail pointer} which selects some entry of the trail at
  1099. Xany given time.  The trail pointer looks like a @samp{>} symbol right
  1100. Xbefore the selected number.  The following commands operate on the
  1101. Xtrail pointer in various ways.
  1102. X
  1103. X@kindex t y
  1104. X@pindex calc-trail-yank
  1105. X@cindex Retrieving previous results
  1106. XThe @kbd{t y} (@code{calc-trail-yank}) command reads the selected value in
  1107. Xthe trail and pushes it onto the Calculator stack.  It allows you to
  1108. Xre-use any previously computed value without retyping.
  1109. X
  1110. X@kindex t <
  1111. X@pindex calc-trail-scroll-left
  1112. X@kindex t >
  1113. X@pindex calc-trail-scroll-right
  1114. XThe @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{d >}
  1115. X(@code{calc-trail-scroll-right}) commands horizontally scroll the trail
  1116. Xwindow left or right by one half of its width.@refill
  1117. X
  1118. X@kindex t n
  1119. X@pindex calc-trail-next
  1120. X@kindex t p
  1121. X@pindex calc-trail-previous
  1122. X@kindex t f
  1123. X@pindex calc-trail-forward
  1124. X@kindex t b
  1125. X@pindex calc-trail-backward
  1126. XThe @kbd{t n} (@code{calc-trail-next}) and @kbd{t p}
  1127. X(@code{calc-trail-previous)} commands move the trail pointer down or up
  1128. Xone line.  The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}
  1129. X(@code{calc-trail-backward}) commands move the trail pointer down or up
  1130. Xone screenful at a time.  All of these commands accept numeric prefix
  1131. Xarguments to move several lines or screenfuls at a time.@refill
  1132. X
  1133. X@kindex t [
  1134. X@pindex calc-trail-first
  1135. X@kindex t ]
  1136. X@pindex calc-trail-last
  1137. X@kindex t h
  1138. X@pindex calc-trail-here
  1139. XThe @kbd{t [} (@code{calc-trail-first}) and @kbd{t ]}
  1140. X(@code{calc-trail-last}) commands move the trail pointer to the first or
  1141. Xlast line of the trail.  The @kbd{t h} (@code{calc-trail-here}) command
  1142. Xmoves the trail pointer to the cursor position; unlike the other trail
  1143. Xcommands, @kbd{t h} works only when Calc Trail is the selected window.@refill
  1144. X
  1145. X@kindex t s
  1146. X@pindex calc-trail-isearch-forward
  1147. X@kindex t r
  1148. X@pindex calc-trail-isearch-backward
  1149. XThe @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
  1150. X(@code{calc-trail-isearch-backward}) commands perform an incremental
  1151. Xsearch forward and backward through the trail.  When you terminate the
  1152. Xsearch (typically by pressing @key{ESC}) the trail pointer moves to the
  1153. Xcurrent line.  If you cancel the search with @kbd{C-g}, the trail pointer
  1154. Xdoes not move.@refill
  1155. X
  1156. X@kindex t m
  1157. X@pindex calc-trail-marker
  1158. XThe @kbd{t m} (@code{calc-trail-marker}) command allows you to enter a
  1159. Xline of text of your own choosing into the trail.  The text is inserted
  1160. Xafter the line containing the trail pointer; this usually means it is
  1161. Xadded to the end of the trail.  Trail markers are useful mainly as the
  1162. Xtargets for later incremental searches in the trail.
  1163. X
  1164. X@kindex t k
  1165. X@pindex calc-trail-kill
  1166. XThe @kbd{t k} (@code{calc-trail-kill}) command removes the selected line
  1167. Xfrom the trail.  The line is saved in the Emacs kill ring suitable for
  1168. Xyanking into another buffer, but it is not easy to yank the text back
  1169. Xinto the trail buffer.  With a numeric prefix argument, this command
  1170. Xkills the @samp{N} lines below or above the selected one.
  1171. X
  1172. X@node Mode Settings, Arithmetic, Stack and Trail, Top
  1173. X@chapter Mode Settings
  1174. X
  1175. XThis chapter describes commands that set modes in the Calculator.
  1176. XThey do not affect the contents of the stack, although they may change
  1177. Xthe @emph{appearance} of the stack's contents.
  1178. X
  1179. X@kindex m m
  1180. X@pindex calc-save-modes
  1181. X@cindex Continuous memory
  1182. X@cindex Saving mode settings
  1183. X@cindex Permanent mode settings
  1184. X@cindex @file{.emacs} file, mode settings
  1185. XYou can save all of the current mode settings in your @file{.emacs} file
  1186. Xwith the @kbd{m m} (@code{calc-save-modes}) command.  This will cause
  1187. XEmacs to reestablish these modes each time it starts up.  The modes saved
  1188. Xin the file include everything controlled by the @kbd{m} and @kbd{d}
  1189. Xprefix keys, the current precision and binary word size, whether or not
  1190. Xthe trail is displayed, and the current height of the Calc window.
  1191. X(You can change which file this uses; @pxref{Installation}.)@refill
  1192. X
  1193. X@kindex m x
  1194. X@pindex calc-always-load-extensions
  1195. XThe @kbd{m x} (@code{calc-always-load-extensions}) command enables a mode
  1196. Xin which the first use of Calc loads the entire program, including the
  1197. Xextensions module.  Otherwise, the extensions module will not be loaded
  1198. Xuntil the first advanced Calc feature is used.  Since this mode only
  1199. Xhas effect when Calc is first loaded, @kbd{m x} is usually followed
  1200. Xby @kbd{m m} to make the mode-setting permanent.
  1201. X
  1202. X@menu
  1203. X* Precision::
  1204. X* Inverse and Hyperbolic::
  1205. X* Calculation Modes::
  1206. X* Simplification Modes::
  1207. X* Display Modes::
  1208. X* Language Modes::
  1209. X@end menu
  1210. X
  1211. X@node Precision, Inverse and Hyperbolic, Mode Settings, Mode Settings
  1212. X@section Precision
  1213. X
  1214. X@kindex p
  1215. X@pindex calc-precision
  1216. X@cindex Precision of calculations
  1217. XThe @kbd{p} (@code{calc-precision}) command controls the precision to
  1218. Xwhich floating-point calculations are carried.  The precision must be
  1219. Xat least 3 digits and may be arbitrarily high, within the limits of
  1220. Xmemory and time.  This affects only floats:  Integer and rational
  1221. Xcalculations are always carried out with as many digits as necessary.
  1222. X
  1223. XMany internal calculations are carried to one or two digits higher
  1224. Xprecision than normal.  Results are rounded down afterward to the
  1225. Xcurrent precision.  Unless a special display mode has been selected,
  1226. Xfloats are always displayed with their full stored precision, i.e.,
  1227. Xwhat you see is what you get.  Reducing the current precision does not
  1228. Xround values already on the stack, but those values will be rounded
  1229. Xdown before being used in any calculation.  The @kbd{c c} (@code{calc-clean})
  1230. Xcommand (@pxref{Conversions}) can be used to round an existing value to
  1231. Xa new precision.@refill
  1232. X
  1233. XThe @kbd{p} key prompts for the current precision.  If you wish you
  1234. Xcan instead give the precision as a numeric prefix argument.
  1235. X
  1236. X@node Inverse and Hyperbolic, Calculation Modes, Precision, Mode Settings
  1237. SHAR_EOF
  1238. echo "End of part 14"
  1239. echo "File calc.texinfo is continued in part 15"
  1240. echo "15" > s2_seq_.tmp
  1241. exit 0
  1242.