X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/450c6476679b5781085f0644d3a094643f4ed1a1..adc55deaa5e0496d50042dd5a6bd4d0c41e09c78:/man/calc.texi diff --git a/man/calc.texi b/man/calc.texi index 8c78cd466b..3ef1b449e8 100644 --- a/man/calc.texi +++ b/man/calc.texi @@ -3,7 +3,7 @@ @c smallbook @setfilename ../info/calc @c [title] -@settitle GNU Emacs Calc 2.02 Manual +@settitle GNU Emacs Calc 2.02g Manual @setchapternewpage odd @comment %**end of header (This is for running Texinfo on a region.) @@ -22,11 +22,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{% @@ -40,128 +36,22 @@ \gdef\mycxxz#1{} @end tex -@c Fix some things to make math mode work properly. -@iftex -@textfont0=@tenrm -@font@teni=cmmi10 scaled @magstephalf @textfont1=@teni -@font@seveni=cmmi7 scaled @magstephalf @scriptfont1=@seveni -@font@fivei=cmmi5 scaled @magstephalf @scriptscriptfont1=@fivei -@font@tensy=cmsy10 scaled @magstephalf @textfont2=@tensy -@font@sevensy=cmsy7 scaled @magstephalf @scriptfont2=@sevensy -@font@fivesy=cmsy5 scaled @magstephalf @scriptscriptfont2=@fivesy -@font@tenex=cmex10 scaled @magstephalf @textfont3=@tenex -@scriptfont3=@tenex @scriptscriptfont3=@tenex -@textfont7=@tentt @scriptfont7=@tentt @scriptscriptfont7=@tentt -@end iftex - @c Fix some other things specifically for this manual. @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} @@ -170,75 +60,49 @@ @catcode`@\=0 \catcode`\@=11 \r@ggedbottomtrue \catcode`\@=0 @catcode`@\=@active +@end ignore @end iftex -@ifinfo +@copying This file documents Calc, the GNU Emacs calculator. -Copyright (C) 1990, 1991 Free Software Foundation, Inc. +Copyright (C) 1990, 1991, 2001, 2002 Free Software Foundation, Inc. -Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.1 or +any later version published by the Free Software Foundation; with the +Invariant Sections being just ``GNU GENERAL PUBLIC LICENSE'', with the +Front-Cover texts being ``A GNU Manual,'' and with the Back-Cover +Texts as in (a) below. -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries copying permission notice -identical to this one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). +(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify +this GNU Manual, like GNU software. Copies published by the Free +Software Foundation raise funds for GNU development.'' +@end quotation +@end copying -@end ignore -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the author instead of in the -original English. -@end ifinfo +@dircategory Emacs +@direntry +* Calc: (calc). Advanced desk calculator and mathematical tool. +@end direntry @titlepage @sp 6 @center @titlefont{Calc Manual} @sp 4 -@center GNU Emacs Calc Version 2.02 +@center GNU Emacs Calc Version 2.02g @c [volume] @sp 1 -@center January 1992 +@center January 2002 @sp 5 @center Dave Gillespie @center daveg@@synaptics.com @page @vskip 0pt plus 1filll -Copyright @copyright{} 1990, 1991 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries copying permission notice -identical to this one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). - -@end ignore -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the author instead of in the -original English. +Copyright @copyright{} 1990, 1991, 2001, 2002 Free Software Foundation, Inc. +@insertcopying @end titlepage @c [begin] @@ -247,14 +111,14 @@ original English. @chapter The GNU Emacs Calculator @noindent -@dfn{Calc 2.02} is an advanced desk calculator and mathematical tool +@dfn{Calc} is an advanced desk calculator and mathematical tool that runs as part of the GNU Emacs environment. -This manual is divided into three major parts: "Getting Started," the -"Calc Tutorial," and the "Calc Reference." The Tutorial introduces all -the major aspects of Calculator use in an easy, hands-on way. The -remainder of the manual is a complete reference to the features of the -Calculator. +This manual is divided into three major parts: ``Getting Started,'' +the ``Calc Tutorial,'' and the ``Calc Reference.'' The Tutorial +introduces all the major aspects of Calculator use in an easy, +hands-on way. The remainder of the manual is a complete reference to +the features of the Calculator. For help in the Emacs Info system (which you are using to read this file), type @kbd{?}. (You can also type @kbd{h} to run through a @@ -570,7 +434,7 @@ Financial functions such as future value and internal rate of return. @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. @@ -597,8 +461,6 @@ read is the ``Getting Started'' chapter of this manual and possibly the 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! @@ -687,10 +549,10 @@ Return key, @key{SPC} for the space bar, @key{TAB} for the Tab key, 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}) @@ -718,19 +580,19 @@ everything you see here will be covered more thoroughly in the 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 @@ -738,30 +600,30 @@ Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$} @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 @@ -787,19 +649,19 @@ the Keypad Calculator off. @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 +@group 1.23 1.97 1.6 2 1.19 1.08 -@end example @end group +@end example @noindent The result @samp{[1.23, 1.97, 1.6, 2, 1.19, 1.08]} is a Calc ``vector.'' @@ -819,23 +681,23 @@ Type @kbd{v t} to transpose this @c{$3\times2$} @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 @@ -845,25 +707,25 @@ to view them in the notation for the @TeX{} typesetting system. 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 @@ -947,11 +809,8 @@ operated by the normal Emacs keyboard. When you type @kbd{M-# c} 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---------------------- @@ -964,8 +823,8 @@ with the file you were editing on top and Calc on the bottom. | ->-5 | --%%-Calc: 12 Deg (Calculator)----All----- --%%-Emacs: *Calc Trail* -@end smallexample @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 @@ -1060,9 +919,9 @@ go into regular Calc (with @kbd{M-# c}) to change the mode settings. @noindent @dfn{Keypad Mode} is a mouse-based interface to the Calculator. -It is designed for use with the X window system. If you don't -have X, you will have to operate keypad mode with your arrow -keys (which is probably more trouble than it's worth). Keypad +It is designed for use with terminals that support a mouse. If you +don't have a mouse, you will have to operate keypad mode with your +arrow keys (which is probably more trouble than it's worth). Keypad mode is currently not supported under Emacs 19. Type @kbd{M-# k} to turn Keypad Mode on or off. Once again you @@ -1100,17 +959,6 @@ Stack; the lower window is a picture of a typical calculator keypad. | OFF | 0 | . | PI | + | |-----+-----+-----+-----+-----+ @end smallexample -@iftex -@begingroup -@ifdim@hsize=5in -@vskip-3.7in -@advance@hsize-2.2in -@else -@vskip-3.89in -@advance@hsize-3.05in -@advance@vsize.1in -@fi -@end iftex Keypad Mode is much easier for beginners to learn, because there is no need to memorize lots of obscure key sequences. But not all @@ -1130,9 +978,6 @@ keypad change to show other sets of commands, such as advanced math functions, vector operations, and operations on binary numbers. -@iftex -@endgroup -@end iftex Because Keypad Mode doesn't use the regular keyboard, Calc leaves the cursor in your original editing buffer. You can type in this buffer in the usual way while also clicking on the Calculator @@ -1181,15 +1026,15 @@ itself. editing buffer. Suppose you have a formula written as part of a document like this: -@group @smallexample +@group The derivative of ln(ln(x)) is -@end smallexample @end group +@end smallexample @noindent and you wish to have Calc compute and format the derivative for @@ -1197,8 +1042,8 @@ you and store this derivative in the buffer automatically. To do this with Embedded Mode, first copy the formula down to where you want the result to be: -@group @smallexample +@group The derivative of ln(ln(x)) @@ -1206,8 +1051,8 @@ The derivative of is ln(ln(x)) -@end smallexample @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 @@ -1220,8 +1065,8 @@ the keyboard now acts like the Calc keyboard, and any new result 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 +@group The derivative of ln(ln(x)) @@ -1229,14 +1074,14 @@ The derivative of is 1 / ln(x) x -@end smallexample @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 +@group The derivative of ln(ln(x)) @@ -1248,8 +1093,8 @@ is 1 ------- ln(x) x -@end smallexample @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 @@ -1259,10 +1104,10 @@ these comments up to the top of the file or otherwise put them out of the way.) As an extra flourish, we can add an equation number using a -righthand label: Type @kbd{d @} (1) RET}. +righthand label: Type @kbd{d @} (1) @key{RET}}. -@group @smallexample +@group % [calc-mode: justify: center] % [calc-mode: language: big] % [calc-mode: right-label: " (1)"] @@ -1270,8 +1115,8 @@ righthand label: Type @kbd{d @} (1) RET}. 1 ------- (1) ln(x) x -@end smallexample @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 @@ -1380,7 +1225,6 @@ Quit Calc; turn off standard, Keypad, or Embedded mode if on. @sp 2 @end iftex -@group @noindent Commands for moving data into and out of the Calculator: @@ -1403,9 +1247,7 @@ Yank a value from the Calculator into the current editing buffer. @iftex @sp 2 @end iftex -@end group -@group @noindent Commands for use with Embedded Mode: @@ -1437,9 +1279,7 @@ Edit (as if by @code{calc-edit}) the formula at the current point. @iftex @sp 2 @end iftex -@end group -@group @noindent Miscellaneous commands: @@ -1459,7 +1299,7 @@ Load Calc entirely into memory. (Normally the various parts 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 @@ -1467,7 +1307,6 @@ and record them as the current keyboard macro. 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 @@ -1720,15 +1559,15 @@ The @kbd{+} key ``pops'' the top two numbers from the stack, adds them, 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 +@group . 1: 2 2: 2 1: 5 . . 1: 3 . . - M-# c 2 RET 3 RET + DEL -@end smallexample + 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 @@ -1765,15 +1604,15 @@ Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill 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 +@group 1: 2 2: 2 1: 5 . 1: 3 . . - 2 RET 3 + -@end smallexample + 2 @key{RET} 3 + @end group +@end smallexample @noindent Here, after pressing @kbd{3} the stack would really show @samp{1: 2} @@ -1826,15 +1665,15 @@ from positive to negative or vice-versa: @kbd{5 n @key{RET}}. 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 +@group 1: 3 2: 3 1: 9 2: 9 1: 81 . 1: 3 . 1: 9 . . . - 3 RET RET * RET * -@end smallexample + 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 ^}, @@ -1850,44 +1689,44 @@ two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +} to get 5, and then you realize what you really wanted to compute was @cite{20 / (2+3)}. -@group @smallexample +@group 1: 5 2: 5 2: 20 1: 4 . 1: 20 1: 5 . . . - 2 RET 3 + 20 TAB / -@end smallexample + 2 @key{RET} 3 + 20 @key{TAB} / @end group +@end smallexample @noindent Planning ahead, the calculation would have gone like this: -@group @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 + 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 +@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 + 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 @@ -1899,15 +1738,15 @@ arguments from the stack and push a result. Operations like @kbd{n} and @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 +@group 1: 3 1: 9 2: 9 1: 25 1: 5 . . 1: 16 . . . - 3 RET RET * 4 RET RET * + Q -@end smallexample + 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 @@ -1919,41 +1758,41 @@ right triangle. Calc actually has a built-in command for that called @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 +@group 1: 3 2: 3 1: 5 . 1: 4 . . - 3 RET 4 RET M-x calc-hypot -@end smallexample + 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 +@group 1: 3 2: 3 1: 5 . 1: 4 . . - 3 RET 4 RET x hypot -@end smallexample + 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 +@group 1: 4 1: -4 1: (0, 2) . . . - 4 RET n Q -@end smallexample + 4 @key{RET} n Q @end group +@end smallexample @noindent The notation @cite{(a, b)} represents a complex number. @@ -1971,29 +1810,29 @@ complex result.) Complex numbers are entered in the notation shown. The @kbd{(} and @kbd{,} and @kbd{)} keys manipulate ``incomplete complex numbers.'' -@group @smallexample +@group 1: ( ... 2: ( ... 1: (2, ... 1: (2, ... 1: (2, 3) . 1: 2 . 3 . . . ( 2 , 3 ) -@end smallexample @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 +@group 1: ( ... 2: ( ... 3: ( ... 1: ( ... 1: ( ... . 1: 2 2: 2 5 5 . 1: 3 . . . (error) - ( 2 RET 3 + + -@end smallexample + ( 2 @key{RET} 3 + + @end group +@end smallexample @noindent Adding 5 to an incomplete object makes no sense, so the last command @@ -2002,16 +1841,16 @@ produces an error message and leaves the stack the same. Incomplete objects can't participate in arithmetic, but they can be moved around by the regular stack commands. -@group @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 +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. @@ -2037,16 +1876,16 @@ necessary digits. Numeric prefix arguments can be negative, as in 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 +@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 + 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 @@ -2054,21 +1893,21 @@ negative argument operates on the entry in level @var{n} only. An argument of zero operates on the entire stack. In this example, we copy the second-to-top element of the stack: -@group @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 + 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.) @@ -2113,14 +1952,14 @@ is equivalent to or, in large mathematical notation, @ifinfo -@group @example +@group 3 * 4 * 5 2 + --------- - 9 8 6 * 7 -@end example @end group +@end example @end ifinfo @tex \turnoffactive @@ -2176,15 +2015,15 @@ distracting, even though they otherwise use Calc as an RPN calculator. Still in algebraic mode, type: -@group @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 + (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} @@ -2214,14 +2053,14 @@ of the stack. Here, we perform the calculation @c{$\sqrt{2\times4+1}$} which on a traditional calculator would be done by pressing @kbd{2 * 4 + 1 =} and then the square-root key. -@group @smallexample +@group 1: 8 1: 9 1: 3 . . . - ' 2*4 RET $+1 RET Q -@end smallexample + ' 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}, @@ -2233,7 +2072,7 @@ if the @kbd{Q} key on your keyboard were broken? @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 @@ -2243,14 +2082,14 @@ on the stack, while @w{@kbd{s t}} removes a number from the stack and stores it in the variable.) A variable name should consist of one or more letters or digits, beginning with a letter. -@group @smallexample +@group 1: 17 . 1: a + a^2 1: 306 . . . - 17 s t a RET ' a+a^2 RET = -@end smallexample + 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 @@ -2260,16 +2099,16 @@ For RPN calculations, you can recall a variable's value on the stack either by entering its name as a formula and pressing @kbd{=}, or by using the @kbd{s r} command. -@group @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 + 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}. @@ -2281,26 +2120,26 @@ simply @kbd{s 3} as a shorthand for @kbd{s s 3}, and likewise for Any variables in an algebraic formula for which you have not stored values are left alone, even when you evaluate the formula. -@group @smallexample +@group 1: 2 a + 2 b 1: 34 + 2 b . . - ' 2a+2b RET = -@end smallexample + ' 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 +@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 + ' 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 @@ -2337,15 +2176,15 @@ the stack, you will see two copies of the formula with an @samp{=>} between them. The lefthand formula is exactly like you typed it; the righthand formula has been evaluated as if by typing @kbd{=}. -@group @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 +' 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 @@ -2356,15 +2195,15 @@ to see the effects on the formulas' values. You can also ``unstore'' a variable when you are through with it: -@group @smallexample +@group 2: 2 + 5 => 5 1: 2 a + 2 b => 2 a + 2 b . - s u a RET -@end smallexample + 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. @@ -2374,46 +2213,46 @@ when we discuss the algebra and calculus features of the Calculator. @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 +@group 1: 2 2: 2 1: 8 2: 2 1: 6 . 1: 3 . 1: 3 . . . - 2 RET 3 ^ U * -@end smallexample + 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 +@group 1: 6 2: 2 1: 2 . . . 1: 3 . . (error) U U U U -@end smallexample @end group +@end smallexample You can also type @kbd{D} to ``redo'' a command that you have undone mistakenly. -@group @smallexample +@group . 1: 2 2: 2 1: 6 1: 6 . 1: 3 . . . (error) D D D D -@end smallexample @end group +@end smallexample @noindent It was not possible to redo past the @cite{6}, since that was placed there @@ -2484,7 +2323,7 @@ trail-related commands. Each entry on the line shows one command, with a single capital letter showing which letter you press to get that command. We have used @kbd{t n}, @kbd{t p}, @kbd{t ]}, and @kbd{t y} so far. The @samp{[MORE]} means you can press @kbd{?} -again to see more @kbd{t}-prefix comands. Notice that the commands +again to see more @kbd{t}-prefix commands. Notice that the commands are roughly divided (by semicolons) into related groups. When you are in the help display for a prefix key, the prefix is @@ -2536,13 +2375,13 @@ You can set the precision to anything you like by pressing @kbd{p}, then entering a suitable number. Try pressing @kbd{p 30 @key{RET}}, then doing @kbd{1 @key{RET} 7 /} again: -@group @smallexample +@group 1: 0.142857142857 2: 0.142857142857142857142857142857 . -@end smallexample @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 @@ -2560,14 +2399,14 @@ duplicate the number, then @w{@kbd{1 +}}. Notice that the @key{RET} 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 +@group 1: 0.142857142857 2: 0.142857142857142857142857142857 3: 1.14285714286 . -@end smallexample @end group +@end smallexample @noindent In fact, since we added a digit on the left, we had to lose one @@ -2591,15 +2430,15 @@ to convert an integer to floating-point form. Let's try entering that last calculation: -@group @smallexample +@group 1: 2. 2: 2. 1: 1.99506311689e3010 . 1: 10000 . . - 2.0 RET 10000 RET ^ -@end smallexample + 2.0 @key{RET} 10000 @key{RET} ^ @end group +@end smallexample @noindent @cindex Scientific notation, entry of @@ -2608,15 +2447,15 @@ power of,'' and is used by Calc automatically whenever writing the number out fully would introduce more extra zeros than you probably want to see. You can enter numbers in this notation, too. -@group @smallexample +@group 1: 2. 2: 2. 1: 1.99506311678e3010 . 1: 10000. . . - 2.0 RET 1e4 RET ^ -@end smallexample + 2.0 @key{RET} 1e4 @key{RET} ^ @end group +@end smallexample @cindex Round-off errors @noindent @@ -2631,15 +2470,15 @@ a slight error crept in during one of these methods. Which one should we trust? Let's raise the precision a bit and find out: -@group @smallexample +@group . 1: 2. 2: 2. 1: 1.995063116880828e3010 . 1: 10000. . . - p 16 RET 2. RET 1e4 ^ p 12 RET -@end smallexample + p 16 @key{RET} 2. @key{RET} 1e4 ^ p 12 @key{RET} @end group +@end smallexample @noindent @cindex Guard digits @@ -2655,7 +2494,7 @@ Calc does many of its internal calculations to a slightly higher precision, but it doesn't always bump the precision up enough. In each case, Calc added about two digits of precision during its calculation and then rounded back down to 12 digits -afterward. In one case, it was enough; in the the other, it +afterward. In one case, it was enough; in the other, it wasn't. If you really need @var{x} digits of precision, it never hurts to do the calculation with a few extra guard digits. @@ -2668,11 +2507,11 @@ notation}. You get them by pressing @w{@kbd{d n}}, @kbd{d f}, 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 +@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 @@ -2680,8 +2519,8 @@ numbers shown here: . . . . . d n M-3 d n d s M-3 d s M-3 d f -@end smallexample @end group +@end smallexample @noindent Notice that when we typed @kbd{M-3 d n}, the numbers were rounded down @@ -2702,23 +2541,23 @@ so Calc allows you to type shift-@kbd{H} before any mode command to prevent it from updating the stack. Anything Calc displays after the mode-changing command will appear in the new format. -@group @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 + 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. @@ -2860,14 +2699,14 @@ the @samp{Deg} indicator in the mode line. This means that if you use a command that interprets a number as an angle, it will assume the angle is measured in degrees. For example, -@group @smallexample +@group 1: 45 1: 0.707106781187 1: 0.500000000001 1: 0.5 . . . . 45 S 2 ^ c 1 -@end smallexample @end group +@end smallexample @noindent The shift-@kbd{S} command computes the sine of an angle. The sine @@ -2894,26 +2733,26 @@ To do this calculation in radians, we would type @kbd{m r} first. again, this is a shifted capital @kbd{P}. Remember, unshifted @kbd{p} sets the precision.) -@group @smallexample +@group 1: 3.14159265359 1: 0.785398163398 1: 0.707106781187 . . . P 4 / m r S -@end smallexample @end group +@end smallexample Likewise, inverse trigonometric functions generate results in either radians or degrees, depending on the current angular mode. -@group @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 smallexample @noindent Here we compute the Inverse Sine of @c{$\sqrt{0.5}$} @@ -2923,14 +2762,14 @@ radians, then in degrees. Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees and vice-versa. -@group @smallexample +@group 1: 45 1: 0.785398163397 1: 45. . . . 45 c r c d -@end smallexample @end group +@end smallexample Another interesting mode is @dfn{fraction mode}. Normally, dividing two integers produces a floating-point result if the @@ -2938,15 +2777,15 @@ quotient can't be expressed as an exact integer. Fraction mode causes integer division to produce a fraction, i.e., a rational number, instead. -@group @smallexample +@group 2: 12 1: 1.33333333333 1: 4:3 1: 9 . . . - 12 RET 9 / m f U / m f -@end smallexample + 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. @@ -2971,14 +2810,14 @@ again when we changed to fraction mode. But if you use the evaluates-to operator you can get commands like @kbd{m f} to recompute for you. -@group @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 + ' 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 @@ -2999,14 +2838,14 @@ and @kbd{^}. Each normally takes two numbers from the top of the stack and pushes back a result. The @kbd{n} and @kbd{&} keys perform change-sign and reciprocal operations, respectively. -@group @smallexample +@group 1: 5 1: 0.2 1: 5. 1: -5. 1: 5. . . . . . 5 & & n n -@end smallexample @end group +@end smallexample @cindex Binary operators You can apply a ``binary operator'' like @kbd{+} across any number of @@ -3014,32 +2853,32 @@ stack entries by giving it a numeric prefix. You can also apply it pairwise to several stack elements along with the top one if you use a negative prefix. -@group @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 +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 +@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 +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 @@ -3047,8 +2886,8 @@ We can convert them back to integers by pressing @kbd{F}, the integer. There is also @kbd{R}, which rounds to the nearest integer. -@group @smallexample +@group 7: 2. 7: 2 7: 2 6: 2.4 6: 2 6: 2 5: 2.5 5: 2 5: 3 @@ -3059,8 +2898,8 @@ integer. . . . M-7 F U M-7 R -@end smallexample @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 @@ -3068,27 +2907,27 @@ backslash @kbd{\}. Another common arithmetic operator is @kbd{%}, which computes the remainder that would arise from a @kbd{\} operation, i.e., the ``modulo'' of two numbers. For example, -@group @smallexample +@group 2: 1234 1: 12 2: 1234 1: 34 1: 100 . 1: 100 . . . -1234 RET 100 \ U % -@end smallexample +1234 @key{RET} 100 \ U % @end group +@end smallexample These commands actually work for any real numbers, not just integers. -@group @smallexample +@group 2: 3.1415 1: 3 2: 3.1415 1: 0.1415 1: 1 . 1: 1 . . . -3.1415 RET 1 \ U % -@end smallexample +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 @@ -3108,15 +2947,15 @@ identity @c{$\sin^2x + \cos^2x = 1$} 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 +@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 + 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. @@ -3127,31 +2966,31 @@ of squares, command. Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} @cite{tan(x) = sin(x) / cos(x)}. -@group @smallexample +@group 2: -0.89879 1: -2.0503 1: -64. 1: 0.43837 . . . U / I T -@end smallexample @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 +@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 smallexample @noindent How can the angle be the same? The answer is that the @kbd{/} operation @@ -3162,16 +3001,16 @@ computes the inverse tangent of the quotient of a pair of numbers. Since you feed it the two original numbers, it has enough information to give you a full 360-degree answer. -@group @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 + 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 @@ -3192,15 +3031,15 @@ except that it is the @emph{difference} @cite{cosh(x)^2 - sinh(x)^2} that always equals one. Let's try to verify this identity.@refill -@group @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 + 64 n @key{RET} @key{RET} H C 2 ^ @key{TAB} H S 2 ^ @end group +@end smallexample @noindent @cindex Roundoff errors, examples @@ -3224,14 +3063,14 @@ The logarithm and exponential functions, for example, work to the base @cite{e} normally but use base-10 instead if you use the Hyperbolic prefix. -@group @smallexample +@group 1: 1000 1: 6.9077 1: 1000 1: 3 . . . . 1000 L U H L -@end smallexample @end group +@end smallexample @noindent First, we mistakenly compute a natural logarithm. Then we undo @@ -3240,15 +3079,15 @@ and compute a common logarithm instead. The @kbd{B} key computes a general base-@var{b} logarithm for any value of @var{b}. -@group @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 + 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 @@ -3276,14 +3115,14 @@ The Calculator also has a set of functions relating to combinatorics 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 +@group 1: 100 1: 93326215443... 1: 100. 1: 9.3326e157 . . . . 100 ! U c f ! -@end smallexample @end group +@end smallexample @noindent Recall, the @kbd{c f} command converts the integer or fraction at the @@ -3299,16 +3138,16 @@ factorial function defined in terms of Euler's Gamma function @cite{gamma(n)} (which is itself available as the @kbd{f g} command). -@group @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 + 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)$} @@ -3327,15 +3166,15 @@ The @kbd{k} prefix key defines several common functions out of combinatorics and number theory. Here we compute the binomial coefficient 30-choose-20, then determine its prime factorization. -@group @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 + 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'' @@ -3348,14 +3187,14 @@ Suppose a program you are writing needs a hash table with at least 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 +@group 1: 10000 1: 10007 1: 9973 . . . 10000 k n I k n -@end smallexample @end group +@end smallexample @noindent Just for kicks we've also computed the next prime @emph{less} than @@ -3392,15 +3231,15 @@ a vector as a list of objects. If you add two vectors, the result is a vector of the sums of the elements, taken pairwise. -@group @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 smallexample @noindent Note that we can separate the vector elements with either commas or @@ -3412,15 +3251,15 @@ If you multiply two vectors, the result is the sum of the products of the elements taken pairwise. This is called the @dfn{dot product} of the vectors. -@group @smallexample +@group 2: [1, 2, 3] 1: 19 1: [7, 6, 0] . . r 1 r 2 * -@end smallexample @end group +@end smallexample @cindex Dot product The dot product of two vectors is equal to the product of their @@ -3430,16 +3269,16 @@ specified point in three-dimensional space.) The @kbd{A} (absolute value) command can be used to compute the length of a vector. -@group @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 + M-@key{RET} M-2 A * / I C @end group +@end smallexample @noindent First we recall the arguments to the dot product command, then @@ -3458,16 +3297,16 @@ input vectors. Unlike the dot product, the cross product is defined only for three-dimensional vectors. Let's double-check our computation of the angle using the cross product. -@group @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 + 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, @@ -3486,15 +3325,15 @@ If we take the dot product of two perpendicular vectors we expect 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 +@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 + r 1 r 3 * @key{DEL} r 2 r 3 * @end group +@end smallexample @cindex Normalizing a vector @cindex Unit vectors @@ -3519,15 +3358,15 @@ This means you can enter a matrix using nested brackets. You can also use the semicolon character to enter a matrix. We'll show both methods here: -@group @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 + [[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. @@ -3545,15 +3384,15 @@ of the right matrix. If we try to duplicate this matrix and multiply it by itself, the dimensions are wrong and the multiplication cannot take place: -@group @smallexample +@group 1: [ [ 1, 2, 3 ] * [ [ 1, 2, 3 ] [ 4, 5, 6 ] ] [ 4, 5, 6 ] ] . - RET * -@end smallexample + @key{RET} * @end group +@end smallexample @noindent Though rather hard to read, this is a formula which shows the product @@ -3562,8 +3401,8 @@ been left in symbolic form. We can multiply the matrices if we @dfn{transpose} one of them first. -@group @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 ] ] @@ -3571,9 +3410,9 @@ We can multiply the matrices if we @dfn{transpose} one of them first. [ 3, 6 ] ] . - U v t * U TAB * -@end smallexample + 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 @@ -3584,16 +3423,16 @@ single row or column depending on which side of the matrix it is on. The result is a plain vector which should also be interpreted as a row or column as appropriate. -@group @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 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 @@ -3611,8 +3450,8 @@ diagonal and zeros elsewhere. It has the property that multiplication by an identity matrix, on the left or on the right, always produces the original matrix. -@group @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 ] . @@ -3620,25 +3459,25 @@ the original matrix. [ 0, 0, 1 ] ] . - r 4 v i 3 RET * -@end smallexample + 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 +@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 smallexample @noindent The vertical bar @kbd{|} @dfn{concatenates} numbers, vectors, and @@ -3647,16 +3486,16 @@ our matrix to make it square. We can multiply these two matrices in either order to get an identity. -@group @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 + M-@key{RET} * U @key{TAB} * @end group +@end smallexample @cindex Systems of linear equations @cindex Linear equations, systems of @@ -3712,8 +3551,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 +@group 2: [6, 2, 3] 1: [-12.6, 15.2, -3.93333] 1: [ [ 1, 2, 3 ] . [ 4, 5, 6 ] @@ -3721,8 +3560,8 @@ inverse of the matrix. Calc can do this all in one step: . [6,2,3] r 5 / -@end smallexample @end group +@end smallexample @noindent The result is the @cite{[a, b, c]} vector that solves the equations. @@ -3731,17 +3570,17 @@ inverse.) Let's verify this solution: -@group @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 + r 5 @key{TAB} * @end group +@end smallexample @noindent Note that we had to be careful about the order in which we multiplied @@ -3847,41 +3686,41 @@ number. You can pack and unpack stack entries into vectors: -@group @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 smallexample You can also build vectors out of consecutive integers, or out of many copies of a given value: -@group @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 + 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 +@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 smallexample @noindent In the first step, we multiply the vector of integers by the vector @@ -3899,14 +3738,14 @@ You can also @dfn{reduce} a binary operator across a vector. For example, reducing @samp{*} computes the product of all the elements in the vector: -@group @smallexample +@group 1: 123123 1: [3, 7, 11, 13, 41] 1: 123123 . . . 123123 k f V R * -@end smallexample @end group +@end smallexample @noindent In this example, we decompose 123123 into its prime factors, then @@ -3915,15 +3754,15 @@ multiply those factors together again to yield the original number. We could compute a dot product ``by hand'' using mapping and reduction: -@group @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 smallexample @noindent Recalling two vectors from the previous section, we compute the @@ -3934,14 +3773,14 @@ A slight variant of vector reduction is the @dfn{accumulate} operation, @kbd{V U}. This produces a vector of the intermediate results from a corresponding reduction. Here we compute a table of factorials: -@group @smallexample +@group 1: [1, 2, 3, 4, 5, 6] 1: [1, 2, 6, 24, 120, 720] . . - v x 6 RET V U * -@end smallexample + 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. @@ -3950,27 +3789,27 @@ for display, not calculating on them. Try the following experiment (if your computer is very fast you may need to substitute a larger vector size). -@group @smallexample +@group 1: [1, 2, 3, 4, ... 1: [2, 3, 4, 5, ... . . - v x 500 RET 1 V M + -@end smallexample + 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 +@group 1: [1, 2, 3, ..., 500] 1: [2, 3, 4, ..., 501] . . - v x 500 RET 1 V M + -@end smallexample + v x 500 @key{RET} 1 V M + @end group +@end smallexample @noindent (where now the @samp{...} is actually part of the Calc display). @@ -4028,20 +3867,20 @@ the manual and find this table there. (Press @kbd{g}, then type 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 +@group 1: [ [ 1.34, 0.234 ] [ 1.41, 0.298 ] @dots{} -@end smallexample @end group +@end smallexample @noindent (You may wish to use @kbd{v .} mode to abbreviate the display of this @@ -4052,27 +3891,27 @@ transpose this matrix into a pair of rows. Remember, a matrix is just a vector of vectors. So we can unpack the matrix into a pair of row vectors on the stack. -@group @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 smallexample @noindent Let's store these in quick variables 1 and 2, respectively. -@group @smallexample +@group 1: [1.34, 1.41, 1.49, ... ] . . t 2 t 1 -@end smallexample @end group +@end smallexample @noindent (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the @@ -4100,24 +3939,24 @@ While there is an actual @code{sum} function in Calc, it's easier to sum a vector using a simple reduction. First, let's compute the four different sums that this formula uses. -@group @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 +@end smallexample @noindent -@group @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 smallexample @ifinfo @noindent @@ -4135,41 +3974,41 @@ $\sum x y$.) Finally, we also need @cite{N}, the number of data points. This is just the length of either of our lists. -@group @smallexample +@group 1: 19 . r 1 v l t 7 -@end smallexample @end group +@end smallexample @noindent (That's @kbd{v} followed by a lower-case @kbd{l}.) Now we grind through the formula: -@group @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 +@end smallexample @noindent -@group @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 smallexample That gives us the slope @cite{m}. The y-intercept @cite{b} can now be found with the simple formula, @@ -4187,27 +4026,27 @@ $$ b = {\sum y - m \sum x \over N} $$ \vskip10pt @end tex -@group @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 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 +@group 1: [0.699, 0.735, ... ] 1: [0.273, 0.309, ... ] . . r 1 r 8 * r 9 + s 0 -@end smallexample @end group +@end smallexample @noindent Notice that multiplying a vector by a constant, and adding a constant @@ -4218,14 +4057,14 @@ we've just been doing geometry in 19-dimensional space! 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 +@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 smallexample @noindent First we compute a vector of differences, then we take the absolute @@ -4244,20 +4083,20 @@ GNUPLOT 3.0, the following instructions will work regardless of the 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 +@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 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 @@ -4268,15 +4107,15 @@ Press @kbd{q} when you are done viewing the character graphics. Next, let's add the line we got from our least-squares fit: -@group @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 + @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} @@ -4324,24 +4163,24 @@ always comes out to zero. Let's verify this for \cite{n=6}. @end tex -@group @smallexample +@group 1: [1, 2, 3, 4, 5, 6, 7] 1: [0, 1, 2, 3, 4, 5, 6] . . - v x 7 RET 1 - + v x 7 @key{RET} 1 - -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [1, -6, 15, -20, 15, -6, 1] 1: 0 . . - V M ' (-1)^$ choose(6,$) RET V R + -@end smallexample + 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{$} @@ -4350,10 +4189,10 @@ The Calculator applies this formula to each element of the vector, 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 @@ -4410,32 +4249,32 @@ leave 1 on the stack if it is, or 0 if it isn't. like the following diagram. (You may wish to use the @kbd{v /} command to enable multi-line display of vectors.) -@group @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 smallexample @noindent @xref{List Answer 6, 6}. (@bullet{}) (@bullet{}) @strong{Exercise 7.} Build the following list of lists. -@group @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 smallexample @noindent @xref{List Answer 7, 7}. (@bullet{}) @@ -4472,7 +4311,7 @@ happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) 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$} @@ -4545,15 +4384,15 @@ the mathematical concept of real numbers, but they are only approximations and are susceptible to roundoff error. Calc also supports @dfn{fractions}, which can exactly represent any rational number. -@group @smallexample +@group 1: 3628800 2: 3628800 1: 518400:7 1: 518414:7 1: 7:518414 . 1: 49 . . . . - 10 ! 49 RET : 2 + & -@end smallexample + 10 ! 49 @key{RET} : 2 + & @end group +@end smallexample @noindent The @kbd{:} command divides two integers to get a fraction; @kbd{/} @@ -4565,27 +4404,27 @@ fraction beginning with 49. You can convert between floating-point and fractional format using @kbd{c f} and @kbd{c F}: -@group @smallexample +@group 1: 1.35027217629e-5 1: 7:518414 . . c f c F -@end smallexample @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 +@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 + 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 @@ -4595,14 +4434,14 @@ to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{}) @dfn{Complex numbers} can be stored in both rectangular and polar form. -@group @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 smallexample @noindent The square root of @i{-9} is by default rendered in rectangular form @@ -4618,15 +4457,15 @@ also write @samp{-inf} for minus infinity, a value less than any real number. The word @code{inf} can only be input using algebraic entry. -@group @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 +' inf @key{RET} 17 n * @key{RET} 72 + A + @end group +@end smallexample @noindent Since infinity is infinitely large, multiplying it by any finite @@ -4639,7 +4478,7 @@ infinity again. Finally, we add this plus infinity to the minus infinity we had earlier. If you work it out, you might expect the answer to be @i{-72} for this. But the 72 has been completely lost next to the infinities; by the time we compute @w{@samp{inf - inf}} -the finite difference between them, if any, is indetectable. +the finite difference between them, if any, is undetectable. So we say the result is @dfn{indeterminate}, which Calc writes with the symbol @code{nan} (for Not A Number). @@ -4647,16 +4486,16 @@ Dividing by zero is normally treated as an error, but you can get Calc to write an answer in terms of infinity by pressing @kbd{m i} to turn on ``infinite mode.'' -@group @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 + 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} @@ -4690,27 +4529,27 @@ a complex number? Can it stand for infinity? @dfn{HMS forms} represent a value in terms of hours, minutes, and seconds. -@group @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 + 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 +@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 smallexample @noindent First we convert the inverse tangent of 0.5 to degrees-minutes-seconds @@ -4728,15 +4567,15 @@ A @dfn{date form} represents a date, or a date and time. Dates must be entered using algebraic entry. Date forms are surrounded by @samp{< >} symbols; most standard formats for dates are recognized. -@group @smallexample +@group 2: 1: 2.25 1: <6:00pm Thu Jan 10, 1991> . . -' <13 Jan 1991>, <1/10/91, 6pm> RET - -@end smallexample +' <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 @@ -4744,14 +4583,14 @@ number of days between them. It is also possible to add an HMS form or a number (of days) to a date form to get another date form. -@group @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 smallexample @c [fix-ref Date Arithmetic] @noindent @@ -4777,15 +4616,15 @@ error of 1 meter, and 8 meters tall, with an estimated error of 0.2 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 +@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 + 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 @@ -4807,15 +4646,15 @@ you exact bounds on an answer. Suppose we additionally know that 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 +@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 smallexample @noindent If our bounds were correct, then the angle to the top of the pole @@ -4829,15 +4668,15 @@ parentheses instead of square brackets. You can even make an interval which is inclusive (``closed'') on one end and exclusive (``open'') on the other. -@group @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 smallexample @noindent The Calculator automatically keeps track of which end values should @@ -4852,38 +4691,38 @@ zero)? What about @samp{@w{1 /} @w{(-10 .. 10)}}? @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 +@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 + 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 +@group 1: 10 mod 24 1: 16 mod 24 1: 1000000... 1: 16 . . . . - 10 M 24 RET 100 ^ 10 RET 100 ^ 24 % -@end smallexample + 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 @@ -4906,14 +4745,14 @@ modulo forms, or as the phase part of a polar complex number. For example, the @code{calc-time} command pushes the current time of day on the stack as an HMS/modulo form. -@group @smallexample +@group 1: 17@@ 34' 45" mod 24@@ 0' 0" 1: 6@@ 22' 15" mod 24@@ 0' 0" . . - x time RET n -@end smallexample + x time @key{RET} n @end group +@end smallexample @noindent This calculation tells me it is six hours and 22 minutes until midnight. @@ -4936,14 +4775,14 @@ application of algebraic expressions, where we use variables with suggestive names like @samp{cm} and @samp{in} to represent units like centimeters and inches. -@group @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 + ' 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 @@ -4951,24 +4790,24 @@ which means two times the variable @samp{in}), then we convert it first to centimeters, then to fathoms, then finally to ``base'' units, which in this case means meters. -@group @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 + ' 9 acre @key{RET} Q u s ' $+30 cm @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @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 smallexample @noindent Since units expressions are really just formulas, taking the square @@ -4983,14 +4822,14 @@ as its standard unit of length. There is a wide variety of units defined in the Calculator. -@group @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 + ' 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 @@ -5004,14 +4843,14 @@ units there is no difference, but temperature units have an offset as well as a scale factor and so there must be two explicit commands for them. -@group @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 + ' 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 @@ -5025,14 +4864,14 @@ Then @kbd{u c} and @kbd{u t} will prompt for both old and new units. When you use this method, you're responsible for remembering which numbers are in which units: -@group @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 + 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 @@ -5075,30 +4914,30 @@ If you enter a formula in algebraic mode that refers to variables, the formula itself is pushed onto the stack. You can manipulate formulas as regular data objects. -@group @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 + ' 2x^2-6 @key{RET} n ' 3x^2+y @key{RET} * @end group +@end smallexample -(@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})? +(@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 +@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 + a x a c x @key{RET} @end group +@end smallexample @noindent First we ``expand'' using the distributive law, then we ``collect'' @@ -5107,14 +4946,14 @@ terms involving like powers of @cite{x}. Let's find the value of this expression when @cite{x} is 2 and @cite{y} is one-half. -@group @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 + 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 @@ -5125,7 +4964,7 @@ back to its original value, if any. (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 @@ -5136,37 +4975,37 @@ values of @cite{x} for which the derivative is zero. If the second derivative of the function at that value of @cite{x} is negative, the function has a local maximum there. -@group @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 + 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 +@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 + ' x @key{RET} / a x a s -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: 34 - 24 x^2 = 0 1: x = 1.19023 . . - 0 a = s 3 a S x RET -@end smallexample + 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 @@ -5175,31 +5014,31 @@ default algebraic simplifications don't do enough, you can use Now we compute the second derivative and plug in our values of @cite{x}: -@group @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 + 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 +@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 + @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 @@ -5214,14 +5053,14 @@ arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}. 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 +@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 + 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; @@ -5233,15 +5072,15 @@ negative, answer, so @cite{x = -1.19023} is also a maximum. To find the actual maximum value, we must plug our two values of @cite{x} into the original formula. -@group @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 + 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 @@ -5251,15 +5090,15 @@ like an assignment to that variable if you don't give a variable name.) 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 +@group 2: [-1, 1] 1: [15.04166, 15.04166] 1: 24.08333 s1^2 ... . . - [ 1 n , 1 ] TAB V M $ RET -@end smallexample + [ 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 @@ -5297,20 +5136,20 @@ like @samp{sqrt(5)} that can't be evaluated exactly are left in symbolic form rather than giving a floating-point approximate answer. Fraction mode (@kbd{m f}) is also useful when doing algebra. -@group @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 + 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 +@group 3 2: 34 x - 24 x @@ -5322,34 +5161,34 @@ One more mode that makes reading formulas easier is ``Big mode.'' . d B -@end smallexample @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 +@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 +@end smallexample @noindent -@group @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 + 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 @@ -5371,27 +5210,27 @@ are shown in normal mode.) 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 +@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 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 +@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 + [ 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$} @@ -5403,7 +5242,7 @@ Calc's integrator can do many simple integrals symbolically, but many 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? @@ -5415,40 +5254,40 @@ to do this by hand using vector mapping and reduction. It is rather slow, though, since the sine and logarithm functions take a long time. We can save some time by reducing the working precision. -@group @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 + 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 *}.) +also have used plain @kbd{v x} as follows: @kbd{v x 10 @key{RET} 9 + .1 *}.) -@group @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 + ' sin(x) ln(x) @key{RET} s 1 m r p 5 @key{RET} V M $ @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: 3.4195 0.34195 . . V R + 0.1 * -@end smallexample @end group +@end smallexample @noindent (If you got wildly different results, did you remember to switch @@ -5464,28 +5303,28 @@ is the same for every box.) 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 +@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 + 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 +@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 + 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 @@ -5573,14 +5412,14 @@ that you can use to define your own algebraic manipulations. Suppose we want to simplify this trigonometric formula: -@group @smallexample +@group 1: 1 / cos(x) - sin(x) tan(x) . - ' 1/cos(x) - sin(x) tan(x) RET s 1 -@end smallexample + ' 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 @@ -5591,14 +5430,14 @@ rules just for practice. Rewrite rules are written with the @samp{:=} symbol. -@group @smallexample +@group 1: 1 / cos(x) - sin(x)^2 / cos(x) . - a r tan(a) := sin(a)/cos(a) RET -@end smallexample + 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 @@ -5621,14 +5460,14 @@ mix this in with the rest of the original formula. To merge over a common denominator, we can use another simple rule: -@group @smallexample +@group 1: (1 - sin(x)^2) / cos(x) . - a r a/x + b/x := (a+b)/x RET -@end smallexample + 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 @@ -5661,14 +5500,14 @@ that the rule @samp{sin(x)^2 := 1 - cos(x)^2} will also work. The latter rule has a more general pattern so it will work in many other situations, too. -@group @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 + 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 @@ -5679,18 +5518,18 @@ need it again later. Also, if the rule doesn't work quite right you 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 +@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 + 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 @@ -5716,24 +5555,24 @@ rewrite. @xref{Rewrites Answer 1, 1}. (@bullet{}) The @kbd{a r} command can also accept a vector of rewrite rules, or a variable containing a vector of rules. -@group @smallexample +@group 1: [tsc, merge, sinsqr] 1: [tan(x) := sin(x) / cos(x), ... ] . . - ' [tsc,merge,sinsqr] RET = + ' [tsc,merge,sinsqr] @key{RET} = -@end smallexample @end group +@end smallexample @noindent -@group @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 + 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, @@ -5747,14 +5586,14 @@ has gotten into an infinite loop. You can give a numeric prefix argument to @kbd{a r} to specify any limit. In particular, @kbd{M-1 a r} does only one rewrite at a time. -@group @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 + 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. @@ -5762,24 +5601,24 @@ of rewrites that occur. Rewrite rules can also be @dfn{conditional}. Simply follow the rule with a @samp{::} symbol and the desired condition. For example, -@group @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 + ' exp(2 pi i) + exp(3 pi i) + exp(4 pi i) @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: 1 + exp(3 pi i) + 1 . - a r exp(k pi i) := 1 :: k % 2 = 0 RET -@end smallexample + 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, @@ -5795,7 +5634,9 @@ to match any @samp{f} with five arguments but in fact matching 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 @@ -5803,16 +5644,16 @@ Fibonacci number. The first two Fibonacci numbers are each 1; 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 +@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 + ' 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 @@ -5826,7 +5667,7 @@ will match @samp{fib(x)} and replace it with @w{@samp{fib(x-1) + fib(x-2)}}. 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 @@ -5835,43 +5676,43 @@ fib(n) := fib(n-1) + fib(n-2) :: integer(n) :: n > 2 @noindent Now: -@group @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 + ' 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 +@group 1: [fib(1) := ...] . 1: [8, 13] . . - s r fib RET s t EvalRules RET ' [fib(6), fib(7)] RET -@end smallexample + 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 +@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 smallexample @noindent Note that @samp{fib(3)} appears three times here. Unless Calc's @@ -5893,7 +5734,7 @@ for technical reasons it is most effective in @code{EvalRules}.) For 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 @@ -5903,7 +5744,7 @@ computed the result for a particular @var{n}, we can get it back (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 @@ -6041,14 +5882,14 @@ key sequence to correspond to any formula. Programming commands use the shift-@kbd{Z} prefix; the user commands they create use the lower case @kbd{z} prefix. -@group @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 + ' 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 @@ -6059,16 +5900,16 @@ default argument list @samp{(x)} is acceptable; and finally @kbd{y} answers the question ``leave it in symbolic form for non-constant arguments?'' -@group @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 + .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 @@ -6080,7 +5921,9 @@ final question, @samp{myexp(a + 1)} would have evaluated by plugging 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)$} @@ -6103,19 +5946,19 @@ keystrokes which Emacs has stored away and can play back on demand. 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 +@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 + ' y=cos(x) @key{RET} X @end group +@end smallexample @noindent When you type @kbd{C-x (}, Emacs begins recording. But it is also @@ -6126,14 +5969,14 @@ re-execute the same keystrokes. You can give a name to your macro by typing @kbd{Z K}. -@group @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 + 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 @@ -6141,14 +5984,14 @@ Notice that we use shift-@kbd{Z} to define the command, and lower-case Keyboard macros can call other macros. -@group @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 + ' 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 @@ -6182,15 +6025,15 @@ In many programs, some of the steps must execute several times. Calc has @dfn{looping} commands that allow this. Loops are useful inside keyboard macros, but actually work at any time. -@group @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 + ' 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 @@ -6204,16 +6047,16 @@ type @w{@kbd{Z C-g}} to cancel the loop command. @cindex Fibonacci numbers Here's another example: -@group @smallexample +@group 3: 1 2: 10946 2: 1 1: 17711 1: 20 . . -1 RET RET 20 Z < TAB C-j + Z > -@end smallexample +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 @@ -6232,14 +6075,14 @@ and then rounding to the nearest integer, where @c{$\phi$ (``phi'')} @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 +@group 1: 1.61803 1: 24476.0000409 1: 10945.9999817 1: 10946 . . . . I H P 21 ^ 5 Q / R -@end smallexample @end group +@end smallexample @cindex Continued fractions (@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} @@ -6266,16 +6109,16 @@ A more sophisticated kind of loop is the @dfn{for} loop. Suppose 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 +@group 3: 0 1: 3.597739 2: 1 . 1: 20 . -0 RET 1 RET 20 Z ( & + 1 Z ) -@end smallexample +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 @@ -6290,15 +6133,15 @@ This harmonic number function uses the stack to hold the running total as well as for the various loop housekeeping functions. If you find this disorienting, you can sum in a variable instead: -@group @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 + 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 @@ -6321,16 +6164,16 @@ we have to worry about the programs clobbering values that the caller was keeping in those same variables. This is easy to fix, though: -@group @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 + 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 @@ -6354,14 +6197,14 @@ command, @kbd{k b}, to compute exact Bernoulli numbers, but this command is very slow for large @cite{n} since the higher Bernoulli numbers are very large fractions.) -@group @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 + 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 @@ -6374,30 +6217,30 @@ if we're asking for an odd Bernoulli number. The actual tenth Bernoulli number is @cite{5/66}. -@group @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 +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 +@group 3: [] 1: [0.10132, 0.03079, 0.02340, 0.033197, ...] 2: 2 . 1: 30 . - [ ] 2 RET 30 Z ( X | 2 Z ) -@end smallexample + [ ] 2 @key{RET} 30 Z ( X | 2 Z ) @end group +@end smallexample @noindent The vertical-bar @kbd{|} is the vector-concatenation command. When @@ -6419,18 +6262,18 @@ it using @kbd{Z E}. First, you must attach it to a key with @kbd{Z K}. One technique is to enter a throwaway dummy definition for the macro, then enter the real one in the edit command. -@group @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 +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} @@ -6456,7 +6299,7 @@ type "0" # Push a zero 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 @@ -6471,14 +6314,14 @@ calc-kbd-pop # Restore values (Z ') @noindent Press @kbd{M-# M-#} to finish editing and return to the Calculator. -@group @smallexample +@group 1: 20 1: 3.597739 . . 20 z h -@end smallexample @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. @@ -6488,18 +6331,18 @@ a handy @code{read-kbd-macro} command which reads the current region 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 +@group Z ` 0 t 1 - 1 TAB + 1 @key{TAB} Z ( & s + 1 1 Z ) r 1 Z ' -@end example @end group +@end example (@bullet{}) @strong{Exercise 8.} A general algorithm for solving equations numerically is @dfn{Newton's Method}. Given the equation @@ -6663,7 +6506,7 @@ The rest of this manual tells the whole story. 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 @@ -6766,43 +6609,43 @@ that result on the stack while you compute the second term. With both of these results waiting on the stack you can then compute the final term, then press @kbd{+ +} to add everything up. -@group @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 * + 2 @key{RET} 4 * 7 @key{RET} 9.5 * -@end smallexample @end group +@end smallexample @noindent -@group @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 + 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 +@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 + ... + 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 @@ -6815,30 +6658,30 @@ you choose is purely a matter of taste. @noindent The @key{TAB} key provides a way to operate on the number in level 2. -@group @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 + @key{TAB} 1 + @key{TAB} @end group +@end smallexample -Similarly, @key{M-TAB} gives you access to the number in level 3. +Similarly, @kbd{M-@key{TAB}} gives you access to the number in level 3. -@group @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 + 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 @@ -6847,15 +6690,15 @@ Similarly, @key{M-TAB} gives you access to the number in level 3. 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 +@group 1: ( ... 2: ( ... 1: (2, ... 2: (2, ... 2: (2, ... . 1: 2 . 1: (2, ... 1: (2, 3) . . . - ( 2 , SPC 3 ) -@end smallexample + ( 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. @@ -6863,19 +6706,19 @@ But a feature of Calc is that @key{DEL} on an incomplete object deletes just one component out of that object, so he had to press @key{DEL} twice to finish the job. -@group @smallexample +@group 2: (2, ... 2: (2, 3) 2: (2, 3) 1: (2, 3) 1: (2, 3) 1: (2, ... 1: ( ... . . . . - TAB DEL DEL -@end smallexample + @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 @@ -6986,7 +6829,7 @@ needs to display scientific notation in a high radix, it writes @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 @@ -7014,24 +6857,24 @@ commands decrease or increase a number by one unit in the last place (according to the current precision). They are useful for determining facts like this. -@group @smallexample +@group 1: 0.707106781187 1: 0.500000000001 . . 45 S 2 ^ -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: 0.707106781187 1: 0.707106781186 1: 0.499999999999 . . . - U DEL f [ 2 ^ -@end smallexample + 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 @@ -7098,15 +6941,15 @@ doesn't try. Duplicate the vector, compute its length, then divide the vector by its length: @kbd{@key{RET} A /}. -@group @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 + 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. @@ -7131,12 +6974,12 @@ get the row sum. Similarly, use @kbd{[1 1] r 4 *} to get the column sum. @subsection Matrix Tutorial Exercise 2 @ifinfo -@group @example +@group x + a y = 6 x + b y = 10 -@end example @end group +@end example @end ifinfo @tex \turnoffactive @@ -7150,27 +6993,27 @@ $$ Just enter the righthand side vector, then divide by the lefthand side matrix as usual. -@group @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 +' [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 +@group 4 a 4 1: [6 - -----, -----] b - a b - a -@end smallexample @end group +@end smallexample Type @kbd{d N} to return to ``normal'' display mode afterwards. @@ -7188,14 +7031,14 @@ system @c{$A' X = B'$} command. @ifinfo -@group @example +@group a + 2b + 3c = 6 4a + 5b + 6c = 2 7a + 6b = 3 2a + 4b + 6c = 11 -@end example @end group +@end example @end ifinfo @tex \turnoffactive @@ -7218,24 +7061,24 @@ quick variable number 7 for later reference. Next, we compute the @c{$B'$} @cite{B2} vector. -@group @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 +' [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 +@group 2: [57, 84, 96] 1: [-11.64, 14.08, -3.64] 1: [ [ 70, 72, 39 ] . [ 72, 81, 60 ] @@ -7243,8 +7086,8 @@ Now we compute the matrix @c{$A'$} . r 7 v t r 7 * / -@end smallexample @end group +@end smallexample @noindent (The actual computed answer will be slightly inexact due to @@ -7264,8 +7107,8 @@ Since the first and fourth equations aren't quite equivalent, they 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 +@group 2: [-11.64, 14.08, -3.64] 1: [5.6, 2., 3., 11.2] 1: [ [ 1, 2, 3 ] . [ 4, 5, 6 ] @@ -7273,9 +7116,9 @@ the original system of equations to see how well they match. [ 2, 4, 6 ] ] . - r 7 TAB * -@end smallexample + r 7 @key{TAB} * @end group +@end smallexample @noindent This is reasonably close to our original @cite{B} vector, @@ -7290,28 +7133,28 @@ adjusted to get the range of integers we desire. Mapping @samp{-} across the vector will accomplish this, although it turns out the plain @samp{-} key will work just as well. -@group @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 + 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 +@group 1: [0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16] . V M ^ -@end smallexample @end group +@end smallexample @node List Answer 2, List Answer 3, List Answer 1, Answers to Exercises @subsection List Tutorial Exercise 2 @@ -7337,44 +7180,44 @@ Thus we want a @c{$19\times2$} 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 +@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 + 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 +@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 smallexample @noindent (Hey, those numbers look familiar!) -@group @smallexample +@group 1: [0.52141679, -0.425978] . / -@end smallexample @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 @@ -7393,40 +7236,40 @@ fits. @xref{Curve Fitting}. @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 +@group 1: [2.3, 6, 22, 15.1, 7, 15, 14, 7.5, 2.5] . -@end smallexample @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 +@group 2: [2.3, 6, 22, ... ] 2: [2.3, 6, 22, ... ] 1: [2.3, 6, 22, ... ] 1: 126356422.5 . . - RET V R * + @key{RET} V R * -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 2: 126356422.5 2: 126356422.5 1: 7.94652913734 1: [2.3, 6, 22, ... ] 1: 9 . . . - TAB v l I ^ -@end smallexample + @key{TAB} v l I ^ @end group +@end smallexample @noindent (The @kbd{I ^} command computes the @var{n}th root of a number. @@ -7441,15 +7284,15 @@ A number @cite{j} is a divisor of @cite{n} if @c{$n \mathbin{\hbox{\code{\%}}} j @samp{n % j = 0}. The first step is to get a vector that identifies the divisors. -@group @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 + 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. @@ -7457,16 +7300,16 @@ This vector has 1's marking divisors of 30 and 0's marking non-divisors. The zeroth divisor function is just the total number of divisors. The first divisor function is the sum of the divisors. -@group @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 smallexample @noindent Once again, the last two steps just compute a dot product for which @@ -7481,25 +7324,25 @@ This list will always be in sorted order, so if there are duplicates 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 +@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 | + 19551 k f @key{RET} 0 | @key{TAB} 0 @key{TAB} | -@end smallexample @end group +@end smallexample @noindent -@group @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 smallexample @noindent Note that we have to arrange for both vectors to have the same length @@ -7516,7 +7359,7 @@ more convenient way to do the above test in practice. @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 @@ -7526,16 +7369,16 @@ to get a list of lists of integers! 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 +@group 1: [ [0], [0, 1], [0, 1, 2], @dots{} 1 - -@end smallexample @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 @@ -7543,22 +7386,22 @@ triangular number is the sum of the integers from 1 to @cite{n}, and can be computed directly by the formula @c{$n (n+1) \over 2$} @cite{n * (n+1) / 2}. -@group @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 + 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 +@group 1: [ [0], [1, 2], [3, 4, 5], @@ -7568,23 +7411,23 @@ result: . V M + -@end smallexample @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 +@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 + @key{RET} V M V R + @end group +@end smallexample @noindent (This means ``map a @kbd{V R +} command across the vector,'' and @@ -7597,41 +7440,41 @@ since each element of the main vector is itself a small vector, @noindent The first step is to build a list of values of @cite{x}. -@group @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 + v x 21 @key{RET} 1 - 4 / s 1 @end group +@end smallexample Next, we compute the Bessel function values. -@group @smallexample +@group 1: [0., 0.124, 0.242, ..., -0.328] . - V M ' besJ(1,$) RET -@end smallexample + V M ' besJ(1,$) @key{RET} @end group +@end smallexample @noindent -(Another way to do this would be @kbd{1 TAB V M f j}.) +(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 +@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 + @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 @@ -7643,15 +7486,15 @@ The vector we have now has a single 1 in the position that indicates the maximum value of @cite{x}. Now it is a simple matter to convert this back into the corresponding value itself. -@group @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 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 @@ -7664,15 +7507,15 @@ The built-in @kbd{a X} command maximizes a function using more efficient methods. Just for illustration, let's use @kbd{a X} to maximize @samp{besJ(1,x)} over this same interval. -@group @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 +' 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} @@ -7685,63 +7528,63 @@ As you can see, our simple search got quite close to the right answer. @noindent Step one is to convert our integer into vector notation. -@group @smallexample +@group 1: 25129925999 3: 25129925999 . 2: 10 1: [11, 10, 9, ..., 1, 0] . - 25129925999 RET 10 RET 12 RET v x 12 RET - + 25129925999 @key{RET} 10 @key{RET} 12 @key{RET} v x 12 @key{RET} - -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: 25129925999 1: [0, 2, 25, 251, 2512, ... ] 2: [100000000000, ... ] . . V M ^ s 1 V M \ -@end smallexample @end group +@end smallexample @noindent (Recall, the @kbd{\} command computes an integer quotient.) -@group @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 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 +@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 +@end smallexample @noindent -@group @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 smallexample @noindent Accumulating @kbd{*} across a vector of ones and zeros will preserve @@ -7750,15 +7593,15 @@ except the rightmost digit. Concatenating a one on the right takes care of aligning the carries properly, and also adding one to the rightmost digit. -@group @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 smallexample @noindent Here we have concatenated 0 to the @emph{left} of the original number; @@ -7767,39 +7610,39 @@ digits that generated them. Finally, we must convert this list back into an integer. -@group @smallexample +@group 3: [0, 0, 2, 5, ... ] 2: [0, 0, 2, 5, ... ] 2: 1000000000000 1: [1000000000000, 100000000000, ... ] 1: [100000000000, ... ] . . - 10 RET 12 ^ r 1 | + 10 @key{RET} 12 ^ r 1 | -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [0, 0, 20000000000, 5000000000, ... ] 1: 25129926000 . . V M * V R + -@end smallexample @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 +@group 1: [0, 0, 2, 5, ... ] 1: 25129926000 . . - V R ' 10 $$ + $ RET -@end smallexample + 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 @@ -7812,25 +7655,25 @@ compared with @cite{d}. This is not at all what Joe wanted. Here's a more correct method: -@group @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 + ' [7,7,7,8,7] @key{RET} @key{RET} v r 1 @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [1, 1, 1, 0, 1] 1: 0 . . V M a = V R * -@end smallexample @end group +@end smallexample @node List Answer 11, List Answer 12, List Answer 10, Answers to Exercises @subsection List Tutorial Exercise 11 @@ -7843,51 +7686,51 @@ and a vector of @cite{y^2}. We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} commands. -@group @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 + v . t . 2. v b 100 @key{RET} @key{RET} V M k r -@end smallexample @end group +@end smallexample @noindent -@group @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 + 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 +@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 smallexample @noindent The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$} @cite{pi/4}. -@group @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 smallexample @noindent Our estimate, 3.36, is off by about 7%. We could get a better estimate @@ -7935,72 +7778,72 @@ and count how many of the results are greater than one. Simple! We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} commands. -@group @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 +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 +@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 +@end smallexample @noindent -@group @smallexample +@group 1: [0, 1, ..., 1] 1: 0.64 1: 3.125 . . . - 1 V M a > V R + 100 / 2 TAB / -@end smallexample + 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 +@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 + 1000000 v b 100 @key{RET} @key{RET} V M k r @key{TAB} V M k r -@end smallexample @end group +@end smallexample @noindent -@group @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 +@end smallexample @noindent -@group @smallexample +@group 1: 10.714 1: 3.273 . . - 6 TAB / Q -@end smallexample + 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. @@ -8014,14 +7857,14 @@ return to full-sized display of vectors. @noindent First, we put the string on the stack as a vector of ASCII codes. -@group @smallexample +@group 1: [84, 101, 115, ..., 51] . - "Testing, 1, 2, 3 RET -@end smallexample + "Testing, 1, 2, 3 @key{RET} @end group +@end smallexample @noindent Note that the @kbd{"} key, like @kbd{$}, initiates algebraic entry so @@ -8034,26 +7877,26 @@ if the input vector is @cite{[a, b, c, d]}, then the hash code is @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 +@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 - + @key{RET} v l v x 16 @key{RET} - -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 2: [84, 101, 115, ..., 51] 1: 1960915098 1: 121 1: [14348907, ..., 1] . . . - 3 TAB V M ^ * 511 % -@end smallexample + 3 @key{TAB} V M ^ * 511 % @end group +@end smallexample @noindent Once again, @kbd{*} elegantly summarizes most of the computation. @@ -8062,14 +7905,14 @@ But there's an even more elegant approach: Reduce the formula function of two arguments that computes its first argument times three plus its second argument. -@group @smallexample +@group 1: [84, 101, 115, ..., 51] 1: 1960915098 . . - "Testing, 1, 2, 3 RET V R ' 3$$+$ RET -@end smallexample + "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. @@ -8083,14 +7926,14 @@ without affecting the result. While this means there are more arithmetic operations, the numbers we operate on remain small so the operations are faster. -@group @smallexample +@group 1: [84, 101, 115, ..., 51] 1: 121 . . - "Testing, 1, 2, 3 RET V R ' (3$$+$)%511 RET -@end smallexample + "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 @@ -8149,7 +7992,7 @@ the calculation. Therefore the two methods are essentially the same. 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 @@ -8158,16 +8001,16 @@ We want to use @kbd{H V U} to nest a function which adds a random step to an @cite{(x,y)} coordinate. The function is a bit long, but otherwise the problem is quite straightforward. -@group @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 + [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 @@ -8177,15 +8020,15 @@ We now have a vector of @cite{[x, y]} sub-vectors, which by Calc's 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 +@group 2: [ 0, 0.4288, -0.4787, ... ] 1: [ 0, -0.1696, -0.9027, ... ] . v t v u g f -@end smallexample @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 @@ -8196,16 +8039,16 @@ a random direction exactly gives us an @cite{[x, y]} step of unit length; in fact, the new nesting function is even briefer, though we might want to lower the precision a bit for it. -@group @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 + [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. @@ -8225,14 +8068,14 @@ If the number is the square root of @c{$\pi$} then its square, divided by @c{$\pi$} @cite{pi}, should be a rational number. -@group @smallexample +@group 1: 1.26508260337 1: 0.509433962268 1: 2486645810:4881193627 . . . 2 ^ P / c F -@end smallexample @end group +@end smallexample @noindent Technically speaking this is a rational number, but not one that is @@ -8243,14 +8086,14 @@ irrational number to within 12 digits. But perhaps our result was not quite exact. Let's reduce the precision slightly and try again: -@group @smallexample +@group 1: 0.509433962268 1: 27:53 . . - U p 10 RET c F -@end smallexample + U p 10 @key{RET} c F @end group +@end smallexample @noindent Aha! It's unlikely that an irrational number would equal a fraction @@ -8323,28 +8166,28 @@ unable to tell what the true answer is. @node Types Answer 4, Types Answer 5, Types Answer 3, Answers to Exercises @subsection Types Tutorial Exercise 4 -@group @smallexample +@group 2: 0@@ 47' 26" 1: 0@@ 2' 47.411765" 1: 17 . . - 0@@ 47' 26" RET 17 / -@end smallexample + 0@@ 47' 26" @key{RET} 17 / @end group +@end smallexample @noindent The average song length is two minutes and 47.4 seconds. -@group @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 smallexample @noindent The album would be 53 minutes and 6 seconds long. @@ -8357,14 +8200,14 @@ Let's suppose it's January 14, 1991. The easiest thing to do is 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 +@group 1: 1: 1: . . . - ' <2/13> RET DEL ' <3/13> RET t I -@end smallexample + ' <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.) @@ -8375,34 +8218,28 @@ vector mapping. The @kbd{t I} command actually takes a second ``how-many-months'' argument, which defaults to one. This argument is exactly what we want to map over: -@group @smallexample +@group 2: 1: [, , 1: [1, 2, 3, 4, 5, 6] , , . , ] . - v x 6 RET V M t I -@end smallexample + v x 6 @key{RET} V M t I @end group +@end smallexample -@ifinfo @noindent -Et voila, September 13, 1991 is a Friday. -@end ifinfo -@tex -\noindent -{\it Et voil{\accent"12 a}}, September 13, 1991 is a Friday. -@end tex +Et voil@`a, September 13, 1991 is a Friday. -@group @smallexample +@group 1: 242 . -' - RET -@end smallexample +' - @key{RET} @end group +@end smallexample @noindent And the answer to our original question: 242 days to go. @@ -8424,27 +8261,27 @@ the number of days between now and then, and compare that to the 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 +@group 1: 2: 1: 2925593 . 1: . . - ' RET ' RET - + ' @key{RET} ' @key{RET} - -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 3: 2925593 2: 2925593 2: 2925593 1: 1943 2: 10001 1: 8010 1: 2923650 . 1: 1991 . . . - 10001 RET 1991 - 365 * - -@end smallexample + 10001 @key{RET} 1991 - 365 * - @end group +@end smallexample @c [fix-ref Date Forms] @noindent @@ -8460,40 +8297,40 @@ background information in that regard.) The relative errors must be converted to absolute errors so that @samp{+/-} notation may be used. -@group @smallexample +@group 1: 1. 2: 1. . 1: 0.2 . - 20 RET .05 * 4 RET .05 * -@end smallexample + 20 @key{RET} .05 * 4 @key{RET} .05 * @end group +@end smallexample Now we simply chug through the formula. -@group @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 + 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 +@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 + @key{RET} v u @key{TAB} / @end group +@end smallexample @noindent Thus the volume is 6316 cubic centimeters, within about 11 percent. @@ -8533,15 +8370,15 @@ that interval arithmetic can do in this case. @node Types Answer 9, Types Answer 10, Types Answer 8, Answers to Exercises @subsection Types Tutorial Exercise 9 -@group @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 + [ 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 @@ -8560,15 +8397,15 @@ The same issue arises when you try to square an error form. @noindent Testing the first number, we might arbitrarily choose 17 for @cite{x}. -@group @smallexample +@group 1: 17 mod 811749613 2: 17 mod 811749613 1: 533694123 mod 811749613 . 811749612 . . - 17 M 811749613 RET 811749612 ^ -@end smallexample + 17 M 811749613 @key{RET} 811749612 ^ @end group +@end smallexample @noindent Since 533694123 is (considerably) different from 1, the number 811749613 @@ -8579,15 +8416,15 @@ various ways to avoid this, and algebraic entry is one. In fact, using a vector mapping operation we can perform several tests at once. Let's use this method to test the second number. -@group @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 + [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 @@ -8610,26 +8447,26 @@ There are several ways to insert a calculated number into an HMS form. 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 +@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 +@end smallexample @noindent -@group @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 + x time @key{RET} + @end group +@end smallexample @noindent It will be just after six in the morning. @@ -8637,14 +8474,14 @@ It will be just after six in the morning. The algebraic @code{hms} function can also be used to build an HMS form: -@group @smallexample +@group 1: hms(0, 0, 10000000. pi) 1: 8726@@ 38' 46.5359" . . - ' hms(0, 0, 1e7 pi) RET = -@end smallexample + ' hms(0, 0, 1e7 pi) @key{RET} = @end group +@end smallexample @noindent The @kbd{=} key is necessary to evaluate the symbol @samp{pi} to @@ -8657,25 +8494,25 @@ the actual number 3.14159... As we recall, there are 17 songs of about 2 minutes and 47 seconds each. -@group @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 +@end smallexample @noindent -@group @smallexample +@group 1: [0@@ 52' 59." .. 1@@ 4' 19."] . 17 * -@end smallexample @end group +@end smallexample @noindent No matter how long it is, the album will fit nicely on one CD. @@ -8684,7 +8521,7 @@ No matter how long it is, the album will fit nicely on one CD. @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 @@ -8693,27 +8530,27 @@ Type @kbd{' 1 yr RET u c s RET}. The answer is 31557600 seconds. How long will it take for a signal to get from one end of the computer to the other? -@group @smallexample +@group 1: m / c 1: 3.3356 ns . . - ' 1 m / c RET u c ns RET -@end smallexample + ' 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 +@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 + ' 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 @@ -8727,29 +8564,29 @@ could actually attain the full speed of light. Pretty tight! 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 +@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 + ' 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 +@group 1: 19360. 2: 19360. 1: 14.24 . 1: 2 . . u s 2 B -@end smallexample @end group +@end smallexample @noindent Thus Sam can take up to 14 pills without a worry. @@ -8776,34 +8613,34 @@ is zero when @cite{x} is any of these values. The trivial polynomial will do the job. We can use @kbd{a c x} to write this in a more familiar form. -@group @smallexample +@group 1: 34 x - 24 x^3 1: [1.19023, -1.19023, 0] . . - r 2 a P x RET + r 2 a P x @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [x - 1.19023, x + 1.19023, x] 1: (x - 1.19023) (x + 1.19023) x . . - V M ' x-$ RET V R * + V M ' x-$ @key{RET} V R * -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: x^3 - 1.41666 x 1: 34 x - 24 x^3 . . - a c x RET 24 n * a x -@end smallexample + 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 @@ -8812,65 +8649,65 @@ same as the original polynomial. @node Algebra Answer 3, Algebra Answer 4, Algebra Answer 2, Answers to Exercises @subsection Algebra Tutorial Exercise 3 -@group @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 + ' x sin(pi x) @key{RET} m r a i x @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [y, 1] 2: (sin(pi x) - pi x cos(pi x)) / pi^2 . - ' [y,1] RET TAB + ' [y,1] @key{RET} @key{TAB} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [(sin(pi y) - pi y cos(pi y)) / pi^2, (sin(pi) - pi cos(pi)) / pi^2] . - V M $ RET + V M $ @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @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 +@end smallexample @noindent -@group @smallexample +@group 1: (sin(3.14159 y) - 3.14159 y cos(3.14159 y)) / 9.8696 - 0.3183 . = -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [0., -0.95493, 0.63662, -1.5915, 1.2732] . - v x 5 RET TAB V M $ RET -@end smallexample + 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 @@ -8881,63 +8718,63 @@ the contributions from the slices, since the slices have varying coefficients. So first we must come up with a vector of these coefficients. Here's one way: -@group @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 - + 1 n v x 9 @key{RET} V M ^ 3 @key{TAB} - -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 1: [4, 2, ..., 4, 1] 1: [1, 4, 2, ..., 4, 1] . . - 1 | 1 TAB | -@end smallexample + 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 +@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 + 11 @key{RET} 1 @key{RET} .1 @key{RET} C-u v x -@end smallexample @end group +@end smallexample @noindent -@group @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 + ' 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 +@group 1: 11.22 1: 1.122 1: 0.374 . . . * .1 * 3 / -@end smallexample @end group +@end smallexample @noindent Wow! That's even better than the result from the Taylor series method. @@ -8948,8 +8785,8 @@ Wow! That's even better than the result from the Taylor series method. @noindent We'll use Big mode to make the formulas more readable. -@group @smallexample +@group ___ 2 + V 2 1: (2 + sqrt(2)) / (1 + sqrt(2)) 1: -------- @@ -8958,33 +8795,33 @@ We'll use Big mode to make the formulas more readable. . - ' (2+sqrt(2)) / (1+sqrt(2)) RET d B -@end smallexample + ' (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 +@group ___ ___ 1: (2 + V 2 ) (V 2 - 1) . - a r a/(b+c) := a*(b-c) / (b^2-c^2) RET + a r a/(b+c) := a*(b-c) / (b^2-c^2) @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @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 smallexample @noindent (We could have used @kbd{a x} instead of a rewrite rule for the @@ -9000,13 +8837,13 @@ sines and cosines or the imaginary constant @code{i}. @noindent Here is the rule set: -@group @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 smallexample @noindent The first rule turns a one-argument @code{fib} that people like to write @@ -9056,16 +8893,18 @@ on the lefthand side, so that the rule matches the actual variable @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 +@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 smallexample Given the initial formula @samp{seq(6, 0)}, application of these rules produces the following sequence of formulas: @@ -9086,13 +8925,13 @@ whereupon neither of the rules match, and rewriting stops. We can pretty this up a bit with a couple more rules: -@group @smallexample +@group [ seq(n) := seq(n, 0), seq(1, c) := c, ... ] -@end smallexample @end group +@end smallexample @noindent Now, given @samp{seq(6)} as the starting configuration, we get 8 @@ -9100,14 +8939,14 @@ as the result. The change to return a vector is quite simple: -@group @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 smallexample @noindent Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. @@ -9127,18 +8966,20 @@ apply and the rewrites will stop right away. @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. +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. -@group @smallexample +@group [ nterms(a + b) := nterms(a) + nterms(b), nterms(x) := 1 ] -@end smallexample @end group +@end smallexample @noindent Here we have taken advantage of the fact that earlier rules always @@ -9151,28 +8992,28 @@ already know that @samp{x} is not a sum. Just put the rule @samp{0^0 := 1} into @code{EvalRules}. For example, before making this definition we have: -@group @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 + v x 5 @key{RET} 3 - 0 V M ^ @end group +@end smallexample @noindent But then: -@group @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 + 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 @@ -9190,8 +9031,8 @@ a nasty surprise when you use Calc to balance your checkbook!) @noindent Here is a rule set that will do the job: -@group @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), @@ -9200,8 +9041,8 @@ Here is a rule set that will do the job: 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 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 @@ -9269,15 +9110,15 @@ variables, the default argument list will be @samp{(t x)}. We want to 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 )}. @@ -9287,7 +9128,7 @@ command like @kbd{n} to operate on the specified stack entry only, 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 @@ -9300,21 +9141,21 @@ algebraic entry, whichever way you prefer: Computing @c{$\displaystyle{\sin x \over x}$} @cite{sin(x) / x}: -Using the stack: @kbd{C-x ( RET S TAB / C-x )}. +Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. -Using algebraic entry: @kbd{C-x ( ' sin($)/$ RET 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 the stack: @kbd{C-x ( @key{TAB} B C-x )} -Using algebraic entry: @kbd{C-x ( ' log($,$$) RET 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.) @@ -9322,26 +9163,26 @@ Alternatively: @kbd{C-x ( ~ v x C-x )}. (The @kbd{~} key pops a 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 +@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 + 1 @key{RET} 20 Z < & 1 + Z > I H P @end group +@end smallexample @noindent This answer is quite accurate. @@ -9362,7 +9203,7 @@ Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @cite{n+1} 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 @@ -9382,15 +9223,15 @@ The trick here is to compute the harmonic numbers differently, so that the loop counter itself accumulates the sum of reciprocals. We use a separate variable to hold the integer counter. -@group @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 + 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 @@ -9401,16 +9242,16 @@ the for loop to use as the step value. The for loop will increase the ``loop counter'' by that amount and keep going until the loop counter exceeds 4. -@group @smallexample +@group 2: 31 3: 31 1: 3.99498713092 2: 3.99498713092 . 1: 4.02724519544 . - r 1 r 2 RET 31 & + -@end smallexample + 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. @@ -9430,95 +9271,95 @@ keystrokes without executing them. In the following diagrams we'll pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group @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 +' sin(cos(x))-0.5 @key{RET} 4.5 m r C-x ( Z ` @key{TAB} @key{RET} a d x @key{RET} -@end smallexample @end group +@end smallexample @noindent -@group @smallexample +@group 2: 4.5 1: x + (sin(cos(x)) - 0.5) / sin(x) cos(cos(x)) . - / ' x RET TAB - t 1 -@end smallexample + / ' 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 +@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 + 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 +@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 + @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 +@group 2: 5.26345856348 1: 0.499999999997 . - RET ' sin(cos($)) RET -@end smallexample + @key{RET} ' sin(cos($)) @key{RET} @end group +@end smallexample Let's test the new definition again: -@group @smallexample +@group 2: x^2 - 9 1: 3. 1: 1 . . - ' x^2-9 RET 1 X -@end smallexample + ' 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 / +@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 example @c [fix-ref Nesting and Fixed Points] It turns out that Calc has a built-in command for applying a formula @@ -9549,14 +9390,14 @@ keystrokes without executing them. In the following diagrams we'll pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group @smallexample +@group 1: 1. 1: 1. . . - 1.0 RET C-x ( Z ` s 1 0 t 2 -@end smallexample + 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. @@ -9566,86 +9407,86 @@ otherwise the calculation below will try to do exact fractional arithmetic, and will never converge because fractions compare equal only if they are exactly equal, not just equal to within the current precision.) -@group @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 + @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 +@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 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 +@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 ^ * / + 2 @key{RET} 40 Z ( @key{RET} k b @key{TAB} @key{RET} r 1 @key{TAB} ^ * / -@end smallexample @end group +@end smallexample @noindent -@group @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 + @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 +@group 2: -0.577215664892 2: -0.577215664892 1: 1. 1: -0.577215664901532 - 1. RET p 16 RET X -@end smallexample + 1. @key{RET} p 16 @key{RET} X @end group +@end smallexample Here's the complete sequence of keystrokes: -@group @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 example @node Programming Answer 10, Programming Answer 11, Programming Answer 9, Answers to Exercises @subsection Programming Tutorial Exercise 10 @@ -9665,83 +9506,83 @@ keystrokes without executing them. In the following diagrams we'll pretend Calc actually executed the keystrokes as you typed them, just for purposes of illustration.) -@group @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 + ' 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 +@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 + 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}. +have written instead, @kbd{r 1 @key{TAB} | t 1}. -@group @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 + 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 +@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 + 6 @key{RET} 1 + 0 @key{RET} 1 C-u v x -@end smallexample @end group +@end smallexample @noindent -@group @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 + ' 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 +@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 +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 @@ -9749,18 +9590,18 @@ C-x ( 1 + 0 RET 1 C-u v x ' x RET TAB V M ^ * C-x ) @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 +@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 + 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 @@ -9770,57 +9611,57 @@ to the form @cite{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}. (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 +@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 : + C-x ( M-2 @key{RET} a = Z [ @key{DEL} @key{DEL} 1 Z : -@end smallexample @end group +@end smallexample @noindent -@group @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 + @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 +@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 * - + M-@key{TAB} M-@key{TAB} @key{TAB} @key{RET} M-@key{TAB} z s * - -@end smallexample @end group +@end smallexample @noindent -@group @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 + 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 @@ -9828,19 +9669,19 @@ the right answers. 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 * - +@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 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 @@ -9859,7 +9700,7 @@ First, we store the rewrite rules corresponding to the definition of 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 ] @@ -9868,15 +9709,15 @@ C-c C-c Now, it's just a matter of applying the rules: -@group @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 + 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 @@ -9938,7 +9779,9 @@ still exists and is updated silently. @xref{Trail Commands}.@refill @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 @@ -9995,13 +9838,17 @@ window, @kbd{M-# o} switches you out of it. (The regular Emacs 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 @@ -10024,15 +9871,17 @@ The @kbd{M-# x} command also turns the Calculator off, no matter which 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. @@ -10209,7 +10058,7 @@ Bugs'' sections of the manual. @noindent @cindex Stack basics @c [fix-tut RPN Calculations and the Stack] -Calc uses RPN notation. If you are not familar with RPN, @pxref{RPN +Calc uses RPN notation. If you are not familiar with RPN, @pxref{RPN Tutorial}. To add the numbers 1 and 2 in Calc you would type the keys: @@ -10246,7 +10095,7 @@ argument, it instead moves the cursor to the specified stack element. 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 @@ -10290,7 +10139,7 @@ non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. 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 @@ -10350,7 +10199,7 @@ punctuation keys begin algebraic entry. Use this if you prefer typing 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 @@ -10390,12 +10239,12 @@ those three numbers onto the stack (leaving the 3 at the top), and @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.) +the variable @samp{pi}, but @kbd{' pi M-@key{RET}} pushes 3.1415.) -If you finish your algebraic entry by pressing @kbd{LFD} (or @kbd{C-j}) +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 @@ -10554,7 +10403,7 @@ information is cleared whenever you give any command that adds new undo 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 @@ -11085,7 +10934,9 @@ Many other operations are applied to vectors element-wise. For example, 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$} @@ -11107,8 +10958,8 @@ enter a string at any time by pressing the @kbd{"} key. Quotation marks and backslashes are written @samp{\"} and @samp{\\}, respectively, inside strings. Other notations introduced by backslashes are: -@group @example +@group \a 7 \^@@ 0 \b 8 \^a-z 1-26 \e 27 \^[ 27 @@ -11117,8 +10968,8 @@ inside strings. Other notations introduced by backslashes are: \r 13 \^^ 30 \t 9 \^_ 31 \^? 127 -@end example @end group +@end example @noindent Finally, a backslash followed by three octal digits produces any @@ -11142,7 +10993,9 @@ The only Calc feature that uses strings is @dfn{compositions}; @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} @@ -11159,7 +11012,9 @@ Characters below 32, and character 127, are shown using @samp{^} notation (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 @@ -11180,17 +11035,29 @@ use HMS as the angular mode so that calculated angles are expressed in 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 @@ -11250,7 +11117,7 @@ precision is 15, the seconds will keep three digits after the decimal point. Decreasing the precision below 12 may cause the time part of a date form to become inaccurate. This can also happen if astronomically high years are used, though this will not be an -issue in everyday (or even everymillenium) use. Note that date +issue in everyday (or even everymillennium) use. Note that date forms without times are stored as exact integers, so roundoff is never an issue for them. @@ -11339,10 +11206,10 @@ conversions. @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 @@ -11365,22 +11232,26 @@ are integers, this calculation is done much more efficiently than 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 @@ -11404,7 +11275,9 @@ Modulo forms cannot have variables or formulas for components. If you 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}}. @@ -11417,7 +11290,7 @@ The algebraic function @samp{makemod(a, m)} builds the modulo form @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$} @@ -11460,10 +11333,10 @@ Consult a good text on error analysis for a discussion of the proper use 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$} @@ -11481,7 +11354,9 @@ the small-error approximation underlying the error analysis. If the error 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} @@ -11502,7 +11377,9 @@ not a complex distribution around a real mean. 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}. @@ -11581,11 +11458,11 @@ contain zero inside them Calc is forced to give the result, 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 @@ -11596,7 +11473,9 @@ HMS forms or date forms. @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 @@ -11618,14 +11497,22 @@ error. @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 @@ -11915,8 +11802,8 @@ type, such as numbers, vectors, formulas, and incomplete objects.) @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} @@ -11932,7 +11819,7 @@ For example, with @samp{10 20 30} on the stack, @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} @@ -11942,7 +11829,7 @@ Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}} 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 @@ -11960,16 +11847,16 @@ For example, with @samp{10 20 30} on the stack, @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 @kbd{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 @kbd{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 @@ -11983,30 +11870,30 @@ For example, with @samp{10 20 30 40 50} on the stack, @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 +@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 @key{M-TAB} is in +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. @@ -12204,10 +12091,10 @@ another example, @kbd{K a s} simplifies a formula, pushing the 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 @@ -12381,7 +12268,7 @@ of the numbers involved. 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. @@ -12828,11 +12715,11 @@ the declaration, effectively ``undeclaring'' the variable.) 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 @@ -12854,13 +12741,13 @@ declaration you will have to edit the @code{Decls} matrix yourself. For example, the declaration matrix -@group @smallexample +@group [ [ foo, real ] [ [j, k, n], int ] [ f(1,2,3), [0 .. inf) ] ] -@end smallexample @end group +@end smallexample @noindent declares that @code{foo} represents a real number, @code{j}, @code{k} @@ -12886,13 +12773,13 @@ vector consisting of zero or more type symbols followed by zero or more intervals or numbers that represent the set of possible values for the variable. -@group @smallexample +@group [ [ a, [1, 2, 3, 4, 5] ] [ b, [1 .. 5] ] [ c, [int, 1 .. 5] ] ] -@end smallexample @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 @@ -12964,8 +12851,8 @@ this property, you could get Calc to recognize it by adding the row 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, @@ -13084,11 +12971,17 @@ do @samp{dint(n)} and @samp{dint(2 n - 3)} if @code{n} has been declared 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 @@ -13099,27 +12992,39 @@ data type functions also accept vectors or matrices composed of 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} @@ -13130,7 +13035,9 @@ expression like @cite{x > 0} to 1 or 0 using @code{dpos}, and that 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 @@ -13140,9 +13047,13 @@ deduced to be nonzero. It does not include error forms, since they 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 @@ -13150,7 +13061,9 @@ is known not to be even (because it is known to be odd or a non-integer). 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 @@ -13162,7 +13075,9 @@ etc., and a suitable set like @samp{[0 .. inf]} is returned. If 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 @@ -13192,20 +13107,20 @@ refresh the stack to leave the stack display alone. The word ``Dirty'' 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:: @@ -13825,7 +13740,7 @@ stack entries are displayed flush-right against the right edge of the 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 @@ -14196,31 +14111,57 @@ in Calc, @TeX{}, and @dfn{eqn} (described in the next section): @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 @@ -14290,67 +14231,67 @@ end of this section. @iftex Here are some examples of how various Calc formulas are formatted in @TeX{}: -@group @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 +@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 +@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 +@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 @@ -14359,15 +14300,14 @@ $$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$ $$ [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 @@ -14375,15 +14315,14 @@ $$ 2 + 3 \to 5 $$ $$ 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 @@ -14392,16 +14331,15 @@ $$ [{2 + 3 \to 5}, {{a \over 2} \to {b + c \over 2}}] $$ $$ [{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 @@ -14409,7 +14347,6 @@ $$ \matrix{ {a \over b} & 0 \cr 0 & 2^{(x + 1)} } $$ $$ \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 @@ -14598,14 +14535,14 @@ to @TeX{}'s ``boxes.'' Each multi-line composition has a decide how formulas should be positioned relative to one another. For example, in the Big mode formula -@group @example +@group 2 a + b 17 + ------ c -@end example @end group +@end example @noindent the second term of the sum is four lines tall and has line three as @@ -14665,7 +14602,9 @@ but the unnatural form @samp{a + (b + c)} keeps its parentheses. 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 @@ -14696,12 +14635,12 @@ structure of formulas. It will not break an ``inner'' formula if it can use an earlier break point from an ``outer'' formula instead. For example, a vector of sums might be formatted as: -@group @example +@group [ a + b + c, d + e + f, g + h + i, j + k + l, m ] -@end example @end group +@end example @noindent If the @samp{m} can fit, then so, it seems, could the @samp{g}. @@ -14729,19 +14668,21 @@ object. @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 +@group a b 17---d c -@end example @end group +@end example @noindent in Big language mode. This is actually one case of the general @@ -14771,7 +14712,9 @@ baselines of the component compositions, which are all aligned. @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 @@ -14779,16 +14722,18 @@ the result is by default the top line of the resulting composition. For example, @samp{f(cvert([a, bb, ccc]), cvert([a^2 + 1, b^2]))} formats in Big mode as -@group @example +@group f( a , 2 ) bb a + 1 ccc 2 b -@end example @end group +@end example -@c @starindex +@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 @@ -14797,19 +14742,23 @@ will be the same as the baseline of whatever component is enclosed in @code{cbase}. Thus @samp{f(cvert([a, cbase(bb), ccc]), cvert([a^2 + 1, cbase(b^2)]))} displays as -@group @example +@group 2 a + 1 a 2 f(bb , b ) ccc -@end example @end group +@end example -@c @starindex +@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 @@ -14817,15 +14766,15 @@ or bottom line (rather than the baseline) of that component. Thus @samp{cvert([cbase(a / b)]) + cvert([ctbase(a / b)]) + cvert([cbbase(a / b)])} gives -@group @example +@group a a - - + a + b b - b -@end example @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 @@ -14834,7 +14783,9 @@ which means the baseline is the top line of the following item, and @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{-} @@ -14844,31 +14795,35 @@ vector of exactly one character code. It is repeated to match the 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 +@group a + 1 ===== 2 b -@end example @end group +@end example -@c @starindex +@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 +@group a + a bb bb ccc ccc -@end example @end group +@end example Like @code{choriz}, the vertical compositions accept a second argument which gives the precedence to use when formatting the components. @@ -14878,7 +14833,9 @@ Vertical compositions do not support separator strings. @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 @@ -14886,7 +14843,9 @@ language mode. This is essentially a horizontal composition of @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 @@ -14894,7 +14853,9 @@ bottom line of @samp{a} (note that this is not quite analogous to @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 @@ -14902,7 +14863,9 @@ or Big. It has no effect in other language modes. For example, @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(" ")}. @@ -14912,17 +14875,19 @@ looks like @samp{abababab}. If the second argument is not a string, it is formatted in the normal way and then several copies of that are composed together: @samp{cspace(4, a^2)} yields -@group @example +@group 2 2 2 2 a a a a -@end example @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 @@ -14930,9 +14895,13 @@ baseline is the center line of the resulting stack. A numerical 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 @@ -14940,8 +14909,8 @@ of the top or bottom copy, respectively, of the second argument. Thus @samp{cvspace(2, a/b) + ctspace(2, a/b) + cbspace(2, a/b)} displays as: -@group @example +@group a - a b @@ -14951,8 +14920,8 @@ a b b - a b - b -@end example @end group +@end example @node Information about Compositions, User-Defined Compositions, Other Compositions, Compositions @subsubsection Information about Compositions @@ -14962,7 +14931,9 @@ The functions in this section are actual functions; they compose their 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 @@ -14970,14 +14941,20 @@ composition. For example, @samp{cwidth(a + b)} is 5, and @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 @@ -15027,23 +15004,23 @@ mode will be removed. The function will revert to its standard format. For example, the default format for the binomial coefficient function @samp{choose(n, m)} in the Big language mode is -@group @example +@group n ( ) m -@end example @end group +@end example @noindent You might prefer the notation, -@group @example +@group C n m -@end example @end group +@end example @noindent To define this notation, first make sure you are in Big mode, @@ -15061,12 +15038,12 @@ of @samp{(C m n)}. Edit this list to be @samp{(n m)} and press off with @kbd{m O} and enter @samp{choose(a,b) + choose(7,3)} as an algebraic entry. -@group @example +@group C + C a b 7 3 -@end example @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 @@ -15382,10 +15359,10 @@ foo ( @{ @{ # @}*, @}*; ) := matrix(#1) @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 @@ -15413,7 +15390,7 @@ empty vector is produced. 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 @@ -15542,7 +15519,7 @@ on the current mode settings. @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.) @@ -15596,8 +15573,8 @@ Command is @kbd{m p}. @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}), @@ -15609,13 +15586,13 @@ Infinite mode. Default is @i{-1} (off). Value is 1 if the mode is on, 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 @@ -15874,7 +15851,9 @@ interpret a prefix argument. @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 @@ -15938,7 +15917,9 @@ infinite in different directions the result is @code{nan}. @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 @@ -15947,7 +15928,9 @@ available for @kbd{+} are available for @kbd{-} as well. @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 @@ -15970,7 +15953,9 @@ whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @samp{[0 ..@: 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 @@ -15996,7 +15981,9 @@ interval. @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 @@ -16008,13 +15995,15 @@ the result is also an error (or interval or modulo) form. @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 @@ -16025,7 +16014,9 @@ operation when the arguments are integers, it avoids problems that @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 @@ -16203,7 +16194,9 @@ expressed as an integer-valued floating-point number. @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 @@ -16214,7 +16207,9 @@ infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces @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 @@ -16224,7 +16219,9 @@ command truncates toward positive infinity. Thus @kbd{3.6 I F} produces @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, @@ -16236,7 +16233,9 @@ but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill @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'' @@ -16250,13 +16249,21 @@ these functions operate on all elements of the vector one by one. 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} @@ -16284,7 +16291,7 @@ no second argument at all. @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), @@ -16311,8 +16318,8 @@ this command replaces each element by its complex conjugate. 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 @@ -16338,16 +16345,20 @@ The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number 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 -the the stack into a composite object such as a complex number. With +the stack into a composite object such as a complex number. With a prefix argument of @i{-1}, it produces a rectangular complex number; 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 @@ -16613,7 +16624,7 @@ The @kbd{t U} (@code{calc-unix-time}) [@code{unixtime}] command 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 @@ -16747,7 +16758,9 @@ to preserve the time-of-day portion of the input (@code{newweek} resets 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 @@ -16775,7 +16788,9 @@ Because of this, @kbd{t I t I} and @kbd{M-2 t I} do not always give the same results (@samp{} versus @samp{} 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 @@ -16927,7 +16942,9 @@ completely consistent though; a subtraction followed by an addition 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 @@ -16966,7 +16983,9 @@ computes the actual number of 24-hour periods between two dates, whereas 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 @@ -16991,8 +17010,8 @@ note that for each time zone there is one name for standard time, another for daylight savings time, and a third for ``generalized'' time in which the daylight savings adjustment is computed from context. -@group @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 @@ -17001,8 +17020,8 @@ YDT PDT MDT CDT EDT ADT NDT BST WETDST METDST MESZ 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 smallexample @vindex math-tzone-names To define time zone names that do not appear in the above table, @@ -17011,13 +17030,13 @@ is a list of lists describing the different time zone names; its structure is best explained by an example. The three entries for Pacific Time look like this: -@group @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 smallexample @cindex @code{TimeZone} variable @vindex TimeZone @@ -17142,7 +17161,7 @@ falls in this hour results in a time value for the following hour, from 3 a.m.@: to 4 a.m. At the end of daylight savings time, the hour from 1 a.m.@: to 2 a.m.@: repeats itself; converting a date/time form that falls in in this hour results in a time value for the first -manifestion of that time (@emph{not} the one that occurs one hour later). +manifestation of that time (@emph{not} the one that occurs one hour later). If @code{math-daylight-savings-hook} is @code{nil}, then the daylight savings adjustment is always taken to be zero. @@ -17159,7 +17178,9 @@ that the daylight-savings computation is always done in 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 @@ -17235,7 +17256,7 @@ but the number @samp{5.4} is probably @emph{not} suitable---it 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 % @@ -17249,7 +17270,7 @@ this number to @samp{0.08%}.) The @kbd{=} key is a convenient way 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 % @@ -17257,13 +17278,13 @@ use @kbd{/ c %}. For example, @w{@kbd{17 RET 68 / c %}} displays @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 @@ -17293,7 +17314,7 @@ earning 5.4% interest, starting right now. How much will be 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 @@ -17548,18 +17569,18 @@ return value will as usual be zero if @var{period} is out of range. 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 +@group [ [ 2000, 3333, 4800 ] [ 2000, 2667, 2880 ] [ 2000, 2000, 1728 ] [ 2000, 1333, 592 ] [ 2000, 667, 0 ] ] -@end example @end group +@end example @noindent (Values have been rounded to nearest integers in this figure.) @@ -17846,11 +17867,17 @@ Bits shifted ``off the end,'' according to the current word size, are lost. @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 @@ -17902,7 +17929,7 @@ bits in a binary integer. 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. @@ -17931,7 +17958,7 @@ flag keys must be used to get some of these functions from the keyboard. @cindex @code{phi} variable @cindex Phi, golden ratio @cindex Golden ratio -One miscellanous command is shift-@kbd{P} (@code{calc-pi}), which pushes +One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes the value of @c{$\pi$} @cite{pi} (at the current precision) onto the stack. With the Hyperbolic flag, it pushes the value @cite{e}, the base of natural logarithms. @@ -17944,8 +17971,12 @@ In Symbolic mode, these commands push the 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; @@ -17973,7 +18004,9 @@ interpret a prefix argument. @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 @@ -17983,7 +18016,9 @@ this is redundant with the @kbd{E} command. @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. @@ -17995,9 +18030,13 @@ the @code{calc-ln} command. @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}], @@ -18109,40 +18148,68 @@ Hyperbolic and Inverse flags, it computes the hyperbolic arcsine @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}] @@ -18164,10 +18231,16 @@ which @code{arctan2} would avoid. By (arbitrary) definition, @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 @@ -18205,18 +18278,30 @@ integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$} @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 @@ -18477,11 +18562,11 @@ of one. The algorithm used generates random numbers in pairs; thus, 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, @@ -18691,7 +18776,9 @@ the GCD of two integers @cite{x} and @cite{y} and returns a vector @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 @@ -18706,7 +18793,9 @@ the commands in this section.@refill @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, @@ -18792,7 +18881,9 @@ even a single iteration is quite reliable.) After the @kbd{k p} command, 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 @@ -18816,7 +18907,9 @@ element of the list will be @i{-1}. For inputs @i{-1}, @i{0}, and @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 @@ -18832,7 +18925,9 @@ prime. @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. @@ -18903,9 +18998,13 @@ recover the original arguments but substitute a new value for @cite{x}.) @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$} @@ -18915,9 +19014,13 @@ correct if its chi-square statistic is @cite{x}. @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$} @@ -18929,9 +19032,13 @@ respectively, used in computing the statistic @cite{F}. @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$} @@ -18942,9 +19049,13 @@ exceed @cite{x}. @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 @@ -18953,9 +19064,13 @@ Poisson random events will occur. @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$} @@ -19129,7 +19244,9 @@ example, @samp{[2, 3, -4]} takes 12 objects and creates a 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 @@ -19188,7 +19305,9 @@ re-packing mode will be a vector of length 2. This might be used 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 @@ -19197,7 +19316,9 @@ a vector of components. Here the @var{mode} must be an 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 @@ -19223,7 +19344,9 @@ subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.@refill @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 @@ -19250,7 +19373,7 @@ See also @code{cons} and @code{rcons} below. @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 @@ -19345,13 +19468,21 @@ whereas @code{cons} will insert @var{h} at the front of the vector @var{t}. @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 @@ -19577,7 +19708,9 @@ phone numbers will remain sorted by name even after the second sort. @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 @@ -19679,10 +19812,14 @@ vectors or matrices: @code{change-sign}, @code{conj}, @code{arg}, 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 @@ -19718,10 +19855,14 @@ The @kbd{V C} (@code{calc-cross}) [@code{cross}] command computes the 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 @@ -19773,7 +19914,7 @@ the integer 4 and the float 4.0 are considered equal even though they are not ``identical.'' Variables are treated like plain symbols without attached values by the set operations; subtracting the set @samp{[b]} from @samp{[a, b]} always yields the set @samp{[a]} even though if -the variables @samp{a} and @samp{b} both equalled 17, you might +the variables @samp{a} and @samp{b} both equaled 17, you might expect the answer @samp{[]}. If a set contains interval forms, then it is assumed to be a set of @@ -20064,7 +20205,7 @@ has an infinite weight, next to which an error form with a finite 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. @@ -20132,7 +20273,7 @@ $$ { N \over \displaystyle \sum {1 \over x_i} } $$ @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 @@ -20219,7 +20360,9 @@ is the square@c{ $\sigma^2$} 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 @@ -20339,7 +20482,7 @@ Calc will prompt for the number of arguments the function takes if it 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; @@ -20377,9 +20520,9 @@ which means ``a function of two arguments that computes the first 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{}. When you type @kbd{V A ' $$ + 2$^$$ RET}, +colon: @samp{}. 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{}}. In both cases, Calc also writes the nameless function to the Trail so that you can get it back later if you wish. @@ -20395,11 +20538,13 @@ the stack and use it with @w{@kbd{V A $}}. Calc will not prompt for an 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{} is @samp{lambda(x, y, x + y)}. (The word @code{lambda} derives from Lisp notation and the theory of @@ -20416,17 +20561,29 @@ called.) @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 @@ -20437,7 +20594,9 @@ written as algebraic symbols have the names @code{add}, @code{sub}, @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 @@ -20671,7 +20830,7 @@ Newton's method for finding roots is a classic example of iteration 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}. @@ -20784,37 +20943,37 @@ enables commas or semicolons at the ends of all rows but the last. The default format is @samp{RO}. (Before Calc 2.00, the format was fixed at @samp{ROC}.) Here are some example matrices: -@group @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 +@end example @noindent -@group @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 +@end example @noindent -@group @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 example @noindent Note that of the formats shown here, @samp{RO}, @samp{ROC}, and @@ -20946,28 +21105,28 @@ all of the rest of the formula with dots. Selection works in any display mode but is perhaps easiest in ``big'' (@kbd{d B}) mode. Suppose you enter the following formula: -@group @smallexample +@group 3 ___ (a + b) + V c 1: --------------- 2 x + 1 -@end smallexample @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 +@group . ... .. . b. . . . 1* ............... . . . . -@end smallexample @end group +@end smallexample @noindent Every character not part of the sub-formula @samp{b} has been changed @@ -20980,19 +21139,19 @@ may not be visible. @pxref{Embedded Mode}.) 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 +@group . ... (a + b) . . . 1* ............... . . . . -@end smallexample @end group +@end smallexample @noindent The portion selected is always large enough to be considered a complete formula all by itself, so selecting the parenthesis selects the whole -formula that it encloses. Putting the cursor on the the @samp{+} sign +formula that it encloses. Putting the cursor on the @samp{+} sign would have had the same effect. (Strictly speaking, the Emacs cursor is really the manifestation of @@ -21098,14 +21257,14 @@ Once you have selected a sub-formula, you can expand it using the @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 +@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 smallexample @noindent In the last example, the entire formula is selected. This is roughly @@ -21189,14 +21348,14 @@ illustrated in the above examples; if we press @kbd{j d} we switch to the other style in which the selected portion itself is obscured by @samp{#} signs: -@group @smallexample +@group 3 ... # ___ (a + b) . . . ## # ## + V c 1* ............... 1* --------------- . . . . 2 x + 1 -@end smallexample @end group +@end smallexample @node Operating on Selections, Rearranging with Selections, Displaying Selections, Selecting Subformulas @subsection Operating on Selections @@ -21228,8 +21387,8 @@ the top two stack elements; here it swaps the value you entered into the selected portion of the formula, returning the old selected portion to the top of the stack. -@group @smallexample +@group 3 ... ... ___ (a + b) . . . 17 x y . . . 17 x y + V c 2* ............... 2* ............. 2: ------------- @@ -21237,8 +21396,8 @@ portion to the top of the stack. 3 3 1: 17 x y 1: (a + b) 1: (a + b) -@end smallexample @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 @@ -21271,14 +21430,14 @@ the sub-formula with the constant zero, but in a few suitable contexts it uses the constant one instead. The @key{DEL} key automatically deselects and re-simplifies the entire formula afterwards. Thus: -@group @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 smallexample In this example, we first delete the @samp{sqrt(c)} term; Calc accomplishes this by replacing @samp{sqrt(c)} with zero and @@ -21290,7 +21449,7 @@ If you select an element of a vector and press @key{DEL}, that 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 @@ -21298,7 +21457,7 @@ The @kbd{j @key{DEL}} (@code{calc-del-selection}) command is like 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.) @@ -21308,14 +21467,14 @@ select the denominator, press @kbd{5 -} to subtract five from the denominator, press @kbd{n} to negate the denominator, then press @kbd{Q} to take the square root. -@group @smallexample +@group .. . .. . .. . .. . 1* ....... 1* ....... 1* ....... 1* .......... 2 x + 1 2 x - 4 4 - 2 x _________ V 4 - 2 x -@end smallexample @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 @@ -21330,14 +21489,14 @@ in an ``un-natural'' state. Consider negating the @samp{2 x} term of our sample formula by selecting it and pressing @kbd{n} (@code{calc-change-sign}).@refill -@group @smallexample +@group .. . .. . 1* .......... 1* ........... ......... .......... . . . 2 x . . . -2 x -@end smallexample @end group +@end smallexample Unselecting the sub-formula reveals that the minus sign, which would normally have cancelled out with the subtraction automatically, has @@ -21346,14 +21505,14 @@ selected portion. Pressing @kbd{=} (@code{calc-evaluate}) or doing any other mathematical operation on the whole formula will cause it to be simplified. -@group @smallexample +@group 17 y 17 y 1: ----------- 1: ---------- __________ _________ V 4 - -2 x V 4 + 2 x -@end smallexample @end group +@end smallexample @node Rearranging with Selections, , Operating on Selections, Selecting Subformulas @subsection Rearranging Formulas using Selections @@ -21366,7 +21525,7 @@ sub-formula to the right in its surrounding formula. Generally the 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. @@ -21426,7 +21585,7 @@ The @kbd{j D} command is implemented using rewrite rules. @xref{Selections with Rewrite Rules}. The rules are stored in the Calc variable @code{DistribRules}. A convenient way to view these rules is to use @kbd{s e} (@code{calc-edit-variable}) which -displays and edits the stored value of a variable. Press @key{M-# M-#} +displays and edits the stored value of a variable. Press @kbd{M-# M-#} to return from editing mode; be careful not to make any actual changes or else you will affect the behavior of future @kbd{j D} commands! @@ -22102,8 +22261,8 @@ for any @cite{x}. This occurs even if you have stored a different 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 @@ -22342,7 +22501,9 @@ as is @cite{x^2 >= 0} if @cite{x} is known to be real. @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} @@ -22539,10 +22700,16 @@ found, and polynomials in more than one variable are not treated. 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 @@ -22660,7 +22827,7 @@ The remainder from the division, if any, is reported at the bottom 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. @@ -22889,7 +23056,9 @@ to use your rule; integral tables generally give rules for 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 @@ -23125,9 +23294,13 @@ happens for both @kbd{a S} and @kbd{H a S}. @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 @@ -23193,7 +23366,7 @@ list of numerical roots, however, provided that symbolic mode (@kbd{m s}) is not turned on. (If you work with symbolic mode on, recall that the @kbd{N} (@code{calc-eval-num}) key is a handy way to reevaluate the formula on the stack with symbolic mode temporarily off.) Naturally, -@kbd{a P} can only provide numerical roots if the polynomial coefficents +@kbd{a P} can only provide numerical roots if the polynomial coefficients are all numbers (real or complex). @node Solving Systems of Equations, Decomposing Polynomials, Multiple Solutions, Solving Equations @@ -23227,7 +23400,9 @@ equations toward the front of the list. Calc's algorithm will 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 @@ -23265,7 +23440,9 @@ to satisfy the equations. @xref{Curve Fitting}. @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 @@ -23288,7 +23465,9 @@ use @samp{vlen(poly(p, x)) - 1}. For example, @samp{poly((x+1)^4, x)} 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 @@ -23339,7 +23518,9 @@ can handle quartics and smaller polynomials, so it calls @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 @@ -23354,7 +23535,9 @@ that @code{pdeg(c) = pdeg(c,x) = 0} for any nonzero constant @code{c}; 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))}, @@ -23362,7 +23545,9 @@ though again more efficient. In particular, @samp{plead((2x+1)^10, x)} 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. @@ -23385,7 +23570,9 @@ denominators, as well as dividing by any common content in the 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} @@ -23507,7 +23694,7 @@ to @kbd{a R} (@code{calc-find-root}): You give the formula and an initial guess on the stack, and are prompted for the name of a variable. The guess may be either a number near the desired minimum, or an interval enclosing the desired minimum. The function returns a vector containing the -value of the the variable which minimizes the formula's value, along +value of the variable which minimizes the formula's value, along with the minimum value itself. Note that this command looks for a @emph{local} minimum. Many functions @@ -23535,9 +23722,13 @@ variable can only be determined meaningfully to about six digits. Thus 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 @@ -23657,12 +23848,12 @@ name only those and let the parameters use default names. For example, suppose the data matrix @ifinfo -@group @example +@group [ [ 1, 2, 3, 4, 5 ] [ 5, 7, 9, 11, 13 ] ] -@end example @end group +@end example @end ifinfo @tex \turnoffactive @@ -23676,7 +23867,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 @@ -23692,8 +23883,8 @@ than pick them out of the formula. (You can type @kbd{t y} 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 @@ -23708,14 +23899,14 @@ The result is: 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 @@ -23750,13 +23941,13 @@ formula in place of @cite{a + b x_i}. @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. @@ -23769,7 +23960,7 @@ To fit the data to higher-order polynomials, just type one of the 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 @@ -23793,8 +23984,8 @@ line slightly to improve the fit. @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: @@ -23833,16 +24024,16 @@ is linear or multilinear by counting the rows in the data matrix.) Given the data matrix, -@group @example +@group [ [ 1, 2, 3, 4, 5 ] [ 7, 2, 3, 5, 2 ] [ 14.5, 15, 18.5, 22.5, 24 ] ] -@end example @end group +@end example @noindent -the command @kbd{a F 1 RET} will call the first row @cite{x} and the +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}. @@ -23899,8 +24090,8 @@ contain error forms. The data values must either all include errors 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, @@ -23941,7 +24132,7 @@ is simply scaled uniformly by @c{$1 / \sigma^2$} where it has a minimum). But there @emph{will} be a difference in the estimated errors of the coefficients reported by @kbd{H a F}. -Consult any text on statistical modelling of data for a discussion +Consult any text on statistical modeling of data for a discussion of where these error estimates come from and how they should be interpreted. @@ -23969,7 +24160,7 @@ will have length @cite{M = d+1} with the constant term first. @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. @@ -24264,7 +24455,7 @@ manually by doing a series of fits. You can compare the fits by 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. @@ -24380,19 +24571,37 @@ a special @kbd{s F} command just for editing @code{FitRules}. @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 @@ -24404,11 +24613,11 @@ to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable 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 +@group fitmodel(fitvar(2) = fitparam(1) fitvar(1)^fitparam(2)) -@end smallexample @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 @@ -24432,13 +24641,13 @@ parameters (the length of the @var{abc} vector), this is not required. The power law model eventually boils down to -@group @smallexample +@group fitsystem(ln(fitvar(2)), [1, ln(fitvar(1))], [exp(fitdummy(1)), fitdummy(2)]) -@end smallexample @end group +@end smallexample The actual implementation of @code{FitRules} is complicated; it proceeds in four phases. First, common rearrangements are done @@ -24488,11 +24697,19 @@ removes the fourth @var{model} argument (which by now will be zero) 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 @@ -24609,7 +24826,7 @@ name of the summation index variable, the lower limit of the 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 @@ -24623,11 +24840,11 @@ in Calc because @code{i} has the imaginary constant @cite{(0, 1)} 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 @@ -24819,29 +25036,49 @@ distinct numbers. @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 @@ -24904,9 +25141,13 @@ number. @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}] @@ -24944,7 +25185,9 @@ plain number, @cite{a} must be numerically equal to @cite{b}. @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, @@ -24971,11 +25214,17 @@ the result will be one of the following numbers: 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 @@ -24993,7 +25242,9 @@ is true because @samp{floor(x)} is provably integer-valued, but @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 @@ -25002,7 +25253,9 @@ even if its arguments are still in symbolic form. The only case where @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}, @@ -25013,14 +25266,18 @@ be stored in a formula if the default simplifications are turned off 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 @@ -25028,13 +25285,21 @@ actually returns zero. However, since Calc's condition-testing 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} @@ -25072,7 +25337,9 @@ first two cases but not the third. Also, neither @code{lin} nor @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. @@ -25151,13 +25418,13 @@ in several ways: @enumerate @item -With a rule: @kbd{f(x) := g(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)] RET}. +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, @@ -25359,7 +25626,7 @@ pattern will check all pairs of terms for possible matches. The rewrite 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. @@ -25666,7 +25933,9 @@ Here is a complete list of these markers. First are listed the 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 @@ -25693,7 +25962,9 @@ The special functions allowed in patterns are: @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 @@ -25705,7 +25976,9 @@ The rewrite may produce either @samp{g(12)} or @samp{g(12.0)} 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 @@ -25717,7 +25990,9 @@ as well, you must enclose them with more @code{plain} markers: @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 @@ -25729,7 +26004,7 @@ binding one summand to @cite{x} and the other to @cite{y}, and it matches anything else by binding the whole expression to @cite{x} and zero to @cite{y}. The other operators above work similarly.@refill -For general miscellanous functions, the default value @code{def} +For general miscellaneous functions, the default value @code{def} must be specified. Optional arguments are dropped starting with the rightmost one during matching. For example, the pattern @samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)}, @@ -25740,14 +26015,18 @@ case, @emph{not} the value that matched the meta-variable @cite{b}. 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 @@ -25755,21 +26034,27 @@ pattern @cite{y}. It is the same as @samp{x &&& y}. @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 @@ -25779,14 +26064,18 @@ length can also be matched as actual vectors: The rule 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 @@ -25832,7 +26121,9 @@ or enter the rule as @samp{apply(f, [x]) := apply(f, [x+1]) @w{:: 1}}. @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}. @@ -25880,7 +26171,9 @@ is converted to a function call. Once again, note that @code{apply} 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 @@ -25891,13 +26184,17 @@ with default simplifications off will be converted to @samp{[2+3]}, 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. @@ -25910,7 +26207,9 @@ There are also some special functions you can use in conditions. @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 @@ -25957,7 +26256,9 @@ the coefficients @code{a} and @code{b} for use elsewhere in the rule. 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 @@ -26010,7 +26311,9 @@ be added to the rule set and will continue to operate even if @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 @@ -26047,7 +26350,9 @@ This does the same thing, but is arguably simpler than, the rule f(a +/- b, a +/- b) := g(a +/- b) @end example -@c @starindex +@ignore +@starindex +@end ignore @tindex ends Here's another interesting example: @@ -26076,7 +26381,9 @@ The pattern @samp{@var{p1} ||| @var{p2}} matches anything that 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 @@ -26179,7 +26486,7 @@ f(!!!a, a) := g(a) will be careful to bind @samp{a} to the second argument of @code{f} before testing the first argument. If Calc had tried to match the first argument of @code{f} first, the results would have been -disasterous: Since @code{a} was unbound so far, the pattern @samp{a} +disastrous: since @code{a} was unbound so far, the pattern @samp{a} would have matched anything at all, and the pattern @samp{!!!a} therefore would @emph{not} have matched anything at all! @@ -26226,8 +26533,12 @@ In particular, @kbd{M-1 a r} applies only one rewrite at a time, 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 @@ -26272,7 +26583,9 @@ During each phase, certain rules will be enabled while certain others 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 @@ -26286,8 +26599,8 @@ If you do not explicitly schedule the phases, Calc sorts all phase numbers that appear in the rule set and executes the phases in ascending order. For example, the rule set -@group @example +@group [ f0(x) := g0(x), phase(1), f1(x) := g1(x), @@ -26297,8 +26610,8 @@ ascending order. For example, the rule set f3(x) := g3(x), phase(1,2), f4(x) := g4(x) ] -@end example @end group +@end example @noindent has three phases, 1 through 3. Phase 1 consists of the @code{f0}, @@ -26323,7 +26636,9 @@ way down to the parts, then goes back to the top and works down again. 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. @@ -26486,14 +26801,18 @@ all the positive vector elements. 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 @@ -26518,12 +26837,12 @@ to @samp{sin(b) cos(a) + cos(b) sin(a)} wherever it appears, and similarly for @samp{cos(a + b)}. The corresponding rewrite rule set would be, -@group @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 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 @@ -26637,11 +26956,16 @@ particularly true of rules where the top-level call is a commonly used 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 @@ -26713,7 +27037,7 @@ This will simplify the formula whenever @cite{b} and/or @cite{c} can be made simpler by squaring. For example, applying this rule to @samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming Symbolic Mode has been enabled to keep the square root from being -evaulated to a floating-point approximation). This rule is also +evaluated to a floating-point approximation). This rule is also useful when working with symbolic complex numbers, e.g., @samp{(a + b i) / (c + d i)}. @@ -26725,7 +27049,7 @@ to apply these rules repeatedly. After six applications, @kbd{a r} will 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 @@ -26826,7 +27150,9 @@ to hit the apostrophe key every time you wish to enter units. @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 @@ -26907,7 +27233,7 @@ If the value on the stack does not contain any units, @kbd{u c} will 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 @@ -27252,21 +27578,37 @@ for trail and time/date commands.) @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 @@ -27296,8 +27638,8 @@ useful if matrix multiplication is involved. Actually, all the arithmetic stores use formulas designed to behave usefully both forwards and backwards: -@group @example +@group s + v := v + a v := a + v s - v := v - a v := a - v s * v := v * a v := a * v @@ -27308,8 +27650,8 @@ s n v := v / (-1) v := (-1) / v 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 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 @@ -27435,7 +27777,7 @@ value of a variable without ever putting that value on the stack or simplifying or evaluating the value. It prompts for the name of the variable to edit. If the variable has no stored value, the editing buffer will start out empty. If the editing buffer is -empty when you press @key{M-# M-#} to finish, the variable will +empty when you press @kbd{M-# M-#} to finish, the variable will be made void. @xref{Editing Stack Entries}, for a general description of editing. @@ -27452,27 +27794,49 @@ as a side effect of putting the value on the stack. @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 @@ -27526,7 +27890,7 @@ names rather than prompting for the variable name. @pindex calc-permanent-variable @cindex Storing variables @cindex Permanent variables -@cindex @file{.emacs} file, veriables +@cindex @file{.emacs} file, variables The @kbd{s p} (@code{calc-permanent-variable}) command saves a variable's value permanently in your @file{.emacs} file, so that its value will still be available in future Emacs sessions. You can @@ -27585,8 +27949,8 @@ a vector of equations or assignments, in which case the default will be 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 @@ -27689,19 +28053,19 @@ to that variable. But this change is temporary in the sense that the next command that causes Calc to look at those stack entries will make them revert to the old variable value. -@group @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 + 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. @@ -27788,7 +28152,9 @@ Calc guesses at a reasonable number of data points to use. See the @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 @@ -27875,7 +28241,9 @@ order; the first takes on values from ``x'' and the second takes on 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 @@ -28214,7 +28582,7 @@ altogether. If there are more curves than elements in the vector, the 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 @@ -28275,7 +28643,7 @@ the output file used by GNUPLOT. For some devices, notably @code{x11}, 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. @@ -28376,7 +28744,7 @@ you have to add them to the @samp{*Gnuplot Commands*} buffer 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 @@ -28731,8 +29099,8 @@ original buffer. @node Keypad Main Menu, Keypad Functions Menu, Keypad Mode, Keypad Mode @section Main Menu -@group @smallexample +@group |----+-----Calc 2.00-----+----1 |FLR |CEIL|RND |TRNC|CLN2|FLT | |----+----+----+----+----+----| @@ -28750,8 +29118,8 @@ original buffer. |-----+-----+-----+-----+-----| | OFF | 0 | . | PI | + | |-----+-----+-----+-----+-----+ -@end smallexample @end group +@end smallexample @noindent This is the menu that appears the first time you start Keypad Mode. @@ -28780,7 +29148,7 @@ duplicates the top entry on the stack. 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 <-} @@ -28862,8 +29230,8 @@ command line that started Emacs), then @kbd{OFF} is replaced with @node Keypad Functions Menu, Keypad Binary Menu, Keypad Main Menu, Keypad Mode @section Functions Menu -@group @smallexample +@group |----+----+----+----+----+----2 |IGAM|BETA|IBET|ERF |BESJ|BESY| |----+----+----+----+----+----| @@ -28871,8 +29239,8 @@ command line that started Emacs), then @kbd{OFF} is replaced with |----+----+----+----+----+----| |GCD |FACT|DFCT|BNOM|PERM|NXTP| |----+----+----+----+----+----| -@end smallexample @end group +@end smallexample @noindent This menu provides various operations from the @kbd{f} and @kbd{k} @@ -28904,8 +29272,8 @@ finds the previous prime. @node Keypad Binary Menu, Keypad Vectors Menu, Keypad Functions Menu, Keypad Mode @section Binary Menu -@group @smallexample +@group |----+----+----+----+----+----3 |AND | OR |XOR |NOT |LSH |RSH | |----+----+----+----+----+----| @@ -28913,8 +29281,8 @@ finds the previous prime. |----+----+----+----+----+----| | A | B | C | D | E | F | |----+----+----+----+----+----| -@end smallexample @end group +@end smallexample @noindent The keys in this menu perform operations on binary integers. @@ -28937,8 +29305,8 @@ The initial word size is 32 bits. @node Keypad Vectors Menu, Keypad Modes Menu, Keypad Binary Menu, Keypad Mode @section Vectors Menu -@group @smallexample +@group |----+----+----+----+----+----4 |SUM |PROD|MAX |MAP*|MAP^|MAP$| |----+----+----+----+----+----| @@ -28946,8 +29314,8 @@ The initial word size is 32 bits. |----+----+----+----+----+----| |PACK|UNPK|INDX|BLD |LEN |... | |----+----+----+----+----+----| -@end smallexample @end group +@end smallexample @noindent The keys in this menu operate on vectors and matrices. @@ -29019,8 +29387,8 @@ With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode @section Modes Menu -@group @smallexample +@group |----+----+----+----+----+----5 |FLT |FIX |SCI |ENG |GRP | | |----+----+----+----+----+----| @@ -29028,8 +29396,8 @@ With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the |----+----+----+----+----+----| |SWAP|RLL3|RLL4|OVER|STO |RCL | |----+----+----+----+----+----| -@end smallexample @end group +@end smallexample @noindent The keys in this menu manipulate modes, variables, and the stack. @@ -29207,7 +29575,7 @@ We define $F_n = F_(n-1)+F_(n-2)$ for all $2 < n$. 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$. @@ -29378,11 +29746,11 @@ The derivative of @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 @@ -29487,13 +29855,13 @@ foo + 7 => foo + 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 @pindex calc-embedded-select The @kbd{M-# j} (@code{calc-embedded-select}) command provides an -easy way to operate on assigments. It is just like @kbd{M-# e}, +easy way to operate on assignments. It is just like @kbd{M-# e}, except that if the enabled formula is an assignment, it uses @kbd{j 2} to select the righthand side. If the enabled formula is an evaluates-to, it uses @kbd{j 1} to select the lefthand side. @@ -30152,7 +30520,7 @@ the definition stored on the key, or, to cancel the edit, type 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 @@ -30160,8 +30528,8 @@ notations @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, @code{DEL}, and 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 @@ -30899,9 +31267,9 @@ buffer if necessary, say, because the command was invoked from inside 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 @@ -31202,7 +31570,9 @@ These programs make use of some of the Calculator's internal functions; @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} @@ -31242,10 +31612,10 @@ recall that Calc stores integers in decimal form so bit shifts must 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)) @@ -31284,7 +31654,9 @@ same thing with a single division by 512. @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$} @@ -31351,7 +31723,7 @@ The strategy is to ensure that @cite{x} is nonnegative before calling to a suitable range, namely, plus-or-minus @c{$\pi \over 4$} @cite{pi/4}. Note that each test, and particularly the first comparison against 7, is designed so -that small roundoff errors cannnot produce an infinite loop. (Suppose +that small roundoff errors cannot produce an infinite loop. (Suppose we compared with @samp{(two-pi)} instead; if due to roundoff problems the modulo operator ever returned @samp{(two-pi)} exactly, an infinite recursion could result!) We use modulo only for arguments that will @@ -31526,7 +31898,7 @@ treat them as ``black box'' objects with no important internal structure. There is also a @code{rawnum} symbol, which is a combination of -@code{raw} (returning a raw Calc object) and @code{num} (signalling +@code{raw} (returning a raw Calc object) and @code{num} (signaling an error if that object is not a constant). You can pass a raw Calc object to @code{calc-eval} in place of a @@ -32830,7 +33202,7 @@ form; this is really just a special case of @code{reject-arg}. @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 @@ -33580,7 +33952,7 @@ command uses this when only one stack entry is being edited. @defun format-value a width Convert the Calc number or formula @var{a} to string form, using the -format seen in the stack buffer. Beware the the string returned may +format seen in the stack buffer. Beware the string returned may not be re-readable by @code{read-expr}, for example, because of digit grouping. Multi-line objects like matrices produce strings that contain newline characters to separate the lines. The @var{w} @@ -33831,12 +34203,12 @@ at Stanford University) as well as the @file{texindex} program and @file{texinfo.tex} file, both of which can be obtained from the FSF as part of the @code{texinfo} package.@refill -To print the Calc manual in one huge 550 page tome, you will need the +To print the Calc manual in one huge 470 page tome, you will need the source code to this manual, @file{calc.texi}, available as part of the -Emacs source. Once you have this file, type @samp{tex calc.texi} -twice. (Running the manual through @TeX{} twice is necessary so that -references to later parts of the manual will have correct page -numbers. (Don't worry if you get some ``overfull box'' warnings.) +Emacs source. Once you have this file, type @kbd{texi2dvi calc.texi}. +Alternatively, change to the @file{man} subdirectory of the Emacs +source distribution, and type @kbd{make calc.dvi}. (Don't worry if you +get some ``overfull box'' warnings while @TeX{} runs.) The result will be a device-independent output file called @file{calc.dvi}, which you must print in whatever way is right @@ -33846,6 +34218,15 @@ for your system. On many systems, the command is lpr -d calc.dvi @end example +@noindent +or + +@example +dvips calc.dvi +@end example + +@c the bumpoddpages macro was deleted +@ignore @cindex Marginal notes, adjusting Marginal notes for each function and key sequence normally alternate between the left and right sides of the page, which is correct if the @@ -33853,6 +34234,7 @@ manual is going to be bound as double-sided pages. Near the top of the file @file{calc.texi} you will find alternate definitions of the @code{\bumpoddpages} macro that put the marginal notes always on the same side, best if you plan to be binding single-sided pages. +@end ignore @appendixsec Settings File @@ -33885,7 +34267,7 @@ autoloading of the extensions modules. The result should be 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, @@ -33959,18 +34341,19 @@ keystrokes are not listed in this summary. \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 @@ -33984,7 +34367,6 @@ keystrokes are not listed in this summary. @format @iftex @advance@baselineskip-2.5pt -@let@tt@ninett @let@c@sumbreak @end iftex @r{ @: M-# a @: @: 33 @:calc-embedded-activate@:} @@ -34052,14 +34434,14 @@ keystrokes are not listed in this summary. @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 @@ -34291,8 +34673,8 @@ keystrokes are not listed in this summary. @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@:} @@ -34428,8 +34810,8 @@ keystrokes are not listed in this summary. @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@:} @@ -34810,7 +35192,7 @@ NOTES 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 @@ -34921,8 +35303,8 @@ input data set. Each entry may be a single value or a vector of values. @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 @@ -35131,7 +35513,7 @@ assigns @c{$x \coloneq a-x$} 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