home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume24 / gnucalc / part38 < prev    next >
Encoding:
Text File  |  1991-10-31  |  55.5 KB  |  1,257 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@synaptics.com (David Gillespie)
  3. Subject:  v24i086:  gnucalc - GNU Emacs Calculator, v2.00, Part38/56
  4. Message-ID: <1991Oct31.214656.2773@sparky.imd.sterling.com>
  5. X-Md4-Signature: cc12ad4ca461f596619fbe0135426c34
  6. Date: Thu, 31 Oct 1991 21:46:56 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: daveg@synaptics.com (David Gillespie)
  10. Posting-number: Volume 24, Issue 86
  11. Archive-name: gnucalc/part38
  12. Environment: Emacs
  13. Supersedes: gmcalc: Volume 13, Issue 27-45
  14.  
  15. ---- Cut Here and unpack ----
  16. #!/bin/sh
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file calc.texinfo continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 38; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping calc.texinfo'
  34. else
  35. echo 'x - continuing file calc.texinfo'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
  37. there is no solution to this equation (which can happen only when
  38. @cite{M} is non-prime), or if any of the arguments are non-integers, the
  39. division is left in symbolic form.  Other operations, such as square
  40. roots, are not yet supported for modulo forms.  (Note that, although
  41. @w{`@t{(}@i{a} @t{mod} @i{M}@t{)^.5}'} will compute a ``modulo square root''
  42. in the sense of reducing @c{$\sqrt a$}
  43. @cite{sqrt(a)} modulo @cite{M}, this is not a
  44. useful definition from the number-theoretical point of view.)@refill
  45. X
  46. @kindex M (modulo forms)
  47. @tindex mod (operator)
  48. To create a modulo form during numeric entry, press the shift-@kbd{M}
  49. key to enter the word @samp{mod}.  As a special convenience, pressing
  50. shift-@kbd{M} a second time automatically enters the value of @cite{M}
  51. that was most recently used before.  During algebraic entry, either
  52. type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
  53. Once again, pressing this a second time enters the current modulo.@refill
  54. X
  55. You can also use @code{calc-pack} and @kbd{%} to modify modulo forms.
  56. @xref{Building Vectors}.  @xref{Basic Arithmetic}.
  57. X
  58. It is possible to mix HMS forms and modulo forms.  For example, an
  59. HMS form modulo 24 could be used to manipulate clock times; an HMS
  60. form modulo 360 would be suitable for angles.  Making the modulo @cite{M}
  61. also be an HMS form eliminates troubles that would arise if the angular
  62. mode were inadvertently set to Radians, in which case
  63. @w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
  64. 24 radians!
  65. X
  66. Modulo forms cannot have variables or formulas for components.  If you
  67. enter the formula @samp{(x + 2) mod 5}, Calc propagates the modulus
  68. to each of the coefficients:  @samp{(1 mod 5) x + (2 mod 5)}.
  69. X
  70. @tindex makemod
  71. The algebraic function @samp{makemod(a, m)} builds the modulo form
  72. @w{@samp{a mod m}}.
  73. X
  74. @node Error Forms, Interval Forms, Modulo Forms, Data Types
  75. @section Error Forms
  76. X
  77. @noindent
  78. @cindex Error forms
  79. @cindex Standard deviations
  80. An @dfn{error form} is a number with an associated standard
  81. deviation, as in @samp{2.3 +/- 0.12}.  The notation
  82. `@i{x} @t{+/-} @c{$\sigma$}
  83. @asis{sigma}' stands for an uncertain value which follows a normal or
  84. Gaussian distribution of mean @cite{x} and standard deviation or
  85. ``error'' @c{$\sigma$}
  86. @cite{sigma}.  Both the mean and the error can be either numbers or
  87. formulas.  Generally these are real numbers but the mean may also be
  88. complex.  If the error is negative or complex, it is changed to its
  89. absolute value.  An error form with zero error is converted to a
  90. regular number by the Calculator.@refill
  91. X
  92. All arithmetic and transcendental functions accept error forms as input.
  93. Operations on the mean-value part work just like operations on regular
  94. numbers.  The error part for any function @cite{f(x)} (such as @c{$\sin x$}
  95. @cite{sin(x)})
  96. is defined by the error of @cite{x} times the derivative of @cite{f}
  97. evaluated at the mean value of @cite{x}.  For a two-argument function
  98. @cite{f(x,y)} (such as addition) the error is the square root of the sum
  99. of the squares of the errors due to @cite{x} and @cite{y}.
  100. @tex
  101. $$ \eqalign{
  102. X  f(x \hbox{\code{ +/- }} \sigma)
  103. X    &= f(x) \hbox{\code{ +/- }} \sigma \left| {df(x) \over dx} \right| \cr
  104. X  f(x \hbox{\code{ +/- }} \sigma_x, y \hbox{\code{ +/- }} \sigma_y)
  105. X    &= f(x,y) \hbox{\code{ +/- }}
  106. X        \sqrt{\left(\sigma_x \left| {\partial f(x,y) \over \partial x}
  107. X                             \right| \right)^2
  108. X             +\left(\sigma_y \left| {\partial f(x,y) \over \partial y}
  109. X                             \right| \right)^2 } \cr
  110. } $$
  111. @end tex
  112. Note that this
  113. definition assumes the errors in @cite{x} and @cite{y} are uncorrelated.
  114. A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
  115. is not the same as @samp{(2 +/- 1)^2}; the former represents the product
  116. of two independent values which happen to have the same probability
  117. distributions, and the latter is the product of one random value with itself.
  118. The former will produce an answer with less error, since on the average
  119. the two independent errors can be expected to cancel out.@refill
  120. X
  121. Consult a good text on error analysis for a discussion of the proper use
  122. of standard deviations.  Actual errors often are neither Gaussian-distributed
  123. nor uncorrelated, and the above formulas are valid only when errors
  124. are small.  As an example, the error arising from
  125. `@t{sin(}@i{x} @t{+/-} @c{$\sigma$}
  126. @i{sigma}@t{)}' is
  127. `@c{$\sigma$}
  128. @i{sigma} @t{abs(cos(}@i{x}@t{))}'.  When @cite{x} is close to zero,
  129. @c{$\cos x$}
  130. @cite{cos(x)} is
  131. close to one so the error in the sine is close to @c{$\sigma$}
  132. @cite{sigma}; this makes sense, since @c{$\sin x$}
  133. @cite{sin(x)} is approximately @cite{x} near zero, so a given
  134. error in @cite{x} will produce about the same error in the sine.  Likewise,
  135. near 90 degrees @c{$\cos x$}
  136. @cite{cos(x)} is nearly zero and so the computed error is
  137. small:  The sine curve is nearly flat in that region, so an error in @cite{x}
  138. has relatively little effect on the value of @c{$\sin x$}
  139. @cite{sin(x)}.  However, consider
  140. @samp{sin(90 +/- 1000)}.  The cosine of 90 is zero, so Calc will report
  141. zero error!  We get an obviously wrong result because we have violated
  142. the small-error approximation underlying the error analysis.  If the error
  143. in @cite{x} had been small, the error in @c{$\sin x$}
  144. @cite{sin(x)} would indeed have been negligible.@refill
  145. X
  146. @kindex p (error forms)
  147. @tindex +/-
  148. To enter an error form during regular numeric entry, use the @kbd{p}
  149. (``plus-or-minus'') key to type the @samp{+/-} symbol.  (If you try actually
  150. typing @samp{+/-} the @kbd{+} key will be interpreted as the Calculator's
  151. @kbd{+} command!)  Within an algebraic formula, you can press @kbd{M-p} to
  152. type the @samp{+/-} symbol, or type it out by hand.
  153. X
  154. Error forms and complex numbers can be mixed; the formulas shown above
  155. are used for complex numbers, too, except that if the error part evaluates
  156. to a complex number its absolute value (or the square root of the sum of
  157. the squares of the absolute values of the two error contributions) is
  158. used.  Mathematically, this corresponds to a radially symmetric Gaussian
  159. distribution of numbers on the complex plane.  However, note that Calc
  160. considers an error form with real components to represent a real number,
  161. not a complex distribution around a real mean.
  162. X
  163. Error forms may also be composed of HMS forms.  For best results, both
  164. the mean and the error should be HMS forms if either one is.
  165. X
  166. @tindex sdev
  167. The algebraic function @samp{sdev(a, b)} builds the error form @samp{a +/- b}.
  168. X
  169. @node Interval Forms, Incomplete Objects, Error Forms, Data Types
  170. @section Interval Forms
  171. X
  172. @noindent
  173. @cindex Interval forms
  174. An @dfn{interval} is a subset of consecutive real numbers.  For example,
  175. the interval @samp{[2 ..@: 4]} represents all the numbers from 2 to 4,
  176. inclusive.  If you multiply it by the interval @samp{[0.5 ..@: 2]} you
  177. obtain @samp{[1 ..@: 8]}.  This calculation represents the fact that if
  178. you multiply some number in the range @samp{[2 ..@: 4]} by some other
  179. number in the range @samp{[0.5 ..@: 2]}, your result will lie in the range
  180. from 1 to 8.  Interval arithmetic is used to get a worst-case estimate
  181. of the possible range of values a computation will produce, given the
  182. set of possible values of the input.
  183. X
  184. @ifinfo
  185. Calc supports several varieties of intervals, including @dfn{closed}
  186. intervals of the type shown above, @dfn{open} intervals such as
  187. @samp{(2 ..@: 4)}, which represents the range of numbers from 2 to 4
  188. @emph{exclusive}, and @dfn{semi-open} intervals in which one end
  189. uses a round parenthesis and the other a square bracket.  In mathematical
  190. terms,
  191. @samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas
  192. @samp{[2 ..@: 4)} represents @cite{2 <= x < 4},
  193. @samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and
  194. @samp{(2 ..@: 4)} represents @cite{2 < x < 4}.@refill
  195. @end ifinfo
  196. @tex
  197. Calc supports several varieties of intervals, including \dfn{closed}
  198. intervals of the type shown above, \dfn{open} intervals such as
  199. \samp{(2 ..\: 4)}, which represents the range of numbers from 2 to 4
  200. \emph{exclusive}, and \dfn{semi-open} intervals in which one end
  201. uses a round parenthesis and the other a square bracket.  In mathematical
  202. terms,
  203. $$ \eqalign{
  204. X   [2 \hbox{\cite{..}} 4]  &\quad\hbox{means}\quad  2 \le x \le 4  \cr
  205. X   [2 \hbox{\cite{..}} 4)  &\quad\hbox{means}\quad  2 \le x  <  4  \cr
  206. X   (2 \hbox{\cite{..}} 4]  &\quad\hbox{means}\quad  2  <  x \le 4  \cr
  207. X   (2 \hbox{\cite{..}} 4)  &\quad\hbox{means}\quad  2  <  x  <  4  \cr
  208. } $$
  209. @end tex
  210. X
  211. The lower and upper limits of an interval must be either real numbers
  212. (or HMS or date forms), or symbolic expressions which are assumed to be
  213. real-valued, or @samp{-inf} and @samp{inf}.  In general the lower limit
  214. must be less than the upper limit.  A closed interval containing only
  215. one value, @samp{[3 ..@: 3]}, is converted to a plain number (3)
  216. automatically.  An interval containing no values at all (such as
  217. @samp{[3 ..@: 2]} or @samp{[2 ..@: 2)}) can be represented but is not
  218. guaranteed to behave well when used in arithmetic.  Note that the
  219. interval @samp{[3 .. inf)} represents all real numbers greater than
  220. or equal to 3, and @samp{(-inf .. inf)} represents all real numbers.
  221. In fact, @samp{[-inf .. inf]} represents all real numbers including
  222. infinity.
  223. X
  224. Intervals are entered in the notation shown here, either as algebraic
  225. formulas, or using incomplete forms.  (@xref{Incomplete Objects}.)
  226. In algebraic formulas, multiple periods in a row are collected from
  227. left to right, so that @samp{1....1e2} is interpreted as @samp{1 ..@: ..@: 1e2}
  228. (a syntax error) rather than @samp{1.@: ..@: .1e2}.  Use spaces or type
  229. @samp{1.0..0.1e2} to make the notation unambiguous.  If you omit
  230. the lower or upper limit, a default of @samp{-inf} or @samp{inf}
  231. (respectively) is furnished.
  232. X
  233. ``Infinite mode'' also affects operations on intervals
  234. (@pxref{Infinities}).  Calc will always introduce an open infinity,
  235. as in @samp{1 / (0 .. 2] = [0.5 .. inf)}.  But closed infinities,
  236. @samp{1 / [0 .. 2] = [0.5 .. inf]}, arise only in infinite mode;
  237. otherwise they are left unevaluated.  Note that the ``direction'' of
  238. a zero is not an issue in this case, since the zero is always assumed
  239. to be continuous with the rest of the interval.  For intervals that
  240. contain zero inside them Calc is forced to give the result,
  241. @samp{1 / (-2 .. 2) = [-inf .. inf]}.
  242. X
  243. While it may seem that intervals and error forms are similar, they are
  244. based on entirely different concepts of inexact quantities.  An error
  245. form `@i{x} @t{+/-} @c{$\sigma$}
  246. @i{sigma}' means a variable is random, and its value could
  247. be anything but is ``probably'' within one @c{$\sigma$}
  248. @i{sigma} of the mean value @cite{x}.
  249. An interval `@t{[}@i{a} @t{..@:} @i{b}@t{]}' means a variable's value
  250. is unknown, but guaranteed to lie in the specified range.  Error forms
  251. are statistical or ``average case'' approximations; interval arithmetic
  252. tends to produce ``worst case'' bounds on an answer.@refill
  253. X
  254. Intervals may not contain complex numbers, but they may contain
  255. HMS forms or date forms.
  256. X
  257. @xref{Set Operations}, for commands that interpret interval forms
  258. as subsets of the set of real numbers.
  259. X
  260. @tindex intv
  261. The algebraic function @samp{intv(n, a, b)} builds an interval form
  262. from @samp{a} to @samp{b}; @samp{n} is an integer code which must
  263. be 0 for @samp{(..)}, 1 for @samp{(..]}, 2 for @samp{[..)}, or
  264. 3 for @samp{[..]}.
  265. X
  266. @node Incomplete Objects, Variables, Interval Forms, Data Types
  267. @section Incomplete Objects
  268. X
  269. @noindent
  270. @kindex [
  271. @kindex ]
  272. @kindex (
  273. @kindex )
  274. @kindex ,
  275. @kindex ;
  276. @cindex Incomplete vectors
  277. @cindex Incomplete complex numbers
  278. @cindex Incomplete interval forms
  279. When @kbd{(} or @kbd{[} is typed to begin entering a complex number or
  280. vector, respectively, the effect is to push an @dfn{incomplete} complex
  281. number or vector onto the stack.  The @kbd{,} key adds the value(s) at
  282. the top of the stack onto the current incomplete object.  The @kbd{)}
  283. and @kbd{]} keys ``close'' the incomplete object after adding any values
  284. on the top of the stack in front of the incomplete object.
  285. X
  286. As a result, the sequence of keystrokes @kbd{[ 2 , 3 @key{RET} 2 * , 9 ]}
  287. pushes the vector @samp{[2, 6, 9]} onto the stack.  Likewise, @kbd{( 1 , 2 Q )}
  288. pushes the complex number @samp{(1, 1.414)} (approximately).
  289. X
  290. If several values lie on the stack in front of the incomplete object,
  291. all are collected and appended to the object.  Thus the @kbd{,} key
  292. is redundant:  @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}.  Some people
  293. prefer the equivalent @key{SPC} key to @key{RET}.@refill
  294. X
  295. As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
  296. @kbd{,} adds a zero or duplicates the preceding value in the list being
  297. formed.  Typing @key{DEL} during incomplete entry removes the last item
  298. from the list.
  299. X
  300. The @kbd{;} key is used in the same way as @kbd{,} to create polar complex
  301. numbers:  @kbd{( 1 ; 2 )}.  When entering a vector, @kbd{;} is useful for
  302. creating a matrix.  In particular, @kbd{[ [ 1 , 2 ; 3 , 4 ; 5 , 6 ] ]} is
  303. equivalent to @kbd{[ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ]}.
  304. X
  305. @pindex calc-dots
  306. Incomplete entry is also used to enter intervals.  For example,
  307. @kbd{[ 2 ..@: 4 )} enters a semi-open interval.  Note that when you type
  308. the first period, it will be interpreted as a decimal point, but when
  309. you type a second period immediately afterward, it is re-interpreted as
  310. part of the interval symbol.  Typing @kbd{..} corresponds to executing
  311. the @code{calc-dots} command.
  312. X
  313. If you find incomplete entry distracting, you may wish to enter vectors
  314. and complex numbers as algebraic formulas by pressing the apostrophe key.
  315. X
  316. @node Variables, Formulas, Incomplete Objects, Data Types
  317. @section Variables
  318. X
  319. @noindent
  320. @cindex Variables, in formulas
  321. A @dfn{variable} is somewhere between a storage register on a conventional
  322. calculator, and a variable in a programming language.  (In fact, a Calc
  323. variable is really just an Emacs Lisp variable that contains a Calc number
  324. or formula.)  A variable's name is normally composed of letters and digits.
  325. Calc also allows apostrophes and underscores in variable names.
  326. The Calc variable @code{foo} corresponds to the Emacs Lisp variable
  327. @code{var-foo}.  The @kbd{s s} (@code{calc-store}) command and other
  328. commands that operate on variables can
  329. be made to use any arbitrary Lisp variable simply by backspacing over the
  330. @samp{var-} prefix in the minibuffer.@refill
  331. X
  332. In a command that takes a variable name, you can either type the full
  333. name of a variable, or type a single digit to use one of the special
  334. convenience variables @code{var-q0} through @code{var-q9}.  For example,
  335. @kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and
  336. @w{@kbd{3 s s foo @key{RET}}} stores that number in variable
  337. @code{var-foo}.@refill
  338. X
  339. To push a variable itself (as opposed to the variable's value) on the
  340. stack, enter its name as an algebraic expression using the apostrophe
  341. (@key{'}) key.  Variable names in algebraic formulas implicitly have
  342. @samp{var-} prefixed to their names.  The @samp{#} character in variable
  343. names used in algebraic formulas corresponds to a dash @samp{-} in the
  344. Lisp variable name.  If the name contains any dashes, the prefix @samp{var-}
  345. is @emph{not} automatically added.  Thus the two formulas @samp{foo + 1}
  346. and @samp{var#foo + 1} both refer to the same variable.
  347. X
  348. @kindex =
  349. @pindex calc-evaluate
  350. @cindex Evaluation of variables in a formula
  351. @cindex Variables, evaluation
  352. @cindex Formulas, evaluation
  353. The @kbd{=} (@code{calc-evaluate}) key ``evaluates'' a formula by
  354. replacing all variables in the formula which have been given values by a
  355. @code{calc-store} or @code{calc-let} command by their stored values.
  356. Other variables are left alone.  Thus a variable that has not been
  357. stored acts like an abstract variable in algebra; a variable that has
  358. been stored acts more like a register in a traditional calculator.
  359. With a positive numeric prefix argument, @kbd{=} evaluates the top
  360. @var{n} stack entries; with a negative argument, @kbd{=} evaluates
  361. the @var{n}th stack entry.
  362. X
  363. @cindex @code{e} variable
  364. @cindex @code{pi} variable
  365. @cindex @code{i} variable
  366. @cindex @code{phi} variable
  367. @cindex @code{gamma} variable
  368. @vindex e
  369. @vindex pi
  370. @vindex i
  371. @vindex phi
  372. @vindex gamma
  373. A few variables are called @dfn{special constants}.  Their names are
  374. @samp{e}, @samp{pi}, @samp{i}, @samp{phi}, and @samp{gamma}.
  375. (@xref{Scientific Functions}.)  When they are evaluated with @kbd{=},
  376. their values are calculated if necessary according to the current precision
  377. or complex polar mode.  If you wish to use these symbols for other purposes,
  378. simply undefine or redefine them using @code{calc-store}.@refill
  379. X
  380. The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
  381. infinite or indeterminate values.  It's best not to use them for
  382. regular variables, since Calc uses special algebraic rules when
  383. it manipulates them.  Calc displays a warning message if you store
  384. a value into any of these special variables.
  385. X
  386. @xref{Store and Recall}, for a discussion of commands dealing with variables.
  387. X
  388. @node Formulas, , Variables, Data Types
  389. @section Formulas
  390. X
  391. @noindent
  392. @cindex Formulas
  393. @cindex Expressions
  394. @cindex Operators in formulas
  395. @cindex Precedence of operators
  396. When you press the apostrophe key you may enter any expression or formula
  397. in algebraic form.  (Calc uses the terms ``expression'' and ``formula''
  398. interchangeably.)  An expression is built up of numbers, variable names,
  399. and function calls, combined with various arithmetic operators.
  400. Parentheses may
  401. be used to indicate grouping.  Spaces are ignored within formulas, except
  402. that spaces are not permitted within variable names or numbers.
  403. Arithmetic operators, in order from highest to lowest precedence, and
  404. with their equivalent function names, are:
  405. X
  406. @display
  407. @samp{_} [@code{subscr}] (subscripts);
  408. X
  409. postfix @samp{%} [@code{percent}] (as in @samp{25% = 0.25});
  410. X
  411. prefix @samp{+} and @samp{-} [@code{neg}] (as in @samp{-x})
  412. X  and prefix @samp{!} [@code{lnot}] (logical ``not,'' as in @samp{!x});
  413. X
  414. @samp{+/-} [@code{sdev}] (the standard deviation symbol) and
  415. X  @samp{mod} [@code{makemod}] (the symbol for modulo forms);
  416. X
  417. postfix @samp{!} [@code{fact}] (factorial, as in @samp{n!})
  418. X  and postfix @samp{!!} [@code{dfact}] (double factorial);
  419. X
  420. @samp{^} [@code{pow}] (raised-to-the-power-of);
  421. X
  422. @samp{*} [@code{mul}];
  423. X
  424. @samp{/} [@code{div}], @samp{%} [@code{mod}] (modulo), and
  425. X  @samp{\} [@code{idiv}] (integer division);
  426. X
  427. infix @samp{+} [@code{add}] and @samp{-} [@code{sub}] (as in @samp{x-y});
  428. X
  429. @samp{|} [@code{vconcat}] (vector concatenation);
  430. X
  431. relations @samp{=} [@code{eq}], @samp{!=} [@code{neq}], @samp{<} [@code{lt}], @samp{>} [@code{gt}],
  432. X  @samp{<=} [@code{leq}], and @samp{>=} [@code{geq}];
  433. X
  434. @samp{&&} [@code{land}] (logical ``and'');
  435. X
  436. @samp{||} [@code{lor}] (logical ``or'');
  437. X
  438. the C-style ``if'' operator @samp{a?b:c} [@code{if}];
  439. X
  440. @samp{!!!} [@code{pnot}] (rewrite pattern ``not'');
  441. X
  442. @samp{&&&} [@code{pand}] (rewrite pattern ``and'');
  443. X
  444. @samp{|||} [@code{por}] (rewrite pattern ``or'');
  445. X
  446. @samp{:=} [@code{assign}] (for assignments and rewrite rules);
  447. X
  448. @samp{::} [@code{condition}] (rewrite pattern condition);
  449. X
  450. @samp{=>} [@code{evalto}].
  451. @end display
  452. X
  453. Note that, unlike in usual computer notation, multiplication binds more
  454. strongly than division:  @samp{a*b/c*d} is equivalent to @c{$a b \over c d$}
  455. @cite{(a*b)/(c*d)}.
  456. X
  457. @cindex Multiplication, implicit
  458. @cindex Implicit multiplication
  459. The multiplication sign @samp{*} may be omitted in many cases.  In particular,
  460. if the righthand side is a number, variable name, or parenthesized
  461. expression, the @samp{*} may be omitted.  Implicit multiplication has the
  462. same precedence as the explicit @samp{*} operator.  The one exception to
  463. the rule is that a variable name followed by a parenthesized expression,
  464. as in @samp{f(x)},
  465. is interpreted as a function call, not an implicit @samp{*}.  In many
  466. cases you must use a space if you omit the @samp{*}:  @samp{2a} is the
  467. same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
  468. is a variable called @code{ab}, @emph{not} the product of @samp{a} and
  469. @samp{b}!  Also note that @samp{f (x)} is still a function call.@refill
  470. X
  471. @cindex Implicit comma in vectors
  472. The rules are slightly different for vectors written with square brackets.
  473. There, the space character is interpreted (like the comma) as a separator
  474. of elements of the vector.  Thus @samp{[ 2a b+c d ]} is equivalent to
  475. @samp{[2*a, b+c, d]}, whereas @samp{2a b+c d} is equivalent to
  476. @samp{2*a*b + c*d}.
  477. Note that spaces around the brackets, and around explicit commas, are
  478. ignored.  To force spaces to be interpreted as multiplication you can
  479. enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
  480. interpreted as @samp{[a*b, 2*c*d]}.  An implicit comma is also inserted
  481. between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill
  482. X
  483. Vectors that contain commas (not embedded within nested parentheses or
  484. brackets) do not treat spaces specially:  @samp{[a b, 2 c d]} is a vector
  485. of two elements.  Also, vectors entered with curly braces instead of
  486. square brackets do not give spaces any special treatment.  When Calc
  487. displays a vector that does not contain any commas, it will insert
  488. parentheses if necessary to make the meaning clear:  @samp{[(a b)]}.
  489. X
  490. The expression @samp{5%-2} is ambiguous; is this five-percent minus two,
  491. or five modulo minus-two?  Calc always interprets the leftmost symbol as
  492. an infix operator preferentially (modulo, in this case), so you would
  493. need to write @samp{(5%)-2} to get the former interpretation.
  494. X
  495. @cindex Function call notation
  496. A function call is, e.g., @samp{sin(1+x)}.  Function names follow the same
  497. rules as variable names except that the default prefix @samp{calcFunc-} is
  498. used (instead of @samp{var-}) for the internal Lisp form.
  499. Most mathematical Calculator commands like
  500. @code{calc-sin} have function equivalents like @code{sin}.
  501. If no Lisp function is defined for a function called by a formula, the
  502. call is left as it is during algebraic manipulation: @samp{f(x+y)} is
  503. left alone.  Beware that many innocent-looking short names like @code{in}
  504. and @code{re} have predefined meanings which could surprise you; however,
  505. single letters or single letters followed by digits are always safe.
  506. @xref{Function Index}.@refill
  507. X
  508. In the documentation for particular commands, the notation @kbd{H S}
  509. (@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the
  510. command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all
  511. represent the same operation.@refill
  512. X
  513. Commands that interpret (``parse'') text as algebraic formulas include
  514. algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
  515. the contents of the editing buffer when you finish, the @kbd{M-# g}
  516. and @kbd{M-# r} commands, the @kbd{C-y} command, the X window system
  517. ``paste'' mouse operation, and Embedded Mode.  All of these operations
  518. use the same rules for parsing formulas; in particular, language modes
  519. (@pxref{Language Modes}) affect them all in the same way.
  520. X
  521. When you read a large amount of text into the Calculator (say a vector
  522. which represents a big set of rewrite rules; @pxref{Rewrite Rules}),
  523. you may wish to include comments in the text.  Calc's formula parser
  524. ignores the symbol @samp{%%} and anything following it on a line:
  525. X
  526. @example
  527. [ a + b,   %% the sum of "a" and "b"
  528. X  c + d,
  529. X  %% last line is coming up:
  530. X  e + f ]
  531. @end example
  532. X
  533. @noindent
  534. This is parsed exactly the same as @samp{[ a + b, c + d, e + f ]}.
  535. X
  536. @xref{Algebra}, for commands for manipulating formulas symbolically.
  537. X
  538. @node Stack and Trail, Mode Settings, Data Types, Top
  539. @chapter Stack and Trail Commands
  540. X
  541. @noindent
  542. This chapter describes the Calc commands for manipulating objects in the
  543. stack and in the trail buffer.  (These commands operate on objects of any
  544. type, such as numbers, vectors, formulas, and incomplete objects.)
  545. X
  546. @menu
  547. * Stack Manipulation::
  548. * Trail Commands::
  549. * Keep Arguments::
  550. @end menu
  551. X
  552. @node Stack Manipulation, Trail Commands, Stack and Trail, Stack and Trail
  553. @section Stack Manipulation Commands
  554. X
  555. @noindent
  556. @kindex RET
  557. @kindex SPC
  558. @pindex calc-enter
  559. @cindex Duplicating stack entries
  560. To duplicate the top object on the stack, press @key{RET} or @key{SPC}
  561. (two equivalent keys for the @code{calc-enter} command).
  562. Given a positive numeric prefix argument, these commands duplicate
  563. several elements at the top of the stack.
  564. Given a negative argument,
  565. these commands duplicate the specified element of the stack.
  566. Given an argument of zero, they duplicate the entire stack.
  567. For example, with @samp{10 20 30} on the stack,
  568. @key{RET} creates @samp{10 20 30 30},
  569. @kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30},
  570. @kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and
  571. @kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.@refill
  572. X
  573. @kindex LFD
  574. @pindex calc-over
  575. The @key{LFD} (@code{calc-over}) command (on a key marked Line-Feed if you
  576. have it, else on @kbd{C-j}) is like @code{calc-enter}
  577. except that the sign of the numeric prefix argument is interpreted
  578. oppositely.  Also, with no prefix argument the default argument is 2.
  579. Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}
  580. are both equivalent to @kbd{C-u - 2 @key{RET}}, producing
  581. @samp{10 20 30 20}.@refill
  582. X
  583. @kindex DEL
  584. @kindex C-d
  585. @pindex calc-pop
  586. @cindex Removing stack entries
  587. @cindex Deleting stack entries
  588. To remove the top element from the stack, press @key{DEL} (@code{calc-pop}).
  589. The @kbd{C-d} key is a synonym for @key{DEL}.
  590. (If the top element is an incomplete object with at least one element, the
  591. last element is removed from it.)  Given a positive numeric prefix argument,
  592. several elements are removed.  Given a negative argument, the specified
  593. element of the stack is deleted.  Given an argument of zero, the entire
  594. stack is emptied.
  595. For example, with @samp{10 20 30} on the stack,
  596. @key{DEL} creates @samp{10 20},
  597. @kbd{C-u 2 @key{DEL}} creates @samp{10},
  598. @kbd{C-u - 2 @key{DEL}} creates @samp{10 30}, and
  599. @kbd{C-u 0 @key{DEL}} creates an empty stack.@refill
  600. X
  601. @kindex M-DEL
  602. @pindex calc-pop-above
  603. The @kbd{M-DEL} (@code{calc-pop-above}) command is to @kbd{DEL} what
  604. @kbd{LFD} is to @kbd{RET}, i.e., it interprets the sign of the numeric
  605. prefix argument in the opposite way, and the default argument is 2.
  606. Thus @kbd{M-DEL} by itself removes the second-from-top stack element,
  607. leaving the first, third, fourth, and so on; @kbd{M-3 M-DEL} deletes
  608. the third stack element.
  609. X
  610. @kindex TAB
  611. @pindex calc-roll-down
  612. To exchange the top two elements of the stack, press @key{TAB}
  613. (@code{calc-roll-down}).  Given a positive numeric prefix argument, the
  614. specified number of elements at the top of the stack are rotated downward.
  615. Given a negative argument, the entire stack is rotated downward the specified
  616. number of times.  Given an argument of zero, the entire stack is reversed
  617. top-for-bottom.
  618. For example, with @samp{10 20 30 40 50} on the stack,
  619. @key{TAB} creates @samp{10 20 30 50 40},
  620. @kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},
  621. @kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and
  622. @kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.@refill
  623. X
  624. @kindex M-TAB
  625. @pindex calc-roll-up
  626. The command @key{M-TAB} (@code{calc-roll-up}) is analogous to @key{TAB}
  627. except that it rotates upward instead of downward.  Also, the default
  628. with no prefix argument is to rotate the top 3 elements.
  629. For example, with @samp{10 20 30 40 50} on the stack,
  630. @key{M-TAB} creates @samp{10 20 40 50 30},
  631. @kbd{C-u 4 @key{M-TAB}} creates @samp{10 30 40 50 20},
  632. @kbd{C-u - 2 @key{M-TAB}} creates @samp{30 40 50 10 20}, and
  633. @kbd{C-u 0 @key{M-TAB}} creates @samp{50 40 30 20 10}.@refill
  634. X
  635. A good way to view the operation of @key{TAB} and @key{M-TAB} is in
  636. terms of moving a particular element to a new position in the stack.
  637. With a positive argument @i{n}, @key{TAB} moves the top stack
  638. element down to level @i{n}, making room for it by pulling all the
  639. intervening stack elements toward the top.  @key{M-TAB} moves the
  640. element at level @i{n} up to the top.  (Compare with @key{LFD},
  641. which copies instead of moving the element in level @i{n}.)
  642. X
  643. With a negative argument @i{-n}, @key{TAB} rotates the stack
  644. to move the object in level @i{n} to the deepest place in the
  645. stack, and the object in level @i{n+1} to the top.  @key{M-TAB}
  646. rotates the deepest stack element to be in level @i{n}, also
  647. putting the top stack element in level @i{n+1}.
  648. X
  649. @xref{Selecting Subformulas}, for a way to apply these commands to
  650. any portion of a vector or formula on the stack.
  651. X
  652. @node Trail Commands, Keep Arguments, Stack Manipulation, Stack and Trail
  653. @section Trail Commands
  654. X
  655. @noindent
  656. @cindex Trail buffer
  657. The commands for manipulating the Calc Trail buffer are two-key sequences
  658. beginning with the @kbd{t} prefix.
  659. X
  660. @kindex t d
  661. @pindex calc-trail-display
  662. The @kbd{t d} (@code{calc-trail-display}) command turns display of the
  663. trail on and off.  Normally the trail display is toggled on if it was off,
  664. off if it was on.  With a numeric prefix of zero, this command always
  665. turns the trail off; with a prefix of one, it always turns the trail on.
  666. The other trail-manipulation commands described here automatically turn
  667. the trail on.  Note that when the trail is off values are still recorded
  668. there; they are simply not displayed.  To set Emacs to turn the trail
  669. off by default, turn it off with @kbd{t d}, then save the mode settings
  670. with @kbd{m m} (@code{calc-save-modes}).
  671. X
  672. @kindex t i
  673. @pindex calc-trail-in
  674. @kindex t o
  675. @pindex calc-trail-out
  676. The @kbd{t i} (@code{calc-trail-in}) and @kbd{t o}
  677. (@code{calc-trail-out}) commands switch the cursor into and out of the
  678. Calc Trail window.  In practice they are rarely used, since the commands
  679. shown below are a more convenient way to move around in the
  680. trail, and they work ``by remote control'' when the cursor is still
  681. in the Calculator window.@refill
  682. X
  683. @cindex Trail pointer
  684. There is a @dfn{trail pointer} which selects some entry of the trail at
  685. any given time.  The trail pointer looks like a @samp{>} symbol right
  686. before the selected number.  The following commands operate on the
  687. trail pointer in various ways.
  688. X
  689. @kindex t y
  690. @pindex calc-trail-yank
  691. @cindex Retrieving previous results
  692. The @kbd{t y} (@code{calc-trail-yank}) command reads the selected value in
  693. the trail and pushes it onto the Calculator stack.  It allows you to
  694. re-use any previously computed value without retyping.  With a numeric
  695. prefix argument @var{n}, it yanks the value @var{n} lines above the current
  696. trail pointer.
  697. X
  698. @kindex t <
  699. @pindex calc-trail-scroll-left
  700. @kindex t >
  701. @pindex calc-trail-scroll-right
  702. The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >}
  703. (@code{calc-trail-scroll-right}) commands horizontally scroll the trail
  704. window left or right by one half of its width.@refill
  705. X
  706. @kindex t n
  707. @pindex calc-trail-next
  708. @kindex t p
  709. @pindex calc-trail-previous
  710. @kindex t f
  711. @pindex calc-trail-forward
  712. @kindex t b
  713. @pindex calc-trail-backward
  714. The @kbd{t n} (@code{calc-trail-next}) and @kbd{t p}
  715. (@code{calc-trail-previous)} commands move the trail pointer down or up
  716. one line.  The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}
  717. (@code{calc-trail-backward}) commands move the trail pointer down or up
  718. one screenful at a time.  All of these commands accept numeric prefix
  719. arguments to move several lines or screenfuls at a time.@refill
  720. X
  721. @kindex t [
  722. @pindex calc-trail-first
  723. @kindex t ]
  724. @pindex calc-trail-last
  725. @kindex t h
  726. @pindex calc-trail-here
  727. The @kbd{t [} (@code{calc-trail-first}) and @kbd{t ]}
  728. (@code{calc-trail-last}) commands move the trail pointer to the first or
  729. last line of the trail.  The @kbd{t h} (@code{calc-trail-here}) command
  730. moves the trail pointer to the cursor position; unlike the other trail
  731. commands, @kbd{t h} works only when Calc Trail is the selected window.@refill
  732. X
  733. @kindex t s
  734. @pindex calc-trail-isearch-forward
  735. @kindex t r
  736. @pindex calc-trail-isearch-backward
  737. @ifinfo
  738. The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
  739. (@code{calc-trail-isearch-backward}) commands perform an incremental
  740. search forward and backward through the trail.  You can press @key{RET}
  741. to terminate the search; the trail pointer moves to the current line.
  742. If you cancel the search with @kbd{C-g}, the trail pointer does not
  743. move.@refill
  744. @end ifinfo
  745. @tex
  746. The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
  747. (@code{calc-trail-isearch-backward}) com\-mands perform an incremental
  748. search forward and backward through the trail.  You can press @key{RET}
  749. to terminate the search; the trail pointer moves to the current line.
  750. If you cancel the search with @kbd{C-g}, the trail pointer does not
  751. move.
  752. @end tex
  753. X
  754. @kindex t m
  755. @pindex calc-trail-marker
  756. The @kbd{t m} (@code{calc-trail-marker}) command allows you to enter a
  757. line of text of your own choosing into the trail.  The text is inserted
  758. after the line containing the trail pointer; this usually means it is
  759. added to the end of the trail.  Trail markers are useful mainly as the
  760. targets for later incremental searches in the trail.
  761. X
  762. @kindex t k
  763. @pindex calc-trail-kill
  764. The @kbd{t k} (@code{calc-trail-kill}) command removes the selected line
  765. from the trail.  The line is saved in the Emacs kill ring suitable for
  766. yanking into another buffer, but it is not easy to yank the text back
  767. into the trail buffer.  With a numeric prefix argument, this command
  768. kills the @var{n} lines below or above the selected one.
  769. X
  770. The @kbd{t .} (@code{calc-full-trail-vectors}) command is described
  771. elsewhere; @pxref{Vector and Matrix Formats}.
  772. X
  773. @node Keep Arguments, , Trail Commands, Stack and Trail
  774. @section Keep Arguments
  775. X
  776. @noindent
  777. @kindex K
  778. @pindex calc-keep-args
  779. The @kbd{K} (@code{calc-keep-args}) command acts like a prefix for
  780. the following command that prevents that command from removing its
  781. arguments from the stack.  For example, after @kbd{2 @key{RET} 3 +},
  782. the stack contains the sole number 5, but after @kbd{2 @key{RET} 3 K +},
  783. the stack contains the arguments and the result: @samp{2 3 5}.
  784. X
  785. This works for all commands that take arguments off the stack.  As
  786. another example, @kbd{K a s} simplifies a formula, pushing the
  787. simplified version of the formula onto the stack after the original
  788. formula (rather than replacing the original formula).
  789. X
  790. Note that you could get the same effect by typing @kbd{RET a s},
  791. copying the formula and then simplifying the copy.  One difference
  792. is that for a very large formula the time taken to format the
  793. intermediate copy in @kbd{RET a s} could be noticeable; @kbd{K a s}
  794. would avoid this extra work.
  795. X
  796. Even stack manipulation commands are affected.  @key{TAB} works by
  797. popping two values and pushing them back in the opposite order,
  798. so @kbd{2 @key{RET} 3 K @key{TAB}} produces @samp{2 3 3 2}.
  799. X
  800. A few Calc commands provide other ways of doing the same thing.
  801. For example, @kbd{' sin($)} replaces the number on the stack with
  802. its sine using algebraic entry; to push the sine and keep the
  803. original argument you could use either @kbd{' sin($1)} or
  804. @kbd{K ' sin($)}.  @xref{Algebraic Entry}.  Also, the @kbd{s s}
  805. command is effectively the same as @kbd{K s t}.  @xref{Storing Variables}.
  806. X
  807. Keyboard macros may interact surprisingly with the @kbd{K} prefix.
  808. If you have defined a keyboard macro to be, say, @samp{Q +} to add
  809. one number to the square root of another, then typing @kbd{K X} will
  810. execute @kbd{K Q +}, probably not what you expected.  The @kbd{K}
  811. prefix will apply to just the first command in the macro rather than
  812. the whole macro.
  813. X
  814. If you execute a command and then decide you really wanted to keep
  815. the argument, you can press @kbd{M-@key{RET}} (@code{calc-last-args}).
  816. This command pushes the last arguments that were popped by any command
  817. onto the stack.  Note that the order of things on the stack will be
  818. different than with @kbd{K}:  @kbd{2 @key{RET} 3 + M-@key{RET}} leaves
  819. @samp{5 2 3} on the stack instead of @samp{2 3 5}.  @xref{Undo}.
  820. X
  821. @node Mode Settings, Arithmetic, Stack and Trail, Top
  822. @chapter Mode Settings
  823. X
  824. @noindent
  825. This chapter describes commands that set modes in the Calculator.
  826. They do not affect the contents of the stack, although they may change
  827. the @emph{appearance} or @emph{interpretation} of the stack's contents.
  828. X
  829. @menu
  830. * General Mode Commands::
  831. * Precision::
  832. * Inverse and Hyperbolic::
  833. * Calculation Modes::
  834. * Simplification Modes::
  835. * Declarations::
  836. * Display Modes::
  837. * Language Modes::
  838. * Calc Mode Line::
  839. @end menu
  840. X
  841. @node General Mode Commands, Precision, Mode Settings, Mode Settings
  842. @section General Mode Commands
  843. X
  844. @noindent
  845. @kindex m m
  846. @pindex calc-save-modes
  847. @cindex Continuous memory
  848. @cindex Saving mode settings
  849. @cindex Permanent mode settings
  850. @cindex @file{.emacs} file, mode settings
  851. You can save all of the current mode settings in your @file{.emacs} file
  852. with the @kbd{m m} (@code{calc-save-modes}) command.  This will cause
  853. Emacs to reestablish these modes each time it starts up.  The modes saved
  854. in the file include everything controlled by the @kbd{m} and @kbd{d}
  855. prefix keys, the current precision and binary word size, whether or not
  856. the trail is displayed, and the current height of the Calc window.
  857. The current interface (used when you type @kbd{M-# M-#}) is also saved.
  858. If there were already saved mode settings in the file, they are replaced.
  859. Otherwise, the new mode information is appended to the end of the file.
  860. X
  861. @kindex m R
  862. @pindex calc-mode-record-mode
  863. The @kbd{m R} (@code{calc-mode-record-mode}) command tells Calc to
  864. record the new mode settings (as if by pressing @kbd{m m}) every
  865. time a mode setting changes.  If Embedded Mode is enabled, other
  866. options are available; @pxref{Mode Settings in Embedded Mode}.
  867. X
  868. @kindex m F
  869. @pindex calc-settings-file-name
  870. The @kbd{m F} (@code{calc-settings-file-name}) command allows you to
  871. choose a different place than your @file{.emacs} file for @kbd{m m},
  872. @kbd{Z P}, and similar commands to save permanent information.
  873. You are prompted for a file name.  All Calc modes are then reset to
  874. their default values, settings from the file you named are loaded
  875. if this file exists, and this file becomes the one that Calc will
  876. use in the future for commands like @kbd{m m}.  The default settings
  877. file name is @file{~/.emacs}.  You can see the current file name by
  878. giving a blank response to the @kbd{m F} prompt.  See also the
  879. discussion of the @code{calc-settings-file} variable; @pxref{Installation}.
  880. X
  881. If the file name you give contains the string @samp{.emacs} anywhere
  882. inside it, @kbd{m F} will not automatically load the new file.  This
  883. is because you are presumably switching to your @file{~/.emacs} file,
  884. which may contain other things you don't want to reread.  You can give
  885. a numeric prefix argument of 1 to @kbd{m F} to force it to read the
  886. file no matter what its name.  Conversely, an argument of @i{-1} tells
  887. @kbd{m F} @emph{not} to read the new file.  An argument of 2 or @i{-2}
  888. tells @kbd{m F} not to reset the modes to their defaults beforehand,
  889. which is useful if you intend your new file to have a variant of the
  890. modes present in the file you were using before.
  891. X
  892. @kindex m x
  893. @pindex calc-always-load-extensions
  894. The @kbd{m x} (@code{calc-always-load-extensions}) command enables a mode
  895. in which the first use of Calc loads the entire program, including all
  896. extensions modules.  Otherwise, the extensions modules will not be loaded
  897. until the various advanced Calc features are used.  Since this mode only
  898. has effect when Calc is first loaded, @kbd{m x} is usually followed by
  899. @kbd{m m} to make the mode-setting permanent.
  900. X
  901. @kindex m X
  902. @kindex M-# L
  903. @pindex calc-load-everything
  904. The @kbd{m X} or @kbd{M-# L} (@code{calc-load-everything}) command loads
  905. all parts of Calc that have not yet been loaded.  This is the command
  906. that Calc executes upon startup if @kbd{m x} mode has been enabled.
  907. X
  908. @kindex m S
  909. @pindex calc-shift-prefix
  910. The @kbd{m S} (@code{calc-shift-prefix}) command enables a mode in which
  911. all of Calc's letter prefix keys may be typed shifted as well as unshifted.
  912. If you are typing, say, @kbd{a S} (@code{calc-solve-for}) quite often
  913. you might find it easier to turn this mode on so that you can type
  914. @kbd{A S} instead.  When this mode is enabled, the commands that used to
  915. be on those single shifted letters (e.g., @kbd{A} (@code{calc-abs})) can
  916. now be invoked by pressing the shifted letter twice: @kbd{A A}.  Note
  917. that the @kbd{v} prefix key always works both shifted and unshifted, and
  918. the @kbd{z} and @kbd{Z} prefix keys are always distinct.  Also, the @kbd{h}
  919. prefix is not affected by this mode.  Press @kbd{m S} again to disable
  920. shifted-prefix mode.
  921. X
  922. @node Precision, Inverse and Hyperbolic, General Mode Commands, Mode Settings
  923. @section Precision
  924. X
  925. @noindent
  926. @kindex p
  927. @pindex calc-precision
  928. @cindex Precision of calculations
  929. The @kbd{p} (@code{calc-precision}) command controls the precision to
  930. which floating-point calculations are carried.  The precision must be
  931. at least 3 digits and may be arbitrarily high, within the limits of
  932. memory and time.  This affects only floats:  Integer and rational
  933. calculations are always carried out with as many digits as necessary.
  934. X
  935. The @kbd{p} key prompts for the current precision.  If you wish you
  936. can instead give the precision as a numeric prefix argument.
  937. X
  938. Many internal calculations are carried to one or two digits higher
  939. precision than normal.  Results are rounded down afterward to the
  940. current precision.  Unless a special display mode has been selected,
  941. floats are always displayed with their full stored precision, i.e.,
  942. what you see is what you get.  Reducing the current precision does not
  943. round values already on the stack, but those values will be rounded
  944. down before being used in any calculation.  The @kbd{c 0} through
  945. @kbd{c 9} commands (@pxref{Conversions}) can be used to round an
  946. existing value to a new precision.@refill
  947. X
  948. @cindex Accuracy of calculations
  949. It is important to distinguish the concepts of @dfn{precision} and
  950. @dfn{accuracy}.  In the normal usage of these words, the number
  951. 123.4567 has a precision of 7 digits but an accuracy of 4 digits;
  952. the precision is the total number of digits not counting leading
  953. or trailing zeros (regardless of the position of the decimal point).
  954. The accuracy is simply the number of digits after the decimal point
  955. (again not counting trailing zeros).  In Calc you control the precision,
  956. not the accuracy of computations.  If you were to set the accuracy
  957. instead, then calculations like @samp{exp(100)} would generate many
  958. more digits than you would typically need, while @samp{exp(-100)} would
  959. probably round to zero!  In Calc, both these computations give you
  960. exactly 12 (or the requested number of) significant digits.
  961. X
  962. The only Calc features that deal with accuracy instead of precision
  963. are fixed-point display mode for floats (@kbd{d f}; @pxref{Float Formats}),
  964. and the rounding functions like @code{floor} and @code{round}
  965. (@pxref{Integer Truncation}).  Also, @kbd{c 0} through @kbd{c 9}
  966. deal with both precision and accuracy depending on the magnitudes
  967. of the numbers involved.
  968. X
  969. If you need to work with a particular fixed accuracy (say, dollars and
  970. cents with two digits after the decimal point), one solution is to work
  971. with integers and an ``implied'' decimal point.  For example, $8.99
  972. divided by 6 would be entered @kbd{899 RET 6 /}, yielding 149.833
  973. (actually $1.49833 with our implied decimal point); pressing @kbd{R}
  974. would round this to 150 cents, i.e., $1.50.
  975. X
  976. @node Inverse and Hyperbolic, Calculation Modes, Precision, Mode Settings
  977. @section Inverse and Hyperbolic Flags
  978. X
  979. @noindent
  980. @kindex I
  981. @pindex calc-inverse
  982. There is no single-key equivalent to the @code{calc-arcsin} function.
  983. Instead, you must first press @kbd{I} (@code{calc-inverse}) to set
  984. the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).
  985. The @kbd{I} key actually toggles the Inverse Flag.  When this flag
  986. is set, the word @samp{Inv} appears in the mode line.@refill
  987. X
  988. @kindex H
  989. @pindex calc-hyperbolic
  990. Likewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the
  991. Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}.
  992. If both of these flags are set at once, the effect will be
  993. @code{calc-arcsinh}.  (The Hyperbolic flag is also used by some
  994. non-trigonometric commands; for example @kbd{H L} computes a base-10,
  995. instead of base-@i{e}, logarithm.)@refill
  996. X
  997. Command names like @code{calc-arcsin} are provided for completeness, and
  998. may be executed with @kbd{x} or @kbd{M-x}.  Their effect is simply to
  999. toggle the Inverse and/or Hyperbolic flags and then execute the
  1000. corresponding base command (@code{calc-sin} in this case).
  1001. X
  1002. The Inverse and Hyperbolic flags apply only to the next Calculator
  1003. command, after which they are automatically cleared.  (They are also
  1004. cleared if the next keystroke is not a Calc command.)  Digits you
  1005. type after @kbd{I} or @kbd{H} (or @kbd{K}) are treated as prefix
  1006. arguments for the next command, not as numeric entries.  The same
  1007. is true of @kbd{C-u}, but not of the minus sign (@kbd{K -} means to
  1008. subtract and keep arguments).
  1009. X
  1010. The third Calc prefix flag, @kbd{K} (keep-arguments), is discussed
  1011. elsewhere.  @xref{Keep Arguments}.
  1012. X
  1013. @node Calculation Modes, Simplification Modes, Inverse and Hyperbolic, Mode Settings
  1014. @section Calculation Modes
  1015. X
  1016. @noindent
  1017. The commands in this section are two-key sequences beginning with
  1018. the @kbd{m} prefix.  (That's the letter @kbd{m}, not the @key{META} key.)
  1019. X
  1020. The @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
  1021. (@pxref{Algebraic Entry}).
  1022. X
  1023. @menu
  1024. * Angular Modes::
  1025. * Polar Mode::
  1026. * Fraction Mode::
  1027. * Infinite Mode::
  1028. * Symbolic Mode::
  1029. * Matrix Mode::
  1030. * Automatic Recomputation::
  1031. * Working Message::
  1032. @end menu
  1033. X
  1034. @node Angular Modes, Polar Mode, Calculation Modes, Calculation Modes
  1035. @subsection Angular Modes
  1036. X
  1037. @noindent
  1038. @cindex Angular mode
  1039. The Calculator supports three notations for angles: radians, degrees,
  1040. and degrees-minutes-seconds.  When a number is presented to a function
  1041. like @code{sin} that requires an angle, the current angular mode is
  1042. used to interpret the number as either radians or degrees.  If an HMS
  1043. form is presented to @code{sin}, it is always interpreted as
  1044. degrees-minutes-seconds.
  1045. X
  1046. Functions that compute angles produce a number in radians, a number in
  1047. degrees, or an HMS form depending on the current angular mode.  If the
  1048. result is a complex number and the current mode is HMS, the number is
  1049. instead expressed in degrees.  (Complex-number calculations would
  1050. normally be done in radians mode, though.  Complex numbers are converted
  1051. to degrees by calculating the complex result in radians and then
  1052. multiplying by 180 over @c{$\pi$}
  1053. @cite{pi}.)
  1054. X
  1055. @kindex m r
  1056. @pindex calc-radians-mode
  1057. @kindex m d
  1058. @pindex calc-degrees-mode
  1059. @kindex m h
  1060. @pindex calc-hms-mode
  1061. The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),
  1062. and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.
  1063. The current angular mode is displayed on the Emacs mode line.
  1064. The default angular mode is degrees.@refill
  1065. X
  1066. @node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
  1067. @subsection Polar Mode
  1068. X
  1069. @noindent
  1070. @cindex Polar mode
  1071. The Calculator normally ``prefers'' rectangular complex numbers in the
  1072. sense that rectangular form is used when the proper form can not be
  1073. decided from the input.  This might happen by multiplying a rectangular
  1074. number by a polar one, by taking the square root of a negative real
  1075. number, or by entering @kbd{( 2 @key{SPC} 3 )}.
  1076. X
  1077. @kindex m p
  1078. @pindex calc-polar-mode
  1079. The @kbd{m p} (@code{calc-polar-mode}) command toggles complex-number
  1080. preference between rectangular and polar forms.  In polar mode, all
  1081. of the above example situations would produce polar complex numbers.
  1082. X
  1083. @node Fraction Mode, Infinite Mode, Polar Mode, Calculation Modes
  1084. @subsection Fraction Mode
  1085. X
  1086. @noindent
  1087. @cindex Fraction mode
  1088. @cindex Division of integers
  1089. Division of two integers normally yields a floating-point number if the
  1090. result cannot be expressed as an integer.  In some cases you would
  1091. rather get an exact fractional answer.  One way to accomplish this is
  1092. to multiply fractions instead:  @kbd{6 @key{RET} 1:4 *} produces @cite{3:2}
  1093. even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}.
  1094. X
  1095. @kindex m f
  1096. @pindex calc-frac-mode
  1097. To set the Calculator to produce fractional results for normal integer
  1098. divisions, use the @kbd{m f} (@code{calc-frac-mode}) command.
  1099. For example, @cite{8/4} produces @cite{2} in either mode,
  1100. but @cite{6/4} produces @cite{3:2} in Fraction Mode, but @cite{1.5} in
  1101. Float Mode.@refill
  1102. X
  1103. At any time you can use @kbd{c f} (@code{calc-float}) to convert a
  1104. fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a
  1105. float to a fraction.  @xref{Conversions}.
  1106. X
  1107. @node Infinite Mode, Symbolic Mode, Fraction Mode, Calculation Modes
  1108. @subsection Infinite Mode
  1109. X
  1110. @noindent
  1111. @cindex Infinite mode
  1112. The Calculator normally treats results like @cite{1 / 0} as errors;
  1113. formulas like this are left in unsimplified form.  But Calc can be
  1114. put into a mode where such calculations instead produce ``infinite''
  1115. results.
  1116. X
  1117. @kindex m i
  1118. @pindex calc-infinite-mode
  1119. The @kbd{m i} (@code{calc-infinite-mode}) command turns this mode
  1120. on and off.  When the mode is off, infinities do not arise except
  1121. in calculations that already had infinities as inputs.  (One exception
  1122. is that infinite open intervals like @samp{[0 .. inf)} can be
  1123. generated; however, intervals closed at infinity (@samp{[0 .. inf]})
  1124. will not be generated when infinite mode is off.)
  1125. X
  1126. With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
  1127. an undirected infinity.  @xref{Infinities}, for a discussion of the
  1128. difference between @code{inf} and @code{uinf}.  Also, @cite{0 / 0}
  1129. evaluates to @code{nan}, the ``indeterminate'' symbol.  Various other
  1130. functions can also return infinities in this mode; for example,
  1131. @samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}.  Once again,
  1132. note that @samp{exp(inf) = inf} regardless of infinite mode because
  1133. this calculation has infinity as an input.
  1134. X
  1135. @cindex Positive infinite mode
  1136. The @kbd{m i} command with a numeric prefix argument of zero,
  1137. i.e., @kbd{C-u 0 m i}, turns on a ``positive infinite mode'' in
  1138. which zero is treated as positive instead of being directionless.  
  1139. Thus, @samp{1 / 0 = inf} and @samp{-1 / 0 = -inf} in this mode.
  1140. Note that zero never actually has a sign in Calc; there are no
  1141. separate representations for @i{+0} and @i{-0}.  Positive
  1142. infinite mode merely changes the interpretation given to the
  1143. single symbol, @samp{0}.  One consequence of this is that, while
  1144. you might expect @samp{1 / -0 = -inf}, actually @samp{1 / -0}
  1145. is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}.
  1146. X
  1147. @node Symbolic Mode, Matrix Mode, Infinite Mode, Calculation Modes
  1148. @subsection Symbolic Mode
  1149. X
  1150. @noindent
  1151. @cindex Symbolic mode
  1152. @cindex Inexact results
  1153. Calculations are normally performed numerically wherever possible.
  1154. For example, the @code{calc-sqrt} command, or @code{sqrt} function in an
  1155. algebraic expression, produces a numeric answer if the argument is a
  1156. number or a symbolic expression if the argument is an expression:
  1157. @kbd{2 Q} pushes 1.4142 but @kbd{@key{'} x+1 @key{RET} Q} pushes @samp{sqrt(x+1)}.
  1158. X
  1159. @kindex m s
  1160. @pindex calc-symbolic-mode
  1161. In @dfn{symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode})
  1162. command, functions which would produce inexact, irrational results are
  1163. left in symbolic form.  Thus @kbd{16 Q} pushes 4, but @kbd{2 Q} pushes
  1164. @samp{sqrt(2)}.
  1165. X
  1166. @kindex N
  1167. @pindex calc-eval-num
  1168. The shift-@kbd{N} (@code{calc-eval-num}) command evaluates numerically
  1169. the expression at the top of the stack, by temporarily disabling
  1170. @code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).
  1171. Given a numeric prefix argument, it also
  1172. sets the floating-point precision to the specified value for the duration
  1173. of the command.@refill
  1174. X
  1175. To evaluate a formula numerically without expanding the variables it
  1176. contains, you can use the key sequence @kbd{m s a v m s} (this uses
  1177. @code{calc-alg-evaluate}, which resimplifies but doesn't evaluate
  1178. variables.)
  1179. X
  1180. @node Matrix Mode, Automatic Recomputation, Symbolic Mode, Calculation Modes
  1181. @subsection Matrix and Scalar Modes
  1182. X
  1183. @noindent
  1184. @cindex Matrix mode
  1185. @cindex Scalar mode
  1186. Calc sometimes makes assumptions during algebraic manipulation that
  1187. are awkward or incorrect when vectors and matrices are involved.
  1188. Calc has two modes, @dfn{matrix mode} and @dfn{scalar mode}, which
  1189. modify its behavior around vectors in useful ways.
  1190. X
  1191. @kindex m v
  1192. @pindex calc-matrix-mode
  1193. Press @kbd{m v} (@code{calc-matrix-mode}) once to enter matrix mode.
  1194. In this mode, all objects are assumed to be matrices unless provably
  1195. otherwise.  One major effect is that Calc will no longer consider
  1196. multiplication to be commutative.  (Recall that in matrix arithmetic,
  1197. @samp{A*B} is not the same as @samp{B*A}.)  This assumption affects
  1198. rewrite rules and algebraic simplification.  Another effect of this
  1199. mode is that calculations that would normally produce constants like
  1200. 0 and 1 (e.g., @cite{a - a} and @cite{a / a}, respectively) will now
  1201. produce function calls that represent ``generic'' zero or identity
  1202. matrices: @samp{idn(0)}, @samp{idn(1)}.  The @code{idn} function
  1203. @samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n}
  1204. identity matrix; if @var{n} is omitted, it doesn't know what
  1205. dimension to use and so the @code{idn} call remains in symbolic
  1206. form.  However, if this generic identity matrix is later combined
  1207. with a matrix whose size is known, it will be converted into
  1208. a true identity matrix of the appropriate size.  On the other hand,
  1209. if it is combined with a scalar (as in @samp{idn(1) + 2}), Calc
  1210. will assume it really was a scalar after all and produce, e.g., 3.
  1211. X
  1212. Press @kbd{m v} a second time to get scalar mode.  Here, objects are
  1213. assumed @emph{not} to be vectors or matrices unless provably so.
  1214. For example, normally adding a variable to a vector, as in
  1215. @samp{[x, y, z] + a}, will leave the sum in symbolic form because
  1216. as far as Calc knows, @samp{a} could represent either a number or
  1217. another 3-vector.  In scalar mode, @samp{a} is assumed to be a
  1218. non-vector, and the addition is evaluated to @samp{[x+a, y+a, z+a]}.
  1219. X
  1220. Press @kbd{m v} a third time to return to the normal mode of operation.
  1221. X
  1222. If you press @kbd{m v} with a numeric prefix argument @var{n}, you
  1223. get a special ``dimensioned matrix mode'' in which matrices of
  1224. unknown size are assumed to be @var{n}x@var{n} square matrices.
  1225. Then, the function call @samp{idn(1)} will expand into an actual
  1226. matrix rather than representing a ``generic'' matrix.
  1227. X
  1228. @cindex Declaring scalar variables
  1229. Of course these modes are approximations to the true state of
  1230. affairs, which is probably that some quantities will be matrices
  1231. and others will be scalars.  One solution is to ``declare''
  1232. certain variables or functions to be scalar-valued.
  1233. @xref{Declarations}, to see how to make declarations in Calc.
  1234. X
  1235. There is nothing stopping you from declaring a variable to be
  1236. scalar and then storing a matrix in it; however, if you do, the
  1237. results you get from Calc may not be valid.  Suppose you let Calc
  1238. get the result @samp{[x+a, y+a, z+a]} shown above, and then stored
  1239. @samp{[1, 2, 3]} in @samp{a}.  The result would not be the same as
  1240. for @samp{[x, y, z] + [1, 2, 3]}, but that's because you have broken
  1241. your earlier promise to Calc that @samp{a} would be scalar.
  1242. X
  1243. Another way to mix scalars and matrices is to use selections
  1244. SHAR_EOF
  1245. true || echo 'restore of calc.texinfo failed'
  1246. fi
  1247. echo 'End of  part 38'
  1248. echo 'File calc.texinfo is continued in part 39'
  1249. echo 39 > _shar_seq_.tmp
  1250. exit 0
  1251. exit 0 # Just in case...
  1252. -- 
  1253. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1254. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1255. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1256. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1257.