Mercurial > emacs
changeset 42512:07a33bb87f3a
Delete many TeX customizations, producing a style more consistent
with our other manuals and eliminating TeX errors.
Use @var instead of @i when appropriate.
Fix utilization of @key.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 03 Jan 2002 23:38:47 +0000 |
parents | 4fcd61c30d0a |
children | 22938e0c54b2 |
files | man/calc.texi |
diffstat | 1 files changed, 2912 insertions(+), 2476 deletions(-) [+] |
line wrap: on
line diff
--- a/man/calc.texi Thu Jan 03 21:28:16 2002 +0000 +++ b/man/calc.texi Thu Jan 03 23:38:47 2002 +0000 @@ -26,11 +26,7 @@ \gdef\citexxx#1{#1$\Etex} \global\let\oldxrefX=\xrefX \gdef\xrefX[#1]{\begingroup\let\cite=\dfn\oldxrefX[#1]\endgroup} -% -% Redefine @i{text} to be equivalent to @cite{text}, i.e., to use math mode. -% This looks the same in TeX but omits the surrounding ` ' in Info. -\global\let\i=\cite -% + % Redefine @c{tex-stuff} \n @whatever{info-stuff}. \gdef\c{\futurelet\next\mycxxx} \gdef\mycxxx{% @@ -62,110 +58,18 @@ @iftex @finalout @mathcode`@:=`@: @c Make Calc fractions come out right in math mode -@tocindent=.5pc @c Indent subsections in table of contents less -@rightskip=0pt plus 2pt @c Favor short lines rather than overfull hboxes @tex \gdef\coloneq{\mathrel{\mathord:\mathord=}} -\ifdim\parskip>17pt - \global\parskip=12pt % Standard parskip looks a bit too large -\fi -\gdef\internalBitem{\parskip=7pt\kyhpos=\tableindent\kyvpos=0pt -\smallbreak\parsearg\itemzzy} -\gdef\itemzzy#1{\itemzzz{#1}\relax\ifvmode\kern-7pt\fi} -\gdef\trademark{${}^{\rm TM}$} -\gdef\group{% - \par\vskip8pt\begingroup - \def\Egroup{\egroup\endgroup}% - \let\aboveenvbreak=\relax % so that nothing gets between vtop and first box - \def\singlespace{\baselineskip=\singlespaceskip}% - \vtop\bgroup -} -% -%\global\abovedisplayskip=0pt -%\global\abovedisplayshortskip=-10pt -%\global\belowdisplayskip=7pt -%\global\belowdisplayshortskip=2pt + \gdef\beforedisplay{\vskip-10pt} \gdef\afterdisplay{\vskip-5pt} \gdef\beforedisplayh{\vskip-25pt} \gdef\afterdisplayh{\vskip-10pt} -% -\gdef\printindex{\parsearg\calcprintindex} -\gdef\calcprintindex#1{% - \doprintindex{#1}% - \openin1 \jobname.#1s - \ifeof1{\let\s=\indexskip \csname indexsize#1\endcsname}\fi - \closein1 -} -\gdef\indexskip{(This page intentionally left blank)\vfill\eject} -\gdef\indexsizeky{\s\s\s\s\s\s\s\s} -\gdef\indexsizepg{\s\s\s\s\s\s} -\gdef\indexsizetp{\s\s\s\s\s\s} -\gdef\indexsizecp{\s\s\s\s} -\gdef\indexsizevr{} -\gdef\indexsizefn{\s\s} -\gdef\langle#1\rangle{\it XXX} % Avoid length mismatch with true expansion -% -% Ensure no indentation at beginning of sections, and avoid club paragraphs. -\global\let\calcchapternofonts=\chapternofonts -\gdef\chapternofonts{\aftergroup\calcfixclub\calcchapternofonts} -\gdef\calcfixclub{\calcclubpenalty=10000\noindent} -\global\let\calcdobreak=\dobreak -\gdef\dobreak{{\penalty-9999\dimen0=\pagetotal\advance\dimen0by1.5in -\ifdim\dimen0>\pagegoal\vfill\eject\fi}\calcdobreak} -% -\gdef\kindex{\def\indexname{ky}\futurelet\next\calcindexer} -\gdef\tindex{\def\indexname{tp}\futurelet\next\calcindexer} -\gdef\mindex{\let\indexname\relax\futurelet\next\calcindexer} -\gdef\calcindexer{\catcode`\ =\active\parsearg\calcindexerxx} -\gdef\calcindexerxx#1{% - \catcode`\ =10% - \ifvmode \indent \fi \setbox0=\lastbox \advance\kyhpos\wd0 \fixoddpages \box0 - \setbox0=\hbox{\ninett #1}% - \calcindexersh{\llap{\hbox to 4em{\bumpoddpages\lower\kyvpos\box0\hss}\hskip\kyhpos}}% - \global\let\calcindexersh=\calcindexershow - \advance\clubpenalty by 5000% - \ifx\indexname\relax \else - \singlecodeindexer{#1\indexstar}% - \global\def\indexstar{}% - \fi - \futurelet\next\calcindexerxxx -} -\gdef\indexstar{} -\gdef\bumpoddpages{\ifodd\calcpageno\hskip7.3in\fi} -%\gdef\bumpoddpages{\hskip7.3in} % for marginal notes on right side always -%\gdef\bumpoddpages{} % for marginal notes on left side always -\gdef\fixoddpages{% -\global\calcpageno=\pageno -{\dimen0=\pagetotal -\advance\dimen0 by2\baselineskip -\ifdim\dimen0>\pagegoal -\global\advance\calcpageno by 1 -\vfill\eject\noindent -\fi}% -} -\gdef\calcindexershow#1{\smash{#1}\advance\kyvpos by 11pt} -\gdef\calcindexernoshow#1{} -\global\let\calcindexersh=\calcindexershow -\gdef\calcindexerxxx{% - \ifx\indexname\relax - \ifx\next\kindex \global\let\calcindexersh=\calcindexernoshow \fi - \ifx\next\tindex \global\let\calcindexersh=\calcindexernoshow \fi - \fi - \calcindexerxxxx -} -\gdef\calcindexerxxxx#1{\next} -\gdef\indexstarxx{\thinspace{\rm *}} -\gdef\starindex{\global\let\indexstar=\indexstarxx} -\gdef\calceverypar{% -\kyhpos=\leftskip\kyvpos=0pt\clubpenalty=\calcclubpenalty -\calcclubpenalty=1000\relax -} -\gdef\idots{{\indrm...}} @end tex @newdimen@kyvpos @kyvpos=0pt @newdimen@kyhpos @kyhpos=0pt @newcount@calcclubpenalty @calcclubpenalty=1000 +@ignore @newcount@calcpageno @newtoks@calcoldeverypar @calcoldeverypar=@everypar @everypar={@calceverypar@the@calcoldeverypar} @@ -174,6 +78,7 @@ @catcode`@\=0 \catcode`\@=11 \r@ggedbottomtrue \catcode`\@=0 @catcode`@\=@active +@end ignore @end iftex @ifinfo @@ -574,7 +479,7 @@ @item Number theoretical features such as prime factorization and arithmetic -modulo @i{M} for any @i{M}. +modulo @var{m} for any @var{m}. @item Algebraic manipulation features, including symbolic calculus. @@ -601,8 +506,6 @@ first few sections of the tutorial. As you become more comfortable with the program you can learn its additional features. In terms of efficiency, scope and depth, Calc cannot replace a powerful tool like Mathematica. -@c Removed this per RMS' request: -@c Mathematica@c{\trademark} @asis{ (tm)}. But Calc has the advantages of convenience, portability, and availability of the source code. And, of course, it's free! @@ -691,10 +594,10 @@ the @kbd{C-j} and @kbd{C-i} keys are equivalent to them, respectively. If you don't have a Meta key, look for Alt or Extend Char. You can also press @key{ESC} or @key{C-[} first to get the same effect, so -that @kbd{M-x}, @kbd{ESC x}, and @kbd{C-[ x} are all equivalent.) +that @kbd{M-x}, @kbd{@key{ESC} x}, and @kbd{C-[ x} are all equivalent.) Sometimes the @key{RET} key is not shown when it is ``obvious'' -that you must press @kbd{RET} to proceed. For example, the @key{RET} +that you must press @key{RET} to proceed. For example, the @key{RET} is usually omitted in key sequences like @kbd{M-x calc-keypad @key{RET}}. Commands are generally shown like this: @kbd{p} (@code{calc-precision}) @@ -722,19 +625,19 @@ Tutorial. To begin, start Emacs if necessary (usually the command @code{emacs} -does this), and type @kbd{M-# c} (or @kbd{ESC # c}) to start the +does this), and type @kbd{M-# c} (or @kbd{@key{ESC} # c}) to start the Calculator. (@xref{Starting Calc}, if this doesn't work for you.) Be sure to type all the sample input exactly, especially noting the difference between lower-case and upper-case letters. Remember, -@kbd{RET}, @kbd{TAB}, @kbd{DEL}, and @kbd{SPC} are the Return, Tab, +@key{RET}, @key{TAB}, @key{DEL}, and @key{SPC} are the Return, Tab, Delete, and Space keys. @strong{RPN calculation.} In RPN, you type the input number(s) first, then the command to operate on the numbers. @noindent -Type @kbd{2 RET 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$} +Type @kbd{2 @key{RET} 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$} @asis{the square root of 2+3, which is 2.2360679775}. @noindent @@ -742,30 +645,30 @@ @asis{the value of `pi' squared, 9.86960440109}. @noindent -Type @kbd{TAB} to exchange the order of these two results. +Type @key{TAB} to exchange the order of these two results. @noindent Type @kbd{- I H S} to subtract these results and compute the Inverse Hyperbolic sine of the difference, 2.72996136574. @noindent -Type @kbd{DEL} to erase this result. +Type @key{DEL} to erase this result. @strong{Algebraic calculation.} You can also enter calculations using conventional ``algebraic'' notation. To enter an algebraic formula, use the apostrophe key. @noindent -Type @kbd{' sqrt(2+3) RET} to compute @c{$\sqrt{2+3}$} +Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$} @asis{the square root of 2+3}. @noindent -Type @kbd{' pi^2 RET} to enter @c{$\pi^2$} +Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$} @asis{`pi' squared}. To evaluate this symbolic formula as a number, type @kbd{=}. @noindent -Type @kbd{' arcsinh($ - $$) RET} to subtract the second-most-recent +Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent result from the most-recent and compute the Inverse Hyperbolic sine. @strong{Keypad mode.} If you are using the X window system, press @@ -791,19 +694,19 @@ @strong{Grabbing data.} Type @kbd{M-# x} if necessary to exit Calc. Now select the following numbers as an Emacs region: ``Mark'' the -front of the list by typing control-@kbd{SPC} or control-@kbd{@@} there, +front of the list by typing @kbd{C-@key{SPC}} or @kbd{C-@@} there, then move to the other end of the list. (Either get this list from the on-line copy of this manual, accessed by @w{@kbd{M-# i}}, or just type these numbers into a scratch file.) Now type @kbd{M-# g} to ``grab'' these numbers into Calc. -@group -@example +@example +@group 1.23 1.97 1.6 2 1.19 1.08 -@end example -@end group +@end group +@end example @noindent The result @samp{[1.23, 1.97, 1.6, 2, 1.19, 1.08]} is a Calc ``vector.'' @@ -823,23 +726,23 @@ @asis{3x2} matrix into a @c{$2\times3$} @asis{2x3} matrix. Type @w{@kbd{v u}} to unpack the rows into two separate vectors. Now type -@w{@kbd{V R + TAB V R +}} to compute the sums of the two original columns. +@w{@kbd{V R + @key{TAB} V R +}} to compute the sums of the two original columns. (There is also a special grab-and-sum-columns command, @kbd{M-# :}.) @strong{Units conversion.} Units are entered algebraically. -Type @w{@kbd{' 43 mi/hr RET}} to enter the quantity 43 miles-per-hour. -Type @w{@kbd{u c km/hr RET}}. Type @w{@kbd{u c m/s RET}}. +Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour. +Type @w{@kbd{u c km/hr @key{RET}}}. Type @w{@kbd{u c m/s @key{RET}}}. @strong{Date arithmetic.} Type @kbd{t N} to get the current date and time. Type @kbd{90 +} to find the date 90 days from now. Type -@kbd{' <25 dec 87> RET} to enter a date, then @kbd{- 7 /} to see how +@kbd{' <25 dec 87> @key{RET}} to enter a date, then @kbd{- 7 /} to see how many weeks have passed since then. @strong{Algebra.} Algebraic entries can also include formulas -or equations involving variables. Type @kbd{@w{' [x + y} = a, x y = 1] RET} +or equations involving variables. Type @kbd{@w{' [x + y} = a, x y = 1] @key{RET}} to enter a pair of equations involving three variables. (Note the leading apostrophe in this example; also, note that the space -between @samp{x y} is required.) Type @w{@kbd{a S x,y RET}} to solve +between @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve these equations for the variables @cite{x} and @cite{y}.@refill @noindent @@ -849,25 +752,25 @@ Type @kbd{d N} to return to normal notation. @noindent -Type @kbd{7.5}, then @kbd{s l a RET} to let @cite{a = 7.5} in these formulas. +Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @cite{a = 7.5} in these formulas. (That's a letter @kbd{l}, not a numeral @kbd{1}.) @iftex @strong{Help functions.} You can read about any command in the on-line manual. Type @kbd{M-# c} to return to Calc after each of these commands: @kbd{h k t N} to read about the @kbd{t N} command, -@kbd{h f sqrt RET} to read about the @code{sqrt} function, and +@kbd{h f sqrt @key{RET}} to read about the @code{sqrt} function, and @kbd{h s} to read the Calc summary. @end iftex @ifinfo @strong{Help functions.} You can read about any command in the on-line manual. Remember to type the letter @kbd{l}, then @kbd{M-# c}, to return here after each of these commands: @w{@kbd{h k t N}} to read -about the @w{@kbd{t N}} command, @kbd{h f sqrt RET} to read about the +about the @w{@kbd{t N}} command, @kbd{h f sqrt @key{RET}} to read about the @code{sqrt} function, and @kbd{h s} to read the Calc summary. @end ifinfo -Press @kbd{DEL} repeatedly to remove any leftover results from the stack. +Press @key{DEL} repeatedly to remove any leftover results from the stack. To exit from Calc, press @kbd{q} or @kbd{M-# c} again. @node Using Calc, History and Acknowledgements, Demonstration of Calc, Getting Started @@ -951,11 +854,11 @@ to start the Calculator, the Emacs screen splits into two windows with the file you were editing on top and Calc on the bottom. -@group @iftex @advance@hsize20pt @end iftex @smallexample +@group ... --**-Emacs: myfile (Fundamental)----All---------------------- @@ -968,8 +871,8 @@ | ->-5 | --%%-Calc: 12 Deg (Calculator)----All----- --%%-Emacs: *Calc Trail* -@end smallexample -@end group +@end group +@end smallexample In this figure, the mode-line for @file{myfile} has moved up and the ``Calculator'' window has appeared below it. As you can see, Calc @@ -1185,15 +1088,15 @@ editing buffer. Suppose you have a formula written as part of a document like this: -@group -@smallexample +@smallexample +@group The derivative of ln(ln(x)) is -@end smallexample -@end group +@end group +@end smallexample @noindent and you wish to have Calc compute and format the derivative for @@ -1201,8 +1104,8 @@ do this with Embedded Mode, first copy the formula down to where you want the result to be: -@group -@smallexample +@smallexample +@group The derivative of ln(ln(x)) @@ -1210,8 +1113,8 @@ is ln(ln(x)) -@end smallexample -@end group +@end group +@end smallexample Now, move the cursor onto this new formula and press @kbd{M-# e}. Calc will read the formula (using the surrounding blank lines to @@ -1224,8 +1127,8 @@ you get is copied from the stack back into the buffer. To take the derivative, you would type @kbd{a d x @key{RET}}. -@group -@smallexample +@smallexample +@group The derivative of ln(ln(x)) @@ -1233,14 +1136,14 @@ is 1 / ln(x) x -@end smallexample -@end group +@end group +@end smallexample To make this look nicer, you might want to press @kbd{d =} to center the formula, and even @kbd{d B} to use ``big'' display mode. -@group -@smallexample +@smallexample +@group The derivative of ln(ln(x)) @@ -1252,8 +1155,8 @@ 1 ------- ln(x) x -@end smallexample -@end group +@end group +@end smallexample Calc has added annotations to the file to help it remember the modes that were used for this formula. They are formatted like comments @@ -1263,10 +1166,10 @@ of the way.) As an extra flourish, we can add an equation number using a -righthand label: Type @kbd{d @} (1) RET}. - -@group -@smallexample +righthand label: Type @kbd{d @} (1) @key{RET}}. + +@smallexample +@group % [calc-mode: justify: center] % [calc-mode: language: big] % [calc-mode: right-label: " (1)"] @@ -1274,8 +1177,8 @@ 1 ------- (1) ln(x) x -@end smallexample -@end group +@end group +@end smallexample To leave Embedded Mode, type @kbd{M-# e} again. The mode line and keyboard will revert to the way they were before. (If you have @@ -1384,7 +1287,6 @@ @sp 2 @end iftex -@group @noindent Commands for moving data into and out of the Calculator: @@ -1407,9 +1309,7 @@ @iftex @sp 2 @end iftex -@end group - -@group + @noindent Commands for use with Embedded Mode: @@ -1441,9 +1341,7 @@ @iftex @sp 2 @end iftex -@end group - -@group + @noindent Miscellaneous commands: @@ -1463,7 +1361,7 @@ are loaded only as they are needed.) @item M -Read a region of written keystroke names (like @samp{C-n a b c RET}) +Read a region of written keystroke names (like @kbd{C-n a b c @key{RET}}) and record them as the current keyboard macro. @item 0 @@ -1471,7 +1369,6 @@ its default state: Empty stack, and default mode settings. With any prefix argument, reset everything but the stack. @end table -@end group @node History and Acknowledgements, , Using Calc, Getting Started @section History and Acknowledgements @@ -1724,15 +1621,15 @@ and pushes the result (5) back onto the stack. Here's how the stack will look at various points throughout the calculation:@refill -@group -@smallexample +@smallexample +@group . 1: 2 2: 2 1: 5 . . 1: 3 . . - M-# c 2 RET 3 RET + DEL -@end smallexample -@end group + M-# c 2 @key{RET} 3 @key{RET} + @key{DEL} +@end group +@end smallexample The @samp{.} symbol is a marker that represents the top of the stack. Note that the ``top'' of the stack is really shown at the bottom of @@ -1769,15 +1666,15 @@ Examples in this tutorial will often omit @key{RET} even when the stack displays shown would only happen if you did press @key{RET}: -@group -@smallexample +@smallexample +@group 1: 2 2: 2 1: 5 . 1: 3 . . - 2 RET 3 + -@end smallexample -@end group + 2 @key{RET} 3 + +@end group +@end smallexample @noindent Here, after pressing @kbd{3} the stack would really show @samp{1: 2} @@ -1830,15 +1727,15 @@ If you press @key{RET} when you're not entering a number, the effect is to duplicate the top number on the stack. Consider this calculation: -@group -@smallexample +@smallexample +@group 1: 3 2: 3 1: 9 2: 9 1: 81 . 1: 3 . 1: 9 . . . - 3 RET RET * RET * -@end smallexample -@end group + 3 @key{RET} @key{RET} * @key{RET} * +@end group +@end smallexample @noindent (Of course, an easier way to do this would be @kbd{3 @key{RET} 4 ^}, @@ -1854,44 +1751,44 @@ to get 5, and then you realize what you really wanted to compute was @cite{20 / (2+3)}. -@group -@smallexample +@smallexample +@group 1: 5 2: 5 2: 20 1: 4 . 1: 20 1: 5 . . . - 2 RET 3 + 20 TAB / -@end smallexample -@end group + 2 @key{RET} 3 + 20 @key{TAB} / +@end group +@end smallexample @noindent Planning ahead, the calculation would have gone like this: -@group -@smallexample +@smallexample +@group 1: 20 2: 20 3: 20 2: 20 1: 4 . 1: 2 2: 2 1: 5 . . 1: 3 . . - 20 RET 2 RET 3 + / -@end smallexample -@end group + 20 @key{RET} 2 @key{RET} 3 + / +@end group +@end smallexample A related stack command is @kbd{M-@key{TAB}} (hold @key{META} and type @key{TAB}). It rotates the top three elements of the stack upward, bringing the object in level 3 to the top. -@group -@smallexample +@smallexample +@group 1: 10 2: 10 3: 10 3: 20 3: 30 . 1: 20 2: 20 2: 30 2: 10 . 1: 30 1: 10 1: 20 . . . - 10 RET 20 RET 30 RET M-TAB M-TAB -@end smallexample -@end group + 10 @key{RET} 20 @key{RET} 30 @key{RET} M-@key{TAB} M-@key{TAB} +@end group +@end smallexample (@bullet{}) @strong{Exercise 3.} Suppose the numbers 10, 20, and 30 are on the stack. Figure out how to add one to the number in level 2 @@ -1903,15 +1800,15 @@ @kbd{Q} (square root) pop a single number and push the result. You can think of them as simply operating on the top element of the stack. -@group -@smallexample +@smallexample +@group 1: 3 1: 9 2: 9 1: 25 1: 5 . . 1: 16 . . . - 3 RET RET * 4 RET RET * + Q -@end smallexample -@end group + 3 @key{RET} @key{RET} * 4 @key{RET} @key{RET} * + Q +@end group +@end smallexample @noindent (Note that capital @kbd{Q} means to hold down the Shift key while @@ -1923,41 +1820,41 @@ @kbd{f h}, but let's suppose we can't remember the necessary keystrokes. We can still enter it by its full name using @kbd{M-x} notation: -@group -@smallexample +@smallexample +@group 1: 3 2: 3 1: 5 . 1: 4 . . - 3 RET 4 RET M-x calc-hypot -@end smallexample -@end group + 3 @key{RET} 4 @key{RET} M-x calc-hypot +@end group +@end smallexample All Calculator commands begin with the word @samp{calc-}. Since it gets tiring to type this, Calc provides an @kbd{x} key which is just like the regular Emacs @kbd{M-x} key except that it types the @samp{calc-} prefix for you: -@group -@smallexample +@smallexample +@group 1: 3 2: 3 1: 5 . 1: 4 . . - 3 RET 4 RET x hypot -@end smallexample -@end group + 3 @key{RET} 4 @key{RET} x hypot +@end group +@end smallexample What happens if you take the square root of a negative number? -@group -@smallexample +@smallexample +@group 1: 4 1: -4 1: (0, 2) . . . - 4 RET n Q -@end smallexample -@end group + 4 @key{RET} n Q +@end group +@end smallexample @noindent The notation @cite{(a, b)} represents a complex number. @@ -1975,29 +1872,29 @@ Complex numbers are entered in the notation shown. The @kbd{(} and @kbd{,} and @kbd{)} keys manipulate ``incomplete complex numbers.'' -@group -@smallexample +@smallexample +@group 1: ( ... 2: ( ... 1: (2, ... 1: (2, ... 1: (2, 3) . 1: 2 . 3 . . . ( 2 , 3 ) -@end smallexample -@end group +@end group +@end smallexample You can perform calculations while entering parts of incomplete objects. However, an incomplete object cannot actually participate in a calculation: -@group -@smallexample +@smallexample +@group 1: ( ... 2: ( ... 3: ( ... 1: ( ... 1: ( ... . 1: 2 2: 2 5 5 . 1: 3 . . . (error) - ( 2 RET 3 + + -@end smallexample -@end group + ( 2 @key{RET} 3 + + +@end group +@end smallexample @noindent Adding 5 to an incomplete object makes no sense, so the last command @@ -2006,16 +1903,16 @@ Incomplete objects can't participate in arithmetic, but they can be moved around by the regular stack commands. -@group -@smallexample +@smallexample +@group 2: 2 3: 2 3: 3 1: ( ... 1: (2, 3) 1: 3 2: 3 2: ( ... 2 . . 1: ( ... 1: 2 3 . . . -2 RET 3 RET ( M-TAB M-TAB ) -@end smallexample -@end group +2 @key{RET} 3 @key{RET} ( M-@key{TAB} M-@key{TAB} ) +@end group +@end smallexample @noindent Note that the @kbd{,} (comma) key did not have to be used here. @@ -2041,16 +1938,16 @@ prefix arguments in a variety of ways. For example, a numeric prefix on the @kbd{+} operator adds any number of stack entries at once: -@group -@smallexample +@smallexample +@group 1: 10 2: 10 3: 10 3: 10 1: 60 . 1: 20 2: 20 2: 20 . . 1: 30 1: 30 . . - 10 RET 20 RET 30 RET C-u 3 + -@end smallexample -@end group + 10 @key{RET} 20 @key{RET} 30 @key{RET} C-u 3 + +@end group +@end smallexample For stack manipulation commands like @key{RET}, a positive numeric prefix argument operates on the top @var{n} stack entries at once. A @@ -2058,21 +1955,21 @@ argument of zero operates on the entire stack. In this example, we copy the second-to-top element of the stack: -@group -@smallexample +@smallexample +@group 1: 10 2: 10 3: 10 3: 10 4: 10 . 1: 20 2: 20 2: 20 3: 20 . 1: 30 1: 30 2: 30 . . 1: 20 . - 10 RET 20 RET 30 RET C-u -2 RET -@end smallexample -@end group + 10 @key{RET} 20 @key{RET} 30 @key{RET} C-u -2 @key{RET} +@end group +@end smallexample @cindex Clearing the stack @cindex Emptying the stack -Another common idiom is @kbd{M-0 DEL}, which clears the stack. +Another common idiom is @kbd{M-0 @key{DEL}}, which clears the stack. (The @kbd{M-0} numeric prefix tells @key{DEL} to operate on the entire stack.) @@ -2117,14 +2014,14 @@ or, in large mathematical notation, @ifinfo -@group -@example +@example +@group 3 * 4 * 5 2 + --------- - 9 8 6 * 7 -@end example -@end group +@end group +@end example @end ifinfo @tex \turnoffactive @@ -2180,15 +2077,15 @@ Still in algebraic mode, type: -@group -@smallexample +@smallexample +@group 1: (2, 3) 2: (2, 3) 1: (8, -1) 2: (8, -1) 1: (9, -1) . 1: (1, -2) . 1: 1 . . . - (2,3) RET (1,-2) RET * 1 RET + -@end smallexample -@end group + (2,3) @key{RET} (1,-2) @key{RET} * 1 @key{RET} + +@end group +@end smallexample Algebraic mode allows us to enter complex numbers without pressing an apostrophe first, but it also means we need to press @key{RET} @@ -2218,14 +2115,14 @@ which on a traditional calculator would be done by pressing @kbd{2 * 4 + 1 =} and then the square-root key. -@group -@smallexample +@smallexample +@group 1: 8 1: 9 1: 3 . . . - ' 2*4 RET $+1 RET Q -@end smallexample -@end group + ' 2*4 @key{RET} $+1 @key{RET} Q +@end group +@end smallexample @noindent Notice that we didn't need to press an apostrophe for the @kbd{$+1}, @@ -2237,7 +2134,7 @@ @xref{Algebraic Answer 1, 1}. (@bullet{}) The notations @kbd{$$}, @kbd{$$$}, and so on stand for higher stack -entries. For example, @kbd{' $$+$ RET} is just like typing @kbd{+}. +entries. For example, @kbd{' $$+$ @key{RET}} is just like typing @kbd{+}. Algebraic formulas can include @dfn{variables}. To store in a variable, press @kbd{s s}, then type the variable name, then press @@ -2247,14 +2144,14 @@ stores it in the variable.) A variable name should consist of one or more letters or digits, beginning with a letter. -@group -@smallexample +@smallexample +@group 1: 17 . 1: a + a^2 1: 306 . . . - 17 s t a RET ' a+a^2 RET = -@end smallexample -@end group + 17 s t a @key{RET} ' a+a^2 @key{RET} = +@end group +@end smallexample @noindent The @kbd{=} key @dfn{evaluates} a formula by replacing all its @@ -2264,16 +2161,16 @@ stack either by entering its name as a formula and pressing @kbd{=}, or by using the @kbd{s r} command. -@group -@smallexample +@smallexample +@group 1: 17 2: 17 3: 17 2: 17 1: 306 . 1: 17 2: 17 1: 289 . . 1: 2 . . - s r a RET ' a RET = 2 ^ + -@end smallexample -@end group + s r a @key{RET} ' a @key{RET} = 2 ^ + +@end group +@end smallexample If you press a single digit for a variable name (as in @kbd{s t 3}, you get one of ten @dfn{quick variables} @code{q0} through @code{q9}. @@ -2285,26 +2182,26 @@ Any variables in an algebraic formula for which you have not stored values are left alone, even when you evaluate the formula. -@group -@smallexample +@smallexample +@group 1: 2 a + 2 b 1: 34 + 2 b . . - ' 2a+2b RET = -@end smallexample -@end group + ' 2a+2b @key{RET} = +@end group +@end smallexample Calls to function names which are undefined in Calc are also left alone, as are calls for which the value is undefined. -@group -@smallexample +@smallexample +@group 1: 2 + log10(0) + log10(x) + log10(5, 6) + foo(3) . - ' log10(100) + log10(0) + log10(x) + log10(5,6) + foo(3) RET -@end smallexample -@end group + ' log10(100) + log10(0) + log10(x) + log10(5,6) + foo(3) @key{RET} +@end group +@end smallexample @noindent In this example, the first call to @code{log10} works, but the other @@ -2341,15 +2238,15 @@ between them. The lefthand formula is exactly like you typed it; the righthand formula has been evaluated as if by typing @kbd{=}. -@group -@smallexample +@smallexample +@group 2: 2 + 3 => 5 2: 2 + 3 => 5 1: 2 a + 2 b => 34 + 2 b 1: 2 a + 2 b => 20 + 2 b . . -' 2+3 => RET ' 2a+2b RET s = 10 s t a RET -@end smallexample -@end group +' 2+3 => @key{RET} ' 2a+2b @key{RET} s = 10 s t a @key{RET} +@end group +@end smallexample @noindent Notice that the instant we stored a new value in @code{a}, all @@ -2360,15 +2257,15 @@ You can also ``unstore'' a variable when you are through with it: -@group -@smallexample +@smallexample +@group 2: 2 + 5 => 5 1: 2 a + 2 b => 2 a + 2 b . - s u a RET -@end smallexample -@end group + s u a @key{RET} +@end group +@end smallexample We will encounter formulas involving variables and functions again when we discuss the algebra and calculus features of the Calculator. @@ -2378,46 +2275,46 @@ @noindent If you make a mistake, you can usually correct it by pressing shift-@kbd{U}, -the ``undo'' command. First, clear the stack (@kbd{M-0 DEL}) and exit +the ``undo'' command. First, clear the stack (@kbd{M-0 @key{DEL}}) and exit and restart Calc (@kbd{M-# M-# M-# M-#}) to make sure things start off with a clean slate. Now: -@group -@smallexample +@smallexample +@group 1: 2 2: 2 1: 8 2: 2 1: 6 . 1: 3 . 1: 3 . . . - 2 RET 3 ^ U * -@end smallexample -@end group + 2 @key{RET} 3 ^ U * +@end group +@end smallexample You can undo any number of times. Calc keeps a complete record of all you have done since you last opened the Calc window. After the above example, you could type: -@group -@smallexample +@smallexample +@group 1: 6 2: 2 1: 2 . . . 1: 3 . . (error) U U U U -@end smallexample -@end group +@end group +@end smallexample You can also type @kbd{D} to ``redo'' a command that you have undone mistakenly. -@group -@smallexample +@smallexample +@group . 1: 2 2: 2 1: 6 1: 6 . 1: 3 . . . (error) D D D D -@end smallexample -@end group +@end group +@end smallexample @noindent It was not possible to redo past the @cite{6}, since that was placed there @@ -2540,13 +2437,13 @@ then entering a suitable number. Try pressing @kbd{p 30 @key{RET}}, then doing @kbd{1 @key{RET} 7 /} again: -@group -@smallexample +@smallexample +@group 1: 0.142857142857 2: 0.142857142857142857142857142857 . -@end smallexample -@end group +@end group +@end smallexample Although the precision can be set arbitrarily high, Calc always has to have @emph{some} value for the current precision. After @@ -2564,14 +2461,14 @@ key didn't round the number, because it doesn't do any calculation. But the instant we pressed @kbd{+}, the number was rounded down. -@group -@smallexample +@smallexample +@group 1: 0.142857142857 2: 0.142857142857142857142857142857 3: 1.14285714286 . -@end smallexample -@end group +@end group +@end smallexample @noindent In fact, since we added a digit on the left, we had to lose one @@ -2595,15 +2492,15 @@ Let's try entering that last calculation: -@group -@smallexample +@smallexample +@group 1: 2. 2: 2. 1: 1.99506311689e3010 . 1: 10000 . . - 2.0 RET 10000 RET ^ -@end smallexample -@end group + 2.0 @key{RET} 10000 @key{RET} ^ +@end group +@end smallexample @noindent @cindex Scientific notation, entry of @@ -2612,15 +2509,15 @@ number out fully would introduce more extra zeros than you probably want to see. You can enter numbers in this notation, too. -@group -@smallexample +@smallexample +@group 1: 2. 2: 2. 1: 1.99506311678e3010 . 1: 10000. . . - 2.0 RET 1e4 RET ^ -@end smallexample -@end group + 2.0 @key{RET} 1e4 @key{RET} ^ +@end group +@end smallexample @cindex Round-off errors @noindent @@ -2635,15 +2532,15 @@ one should we trust? Let's raise the precision a bit and find out: -@group -@smallexample +@smallexample +@group . 1: 2. 2: 2. 1: 1.995063116880828e3010 . 1: 10000. . . - p 16 RET 2. RET 1e4 ^ p 12 RET -@end smallexample -@end group + p 16 @key{RET} 2. @key{RET} 1e4 ^ p 12 @key{RET} +@end group +@end smallexample @noindent @cindex Guard digits @@ -2672,11 +2569,11 @@ supply a numeric prefix argument which says how many digits should be displayed. As an example, let's put a few numbers onto the stack and try some different display modes. First, -use @kbd{M-0 DEL} to clear the stack, then enter the four +use @kbd{M-0 @key{DEL}} to clear the stack, then enter the four numbers shown here: -@group -@smallexample +@smallexample +@group 4: 12345 4: 12345 4: 12345 4: 12345 4: 12345 3: 12345. 3: 12300. 3: 1.2345e4 3: 1.23e4 3: 12345.000 2: 123.45 2: 123. 2: 1.2345e2 2: 1.23e2 2: 123.450 @@ -2684,8 +2581,8 @@ . . . . . d n M-3 d n d s M-3 d s M-3 d f -@end smallexample -@end group +@end group +@end smallexample @noindent Notice that when we typed @kbd{M-3 d n}, the numbers were rounded down @@ -2706,23 +2603,23 @@ prevent it from updating the stack. Anything Calc displays after the mode-changing command will appear in the new format. -@group -@smallexample +@smallexample +@group 4: 12345 4: 12345 4: 12345 4: 12345 4: 12345 3: 12345.000 3: 12345.000 3: 12345.000 3: 1.2345e4 3: 12345. 2: 123.450 2: 123.450 2: 1.2345e1 2: 1.2345e1 2: 123.45 1: 12.345 1: 1.2345e1 1: 1.2345e2 1: 1.2345e2 1: 12.345 . . . . . - H d s DEL U TAB d SPC d n -@end smallexample -@end group + H d s @key{DEL} U @key{TAB} d @key{SPC} d n +@end group +@end smallexample @noindent Here the @kbd{H d s} command changes to scientific notation but without updating the screen. Deleting the top stack entry and undoing it back causes it to show up in the new format; swapping the top two stack -entries reformats both entries. The @kbd{d SPC} command refreshes the +entries reformats both entries. The @kbd{d @key{SPC}} command refreshes the whole stack. The @kbd{d n} command changes back to the normal float format; since it doesn't have an @kbd{H} prefix, it also updates all the stack entries to be in @kbd{d n} format. @@ -2864,14 +2761,14 @@ a command that interprets a number as an angle, it will assume the angle is measured in degrees. For example, -@group -@smallexample +@smallexample +@group 1: 45 1: 0.707106781187 1: 0.500000000001 1: 0.5 . . . . 45 S 2 ^ c 1 -@end smallexample -@end group +@end group +@end smallexample @noindent The shift-@kbd{S} command computes the sine of an angle. The sine @@ -2898,26 +2795,26 @@ again, this is a shifted capital @kbd{P}. Remember, unshifted @kbd{p} sets the precision.) -@group -@smallexample +@smallexample +@group 1: 3.14159265359 1: 0.785398163398 1: 0.707106781187 . . . P 4 / m r S -@end smallexample -@end group +@end group +@end smallexample Likewise, inverse trigonometric functions generate results in either radians or degrees, depending on the current angular mode. -@group -@smallexample +@smallexample +@group 1: 0.707106781187 1: 0.785398163398 1: 45. . . . .5 Q m r I S m d U I S -@end smallexample -@end group +@end group +@end smallexample @noindent Here we compute the Inverse Sine of @c{$\sqrt{0.5}$} @@ -2927,14 +2824,14 @@ Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees and vice-versa. -@group -@smallexample +@smallexample +@group 1: 45 1: 0.785398163397 1: 45. . . . 45 c r c d -@end smallexample -@end group +@end group +@end smallexample Another interesting mode is @dfn{fraction mode}. Normally, dividing two integers produces a floating-point result if the @@ -2942,15 +2839,15 @@ causes integer division to produce a fraction, i.e., a rational number, instead. -@group -@smallexample +@smallexample +@group 2: 12 1: 1.33333333333 1: 4:3 1: 9 . . . - 12 RET 9 / m f U / m f -@end smallexample -@end group + 12 @key{RET} 9 / m f U / m f +@end group +@end smallexample @noindent In the first case, we get an approximate floating-point result. @@ -2975,14 +2872,14 @@ evaluates-to operator you can get commands like @kbd{m f} to recompute for you. -@group -@smallexample +@smallexample +@group 1: 12 / 9 => 1.33333333333 1: 12 / 9 => 1.333 1: 12 / 9 => 4:3 . . . - ' 12/9 => RET p 4 RET m f -@end smallexample -@end group + ' 12/9 => @key{RET} p 4 @key{RET} m f +@end group +@end smallexample @noindent In this example, the righthand side of the @samp{=>} operator @@ -3003,14 +2900,14 @@ and pushes back a result. The @kbd{n} and @kbd{&} keys perform change-sign and reciprocal operations, respectively. -@group -@smallexample +@smallexample +@group 1: 5 1: 0.2 1: 5. 1: -5. 1: 5. . . . . . 5 & & n n -@end smallexample -@end group +@end group +@end smallexample @cindex Binary operators You can apply a ``binary operator'' like @kbd{+} across any number of @@ -3018,32 +2915,32 @@ pairwise to several stack elements along with the top one if you use a negative prefix. -@group -@smallexample +@smallexample +@group 3: 2 1: 9 3: 2 4: 2 3: 12 2: 3 . 2: 3 3: 3 2: 13 1: 4 1: 4 2: 4 1: 14 . . 1: 10 . . -2 RET 3 RET 4 M-3 + U 10 M-- M-3 + -@end smallexample -@end group +2 @key{RET} 3 @key{RET} 4 M-3 + U 10 M-- M-3 + +@end group +@end smallexample @cindex Unary operators You can apply a ``unary operator'' like @kbd{&} to the top @var{n} stack entries with a numeric prefix, too. -@group -@smallexample +@smallexample +@group 3: 2 3: 0.5 3: 0.5 2: 3 2: 0.333333333333 2: 3. 1: 4 1: 0.25 1: 4. . . . -2 RET 3 RET 4 M-3 & M-2 & -@end smallexample -@end group +2 @key{RET} 3 @key{RET} 4 M-3 & M-2 & +@end group +@end smallexample Notice that the results here are left in floating-point form. We can convert them back to integers by pressing @kbd{F}, the @@ -3051,8 +2948,8 @@ integer. There is also @kbd{R}, which rounds to the nearest integer. -@group -@smallexample +@smallexample +@group 7: 2. 7: 2 7: 2 6: 2.4 6: 2 6: 2 5: 2.5 5: 2 5: 3 @@ -3063,8 +2960,8 @@ . . . M-7 F U M-7 R -@end smallexample -@end group +@end group +@end smallexample Since dividing-and-flooring (i.e., ``integer quotient'') is such a common operation, Calc provides a special command for that purpose, the @@ -3072,27 +2969,27 @@ computes the remainder that would arise from a @kbd{\} operation, i.e., the ``modulo'' of two numbers. For example, -@group -@smallexample +@smallexample +@group 2: 1234 1: 12 2: 1234 1: 34 1: 100 . 1: 100 . . . -1234 RET 100 \ U % -@end smallexample -@end group +1234 @key{RET} 100 \ U % +@end group +@end smallexample These commands actually work for any real numbers, not just integers. -@group -@smallexample +@smallexample +@group 2: 3.1415 1: 3 2: 3.1415 1: 0.1415 1: 1 . 1: 1 . . . -3.1415 RET 1 \ U % -@end smallexample -@end group +3.1415 @key{RET} 1 \ U % +@end group +@end smallexample (@bullet{}) @strong{Exercise 1.} The @kbd{\} command would appear to be a frill, since you could always do the same thing with @kbd{/ F}. Think @@ -3112,15 +3009,15 @@ arbitrarily pick @i{-64} degrees as a good value for @cite{x}. With the angular mode set to degrees (type @w{@kbd{m d}}), do: -@group -@smallexample +@smallexample +@group 2: -64 2: -64 2: -0.89879 2: -0.89879 1: 1. 1: -64 1: -0.89879 1: -64 1: 0.43837 . . . . . - 64 n RET RET S TAB C f h -@end smallexample -@end group + 64 n @key{RET} @key{RET} S @key{TAB} C f h +@end group +@end smallexample @noindent (For brevity, we're showing only five digits of the results here. @@ -3131,31 +3028,31 @@ Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} @cite{tan(x) = sin(x) / cos(x)}. -@group -@smallexample +@smallexample +@group 2: -0.89879 1: -2.0503 1: -64. 1: 0.43837 . . . U / I T -@end smallexample -@end group +@end group +@end smallexample A physical interpretation of this calculation is that if you move @cite{0.89879} units downward and @cite{0.43837} units to the right, your direction of motion is @i{-64} degrees from horizontal. Suppose we move in the opposite direction, up and to the left: -@group -@smallexample +@smallexample +@group 2: -0.89879 2: 0.89879 1: -2.0503 1: -64. 1: 0.43837 1: -0.43837 . . . . U U M-2 n / I T -@end smallexample -@end group +@end group +@end smallexample @noindent How can the angle be the same? The answer is that the @kbd{/} operation @@ -3166,16 +3063,16 @@ Since you feed it the two original numbers, it has enough information to give you a full 360-degree answer. -@group -@smallexample +@smallexample +@group 2: 0.89879 1: 116. 3: 116. 2: 116. 1: 180. 1: -0.43837 . 2: -0.89879 1: -64. . . 1: 0.43837 . . - U U f T M-RET M-2 n f T - -@end smallexample -@end group + U U f T M-@key{RET} M-2 n f T - +@end group +@end smallexample @noindent The resulting angles differ by 180 degrees; in other words, they @@ -3196,15 +3093,15 @@ @cite{cosh(x)^2 - sinh(x)^2} that always equals one. Let's try to verify this identity.@refill -@group -@smallexample +@smallexample +@group 2: -64 2: -64 2: -64 2: 9.7192e54 2: 9.7192e54 1: -64 1: -3.1175e27 1: 9.7192e54 1: -64 1: 9.7192e54 . . . . . - 64 n RET RET H C 2 ^ TAB H S 2 ^ -@end smallexample -@end group + 64 n @key{RET} @key{RET} H C 2 ^ @key{TAB} H S 2 ^ +@end group +@end smallexample @noindent @cindex Roundoff errors, examples @@ -3228,14 +3125,14 @@ @cite{e} normally but use base-10 instead if you use the Hyperbolic prefix. -@group -@smallexample +@smallexample +@group 1: 1000 1: 6.9077 1: 1000 1: 3 . . . . 1000 L U H L -@end smallexample -@end group +@end group +@end smallexample @noindent First, we mistakenly compute a natural logarithm. Then we undo @@ -3244,15 +3141,15 @@ The @kbd{B} key computes a general base-@var{b} logarithm for any value of @var{b}. -@group -@smallexample +@smallexample +@group 2: 1000 1: 3 1: 1000. 2: 1000. 1: 6.9077 1: 10 . . 1: 2.71828 . . . - 1000 RET 10 B H E H P B -@end smallexample -@end group + 1000 @key{RET} 10 B H E H P B +@end group +@end smallexample @noindent Here we first use @kbd{B} to compute the base-10 logarithm, then use @@ -3280,14 +3177,14 @@ and statistics. You may be familiar with the @dfn{factorial} function, which computes the product of all the integers up to a given number. -@group -@smallexample +@smallexample +@group 1: 100 1: 93326215443... 1: 100. 1: 9.3326e157 . . . . 100 ! U c f ! -@end smallexample -@end group +@end group +@end smallexample @noindent Recall, the @kbd{c f} command converts the integer or fraction at the @@ -3303,16 +3200,16 @@ @cite{gamma(n)} (which is itself available as the @kbd{f g} command). -@group -@smallexample +@smallexample +@group 3: 4. 3: 24. 1: 5.5 1: 52.342777847 2: 4.5 2: 52.3427777847 . . 1: 5. 1: 120. . . - M-3 ! M-0 DEL 5.5 f g -@end smallexample -@end group + M-3 ! M-0 @key{DEL} 5.5 f g +@end group +@end smallexample @noindent Here we verify the identity @c{$n! = \Gamma(n+1)$} @@ -3331,15 +3228,15 @@ combinatorics and number theory. Here we compute the binomial coefficient 30-choose-20, then determine its prime factorization. -@group -@smallexample +@smallexample +@group 2: 30 1: 30045015 1: [3, 3, 5, 7, 11, 13, 23, 29] 1: 20 . . . - 30 RET 20 k c k f -@end smallexample -@end group + 30 @key{RET} 20 k c k f +@end group +@end smallexample @noindent You can verify these prime factors by using @kbd{v u} to ``unpack'' @@ -3352,14 +3249,14 @@ 10000 entries. It's best to use a prime number as the actual size of a hash table. Calc can compute the next prime number after 10000: -@group -@smallexample +@smallexample +@group 1: 10000 1: 10007 1: 9973 . . . 10000 k n I k n -@end smallexample -@end group +@end group +@end smallexample @noindent Just for kicks we've also computed the next prime @emph{less} than @@ -3396,15 +3293,15 @@ If you add two vectors, the result is a vector of the sums of the elements, taken pairwise. -@group -@smallexample +@smallexample +@group 1: [1, 2, 3] 2: [1, 2, 3] 1: [8, 8, 3] . 1: [7, 6, 0] . . [1,2,3] s 1 [7 6 0] s 2 + -@end smallexample -@end group +@end group +@end smallexample @noindent Note that we can separate the vector elements with either commas or @@ -3416,15 +3313,15 @@ of the elements taken pairwise. This is called the @dfn{dot product} of the vectors. -@group -@smallexample +@smallexample +@group 2: [1, 2, 3] 1: 19 1: [7, 6, 0] . . r 1 r 2 * -@end smallexample -@end group +@end group +@end smallexample @cindex Dot product The dot product of two vectors is equal to the product of their @@ -3434,16 +3331,16 @@ (absolute value) command can be used to compute the length of a vector. -@group -@smallexample +@smallexample +@group 3: 19 3: 19 1: 0.550782 1: 56.579 2: [1, 2, 3] 2: 3.741657 . . 1: [7, 6, 0] 1: 9.219544 . . - M-RET M-2 A * / I C -@end smallexample -@end group + M-@key{RET} M-2 A * / I C +@end group +@end smallexample @noindent First we recall the arguments to the dot product command, then @@ -3462,16 +3359,16 @@ defined only for three-dimensional vectors. Let's double-check our computation of the angle using the cross product. -@group -@smallexample +@smallexample +@group 2: [1, 2, 3] 3: [-18, 21, -8] 1: [-0.52, 0.61, -0.23] 1: 56.579 1: [7, 6, 0] 2: [1, 2, 3] . . . 1: [7, 6, 0] . - r 1 r 2 V C s 3 M-RET M-2 A * / A I S -@end smallexample -@end group + r 1 r 2 V C s 3 M-@key{RET} M-2 A * / A I S +@end group +@end smallexample @noindent First we recall the original vectors and compute their cross product, @@ -3490,15 +3387,15 @@ to get zero, since the cosine of 90 degrees is zero. Let's check that the cross product is indeed perpendicular to both inputs: -@group -@smallexample +@smallexample +@group 2: [1, 2, 3] 1: 0 2: [7, 6, 0] 1: 0 1: [-18, 21, -8] . 1: [-18, 21, -8] . . . - r 1 r 3 * DEL r 2 r 3 * -@end smallexample -@end group + r 1 r 3 * @key{DEL} r 2 r 3 * +@end group +@end smallexample @cindex Normalizing a vector @cindex Unit vectors @@ -3523,15 +3420,15 @@ also use the semicolon character to enter a matrix. We'll show both methods here: -@group -@smallexample +@smallexample +@group 1: [ [ 1, 2, 3 ] 1: [ [ 1, 2, 3 ] [ 4, 5, 6 ] ] [ 4, 5, 6 ] ] . . - [[1 2 3] [4 5 6]] ' [1 2 3; 4 5 6] RET -@end smallexample -@end group + [[1 2 3] [4 5 6]] ' [1 2 3; 4 5 6] @key{RET} +@end group +@end smallexample @noindent We'll be using this matrix again, so type @kbd{s 4} to save it now. @@ -3549,15 +3446,15 @@ If we try to duplicate this matrix and multiply it by itself, the dimensions are wrong and the multiplication cannot take place: -@group -@smallexample +@smallexample +@group 1: [ [ 1, 2, 3 ] * [ [ 1, 2, 3 ] [ 4, 5, 6 ] ] [ 4, 5, 6 ] ] . - RET * -@end smallexample -@end group + @key{RET} * +@end group +@end smallexample @noindent Though rather hard to read, this is a formula which shows the product @@ -3566,8 +3463,8 @@ We can multiply the matrices if we @dfn{transpose} one of them first. -@group -@smallexample +@smallexample +@group 2: [ [ 1, 2, 3 ] 1: [ [ 14, 32 ] 1: [ [ 17, 22, 27 ] [ 4, 5, 6 ] ] [ 32, 77 ] ] [ 22, 29, 36 ] 1: [ [ 1, 4 ] . [ 27, 36, 45 ] ] @@ -3575,9 +3472,9 @@ [ 3, 6 ] ] . - U v t * U TAB * -@end smallexample -@end group + U v t * U @key{TAB} * +@end group +@end smallexample Matrix multiplication is not commutative; indeed, switching the order of the operands can even change the dimensions of the result @@ -3588,16 +3485,16 @@ on. The result is a plain vector which should also be interpreted as a row or column as appropriate. -@group -@smallexample +@smallexample +@group 2: [ [ 1, 2, 3 ] 1: [14, 32] [ 4, 5, 6 ] ] . 1: [1, 2, 3] . r 4 r 1 * -@end smallexample -@end group +@end group +@end smallexample Multiplying in the other order wouldn't work because the number of rows in the matrix is different from the number of elements in the @@ -3615,8 +3512,8 @@ by an identity matrix, on the left or on the right, always produces the original matrix. -@group -@smallexample +@smallexample +@group 1: [ [ 1, 2, 3 ] 2: [ [ 1, 2, 3 ] 1: [ [ 1, 2, 3 ] [ 4, 5, 6 ] ] [ 4, 5, 6 ] ] [ 4, 5, 6 ] ] . 1: [ [ 1, 0, 0 ] . @@ -3624,25 +3521,25 @@ [ 0, 0, 1 ] ] . - r 4 v i 3 RET * -@end smallexample -@end group + r 4 v i 3 @key{RET} * +@end group +@end smallexample If a matrix is square, it is often possible to find its @dfn{inverse}, that is, a matrix which, when multiplied by the original matrix, yields an identity matrix. The @kbd{&} (reciprocal) key also computes the inverse of a matrix. -@group -@smallexample +@smallexample +@group 1: [ [ 1, 2, 3 ] 1: [ [ -2.4, 1.2, -0.2 ] [ 4, 5, 6 ] [ 2.8, -1.4, 0.4 ] [ 7, 6, 0 ] ] [ -0.73333, 0.53333, -0.2 ] ] . . r 4 r 2 | s 5 & -@end smallexample -@end group +@end group +@end smallexample @noindent The vertical bar @kbd{|} @dfn{concatenates} numbers, vectors, and @@ -3651,16 +3548,16 @@ We can multiply these two matrices in either order to get an identity. -@group -@smallexample +@smallexample +@group 1: [ [ 1., 0., 0. ] 1: [ [ 1., 0., 0. ] [ 0., 1., 0. ] [ 0., 1., 0. ] [ 0., 0., 1. ] ] [ 0., 0., 1. ] ] . . - M-RET * U TAB * -@end smallexample -@end group + M-@key{RET} * U @key{TAB} * +@end group +@end smallexample @cindex Systems of linear equations @cindex Linear equations, systems of @@ -3716,8 +3613,8 @@ We can solve this system of equations by multiplying both sides by the inverse of the matrix. Calc can do this all in one step: -@group -@smallexample +@smallexample +@group 2: [6, 2, 3] 1: [-12.6, 15.2, -3.93333] 1: [ [ 1, 2, 3 ] . [ 4, 5, 6 ] @@ -3725,8 +3622,8 @@ . [6,2,3] r 5 / -@end smallexample -@end group +@end group +@end smallexample @noindent The result is the @cite{[a, b, c]} vector that solves the equations. @@ -3735,17 +3632,17 @@ Let's verify this solution: -@group -@smallexample +@smallexample +@group 2: [ [ 1, 2, 3 ] 1: [6., 2., 3.] [ 4, 5, 6 ] . [ 7, 6, 0 ] ] 1: [-12.6, 15.2, -3.93333] . - r 5 TAB * -@end smallexample -@end group + r 5 @key{TAB} * +@end group +@end smallexample @noindent Note that we had to be careful about the order in which we multiplied @@ -3851,41 +3748,41 @@ You can pack and unpack stack entries into vectors: -@group -@smallexample +@smallexample +@group 3: 10 1: [10, 20, 30] 3: 10 2: 20 . 2: 20 1: 30 1: 30 . . M-3 v p v u -@end smallexample -@end group +@end group +@end smallexample You can also build vectors out of consecutive integers, or out of many copies of a given value: -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, 4] 2: [1, 2, 3, 4] 2: [1, 2, 3, 4] . 1: 17 1: [17, 17, 17, 17] . . - v x 4 RET 17 v b 4 RET -@end smallexample -@end group + v x 4 @key{RET} 17 v b 4 @key{RET} +@end group +@end smallexample You can apply an operator to every element of a vector using the @dfn{map} command. -@group -@smallexample +@smallexample +@group 1: [17, 34, 51, 68] 1: [289, 1156, 2601, 4624] 1: [17, 34, 51, 68] . . . V M * 2 V M ^ V M Q -@end smallexample -@end group +@end group +@end smallexample @noindent In the first step, we multiply the vector of integers by the vector @@ -3903,14 +3800,14 @@ For example, reducing @samp{*} computes the product of all the elements in the vector: -@group -@smallexample +@smallexample +@group 1: 123123 1: [3, 7, 11, 13, 41] 1: 123123 . . . 123123 k f V R * -@end smallexample -@end group +@end group +@end smallexample @noindent In this example, we decompose 123123 into its prime factors, then @@ -3919,15 +3816,15 @@ We could compute a dot product ``by hand'' using mapping and reduction: -@group -@smallexample +@smallexample +@group 2: [1, 2, 3] 1: [7, 12, 0] 1: 19 1: [7, 6, 0] . . . r 1 r 2 V M * V R + -@end smallexample -@end group +@end group +@end smallexample @noindent Recalling two vectors from the previous section, we compute the @@ -3938,14 +3835,14 @@ @kbd{V U}. This produces a vector of the intermediate results from a corresponding reduction. Here we compute a table of factorials: -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, 4, 5, 6] 1: [1, 2, 6, 24, 120, 720] . . - v x 6 RET V U * -@end smallexample -@end group + v x 6 @key{RET} V U * +@end group +@end smallexample Calc allows vectors to grow as large as you like, although it gets rather slow if vectors have more than about a hundred elements. @@ -3954,27 +3851,27 @@ (if your computer is very fast you may need to substitute a larger vector size). -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, 4, ... 1: [2, 3, 4, 5, ... . . - v x 500 RET 1 V M + -@end smallexample -@end group + v x 500 @key{RET} 1 V M + +@end group +@end smallexample Now press @kbd{v .} (the letter @kbd{v}, then a period) and try the experiment again. In @kbd{v .} mode, long vectors are displayed ``abbreviated'' like this: -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, ..., 500] 1: [2, 3, 4, ..., 501] . . - v x 500 RET 1 V M + -@end smallexample -@end group + v x 500 @key{RET} 1 V M + +@end group +@end smallexample @noindent (where now the @samp{...} is actually part of the Calc display). @@ -4032,20 +3929,20 @@ Position the cursor at the upper-left corner of this table, just to the left of the @cite{1.34}. Press @kbd{C-@@} to set the mark. -(On your system this may be @kbd{C-2}, @kbd{C-SPC}, or @kbd{NUL}.) +(On your system this may be @kbd{C-2}, @kbd{C-@key{SPC}}, or @kbd{NUL}.) Now position the cursor to the lower-right, just after the @cite{1.354}. You have now defined this region as an Emacs ``rectangle.'' Still in the Info buffer, type @kbd{M-# r}. This command (@code{calc-grab-rectangle}) will pop you back into the Calculator, with the contents of the rectangle you specified in the form of a matrix.@refill -@group -@smallexample +@smallexample +@group 1: [ [ 1.34, 0.234 ] [ 1.41, 0.298 ] @dots{} -@end smallexample -@end group +@end group +@end smallexample @noindent (You may wish to use @kbd{v .} mode to abbreviate the display of this @@ -4056,27 +3953,27 @@ just a vector of vectors. So we can unpack the matrix into a pair of row vectors on the stack. -@group -@smallexample +@smallexample +@group 1: [ [ 1.34, 1.41, 1.49, ... ] 2: [1.34, 1.41, 1.49, ... ] [ 0.234, 0.298, 0.402, ... ] ] 1: [0.234, 0.298, 0.402, ... ] . . v t v u -@end smallexample -@end group +@end group +@end smallexample @noindent Let's store these in quick variables 1 and 2, respectively. -@group -@smallexample +@smallexample +@group 1: [1.34, 1.41, 1.49, ... ] . . t 2 t 1 -@end smallexample -@end group +@end group +@end smallexample @noindent (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the @@ -4104,24 +4001,24 @@ sum a vector using a simple reduction. First, let's compute the four different sums that this formula uses. -@group -@smallexample +@smallexample +@group 1: 41.63 1: 98.0003 . . r 1 V R + t 3 r 1 2 V M ^ V R + t 4 -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: 13.613 1: 33.36554 . . r 2 V R + t 5 r 1 r 2 V M * V R + t 6 -@end smallexample -@end group +@end group +@end smallexample @ifinfo @noindent @@ -4139,41 +4036,41 @@ Finally, we also need @cite{N}, the number of data points. This is just the length of either of our lists. -@group -@smallexample +@smallexample +@group 1: 19 . r 1 v l t 7 -@end smallexample -@end group +@end group +@end smallexample @noindent (That's @kbd{v} followed by a lower-case @kbd{l}.) Now we grind through the formula: -@group -@smallexample +@smallexample +@group 1: 633.94526 2: 633.94526 1: 67.23607 . 1: 566.70919 . . r 7 r 6 * r 3 r 5 * - -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 2: 67.23607 3: 67.23607 2: 67.23607 1: 0.52141679 1: 1862.0057 2: 1862.0057 1: 128.9488 . . 1: 1733.0569 . . r 7 r 4 * r 3 2 ^ - / t 8 -@end smallexample -@end group +@end group +@end smallexample That gives us the slope @cite{m}. The y-intercept @cite{b} can now be found with the simple formula, @@ -4191,27 +4088,27 @@ \vskip10pt @end tex -@group -@smallexample +@smallexample +@group 1: 13.613 2: 13.613 1: -8.09358 1: -0.425978 . 1: 21.70658 . . . r 5 r 8 r 3 * - r 7 / t 9 -@end smallexample -@end group +@end group +@end smallexample Let's ``plot'' this straight line approximation, @c{$y \approx m x + b$} @cite{m x + b}, and compare it with the original data.@refill -@group -@smallexample +@smallexample +@group 1: [0.699, 0.735, ... ] 1: [0.273, 0.309, ... ] . . r 1 r 8 * r 9 + s 0 -@end smallexample -@end group +@end group +@end smallexample @noindent Notice that multiplying a vector by a constant, and adding a constant @@ -4222,14 +4119,14 @@ We can subtract this vector from our original @cite{y} vector to get a feel for the error of our fit. Let's find the maximum error: -@group -@smallexample +@smallexample +@group 1: [0.0387, 0.0112, ... ] 1: [0.0387, 0.0112, ... ] 1: 0.0897 . . . r 2 - V M A V R X -@end smallexample -@end group +@end group +@end smallexample @noindent First we compute a vector of differences, then we take the absolute @@ -4248,20 +4145,20 @@ kind of display you have. Some GNUPLOT 2.0, non-X-windows systems may require additional steps to view the graphs.) -Let's start by plotting the original data. Recall the ``@i{x}'' and ``@i{y}'' +Let's start by plotting the original data. Recall the ``@var{x}'' and ``@var{y}'' vectors onto the stack and press @kbd{g f}. This ``fast'' graphing command does everything you need to do for simple, straightforward plotting of data. -@group -@smallexample +@smallexample +@group 2: [1.34, 1.41, 1.49, ... ] 1: [0.234, 0.298, 0.402, ... ] . r 1 r 2 g f -@end smallexample -@end group +@end group +@end smallexample If all goes well, you will shortly get a new window containing a graph of the data. (If not, contact your GNUPLOT or Calc installer to find @@ -4272,15 +4169,15 @@ Next, let's add the line we got from our least-squares fit: -@group -@smallexample +@smallexample +@group 2: [1.34, 1.41, 1.49, ... ] 1: [0.273, 0.309, 0.351, ... ] . - DEL r 0 g a g p -@end smallexample -@end group + @key{DEL} r 0 g a g p +@end group +@end smallexample It's not very useful to get symbols to mark the data points on this second curve; you can type @kbd{g S g p} to remove them. Type @kbd{g q} @@ -4328,24 +4225,24 @@ for \cite{n=6}. @end tex -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, 4, 5, 6, 7] 1: [0, 1, 2, 3, 4, 5, 6] . . - v x 7 RET 1 - - -@end smallexample -@end group -@noindent -@group -@smallexample + v x 7 @key{RET} 1 - + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [1, -6, 15, -20, 15, -6, 1] 1: 0 . . - V M ' (-1)^$ choose(6,$) RET V R + -@end smallexample -@end group + V M ' (-1)^$ choose(6,$) @key{RET} V R + +@end group +@end smallexample The @kbd{V M '} command prompts you to enter any algebraic expression to define the function to map over the vector. The symbol @samp{$} @@ -4354,10 +4251,10 @@ substituting each element's value for the @samp{$} sign(s) in turn. To define a two-argument function, use @samp{$$} for the first -argument and @samp{$} for the second: @kbd{V M ' $$-$ RET} is +argument and @samp{$} for the second: @kbd{V M ' $$-$ @key{RET}} is equivalent to @kbd{V M -}. This is analogous to regular algebraic entry, where @samp{$$} would refer to the next-to-top stack entry -and @samp{$} would refer to the top stack entry, and @kbd{' $$-$ RET} +and @samp{$} would refer to the top stack entry, and @kbd{' $$-$ @key{RET}} would act exactly like @kbd{-}. Notice that the @kbd{V M '} command has recorded two things in the @@ -4414,32 +4311,32 @@ like the following diagram. (You may wish to use the @kbd{v /} command to enable multi-line display of vectors.) -@group -@smallexample +@smallexample +@group 1: [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6] ] -@end smallexample -@end group +@end group +@end smallexample @noindent @xref{List Answer 6, 6}. (@bullet{}) (@bullet{}) @strong{Exercise 7.} Build the following list of lists. -@group -@smallexample +@smallexample +@group 1: [ [0], [1, 2], [3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20] ] -@end smallexample -@end group +@end group +@end smallexample @noindent @xref{List Answer 7, 7}. (@bullet{}) @@ -4476,7 +4373,7 @@ is @c{$\pi$} @cite{pi}. The area of the @c{$2\times2$} @asis{2x2} square that encloses that -circle is 4. So if we throw @i{N} darts at random points in the square, +circle is 4. So if we throw @var{n} darts at random points in the square, about @c{$\pi/4$} @cite{pi/4} of them will land inside the circle. This gives us an entertaining way to estimate the value of @c{$\pi$} @@ -4549,15 +4446,15 @@ and are susceptible to roundoff error. Calc also supports @dfn{fractions}, which can exactly represent any rational number. -@group -@smallexample +@smallexample +@group 1: 3628800 2: 3628800 1: 518400:7 1: 518414:7 1: 7:518414 . 1: 49 . . . . - 10 ! 49 RET : 2 + & -@end smallexample -@end group + 10 ! 49 @key{RET} : 2 + & +@end group +@end smallexample @noindent The @kbd{:} command divides two integers to get a fraction; @kbd{/} @@ -4569,27 +4466,27 @@ You can convert between floating-point and fractional format using @kbd{c f} and @kbd{c F}: -@group -@smallexample +@smallexample +@group 1: 1.35027217629e-5 1: 7:518414 . . c f c F -@end smallexample -@end group +@end group +@end smallexample The @kbd{c F} command replaces a floating-point number with the ``simplest'' fraction whose floating-point representation is the same, to within the current precision. -@group -@smallexample +@smallexample +@group 1: 3.14159265359 1: 1146408:364913 1: 3.1416 1: 355:113 . . . . - P c F DEL p 5 RET P c F -@end smallexample -@end group + P c F @key{DEL} p 5 @key{RET} P c F +@end group +@end smallexample (@bullet{}) @strong{Exercise 1.} A calculation has produced the result 1.26508260337. You suspect it is the square root of the @@ -4599,14 +4496,14 @@ @dfn{Complex numbers} can be stored in both rectangular and polar form. -@group -@smallexample +@smallexample +@group 1: -9 1: (0, 3) 1: (3; 90.) 1: (6; 90.) 1: (2.4495; 45.) . . . . . 9 n Q c p 2 * Q -@end smallexample -@end group +@end group +@end smallexample @noindent The square root of @i{-9} is by default rendered in rectangular form @@ -4622,15 +4519,15 @@ real number. The word @code{inf} can only be input using algebraic entry. -@group -@smallexample +@smallexample +@group 2: inf 2: -inf 2: -inf 2: -inf 1: nan 1: -17 1: -inf 1: -inf 1: inf . . . . . -' inf RET 17 n * RET 72 + A + -@end smallexample -@end group +' inf @key{RET} 17 n * @key{RET} 72 + A + +@end group +@end smallexample @noindent Since infinity is infinitely large, multiplying it by any finite @@ -4651,16 +4548,16 @@ Calc to write an answer in terms of infinity by pressing @kbd{m i} to turn on ``infinite mode.'' -@group -@smallexample +@smallexample +@group 3: nan 2: nan 2: nan 2: nan 1: nan 2: 1 1: 1 / 0 1: uinf 1: uinf . 1: 0 . . . . - 1 RET 0 / m i U / 17 n * + -@end smallexample -@end group + 1 @key{RET} 0 / m i U / 17 n * + +@end group +@end smallexample @noindent Dividing by zero normally is left unevaluated, but after @kbd{m i} @@ -4694,27 +4591,27 @@ @dfn{HMS forms} represent a value in terms of hours, minutes, and seconds. -@group -@smallexample +@smallexample +@group 1: 2@@ 30' 0" 1: 3@@ 30' 0" 2: 3@@ 30' 0" 1: 2. . . 1: 1@@ 45' 0." . . - 2@@ 30' RET 1 + RET 2 / / -@end smallexample -@end group + 2@@ 30' @key{RET} 1 + @key{RET} 2 / / +@end group +@end smallexample HMS forms can also be used to hold angles in degrees, minutes, and seconds. -@group -@smallexample +@smallexample +@group 1: 0.5 1: 26.56505 1: 26@@ 33' 54.18" 1: 0.44721 . . . . 0.5 I T c h S -@end smallexample -@end group +@end group +@end smallexample @noindent First we convert the inverse tangent of 0.5 to degrees-minutes-seconds @@ -4732,15 +4629,15 @@ be entered using algebraic entry. Date forms are surrounded by @samp{< >} symbols; most standard formats for dates are recognized. -@group -@smallexample +@smallexample +@group 2: <Sun Jan 13, 1991> 1: 2.25 1: <6:00pm Thu Jan 10, 1991> . . -' <13 Jan 1991>, <1/10/91, 6pm> RET - -@end smallexample -@end group +' <13 Jan 1991>, <1/10/91, 6pm> @key{RET} - +@end group +@end smallexample @noindent In this example, we enter two dates, then subtract to find the @@ -4748,14 +4645,14 @@ HMS form or a number (of days) to a date form to get another date form. -@group -@smallexample +@smallexample +@group 1: <4:45:59pm Mon Jan 14, 1991> 1: <2:50:59am Thu Jan 17, 1991> . . t N 2 + 10@@ 5' + -@end smallexample -@end group +@end group +@end smallexample @c [fix-ref Date Arithmetic] @noindent @@ -4781,15 +4678,15 @@ meters. What is the slope of a line from here to the top of the pole, and what is the equivalent angle in degrees? -@group -@smallexample +@smallexample +@group 1: 8 +/- 0.2 2: 8 +/- 0.2 1: 0.266 +/- 0.011 1: 14.93 +/- 0.594 . 1: 30 +/- 1 . . . - 8 p .2 RET 30 p 1 / I T -@end smallexample -@end group + 8 p .2 @key{RET} 30 p 1 / I T +@end group +@end smallexample @noindent This means that the angle is about 15 degrees, and, assuming our @@ -4811,15 +4708,15 @@ our telephone pole is definitely between 28 and 31 meters away, and that it is between 7.7 and 8.1 meters tall. -@group -@smallexample +@smallexample +@group 1: [7.7 .. 8.1] 2: [7.7 .. 8.1] 1: [0.24 .. 0.28] 1: [13.9 .. 16.1] . 1: [28 .. 31] . . . [ 7.7 .. 8.1 ] [ 28 .. 31 ] / I T -@end smallexample -@end group +@end group +@end smallexample @noindent If our bounds were correct, then the angle to the top of the pole @@ -4833,15 +4730,15 @@ which is inclusive (``closed'') on one end and exclusive (``open'') on the other. -@group -@smallexample +@smallexample +@group 1: [1 .. 10) 1: (0.1 .. 1] 2: (0.1 .. 1] 1: (0.2 .. 3) . . 1: [2 .. 3) . . [ 1 .. 10 ) & [ 2 .. 3 ) * -@end smallexample -@end group +@end group +@end smallexample @noindent The Calculator automatically keeps track of which end values should @@ -4856,38 +4753,38 @@ @xref{Types Answer 8, 8}. (@bullet{}) (@bullet{}) @strong{Exercise 9.} Two easy ways of squaring a number -are @kbd{RET *} and @w{@kbd{2 ^}}. Normally these produce the same +are @kbd{@key{RET} *} and @w{@kbd{2 ^}}. Normally these produce the same answer. Would you expect this still to hold true for interval forms? If not, which of these will result in a larger interval? @xref{Types Answer 9, 9}. (@bullet{}) -A @dfn{modulo form} is used for performing arithmetic modulo @i{M}. +A @dfn{modulo form} is used for performing arithmetic modulo @var{m}. For example, arithmetic involving time is generally done modulo 12 or 24 hours. -@group -@smallexample +@smallexample +@group 1: 17 mod 24 1: 3 mod 24 1: 21 mod 24 1: 9 mod 24 . . . . - 17 M 24 RET 10 + n 5 / -@end smallexample -@end group + 17 M 24 @key{RET} 10 + n 5 / +@end group +@end smallexample @noindent In this last step, Calc has found a new number which, when multiplied -by 5 modulo 24, produces the original number, 21. If @i{M} is prime -it is always possible to find such a number. For non-prime @i{M} +by 5 modulo 24, produces the original number, 21. If @var{m} is prime +it is always possible to find such a number. For non-prime @var{m} like 24, it is only sometimes possible. -@group -@smallexample +@smallexample +@group 1: 10 mod 24 1: 16 mod 24 1: 1000000... 1: 16 . . . . - 10 M 24 RET 100 ^ 10 RET 100 ^ 24 % -@end smallexample -@end group + 10 M 24 @key{RET} 100 ^ 10 @key{RET} 100 ^ 24 % +@end group +@end smallexample @noindent These two calculations get the same answer, but the first one is @@ -4910,14 +4807,14 @@ For example, the @code{calc-time} command pushes the current time of day on the stack as an HMS/modulo form. -@group -@smallexample +@smallexample +@group 1: 17@@ 34' 45" mod 24@@ 0' 0" 1: 6@@ 22' 15" mod 24@@ 0' 0" . . - x time RET n -@end smallexample -@end group + x time @key{RET} n +@end group +@end smallexample @noindent This calculation tells me it is six hours and 22 minutes until midnight. @@ -4940,14 +4837,14 @@ suggestive names like @samp{cm} and @samp{in} to represent units like centimeters and inches. -@group -@smallexample +@smallexample +@group 1: 2 in 1: 5.08 cm 1: 0.027778 fath 1: 0.0508 m . . . . - ' 2in RET u c cm RET u c fath RET u b -@end smallexample -@end group + ' 2in @key{RET} u c cm @key{RET} u c fath @key{RET} u b +@end group +@end smallexample @noindent We enter the quantity ``2 inches'' (actually an algebraic expression @@ -4955,24 +4852,24 @@ first to centimeters, then to fathoms, then finally to ``base'' units, which in this case means meters. -@group -@smallexample +@smallexample +@group 1: 9 acre 1: 3 sqrt(acre) 1: 190.84 m 1: 190.84 m + 30 cm . . . . - ' 9 acre RET Q u s ' $+30 cm RET - -@end smallexample -@end group -@noindent -@group -@smallexample + ' 9 acre @key{RET} Q u s ' $+30 cm @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 191.14 m 1: 36536.3046 m^2 1: 365363046 cm^2 . . . u s 2 ^ u c cgs -@end smallexample -@end group +@end group +@end smallexample @noindent Since units expressions are really just formulas, taking the square @@ -4987,14 +4884,14 @@ There is a wide variety of units defined in the Calculator. -@group -@smallexample +@smallexample +@group 1: 55 mph 1: 88.5139 kph 1: 88.5139 km / hr 1: 8.201407e-8 c . . . . - ' 55 mph RET u c kph RET u c km/hr RET u c c RET -@end smallexample -@end group + ' 55 mph @key{RET} u c kph @key{RET} u c km/hr @key{RET} u c c @key{RET} +@end group +@end smallexample @noindent We express a speed first in miles per hour, then in kilometers per @@ -5008,14 +4905,14 @@ as well as a scale factor and so there must be two explicit commands for them. -@group -@smallexample +@smallexample +@group 1: 20 degF 1: 11.1111 degC 1: -20:3 degC 1: -6.666 degC . . . . - ' 20 degF RET u c degC RET U u t degC RET c f -@end smallexample -@end group + ' 20 degF @key{RET} u c degC @key{RET} U u t degC @key{RET} c f +@end group +@end smallexample @noindent First we convert a change of 20 degrees Fahrenheit into an equivalent @@ -5029,14 +4926,14 @@ When you use this method, you're responsible for remembering which numbers are in which units: -@group -@smallexample +@smallexample +@group 1: 55 1: 88.5139 1: 8.201407e-8 . . . - 55 u c mph RET kph RET u c km/hr RET c RET -@end smallexample -@end group + 55 u c mph @key{RET} kph @key{RET} u c km/hr @key{RET} c @key{RET} +@end group +@end smallexample To see a complete list of built-in units, type @kbd{u v}. Press @w{@kbd{M-# c}} again to re-enter the Calculator when you're done looking @@ -5079,30 +4976,30 @@ the formula itself is pushed onto the stack. You can manipulate formulas as regular data objects. -@group -@smallexample +@smallexample +@group 1: 2 x^2 - 6 1: 6 - 2 x^2 1: (6 - 2 x^2) (3 x^2 + y) . . . - ' 2x^2-6 RET n ' 3x^2+y RET * -@end smallexample -@end group - -(@bullet{}) @strong{Exercise 1.} Do @kbd{' x RET Q 2 ^} and -@kbd{' x RET 2 ^ Q} both wind up with the same result (@samp{x})? + ' 2x^2-6 @key{RET} n ' 3x^2+y @key{RET} * +@end group +@end smallexample + +(@bullet{}) @strong{Exercise 1.} Do @kbd{' x @key{RET} Q 2 ^} and +@kbd{' x @key{RET} 2 ^ Q} both wind up with the same result (@samp{x})? Why or why not? @xref{Algebra Answer 1, 1}. (@bullet{}) There are also commands for doing common algebraic operations on formulas. Continuing with the formula from the last example, -@group -@smallexample +@smallexample +@group 1: 18 x^2 + 6 y - 6 x^4 - 2 x^2 y 1: (18 - 2 y) x^2 - 6 x^4 + 6 y . . - a x a c x RET -@end smallexample -@end group + a x a c x @key{RET} +@end group +@end smallexample @noindent First we ``expand'' using the distributive law, then we ``collect'' @@ -5111,14 +5008,14 @@ Let's find the value of this expression when @cite{x} is 2 and @cite{y} is one-half. -@group -@smallexample +@smallexample +@group 1: 17 x^2 - 6 x^4 + 3 1: -25 . . - 1:2 s l y RET 2 s l x RET -@end smallexample -@end group + 1:2 s l y @key{RET} 2 s l x @key{RET} +@end group +@end smallexample @noindent The @kbd{s l} command means ``let''; it takes a number from the top of @@ -5129,7 +5026,7 @@ (An earlier exercise in this tutorial involved storing a value in the variable @code{x}; if this value is still there, you will have to -unstore it with @kbd{s u x RET} before the above example will work +unstore it with @kbd{s u x @key{RET}} before the above example will work properly.) @cindex Maximum of a function using Calculus @@ -5140,37 +5037,37 @@ derivative of the function at that value of @cite{x} is negative, the function has a local maximum there. -@group -@smallexample +@smallexample +@group 1: 17 x^2 - 6 x^4 + 3 1: 34 x - 24 x^3 . . - U DEL s 1 a d x RET s 2 -@end smallexample -@end group + U @key{DEL} s 1 a d x @key{RET} s 2 +@end group +@end smallexample @noindent Well, the derivative is clearly zero when @cite{x} is zero. To find the other root(s), let's divide through by @cite{x} and then solve: -@group -@smallexample +@smallexample +@group 1: (34 x - 24 x^3) / x 1: 34 x / x - 24 x^3 / x 1: 34 - 24 x^2 . . . - ' x RET / a x a s - -@end smallexample -@end group -@noindent -@group -@smallexample + ' x @key{RET} / a x a s + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 34 - 24 x^2 = 0 1: x = 1.19023 . . - 0 a = s 3 a S x RET -@end smallexample -@end group + 0 a = s 3 a S x @key{RET} +@end group +@end smallexample @noindent Notice the use of @kbd{a s} to ``simplify'' the formula. When the @@ -5179,31 +5076,31 @@ Now we compute the second derivative and plug in our values of @cite{x}: -@group -@smallexample +@smallexample +@group 1: 1.19023 2: 1.19023 2: 1.19023 . 1: 34 x - 24 x^3 1: 34 - 72 x^2 . . - a . r 2 a d x RET s 4 -@end smallexample -@end group + a . r 2 a d x @key{RET} s 4 +@end group +@end smallexample @noindent (The @kbd{a .} command extracts just the righthand side of an equation. Another method would have been to use @kbd{v u} to unpack the equation -@w{@samp{x = 1.19}} to @samp{x} and @samp{1.19}, then use @kbd{M-- M-2 DEL} +@w{@samp{x = 1.19}} to @samp{x} and @samp{1.19}, then use @kbd{M-- M-2 @key{DEL}} to delete the @samp{x}.) -@group -@smallexample +@smallexample +@group 2: 34 - 72 x^2 1: -68. 2: 34 - 72 x^2 1: 34 1: 1.19023 . 1: 0 . . . - TAB s l x RET U DEL 0 s l x RET -@end smallexample -@end group + @key{TAB} s l x @key{RET} U @key{DEL} 0 s l x @key{RET} +@end group +@end smallexample @noindent The first of these second derivatives is negative, so we know the function @@ -5218,14 +5115,14 @@ If it needs an arbitrary integer, it picks zero. We can get a full solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}. -@group -@smallexample +@smallexample +@group 1: 34 - 24 x^2 = 0 1: x = 1.19023 s1 1: x = -1.19023 . . . - r 3 H a S x RET s 5 1 n s l s1 RET -@end smallexample -@end group + r 3 H a S x @key{RET} s 5 1 n s l s1 @key{RET} +@end group +@end smallexample @noindent Calc has invented the variable @samp{s1} to represent an unknown sign; @@ -5237,15 +5134,15 @@ To find the actual maximum value, we must plug our two values of @cite{x} into the original formula. -@group -@smallexample +@smallexample +@group 2: 17 x^2 - 6 x^4 + 3 1: 24.08333 s1^2 - 12.04166 s1^4 + 3 1: x = 1.19023 s1 . . - r 1 r 5 s l RET -@end smallexample -@end group + r 1 r 5 s l @key{RET} +@end group +@end smallexample @noindent (Here we see another way to use @kbd{s l}; if its input is an equation @@ -5255,15 +5152,15 @@ It's clear that this will have the same value for either sign of @code{s1}, but let's work it out anyway, just for the exercise: -@group -@smallexample +@smallexample +@group 2: [-1, 1] 1: [15.04166, 15.04166] 1: 24.08333 s1^2 ... . . - [ 1 n , 1 ] TAB V M $ RET -@end smallexample -@end group + [ 1 n , 1 ] @key{TAB} V M $ @key{RET} +@end group +@end smallexample @noindent Here we have used a vector mapping operation to evaluate the function @@ -5301,20 +5198,20 @@ symbolic form rather than giving a floating-point approximate answer. Fraction mode (@kbd{m f}) is also useful when doing algebra. -@group -@smallexample +@smallexample +@group 2: 34 x - 24 x^3 2: 34 x - 24 x^3 1: 34 x - 24 x^3 1: [sqrt(51) / 6, sqrt(51) / -6, 0] . . - r 2 RET m s m f a P x RET -@end smallexample -@end group + r 2 @key{RET} m s m f a P x @key{RET} +@end group +@end smallexample One more mode that makes reading formulas easier is ``Big mode.'' -@group -@smallexample +@smallexample +@group 3 2: 34 x - 24 x @@ -5326,34 +5223,34 @@ . d B -@end smallexample -@end group +@end group +@end smallexample Here things like powers, square roots, and quotients and fractions are displayed in a two-dimensional pictorial form. Calc has other language modes as well, such as C mode, FORTRAN mode, and @TeX{} mode. -@group -@smallexample +@smallexample +@group 2: 34*x - 24*pow(x, 3) 2: 34*x - 24*x**3 1: @{sqrt(51) / 6, sqrt(51) / -6, 0@} 1: /sqrt(51) / 6, sqrt(51) / -6, 0/ . . d C d F -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 3: 34 x - 24 x^3 2: [@{\sqrt@{51@} \over 6@}, @{\sqrt@{51@} \over -6@}, 0] 1: @{2 \over 3@} \sqrt@{5@} . - d T ' 2 \sqrt@{5@} \over 3 RET -@end smallexample -@end group + d T ' 2 \sqrt@{5@} \over 3 @key{RET} +@end group +@end smallexample @noindent As you can see, language modes affect both entry and display of @@ -5375,27 +5272,27 @@ What is the area under the portion of this curve from @cite{x = 1} to @cite{2}? This is simply the integral of the function: -@group -@smallexample +@smallexample +@group 1: 17 x^2 - 6 x^4 + 3 1: 5.6666 x^3 - 1.2 x^5 + 3 x . . r 1 a i x -@end smallexample -@end group +@end group +@end smallexample @noindent We want to evaluate this at our two values for @cite{x} and subtract. One way to do it is again with vector mapping and reduction: -@group -@smallexample +@smallexample +@group 2: [2, 1] 1: [12.93333, 7.46666] 1: 5.46666 1: 5.6666 x^3 ... . . - [ 2 , 1 ] TAB V M $ RET V R - -@end smallexample -@end group + [ 2 , 1 ] @key{TAB} V M $ @key{RET} V R - +@end group +@end smallexample (@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @cite{y} of @c{$x \sin \pi x$} @@ -5407,7 +5304,7 @@ others are beyond its capabilities. Suppose we wish to find the area under the curve @c{$\sin x \ln x$} @cite{sin(x) ln(x)} over the same range of @cite{x}. If -you entered this formula and typed @kbd{a i x RET} (don't bother to try +you entered this formula and typed @kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a long time but would be unable to find a solution. In fact, there is no closed-form solution to this integral. Now what do we do? @@ -5419,40 +5316,40 @@ slow, though, since the sine and logarithm functions take a long time. We can save some time by reducing the working precision. -@group -@smallexample +@smallexample +@group 3: 10 1: [1, 1.1, 1.2, ... , 1.8, 1.9] 2: 1 . 1: 0.1 . - 10 RET 1 RET .1 RET C-u v x -@end smallexample -@end group + 10 @key{RET} 1 @key{RET} .1 @key{RET} C-u v x +@end group +@end smallexample @noindent (Note that we have used the extended version of @kbd{v x}; we could -also have used plain @kbd{v x} as follows: @kbd{v x 10 RET 9 + .1 *}.) - -@group -@smallexample +also have used plain @kbd{v x} as follows: @kbd{v x 10 @key{RET} 9 + .1 *}.) + +@smallexample +@group 2: [1, 1.1, ... ] 1: [0., 0.084941, 0.16993, ... ] 1: sin(x) ln(x) . . - ' sin(x) ln(x) RET s 1 m r p 5 RET V M $ RET - -@end smallexample -@end group -@noindent -@group -@smallexample + ' sin(x) ln(x) @key{RET} s 1 m r p 5 @key{RET} V M $ @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 3.4195 0.34195 . . V R + 0.1 * -@end smallexample -@end group +@end group +@end smallexample @noindent (If you got wildly different results, did you remember to switch @@ -5468,28 +5365,28 @@ The true value of this integral turns out to be about 0.374, so we're not doing too well. Let's try another approach. -@group -@smallexample +@smallexample +@group 1: sin(x) ln(x) 1: 0.84147 x - 0.84147 + 0.11957 (x - 1)^2 - ... . . - r 1 a t x=1 RET 4 RET -@end smallexample -@end group + r 1 a t x=1 @key{RET} 4 @key{RET} +@end group +@end smallexample @noindent Here we have computed the Taylor series expansion of the function about the point @cite{x=1}. We can now integrate this polynomial approximation, since polynomials are easy to integrate. -@group -@smallexample +@smallexample +@group 1: 0.42074 x^2 + ... 1: [-0.0446, -0.42073] 1: 0.3761 . . . - a i x RET [ 2 , 1 ] TAB V M $ RET V R - -@end smallexample -@end group + a i x @key{RET} [ 2 , 1 ] @key{TAB} V M $ @key{RET} V R - +@end group +@end smallexample @noindent Better! By increasing the precision and/or asking for more terms @@ -5577,14 +5474,14 @@ Suppose we want to simplify this trigonometric formula: -@group -@smallexample +@smallexample +@group 1: 1 / cos(x) - sin(x) tan(x) . - ' 1/cos(x) - sin(x) tan(x) RET s 1 -@end smallexample -@end group + ' 1/cos(x) - sin(x) tan(x) @key{RET} s 1 +@end group +@end smallexample @noindent If we were simplifying this by hand, we'd probably replace the @@ -5595,14 +5492,14 @@ Rewrite rules are written with the @samp{:=} symbol. -@group -@smallexample +@smallexample +@group 1: 1 / cos(x) - sin(x)^2 / cos(x) . - a r tan(a) := sin(a)/cos(a) RET -@end smallexample -@end group + a r tan(a) := sin(a)/cos(a) @key{RET} +@end group +@end smallexample @noindent (The ``assignment operator'' @samp{:=} has several uses in Calc. All @@ -5625,14 +5522,14 @@ To merge over a common denominator, we can use another simple rule: -@group -@smallexample +@smallexample +@group 1: (1 - sin(x)^2) / cos(x) . - a r a/x + b/x := (a+b)/x RET -@end smallexample -@end group + a r a/x + b/x := (a+b)/x @key{RET} +@end group +@end smallexample This rule points out several interesting features of rewrite patterns. First, if a meta-variable appears several times in a pattern, it must @@ -5665,14 +5562,14 @@ latter rule has a more general pattern so it will work in many other situations, too. -@group -@smallexample +@smallexample +@group 1: (1 + cos(x)^2 - 1) / cos(x) 1: cos(x) . . - a r sin(x)^2 := 1 - cos(x)^2 RET a s -@end smallexample -@end group + a r sin(x)^2 := 1 - cos(x)^2 @key{RET} a s +@end group +@end smallexample You may ask, what's the point of using the most general rule if you have to type it in every time anyway? The answer is that Calc allows @@ -5683,18 +5580,18 @@ can simply Undo, edit the variable, and run the rule again without having to retype it. -@group -@smallexample -' tan(x) := sin(x)/cos(x) RET s t tsc RET -' a/x + b/x := (a+b)/x RET s t merge RET -' sin(x)^2 := 1 - cos(x)^2 RET s t sinsqr RET +@smallexample +@group +' tan(x) := sin(x)/cos(x) @key{RET} s t tsc @key{RET} +' a/x + b/x := (a+b)/x @key{RET} s t merge @key{RET} +' sin(x)^2 := 1 - cos(x)^2 @key{RET} s t sinsqr @key{RET} 1: 1 / cos(x) - sin(x) tan(x) 1: cos(x) . . - r 1 a r tsc RET a r merge RET a r sinsqr RET a s -@end smallexample -@end group + r 1 a r tsc @key{RET} a r merge @key{RET} a r sinsqr @key{RET} a s +@end group +@end smallexample To edit a variable, type @kbd{s e} and the variable name, use regular Emacs editing commands as necessary, then type @kbd{M-# M-#} or @@ -5720,24 +5617,24 @@ The @kbd{a r} command can also accept a vector of rewrite rules, or a variable containing a vector of rules. -@group -@smallexample +@smallexample +@group 1: [tsc, merge, sinsqr] 1: [tan(x) := sin(x) / cos(x), ... ] . . - ' [tsc,merge,sinsqr] RET = - -@end smallexample -@end group -@noindent -@group -@smallexample + ' [tsc,merge,sinsqr] @key{RET} = + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 1 / cos(x) - sin(x) tan(x) 1: cos(x) . . - s t trig RET r 1 a r trig RET a s -@end smallexample -@end group + s t trig @key{RET} r 1 a r trig @key{RET} a s +@end group +@end smallexample @c [fix-ref Nested Formulas with Rewrite Rules] Calc tries all the rules you give against all parts of the formula, @@ -5751,14 +5648,14 @@ to @kbd{a r} to specify any limit. In particular, @kbd{M-1 a r} does only one rewrite at a time. -@group -@smallexample +@smallexample +@group 1: 1 / cos(x) - sin(x)^2 / cos(x) 1: (1 - sin(x)^2) / cos(x) . . - r 1 M-1 a r trig RET M-1 a r trig RET -@end smallexample -@end group + r 1 M-1 a r trig @key{RET} M-1 a r trig @key{RET} +@end group +@end smallexample You can type @kbd{M-0 a r} if you want no limit at all on the number of rewrites that occur. @@ -5766,24 +5663,24 @@ Rewrite rules can also be @dfn{conditional}. Simply follow the rule with a @samp{::} symbol and the desired condition. For example, -@group -@smallexample +@smallexample +@group 1: exp(2 pi i) + exp(3 pi i) + exp(4 pi i) . - ' exp(2 pi i) + exp(3 pi i) + exp(4 pi i) RET - -@end smallexample -@end group -@noindent -@group -@smallexample + ' exp(2 pi i) + exp(3 pi i) + exp(4 pi i) @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 1 + exp(3 pi i) + 1 . - a r exp(k pi i) := 1 :: k % 2 = 0 RET -@end smallexample -@end group + a r exp(k pi i) := 1 :: k % 2 = 0 @key{RET} +@end group +@end smallexample @noindent (Recall, @samp{k % 2} is the remainder from dividing @samp{k} by 2, @@ -5799,7 +5696,9 @@ only when the fifth argument is literally @samp{e}!@refill @cindex Fibonacci numbers -@c @starindex +@ignore +@starindex +@end ignore @tindex fib Rewrite rules provide an interesting way to define your own functions. Suppose we want to define @samp{fib(n)} to produce the @var{n}th @@ -5807,16 +5706,16 @@ later numbers are formed by summing the two preceding numbers in the sequence. This is easy to express in a set of three rules: -@group -@smallexample -' [fib(1) := 1, fib(2) := 1, fib(n) := fib(n-1) + fib(n-2)] RET s t fib +@smallexample +@group +' [fib(1) := 1, fib(2) := 1, fib(n) := fib(n-1) + fib(n-2)] @key{RET} s t fib 1: fib(7) 1: 13 . . - ' fib(7) RET a r fib RET -@end smallexample -@end group + ' fib(7) @key{RET} a r fib @key{RET} +@end group +@end smallexample One thing that is guaranteed about the order that rewrites are tried is that, for any given subformula, earlier rules in the rule set will @@ -5830,7 +5729,7 @@ Each of these will then be replaced to get @samp{fib(x-2) + 2 fib(x-3) + fib(x-4)}, and so on, expanding forever. What we really want is to apply the third rule only when @samp{n} is an integer greater than two. Type -@w{@kbd{s e fib RET}}, then edit the third rule to: +@w{@kbd{s e fib @key{RET}}}, then edit the third rule to: @smallexample fib(n) := fib(n-1) + fib(n-2) :: integer(n) :: n > 2 @@ -5839,43 +5738,43 @@ @noindent Now: -@group -@smallexample +@smallexample +@group 1: fib(6) + fib(x) + fib(0) 1: 8 + fib(x) + fib(0) . . - ' fib(6)+fib(x)+fib(0) RET a r fib RET -@end smallexample -@end group + ' fib(6)+fib(x)+fib(0) @key{RET} a r fib @key{RET} +@end group +@end smallexample @noindent We've created a new function, @code{fib}, and a new command, -@w{@kbd{a r fib RET}}, which means ``evaluate all @code{fib} calls in +@w{@kbd{a r fib @key{RET}}}, which means ``evaluate all @code{fib} calls in this formula.'' To make things easier still, we can tell Calc to apply these rules automatically by storing them in the special variable @code{EvalRules}. -@group -@smallexample +@smallexample +@group 1: [fib(1) := ...] . 1: [8, 13] . . - s r fib RET s t EvalRules RET ' [fib(6), fib(7)] RET -@end smallexample -@end group + s r fib @key{RET} s t EvalRules @key{RET} ' [fib(6), fib(7)] @key{RET} +@end group +@end smallexample It turns out that this rule set has the problem that it does far more work than it needs to when @samp{n} is large. Consider the first few steps of the computation of @samp{fib(6)}: -@group -@smallexample +@smallexample +@group fib(6) = fib(5) + fib(4) = fib(4) + fib(3) + fib(3) + fib(2) = fib(3) + fib(2) + fib(2) + fib(1) + fib(2) + fib(1) + 1 = ... -@end smallexample -@end group +@end group +@end smallexample @noindent Note that @samp{fib(3)} appears three times here. Unless Calc's @@ -5897,7 +5796,7 @@ example, if the rule rewrites @samp{fib(7)} to something that evaluates to 13, then the rule @samp{fib(7) := 13} will be added to the rule set. -Type @kbd{' fib(8) RET} to compute the eighth Fibonacci number, then +Type @kbd{' fib(8) @key{RET}} to compute the eighth Fibonacci number, then type @kbd{s E} again to see what has happened to the rule set. With the @code{remember} feature, our rule set can now compute @@ -5907,7 +5806,7 @@ (and the results for all smaller @var{n}) later in just one step. All Calc operations will run somewhat slower whenever @code{EvalRules} -contains any rules. You should type @kbd{s u EvalRules RET} now to +contains any rules. You should type @kbd{s u EvalRules @key{RET}} now to un-store the variable. (@bullet{}) @strong{Exercise 2.} Sometimes it is possible to reformulate @@ -6045,14 +5944,14 @@ the shift-@kbd{Z} prefix; the user commands they create use the lower case @kbd{z} prefix. -@group -@smallexample +@smallexample +@group 1: 1 + x + x^2 / 2 + x^3 / 6 1: 1 + x + x^2 / 2 + x^3 / 6 . . - ' 1 + x + x^2/2! + x^3/3! RET Z F e myexp RET RET RET y -@end smallexample -@end group + ' 1 + x + x^2/2! + x^3/3! @key{RET} Z F e myexp @key{RET} @key{RET} @key{RET} y +@end group +@end smallexample This polynomial is a Taylor series approximation to @samp{exp(x)}. The @kbd{Z F} command asks a number of questions. The above answers @@ -6063,16 +5962,16 @@ answers the question ``leave it in symbolic form for non-constant arguments?'' -@group -@smallexample +@smallexample +@group 1: 1.3495 2: 1.3495 3: 1.3495 . 1: 1.34986 2: 1.34986 . 1: myexp(a + 1) . - .3 z e .3 E ' a+1 RET z e -@end smallexample -@end group + .3 z e .3 E ' a+1 @key{RET} z e +@end group +@end smallexample @noindent First we call our new @code{exp} approximation with 0.3 as an @@ -6084,7 +5983,9 @@ in @samp{a + 1} for @samp{x} in the defining formula. @cindex Sine integral Si(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex Si (@bullet{}) @strong{Exercise 1.} The ``sine integral'' function @c{${\rm Si}(x)$} @@ -6107,19 +6008,19 @@ For example, if you find yourself typing @kbd{H a S x @key{RET}} often, you may wish to program a keyboard macro to type this for you. -@group -@smallexample +@smallexample +@group 1: y = sqrt(x) 1: x = y^2 . . - ' y=sqrt(x) RET C-x ( H a S x RET C-x ) + ' y=sqrt(x) @key{RET} C-x ( H a S x @key{RET} C-x ) 1: y = cos(x) 1: x = s1 arccos(y) + 2 pi n1 . . - ' y=cos(x) RET X -@end smallexample -@end group + ' y=cos(x) @key{RET} X +@end group +@end smallexample @noindent When you type @kbd{C-x (}, Emacs begins recording. But it is also @@ -6130,14 +6031,14 @@ You can give a name to your macro by typing @kbd{Z K}. -@group -@smallexample +@smallexample +@group 1: . 1: y = x^4 1: x = s2 sqrt(s1 sqrt(y)) . . - Z K x RET ' y=x^4 RET z x -@end smallexample -@end group + Z K x @key{RET} ' y=x^4 @key{RET} z x +@end group +@end smallexample @noindent Notice that we use shift-@kbd{Z} to define the command, and lower-case @@ -6145,14 +6046,14 @@ Keyboard macros can call other macros. -@group -@smallexample +@smallexample +@group 1: abs(x) 1: x = s1 y 1: 2 / x 1: x = 2 / y . . . . - ' abs(x) RET C-x ( ' y RET a = z x C-x ) ' 2/x RET X -@end smallexample -@end group + ' abs(x) @key{RET} C-x ( ' y @key{RET} a = z x C-x ) ' 2/x @key{RET} X +@end group +@end smallexample (@bullet{}) @strong{Exercise 2.} Define a keyboard macro to negate the item in level 3 of the stack, without disturbing the rest of @@ -6186,15 +6087,15 @@ Calc has @dfn{looping} commands that allow this. Loops are useful inside keyboard macros, but actually work at any time. -@group -@smallexample +@smallexample +@group 1: x^6 2: x^6 1: 360 x^2 . 1: 4 . . - ' x^6 RET 4 Z < a d x RET Z > -@end smallexample -@end group + ' x^6 @key{RET} 4 Z < a d x @key{RET} Z > +@end group +@end smallexample @noindent Here we have computed the fourth derivative of @cite{x^6} by @@ -6208,16 +6109,16 @@ @cindex Fibonacci numbers Here's another example: -@group -@smallexample +@smallexample +@group 3: 1 2: 10946 2: 1 1: 17711 1: 20 . . -1 RET RET 20 Z < TAB C-j + Z > -@end smallexample -@end group +1 @key{RET} @key{RET} 20 Z < @key{TAB} C-j + Z > +@end group +@end smallexample @noindent The numbers in levels 2 and 1 should be the 21st and 22nd Fibonacci @@ -6236,14 +6137,14 @@ @cite{(1 + sqrt(5)) / 2}. (For convenience, this constant is available from the @code{phi} variable, or the @kbd{I H P} command.) -@group -@smallexample +@smallexample +@group 1: 1.61803 1: 24476.0000409 1: 10945.9999817 1: 10946 . . . . I H P 21 ^ 5 Q / R -@end smallexample -@end group +@end group +@end smallexample @cindex Continued fractions (@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} @@ -6270,16 +6171,16 @@ we wish to compute the 20th ``harmonic'' number, which is equal to the sum of the reciprocals of the integers from 1 to 20. -@group -@smallexample +@smallexample +@group 3: 0 1: 3.597739 2: 1 . 1: 20 . -0 RET 1 RET 20 Z ( & + 1 Z ) -@end smallexample -@end group +0 @key{RET} 1 @key{RET} 20 Z ( & + 1 Z ) +@end group +@end smallexample @noindent The ``for'' loop pops two numbers, the lower and upper limits, then @@ -6294,15 +6195,15 @@ total as well as for the various loop housekeeping functions. If you find this disorienting, you can sum in a variable instead: -@group -@smallexample +@smallexample +@group 1: 0 2: 1 . 1: 3.597739 . 1: 20 . . - 0 t 7 1 RET 20 Z ( & s + 7 1 Z ) r 7 -@end smallexample -@end group + 0 t 7 1 @key{RET} 20 Z ( & s + 7 1 Z ) r 7 +@end group +@end smallexample @noindent The @kbd{s +} command adds the top-of-stack into the value in a @@ -6325,16 +6226,16 @@ caller was keeping in those same variables. This is easy to fix, though: -@group -@smallexample +@smallexample +@group . 1: 0.6667 1: 0.6667 3: 0.6667 . . 2: 3.597739 1: 0.6667 . - Z ` p 4 RET 2 RET 3 / s 7 s s a RET Z ' r 7 s r a RET -@end smallexample -@end group + Z ` p 4 @key{RET} 2 @key{RET} 3 / s 7 s s a @key{RET} Z ' r 7 s r a @key{RET} +@end group +@end smallexample @noindent When we type @kbd{Z `} (that's a back-quote character), Calc saves @@ -6358,14 +6259,14 @@ this command is very slow for large @cite{n} since the higher Bernoulli numbers are very large fractions.) -@group -@smallexample +@smallexample +@group 1: 10 1: 0.0756823 . . - 10 C-x ( RET 2 % Z [ DEL 0 Z : ' 2 $! / (2 pi)^$ RET = Z ] C-x ) -@end smallexample -@end group + 10 C-x ( @key{RET} 2 % Z [ @key{DEL} 0 Z : ' 2 $! / (2 pi)^$ @key{RET} = Z ] C-x ) +@end group +@end smallexample @noindent You can read @kbd{Z [} as ``then,'' @kbd{Z :} as ``else,'' and @@ -6378,30 +6279,30 @@ The actual tenth Bernoulli number is @cite{5/66}. -@group -@smallexample +@smallexample +@group 3: 0.0756823 1: 0 1: 0.25305 1: 0 1: 1.16659 2: 5:66 . . . . 1: 0.0757575 . -10 k b RET c f M-0 DEL 11 X DEL 12 X DEL 13 X DEL 14 X -@end smallexample -@end group +10 k b @key{RET} c f M-0 @key{DEL} 11 X @key{DEL} 12 X @key{DEL} 13 X @key{DEL} 14 X +@end group +@end smallexample Just to exercise loops a bit more, let's compute a table of even Bernoulli numbers. -@group -@smallexample +@smallexample +@group 3: [] 1: [0.10132, 0.03079, 0.02340, 0.033197, ...] 2: 2 . 1: 30 . - [ ] 2 RET 30 Z ( X | 2 Z ) -@end smallexample -@end group + [ ] 2 @key{RET} 30 Z ( X | 2 Z ) +@end group +@end smallexample @noindent The vertical-bar @kbd{|} is the vector-concatenation command. When @@ -6423,18 +6324,18 @@ One technique is to enter a throwaway dummy definition for the macro, then enter the real one in the edit command. -@group -@smallexample +@smallexample +@group 1: 3 1: 3 Keyboard Macro Editor. - . . Original keys: 1 RET 2 + + . . Original keys: 1 @key{RET} 2 + type "1\r" type "2" calc-plus -C-x ( 1 RET 2 + C-x ) Z K h RET Z E h -@end smallexample -@end group +C-x ( 1 @key{RET} 2 + C-x ) Z K h @key{RET} Z E h +@end group +@end smallexample @noindent This shows the screen display assuming you have the @file{macedit} @@ -6460,7 +6361,7 @@ calc-store-into # Store it in variable 1 type "1" type "1" # Initial value for loop -calc-roll-down # This is the TAB key; swap initial & final +calc-roll-down # This is the @key{TAB} key; swap initial & final calc-kbd-for # Begin "for" loop... calc-inv # Take reciprocal calc-store-plus # Add to accumulator @@ -6475,14 +6376,14 @@ @noindent Press @kbd{M-# M-#} to finish editing and return to the Calculator. -@group -@smallexample +@smallexample +@group 1: 20 1: 3.597739 . . 20 z h -@end smallexample -@end group +@end group +@end smallexample If you don't know how to write a particular command in @file{macedit} format, you can always write it as keystrokes in a @code{type} command. @@ -6492,18 +6393,18 @@ of the current buffer as a sequence of keystroke names, and defines that sequence on the @kbd{X} (and @kbd{C-x e}) key. Because this is so useful, Calc puts this command on the @kbd{M-# m} key. Try reading in -this macro in the following form: Press @kbd{C-@@} (or @kbd{C-SPC}) at +this macro in the following form: Press @kbd{C-@@} (or @kbd{C-@key{SPC}}) at one end of the text below, then type @kbd{M-# m} at the other. -@group -@example +@example +@group Z ` 0 t 1 - 1 TAB + 1 @key{TAB} Z ( & s + 1 1 Z ) r 1 Z ' -@end example -@end group +@end group +@end example (@bullet{}) @strong{Exercise 8.} A general algorithm for solving equations numerically is @dfn{Newton's Method}. Given the equation @@ -6667,7 +6568,7 @@ This section includes answers to all the exercises in the Calc tutorial. @menu -* RPN Answer 1:: 1 RET 2 RET 3 RET 4 + * - +* RPN Answer 1:: 1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * - * RPN Answer 2:: 2*4 + 7*9.5 + 5/4 * RPN Answer 3:: Operating on levels 2 and 3 * RPN Answer 4:: Joe's complex problems @@ -6770,43 +6671,43 @@ both of these results waiting on the stack you can then compute the final term, then press @kbd{+ +} to add everything up. -@group -@smallexample +@smallexample +@group 2: 2 1: 8 3: 8 2: 8 1: 4 . 2: 7 1: 66.5 . 1: 9.5 . . - 2 RET 4 * 7 RET 9.5 * - -@end smallexample -@end group -@noindent -@group -@smallexample + 2 @key{RET} 4 * 7 @key{RET} 9.5 * + +@end group +@end smallexample +@noindent +@smallexample +@group 4: 8 3: 8 2: 8 1: 75.75 3: 66.5 2: 66.5 1: 67.75 . 2: 5 1: 1.25 . 1: 4 . . - 5 RET 4 / + + -@end smallexample -@end group + 5 @key{RET} 4 / + + +@end group +@end smallexample Alternatively, you could add the first two terms before going on with the third term. -@group -@smallexample +@smallexample +@group 2: 8 1: 74.5 3: 74.5 2: 74.5 1: 75.75 1: 66.5 . 2: 5 1: 1.25 . . 1: 4 . . - ... + 5 RET 4 / + -@end smallexample -@end group + ... + 5 @key{RET} 4 / + +@end group +@end smallexample On an old-style RPN calculator this second method would have the advantage of using only three stack levels. But since Calc's stack @@ -6819,30 +6720,30 @@ @noindent The @key{TAB} key provides a way to operate on the number in level 2. -@group -@smallexample +@smallexample +@group 3: 10 3: 10 4: 10 3: 10 3: 10 2: 20 2: 30 3: 30 2: 30 2: 21 1: 30 1: 20 2: 20 1: 21 1: 30 . . 1: 1 . . . - TAB 1 + TAB -@end smallexample -@end group - -Similarly, @key{M-TAB} gives you access to the number in level 3. - -@group -@smallexample + @key{TAB} 1 + @key{TAB} +@end group +@end smallexample + +Similarly, @kbd{M-@key{TAB}} gives you access to the number in level 3. + +@smallexample +@group 3: 10 3: 21 3: 21 3: 30 3: 11 2: 21 2: 30 2: 30 2: 11 2: 21 1: 30 1: 10 1: 11 1: 21 1: 30 . . . . . - M-TAB 1 + M-TAB M-TAB -@end smallexample -@end group + M-@key{TAB} 1 + M-@key{TAB} M-@key{TAB} +@end group +@end smallexample @node RPN Answer 4, Algebraic Answer 1, RPN Answer 3, Answers to Exercises @subsection RPN Tutorial Exercise 4 @@ -6851,15 +6752,15 @@ Either @kbd{( 2 , 3 )} or @kbd{( 2 @key{SPC} 3 )} would have worked, but using both the comma and the space at once yields: -@group -@smallexample +@smallexample +@group 1: ( ... 2: ( ... 1: (2, ... 2: (2, ... 2: (2, ... . 1: 2 . 1: (2, ... 1: (2, 3) . . . - ( 2 , SPC 3 ) -@end smallexample -@end group + ( 2 , @key{SPC} 3 ) +@end group +@end smallexample Joe probably tried to type @kbd{@key{TAB} @key{DEL}} to swap the extra incomplete object to the top of the stack and delete it. @@ -6867,19 +6768,19 @@ deletes just one component out of that object, so he had to press @key{DEL} twice to finish the job. -@group -@smallexample +@smallexample +@group 2: (2, ... 2: (2, 3) 2: (2, 3) 1: (2, 3) 1: (2, 3) 1: (2, ... 1: ( ... . . . . - TAB DEL DEL -@end smallexample -@end group + @key{TAB} @key{DEL} @key{DEL} +@end group +@end smallexample (As it turns out, deleting the second-to-top stack entry happens often -enough that Calc provides a special key, @kbd{M-DEL}, to do just that. -@kbd{M-DEL} is just like @kbd{TAB DEL}, except that it doesn't exhibit +enough that Calc provides a special key, @kbd{M-@key{DEL}}, to do just that. +@kbd{M-@key{DEL}} is just like @kbd{@key{TAB} @key{DEL}}, except that it doesn't exhibit the ``feature'' that tripped poor Joe.) @node Algebraic Answer 1, Algebraic Answer 2, RPN Answer 4, Answers to Exercises @@ -6990,7 +6891,7 @@ @samp{16#F.E8F*16.^15}. You can enter a number like this as an algebraic entry. Also, pressing @kbd{e} without any digits before it normally types @kbd{1e}, but in a high radix it types @kbd{16.^} and -puts you in algebraic entry: @kbd{16#f.e8f RET e 15 RET *} is another +puts you in algebraic entry: @kbd{16#f.e8f @key{RET} e 15 @key{RET} *} is another way to enter this number. The reason Calc puts a decimal point in the @samp{16.^} is to prevent @@ -7018,24 +6919,24 @@ place (according to the current precision). They are useful for determining facts like this. -@group -@smallexample +@smallexample +@group 1: 0.707106781187 1: 0.500000000001 . . 45 S 2 ^ -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: 0.707106781187 1: 0.707106781186 1: 0.499999999999 . . . - U DEL f [ 2 ^ -@end smallexample -@end group + U @key{DEL} f [ 2 ^ +@end group +@end smallexample A high-precision calculation must be carried out in high precision all the way. The only number in the original problem which was known @@ -7102,15 +7003,15 @@ Duplicate the vector, compute its length, then divide the vector by its length: @kbd{@key{RET} A /}. -@group -@smallexample +@smallexample +@group 1: [1, 2, 3] 2: [1, 2, 3] 1: [0.27, 0.53, 0.80] 1: 1. . 1: 3.74165738677 . . . - r 1 RET A / A -@end smallexample -@end group + r 1 @key{RET} A / A +@end group +@end smallexample The final @kbd{A} command shows that the normalized vector does indeed have unit length. @@ -7135,12 +7036,12 @@ @subsection Matrix Tutorial Exercise 2 @ifinfo -@group -@example +@example +@group x + a y = 6 x + b y = 10 -@end example -@end group +@end group +@end example @end ifinfo @tex \turnoffactive @@ -7154,27 +7055,27 @@ Just enter the righthand side vector, then divide by the lefthand side matrix as usual. -@group -@smallexample +@smallexample +@group 1: [6, 10] 2: [6, 10] 1: [6 - 4 a / (b - a), 4 / (b - a) ] . 1: [ [ 1, a ] . [ 1, b ] ] . -' [6 10] RET ' [1 a; 1 b] RET / -@end smallexample -@end group +' [6 10] @key{RET} ' [1 a; 1 b] @key{RET} / +@end group +@end smallexample This can be made more readable using @kbd{d B} to enable ``big'' display mode: -@group -@smallexample +@smallexample +@group 4 a 4 1: [6 - -----, -----] b - a b - a -@end smallexample -@end group +@end group +@end smallexample Type @kbd{d N} to return to ``normal'' display mode afterwards. @@ -7192,14 +7093,14 @@ command. @ifinfo -@group -@example +@example +@group a + 2b + 3c = 6 4a + 5b + 6c = 2 7a + 6b = 3 2a + 4b + 6c = 11 -@end example -@end group +@end group +@end example @end ifinfo @tex \turnoffactive @@ -7222,24 +7123,24 @@ @c{$B'$} @cite{B2} vector. -@group -@smallexample +@smallexample +@group 1: [ [ 1, 2, 3 ] 2: [ [ 1, 4, 7, 2 ] 1: [57, 84, 96] [ 4, 5, 6 ] [ 2, 5, 6, 4 ] . [ 7, 6, 0 ] [ 3, 6, 0, 6 ] ] [ 2, 4, 6 ] ] 1: [6, 2, 3, 11] . . -' [1 2 3; 4 5 6; 7 6 0; 2 4 6] RET s 7 v t [6 2 3 11] * -@end smallexample -@end group +' [1 2 3; 4 5 6; 7 6 0; 2 4 6] @key{RET} s 7 v t [6 2 3 11] * +@end group +@end smallexample @noindent Now we compute the matrix @c{$A'$} @cite{A2} and divide. -@group -@smallexample +@smallexample +@group 2: [57, 84, 96] 1: [-11.64, 14.08, -3.64] 1: [ [ 70, 72, 39 ] . [ 72, 81, 60 ] @@ -7247,8 +7148,8 @@ . r 7 v t r 7 * / -@end smallexample -@end group +@end group +@end smallexample @noindent (The actual computed answer will be slightly inexact due to @@ -7268,8 +7169,8 @@ can't both be satisfied at once. Let's plug our answers back into the original system of equations to see how well they match. -@group -@smallexample +@smallexample +@group 2: [-11.64, 14.08, -3.64] 1: [5.6, 2., 3., 11.2] 1: [ [ 1, 2, 3 ] . [ 4, 5, 6 ] @@ -7277,9 +7178,9 @@ [ 2, 4, 6 ] ] . - r 7 TAB * -@end smallexample -@end group + r 7 @key{TAB} * +@end group +@end smallexample @noindent This is reasonably close to our original @cite{B} vector, @@ -7294,28 +7195,28 @@ across the vector will accomplish this, although it turns out the plain @samp{-} key will work just as well. -@group -@smallexample +@smallexample +@group 2: 2 2: 2 1: [1, 2, 3, 4, 5, 6, 7, 8, 9] 1: [-4, -3, -2, -1, 0, 1, 2, 3, 4] . . - 2 v x 9 RET 5 V M - or 5 - -@end smallexample -@end group + 2 v x 9 @key{RET} 5 V M - or 5 - +@end group +@end smallexample @noindent Now we use @kbd{V M ^} to map the exponentiation operator across the vector. -@group -@smallexample +@smallexample +@group 1: [0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16] . V M ^ -@end smallexample -@end group +@end group +@end smallexample @node List Answer 2, List Answer 3, List Answer 1, Answers to Exercises @subsection List Tutorial Exercise 2 @@ -7341,44 +7242,44 @@ ones as the other column. So, first we build the column of ones, then we combine the two columns to form our @cite{A} matrix. -@group -@smallexample +@smallexample +@group 2: [1.34, 1.41, 1.49, ... ] 1: [ [ 1.34, 1 ] 1: [1, 1, 1, ...] [ 1.41, 1 ] . [ 1.49, 1 ] @dots{} - r 1 1 v b 19 RET M-2 v p v t s 3 -@end smallexample -@end group + r 1 1 v b 19 @key{RET} M-2 v p v t s 3 +@end group +@end smallexample @noindent Now we compute @c{$A^T y$} @cite{trn(A) * y} and @c{$A^T A$} @cite{trn(A) * A} and divide. -@group -@smallexample +@smallexample +@group 1: [33.36554, 13.613] 2: [33.36554, 13.613] . 1: [ [ 98.0003, 41.63 ] [ 41.63, 19 ] ] . v t r 2 * r 3 v t r 3 * -@end smallexample -@end group +@end group +@end smallexample @noindent (Hey, those numbers look familiar!) -@group -@smallexample +@smallexample +@group 1: [0.52141679, -0.425978] . / -@end smallexample -@end group +@end group +@end smallexample Since we were solving equations of the form @c{$m \times x + b \times 1 = y$} @cite{m*x + b*1 = y}, these @@ -7397,40 +7298,40 @@ @subsection List Tutorial Exercise 3 @noindent -Move to one end of the list and press @kbd{C-@@} (or @kbd{C-SPC} or +Move to one end of the list and press @kbd{C-@@} (or @kbd{C-@key{SPC}} or whatever) to set the mark, then move to the other end of the list and type @w{@kbd{M-# g}}. -@group -@smallexample +@smallexample +@group 1: [2.3, 6, 22, 15.1, 7, 15, 14, 7.5, 2.5] . -@end smallexample -@end group +@end group +@end smallexample To make things interesting, let's assume we don't know at a glance how many numbers are in this list. Then we could type: -@group -@smallexample +@smallexample +@group 2: [2.3, 6, 22, ... ] 2: [2.3, 6, 22, ... ] 1: [2.3, 6, 22, ... ] 1: 126356422.5 . . - RET V R * - -@end smallexample -@end group -@noindent -@group -@smallexample + @key{RET} V R * + +@end group +@end smallexample +@noindent +@smallexample +@group 2: 126356422.5 2: 126356422.5 1: 7.94652913734 1: [2.3, 6, 22, ... ] 1: 9 . . . - TAB v l I ^ -@end smallexample -@end group + @key{TAB} v l I ^ +@end group +@end smallexample @noindent (The @kbd{I ^} command computes the @var{n}th root of a number. @@ -7445,15 +7346,15 @@ @samp{n % j = 0}. The first step is to get a vector that identifies the divisors. -@group -@smallexample +@smallexample +@group 2: 30 2: [0, 0, 0, 2, ...] 1: [1, 1, 1, 0, ...] 1: [1, 2, 3, 4, ...] 1: 0 . . . - 30 RET v x 30 RET s 1 V M % 0 V M a = s 2 -@end smallexample -@end group + 30 @key{RET} v x 30 @key{RET} s 1 V M % 0 V M a = s 2 +@end group +@end smallexample @noindent This vector has 1's marking divisors of 30 and 0's marking non-divisors. @@ -7461,16 +7362,16 @@ The zeroth divisor function is just the total number of divisors. The first divisor function is the sum of the divisors. -@group -@smallexample +@smallexample +@group 1: 8 3: 8 2: 8 2: 8 2: [1, 2, 3, 4, ...] 1: [1, 2, 3, 0, ...] 1: 72 1: [1, 1, 1, 0, ...] . . . V R + r 1 r 2 V M * V R + -@end smallexample -@end group +@end group +@end smallexample @noindent Once again, the last two steps just compute a dot product for which @@ -7485,25 +7386,25 @@ they will be right next to each other. A suitable method is to compare the list with a copy of itself shifted over by one. -@group -@smallexample +@smallexample +@group 1: [3, 7, 7, 7, 19] 2: [3, 7, 7, 7, 19] 2: [3, 7, 7, 7, 19, 0] . 1: [3, 7, 7, 7, 19, 0] 1: [0, 3, 7, 7, 7, 19] . . - 19551 k f RET 0 | TAB 0 TAB | - -@end smallexample -@end group -@noindent -@group -@smallexample + 19551 k f @key{RET} 0 | @key{TAB} 0 @key{TAB} | + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [0, 0, 1, 1, 0, 0] 1: 2 1: 0 . . . V M a = V R + 0 a = -@end smallexample -@end group +@end group +@end smallexample @noindent Note that we have to arrange for both vectors to have the same length @@ -7520,7 +7421,7 @@ @subsection List Tutorial Exercise 6 @noindent -First use @kbd{v x 6 RET} to get a list of integers, then @kbd{V M v x} +First use @kbd{v x 6 @key{RET}} to get a list of integers, then @kbd{V M v x} to get a list of lists of integers! @node List Answer 7, List Answer 8, List Answer 6, Answers to Exercises @@ -7530,16 +7431,16 @@ Here's one solution. First, compute the triangular list from the previous exercise and type @kbd{1 -} to subtract one from all the elements. -@group -@smallexample +@smallexample +@group 1: [ [0], [0, 1], [0, 1, 2], @dots{} 1 - -@end smallexample -@end group +@end group +@end smallexample The numbers down the lefthand edge of the list we desire are called the ``triangular numbers'' (now you know why!). The @cite{n}th @@ -7547,22 +7448,22 @@ can be computed directly by the formula @c{$n (n+1) \over 2$} @cite{n * (n+1) / 2}. -@group -@smallexample +@smallexample +@group 2: [ [0], [0, 1], ... ] 2: [ [0], [0, 1], ... ] 1: [0, 1, 2, 3, 4, 5] 1: [0, 1, 3, 6, 10, 15] . . - v x 6 RET 1 - V M ' $ ($+1)/2 RET -@end smallexample -@end group + v x 6 @key{RET} 1 - V M ' $ ($+1)/2 @key{RET} +@end group +@end smallexample @noindent Adding this list to the above list of lists produces the desired result: -@group -@smallexample +@smallexample +@group 1: [ [0], [1, 2], [3, 4, 5], @@ -7572,23 +7473,23 @@ . V M + -@end smallexample -@end group +@end group +@end smallexample If we did not know the formula for triangular numbers, we could have computed them using a @kbd{V U +} command. We could also have gotten them the hard way by mapping a reduction across the original triangular list. -@group -@smallexample +@smallexample +@group 2: [ [0], [0, 1], ... ] 2: [ [0], [0, 1], ... ] 1: [ [0], [0, 1], ... ] 1: [0, 1, 3, 6, 10, 15] . . - RET V M V R + -@end smallexample -@end group + @key{RET} V M V R + +@end group +@end smallexample @noindent (This means ``map a @kbd{V R +} command across the vector,'' and @@ -7601,41 +7502,41 @@ @noindent The first step is to build a list of values of @cite{x}. -@group -@smallexample +@smallexample +@group 1: [1, 2, 3, ..., 21] 1: [0, 1, 2, ..., 20] 1: [0, 0.25, 0.5, ..., 5] . . . - v x 21 RET 1 - 4 / s 1 -@end smallexample -@end group + v x 21 @key{RET} 1 - 4 / s 1 +@end group +@end smallexample Next, we compute the Bessel function values. -@group -@smallexample +@smallexample +@group 1: [0., 0.124, 0.242, ..., -0.328] . - V M ' besJ(1,$) RET -@end smallexample -@end group - -@noindent -(Another way to do this would be @kbd{1 TAB V M f j}.) + V M ' besJ(1,$) @key{RET} +@end group +@end smallexample + +@noindent +(Another way to do this would be @kbd{1 @key{TAB} V M f j}.) A way to isolate the maximum value is to compute the maximum using @kbd{V R X}, then compare all the Bessel values with that maximum. -@group -@smallexample +@smallexample +@group 2: [0., 0.124, 0.242, ... ] 1: [0, 0, 0, ... ] 2: [0, 0, 0, ... ] 1: 0.5801562 . 1: 1 . . - RET V R X V M a = RET V R + DEL -@end smallexample -@end group + @key{RET} V R X V M a = @key{RET} V R + @key{DEL} +@end group +@end smallexample @noindent It's a good idea to verify, as in the last step above, that only @@ -7647,15 +7548,15 @@ the maximum value of @cite{x}. Now it is a simple matter to convert this back into the corresponding value itself. -@group -@smallexample +@smallexample +@group 2: [0, 0, 0, ... ] 1: [0, 0., 0., ... ] 1: 1.75 1: [0, 0.25, 0.5, ... ] . . . r 1 V M * V R + -@end smallexample -@end group +@end group +@end smallexample If @kbd{a =} had produced more than one @cite{1} value, this method would have given the sum of all maximum @cite{x} values; not very @@ -7668,15 +7569,15 @@ efficient methods. Just for illustration, let's use @kbd{a X} to maximize @samp{besJ(1,x)} over this same interval. -@group -@smallexample +@smallexample +@group 2: besJ(1, x) 1: [1.84115, 0.581865] 1: [0 .. 5] . . -' besJ(1,x), [0..5] RET a X x RET -@end smallexample -@end group +' besJ(1,x), [0..5] @key{RET} a X x @key{RET} +@end group +@end smallexample @noindent The output from @kbd{a X} is a vector containing the value of @cite{x} @@ -7689,63 +7590,63 @@ @noindent Step one is to convert our integer into vector notation. -@group -@smallexample +@smallexample +@group 1: 25129925999 3: 25129925999 . 2: 10 1: [11, 10, 9, ..., 1, 0] . - 25129925999 RET 10 RET 12 RET v x 12 RET - - -@end smallexample -@end group -@noindent -@group -@smallexample + 25129925999 @key{RET} 10 @key{RET} 12 @key{RET} v x 12 @key{RET} - + +@end group +@end smallexample +@noindent +@smallexample +@group 1: 25129925999 1: [0, 2, 25, 251, 2512, ... ] 2: [100000000000, ... ] . . V M ^ s 1 V M \ -@end smallexample -@end group +@end group +@end smallexample @noindent (Recall, the @kbd{\} command computes an integer quotient.) -@group -@smallexample +@smallexample +@group 1: [0, 2, 5, 1, 2, 9, 9, 2, 5, 9, 9, 9] . 10 V M % s 2 -@end smallexample -@end group +@end group +@end smallexample Next we must increment this number. This involves adding one to the last digit, plus handling carries. There is a carry to the left out of a digit if that digit is a nine and all the digits to the right of it are nines. -@group -@smallexample +@smallexample +@group 1: [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1] 1: [1, 1, 1, 0, 0, 1, ... ] . . 9 V M a = v v -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: [1, 1, 1, 0, 0, 0, ... ] 1: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1] . . V U * v v 1 | -@end smallexample -@end group +@end group +@end smallexample @noindent Accumulating @kbd{*} across a vector of ones and zeros will preserve @@ -7754,15 +7655,15 @@ care of aligning the carries properly, and also adding one to the rightmost digit. -@group -@smallexample +@smallexample +@group 2: [0, 0, 0, 0, ... ] 1: [0, 0, 2, 5, 1, 2, 9, 9, 2, 6, 0, 0, 0] 1: [0, 0, 2, 5, ... ] . . 0 r 2 | V M + 10 V M % -@end smallexample -@end group +@end group +@end smallexample @noindent Here we have concatenated 0 to the @emph{left} of the original number; @@ -7771,39 +7672,39 @@ Finally, we must convert this list back into an integer. -@group -@smallexample +@smallexample +@group 3: [0, 0, 2, 5, ... ] 2: [0, 0, 2, 5, ... ] 2: 1000000000000 1: [1000000000000, 100000000000, ... ] 1: [100000000000, ... ] . . - 10 RET 12 ^ r 1 | - -@end smallexample -@end group -@noindent -@group -@smallexample + 10 @key{RET} 12 ^ r 1 | + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [0, 0, 20000000000, 5000000000, ... ] 1: 25129926000 . . V M * V R + -@end smallexample -@end group +@end group +@end smallexample @noindent Another way to do this final step would be to reduce the formula @w{@samp{10 $$ + $}} across the vector of digits. -@group -@smallexample +@smallexample +@group 1: [0, 0, 2, 5, ... ] 1: 25129926000 . . - V R ' 10 $$ + $ RET -@end smallexample -@end group + V R ' 10 $$ + $ @key{RET} +@end group +@end smallexample @node List Answer 10, List Answer 11, List Answer 9, Answers to Exercises @subsection List Tutorial Exercise 10 @@ -7816,25 +7717,25 @@ Here's a more correct method: -@group -@smallexample +@smallexample +@group 1: [7, 7, 7, 8, 7] 2: [7, 7, 7, 8, 7] . 1: 7 . - ' [7,7,7,8,7] RET RET v r 1 RET - -@end smallexample -@end group -@noindent -@group -@smallexample + ' [7,7,7,8,7] @key{RET} @key{RET} v r 1 @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [1, 1, 1, 0, 1] 1: 0 . . V M a = V R * -@end smallexample -@end group +@end group +@end smallexample @node List Answer 11, List Answer 12, List Answer 10, Answers to Exercises @subsection List Tutorial Exercise 11 @@ -7847,51 +7748,51 @@ We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} commands. -@group -@smallexample +@smallexample +@group 2: [2., 2., ..., 2.] 2: [2., 2., ..., 2.] 1: [2., 2., ..., 2.] 1: [1.16, 1.98, ..., 0.81] . . - v . t . 2. v b 100 RET RET V M k r - -@end smallexample -@end group -@noindent -@group -@smallexample + v . t . 2. v b 100 @key{RET} @key{RET} V M k r + +@end group +@end smallexample +@noindent +@smallexample +@group 2: [2., 2., ..., 2.] 1: [0.026, 0.96, ..., 0.036] 1: [0.026, 0.96, ..., 0.036] 2: [0.53, 0.81, ..., 0.094] . . - 1 - 2 V M ^ TAB V M k r 1 - 2 V M ^ -@end smallexample -@end group + 1 - 2 V M ^ @key{TAB} V M k r 1 - 2 V M ^ +@end group +@end smallexample Now we sum the @cite{x^2} and @cite{y^2} values, compare with 1 to get a vector of 1/0 truth values, then sum the truth values. -@group -@smallexample +@smallexample +@group 1: [0.56, 1.78, ..., 0.13] 1: [1, 0, ..., 1] 1: 84 . . . + 1 V M a < V R + -@end smallexample -@end group +@end group +@end smallexample @noindent The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$} @cite{pi/4}. -@group -@smallexample +@smallexample +@group 1: 0.84 1: 3.36 2: 3.36 1: 1.0695 . . 1: 3.14159 . 100 / 4 * P / -@end smallexample -@end group +@end group +@end smallexample @noindent Our estimate, 3.36, is off by about 7%. We could get a better estimate @@ -7939,72 +7840,72 @@ We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} commands. -@group -@smallexample +@smallexample +@group 1: [0.52, 0.71, ..., 0.72] 2: [0.52, 0.71, ..., 0.72] . 1: [78.4, 64.5, ..., -42.9] . -v . t . 1. v b 100 RET V M k r 180. v b 100 RET V M k r 90 - -@end smallexample -@end group +v . t . 1. v b 100 @key{RET} V M k r 180. v b 100 @key{RET} V M k r 90 - +@end group +@end smallexample @noindent (The next step may be slow, depending on the speed of your computer.) -@group -@smallexample +@smallexample +@group 2: [0.52, 0.71, ..., 0.72] 1: [0.72, 1.14, ..., 1.45] 1: [0.20, 0.43, ..., 0.73] . . m d V M C + -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: [0, 1, ..., 1] 1: 0.64 1: 3.125 . . . - 1 V M a > V R + 100 / 2 TAB / -@end smallexample -@end group + 1 V M a > V R + 100 / 2 @key{TAB} / +@end group +@end smallexample Let's try the third method, too. We'll use random integers up to one million. The @kbd{k r} command with an integer argument picks a random integer. -@group -@smallexample +@smallexample +@group 2: [1000000, 1000000, ..., 1000000] 2: [78489, 527587, ..., 814975] 1: [1000000, 1000000, ..., 1000000] 1: [324014, 358783, ..., 955450] . . - 1000000 v b 100 RET RET V M k r TAB V M k r - -@end smallexample -@end group -@noindent -@group -@smallexample + 1000000 v b 100 @key{RET} @key{RET} V M k r @key{TAB} V M k r + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [1, 1, ..., 25] 1: [1, 1, ..., 0] 1: 0.56 . . . V M k g 1 V M a = V R + 100 / -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: 10.714 1: 3.273 . . - 6 TAB / Q -@end smallexample -@end group + 6 @key{TAB} / Q +@end group +@end smallexample For a proof of this property of the GCD function, see section 4.5.2, exercise 10, of Knuth's @emph{Art of Computer Programming}, volume II. @@ -8018,14 +7919,14 @@ @noindent First, we put the string on the stack as a vector of ASCII codes. -@group -@smallexample +@smallexample +@group 1: [84, 101, 115, ..., 51] . - "Testing, 1, 2, 3 RET -@end smallexample -@end group + "Testing, 1, 2, 3 @key{RET} +@end group +@end smallexample @noindent Note that the @kbd{"} key, like @kbd{$}, initiates algebraic entry so @@ -8038,26 +7939,26 @@ @cite{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}. In other words, it's a sum of descending powers of three times the ASCII codes. -@group -@smallexample +@smallexample +@group 2: [84, 101, 115, ..., 51] 2: [84, 101, 115, ..., 51] 1: 16 1: [15, 14, 13, ..., 0] . . - RET v l v x 16 RET - - -@end smallexample -@end group -@noindent -@group -@smallexample + @key{RET} v l v x 16 @key{RET} - + +@end group +@end smallexample +@noindent +@smallexample +@group 2: [84, 101, 115, ..., 51] 1: 1960915098 1: 121 1: [14348907, ..., 1] . . . - 3 TAB V M ^ * 511 % -@end smallexample -@end group + 3 @key{TAB} V M ^ * 511 % +@end group +@end smallexample @noindent Once again, @kbd{*} elegantly summarizes most of the computation. @@ -8066,14 +7967,14 @@ function of two arguments that computes its first argument times three plus its second argument. -@group -@smallexample +@smallexample +@group 1: [84, 101, 115, ..., 51] 1: 1960915098 . . - "Testing, 1, 2, 3 RET V R ' 3$$+$ RET -@end smallexample -@end group + "Testing, 1, 2, 3 @key{RET} V R ' 3$$+$ @key{RET} +@end group +@end smallexample @noindent If you did the decimal arithmetic exercise, this will be familiar. @@ -8087,14 +7988,14 @@ arithmetic operations, the numbers we operate on remain small so the operations are faster. -@group -@smallexample +@smallexample +@group 1: [84, 101, 115, ..., 51] 1: 121 . . - "Testing, 1, 2, 3 RET V R ' (3$$+$)%511 RET -@end smallexample -@end group + "Testing, 1, 2, 3 @key{RET} V R ' (3$$+$)%511 @key{RET} +@end group +@end smallexample Why does this work? Think about a two-step computation: @w{@cite{3 (3a + b) + c}}. Taking a result modulo 511 basically means @@ -8153,7 +8054,7 @@ Later in the tutorial we will encounter @dfn{modulo forms}, which basically automate the idea of reducing every intermediate result -modulo some value @i{M}. +modulo some value @var{m}. @node List Answer 14, Types Answer 1, List Answer 13, Answers to Exercises @subsection List Tutorial Exercise 14 @@ -8162,16 +8063,16 @@ step to an @cite{(x,y)} coordinate. The function is a bit long, but otherwise the problem is quite straightforward. -@group -@smallexample +@smallexample +@group 2: [0, 0] 1: [ [ 0, 0 ] 1: 50 [ 0.4288, -0.1695 ] . [ -0.4787, -0.9027 ] ... - [0,0] 50 H V U ' <# + [random(2.0)-1, random(2.0)-1]> RET -@end smallexample -@end group + [0,0] 50 H V U ' <# + [random(2.0)-1, random(2.0)-1]> @key{RET} +@end group +@end smallexample Just as the text recommended, we used @samp{< >} nameless function notation to keep the two @code{random} calls from being evaluated @@ -8181,15 +8082,15 @@ rules acts like a matrix. We can transpose this matrix and unpack to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing. -@group -@smallexample +@smallexample +@group 2: [ 0, 0.4288, -0.4787, ... ] 1: [ 0, -0.1696, -0.9027, ... ] . v t v u g f -@end smallexample -@end group +@end group +@end smallexample Incidentally, because the @cite{x} and @cite{y} are completely independent in this case, we could have done two separate commands @@ -8200,16 +8101,16 @@ length; in fact, the new nesting function is even briefer, though we might want to lower the precision a bit for it. -@group -@smallexample +@smallexample +@group 2: [0, 0] 1: [ [ 0, 0 ] 1: 50 [ 0.1318, 0.9912 ] . [ -0.5965, 0.3061 ] ... - [0,0] 50 m d p 6 RET H V U ' <# + sincos(random(360.0))> RET -@end smallexample -@end group + [0,0] 50 m d p 6 @key{RET} H V U ' <# + sincos(random(360.0))> @key{RET} +@end group +@end smallexample Another @kbd{v t v u g f} sequence will graph this new random walk. @@ -8229,14 +8130,14 @@ then its square, divided by @c{$\pi$} @cite{pi}, should be a rational number. -@group -@smallexample +@smallexample +@group 1: 1.26508260337 1: 0.509433962268 1: 2486645810:4881193627 . . . 2 ^ P / c F -@end smallexample -@end group +@end group +@end smallexample @noindent Technically speaking this is a rational number, but not one that is @@ -8247,14 +8148,14 @@ But perhaps our result was not quite exact. Let's reduce the precision slightly and try again: -@group -@smallexample +@smallexample +@group 1: 0.509433962268 1: 27:53 . . - U p 10 RET c F -@end smallexample -@end group + U p 10 @key{RET} c F +@end group +@end smallexample @noindent Aha! It's unlikely that an irrational number would equal a fraction @@ -8327,28 +8228,28 @@ @node Types Answer 4, Types Answer 5, Types Answer 3, Answers to Exercises @subsection Types Tutorial Exercise 4 -@group -@smallexample +@smallexample +@group 2: 0@@ 47' 26" 1: 0@@ 2' 47.411765" 1: 17 . . - 0@@ 47' 26" RET 17 / -@end smallexample -@end group + 0@@ 47' 26" @key{RET} 17 / +@end group +@end smallexample @noindent The average song length is two minutes and 47.4 seconds. -@group -@smallexample +@smallexample +@group 2: 0@@ 2' 47.411765" 1: 0@@ 3' 7.411765" 1: 0@@ 53' 6.000005" 1: 0@@ 0' 20" . . . 20" + 17 * -@end smallexample -@end group +@end group +@end smallexample @noindent The album would be 53 minutes and 6 seconds long. @@ -8361,14 +8262,14 @@ to keep trying 13ths of months until Calc reports a Friday. We can do this by manually entering dates, or by using @kbd{t I}: -@group -@smallexample +@smallexample +@group 1: <Wed Feb 13, 1991> 1: <Wed Mar 13, 1991> 1: <Sat Apr 13, 1991> . . . - ' <2/13> RET DEL ' <3/13> RET t I -@end smallexample -@end group + ' <2/13> @key{RET} @key{DEL} ' <3/13> @key{RET} t I +@end group +@end smallexample @noindent (Calc assumes the current year if you don't say otherwise.) @@ -8379,16 +8280,16 @@ ``how-many-months'' argument, which defaults to one. This argument is exactly what we want to map over: -@group -@smallexample +@smallexample +@group 2: <Sat Apr 13, 1991> 1: [<Mon May 13, 1991>, <Thu Jun 13, 1991>, 1: [1, 2, 3, 4, 5, 6] <Sat Jul 13, 1991>, <Tue Aug 13, 1991>, . <Fri Sep 13, 1991>, <Sun Oct 13, 1991>] . - v x 6 RET V M t I -@end smallexample -@end group + v x 6 @key{RET} V M t I +@end group +@end smallexample @ifinfo @noindent @@ -8399,14 +8300,14 @@ {\it Et voil{\accent"12 a}}, September 13, 1991 is a Friday. @end tex -@group -@smallexample +@smallexample +@group 1: 242 . -' <sep 13> - <jan 14> RET -@end smallexample -@end group +' <sep 13> - <jan 14> @key{RET} +@end group +@end smallexample @noindent And the answer to our original question: 242 days to go. @@ -8428,27 +8329,27 @@ number of years times 365. The number of extra days we find must be equal to the number of leap years there were. -@group -@smallexample +@smallexample +@group 1: <Mon Jan 1, 10001> 2: <Mon Jan 1, 10001> 1: 2925593 . 1: <Tue Jan 1, 1991> . . - ' <jan 1 10001> RET ' <jan 1 1991> RET - - -@end smallexample -@end group -@noindent -@group -@smallexample + ' <jan 1 10001> @key{RET} ' <jan 1 1991> @key{RET} - + +@end group +@end smallexample +@noindent +@smallexample +@group 3: 2925593 2: 2925593 2: 2925593 1: 1943 2: 10001 1: 8010 1: 2923650 . 1: 1991 . . . - 10001 RET 1991 - 365 * - -@end smallexample -@end group + 10001 @key{RET} 1991 - 365 * - +@end group +@end smallexample @c [fix-ref Date Forms] @noindent @@ -8464,40 +8365,40 @@ The relative errors must be converted to absolute errors so that @samp{+/-} notation may be used. -@group -@smallexample +@smallexample +@group 1: 1. 2: 1. . 1: 0.2 . - 20 RET .05 * 4 RET .05 * -@end smallexample -@end group + 20 @key{RET} .05 * 4 @key{RET} .05 * +@end group +@end smallexample Now we simply chug through the formula. -@group -@smallexample +@smallexample +@group 1: 19.7392088022 1: 394.78 +/- 19.739 1: 6316.5 +/- 706.21 . . . - 2 P 2 ^ * 20 p 1 * 4 p .2 RET 2 ^ * -@end smallexample -@end group + 2 P 2 ^ * 20 p 1 * 4 p .2 @key{RET} 2 ^ * +@end group +@end smallexample It turns out the @kbd{v u} command will unpack an error form as well as a vector. This saves us some retyping of numbers. -@group -@smallexample +@smallexample +@group 3: 6316.5 +/- 706.21 2: 6316.5 +/- 706.21 2: 6316.5 1: 0.1118 1: 706.21 . . - RET v u TAB / -@end smallexample -@end group + @key{RET} v u @key{TAB} / +@end group +@end smallexample @noindent Thus the volume is 6316 cubic centimeters, within about 11 percent. @@ -8537,15 +8438,15 @@ @node Types Answer 9, Types Answer 10, Types Answer 8, Answers to Exercises @subsection Types Tutorial Exercise 9 -@group -@smallexample +@smallexample +@group 1: [-3 .. 3] 2: [-3 .. 3] 2: [0 .. 9] . 1: [0 .. 9] 1: [-9 .. 9] . . - [ 3 n .. 3 ] RET 2 ^ TAB RET * -@end smallexample -@end group + [ 3 n .. 3 ] @key{RET} 2 ^ @key{TAB} @key{RET} * +@end group +@end smallexample @noindent In the first case the result says, ``if a number is between @i{-3} and @@ -8564,15 +8465,15 @@ @noindent Testing the first number, we might arbitrarily choose 17 for @cite{x}. -@group -@smallexample +@smallexample +@group 1: 17 mod 811749613 2: 17 mod 811749613 1: 533694123 mod 811749613 . 811749612 . . - 17 M 811749613 RET 811749612 ^ -@end smallexample -@end group + 17 M 811749613 @key{RET} 811749612 ^ +@end group +@end smallexample @noindent Since 533694123 is (considerably) different from 1, the number 811749613 @@ -8583,15 +8484,15 @@ a vector mapping operation we can perform several tests at once. Let's use this method to test the second number. -@group -@smallexample +@smallexample +@group 2: [17, 42, 100000] 1: [1 mod 15485863, 1 mod ... ] 1: 15485863 . . - [17 42 100000] 15485863 RET V M ' ($$ mod $)^($-1) RET -@end smallexample -@end group + [17 42 100000] 15485863 @key{RET} V M ' ($$ mod $)^($-1) @key{RET} +@end group +@end smallexample @noindent The result is three ones (modulo @cite{n}), so it's very probable that @@ -8614,26 +8515,26 @@ One way to convert a number of seconds to an HMS form is simply to multiply the number by an HMS form representing one second: -@group -@smallexample +@smallexample +@group 1: 31415926.5359 2: 31415926.5359 1: 8726@@ 38' 46.5359" . 1: 0@@ 0' 1" . . P 1e7 * 0@@ 0' 1" * -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 2: 8726@@ 38' 46.5359" 1: 6@@ 6' 2.5359" mod 24@@ 0' 0" 1: 15@@ 27' 16" mod 24@@ 0' 0" . . - x time RET + -@end smallexample -@end group + x time @key{RET} + +@end group +@end smallexample @noindent It will be just after six in the morning. @@ -8641,14 +8542,14 @@ The algebraic @code{hms} function can also be used to build an HMS form: -@group -@smallexample +@smallexample +@group 1: hms(0, 0, 10000000. pi) 1: 8726@@ 38' 46.5359" . . - ' hms(0, 0, 1e7 pi) RET = -@end smallexample -@end group + ' hms(0, 0, 1e7 pi) @key{RET} = +@end group +@end smallexample @noindent The @kbd{=} key is necessary to evaluate the symbol @samp{pi} to @@ -8661,25 +8562,25 @@ As we recall, there are 17 songs of about 2 minutes and 47 seconds each. -@group -@smallexample +@smallexample +@group 2: 0@@ 2' 47" 1: [0@@ 3' 7" .. 0@@ 3' 47"] 1: [0@@ 0' 20" .. 0@@ 1' 0"] . . [ 0@@ 20" .. 0@@ 1' ] + -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: [0@@ 52' 59." .. 1@@ 4' 19."] . 17 * -@end smallexample -@end group +@end group +@end smallexample @noindent No matter how long it is, the album will fit nicely on one CD. @@ -8688,7 +8589,7 @@ @subsection Types Tutorial Exercise 13 @noindent -Type @kbd{' 1 yr RET u c s RET}. The answer is 31557600 seconds. +Type @kbd{' 1 yr @key{RET} u c s @key{RET}}. The answer is 31557600 seconds. @node Types Answer 14, Types Answer 15, Types Answer 13, Answers to Exercises @subsection Types Tutorial Exercise 14 @@ -8697,27 +8598,27 @@ How long will it take for a signal to get from one end of the computer to the other? -@group -@smallexample +@smallexample +@group 1: m / c 1: 3.3356 ns . . - ' 1 m / c RET u c ns RET -@end smallexample -@end group + ' 1 m / c @key{RET} u c ns @key{RET} +@end group +@end smallexample @noindent (Recall, @samp{c} is a ``unit'' corresponding to the speed of light.) -@group -@smallexample +@smallexample +@group 1: 3.3356 ns 1: 0.81356 ns / ns 1: 0.81356 2: 4.1 ns . . . - ' 4.1 ns RET / u s -@end smallexample -@end group + ' 4.1 ns @key{RET} / u s +@end group +@end smallexample @noindent Thus a signal could take up to 81 percent of a clock cycle just to @@ -8731,29 +8632,29 @@ The speed limit is 55 miles per hour on most highways. We want to find the ratio of Sam's speed to the US speed limit. -@group -@smallexample +@smallexample +@group 1: 55 mph 2: 55 mph 3: 11 hr mph / yd . 1: 5 yd / hr . . - ' 55 mph RET ' 5 yd/hr RET / -@end smallexample -@end group + ' 55 mph @key{RET} ' 5 yd/hr @key{RET} / +@end group +@end smallexample The @kbd{u s} command cancels out these units to get a plain number. Now we take the logarithm base two to find the final answer, assuming that each successive pill doubles his speed. -@group -@smallexample +@smallexample +@group 1: 19360. 2: 19360. 1: 14.24 . 1: 2 . . u s 2 B -@end smallexample -@end group +@end group +@end smallexample @noindent Thus Sam can take up to 14 pills without a worry. @@ -8780,34 +8681,34 @@ will do the job. We can use @kbd{a c x} to write this in a more familiar form. -@group -@smallexample +@smallexample +@group 1: 34 x - 24 x^3 1: [1.19023, -1.19023, 0] . . - r 2 a P x RET - -@end smallexample -@end group -@noindent -@group -@smallexample + r 2 a P x @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [x - 1.19023, x + 1.19023, x] 1: (x - 1.19023) (x + 1.19023) x . . - V M ' x-$ RET V R * - -@end smallexample -@end group -@noindent -@group -@smallexample + V M ' x-$ @key{RET} V R * + +@end group +@end smallexample +@noindent +@smallexample +@group 1: x^3 - 1.41666 x 1: 34 x - 24 x^3 . . - a c x RET 24 n * a x -@end smallexample -@end group + a c x @key{RET} 24 n * a x +@end group +@end smallexample @noindent Sure enough, our answer (multiplied by a suitable constant) is the @@ -8816,65 +8717,65 @@ @node Algebra Answer 3, Algebra Answer 4, Algebra Answer 2, Answers to Exercises @subsection Algebra Tutorial Exercise 3 -@group -@smallexample +@smallexample +@group 1: x sin(pi x) 1: (sin(pi x) - pi x cos(pi x)) / pi^2 . . - ' x sin(pi x) RET m r a i x RET - -@end smallexample -@end group -@noindent -@group -@smallexample + ' x sin(pi x) @key{RET} m r a i x @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [y, 1] 2: (sin(pi x) - pi x cos(pi x)) / pi^2 . - ' [y,1] RET TAB - -@end smallexample -@end group -@noindent -@group -@smallexample + ' [y,1] @key{RET} @key{TAB} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [(sin(pi y) - pi y cos(pi y)) / pi^2, (sin(pi) - pi cos(pi)) / pi^2] . - V M $ RET - -@end smallexample -@end group -@noindent -@group -@smallexample + V M $ @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 1: (sin(pi y) - pi y cos(pi y)) / pi^2 + (pi cos(pi) - sin(pi)) / pi^2 . V R - -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: (sin(3.14159 y) - 3.14159 y cos(3.14159 y)) / 9.8696 - 0.3183 . = -@end smallexample -@end group -@noindent -@group -@smallexample +@end group +@end smallexample +@noindent +@smallexample +@group 1: [0., -0.95493, 0.63662, -1.5915, 1.2732] . - v x 5 RET TAB V M $ RET -@end smallexample -@end group + v x 5 @key{RET} @key{TAB} V M $ @key{RET} +@end group +@end smallexample @node Algebra Answer 4, Rewrites Answer 1, Algebra Answer 3, Answers to Exercises @subsection Algebra Tutorial Exercise 4 @@ -8885,63 +8786,63 @@ coefficients. So first we must come up with a vector of these coefficients. Here's one way: -@group -@smallexample +@smallexample +@group 2: -1 2: 3 1: [4, 2, ..., 4] 1: [1, 2, ..., 9] 1: [-1, 1, ..., -1] . . . - 1 n v x 9 RET V M ^ 3 TAB - - -@end smallexample -@end group -@noindent -@group -@smallexample + 1 n v x 9 @key{RET} V M ^ 3 @key{TAB} - + +@end group +@end smallexample +@noindent +@smallexample +@group 1: [4, 2, ..., 4, 1] 1: [1, 4, 2, ..., 4, 1] . . - 1 | 1 TAB | -@end smallexample -@end group + 1 | 1 @key{TAB} | +@end group +@end smallexample @noindent Now we compute the function values. Note that for this method we need eleven values, including both endpoints of the desired interval. -@group -@smallexample +@smallexample +@group 2: [1, 4, 2, ..., 4, 1] 1: [1, 1.1, 1.2, ... , 1.8, 1.9, 2.] . - 11 RET 1 RET .1 RET C-u v x - -@end smallexample -@end group -@noindent -@group -@smallexample + 11 @key{RET} 1 @key{RET} .1 @key{RET} C-u v x + +@end group +@end smallexample +@noindent +@smallexample +@group 2: [1, 4, 2, ..., 4, 1] 1: [0., 0.084941, 0.16993, ... ] . - ' sin(x) ln(x) RET m r p 5 RET V M $ RET -@end smallexample -@end group + ' sin(x) ln(x) @key{RET} m r p 5 @key{RET} V M $ @key{RET} +@end group +@end smallexample @noindent Once again this calls for @kbd{V M * V R +}; a simple @kbd{*} does the same thing. -@group -@smallexample +@smallexample +@group 1: 11.22 1: 1.122 1: 0.374 . . . * .1 * 3 / -@end smallexample -@end group +@end group +@end smallexample @noindent Wow! That's even better than the result from the Taylor series method. @@ -8952,8 +8853,8 @@ @noindent We'll use Big mode to make the formulas more readable. -@group -@smallexample +@smallexample +@group ___ 2 + V 2 1: (2 + sqrt(2)) / (1 + sqrt(2)) 1: -------- @@ -8962,33 +8863,33 @@ . - ' (2+sqrt(2)) / (1+sqrt(2)) RET d B -@end smallexample -@end group + ' (2+sqrt(2)) / (1+sqrt(2)) @key{RET} d B +@end group +@end smallexample @noindent Multiplying by the conjugate helps because @cite{(a+b) (a-b) = a^2 - b^2}. -@group -@smallexample +@smallexample +@group ___ ___ 1: (2 + V 2 ) (V 2 - 1) . - a r a/(b+c) := a*(b-c) / (b^2-c^2) RET - -@end smallexample -@end group -@noindent -@group -@smallexample + a r a/(b+c) := a*(b-c) / (b^2-c^2) @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group ___ ___ 1: 2 + V 2 - 2 1: V 2 . . a r a*(b+c) := a*b + a*c a s -@end smallexample -@end group +@end group +@end smallexample @noindent (We could have used @kbd{a x} instead of a rewrite rule for the @@ -9004,13 +8905,13 @@ @noindent Here is the rule set: -@group -@smallexample +@smallexample +@group [ fib(n) := fib(n, 1, 1) :: integer(n) :: n >= 1, fib(1, x, y) := x, fib(n, x, y) := fib(n-1, y, x+y) ] -@end smallexample -@end group +@end group +@end smallexample @noindent The first rule turns a one-argument @code{fib} that people like to write @@ -9060,16 +8961,18 @@ @subsection Rewrites Tutorial Exercise 4 @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex seq Here is a suitable set of rules to solve the first part of the problem: -@group -@smallexample +@smallexample +@group [ seq(n, c) := seq(n/2, c+1) :: n%2 = 0, seq(n, c) := seq(3n+1, c+1) :: n%2 = 1 :: n > 1 ] -@end smallexample -@end group +@end group +@end smallexample Given the initial formula @samp{seq(6, 0)}, application of these rules produces the following sequence of formulas: @@ -9090,13 +8993,13 @@ We can pretty this up a bit with a couple more rules: -@group -@smallexample +@smallexample +@group [ seq(n) := seq(n, 0), seq(1, c) := c, ... ] -@end smallexample -@end group +@end group +@end smallexample @noindent Now, given @samp{seq(6)} as the starting configuration, we get 8 @@ -9104,14 +9007,14 @@ The change to return a vector is quite simple: -@group -@smallexample +@smallexample +@group [ seq(n) := seq(n, []) :: integer(n) :: n > 0, seq(1, v) := v | 1, seq(n, v) := seq(n/2, v | n) :: n%2 = 0, seq(n, v) := seq(3n+1, v | n) :: n%2 = 1 ] -@end smallexample -@end group +@end group +@end smallexample @noindent Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. @@ -9131,18 +9034,20 @@ @subsection Rewrites Tutorial Exercise 5 @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex nterms -If @cite{x} is the sum @cite{a + b}, then `@t{nterms(}@i{x}@t{)}' must -be `@t{nterms(}@i{a}@t{)}' plus `@t{nterms(}@i{b}@t{)}'. If @cite{x} -is not a sum, then `@t{nterms(}@i{x}@t{)}' = 1. - -@group -@smallexample +If @cite{x} is the sum @cite{a + b}, then `@t{nterms(}@var{x}@t{)}' must +be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @cite{x} +is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1. + +@smallexample +@group [ nterms(a + b) := nterms(a) + nterms(b), nterms(x) := 1 ] -@end smallexample -@end group +@end group +@end smallexample @noindent Here we have taken advantage of the fact that earlier rules always @@ -9155,28 +9060,28 @@ Just put the rule @samp{0^0 := 1} into @code{EvalRules}. For example, before making this definition we have: -@group -@smallexample +@smallexample +@group 2: [-2, -1, 0, 1, 2] 1: [1, 1, 0^0, 1, 1] 1: 0 . . - v x 5 RET 3 - 0 V M ^ -@end smallexample -@end group + v x 5 @key{RET} 3 - 0 V M ^ +@end group +@end smallexample @noindent But then: -@group -@smallexample +@smallexample +@group 2: [-2, -1, 0, 1, 2] 1: [1, 1, 1, 1, 1] 1: 0 . . - U ' 0^0:=1 RET s t EvalRules RET V M ^ -@end smallexample -@end group + U ' 0^0:=1 @key{RET} s t EvalRules @key{RET} V M ^ +@end group +@end smallexample Perhaps more surprisingly, this rule still works with infinite mode turned on. Calc tries @code{EvalRules} before any built-in rules for @@ -9194,8 +9099,8 @@ @noindent Here is a rule set that will do the job: -@group -@smallexample +@smallexample +@group [ a*(b + c) := a*b + a*c, opt(a) O(x^n) + opt(b) O(x^m) := O(x^n) :: n <= m :: constant(a) :: constant(b), @@ -9204,8 +9109,8 @@ a O(x^n) := O(x^n) :: constant(a), x^opt(m) O(x^n) := O(x^(n+m)), O(x^n) O(x^m) := O(x^(n+m)) ] -@end smallexample -@end group +@end group +@end smallexample If we really want the @kbd{+} and @kbd{*} keys to operate naturally on power series, we should put these rules in @code{EvalRules}. For @@ -9273,15 +9178,15 @@ change this to @samp{(x)} since @cite{t} is really a dummy variable to be used within @code{ninteg}. -The exact keystrokes are @kbd{Z F s Si RET RET C-b C-b DEL DEL RET y}. -(The @kbd{C-b C-b DEL DEL} are what fix the argument list.) +The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}. +(The @kbd{C-b C-b @key{DEL} @key{DEL}} are what fix the argument list.) @node Programming Answer 2, Programming Answer 3, Programming Answer 1, Answers to Exercises @subsection Programming Tutorial Exercise 2 @noindent One way is to move the number to the top of the stack, operate on -it, then move it back: @kbd{C-x ( M-TAB n M-TAB M-TAB C-x )}. +it, then move it back: @kbd{C-x ( M-@key{TAB} n M-@key{TAB} M-@key{TAB} C-x )}. Another way is to negate the top three stack entries, then negate again the top two stack entries: @kbd{C-x ( M-3 n M-2 n C-x )}. @@ -9291,7 +9196,7 @@ which is just what we want: @kbd{C-x ( M-- 3 n C-x )}. Just for kicks, let's also do it algebraically: -@w{@kbd{C-x ( ' -$$$, $$, $ RET C-x )}}. +@w{@kbd{C-x ( ' -$$$, $$, $ @key{RET} C-x )}}. @node Programming Answer 3, Programming Answer 4, Programming Answer 2, Answers to Exercises @subsection Programming Tutorial Exercise 3 @@ -9304,21 +9209,21 @@ Computing @c{$\displaystyle{\sin x \over x}$} @cite{sin(x) / x}: -Using the stack: @kbd{C-x ( RET S TAB / C-x )}. - -Using algebraic entry: @kbd{C-x ( ' sin($)/$ RET C-x )}. +Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. + +Using algebraic entry: @kbd{C-x ( ' sin($)/$ @key{RET} C-x )}. @noindent Computing the logarithm: -Using the stack: @kbd{C-x ( TAB B C-x )} - -Using algebraic entry: @kbd{C-x ( ' log($,$$) RET C-x )}. +Using the stack: @kbd{C-x ( @key{TAB} B C-x )} + +Using algebraic entry: @kbd{C-x ( ' log($,$$) @key{RET} C-x )}. @noindent Computing the vector of integers: -Using the stack: @kbd{C-x ( 1 RET 1 C-u v x C-x )}. (Recall that +Using the stack: @kbd{C-x ( 1 @key{RET} 1 C-u v x C-x )}. (Recall that @kbd{C-u v x} takes the vector size, starting value, and increment from the stack.) @@ -9326,26 +9231,26 @@ number from the stack and uses it as the prefix argument for the next command.) -Using algebraic entry: @kbd{C-x ( ' index($) RET C-x )}. +Using algebraic entry: @kbd{C-x ( ' index($) @key{RET} C-x )}. @node Programming Answer 4, Programming Answer 5, Programming Answer 3, Answers to Exercises @subsection Programming Tutorial Exercise 4 @noindent -Here's one way: @kbd{C-x ( RET V R + TAB v l / C-x )}. +Here's one way: @kbd{C-x ( @key{RET} V R + @key{TAB} v l / C-x )}. @node Programming Answer 5, Programming Answer 6, Programming Answer 4, Answers to Exercises @subsection Programming Tutorial Exercise 5 -@group -@smallexample +@smallexample +@group 2: 1 1: 1.61803398502 2: 1.61803398502 1: 20 . 1: 1.61803398875 . . - 1 RET 20 Z < & 1 + Z > I H P -@end smallexample -@end group + 1 @key{RET} 20 Z < & 1 + Z > I H P +@end group +@end smallexample @noindent This answer is quite accurate. @@ -9366,7 +9271,7 @@ and @cite{n+2}. Here's one program that does the job: @example -C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] RET v u DEL C-x ) +C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x ) @end example @noindent @@ -9386,15 +9291,15 @@ the loop counter itself accumulates the sum of reciprocals. We use a separate variable to hold the integer counter. -@group -@smallexample +@smallexample +@group 1: 1 2: 1 1: . . 1: 4 . - 1 t 1 1 RET 4 Z ( t 2 r 1 1 + s 1 & Z ) -@end smallexample -@end group + 1 t 1 1 @key{RET} 4 Z ( t 2 r 1 1 + s 1 & Z ) +@end group +@end smallexample @noindent The body of the loop goes as follows: First save the harmonic sum @@ -9405,16 +9310,16 @@ the ``loop counter'' by that amount and keep going until the loop counter exceeds 4. -@group -@smallexample +@smallexample +@group 2: 31 3: 31 1: 3.99498713092 2: 3.99498713092 . 1: 4.02724519544 . - r 1 r 2 RET 31 & + -@end smallexample -@end group + r 1 r 2 @key{RET} 31 & + +@end group +@end smallexample Thus we find that the 30th harmonic number is 3.99, and the 31st harmonic number is 4.02. @@ -9434,95 +9339,95 @@ pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group -@smallexample +@smallexample +@group 2: sin(cos(x)) - 0.5 3: 4.5 1: 4.5 2: sin(cos(x)) - 0.5 . 1: -(sin(x) cos(cos(x))) . -' sin(cos(x))-0.5 RET 4.5 m r C-x ( Z ` TAB RET a d x RET - -@end smallexample -@end group -@noindent -@group -@smallexample +' sin(cos(x))-0.5 @key{RET} 4.5 m r C-x ( Z ` @key{TAB} @key{RET} a d x @key{RET} + +@end group +@end smallexample +@noindent +@smallexample +@group 2: 4.5 1: x + (sin(cos(x)) - 0.5) / sin(x) cos(cos(x)) . - / ' x RET TAB - t 1 -@end smallexample -@end group + / ' x @key{RET} @key{TAB} - t 1 +@end group +@end smallexample Now, we enter the loop. We'll use a repeat loop with a 20-repetition limit just in case the method fails to converge for some reason. (Normally, the @w{@kbd{Z /}} command will stop the loop before all 20 repetitions are done.) -@group -@smallexample +@smallexample +@group 1: 4.5 3: 4.5 2: 4.5 . 2: x + (sin(cos(x)) ... 1: 5.24196456928 1: 4.5 . . - 20 Z < RET r 1 TAB s l x RET -@end smallexample -@end group + 20 Z < @key{RET} r 1 @key{TAB} s l x @key{RET} +@end group +@end smallexample This is the new guess for @cite{x}. Now we compare it with the old one to see if we've converged. -@group -@smallexample +@smallexample +@group 3: 5.24196 2: 5.24196 1: 5.24196 1: 5.26345856348 2: 5.24196 1: 0 . . 1: 4.5 . . - RET M-TAB a = Z / Z > Z ' C-x ) -@end smallexample -@end group + @key{RET} M-@key{TAB} a = Z / Z > Z ' C-x ) +@end group +@end smallexample The loop converges in just a few steps to this value. To check the result, we can simply substitute it back into the equation. -@group -@smallexample +@smallexample +@group 2: 5.26345856348 1: 0.499999999997 . - RET ' sin(cos($)) RET -@end smallexample -@end group + @key{RET} ' sin(cos($)) @key{RET} +@end group +@end smallexample Let's test the new definition again: -@group -@smallexample +@smallexample +@group 2: x^2 - 9 1: 3. 1: 1 . . - ' x^2-9 RET 1 X -@end smallexample -@end group + ' x^2-9 @key{RET} 1 X +@end group +@end smallexample Once again, here's the full Newton's Method definition: -@group -@example -C-x ( Z ` TAB RET a d x RET / ' x RET TAB - t 1 - 20 Z < RET r 1 TAB s l x RET - RET M-TAB a = Z / +@example +@group +C-x ( Z ` @key{TAB} @key{RET} a d x @key{RET} / ' x @key{RET} @key{TAB} - t 1 + 20 Z < @key{RET} r 1 @key{TAB} s l x @key{RET} + @key{RET} M-@key{TAB} a = Z / Z > Z ' C-x ) -@end example -@end group +@end group +@end example @c [fix-ref Nesting and Fixed Points] It turns out that Calc has a built-in command for applying a formula @@ -9553,14 +9458,14 @@ pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group -@smallexample +@smallexample +@group 1: 1. 1: 1. . . - 1.0 RET C-x ( Z ` s 1 0 t 2 -@end smallexample -@end group + 1.0 @key{RET} C-x ( Z ` s 1 0 t 2 +@end group +@end smallexample Here, variable 1 holds @cite{z} and variable 2 holds the adjustment factor. If @cite{z < 5}, we use a loop to increase it. @@ -9570,86 +9475,86 @@ and will never converge because fractions compare equal only if they are exactly equal, not just equal to within the current precision.) -@group -@smallexample +@smallexample +@group 3: 1. 2: 1. 1: 6. 2: 1. 1: 1 . 1: 5 . . - RET 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] -@end smallexample -@end group + @key{RET} 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] +@end group +@end smallexample Now we compute the initial part of the sum: @c{$\ln z - {1 \over 2z}$} @cite{ln(z) - 1/2z} minus the adjustment factor. -@group -@smallexample +@smallexample +@group 2: 1.79175946923 2: 1.7084261359 1: -0.57490719743 1: 0.0833333333333 1: 2.28333333333 . . . L r 1 2 * & - r 2 - -@end smallexample -@end group +@end group +@end smallexample Now we evaluate the series. We'll use another ``for'' loop counting up the value of @cite{2 n}. (Calc does have a summation command, @kbd{a +}, but we'll use loops just to get more practice with them.) -@group -@smallexample +@smallexample +@group 3: -0.5749 3: -0.5749 4: -0.5749 2: -0.5749 2: 2 2: 1:6 3: 1:6 1: 2.3148e-3 1: 40 1: 2 2: 2 . . . 1: 36. . - 2 RET 40 Z ( RET k b TAB RET r 1 TAB ^ * / - -@end smallexample -@end group -@noindent -@group -@smallexample + 2 @key{RET} 40 Z ( @key{RET} k b @key{TAB} @key{RET} r 1 @key{TAB} ^ * / + +@end group +@end smallexample +@noindent +@smallexample +@group 3: -0.5749 3: -0.5772 2: -0.5772 1: -0.577215664892 2: -0.5749 2: -0.5772 1: 0 . 1: 2.3148e-3 1: -0.5749 . . . - TAB RET M-TAB - RET M-TAB a = Z / 2 Z ) Z ' C-x ) -@end smallexample -@end group + @key{TAB} @key{RET} M-@key{TAB} - @key{RET} M-@key{TAB} a = Z / 2 Z ) Z ' C-x ) +@end group +@end smallexample This is the value of @c{$-\gamma$} @cite{- gamma}, with a slight bit of roundoff error. To get a full 12 digits, let's use a higher precision: -@group -@smallexample +@smallexample +@group 2: -0.577215664892 2: -0.577215664892 1: 1. 1: -0.577215664901532 - 1. RET p 16 RET X -@end smallexample -@end group + 1. @key{RET} p 16 @key{RET} X +@end group +@end smallexample Here's the complete sequence of keystrokes: -@group -@example +@example +@group C-x ( Z ` s 1 0 t 2 - RET 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] + @key{RET} 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] L r 1 2 * & - r 2 - - 2 RET 40 Z ( RET k b TAB RET r 1 TAB ^ * / - TAB RET M-TAB - RET M-TAB a = Z / + 2 @key{RET} 40 Z ( @key{RET} k b @key{TAB} @key{RET} r 1 @key{TAB} ^ * / + @key{TAB} @key{RET} M-@key{TAB} - @key{RET} M-@key{TAB} a = Z / 2 Z ) Z ' C-x ) -@end example -@end group +@end group +@end example @node Programming Answer 10, Programming Answer 11, Programming Answer 9, Answers to Exercises @subsection Programming Tutorial Exercise 10 @@ -9669,83 +9574,83 @@ pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group -@smallexample +@smallexample +@group 2: 5 x^4 + (x + 1)^2 3: 5 x^4 + (x + 1)^2 1: 6 2: 0 . 1: 6 . - ' 5 x^4 + (x+1)^2 RET 6 C-x ( Z ` [ ] t 1 0 TAB -@end smallexample -@end group + ' 5 x^4 + (x+1)^2 @key{RET} 6 C-x ( Z ` [ ] t 1 0 @key{TAB} +@end group +@end smallexample @noindent Variable 1 will accumulate the vector of coefficients. -@group -@smallexample +@smallexample +@group 2: 0 3: 0 2: 5 x^4 + ... 1: 5 x^4 + ... 2: 5 x^4 + ... 1: 1 . 1: 1 . . - Z ( TAB RET 0 s l x RET M-TAB ! / s | 1 -@end smallexample -@end group + Z ( @key{TAB} @key{RET} 0 s l x @key{RET} M-@key{TAB} ! / s | 1 +@end group +@end smallexample @noindent Note that @kbd{s | 1} appends the top-of-stack value to the vector in a variable; it is completely analogous to @kbd{s + 1}. We could -have written instead, @kbd{r 1 TAB | t 1}. - -@group -@smallexample +have written instead, @kbd{r 1 @key{TAB} | t 1}. + +@smallexample +@group 1: 20 x^3 + 2 x + 2 1: 0 1: [1, 2, 1, 0, 5, 0, 0] . . . - a d x RET 1 Z ) DEL r 1 Z ' C-x ) -@end smallexample -@end group + a d x @key{RET} 1 Z ) @key{DEL} r 1 Z ' C-x ) +@end group +@end smallexample To convert back, a simple method is just to map the coefficients against a table of powers of @cite{x}. -@group -@smallexample +@smallexample +@group 2: [1, 2, 1, 0, 5, 0, 0] 2: [1, 2, 1, 0, 5, 0, 0] 1: 6 1: [0, 1, 2, 3, 4, 5, 6] . . - 6 RET 1 + 0 RET 1 C-u v x - -@end smallexample -@end group -@noindent -@group -@smallexample + 6 @key{RET} 1 + 0 @key{RET} 1 C-u v x + +@end group +@end smallexample +@noindent +@smallexample +@group 2: [1, 2, 1, 0, 5, 0, 0] 2: 1 + 2 x + x^2 + 5 x^4 1: [1, x, x^2, x^3, ... ] . . - ' x RET TAB V M ^ * -@end smallexample -@end group + ' x @key{RET} @key{TAB} V M ^ * +@end group +@end smallexample Once again, here are the whole polynomial to/from vector programs: -@group -@example -C-x ( Z ` [ ] t 1 0 TAB - Z ( TAB RET 0 s l x RET M-TAB ! / s | 1 - a d x RET +@example +@group +C-x ( Z ` [ ] t 1 0 @key{TAB} + Z ( @key{TAB} @key{RET} 0 s l x @key{RET} M-@key{TAB} ! / s | 1 + a d x @key{RET} 1 Z ) r 1 Z ' C-x ) -C-x ( 1 + 0 RET 1 C-u v x ' x RET TAB V M ^ * C-x ) -@end example -@end group +C-x ( 1 + 0 @key{RET} 1 C-u v x ' x @key{RET} @key{TAB} V M ^ * C-x ) +@end group +@end example @node Programming Answer 11, Programming Answer 12, Programming Answer 10, Answers to Exercises @subsection Programming Tutorial Exercise 11 @@ -9753,18 +9658,18 @@ @noindent First we define a dummy program to go on the @kbd{z s} key. The true @w{@kbd{z s}} key is supposed to take two numbers from the stack and -return one number, so @kbd{DEL} as a dummy definition will make +return one number, so @key{DEL} as a dummy definition will make sure the stack comes out right. -@group -@smallexample +@smallexample +@group 2: 4 1: 4 2: 4 1: 2 . 1: 2 . . - 4 RET 2 C-x ( DEL C-x ) Z K s RET 2 -@end smallexample -@end group + 4 @key{RET} 2 C-x ( @key{DEL} C-x ) Z K s @key{RET} 2 +@end group +@end smallexample The last step replaces the 2 that was eaten during the creation of the dummy @kbd{z s} command. Now we move on to the real @@ -9774,57 +9679,57 @@ (Because this definition is long, it will be repeated in concise form below. You can use @kbd{M-# m} to load it from there.) -@group -@smallexample +@smallexample +@group 2: 4 4: 4 3: 4 2: 4 1: 2 3: 2 2: 2 1: 2 . 2: 4 1: 0 . 1: 2 . . - C-x ( M-2 RET a = Z [ DEL DEL 1 Z : - -@end smallexample -@end group -@noindent -@group -@smallexample + C-x ( M-2 @key{RET} a = Z [ @key{DEL} @key{DEL} 1 Z : + +@end group +@end smallexample +@noindent +@smallexample +@group 4: 4 2: 4 2: 3 4: 3 4: 3 3: 3 3: 2 1: 2 1: 2 3: 2 3: 2 2: 2 2: 2 . . 2: 3 2: 3 1: 3 1: 0 1: 2 1: 1 . . . . - RET 0 a = Z [ DEL DEL 0 Z : TAB 1 - TAB M-2 RET 1 - z s -@end smallexample -@end group + @key{RET} 0 a = Z [ @key{DEL} @key{DEL} 0 Z : @key{TAB} 1 - @key{TAB} M-2 @key{RET} 1 - z s +@end group +@end smallexample @noindent (Note that the value 3 that our dummy @kbd{z s} produces is not correct; it is merely a placeholder that will do just as well for now.) -@group -@smallexample +@smallexample +@group 3: 3 4: 3 3: 3 2: 3 1: -6 2: 3 3: 3 2: 3 1: 9 . 1: 2 2: 3 1: 3 . . 1: 2 . . - M-TAB M-TAB TAB RET M-TAB z s * - - -@end smallexample -@end group -@noindent -@group -@smallexample + M-@key{TAB} M-@key{TAB} @key{TAB} @key{RET} M-@key{TAB} z s * - + +@end group +@end smallexample +@noindent +@smallexample +@group 1: -6 2: 4 1: 11 2: 11 . 1: 2 . 1: 11 . . - Z ] Z ] C-x ) Z K s RET DEL 4 RET 2 z s M-RET k s -@end smallexample -@end group + Z ] Z ] C-x ) Z K s @key{RET} @key{DEL} 4 @key{RET} 2 z s M-@key{RET} k s +@end group +@end smallexample Even though the result that we got during the definition was highly bogus, once the definition is complete the @kbd{z s} command gets @@ -9832,19 +9737,19 @@ Here's the full program once again: -@group -@example -C-x ( M-2 RET a = - Z [ DEL DEL 1 - Z : RET 0 a = - Z [ DEL DEL 0 - Z : TAB 1 - TAB M-2 RET 1 - z s - M-TAB M-TAB TAB RET M-TAB z s * - +@example +@group +C-x ( M-2 @key{RET} a = + Z [ @key{DEL} @key{DEL} 1 + Z : @key{RET} 0 a = + Z [ @key{DEL} @key{DEL} 0 + Z : @key{TAB} 1 - @key{TAB} M-2 @key{RET} 1 - z s + M-@key{TAB} M-@key{TAB} @key{TAB} @key{RET} M-@key{TAB} z s * - Z ] Z ] C-x ) -@end example -@end group +@end group +@end example You can read this definition using @kbd{M-# m} (@code{read-kbd-macro}) followed by @kbd{Z K s}, without having to make a dummy definition @@ -9863,7 +9768,7 @@ Stirling numbers in a convenient variable: @smallexample -s e StirlingRules RET +s e StirlingRules @key{RET} [ s(n,n) := 1 :: n >= 0, s(n,0) := 0 :: n > 0, s(n,m) := s(n-1,m-1) - (n-1) s(n-1,m) :: n >= m :: m >= 1 ] @@ -9872,15 +9777,15 @@ Now, it's just a matter of applying the rules: -@group -@smallexample +@smallexample +@group 2: 4 1: s(4, 2) 1: 11 1: 2 . . . - 4 RET 2 C-x ( ' s($$,$) RET a r StirlingRules RET C-x ) -@end smallexample -@end group + 4 @key{RET} 2 C-x ( ' s($$,$) @key{RET} a r StirlingRules @key{RET} C-x ) +@end group +@end smallexample As in the case of the @code{fib} rules, it would be useful to put these rules in @code{EvalRules} and to add a @samp{:: remember} condition to @@ -9942,7 +9847,9 @@ @kindex M-# c @kindex M-# M-# -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex M-# # In most installations, the @kbd{M-# c} key sequence is a more convenient way to start the Calculator. Also, @kbd{M-# M-#} and @@ -9999,13 +9906,17 @@ tendency to drop you into the Calc Trail window instead, which @kbd{M-# o} takes care not to do.) -@c @mindex M-# q +@ignore +@mindex M-# q +@end ignore For one quick calculation, you can type @kbd{M-# q} (@code{quick-calc}) which prompts you for a formula (like @samp{2+3/4}). The result is displayed at the bottom of the Emacs screen without ever creating any special Calculator windows. @xref{Quick Calculator}. -@c @mindex M-# k +@ignore +@mindex M-# k +@end ignore Finally, if you are using the X window system you may want to try @kbd{M-# k} (@code{calc-keypad}) which runs Calc with a ``calculator keypad'' picture as well as a stack display. Click on @@ -10028,15 +9939,17 @@ user interface (standard, Keypad, or Embedded) is currently active. It also cancels @code{calc-edit} mode if used from there. -@kindex d SPC +@kindex d @key{SPC} @pindex calc-refresh @cindex Refreshing a garbled display @cindex Garbled displays, refreshing -The @kbd{d SPC} key sequence (@code{calc-refresh}) redraws the contents +The @kbd{d @key{SPC}} key sequence (@code{calc-refresh}) redraws the contents of the Calculator buffer from memory. Use this if the contents of the buffer have been damaged somehow. -@c @mindex o +@ignore +@mindex o +@end ignore The @kbd{o} key (@code{calc-realign}) moves the cursor back to its ``home'' position at the bottom of the Calculator buffer. @@ -10250,7 +10163,7 @@ The @key{RET} (or equivalent @key{SPC}) key is only required to separate two consecutive numbers. (After all, if you typed @kbd{1 2} by themselves the Calculator -would enter the number 12.) If you press @kbd{RET} or @kbd{SPC} @emph{not} +would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not} right after typing a number, the key duplicates the number on the top of the stack. @kbd{@key{RET} *} is thus a handy way to square a number.@refill @@ -10294,7 +10207,7 @@ These notations are described later in this manual with the corresponding data types. @xref{Data Types}. -During numeric entry, the only editing key available is @kbd{DEL}. +During numeric entry, the only editing key available is @key{DEL}. @node Algebraic Entry, Quick Calculator, Numeric Entry, Introduction @section Algebraic Entry @@ -10354,7 +10267,7 @@ is the command to quit Calc, @kbd{M-p} sets the precision, and @kbd{M-m t} (or @kbd{M-m M-t}, if you prefer) turns total algebraic mode back off again. Meta keys also terminate algebraic entry, so -that @kbd{2+3 M-S} is equivalent to @kbd{2+3 RET M-S}. The symbol +that @kbd{2+3 M-S} is equivalent to @kbd{2+3 @key{RET} M-S}. The symbol @samp{Alg*} will appear in the mode line whenever you are in this mode. Pressing @kbd{'} (the apostrophe) a second time re-enters the previous @@ -10394,12 +10307,12 @@ @samp{$,$$} exchanges the top two elements of the stack, just like the @key{TAB} key. -You can finish an algebraic entry with @kbd{M-=} or @kbd{M-RET} instead +You can finish an algebraic entry with @kbd{M-=} or @kbd{M-@key{RET}} instead of @key{RET}. This uses @kbd{=} to evaluate the variables in each formula that goes onto the stack. (Thus @kbd{' pi @key{RET}} pushes -the variable @samp{pi}, but @kbd{' pi M-RET} pushes 3.1415.) - -If you finish your algebraic entry by pressing @kbd{LFD} (or @kbd{C-j}) +the variable @samp{pi}, but @kbd{' pi M-@key{RET}} pushes 3.1415.) + +If you finish your algebraic entry by pressing @key{LFD} (or @kbd{C-j}) instead of @key{RET}, Calc disables the default simplifications (as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3 @@ -10558,7 +10471,7 @@ information, i.e., if you undo, then enter a number on the stack or make any other change, then it will be too late to redo. -@kindex M-RET +@kindex M-@key{RET} @pindex calc-last-args @cindex Last-arguments feature @cindex Arguments, restoring @@ -11089,7 +11002,9 @@ the complex conjugate of a vector is a vector of the complex conjugates of its elements.@refill -@c @starindex +@ignore +@starindex +@end ignore @tindex vec Algebraic functions for building vectors include @samp{vec(a, b, c)} to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an @c{$n\times m$} @@ -11111,8 +11026,8 @@ marks and backslashes are written @samp{\"} and @samp{\\}, respectively, inside strings. Other notations introduced by backslashes are: -@group -@example +@example +@group \a 7 \^@@ 0 \b 8 \^a-z 1-26 \e 27 \^[ 27 @@ -11121,8 +11036,8 @@ \r 13 \^^ 30 \t 9 \^_ 31 \^? 127 -@end example -@end group +@end group +@end example @noindent Finally, a backslash followed by three octal digits produces any @@ -11146,7 +11061,9 @@ @pxref{Compositions}. Strings also provide a convenient way to do conversions between ASCII characters and integers. -@c @starindex +@ignore +@starindex +@end ignore @tindex string There is a @code{string} function which provides a different display format for strings. Basically, @samp{string(@var{s})}, where @var{s} @@ -11163,7 +11080,9 @@ (same as shown above, but without the backslash). The quote and backslash characters are left alone, as are characters 128 and above. -@c @starindex +@ignore +@starindex +@end ignore @tindex bstring The @code{bstring} function is just like @code{string} except that the resulting string is breakable across multiple lines if it doesn't @@ -11184,17 +11103,29 @@ degrees, minutes, and seconds. @kindex @@ -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex ' (HMS forms) -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex " (HMS forms) -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex h (HMS forms) -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex o (HMS forms) -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex m (HMS forms) -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s (HMS forms) The default format for HMS values is @samp{@var{hours}@@ @var{mins}' @var{secs}"}. During entry, the letters @@ -11343,10 +11274,10 @@ @noindent @cindex Modulo forms A @dfn{modulo form} is a real number which is taken modulo (i.e., within -an integer multiple of) some value @cite{M}. Arithmetic modulo @cite{M} +an integer multiple of) some value @var{M}. Arithmetic modulo @var{M} often arises in number theory. Modulo forms are written -`@i{a} @t{mod} @i{M}', -where @cite{a} and @cite{M} are real numbers or HMS forms, and +`@var{a} @t{mod} @var{M}', +where @var{a} and @var{M} are real numbers or HMS forms, and @c{$0 \le a < M$} @cite{0 <= a < @var{M}}. In many applications @cite{a} and @cite{M} will be @@ -11369,22 +11300,26 @@ actually computing the power and then reducing.) @cindex Modulo division -Two modulo forms `@i{a} @t{mod} @i{M}' and `@i{b} @t{mod} @i{M}' +Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}' can be divided if @cite{a}, @cite{b}, and @cite{M} are all integers. The result is the modulo form which, when multiplied by -`@i{b} @t{mod} @i{M}', produces `@i{a} @t{mod} @i{M}'. If +`@var{b} @t{mod} @var{M}', produces `@var{a} @t{mod} @var{M}'. If there is no solution to this equation (which can happen only when @cite{M} is non-prime), or if any of the arguments are non-integers, the division is left in symbolic form. Other operations, such as square roots, are not yet supported for modulo forms. (Note that, although -@w{`@t{(}@i{a} @t{mod} @i{M}@t{)^.5}'} will compute a ``modulo square root'' +@w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root'' in the sense of reducing @c{$\sqrt a$} @cite{sqrt(a)} modulo @cite{M}, this is not a useful definition from the number-theoretical point of view.)@refill -@c @mindex M +@ignore +@mindex M +@end ignore @kindex M (modulo forms) -@c @mindex mod +@ignore +@mindex mod +@end ignore @tindex mod (operator) To create a modulo form during numeric entry, press the shift-@kbd{M} key to enter the word @samp{mod}. As a special convenience, pressing @@ -11408,7 +11343,9 @@ enter the formula @samp{(x + 2) mod 5}, Calc propagates the modulus to each of the coefficients: @samp{(1 mod 5) x + (2 mod 5)}. -@c @starindex +@ignore +@starindex +@end ignore @tindex makemod The algebraic function @samp{makemod(a, m)} builds the modulo form @w{@samp{a mod m}}. @@ -11421,7 +11358,7 @@ @cindex Standard deviations An @dfn{error form} is a number with an associated standard deviation, as in @samp{2.3 +/- 0.12}. The notation -`@i{x} @t{+/-} @c{$\sigma$} +`@var{x} @t{+/-} @c{$\sigma$} @asis{sigma}' stands for an uncertain value which follows a normal or Gaussian distribution of mean @cite{x} and standard deviation or ``error'' @c{$\sigma$} @@ -11464,10 +11401,10 @@ of standard deviations. Actual errors often are neither Gaussian-distributed nor uncorrelated, and the above formulas are valid only when errors are small. As an example, the error arising from -`@t{sin(}@i{x} @t{+/-} @c{$\sigma$} -@i{sigma}@t{)}' is +`@t{sin(}@var{x} @t{+/-} @c{$\sigma$} +@var{sigma}@t{)}' is `@c{$\sigma$\nobreak} -@i{sigma} @t{abs(cos(}@i{x}@t{))}'. When @cite{x} is close to zero, +@var{sigma} @t{abs(cos(}@var{x}@t{))}'. When @cite{x} is close to zero, @c{$\cos x$} @cite{cos(x)} is close to one so the error in the sine is close to @c{$\sigma$} @@ -11485,7 +11422,9 @@ in @cite{x} had been small, the error in @c{$\sin x$} @cite{sin(x)} would indeed have been negligible.@refill -@c @mindex p +@ignore +@mindex p +@end ignore @kindex p (error forms) @tindex +/- To enter an error form during regular numeric entry, use the @kbd{p} @@ -11506,7 +11445,9 @@ Error forms may also be composed of HMS forms. For best results, both the mean and the error should be HMS forms if either one is. -@c @starindex +@ignore +@starindex +@end ignore @tindex sdev The algebraic function @samp{sdev(a, b)} builds the error form @samp{a +/- b}. @@ -11585,11 +11526,11 @@ While it may seem that intervals and error forms are similar, they are based on entirely different concepts of inexact quantities. An error -form `@i{x} @t{+/-} @c{$\sigma$} -@i{sigma}' means a variable is random, and its value could +form `@var{x} @t{+/-} @c{$\sigma$} +@var{sigma}' means a variable is random, and its value could be anything but is ``probably'' within one @c{$\sigma$} -@i{sigma} of the mean value @cite{x}. -An interval `@t{[}@i{a} @t{..@:} @i{b}@t{]}' means a variable's value +@var{sigma} of the mean value @cite{x}. +An interval `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a variable's value is unknown, but guaranteed to lie in the specified range. Error forms are statistical or ``average case'' approximations; interval arithmetic tends to produce ``worst case'' bounds on an answer.@refill @@ -11600,7 +11541,9 @@ @xref{Set Operations}, for commands that interpret interval forms as subsets of the set of real numbers. -@c @starindex +@ignore +@starindex +@end ignore @tindex intv The algebraic function @samp{intv(n, a, b)} builds an interval form from @samp{a} to @samp{b}; @samp{n} is an integer code which must @@ -11622,14 +11565,22 @@ @section Incomplete Objects @noindent -@c @mindex [ ] +@ignore +@mindex [ ] +@end ignore @kindex [ -@c @mindex ( ) +@ignore +@mindex ( ) +@end ignore @kindex ( @kindex , -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex ] -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex ) @cindex Incomplete vectors @cindex Incomplete complex numbers @@ -11919,8 +11870,8 @@ @section Stack Manipulation Commands @noindent -@kindex RET -@kindex SPC +@kindex @key{RET} +@kindex @key{SPC} @pindex calc-enter @cindex Duplicating stack entries To duplicate the top object on the stack, press @key{RET} or @key{SPC} @@ -11936,7 +11887,7 @@ @kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and @kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.@refill -@kindex LFD +@kindex @key{LFD} @pindex calc-over The @key{LFD} (@code{calc-over}) command (on a key marked Line-Feed if you have it, else on @kbd{C-j}) is like @code{calc-enter} @@ -11946,7 +11897,7 @@ are both equivalent to @kbd{C-u - 2 @key{RET}}, producing @samp{10 20 30 20}.@refill -@kindex DEL +@kindex @key{DEL} @kindex C-d @pindex calc-pop @cindex Removing stack entries @@ -11964,16 +11915,16 @@ @kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and @kbd{C-u 0 @key{DEL}} leaves an empty stack.@refill -@kindex M-DEL +@kindex M-@key{DEL} @pindex calc-pop-above -The @key{M-DEL} (@code{calc-pop-above}) command is to @key{DEL} what +The @key{M-@key{DEL}} (@code{calc-pop-above}) command is to @key{DEL} what @key{LFD} is to @key{RET}: It interprets the sign of the numeric prefix argument in the opposite way, and the default argument is 2. -Thus @key{M-DEL} by itself removes the second-from-top stack element, -leaving the first, third, fourth, and so on; @kbd{M-3 M-DEL} deletes +Thus @key{M-@key{DEL}} by itself removes the second-from-top stack element, +leaving the first, third, fourth, and so on; @kbd{M-3 M-@key{DEL}} deletes the third stack element. -@kindex TAB +@kindex @key{TAB} @pindex calc-roll-down To exchange the top two elements of the stack, press @key{TAB} (@code{calc-roll-down}). Given a positive numeric prefix argument, the @@ -11987,30 +11938,30 @@ @kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and @kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.@refill -@kindex M-TAB +@kindex M-@key{TAB} @pindex calc-roll-up -The command @key{M-TAB} (@code{calc-roll-up}) is analogous to @key{TAB} +The command @kbd{M-@key{TAB}} (@code{calc-roll-up}) is analogous to @key{TAB} except that it rotates upward instead of downward. Also, the default with no prefix argument is to rotate the top 3 elements. For example, with @samp{10 20 30 40 50} on the stack, -@key{M-TAB} creates @samp{10 20 40 50 30}, -@kbd{C-u 4 @key{M-TAB}} creates @samp{10 30 40 50 20}, -@kbd{C-u - 2 @key{M-TAB}} creates @samp{30 40 50 10 20}, and -@kbd{C-u 0 @key{M-TAB}} creates @samp{50 40 30 20 10}.@refill - -A good way to view the operation of @key{TAB} and @key{M-TAB} is in +@kbd{M-@key{TAB}} creates @samp{10 20 40 50 30}, +@kbd{C-u 4 M-@key{TAB}} creates @samp{10 30 40 50 20}, +@kbd{C-u - 2 M-@key{TAB}} creates @samp{30 40 50 10 20}, and +@kbd{C-u 0 M-@key{TAB}} creates @samp{50 40 30 20 10}.@refill + +A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in terms of moving a particular element to a new position in the stack. -With a positive argument @i{n}, @key{TAB} moves the top stack -element down to level @i{n}, making room for it by pulling all the -intervening stack elements toward the top. @key{M-TAB} moves the -element at level @i{n} up to the top. (Compare with @key{LFD}, -which copies instead of moving the element in level @i{n}.) - -With a negative argument @i{-n}, @key{TAB} rotates the stack -to move the object in level @i{n} to the deepest place in the -stack, and the object in level @i{n+1} to the top. @key{M-TAB} +With a positive argument @var{n}, @key{TAB} moves the top stack +element down to level @var{n}, making room for it by pulling all the +intervening stack elements toward the top. @kbd{M-@key{TAB}} moves the +element at level @var{n} up to the top. (Compare with @key{LFD}, +which copies instead of moving the element in level @var{n}.) + +With a negative argument @i{-@var{n}}, @key{TAB} rotates the stack +to move the object in level @var{n} to the deepest place in the +stack, and the object in level @i{@var{n}+1} to the top. @kbd{M-@key{TAB}} rotates the deepest stack element to be in level @i{n}, also -putting the top stack element in level @i{n+1}. +putting the top stack element in level @i{@var{n}+1}. @xref{Selecting Subformulas}, for a way to apply these commands to any portion of a vector or formula on the stack. @@ -12208,10 +12159,10 @@ simplified version of the formula onto the stack after the original formula (rather than replacing the original formula). -Note that you could get the same effect by typing @kbd{RET a s}, +Note that you could get the same effect by typing @kbd{@key{RET} a s}, copying the formula and then simplifying the copy. One difference is that for a very large formula the time taken to format the -intermediate copy in @kbd{RET a s} could be noticeable; @kbd{K a s} +intermediate copy in @kbd{@key{RET} a s} could be noticeable; @kbd{K a s} would avoid this extra work. Even stack manipulation commands are affected. @key{TAB} works by @@ -12385,7 +12336,7 @@ If you need to work with a particular fixed accuracy (say, dollars and cents with two digits after the decimal point), one solution is to work with integers and an ``implied'' decimal point. For example, $8.99 -divided by 6 would be entered @kbd{899 RET 6 /}, yielding 149.833 +divided by 6 would be entered @kbd{899 @key{RET} 6 /}, yielding 149.833 (actually $1.49833 with our implied decimal point); pressing @kbd{R} would round this to 150 cents, i.e., $1.50. @@ -12832,11 +12783,11 @@ A declaration is in general a vector of @dfn{type symbols} and @dfn{range} values. If there is only one type symbol or range value, you can write it directly rather than enclosing it in a vector. -For example, @kbd{s d foo RET real RET} declares @code{foo} to -be a real number, and @kbd{s d bar RET [int, const, [1..6]] RET} +For example, @kbd{s d foo @key{RET} real @key{RET}} declares @code{foo} to +be a real number, and @kbd{s d bar @key{RET} [int, const, [1..6]] @key{RET}} declares @code{bar} to be a constant integer between 1 and 6. (Actually, you can omit the outermost brackets and Calc will -provide them for you: @kbd{s d bar RET int, const, [1..6] RET}.) +provide them for you: @kbd{s d bar @key{RET} int, const, [1..6] @key{RET}}.) @cindex @code{Decls} variable @vindex Decls @@ -12858,13 +12809,13 @@ For example, the declaration matrix -@group -@smallexample +@smallexample +@group [ [ foo, real ] [ [j, k, n], int ] [ f(1,2,3), [0 .. inf) ] ] -@end smallexample -@end group +@end group +@end smallexample @noindent declares that @code{foo} represents a real number, @code{j}, @code{k} @@ -12890,13 +12841,13 @@ more intervals or numbers that represent the set of possible values for the variable. -@group -@smallexample +@smallexample +@group [ [ a, [1, 2, 3, 4, 5] ] [ b, [1 .. 5] ] [ c, [int, 1 .. 5] ] ] -@end smallexample -@end group +@end group +@end smallexample Here @code{a} is declared to contain one of the five integers shown; @code{b} is any number in the interval from 1 to 5 (any real number @@ -12968,8 +12919,8 @@ One instance of this simplification is @samp{sqrt(x^2)} (since the @code{sqrt} function is effectively a one-half power). Normally Calc leaves this formula alone. After the command -@kbd{s d x RET real RET}, however, it can simplify the formula to -@samp{abs(x)}. And after @kbd{s d x RET nonneg RET}, Calc can +@kbd{s d x @key{RET} real @key{RET}}, however, it can simplify the formula to +@samp{abs(x)}. And after @kbd{s d x @key{RET} nonneg @key{RET}}, Calc can simplify this formula all the way to @samp{x}. If there are any intervals or real numbers in the type specifier, @@ -13088,11 +13039,17 @@ Calc consults knowledge of its own built-in functions as well as your own declarations: @samp{dint(floor(x))} returns 1. -@c @starindex +@ignore +@starindex +@end ignore @tindex dint -@c @starindex +@ignore +@starindex +@end ignore @tindex dnumint -@c @starindex +@ignore +@starindex +@end ignore @tindex dnatnum The @code{dint} function checks if its argument is an integer. The @code{dnatnum} function checks if its argument is a natural @@ -13103,27 +13060,39 @@ suitable elements, and that real infinities @samp{inf} and @samp{-inf} are considered to be integers for the purposes of these functions. -@c @starindex +@ignore +@starindex +@end ignore @tindex drat The @code{drat} function checks if its argument is rational, i.e., an integer or fraction. Infinities count as rational, but intervals and error forms do not. -@c @starindex +@ignore +@starindex +@end ignore @tindex dreal The @code{dreal} function checks if its argument is real. This includes integers, fractions, floats, real error forms, and intervals. -@c @starindex +@ignore +@starindex +@end ignore @tindex dimag The @code{dimag} function checks if its argument is imaginary, i.e., is mathematically equal to a real number times @cite{i}. -@c @starindex +@ignore +@starindex +@end ignore @tindex dpos -@c @starindex +@ignore +@starindex +@end ignore @tindex dneg -@c @starindex +@ignore +@starindex +@end ignore @tindex dnonneg The @code{dpos} function checks for positive (but nonzero) reals. The @code{dneg} function checks for negative reals. The @code{dnonneg} @@ -13134,7 +13103,9 @@ so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg} are rarely necessary. -@c @starindex +@ignore +@starindex +@end ignore @tindex dnonzero The @code{dnonzero} function checks that its argument is nonzero. This includes all nonzero real or complex numbers, all intervals that @@ -13144,9 +13115,13 @@ represent values which could be anything including zero. (This is also the set of objects considered ``true'' in conditional contexts.) -@c @starindex +@ignore +@starindex +@end ignore @tindex deven -@c @starindex +@ignore +@starindex +@end ignore @tindex dodd The @code{deven} function returns 1 if its argument is known to be an even integer (or integer-valued float); it returns 0 if its argument @@ -13154,7 +13129,9 @@ The @kbd{a s} command uses this to simplify a test of the form @samp{x % 2 = 0}. There is also an analogous @code{dodd} function. -@c @starindex +@ignore +@starindex +@end ignore @tindex drange The @code{drange} function returns a set (an interval or a vector of intervals and/or numbers; @pxref{Set Operations}) that describes @@ -13166,7 +13143,9 @@ the expression is not provably real, the @code{drange} function remains unevaluated. -@c @starindex +@ignore +@starindex +@end ignore @tindex dscalar The @code{dscalar} function returns 1 if its argument is provably scalar, or 0 if its argument is provably non-scalar. It is left @@ -13196,20 +13175,20 @@ will appear in the mode line when Calc thinks the stack display may not reflect the latest mode settings. -@kindex d RET +@kindex d @key{RET} @pindex calc-refresh-top -The @kbd{d RET} (@code{calc-refresh-top}) command reformats the +The @kbd{d @key{RET}} (@code{calc-refresh-top}) command reformats the top stack entry according to all the current modes. Positive prefix arguments reformat the top @var{n} entries; negative prefix arguments reformat the specified entry, and a prefix of zero is equivalent to -@kbd{d SPC} (@code{calc-refresh}), which reformats the entire stack. -For example, @kbd{H d s M-2 d RET} changes to scientific notation +@kbd{d @key{SPC}} (@code{calc-refresh}), which reformats the entire stack. +For example, @kbd{H d s M-2 d @key{RET}} changes to scientific notation but reformats only the top two stack entries in the new mode. The @kbd{I} prefix has another effect on the display modes. The mode is set only temporarily; the top stack entry is reformatted according to that mode, then the original mode setting is restored. In other -words, @kbd{I d s} is equivalent to @kbd{H d s d RET H d (@var{old mode})}. +words, @kbd{I d s} is equivalent to @kbd{H d s d @key{RET} H d (@var{old mode})}. @menu * Radix Modes:: @@ -13829,7 +13808,7 @@ window.@refill If you change the width of the Calculator window you may have to type -@kbd{d SPC} (@code{calc-refresh}) to re-align right-justified or centered +@kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered text. Right-justification is especially useful together with fixed-point @@ -14200,31 +14179,57 @@ @let@calcindexershow=@calcindexernoshow @c Suppress marginal notes @let@calcindexersh=@calcindexernoshow @end iftex -@c @starindex +@ignore +@starindex +@end ignore @tindex acute -@c @starindex +@ignore +@starindex +@end ignore @tindex bar -@c @starindex +@ignore +@starindex +@end ignore @tindex breve -@c @starindex +@ignore +@starindex +@end ignore @tindex check -@c @starindex +@ignore +@starindex +@end ignore @tindex dot -@c @starindex +@ignore +@starindex +@end ignore @tindex dotdot -@c @starindex +@ignore +@starindex +@end ignore @tindex dyad -@c @starindex +@ignore +@starindex +@end ignore @tindex grave -@c @starindex +@ignore +@starindex +@end ignore @tindex hat -@c @starindex +@ignore +@starindex +@end ignore @tindex Prime -@c @starindex +@ignore +@starindex +@end ignore @tindex tilde -@c @starindex +@ignore +@starindex +@end ignore @tindex under -@c @starindex +@ignore +@starindex +@end ignore @tindex Vec @iftex @endgroup @@ -14294,67 +14299,67 @@ @iftex Here are some examples of how various Calc formulas are formatted in @TeX{}: -@group -@example +@example +@group sin(a^2 / b_i) \sin\left( {a^2 \over b_i} \right) +@end group @end example @tex \let\rm\goodrm $$ \sin\left( a^2 \over b_i \right) $$ @end tex @sp 1 -@end group - -@group -@example + +@example +@group [(3, 4), 3:4, 3 +/- 4, [3 .. inf)] [3 + 4i, @{3 \over 4@}, 3 \pm 4, [3 \ldots \infty)] +@end group @end example @tex \turnoffactive $$ [3 + 4i, {3 \over 4}, 3 \pm 4, [ 3 \ldots \infty)] $$ @end tex @sp 1 -@end group - -@group -@example + +@example +@group [abs(a), abs(a / b), floor(a), ceil(a / b)] [|a|, \left| a \over b \right|, \lfloor a \rfloor, \left\lceil a \over b \right\rceil] +@end group @end example @tex $$ [|a|, \left| a \over b \right|, \lfloor a \rfloor, \left\lceil a \over b \right\rceil] $$ @end tex @sp 1 -@end group - -@group -@example + +@example +@group [sin(a), sin(2 a), sin(2 + a), sin(a / b)] [\sin@{a@}, \sin@{2 a@}, \sin(2 + a), \sin\left( @{a \over b@} \right)] +@end group @end example @tex \turnoffactive\let\rm\goodrm $$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$ @end tex @sp 2 -@end group - -@group + First with plain @kbd{d T}, then with @kbd{C-u d T}, then finally with @kbd{C-u - d T} (using the example definition @samp{\def\foo#1@{\tilde F(#1)@}}: @example - +@group [f(a), foo(bar), sin(pi)] [f(a), foo(bar), \sin{\pi}] [f(a), \hbox@{foo@}(\hbox@{bar@}), \sin@{\pi@}] [f(a), \foo@{\hbox@{bar@}@}, \sin@{\pi@}] +@end group @end example @tex \let\rm\goodrm @@ -14363,15 +14368,14 @@ $$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$ @end tex @sp 2 -@end group - -@group + First with @samp{\def\evalto@{@}}, then with @samp{\def\evalto#1\to@{@}}: @example - +@group 2 + 3 => 5 \evalto 2 + 3 \to 5 +@end group @end example @tex \turnoffactive @@ -14379,15 +14383,14 @@ $$ 5 $$ @end tex @sp 2 -@end group - -@group + First with standard @code{\to}, then with @samp{\let\to\Rightarrow}: @example - +@group [2 + 3 => 5, a / 2 => (b + c) / 2] [@{2 + 3 \to 5@}, @{@{a \over 2@} \to @{b + c \over 2@}@}] +@end group @end example @tex \turnoffactive @@ -14396,16 +14399,15 @@ $$ [{2 + 3 \to 5}, {{a \over 2} \to {b + c \over 2}}] $$} @end tex @sp 2 -@end group - -@group + Matrices normally, then changing @code{\matrix} to @code{\pmatrix}: @example - +@group [ [ a / b, 0 ], [ 0, 2^(x + 1) ] ] \matrix@{ @{a \over b@} & 0 \\ 0 & 2^@{(x + 1)@} @} \pmatrix@{ @{a \over b@} & 0 \\ 0 & 2^@{(x + 1)@} @} +@end group @end example @tex \turnoffactive @@ -14413,7 +14415,6 @@ $$ \pmatrix{ {a \over b} & 0 \cr 0 & 2^{(x + 1)} } $$ @end tex @sp 2 -@end group @end iftex @node Eqn Language Mode, Mathematica Language Mode, TeX Language Mode, Language Modes @@ -14602,14 +14603,14 @@ decide how formulas should be positioned relative to one another. For example, in the Big mode formula -@group -@example +@example +@group 2 a + b 17 + ------ c -@end example -@end group +@end group +@end example @noindent the second term of the sum is four lines tall and has line three as @@ -14669,7 +14670,9 @@ Right-associative operators like @samp{^} format the lefthand argument with one-higher precedence. -@c @starindex +@ignore +@starindex +@end ignore @tindex cprec The @code{cprec} function formats an expression with an arbitrary precedence. For example, @samp{cprec(abc, 185)} will combine into @@ -14700,12 +14703,12 @@ it can use an earlier break point from an ``outer'' formula instead. For example, a vector of sums might be formatted as: -@group -@example +@example +@group [ a + b + c, d + e + f, g + h + i, j + k + l, m ] -@end example -@end group +@end group +@end example @noindent If the @samp{m} can fit, then so, it seems, could the @samp{g}. @@ -14733,19 +14736,21 @@ @subsubsection Horizontal Compositions @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex choriz The @code{choriz} function takes a vector of objects and composes them horizontally. For example, @samp{choriz([17, a b/c, d])} formats as @w{@samp{17a b / cd}} in normal language mode, or as -@group -@example +@example +@group a b 17---d c -@end example -@end group +@end group +@end example @noindent in Big language mode. This is actually one case of the general @@ -14775,7 +14780,9 @@ @subsubsection Vertical Compositions @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex cvert The @code{cvert} function makes a vertical composition. Each component of the vector is centered in a column. The baseline of @@ -14783,16 +14790,18 @@ For example, @samp{f(cvert([a, bb, ccc]), cvert([a^2 + 1, b^2]))} formats in Big mode as -@group -@example +@example +@group f( a , 2 ) bb a + 1 ccc 2 b -@end example -@end group - -@c @starindex +@end group +@end example + +@ignore +@starindex +@end ignore @tindex cbase There are several special composition functions that work only as components of a vertical composition. The @code{cbase} function @@ -14801,19 +14810,23 @@ in @code{cbase}. Thus @samp{f(cvert([a, cbase(bb), ccc]), cvert([a^2 + 1, cbase(b^2)]))} displays as -@group -@example +@example +@group 2 a + 1 a 2 f(bb , b ) ccc -@end example -@end group - -@c @starindex +@end group +@end example + +@ignore +@starindex +@end ignore @tindex ctbase -@c @starindex +@ignore +@starindex +@end ignore @tindex cbbase There are also @code{ctbase} and @code{cbbase} functions which make the baseline of the vertical composition equal to the top @@ -14821,15 +14834,15 @@ Thus @samp{cvert([cbase(a / b)]) + cvert([ctbase(a / b)]) + cvert([cbbase(a / b)])} gives -@group -@example +@example +@group a a - - + a + b b - b -@end example -@end group +@end group +@end example There should be only one @code{cbase}, @code{ctbase}, or @code{cbbase} function in a given vertical composition. These functions can also @@ -14838,7 +14851,9 @@ @samp{cbbase()} means the baseline is the bottom line of the preceding item. -@c @starindex +@ignore +@starindex +@end ignore @tindex crule The @code{crule} function builds a ``rule,'' or horizontal line, across a vertical composition. By itself @samp{crule()} uses @samp{-} @@ -14848,31 +14863,35 @@ width of the widest item in the stack. For example, a quotient with a thick line is @samp{cvert([a + 1, cbase(crule("=")), b^2])}: -@group -@example +@example +@group a + 1 ===== 2 b -@end example -@end group - -@c @starindex +@end group +@end example + +@ignore +@starindex +@end ignore @tindex clvert -@c @starindex +@ignore +@starindex +@end ignore @tindex crvert Finally, the functions @code{clvert} and @code{crvert} act exactly like @code{cvert} except that the items are left- or right-justified in the stack. Thus @samp{clvert([a, bb, ccc]) + crvert([a, bb, ccc])} gives: -@group -@example +@example +@group a + a bb bb ccc ccc -@end example -@end group +@end group +@end example Like @code{choriz}, the vertical compositions accept a second argument which gives the precedence to use when formatting the components. @@ -14882,7 +14901,9 @@ @subsubsection Other Compositions @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex csup The @code{csup} function builds a superscripted expression. For example, @samp{csup(a, b)} looks the same as @samp{a^b} does in Big @@ -14890,7 +14911,9 @@ @samp{a} and @samp{b}, where @samp{b} is shifted up so that its bottom line is one above the baseline. -@c @starindex +@ignore +@starindex +@end ignore @tindex csub Likewise, the @code{csub} function builds a subscripted expression. This shifts @samp{b} down so that its top line is one below the @@ -14898,7 +14921,9 @@ @code{csup}). Other arrangements can be obtained by using @code{choriz} and @code{cvert} directly. -@c @starindex +@ignore +@starindex +@end ignore @tindex cflat The @code{cflat} function formats its argument in ``flat'' mode, as obtained by @samp{d O}, if the current language mode is normal @@ -14906,7 +14931,9 @@ @samp{a^(b/c)} is formatted by Big mode like @samp{csup(a, cflat(b/c))} to improve its readability. -@c @starindex +@ignore +@starindex +@end ignore @tindex cspace The @code{cspace} function creates horizontal space. For example, @samp{cspace(4)} is effectively the same as @samp{string(" ")}. @@ -14916,17 +14943,19 @@ it is formatted in the normal way and then several copies of that are composed together: @samp{cspace(4, a^2)} yields -@group -@example +@example +@group 2 2 2 2 a a a a -@end example -@end group +@end group +@end example @noindent If the number argument is zero, this is a zero-width object. -@c @starindex +@ignore +@starindex +@end ignore @tindex cvspace The @code{cvspace} function creates vertical space, or a vertical stack of copies of a certain string or formatted object. The @@ -14934,9 +14963,13 @@ argument of zero will produce an object which contributes zero height if used in a vertical composition. -@c @starindex +@ignore +@starindex +@end ignore @tindex ctspace -@c @starindex +@ignore +@starindex +@end ignore @tindex cbspace There are also @code{ctspace} and @code{cbspace} functions which create vertical space with the baseline the same as the baseline @@ -14944,8 +14977,8 @@ Thus @samp{cvspace(2, a/b) + ctspace(2, a/b) + cbspace(2, a/b)} displays as: -@group -@example +@example +@group a - a b @@ -14955,8 +14988,8 @@ - a b - b -@end example -@end group +@end group +@end example @node Information about Compositions, User-Defined Compositions, Other Compositions, Compositions @subsubsection Information about Compositions @@ -14966,7 +14999,9 @@ arguments according to the current language and other display modes, then return a certain measurement of the composition as an integer. -@c @starindex +@ignore +@starindex +@end ignore @tindex cwidth The @code{cwidth} function measures the width, in characters, of a composition. For example, @samp{cwidth(a + b)} is 5, and @@ -14974,14 +15009,20 @@ @TeX{} mode (for @samp{@{a \over b@}}). The argument may involve the composition functions described in this section. -@c @starindex +@ignore +@starindex +@end ignore @tindex cheight The @code{cheight} function measures the height of a composition. This is the total number of lines in the argument's printed form. -@c @starindex +@ignore +@starindex +@end ignore @tindex cascent -@c @starindex +@ignore +@starindex +@end ignore @tindex cdescent The functions @code{cascent} and @code{cdescent} measure the amount of the height that is above (and including) the baseline, or below @@ -15031,23 +15072,23 @@ For example, the default format for the binomial coefficient function @samp{choose(n, m)} in the Big language mode is -@group -@example +@example +@group n ( ) m -@end example -@end group +@end group +@end example @noindent You might prefer the notation, -@group -@example +@example +@group C n m -@end example -@end group +@end group +@end example @noindent To define this notation, first make sure you are in Big mode, @@ -15065,12 +15106,12 @@ off with @kbd{m O} and enter @samp{choose(a,b) + choose(7,3)} as an algebraic entry. -@group -@example +@example +@group C + C a b 7 3 -@end example -@end group +@end group +@end example As another example, let's define the usual notation for Stirling numbers of the first kind, @samp{stir1(n, m)}. This is just like @@ -15386,10 +15427,10 @@ @end example @noindent -will parse @samp{foo(1,2,3,4)} as @samp{bar([1,2,3,4])}, and -@samp{foo(1,2;3,4)} as @samp{matrix([[1,2],[3,4]])}. Also, after +will parse @samp{foo(1, 2, 3, 4)} as @samp{bar([1, 2, 3, 4])}, and +@samp{foo(1, 2; 3, 4)} as @samp{matrix([[1, 2], [3, 4]])}. Also, after some thought it's easy to see how this pair of rules will parse -@samp{foo(1,2,3)} as @samp{matrix([[1,2,3]])}, since the first +@samp{foo(1, 2, 3)} as @samp{matrix([[1, 2, 3]])}, since the first rule will only match an even number of arguments. The rule @example @@ -15417,7 +15458,7 @@ Another variant is @samp{@{ ... @}?$}, which means the body is optional only at the end of the input formula. All built-in syntax rules in Calc use this for closing delimiters, so that during -algebraic entry you can type @kbd{[sqrt(2), sqrt(3 RET}, omitting +algebraic entry you can type @kbd{[sqrt(2), sqrt(3 @key{RET}}, omitting the closing parenthesis and bracket. Calc does this automatically for trailing @samp{)}, @samp{]}, and @samp{>} tokens in syntax rules, but you can use @samp{@{ ... @}?$} explicitly to get @@ -15546,7 +15587,7 @@ @cindex @code{Modes} variable @vindex Modes The modes vector is also available in the special variable -@code{Modes}. In other words, @kbd{m g} is like @kbd{s r Modes RET}. +@code{Modes}. In other words, @kbd{m g} is like @kbd{s r Modes @key{RET}}. It will not work to store into this variable; in fact, if you do, @code{Modes} will cease to track the current modes. (The @kbd{m g} command will continue to work, however.) @@ -15600,8 +15641,8 @@ @item Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar -mode, @i{-2} for matrix mode, or @i{N} for @c{$N\times N$} -@i{NxN} matrix mode. Command is @kbd{m v}. +mode, @i{-2} for matrix mode, or @var{N} for @c{$N\times N$} +@var{N}x@var{N} matrix mode. Command is @kbd{m v}. @item Simplification mode. Default is 1. Value is @i{-1} for off (@kbd{m O}), @@ -15613,13 +15654,13 @@ or 0 if the mode is on with positive zeros. Command is @kbd{m i}. @end enumerate -For example, the sequence @kbd{M-1 m g RET 2 + ~ p} increases the +For example, the sequence @kbd{M-1 m g @key{RET} 2 + ~ p} increases the precision by two, leaving a copy of the old precision on the stack. Later, @kbd{~ p} will restore the original precision using that stack value. (This sequence might be especially useful inside a keyboard macro.) -As another example, @kbd{M-3 m g 1 - ~ DEL} deletes all but the +As another example, @kbd{M-3 m g 1 - ~ @key{DEL}} deletes all but the oldest (bottommost) stack entry. Yet another example: The HP-48 ``round'' command rounds a number @@ -15878,7 +15919,9 @@ @noindent @kindex + @pindex calc-plus -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex + The @kbd{+} (@code{calc-plus}) command adds two numbers. The numbers may be any of the standard Calc data types. The resulting sum is pushed back @@ -15942,7 +15985,9 @@ @kindex - @pindex calc-minus -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex - The @kbd{-} (@code{calc-minus}) command subtracts two values. The top number on the stack is subtracted from the one behind it, so that the @@ -15951,7 +15996,9 @@ @kindex * @pindex calc-times -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex * The @kbd{*} (@code{calc-times}) command multiplies two numbers. If one argument is a vector and the other a scalar, the scalar is multiplied by @@ -15974,7 +16021,9 @@ @kindex / @pindex calc-divide -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex / The @kbd{/} (@code{calc-divide}) command divides two numbers. When dividing a scalar @cite{B} by a square matrix @cite{A}, the computation @@ -16000,7 +16049,9 @@ @kindex ^ @pindex calc-power -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ^ The @kbd{^} (@code{calc-power}) command raises a number to a power. If the power is an integer, an exact result is computed using repeated @@ -16012,13 +16063,15 @@ @kindex I ^ @tindex nroot If you press the @kbd{I} (inverse) key first, the @kbd{I ^} command -computes an Nth root: @kbd{125 RET 3 I ^} computes the number 5. -(This is entirely equivalent to @kbd{125 RET 1:3 ^}.) +computes an Nth root: @kbd{125 @key{RET} 3 I ^} computes the number 5. +(This is entirely equivalent to @kbd{125 @key{RET} 1:3 ^}.) @kindex \ @pindex calc-idiv @tindex idiv -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex \ The @kbd{\} (@code{calc-idiv}) command divides two numbers on the stack to produce an integer result. It is equivalent to dividing with @@ -16029,7 +16082,9 @@ @kindex % @pindex calc-mod -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex % The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined @@ -16207,7 +16262,9 @@ @pindex calc-floor @tindex floor @tindex ffloor -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H F The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command truncates a real number to the next lower integer, i.e., toward minus @@ -16218,7 +16275,9 @@ @pindex calc-ceiling @tindex ceil @tindex fceil -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I F The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] command truncates toward positive infinity. Thus @kbd{3.6 I F} produces @@ -16228,7 +16287,9 @@ @pindex calc-round @tindex round @tindex fround -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H R The @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command rounds to the nearest integer. When the fractional part is .5 exactly, @@ -16240,7 +16301,9 @@ @pindex calc-trunc @tindex trunc @tindex ftrunc -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I R The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] command truncates toward zero. In other words, it ``chops off'' @@ -16254,13 +16317,21 @@ Applied to a date form, they operate on the internal numerical representation of dates, converting a date/time form into a pure date. -@c @starindex +@ignore +@starindex +@end ignore @tindex rounde -@c @starindex +@ignore +@starindex +@end ignore @tindex roundu -@c @starindex +@ignore +@starindex +@end ignore @tindex frounde -@c @starindex +@ignore +@starindex +@end ignore @tindex froundu There are two more rounding functions which can only be entered in algebraic notation. The @code{roundu} function is like @code{round} @@ -16288,7 +16359,7 @@ @cindex Fractional part of a number To compute the fractional part of a number (i.e., the amount which, when -added to `@t{floor(}@i{N}@t{)}', will produce @cite{N}) just take @cite{N} +added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n} modulo 1 using the @code{%} command.@refill Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm), @@ -16315,8 +16386,8 @@ The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the ``argument'' or polar angle of a complex number. For a number in polar notation, this is simply the second component of the pair -`@t{(}@i{r}@t{;}@c{$\theta$} -@i{theta}@t{)}'. +`@t{(}@var{r}@t{;}@c{$\theta$} +@var{theta}@t{)}'. The result is expressed according to the current angular mode and will be in the range @i{-180} degrees (exclusive) to @i{+180} degrees (inclusive), or the equivalent range in radians.@refill @@ -16342,7 +16413,9 @@ by its imaginary part; real numbers are converted to zero. With a vector or matrix argument, these functions operate element-wise.@refill -@c @mindex v p +@ignore +@mindex v p +@end ignore @kindex v p (complex) @pindex calc-pack The @kbd{v p} (@code{calc-pack}) command can pack the top two numbers on @@ -16351,7 +16424,9 @@ with an argument of @i{-2}, it produces a polar complex number. (Also, @pxref{Building Vectors}.) -@c @mindex v u +@ignore +@mindex v u +@end ignore @kindex v u (complex) @pindex calc-unpack The @kbd{v u} (@code{calc-unpack}) command takes the complex number @@ -16617,7 +16692,7 @@ converts a date form into a Unix time value, which is the number of seconds since midnight on Jan 1, 1970, or vice-versa. The numeric result will be an integer if the current precision is 12 or less; for higher -precisions, the result may be a float with (@var{precision}@i{-}12) +precisions, the result may be a float with (@var{precision}@minus{}12) digits after the decimal. Just as for @kbd{t J}, the numeric time is interpreted in the GMT time zone and the date form is interpreted in the current or specified zone. Some systems use Unix-like @@ -16751,7 +16826,9 @@ the time to midnight; hint:@: how can @code{newweek} be defined in terms of the @code{weekday} function?). -@c @starindex +@ignore +@starindex +@end ignore @tindex pwday The @samp{pwday(@var{date})} function (not on any key) computes the day-of-month number of the Sunday on or before @var{date}. With @@ -16779,7 +16856,9 @@ the same results (@samp{<Mar 28, 1991>} versus @samp{<Mar 31, 1991>} in this case). -@c @starindex +@ignore +@starindex +@end ignore @tindex incyear The @samp{incyear(@var{date}, @var{step})} function increases a date form by the specified number of years, which may be @@ -16931,7 +17010,9 @@ might come out a bit differently, since @kbd{t +} is incapable of producing a date that falls on a weekend or holiday.) -@c @starindex +@ignore +@starindex +@end ignore @tindex holiday There is a @code{holiday} function, not on any keys, that takes any date form and returns 1 if that date falls on a weekend or @@ -16970,7 +17051,9 @@ days between two dates without taking daylight savings into account. @pindex calc-time-zone -@c @starindex +@ignore +@starindex +@end ignore @tindex tzone The @code{calc-time-zone} [@code{tzone}] command converts the time zone specified by its numeric prefix argument into a number of @@ -16995,8 +17078,8 @@ another for daylight savings time, and a third for ``generalized'' time in which the daylight savings adjustment is computed from context. -@group -@smallexample +@smallexample +@group YST PST MST CST EST AST NST GMT WET MET MEZ 9 8 7 6 5 4 3.5 0 -1 -2 -2 @@ -17005,8 +17088,8 @@ YGT PGT MGT CGT EGT AGT NGT BGT WEGT MEGT MEGZ 9/8 8/7 7/6 6/5 5/4 4/3 3.5/2.5 0/-1 -1/-2 -2/-3 -2/-3 -@end smallexample -@end group +@end group +@end smallexample @vindex math-tzone-names To define time zone names that do not appear in the above table, @@ -17015,13 +17098,13 @@ structure is best explained by an example. The three entries for Pacific Time look like this: -@group -@smallexample +@smallexample +@group ( ( "PST" 8 0 ) ; Name as an upper-case string, then standard ( "PDT" 8 -1 ) ; adjustment, then daylight savings adjustment. ( "PGT" 8 "PST" "PDT" ) ) ; Generalized time zone. -@end smallexample -@end group +@end group +@end smallexample @cindex @code{TimeZone} variable @vindex TimeZone @@ -17163,7 +17246,9 @@ local time, not in the GMT time that a numeric @var{date} is typically represented in. -@c @starindex +@ignore +@starindex +@end ignore @tindex dsadj The @samp{dsadj(@var{date}, @var{zone})} function computes the daylight savings adjustment that is appropriate for @var{date} in @@ -17239,7 +17324,7 @@ represents a rate of 540 percent! The key sequence @kbd{M-% *} effectively means ``percent-of.'' -For example, @kbd{68 RET 25 M-% *} computes 17, which is 25% of +For example, @kbd{68 @key{RET} 25 M-% *} computes 17, which is 25% of 68 (and also 68% of 25, which comes out to the same thing). @kindex c % @@ -17253,7 +17338,7 @@ to convert a formula like @samp{8%} back to numeric form, 0.08. To compute what percentage one quantity is of another quantity, -use @kbd{/ c %}. For example, @w{@kbd{17 RET 68 / c %}} displays +use @kbd{/ c %}. For example, @w{@kbd{17 @key{RET} 68 / c %}} displays @samp{25%}. @kindex b % @@ -17261,13 +17346,13 @@ @tindex relch The @kbd{b %} (@code{calc-percent-change}) [@code{relch}] command calculates the percentage change from one number to another. -For example, @kbd{40 RET 50 b %} produces the answer @samp{25%}, +For example, @kbd{40 @key{RET} 50 b %} produces the answer @samp{25%}, since 50 is 25% larger than 40. A negative result represents a -decrease: @kbd{50 RET 40 b %} produces @samp{-20%}, since 40 is +decrease: @kbd{50 @key{RET} 40 b %} produces @samp{-20%}, since 40 is 20% smaller than 50. (The answers are different in magnitude because, in the first case, we're increasing by 25% of 40, but in the second case, we're decreasing by 20% of 50.) The effect -of @kbd{40 RET 50 b %} is to compute @cite{(50-40)/40}, converting +of @kbd{40 @key{RET} 50 b %} is to compute @cite{(50-40)/40}, converting the answer to percentage form as if by @kbd{c %}. @node Future Value, Present Value, Percentages, Financial Functions @@ -17297,7 +17382,7 @@ in the account after five years? @code{fvb(5.4%, 5, 1000) = 5870.73}. Thus you will have earned $870 worth of interest over the years. Using the stack, this calculation would have been -@kbd{5.4 M-% 5 RET 1000 I b F}. Note that the rate is expressed +@kbd{5.4 M-% 5 @key{RET} 1000 I b F}. Note that the rate is expressed as a number between 0 and 1, @emph{not} as a percentage. @kindex H b F @@ -17552,18 +17637,18 @@ For example, pushing the vector @cite{[1,2,3,4,5]} (perhaps with @kbd{v x 5}) and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$), -ddb(12000,2000,5,$)] RET} produces a matrix that allows us to compare +ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare the three depreciation methods: -@group -@example +@example +@group [ [ 2000, 3333, 4800 ] [ 2000, 2667, 2880 ] [ 2000, 2000, 1728 ] [ 2000, 1333, 592 ] [ 2000, 667, 0 ] ] -@end example -@end group +@end group +@end example @noindent (Values have been rounded to nearest integers in this figure.) @@ -17850,11 +17935,17 @@ @kindex H b l @kindex H b r -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex H b L -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H b R -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H b t The @kbd{H b l} command also does a left shift, but it takes two arguments from the stack (the value to shift, and, at top-of-stack, the number of @@ -17906,7 +17997,7 @@ Another interesting use of the set representation of binary integers is to reverse the bits in, say, a 32-bit integer. Type @kbd{b u} to -unpack; type @kbd{31 TAB -} to replace each bit-number in the set +unpack; type @kbd{31 @key{TAB} -} to replace each bit-number in the set with 31 minus that bit-number; type @kbd{b p} to pack the set back into a binary integer. @@ -17948,8 +18039,12 @@ actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, respectively, instead of their values; @pxref{Symbolic Mode}.@refill -@c @mindex Q -@c @mindex I Q +@ignore +@mindex Q +@end ignore +@ignore +@mindex I Q +@end ignore @kindex I Q @tindex sqr The @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] function is described elsewhere; @@ -17977,7 +18072,9 @@ @kindex L @pindex calc-ln @tindex ln -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex I E The shift-@kbd{L} (@code{calc-ln}) [@code{ln}] command computes the natural logarithm of the real or complex number on the top of the stack. With @@ -17987,7 +18084,9 @@ @kindex E @pindex calc-exp @tindex exp -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex I L The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the exponential, i.e., @cite{e} raised to the power of the number on the stack. @@ -17999,9 +18098,13 @@ @pindex calc-log10 @tindex log10 @tindex exp10 -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I L -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I E The @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common (base-10) logarithm of a number. (With the Inverse flag [@code{exp10}], @@ -18113,40 +18216,68 @@ @kindex C @pindex calc-cos @tindex cos -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I C @pindex calc-arccos -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex arccos -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H C @pindex calc-cosh -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex cosh -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I C @pindex calc-arccosh -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex arccosh -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex T @pindex calc-tan -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex tan -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex I T @pindex calc-arctan -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex arctan -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H T @pindex calc-tanh -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex tanh -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I T @pindex calc-arctanh -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex arctanh The shift-@kbd{C} (@code{calc-cos}) [@code{cos}] command computes the cosine of an angle or complex number, and shift-@kbd{T} (@code{calc-tan}) [@code{tan}] @@ -18168,10 +18299,16 @@ @samp{arctan2(0,0)=0}. @pindex calc-sincos -@c @starindex +@ignore +@starindex +@end ignore @tindex sincos -@c @starindex -@c @mindex arc@idots +@ignore +@starindex +@end ignore +@ignore +@mindex arc@idots +@end ignore @tindex arcsincos The @code{calc-sincos} [@code{sincos}] command computes the sine and cosine of a number, returning them as a vector of the form @@ -18209,18 +18346,30 @@ @kindex f G @tindex gammaP -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I f G -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H f G -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H I f G @pindex calc-inc-gamma -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex gammaQ -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex gammag -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex gammaG The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by @@ -18481,11 +18630,11 @@ every other call to this function will be especially fast. If @cite{M} is an error form @c{$m$ @code{+/-} $\sigma$} -@samp{m +/- s} where @i{m} +@samp{m +/- s} where @var{m} and @c{$\sigma$} -@i{s} are both real numbers, the result uses a Gaussian -distribution with mean @i{m} and standard deviation @c{$\sigma$} -@i{s}. +@var{s} are both real numbers, the result uses a Gaussian +distribution with mean @var{m} and standard deviation @c{$\sigma$} +@var{s}. If @cite{M} is an interval form, the lower and upper bounds specify the acceptable limits of the random numbers. If both bounds are integers, @@ -18695,7 +18844,9 @@ @kindex ! @pindex calc-factorial @tindex fact -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ! The @kbd{!} (@code{calc-factorial}) [@code{fact}] command computes the factorial of the number at the top of the stack. If the number is an @@ -18710,7 +18861,9 @@ @kindex k d @pindex calc-double-factorial @tindex dfact -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex !! The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command computes the ``double factorial'' of an integer. For an even integer, @@ -18796,7 +18949,9 @@ the number will be reported as definitely prime or non-prime if possible, or otherwise ``probably'' prime with a certain probability of error. -@c @starindex +@ignore +@starindex +@end ignore @tindex prime The normal @kbd{k p} command performs one iteration of the primality test. Pressing @kbd{k p} repeatedly for the same integer will perform @@ -18820,7 +18975,9 @@ @kindex k n @pindex calc-next-prime -@c @mindex nextpr@idots +@ignore +@mindex nextpr@idots +@end ignore @tindex nextprime The @kbd{k n} (@code{calc-next-prime}) [@code{nextprime}] command finds the next prime above a given number. Essentially, it searches by calling @@ -18836,7 +18993,9 @@ @kindex I k n @pindex calc-prev-prime -@c @mindex prevpr@idots +@ignore +@mindex prevpr@idots +@end ignore @tindex prevprime The @kbd{I k n} (@code{calc-prev-prime}) [@code{prevprime}] command analogously finds the next prime less than a given number. @@ -18907,9 +19066,13 @@ @kindex k C @pindex calc-utpc @tindex utpc -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I k C -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ltpc The @samp{utpc(x,v)} function uses the chi-square distribution with @c{$\nu$} @@ -18919,9 +19082,13 @@ @kindex k F @pindex calc-utpf @tindex utpf -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I k F -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ltpf The @samp{utpf(F,v1,v2)} function uses the F distribution, used in various statistical tests. The parameters @c{$\nu_1$} @@ -18933,9 +19100,13 @@ @kindex k N @pindex calc-utpn @tindex utpn -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I k N -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ltpn The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution with mean @cite{m} and standard deviation @c{$\sigma$} @@ -18946,9 +19117,13 @@ @kindex k P @pindex calc-utpp @tindex utpp -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I k P -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ltpp The @samp{utpp(n,x)} function uses a Poisson distribution with mean @cite{x}. It is the probability that @cite{n} or more such @@ -18957,9 +19132,13 @@ @kindex k T @pindex calc-ltpt @tindex utpt -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex I k T -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex ltpt The @samp{utpt(t,v)} function uses the Student's ``t'' distribution with @c{$\nu$} @@ -19133,7 +19312,9 @@ Also, @samp{[-4, -10]} will convert four integers into an error form consisting of two fractions: @samp{a:b +/- c:d}. -@c @starindex +@ignore +@starindex +@end ignore @tindex pack There is an equivalent algebraic function, @samp{pack(@var{mode}, @var{items})} where @var{mode} is a @@ -19192,7 +19373,9 @@ to unpack a matrix, say, or a vector of error forms. Higher unpacking modes unpack the input even more deeply. -@c @starindex +@ignore +@starindex +@end ignore @tindex unpack There are two algebraic functions analogous to @kbd{v u}. The @samp{unpack(@var{mode}, @var{item})} function unpacks the @@ -19201,7 +19384,9 @@ integer, not a vector. For example, @samp{unpack(-4, a +/- b)} returns @samp{[a, b]}, as does @samp{unpack(1, a +/- b)}. -@c @starindex +@ignore +@starindex +@end ignore @tindex unpackt The @code{unpackt} function is like @code{unpack} but instead of returning a simple vector of items, it returns a vector of @@ -19227,7 +19412,9 @@ @kindex | @pindex calc-concat -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex | The @kbd{|} (@code{calc-concat}) command ``concatenates'' two vectors into one. For example, after @kbd{@w{[ 1 , 2 ]} [ 3 , 4 ] |}, the stack @@ -19254,7 +19441,7 @@ @kindex H I | The @kbd{I |} and @kbd{H I |} commands are similar, but they use their two stack arguments in the opposite order. Thus @kbd{I |} is equivalent -to @kbd{TAB |}, but possibly more convenient and also a bit faster. +to @kbd{@key{TAB} |}, but possibly more convenient and also a bit faster. @kindex v d @pindex calc-diag @@ -19349,13 +19536,21 @@ @kindex H v h @tindex rhead -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex H I v h -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex H v k -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex rtail -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex rcons Each of these three functions also accepts the Hyperbolic flag [@code{rhead}, @code{rtail}, @code{rcons}] in which case @var{t} instead represents @@ -19581,7 +19776,9 @@ @cindex Histograms @kindex V H @pindex calc-histogram -@c @mindex histo@idots +@ignore +@mindex histo@idots +@end ignore @tindex histogram The @kbd{V H} (@code{calc-histogram}) [@code{histogram}] command builds a histogram of a vector of numbers. Vector elements are assumed to be @@ -19683,10 +19880,14 @@ The @kbd{V J} (@code{calc-conj-transpose}) [@code{ctrn}] command computes the conjugate transpose of its argument, i.e., @samp{conj(trn(x))}. -@c @mindex A +@ignore +@mindex A +@end ignore @kindex A (vectors) @pindex calc-abs (vectors) -@c @mindex abs +@ignore +@mindex abs +@end ignore @tindex abs (vectors) The @kbd{A} (@code{calc-abs}) [@code{abs}] command computes the Frobenius norm of a vector or matrix argument. This is the square @@ -19722,10 +19923,14 @@ right-handed cross product of two vectors, each of which must have exactly three elements. -@c @mindex & +@ignore +@mindex & +@end ignore @kindex & (matrices) @pindex calc-inv (matrices) -@c @mindex inv +@ignore +@mindex inv +@end ignore @tindex inv (matrices) The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the inverse of a square matrix. If the matrix is singular, the inverse @@ -20068,7 +20273,7 @@ weight is completely negligible.) This function also works for distributions (error forms or -intervals). The mean of an error form `@i{a} @t{+/-} @i{b}' is simply +intervals). The mean of an error form `@var{a} @t{+/-} @var{b}' is simply @cite{a}. The mean of an interval is the mean of the minimum and maximum values of the interval. @@ -20136,7 +20341,7 @@ @cindex Geometric mean The @kbd{u G} (@code{calc-vector-geometric-mean}) [@code{vgmean}] command computes the geometric mean of the data values. This -is the @i{N}th root of the product of the values. This is also +is the @var{n}th root of the product of the values. This is also equal to the @code{exp} of the arithmetic mean of the logarithms of the data values. @tex @@ -20223,7 +20428,9 @@ squares of the deviations of the data values from the mean. (This definition also applies when the argument is a distribution.) -@c @starindex +@ignore +@starindex +@end ignore @tindex vflat The @code{vflat} algebraic function returns a vector of its arguments, interpreted in the same way as the other functions @@ -20343,7 +20550,7 @@ can't figure it out on its own (say, because you named a function that is currently undefined). It is also possible to type a digit key before the function name to specify the number of arguments, e.g., -@kbd{V M 3 x f RET} calls @code{f} with three arguments even if it +@kbd{V M 3 x f @key{RET}} calls @code{f} with three arguments even if it looks like it ought to have only two. This technique may be necessary if the function allows a variable number of arguments. For example, the @kbd{v e} [@code{vexp}] function accepts two or three arguments; @@ -20381,9 +20588,9 @@ argument minus the second argument.'' The symbols @samp{#1} and @samp{#2} are placeholders for the arguments. You can use any names for these placeholders if you wish, by including an argument list followed by a -colon: @samp{<x, y : x - y>}. When you type @kbd{V A ' $$ + 2$^$$ RET}, +colon: @samp{<x, y : x - y>}. When you type @kbd{V A ' $$ + 2$^$$ @key{RET}}, Calc builds the nameless function @samp{<#1 + 2 #2^#1>} as the function -to map across the vectors. When you type @kbd{V A ' x + 2y^x RET RET}, +to map across the vectors. When you type @kbd{V A ' x + 2y^x @key{RET} @key{RET}}, Calc builds the nameless function @w{@samp{<x, y : x + 2 y^x>}}. In both cases, Calc also writes the nameless function to the Trail so that you can get it back later if you wish. @@ -20399,11 +20606,13 @@ argument list in this case, since the nameless function specifies the argument list as well as the function itself. In @kbd{V A '}, you can omit the @samp{< >} marks if you use @samp{#} notation for the arguments, -so that @kbd{V A ' #1+#2 RET} is the same as @kbd{V A ' <#1+#2> RET}, -which in turn is the same as @kbd{V A ' $$+$ RET}. +so that @kbd{V A ' #1+#2 @key{RET}} is the same as @kbd{V A ' <#1+#2> @key{RET}}, +which in turn is the same as @kbd{V A ' $$+$ @key{RET}}. @cindex Lambda expressions -@c @starindex +@ignore +@starindex +@end ignore @tindex lambda The internal format for @samp{<x, y : x + y>} is @samp{lambda(x, y, x + y)}. (The word @code{lambda} derives from Lisp notation and the theory of @@ -20420,17 +20629,29 @@ @tindex add @tindex sub -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @tindex mul -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex div -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex pow -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex neg -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex mod -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex vconcat As usual, commands like @kbd{V A} have algebraic function name equivalents. For example, @kbd{V A k g} with an argument of @samp{v} is equivalent to @@ -20441,7 +20662,9 @@ @code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and @code{vconcat}.@refill -@c @starindex +@ignore +@starindex +@end ignore @tindex call The @code{call} function builds a function call out of several arguments: @samp{call(gcd, x, y)} is the same as @samp{apply(gcd, [x, y])}, which @@ -20675,7 +20898,7 @@ to a fixed point. To find the square root of five starting with an initial guess, Newton's method would look for a fixed point of the function @samp{(x + 5/x) / 2}. Putting a guess of 1 on the stack -and typing @kbd{H I V R ' ($ + 5/$)/2 RET} quickly yields the result +and typing @kbd{H I V R ' ($ + 5/$)/2 @key{RET}} quickly yields the result 2.23607. This is equivalent to using the @kbd{a R} (@code{calc-find-root}) command to find a root of the equation @samp{x^2 = 5}. @@ -20788,37 +21011,37 @@ The default format is @samp{RO}. (Before Calc 2.00, the format was fixed at @samp{ROC}.) Here are some example matrices: -@group -@example +@example +@group [ [ 123, 0, 0 ] [ [ 123, 0, 0 ], [ 0, 123, 0 ] [ 0, 123, 0 ], [ 0, 0, 123 ] ] [ 0, 0, 123 ] ] RO ROC -@end example -@end group -@noindent -@group -@example +@end group +@end example +@noindent +@example +@group [ 123, 0, 0 [ 123, 0, 0 ; 0, 123, 0 0, 123, 0 ; 0, 0, 123 ] 0, 0, 123 ] O OC -@end example -@end group -@noindent -@group -@example +@end group +@end example +@noindent +@example +@group [ 123, 0, 0 ] 123, 0, 0 [ 0, 123, 0 ] 0, 123, 0 [ 0, 0, 123 ] 0, 0, 123 R @r{blank} -@end example -@end group +@end group +@end example @noindent Note that of the formats shown here, @samp{RO}, @samp{ROC}, and @@ -20950,28 +21173,28 @@ display mode but is perhaps easiest in ``big'' (@kbd{d B}) mode. Suppose you enter the following formula: -@group -@smallexample +@smallexample +@group 3 ___ (a + b) + V c 1: --------------- 2 x + 1 -@end smallexample -@end group +@end group +@end smallexample @noindent (by typing @kbd{' ((a+b)^3 + sqrt(c)) / (2x+1)}). If you move the cursor to the letter @samp{b} and press @w{@kbd{j s}}, the display changes to -@group -@smallexample +@smallexample +@group . ... .. . b. . . . 1* ............... . . . . -@end smallexample -@end group +@end group +@end smallexample @noindent Every character not part of the sub-formula @samp{b} has been changed @@ -20984,14 +21207,14 @@ If you had instead placed the cursor on the parenthesis immediately to the right of the @samp{b}, the selection would have been: -@group -@smallexample +@smallexample +@group . ... (a + b) . . . 1* ............... . . . . -@end smallexample -@end group +@end group +@end smallexample @noindent The portion selected is always large enough to be considered a complete @@ -21102,14 +21325,14 @@ @w{@kbd{j m}} (@code{calc-select-more}) command. If @samp{a + b} is selected, pressing @w{@kbd{j m}} repeatedly works as follows: -@group -@smallexample +@smallexample +@group 3 ... 3 ___ 3 ___ (a + b) . . . (a + b) + V c (a + b) + V c 1* ............... 1* ............... 1* --------------- . . . . . . . . 2 x + 1 -@end smallexample -@end group +@end group +@end smallexample @noindent In the last example, the entire formula is selected. This is roughly @@ -21193,14 +21416,14 @@ to the other style in which the selected portion itself is obscured by @samp{#} signs: -@group -@smallexample +@smallexample +@group 3 ... # ___ (a + b) . . . ## # ## + V c 1* ............... 1* --------------- . . . . 2 x + 1 -@end smallexample -@end group +@end group +@end smallexample @node Operating on Selections, Rearranging with Selections, Displaying Selections, Selecting Subformulas @subsection Operating on Selections @@ -21232,8 +21455,8 @@ the selected portion of the formula, returning the old selected portion to the top of the stack. -@group -@smallexample +@smallexample +@group 3 ... ... ___ (a + b) . . . 17 x y . . . 17 x y + V c 2* ............... 2* ............. 2: ------------- @@ -21241,8 +21464,8 @@ 3 3 1: 17 x y 1: (a + b) 1: (a + b) -@end smallexample -@end group +@end group +@end smallexample In this example we select a sub-formula of our original example, enter a new formula, @key{TAB} it into place, then deselect to see @@ -21275,14 +21498,14 @@ it uses the constant one instead. The @key{DEL} key automatically deselects and re-simplifies the entire formula afterwards. Thus: -@group -@smallexample +@smallexample +@group ### 17 x y + # # 17 x y 17 # y 17 y 1* ------------- 1: ------- 1* ------- 1: ------- 2 x + 1 2 x + 1 2 x + 1 2 x + 1 -@end smallexample -@end group +@end group +@end smallexample In this example, we first delete the @samp{sqrt(c)} term; Calc accomplishes this by replacing @samp{sqrt(c)} with zero and @@ -21294,7 +21517,7 @@ element is deleted from the vector. If you delete one side of an equation or inequality, only the opposite side remains. -@kindex j DEL +@kindex j @key{DEL} @pindex calc-del-selection The @kbd{j @key{DEL}} (@code{calc-del-selection}) command is like @key{DEL} but with the auto-selecting behavior of @kbd{j '} and @@ -21302,7 +21525,7 @@ indicated by the cursor, or, in the absence of a selection, it deletes the sub-formula indicated by the cursor position. -@kindex j RET +@kindex j @key{RET} @pindex calc-grab-selection (There is also an auto-selecting @kbd{j @key{RET}} (@code{calc-copy-selection}) command.) @@ -21312,14 +21535,14 @@ denominator, press @kbd{n} to negate the denominator, then press @kbd{Q} to take the square root. -@group -@smallexample +@smallexample +@group .. . .. . .. . .. . 1* ....... 1* ....... 1* ....... 1* .......... 2 x + 1 2 x - 4 4 - 2 x _________ V 4 - 2 x -@end smallexample -@end group +@end group +@end smallexample Certain types of operations on selections are not allowed. For example, for an arithmetic function like @kbd{-} no more than one of @@ -21334,14 +21557,14 @@ of our sample formula by selecting it and pressing @kbd{n} (@code{calc-change-sign}).@refill -@group -@smallexample +@smallexample +@group .. . .. . 1* .......... 1* ........... ......... .......... . . . 2 x . . . -2 x -@end smallexample -@end group +@end group +@end smallexample Unselecting the sub-formula reveals that the minus sign, which would normally have cancelled out with the subtraction automatically, has @@ -21350,14 +21573,14 @@ any other mathematical operation on the whole formula will cause it to be simplified. -@group -@smallexample +@smallexample +@group 17 y 17 y 1: ----------- 1: ---------- __________ _________ V 4 - -2 x V 4 + 2 x -@end smallexample -@end group +@end group +@end smallexample @node Rearranging with Selections, , Operating on Selections, Selecting Subformulas @subsection Rearranging Formulas using Selections @@ -21370,7 +21593,7 @@ selection is one term of a sum or product; the sum or product is rearranged according to the commutative laws of algebra. -As with @kbd{j '} and @kbd{j DEL}, the term under the cursor is used +As with @kbd{j '} and @kbd{j @key{DEL}}, the term under the cursor is used if there is no selection in the current formula. All commands described in this section share this property. In this example, we place the cursor on the @samp{a} and type @kbd{j R}, then repeat. @@ -22106,8 +22329,8 @@ value in the Calc variable @samp{e}; but this would be a bad idea in any case if you were also using natural logarithms! -Among the logical functions, @t{!}@i{(a} @t{<=} @i{b)} changes to -@cite{a > b} and so on. Equations and inequalities where both sides +Among the logical functions, @t{(@var{a} <= @var{b})} changes to +@t{@var{a} > @var{b}} and so on. Equations and inequalities where both sides are either negative-looking or zero are simplified by negating both sides and reversing the inequality. While it might seem reasonable to simplify @cite{!!x} to @cite{x}, this would not be valid in general because @@ -22346,7 +22569,9 @@ @cindex Extended simplification @kindex a e @pindex calc-simplify-extended -@c @mindex esimpl@idots +@ignore +@mindex esimpl@idots +@end ignore @tindex esimplify The @kbd{a e} (@code{calc-simplify-extended}) [@code{esimplify}] command is like @kbd{a s} @@ -22543,10 +22768,16 @@ version of Calc.) @vindex FactorRules -@c @starindex +@ignore +@starindex +@end ignore @tindex thecoefs -@c @starindex -@c @mindex @idots +@ignore +@starindex +@end ignore +@ignore +@mindex @idots +@end ignore @tindex thefactors The rewrite-based factorization method uses rules stored in the variable @code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the @@ -22664,7 +22895,7 @@ of the screen and is also placed in the Trail along with the quotient. Using @code{pdiv} in algebraic notation, you can specify the particular -variable to be used as the base: `@t{pdiv(}@i{a}@t{,}@i{b}@t{,}@i{x}@t{)}'. +variable to be used as the base: @code{pdiv(@var{a},@var{b},@var{x})}. If @code{pdiv} is given only two arguments (as is always the case with the @kbd{a \} command), then it does a multivariate division as outlined above. @@ -22893,7 +23124,9 @@ in your @code{IntegRules}. @cindex Exponential integral Ei(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex Ei As a more serious example, the expression @samp{exp(x)/x} cannot be integrated in terms of the standard functions, so the ``exponential @@ -23129,9 +23362,13 @@ @cindex @code{GenCount} variable @vindex GenCount -@c @starindex +@ignore +@starindex +@end ignore @tindex an -@c @starindex +@ignore +@starindex +@end ignore @tindex as If you store a positive integer in the Calc variable @code{GenCount}, then Calc will generate formulas of the form @samp{as(@var{n})} for @@ -23231,7 +23468,9 @@ solve any system of linear equations, and also many kinds of nonlinear systems. -@c @starindex +@ignore +@starindex +@end ignore @tindex elim Normally there will be as many variables as equations. If you give fewer variables than equations (an ``over-determined'' system @@ -23269,7 +23508,9 @@ @subsection Decomposing Polynomials @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex poly The @code{poly} function takes a polynomial and a variable as arguments, and returns a vector of polynomial coefficients (constant @@ -23292,7 +23533,9 @@ returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)} gives the @cite{x^2} coefficient of this polynomial, 6. -@c @starindex +@ignore +@starindex +@end ignore @tindex gpoly One important feature of the solver is its ability to recognize formulas which are ``essentially'' polynomials. This ability is @@ -23343,7 +23586,9 @@ @samp{gpoly(@var{expr}, @var{var}, 4)} to discover whether @var{expr} can be treated by its linear, quadratic, cubic, or quartic formulas. -@c @starindex +@ignore +@starindex +@end ignore @tindex pdeg The @code{pdeg} function computes the degree of a polynomial; @samp{pdeg(p,x)} is the highest power of @code{x} that appears in @@ -23358,7 +23603,9 @@ the degree of the constant zero is considered to be @code{-inf} (minus infinity). -@c @starindex +@ignore +@starindex +@end ignore @tindex plead The @code{plead} function finds the leading term of a polynomial. Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))}, @@ -23366,7 +23613,9 @@ returns 1024 without expanding out the list of coefficients. The value of @code{plead(p,x)} will be zero only if @cite{p = 0}. -@c @starindex +@ignore +@starindex +@end ignore @tindex pcont The @code{pcont} function finds the @dfn{content} of a polynomial. This is the greatest common divisor of all the coefficients of the polynomial. @@ -23389,7 +23638,9 @@ numerators. The numerical content of a polynomial is negative only if all the coefficients in the polynomial are negative. -@c @starindex +@ignore +@starindex +@end ignore @tindex pprim The @code{pprim} function finds the @dfn{primitive part} of a polynomial, which is simply the polynomial divided (using @code{pdiv} @@ -23539,9 +23790,13 @@ you should set the precision to twice as many digits as you need in your answer. -@c @mindex wmin@idots +@ignore +@mindex wmin@idots +@end ignore @tindex wminimize -@c @mindex wmax@idots +@ignore +@mindex wmax@idots +@end ignore @tindex wmaximize The @kbd{H a N} [@code{wminimize}] command, analogously to @kbd{H a R}, expands the guess interval to enclose a minimum rather than requiring @@ -23661,12 +23916,12 @@ For example, suppose the data matrix @ifinfo -@group -@example +@example +@group [ [ 1, 2, 3, 4, 5 ] [ 5, 7, 9, 11, 13 ] ] -@end example -@end group +@end group +@end example @end ifinfo @tex \turnoffactive @@ -23680,7 +23935,7 @@ @noindent is on the stack and we wish to do a simple linear fit. Type -@kbd{a F}, then @kbd{1} for the model, then @kbd{RET} to use +@kbd{a F}, then @kbd{1} for the model, then @key{RET} to use the default names. The result will be the formula @cite{3 + 2 x} on the stack. Calc has created the model expression @kbd{a + b x}, then found the optimal values of @cite{a} and @cite{b} to fit the @@ -23696,8 +23951,8 @@ to move this vector to the stack; see @ref{Trail Commands}. Specifying a different independent variable name will affect the -resulting formula: @kbd{a F 1 k RET} produces @kbd{3 + 2 k}. -Changing the parameter names (say, @kbd{a F 1 k;b,m RET}) will affect +resulting formula: @kbd{a F 1 k @key{RET}} produces @kbd{3 + 2 k}. +Changing the parameter names (say, @kbd{a F 1 k;b,m @key{RET}}) will affect the equations that go into the trail. @tex @@ -23712,14 +23967,14 @@ 2.6 + 2.2 x @end example -Evaluating this formula, say with @kbd{v x 5 RET TAB V M $ RET}, shows +Evaluating this formula, say with @kbd{v x 5 @key{RET} @key{TAB} V M $ @key{RET}}, shows a reasonably close match to the y-values in the data. @example [4.8, 7., 9.2, 11.4, 13.6] @end example -Since there is no line which passes through all the @i{N} data points, +Since there is no line which passes through all the @var{n} data points, Calc has chosen a line that best approximates the data points using the method of least squares. The idea is to define the @dfn{chi-square} error measure @@ -23754,13 +24009,13 @@ @end tex A numeric prefix argument causes the @kbd{a F} command to take the -data in some other form than one big matrix. A positive argument @i{N} -will take @i{N} items from the stack, corresponding to the @i{N} rows -of a data matrix. In the linear case, @i{N} must be 2 since there +data in some other form than one big matrix. A positive argument @var{n} +will take @var{N} items from the stack, corresponding to the @var{n} rows +of a data matrix. In the linear case, @var{n} must be 2 since there is always one independent variable and one dependent variable. A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two -items from the stack, an @i{N}-row matrix of @cite{x} values, and a +items from the stack, an @var{n}-row matrix of @cite{x} values, and a vector of @cite{y} values. If there is only one independent variable, the @cite{x} values can be either a one-row matrix or a plain vector, in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix. @@ -23773,7 +24028,7 @@ digits @kbd{2} through @kbd{9} when prompted for a model. For example, we could fit the original data matrix from the previous section (with 13, not 14) to a parabola instead of a line by typing -@kbd{a F 2 RET}. +@kbd{a F 2 @key{RET}}. @example 2.00000000001 x - 1.5e-12 x^2 + 2.99999999999 @@ -23797,8 +24052,8 @@ @end example An important result from the theory of polynomial fitting is that it -is always possible to fit @i{N} data points exactly using a polynomial -of degree @i{N-1}, sometimes called an @dfn{interpolating polynomial}. +is always possible to fit @var{n} data points exactly using a polynomial +of degree @i{@var{n}-1}, sometimes called an @dfn{interpolating polynomial}. Using the modified (14) data matrix, a model number of 4 gives a polynomial that exactly matches all five data points: @@ -23837,16 +24092,16 @@ Given the data matrix, -@group -@example +@example +@group [ [ 1, 2, 3, 4, 5 ] [ 7, 2, 3, 5, 2 ] [ 14.5, 15, 18.5, 22.5, 24 ] ] -@end example -@end group - -@noindent -the command @kbd{a F 1 RET} will call the first row @cite{x} and the +@end group +@end example + +@noindent +the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the second row @cite{y}, and will fit the values in the third row to the model @cite{a + b x + c y}. @@ -23903,8 +24158,8 @@ or all be plain numbers. Error forms can go anywhere but generally go on the numbers in the last row of the data matrix. If the last row contains error forms -`@i{y_i}@w{ @t{+/-} }@c{$\sigma_i$} -@i{sigma_i}', then the @c{$\chi^2$} +`@var{y_i}@w{ @t{+/-} }@c{$\sigma_i$} +@var{sigma_i}', then the @c{$\chi^2$} @cite{chi^2} statistic is now, @@ -23973,7 +24228,7 @@ @item The covariance matrix @cite{C} computed from the fit. This is -an @i{M}x@i{M} symmetric matrix; the diagonal elements +an @var{m}x@var{m} symmetric matrix; the diagonal elements @c{$C_{jj}$} @cite{C_j_j} are the variances @c{$\sigma_j^2$} @cite{sigma_j^2} of the parameters. @@ -24268,7 +24523,7 @@ graphing them, by examining the goodness-of-fit measures returned by @kbd{I a F}, or by some other method suitable to your application. Note that some models can be linearized in several ways. The -Gaussian-plus-@i{d} model can be linearized by setting @cite{d} +Gaussian-plus-@var{d} model can be linearized by setting @cite{d} (the background) to a constant, or by setting @cite{b} (the standard deviation) and @cite{c} (the mean) to constants. @@ -24384,19 +24639,37 @@ @xref{Rewrite Rules}, for a discussion of rewrite rules. -@c @starindex +@ignore +@starindex +@end ignore @tindex fitvar -@c @starindex -@c @mindex @idots +@ignore +@starindex +@end ignore +@ignore +@mindex @idots +@end ignore @tindex fitparam -@c @starindex -@c @mindex @null +@ignore +@starindex +@end ignore +@ignore +@mindex @null +@end ignore @tindex fitmodel -@c @starindex -@c @mindex @null +@ignore +@starindex +@end ignore +@ignore +@mindex @null +@end ignore @tindex fitsystem -@c @starindex -@c @mindex @null +@ignore +@starindex +@end ignore +@ignore +@mindex @null +@end ignore @tindex fitdummy Calc uses @code{FitRules} as follows. First, it converts the model to an equation if necessary and encloses the model equation in a @@ -24408,11 +24681,11 @@ is the highest-numbered @code{fitvar}. For example, the power law model @cite{a x^b} is converted to @cite{y = a x^b}, then to -@group -@smallexample +@smallexample +@group fitmodel(fitvar(2) = fitparam(1) fitvar(1)^fitparam(2)) -@end smallexample -@end group +@end group +@end smallexample Calc then applies the rewrites as if by @samp{C-u 0 a r FitRules}. (The zero prefix means that rewriting should continue until no further @@ -24436,13 +24709,13 @@ The power law model eventually boils down to -@group -@smallexample +@smallexample +@group fitsystem(ln(fitvar(2)), [1, ln(fitvar(1))], [exp(fitdummy(1)), fitdummy(2)]) -@end smallexample -@end group +@end group +@end smallexample The actual implementation of @code{FitRules} is complicated; it proceeds in four phases. First, common rearrangements are done @@ -24492,11 +24765,19 @@ to obtain the three-argument @code{fitsystem} that the linear least-squares solver wants to see. -@c @starindex -@c @mindex hasfit@idots +@ignore +@starindex +@end ignore +@ignore +@mindex hasfit@idots +@end ignore @tindex hasfitparams -@c @starindex -@c @mindex @null +@ignore +@starindex +@end ignore +@ignore +@mindex @null +@end ignore @tindex hasfitvars Two functions which are useful in connection with @code{FitRules} are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check @@ -24613,7 +24894,7 @@ sum (any formula), and the upper limit of the sum. If you enter a blank line at any of these prompts, that prompt and any later ones are answered by reading additional elements from -the stack. Thus, @kbd{' k^2 RET ' k RET 1 RET 5 RET a + RET} +the stack. Thus, @kbd{' k^2 @key{RET} ' k @key{RET} 1 @key{RET} 5 @key{RET} a + @key{RET}} produces the result 55. @tex \turnoffactive @@ -24627,11 +24908,11 @@ as a value. If you pressed @kbd{=} on a sum over @code{i}, it would be changed to a nonsensical sum over the ``variable'' @cite{(0, 1)}! If you really want to use @code{i} as an index variable, use -@w{@kbd{s u i RET}} first to ``unstore'' this variable. +@w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable. (@xref{Storing Variables}.) A numeric prefix argument steps the index by that amount rather -than by one. Thus @kbd{' a_k RET C-u -2 a + k RET 10 RET 0 RET} +than by one. Thus @kbd{' a_k @key{RET} C-u -2 a + k @key{RET} 10 @key{RET} 0 @key{RET}} yields @samp{a_10 + a_8 + a_6 + a_4 + a_2 + a_0}. A prefix argument of plain @kbd{C-u} causes @kbd{a +} to prompt for the step value, in which case you can enter any formula or enter @@ -24823,29 +25104,49 @@ @kindex a < @tindex lt -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex a > -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex a [ -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex a ] @pindex calc-less-than @pindex calc-greater-than @pindex calc-less-equal @pindex calc-greater-equal -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex gt -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex leq -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex geq -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex < -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex > -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex <= -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex >= The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}] operation is true if @cite{a} is less than @cite{b}. Similar functions @@ -24908,9 +25209,13 @@ @kindex a : @pindex calc-logical-if @tindex if -@c @mindex ? : +@ignore +@mindex ? : +@end ignore @tindex ? -@c @mindex @null +@ignore +@mindex @null +@end ignore @tindex : @cindex Arguments, not evaluated The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}] @@ -24948,7 +25253,9 @@ @xref{Set Operations}, for a group of commands that manipulate sets of this sort. -@c @starindex +@ignore +@starindex +@end ignore @tindex typeof The @samp{typeof(a)} function produces an integer or variable which characterizes @cite{a}. If @cite{a} is a number, vector, or variable, @@ -24975,11 +25282,17 @@ Otherwise, @cite{a} is a formula, and the result is a variable which represents the name of the top-level function call. -@c @starindex +@ignore +@starindex +@end ignore @tindex integer -@c @starindex +@ignore +@starindex +@end ignore @tindex real -@c @starindex +@ignore +@starindex +@end ignore @tindex constant The @samp{integer(a)} function returns true if @cite{a} is an integer. The @samp{real(a)} function @@ -24997,7 +25310,9 @@ @samp{integer(floor(x))} does not because @samp{floor(x)} is not literally an integer constant. -@c @starindex +@ignore +@starindex +@end ignore @tindex refers The @samp{refers(a,b)} function is true if the variable (or sub-expression) @cite{b} appears in @cite{a}, or false otherwise. Unlike the other @@ -25006,7 +25321,9 @@ @code{refers} will be left unevaluated is if @cite{a} is a plain variable (different from @cite{b}). -@c @starindex +@ignore +@starindex +@end ignore @tindex negative The @samp{negative(a)} function returns true if @cite{a} ``looks'' negative, because it is a negative number, because it is of the form @cite{-x}, @@ -25017,14 +25334,18 @@ first with @kbd{m O} (or if it appears in an unevaluated context such as a rewrite rule condition). -@c @starindex +@ignore +@starindex +@end ignore @tindex variable The @samp{variable(a)} function is true if @cite{a} is a variable, or false if not. If @cite{a} is a function call, this test is left in symbolic form. Built-in variables like @code{pi} and @code{inf} are considered variables like any others by this test. -@c @starindex +@ignore +@starindex +@end ignore @tindex nonvar The @samp{nonvar(a)} function is true if @cite{a} is a non-variable. If its argument is a variable it is left unsimplified; it never @@ -25032,13 +25353,21 @@ commands consider ``false'' anything not provably true, this is often good enough. -@c @starindex +@ignore +@starindex +@end ignore @tindex lin -@c @starindex +@ignore +@starindex +@end ignore @tindex linnt -@c @starindex +@ignore +@starindex +@end ignore @tindex islin -@c @starindex +@ignore +@starindex +@end ignore @tindex islinnt @cindex Linearity testing The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt} @@ -25076,7 +25405,9 @@ @code{linnt} accept plain constants as linear in the one-argument case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false. -@c @starindex +@ignore +@starindex +@end ignore @tindex istrue The @samp{istrue(a)} function returns 1 if @cite{a} is a nonzero number or provably nonzero formula, or 0 if @cite{a} is anything else. @@ -25155,13 +25486,13 @@ @enumerate @item -With a rule: @kbd{f(x) := g(x) RET}. -@item -With a vector of rules: @kbd{[f1(x) := g1(x), f2(x) := g2(x)] RET}. +With a rule: @kbd{f(x) := g(x) @key{RET}}. +@item +With a vector of rules: @kbd{[f1(x) := g1(x), f2(x) := g2(x)] @key{RET}}. (You can omit the enclosing square brackets if you wish.) @item With the name of a variable that contains the rule or rules vector: -@kbd{myrules RET}. +@kbd{myrules @key{RET}}. @item With any formula except a rule, a vector, or a variable name; this will be interpreted as the @var{old} half of a rewrite rule, @@ -25363,7 +25694,7 @@ will take whichever suitable pair it discovers first. In general, a pattern using an associative operator like @samp{a + b} -will try @i{2 n} different ways to match a sum of @i{n} terms +will try @var{2 n} different ways to match a sum of @var{n} terms like @samp{x + y + z - w}. First, @samp{a} is matched against each of @samp{x}, @samp{y}, @samp{z}, and @samp{-w} in turn, with @samp{b} being matched to the remainders @samp{y + z - w}, @samp{x + z - w}, etc. @@ -25670,7 +26001,9 @@ markers that work inside a pattern; then come the markers that work in the righthand side of a rule. -@c @starindex +@ignore +@starindex +@end ignore @tindex import One kind of marker, @samp{import(x)}, takes the place of a whole rule. Here @cite{x} is the name of a variable containing another @@ -25697,7 +26030,9 @@ @table @samp @item quote(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex quote This pattern matches exactly @cite{x}; variable names in @cite{x} are not interpreted as meta-variables. The only flexibility is that @@ -25709,7 +26044,9 @@ as a result in this case.) @item plain(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex plain Here @cite{x} must be a function call @samp{f(x1,x2,@dots{})}. This pattern matches a call to function @cite{f} with the specified @@ -25721,7 +26058,9 @@ @samp{plain(plain(@w{-a}) + plain(b c))}. @item opt(x,def) -@c @starindex +@ignore +@starindex +@end ignore @tindex opt Here @cite{x} must be a variable name. This must appear as an argument to a function or an element of a vector; it specifies that @@ -25744,14 +26083,18 @@ In other words, the default @var{def} is effectively quoted. @item condition(x,c) -@c @starindex +@ignore +@starindex +@end ignore @tindex condition @tindex :: This matches the pattern @cite{x}, with the attached condition @cite{c}. It is the same as @samp{x :: c}. @item pand(x,y) -@c @starindex +@ignore +@starindex +@end ignore @tindex pand @tindex &&& This matches anything that matches both pattern @cite{x} and @@ -25759,21 +26102,27 @@ @pxref{Composing Patterns in Rewrite Rules}. @item por(x,y) -@c @starindex +@ignore +@starindex +@end ignore @tindex por @tindex ||| This matches anything that matches either pattern @cite{x} or pattern @cite{y}. It is the same as @w{@samp{x ||| y}}. @item pnot(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex pnot @tindex !!! This matches anything that does not match pattern @cite{x}. It is the same as @samp{!!! x}. @item cons(h,t) -@c @mindex cons +@ignore +@mindex cons +@end ignore @tindex cons (rewrites) This matches any vector of one or more elements. The first element is matched to @cite{h}; a vector of the remaining @@ -25783,14 +26132,18 @@ to the rule @samp{[a,b] := [a+b]}. @item rcons(t,h) -@c @mindex rcons +@ignore +@mindex rcons +@end ignore @tindex rcons (rewrites) This is like @code{cons}, except that the @emph{last} element is matched to @cite{h}, with the remaining elements matched to @cite{t}. @item apply(f,args) -@c @mindex apply +@ignore +@mindex apply +@end ignore @tindex apply (rewrites) This matches any function call. The name of the function, in the form of a variable, is matched to @cite{f}. The arguments @@ -25836,7 +26189,9 @@ @xref{Conditional Rewrite Rules}. @item select(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex select This is used for applying rules to formulas with selections; @pxref{Selections with Rewrite Rules}. @@ -25884,7 +26239,9 @@ is also a regular Calc function. @item eval(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex eval The formula @cite{x} is handled in the usual way, then the default simplifications are applied to it even if they have @@ -25895,13 +26252,17 @@ whereas @samp{eval(cons(2+3, []))} will be converted to @samp{[5]}. @item evalsimp(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex evalsimp The formula @cite{x} has meta-variables substituted in the usual way, then algebraically simplified as if by the @kbd{a s} command. @item evalextsimp(x) -@c @starindex +@ignore +@starindex +@end ignore @tindex evalextsimp The formula @cite{x} has meta-variables substituted in the normal way, then ``extendedly'' simplified as if by the @kbd{a e} command. @@ -25914,7 +26275,9 @@ @table @samp @item let(v := x) -@c @starindex +@ignore +@starindex +@end ignore @tindex let The expression @cite{x} is evaluated with meta-variables substituted. The @kbd{a s} command's simplifications are @emph{not} applied by @@ -25961,7 +26324,9 @@ righthand side instead, but using @samp{sin(y)/b} avoids gratuitous rearrangement of the argument of the sine.)@refill -@c @starindex +@ignore +@starindex +@end ignore @tindex ierf Similarly, here is a rule that implements an inverse-@code{erf} function. It uses @code{root} to search for a solution. If @@ -26014,7 +26379,9 @@ @code{eatfoo} is later changed to 0. @item remember(c) -@c @starindex +@ignore +@starindex +@end ignore @tindex remember Remember the match as described above, but only if condition @cite{c} is true. For example, @samp{remember(n % 4 = 0)} in the above factorial @@ -26051,7 +26418,9 @@ f(a +/- b, a +/- b) := g(a +/- b) @end example -@c @starindex +@ignore +@starindex +@end ignore @tindex ends Here's another interesting example: @@ -26080,7 +26449,9 @@ matches either @var{p1} or @var{p2}. Calc first tries matching against @var{p1}; if that fails, it goes on to try @var{p2}. -@c @starindex +@ignore +@starindex +@end ignore @tindex curve A simple example of @samp{|||} is @@ -26230,8 +26601,12 @@ useful when you are first testing your rule (or just if repeated rewriting is not what is called for by your application). -@c @starindex -@c @mindex iter@idots +@ignore +@starindex +@end ignore +@ignore +@mindex iter@idots +@end ignore @tindex iterations You can also put a ``function call'' @samp{iterations(@var{n})} in place of a rule anywhere in your rules vector (but usually at @@ -26276,7 +26651,9 @@ will be disabled. A @dfn{phase schedule} controls the order in which phases occur during the rewriting process. -@c @starindex +@ignore +@starindex +@end ignore @tindex phase @vindex all If a call to the marker function @code{phase} appears in the rules @@ -26290,8 +26667,8 @@ numbers that appear in the rule set and executes the phases in ascending order. For example, the rule set -@group -@example +@example +@group [ f0(x) := g0(x), phase(1), f1(x) := g1(x), @@ -26301,8 +26678,8 @@ f3(x) := g3(x), phase(1,2), f4(x) := g4(x) ] -@end example -@end group +@end group +@end example @noindent has three phases, 1 through 3. Phase 1 consists of the @code{f0}, @@ -26327,7 +26704,9 @@ The phase 2 rules do not begin until no phase 1 rules apply anywhere in the formula. -@c @starindex +@ignore +@starindex +@end ignore @tindex schedule A @code{schedule} marker appearing in the rule set (anywhere, but conventionally at the top) changes the default schedule of phases. @@ -26490,14 +26869,18 @@ With the Inverse flag [@code{matchnot}], this command extracts all vector elements which do @emph{not} match the given pattern. -@c @starindex +@ignore +@starindex +@end ignore @tindex matches There is also a function @samp{matches(@var{x}, @var{p})} which evaluates to 1 if expression @var{x} matches pattern @var{p}, or to 0 otherwise. This is sometimes useful for including into the conditional clauses of other rewrite rules. -@c @starindex +@ignore +@starindex +@end ignore @tindex vmatches The function @code{vmatches} is just like @code{matches}, except that if the match succeeds it returns a vector of assignments to @@ -26522,12 +26905,12 @@ similarly for @samp{cos(a + b)}. The corresponding rewrite rule set would be, -@group -@smallexample +@smallexample +@group [ sin(a + b) := cos(a) sin(b) + sin(a) cos(b), cos(a + b) := cos(a) cos(b) - sin(a) sin(b) ] -@end smallexample -@end group +@end group +@end smallexample To apply these manually, you could put them in a variable called @code{trigexp} and then use @kbd{a r trigexp} every time you wanted @@ -26641,11 +27024,16 @@ function, or is not fixed. The rule @samp{f(n) := n f(n-1) :: n>0} will only activate the rewrite mechanism for calls to the function @code{f}, but @samp{lg(n) + lg(m) := lg(n m)} will check every @samp{+} operator. -And @samp{apply(f, [a*b]) := apply(f, [a]) + apply(f, [b]) :: -in(f, [ln, log10])} may seem more ``efficient'' than two separate -rules for @code{ln} and @code{log10}, but actually it is vastly less -efficient because rules with @code{apply} as the top-level pattern -must be tested against @emph{every} function call that is simplified. + +@smallexample +apply(f, [a*b]) := apply(f, [a]) + apply(f, [b]) :: in(f, [ln, log10]) +@end smallexample + +@noindent +may seem more ``efficient'' than two separate rules for @code{ln} and +@code{log10}, but actually it is vastly less efficient because rules +with @code{apply} as the top-level pattern must be tested against +@emph{every} function call that is simplified. @cindex @code{AlgSimpRules} variable @vindex AlgSimpRules @@ -26729,7 +27117,7 @@ stop with 15 on the stack. Once these rules are debugged, it would probably be most useful to add them to @code{EvalRules} so that Calc will evaluate the new @code{tri} function automatically. We could then use @kbd{Z K} on -the keyboard macro @kbd{' tri($) RET} to make a command that applies +the keyboard macro @kbd{' tri($) @key{RET}} to make a command that applies @code{tri} to the value on the top of the stack. @xref{Programming}. @cindex Quaternions @@ -26830,7 +27218,9 @@ @kindex u s @pindex calc-simplify-units -@c @mindex usimpl@idots +@ignore +@mindex usimpl@idots +@end ignore @tindex usimplify The @kbd{u s} (@code{calc-simplify-units}) [@code{usimplify}] command simplifies a units @@ -26911,7 +27301,7 @@ prompt first for the old units which this value should be considered to have, then for the new units. Assuming the old and new units you give are consistent with each other, the result also will not contain -any units. For example, @kbd{@w{u c} cm RET in RET} converts the number +any units. For example, @kbd{@w{u c} cm @key{RET} in @key{RET}} converts the number 2 on the stack to 5.08. @kindex u b @@ -27256,21 +27646,37 @@ @kindex s + @kindex s - -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex s * -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s / -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s ^ -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s | -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s n -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s & -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s [ -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s ] @pindex calc-store-plus @pindex calc-store-minus @@ -27300,8 +27706,8 @@ arithmetic stores use formulas designed to behave usefully both forwards and backwards: -@group -@example +@example +@group s + v := v + a v := a + v s - v := v - a v := a - v s * v := v * a v := a * v @@ -27312,8 +27718,8 @@ s & v := v ^ (-1) v := (-1) ^ v s [ v := v - 1 v := 1 - v s ] v := v - (-1) v := (-1) - v -@end example -@end group +@end group +@end example In the last four cases, a numeric prefix argument will be used in place of the number one. (For example, @kbd{M-2 s ]} increases @@ -27456,27 +27862,49 @@ @kindex s A @kindex s D -@c @mindex @idots +@ignore +@mindex @idots +@end ignore @kindex s E -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s F -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s G -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s H -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s I -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s L -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s P -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s R -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s T -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s U -@c @mindex @null +@ignore +@mindex @null +@end ignore @kindex s X @pindex calc-store-AlgSimpRules @pindex calc-store-Decls @@ -27589,8 +28017,8 @@ analogous to the case of @kbd{s t @key{RET}}. @xref{Storing Variables}. Also, you can answer the variable-name prompt with an equation or -assignment: @kbd{s l b=3 RET} is the same as storing 3 on the stack -and typing @kbd{s l b RET}. +assignment: @kbd{s l b=3 @key{RET}} is the same as storing 3 on the stack +and typing @kbd{s l b @key{RET}}. The @kbd{a b} (@code{calc-substitute}) command is another way to substitute a variable with a value in a formula. It does an actual substitution @@ -27693,19 +28121,19 @@ that the next command that causes Calc to look at those stack entries will make them revert to the old variable value. -@group -@smallexample +@smallexample +@group 2: a => a 2: a => 17 2: a => a 1: a + 1 => a + 1 1: a + 1 => 18 1: a + 1 => a + 1 . . . - 17 s l a RET p 8 RET -@end smallexample -@end group + 17 s l a @key{RET} p 8 @key{RET} +@end group +@end smallexample Here the @kbd{p 8} command changes the current precision, thus causing the @samp{=>} forms to be recomputed after the -influence of the ``let'' is gone. The @kbd{d SPC} command +influence of the ``let'' is gone. The @kbd{d @key{SPC}} command (@code{calc-refresh}) is a handy way to force the @samp{=>} operators on the stack to be recomputed without any other side effects. @@ -27792,7 +28220,9 @@ @kbd{g N} command below. (The ``x'' values must be either a vector or an interval if ``y'' is a formula.) -@c @starindex +@ignore +@starindex +@end ignore @tindex xy If ``y'' is (or evaluates to) a formula of the form @samp{xy(@var{x}, @var{y})} then the result is a @@ -27879,7 +28309,9 @@ values from ``y'' to form a matrix of results that are graphed as a 3D surface. -@c @starindex +@ignore +@starindex +@end ignore @tindex xyz If the ``z'' formula evaluates to a call to the fictitious function @samp{xyz(@var{x}, @var{y}, @var{z})}, then the result is a @@ -28218,7 +28650,7 @@ last few curves will continue to have the default styles. Of course, you can later use @kbd{g s} and @kbd{g S} to change any of these styles. -For example, @kbd{'[2 -1 3] RET s t LineStyles} causes the first curve +For example, @kbd{'[2 -1 3] @key{RET} s t LineStyles} causes the first curve to have lines in style number 2, the second curve to have no connecting lines, and the third curve to have lines in style 3. Point styles will still be assigned automatically, but you could store another vector in @@ -28279,7 +28711,7 @@ there is no output file and this information is not used. Many other ``devices'' are really file formats like @code{postscript}; in these cases the output in the desired format goes into the file you name -with @kbd{g O}. Type @kbd{g O stdout RET} to set GNUPLOT to write +with @kbd{g O}. Type @kbd{g O stdout @key{RET}} to set GNUPLOT to write to its standard output stream, i.e., to @samp{*Gnuplot Trail*}. This is the default setting. @@ -28380,7 +28812,7 @@ yourself, then use @w{@kbd{g p}} to replot using these new commands. Note that your commands must appear @emph{before} the @code{plot} command. To get help on any GNUPLOT feature, type, e.g., @kbd{g C help set label}. -You may have to type @kbd{g C RET} a few times to clear the +You may have to type @kbd{g C @key{RET}} a few times to clear the ``press return for more'' or ``subtopic of @dots{}'' requests. Note that Calc always sends commands (like @samp{set nolabel}) to reset all plotting parameters to the defaults before each plot, so @@ -28735,8 +29167,8 @@ @node Keypad Main Menu, Keypad Functions Menu, Keypad Mode, Keypad Mode @section Main Menu -@group -@smallexample +@smallexample +@group |----+-----Calc 2.00-----+----1 |FLR |CEIL|RND |TRNC|CLN2|FLT | |----+----+----+----+----+----| @@ -28754,8 +29186,8 @@ |-----+-----+-----+-----+-----| | OFF | 0 | . | PI | + | |-----+-----+-----+-----+-----+ -@end smallexample -@end group +@end group +@end smallexample @noindent This is the menu that appears the first time you start Keypad Mode. @@ -28784,7 +29216,7 @@ The @key{UNDO} key undoes the most recent Calc operation. @kbd{INV UNDO} is the ``redo'' command, and @kbd{HYP UNDO} is -``last arguments'' (@kbd{M-RET}). +``last arguments'' (@kbd{M-@key{RET}}). The @key{<-} key acts as a ``backspace'' during numeric entry. At other times it removes the top stack entry. @kbd{INV <-} @@ -28866,8 +29298,8 @@ @node Keypad Functions Menu, Keypad Binary Menu, Keypad Main Menu, Keypad Mode @section Functions Menu -@group -@smallexample +@smallexample +@group |----+----+----+----+----+----2 |IGAM|BETA|IBET|ERF |BESJ|BESY| |----+----+----+----+----+----| @@ -28875,8 +29307,8 @@ |----+----+----+----+----+----| |GCD |FACT|DFCT|BNOM|PERM|NXTP| |----+----+----+----+----+----| -@end smallexample -@end group +@end group +@end smallexample @noindent This menu provides various operations from the @kbd{f} and @kbd{k} @@ -28908,8 +29340,8 @@ @node Keypad Binary Menu, Keypad Vectors Menu, Keypad Functions Menu, Keypad Mode @section Binary Menu -@group -@smallexample +@smallexample +@group |----+----+----+----+----+----3 |AND | OR |XOR |NOT |LSH |RSH | |----+----+----+----+----+----| @@ -28917,8 +29349,8 @@ |----+----+----+----+----+----| | A | B | C | D | E | F | |----+----+----+----+----+----| -@end smallexample -@end group +@end group +@end smallexample @noindent The keys in this menu perform operations on binary integers. @@ -28941,8 +29373,8 @@ @node Keypad Vectors Menu, Keypad Modes Menu, Keypad Binary Menu, Keypad Mode @section Vectors Menu -@group -@smallexample +@smallexample +@group |----+----+----+----+----+----4 |SUM |PROD|MAX |MAP*|MAP^|MAP$| |----+----+----+----+----+----| @@ -28950,8 +29382,8 @@ |----+----+----+----+----+----| |PACK|UNPK|INDX|BLD |LEN |... | |----+----+----+----+----+----| -@end smallexample -@end group +@end group +@end smallexample @noindent The keys in this menu operate on vectors and matrices. @@ -29023,8 +29455,8 @@ @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode @section Modes Menu -@group -@smallexample +@smallexample +@group |----+----+----+----+----+----5 |FLT |FIX |SCI |ENG |GRP | | |----+----+----+----+----+----| @@ -29032,8 +29464,8 @@ |----+----+----+----+----+----| |SWAP|RLL3|RLL4|OVER|STO |RCL | |----+----+----+----+----+----| -@end smallexample -@end group +@end group +@end smallexample @noindent The keys in this menu manipulate modes, variables, and the stack. @@ -29211,7 +29643,7 @@ The @kbd{M-# o} command is a useful way to open a Calc window without actually selecting that window. Giving this command verifies that @samp{2 < n} is also on the Calc stack. Typing -@kbd{17 RET} would produce: +@kbd{17 @key{RET}} would produce: @example We define $F_n = F_(n-1)+F_(n-2)$ for all $17$. @@ -29382,11 +29814,11 @@ @noindent with the second copy of the formula enabled in Embedded mode. -You can now press @kbd{a d x RET} to take the derivative, and +You can now press @kbd{a d x @key{RET}} to take the derivative, and @kbd{M-# d M-# d} to make two more copies of the derivative. -To complete the computations, type @kbd{3 s l x RET} to evaluate +To complete the computations, type @kbd{3 s l x @key{RET}} to evaluate the last formula, then move up to the second-to-last formula -and type @kbd{2 s l x RET}. +and type @kbd{2 s l x @key{RET}}. Finally, you would want to press @kbd{M-# e} to exit Embedded mode, then go up and insert the necessary text in between the @@ -29491,7 +29923,7 @@ The right thing to do is first to use a selection command (@kbd{j 2} will do the trick) to select the righthand side of the assignment. -Then, @kbd{17 TAB DEL} will swap the 17 into place (@pxref{Selecting +Then, @kbd{17 @key{TAB} @key{DEL}} will swap the 17 into place (@pxref{Selecting Subformulas}, to see how this works). @kindex M-# j @@ -30156,7 +30588,7 @@ If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard macro is edited in spelled-out keystroke form. For example, the editing -buffer might contain the nine characters @w{@samp{1 RET 2 +}}. When you press +buffer might contain the nine characters @w{@samp{1 @key{RET} 2 +}}. When you press @kbd{M-# M-#}, the @code{read-kbd-macro} feature of the @file{macedit} package is used to reinterpret these key names. The notations @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, @code{DEL}, and @@ -30164,8 +30596,8 @@ and @code{M-}. Spaces and line breaks are ignored. Other characters are copied verbatim into the keyboard macro. Basically, the notation is the same as is used in all of this manual's examples, except that the manual -takes some liberties with spaces: When we say @kbd{' [1 2 3] RET}, we take -it for granted that it is clear we really mean @kbd{' [1 SPC 2 SPC 3] RET}, +takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take +it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}, which is what @code{read-kbd-macro} wants to see.@refill If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro @@ -30903,9 +31335,9 @@ the @samp{*Calc Trail*} window. @findex calc-set-command-flag -You can call, for example, @code{(calc-set-command-flag 'no-align)} to set -the above-mentioned command flags. The following command flags are -recognized by Calc routines: +You can call, for example, @code{(calc-set-command-flag 'no-align)} to +set the above-mentioned command flags. Calc routines recognize the +following command flags: @table @code @item renum-stack @@ -31206,7 +31638,9 @@ @subsubsection Bit-Counting @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex bcount Calc does not include a built-in function for counting the number of ``one'' bits in a binary integer. It's easy to invent one using @kbd{b u} @@ -31246,10 +31680,10 @@ involve actual division. To gain a bit more efficiency, we could divide the integer into -@i{n}-bit chunks, each of which can be handled quickly because +@var{n}-bit chunks, each of which can be handled quickly because they fit into Lisp integers. It turns out that Calc's arithmetic routines are especially fast when dividing by an integer less than -1000, so we can set @i{n = 9} bits and use repeated division by 512: +1000, so we can set @var{n = 9} bits and use repeated division by 512: @smallexample (defmath bcount ((natnum n)) @@ -31288,7 +31722,9 @@ @subsubsection The Sine Function @noindent -@c @starindex +@ignore +@starindex +@end ignore @tindex mysin A somewhat limited sine function could be defined as follows, using the well-known Taylor series expansion for @c{$\sin x$} @@ -32834,7 +33270,7 @@ @end defun @defun build-vector args -Return a Calc vector with the zero-or-more @var{args} as elements. +Return a Calc vector with @var{args} as elements. For example, @samp{(build-vector 1 2 3)} returns the Calc vector @samp{[1, 2, 3]}, stored internally as the list @samp{(vec 1 2 3)}. @end defun @@ -33889,7 +34325,7 @@ Calculator can exit. You may also wish to test the GNUPLOT interface; to plot a sine wave, -type @kbd{' [0 ..@: 360], sin(x) RET g f}. Type @kbd{g q} when you +type @kbd{' [0 ..@: 360], sin(x) @key{RET} g f}. Type @kbd{g q} when you are done viewing the plot. Calc is now ready to use. If you wish to go through the Calc Tutorial, @@ -33963,18 +34399,19 @@ \gdef\sumrow#1{\sumrowx#1\relax}% \gdef\sumrowx#1\:#2\:#3\:#4\:#5\:#6\relax{% \leavevmode% -\hbox to5em{\indsl\hss#1}% -\hbox to5em{\ninett#2\hss}% -\hbox to4em{\indsl#3\hss}% -\hbox to5em{\indrm\hss#4}% +{\smallfonts +\hbox to5em{\sl\hss#1}% +\hbox to5em{\tt#2\hss}% +\hbox to4em{\sl#3\hss}% +\hbox to5em{\rm\hss#4}% \thinspace% -{\ninett#5}% -{\indsl#6}% -}% -\gdef\sumlpar{{\indrm(}}% -\gdef\sumrpar{{\indrm)}}% -\gdef\sumcomma{{\indrm,\thinspace}}% -\gdef\sumexcl{{\indrm!}}% +{\tt#5}% +{\sl#6}% +}}% +\gdef\sumlpar{{\rm(}}% +\gdef\sumrpar{{\rm)}}% +\gdef\sumcomma{{\rm,\thinspace}}% +\gdef\sumexcl{{\rm!}}% \gdef\sumbreak{\vskip-2.5\baselineskip\goodbreak}% \gdef\minus#1{{\tt-}}% @end tex @@ -33988,7 +34425,6 @@ @format @iftex @advance@baselineskip-2.5pt -@let@tt@ninett @let@c@sumbreak @end iftex @r{ @: M-# a @: @: 33 @:calc-embedded-activate@:} @@ -34056,14 +34492,14 @@ @r{ a@: M-% @: @: @:percent@:(a) a%} @c -@r{ ... a@: RET @: @: 1 @:@:... a a} -@r{ ... a@: SPC @: @: 1 @:@:... a a} -@r{... a b@: TAB @: @: 3 @:@:... b a} -@r{. a b c@: M-TAB @: @: 3 @:@:... b c a} -@r{... a b@: LFD @: @: 1 @:@:... a b a} -@r{ ... a@: DEL @: @: 1 @:@:...} -@r{... a b@: M-DEL @: @: 1 @:@:... b} -@r{ @: M-RET @: @: 4 @:calc-last-args@:} +@r{ ... a@: @key{RET} @: @: 1 @:@:... a a} +@r{ ... a@: @key{SPC} @: @: 1 @:@:... a a} +@r{... a b@: @key{TAB} @: @: 3 @:@:... b a} +@r{. a b c@: M-@key{TAB} @: @: 3 @:@:... b c a} +@r{... a b@: @key{LFD} @: @: 1 @:@:... a b a} +@r{ ... a@: @key{DEL} @: @: 1 @:@:...} +@r{... a b@: M-@key{DEL} @: @: 1 @:@:... b} +@r{ @: M-@key{RET} @: @: 4 @:calc-last-args@:} @r{ a@: ` @:editing @: 1,30 @:calc-edit@:} @c @@ -34295,8 +34731,8 @@ @r{ @: d [ @: @: 4 @:calc-truncate-up@:} @r{ @: d ] @: @: 4 @:calc-truncate-down@:} @r{ @: d " @: @: 12,50 @:calc-display-strings@:} -@r{ @: d SPC @: @: @:calc-refresh@:} -@r{ @: d RET @: @: 1 @:calc-refresh-top@:} +@r{ @: d @key{SPC} @: @: @:calc-refresh@:} +@r{ @: d @key{RET} @: @: 1 @:calc-refresh-top@:} @c @r{ @: d 0 @: @: 50 @:calc-decimal-radix@:} @@ -34432,8 +34868,8 @@ @c @r{ @: j 1-9 @: @: @:calc-select-part@:} -@r{ @: j RET @: @: 27 @:calc-copy-selection@:} -@r{ @: j DEL @: @: 27 @:calc-del-selection@:} +@r{ @: j @key{RET} @: @: 27 @:calc-copy-selection@:} +@r{ @: j @key{DEL} @: @: 27 @:calc-del-selection@:} @r{ @: j ' @:formula @: 27 @:calc-enter-selection@:} @r{ @: j ` @:editing @: 27,30 @:calc-edit-selection@:} @r{ @: j " @: @: 7,27 @:calc-sel-expand-formula@:} @@ -34814,7 +35250,7 @@ Positive prefix arguments apply to @cite{n} stack entries. Negative prefix arguments apply to the @cite{-n}th stack entry. A prefix of zero applies to the entire stack. (For @key{LFD} and -@kbd{M-DEL}, the meaning of the sign is reversed.) +@kbd{M-@key{DEL}}, the meaning of the sign is reversed.) @c 2 @item @@ -34925,8 +35361,8 @@ @c 20 @item -With a prefix argument of 1, take a single @c{$N\times2$} -@asis{Nx2} matrix from the +With a prefix argument of 1, take a single @c{$@var{n}\times2$} +@i{@var{N}x2} matrix from the stack instead of two separate data vectors. @c 21 @@ -35135,7 +35571,7 @@ Press @kbd{?} repeatedly to see how to choose a model. Answer the variables prompt with @cite{iv} or @cite{iv;pv} to specify independent and parameter variables. A positive prefix argument -takes @i{N+1} vectors from the stack; a zero prefix takes a matrix +takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix and a vector from the stack. @c 49