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

  1. Newsgroups: comp.sources.misc
  2. From: daveg@synaptics.com (David Gillespie)
  3. Subject:  v24i088:  gnucalc - GNU Emacs Calculator, v2.00, Part40/56
  4. Message-ID: <1991Nov1.183620.20727@sparky.imd.sterling.com>
  5. X-Md4-Signature: 6ad8483a57dad31381f25e9c86e0cfb3
  6. Date: Fri, 1 Nov 1991 18:36:20 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: daveg@synaptics.com (David Gillespie)
  10. Posting-number: Volume 24, Issue 88
  11. Archive-name: gnucalc/part40
  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" != 40; 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. The @kbd{d b} (@code{calc-line-breaking}) command turns this line-breaking
  38. feature on and off.  (It works independently of the current language.)
  39. If you give a numeric prefix argument of five or greater to the @kbd{d b}
  40. command, that argument will specify the line width used when breaking
  41. long lines.
  42. X
  43. @kindex d B
  44. @pindex calc-big-language
  45. The @kbd{d B} (@code{calc-big-language}) command selects a language
  46. which uses textual approximations to various mathematical notations,
  47. such as powers, quotients, and square roots:
  48. X
  49. @example
  50. X  ____________
  51. X | a + 1    2
  52. X | ----- + c
  53. \|   b
  54. @end example
  55. X
  56. @noindent
  57. in place of @samp{sqrt((a+1)/b + c^2)}.
  58. X
  59. Subscripts like @samp{a_i} are displayed as actual subscripts in ``big''
  60. mode.  Double subscripts, @samp{a_i_j} (@samp{subscr(subscr(a, i), j)})
  61. are displayed as @samp{a} with subscripts separated by commas:
  62. @samp{i, j}.  They must still be entered in the usual underscore
  63. notation.
  64. X
  65. One slight ambiguity of Big notation is that
  66. X
  67. @example
  68. X  3
  69. - -
  70. X  4
  71. @end example
  72. X
  73. @noindent
  74. can represent either the negative rational number @cite{-3:4}, or the
  75. actual expression @samp{-(3/4)}; but the latter formula would normally
  76. never be displayed because it would immediately be evaluated to
  77. @cite{-3:4} or @cite{-0.75}, so this ambiguity is not a problem in
  78. typical use.
  79. X
  80. Non-decimal numbers are displayed with subscripts.  Thus there is no
  81. way to tell the difference between @samp{16#C2} and @samp{C2_16},
  82. though generally you will know which interpretation is correct.
  83. Logarithms @samp{log(x,b)} and @samp{log10(x)} also use subscripts
  84. in Big mode.
  85. X
  86. In Big mode, stack entries often take up several lines.  To aid
  87. readability, stack entries are separated by a blank line in this mode.
  88. You may find it useful to expand the Calc window's height using
  89. @kbd{C-x ^} (@code{enlarge-window}) or to make the Calc window the only
  90. one on the screen with @kbd{C-x 1} (@code{delete-other-windows}).
  91. X
  92. Long lines are currently not rearranged to fit the window width in
  93. Big mode, so you may need to use the @kbd{<} and @kbd{>} keys
  94. to scroll across a wide formula.  For really big formulas, you may
  95. even need to use @kbd{@{} and @kbd{@}} to scroll up and down.
  96. X
  97. @kindex d U
  98. @pindex calc-unformatted-language
  99. The @kbd{d U} (@code{calc-unformatted-language}) command altogether disables
  100. the use of operator notation in formulas.  In this mode, the formula
  101. shown above would be displayed:
  102. X
  103. @example
  104. sqrt(add(div(add(a, 1), b), pow(c, 2)))
  105. @end example
  106. X
  107. These four modes differ only in display format, not in the format
  108. expected for algebraic entry.  The standard Calc operators work in
  109. all four modes, and unformatted notation works in any language mode
  110. (except that Mathematica mode expects square brackets instead of
  111. parentheses).
  112. X
  113. @node C FORTRAN Pascal, TeX Language Mode, Normal Language Modes, Language Modes
  114. @subsection C, FORTRAN, and Pascal Modes
  115. X
  116. @noindent
  117. @kindex d C
  118. @pindex calc-c-language
  119. @cindex C language
  120. The @kbd{d C} (@code{calc-c-language}) command selects the conventions
  121. of the C language for display and entry of formulas.  This differs from
  122. the normal language mode in a variety of (mostly minor) ways.  In
  123. particular, C language operators and operator precedences are used in
  124. place of Calc's usual ones.  For example, @samp{a^b} means @samp{xor(a,b)}
  125. in C mode; a value raised to a power is written as a function call,
  126. @samp{pow(a,b)}.
  127. X
  128. In C mode, vectors and matrices use curly braces instead of brackets.
  129. Octal and hexadecimal values are written with leading @samp{0} or @samp{0x}
  130. rather than using the @samp{#} symbol.  Array subscripting is
  131. translated into @code{subscr} calls, so that @samp{a[i]} in C
  132. mode is the same as @samp{a_i} in normal mode.  Assignments
  133. turn into the @code{assign} function, which Calc normally displays
  134. using the @samp{:=} symbol even though the @code{assign} function is
  135. not given any actual meaning by the rest of Calc (except for rewrite
  136. rules and Embedded Mode).
  137. X
  138. The variables @code{var-pi} and @code{var-e} would be displayed @samp{pi}
  139. and @samp{e} in normal mode, but in C mode they are displayed as
  140. @samp{M_PI} and @samp{M_E}, corresponding to the names of constants
  141. typically provided in the @file{<math.h>} header.  Functions whose
  142. names are different in C are translated automatically for entry and
  143. display purposes.  For example, entering @samp{asin(x)} will push the
  144. formula @samp{arcsin(x)} onto the stack; this formula will be displayed
  145. as @samp{asin(x)} as long as C mode is in effect.
  146. X
  147. @kindex d P
  148. @pindex calc-pascal-language
  149. @cindex Pascal language
  150. The @kbd{d P} (@code{calc-pascal-language}) command selects Pascal
  151. conventions.  Like C mode, Pascal mode interprets array brackets and uses
  152. a different table of operators.  Hexadecimal numbers are entered and
  153. displayed with a preceding dollar sign.  (Thus the regular meaning of
  154. @kbd{$2} during algebraic entry does not work in Pascal mode, though
  155. @kbd{$} (and @kbd{$$}, etc.) not followed by digits works the same as
  156. always.)  No special provisions are made for other non-decimal numbers,
  157. vectors, and so on, since there is no universally accepted standard way
  158. of handling these in Pascal.
  159. X
  160. @kindex d F
  161. @pindex calc-fortran-language
  162. @cindex FORTRAN language
  163. The @kbd{d F} (@code{calc-fortran-language}) command selects FORTRAN
  164. conventions.  Various function names are transformed into FORTRAN
  165. equivalents.  Vectors are written as @samp{/1, 2, 3/}, and may be
  166. entered this way or using square brackets.  Since FORTRAN uses round
  167. parentheses for both function calls and array subscripts, Calc displays
  168. both in the same way; @samp{a(i)} is interpreted as a function call
  169. upon reading, and subscripts must be entered as @samp{subscr(a, i)}.
  170. However, you can almost always enter @samp{a(i)} and it will work
  171. just as well as a subscript, as long as the array name @samp{a} doesn't
  172. accidentally correspond to any built-in one-argument Calc function.
  173. (Another time that the distinction could matter is when you are planning
  174. to switch the expression to another language like Pascal after entering
  175. it in FORTRAN.)
  176. X
  177. Underscores are allowed in variable names in all of these language
  178. modes.  The underscore here is equivalent to the @samp{#} in normal
  179. mode, or to hyphens in the underlying Emacs Lisp variable names.
  180. X
  181. FORTRAN and Pascal modes normally do not adjust the case of letters in
  182. formulas.  Most built-in Calc names use lower-case letters.  If you use a
  183. positive numeric prefix argument with @kbd{d P} or @kbd{d F}, these
  184. modes will use upper-case letters exclusively for display, and will
  185. convert to lower-case on input.  With a negative prefix, these modes
  186. convert to lower-case for display and input.
  187. X
  188. @node TeX Language Mode, Eqn Language Mode, C FORTRAN Pascal, Language Modes
  189. @subsection @TeX{} Language Mode
  190. X
  191. @noindent
  192. @kindex d T
  193. @pindex calc-tex-language
  194. @cindex TeX language
  195. The @kbd{d T} (@code{calc-tex-language}) command selects the conventions
  196. of ``math mode'' in the @TeX{} typesetting language, by Donald Knuth.
  197. Formulas are entered
  198. and displayed in @TeX{} notation, as in @samp{\sin\left( a \over b \right)}.
  199. Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
  200. should be omitted when interfacing with Calc.  To Calc, the @samp{$} sign
  201. has the same meaning it always does in algebraic formulas (a reference to
  202. an existing entry on the stack).@refill
  203. X
  204. Complex numbers are displayed as in @samp{3 + 4i}.  Fractions and
  205. quotients are written using @code{\over};
  206. binomial coefficients are written with @code{\choose}.
  207. Interval forms are written with @code{\ldots}, and
  208. error forms are written with @code{\pm}.
  209. Absolute values are written as in @samp{|x + 1|}, and the floor and
  210. ceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc.
  211. The words @code{\left} and @code{\right} are ignored when reading
  212. formulas in @TeX{} mode.  Both @code{inf} and @code{uinf} are written
  213. as @code{\infty}; when read, @code{\infty} always translates to
  214. @code{inf}.@refill
  215. X
  216. Function calls are written the usual way, with the function name followed
  217. by the arguments in parentheses.  However, functions for which @TeX{} has
  218. special names (like @code{\sin}) will use curly braces instead of
  219. parentheses for very simple arguments.  During input, curly braces and
  220. parentheses work equally well for grouping, but when the document is
  221. formatted the curly braces will be invisible.  Thus the printed result is
  222. @c{$\sin{2 x}$}
  223. @cite{sin 2x} but @c{$\sin(2 + x)$}
  224. @cite{sin(2 + x)}.
  225. X
  226. Function and variable names not treated specially by @TeX{} are simply
  227. written out as-is, which will cause them to come out in italic letters
  228. in the printed document.  If you invoke @kbd{d T} with a positive numeric
  229. prefix argument, names of more than one character will instead be written
  230. @samp{\hbox@{@var{name}@}}.  The @samp{\hbox@{ @}} notation is ignored
  231. during reading.  If you use a negative prefix argument, such function
  232. names are written @samp{\@var{name}}, and function names that begin
  233. with @code{\} during reading have the @code{\} removed.  (Note that
  234. in this mode, long variable names are still written with @code{\hbox}.
  235. However, you can always make an actual variable name like @code{\bar}
  236. in any @TeX{} mode.)
  237. X
  238. During reading, text of the form @samp{\matrix@{ ...@: @}} is replaced
  239. by @samp{[ ...@: ]}.  The same also applies to @code{\pmatrix} and
  240. @code{\bmatrix}.  The symbol @samp{&} is interpreted as a comma,
  241. and the symbols @samp{\cr} and @samp{\\} are interpreted as semicolons.
  242. During output, matrices are displayed in @samp{\matrix@{ a & b \\ c & d@}}
  243. format; you may need to edit this afterwards to change @code{\matrix}
  244. to @code{\pmatrix} or @code{\\} to @code{\cr}.
  245. X
  246. Accents like @code{\tilde} and @code{\bar} translate into function
  247. calls internally (@samp{tilde(x)}, @samp{bar(x)}).  The @code{\underline}
  248. sequence is treated as an accent.  The @code{\vec} accent corresponds
  249. to the function name @code{Vec}, because @code{vec} is the name of
  250. a built-in Calc function.  The following table shows the accents
  251. in Calc, @TeX{}, and @dfn{eqn} (described in the next section):
  252. X
  253. @tindex acute
  254. @tindex bar
  255. @tindex breve
  256. @tindex check
  257. @tindex dot
  258. @tindex dotdot
  259. @tindex dyad
  260. @tindex grave
  261. @tindex hat
  262. @tindex Prime
  263. @tindex tilde
  264. @tindex under
  265. @tindex Vec
  266. @example
  267. Calc      TeX           eqn
  268. ----      ---           ---
  269. acute     \acute
  270. bar       \bar          bar
  271. breve     \breve        
  272. check     \check
  273. dot       \dot          dot
  274. dotdot    \ddot         dotdot
  275. dyad                    dyad
  276. grave     \grave
  277. hat       \hat          hat
  278. Prime                   prime
  279. tilde     \tilde        tilde
  280. under     \underline    under
  281. Vec       \vec          vec
  282. @end example
  283. X
  284. The @samp{=>} (evaluates-to) operator appears as a @code{\to} symbol:
  285. @samp{@{@var{a} \to @var{b}@}}.  @TeX{} defines @code{\to} as an
  286. alias for @code{\rightarrow}.  However, if the @samp{=>} is the
  287. top-level expression being formatted, a slightly different notation
  288. is used:  @samp{\evalto @var{a} \to @var{b}}.  The @code{\evalto}
  289. word is ignored by Calc's input routines, and is undefined in @TeX{}.
  290. You will typically want to include one of the following definitions
  291. at the top of a @TeX{} file that uses @code{\evalto}:
  292. X
  293. @example
  294. \def\evalto@{@}
  295. \def\evalto#1\to@{@}
  296. @end example
  297. X
  298. The first definition formats evaluates-to operators in the usual
  299. way.  The second causes only the @var{b} part to appear in the
  300. printed document; the @var{a} part and the arrow are hidden.
  301. Another definition you may wish to use is @samp{\let\to=\Rightarrow}
  302. which causes @code{\to} to appear more like Calc's @samp{=>} symbol.
  303. @xref{Evaluates-To Operator}, for a discussion of @code{evalto}.
  304. X
  305. The complete set of @TeX{} control sequences that are ignored during
  306. reading is:
  307. X
  308. @example
  309. \hbox  \mbox  \text  \left  \right
  310. \,  \>  \:  \;  \!  \quad  \qquad  \hfil  \hfill
  311. \displaystyle  \textstyle  \dsize  \tsize
  312. \scriptstyle  \scriptscriptstyle  \ssize  \ssize
  313. \rm  \bf  \it  \sl  \roman  \bold  \italic  \slanted
  314. \cal  \mit  \Cal  \Bbb  \frak  \goth
  315. \evalto
  316. @end example
  317. X
  318. Note that, because these symbols are ignored, reading a @TeX{} formula
  319. into Calc and writing it back out may lose spacing and font information.
  320. X
  321. Also, the ``discretionary multiplication sign'' @samp{\*} is read
  322. the same as @samp{*}.
  323. X
  324. @ifinfo
  325. The @TeX{} version of this manual includes some printed examples at the
  326. end of this section.
  327. @end ifinfo
  328. @iftex
  329. Here are some examples of how various Calc formulas are formatted in @TeX{}:
  330. X
  331. @group
  332. @example
  333. sin(a^2 / subscr(b,i))
  334. \sin\left( {a^2 \over b_i} \right)
  335. @end example
  336. @tex
  337. \let\rm\goodrm
  338. $$ \sin\left( a^2 \over b_i \right) $$
  339. @end tex
  340. @sp 1
  341. @end group
  342. X
  343. @group
  344. @example
  345. [(3, 4), 3:4, 3 +/- 4, [3 .. inf)]
  346. [3 + 4i, @{3 \over 4@}, 3 \pm 4, [3 \ldots \infty)]
  347. @end example
  348. @tex
  349. \turnoffactive
  350. $$ [3 + 4i, {3 \over 4}, 3 \pm 4, [ 3 \ldots \infty)] $$
  351. @end tex
  352. @sp 1
  353. @end group
  354. X
  355. @group
  356. @example
  357. [abs(a), abs(a / b), floor(a), ceil(a / b)]
  358. [|a|, \left| a \over b \right|,
  359. X \lfloor a \rfloor, \left\lceil a \over b \right\rceil]
  360. @end example
  361. @tex
  362. $$ [|a|, \left| a \over b \right|,
  363. X    \lfloor a \rfloor, \left\lceil a \over b \right\rceil] $$
  364. @end tex
  365. @sp 1
  366. @end group
  367. X
  368. @group
  369. @example
  370. [sin(a), sin(2 a), sin(2 + a), sin(a / b)]
  371. [\sin@{a@}, \sin@{2 a@}, \sin(2 + a),
  372. X \sin\left( @{a \over b@} \right)]
  373. @end example
  374. @tex
  375. \turnoffactive\let\rm\goodrm
  376. $$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$
  377. @end tex
  378. @sp 2
  379. @end group
  380. X
  381. @group
  382. First with plain @kbd{d T}, then with @kbd{C-u d T}, then finally with
  383. @kbd{C-u - d T} (using the example definition
  384. @samp{\def\foo#1@{\tilde F(#1)@}}:
  385. X
  386. @example
  387. [f(a), foo(bar), sin(pi)]
  388. [f(a), foo(bar), \sin{\pi}]
  389. [f(a), \hbox@{foo@}(\hbox@{bar@}), \sin@{\pi@}]
  390. [f(a), \foo@{\hbox@{bar@}@}, \sin@{\pi@}]
  391. @end example
  392. @tex
  393. \let\rm\goodrm
  394. $$ [f(a), foo(bar), \sin{\pi}] $$
  395. $$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$
  396. $$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$
  397. @end tex
  398. @sp 2
  399. @end group
  400. X
  401. @group
  402. First with @samp{\def\evalto@{@}}, then with @samp{\def\evalto#1\to@{@}}:
  403. X
  404. @example
  405. 2 + 3 => 5
  406. \evalto 2 + 3 \to 5
  407. @end example
  408. @tex
  409. \turnoffactive
  410. $$ 2 + 3 \to 5 $$
  411. $$ 5 $$
  412. @end tex
  413. @sp 2
  414. @end group
  415. X
  416. @group
  417. First with standard @code{\to}, then with @samp{\let\to\Rightarrow}:
  418. X
  419. @example
  420. [2 + 3 => 5, a / 2 => (b + c) / 2]
  421. [@{2 + 3 \to 5@}, @{@{a \over 2@} \to @{b + c \over 2@}@}]
  422. @end example
  423. @tex
  424. \turnoffactive
  425. $$ [{2 + 3 \to 5}, {{a \over 2} \to {b + c \over 2}}] $$
  426. {\let\to\Rightarrow
  427. $$ [{2 + 3 \to 5}, {{a \over 2} \to {b + c \over 2}}] $$}
  428. @end tex
  429. @sp 2
  430. @end group
  431. X
  432. @group
  433. Matrices normally, then changing @code{\matrix} to @code{\pmatrix}:
  434. X
  435. @example
  436. [ [ a / b, 0 ], [ 0, 2^(x + 1) ] ]
  437. \matrix@{ @{a \over b@} & 0 \\ 0 & 2^@{(x + 1)@} @}
  438. \pmatrix@{ @{a \over b@} & 0 \\ 0 & 2^@{(x + 1)@} @}
  439. @end example
  440. @tex
  441. \turnoffactive
  442. $$ \matrix{ {a \over b} & 0 \cr 0 & 2^{(x + 1)} } $$
  443. $$ \pmatrix{ {a \over b} & 0 \cr 0 & 2^{(x + 1)} } $$
  444. @end tex
  445. @sp 2
  446. @end group
  447. @end iftex
  448. X
  449. @node Eqn Language Mode, Mathematica Language Mode, TeX Language Mode, Language Modes
  450. @subsection Eqn Language Mode
  451. X
  452. @noindent
  453. @kindex d E
  454. @pindex calc-eqn-language
  455. @dfn{Eqn} is another popular formatter for math formulas.  It is
  456. designed for use with the TROFF text formatter, and comes standard
  457. with many versions of Unix.  The @kbd{d E} (@code{calc-eqn-language})
  458. command selects @dfn{eqn} notation.
  459. X
  460. The @dfn{eqn} language's main idiosyncrasy is that whitespace plays
  461. a significant part in the parsing of the language.  For example,
  462. @samp{sqrt x+1 + y} treats @samp{x+1} as the argument of the
  463. @code{sqrt} operator.  @dfn{Eqn} also understands more conventional
  464. grouping using curly braces:  @samp{sqrt@{x+1@} + y}.  Braces are
  465. required only when the argument contains spaces.
  466. X
  467. In Calc's @dfn{eqn} mode, however, curly braces are required to
  468. delimit arguments of operators like @code{sqrt}.  The first of the
  469. above examples would treat only the @samp{x} as the argument of
  470. @code{sqrt}, and in fact @samp{sin x+1} would be interpreted as
  471. @samp{sin * x + 1}, because @code{sin} is not a special operator
  472. in the @dfn{eqn} language.  If you always surround the argument
  473. with curly braces, Calc will never misunderstand.
  474. X
  475. Calc also understands parentheses as grouping characters.  Another
  476. peculiarity of @dfn{eqn}'s syntax makes it advisable to separate
  477. words with spaces from any surrounding characters that aren't curly
  478. braces, so Calc writes @samp{sin ( x + y )} in @dfn{eqn} mode.
  479. (The spaces around @code{sin} are important to make @dfn{eqn}
  480. recognize that @code{sin} should be typeset in a roman font, and
  481. the spaces around @code{x} and @code{y} are a good idea just in
  482. case the @dfn{eqn} document has defined special meanings for these
  483. names, too.)
  484. X
  485. Powers and subscripts are written with the @code{sub} and @code{sup}
  486. operators, respectively.  Note that the caret symbol @samp{^} is
  487. treated the same as a space in @dfn{eqn} mode, as is the @samp{~}
  488. symbol (these are used to introduce spaces of various widths into
  489. the typeset output of @dfn{eqn}).
  490. X
  491. As in @TeX{} mode, Calc's formatter omits parentheses around the
  492. arguments of functions like @code{ln} and @code{sin} if they are
  493. ``simple-looking''; in this case Calc surrounds the argument with
  494. braces, separated by a @samp{~} from the function name: @samp{sin~@{x@}}.
  495. X
  496. Font change codes (like @samp{roman @var{x}}) and positioning codes
  497. (like @samp{~} and @samp{down @var{n} @var{x}}) are ignored by the
  498. @dfn{eqn} reader.  Also ignored are the words @code{left}, @code{right},
  499. @code{mark}, and @code{lineup}.  Quotation marks in @dfn{eqn} mode input
  500. are treated the same as curly braces: @samp{sqrt "1+x"} is equivalent to
  501. @samp{sqrt @{1+x@}}; this is only an approximation to the true meaning
  502. of quotes in @dfn{eqn}, but it is good enough for most uses.
  503. X
  504. Accent codes (@samp{@var{x} dot}) are handled by treating them as
  505. function calls (@samp{dot(@var{x})}) internally.  @xref{TeX Language
  506. Mode} for a table of these accent functions.  The @code{prime} accent
  507. is treated specially if it occurs on a variable or function name:
  508. @samp{f prime prime ( x prime )} is stored internally as @samp{f''(x')}.
  509. For example, taking the derivative of @samp{f(2 x)} with @kbd{a d x}
  510. will produce @samp{2 f'(2 x)}, which @dfn{eqn} mode will display as
  511. @samp{2 f prime ( 2 x )}.
  512. X
  513. Assignments are written with the @samp{<-} (left-arrow) symbol,
  514. and @code{evalto} operators are written with @samp{->} or
  515. @samp{evalto ... ->} (@pxref{TeX Language Mode}, for a discussion
  516. of this).  The regular Calc symbols @samp{:=} and @samp{=>} are also
  517. recognized for these operators during reading.
  518. X
  519. Vectors in @dfn{eqn} mode use regular Calc square brackets, but
  520. matrices are formatted as @samp{matrix @{ ccol @{ a above b @} ... @}}.
  521. The words @code{lcol} and @code{rcol} are recognized as synonyms
  522. for @code{ccol} during input, and are generated instead of @code{ccol}
  523. if the matrix justification mode so specifies.
  524. X
  525. @node Mathematica Language Mode, Maple Language Mode, Eqn Language Mode, Language Modes
  526. @subsection Mathematica Language Mode
  527. X
  528. @noindent
  529. @kindex d M
  530. @pindex calc-mathematica-language
  531. @cindex Mathematica language
  532. The @kbd{d M} (@code{calc-mathematica-language}) command selects the
  533. conventions of Mathematica, a powerful and popular mathematical tool
  534. from Wolfram Research, Inc.  Notable differences in Mathematica mode
  535. are that the names of built-in functions are capitalized, and function
  536. calls use square brackets instead of parentheses.  Thus the Calc
  537. formula @samp{sin(2 x)} is entered and displayed @samp{Sin[2 x]} in
  538. Mathematica mode.
  539. X
  540. Vectors and matrices use curly braces in Mathematica.  Complex numbers
  541. are written @samp{3 + 4 I}.  The standard special constants in Calc are
  542. written @code{Pi}, @code{E}, @code{I}, @code{GoldenRatio}, @code{EulerGamma},
  543. @code{Infinity}, @code{ComplexInfinity}, and @code{Indeterminate} in
  544. Mathematica mode.
  545. Non-decimal numbers are written, e.g., @samp{16^^7fff}.  Floating-point
  546. numbers in scientific notation are written @samp{1.23*10.^3}.
  547. Subscripts use double square brackets: @samp{a[[i]]}.@refill
  548. X
  549. @node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes
  550. @subsection Maple Language Mode
  551. X
  552. @noindent
  553. @kindex d W
  554. @pindex calc-maple-language
  555. @cindex Maple language
  556. The @kbd{d W} (@code{calc-maple-language}) command selects the
  557. conventions of Maple, another mathematical tool from the University
  558. of Waterloo.  
  559. X
  560. Maple's language is much like C.  Underscores are allowed in symbol
  561. names; square brackets are used for subscripts; explicit @samp{*}s for
  562. multiplications are required.  Use either @samp{^} or @samp{**} to
  563. denote powers.
  564. X
  565. Maple uses square brackets for lists and curly braces for sets.  Calc
  566. interprets both notations as vectors, and displays vectors with square
  567. brackets.  This means Maple sets will be converted to lists when they
  568. pass through Calc.  As a special case, matrices are written as calls
  569. to the function @code{matrix}, given a list of lists as the argument,
  570. and can be read in this form or with all-capitals @code{MATRIX}.
  571. X
  572. The Maple interval notation @samp{2 .. 3} has no surrounding brackets;
  573. Calc reads @samp{2 .. 3} as the closed interval @samp{[2 .. 3]}, and
  574. writes any kind of interval as @samp{2 .. 3}.  This means you cannot
  575. see the difference between an open and a closed interval while in
  576. Maple display mode.
  577. X
  578. Maple writes complex numbers as @samp{3 + 4*I}.  Its special constants
  579. are @code{Pi}, @code{E}, @code{I}, and @code{infinity} (all three of
  580. @code{inf}, @code{uinf}, and @code{nan} display as @code{infinity}).
  581. Floating-point numbers are written @samp{1.23*10.^3}.
  582. X
  583. Among things not currently handled by Calc's Maple mode are the
  584. various quote symbols, procedures and functional operators, and
  585. inert (@samp{&}) operators.
  586. X
  587. @node Compositions, , Maple Language Mode, Language Modes
  588. @subsection Compositions
  589. X
  590. @noindent
  591. @cindex Compositions
  592. There are several @dfn{composition functions} which allow you to get
  593. displays in a variety of formats similar to those in Big language
  594. mode.  Most of these functions do not evaluate to anything; they are
  595. placeholders which are left in symbolic form by Calc's evaluator but
  596. are recognized by Calc's display formatting routines.
  597. X
  598. Two of these, @code{string} and @code{bstring}, are described elsewhere.
  599. @xref{Strings}.  For example, @samp{string("ABC")} is displayed as
  600. @samp{ABC}.  When viewed on the stack it will be indistinguishable from
  601. the variable @code{ABC}, but internally it will be stored as
  602. @samp{string([65, 66, 67])} and can still be manipulated this way; for
  603. example, the selection and vector commands @kbd{j 1 v v j u} would
  604. select the vector portion of this object and reverse the elements, then
  605. deselect to reveal a string whose characters have been reversed.
  606. X
  607. The composition functions do the same thing in all language modes
  608. (although their components will of course be formatted in the current
  609. language mode).  The one exception is Unformatted mode (@kbd{d U}),
  610. which does not give the composition functions any special treatment.
  611. The functions are discussed here because of their relationship to
  612. the language modes.
  613. X
  614. @menu
  615. * Composition Basics::
  616. * Horizontal Compositions::
  617. * Vertical Compositions::
  618. * Other Compositions::
  619. * Information about Compositions::
  620. * User-Defined Compositions::
  621. @end menu
  622. X
  623. @node Composition Basics, Horizontal Compositions, Compositions, Compositions
  624. @subsubsection Compositions
  625. X
  626. @noindent
  627. Compositions are generally formed by stacking formulas together
  628. horizontally or vertically in various ways.  Those formulas are
  629. themselves compositions.  @TeX{} users will find this analogous
  630. to @TeX{}'s ``boxes.''  Each multi-line composition has a
  631. @dfn{baseline}; horizontal compositions use the baselines to
  632. decide how formulas should be positioned relative to one another.
  633. For example, in the Big mode formula
  634. X
  635. @group
  636. @example
  637. X          2
  638. X     a + b
  639. 17 + ------
  640. X       c
  641. @end example
  642. @end group
  643. X
  644. @noindent
  645. the second term of the sum is four lines tall and has line three as
  646. its baseline.  Thus when the term is combined with 17, line three
  647. is placed on the same level as the baseline of 17.
  648. X
  649. @tex
  650. \bigskip
  651. @end tex
  652. X
  653. Another important composition concept is @dfn{precedence}.  This is
  654. an integer that represents the binding strength of various operators.
  655. For example, @samp{*} has higher precedence (195) than @samp{+} (180),
  656. which means that @samp{(a * b) + c} will be formatted without the
  657. parentheses, but @samp{a * (b + c)} will keep the parentheses.
  658. X
  659. The operator table used by normal and Big language modes has the
  660. following precedences:
  661. X
  662. @example
  663. _     1200   @r{(subscripts)}
  664. %     1100   @r{(as in n}%@r{)}
  665. -     1000   @r{(as in }-@r{n)}
  666. !     1000   @r{(as in }!@r{n)}
  667. mod    400
  668. +/-    300
  669. !!     210    @r{(as in n}!!@r{)}
  670. !      210    @r{(as in n}!@r{)}
  671. ^      200
  672. *      195    @r{(or implicit multiplication)}
  673. / % \  190
  674. + -    180    @r{(as in a}+@r{b)}
  675. |      170
  676. < =    160    @r{(and other relations)}
  677. &&     110
  678. ||     100
  679. ? :     90
  680. !!!     85
  681. &&&     80
  682. |||     75
  683. :=      50
  684. ::      45
  685. =>      40
  686. @end example
  687. X
  688. The general rule is that if an operator with precedence @cite{n}
  689. occurs as an argument to an operator with precedence @cite{m}, then
  690. the argument is enclosed in parentheses if @cite{n < m}.  Top-level
  691. expressions and expressions which are function arguments, vector
  692. components, etc., are formatted with precedence zero (so that they
  693. normally never get additional parentheses).
  694. X
  695. For binary left-associative operators like @samp{+}, the righthand
  696. argument is actually formatted with one-higher precedence than shown
  697. in the table.  This makes sure @samp{(a + b) + c} omits the parentheses,
  698. but the unnatural form @samp{a + (b + c)} keeps its parentheses.
  699. Right-associative operators like @samp{^} format the lefthand argument
  700. with one-higher precedence.
  701. X
  702. @tindex cprec
  703. The @code{cprec} function formats an expression with an arbitrary
  704. precedence.  For example, @samp{cprec(abc, 185)} will combine into
  705. sums and products as follows:  @samp{7 + abc}, @samp{7 (abc)} (because
  706. this @code{cprec} form has higher precedence than addition, but lower
  707. precedence than multiplication).
  708. X
  709. @tex
  710. \bigskip
  711. @end tex
  712. X
  713. A final composition issue is @dfn{line breaking}.  Calc uses two
  714. different strategies for ``flat'' and ``non-flat'' compositions.
  715. A non-flat composition is anything that appears on multiple lines
  716. (not counting line breaking).  Examples would be matrices, and Big
  717. mode powers and quotients.  Non-flat compositions are displayed
  718. exactly as specified.  If they come out wider than the current
  719. window, you must use horizontal scrolling (@kbd{<} and @kbd{>}) to
  720. view them.
  721. X
  722. Flat compositions, on the other hand, will be broken across several
  723. lines if they are too wide to fit the window.  Certain points in a
  724. composition are noted internally as @dfn{break points}.  Calc's
  725. general strategy is to fill each line as much as possible, then to
  726. move down to the next line starting at the first break point that
  727. didn't fit.  However, the line breaker understands the hierarchical
  728. structure of formulas.  It will not break an ``inner'' formula if
  729. it can use an earlier break point from an ``outer'' formula instead.
  730. For example, a vector of sums might be formatted as:
  731. X
  732. @group
  733. @example
  734. [ a + b + c, d + e + f,
  735. X  g + h + i, j + k + l, m ]
  736. @end example
  737. @end group
  738. X
  739. @noindent
  740. If the @samp{m} can fit, then so, it seems, could the @samp{g}.
  741. But Calc prefers to break at the comma since the comma is part
  742. of a ``more outer'' formula.  Calc would break at a plus sign
  743. only if it had to, say, if the very first sum in the vector had
  744. itself been too large to fit.
  745. X
  746. Of the composition functions described below, only @code{choriz}
  747. generates break points.  The @code{bstring} function (@pxref{Strings})
  748. also generates breakable items:  A break point is added after every
  749. space (or group of spaces) except for spaces at the very beginning or
  750. end of the string.
  751. X
  752. Composition functions themselves count as levels in the formula
  753. hierarchy, so a @code{choriz} that is a component of a larger
  754. @code{choriz} will be less likely to be broken.  As a special case,
  755. if a @code{bstring} occurs as a component of a @code{choriz} or
  756. @code{choriz}-like object (such as a vector or a list of arguments
  757. in a function call), then the break points in that @code{bstring}
  758. will be on the same level as the break points of the surrounding
  759. object.
  760. X
  761. @node Horizontal Compositions, Vertical Compositions, Composition Basics, Compositions
  762. @subsubsection Horizontal Compositions
  763. X
  764. @noindent
  765. @tindex choriz
  766. The @code{choriz} function takes a vector of objects and composes
  767. them horizontally.  For example, @samp{choriz([17, a b/c, d])} formats
  768. as @w{@samp{17a b / cd}} in normal language mode, or as
  769. X
  770. @group
  771. @example
  772. X  a b
  773. 17---d
  774. X   c
  775. @end example
  776. @end group
  777. X
  778. @noindent
  779. in Big language mode.  This is actually one case of the general
  780. function @samp{choriz(@var{vec}, @var{sep}, @var{prec})}, where
  781. either or both of @var{sep} and @var{prec} may be omitted.
  782. @var{Prec} gives the @dfn{precedence} to use when formatting
  783. each of the components of @var{vec}.  The default precedence is
  784. the precedence from the surrounding environment.
  785. X
  786. @var{Sep} is a string (i.e., a vector of character codes as might
  787. be entered with @code{" "} notation) which should separate components
  788. of the composition.  Also, if @var{sep} is given, the line breaker
  789. will allow lines to be broken after each occurrence of @var{sep}.
  790. If @var{sep} is omitted, the composition will not be breakable
  791. (unless any of its component compositions are breakable).
  792. X
  793. For example, @samp{2 choriz([a, b c, d = e], " + ", 180)} is
  794. formatted as @samp{2 a + b c + (d = e)}.  To get the @code{choriz}
  795. to have precedence 180 ``outwards'' as well as ``inwards'',
  796. enclose it in a @code{cprec} form:  @samp{2 cprec(choriz(...), 180)}
  797. formats as @samp{2 (a + b c + (d = e))}.
  798. X
  799. The baseline of a horizontal composition is the same as the
  800. baselines of the component compositions, which are all aligned.
  801. X
  802. @node Vertical Compositions, Other Compositions, Horizontal Compositions, Compositions
  803. @subsubsection Vertical Compositions
  804. X
  805. @noindent
  806. @tindex cvert
  807. The @code{cvert} function makes a vertical composition.  Each
  808. component of the vector is centered in a column.  The baseline of
  809. the result is by default the top line of the resulting composition.
  810. For example, @samp{f(cvert([a, bb, ccc]), cvert([a^2 + 1, b^2]))}
  811. formats in Big mode as
  812. X
  813. @group
  814. @example
  815. f( a ,  2    )
  816. X  bb   a  + 1
  817. X  ccc     2
  818. X         b
  819. @end example
  820. @end group
  821. X
  822. @tindex cbase
  823. There are several special composition functions that work only as
  824. components of a vertical composition.  The @code{cbase} function
  825. controls the baseline of the vertical composition; the baseline
  826. will be the same as the baseline of whatever component is enclosed
  827. in @code{cbase}.  Thus @samp{f(cvert([a, cbase(bb), ccc]),
  828. cvert([a^2 + 1, cbase(b^2)]))} displays as
  829. X
  830. @group
  831. @example
  832. X        2
  833. X       a  + 1
  834. X   a      2
  835. f(bb ,   b   )
  836. X  ccc
  837. @end example
  838. @end group
  839. X
  840. @tindex ctbase
  841. @tindex cbbase
  842. There are also @code{ctbase} and @code{cbbase} functions which
  843. make the baseline of the vertical composition equal to the top
  844. or bottom line (rather than the baseline) of that component.
  845. Thus @samp{cvert([cbase(a / b)]) + cvert([ctbase(a / b)]) +
  846. cvert([cbbase(a / b)])} gives
  847. X
  848. @group
  849. @example
  850. X        a
  851. a       -
  852. - + a + b
  853. b   -
  854. X    b
  855. @end example
  856. @end group
  857. X
  858. There should be only one @code{cbase}, @code{ctbase}, or @code{cbbase}
  859. function in a given vertical composition.  These functions can also
  860. be written with no arguments:  @samp{ctbase()} is a zero-height object
  861. which means the baseline is the top line of the following item, and
  862. @samp{cbbase()} means the baseline is the bottom line of the preceding
  863. item.
  864. X
  865. @tindex crule
  866. The @code{crule} function builds a ``rule,'' or horizontal line,
  867. across a vertical composition.  By itself @samp{crule()} uses @samp{-}
  868. characters to build the rule.  You can specify any other character,
  869. e.g., @samp{crule("=")}.  The argument must be a character code or
  870. vector of exactly one character code.  It is repeated to match the
  871. width of the widest item in the stack.  For example, a quotient
  872. with a thick line is @samp{cvert([a + 1, cbase(crule("=")), b^2])}:
  873. X
  874. @group
  875. @example
  876. a + 1
  877. =====
  878. X  2
  879. X b
  880. @end example
  881. @end group
  882. X
  883. @tindex clvert
  884. @tindex crvert
  885. Finally, the functions @code{clvert} and @code{crvert} act exactly
  886. like @code{cvert} except that the items are left- or right-justified
  887. in the stack.  Thus @samp{clvert([a, bb, ccc]) + crvert([a, bb, ccc])}
  888. gives:
  889. X
  890. @group
  891. @example
  892. a   +   a
  893. bb     bb
  894. ccc   ccc
  895. @end example
  896. @end group
  897. X
  898. Like @code{choriz}, the vertical compositions accept a second argument
  899. which gives the precedence to use when formatting the components.
  900. Vertical compositions do not support separator strings.
  901. X
  902. @node Other Compositions, Information about Compositions, Vertical Compositions, Compositions
  903. @subsubsection Other Compositions
  904. X
  905. @noindent
  906. @tindex csup
  907. The @code{csup} function builds a superscripted expression.  For
  908. example, @samp{csup(a, b)} looks the same as @samp{a^b} does in Big
  909. language mode.  This is essentially a horizontal composition of
  910. @samp{a} and @samp{b}, where @samp{b} is shifted up so that its
  911. bottom line is one above the baseline.
  912. X
  913. @tindex csub
  914. Likewise, the @code{csub} function builds a subscripted expression.
  915. This shifts @samp{b} down so that its top line is one below the
  916. bottom line of @samp{a} (note that this is not quite analogous to
  917. @code{csup}).  Other arrangements can be obtained by using
  918. @code{choriz} and @code{cvert} directly.
  919. X
  920. @tindex cflat
  921. The @code{cflat} function formats its argument in ``flat'' mode,
  922. as obtained by @samp{d O}, if the current language mode is normal
  923. or Big.  It is invisible in other language modes.  For example,
  924. @samp{a^(b/c)} is formatted by Big mode like @samp{csup(a, cflat(b/c))}
  925. to improve its readability.
  926. X
  927. @tindex cspace
  928. The @code{cspace} function creates horizontal space.  For example,
  929. @samp{cspace(4)} is effectively the same as @samp{string("    ")}.
  930. A second string (i.e., vector of characters) argument is repeated
  931. instead of the space character.  For example, @samp{cspace(4, "ab")}
  932. looks like @samp{abababab}.  If the second argument is not a string,
  933. it is formatted in the normal way and then several copies of that
  934. are composed together:  @samp{cspace(4, a^2)} yields
  935. X
  936. @group
  937. @example
  938. X 2 2 2 2
  939. a a a a
  940. @end example
  941. @end group
  942. X
  943. @noindent
  944. If the number argument is zero, this is a zero-width object.
  945. X
  946. @tindex cvspace
  947. The @code{cvspace} function creates vertical space, or a vertical
  948. stack of copies of a certain string or formatted object.  The
  949. baseline is the center line of the resulting stack.  A numerical
  950. argument of zero will produce an object which contributes zero
  951. height if used in a vertical composition.
  952. X
  953. @tindex ctspace
  954. @tindex cbspace
  955. There are also @code{ctspace} and @code{cbspace} functions which
  956. create vertical space with the baseline the same as the baseline
  957. of the top or bottom copy, respectively, of the second argument.
  958. Thus @samp{cvspace(2, a/b) + ctspace(2, a/b) + cbspace(2, a/b)}
  959. displays as:
  960. X
  961. @group
  962. @example
  963. X        a
  964. X        -
  965. a       b
  966. -   a   a
  967. b + - + -
  968. a   b   b
  969. -   a
  970. b   -
  971. X    b
  972. @end example
  973. @end group
  974. X
  975. @node Information about Compositions, User-Defined Compositions, Other Compositions, Compositions
  976. @subsubsection Information about Compositions
  977. X
  978. @noindent
  979. The functions in this section are actual functions; they compose their
  980. arguments according to the current language and other display modes,
  981. then return a certain measurement of the composition as an integer.
  982. X
  983. @tindex cwidth
  984. The @code{cwidth} function measures the width, in characters, of a
  985. composition.  For example, @samp{cwidth(a + b)} is 5, and
  986. @samp{cwidth(a / b)} is 5 in normal mode, 1 in Big mode, and 11 in
  987. @TeX{} mode (for @samp{@{a \over b@}}).  The argument may involve
  988. the composition functions described in this section.
  989. X
  990. @tindex cheight
  991. The @code{cheight} function measures the height of a composition.
  992. This is the total number of lines in the argument's printed form.
  993. X
  994. @tindex cascent
  995. @tindex cdescent
  996. The functions @code{cascent} and @code{cdescent} measure the amount
  997. of the height that is above (and including) the baseline, or below
  998. the baseline, respectively.  Thus @samp{cascent(@var{x}) + cdescent(@var{x})}
  999. always equals @samp{cheight(@var{x})}.  For a one-line formula like
  1000. @samp{a + b}, @code{cascent} returns 1 and @code{cdescent} returns 0.
  1001. For @samp{a / b} in Big mode, @code{cascent} returns 2 and @code{cdescent}
  1002. returns 1.  The only formula for which @code{cascent} will return zero
  1003. is @samp{cvspace(0)} or equivalents.
  1004. X
  1005. @node User-Defined Compositions, , Information about Compositions, Compositions
  1006. @subsubsection User-Defined Compositions
  1007. X
  1008. @noindent
  1009. @kindex Z C
  1010. @pindex calc-user-define-composition
  1011. The @kbd{Z C} (@code{calc-user-define-composition}) command lets you
  1012. define the display format for any algebraic function.  You provide a
  1013. formula containing a certain number of argument variables on the stack.
  1014. Any time Calc formats a call to the specified function in the current
  1015. language mode and with that number of arguments, Calc effectively
  1016. replaces the function call with that formula with the arguments
  1017. replaced.
  1018. X
  1019. Calc builds the default argument list by sorting all the variable names
  1020. that appear in the formula into alphabetical order.  You can edit this
  1021. argument list before pressing @key{RET} if you wish.  Any variables in
  1022. the formula that do not appear in the argument list will be displayed
  1023. literally; any arguments that do not appear in the formula will not
  1024. affect the display at all.
  1025. X
  1026. You can define formats for built-in functions, for functions you have
  1027. defined with @kbd{Z F} (@pxref{Algebraic Definitions}), or for functions
  1028. which have no definitions but are being used as purely syntactic objects.
  1029. You can define different formats for each language mode, and for each
  1030. number of arguments, using a succession of @kbd{Z C} commands.  When
  1031. Calc formats a function call, it first searches for a format defined
  1032. for the current language mode (and number of arguments); if there is
  1033. none, it uses the format defined for the Normal language mode.  If
  1034. neither format exists, Calc uses its built-in standard format for that
  1035. function (usually just @samp{@var{func}(@var{args})}).
  1036. X
  1037. If you execute @kbd{Z C} with the number 0 on the stack instead of a
  1038. formula, any defined formats for the function in the current language
  1039. mode will be removed.  The function will revert to its standard format.
  1040. X
  1041. For example, the default format for the binomial coefficient function
  1042. @samp{choose(n, m)} in the Big language mode is
  1043. X
  1044. @group
  1045. @example
  1046. X n
  1047. ( )
  1048. X m
  1049. @end example
  1050. @end group
  1051. X
  1052. You might prefer the notation,
  1053. X
  1054. @group
  1055. @example
  1056. X C
  1057. n m
  1058. @end example
  1059. @end group
  1060. X
  1061. To define this notation, first make sure you are in Big mode,
  1062. then put the formula
  1063. X
  1064. @smallexample
  1065. choriz([cvert([cvspace(1), n]), C, cvert([cvspace(1), m])])
  1066. @end smallexample
  1067. X
  1068. @noindent
  1069. on the stack and type @kbd{Z C}.  Answer the first prompt with
  1070. @code{choose}.  The second prompt will be the default argument list
  1071. of @samp{(C m n)}.  Edit this list to be @samp{(n m)} and press
  1072. @key{RET}.  Now, try it out:  For example, turn simplification
  1073. off with @kbd{m O} and enter @samp{choose(a,b) + choose(7,3)}
  1074. as an algebraic entry.
  1075. X
  1076. @group
  1077. @example
  1078. X C  +  C 
  1079. a b   7 3
  1080. @end example
  1081. @end group
  1082. X
  1083. As another example, let's define the usual notation for Stirling
  1084. numbers of the first kind, @samp{stir1(n, m)}.  This is just like
  1085. the regular format for binomial coefficients but with square brackets
  1086. instead of parentheses.
  1087. X
  1088. @smallexample
  1089. choriz([string("["), cvert([n, cbase(cvspace(1)), m]), string("]")])
  1090. @end smallexample
  1091. X
  1092. Now type @kbd{Z C stir1 @key{RET}}, edit the argument list to
  1093. @samp{(n m)}, and type @key{RET}.
  1094. X
  1095. The formula provided to @kbd{Z C} usually will involve composition
  1096. functions, but it doesn't have to.  Putting the formula @samp{a + b + c}
  1097. onto the stack and typing @kbd{Z C foo @key{RET} @key{RET}} would define
  1098. the function @samp{foo(x,y,z)} to display like @samp{x + y + z}.
  1099. This ``sum'' will act exactly like a real sum for all formatting
  1100. purposes (it will be parenthesized the same, and so on).  However
  1101. it will be computationally unrelated to a sum.  For example, the
  1102. formula @samp{2 * foo(1, 2, 3)} will display as @samp{2 (1 + 2 + 3)}.
  1103. Operator precedences have caused the ``sum'' to be written in
  1104. parentheses, but the arguments have not actually been summed.
  1105. (Generally a display format like this would be undesirable, since
  1106. it can easily be confused with a real sum.)
  1107. X
  1108. The special function @code{eval} can be used inside a @kbd{Z C}
  1109. composition formula to cause all or part of the formula to be
  1110. evaluated at display time.  For example, if the formula is
  1111. @samp{a + eval(b + c)}, then @samp{foo(1, 2, 3)} will be displayed
  1112. as @samp{1 + 5}.  Evaluation will use the default simplifications,
  1113. regardless of the current simplification mode.  There are also
  1114. @code{evalsimp} and @code{evalextsimp} which simplify as if by
  1115. @kbd{a s} and @kbd{a e} (respectively).  Note that these ``functions''
  1116. operate only in the context of composition formulas (and also in
  1117. rewrite rules, where they serve a similar purpose; @pxref{Rewrite
  1118. Rules}).  On the stack, a call to @code{eval} will be left in
  1119. symbolic form.
  1120. X
  1121. It is not a good idea to use @code{eval} except as a last resort.
  1122. It can cause the display of formulas to be extremely slow.  For
  1123. example, while @samp{eval(a + b)} might seem quite fast and simple,
  1124. there are several situations where it could be slow.  For example,
  1125. @samp{a} and/or @samp{b} could be polar complex numbers, in which
  1126. case doing the sum requires trigonometry.  Or, @samp{a} could be
  1127. the factorial @samp{fact(100)} which is unevaluated because the
  1128. user has typed @kbd{m O}; @code{eval} will evaluate it anyway to
  1129. produce a large, unwieldy integer.
  1130. X
  1131. You can save your display formats permanently using the @kbd{Z P}
  1132. command (@pxref{Creating User Keys}).
  1133. X
  1134. @node Calc Mode Line, , Language Modes, Mode Settings
  1135. @section The Calc Mode Line
  1136. X
  1137. @noindent
  1138. @cindex Mode line indicators
  1139. This section is a summary of all symbols that can appear on the
  1140. Calc mode line, the highlighted bar that appears under the Calc
  1141. stack window (or under an editing window in Embedded Mode).
  1142. X
  1143. The basic mode line format is:
  1144. X
  1145. @example
  1146. --%%-Calc: 12 Deg @var{other modes}       (Calculator)
  1147. @end example
  1148. X
  1149. The @samp{%%} is the Emacs symbol for ``read-only''; it shows that
  1150. regular Emacs commands are not allowed to edit the stack buffer
  1151. as if it were text.
  1152. X
  1153. The word @samp{Calc:} changes to @samp{CalcEmbed:} if Embedded Mode
  1154. is enabled.  The words after this describe the various Calc modes
  1155. that are in effect.
  1156. X
  1157. The first mode is always the current precision, an integer.
  1158. The second mode is always the angular mode, either @code{Deg},
  1159. @code{Rad}, or @code{Hms}.
  1160. X
  1161. Here is a complete list of the remaining symbols that can appear
  1162. on the mode line:
  1163. X
  1164. @table @code
  1165. @item Alg
  1166. Algebraic mode (@kbd{m a}; @pxref{Algebraic Entry}).
  1167. X
  1168. @item Alg[(
  1169. Incomplete algebraic mode (@kbd{C-u m a}).
  1170. X
  1171. @item Alg*
  1172. Total algebraic mode (@kbd{m t}).
  1173. X
  1174. @item Symb
  1175. Symbolic mode (@kbd{m s}; @pxref{Symbolic Mode}).
  1176. X
  1177. @item Matrix
  1178. Matrix mode (@kbd{m v}; @pxref{Matrix Mode}).
  1179. X
  1180. @item Matrix@var{n}
  1181. Dimensioned matrix mode (@kbd{C-u @var{n} m v}).
  1182. X
  1183. @item Scalar
  1184. Scalar mode (@kbd{m v}; @pxref{Matrix Mode}).
  1185. X
  1186. @item Polar
  1187. Polar complex mode (@kbd{m p}; @pxref{Polar Mode}).
  1188. X
  1189. @item Frac
  1190. Fraction mode (@kbd{m f}; @pxref{Fraction Mode}).
  1191. X
  1192. @item Inf
  1193. Infinite mode (@kbd{m i}; @pxref{Infinite Mode}).
  1194. X
  1195. @item +Inf
  1196. Positive infinite mode (@kbd{C-u 0 m i}).
  1197. X
  1198. @item NoSimp
  1199. Default simplifications off (@kbd{m O}; @pxref{Simplification Modes}).
  1200. X
  1201. @item NumSimp
  1202. Default simplifications for numeric arguments only (@kbd{m N}).
  1203. X
  1204. @item BinSimp@var{w}
  1205. Binary-integer simplification mode; word size @var{w} (@kbd{m B}).
  1206. X
  1207. @item AlgSimp
  1208. Algebraic simplification mode (@kbd{m A}).
  1209. X
  1210. @item ExtSimp
  1211. Extended algebraic simplification mode (@kbd{m E}).
  1212. X
  1213. @item UnitSimp
  1214. Units simplification mode (@kbd{m U}).
  1215. X
  1216. @item Bin
  1217. Current radix is 2 (@kbd{d 2}; @pxref{Radix Modes}).
  1218. X
  1219. @item Oct
  1220. Current radix is 8 (@kbd{d 8}).
  1221. X
  1222. @item Hex
  1223. Current radix is 16 (@kbd{d 6}).
  1224. X
  1225. @item Radix@var{n}
  1226. Current radix is @var{n} (@kbd{d r}).
  1227. X
  1228. @item Zero
  1229. Leading zeros (@kbd{d z}; @pxref{Radix Modes}).
  1230. X
  1231. @item Flat
  1232. One-line normal language mode (@kbd{d O}; @pxref{Normal Language Modes}).
  1233. X
  1234. @item Big
  1235. Big language mode (@kbd{d B}).
  1236. X
  1237. @item Unform
  1238. Unformatted language mode (@kbd{d U}).
  1239. X
  1240. @item C
  1241. C language mode (@kbd{d C}; @pxref{C FORTRAN Pascal}).
  1242. X
  1243. @item Pascal
  1244. Pascal language mode (@kbd{d P}).
  1245. X
  1246. @item Fortran
  1247. FORTRAN language mode (@kbd{d F}).
  1248. X
  1249. @item TeX
  1250. @TeX{} language mode (@kbd{d T}; @pxref{TeX Language Mode}).
  1251. X
  1252. @item Eqn
  1253. @dfn{Eqn} language mode (@kbd{d E}; @pxref{Eqn Language Mode}).
  1254. X
  1255. @item Math
  1256. Mathematica language mode (@kbd{d M}; @pxref{Mathematica Language Mode}).
  1257. X
  1258. @item Maple
  1259. Maple language mode (@kbd{d W}; @pxref{Maple Language Mode}).
  1260. X
  1261. @item Norm@var{n}
  1262. Normal float mode with @var{n} digits (@kbd{d n}; @pxref{Float Formats}).
  1263. X
  1264. @item Fix@var{n}
  1265. Fixed point mode with @var{n} digits after the point (@kbd{d f}).
  1266. X
  1267. @item Sci
  1268. Scientific notation mode (@kbd{d s}).
  1269. X
  1270. @item Sci@var{n}
  1271. Scientific notation with @var{n} digits (@kbd{d s}).
  1272. X
  1273. @item Eng
  1274. Engineering notation mode (@kbd{d e}).
  1275. X
  1276. @item Eng@var{n}
  1277. Engineering notation with @var{n} digits (@kbd{d e}).
  1278. X
  1279. @item Left@var{n}
  1280. Left-justified display indented by @var{n} (@kbd{d <}; @pxref{Justification}).
  1281. X
  1282. @item Right
  1283. Right-justified display (@kbd{d >}).
  1284. X
  1285. @item Right@var{n}
  1286. Right-justified display with width @var{n} (@kbd{d >}).
  1287. X
  1288. @item Center
  1289. Centered display (@kbd{d =}).
  1290. X
  1291. @item Center@var{n}
  1292. Centered display with center column @var{n} (@kbd{d =}).
  1293. X
  1294. @item Wid@var{n}
  1295. Line breaking with width @var{n} (@kbd{d b}; @pxref{Normal Language Modes}).
  1296. X
  1297. @item Wide
  1298. No line breaking (@kbd{d b}).
  1299. X
  1300. @item Break
  1301. Selections show deep structure (@kbd{j b}; @pxref{Making Selections}).
  1302. X
  1303. @item Save
  1304. Record modes in @file{~/.emacs} (@kbd{m R}; @pxref{General Mode Commands}).
  1305. X
  1306. @item Local
  1307. Record modes in Embedded buffer (@kbd{m R}).
  1308. X
  1309. @item LocEdit
  1310. Record modes as editing-only in Embedded buffer (@kbd{m R}).
  1311. X
  1312. @item LocPerm
  1313. Record modes as permanent-only in Embedded buffer (@kbd{m R}).
  1314. X
  1315. @item Global
  1316. Record modes as global in Embedded buffer (@kbd{m R}).
  1317. X
  1318. @item Manual
  1319. Automatic recomputation turned off (@kbd{m C}; @pxref{Automatic
  1320. Recomputation}).
  1321. X
  1322. @item Graph
  1323. GNUPLOT process is alive in background (@pxref{Graphics}).
  1324. X
  1325. @item Sel
  1326. Top-of-stack has a selection (Embedded only; @pxref{Making Selections}).
  1327. X
  1328. @item Dirty
  1329. The stack display may not be up-to-date (@pxref{Display Modes}).
  1330. X
  1331. @item Inv
  1332. ``Inverse'' prefix was pressed (@kbd{I}; @pxref{Inverse and Hyperbolic}).
  1333. X
  1334. @item Hyp
  1335. ``Hyperbolic'' prefix was pressed (@kbd{H}).
  1336. X
  1337. @item Keep
  1338. ``Keep-arguments'' prefix was pressed (@kbd{K}).
  1339. X
  1340. @item Narrow
  1341. Stack is truncated (@kbd{d t}; @pxref{Truncating the Stack}).
  1342. @end table
  1343. X
  1344. In addition, the symbols @code{Active} and @code{~Active} can appear
  1345. as minor modes on an Embedded buffer's mode line.  @xref{Embedded Mode}.
  1346. X
  1347. @node Arithmetic, Scientific Functions, Mode Settings, Top
  1348. @chapter Arithmetic Functions
  1349. X
  1350. @noindent
  1351. This chapter describes the Calc commands for doing simple calculations
  1352. on numbers, such as addition, absolute value, and square roots.  These
  1353. commands work by removing the top one or two values from the stack,
  1354. performing the desired operation, and pushing the result back onto the
  1355. stack.  If the operation cannot be performed, the result pushed is a
  1356. formula instead of a number, such as @samp{2/0} (because division by zero
  1357. is illegal) or @samp{sqrt(x)} (because the argument @samp{x} is a formula).
  1358. X
  1359. Most of the commands described here can be invoked by a single keystroke.
  1360. Some of the more obscure ones are two-letter sequences beginning with
  1361. the @kbd{f} (``functions'') prefix key.
  1362. X
  1363. @xref{Prefix Arguments}, for a discussion of the effect of numeric
  1364. prefix arguments on commands in this chapter which do not otherwise
  1365. interpret a prefix argument.
  1366. X
  1367. @menu
  1368. * Basic Arithmetic::
  1369. * Integer Truncation::
  1370. * Complex Number Functions::
  1371. * Conversions::
  1372. * Date Arithmetic::
  1373. * Financial Functions::
  1374. * Binary Functions::
  1375. @end menu
  1376. X
  1377. @node Basic Arithmetic, Integer Truncation, Arithmetic, Arithmetic
  1378. @section Basic Arithmetic
  1379. X
  1380. @noindent
  1381. @kindex +
  1382. @pindex calc-plus
  1383. @tindex +
  1384. The @kbd{+} (@code{calc-plus}) command adds two numbers.  The numbers may
  1385. be any of the standard Calc data types.  The resulting sum is pushed back
  1386. onto the stack.
  1387. X
  1388. If both arguments of @kbd{+} are vectors or matrices (of matching dimensions),
  1389. the result is a vector or matrix sum.  If one argument is a vector and the
  1390. other a scalar (i.e., a non-vector), the scalar is added to each of the
  1391. elements of the vector to form a new vector.  If the scalar is not a
  1392. number, the operation is left in symbolic form:  Suppose you added @samp{x}
  1393. to the vector @samp{[1,2]}.  You may want the result @samp{[1+x,2+x]}, or
  1394. you may plan to substitute a 2-vector for @samp{x} in the future.  Since
  1395. the Calculator can't tell which interpretation you want, it makes the
  1396. safest assumption.  @xref{Reducing and Mapping}, for a way to add @samp{x}
  1397. to every element of a vector.
  1398. X
  1399. If either argument of @kbd{+} is a complex number, the result will in general
  1400. be complex.  If one argument is in rectangular form and the other polar,
  1401. the current Polar Mode determines the form of the result.  If Symbolic
  1402. Mode is enabled, the sum may be left as a formula if the necessary
  1403. conversions for polar addition are non-trivial.
  1404. X
  1405. If both arguments of @kbd{+} are HMS forms, the forms are added according to
  1406. the usual conventions of hours-minutes-seconds notation.  If one argument
  1407. is an HMS form and the other is a number, that number is converted from
  1408. degrees or radians (depending on the current Angular Mode) to HMS format
  1409. and then the two HMS forms are added.
  1410. X
  1411. If one argument of @kbd{+} is a date form, the other can be either a
  1412. real number, which advances the date by a certain number of days, or
  1413. an HMS form, which advances the date by a certain amount of time.
  1414. Subtracting two date forms yields the number of days between them.
  1415. Adding two date forms is meaningless, but Calc interprets it as the
  1416. subtraction of one date form and the negative of the other.  (The
  1417. negative of a date form can be understood by remembering that dates
  1418. are stored as the number of days before or after Jan 1, 1 AD.)
  1419. X
  1420. If both arguments of @kbd{+} are error forms, the result is an error form
  1421. with an appropriately computed standard deviation.  If one argument is an
  1422. error form and the other is a number, the number is taken to have zero error.
  1423. Error forms may have symbolic formulas as their mean and/or error parts;
  1424. adding these will produce a symbolic error form result.  However, adding an
  1425. error form to a plain symbolic formula (as in @samp{(a +/- b) + c}) will not
  1426. work, for the same reasons just mentioned for vectors.  Instead you must
  1427. write @samp{(a +/- b) + (c +/- 0)}.
  1428. X
  1429. If both arguments of @kbd{+} are modulo forms with equal values of @cite{M},
  1430. or if one argument is a modulo form and the other a plain number, the
  1431. result is a modulo form which represents the sum, modulo @cite{M}, of
  1432. the two values.
  1433. X
  1434. If both arguments of @kbd{+} are intervals, the result is an interval
  1435. which describes all possible sums of the possible input values.  If one
  1436. argument is a plain number, it is treated as the interval @samp{[x ..@: x]}.
  1437. X
  1438. If one argument of @kbd{+} is an infinity and the other is not, the
  1439. result is that same infinity.  If both arguments are infinite and in
  1440. the same direction, the result is the same infinity, but if they are
  1441. infinite in different directions the result is @code{nan}.
  1442. X
  1443. @kindex -
  1444. @pindex calc-minus
  1445. @tindex -
  1446. The @kbd{-} (@code{calc-minus}) command subtracts two values.  The top
  1447. number on the stack is subtracted from the one behind it, so that the
  1448. computation @kbd{5 @key{RET} 2 -} produces 3, not @i{-3}.  All options
  1449. available for @kbd{+} are available for @kbd{-} as well.
  1450. X
  1451. @kindex *
  1452. @pindex calc-times
  1453. @tindex *
  1454. The @kbd{*} (@code{calc-times}) command multiplies two numbers.  If one
  1455. argument is a vector and the other a scalar, the scalar is multiplied by
  1456. the elements of the vector to produce a new vector.  If both arguments
  1457. are vectors, the interpretation depends on the dimensions of the
  1458. vectors:  If both arguments are matrices, a matrix multiplication is
  1459. done.  If one argument is a matrix and the other a plain vector, the
  1460. vector is interpreted as a row vector or column vector, whichever is
  1461. dimensionally correct.  If both arguments are plain vectors, the result
  1462. is a single scalar number which is the dot product of the two vectors.
  1463. X
  1464. If one argument of @kbd{*} is an HMS form and the other a number, the
  1465. HMS form is multiplied by that amount.  It is an error to multiply two
  1466. HMS forms together, or to attempt any multiplication involving date
  1467. forms.  Error forms, modulo forms, and intervals can be multiplied;
  1468. see the comments for addition of those forms.  When two error forms
  1469. or intervals are multiplied they are considered to be statistically
  1470. independent; thus, @samp{[-2 ..@: 3] * [-2 ..@: 3]} is @samp{[-6 ..@: 9]},
  1471. whereas @samp{[-2 ..@: 3] ^ 2} is @samp{[0 ..@: 9]}.
  1472. X
  1473. @kindex /
  1474. @pindex calc-divide
  1475. @tindex /
  1476. The @kbd{/} (@code{calc-divide}) command divides two numbers.  When
  1477. dividing a scalar @cite{B} by a square matrix @cite{A}, the computation
  1478. performed is @cite{B} times the inverse of @cite{A}.  This also occurs
  1479. if @cite{B} is itself a vector or matrix, in which case the effect is
  1480. to solve the set of linear equations represented by @cite{B}.  If @cite{B}
  1481. is a matrix with the same number of rows as @cite{A}, or a plain vector
  1482. (which is interpreted here as a column vector), then the equation
  1483. @cite{A X = B} is solved for the vector or matrix @cite{X}.  Otherwise,
  1484. if @cite{B} is a non-square matrix with the same number of @emph{columns}
  1485. as @cite{A}, the equation @cite{X A = B} is solved.  If you wish a vector
  1486. @cite{B} to be interpreted as a row vector to be solved as @cite{X A = B},
  1487. make it into a one-row matrix with @kbd{C-u 1 v p} first.  To force a
  1488. left-handed solution with a square matrix @cite{B}, transpose @cite{A} and
  1489. @cite{B} before dividing, then transpose the result.
  1490. X
  1491. HMS forms can be divided by real numbers or by other HMS forms.  Error
  1492. forms can be divided in any combination of ways.  Modulo forms where both
  1493. values and the modulo are integers can be divided to get an integer modulo
  1494. form result.  Intervals can be divided; dividing by an interval that
  1495. encompasses zero or has zero as a limit will result in an infinite
  1496. interval.
  1497. X
  1498. @kindex ^
  1499. @pindex calc-power
  1500. @tindex ^
  1501. The @kbd{^} (@code{calc-power}) command raises a number to a power.  If
  1502. the power is an integer, an exact result is computed using repeated
  1503. multiplications.  For non-integer powers, Calc uses Newton's method or
  1504. logarithms and exponentials.  Square matrices can be raised to integer
  1505. powers.  If either argument is an error (or interval or modulo) form,
  1506. the result is also an error (or interval or modulo) form.
  1507. X
  1508. @kindex I ^
  1509. @tindex nroot
  1510. If you press the @kbd{I} (inverse) key first, the @kbd{I ^} command
  1511. computes an Nth root:  @kbd{125 RET 3 I ^} computes the number 5.
  1512. SHAR_EOF
  1513. true || echo 'restore of calc.texinfo failed'
  1514. fi
  1515. echo 'End of  part 40'
  1516. echo 'File calc.texinfo is continued in part 41'
  1517. echo 41 > _shar_seq_.tmp
  1518. exit 0
  1519. exit 0 # Just in case...
  1520. -- 
  1521. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1522. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1523. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1524. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1525.