X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/0d48e8aad38c02e7e157c89f505869a1539114ad..8ed713c67c3078cf1421e8b04625f6585990d39e:/man/calc.texi diff --git a/man/calc.texi b/man/calc.texi index f560f6f8a2..9912d1a81c 100644 --- a/man/calc.texi +++ b/man/calc.texi @@ -5,55 +5,57 @@ @c [title] @settitle GNU Emacs Calc 2.02g Manual @setchapternewpage odd -@dircategory Emacs -@direntry -* Calc: (calc). Advanced desk calculator and mathematical tool. -@end direntry @comment %**end of header (This is for running Texinfo on a region.) +@c The following macros are used for conditional output for single lines. +@c @texline foo +@c `foo' will appear only in TeX output +@c @infoline foo +@c `foo' will appear only in non-TeX output + +@c @expr{expr} will typeset an expression; +@c $x$ in TeX, @samp{x} otherwise. + +@iftex +@macro texline{stuff} +\stuff\ +@end macro +@alias infoline=comment +@tex +\gdef\exprsetup{\tex \let\t\ttfont \turnoffactive} +\gdef\expr{\exprsetup$\exprfinish} +\gdef\exprfinish#1{#1$\endgroup} +@end tex +@alias mathit=expr +@macro cpi{} +@math{@pi{}} +@end macro +@macro cpiover{den} +@math{@pi/\den\} +@end macro +@end iftex + +@ifnottex +@alias texline=comment +@macro infoline{stuff} +\stuff\ +@end macro +@alias expr=samp +@alias mathit=i +@macro cpi{} +@expr{pi} +@end macro +@macro cpiover{den} +@expr{pi/\den\} +@end macro +@end ifnottex + + @tex -% Some special kludges to make TeX formatting prettier. -% Because makeinfo.c exists, we can't just define new commands. -% So instead, we take over little-used existing commands. -% % Suggested by Karl Berry \gdef\!{\mskip-\thinmuskip} -% Redefine @cite{text} to act like $text$ in regular TeX. -% Info will typeset this same as @samp{text}. -\gdef\goodtex{\tex \let\rm\goodrm \let\t\ttfont \turnoffactive} -\gdef\goodrm{\fam0\tenrm} -\gdef\cite{\goodtex$\citexxx} -\gdef\citexxx#1{#1$\Etex} -\global\let\oldxrefX=\xrefX -\gdef\xrefX[#1]{\begingroup\let\cite=\dfn\oldxrefX[#1]\endgroup} - -% Redefine @c{tex-stuff} \n @whatever{info-stuff}. -\gdef\c{\futurelet\next\mycxxx} -\gdef\mycxxx{% - \ifx\next\bgroup \goodtex\let\next\mycxxy - \else\ifx\next\mindex \let\next\relax - \else\ifx\next\kindex \let\next\relax - \else\ifx\next\starindex \let\next\relax \else \let\next\comment - \fi\fi\fi\fi \next -} -\gdef\mycxxy#1#2{#1\Etex\mycxxz} -\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 @@ -81,11 +83,12 @@ @end ignore @end iftex -@ifnottex +@copying This file documents Calc, the GNU Emacs calculator. Copyright (C) 1990, 1991, 2001, 2002 Free Software Foundation, Inc. +@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 @@ -96,7 +99,13 @@ Texts as in (a) below. (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 ifnottex +@end quotation +@end copying + +@dircategory Emacs +@direntry +* Calc: (calc). Advanced desk calculator and mathematical tool. +@end direntry @titlepage @sp 6 @@ -113,17 +122,7 @@ Software Foundation raise funds for GNU development.'' @vskip 0pt plus 1filll Copyright @copyright{} 1990, 1991, 2001, 2002 Free Software Foundation, Inc. - -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. - -(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.'' +@insertcopying @end titlepage @c [begin] @@ -464,7 +463,7 @@ Algebraic manipulation features, including symbolic calculus. Moving data to and from regular editing buffers. @item -``Embedded mode'' for manipulating Calc formulas and data directly +Embedded mode for manipulating Calc formulas and data directly inside any editing buffer. @item @@ -534,8 +533,9 @@ need to know. @cindex Marginal notes Every Calc keyboard command is listed in the Calc Summary, and also in the Key Index. Algebraic functions, @kbd{M-x} commands, and -variables also have their own indices. @c{Each} -@asis{In the printed manual, each} +variables also have their own indices. +@texline Each +@infoline In the printed manual, each paragraph that is referenced in the Key or Function Index is marked in the margin with its index entry. @@ -565,6 +565,9 @@ held down are shown as @kbd{C-x}. Keys pressed with Meta held down are shown as @kbd{M-x}. Other notations are @key{RET} for the Return key, @key{SPC} for the space bar, @key{TAB} for the Tab key, @key{DEL} for the Delete key, and @key{LFD} for the Line-Feed key. +The @key{DEL} key is called Backspace on some keyboards, it is +whatever key you would use to correct a simple typing error when +regularly using Emacs. (If you don't have the @key{LFD} or @key{TAB} keys on your keyboard, the @kbd{C-j} and @kbd{C-i} keys are equivalent to them, respectively. @@ -588,7 +591,7 @@ the corresponding function in an algebraic-style formula would be @samp{cos(@var{x})}. A few commands don't have key equivalents: @code{calc-sincos} -[@code{sincos}].@refill +[@code{sincos}]. @node Demonstration of Calc, Using Calc, Notations Used in This Manual, Getting Started @section A Demonstration of Calc @@ -613,12 +616,14 @@ Delete, and Space keys. then the command to operate on the numbers. @noindent -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}. +Type @kbd{2 @key{RET} 3 + Q} to compute +@texline @math{\sqrt{2+3} = 2.2360679775}. +@infoline the square root of 2+3, which is 2.2360679775. @noindent -Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$} -@asis{the value of `pi' squared, 9.86960440109}. +Type @kbd{P 2 ^} to compute +@texline @math{\pi^2 = 9.86960440109}. +@infoline the value of `pi' squared, 9.86960440109. @noindent Type @key{TAB} to exchange the order of these two results. @@ -635,13 +640,15 @@ conventional ``algebraic'' notation. To enter an algebraic formula, use the apostrophe key. @noindent -Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$} -@asis{the square root of 2+3}. +Type @kbd{' sqrt(2+3) @key{RET}} to compute +@texline @math{\sqrt{2+3}}. +@infoline the square root of 2+3. @noindent -Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$} -@asis{`pi' squared}. To evaluate this symbolic -formula as a number, type @kbd{=}. +Type @kbd{' pi^2 @key{RET}} to enter +@texline @math{\pi^2}. +@infoline `pi' squared. +To evaluate this symbolic formula as a number, type @kbd{=}. @noindent Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent @@ -698,12 +705,16 @@ the upper-leftmost @samp{1} and set the mark, then move to just after the lower-right @samp{8} and press @kbd{M-# r}. @noindent -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 + @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-# :}.) +Type @kbd{v t} to transpose this +@texline @math{3\times2} +@infoline 3x2 +matrix into a +@texline @math{2\times3} +@infoline 2x3 +matrix. Type @w{@kbd{v u}} to unpack the rows into two separate +vectors. Now type @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 @key{RET}}} to enter the quantity 43 miles-per-hour. @@ -719,16 +730,17 @@ 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 @key{RET}}} to solve -these equations for the variables @cite{x} and @cite{y}.@refill +these equations for the variables @expr{x} and @expr{y}. @noindent Type @kbd{d B} to view the solutions in more readable notation. -Type @w{@kbd{d C}} to view them in C language notation, and @kbd{d T} -to view them in the notation for the @TeX{} typesetting system. -Type @kbd{d N} to return to normal notation. +Type @w{@kbd{d C}} to view them in C language notation, @kbd{d T} +to view them in the notation for the @TeX{} typesetting system, +and @kbd{d L} to view them in the notation for the @LaTeX{} typesetting +system. Type @kbd{d N} to return to normal notation. @noindent -Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @cite{a = 7.5} in these formulas. +Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @expr{a = 7.5} in these formulas. (That's a letter @kbd{l}, not a numeral @kbd{1}.) @iftex @@ -755,13 +767,7 @@ To exit from Calc, press @kbd{q} or @kbd{M-# c} again. @noindent Calc has several user interfaces that are specialized for different kinds of tasks. As well as Calc's standard interface, -there are Quick Mode, Keypad Mode, and Embedded Mode. - -@c [fix-ref Installation] -Calc must be @dfn{installed} before it can be used. @xref{Installation}, -for instructions on setting up and installing Calc. We will assume -you or someone on your system has already installed Calc as described -there. +there are Quick mode, Keypad mode, and Embedded mode. @menu * Starting Calc:: @@ -787,7 +793,7 @@ Once again, if you don't have a Meta key on your keyboard you can type @key{ESC} first, then @kbd{#}, to accomplish the same thing. If you don't even have an @key{ESC} key, you can fake it by holding down Control or @key{CTRL} while typing a left square bracket -(that's @kbd{C-[} in Emacs notation).@refill +(that's @kbd{C-[} in Emacs notation). @kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for you to press a second key to complete the command. In this case, @@ -796,7 +802,7 @@ doesn't matter for @kbd{M-#}) that says which Calc interface you want to use. To get Calc's standard interface, type @kbd{M-# c}. To get -Keypad Mode, type @kbd{M-# k}. Type @kbd{M-# ?} to get a brief +Keypad mode, type @kbd{M-# k}. Type @kbd{M-# ?} to get a brief list of the available options, and type a second @kbd{?} to get a complete list. @@ -809,14 +815,10 @@ function key twice is just like hitting @kbd{M-# M-#}.) If @kbd{M-#} doesn't work for you, you can always type explicit commands like @kbd{M-x calc} (for the standard user interface) or -@w{@kbd{M-x calc-keypad}} (for Keypad Mode). First type @kbd{M-x} +@w{@kbd{M-x calc-keypad}} (for Keypad mode). First type @kbd{M-x} (that's Meta with the letter @kbd{x}), then, at the prompt, type the full command (like @kbd{calc-keypad}) and press Return. -If you type @kbd{M-x calc} and Emacs still doesn't recognize the -command (it will say @samp{[No match]} when you try to press -@key{RET}), then Calc has not been properly installed. - The same commands (like @kbd{M-# c} or @kbd{M-# M-#}) that start the Calculator also turn it off if it is already on. @@ -830,9 +832,6 @@ 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. -@iftex -@advance@hsize20pt -@end iftex @smallexample @group @@ -862,9 +861,9 @@ you do. In this case, the trail shows that four numbers (17.3, 3, 2, and 4) were first entered into the Calculator, then the 2 and 4 were -multiplied to get 8, then the 3 and 8 were subtracted to get @i{-5}. +multiplied to get 8, then the 3 and 8 were subtracted to get @mathit{-5}. (The @samp{>} symbol shows that this was the most recent calculation.) -The net result is the two numbers 17.3 and @i{-5} sitting on the stack. +The net result is the two numbers 17.3 and @mathit{-5} sitting on the stack. Most Calculator commands deal explicitly with the stack only, but there is a set of commands that allow you to search back through @@ -874,7 +873,7 @@ Calc commands use the digits, letters, and punctuation keys. Shifted (i.e., upper-case) letters are different from lowercase letters. Some letters are @dfn{prefix} keys that begin two-letter commands. For example, @kbd{e} means ``enter exponent'' and shifted -@kbd{E} means @cite{e^x}. With the @kbd{d} (``display modes'') prefix +@kbd{E} means @expr{e^x}. With the @kbd{d} (``display modes'') prefix the letter ``e'' takes on very different meanings: @kbd{d e} means ``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.'' @@ -919,20 +918,20 @@ way to switch out of Calc momentarily to edit your file; type @subsection Quick Mode (Overview) @noindent -@dfn{Quick Mode} is a quick way to use Calc when you don't need the +@dfn{Quick mode} is a quick way to use Calc when you don't need the full complexity of the stack and trail. To use it, type @kbd{M-# q} (@code{quick-calc}) in any regular editing buffer. -Quick Mode is very simple: It prompts you to type any formula in +Quick mode is very simple: It prompts you to type any formula in standard algebraic notation (like @samp{4 - 2/3}) and then displays -the result at the bottom of the Emacs screen (@i{3.33333333333} +the result at the bottom of the Emacs screen (@mathit{3.33333333333} in this case). You are then back in the same editing buffer you were in before, ready to continue editing or to type @kbd{M-# q} again to do another quick calculation. The result of the calculation will also be in the Emacs ``kill ring'' so that a @kbd{C-y} command at this point will yank the result into your editing buffer. -Calc mode settings affect Quick Mode, too, though you will have to +Calc mode settings affect Quick mode, too, though you will have to go into regular Calc (with @kbd{M-# c}) to change the mode settings. @c [fix-ref Quick Calculator mode] @@ -942,13 +941,12 @@ go into regular Calc (with @kbd{M-# c}) to change the mode settings. @subsection Keypad Mode (Overview) @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 -mode is currently not supported under Emacs 19. +@dfn{Keypad mode} is a mouse-based interface to the Calculator. +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). -Type @kbd{M-# k} to turn Keypad Mode on or off. Once again you +Type @kbd{M-# k} to turn Keypad mode on or off. Once again you get two new windows, this time on the righthand side of the screen instead of at the bottom. The upper window is the familiar Calc Stack; the lower window is a picture of a typical calculator keypad. @@ -983,24 +981,13 @@ 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 +Keypad mode is much easier for beginners to learn, because there is no need to memorize lots of obscure key sequences. But not all commands in regular Calc are available on the Keypad. You can always switch the cursor into the Calc stack window to use standard Calc commands if you need. Serious Calc users, though, -often find they prefer the standard interface over Keypad Mode. +often find they prefer the standard interface over Keypad mode. To operate the Calculator, just click on the ``buttons'' of the keypad using your left mouse button. To enter the two numbers @@ -1013,16 +1000,13 @@ 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 +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 -keypad. One advantage of Keypad Mode is that you don't need an +keypad. One advantage of Keypad mode is that you don't need an explicit command to switch between editing and calculating. -If you press @kbd{M-# b} first, you get a full-screen Keypad Mode +If you press @kbd{M-# b} first, you get a full-screen Keypad mode (@code{full-calc-keypad}) with three windows: The keypad in the lower left, the stack in the lower right, and the trail on top. @@ -1060,7 +1044,7 @@ itself. @subsection Embedded Mode (Overview) @noindent -@dfn{Embedded Mode} is a way to use Calc directly from inside an +@dfn{Embedded mode} is a way to use Calc directly from inside an editing buffer. Suppose you have a formula written as part of a document like this: @@ -1077,7 +1061,7 @@ is @noindent and you wish to have Calc compute and format the derivative for you and store this derivative in the buffer automatically. To -do this with Embedded Mode, first copy the formula down to where +do this with Embedded mode, first copy the formula down to where you want the result to be: @smallexample @@ -1116,7 +1100,7 @@ is @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. +the formula, and even @kbd{d B} to use Big display mode. @smallexample @group @@ -1136,10 +1120,10 @@ is Calc has added annotations to the file to help it remember the modes that were used for this formula. They are formatted like comments -in the @TeX{} typesetting language, just in case you are using @TeX{}. -(In this example @TeX{} is not being used, so you might want to move -these comments up to the top of the file or otherwise put them out -of the way.) +in the @TeX{} typesetting language, just in case you are using @TeX{} or +@LaTeX{}. (In this example @TeX{} is not being used, so you might want +to move 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) @key{RET}}. @@ -1156,7 +1140,7 @@ righthand label: Type @kbd{d @} (1) @key{RET}}. @end group @end smallexample -To leave Embedded Mode, type @kbd{M-# e} again. The mode line +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 actually been trying this as you read along, you'll want to press @kbd{M-# 0} [with the digit zero] now to reset the modes you changed.) @@ -1171,7 +1155,7 @@ A slope of one-third corresponds to an angle of 1 degrees. @end smallexample Place the cursor on the @samp{1}, then type @kbd{M-# w} to enable -Embedded Mode on that number. Now type @kbd{3 /} (to get one-third), +Embedded mode on that number. Now type @kbd{3 /} (to get one-third), and @kbd{I T} (the Inverse Tangent converts a slope into an angle), then @w{@kbd{M-# w}} again to exit Embedded mode. @@ -1238,7 +1222,7 @@ move it out of that window. Control whether @kbd{M-# c} and @kbd{M-# k} use the full screen. @item Q -Use Quick Mode for a single short calculation. +Use Quick mode for a single short calculation. @item K Turn Calc Keypad mode on or off. @@ -1287,7 +1271,7 @@ Yank a value from the Calculator into the current editing buffer. @end iftex @noindent -Commands for use with Embedded Mode: +Commands for use with Embedded mode: @table @kbd @item A @@ -1352,13 +1336,15 @@ With any prefix argument, reset everything but the stack. @noindent Calc was originally started as a two-week project to occupy a lull in the author's schedule. Basically, a friend asked if I remembered -the value of @c{$2^{32}$} -@cite{2^32}. I didn't offhand, but I said, ``that's -easy, just call up an @code{xcalc}.'' @code{Xcalc} duly reported -that the answer to our question was @samp{4.294967e+09}---with no way to -see the full ten digits even though we knew they were there in the -program's memory! I was so annoyed, I vowed to write a calculator -of my own, once and for all. +the value of +@texline @math{2^{32}}. +@infoline @expr{2^32}. +I didn't offhand, but I said, ``that's easy, just call up an +@code{xcalc}.'' @code{Xcalc} duly reported that the answer to our +question was @samp{4.294967e+09}---with no way to see the full ten +digits even though we knew they were there in the program's memory! I +was so annoyed, I vowed to write a calculator of my own, once and for +all. I chose Emacs Lisp, a) because I had always been curious about it and b) because, being only a text editor extension language after @@ -1408,18 +1394,19 @@ algebra system for microcomputers. Many people have contributed to Calc by reporting bugs and suggesting features, large and small. A few deserve special mention: Tim Peters, who helped develop the ideas that led to the selection commands, rewrite -rules, and many other algebra features; @c{Fran\c cois} -@asis{Francois} Pinard, who contributed -an early prototype of the Calc Summary appendix as well as providing -valuable suggestions in many other areas of Calc; Carl Witty, whose eagle -eyes discovered many typographical and factual errors in the Calc manual; -Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who -made many suggestions relating to the algebra commands and contributed -some code for polynomial operations; Randal Schwartz, who suggested the -@code{calc-eval} function; Robert J. Chassell, who suggested the Calc -Tutorial and exercises; and Juha Sarlin, who first worked out how to split -Calc into quickly-loading parts. Bob Weiner helped immensely with the -Lucid Emacs port. +rules, and many other algebra features; +@texline Fran\c cois +@infoline Francois +Pinard, who contributed an early prototype of the Calc Summary appendix +as well as providing valuable suggestions in many other areas of Calc; +Carl Witty, whose eagle eyes discovered many typographical and factual +errors in the Calc manual; Tim Kay, who drove the development of +Embedded mode; Ove Ewerlid, who made many suggestions relating to the +algebra commands and contributed some code for polynomial operations; +Randal Schwartz, who suggested the @code{calc-eval} function; Robert +J. Chassell, who suggested the Calc Tutorial and exercises; and Juha +Sarlin, who first worked out how to split Calc into quickly-loading +parts. Bob Weiner helped immensely with the Lucid Emacs port. @cindex Bibliography @cindex Knuth, Art of Computer Programming @@ -1492,9 +1479,9 @@ to skip on to the rest of this manual. @c [fix-ref Embedded Mode] This tutorial describes the standard user interface of Calc only. -The ``Quick Mode'' and ``Keypad Mode'' interfaces are fairly +The Quick mode and Keypad mode interfaces are fairly self-explanatory. @xref{Embedded Mode}, for a description of -the ``Embedded Mode'' interface. +the Embedded mode interface. @ifinfo The easiest way to read this tutorial on-line is to have two windows on @@ -1580,8 +1567,8 @@ from the top of the stack. @cindex Operators @cindex Operands -In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands} -and the @cite{+} is the @dfn{operator}. In an RPN calculator you always +In an operation like @expr{2+3}, the 2 and 3 are called the @dfn{operands} +and the @expr{+} is the @dfn{operator}. In an RPN calculator you always enter the operands first, then the operator. Each time you type a number, Calc adds or @dfn{pushes} it onto the top of the Stack. When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate @@ -1595,7 +1582,7 @@ you wish; type @kbd{M-# c} to switch into the Calc window (you can type The first four keystrokes ``push'' the numbers 2 and 3 onto the stack. 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 +will look at various points throughout the calculation: @smallexample @group @@ -1616,11 +1603,11 @@ less distracting in regular use. @cindex Levels of stack The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level numbers}. Old RPN calculators always had four stack levels called -@cite{x}, @cite{y}, @cite{z}, and @cite{t}. Calc's stack can grow +@expr{x}, @expr{y}, @expr{z}, and @expr{t}. Calc's stack can grow as large as you like, so it uses numbers instead of letters. Some stack-manipulation commands accept a numeric argument that says which stack level to work on. Normal commands like @kbd{+} always -work on the top few levels of the stack.@refill +work on the top few levels of the stack. @c [fix-ref Truncating the Stack] The Stack buffer is just an Emacs buffer, and you can move around in @@ -1637,7 +1624,7 @@ You don't really need the second @key{RET} in @kbd{2 @key{RET} 3 @key{RET} +}. That's because if you type any operator name or other non-numeric key when you are entering a number, the Calculator automatically enters that number and then does the requested command. -Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill +Thus @kbd{2 @key{RET} 3 +} will work just as well. Examples in this tutorial will often omit @key{RET} even when the stack displays shown would only happen if you did press @key{RET}: @@ -1671,9 +1658,10 @@ Here's the first exercise: What will the keystrokes @kbd{1 @key{RET} 2 multiplication.) Figure it out by hand, then try it with Calc to see if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) -(@bullet{}) @strong{Exercise 2.} Compute @c{$(2\times4) + (7\times9.4) + {5\over4}$} -@cite{2*4 + 7*9.5 + 5/4} using the -stack. @xref{RPN Answer 2, 2}. (@bullet{}) +(@bullet{}) @strong{Exercise 2.} Compute +@texline @math{(2\times4) + (7\times9.4) + {5\over4}} +@infoline @expr{2*4 + 7*9.5 + 5/4} +using the stack. @xref{RPN Answer 2, 2}. (@bullet{}) The @key{DEL} key is called Backspace on some keyboards. It is whatever key you would use to correct a simple typing error when @@ -1725,7 +1713,7 @@ the above example with @key{SPC} and the effect would be the same. Another stack manipulation key is @key{TAB}. This exchanges the top 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)}. +was @expr{20 / (2+3)}. @smallexample @group @@ -1833,11 +1821,10 @@ What happens if you take the square root of a negative number? @end smallexample @noindent -The notation @cite{(a, b)} represents a complex number. -Complex numbers are more traditionally written @c{$a + b i$} -@cite{a + b i}; +The notation @expr{(a, b)} represents a complex number. +Complex numbers are more traditionally written @expr{a + b i}; Calc can display in this format, too, but for now we'll stick to the -@cite{(a, b)} notation. +@expr{(a, b)} notation. If you don't know how complex numbers work, you can safely ignore this feature. Complex numbers only arise from operations that would be @@ -1896,7 +1883,7 @@ When you press @kbd{)} all the stack entries between the incomplete entry and the top are collected, so there's never really a reason to use the comma. It's up to you. -(@bullet{}) @strong{Exercise 4.} To enter the complex number @cite{(2, 3)}, +(@bullet{}) @strong{Exercise 4.} To enter the complex number @expr{(2, 3)}, your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened? (Joe thought of a clever way to correct his mistake in only two keystrokes, but it didn't quite work. Try it to find out why.) @@ -1954,9 +1941,9 @@ entire stack.) @noindent If you are not used to RPN notation, you may prefer to operate the -Calculator in ``algebraic mode,'' which is closer to the way -non-RPN calculators work. In algebraic mode, you enter formulas -in traditional @cite{2+3} notation. +Calculator in Algebraic mode, which is closer to the way +non-RPN calculators work. In Algebraic mode, you enter formulas +in traditional @expr{2+3} notation. You don't really need any special ``mode'' to enter algebraic formulas. You can enter a formula at any time by pressing the apostrophe (@kbd{'}) @@ -2007,7 +1994,7 @@ $$ 2 + { 3 \times 4 \times 5 \over 6 \times 7^8 } - 9 $$ @end tex @noindent -The result of this expression will be the number @i{-6.99999826533}. +The result of this expression will be the number @mathit{-6.99999826533}. Calc's order of evaluation is the same as for most computer languages, except that @samp{*} binds more strongly than @samp{/}, as the above @@ -2016,18 +2003,18 @@ can often be omitted: @samp{2 a} is the same as @samp{2*a}. Operators at the same level are evaluated from left to right, except that @samp{^} is evaluated from right to left. Thus, @samp{2-3-4} is -equivalent to @samp{(2-3)-4} or @i{-5}, whereas @samp{2^3^4} is equivalent +equivalent to @samp{(2-3)-4} or @mathit{-5}, whereas @samp{2^3^4} is equivalent to @samp{2^(3^4)} (a very large integer; try it!). -If you tire of typing the apostrophe all the time, there is an -``algebraic mode'' you can select in which Calc automatically senses +If you tire of typing the apostrophe all the time, there is +Algebraic mode, where Calc automatically senses when you are about to type an algebraic expression. To enter this mode, press the two letters @w{@kbd{m a}}. (An @samp{Alg} indicator should appear in the Calc window's mode line.) Press @kbd{m a}, then @kbd{2+3+4} with no apostrophe, then @key{RET}. -In algebraic mode, when you press any key that would normally begin +In Algebraic mode, when you press any key that would normally begin entering a number (such as a digit, a decimal point, or the @kbd{_} key), or if you press @kbd{(} or @kbd{[}, Calc automatically begins an algebraic entry. @@ -2039,10 +2026,10 @@ the function name corresponding to the square-root key @kbd{Q} is the notation @samp{sqrt(@var{x})}. Press the apostrophe, then type @kbd{sqrt(5*2) - 3}. The result should -be @cite{0.16227766017}. +be @expr{0.16227766017}. Note that if the formula begins with a function name, you need to use -the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin} +the apostrophe even if you are in Algebraic mode. If you type @kbd{arcsin} out of the blue, the @kbd{a r} will be taken as an Algebraic Rewrite command, and the @kbd{csin} will be taken as the name of the rewrite rule to use! @@ -2051,7 +2038,7 @@ Some people prefer to enter complex numbers and vectors in algebraic form because they find RPN entry with incomplete objects to be too distracting, even though they otherwise use Calc as an RPN calculator. -Still in algebraic mode, type: +Still in Algebraic mode, type: @smallexample @group @@ -2065,18 +2052,17 @@ Still in algebraic mode, type: Algebraic mode allows us to enter complex numbers without pressing an apostrophe first, but it also means we need to press @key{RET} -after every entry, even for a simple number like @cite{1}. +after every entry, even for a simple number like @expr{1}. -(You can type @kbd{C-u m a} to enable a special ``incomplete algebraic -mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even +(You can type @kbd{C-u m a} to enable a special Incomplete Algebraic +mode in which the @kbd{(} and @kbd{[} keys use algebraic entry even though regular numeric keys still use RPN numeric entry. There is also -a ``total algebraic mode,'' started by typing @kbd{m t}, in which all +Total Algebraic mode, started by typing @kbd{m t}, in which all normal keys begin algebraic entry. You must then use the @key{META} key -to type Calc commands: @kbd{M-m t} to get back out of total algebraic -mode, @kbd{M-q} to quit, etc. Total algebraic mode is not supported -under Emacs 19.) +to type Calc commands: @kbd{M-m t} to get back out of Total Algebraic +mode, @kbd{M-q} to quit, etc.) -If you're still in algebraic mode, press @kbd{m a} again to turn it off. +If you're still in Algebraic mode, press @kbd{m a} again to turn it off. Actual non-RPN calculators use a mixture of algebraic and RPN styles. In general, operators of two numbers (like @kbd{+} and @kbd{*}) @@ -2086,8 +2072,9 @@ intermediate results of a calculation as you go along. You can accomplish this in Calc by performing your calculation as a series of algebraic entries, using the @kbd{$} sign to tie them together. In an algebraic formula, @kbd{$} represents the number on the top -of the stack. Here, we perform the calculation @c{$\sqrt{2\times4+1}$} -@cite{sqrt(2*4+1)}, +of the stack. Here, we perform the calculation +@texline @math{\sqrt{2\times4+1}}, +@infoline @expr{sqrt(2*4+1)}, which on a traditional calculator would be done by pressing @kbd{2 * 4 + 1 =} and then the square-root key. @@ -2226,7 +2213,7 @@ the righthand formula has been evaluated as if by typing @kbd{=}. @noindent Notice that the instant we stored a new value in @code{a}, all -@samp{=>} operators already on the stack that referred to @cite{a} +@samp{=>} operators already on the stack that referred to @expr{a} were updated to use the new value. With @samp{=>}, you can push a set of formulas on the stack, then change the variables experimentally to see the effects on the formulas' values. @@ -2293,7 +2280,7 @@ mistakenly. @end smallexample @noindent -It was not possible to redo past the @cite{6}, since that was placed there +It was not possible to redo past the @expr{6}, since that was placed there by something other than an undo command. @cindex Time travel @@ -2301,7 +2288,7 @@ You can think of undo and redo as a sort of ``time machine.'' Press @kbd{U} to go backward in time, @kbd{D} to go forward. If you go backward and do something (like @kbd{*}) then, as any science fiction reader knows, you have changed your future and you cannot go forward -again. Thus, the inability to redo past the @cite{6} even though there +again. Thus, the inability to redo past the @expr{6} even though there was an earlier undo command. You can always recall an earlier result using the Trail. We've ignored @@ -2309,13 +2296,13 @@ the trail so far, but it has been faithfully recording everything we did since we loaded the Calculator. If the Trail is not displayed, press @kbd{t d} now to turn it on. -Let's try grabbing an earlier result. The @cite{8} we computed was +Let's try grabbing an earlier result. The @expr{8} we computed was undone by a @kbd{U} command, and was lost even to Redo when we pressed @kbd{*}, but it's still there in the trail. There should be a little @samp{>} arrow (the @dfn{trail pointer}) resting on the last trail entry. If there isn't, press @kbd{t ]} to reset the trail pointer. Now, press @w{@kbd{t p}} to move the arrow onto the line containing -@cite{8}, and press @w{@kbd{t y}} to ``yank'' that number back onto the +@expr{8}, and press @w{@kbd{t y}} to ``yank'' that number back onto the stack. If you press @kbd{t ]} again, you will see that even our Yank command @@ -2345,9 +2332,8 @@ key. If you type a prefix key by accident, you can press @kbd{C-g} to cancel it. (In fact, you can press @kbd{C-g} to cancel almost anything in Emacs.) To get help on a prefix key, press that key followed by @kbd{?}. Some prefixes have several lines of help, -so you need to press @kbd{?} repeatedly to see them all. This may -not work under Lucid Emacs, but you can also type @kbd{h h} to -see all the help at once. +so you need to press @kbd{?} repeatedly to see them all. +You can also type @kbd{h h} to see all the help at once. Try pressing @kbd{t ?} now. You will see a line of the form, @@ -2361,7 +2347,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 @@ -2376,8 +2362,7 @@ directly, but you can press @kbd{`} (the backquote or accent grave) to edit a stack entry. Try entering @samp{3.141439} now. If this is supposed to represent -@c{$\pi$} -@cite{pi}, it's got several errors. Press @kbd{`} to edit this number. +@cpi{}, it's got several errors. Press @kbd{`} to edit this number. Now use the normal Emacs cursor motion and editing keys to change the second 4 to a 5, and to transpose the 3 and the 9. When you press @key{RET}, the number on the stack will be replaced by your @@ -2391,7 +2376,7 @@ during entry of a number or algebraic formula. @noindent Calc has many types of @dfn{modes} that affect the way it interprets your commands or the way it displays data. We have already seen one -mode, namely algebraic mode. There are many others, too; we'll +mode, namely Algebraic mode. There are many others, too; we'll try some of the most common ones here. Perhaps the most fundamental mode in Calc is the current @dfn{precision}. @@ -2406,7 +2391,7 @@ Most of the symbols there are Emacs things you don't need to worry about, but the @samp{12} and the @samp{Deg} are mode indicators. The @samp{12} means that calculations should always be carried to 12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /}, -we get @cite{0.142857142857} with exactly 12 digits, not counting +we get @expr{0.142857142857} with exactly 12 digits, not counting leading and trailing zeros. You can set the precision to anything you like by pressing @kbd{p}, @@ -2423,14 +2408,14 @@ then doing @kbd{1 @key{RET} 7 /} again: Although the precision can be set arbitrarily high, Calc always has to have @emph{some} value for the current precision. After -all, the true value @cite{1/7} is an infinitely repeating decimal; +all, the true value @expr{1/7} is an infinitely repeating decimal; Calc has to stop somewhere. Of course, calculations are slower the more digits you request. Press @w{@kbd{p 12}} now to set the precision back down to the default. Calculations always use the current precision. For example, even -though we have a 30-digit value for @cite{1/7} on the stack, if +though we have a 30-digit value for @expr{1/7} on the stack, if we use it in a calculation in 12-digit mode it will be rounded down to 12 digits before it is used. Try it; press @key{RET} to duplicate the number, then @w{@kbd{1 +}}. Notice that the @key{RET} @@ -2448,7 +2433,7 @@ But the instant we pressed @kbd{+}, the number was rounded down. @noindent In fact, since we added a digit on the left, we had to lose one -digit on the right from even the 12-digit value of @cite{1/7}. +digit on the right from even the 12-digit value of @expr{1/7}. How did we get more than 12 digits when we computed @samp{2^3^4}? The answer is that Calc makes a distinction between @dfn{integers} and @@ -2499,7 +2484,7 @@ want to see. You can enter numbers in this notation, too. @noindent Hey, the answer is different! Look closely at the middle columns of the two examples. In the first, the stack contained the -exact integer @cite{10000}, but in the second it contained +exact integer @expr{10000}, but in the second it contained a floating-point value with a decimal point. When you raise a number to an integer power, Calc uses repeated squaring and multiplication to get the answer. When you use a floating-point @@ -2532,7 +2517,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. @@ -2600,7 +2585,7 @@ 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. -Notice that the integer @cite{12345} was not affected by any +Notice that the integer @expr{12345} was not affected by any of the float formats. Integers are integers, and are always displayed exactly. @@ -2681,7 +2666,7 @@ fit on a typical screen, either, so you will have to use horizontal scrolling to see them all. Press @kbd{<} and @kbd{>} to scroll the stack window left and right by half its width. Another way to view something large is to press @kbd{`} (back-quote) to edit the top of -stack in a separate window. (Press @kbd{M-# M-#} when you are done.) +stack in a separate window. (Press @kbd{C-c C-c} when you are done.) You can enter non-decimal numbers using the @kbd{#} symbol, too. Let's see what the hexadecimal number @samp{5FE} looks like in @@ -2748,13 +2733,15 @@ angle is measured in degrees. For example, @noindent The shift-@kbd{S} command computes the sine of an angle. The sine -of 45 degrees is @c{$\sqrt{2}/2$} -@cite{sqrt(2)/2}; squaring this yields @cite{2/4 = 0.5}. -However, there has been a slight roundoff error because the -representation of @c{$\sqrt{2}/2$} -@cite{sqrt(2)/2} wasn't exact. The @kbd{c 1} -command is a handy way to clean up numbers in this case; it -temporarily reduces the precision by one digit while it +of 45 degrees is +@texline @math{\sqrt{2}/2}; +@infoline @expr{sqrt(2)/2}; +squaring this yields @expr{2/4 = 0.5}. However, there has been a slight +roundoff error because the representation of +@texline @math{\sqrt{2}/2} +@infoline @expr{sqrt(2)/2} +wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers +in this case; it temporarily reduces the precision by one digit while it re-rounds the number on the top of the stack. @cindex Roundoff errors, examples @@ -2765,9 +2752,7 @@ What happened? @xref{Modes Answer 3, 3}. (@bullet{}) To do this calculation in radians, we would type @kbd{m r} first. (The indicator changes to @samp{Rad}.) 45 degrees corresponds to -@c{$\pi\over4$} -@cite{pi/4} radians. To get @c{$\pi$} -@cite{pi}, press the @kbd{P} key. (Once +@cpiover{4} radians. To get @cpi{}, press the @kbd{P} key. (Once again, this is a shifted capital @kbd{P}. Remember, unshifted @kbd{p} sets the precision.) @@ -2793,9 +2778,10 @@ either radians or degrees, depending on the current angular mode. @end smallexample @noindent -Here we compute the Inverse Sine of @c{$\sqrt{0.5}$} -@cite{sqrt(0.5)}, first in -radians, then in degrees. +Here we compute the Inverse Sine of +@texline @math{\sqrt{0.5}}, +@infoline @expr{sqrt(0.5)}, +first in radians, then in degrees. Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees and vice-versa. @@ -2809,7 +2795,7 @@ and vice-versa. @end group @end smallexample -Another interesting mode is @dfn{fraction mode}. Normally, +Another interesting mode is @dfn{Fraction mode}. Normally, dividing two integers produces a floating-point result if the quotient can't be expressed as an exact integer. Fraction mode causes integer division to produce a fraction, i.e., a rational @@ -2833,7 +2819,7 @@ You can enter a fraction at any time using @kbd{:} notation. (Calc uses @kbd{:} instead of @kbd{/} as the fraction separator because @kbd{/} is already used to divide the top two stack elements.) Calculations involving fractions will always -produce exact fractional results; fraction mode only says +produce exact fractional results; Fraction mode only says what to do when dividing two integers. @cindex Fractions vs. floats @@ -2844,7 +2830,7 @@ why would you ever use floating-point numbers instead? Typing @kbd{m f} doesn't change any existing values in the stack. In the above example, we had to Undo the division and do it over -again when we changed to fraction mode. But if you use the +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. @@ -2860,7 +2846,7 @@ recompute for you. @noindent In this example, the righthand side of the @samp{=>} operator on the stack is recomputed when we change the precision, then -again when we change to fraction mode. All @samp{=>} expressions +again when we change to Fraction mode. All @samp{=>} expressions on the stack are recomputed every time you change any mode that might affect their values. @@ -2975,15 +2961,16 @@ provide a @kbd{\} command. @xref{Arithmetic Answer 1, 1}. (@bullet{}) We've already seen the @kbd{Q} (square root) and @kbd{S} (sine) commands. Other commands along those lines are @kbd{C} (cosine), -@kbd{T} (tangent), @kbd{E} (@cite{e^x}) and @kbd{L} (natural +@kbd{T} (tangent), @kbd{E} (@expr{e^x}) and @kbd{L} (natural logarithm). These can be modified by the @kbd{I} (inverse) and @kbd{H} (hyperbolic) prefix keys. Let's compute the sine and cosine of an angle, and verify the -identity @c{$\sin^2x + \cos^2x = 1$} -@cite{sin(x)^2 + cos(x)^2 = 1}. We'll -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: +identity +@texline @math{\sin^2x + \cos^2x = 1}. +@infoline @expr{sin(x)^2 + cos(x)^2 = 1}. +We'll arbitrarily pick @mathit{-64} degrees as a good value for @expr{x}. +With the angular mode set to degrees (type @w{@kbd{m d}}), do: @smallexample @group @@ -3002,8 +2989,9 @@ You can of course do these calculations to any precision you like.) Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum of squares, command. -Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} -@cite{tan(x) = sin(x) / cos(x)}. +Another identity is +@texline @math{\displaystyle\tan x = {\sin x \over \cos x}}. +@infoline @expr{tan(x) = sin(x) / cos(x)}. @smallexample @group @@ -3016,8 +3004,8 @@ Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} @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 +@expr{0.89879} units downward and @expr{0.43837} units to the right, +your direction of motion is @mathit{-64} degrees from horizontal. Suppose we move in the opposite direction, up and to the left: @smallexample @@ -3065,9 +3053,9 @@ the top two stack elements right after the @kbd{U U}, then a pair of A similar identity is supposed to hold for hyperbolic sines and cosines, except that it is the @emph{difference} -@c{$\cosh^2x - \sinh^2x$} -@cite{cosh(x)^2 - sinh(x)^2} that always equals one. -Let's try to verify this identity.@refill +@texline @math{\cosh^2x - \sinh^2x} +@infoline @expr{cosh(x)^2 - sinh(x)^2} +that always equals one. Let's try to verify this identity. @smallexample @group @@ -3093,12 +3081,12 @@ enormously so. Try it if you wish; sure enough, the answer is 0.99999, reasonably close to 1. Of course, a more reasonable way to verify the identity is to use -a more reasonable value for @cite{x}! +a more reasonable value for @expr{x}! @cindex Common logarithm Some Calculator commands use the Hyperbolic prefix for other purposes. The logarithm and exponential functions, for example, work to the base -@cite{e} normally but use base-10 instead if you use the Hyperbolic +@expr{e} normally but use base-10 instead if you use the Hyperbolic prefix. @smallexample @@ -3131,7 +3119,7 @@ value of @var{b}. Here we first use @kbd{B} to compute the base-10 logarithm, then use the ``hyperbolic'' exponential as a cheap hack to recover the number 1000, then use @kbd{B} again to compute the natural logarithm. Note -that @kbd{P} with the hyperbolic prefix pushes the constant @cite{e} +that @kbd{P} with the hyperbolic prefix pushes the constant @expr{e} onto the stack. You may have noticed that both times we took the base-10 logarithm @@ -3172,8 +3160,8 @@ in this case). If you take the factorial of a non-integer, Calc uses a generalized factorial function defined in terms of Euler's Gamma function -@c{$\Gamma(n)$} -@cite{gamma(n)} +@texline @math{\Gamma(n)} +@infoline @expr{gamma(n)} (which is itself available as the @kbd{f g} command). @smallexample @@ -3188,17 +3176,19 @@ factorial function defined in terms of Euler's Gamma function @end smallexample @noindent -Here we verify the identity @c{$n! = \Gamma(n+1)$} -@cite{@var{n}!@: = gamma(@var{n}+1)}. +Here we verify the identity +@texline @math{n! = \Gamma(n+1)}. +@infoline @expr{@var{n}!@: = gamma(@var{n}+1)}. -The binomial coefficient @var{n}-choose-@var{m}@c{ or $\displaystyle {n \choose m}$} -@asis{} is defined by -@c{$\displaystyle {n! \over m! \, (n-m)!}$} -@cite{n!@: / m!@: (n-m)!} for all reals @cite{n} and -@cite{m}. The intermediate results in this formula can become quite -large even if the final result is small; the @kbd{k c} command computes -a binomial coefficient in a way that avoids large intermediate -values. +The binomial coefficient @var{n}-choose-@var{m} +@texline or @math{\displaystyle {n \choose m}} +is defined by +@texline @math{\displaystyle {n! \over m! \, (n-m)!}} +@infoline @expr{n!@: / m!@: (n-m)!} +for all reals @expr{n} and @expr{m}. The intermediate results in this +formula can become quite large even if the final result is small; the +@kbd{k c} command computes a binomial coefficient in a way that avoids +large intermediate values. The @kbd{k} prefix key defines several common functions out of combinatorics and number theory. Here we compute the binomial @@ -3302,7 +3292,7 @@ of the vectors. @cindex Dot product The dot product of two vectors is equal to the product of their lengths times the cosine of the angle between them. (Here the vector -is interpreted as a line from the origin @cite{(0,0,0)} to the +is interpreted as a line from the origin @expr{(0,0,0)} to the specified point in three-dimensional space.) The @kbd{A} (absolute value) command can be used to compute the length of a vector. @@ -3415,8 +3405,8 @@ the second example. When two matrices are multiplied, the lefthand matrix must have the same number of columns as the righthand matrix has rows. -Row @cite{i}, column @cite{j} of the result is effectively the -dot product of row @cite{i} of the left matrix by column @cite{j} +Row @expr{i}, column @expr{j} of the result is effectively the +dot product of row @expr{i} of the left matrix by column @expr{j} of the right matrix. If we try to duplicate this matrix and multiply it by itself, @@ -3477,9 +3467,11 @@ rows in the matrix is different from the number of elements in the vector. (@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows -of the above @c{$2\times3$} -@asis{2x3} matrix to get @cite{[6, 15]}. Now use @samp{*} to -sum along the columns to get @cite{[5, 7, 9]}. +of the above +@texline @math{2\times3} +@infoline 2x3 +matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns +to get @expr{[5, 7, 9]}. @xref{Matrix Answer 1, 1}. (@bullet{}) @cindex Identity matrix @@ -3602,7 +3594,7 @@ inverse of the matrix. Calc can do this all in one step: @end smallexample @noindent -The result is the @cite{[a, b, c]} vector that solves the equations. +The result is the @expr{[a, b, c]} vector that solves the equations. (Dividing by a square matrix is equivalent to multiplying by its inverse.) @@ -3626,16 +3618,19 @@ the matrix and vector. If we multiplied in the other order, Calc would assume the vector was a row vector in order to make the dimensions come out right, and the answer would be incorrect. If you don't feel safe letting Calc take either interpretation of your -vectors, use explicit @c{$N\times1$} -@asis{Nx1} or @c{$1\times N$} -@asis{1xN} matrices instead. -In this case, you would enter the original column vector as -@samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. +vectors, use explicit +@texline @math{N\times1} +@infoline Nx1 +or +@texline @math{1\times N} +@infoline 1xN +matrices instead. In this case, you would enter the original column +vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. (@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make vectors and matrices that include variables. Solve the following -system of equations to get expressions for @cite{x} and @cite{y} -in terms of @cite{a} and @cite{b}. +system of equations to get expressions for @expr{x} and @expr{y} +in terms of @expr{a} and @expr{b}. @ifinfo @group @@ -3664,10 +3659,10 @@ if it has more equations than variables. It is often the case that there are no values for the variables that will satisfy all the equations at once, but it is still useful to find a set of values which ``nearly'' satisfy all the equations. In terms of matrix equations, -you can't solve @cite{A X = B} directly because the matrix @cite{A} +you can't solve @expr{A X = B} directly because the matrix @expr{A} is not square for an over-determined system. Matrix inversion works only for square matrices. One common trick is to multiply both sides -on the left by the transpose of @cite{A}: +on the left by the transpose of @expr{A}: @ifinfo @samp{trn(A)*A*X = trn(A)*B}. @end ifinfo @@ -3675,12 +3670,14 @@ on the left by the transpose of @cite{A}: \turnoffactive $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}. @end tex -Now @c{$A^T A$} -@cite{trn(A)*A} is a square matrix so a solution is possible. It -turns out that the @cite{X} vector you compute in this way will be a -``least-squares'' solution, which can be regarded as the ``closest'' -solution to the set of equations. Use Calc to solve the following -over-determined system:@refill +Now +@texline @math{A^T A} +@infoline @expr{trn(A)*A} +is a square matrix so a solution is possible. It turns out that the +@expr{X} vector you compute in this way will be a ``least-squares'' +solution, which can be regarded as the ``closest'' solution to the set +of equations. Use Calc to solve the following over-determined +system: @ifinfo @group @@ -3769,8 +3766,10 @@ other a plain number.) In the final step, we take the square root of each element. (@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two -from @c{$2^{-4}$} -@cite{2^-4} to @cite{2^4}. @xref{List Answer 1, 1}. (@bullet{}) +from +@texline @math{2^{-4}} +@infoline @expr{2^-4} +to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{}) You can also @dfn{reduce} a binary operator across a vector. For example, reducing @samp{*} computes the product of all the @@ -3904,13 +3903,13 @@ the manual and find this table there. (Press @kbd{g}, then type @kbd{List Tutorial}, to jump straight to this section.) 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. +to the left of the @expr{1.34}. Press @kbd{C-@@} to set the mark. (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}. +Now position the cursor to the lower-right, just after the @expr{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 +the contents of the rectangle you specified in the form of a matrix. @smallexample @group @@ -3955,7 +3954,7 @@ Let's store these in quick variables 1 and 2, respectively. (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the stored value from the stack.) -In a least squares fit, the slope @cite{m} is given by the formula +In a least squares fit, the slope @expr{m} is given by the formula @ifinfo @example @@ -3971,11 +3970,13 @@ $$ m = {N \sum x y - \sum x \sum y \over @end tex @noindent -where @c{$\sum x$} -@cite{sum(x)} represents the sum of all the values of @cite{x}. -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. +where +@texline @math{\sum x} +@infoline @expr{sum(x)} +represents the sum of all the values of @expr{x}. 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. @smallexample @group @@ -4009,7 +4010,7 @@ respectively. (We could have used \kbd{*} to compute $\sum x^2$ and $\sum x y$.) @end tex -Finally, we also need @cite{N}, the number of data points. This is just +Finally, we also need @expr{N}, the number of data points. This is just the length of either of our lists. @smallexample @@ -4048,7 +4049,7 @@ Now we grind through the formula: @end group @end smallexample -That gives us the slope @cite{m}. The y-intercept @cite{b} can now +That gives us the slope @expr{m}. The y-intercept @expr{b} can now be found with the simple formula, @ifinfo @@ -4074,8 +4075,10 @@ $$ b = {\sum y - m \sum x \over N} $$ @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 +Let's ``plot'' this straight line approximation, +@texline @math{y \approx m x + b}, +@infoline @expr{m x + b}, +and compare it with the original data. @smallexample @group @@ -4092,7 +4095,7 @@ to a vector, can be done without mapping commands since these are common operations from vector algebra. As far as Calc is concerned, we've just been doing geometry in 19-dimensional space! -We can subtract this vector from our original @cite{y} vector to get +We can subtract this vector from our original @expr{y} vector to get a feel for the error of our fit. Let's find the maximum error: @smallexample @@ -4143,7 +4146,13 @@ graphics window. For other kinds of displays, the default is to display the graph in Emacs itself using rough character graphics. Press @kbd{q} when you are done viewing the character graphics. -Next, let's add the line we got from our least-squares fit: +Next, let's add the line we got from our least-squares fit. +@ifinfo +(If you are reading this tutorial on-line while running Calc, typing +@kbd{g a} may cause the tutorial to disappear from its window and be +replaced by a buffer named @samp{*Gnuplot Commands*}. The tutorial +will reappear when you terminate GNUPLOT by typing @kbd{g q}.) +@end ifinfo @smallexample @group @@ -4161,9 +4170,9 @@ when you are done to remove the X graphics window and terminate GNUPLOT. (@bullet{}) @strong{Exercise 2.} An earlier exercise showed how to do least squares fitting to a general system of equations. Our 19 data -points are really 19 equations of the form @cite{y_i = m x_i + b} for -different pairs of @cite{(x_i,y_i)}. Use the matrix-transpose method -to solve for @cite{m} and @cite{b}, duplicating the above result. +points are really 19 equations of the form @expr{y_i = m x_i + b} for +different pairs of @expr{(x_i,y_i)}. Use the matrix-transpose method +to solve for @expr{m} and @expr{b}, duplicating the above result. @xref{List Answer 2, 2}. (@bullet{}) @cindex Geometric mean @@ -4191,7 +4200,7 @@ us that the alternating sum of binomial coefficients @var{n}-choose-0 minus @var{n}-choose-1 plus @var{n}-choose-2, and so on up to @var{n}-choose-@var{n}, always comes out to zero. Let's verify this -for @cite{n=6}.@refill +for @expr{n=6}. @end ifinfo @tex As another example, a theorem about binomial coefficients tells @@ -4262,13 +4271,13 @@ element of a plain vector. With a negative argument, @kbd{v r} and @kbd{v c} instead delete one row, column, or vector element. @cindex Divisor functions -(@bullet{}) @strong{Exercise 4.} The @cite{k}th @dfn{divisor function} +(@bullet{}) @strong{Exercise 4.} The @expr{k}th @dfn{divisor function} @tex $\sigma_k(n)$ @end tex -is the sum of the @cite{k}th powers of all the divisors of an -integer @cite{n}. Figure out a method for computing the divisor -function for reasonably small values of @cite{n}. As a test, +is the sum of the @expr{k}th powers of all the divisors of an +integer @expr{n}. Figure out a method for computing the divisor +function for reasonably small values of @expr{n}. As a test, the 0th and 1st divisor functions of 30 are 8 and 72, respectively. @xref{List Answer 4, 4}. (@bullet{}) @@ -4320,23 +4329,24 @@ command to enable multi-line display of vectors.) @cindex Maximizing a function over a list of values @c [fix-ref Numerical Solutions] (@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's -@c{$J_1(x)$} -@cite{J1} function @samp{besJ(1,x)} for @cite{x} from 0 to 5 -in steps of 0.25. -Find the value of @cite{x} (from among the above set of values) for +@texline @math{J_1(x)} +@infoline @expr{J1} +function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25. +Find the value of @expr{x} (from among the above set of values) for which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, i.e., just reading along the list by hand to find the largest value is not allowed! (There is an @kbd{a X} command which does this kind of thing automatically; @pxref{Numerical Solutions}.) -@xref{List Answer 8, 8}. (@bullet{})@refill +@xref{List Answer 8, 8}. (@bullet{}) @cindex Digits, vectors of (@bullet{}) @strong{Exercise 9.} You are given an integer in the range -@c{$0 \le N < 10^m$} -@cite{0 <= N < 10^m} for @cite{m=12} (i.e., an integer of less than -twelve digits). Convert this integer into a vector of @cite{m} +@texline @math{0 \le N < 10^m} +@infoline @expr{0 <= N < 10^m} +for @expr{m=12} (i.e., an integer of less than +twelve digits). Convert this integer into a vector of @expr{m} digits, each in the range from 0 to 9. In vector-of-digits notation, -add one to this integer to produce a vector of @cite{m+1} digits +add one to this integer to produce a vector of @expr{m+1} digits (since there could be a carry out of the most significant digit). Convert this vector back into a regular integer. A good integer to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) @@ -4346,40 +4356,39 @@ to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) (@bullet{}) @strong{Exercise 11.} The area of a circle of radius one -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 @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$} -@cite{pi}. The @w{@kbd{k r}} +is @cpi{}. The area of the +@texline @math{2\times2} +@infoline 2x2 +square that encloses that circle is 4. So if we throw @var{n} darts at +random points in the square, about @cpiover{4} of them will land inside +the circle. This gives us an entertaining way to estimate the value of +@cpi{}. The @w{@kbd{k r}} command picks a random number between zero and the value on the stack. -We could get a random floating-point number between @i{-1} and 1 by typing -@w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @cite{(x,y)} points in +We could get a random floating-point number between @mathit{-1} and 1 by typing +@w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @expr{(x,y)} points in this square, then use vector mapping and reduction to count how many points lie inside the unit circle. Hint: Use the @kbd{v b} command. @xref{List Answer 11, 11}. (@bullet{}) @cindex Matchstick problem (@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides -another way to calculate @c{$\pi$} -@cite{pi}. Say you have an infinite field +another way to calculate @cpi{}. Say you have an infinite field of vertical lines with a spacing of one inch. Toss a one-inch matchstick onto the field. The probability that the matchstick will land crossing -a line turns out to be @c{$2/\pi$} -@cite{2/pi}. Toss 100 matchsticks to estimate -@c{$\pi$} -@cite{pi}. (If you want still more fun, the probability that the GCD -(@w{@kbd{k g}}) of two large integers is one turns out to be @c{$6/\pi^2$} -@cite{6/pi^2}. -That provides yet another way to estimate @c{$\pi$} -@cite{pi}.) +a line turns out to be +@texline @math{2/\pi}. +@infoline @expr{2/pi}. +Toss 100 matchsticks to estimate @cpi{}. (If you want still more fun, +the probability that the GCD (@w{@kbd{k g}}) of two large integers is +one turns out to be +@texline @math{6/\pi^2}. +@infoline @expr{6/pi^2}. +That provides yet another way to estimate @cpi{}.) @xref{List Answer 12, 12}. (@bullet{}) (@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in double-quote marks, @samp{"hello"}, creates a vector of the numerical -(ASCII) codes of the characters (here, @cite{[104, 101, 108, 108, 111]}). +(ASCII) codes of the characters (here, @expr{[104, 101, 108, 108, 111]}). Sometimes it is convenient to compute a @dfn{hash code} of a string, which is just an integer that represents the value of that string. Two equal strings have the same hash code; two different strings @@ -4388,9 +4397,9 @@ over 400 function names, but Emacs can quickly find the definition for any given name because it has sorted the functions into ``buckets'' by their hash codes. Sometimes a few names will hash into the same bucket, but it is easier to search among a few names than among all the names.) -One popular hash function is computed as follows: First set @cite{h = 0}. -Then, for each character from the string in turn, set @cite{h = 3h + c_i} -where @cite{c_i} is the character's ASCII code. If we have 511 buckets, +One popular hash function is computed as follows: First set @expr{h = 0}. +Then, for each character from the string in turn, set @expr{h = 3h + c_i} +where @expr{c_i} is the character's ASCII code. If we have 511 buckets, we then take the hash code modulo 511 to get the bucket number. Develop a simple command or commands for converting string vectors into hash codes. The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo @@ -4402,8 +4411,8 @@ value and a number of steps @var{n} from the stack; it then applies the function you give to the starting value 0, 1, 2, up to @var{n} times and returns a vector of the results. Use this command to create a ``random walk'' of 50 steps. Start with the two-dimensional point -@cite{(0,0)}; then take one step a random distance between @i{-1} and 1 -in both @cite{x} and @cite{y}; then take another step, and so on. Use the +@expr{(0,0)}; then take one step a random distance between @mathit{-1} and 1 +in both @expr{x} and @expr{y}; then take another step, and so on. Use the @kbd{g f} command to display this random walk. Now modify your random walk to walk a unit distance, but in a random direction, at each step. (Hint: The @code{sincos} function returns a vector of the cosine and @@ -4466,8 +4475,7 @@ same, to within the current precision. (@bullet{}) @strong{Exercise 1.} A calculation has produced the result 1.26508260337. You suspect it is the square root of the -product of @c{$\pi$} -@cite{pi} and some rational number. Is it? (Be sure +product of @cpi{} and some rational number. Is it? (Be sure to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{}) @dfn{Complex numbers} can be stored in both rectangular and polar form. @@ -4482,8 +4490,8 @@ to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{}) @end smallexample @noindent -The square root of @i{-9} is by default rendered in rectangular form -(@w{@cite{0 + 3i}}), but we can convert it to polar form (3 with a +The square root of @mathit{-9} is by default rendered in rectangular form +(@w{@expr{0 + 3i}}), but we can convert it to polar form (3 with a phase angle of 90 degrees). All the usual arithmetic and scientific operations are defined on both types of complex numbers. @@ -4507,22 +4515,22 @@ algebraic entry. @noindent Since infinity is infinitely large, multiplying it by any finite -number (like @i{-17}) has no effect, except that since @i{-17} +number (like @mathit{-17}) has no effect, except that since @mathit{-17} is negative, it changes a plus infinity to a minus infinity. -(``A huge positive number, multiplied by @i{-17}, yields a huge +(``A huge positive number, multiplied by @mathit{-17}, yields a huge negative number.'') Adding any finite number to infinity also leaves it unchanged. Taking an absolute value gives us plus 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 +the answer to be @mathit{-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). 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.'' +to turn on Infinite mode. @smallexample @group @@ -4539,9 +4547,9 @@ to turn on ``infinite mode.'' Dividing by zero normally is left unevaluated, but after @kbd{m i} it instead gives an infinite result. The answer is actually @code{uinf}, ``undirected infinity.'' If you look at a graph of -@cite{1 / x} around @w{@cite{x = 0}}, you'll see that it goes toward +@expr{1 / x} around @w{@expr{x = 0}}, you'll see that it goes toward plus infinity as you approach zero from above, but toward minus -infinity as you approach from below. Since we said only @cite{1 / 0}, +infinity as you approach from below. Since we said only @expr{1 / 0}, Calc knows that the answer is infinite but not in which direction. That's what @code{uinf} means. Notice that multiplying @code{uinf} by a negative number still leaves plain @code{uinf}; there's no @@ -4671,10 +4679,11 @@ a 60% chance that the result is correct within 0.59 degrees. @cindex Torus, volume of (@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is -@c{$2 \pi^2 R r^2$} -@w{@cite{2 pi^2 R r^2}} where @cite{R} is the radius of the circle that -defines the center of the tube and @cite{r} is the radius of the tube -itself. Suppose @cite{R} is 20 cm and @cite{r} is 4 cm, each known to +@texline @math{2 \pi^2 R r^2} +@infoline @w{@expr{2 pi^2 R r^2}} +where @expr{R} is the radius of the circle that +defines the center of the tube and @expr{r} is the radius of the tube +itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to within 5 percent. What is the volume and the relative uncertainty of the volume? @xref{Types Answer 7, 7}. (@bullet{}) @@ -4748,10 +4757,11 @@ or 24 hours. @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 @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. +In this last step, Calc has divided by 5 modulo 24; i.e., it has found a +new number which, when multiplied by 5 modulo 24, produces the original +number, 21. If @var{m} is prime and the divisor is not a multiple of +@var{m}, it is always possible to find such a number. For non-prime +@var{m} like 24, it is only sometimes possible. @smallexample @group @@ -4769,14 +4779,15 @@ that arises in the second one. @cindex Fermat, primality test of (@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat -says that @c{\w{$x^{n-1} \bmod n = 1$}} -@cite{x^(n-1) mod n = 1} if @cite{n} is a prime number -and @cite{x} is an integer less than @cite{n}. If @cite{n} is -@emph{not} a prime number, this will @emph{not} be true for most -values of @cite{x}. Thus we can test informally if a number is -prime by trying this formula for several values of @cite{x}. -Use this test to tell whether the following numbers are prime: -811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{}) +says that +@texline @w{@math{x^{n-1} \bmod n = 1}} +@infoline @expr{x^(n-1) mod n = 1} +if @expr{n} is a prime number and @expr{x} is an integer less than +@expr{n}. If @expr{n} is @emph{not} a prime number, this will +@emph{not} be true for most values of @expr{x}. Thus we can test +informally if a number is prime by trying this formula for several +values of @expr{x}. Use this test to tell whether the following numbers +are prime: 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{}) It is possible to use HMS forms as parts of error forms, intervals, modulo forms, or as the phase part of a polar complex number. @@ -4796,9 +4807,11 @@ of day on the stack as an HMS/modulo form. This calculation tells me it is six hours and 22 minutes until midnight. (@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year -is about @c{$\pi \times 10^7$} -@w{@cite{pi * 10^7}} seconds. What time will it be that -many seconds from right now? @xref{Types Answer 11, 11}. (@bullet{}) +is about +@texline @math{\pi \times 10^7} +@infoline @w{@expr{pi * 10^7}} +seconds. What time will it be that many seconds from right now? +@xref{Types Answer 11, 11}. (@bullet{}) (@bullet{}) @strong{Exercise 12.} You are preparing to order packaging for the CD release of the Extended Disco Version of @emph{Abbey Road}. @@ -4948,7 +4961,7 @@ formulas. @subsection Basic Algebra @noindent -If you enter a formula in algebraic mode that refers to variables, +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. @@ -4979,9 +4992,9 @@ formulas. Continuing with the formula from the last example, @noindent First we ``expand'' using the distributive law, then we ``collect'' -terms involving like powers of @cite{x}. +terms involving like powers of @expr{x}. -Let's find the value of this expression when @cite{x} is 2 and @cite{y} +Let's find the value of this expression when @expr{x} is 2 and @expr{y} is one-half. @smallexample @@ -5006,11 +5019,11 @@ unstore it with @kbd{s u x @key{RET}} before the above example will work properly.) @cindex Maximum of a function using Calculus -Let's find the maximum value of our original expression when @cite{y} -is one-half and @cite{x} ranges over all possible values. We can -do this by taking the derivative with respect to @cite{x} and examining -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, +Let's find the maximum value of our original expression when @expr{y} +is one-half and @expr{x} ranges over all possible values. We can +do this by taking the derivative with respect to @expr{x} and examining +values of @expr{x} for which the derivative is zero. If the second +derivative of the function at that value of @expr{x} is negative, the function has a local maximum there. @smallexample @@ -5023,8 +5036,8 @@ the function has a local maximum there. @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: +Well, the derivative is clearly zero when @expr{x} is zero. To find +the other root(s), let's divide through by @expr{x} and then solve: @smallexample @group @@ -5050,7 +5063,7 @@ Notice the use of @kbd{a s} to ``simplify'' the formula. When the default algebraic simplifications don't do enough, you can use @kbd{a s} to tell Calc to spend more time on the job. -Now we compute the second derivative and plug in our values of @cite{x}: +Now we compute the second derivative and plug in our values of @expr{x}: @smallexample @group @@ -5080,14 +5093,14 @@ to delete the @samp{x}.) @noindent The first of these second derivatives is negative, so we know the function -has a maximum value at @cite{x = 1.19023}. (The function also has a -local @emph{minimum} at @cite{x = 0}.) +has a maximum value at @expr{x = 1.19023}. (The function also has a +local @emph{minimum} at @expr{x = 0}.) -When we solved for @cite{x}, we got only one value even though -@cite{34 - 24 x^2 = 0} is a quadratic equation that ought to have +When we solved for @expr{x}, we got only one value even though +@expr{34 - 24 x^2 = 0} is a quadratic equation that ought to have two solutions. The reason is that @w{@kbd{a S}} normally returns a single ``principal'' solution. If it needs to come up with an -arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}. +arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}. 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}. @@ -5102,12 +5115,12 @@ solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}. @noindent Calc has invented the variable @samp{s1} to represent an unknown sign; -it is supposed to be either @i{+1} or @i{-1}. Here we have used +it is supposed to be either @mathit{+1} or @mathit{-1}. Here we have used the ``let'' command to evaluate the expression when the sign is negative. If we plugged this into our second derivative we would get the same, -negative, answer, so @cite{x = -1.19023} is also a maximum. +negative, answer, so @expr{x = -1.19023} is also a maximum. -To find the actual maximum value, we must plug our two values of @cite{x} +To find the actual maximum value, we must plug our two values of @expr{x} into the original formula. @smallexample @@ -5157,7 +5170,7 @@ Calc has a built-in @kbd{a P} command that solves an equation using @w{@kbd{H a S}} and returns a vector of all the solutions. It simply automates the job we just did by hand. Applied to our original cubic polynomial, it would produce the vector of solutions -@cite{[1.19023, -1.19023, 0]}. (There is also an @kbd{a X} command +@expr{[1.19023, -1.19023, 0]}. (There is also an @kbd{a X} command which finds a local maximum of a function. It uses a numerical search method rather than examining the derivatives, and thus requires you to provide some kind of initial guess to show it where to look.) @@ -5169,7 +5182,7 @@ polynomial? (The answer will be unique to within a constant multiple; choose the solution where the leading coefficient is one.) @xref{Algebra Answer 2, 2}. (@bullet{}) -The @kbd{m s} command enables ``symbolic mode,'' in which formulas +The @kbd{m s} command enables Symbolic mode, in which formulas 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. @@ -5184,7 +5197,7 @@ Fraction mode (@kbd{m f}) is also useful when doing algebra. @end group @end smallexample -One more mode that makes reading formulas easier is ``Big mode.'' +One more mode that makes reading formulas easier is Big mode. @smallexample @group @@ -5204,7 +5217,8 @@ One more mode that makes reading formulas easier is ``Big mode.'' 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. +language modes as well, such as C mode, FORTRAN mode, @TeX{} mode +and @LaTeX{} mode. @smallexample @group @@ -5245,7 +5259,7 @@ may prefer to remain in Big mode, but all the examples in the tutorial are shown in normal mode.) @cindex Area under a curve -What is the area under the portion of this curve from @cite{x = 1} to @cite{2}? +What is the area under the portion of this curve from @expr{x = 1} to @expr{2}? This is simply the integral of the function: @smallexample @@ -5258,7 +5272,7 @@ This is simply the integral of the function: @end smallexample @noindent -We want to evaluate this at our two values for @cite{x} and subtract. +We want to evaluate this at our two values for @expr{x} and subtract. One way to do it is again with vector mapping and reduction: @smallexample @@ -5270,20 +5284,23 @@ One way to do it is again with vector mapping and reduction: @end group @end smallexample -(@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @cite{y} -of @c{$x \sin \pi x$} -@w{@cite{x sin(pi x)}} (where the sine is calculated in radians). -Find the values of the integral for integers @cite{y} from 1 to 5. -@xref{Algebra Answer 3, 3}. (@bullet{}) +(@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @expr{y} +of +@texline @math{x \sin \pi x} +@infoline @w{@expr{x sin(pi x)}} +(where the sine is calculated in radians). Find the values of the +integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3, +3}. (@bullet{}) 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 @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? +under the curve +@texline @math{\sin x \ln x} +@infoline @expr{sin(x) ln(x)} +over the same range of @expr{x}. If 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? @cindex Integration, numerical @cindex Numerical integration @@ -5329,7 +5346,7 @@ also have used plain @kbd{v x} as follows: @kbd{v x 10 @key{RET} 9 + .1 *}.) @noindent (If you got wildly different results, did you remember to switch -to radians mode?) +to Radians mode?) Here we have divided the curve into ten segments of equal width; approximating these segments as rectangular boxes (i.e., assuming @@ -5352,7 +5369,7 @@ we're not doing too well. Let's try another approach. @noindent Here we have computed the Taylor series expansion of the function -about the point @cite{x=1}. We can now integrate this polynomial +about the point @expr{x=1}. We can now integrate this polynomial approximation, since polynomials are easy to integrate. @smallexample @@ -5369,8 +5386,8 @@ Better! By increasing the precision and/or asking for more terms in the Taylor series, we can get a result as accurate as we like. (Taylor series converge better away from singularities in the function such as the one at @code{ln(0)}, so it would also help to -expand the series about the points @cite{x=2} or @cite{x=1.5} instead -of @cite{x=1}.) +expand the series about the points @expr{x=2} or @expr{x=1.5} instead +of @expr{x=1}.) @cindex Simpson's rule @cindex Integration by Simpson's rule @@ -5400,7 +5417,7 @@ $$ \displaylines{ @end tex @noindent -where @cite{n} (which must be even) is the number of slices and @cite{h} +where @expr{n} (which must be even) is the number of slices and @expr{h} is the width of each slice. These are 10 and 0.1 in our example. For reference, here is the corresponding formula for the stairstep method: @@ -5419,9 +5436,11 @@ $$ h (f(a) + f(a+h) + f(a+2h) + f(a+3h) + \cdots \afterdisplay @end tex -Compute the integral from 1 to 2 of @c{$\sin x \ln x$} -@cite{sin(x) ln(x)} using -Simpson's rule with 10 slices. @xref{Algebra Answer 4, 4}. (@bullet{}) +Compute the integral from 1 to 2 of +@texline @math{\sin x \ln x} +@infoline @expr{sin(x) ln(x)} +using Simpson's rule with 10 slices. +@xref{Algebra Answer 4, 4}. (@bullet{}) Calc has a built-in @kbd{a I} command for doing numerical integration. It uses @dfn{Romberg's method}, which is a more sophisticated cousin @@ -5570,8 +5589,8 @@ having to retype it. @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 -@kbd{C-c C-c} to store the edited value back into the variable. +Emacs editing commands as necessary, then type @kbd{C-c C-c} to store +the edited value back into the variable. You can also use @w{@kbd{s e}} to create a new variable if you wish. Notice that the first time you use each rule, Calc puts up a ``compiling'' @@ -5583,7 +5602,7 @@ only once and stores the compiled form along with the variable. That's another good reason to store your rules in variables rather than entering them on the fly. -(@bullet{}) @strong{Exercise 1.} Type @kbd{m s} to get symbolic +(@bullet{}) @strong{Exercise 1.} Type @kbd{m s} to get Symbolic mode, then enter the formula @samp{@w{(2 + sqrt(2))} / @w{(1 + sqrt(2))}}. Using a rewrite rule, simplify this formula by multiplying both sides by the conjugate @w{@samp{1 - sqrt(2)}}. The result will have @@ -5669,7 +5688,7 @@ constants @samp{e}, @samp{phi}, and so on also match literally. A common error with rewrite rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting to match any @samp{f} with five arguments but in fact matching -only when the fifth argument is literally @samp{e}!@refill +only when the fifth argument is literally @samp{e}! @cindex Fibonacci numbers @ignore @@ -5819,10 +5838,10 @@ on the stack and tried to use the rule @samp{opt(a) + opt(b) x := f(a, b, x)}. What happened? @xref{Rewrites Answer 3, 3}. (@bullet{}) -(@bullet{}) @strong{Exercise 4.} Starting with a positive integer @cite{a}, -divide @cite{a} by two if it is even, otherwise compute @cite{3 a + 1}. +(@bullet{}) @strong{Exercise 4.} Starting with a positive integer @expr{a}, +divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}. Now repeat this step over and over. A famous unproved conjecture -is that for any starting @cite{a}, the sequence always eventually +is that for any starting @expr{a}, the sequence always eventually reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of rules that convert this into @samp{seq(1, @var{n})} where @var{n} is the number of steps it took the sequence to reach the value 1. @@ -5831,27 +5850,19 @@ configuration, and to stop with just the number @var{n} by itself. Now make the result be a vector of values in the sequence, from @var{a} to 1. (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x} and @var{y}.) For example, rewriting @samp{seq(6)} should yield the -vector @cite{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. +vector @expr{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. @xref{Rewrites Answer 4, 4}. (@bullet{}) (@bullet{}) @strong{Exercise 5.} Define, using rewrite rules, a function @samp{nterms(@var{x})} that returns the number of terms in the sum @var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes is one or more non-sum terms separated by @samp{+} or @samp{-} signs, -so that @cite{2 - 3 (x + y) + x y} is a sum of three terms.) +so that @expr{2 - 3 (x + y) + x y} is a sum of three terms.) @xref{Rewrites Answer 5, 5}. (@bullet{}) -(@bullet{}) @strong{Exercise 6.} Calc considers the form @cite{0^0} -to be ``indeterminate,'' and leaves it unevaluated (assuming infinite -mode is not enabled). Some people prefer to define @cite{0^0 = 1}, -so that the identity @cite{x^0 = 1} can safely be used for all @cite{x}. -Find a way to make Calc follow this convention. What happens if you -now type @kbd{m i} to turn on infinite mode? -@xref{Rewrites Answer 6, 6}. (@bullet{}) - -(@bullet{}) @strong{Exercise 7.} A Taylor series for a function is an +(@bullet{}) @strong{Exercise 6.} A Taylor series for a function is an infinite series that exactly equals the value of that function at -values of @cite{x} near zero. +values of @expr{x} near zero. @ifinfo @example @@ -5859,15 +5870,15 @@ cos(x) = 1 - x^2 / 2! + x^4 / 4! - x^6 / 6! + ... @end example @end ifinfo @tex -\turnoffactive \let\rm\goodrm +\turnoffactive \beforedisplay $$ \cos x = 1 - {x^2 \over 2!} + {x^4 \over 4!} - {x^6 \over 6!} + \cdots $$ \afterdisplay @end tex The @kbd{a t} command produces a @dfn{truncated Taylor series} which -is obtained by dropping all the terms higher than, say, @cite{x^2}. -Calc represents the truncated Taylor series as a polynomial in @cite{x}. +is obtained by dropping all the terms higher than, say, @expr{x^2}. +Calc represents the truncated Taylor series as a polynomial in @expr{x}. Mathematicians often write a truncated series using a ``big-O'' notation that records what was the lowest term that was truncated. @@ -5877,15 +5888,15 @@ cos(x) = 1 - x^2 / 2! + O(x^3) @end example @end ifinfo @tex -\turnoffactive \let\rm\goodrm +\turnoffactive \beforedisplay $$ \cos x = 1 - {x^2 \over 2!} + O(x^3) $$ \afterdisplay @end tex @noindent -The meaning of @cite{O(x^3)} is ``a quantity which is negligibly small -if @cite{x^3} is considered negligibly small as @cite{x} goes to zero.'' +The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small +if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.'' The exercise is to create rewrite rules that simplify sums and products of power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}. @@ -5895,9 +5906,12 @@ on the stack, we want to be able to type @kbd{*} and get the result rearranged or if @kbd{a s} needs to be typed after rewriting. (This one is rather tricky; the solution at the end of this chapter uses 6 rewrite rules. Hint: The @samp{constant(x)} condition tests whether @samp{x} is -a number.) @xref{Rewrites Answer 7, 7}. (@bullet{}) +a number.) @xref{Rewrites Answer 6, 6}. (@bullet{}) + +Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}. +What happens? (Be sure to remove this rule afterward, or you might get +a nasty surprise when you use Calc to balance your checkbook!) -@c [fix-ref Rewrite Rules] @xref{Rewrite Rules}, for the whole story on rewrite rules. @node Programming Tutorial, Answers to Exercises, Algebra Tutorial, Tutorial @@ -5911,9 +5925,6 @@ system. But Lisp and rewrite rules take a while to master, and often all you want to do is define a new function or repeat a command a few times. Calc has features that allow you to do these things easily. -(Note that the programming commands relating to user-defined keys -are not yet supported under Lucid Emacs 19.) - One very limited form of programming is defining your own functions. Calc's @kbd{Z F} command allows you to define a function name and key sequence to correspond to any formula. Programming commands use @@ -5964,9 +5975,10 @@ in @samp{a + 1} for @samp{x} in the defining formula. @end ignore @tindex Si (@bullet{}) @strong{Exercise 1.} The ``sine integral'' function -@c{${\rm Si}(x)$} -@cite{Si(x)} is defined as the integral of @samp{sin(t)/t} for -@cite{t = 0} to @cite{x} in radians. (It was invented because this +@texline @math{{\rm Si}(x)} +@infoline @expr{Si(x)} +is defined as the integral of @samp{sin(t)/t} for +@expr{t = 0} to @expr{x} in radians. (It was invented because this integral has no solution in terms of basic functions; if you give it to Calc's @kbd{a i} command, it will ponder it for a long time and then give up.) We can use the numerical integration command, however, @@ -5974,8 +5986,9 @@ which in algebraic notation is written like @samp{ninteg(f(t), t, 0, x)} with any integrand @samp{f(t)}. Define a @kbd{z s} command and @code{Si} function that implement this. You will need to edit the default argument list a bit. As a test, @samp{Si(1)} should return -0.946083. (Hint: @code{ninteg} will run a lot faster if you reduce -the precision to, say, six digits beforehand.) +0.946083. (If you don't get this answer, you might want to check that +Calc is in Radians mode. Also, @code{ninteg} will run a lot faster if +you reduce the precision to, say, six digits beforehand.) @xref{Programming Answer 1, 1}. (@bullet{}) The simplest way to do real ``programming'' of Emacs is to define a @@ -6040,12 +6053,13 @@ the following functions: @enumerate @item -Compute @c{$\displaystyle{\sin x \over x}$} -@cite{sin(x) / x}, where @cite{x} is the number on the -top of the stack. +Compute +@texline @math{\displaystyle{\sin x \over x}}, +@infoline @expr{sin(x) / x}, +where @expr{x} is the number on the top of the stack. @item -Compute the base-@cite{b} logarithm, just like the @kbd{B} key except +Compute the base-@expr{b} logarithm, just like the @kbd{B} key except the arguments are taken in the opposite order. @item @@ -6074,7 +6088,7 @@ inside keyboard macros, but actually work at any time. @end smallexample @noindent -Here we have computed the fourth derivative of @cite{x^6} by +Here we have computed the fourth derivative of @expr{x^6} by enclosing a derivative command in a ``repeat loop'' structure. This structure pops a repeat count from the stack, then executes the body of the loop that many times. @@ -6104,14 +6118,18 @@ key if you have one, makes a copy of the number in level 2.) @cindex Golden ratio @cindex Phi, golden ratio -A fascinating property of the Fibonacci numbers is that the @cite{n}th -Fibonacci number can be found directly by computing @c{$\phi^n / \sqrt{5}$} -@cite{phi^n / sqrt(5)} -and then rounding to the nearest integer, where @c{$\phi$ (``phi'')} -@cite{phi}, the -``golden ratio,'' is @c{$(1 + \sqrt{5}) / 2$} -@cite{(1 + sqrt(5)) / 2}. (For convenience, this constant is available -from the @code{phi} variable, or the @kbd{I H P} command.) +A fascinating property of the Fibonacci numbers is that the @expr{n}th +Fibonacci number can be found directly by computing +@texline @math{\phi^n / \sqrt{5}} +@infoline @expr{phi^n / sqrt(5)} +and then rounding to the nearest integer, where +@texline @math{\phi} (``phi''), +@infoline @expr{phi}, +the ``golden ratio,'' is +@texline @math{(1 + \sqrt{5}) / 2}. +@infoline @expr{(1 + sqrt(5)) / 2}. +(For convenience, this constant is available from the @code{phi} +variable, or the @kbd{I H P} command.) @smallexample @group @@ -6124,22 +6142,28 @@ from the @code{phi} variable, or the @kbd{I H P} command.) @cindex Continued fractions (@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} -representation of @c{$\phi$} -@cite{phi} is @c{$1 + 1/(1 + 1/(1 + 1/( \ldots )))$} -@cite{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. +representation of +@texline @math{\phi} +@infoline @expr{phi} +is +@texline @math{1 + 1/(1 + 1/(1 + 1/( \ldots )))}. +@infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. We can compute an approximate value by carrying this however far -and then replacing the innermost @c{$1/( \ldots )$} -@cite{1/( ...@: )} by 1. Approximate -@c{$\phi$} -@cite{phi} using a twenty-term continued fraction. +and then replacing the innermost +@texline @math{1/( \ldots )} +@infoline @expr{1/( ...@: )} +by 1. Approximate +@texline @math{\phi} +@infoline @expr{phi} +using a twenty-term continued fraction. @xref{Programming Answer 5, 5}. (@bullet{}) (@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for Fibonacci numbers can be expressed in terms of matrices. Given a -vector @w{@cite{[a, b]}} determine a matrix which, when multiplied by this -vector, produces the vector @cite{[b, c]}, where @cite{a}, @cite{b} and -@cite{c} are three successive Fibonacci numbers. Now write a program -that, given an integer @cite{n}, computes the @cite{n}th Fibonacci number +vector @w{@expr{[a, b]}} determine a matrix which, when multiplied by this +vector, produces the vector @expr{[b, c]}, where @expr{a}, @expr{b} and +@expr{c} are three successive Fibonacci numbers. Now write a program +that, given an integer @expr{n}, computes the @expr{n}th Fibonacci number using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{}) @cindex Harmonic numbers @@ -6228,12 +6252,13 @@ survive past the @kbd{Z '} command. The @dfn{Bernoulli numbers} are a sequence with the interesting property that all of the odd Bernoulli numbers are zero, and the even ones, while difficult to compute, can be roughly approximated -by the formula @c{$\displaystyle{2 n! \over (2 \pi)^n}$} -@cite{2 n!@: / (2 pi)^n}. Let's write a keyboard -macro to compute (approximate) Bernoulli numbers. (Calc has a -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.) +by the formula +@texline @math{\displaystyle{2 n! \over (2 \pi)^n}}. +@infoline @expr{2 n!@: / (2 pi)^n}. +Let's write a keyboard macro to compute (approximate) Bernoulli numbers. +(Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but +this command is very slow for large @expr{n} since the higher Bernoulli +numbers are very large fractions.) @smallexample @group @@ -6253,7 +6278,7 @@ if it pops zero or something that is not a number (like a formula). Here we take our integer argument modulo 2; this will be nonzero if we're asking for an odd Bernoulli number. -The actual tenth Bernoulli number is @cite{5/66}. +The actual tenth Bernoulli number is @expr{5/66}. @smallexample @group @@ -6302,55 +6327,56 @@ then enter the real one in the edit command. @smallexample @group -1: 3 1: 3 Keyboard Macro Editor. - . . Original keys: 1 @key{RET} 2 + +1: 3 1: 3 Calc Macro Edit Mode. + . . Original keys: 1 2 + - type "1\r" - type "2" - calc-plus + 1 ;; calc digits + RET ;; calc-enter + 2 ;; calc digits + + ;; calc-plus 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} -keyboard macro editing package installed, which is usually the case -since a copy of @file{macedit} comes bundled with Calc. - A keyboard macro is stored as a pure keystroke sequence. The -@file{macedit} package (invoked by @kbd{Z E}) scans along the +@file{edmacro} package (invoked by @kbd{Z E}) scans along the macro and tries to decode it back into human-readable steps. -If a key or keys are simply shorthand for some command with a -@kbd{M-x} name, that name is shown. Anything that doesn't correspond -to a @kbd{M-x} command is written as a @samp{type} command. +Descriptions of the keystrokes are given as comments, which begin with +@samp{;;}, and which are ignored when the edited macro is saved. +Spaces and line breaks are also ignored when the edited macro is saved. +To enter a space into the macro, type @code{SPC}. All the special +characters @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, @code{DEL}, +and @code{NUL} must be written in all uppercase, as must the prefixes +@code{C-} and @code{M-}. Let's edit in a new definition, for computing harmonic numbers. -First, erase the three lines of the old definition. Then, type +First, erase the four lines of the old definition. Then, type in the new definition (or use Emacs @kbd{M-w} and @kbd{C-y} commands -to copy it from this page of the Info file; you can skip typing -the comments that begin with @samp{#}). +to copy it from this page of the Info file; you can of course skip +typing the comments, which begin with @samp{;;}). @smallexample -calc-kbd-push # Save local values (Z `) -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 @key{TAB} key; swap initial & final -calc-kbd-for # Begin "for" loop... -calc-inv # Take reciprocal -calc-store-plus # Add to accumulator -type "1" -type "1" # Loop step is 1 -calc-kbd-end-for # End "for" loop -calc-recall # Now recall final accumulated value -type "1" -calc-kbd-pop # Restore values (Z ') +Z` ;; calc-kbd-push (Save local values) +0 ;; calc digits (Push a zero onto the stack) +st ;; calc-store-into (Store it in the following variable) +1 ;; calc quick variable (Quick variable q1) +1 ;; calc digits (Initial value for the loop) +TAB ;; calc-roll-down (Swap initial and final) +Z( ;; calc-kbd-for (Begin the "for" loop) +& ;; calc-inv (Take the reciprocal) +s+ ;; calc-store-plus (Add to the following variable) +1 ;; calc quick variable (Quick variable q1) +1 ;; calc digits (The loop step is 1) +Z) ;; calc-kbd-end-for (End the "for" loop) +sr ;; calc-recall (Recall the final accumulated value) +1 ;; calc quick variable (Quick variable q1) +Z' ;; calc-kbd-pop (Restore values) @end smallexample @noindent -Press @kbd{M-# M-#} to finish editing and return to the Calculator. +Press @kbd{C-c C-c} to finish editing and return to the Calculator. @smallexample @group @@ -6361,21 +6387,18 @@ Press @kbd{M-# M-#} to finish editing and return to the Calculator. @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. -There is also a @code{keys} command which interprets the rest of the -line as standard Emacs keystroke names. In fact, @file{macedit} defines -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-@key{SPC}}) at +The @file{edmacro} package defines 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-@key{SPC}}) at one end of the text below, then type @kbd{M-# m} at the other. @example @group Z ` 0 t 1 - 1 @key{TAB} + 1 TAB Z ( & s + 1 1 Z ) r 1 Z ' @@ -6384,8 +6407,8 @@ Z ' (@bullet{}) @strong{Exercise 8.} A general algorithm for solving equations numerically is @dfn{Newton's Method}. Given the equation -@cite{f(x) = 0} for any function @cite{f}, and an initial guess -@cite{x_0} which is reasonably close to the desired solution, apply +@expr{f(x) = 0} for any function @expr{f}, and an initial guess +@expr{x_0} which is reasonably close to the desired solution, apply this formula over and over: @ifinfo @@ -6395,32 +6418,36 @@ new_x = x - f(x)/f'(x) @end ifinfo @tex \beforedisplay -$$ x_{\goodrm new} = x - {f(x) \over f'(x)} $$ +$$ x_{\rm new} = x - {f(x) \over f'(x)} $$ \afterdisplay @end tex @noindent -where @cite{f'(x)} is the derivative of @cite{f}. The @cite{x} +where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x} values will quickly converge to a solution, i.e., eventually -@c{$x_{\rm new}$} -@cite{new_x} and @cite{x} will be equal to within the limits +@texline @math{x_{\rm new}} +@infoline @expr{new_x} +and @expr{x} will be equal to within the limits of the current precision. Write a program which takes a formula -involving the variable @cite{x}, and an initial guess @cite{x_0}, -on the stack, and produces a value of @cite{x} for which the formula -is zero. Use it to find a solution of @c{$\sin(\cos x) = 0.5$} -@cite{sin(cos(x)) = 0.5} -near @cite{x = 4.5}. (Use angles measured in radians.) Note that +involving the variable @expr{x}, and an initial guess @expr{x_0}, +on the stack, and produces a value of @expr{x} for which the formula +is zero. Use it to find a solution of +@texline @math{\sin(\cos x) = 0.5} +@infoline @expr{sin(cos(x)) = 0.5} +near @expr{x = 4.5}. (Use angles measured in radians.) Note that the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's method when it is able. @xref{Programming Answer 8, 8}. (@bullet{}) @cindex Digamma function @cindex Gamma constant, Euler's @cindex Euler's gamma constant -(@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function @c{$\psi(z)$ (``psi'')} -@cite{psi(z)} -is defined as the derivative of @c{$\ln \Gamma(z)$} -@cite{ln(gamma(z))}. For large -values of @cite{z}, it can be approximated by the infinite sum +(@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function +@texline @math{\psi(z) (``psi'')} +@infoline @expr{psi(z)} +is defined as the derivative of +@texline @math{\ln \Gamma(z)}. +@infoline @expr{ln(gamma(z))}. +For large values of @expr{z}, it can be approximated by the infinite sum @ifinfo @example @@ -6428,7 +6455,6 @@ psi(z) ~= ln(z) - 1/2z - sum(bern(2 n) / 2 n z^(2 n), n, 1, inf) @end example @end ifinfo @tex -\let\rm\goodrm \beforedisplay $$ \psi(z) \approx \ln z - {1\over2z} - \sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}} @@ -6437,37 +6463,48 @@ $$ @end tex @noindent -where @c{$\sum$} -@cite{sum} represents the sum over @cite{n} from 1 to infinity +where +@texline @math{\sum} +@infoline @expr{sum} +represents the sum over @expr{n} from 1 to infinity (or to some limit high enough to give the desired accuracy), and the @code{bern} function produces (exact) Bernoulli numbers. While this sum is not guaranteed to converge, in practice it is safe. An interesting mathematical constant is Euler's gamma, which is equal to about 0.5772. One way to compute it is by the formula, -@c{$\gamma = -\psi(1)$} -@cite{gamma = -psi(1)}. Unfortunately, 1 isn't a large enough argument -for the above formula to work (5 is a much safer value for @cite{z}). -Fortunately, we can compute @c{$\psi(1)$} -@cite{psi(1)} from @c{$\psi(5)$} -@cite{psi(5)} using -the recurrence @c{$\psi(z+1) = \psi(z) + {1 \over z}$} -@cite{psi(z+1) = psi(z) + 1/z}. Your task: Develop -a program to compute @c{$\psi(z)$} -@cite{psi(z)}; it should ``pump up'' @cite{z} +@texline @math{\gamma = -\psi(1)}. +@infoline @expr{gamma = -psi(1)}. +Unfortunately, 1 isn't a large enough argument +for the above formula to work (5 is a much safer value for @expr{z}). +Fortunately, we can compute +@texline @math{\psi(1)} +@infoline @expr{psi(1)} +from +@texline @math{\psi(5)} +@infoline @expr{psi(5)} +using the recurrence +@texline @math{\psi(z+1) = \psi(z) + {1 \over z}}. +@infoline @expr{psi(z+1) = psi(z) + 1/z}. +Your task: Develop a program to compute +@texline @math{\psi(z)}; +@infoline @expr{psi(z)}; +it should ``pump up'' @expr{z} if necessary to be greater than 5, then use the above summation formula. Use looping commands to compute the sum. Use your function -to compute @c{$\gamma$} -@cite{gamma} to twelve decimal places. (Calc has a built-in command +to compute +@texline @math{\gamma} +@infoline @expr{gamma} +to twelve decimal places. (Calc has a built-in command for Euler's constant, @kbd{I P}, which you can use to check your answer.) @xref{Programming Answer 9, 9}. (@bullet{}) @cindex Polynomial, list of coefficients -(@bullet{}) @strong{Exercise 10.} Given a polynomial in @cite{x} and -a number @cite{m} on the stack, where the polynomial is of degree -@cite{m} or less (i.e., does not have any terms higher than @cite{x^m}), +(@bullet{}) @strong{Exercise 10.} Given a polynomial in @expr{x} and +a number @expr{m} on the stack, where the polynomial is of degree +@expr{m} or less (i.e., does not have any terms higher than @expr{x^m}), write a program to convert the polynomial into a list-of-coefficients -notation. For example, @cite{5 x^4 + (x + 1)^2} with @cite{m = 6} -should produce the list @cite{[1, 2, 1, 0, 5, 0, 0]}. Also develop +notation. For example, @expr{5 x^4 + (x + 1)^2} with @expr{m = 6} +should produce the list @expr{[1, 2, 1, 0, 5, 0, 0]}. Also develop a way to convert from this form back to the standard algebraic form. @xref{Programming Answer 10, 10}. (@bullet{}) @@ -6508,9 +6545,9 @@ to the same key with @kbd{Z K s}. Now the @kbd{z s} command will run the complete recursive program. (Another way is to use @w{@kbd{Z E}} or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once, thus avoiding the ``training'' phase.) The task: Write a program -that computes Stirling numbers of the first kind, given @cite{n} and -@cite{m} on the stack. Test it with @emph{small} inputs like -@cite{s(4,2)}. (There is a built-in command for Stirling numbers, +that computes Stirling numbers of the first kind, given @expr{n} and +@expr{m} on the stack. Test it with @emph{small} inputs like +@expr{s(4,2)}. (There is a built-in command for Stirling numbers, @kbd{k s}, which you can use to check your answers.) @xref{Programming Answer 11, 11}. (@bullet{}) @@ -6522,7 +6559,7 @@ program can: (@bullet{}) @strong{Exercise 12.} Write another program for computing Stirling numbers of the first kind, this time using -rewrite rules. Once again, @cite{n} and @cite{m} should be taken +rewrite rules. Once again, @expr{n} and @expr{m} should be taken from the stack. @xref{Programming Answer 12, 12}. (@bullet{}) @example @@ -6600,8 +6637,7 @@ This section includes answers to all the exercises in the Calc tutorial. * Rewrites Answer 3:: Rewriting opt(a) + opt(b) x * Rewrites Answer 4:: Sequence of integers * Rewrites Answer 5:: Number of terms in sum -* Rewrites Answer 6:: Defining 0^0 = 1 -* Rewrites Answer 7:: Truncated Taylor series +* Rewrites Answer 6:: Truncated Taylor series * Programming Answer 1:: Fresnel's C(x) * Programming Answer 2:: Negate third stack element * Programming Answer 3:: Compute sin(x) / x, etc. @@ -6631,21 +6667,23 @@ This section includes answers to all the exercises in the Calc tutorial. @noindent @kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -} -The result is @c{$1 - (2 \times (3 + 4)) = -13$} -@cite{1 - (2 * (3 + 4)) = -13}. +The result is +@texline @math{1 - (2 \times (3 + 4)) = -13}. +@infoline @expr{1 - (2 * (3 + 4)) = -13}. @node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises @subsection RPN Tutorial Exercise 2 @noindent -@c{$2\times4 + 7\times9.5 + {5\over4} = 75.75$} -@cite{2*4 + 7*9.5 + 5/4 = 75.75} +@texline @math{2\times4 + 7\times9.5 + {5\over4} = 75.75} +@infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75} -After computing the intermediate term @c{$2\times4 = 8$} -@cite{2*4 = 8}, you can leave -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. +After computing the intermediate term +@texline @math{2\times4 = 8}, +@infoline @expr{2*4 = 8}, +you can leave 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. @smallexample @group @@ -6769,8 +6807,8 @@ If the @kbd{Q} key is broken, you could use @kbd{' $^0.5 @key{RET}}. Or, RPN style, @kbd{0.5 ^}. (Actually, @samp{$^1:2}, using the fraction one-half as the power, is -a closer equivalent, since @samp{9^0.5} yields @cite{3.0} whereas -@samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @cite{3}.) +a closer equivalent, since @samp{9^0.5} yields @expr{3.0} whereas +@samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @expr{3}.) @node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to Exercises @subsection Algebraic Entry Tutorial Exercise 2 @@ -6785,14 +6823,14 @@ explicit @samp{*} symbol here: @samp{2 x*(1+y)}. @subsection Algebraic Entry Tutorial Exercise 3 @noindent -The result from @kbd{1 @key{RET} 0 /} will be the formula @cite{1 / 0}. +The result from @kbd{1 @key{RET} 0 /} will be the formula @expr{1 / 0}. The ``function'' @samp{/} cannot be evaluated when its second argument is zero, so it is left in symbolic form. When you now type @kbd{0 *}, the result will be zero because Calc uses the general rule that ``zero times anything is zero.'' @c [fix-ref Infinities] -The @kbd{m i} command enables an @dfn{infinite mode} in which @cite{1 / 0} +The @kbd{m i} command enables an @dfn{Infinite mode} in which @expr{1 / 0} results in a special symbol that represents ``infinity.'' If you multiply infinity by zero, Calc uses another special new symbol to show that the answer is ``indeterminate.'' @xref{Infinities}, for @@ -6882,7 +6920,7 @@ copied that number into a file and later moved it back into Calc. @subsection Modes Tutorial Exercise 3 @noindent -The answer he got was @cite{0.5000000000006399}. +The answer he got was @expr{0.5000000000006399}. The problem is not that the square operation is inexact, but that the sine of 45 that was already on the stack was accurate to only 12 places. @@ -6947,16 +6985,17 @@ There is no fractional form for the square root of two, so if you type @noindent Dividing two integers that are larger than the current precision may give a floating-point result that is inaccurate even when rounded -down to an integer. Consider @cite{123456789 / 2} when the current -precision is 6 digits. The true answer is @cite{61728394.5}, but -with a precision of 6 this will be rounded to @c{$12345700.0/2.0 = 61728500.0$} -@cite{12345700.@: / 2.@: = 61728500.}. +down to an integer. Consider @expr{123456789 / 2} when the current +precision is 6 digits. The true answer is @expr{61728394.5}, but +with a precision of 6 this will be rounded to +@texline @math{12345700.0/2.0 = 61728500.0}. +@infoline @expr{12345700.@: / 2.@: = 61728500.}. The result, when converted to an integer, will be off by 106. Here are two solutions: Raise the precision enough that the floating-point round-off error is strictly to the right of the -decimal point. Or, convert to fraction mode so that @cite{123456789 / 2} -produces the exact fraction @cite{123456789:2}, which can be rounded +decimal point. Or, convert to Fraction mode so that @expr{123456789 / 2} +produces the exact fraction @expr{123456789:2}, which can be rounded down by the @kbd{F} command without ever switching to floating-point format. @@ -6964,13 +7003,13 @@ format. @subsection Arithmetic Tutorial Exercise 2 @noindent -@kbd{27 @key{RET} 9 B} could give the exact result @cite{3:2}, but it -does a floating-point calculation instead and produces @cite{1.5}. +@kbd{27 @key{RET} 9 B} could give the exact result @expr{3:2}, but it +does a floating-point calculation instead and produces @expr{1.5}. Calc will find an exact result for a logarithm if the result is an integer -or the reciprocal of an integer. But there is no efficient way to search -the space of all possible rational numbers for an exact answer, so Calc -doesn't try. +or (when in Fraction mode) the reciprocal of an integer. But there is +no efficient way to search the space of all possible rational numbers +for an exact answer, so Calc doesn't try. @node Vector Answer 1, Vector Answer 2, Arithmetic Answer 2, Answers to Exercises @subsection Vector Tutorial Exercise 1 @@ -7042,7 +7081,7 @@ matrix as usual. @end group @end smallexample -This can be made more readable using @kbd{d B} to enable ``big'' display +This can be made more readable using @kbd{d B} to enable Big display mode: @smallexample @@ -7053,20 +7092,25 @@ mode: @end group @end smallexample -Type @kbd{d N} to return to ``normal'' display mode afterwards. +Type @kbd{d N} to return to Normal display mode afterwards. @node Matrix Answer 3, List Answer 1, Matrix Answer 2, Answers to Exercises @subsection Matrix Tutorial Exercise 3 @noindent -To solve @c{$A^T A \, X = A^T B$} -@cite{trn(A) * A * X = trn(A) * B}, first we compute -@c{$A' = A^T A$} -@cite{A2 = trn(A) * A} and @c{$B' = A^T B$} -@cite{B2 = trn(A) * B}; now, we have a -system @c{$A' X = B'$} -@cite{A2 * X = B2} which we can solve using Calc's @samp{/} -command. +To solve +@texline @math{A^T A \, X = A^T B}, +@infoline @expr{trn(A) * A * X = trn(A) * B}, +first we compute +@texline @math{A' = A^T A} +@infoline @expr{A2 = trn(A) * A} +and +@texline @math{B' = A^T B}; +@infoline @expr{B2 = trn(A) * B}; +now, we have a system +@texline @math{A' X = B'} +@infoline @expr{A2 * X = B2} +which we can solve using Calc's @samp{/} command. @ifinfo @example @@ -7096,8 +7140,9 @@ $$ The first step is to enter the coefficient matrix. We'll store it in quick variable number 7 for later reference. Next, we compute the -@c{$B'$} -@cite{B2} vector. +@texline @math{B'} +@infoline @expr{B2} +vector. @smallexample @group @@ -7112,8 +7157,10 @@ quick variable number 7 for later reference. Next, we compute the @end smallexample @noindent -Now we compute the matrix @c{$A'$} -@cite{A2} and divide. +Now we compute the matrix +@texline @math{A'} +@infoline @expr{A2} +and divide. @smallexample @group @@ -7131,14 +7178,18 @@ Now we compute the matrix @c{$A'$} (The actual computed answer will be slightly inexact due to round-off error.) -Notice that the answers are similar to those for the @c{$3\times3$} -@asis{3x3} system -solved in the text. That's because the fourth equation that was +Notice that the answers are similar to those for the +@texline @math{3\times3} +@infoline 3x3 +system solved in the text. That's because the fourth equation that was added to the system is almost identical to the first one multiplied by two. (If it were identical, we would have gotten the exact same -answer since the @c{$4\times3$} -@asis{4x3} system would be equivalent to the original @c{$3\times3$} -@asis{3x3} +answer since the +@texline @math{4\times3} +@infoline 4x3 +system would be equivalent to the original +@texline @math{3\times3} +@infoline 3x3 system.) Since the first and fourth equations aren't quite equivalent, they @@ -7159,8 +7210,8 @@ the original system of equations to see how well they match. @end smallexample @noindent -This is reasonably close to our original @cite{B} vector, -@cite{[6, 2, 3, 11]}. +This is reasonably close to our original @expr{B} vector, +@expr{[6, 2, 3, 11]}. @node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises @subsection List Tutorial Exercise 1 @@ -7198,7 +7249,7 @@ vector. @subsection List Tutorial Exercise 2 @noindent -Given @cite{x} and @cite{y} vectors in quick variables 1 and 2 as before, +Given @expr{x} and @expr{y} vectors in quick variables 1 and 2 as before, the first job is to form the matrix that describes the problem. @ifinfo @@ -7213,10 +7264,12 @@ $$ m \times x + b \times 1 = y $$ \afterdisplay @end tex -Thus we want a @c{$19\times2$} -@asis{19x2} matrix with our @cite{x} vector as one column and +Thus we want a +@texline @math{19\times2} +@infoline 19x2 +matrix with our @expr{x} vector as one column and 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. +we combine the two columns to form our @expr{A} matrix. @smallexample @group @@ -7230,9 +7283,13 @@ we combine the two columns to form our @cite{A} matrix. @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. +Now we compute +@texline @math{A^T y} +@infoline @expr{trn(A) * y} +and +@texline @math{A^T A} +@infoline @expr{trn(A) * A} +and divide. @smallexample @group @@ -7257,10 +7314,12 @@ Now we compute @c{$A^T y$} @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 -numbers should be @cite{m} and @cite{b}, respectively. Sure enough, they -agree exactly with the result computed using @kbd{V M} and @kbd{V R}! +Since we were solving equations of the form +@texline @math{m \times x + b \times 1 = y}, +@infoline @expr{m*x + b*1 = y}, +these numbers should be @expr{m} and @expr{b}, respectively. Sure +enough, they agree exactly with the result computed using @kbd{V M} and +@kbd{V R}! The moral of this story: @kbd{V M} and @kbd{V R} will probably solve your problem, but there is often an easier way using the higher-level @@ -7318,9 +7377,10 @@ then raise the number to that power.) @subsection List Tutorial Exercise 4 @noindent -A number @cite{j} is a divisor of @cite{n} if @c{$n \mathbin{\hbox{\code{\%}}} j = 0$} -@samp{n % j = 0}. The first -step is to get a vector that identifies the divisors. +A number @expr{j} is a divisor of @expr{n} if +@texline @math{n \mathbin{\hbox{\code{\%}}} j = 0}. +@infoline @samp{n % j = 0}. +The first step is to get a vector that identifies the divisors. @smallexample @group @@ -7388,10 +7448,11 @@ so that the mapping operation works; no prime factor will ever be zero, so adding zeros on the left and right is safe. From then on the job is pretty straightforward. -Incidentally, Calc provides the @c{\dfn{M\"obius} $\mu$} -@dfn{Moebius mu} function which is -zero if and only if its argument is square-free. It would be a much -more convenient way to do the above test in practice. +Incidentally, Calc provides the +@texline @dfn{M@"obius} @math{\mu} +@infoline @dfn{Moebius mu} +function which is zero if and only if its argument is square-free. It +would be a much more convenient way to do the above test in practice. @node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises @subsection List Tutorial Exercise 6 @@ -7419,10 +7480,11 @@ exercise and type @kbd{1 -} to subtract one from all the elements. @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 -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}. +the ``triangular numbers'' (now you know why!). The @expr{n}th +triangular number is the sum of the integers from 1 to @expr{n}, and +can be computed directly by the formula +@texline @math{n (n+1) \over 2}. +@infoline @expr{n * (n+1) / 2}. @smallexample @group @@ -7476,7 +7538,7 @@ since each element of the main vector is itself a small vector, @subsection List Tutorial Exercise 8 @noindent -The first step is to build a list of values of @cite{x}. +The first step is to build a list of values of @expr{x}. @smallexample @group @@ -7516,12 +7578,13 @@ A way to isolate the maximum value is to compute the maximum using @noindent It's a good idea to verify, as in the last step above, that only -one value is equal to the maximum. (After all, a plot of @c{$\sin x$} -@cite{sin(x)} +one value is equal to the maximum. (After all, a plot of +@texline @math{\sin x} +@infoline @expr{sin(x)} might have many points all equal to the maximum value, 1.) 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 +the maximum value of @expr{x}. Now it is a simple matter to convert this back into the corresponding value itself. @smallexample @@ -7534,12 +7597,12 @@ this back into the corresponding value itself. @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 +If @kbd{a =} had produced more than one @expr{1} value, this method +would have given the sum of all maximum @expr{x} values; not very useful! In this case we could have used @kbd{v m} (@code{calc-mask-vector}) instead. This command deletes all elements of a ``data'' vector that correspond to zeros in a ``mask'' vector, leaving us with, in this -example, a vector of maximum @cite{x} values. +example, a vector of maximum @expr{x} values. The built-in @kbd{a X} command maximizes a function using more efficient methods. Just for illustration, let's use @kbd{a X} @@ -7556,7 +7619,7 @@ to maximize @samp{besJ(1,x)} over this same interval. @end smallexample @noindent -The output from @kbd{a X} is a vector containing the value of @cite{x} +The output from @kbd{a X} is a vector containing the value of @expr{x} that maximizes the function, and the function's value at that maximum. As you can see, our simple search got quite close to the right answer. @@ -7686,10 +7749,10 @@ Another way to do this final step would be to reduce the formula @subsection List Tutorial Exercise 10 @noindent -For the list @cite{[a, b, c, d]}, the result is @cite{((a = b) = c) = d}, -which will compare @cite{a} and @cite{b} to produce a 1 or 0, which is -then compared with @cite{c} to produce another 1 or 0, which is then -compared with @cite{d}. This is not at all what Joe wanted. +For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d}, +which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is +then compared with @expr{c} to produce another 1 or 0, which is then +compared with @expr{d}. This is not at all what Joe wanted. Here's a more correct method: @@ -7717,9 +7780,9 @@ Here's a more correct method: @subsection List Tutorial Exercise 11 @noindent -The circle of unit radius consists of those points @cite{(x,y)} for which -@cite{x^2 + y^2 < 1}. We start by generating a vector of @cite{x^2} -and a vector of @cite{y^2}. +The circle of unit radius consists of those points @expr{(x,y)} for which +@expr{x^2 + y^2 < 1}. We start by generating a vector of @expr{x^2} +and a vector of @expr{y^2}. We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} commands. @@ -7745,7 +7808,7 @@ commands. @end group @end smallexample -Now we sum the @cite{x^2} and @cite{y^2} values, compare with 1 to +Now we sum the @expr{x^2} and @expr{y^2} values, compare with 1 to get a vector of 1/0 truth values, then sum the truth values. @smallexample @@ -7758,8 +7821,7 @@ get a vector of 1/0 truth values, then sum the truth values. @end smallexample @noindent -The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$} -@cite{pi/4}. +The ratio @expr{84/100} should approximate the ratio @cpiover{4}. @smallexample @group @@ -7787,30 +7849,33 @@ return to full-sized display of vectors. @noindent This problem can be made a lot easier by taking advantage of some symmetries. First of all, after some thought it's clear that the -@cite{y} axis can be ignored altogether. Just pick a random @cite{x} -component for one end of the match, pick a random direction @c{$\theta$} -@cite{theta}, -and see if @cite{x} and @c{$x + \cos \theta$} -@cite{x + cos(theta)} (which is the @cite{x} -coordinate of the other endpoint) cross a line. The lines are at -integer coordinates, so this happens when the two numbers surround -an integer. +@expr{y} axis can be ignored altogether. Just pick a random @expr{x} +component for one end of the match, pick a random direction +@texline @math{\theta}, +@infoline @expr{theta}, +and see if @expr{x} and +@texline @math{x + \cos \theta} +@infoline @expr{x + cos(theta)} +(which is the @expr{x} coordinate of the other endpoint) cross a line. +The lines are at integer coordinates, so this happens when the two +numbers surround an integer. Since the two endpoints are equivalent, we may as well choose the leftmost -of the two endpoints as @cite{x}. Then @cite{theta} is an angle pointing +of the two endpoints as @expr{x}. Then @expr{theta} is an angle pointing to the right, in the range -90 to 90 degrees. (We could use radians, but -it would feel like cheating to refer to @c{$\pi/2$} -@cite{pi/2} radians while trying -to estimate @c{$\pi$} -@cite{pi}!) +it would feel like cheating to refer to @cpiover{2} radians while trying +to estimate @cpi{}!) In fact, since the field of lines is infinite we can choose the coordinates 0 and 1 for the lines on either side of the leftmost endpoint. The rightmost endpoint will be between 0 and 1 if the match does not cross a line, or between 1 and 2 if it does. So: -Pick random @cite{x} and @c{$\theta$} -@cite{theta}, compute @c{$x + \cos \theta$} -@cite{x + cos(theta)}, +Pick random @expr{x} and +@texline @math{\theta}, +@infoline @expr{theta}, +compute +@texline @math{x + \cos \theta}, +@infoline @expr{x + cos(theta)}, 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 .} @@ -7911,8 +7976,8 @@ we omitted the closing @kbd{"}. (The same goes for all closing delimiters like @kbd{)} and @kbd{]} at the end of a formula. We'll show two different approaches here. In the first, we note that -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, +if the input vector is @expr{[a, b, c, d]}, then the hash code is +@expr{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. @smallexample @@ -7974,7 +8039,7 @@ the operations are faster. @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 +@w{@expr{3 (3a + b) + c}}. Taking a result modulo 511 basically means subtracting off enough 511's to put the result in the desired range. So the result when we take the modulo after every step is, @@ -7991,7 +8056,7 @@ $$ 3 (3 a + b - 511 m) + c - 511 n $$ @end tex @noindent -for some suitable integers @cite{m} and @cite{n}. Expanding out by +for some suitable integers @expr{m} and @expr{n}. Expanding out by the distributive law yields @ifinfo @@ -8007,10 +8072,10 @@ $$ 9 a + 3 b + c - 511\times3 m - 511 n $$ @end tex @noindent -The @cite{m} term in the latter formula is redundant because any -contribution it makes could just as easily be made by the @cite{n} +The @expr{m} term in the latter formula is redundant because any +contribution it makes could just as easily be made by the @expr{n} term. So we can take it out to get an equivalent formula with -@cite{n' = 3m + n}, +@expr{n' = 3m + n}, @ifinfo @example @@ -8036,7 +8101,7 @@ modulo some value @var{m}. @subsection List Tutorial Exercise 14 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 +step to an @expr{(x,y)} coordinate. The function is a bit long, but otherwise the problem is quite straightforward. @smallexample @@ -8054,9 +8119,9 @@ Just as the text recommended, we used @samp{< >} nameless function notation to keep the two @code{random} calls from being evaluated before nesting even begins. -We now have a vector of @cite{[x, y]} sub-vectors, which by Calc's +We now have a vector of @expr{[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. +to get a pair of vectors, @expr{x} and @expr{y}, suitable for graphing. @smallexample @group @@ -8068,12 +8133,12 @@ to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing. @end group @end smallexample -Incidentally, because the @cite{x} and @cite{y} are completely +Incidentally, because the @expr{x} and @expr{y} are completely independent in this case, we could have done two separate commands -to create our @cite{x} and @cite{y} vectors of numbers directly. +to create our @expr{x} and @expr{y} vectors of numbers directly. To make a random walk of unit steps, we note that @code{sincos} of -a random direction exactly gives us an @cite{[x, y]} step of unit +a random direction exactly gives us an @expr{[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. @@ -8101,10 +8166,8 @@ Schwartz.) @subsection Types Tutorial Exercise 1 @noindent -If the number is the square root of @c{$\pi$} -@cite{pi} times a rational number, -then its square, divided by @c{$\pi$} -@cite{pi}, should be a rational number. +If the number is the square root of @cpi{} times a rational number, +then its square, divided by @cpi{}, should be a rational number. @smallexample @group @@ -8136,8 +8199,8 @@ precision slightly and try again: @noindent Aha! It's unlikely that an irrational number would equal a fraction this simple to within ten digits, so our original number was probably -@c{$\sqrt{27 \pi / 53}$} -@cite{sqrt(27 pi / 53)}. +@texline @math{\sqrt{27 \pi / 53}}. +@infoline @expr{sqrt(27 pi / 53)}. Notice that we didn't need to re-round the number when we reduced the precision. Remember, arithmetic operations always round their inputs @@ -8153,17 +8216,17 @@ But if @w{@samp{17 inf = inf}}, then @samp{17 inf / inf = inf / inf = 17}, too. @samp{exp(inf) = inf}. It's tempting to say that the exponential of infinity must be ``bigger'' than ``regular'' infinity, but as far as Calc is concerned all infinities are as just as big. -In other words, as @cite{x} goes to infinity, @cite{e^x} also goes -to infinity, but the fact the @cite{e^x} grows much faster than -@cite{x} is not relevant here. +In other words, as @expr{x} goes to infinity, @expr{e^x} also goes +to infinity, but the fact the @expr{e^x} grows much faster than +@expr{x} is not relevant here. @samp{exp(-inf) = 0}. Here we have a finite answer even though the input is infinite. -@samp{sqrt(-inf) = (0, 1) inf}. Remember that @cite{(0, 1)} -represents the imaginary number @cite{i}. Here's a derivation: +@samp{sqrt(-inf) = (0, 1) inf}. Remember that @expr{(0, 1)} +represents the imaginary number @expr{i}. Here's a derivation: @samp{sqrt(-inf) = @w{sqrt((-1) * inf)} = sqrt(-1) * sqrt(inf)}. -The first part is, by definition, @cite{i}; the second is @code{inf} +The first part is, by definition, @expr{i}; the second is @code{inf} because, once again, all infinities are the same size. @samp{sqrt(uinf) = uinf}. In fact, we do know something about the @@ -8171,12 +8234,12 @@ direction because @code{sqrt} is defined to return a value in the right half of the complex plane. But Calc has no notation for this, so it settles for the conservative answer @code{uinf}. -@samp{abs(uinf) = inf}. No matter which direction @cite{x} points, +@samp{abs(uinf) = inf}. No matter which direction @expr{x} points, @samp{abs(x)} always points along the positive real axis. @samp{ln(0) = -inf}. Here we have an infinite answer to a finite -input. As in the @cite{1 / 0} case, Calc will only use infinities -here if you have turned on ``infinite'' mode. Otherwise, it will +input. As in the @expr{1 / 0} case, Calc will only use infinities +here if you have turned on Infinite mode. Otherwise, it will treat @samp{ln(0)} as an error. @node Types Answer 3, Types Answer 4, Types Answer 2, Answers to Exercises @@ -8184,9 +8247,9 @@ treat @samp{ln(0)} as an error. @noindent We can make @samp{inf - inf} be any real number we like, say, -@cite{a}, just by claiming that we added @cite{a} to the first +@expr{a}, just by claiming that we added @expr{a} to the first infinity but not to the second. This is just as true for complex -values of @cite{a}, so @code{nan} can stand for a complex number. +values of @expr{a}, so @code{nan} can stand for a complex number. (And, similarly, @code{uinf} can stand for an infinity that points in any direction in the complex plane, such as @samp{(0, 1) inf}). @@ -8267,14 +8330,8 @@ argument is exactly what we want to map over: @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. @smallexample @group @@ -8396,16 +8453,16 @@ Calc normally treats division by zero as an error, so that the formula @w{@samp{1 / [0 .. 10]}}, also (potentially) divides by zero because zero is now a member of the interval. So Calc leaves this one unevaluated, too. -If you turn on ``infinite'' mode by pressing @kbd{m i}, you will +If you turn on Infinite mode by pressing @kbd{m i}, you will instead get the answer @samp{[0.1 .. inf]}, which includes infinity as a possible value. The fourth calculation, @samp{1 / (-10 .. 10)}, has the same problem. Zero is buried inside the interval, but it's still a possible value. It's not hard to see that the actual result of @samp{1 / (-10 .. 10)} -will be either greater than @i{0.1}, or less than @i{-0.1}. Thus +will be either greater than @mathit{0.1}, or less than @mathit{-0.1}. Thus the interval goes from minus infinity to plus infinity, with a ``hole'' -in it from @i{-0.1} to @i{0.1}. Calc doesn't have any way to +in it from @mathit{-0.1} to @mathit{0.1}. Calc doesn't have any way to represent this, so it just reports @samp{[-inf .. inf]} as the answer. It may be disappointing to hear ``the answer lies somewhere between minus infinity and plus infinity, inclusive,'' but that's the best @@ -8425,9 +8482,9 @@ that interval arithmetic can do in this case. @end smallexample @noindent -In the first case the result says, ``if a number is between @i{-3} and +In the first case the result says, ``if a number is between @mathit{-3} and 3, its square is between 0 and 9.'' The second case says, ``the product -of two numbers each between @i{-3} and 3 is between @i{-9} and 9.'' +of two numbers each between @mathit{-3} and 3 is between @mathit{-9} and 9.'' An interval form is not a number; it is a symbol that can stand for many different numbers. Two identical-looking interval forms can stand @@ -8439,7 +8496,7 @@ The same issue arises when you try to square an error form. @subsection Types Tutorial Exercise 10 @noindent -Testing the first number, we might arbitrarily choose 17 for @cite{x}. +Testing the first number, we might arbitrarily choose 17 for @expr{x}. @smallexample @group @@ -8471,7 +8528,7 @@ use this method to test the second number. @end smallexample @noindent -The result is three ones (modulo @cite{n}), so it's very probable that +The result is three ones (modulo @expr{n}), so it's very probable that 15485863 is prime. (In fact, this number is the millionth prime.) Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $} @@ -8640,20 +8697,20 @@ Thus Sam can take up to 14 pills without a worry. @noindent @c [fix-ref Declarations] -The result @samp{sqrt(x)^2} is simplified back to @cite{x} by the +The result @samp{sqrt(x)^2} is simplified back to @expr{x} by the Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens -if @w{@cite{x = -4}}.) If @cite{x} is real, this formula could be +if @w{@expr{x = -4}}.) If @expr{x} is real, this formula could be simplified to @samp{abs(x)}, but for general complex arguments even that is not safe. (@xref{Declarations}, for a way to tell Calc -that @cite{x} is known to be real.) +that @expr{x} is known to be real.) @node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to Exercises @subsection Algebra Tutorial Exercise 2 @noindent -Suppose our roots are @cite{[a, b, c]}. We want a polynomial which -is zero when @cite{x} is any of these values. The trivial polynomial -@cite{x-a} is zero when @cite{x=a}, so the product @cite{(x-a)(x-b)(x-c)} +Suppose our roots are @expr{[a, b, c]}. We want a polynomial which +is zero when @expr{x} is any of these values. The trivial polynomial +@expr{x-a} is zero when @expr{x=a}, so the product @expr{(x-a)(x-b)(x-c)} will do the job. We can use @kbd{a c x} to write this in a more familiar form. @@ -8844,7 +8901,7 @@ We'll use Big mode to make the formulas more readable. @end smallexample @noindent -Multiplying by the conjugate helps because @cite{(a+b) (a-b) = a^2 - b^2}. +Multiplying by the conjugate helps because @expr{(a+b) (a-b) = a^2 - b^2}. @smallexample @group @@ -8894,11 +8951,11 @@ The first rule turns a one-argument @code{fib} that people like to write into a three-argument @code{fib} that makes computation easier. The second rule converts back from three-argument form once the computation is done. The third rule does the computation itself. It basically -says that if @cite{x} and @cite{y} are two consecutive Fibonacci numbers, -then @cite{y} and @cite{x+y} are the next (overlapping) pair of Fibonacci +says that if @expr{x} and @expr{y} are two consecutive Fibonacci numbers, +then @expr{y} and @expr{x+y} are the next (overlapping) pair of Fibonacci numbers. -Notice that because the number @cite{n} was ``validated'' by the +Notice that because the number @expr{n} was ``validated'' by the conditions on the first rule, there is no need to put conditions on the other rules because the rule set would never get that far unless the input were valid. That further speeds computation, since no @@ -8995,8 +9052,8 @@ The change to return a vector is quite simple: @noindent Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. -Notice that the @cite{n > 1} guard is no longer necessary on the last -rule since the @cite{n = 1} case is now detected by another rule. +Notice that the @expr{n > 1} guard is no longer necessary on the last +rule since the @expr{n = 1} case is now detected by another rule. But a guard has been added to the initial rule to make sure the initial value is suitable before the computation begins. @@ -9014,8 +9071,8 @@ apply and the rewrites will stop right away. @starindex @end ignore @tindex nterms -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} +If @expr{x} is the sum @expr{a + b}, then `@t{nterms(}@var{x}@t{)}' must +be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @expr{x} is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1. @smallexample @@ -9030,48 +9087,9 @@ Here we have taken advantage of the fact that earlier rules always match before later rules; @samp{nterms(x)} will only be tried if we already know that @samp{x} is not a sum. -@node Rewrites Answer 6, Rewrites Answer 7, Rewrites Answer 5, Answers to Exercises +@node Rewrites Answer 6, Programming Answer 1, Rewrites Answer 5, Answers to Exercises @subsection Rewrites Tutorial Exercise 6 -Just put the rule @samp{0^0 := 1} into @code{EvalRules}. For example, -before making this definition we have: - -@smallexample -@group -2: [-2, -1, 0, 1, 2] 1: [1, 1, 0^0, 1, 1] -1: 0 . - . - - v x 5 @key{RET} 3 - 0 V M ^ -@end group -@end smallexample - -@noindent -But then: - -@smallexample -@group -2: [-2, -1, 0, 1, 2] 1: [1, 1, 1, 1, 1] -1: 0 . - . - - 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 -a function. This allows you to override the default behavior of any -Calc feature: Even though Calc now wants to evaluate @cite{0^0} to -@code{nan}, your rule gets there first and evaluates it to 1 instead. - -Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}. -What happens? (Be sure to remove this rule afterward, or you might get -a nasty surprise when you use Calc to balance your checkbook!) - -@node Rewrites Answer 7, Programming Answer 1, Rewrites Answer 6, Answers to Exercises -@subsection Rewrites Tutorial Exercise 7 - @noindent Here is a rule set that will do the job: @@ -9121,7 +9139,7 @@ The sixth rule is the corresponding rule for products of two O's. Another way to solve this problem would be to create a new ``data type'' that represents truncated power series. We might represent these as function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is -a vector of coefficients for @cite{x^0}, @cite{x^1}, @cite{x^2}, and so +a vector of coefficients for @expr{x^0}, @expr{x^1}, @expr{x^2}, and so on. Rules would exist for sums and products of such @code{series} objects, and as an optional convenience could also know how to combine a @code{series} object with a normal polynomial. (With this, and with a @@ -9144,14 +9162,14 @@ for a way to do this in Calc, although for something as involved as this it would probably be better to write the formatting routine in Lisp.) -@node Programming Answer 1, Programming Answer 2, Rewrites Answer 7, Answers to Exercises +@node Programming Answer 1, Programming Answer 2, Rewrites Answer 6, Answers to Exercises @subsection Programming Tutorial Exercise 1 @noindent Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type @kbd{Z F}, and answer the questions. Since this formula contains two 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 +change this to @samp{(x)} since @expr{t} is really a dummy variable to be used within @code{ninteg}. The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}. @@ -9182,8 +9200,9 @@ Each of these functions can be computed using the stack, or using algebraic entry, whichever way you prefer: @noindent -Computing @c{$\displaystyle{\sin x \over x}$} -@cite{sin(x) / x}: +Computing +@texline @math{\displaystyle{\sin x \over x}}: +@infoline @expr{sin(x) / x}: Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. @@ -9243,8 +9262,8 @@ Here is the matrix: @end example @noindent -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: +Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @expr{n+1} +and @expr{n+2}. Here's one program that does the job: @example C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x ) @@ -9252,8 +9271,9 @@ C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x ) @noindent This program is quite efficient because Calc knows how to raise a -matrix (or other value) to the power @cite{n} in only @c{$\log_2 n$} -@cite{log(n,2)} +matrix (or other value) to the power @expr{n} in only +@texline @math{\log_2 n} +@infoline @expr{log(n,2)} steps. For example, this program can compute the 1000th Fibonacci number (a 209-digit integer!) in about 10 steps; even though the @kbd{Z < ... Z >} solution had much simpler steps, it would have @@ -9304,9 +9324,10 @@ harmonic number is 4.02. @subsection Programming Tutorial Exercise 8 @noindent -The first step is to compute the derivative @cite{f'(x)} and thus -the formula @c{$\displaystyle{x - {f(x) \over f'(x)}}$} -@cite{x - f(x)/f'(x)}. +The first step is to compute the derivative @expr{f'(x)} and thus +the formula +@texline @math{\displaystyle{x - {f(x) \over f'(x)}}}. +@infoline @expr{x - f(x)/f'(x)}. (Because this definition is long, it will be repeated in concise form below. You can use @w{@kbd{M-# m}} to load it from there. While you are @@ -9353,7 +9374,7 @@ repetitions are done.) @end group @end smallexample -This is the new guess for @cite{x}. Now we compare it with the +This is the new guess for @expr{x}. Now we compare it with the old one to see if we've converged. @smallexample @@ -9419,13 +9440,16 @@ method (among others) to look for numerical solutions to any equation. @subsection Programming Tutorial Exercise 9 @noindent -The first step is to adjust @cite{z} to be greater than 5. A simple -``for'' loop will do the job here. If @cite{z} is less than 5, we -reduce the problem using @c{$\psi(z) = \psi(z+1) - 1/z$} -@cite{psi(z) = psi(z+1) - 1/z}. We go -on to compute @c{$\psi(z+1)$} -@cite{psi(z+1)}, and remember to add back a factor of -@cite{-1/z} when we're done. This step is repeated until @cite{z > 5}. +The first step is to adjust @expr{z} to be greater than 5. A simple +``for'' loop will do the job here. If @expr{z} is less than 5, we +reduce the problem using +@texline @math{\psi(z) = \psi(z+1) - 1/z}. +@infoline @expr{psi(z) = psi(z+1) - 1/z}. We go +on to compute +@texline @math{\psi(z+1)}, +@infoline @expr{psi(z+1)}, +and remember to add back a factor of @expr{-1/z} when we're done. This +step is repeated until @expr{z > 5}. (Because this definition is long, it will be repeated in concise form below. You can use @w{@kbd{M-# m}} to load it from there. While you are @@ -9443,8 +9467,8 @@ just for purposes of illustration.) @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. +Here, variable 1 holds @expr{z} and variable 2 holds the adjustment +factor. If @expr{z < 5}, we use a loop to increase it. (By the way, we started with @samp{1.0} instead of the integer 1 because otherwise the calculation below will try to do exact fractional arithmetic, @@ -9462,8 +9486,9 @@ are exactly equal, not just equal to within the current precision.) @end group @end smallexample -Now we compute the initial part of the sum: @c{$\ln z - {1 \over 2z}$} -@cite{ln(z) - 1/2z} +Now we compute the initial part of the sum: +@texline @math{\ln z - {1 \over 2z}} +@infoline @expr{ln(z) - 1/2z} minus the adjustment factor. @smallexample @@ -9477,7 +9502,7 @@ minus the adjustment factor. @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, +up the value of @expr{2 n}. (Calc does have a summation command, @kbd{a +}, but we'll use loops just to get more practice with them.) @smallexample @@ -9504,9 +9529,11 @@ up the value of @cite{2 n}. (Calc does have a summation command, @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: +This is the value of +@texline @math{-\gamma}, +@infoline @expr{- gamma}, +with a slight bit of roundoff error. To get a full 12 digits, let's use +a higher precision: @smallexample @group @@ -9536,12 +9563,14 @@ C-x ) @subsection Programming Tutorial Exercise 10 @noindent -Taking the derivative of a term of the form @cite{x^n} will produce -a term like @c{$n x^{n-1}$} -@cite{n x^(n-1)}. Taking the derivative of a constant -produces zero. From this it is easy to see that the @cite{n}th -derivative of a polynomial, evaluated at @cite{x = 0}, will equal the -coefficient on the @cite{x^n} term times @cite{n!}. +Taking the derivative of a term of the form @expr{x^n} will produce +a term like +@texline @math{n x^{n-1}}. +@infoline @expr{n x^(n-1)}. +Taking the derivative of a constant +produces zero. From this it is easy to see that the @expr{n}th +derivative of a polynomial, evaluated at @expr{x = 0}, will equal the +coefficient on the @expr{x^n} term times @expr{n!}. (Because this definition is long, it will be repeated in concise form below. You can use @w{@kbd{M-# m}} to load it from there. While you are @@ -9590,7 +9619,7 @@ have written instead, @kbd{r 1 @key{TAB} | t 1}. @end smallexample To convert back, a simple method is just to map the coefficients -against a table of powers of @cite{x}. +against a table of powers of @expr{x}. @smallexample @group @@ -9650,7 +9679,7 @@ sure the stack comes out right. 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 definition. The recurrence needs to be rewritten slightly, -to the form @cite{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}. +to the form @expr{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.) @@ -9813,13 +9842,13 @@ By default this creates a pair of small windows, @samp{*Calculator*} and @samp{*Calc Trail*}. The former displays the contents of the Calculator stack and is manipulated exclusively through Calc commands. It is possible (though not usually necessary) to create several Calc -Mode buffers each of which has an independent stack, undo list, and +mode buffers each of which has an independent stack, undo list, and mode settings. There is exactly one Calc Trail buffer; it records a list of the results of all calculations that have been done. The -Calc Trail buffer uses a variant of Calc Mode, so Calculator commands +Calc Trail buffer uses a variant of Calc mode, so Calculator commands still work when the trail buffer's window is selected. It is possible to turn the trail window off, but the @samp{*Calc Trail*} buffer itself -still exists and is updated silently. @xref{Trail Commands}.@refill +still exists and is updated silently. @xref{Trail Commands}. @kindex M-# c @kindex M-# M-# @@ -9830,7 +9859,7 @@ still exists and is updated silently. @xref{Trail Commands}.@refill In most installations, the @kbd{M-# c} key sequence is a more convenient way to start the Calculator. Also, @kbd{M-# M-#} and @kbd{M-# #} are synonyms for @kbd{M-# c} unless you last used Calc -in its ``keypad'' mode. +in its Keypad mode. @kindex x @kindex M-x @@ -9841,7 +9870,7 @@ for some commands this is the only form. As a convenience, the @kbd{x} key (@code{calc-execute-extended-command}) is like @kbd{M-x} except that it enters the initial string @samp{calc-} for you. For example, the following key sequences are equivalent: -@kbd{S}, @kbd{M-x calc-sin @key{RET}}, @kbd{x sin @key{RET}}.@refill +@kbd{S}, @kbd{M-x calc-sin @key{RET}}, @kbd{x sin @key{RET}}. @cindex Extensions module @cindex @file{calc-ext} module @@ -9854,14 +9883,14 @@ of the Calculator in the common case when all you need to do is a little arithmetic. If for some reason the Calculator fails to load an extension module automatically, you can force it to load all the extensions by using the @kbd{M-# L} (@code{calc-load-everything}) -command. @xref{Mode Settings}.@refill +command. @xref{Mode Settings}. If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument, the Calculator is loaded if necessary, but it is not actually started. If the argument is positive, the @file{calc-ext} extensions are also loaded if necessary. User-written Lisp code that wishes to make use of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)} -to auto-load the Calculator.@refill +to auto-load the Calculator. @kindex M-# b @pindex full-calc @@ -9902,13 +9931,13 @@ the keys with the mouse to operate the calculator. @xref{Keypad Mode}. @pindex calc-quit @cindex Quitting the Calculator @cindex Exiting the Calculator -The @kbd{q} key (@code{calc-quit}) exits Calc Mode and closes the +The @kbd{q} key (@code{calc-quit}) exits Calc mode and closes the Calculator's window(s). It does not delete the Calculator buffers. If you type @kbd{M-x calc} again, the Calculator will reappear with the contents of the stack intact. Typing @kbd{M-# c} or @kbd{M-# M-#} again from inside the Calculator buffer is equivalent to executing @code{calc-quit}; you can think of @kbd{M-# M-#} as toggling the -Calculator on and off.@refill +Calculator on and off. @kindex M-# x The @kbd{M-# x} command also turns the Calculator off, no matter which @@ -9940,7 +9969,7 @@ The @kbd{<} and @kbd{>} keys are bound to @code{calc-scroll-left} and @code{calc-scroll-right}. These are just like the normal horizontal scrolling commands except that they scroll one half-screen at a time by default. (Calc formats its output to fit within the bounds of the -window whenever it can.)@refill +window whenever it can.) @kindex @{ @kindex @} @@ -9949,16 +9978,21 @@ window whenever it can.)@refill @cindex Vertical scrolling The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down} and @code{calc-scroll-up}. They scroll up or down by one-half the -height of the Calc window.@refill +height of the Calc window. @kindex M-# 0 @pindex calc-reset The @kbd{M-# 0} command (@code{calc-reset}; that's @kbd{M-#} followed -by a zero) resets the Calculator to its default state. This clears -the stack, resets all the modes, clears the caches (@pxref{Caches}), -and so on. (It does @emph{not} erase the values of any variables.) -With a numeric prefix argument, @kbd{M-# 0} preserves the contents -of the stack but resets everything else. +by a zero) resets the Calculator to its initial state. This clears +the stack, resets all the modes to their initial values (the values +that were saved with @kbd{m m} (@code{calc-save-modes})), clears the +caches (@pxref{Caches}), and so on. (It does @emph{not} erase the +values of any variables.) With an argument of 0, Calc will be reset to +its default state; namely, the modes will be given their default values. +With a positive prefix argument, @kbd{M-# 0} preserves the contents of +the stack but resets everything else to its initial state; with a +negative prefix argument, @kbd{M-# 0} preserves the contents of the +stack but resets everything else to its default state. @pindex calc-version The @kbd{M-x calc-version} command displays the current version number @@ -10053,7 +10087,7 @@ H a S runs calc-solve-for: a `H a S' v => fsolve(a,v) (?=notes) @noindent which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for} -takes a value @cite{a} from the stack, prompts for a value @cite{v}, +takes a value @expr{a} from the stack, prompts for a value @expr{v}, then applies the algebraic function @code{fsolve} to these values. The @samp{?=notes} message means you can now type @kbd{?} to see additional notes from the summary that apply to this command. @@ -10061,19 +10095,17 @@ additional notes from the summary that apply to this command. @kindex h f @pindex calc-describe-function The @kbd{h f} (@code{calc-describe-function}) command looks up an -algebraic function or a command name in the Calc manual. The -prompt initially contains @samp{calcFunc-}; follow this with an +algebraic function or a command name in the Calc manual. Enter an algebraic function name to look up that function in the Function -Index. Or, backspace and enter a command name beginning with -@samp{calc-} to look it up in the Command Index. This command -will also look up operator symbols that can appear in algebraic -formulas, like @samp{%} and @samp{=>}. +Index or enter a command name beginning with @samp{calc-} to look it +up in the Command Index. This command will also look up operator +symbols that can appear in algebraic formulas, like @samp{%} and +@samp{=>}. @kindex h v @pindex calc-describe-variable The @kbd{h v} (@code{calc-describe-variable}) command looks up a -variable in the Calc manual. The prompt initially contains the -@samp{var-} prefix; just add a variable name like @code{pi} or +variable in the Calc manual. Enter a variable name like @code{pi} or @code{PlotRejects}. @kindex h b @@ -10102,7 +10134,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: @@ -10112,7 +10144,7 @@ The first three keystrokes ``push'' the numbers 1 and 2 onto the stack. The @kbd{+} key always ``pops'' the top two numbers from the stack, adds them, and pushes the result (3) back onto the stack. This number is ready for further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the -3 and 5, subtracts them, and pushes the result (@i{-2}).@refill +3 and 5, subtracts them, and pushes the result (@mathit{-2}). Note that the ``top'' of the stack actually appears at the @emph{bottom} of the buffer. A line containing a single @samp{.} character signifies @@ -10141,12 +10173,12 @@ two consecutive numbers. (After all, if you typed @kbd{1 2} by themselves the Calculator 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 +the stack. @kbd{@key{RET} *} is thus a handy way to square a number. The @key{DEL} key pops and throws away the top number on the stack. The @key{TAB} key swaps the top two objects on the stack. @xref{Stack and Trail}, for descriptions of these and other stack-related -commands.@refill +commands. @node Numeric Entry, Algebraic Entry, Stack Basics, Introduction @section Numeric Entry @@ -10167,16 +10199,16 @@ you press a numeric key which is not valid, the key is ignored. @cindex Negative numbers, entering @kindex _ There are three different concepts corresponding to the word ``minus,'' -typified by @cite{a-b} (subtraction), @cite{-x} -(change-sign), and @cite{-5} (negative number). Calc uses three +typified by @expr{a-b} (subtraction), @expr{-x} +(change-sign), and @expr{-5} (negative number). Calc uses three different keys for these operations, respectively: @kbd{-}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{-} key subtracts the two numbers on the top of the stack. The @kbd{n} key changes the sign of the number on the top of the stack or the number currently being entered. The @kbd{_} key begins entry of a negative number or changes the sign of the number currently being entered. The following sequences all enter the -number @i{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, -@kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.@refill +number @mathit{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, +@kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}. Some other keys are active during numeric entry, such as @kbd{#} for non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. @@ -10196,14 +10228,15 @@ During numeric entry, the only editing key available is @key{DEL}. Calculations can also be entered in algebraic form. This is accomplished by typing the apostrophe key, @kbd{'}, followed by the expression in standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes -@c{$2+(3\times4) = 14$} -@cite{2+(3*4) = 14} and pushes that on the stack. If you wish you can +@texline @math{2+(3\times4) = 14} +@infoline @expr{2+(3*4) = 14} +and pushes that on the stack. If you wish you can ignore the RPN aspect of Calc altogether and simply enter algebraic expressions in this way. You may want to use @key{DEL} every so often to -clear previous results off the stack.@refill +clear previous results off the stack. You can press the apostrophe key during normal numeric entry to switch -the half-entered number into algebraic entry mode. One reason to do this +the half-entered number into Algebraic entry mode. One reason to do this would be to use the full Emacs cursor motion and editing keys, which are available during algebraic entry but not during numeric entry. @@ -10214,7 +10247,7 @@ you complete your half-finished entry in a separate buffer. @kindex m a @pindex calc-algebraic-mode -@cindex Algebraic mode +@cindex Algebraic Mode If you prefer algebraic entry, you can use the command @kbd{m a} (@code{calc-algebraic-mode}) to set Algebraic mode. In this mode, digits and other keys that would normally start numeric entry instead @@ -10223,9 +10256,9 @@ you can omit the apostrophe. Open parentheses and square brackets also begin algebraic entry. You can still do RPN calculations in this mode, but you will have to press @key{RET} to terminate every number: @kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same -thing as @kbd{2*3+4 @key{RET}}.@refill +thing as @kbd{2*3+4 @key{RET}}. -@cindex Incomplete algebraic mode +@cindex Incomplete Algebraic Mode If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a} command, it enables Incomplete Algebraic mode; this is like regular Algebraic mode except that it applies to the @kbd{(} and @kbd{[} keys @@ -10233,15 +10266,15 @@ only. Numeric keys still begin a numeric entry in this mode. @kindex m t @pindex calc-total-algebraic-mode -@cindex Total algebraic mode +@cindex Total Algebraic Mode The @kbd{m t} (@code{calc-total-algebraic-mode}) gives you an even stronger algebraic-entry mode, in which @emph{all} regular letter and punctuation keys begin algebraic entry. Use this if you prefer typing @w{@kbd{sqrt( )}} instead of @kbd{Q}, @w{@kbd{factor( )}} instead of @kbd{a f}, and so on. To type regular Calc commands when you are in -``total'' algebraic mode, hold down the @key{META} key. Thus @kbd{M-q} +Total Algebraic mode, hold down the @key{META} key. Thus @kbd{M-q} 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 +@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 @key{RET} M-S}. The symbol @samp{Alg*} will appear in the mode line whenever you are in this mode. @@ -10259,7 +10292,7 @@ stack with that formula rather than simply pushing the formula onto the stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2 @key{RET}} replaces it with 6. Note that the @kbd{$} key always initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the -first character in the new formula.@refill +first character in the new formula. Higher stack elements can be accessed from an entered formula with the symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements @@ -10267,7 +10300,7 @@ removed (to be replaced by the entered values) equals the number of dollar signs in the longest such symbol in the formula. For example, @samp{$$+$$$} adds the second and third stack elements, replacing the top three elements with the answer. (All information about the top stack element is thus lost -since no single @samp{$} appears in this formula.)@refill +since no single @samp{$} appears in this formula.) A slightly different way to refer to stack elements is with a dollar sign followed by a number: @samp{$1}, @samp{$2}, and so on are much @@ -10292,7 +10325,7 @@ 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 -on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @cite{1+2}; +on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @expr{1+2}; you might then press @kbd{=} when it is time to evaluate this formula. @node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction @@ -10371,7 +10404,7 @@ Many Calculator commands use numeric prefix arguments. Some, such as @kbd{d s} (@code{calc-sci-notation}), set a parameter to the value of the prefix argument or use a default if you don't use a prefix. Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument -and prompt for a number if you don't give one as a prefix.@refill +and prompt for a number if you don't give one as a prefix. As a rule, stack-manipulation commands accept a numeric prefix argument which is interpreted as an index into the stack. A positive argument @@ -10398,7 +10431,7 @@ argument for some other purpose. Numeric prefixes are specified the same way as always in Emacs: Press a sequence of @key{META}-digits, or press @key{ESC} followed by digits, or press @kbd{C-u} followed by digits. Some commands treat plain -@kbd{C-u} (without any actual digits) specially.@refill +@kbd{C-u} (without any actual digits) specially. @kindex ~ @pindex calc-num-prefix @@ -10406,7 +10439,7 @@ You can type @kbd{~} (@code{calc-num-prefix}) to pop an integer from the top of the stack and enter it as the numeric prefix for the next command. For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate (silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2 -to the fourth power and set the precision to that value.@refill +to the fourth power and set the precision to that value. Conversely, if you have typed a numeric prefix argument the @kbd{~} key pushes it onto the stack in the form of an integer. @@ -10454,7 +10487,7 @@ any other change, then it will be too late to redo. The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that it restores the arguments of the most recent command onto the stack; however, it does not remove the result of that command. Given a numeric -prefix argument, this command applies to the @cite{n}th most recent +prefix argument, this command applies to the @expr{n}th most recent command which removed items from the stack; it pushes those items back onto the stack. @@ -10476,7 +10509,7 @@ The standard Emacs @kbd{C-_} undo key is recognized as a synonym for @kbd{U}. @cindex Why did an error occur? Many situations that would produce an error message in other calculators simply create unsimplified formulas in the Emacs Calculator. For example, -@kbd{1 @key{RET} 0 /} pushes the formula @cite{1 / 0}; @w{@kbd{0 L}} pushes +@kbd{1 @key{RET} 0 /} pushes the formula @expr{1 / 0}; @w{@kbd{0 L}} pushes the formula @samp{ln(0)}. Floating-point overflow and underflow are also reasons for this to happen. @@ -10502,7 +10535,7 @@ that you must always press @kbd{w} yourself to see the messages). @noindent @pindex another-calc -It is possible to have any number of Calc Mode buffers at once. +It is possible to have any number of Calc mode buffers at once. Usually this is done by executing @kbd{M-x another-calc}, which is similar to @kbd{M-# c} except that if a @samp{*Calculator*} buffer already exists, a new, independent one with a name of the @@ -10581,7 +10614,7 @@ possible in an attempt to recover from program bugs. If a calculation ever halts incorrectly with the message ``Computation got stuck or ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth}) to increase this limit. (Of course, this will not help if the -calculation really did get stuck due to some problem inside Calc.)@refill +calculation really did get stuck due to some problem inside Calc.) The limit is always increased (multiplied) by a factor of two. There is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which @@ -10599,16 +10632,15 @@ internal Lisp recursion limit. The minimum value for this limit is 600. @cindex Flushing caches Calc saves certain values after they have been computed once. For example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the -constant @c{$\pi$} -@cite{pi} to about 20 decimal places; if the current precision -is greater than this, it will recompute @c{$\pi$} -@cite{pi} using a series +constant @cpi{} to about 20 decimal places; if the current precision +is greater than this, it will recompute @cpi{} using a series approximation. This value will not need to be recomputed ever again unless you raise the precision still further. Many operations such as logarithms and sines make use of similarly cached values such as -@c{$\pi \over 4$} -@cite{pi/4} and @c{$\ln 2$} -@cite{ln(2)}. The visible effect of caching is that +@cpiover{4} and +@texline @math{\ln 2}. +@infoline @expr{ln(2)}. +The visible effect of caching is that high-precision computations may seem to do extra work the first time. Other things cached include powers of two (for the binary arithmetic functions), matrix inverses and determinants, symbolic integrals, and @@ -10681,7 +10713,7 @@ will be lost. This chapter discusses the various types of objects that can be placed on the Calculator stack, how they are displayed, and how they are entered. (@xref{Data Type Formats}, for information on how these data -types are represented as underlying Lisp objects.)@refill +types are represented as underlying Lisp objects.) Integers, fractions, and floats are various ways of describing real numbers. HMS forms also for many purposes act as real numbers. These @@ -10718,13 +10750,13 @@ The Calculator stores integers to arbitrary precision. Addition, subtraction, and multiplication of integers always yields an exact integer result. (If the result of a division or exponentiation of integers is not an integer, it is expressed in fractional or -floating-point form according to the current Fraction Mode. +floating-point form according to the current Fraction mode. @xref{Fraction Mode}.) A decimal integer is represented as an optional sign followed by a sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to insert a comma at every third digit for display purposes, but you -must not type commas during the entry of numbers.@refill +must not type commas during the entry of numbers. @kindex # A non-decimal integer is represented as an optional sign, a radix @@ -10733,7 +10765,7 @@ and above, the letters A through Z (upper- or lower-case) count as digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how to set the default radix for display of integers. Numbers of any radix may be entered at any time. If you press @kbd{#} at the beginning of a -number, the current display radix is used.@refill +number, the current display radix is used. @node Fractions, Floats, Integers, Data Types @section Fractions @@ -10744,17 +10776,17 @@ A @dfn{fraction} is a ratio of two integers. Fractions are traditionally written ``2/3'' but Calc uses the notation @samp{2:3}. (The @kbd{/} key performs RPN division; the following two sequences push the number @samp{2:3} on the stack: @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /} -assuming Fraction Mode has been enabled.) +assuming Fraction mode has been enabled.) When the Calculator produces a fractional result it always reduces it to -simplest form, which may in fact be an integer.@refill +simplest form, which may in fact be an integer. Fractions may also be entered in a three-part form, where @samp{2:3:4} represents two-and-three-quarters. @xref{Fraction Formats}, for fraction -display formats.@refill +display formats. Non-decimal fractions are entered and displayed as @samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part -form). The numerator and denominator always use the same radix.@refill +form). The numerator and denominator always use the same radix. @node Floats, Complex Numbers, Fractions, Data Types @section Floats @@ -10764,12 +10796,13 @@ form). The numerator and denominator always use the same radix.@refill A floating-point number or @dfn{float} is a number stored in scientific notation. The number of significant digits in the fractional part is governed by the current floating precision (@pxref{Precision}). The -range of acceptable values is from @c{$10^{-3999999}$} -@cite{10^-3999999} (inclusive) -to @c{$10^{4000000}$} -@cite{10^4000000} -(exclusive), plus the corresponding negative -values and zero. +range of acceptable values is from +@texline @math{10^{-3999999}} +@infoline @expr{10^-3999999} +(inclusive) to +@texline @math{10^{4000000}} +@infoline @expr{10^4000000} +(exclusive), plus the corresponding negative values and zero. Calculations that would exceed the allowable range of values (such as @samp{exp(exp(20))}) are left in symbolic form by Calc. The @@ -10810,7 +10843,7 @@ final result accurate to the full requested precision. However, accuracy is not rigorously guaranteed. If you suspect the validity of a result, try doing the same calculation in a higher precision. The Calculator's arithmetic is not intended to be IEEE-conformant in any -way.@refill +way. While floats are always @emph{stored} in decimal, they can be entered and displayed in any radix just like integers and fractions. The @@ -10836,16 +10869,20 @@ polar. The default format is rectangular, displayed in the form @samp{(@var{real},@var{imag})} where @var{real} is the real part and @var{imag} is the imaginary part, each of which may be any real number. Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} -notation; @pxref{Complex Formats}.@refill - -Polar complex numbers are displayed in the form `@t{(}@var{r}@t{;}@c{$\theta$} -@var{theta}@t{)}' -where @var{r} is the nonnegative magnitude and @c{$\theta$} -@var{theta} is the argument -or phase angle. The range of @c{$\theta$} -@var{theta} depends on the current angular -mode (@pxref{Angular Modes}); it is generally between @i{-180} and -@i{+180} degrees or the equivalent range in radians.@refill +notation; @pxref{Complex Formats}. + +Polar complex numbers are displayed in the form +@texline `@t{(}@var{r}@t{;}@math{\theta}@t{)}' +@infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}' +where @var{r} is the nonnegative magnitude and +@texline @math{\theta} +@infoline @var{theta} +is the argument or phase angle. The range of +@texline @math{\theta} +@infoline @var{theta} +depends on the current angular mode (@pxref{Angular Modes}); it is +generally between @mathit{-180} and @mathit{+180} degrees or the equivalent range +in radians. Complex numbers are entered in stages using incomplete objects. @xref{Incomplete Objects}. @@ -10853,12 +10890,11 @@ Complex numbers are entered in stages using incomplete objects. Operations on rectangular complex numbers yield rectangular complex results, and similarly for polar complex numbers. Where the two types are mixed, or where new complex numbers arise (as for the square root of -a negative real), the current @dfn{Polar Mode} is used to determine the +a negative real), the current @dfn{Polar mode} is used to determine the type. @xref{Polar Mode}. A complex result in which the imaginary part is zero (or the phase angle -is 0 or 180 degrees or @c{$\pi$} -@cite{pi} radians) is automatically converted to a real +is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real number. @node Infinities, Vectors and Matrices, Complex Numbers, Data Types @@ -10883,24 +10919,25 @@ entered using algebraic entry. Mathematically speaking, it is not rigorously correct to treat ``infinity'' as if it were a number, but mathematicians often do so informally. When they say that @samp{1 / inf = 0}, what they -really mean is that @cite{1 / x}, as @cite{x} becomes larger and +really mean is that @expr{1 / x}, as @expr{x} becomes larger and larger, becomes arbitrarily close to zero. So you can imagine -that if @cite{x} got ``all the way to infinity,'' then @cite{1 / x} +that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x} would go all the way to zero. Similarly, when they say that -@samp{exp(inf) = inf}, they mean that @c{$e^x$} -@cite{exp(x)} grows without -bound as @cite{x} grows. The symbol @samp{-inf} likewise stands -for an infinitely negative real value; for example, we say that +@samp{exp(inf) = inf}, they mean that +@texline @math{e^x} +@infoline @expr{exp(x)} +grows without bound as @expr{x} grows. The symbol @samp{-inf} likewise +stands for an infinitely negative real value; for example, we say that @samp{exp(-inf) = 0}. You can have an infinity pointing in any direction on the complex plane: @samp{sqrt(-inf) = i inf}. -The same concept of limits can be used to define @cite{1 / 0}. We -really want the value that @cite{1 / x} approaches as @cite{x} -approaches zero. But if all we have is @cite{1 / 0}, we can't -tell which direction @cite{x} was coming from. If @cite{x} was +The same concept of limits can be used to define @expr{1 / 0}. We +really want the value that @expr{1 / x} approaches as @expr{x} +approaches zero. But if all we have is @expr{1 / 0}, we can't +tell which direction @expr{x} was coming from. If @expr{x} was positive and decreasing toward zero, then we should say that -@samp{1 / 0 = inf}. But if @cite{x} was negative and increasing -toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @cite{x} +@samp{1 / 0 = inf}. But if @expr{x} was negative and increasing +toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @expr{x} could be an imaginary number, giving the answer @samp{i inf} or @samp{-i inf}. Calc uses the special symbol @samp{uinf} to mean @dfn{undirected infinity}, i.e., a value which is infinitely @@ -10908,10 +10945,10 @@ large but with an unknown sign (or direction on the complex plane). Calc actually has three modes that say how infinities are handled. Normally, infinities never arise from calculations that didn't -already have them. Thus, @cite{1 / 0} is treated simply as an +already have them. Thus, @expr{1 / 0} is treated simply as an error and left unevaluated. The @kbd{m i} (@code{calc-infinite-mode}) command (@pxref{Infinite Mode}) enables a mode in which -@cite{1 / 0} evaluates to @code{uinf} instead. There is also +@expr{1 / 0} evaluates to @code{uinf} instead. There is also an alternative type of infinite mode which says to treat zeros as if they were positive, so that @samp{1 / 0 = inf}. While this is less mathematically correct, it may be the answer you want in @@ -10930,9 +10967,9 @@ notation. It's not so easy to define certain formulas like @samp{0 * inf} and @samp{inf / inf}. Depending on where these zeros and infinities came from, the answer could be literally anything. The latter -formula could be the limit of @cite{x / x} (giving a result of one), -or @cite{2 x / x} (giving two), or @cite{x^2 / x} (giving @code{inf}), -or @cite{x / x^2} (giving zero). Calc uses the symbol @code{nan} +formula could be the limit of @expr{x / x} (giving a result of one), +or @expr{2 x / x} (giving two), or @expr{x^2 / x} (giving @code{inf}), +or @expr{x / x^2} (giving zero). Calc uses the symbol @code{nan} to represent such an @dfn{indeterminate} value. (The name ``nan'' comes from analogy with the ``NAN'' concept of IEEE standard arithmetic; it stands for ``Not A Number.'' This is somewhat of a @@ -10941,7 +10978,7 @@ infinity, it's just that @emph{which} number it stands for cannot be determined.) In Calc's notation, @samp{0 * inf = nan} and @samp{inf / inf = nan}. A few other common indeterminate expressions are @samp{inf - inf} and @samp{inf ^ 0}. Also, -@samp{0 / 0 = nan} if you have turned on ``infinite mode'' +@samp{0 / 0 = nan} if you have turned on Infinite mode (as described above). Infinities are especially useful as parts of @dfn{intervals}. @@ -10976,15 +11013,16 @@ Traditional vector and matrix arithmetic is also supported; @pxref{Basic Arithmetic} and @pxref{Matrix Functions}. 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 +of its elements. @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$} -@asis{@var{n}x@var{m}} +to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an +@texline @math{n\times m} +@infoline @var{n}x@var{m} matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers from 1 to @samp{n}. @@ -11114,8 +11152,8 @@ The @var{mins} value is an integer or integer-valued float between 0 and 59. The @var{secs} value is a real number between 0 (inclusive) and 60 (exclusive). A positive HMS form is interpreted as @var{hours} + @var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted -as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600. -Display format for HMS forms is quite flexible. @xref{HMS Formats}.@refill +as @mathit{- @var{hours}} @mathit{-} @var{mins}/60 @mathit{-} @var{secs}/3600. +Display format for HMS forms is quite flexible. @xref{HMS Formats}. HMS forms can be added and subtracted. When they are added to numbers, the numbers are interpreted according to the current angular mode. HMS @@ -11161,7 +11199,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. @@ -11208,12 +11246,12 @@ between, say, @samp{<12:00am Mon Jan 1, 1900>} and Calc uses the Julian calendar for all dates before the year 1752, including dates BC when the Julian calendar technically had not -yet been invented. Thus the claim that day number @i{-10000} is +yet been invented. Thus the claim that day number @mathit{-10000} is called ``August 16, 28 BC'' should be taken with a grain of salt. Please note that there is no ``year 0''; the day before @samp{} is @samp{}. These are -days 0 and @i{-1} respectively in Calc's internal numbering scheme. +days 0 and @mathit{-1} respectively in Calc's internal numbering scheme. @cindex Julian day counting Another day counting system in common use is, confusingly, also @@ -11221,7 +11259,7 @@ called ``Julian.'' It was invented in 1583 by Joseph Justus Scaliger, who named it in honor of his father Julius Caesar Scaliger. For obscure reasons he chose to start his day numbering on Jan 1, 4713 BC at noon, which in Calc's scheme -is @i{-1721423.5} (recall that Calc starts at midnight instead +is @mathit{-1721423.5} (recall that Calc starts at midnight instead of noon). Thus to convert a Calc date code obtained by unpacking a date form into a Julian day number, simply add 1721423.5. The Julian code for @samp{6:00am Jan 9, 1991} @@ -11254,10 +11292,10 @@ an integer multiple of) some value @var{M}. Arithmetic modulo @var{M} often arises in number theory. Modulo forms are written `@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 -integers but this is not required.@refill +@texline @math{0 \le a < M}. +@infoline @expr{0 <= a < @var{M}}. +In many applications @expr{a} and @expr{M} will be +integers but this is not required. Modulo forms are not to be confused with the modulo operator @samp{%}. The expression @samp{27 % 10} means to compute 27 modulo 10 to produce @@ -11266,28 +11304,30 @@ The expression @samp{27 mod 10} produces the result @samp{7 mod 10}; further computations with this value are again reduced modulo 10 so that the result always lies in the desired range. -When two modulo forms with identical @cite{M}'s are added or multiplied, +When two modulo forms with identical @expr{M}'s are added or multiplied, the Calculator simply adds or multiplies the values, then reduces modulo -@cite{M}. If one argument is a modulo form and the other a plain number, +@expr{M}. If one argument is a modulo form and the other a plain number, the plain number is treated like a compatible modulo form. It is also possible to raise modulo forms to powers; the result is the value raised -to the power, then reduced modulo @cite{M}. (When all values involved +to the power, then reduced modulo @expr{M}. (When all values involved are integers, this calculation is done much more efficiently than actually computing the power and then reducing.) @cindex Modulo division 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 +can be divided if @expr{a}, @expr{b}, and @expr{M} are all integers. The result is the modulo form which, when multiplied by `@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 +@expr{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{(}@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 +in the sense of reducing +@texline @math{\sqrt a} +@infoline @expr{sqrt(a)} +modulo @expr{M}, this is not a useful definition from the +number-theoretical point of view.) @ignore @mindex M @@ -11299,17 +11339,17 @@ useful definition from the number-theoretical point of view.)@refill @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 -shift-@kbd{M} a second time automatically enters the value of @cite{M} +shift-@kbd{M} a second time automatically enters the value of @expr{M} that was most recently used before. During algebraic entry, either type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}). -Once again, pressing this a second time enters the current modulo.@refill +Once again, pressing this a second time enters the current modulo. You can also use @kbd{v p} and @kbd{%} to modify modulo forms. @xref{Building Vectors}. @xref{Basic Arithmetic}. It is possible to mix HMS forms and modulo forms. For example, an HMS form modulo 24 could be used to manipulate clock times; an HMS -form modulo 360 would be suitable for angles. Making the modulo @cite{M} +form modulo 360 would be suitable for angles. Making the modulo @expr{M} also be an HMS form eliminates troubles that would arise if the angular mode were inadvertently set to Radians, in which case @w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo @@ -11334,24 +11374,28 @@ 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 -`@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$} -@cite{sigma}. Both the mean and the error can be either numbers or +@texline `@var{x} @t{+/-} @math{\sigma}' +@infoline `@var{x} @t{+/-} sigma' +stands for an uncertain value which follows +a normal or Gaussian distribution of mean @expr{x} and standard +deviation or ``error'' +@texline @math{\sigma}. +@infoline @expr{sigma}. +Both the mean and the error can be either numbers or formulas. Generally these are real numbers but the mean may also be complex. If the error is negative or complex, it is changed to its absolute value. An error form with zero error is converted to a -regular number by the Calculator.@refill +regular number by the Calculator. All arithmetic and transcendental functions accept error forms as input. Operations on the mean-value part work just like operations on regular -numbers. The error part for any function @cite{f(x)} (such as @c{$\sin x$} -@cite{sin(x)}) -is defined by the error of @cite{x} times the derivative of @cite{f} -evaluated at the mean value of @cite{x}. For a two-argument function -@cite{f(x,y)} (such as addition) the error is the square root of the sum -of the squares of the errors due to @cite{x} and @cite{y}. +numbers. The error part for any function @expr{f(x)} (such as +@texline @math{\sin x} +@infoline @expr{sin(x)}) +is defined by the error of @expr{x} times the derivative of @expr{f} +evaluated at the mean value of @expr{x}. For a two-argument function +@expr{f(x,y)} (such as addition) the error is the square root of the sum +of the squares of the errors due to @expr{x} and @expr{y}. @tex $$ \eqalign{ f(x \hbox{\code{ +/- }} \sigma) @@ -11365,38 +11409,48 @@ $$ \eqalign{ } $$ @end tex Note that this -definition assumes the errors in @cite{x} and @cite{y} are uncorrelated. +definition assumes the errors in @expr{x} and @expr{y} are uncorrelated. A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)} is not the same as @samp{(2 +/- 1)^2}; the former represents the product of two independent values which happen to have the same probability distributions, and the latter is the product of one random value with itself. The former will produce an answer with less error, since on the average -the two independent errors can be expected to cancel out.@refill +the two independent errors can be expected to cancel out. 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(}@var{x} @t{+/-} @c{$\sigma$} -@var{sigma}@t{)}' is -`@c{$\sigma$\nobreak} -@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$} -@cite{sigma}; this makes sense, since @c{$\sin x$} -@cite{sin(x)} is approximately @cite{x} near zero, so a given -error in @cite{x} will produce about the same error in the sine. Likewise, -near 90 degrees @c{$\cos x$} -@cite{cos(x)} is nearly zero and so the computed error is -small: The sine curve is nearly flat in that region, so an error in @cite{x} -has relatively little effect on the value of @c{$\sin x$} -@cite{sin(x)}. However, consider -@samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so Calc will report -zero error! We get an obviously wrong result because we have violated -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 +@texline `@t{sin(}@var{x} @t{+/-} @math{\sigma}@t{)}' +@infoline `@t{sin(}@var{x} @t{+/-} @var{sigma}@t{)}' +is +@texline `@math{\sigma} @t{abs(cos(}@var{x}@t{))}'. +@infoline `@var{sigma} @t{abs(cos(}@var{x}@t{))}'. +When @expr{x} is close to zero, +@texline @math{\cos x} +@infoline @expr{cos(x)} +is close to one so the error in the sine is close to +@texline @math{\sigma}; +@infoline @expr{sigma}; +this makes sense, since +@texline @math{\sin x} +@infoline @expr{sin(x)} +is approximately @expr{x} near zero, so a given error in @expr{x} will +produce about the same error in the sine. Likewise, near 90 degrees +@texline @math{\cos x} +@infoline @expr{cos(x)} +is nearly zero and so the computed error is +small: The sine curve is nearly flat in that region, so an error in @expr{x} +has relatively little effect on the value of +@texline @math{\sin x}. +@infoline @expr{sin(x)}. +However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so +Calc will report zero error! We get an obviously wrong result because +we have violated the small-error approximation underlying the error +analysis. If the error in @expr{x} had been small, the error in +@texline @math{\sin x} +@infoline @expr{sin(x)} +would indeed have been negligible. @ignore @mindex p @@ -11449,10 +11503,10 @@ intervals of the type shown above, @dfn{open} intervals such as @emph{exclusive}, and @dfn{semi-open} intervals in which one end uses a round parenthesis and the other a square bracket. In mathematical terms, -@samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas -@samp{[2 ..@: 4)} represents @cite{2 <= x < 4}, -@samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and -@samp{(2 ..@: 4)} represents @cite{2 < x < 4}.@refill +@samp{[2 ..@: 4]} means @expr{2 <= x <= 4}, whereas +@samp{[2 ..@: 4)} represents @expr{2 <= x < 4}, +@samp{(2 ..@: 4]} represents @expr{2 < x <= 4}, and +@samp{(2 ..@: 4)} represents @expr{2 < x < 4}. @end ifinfo @tex Calc supports several varieties of intervals, including \dfn{closed} @@ -11490,10 +11544,10 @@ rather than @samp{1 ..@: 0.1e2}. Add spaces or zeros if you want to get the other interpretation. If you omit the lower or upper limit, a default of @samp{-inf} or @samp{inf} (respectively) is furnished. -``Infinite mode'' also affects operations on intervals +Infinite mode also affects operations on intervals (@pxref{Infinities}). Calc will always introduce an open infinity, as in @samp{1 / (0 .. 2] = [0.5 .. inf)}. But closed infinities, -@w{@samp{1 / [0 .. 2] = [0.5 .. inf]}}, arise only in infinite mode; +@w{@samp{1 / [0 .. 2] = [0.5 .. inf]}}, arise only in Infinite mode; otherwise they are left unevaluated. Note that the ``direction'' of a zero is not an issue in this case since the zero is always assumed to be continuous with the rest of the interval. For intervals that @@ -11502,14 +11556,19 @@ 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 `@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$} -@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 +form +@texline `@var{x} @t{+/-} @math{\sigma}' +@infoline `@var{x} @t{+/-} @var{sigma}' +means a variable is random, and its value could +be anything but is ``probably'' within one +@texline @math{\sigma} +@infoline @var{sigma} +of the mean value @expr{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. Intervals may not contain complex numbers, but they may contain HMS forms or date forms. @@ -11575,7 +11634,7 @@ pushes the complex number @samp{(1, 1.414)} (approximately). If several values lie on the stack in front of the incomplete object, all are collected and appended to the object. Thus the @kbd{,} key is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people -prefer the equivalent @key{SPC} key to @key{RET}.@refill +prefer the equivalent @key{SPC} key to @key{RET}. As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or @kbd{,} adds a zero or duplicates the preceding value in the list being @@ -11610,26 +11669,26 @@ calculator, and a variable in a programming language. (In fact, a Calc variable is really just an Emacs Lisp variable that contains a Calc number or formula.) A variable's name is normally composed of letters and digits. Calc also allows apostrophes and @code{#} signs in variable names. -The Calc variable @code{foo} corresponds to the Emacs Lisp variable -@code{var-foo}. Commands like @kbd{s s} (@code{calc-store}) that operate -on variables can be made to use any arbitrary Lisp variable simply by -backspacing over the @samp{var-} prefix in the minibuffer.@refill +(The Calc variable @code{foo} corresponds to the Emacs Lisp variable +@code{var-foo}, but unless you access the variable from within Emacs +Lisp, you don't need to worry about it. Variable names in algebraic +formulas implicitly have @samp{var-} prefixed to their names. The +@samp{#} character in variable names used in algebraic formulas +corresponds to a dash @samp{-} in the Lisp variable name. If the name +contains any dashes, the prefix @samp{var-} is @emph{not} automatically +added. Thus the two formulas @samp{foo + 1} and @samp{var#foo + 1} both +refer to the same variable.) In a command that takes a variable name, you can either type the full name of a variable, or type a single digit to use one of the special -convenience variables @code{var-q0} through @code{var-q9}. For example, -@kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and +convenience variables @code{q0} through @code{q9}. For example, +@kbd{3 s s 2} stores the number 3 in variable @code{q2}, and @w{@kbd{3 s s foo @key{RET}}} stores that number in variable -@code{var-foo}.@refill +@code{foo}. To push a variable itself (as opposed to the variable's value) on the stack, enter its name as an algebraic expression using the apostrophe -(@key{'}) key. Variable names in algebraic formulas implicitly have -@samp{var-} prefixed to their names. The @samp{#} character in variable -names used in algebraic formulas corresponds to a dash @samp{-} in the -Lisp variable name. If the name contains any dashes, the prefix @samp{var-} -is @emph{not} automatically added. Thus the two formulas @samp{foo + 1} -and @samp{var#foo + 1} both refer to the same variable. +(@key{'}) key. @kindex = @pindex calc-evaluate @@ -11661,7 +11720,7 @@ A few variables are called @dfn{special constants}. Their names are (@xref{Scientific Functions}.) When they are evaluated with @kbd{=}, their values are calculated if necessary according to the current precision or complex polar mode. If you wish to use these symbols for other purposes, -simply undefine or redefine them using @code{calc-store}.@refill +simply undefine or redefine them using @code{calc-store}. The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for infinite or indeterminate values. It's best not to use them as @@ -11735,8 +11794,9 @@ the C-style ``if'' operator @samp{a?b:c} [@code{if}]; @samp{=>} [@code{evalto}]. Note that, unlike in usual computer notation, multiplication binds more -strongly than division: @samp{a*b/c*d} is equivalent to @c{$a b \over c d$} -@cite{(a*b)/(c*d)}. +strongly than division: @samp{a*b/c*d} is equivalent to +@texline @math{a b \over c d}. +@infoline @expr{(a*b)/(c*d)}. @cindex Multiplication, implicit @cindex Implicit multiplication @@ -11750,7 +11810,7 @@ is interpreted as a function call, not an implicit @samp{*}. In many cases you must use a space if you omit the @samp{*}: @samp{2a} is the same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab} is a variable called @code{ab}, @emph{not} the product of @samp{a} and -@samp{b}! Also note that @samp{f (x)} is still a function call.@refill +@samp{b}! Also note that @samp{f (x)} is still a function call. @cindex Implicit comma in vectors The rules are slightly different for vectors written with square brackets. @@ -11762,7 +11822,7 @@ Note that spaces around the brackets, and around explicit commas, are ignored. To force spaces to be interpreted as multiplication you can enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted -between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill +between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}. Vectors that contain commas (not embedded within nested parentheses or brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector @@ -11781,28 +11841,28 @@ an infix operator preferentially (modulo, in this case), so you would need to write @samp{(5%)-2} to get the former interpretation. @cindex Function call notation -A function call is, e.g., @samp{sin(1+x)}. Function names follow the same -rules as variable names except that the default prefix @samp{calcFunc-} is -used (instead of @samp{var-}) for the internal Lisp form. -Most mathematical Calculator commands like +A function call is, e.g., @samp{sin(1+x)}. (The Calc algebraic function +@code{foo} corresponds to the Emacs Lisp function @code{calcFunc-foo}, +but unless you access the function from within Emacs Lisp, you don't +need to worry about it.) Most mathematical Calculator commands like @code{calc-sin} have function equivalents like @code{sin}. If no Lisp function is defined for a function called by a formula, the call is left as it is during algebraic manipulation: @samp{f(x+y)} is left alone. Beware that many innocent-looking short names like @code{in} and @code{re} have predefined meanings which could surprise you; however, single letters or single letters followed by digits are always safe to -use for your own function names. @xref{Function Index}.@refill +use for your own function names. @xref{Function Index}. In the documentation for particular commands, the notation @kbd{H S} (@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all -represent the same operation.@refill +represent the same operation. Commands that interpret (``parse'') text as algebraic formulas include algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse the contents of the editing buffer when you finish, the @kbd{M-# g} and @w{@kbd{M-# r}} commands, the @kbd{C-y} command, the X window system -``paste'' mouse operation, and Embedded Mode. All of these operations +``paste'' mouse operation, and Embedded mode. All of these operations use the same rules for parsing formulas; in particular, language modes (@pxref{Language Modes}) affect them all in the same way. @@ -11861,7 +11921,7 @@ For example, with @samp{10 20 30} on the stack, @key{RET} creates @samp{10 20 30 30}, @kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30}, @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 +@kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}. @kindex @key{LFD} @pindex calc-over @@ -11871,7 +11931,7 @@ except that the sign of the numeric prefix argument is interpreted oppositely. Also, with no prefix argument the default argument is 2. 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 +@samp{10 20 30 20}. @kindex @key{DEL} @kindex C-d @@ -11889,7 +11949,7 @@ For example, with @samp{10 20 30} on the stack, @key{DEL} leaves @samp{10 20}, @kbd{C-u 2 @key{DEL}} leaves @samp{10}, @kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and -@kbd{C-u 0 @key{DEL}} leaves an empty stack.@refill +@kbd{C-u 0 @key{DEL}} leaves an empty stack. @kindex M-@key{DEL} @pindex calc-pop-above @@ -11912,7 +11972,7 @@ For example, with @samp{10 20 30 40 50} on the stack, @key{TAB} creates @samp{10 20 30 50 40}, @kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40}, @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 +@kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}. @kindex M-@key{TAB} @pindex calc-roll-up @@ -11923,7 +11983,7 @@ For example, with @samp{10 20 30 40 50} on the stack, @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 +@kbd{C-u 0 M-@key{TAB}} creates @samp{50 40 30 20 10}. 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. @@ -11933,11 +11993,11 @@ 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 +With a negative argument @mathit{-@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{@var{n}+1}. +stack, and the object in level @mathit{@var{n}+1} to the top. @kbd{M-@key{TAB}} +rotates the deepest stack element to be in level @mathit{n}, also +putting the top stack element in level @mathit{@var{n}+1}. @xref{Selecting Subformulas}, for a way to apply these commands to any portion of a vector or formula on the stack. @@ -11956,13 +12016,11 @@ regular Emacs commands. With a numeric prefix argument, it edits the specified number of stack entries at once. (An argument of zero edits the entire stack; a negative argument edits one specific stack entry.) -When you are done editing, press @kbd{M-# M-#} to finish and return +When you are done editing, press @kbd{C-c C-c} to finish and return to Calc. The @key{RET} and @key{LFD} keys also work to finish most sorts of editing, though in some cases Calc leaves @key{RET} with its usual meaning (``insert a newline'') if it's a situation where you -might want to insert new lines into the editing buffer. The traditional -Emacs ``finish'' key sequence, @kbd{C-c C-c}, also works to finish -editing and may be easier to type, depending on your keyboard. +might want to insert new lines into the editing buffer. When you finish editing, the Calculator parses the lines of text in the @samp{*Calc Edit*} buffer as numbers or formulas, replaces the @@ -11970,18 +12028,18 @@ original stack elements in the original buffer with these new values, then kills the @samp{*Calc Edit*} buffer. The original Calculator buffer continues to exist during editing, but for best results you should be careful not to change it until you have finished the edit. You can -also cancel the edit by pressing @kbd{M-# x}. +also cancel the edit by killing the buffer with @kbd{C-x k}. The formula is normally reevaluated as it is put onto the stack. For example, editing @samp{a + 2} to @samp{3 + 2} and pressing -@kbd{M-# M-#} will push 5 on the stack. If you use @key{LFD} to +@kbd{C-c C-c} will push 5 on the stack. If you use @key{LFD} to finish, Calc will put the result on the stack without evaluating it. -If you give a prefix argument to @kbd{M-# M-#} (or @kbd{C-c C-c}), +If you give a prefix argument to @kbd{C-c C-c}, Calc will not kill the @samp{*Calc Edit*} buffer. You can switch back to that buffer and continue editing if you wish. However, you should understand that if you initiated the edit with @kbd{`}, the -@kbd{M-# M-#} operation will be programmed to replace the top of the +@kbd{C-c C-c} operation will be programmed to replace the top of the stack with the new edited value, and it will do this even if you have rearranged the stack in the meanwhile. This is not so much of a problem with other editing commands, though, such as @kbd{s e} @@ -12026,7 +12084,7 @@ The @kbd{t i} (@code{calc-trail-in}) and @kbd{t o} Calc Trail window. In practice they are rarely used, since the commands shown below are a more convenient way to move around in the trail, and they work ``by remote control'' when the cursor is still -in the Calculator window.@refill +in the Calculator window. @cindex Trail pointer There is a @dfn{trail pointer} which selects some entry of the trail at @@ -12049,7 +12107,7 @@ trail pointer. @pindex calc-trail-scroll-right The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >} (@code{calc-trail-scroll-right}) commands horizontally scroll the trail -window left or right by one half of its width.@refill +window left or right by one half of its width. @kindex t n @pindex calc-trail-next @@ -12064,7 +12122,7 @@ The @kbd{t n} (@code{calc-trail-next}) and @kbd{t p} one line. The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b} (@code{calc-trail-backward}) commands move the trail pointer down or up one screenful at a time. All of these commands accept numeric prefix -arguments to move several lines or screenfuls at a time.@refill +arguments to move several lines or screenfuls at a time. @kindex t [ @pindex calc-trail-first @@ -12076,7 +12134,7 @@ The @kbd{t [} (@code{calc-trail-first}) and @kbd{t ]} (@code{calc-trail-last}) commands move the trail pointer to the first or last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command moves the trail pointer to the cursor position; unlike the other trail -commands, @kbd{t h} works only when Calc Trail is the selected window.@refill +commands, @kbd{t h} works only when Calc Trail is the selected window. @kindex t s @pindex calc-trail-isearch-forward @@ -12088,7 +12146,7 @@ The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r} search forward or backward through the trail. You can press @key{RET} to terminate the search; the trail pointer moves to the current line. If you cancel the search with @kbd{C-g}, the trail pointer stays where -it was when the search began.@refill +it was when the search began. @end ifinfo @tex The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r} @@ -12130,16 +12188,18 @@ arguments from the stack. For example, after @kbd{2 @key{RET} 3 +}, the stack contains the sole number 5, but after @kbd{2 @key{RET} 3 K +}, the stack contains the arguments and the result: @samp{2 3 5}. -This works for all commands that take arguments off the stack. As -another example, @kbd{K a s} simplifies a formula, pushing the +With the exception of keyboard macros, this works for all commands that +take arguments off the stack. (To avoid potentially unpleasant behavior, +a @kbd{K} prefix before a keyboard macro will be ignored. A @kbd{K} +prefix called @emph{within} the keyboard macro will still take effect.) +As 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{@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{@key{RET} a s} could be noticeable; @kbd{K a s} -would avoid this extra work. +formula (rather than replacing the original formula). 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{@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 popping two values and pushing them back in the opposite order, @@ -12152,13 +12212,6 @@ original argument you could use either @kbd{' sin($1)} or @kbd{K ' sin($)}. @xref{Algebraic Entry}. Also, the @kbd{s s} command is effectively the same as @kbd{K s t}. @xref{Storing Variables}. -Keyboard macros may interact surprisingly with the @kbd{K} prefix. -If you have defined a keyboard macro to be, say, @samp{Q +} to add -one number to the square root of another, then typing @kbd{K X} will -execute @kbd{K Q +}, probably not what you expected. The @kbd{K} -prefix will apply to just the first command in the macro rather than -the whole macro. - If you execute a command and then decide you really wanted to keep the argument, you can press @kbd{M-@key{RET}} (@code{calc-last-args}). This command pushes the last arguments that were popped by any command @@ -12196,44 +12249,46 @@ the @emph{appearance} or @emph{interpretation} of the stack's contents. @cindex Continuous memory @cindex Saving mode settings @cindex Permanent mode settings -@cindex @file{.emacs} file, mode settings -You can save all of the current mode settings in your @file{.emacs} file -with the @kbd{m m} (@code{calc-save-modes}) command. This will cause -Emacs to reestablish these modes each time it starts up. The modes saved -in the file include everything controlled by the @kbd{m} and @kbd{d} -prefix keys, the current precision and binary word size, whether or not -the trail is displayed, the current height of the Calc window, and more. -The current interface (used when you type @kbd{M-# M-#}) is also saved. -If there were already saved mode settings in the file, they are replaced. -Otherwise, the new mode information is appended to the end of the file. +@cindex Calc init file, mode settings +You can save all of the current mode settings in your Calc init file +(the file given by the variable @code{calc-settings-file}, typically +@file{~/.calc.el}) with the @kbd{m m} (@code{calc-save-modes}) command. +This will cause Emacs to reestablish these modes each time it starts up. +The modes saved in the file include everything controlled by the @kbd{m} +and @kbd{d} prefix keys, the current precision and binary word size, +whether or not the trail is displayed, the current height of the Calc +window, and more. The current interface (used when you type @kbd{M-# +M-#}) is also saved. If there were already saved mode settings in the +file, they are replaced. Otherwise, the new mode information is +appended to the end of the file. @kindex m R @pindex calc-mode-record-mode The @kbd{m R} (@code{calc-mode-record-mode}) command tells Calc to record the new mode settings (as if by pressing @kbd{m m}) every -time a mode setting changes. If Embedded Mode is enabled, other +time a mode setting changes. If Embedded mode is enabled, other options are available; @pxref{Mode Settings in Embedded Mode}. @kindex m F @pindex calc-settings-file-name The @kbd{m F} (@code{calc-settings-file-name}) command allows you to -choose a different place than your @file{.emacs} file for @kbd{m m}, -@kbd{Z P}, and similar commands to save permanent information. +choose a different file than the current value of @code{calc-settings-file} +for @kbd{m m}, @kbd{Z P}, and similar commands to save permanent information. You are prompted for a file name. All Calc modes are then reset to their default values, then settings from the file you named are loaded if this file exists, and this file becomes the one that Calc will use in the future for commands like @kbd{m m}. The default settings -file name is @file{~/.emacs}. You can see the current file name by +file name is @file{~/.calc.el}. You can see the current file name by giving a blank response to the @kbd{m F} prompt. See also the discussion of the @code{calc-settings-file} variable; @pxref{Installation}. -If the file name you give contains the string @samp{.emacs} anywhere -inside it, @kbd{m F} will not automatically load the new file. This -is because you are presumably switching to your @file{~/.emacs} file, -which may contain other things you don't want to reread. You can give +If the file name you give is your user init file (typically +@file{~/.emacs}), @kbd{m F} will not automatically load the new file. This +is because your user init file may contain other things you don't want +to reread. You can give a numeric prefix argument of 1 to @kbd{m F} to force it to read the -file no matter what its name. Conversely, an argument of @i{-1} tells -@kbd{m F} @emph{not} to read the new file. An argument of 2 or @i{-2} +file no matter what. Conversely, an argument of @mathit{-1} tells +@kbd{m F} @emph{not} to read the new file. An argument of 2 or @mathit{-2} tells @kbd{m F} not to reset the modes to their defaults beforehand, which is useful if you intend your new file to have a variant of the modes present in the file you were using before. @@ -12286,7 +12341,7 @@ what you see is what you get. Reducing the current precision does not round values already on the stack, but those values will be rounded down before being used in any calculation. The @kbd{c 0} through @kbd{c 9} commands (@pxref{Conversions}) can be used to round an -existing value to a new precision.@refill +existing value to a new precision. @cindex Accuracy of calculations It is important to distinguish the concepts of @dfn{precision} and @@ -12329,7 +12384,7 @@ There is no single-key equivalent to the @code{calc-arcsin} function. Instead, you must first press @kbd{I} (@code{calc-inverse}) to set the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}). The @kbd{I} key actually toggles the Inverse Flag. When this flag -is set, the word @samp{Inv} appears in the mode line.@refill +is set, the word @samp{Inv} appears in the mode line. @kindex H @pindex calc-hyperbolic @@ -12338,7 +12393,7 @@ Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}. If both of these flags are set at once, the effect will be @code{calc-arcsinh}. (The Hyperbolic flag is also used by some non-trigonometric commands; for example @kbd{H L} computes a base-10, -instead of base-@i{e}, logarithm.)@refill +instead of base-@mathit{e}, logarithm.) Command names like @code{calc-arcsin} are provided for completeness, and may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to @@ -12392,10 +12447,9 @@ Functions that compute angles produce a number in radians, a number in degrees, or an HMS form depending on the current angular mode. If the result is a complex number and the current mode is HMS, the number is instead expressed in degrees. (Complex-number calculations would -normally be done in radians mode, though. Complex numbers are converted +normally be done in Radians mode, though. Complex numbers are converted to degrees by calculating the complex result in radians and then -multiplying by 180 over @c{$\pi$} -@cite{pi}.) +multiplying by 180 over @cpi{}.) @kindex m r @pindex calc-radians-mode @@ -12406,7 +12460,7 @@ multiplying by 180 over @c{$\pi$} The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}), and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode. The current angular mode is displayed on the Emacs mode line. -The default angular mode is degrees.@refill +The default angular mode is Degrees. @node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes @subsection Polar Mode @@ -12422,7 +12476,7 @@ number, or by entering @kbd{( 2 @key{SPC} 3 )}. @kindex m p @pindex calc-polar-mode The @kbd{m p} (@code{calc-polar-mode}) command toggles complex-number -preference between rectangular and polar forms. In polar mode, all +preference between rectangular and polar forms. In Polar mode, all of the above example situations would produce polar complex numbers. @node Fraction Mode, Infinite Mode, Polar Mode, Calculation Modes @@ -12434,16 +12488,16 @@ of the above example situations would produce polar complex numbers. Division of two integers normally yields a floating-point number if the result cannot be expressed as an integer. In some cases you would rather get an exact fractional answer. One way to accomplish this is -to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @cite{3:2} -even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}. +to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @expr{3:2} +even though @kbd{6 @key{RET} 4 /} produces @expr{1.5}. @kindex m f @pindex calc-frac-mode To set the Calculator to produce fractional results for normal integer divisions, use the @kbd{m f} (@code{calc-frac-mode}) command. -For example, @cite{8/4} produces @cite{2} in either mode, -but @cite{6/4} produces @cite{3:2} in Fraction Mode, @cite{1.5} in -Float Mode.@refill +For example, @expr{8/4} produces @expr{2} in either mode, +but @expr{6/4} produces @expr{3:2} in Fraction mode, @expr{1.5} in +Float mode. At any time you can use @kbd{c f} (@code{calc-float}) to convert a fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a @@ -12454,7 +12508,7 @@ float to a fraction. @xref{Conversions}. @noindent @cindex Infinite mode -The Calculator normally treats results like @cite{1 / 0} as errors; +The Calculator normally treats results like @expr{1 / 0} as errors; formulas like this are left in unsimplified form. But Calc can be put into a mode where such calculations instead produce ``infinite'' results. @@ -12466,25 +12520,25 @@ on and off. When the mode is off, infinities do not arise except in calculations that already had infinities as inputs. (One exception is that infinite open intervals like @samp{[0 .. inf)} can be generated; however, intervals closed at infinity (@samp{[0 .. inf]}) -will not be generated when infinite mode is off.) +will not be generated when Infinite mode is off.) -With infinite mode turned on, @samp{1 / 0} will generate @code{uinf}, +With Infinite mode turned on, @samp{1 / 0} will generate @code{uinf}, an undirected infinity. @xref{Infinities}, for a discussion of the -difference between @code{inf} and @code{uinf}. Also, @cite{0 / 0} +difference between @code{inf} and @code{uinf}. Also, @expr{0 / 0} evaluates to @code{nan}, the ``indeterminate'' symbol. Various other functions can also return infinities in this mode; for example, @samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}. Once again, -note that @samp{exp(inf) = inf} regardless of infinite mode because +note that @samp{exp(inf) = inf} regardless of Infinite mode because this calculation has infinity as an input. -@cindex Positive infinite mode +@cindex Positive Infinite mode The @kbd{m i} command with a numeric prefix argument of zero, -i.e., @kbd{C-u 0 m i}, turns on a ``positive infinite mode'' in -which zero is treated as positive instead of being directionless. +i.e., @kbd{C-u 0 m i}, turns on a Positive Infinite mode in +which zero is treated as positive instead of being directionless. Thus, @samp{1 / 0 = inf} and @samp{-1 / 0 = -inf} in this mode. Note that zero never actually has a sign in Calc; there are no -separate representations for @i{+0} and @i{-0}. Positive -infinite mode merely changes the interpretation given to the +separate representations for @mathit{+0} and @mathit{-0}. Positive +Infinite mode merely changes the interpretation given to the single symbol, @samp{0}. One consequence of this is that, while you might expect @samp{1 / -0 = -inf}, actually @samp{1 / -0} is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}. @@ -12503,7 +12557,7 @@ number or a symbolic expression if the argument is an expression: @kindex m s @pindex calc-symbolic-mode -In @dfn{symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode}) +In @dfn{Symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode}) command, functions which would produce inexact, irrational results are left in symbolic form. Thus @kbd{16 Q} pushes 4, but @kbd{2 Q} pushes @samp{sqrt(2)}. @@ -12515,7 +12569,7 @@ the expression at the top of the stack, by temporarily disabling @code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}). Given a numeric prefix argument, it also sets the floating-point precision to the specified value for the duration -of the command.@refill +of the command. To evaluate a formula numerically without expanding the variables it contains, you can use the key sequence @kbd{m s a v m s} (this uses @@ -12530,19 +12584,19 @@ variables.) @cindex Scalar mode Calc sometimes makes assumptions during algebraic manipulation that are awkward or incorrect when vectors and matrices are involved. -Calc has two modes, @dfn{matrix mode} and @dfn{scalar mode}, which +Calc has two modes, @dfn{Matrix mode} and @dfn{Scalar mode}, which modify its behavior around vectors in useful ways. @kindex m v @pindex calc-matrix-mode -Press @kbd{m v} (@code{calc-matrix-mode}) once to enter matrix mode. +Press @kbd{m v} (@code{calc-matrix-mode}) once to enter Matrix mode. In this mode, all objects are assumed to be matrices unless provably otherwise. One major effect is that Calc will no longer consider multiplication to be commutative. (Recall that in matrix arithmetic, @samp{A*B} is not the same as @samp{B*A}.) This assumption affects rewrite rules and algebraic simplification. Another effect of this mode is that calculations that would normally produce constants like -0 and 1 (e.g., @cite{a - a} and @cite{a / a}, respectively) will now +0 and 1 (e.g., @expr{a - a} and @expr{a / a}, respectively) will now produce function calls that represent ``generic'' zero or identity matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function @samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n} @@ -12554,18 +12608,18 @@ a true identity matrix of the appropriate size. On the other hand, if it is combined with a scalar (as in @samp{idn(1) + 2}), Calc will assume it really was a scalar after all and produce, e.g., 3. -Press @kbd{m v} a second time to get scalar mode. Here, objects are +Press @kbd{m v} a second time to get Scalar mode. Here, objects are assumed @emph{not} to be vectors or matrices unless provably so. For example, normally adding a variable to a vector, as in @samp{[x, y, z] + a}, will leave the sum in symbolic form because as far as Calc knows, @samp{a} could represent either a number or -another 3-vector. In scalar mode, @samp{a} is assumed to be a +another 3-vector. In Scalar mode, @samp{a} is assumed to be a non-vector, and the addition is evaluated to @samp{[x+a, y+a, z+a]}. Press @kbd{m v} a third time to return to the normal mode of operation. If you press @kbd{m v} with a numeric prefix argument @var{n}, you -get a special ``dimensioned matrix mode'' in which matrices of +get a special ``dimensioned'' Matrix mode in which matrices of unknown size are assumed to be @var{n}x@var{n} square matrices. Then, the function call @samp{idn(1)} will expand into an actual matrix rather than representing a ``generic'' matrix. @@ -12586,11 +12640,11 @@ for @samp{[x, y, z] + [1, 2, 3]}, but that's because you have broken your earlier promise to Calc that @samp{a} would be scalar. Another way to mix scalars and matrices is to use selections -(@pxref{Selecting Subformulas}). Use matrix mode when operating on -your formula normally; then, to apply scalar mode to a certain part +(@pxref{Selecting Subformulas}). Use Matrix mode when operating on +your formula normally; then, to apply Scalar mode to a certain part of the formula without affecting the rest just select that part, -change into scalar mode and press @kbd{=} to resimplify the part -under this mode, then change back to matrix mode before deselecting. +change into Scalar mode and press @kbd{=} to resimplify the part +under this mode, then change back to Matrix mode before deselecting. @node Automatic Recomputation, Working Message, Matrix Mode, Calculation Modes @subsection Automatic Recomputation @@ -12606,7 +12660,7 @@ are changed. @xref{Evaluates-To Operator}. The @kbd{m C} (@code{calc-auto-recompute}) command turns this automatic recomputation on and off. If you turn it off, Calc will not update @samp{=>} operators on the stack (nor those in the -attached Embedded Mode buffer, if there is one). They will not +attached Embedded mode buffer, if there is one). They will not be updated unless you explicitly do so by pressing @kbd{=} or until you press @kbd{m C} to turn recomputation back on. (While automatic recomputation is off, you can think of @kbd{m C m C} as a command @@ -12636,7 +12690,7 @@ Type @kbd{m w} (@code{calc-working}) with a numeric prefix of 0 to disable all ``working'' messages. Use a numeric prefix of 1 to enable only the plain @samp{Working...} message. Use a numeric prefix of 2 to see intermediate results as well. With no numeric prefix this displays -the current mode.@refill +the current mode. While it may seem that the ``working'' messages will slow Calc down considerably, experiments have shown that their impact is actually @@ -12651,13 +12705,13 @@ The current @dfn{simplification mode} controls how numbers and formulas are ``normalized'' when being taken from or pushed onto the stack. Some normalizations are unavoidable, such as rounding floating-point results to the current precision, and reducing fractions to simplest -form. Others, such as simplifying a formula like @cite{a+a} (or @cite{2+3}), +form. Others, such as simplifying a formula like @expr{a+a} (or @expr{2+3}), are done by default but can be turned off when necessary. -When you press a key like @kbd{+} when @cite{2} and @cite{3} are on the +When you press a key like @kbd{+} when @expr{2} and @expr{3} are on the stack, Calc pops these numbers, normalizes them, creates the formula -@cite{2+3}, normalizes it, and pushes the result. Of course the standard -rules for normalizing @cite{2+3} will produce the result @cite{5}. +@expr{2+3}, normalizes it, and pushes the result. Of course the standard +rules for normalizing @expr{2+3} will produce the result @expr{5}. Simplification mode commands consist of the lower-case @kbd{m} prefix key followed by a shifted letter. @@ -12665,7 +12719,7 @@ followed by a shifted letter. @kindex m O @pindex calc-no-simplify-mode The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional -simplifications. These would leave a formula like @cite{2+3} alone. In +simplifications. These would leave a formula like @expr{2+3} alone. In fact, nothing except simple numbers are ever affected by normalization in this mode. @@ -12673,22 +12727,24 @@ in this mode. @pindex calc-num-simplify-mode The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification of any formulas except those for which all arguments are constants. For -example, @cite{1+2} is simplified to @cite{3}, and @cite{a+(2-2)} is -simplified to @cite{a+0} but no further, since one argument of the sum -is not a constant. Unfortunately, @cite{(a+2)-2} is @emph{not} simplified +example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(2-2)} is +simplified to @expr{a+0} but no further, since one argument of the sum +is not a constant. Unfortunately, @expr{(a+2)-2} is @emph{not} simplified because the top-level @samp{-} operator's arguments are not both -constant numbers (one of them is the formula @cite{a+2}). +constant numbers (one of them is the formula @expr{a+2}). A constant is a number or other numeric object (such as a constant error form or modulo form), or a vector all of whose -elements are constant.@refill +elements are constant. @kindex m D @pindex calc-default-simplify-mode The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the default simplifications for all formulas. This includes many easy and -fast algebraic simplifications such as @cite{a+0} to @cite{a}, and -@cite{a + 2 a} to @cite{3 a}, as well as evaluating functions like -@cite{@t{deriv}(x^2, x)} to @cite{2 x}. +fast algebraic simplifications such as @expr{a+0} to @expr{a}, and +@expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like +@texline @t{deriv}@expr{(x^2,x)} +@infoline @expr{@t{deriv}(x^2, x)} +to @expr{2 x}. @kindex m B @pindex calc-bin-simplify-mode @@ -12719,13 +12775,13 @@ simplification; it applies the command @kbd{u s} (@code{calc-simplify-units}), which in turn is a superset of @kbd{a s}. In this mode, variable names which are identifiable as unit names (like @samp{mm} for ``millimeters'') -are simplified with their unit definitions in mind.@refill +are simplified with their unit definitions in mind. A common technique is to set the simplification mode down to the lowest amount of simplification you will allow to be applied automatically, then use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to perform higher types of simplifications on demand. @xref{Algebraic -Definitions}, for another sample use of no-simplification mode.@refill +Definitions}, for another sample use of No-Simplification mode. @node Declarations, Display Modes, Simplification Modes, Mode Settings @section Declarations @@ -12872,7 +12928,7 @@ Numbers. (Real or complex.) Calc uses this information to determine when certain simplifications of formulas are safe. For example, @samp{(x^y)^z} cannot be simplified to @samp{x^(y z)} in general; for example, -@samp{((-3)^2)^1:2} is 3, but @samp{(-3)^(2*1:2) = (-3)^1} is @i{-3}. +@samp{((-3)^2)^1:2} is 3, but @samp{(-3)^(2*1:2) = (-3)^1} is @mathit{-3}. However, this simplification @emph{is} safe if @code{z} is known to be an integer, or if @code{x} is known to be a nonnegative real number. If you have given declarations that allow Calc to @@ -12972,8 +13028,8 @@ and @code{y} are known to be vectors or matrices. (Calc currently never distinguishes between @code{vector} and @code{matrix} declarations.) -@xref{Matrix Mode}, for a discussion of ``matrix mode'' and -``scalar mode,'' which are similar to declaring @samp{[All, matrix]} +@xref{Matrix Mode}, for a discussion of Matrix mode and +Scalar mode, which are similar to declaring @samp{[All, matrix]} or @samp{[All, scalar]} but much more convenient. One more type symbol that is recognized is used with the @kbd{H a d} @@ -12985,10 +13041,10 @@ The value is a constant with respect to other variables. @end table Calc does not check the declarations for a variable when you store -a value in it. However, storing @i{-3.5} in a variable that has +a value in it. However, storing @mathit{-3.5} in a variable that has been declared @code{pos}, @code{int}, or @code{matrix} may have -unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @cite{3.5} -if it substitutes the value first, or to @cite{-3.5} if @code{x} +unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5} +if it substitutes the value first, or to @expr{-3.5} if @code{x} was declared @code{pos} and the formula @samp{sqrt(x^2)} is simplified to @samp{x} before the value is substituted. Before using a variable for a new purpose, it is best to use @kbd{s d} @@ -13056,7 +13112,7 @@ includes integers, fractions, floats, real error forms, and intervals. @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}. +i.e., is mathematically equal to a real number times @expr{i}. @ignore @starindex @@ -13074,7 +13130,7 @@ The @code{dpos} function checks for positive (but nonzero) reals. The @code{dneg} function checks for negative reals. The @code{dnonneg} function checks for nonnegative reals, i.e., reals greater than or equal to zero. Note that the @kbd{a s} command can simplify an -expression like @cite{x > 0} to 1 or 0 using @code{dpos}, and that +expression like @expr{x > 0} to 1 or 0 using @code{dpos}, and that @kbd{a s} is effectively applied to all conditions in rewrite rules, so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg} are rarely necessary. @@ -13125,8 +13181,8 @@ remains unevaluated. @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 -unevaluated if this cannot be determined. (If matrix mode or scalar -mode are in effect, this function returns 1 or 0, respectively, +unevaluated if this cannot be determined. (If Matrix mode or Scalar +mode is in effect, this function returns 1 or 0, respectively, if it has no other information.) When Calc interprets a condition (say, in a rewrite rule) it considers an unevaluated formula to be ``false.'' Thus, @samp{dscalar(a)} is ``true'' only if @code{a} is @@ -13143,7 +13199,7 @@ The commands in this section are two-key sequences beginning with the (@code{calc-line-breaking}) commands are described elsewhere; @pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively. Display formats for vectors and matrices are also covered elsewhere; -@pxref{Vector and Matrix Formats}.@refill +@pxref{Vector and Matrix Formats}. One thing all display modes have in common is their treatment of the @kbd{H} prefix. This prefix causes any mode command that would normally @@ -13203,7 +13259,7 @@ binary, octal, hexadecimal, and decimal as the current display radix, respectively. Numbers can always be entered in any radix, though the current radix is used as a default if you press @kbd{#} without any initial digits. A number entered without a @kbd{#} is @emph{always} interpreted -as decimal.@refill +as decimal. @kindex d r @pindex calc-radix @@ -13218,10 +13274,12 @@ Integers normally are displayed with however many digits are necessary to represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) command causes integers to be padded out with leading zeros according to the current binary word size. (@xref{Binary Functions}, for a discussion of -word size.) If the absolute value of the word size is @cite{w}, all integers -are displayed with at least enough digits to represent @c{$2^w-1$} -@cite{(2^w)-1} in the -current radix. (Larger integers will still be displayed in their entirety.) +word size.) If the absolute value of the word size is @expr{w}, all integers +are displayed with at least enough digits to represent +@texline @math{2^w-1} +@infoline @expr{(2^w)-1} +in the current radix. (Larger integers will still be displayed in their +entirety.) @node Grouping Digits, Float Formats, Radix Modes, Display Modes @subsection Grouping Digits @@ -13233,17 +13291,17 @@ current radix. (Larger integers will still be displayed in their entirety.) @cindex Digit grouping Long numbers can be hard to read if they have too many digits. For example, the factorial of 30 is 33 digits long! Press @kbd{d g} -(@code{calc-group-digits}) to enable @dfn{grouping} mode, in which digits +(@code{calc-group-digits}) to enable @dfn{Grouping} mode, in which digits are displayed in clumps of 3 or 4 (depending on the current radix) separated by commas. The @kbd{d g} command toggles grouping on and off. With a numerix prefix of 0, this command displays the current state of the grouping flag; with an argument of minus one it disables grouping; -with a positive argument @cite{N} it enables grouping on every @cite{N} +with a positive argument @expr{N} it enables grouping on every @expr{N} digits. For floating-point numbers, grouping normally occurs only -before the decimal point. A negative prefix argument @cite{-N} enables -grouping every @cite{N} digits both before and after the decimal point.@refill +before the decimal point. A negative prefix argument @expr{-N} enables +grouping every @expr{N} digits both before and after the decimal point. @kindex d , @pindex calc-group-char @@ -13336,7 +13394,7 @@ numbers, and commas to separate elements in a list. There are three supported notations for complex numbers in rectangular form. The default is as a pair of real numbers enclosed in parentheses and separated by a comma: @samp{(a,b)}. The @kbd{d c} -(@code{calc-complex-notation}) command selects this style.@refill +(@code{calc-complex-notation}) command selects this style. @kindex d i @pindex calc-i-notation @@ -13345,7 +13403,7 @@ and separated by a comma: @samp{(a,b)}. The @kbd{d c} The other notations are @kbd{d i} (@code{calc-i-notation}), in which numbers are displayed in @samp{a+bi} form, and @kbd{d j} (@code{calc-j-notation}) which displays the form @samp{a+bj} preferred -in some disciplines.@refill +in some disciplines. @cindex @code{i} variable @vindex i @@ -13356,7 +13414,7 @@ this formula and you have not changed the variable @samp{i}, the @samp{i} will be interpreted as @samp{(0,1)} and the formula will be simplified to @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not} interpret the formula @samp{2 + 3 * i} as a complex number. -@xref{Variables}, under ``special constants.''@refill +@xref{Variables}, under ``special constants.'' @node Fraction Formats, HMS Formats, Complex Formats, Display Modes @subsection Fraction Formats @@ -13384,12 +13442,12 @@ a number. For example: @samp{:10} or @samp{+/3}. In this case, Calc adjusts all fractions that are displayed to have the specified denominator, if possible. Otherwise it adjusts the denominator to be a multiple of the specified value. For example, in @samp{:6} mode -the fraction @cite{1:6} will be unaffected, but @cite{2:3} will be -displayed as @cite{4:6}, @cite{1:2} will be displayed as @cite{3:6}, -and @cite{1:8} will be displayed as @cite{3:24}. Integers are also -affected by this mode: 3 is displayed as @cite{18:6}. Note that the +the fraction @expr{1:6} will be unaffected, but @expr{2:3} will be +displayed as @expr{4:6}, @expr{1:2} will be displayed as @expr{3:6}, +and @expr{1:8} will be displayed as @expr{3:24}. Integers are also +affected by this mode: 3 is displayed as @expr{18:6}. Note that the format @samp{:1} writes fractions the same as @samp{:}, but it writes -integers as @cite{n:1}. +integers as @expr{n:1}. The fraction format does not affect the way fractions or integers are stored, only the way they appear on the screen. The fraction format @@ -13748,15 +13806,15 @@ operations. This is similar to the Emacs ``narrowing'' feature, except that the values below the @samp{.} are @emph{visible}, just temporarily frozen. This feature allows you to keep several independent calculations running at once in different parts of the stack, or to apply a certain -command to an element buried deep in the stack.@refill +command to an element buried deep in the stack. Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor is on. Thus, this line and all those below it become hidden. To un-hide these lines, move down to the end of the buffer and press @w{@kbd{d t}}. -With a positive numeric prefix argument @cite{n}, @kbd{d t} hides the -bottom @cite{n} values in the buffer. With a negative argument, it hides -all but the top @cite{n} values. With an argument of zero, it hides zero -values, i.e., moves the @samp{.} all the way down to the bottom.@refill +With a positive numeric prefix argument @expr{n}, @kbd{d t} hides the +bottom @expr{n} values in the buffer. With a negative argument, it hides +all but the top @expr{n} values. With an argument of zero, it hides zero +values, i.e., moves the @samp{.} all the way down to the bottom. @kindex d [ @pindex calc-truncate-up @@ -13764,7 +13822,7 @@ values, i.e., moves the @samp{.} all the way down to the bottom.@refill @pindex calc-truncate-down The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]} (@code{calc-truncate-down}) commands move the @samp{.} up or down one -line at a time (or several lines with a prefix argument).@refill +line at a time (or several lines with a prefix argument). @node Justification, Labels, Truncating the Stack, Display Modes @subsection Justification @@ -13779,9 +13837,9 @@ line at a time (or several lines with a prefix argument).@refill Values on the stack are normally left-justified in the window. You can control this arrangement by typing @kbd{d <} (@code{calc-left-justify}), @kbd{d >} (@code{calc-right-justify}), or @kbd{d =} -(@code{calc-center-justify}). For example, in right-justification mode, +(@code{calc-center-justify}). For example, in Right-Justification mode, stack entries are displayed flush-right against the right edge of the -window.@refill +window. If you change the width of the Calculator window you may have to type @kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered @@ -13800,20 +13858,20 @@ breaking lines are given below. Notice that the interaction between origin and line width is slightly different in each justification mode. -In left-justified mode, the line is indented by a number of spaces +In Left-Justified mode, the line is indented by a number of spaces given by the origin (default zero). If the result is longer than the maximum line width, if given, or too wide to fit in the Calc window otherwise, then it is broken into lines which will fit; each broken line is indented to the origin. -In right-justified mode, lines are shifted right so that the rightmost +In Right-Justified mode, lines are shifted right so that the rightmost character is just before the origin, or just before the current window width if no origin was specified. If the line is too long for this, then it is broken; the current line width is used, if specified, or else the origin is used as a width if that is specified, or else the line is broken to fit in the window. -In centering mode, the origin is the column number of the center of +In Centering mode, the origin is the column number of the center of each stack entry. If a line width is specified, lines will not be allowed to go past that width; Calc will either indent less or break the lines if necessary. If no origin is specified, half the @@ -13848,13 +13906,13 @@ Give a blank string (with @kbd{d @{ @key{RET}}) to turn the label off. The @kbd{d @}} (@code{calc-right-label}) command similarly adds a label on the righthand side. It does not affect positioning of the stack entries unless they are right-justified. Also, if both -a line width and an origin are given in right-justified mode, the +a line width and an origin are given in Right-Justified mode, the stack entry is justified to the origin and the righthand label is justified to the line width. One application of labels would be to add equation numbers to formulas you are manipulating in Calc and then copying into a -document (possibly using Embedded Mode). The equations would +document (possibly using Embedded mode). The equations would typically be centered, and the equation numbers would be on the left or right as you prefer. @@ -13864,7 +13922,7 @@ left or right as you prefer. @noindent The commands in this section change Calc to use a different notation for entry and display of formulas, corresponding to the conventions of some -other common language such as Pascal or @TeX{}. Objects displayed on the +other common language such as Pascal or @LaTeX{}. Objects displayed on the stack or yanked from the Calculator to an editing buffer will be formatted in the current language; objects entered in algebraic entry or yanked from another buffer will be interpreted according to the current language. @@ -13889,10 +13947,10 @@ the brackets in @samp{a[1]} and @samp{a[2]}, would not have known that and would have written the formula back with notations (like implicit multiplication) which would not have been legal for a C program. -As another example, suppose you are maintaining a C program and a @TeX{} +As another example, suppose you are maintaining a C program and a @LaTeX{} document, each of which needs a copy of the same formula. You can grab the -formula from the program in C mode, switch to @TeX{} mode, and yank the -formula into the document in @TeX{} math-mode format. +formula from the program in C mode, switch to @LaTeX{} mode, and yank the +formula into the document in @LaTeX{} math-mode format. Language modes are selected by typing the letter @kbd{d} followed by a shifted letter key. @@ -13900,7 +13958,7 @@ shifted letter key. @menu * Normal Language Modes:: * C FORTRAN Pascal:: -* TeX Language Mode:: +* TeX and LaTeX Language Modes:: * Eqn Language Mode:: * Mathematica Language Mode:: * Maple Language Mode:: @@ -13956,7 +14014,7 @@ such as powers, quotients, and square roots: @noindent in place of @samp{sqrt((a+1)/b + c^2)}. -Subscripts like @samp{a_i} are displayed as actual subscripts in ``big'' +Subscripts like @samp{a_i} are displayed as actual subscripts in Big mode. Double subscripts, @samp{a_i_j} (@samp{subscr(subscr(a, i), j)}) are displayed as @samp{a} with subscripts separated by commas: @samp{i, j}. They must still be entered in the usual underscore @@ -13971,10 +14029,10 @@ One slight ambiguity of Big notation is that @end example @noindent -can represent either the negative rational number @cite{-3:4}, or the +can represent either the negative rational number @expr{-3:4}, or the actual expression @samp{-(3/4)}; but the latter formula would normally never be displayed because it would immediately be evaluated to -@cite{-3:4} or @cite{-0.75}, so this ambiguity is not a problem in +@expr{-3:4} or @expr{-0.75}, so this ambiguity is not a problem in typical use. Non-decimal numbers are displayed with subscripts. Thus there is no @@ -14010,7 +14068,7 @@ all four modes, and unformatted notation works in any language mode (except that Mathematica mode expects square brackets instead of parentheses). -@node C FORTRAN Pascal, TeX Language Mode, Normal Language Modes, Language Modes +@node C FORTRAN Pascal, TeX and LaTeX Language Modes, Normal Language Modes, Language Modes @subsection C, FORTRAN, and Pascal Modes @noindent @@ -14029,12 +14087,12 @@ In C mode, vectors and matrices use curly braces instead of brackets. Octal and hexadecimal values are written with leading @samp{0} or @samp{0x} rather than using the @samp{#} symbol. Array subscripting is translated into @code{subscr} calls, so that @samp{a[i]} in C -mode is the same as @samp{a_i} in normal mode. Assignments +mode is the same as @samp{a_i} in Normal mode. Assignments turn into the @code{assign} function, which Calc normally displays using the @samp{:=} symbol. -The variables @code{var-pi} and @code{var-e} would be displayed @samp{pi} -and @samp{e} in normal mode, but in C mode they are displayed as +The variables @code{pi} and @code{e} would be displayed @samp{pi} +and @samp{e} in Normal mode, but in C mode they are displayed as @samp{M_PI} and @samp{M_E}, corresponding to the names of constants typically provided in the @file{} header. Functions whose names are different in C are translated automatically for entry and @@ -14076,7 +14134,7 @@ function!). Underscores are allowed in variable and function names in all of these language modes. The underscore here is equivalent to the @samp{#} in -normal mode, or to hyphens in the underlying Emacs Lisp variable names. +Normal mode, or to hyphens in the underlying Emacs Lisp variable names. FORTRAN and Pascal modes normally do not adjust the case of letters in formulas. Most built-in Calc names use lower-case letters. If you use a @@ -14085,70 +14143,122 @@ modes will use upper-case letters exclusively for display, and will convert to lower-case on input. With a negative prefix, these modes convert to lower-case for display and input. -@node TeX Language Mode, Eqn Language Mode, C FORTRAN Pascal, Language Modes -@subsection @TeX{} Language Mode +@node TeX and LaTeX Language Modes, Eqn Language Mode, C FORTRAN Pascal, Language Modes +@subsection @TeX{} and @LaTeX{} Language Modes @noindent @kindex d T @pindex calc-tex-language @cindex TeX language +@kindex d L +@pindex calc-latex-language +@cindex LaTeX language The @kbd{d T} (@code{calc-tex-language}) command selects the conventions -of ``math mode'' in the @TeX{} typesetting language, by Donald Knuth. -Formulas are entered -and displayed in @TeX{} notation, as in @samp{\sin\left( a \over b \right)}. -Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these -should be omitted when interfacing with Calc. To Calc, the @samp{$} sign -has the same meaning it always does in algebraic formulas (a reference to -an existing entry on the stack).@refill +of ``math mode'' in Donald Knuth's @TeX{} typesetting language, +and the @kbd{d L} (@code{calc-latex-language}) command selects the +conventions of ``math mode'' in @LaTeX{}, a typesetting language that +uses @TeX{} as its formatting engine. Calc's @LaTeX{} language mode can +read any formula that the @TeX{} language mode can, although @LaTeX{} +mode may display it differently. + +Formulas are entered and displayed in the appropriate notation; +@texline @math{\sin(a/b)} +@infoline @expr{sin(a/b)} +will appear as @samp{\sin\left( a \over b \right)} in @TeX{} mode and +@samp{\sin\left(\frac@{a@}@{b@}\right)} in @LaTeX{} mode. +Math formulas are often enclosed by @samp{$ $} signs in @TeX{} and +@LaTeX{}; these should be omitted when interfacing with Calc. To Calc, +the @samp{$} sign has the same meaning it always does in algebraic +formulas (a reference to an existing entry on the stack). Complex numbers are displayed as in @samp{3 + 4i}. Fractions and -quotients are written using @code{\over}; -binomial coefficients are written with @code{\choose}. -Interval forms are written with @code{\ldots}, and -error forms are written with @code{\pm}. -Absolute values are written as in @samp{|x + 1|}, and the floor and -ceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc. -The words @code{\left} and @code{\right} are ignored when reading -formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written -as @code{\infty}; when read, @code{\infty} always translates to -@code{inf}.@refill +quotients are written using @code{\over} in @TeX{} mode (as in +@code{@{a \over b@}}) and @code{\frac} in @LaTeX{} mode (as in +@code{\frac@{a@}@{b@}}); binomial coefficients are written with +@code{\choose} in @TeX{} mode (as in @code{@{a \choose b@}}) and +@code{\binom} in @LaTeX{} mode (as in @code{\binom@{a@}@{b@}}). +Interval forms are written with @code{\ldots}, and error forms are +written with @code{\pm}. Absolute values are written as in +@samp{|x + 1|}, and the floor and ceiling functions are written with +@code{\lfloor}, @code{\rfloor}, etc. The words @code{\left} and +@code{\right} are ignored when reading formulas in @TeX{} and @LaTeX{} +modes. Both @code{inf} and @code{uinf} are written as @code{\infty}; +when read, @code{\infty} always translates to @code{inf}. Function calls are written the usual way, with the function name followed -by the arguments in parentheses. However, functions for which @TeX{} has -special names (like @code{\sin}) will use curly braces instead of -parentheses for very simple arguments. During input, curly braces and -parentheses work equally well for grouping, but when the document is -formatted the curly braces will be invisible. Thus the printed result is -@c{$\sin{2 x}$} -@cite{sin 2x} but @c{$\sin(2 + x)$} -@cite{sin(2 + x)}. - -Function and variable names not treated specially by @TeX{} are simply -written out as-is, which will cause them to come out in italic letters -in the printed document. If you invoke @kbd{d T} with a positive numeric -prefix argument, names of more than one character will instead be written -@samp{\hbox@{@var{name}@}}. The @samp{\hbox@{ @}} notation is ignored -during reading. If you use a negative prefix argument, such function -names are written @samp{\@var{name}}, and function names that begin -with @code{\} during reading have the @code{\} removed. (Note that -in this mode, long variable names are still written with @code{\hbox}. -However, you can always make an actual variable name like @code{\bar} -in any @TeX{} mode.) +by the arguments in parentheses. However, functions for which @TeX{} +and @LaTeX{} have special names (like @code{\sin}) will use curly braces +instead of parentheses for very simple arguments. During input, curly +braces and parentheses work equally well for grouping, but when the +document is formatted the curly braces will be invisible. Thus the +printed result is +@texline @math{\sin{2 x}} +@infoline @expr{sin 2x} +but +@texline @math{\sin(2 + x)}. +@infoline @expr{sin(2 + x)}. + +Function and variable names not treated specially by @TeX{} and @LaTeX{} +are simply written out as-is, which will cause them to come out in +italic letters in the printed document. If you invoke @kbd{d T} or +@kbd{d L} with a positive numeric prefix argument, names of more than +one character will instead be enclosed in a protective commands that +will prevent them from being typeset in the math italics; they will be +written @samp{\hbox@{@var{name}@}} in @TeX{} mode and +@samp{\text@{@var{name}@}} in @LaTeX{} mode. The +@samp{\hbox@{ @}} and @samp{\text@{ @}} notations are ignored during +reading. If you use a negative prefix argument, such function names are +written @samp{\@var{name}}, and function names that begin with @code{\} during +reading have the @code{\} removed. (Note that in this mode, long +variable names are still written with @code{\hbox} or @code{\text}. +However, you can always make an actual variable name like @code{\bar} in +any @TeX{} mode.) During reading, text of the form @samp{\matrix@{ ...@: @}} is replaced by @samp{[ ...@: ]}. The same also applies to @code{\pmatrix} and -@code{\bmatrix}. The symbol @samp{&} is interpreted as a comma, +@code{\bmatrix}. In @LaTeX{} mode this also applies to +@samp{\begin@{matrix@} ... \end@{matrix@}}, +@samp{\begin@{bmatrix@} ... \end@{bmatrix@}}, +@samp{\begin@{pmatrix@} ... \end@{pmatrix@}}, as well as +@samp{\begin@{smallmatrix@} ... \end@{smallmatrix@}}. +The symbol @samp{&} is interpreted as a comma, and the symbols @samp{\cr} and @samp{\\} are interpreted as semicolons. During output, matrices are displayed in @samp{\matrix@{ a & b \\ c & d@}} -format; you may need to edit this afterwards to change @code{\matrix} -to @code{\pmatrix} or @code{\\} to @code{\cr}. +format in @TeX{} mode and in +@samp{\begin@{pmatrix@} a & b \\ c & d \end@{pmatrix@}} format in +@LaTeX{} mode; you may need to edit this afterwards to change to your +preferred matrix form. If you invoke @kbd{d T} or @kbd{d L} with an +argument of 2 or -2, then matrices will be displayed in two-dimensional +form, such as + +@example +\begin@{pmatrix@} +a & b \\ +c & d +\end@{pmatrix@} +@end example + +@noindent +This may be convenient for isolated matrices, but could lead to +expressions being displayed like + +@example +\begin@{pmatrix@} \times x +a & b \\ +c & d +\end@{pmatrix@} +@end example + +@noindent +While this wouldn't bother Calc, it is incorrect @LaTeX{}. +(Similarly for @TeX{}.) Accents like @code{\tilde} and @code{\bar} translate into function calls internally (@samp{tilde(x)}, @samp{bar(x)}). The @code{\underline} sequence is treated as an accent. The @code{\vec} accent corresponds to the function name @code{Vec}, because @code{vec} is the name of a built-in Calc function. The following table shows the accents -in Calc, @TeX{}, and @dfn{eqn} (described in the next section): +in Calc, @TeX{}, @LaTeX{} and @dfn{eqn} (described in the next section): @iftex @begingroup @@ -14162,26 +14272,58 @@ in Calc, @TeX{}, and @dfn{eqn} (described in the next section): @ignore @starindex @end ignore +@tindex Acute +@ignore +@starindex +@end ignore @tindex bar @ignore @starindex @end ignore +@tindex Bar +@ignore +@starindex +@end ignore @tindex breve @ignore @starindex @end ignore +@tindex Breve +@ignore +@starindex +@end ignore @tindex check @ignore @starindex @end ignore +@tindex Check +@ignore +@starindex +@end ignore +@tindex dddot +@ignore +@starindex +@end ignore +@tindex ddddot +@ignore +@starindex +@end ignore @tindex dot @ignore @starindex @end ignore +@tindex Dot +@ignore +@starindex +@end ignore @tindex dotdot @ignore @starindex @end ignore +@tindex DotDot +@ignore +@starindex +@end ignore @tindex dyad @ignore @starindex @@ -14190,10 +14332,18 @@ in Calc, @TeX{}, and @dfn{eqn} (described in the next section): @ignore @starindex @end ignore +@tindex Grave +@ignore +@starindex +@end ignore @tindex hat @ignore @starindex @end ignore +@tindex Hat +@ignore +@starindex +@end ignore @tindex Prime @ignore @starindex @@ -14202,30 +14352,50 @@ in Calc, @TeX{}, and @dfn{eqn} (described in the next section): @ignore @starindex @end ignore +@tindex Tilde +@ignore +@starindex +@end ignore @tindex under @ignore @starindex @end ignore @tindex Vec +@ignore +@starindex +@end ignore +@tindex VEC @iftex @endgroup @end iftex @example -Calc TeX eqn ----- --- --- -acute \acute -bar \bar bar -breve \breve -check \check -dot \dot dot -dotdot \ddot dotdot -dyad dyad -grave \grave -hat \hat hat -Prime prime -tilde \tilde tilde -under \underline under -Vec \vec vec +Calc TeX LaTeX eqn +---- --- ----- --- +acute \acute \acute +Acute \Acute +bar \bar \bar bar +Bar \Bar +breve \breve \breve +Breve \Breve +check \check \check +Check \Check +dddot \dddot +ddddot \ddddot +dot \dot \dot dot +Dot \Dot +dotdot \ddot \ddot dotdot +DotDot \Ddot +dyad dyad +grave \grave \grave +Grave \Grave +hat \hat \hat hat +Hat \Hat +Prime prime +tilde \tilde \tilde tilde +Tilde \Tilde +under \underline \underline under +Vec \vec \vec vec +VEC \Vec @end example The @samp{=>} (evaluates-to) operator appears as a @code{\to} symbol: @@ -14262,8 +14432,9 @@ reading is: \evalto @end example -Note that, because these symbols are ignored, reading a @TeX{} formula -into Calc and writing it back out may lose spacing and font information. +Note that, because these symbols are ignored, reading a @TeX{} or +@LaTeX{} formula into Calc and writing it back out may lose spacing and +font information. Also, the ``discretionary multiplication sign'' @samp{\*} is read the same as @samp{*}. @@ -14282,7 +14453,6 @@ sin(a^2 / b_i) @end group @end example @tex -\let\rm\goodrm $$ \sin\left( a^2 \over b_i \right) $$ @end tex @sp 1 @@ -14320,7 +14490,7 @@ $$ [|a|, \left| a \over b \right|, @end group @end example @tex -\turnoffactive\let\rm\goodrm +\turnoffactive $$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$ @end tex @sp 2 @@ -14338,7 +14508,6 @@ First with plain @kbd{d T}, then with @kbd{C-u d T}, then finally with @end group @end example @tex -\let\rm\goodrm $$ [f(a), foo(bar), \sin{\pi}] $$ $$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$ $$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$ @@ -14393,7 +14562,7 @@ $$ \pmatrix{ {a \over b} & 0 \cr 0 & 2^{(x + 1)} } $$ @sp 2 @end iftex -@node Eqn Language Mode, Mathematica Language Mode, TeX Language Mode, Language Modes +@node Eqn Language Mode, Mathematica Language Mode, TeX and LaTeX Language Modes, Language Modes @subsection Eqn Language Mode @noindent @@ -14435,7 +14604,7 @@ treated the same as a space in @dfn{eqn} mode, as is the @samp{~} symbol (these are used to introduce spaces of various widths into the typeset output of @dfn{eqn}). -As in @TeX{} mode, Calc's formatter omits parentheses around the +As in @LaTeX{} mode, Calc's formatter omits parentheses around the arguments of functions like @code{ln} and @code{sin} if they are ``simple-looking''; in this case Calc surrounds the argument with braces, separated by a @samp{~} from the function name: @samp{sin~@{x@}}. @@ -14449,17 +14618,17 @@ are treated the same as curly braces: @samp{sqrt "1+x"} is equivalent to of quotes in @dfn{eqn}, but it is good enough for most uses. Accent codes (@samp{@var{x} dot}) are handled by treating them as -function calls (@samp{dot(@var{x})}) internally. @xref{TeX Language -Mode}, for a table of these accent functions. The @code{prime} accent -is treated specially if it occurs on a variable or function name: -@samp{f prime prime @w{( x prime )}} is stored internally as -@samp{f'@w{'}(x')}. For example, taking the derivative of @samp{f(2 x)} -with @kbd{a d x} will produce @samp{2 f'(2 x)}, which @dfn{eqn} mode -will display as @samp{2 f prime ( 2 x )}. +function calls (@samp{dot(@var{x})}) internally. +@xref{TeX and LaTeX Language Modes}, for a table of these accent +functions. The @code{prime} accent is treated specially if it occurs on +a variable or function name: @samp{f prime prime @w{( x prime )}} is +stored internally as @samp{f'@w{'}(x')}. For example, taking the +derivative of @samp{f(2 x)} with @kbd{a d x} will produce @samp{2 f'(2 +x)}, which @dfn{eqn} mode will display as @samp{2 f prime ( 2 x )}. Assignments are written with the @samp{<-} (left-arrow) symbol, and @code{evalto} operators are written with @samp{->} or -@samp{evalto ... ->} (@pxref{TeX Language Mode}, for a discussion +@samp{evalto ... ->} (@pxref{TeX and LaTeX Language Modes}, for a discussion of this). The regular Calc symbols @samp{:=} and @samp{=>} are also recognized for these operators during reading. @@ -14491,7 +14660,7 @@ written @code{Pi}, @code{E}, @code{I}, @code{GoldenRatio}, @code{EulerGamma}, Mathematica mode. Non-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point numbers in scientific notation are written @samp{1.23*10.^3}. -Subscripts use double square brackets: @samp{a[[i]]}.@refill +Subscripts use double square brackets: @samp{a[[i]]}. @node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes @subsection Maple Language Mode @@ -14502,7 +14671,7 @@ Subscripts use double square brackets: @samp{a[[i]]}.@refill @cindex Maple language The @kbd{d W} (@code{calc-maple-language}) command selects the conventions of Maple, another mathematical tool from the University -of Waterloo. +of Waterloo. Maple's language is much like C. Underscores are allowed in symbol names; square brackets are used for subscripts; explicit @samp{*}s for @@ -14632,9 +14801,9 @@ mod 400 => 40 @end example -The general rule is that if an operator with precedence @cite{n} -occurs as an argument to an operator with precedence @cite{m}, then -the argument is enclosed in parentheses if @cite{n < m}. Top-level +The general rule is that if an operator with precedence @expr{n} +occurs as an argument to an operator with precedence @expr{m}, then +the argument is enclosed in parentheses if @expr{n < m}. Top-level expressions and expressions which are function arguments, vector components, etc., are formatted with precedence zero (so that they normally never get additional parentheses). @@ -14718,7 +14887,7 @@ object. @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 +as @w{@samp{17a b / cd}} in Normal language mode, or as @example @group @@ -14981,7 +15150,7 @@ then return a certain measurement of the composition as an integer. @tindex cwidth The @code{cwidth} function measures the width, in characters, of a composition. For example, @samp{cwidth(a + b)} is 5, and -@samp{cwidth(a / b)} is 5 in normal mode, 1 in Big mode, and 11 in +@samp{cwidth(a / b)} is 5 in Normal mode, 1 in Big mode, and 11 in @TeX{} mode (for @samp{@{a \over b@}}). The argument may involve the composition functions described in this section. @@ -15084,7 +15253,7 @@ as an algebraic entry. @example @group - C + C + C + C a b 7 3 @end group @end example @@ -15157,9 +15326,9 @@ unrelated to the syntax tables described in the Emacs manual.) @pindex calc-edit-user-syntax The @kbd{Z S} (@code{calc-edit-user-syntax}) command edits the syntax table for the current language mode. If you want your -syntax to work in any language, define it in the normal language -mode. Type @kbd{M-# M-#} to finish editing the syntax table, or -@kbd{M-# x} to cancel the edit. The @kbd{m m} command saves all +syntax to work in any language, define it in the Normal language +mode. Type @kbd{C-c C-c} to finish editing the syntax table, or +@kbd{C-x k} to cancel the edit. The @kbd{m m} command saves all the syntax tables along with the other mode settings; @pxref{General Mode Commands}. @@ -15188,7 +15357,7 @@ zero or more expressions separated by commas, and @samp{)}.'' A @dfn{syntax table} is a list of user-defined @dfn{syntax rules}, which allow you to specify new patterns to define your own favorite input notations. Calc's parser always checks the syntax -table for the current language mode, then the table for the normal +table for the current language mode, then the table for the Normal language mode, before it uses its built-in rules to parse an algebraic formula you have entered. Each syntax rule should go on its own line; it consists of a @dfn{pattern}, a @samp{:=} symbol, @@ -15543,7 +15712,7 @@ In this approach, we allow @samp{#2} to equal the whole expression @samp{i=1..10}. Then, we use @code{matches} to break it apart into its components. If the expression turns out not to match the pattern, the syntax rule will fail. Note that @kbd{Z S} always uses Calc's -normal language mode for editing expressions in syntax rules, so we +Normal language mode for editing expressions in syntax rules, so we must use regular Calc notation for the interval @samp{[b..c]} that will correspond to the Maple mode interval @samp{1..10}. @@ -15608,7 +15777,7 @@ and 3 (HMS). The @kbd{m d} command accepts these prefixes. @item Symbolic mode. Value is 0 or 1; default is 0. Command is @kbd{m s}. -@item +@item Fraction mode. Value is 0 or 1; default is 0. Command is @kbd{m f}. @item @@ -15616,17 +15785,19 @@ Polar mode. Value is 0 (rectangular) or 1 (polar); default is 0. 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 @var{N} for @c{$N\times N$} -@var{N}x@var{N} matrix mode. Command is @kbd{m v}. +Matrix/Scalar mode. Default value is @mathit{-1}. Value is 0 for Scalar +mode, @mathit{-2} for Matrix mode, or @var{N} for +@texline @math{N\times N} +@infoline @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}), +Simplification mode. Default is 1. Value is @mathit{-1} for off (@kbd{m O}), 0 for @kbd{m N}, 2 for @kbd{m B}, 3 for @kbd{m A}, 4 for @kbd{m E}, or 5 for @w{@kbd{m U}}. The @kbd{m D} command accepts these prefixes. @item -Infinite mode. Default is @i{-1} (off). Value is 1 if the mode is on, +Infinite mode. Default is @mathit{-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 @@ -15653,7 +15824,7 @@ programming commands. @xref{Conditionals in Macros}.) @cindex Mode line indicators This section is a summary of all symbols that can appear on the Calc mode line, the highlighted bar that appears under the Calc -stack window (or under an editing window in Embedded Mode). +stack window (or under an editing window in Embedded mode). The basic mode line format is: @@ -15665,7 +15836,7 @@ The @samp{%%} is the Emacs symbol for ``read-only''; it shows that regular Emacs commands are not allowed to edit the stack buffer as if it were text. -The word @samp{Calc:} changes to @samp{CalcEmbed:} if Embedded Mode +The word @samp{Calc:} changes to @samp{CalcEmbed:} if Embedded mode is enabled. The words after this describe the various Calc modes that are in effect. @@ -15693,7 +15864,7 @@ Symbolic mode (@kbd{m s}; @pxref{Symbolic Mode}). Matrix mode (@kbd{m v}; @pxref{Matrix Mode}). @item Matrix@var{n} -Dimensioned matrix mode (@kbd{C-u @var{n} m v}). +Dimensioned Matrix mode (@kbd{C-u @var{n} m v}). @item Scalar Scalar mode (@kbd{m v}; @pxref{Matrix Mode}). @@ -15708,7 +15879,7 @@ Fraction mode (@kbd{m f}; @pxref{Fraction Mode}). Infinite mode (@kbd{m i}; @pxref{Infinite Mode}). @item +Inf -Positive infinite mode (@kbd{C-u 0 m i}). +Positive Infinite mode (@kbd{C-u 0 m i}). @item NoSimp Default simplifications off (@kbd{m O}; @pxref{Simplification Modes}). @@ -15762,7 +15933,10 @@ Pascal language mode (@kbd{d P}). FORTRAN language mode (@kbd{d F}). @item TeX -@TeX{} language mode (@kbd{d T}; @pxref{TeX Language Mode}). +@TeX{} language mode (@kbd{d T}; @pxref{TeX and LaTeX Language Modes}). + +@item LaTeX +@LaTeX{} language mode (@kbd{d L}; @pxref{TeX and LaTeX Language Modes}). @item Eqn @dfn{Eqn} language mode (@kbd{d E}; @pxref{Eqn Language Mode}). @@ -15816,7 +15990,7 @@ No line breaking (@kbd{d b}). Selections show deep structure (@kbd{j b}; @pxref{Making Selections}). @item Save -Record modes in @file{~/.emacs} (@kbd{m R}; @pxref{General Mode Commands}). +Record modes in @file{~/.calc.el} (@kbd{m R}; @pxref{General Mode Commands}). @item Local Record modes in Embedded buffer (@kbd{m R}). @@ -15916,14 +16090,14 @@ to every element of a vector. If either argument of @kbd{+} is a complex number, the result will in general be complex. If one argument is in rectangular form and the other polar, -the current Polar Mode determines the form of the result. If Symbolic -Mode is enabled, the sum may be left as a formula if the necessary +the current Polar mode determines the form of the result. If Symbolic +mode is enabled, the sum may be left as a formula if the necessary conversions for polar addition are non-trivial. If both arguments of @kbd{+} are HMS forms, the forms are added according to the usual conventions of hours-minutes-seconds notation. If one argument is an HMS form and the other is a number, that number is converted from -degrees or radians (depending on the current Angular Mode) to HMS format +degrees or radians (depending on the current Angular mode) to HMS format and then the two HMS forms are added. If one argument of @kbd{+} is a date form, the other can be either a @@ -15944,9 +16118,9 @@ error form to a plain symbolic formula (as in @samp{(a +/- b) + c}) will not work, for the same reasons just mentioned for vectors. Instead you must write @samp{(a +/- b) + (c +/- 0)}. -If both arguments of @kbd{+} are modulo forms with equal values of @cite{M}, +If both arguments of @kbd{+} are modulo forms with equal values of @expr{M}, or if one argument is a modulo form and the other a plain number, the -result is a modulo form which represents the sum, modulo @cite{M}, of +result is a modulo form which represents the sum, modulo @expr{M}, of the two values. If both arguments of @kbd{+} are intervals, the result is an interval @@ -15967,7 +16141,7 @@ infinite in different directions the result is @code{nan}. @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 -computation @kbd{5 @key{RET} 2 -} produces 3, not @i{-3}. All options +computation @kbd{5 @key{RET} 2 -} produces 3, not @mathit{-3}. All options available for @kbd{+} are available for @kbd{-} as well. @kindex * @@ -16002,19 +16176,19 @@ whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @samp{[0 ..@: 9]}. @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 -performed is @cite{B} times the inverse of @cite{A}. This also occurs -if @cite{B} is itself a vector or matrix, in which case the effect is -to solve the set of linear equations represented by @cite{B}. If @cite{B} -is a matrix with the same number of rows as @cite{A}, or a plain vector +dividing a scalar @expr{B} by a square matrix @expr{A}, the computation +performed is @expr{B} times the inverse of @expr{A}. This also occurs +if @expr{B} is itself a vector or matrix, in which case the effect is +to solve the set of linear equations represented by @expr{B}. If @expr{B} +is a matrix with the same number of rows as @expr{A}, or a plain vector (which is interpreted here as a column vector), then the equation -@cite{A X = B} is solved for the vector or matrix @cite{X}. Otherwise, -if @cite{B} is a non-square matrix with the same number of @emph{columns} -as @cite{A}, the equation @cite{X A = B} is solved. If you wish a vector -@cite{B} to be interpreted as a row vector to be solved as @cite{X A = B}, +@expr{A X = B} is solved for the vector or matrix @expr{X}. Otherwise, +if @expr{B} is a non-square matrix with the same number of @emph{columns} +as @expr{A}, the equation @expr{X A = B} is solved. If you wish a vector +@expr{B} to be interpreted as a row vector to be solved as @expr{X A = B}, make it into a one-row matrix with @kbd{C-u 1 v p} first. To force a -left-handed solution with a square matrix @cite{B}, transpose @cite{A} and -@cite{B} before dividing, then transpose the result. +left-handed solution with a square matrix @expr{B}, transpose @expr{A} and +@expr{B} before dividing, then transpose the result. HMS forms can be divided by real numbers or by other HMS forms. Error forms can be divided in any combination of ways. Modulo forms where both @@ -16064,10 +16238,10 @@ operation when the arguments are integers, it avoids problems that @tindex % The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined -for all real numbers @cite{a} and @cite{b} (except @cite{b=0}). For -positive @cite{b}, the result will always be between 0 (inclusive) and -@cite{b} (exclusive). Modulo does not work for HMS forms and error forms. -If @cite{a} is a modulo form, its modulo is changed to @cite{b}, which +for all real numbers @expr{a} and @expr{b} (except @expr{b=0}). For +positive @expr{b}, the result will always be between 0 (inclusive) and +@expr{b} (exclusive). Modulo does not work for HMS forms and error forms. +If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which must be positive real number. @kindex : @@ -16075,7 +16249,7 @@ must be positive real number. @tindex fdiv The @kbd{:} (@code{calc-fdiv}) command [@code{fdiv} function in a formula] divides the two integers on the top of the stack to produce a fractional -result. This is a convenient shorthand for enabling Fraction Mode (with +result. This is a convenient shorthand for enabling Fraction mode (with @kbd{m f}) temporarily and using @samp{/}. Note that during numeric entry the @kbd{:} key is interpreted as a fraction separator, so to divide 8 by 6 you would have to type @kbd{8 @key{RET} 6 @key{RET} :}. (Of course, in @@ -16111,7 +16285,7 @@ absolute value squared of a number, vector or matrix, or error form. @pindex calc-sign @tindex sign The @kbd{f s} (@code{calc-sign}) [@code{sign}] command returns 1 if its -argument is positive, @i{-1} if its argument is negative, or 0 if its +argument is positive, @mathit{-1} if its argument is negative, or 0 if its argument is zero. In algebraic form, you can also write @samp{sign(a,x)} which evaluates to @samp{x * sign(a)}, i.e., either @samp{x}, @samp{-x}, or zero depending on the sign of @samp{a}. @@ -16121,7 +16295,7 @@ zero depending on the sign of @samp{a}. @tindex inv @cindex Reciprocal The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the -reciprocal of a number, i.e., @cite{1 / x}. Operating on a square +reciprocal of a number, i.e., @expr{1 / x}. Operating on a square matrix, it computes the inverse of that matrix. @kindex Q @@ -16129,15 +16303,15 @@ matrix, it computes the inverse of that matrix. @tindex sqrt The @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] command computes the square root of a number. For a negative real argument, the result will be a -complex number whose form is determined by the current Polar Mode. +complex number whose form is determined by the current Polar mode. @kindex f h @pindex calc-hypot @tindex hypot The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)} -is the length of the hypotenuse of a right triangle with sides @cite{a} -and @cite{b}. If the arguments are complex numbers, their squared +is the length of the hypotenuse of a right triangle with sides @expr{a} +and @expr{b}. If the arguments are complex numbers, their squared magnitudes are used. @kindex f Q @@ -16162,7 +16336,7 @@ The @kbd{f n} (@code{calc-min}) [@code{min}] and @kbd{f x} (@code{calc-max}) respectively. These commands also work on HMS forms, date forms, intervals, and infinities. (In algebraic expressions, these functions take any number of arguments and return the maximum or minimum among -all the arguments.)@refill +all the arguments.) @kindex f M @kindex f X @@ -16171,17 +16345,18 @@ all the arguments.)@refill @pindex calc-xpon-part @tindex xpon The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts -the ``mantissa'' part @cite{m} of its floating-point argument; @kbd{f X} +the ``mantissa'' part @expr{m} of its floating-point argument; @kbd{f X} (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part -@cite{e}. The original number is equal to @c{$m \times 10^e$} -@cite{m * 10^e}, -where @cite{m} is in the interval @samp{[1.0 ..@: 10.0)} except that -@cite{m=e=0} if the original number is zero. For integers +@expr{e}. The original number is equal to +@texline @math{m \times 10^e}, +@infoline @expr{m * 10^e}, +where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that +@expr{m=e=0} if the original number is zero. For integers and fractions, @code{mant} returns the number unchanged and @code{xpon} returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be used to ``unpack'' a floating-point number; this produces an integer mantissa and exponent, with the constraint that the mantissa is not -a multiple of ten (again except for the @cite{m=e=0} case).@refill +a multiple of ten (again except for the @expr{m=e=0} case). @kindex f S @pindex calc-scale-float @@ -16190,7 +16365,7 @@ The @kbd{f S} (@code{calc-scale-float}) [@code{scf}] function scales a number by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any real @samp{x}. The second argument must be an integer, but the first may actually be any numeric value. For example, @samp{scf(5,-2) = 0.05} -or @samp{1:20} depending on the current Fraction Mode.@refill +or @samp{1:20} depending on the current Fraction mode. @kindex f [ @kindex f ] @@ -16205,10 +16380,12 @@ floating-point numbers, the change is by one unit in the last place. For example, incrementing @samp{12.3456} when the current precision is 6 digits yields @samp{12.3457}. If the current precision had been 8 digits, the result would have been @samp{12.345601}. Incrementing -@samp{0.0} produces @c{$10^{-p}$} -@cite{10^-p}, where @cite{p} is the current +@samp{0.0} produces +@texline @math{10^{-p}}, +@infoline @expr{10^-p}, +where @expr{p} is the current precision. These operations are defined only on integers and floats. -With numeric prefix arguments, they change the number by @cite{n} units. +With numeric prefix arguments, they change the number by @expr{n} units. Note that incrementing followed by decrementing, or vice-versa, will almost but not quite always cancel out. Suppose the precision is @@ -16245,7 +16422,7 @@ expressed as an integer-valued floating-point number. 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 infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces -@i{-4}.@refill +@mathit{-4}. @kindex I F @pindex calc-ceiling @@ -16257,7 +16434,7 @@ infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces @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 -4, and @kbd{_3.6 I F} produces @i{-3}.@refill +4, and @kbd{_3.6 I F} produces @mathit{-3}. @kindex R @pindex calc-round @@ -16271,7 +16448,7 @@ The @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command rounds to the nearest integer. When the fractional part is .5 exactly, this command rounds away from zero. (All other rounding in the Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 -but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill +but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @mathit{-4}. @kindex I R @pindex calc-trunc @@ -16284,7 +16461,7 @@ but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] command truncates toward zero. In other words, it ``chops off'' everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and -@kbd{_3.6 I R} produces @i{-3}.@refill +@kbd{_3.6 I R} produces @mathit{-3}. These functions may not be applied meaningfully to error forms, but they do work for intervals. As a convenience, applying @code{floor} to a @@ -16322,7 +16499,7 @@ subtle point here is that the number being fed to @code{rounde} will already have been rounded to the current precision before @code{rounde} begins. For example, @samp{rounde(2.500001)} with a current precision of 6 will incorrectly, or at least surprisingly, yield 2 because the -argument will first have been rounded down to @cite{2.5} (which +argument will first have been rounded down to @expr{2.5} (which @code{rounde} sees as an exact tie between 2 and 3). Each of these functions, when written in algebraic formulas, allows @@ -16336,7 +16513,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(}@var{n}@t{)}', will produce @var{n}) just take @var{n} -modulo 1 using the @code{%} command.@refill +modulo 1 using the @code{%} command. Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm), and @kbd{f Q} (integer square root) commands, which are analogous to @@ -16351,8 +16528,8 @@ arguments and return the result rounded down to an integer. @pindex calc-conj @tindex conj The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the -complex conjugate of a number. For complex number @cite{a+bi}, the -complex conjugate is @cite{a-bi}. If the argument is a real number, +complex conjugate of a number. For complex number @expr{a+bi}, the +complex conjugate is @expr{a-bi}. If the argument is a real number, this command leaves it the same. If the argument is a vector or matrix, this command replaces each element by its complex conjugate. @@ -16362,17 +16539,17 @@ 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{(}@var{r}@t{;}@c{$\theta$} -@var{theta}@t{)}'. +@texline `@t{(}@var{r}@t{;}@math{\theta}@t{)}'. +@infoline `@t{(}@var{r}@t{;}@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 +be in the range @mathit{-180} degrees (exclusive) to @mathit{+180} degrees +(inclusive), or the equivalent range in radians. @pindex calc-imaginary The @code{calc-imaginary} command multiplies the number on the -top of the stack by the imaginary number @cite{i = (0,1)}. This +top of the stack by the imaginary number @expr{i = (0,1)}. This command is not normally bound to a key in Calc, but it is available -on the @key{IMAG} button in Keypad Mode. +on the @key{IMAG} button in Keypad mode. @kindex f r @pindex calc-re @@ -16380,14 +16557,14 @@ on the @key{IMAG} button in Keypad Mode. The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number by its real part. This command has no effect on real numbers. (As an added convenience, @code{re} applied to a modulo form extracts -the value part.)@refill +the value part.) @kindex f i @pindex calc-im @tindex im 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 +or matrix argument, these functions operate element-wise. @ignore @mindex v p @@ -16395,9 +16572,9 @@ or matrix argument, these functions operate element-wise.@refill @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 -a prefix argument of @i{-1}, it produces a rectangular complex number; -with an argument of @i{-2}, it produces a polar complex number. +the stack into a composite object such as a complex number. With +a prefix argument of @mathit{-1}, it produces a rectangular complex number; +with an argument of @mathit{-2}, it produces a polar complex number. (Also, @pxref{Building Vectors}.) @ignore @@ -16421,13 +16598,13 @@ to another; they are two-key sequences beginning with the letter @kbd{c}. @tindex pfloat The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the number on the top of the stack to floating-point form. For example, -@cite{23} is converted to @cite{23.0}, @cite{3:2} is converted to -@cite{1.5}, and @cite{2.3} is left the same. If the value is a composite +@expr{23} is converted to @expr{23.0}, @expr{3:2} is converted to +@expr{1.5}, and @expr{2.3} is left the same. If the value is a composite object such as a complex number or vector, each of the components is converted to floating-point. If the value is a formula, all numbers in the formula are converted to floating-point. Note that depending on the current floating-point precision, conversion to floating-point -format may lose information.@refill +format may lose information. As a special exception, integers which appear as powers or subscripts are not floated by @kbd{c f}. If you really want to float a power, @@ -16480,7 +16657,7 @@ which is analogous to @kbd{H c f} discussed above. The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a number into degrees form. The value on the top of the stack may be an HMS form (interpreted as degrees-minutes-seconds), or a real number which -will be interpreted in radians regardless of the current angular mode.@refill +will be interpreted in radians regardless of the current angular mode. @kindex c r @pindex calc-to-radians @@ -16513,7 +16690,7 @@ This command is equivalent to the @code{rect} or @code{polar} functions in algebraic formulas, depending on the direction of conversion. (It uses @code{polar}, except that if the argument is already a polar complex number, it uses @code{rect} instead. The -@kbd{I c p} command always uses @code{rect}.)@refill +@kbd{I c p} command always uses @code{rect}.) @kindex c c @pindex calc-clean @@ -16521,12 +16698,12 @@ already a polar complex number, it uses @code{rect} instead. The The @kbd{c c} (@code{calc-clean}) [@code{pclean}] command ``cleans'' the number on the top of the stack. Floating point numbers are re-rounded according to the current precision. Polar numbers whose angular -components have strayed from the @i{-180} to @i{+180} degree range +components have strayed from the @mathit{-180} to @mathit{+180} degree range are normalized. (Note that results will be undesirable if the current angular mode is different from the one under which the number was produced!) Integers and fractions are generally unaffected by this operation. Vectors and formulas are cleaned by cleaning each component -number (i.e., pervasively).@refill +number (i.e., pervasively). If the simplification mode is set below the default level, it is raised to the default level for the purposes of this command. Thus, @kbd{c c} @@ -16777,8 +16954,8 @@ of the input date form are lost. With a numeric prefix argument @var{n} in the range from 1 to 366, @kbd{t Y} computes the @var{n}th day of the year (366 is treated as 365 in non-leap years). A prefix argument of 0 computes the last day of the -year (December 31). A negative prefix argument from @i{-1} to -@i{-12} computes the first day of the @var{n}th month of the year. +year (December 31). A negative prefix argument from @mathit{-1} to +@mathit{-12} computes the first day of the @var{n}th month of the year. @kindex t W @pindex calc-new-week @@ -16847,7 +17024,7 @@ command for this function; use @kbd{C-u 12 t I} instead. There is no @code{newday} function at all because @kbd{F} [@code{floor}] serves this purpose. Similarly, instead of @code{incday} and -@code{incweek} simply use @cite{d + n} or @cite{d + 7 n}. +@code{incweek} simply use @expr{d + n} or @expr{d + 7 n}. @xref{Basic Arithmetic}, for the @kbd{f ]} [@code{incr}] command which can adjust a date/time form by a certain number of seconds. @@ -16908,12 +17085,12 @@ considered to be a holiday. @item Any Calc formula which evaluates to one of the above three things. -If the formula involves the variable @cite{y}, it stands for a -yearly repeating holiday; @cite{y} will take on various year +If the formula involves the variable @expr{y}, it stands for a +yearly repeating holiday; @expr{y} will take on various year numbers like 1992. For example, @samp{date(y, 12, 25)} specifies Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies Thanksgiving (which is held on the fourth Thursday of November). -If the formula involves the variable @cite{m}, that variable +If the formula involves the variable @expr{m}, that variable takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is a holiday that takes place on the 15th of every month. @@ -17109,7 +17286,9 @@ the corresponding generalized time zone (like @code{PGT}). If your system does not have a suitable @samp{date} command, you may wish to put a @samp{(setq var-TimeZone ...)} in your Emacs -initialization file to set the time zone. The easiest way to do +initialization file to set the time zone. (Since you are interacting +with the variable @code{TimeZone} directly from Emacs Lisp, the +@code{var-} prefix needs to be present.) The easiest way to do this is to edit the @code{TimeZone} variable using Calc's @kbd{s T} command, then use the @kbd{s p} (@code{calc-permanent-variable}) command to save the value of @code{TimeZone} permanently. @@ -17147,7 +17326,7 @@ The Lisp variable @code{math-daylight-savings-hook} holds the name of a function that is used to compute the daylight savings adjustment for a given date. The default is @code{math-std-daylight-savings}, which computes an adjustment -(either 0 or @i{-1}) using the North American rules given above. +(either 0 or @mathit{-1}) using the North American rules given above. The daylight savings hook function is called with four arguments: The date, as a floating-point number in standard Calc format; @@ -17195,7 +17374,7 @@ daylight savings hook: @noindent The @code{bump} parameter is equal to zero when Calc is converting from a date form in a generalized time zone into a GMT date value. -It is @i{-1} when Calc is converting in the other direction. The +It is @mathit{-1} when Calc is converting in the other direction. The adjustments shown above ensure that the conversion behaves correctly and reasonably around the 2 a.m.@: transition in each direction. @@ -17205,7 +17384,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. @@ -17328,7 +17507,7 @@ 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 @key{RET} 50 b %} is to compute @cite{(50-40)/40}, converting +of @kbd{40 @key{RET} 50 b %} is to compute @expr{(50-40)/40}, converting the answer to percentage form as if by @kbd{c %}. @node Future Value, Present Value, Percentages, Financial Functions @@ -17372,7 +17551,7 @@ The algebraic functions @code{fv} and @code{fvb} accept an optional fourth argument, which is used as an initial lump sum in the sense of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n}, @var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment}) -+ fvl(@var{rate}, @var{n}, @var{initial})}.@refill ++ fvl(@var{rate}, @var{n}, @var{initial})}. To illustrate the relationships between these functions, we could do the @code{fvb} calculation ``by hand'' using @code{fvl}. The @@ -17390,7 +17569,7 @@ are now at the ends of the periods. The end of one year is the same as the beginning of the next, so what this really means is that we've lost the payment at year zero (which contributed $1300.78), but we're now counting the payment at year five (which, since it didn't have -a chance to earn interest, counts as $1000). Indeed, @cite{5569.96 = +a chance to earn interest, counts as $1000). Indeed, @expr{5569.96 = 5870.73 - 1300.78 + 1000} (give or take a bit of roundoff error). @node Present Value, Related Financial Functions, Future Value, Financial Functions @@ -17420,7 +17599,7 @@ considering, which is @code{fv(9%, 4, 2000) = 9146.26}, with the return from leaving the money in the bank, which is @code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money you would have to put up in advance. The @code{pv} function -finds the break-even point, @cite{x = 6479.44}, at which +finds the break-even point, @expr{x = 6479.44}, at which @code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is the largest amount you should be willing to invest. @@ -17469,7 +17648,7 @@ vector statistical functions like @code{vsum}. payment arguments, each either a vector or a plain number, all these values are collected left-to-right into the complete list of payments. A numeric prefix argument on the @kbd{b N} command says how many -payment values or vectors to take from the stack.@refill +payment values or vectors to take from the stack. @kindex I b N @tindex npvb @@ -17491,7 +17670,7 @@ The @kbd{b M} (@code{calc-fin-pmt}) [@code{pmt}] command computes the amount of periodic payment necessary to amortize a loan. Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the value of @var{payment} such that @code{pv(@var{rate}, @var{n}, -@var{payment}) = @var{amount}}.@refill +@var{payment}) = @var{amount}}. @kindex I b M @tindex pmtb @@ -17513,14 +17692,14 @@ Thus @code{nper(@var{rate}, @var{payment}, @var{amount})} equals the value of @var{n} such that @code{pv(@var{rate}, @var{n}, @var{payment}) = @var{amount}}. If @var{payment} is too small ever to amortize a loan for @var{amount} at interest rate @var{rate}, -the @code{nper} function is left in symbolic form.@refill +the @code{nper} function is left in symbolic form. @kindex I b # @tindex nperb The @kbd{I b #} [@code{nperb}] command does the same computation but using @code{pvb} instead of @code{pv}. You can give a fourth lump-sum argument to these functions, but the computation will be -rather slow in the four-argument case.@refill +rather slow in the four-argument case. @kindex H b # @tindex nperl @@ -17528,7 +17707,7 @@ The @kbd{H b #} [@code{nperl}] command does the same computation using @code{pvl}. By exchanging @var{payment} and @var{amount} you can also get the solution for @code{fvl}. For example, @code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a -bank account earning 8%, it will take nine years to grow to $2000.@refill +bank account earning 8%, it will take nine years to grow to $2000. @kindex b T @pindex calc-fin-rate @@ -17537,7 +17716,7 @@ The @kbd{b T} (@code{calc-fin-rate}) [@code{rate}] command computes the rate of return on an investment. This is also an inverse of @code{pv}: @code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of @var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) = -@var{amount}}. The result is expressed as a formula like @samp{6.3%}.@refill +@var{amount}}. The result is expressed as a formula like @samp{6.3%}. @kindex I b T @kindex H b T @@ -17549,7 +17728,7 @@ in place of @code{pv}. Also, @code{rate} and @code{rateb} can accept an optional fourth argument just like @code{pv} and @code{pvb}. To redo the above example from a different perspective, @code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an -interest rate of 8% in order to double your account in nine years.@refill +interest rate of 8% in order to double your account in nine years. @kindex b I @pindex calc-fin-irr @@ -17611,7 +17790,7 @@ For symmetry, the @code{sln} function will accept a @var{period} parameter as well, although it will ignore its value except that the 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}) +For example, pushing the vector @expr{[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,$)] @key{RET}} produces a matrix that allows us to compare the three depreciation methods: @@ -17632,7 +17811,7 @@ We see that @code{sln} depreciates by the same amount each year, @kbd{syd} depreciates more at the beginning and less at the end, and @kbd{ddb} weights the depreciation even more toward the beginning. -Summing columns with @kbd{V R : +} yields @cite{[10000, 10000, 10000]}; +Summing columns with @kbd{V R : +} yields @expr{[10000, 10000, 10000]}; the total depreciation in any method is (by definition) the difference between the cost and the salvage value. @@ -17651,7 +17830,7 @@ formulas below for symbolic arguments only when you use the @kbd{a "} integrals or solving equations involving the functions. @ifinfo -These formulas are shown using the conventions of ``Big'' display +These formulas are shown using the conventions of Big display mode (@kbd{d B}); for example, the formula for @code{fv} written linearly is @samp{pmt * ((1 + rate)^n) - 1) / rate}. @@ -17670,7 +17849,7 @@ fvb(rate, n, pmt) = pmt * ---------------------------- fvl(rate, n, pmt) = pmt * (1 + rate) -n - 1 - (1 + rate) + 1 - (1 + rate) pv(rate, n, pmt) = pmt * ---------------- rate @@ -17754,7 +17933,7 @@ $$ \code{ddb}(c, s, l, p) = { 2 (c - \hbox{depreciation so far}) \over l } $$ @end tex @noindent -In @code{pmt} and @code{pmtb}, @cite{x=0} if omitted. +In @code{pmt} and @code{pmtb}, @expr{x=0} if omitted. These functions accept any numeric objects, including error forms, intervals, and even (though not very usefully) complex numbers. The @@ -17814,31 +17993,34 @@ commands, respectively). You may also wish to enable display of leading zeros with @kbd{d z}. @xref{Radix Modes}. @cindex Word size for binary operations -The Calculator maintains a current @dfn{word size} @cite{w}, an +The Calculator maintains a current @dfn{word size} @expr{w}, an arbitrary positive or negative integer. For a positive word size, all -of the binary operations described here operate modulo @cite{2^w}. In +of the binary operations described here operate modulo @expr{2^w}. In particular, negative arguments are converted to positive integers modulo -@cite{2^w} by all binary functions.@refill +@expr{2^w} by all binary functions. If the word size is negative, binary operations produce 2's complement -integers from @c{$-2^{-w-1}$} -@cite{-(2^(-w-1))} to @c{$2^{-w-1}-1$} -@cite{2^(-w-1)-1} inclusive. Either -mode accepts inputs in any range; the sign of @cite{w} affects only -the results produced. +integers from +@texline @math{-2^{-w-1}} +@infoline @expr{-(2^(-w-1))} +to +@texline @math{2^{-w-1}-1} +@infoline @expr{2^(-w-1)-1} +inclusive. Either mode accepts inputs in any range; the sign of +@expr{w} affects only the results produced. @kindex b c @pindex calc-clip @tindex clip The @kbd{b c} (@code{calc-clip}) [@code{clip}] command can be used to clip a number by reducing it modulo -@cite{2^w}. The commands described in this chapter automatically clip +@expr{2^w}. The commands described in this chapter automatically clip their results to the current word size. Note that other operations like addition do not use the current word size, since integer addition generally is not ``binary.'' (However, @pxref{Simplification Modes}, @code{calc-bin-simplify-mode}.) For example, with a word size of 8 bits @kbd{b c} converts a number to the range 0 to 255; with a word -size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.@refill +size of @mathit{-8} @kbd{b c} converts to the range @mathit{-128} to 127. @kindex b w @pindex calc-word-size @@ -17854,11 +18036,11 @@ When the binary operations are written in symbolic form, they take an optional second (or third) word-size parameter. When a formula like @samp{and(a,b)} is finally evaluated, the word size current at that time will be used, but when @samp{and(a,b,-8)} is evaluated, a word size of -@i{-8} will always be used. A symbolic binary function will be left +@mathit{-8} will always be used. A symbolic binary function will be left in symbolic form unless the all of its argument(s) are integers or integer-valued floats. -If either or both arguments are modulo forms for which @cite{M} is a +If either or both arguments are modulo forms for which @expr{M} is a power of two, that power of two is taken as the word size unless a numeric prefix argument overrides it. The current word size is never consulted when modulo-power-of-two forms are involved. @@ -17868,7 +18050,7 @@ consulted when modulo-power-of-two forms are involved. @tindex and The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise AND of the two numbers on the top of the stack. In other words, for each -of the @cite{w} binary digits of the two numbers (pairwise), the corresponding +of the @expr{w} binary digits of the two numbers (pairwise), the corresponding bit of the result is 1 if and only if both input bits are 1: @samp{and(2#1100, 2#1010) = 2#1000}. @@ -18002,18 +18184,21 @@ 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 -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. -With the Inverse flag, it pushes Euler's constant @c{$\gamma$} -@cite{gamma} (about 0.5772). With both Inverse and Hyperbolic, it -pushes the ``golden ratio'' @c{$\phi$} -@cite{phi} (about 1.618). (At present, Euler's constant is not available +One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes +the value of @cpi{} (at the current precision) onto the stack. With the +Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms. +With the Inverse flag, it pushes Euler's constant +@texline @math{\gamma} +@infoline @expr{gamma} +(about 0.5772). With both Inverse and Hyperbolic, it +pushes the ``golden ratio'' +@texline @math{\phi} +@infoline @expr{phi} +(about 1.618). (At present, Euler's constant is not available to unlimited precision; Calc knows only the first 100 digits.) 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 +respectively, instead of their values; @pxref{Symbolic Mode}. @ignore @mindex Q @@ -18065,7 +18250,7 @@ this is redundant with the @kbd{E} command. @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. +exponential, i.e., @expr{e} raised to the power of the number on the stack. The meanings of the Inverse and Hyperbolic flags follow from those for the @code{calc-ln} command. @@ -18086,8 +18271,9 @@ 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}], it raises ten to a given power.) Note that the common logarithm of a complex number is computed by taking the natural logarithm and dividing -by @c{$\ln10$} -@cite{ln(10)}. +by +@texline @math{\ln10}. +@infoline @expr{ln(10)}. @kindex B @kindex I B @@ -18096,10 +18282,11 @@ by @c{$\ln10$} @tindex alog The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since -@c{$2^{10} = 1024$} -@cite{2^10 = 1024}. In certain cases like @samp{log(3,9)}, the result -will be either @cite{1:2} or @cite{0.5} depending on the current Fraction -Mode setting. With the Inverse flag [@code{alog}], this command is +@texline @math{2^{10} = 1024}. +@infoline @expr{2^10 = 1024}. +In certain cases like @samp{log(3,9)}, the result +will be either @expr{1:2} or @expr{0.5} depending on the current Fraction +mode setting. With the Inverse flag [@code{alog}], this command is similar to @kbd{^} except that the order of the arguments is reversed. @kindex f I @@ -18108,7 +18295,7 @@ similar to @kbd{^} except that the order of the arguments is reversed. The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the integer logarithm of a number to any base. The number and the base must themselves be positive integers. This is the true logarithm, rounded -down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @cite{x} in the +down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @expr{x} in the range from 1000 to 9999. If both arguments are positive integers, exact integer arithmetic is used; otherwise, this is equivalent to @samp{floor(log(x,b))}. @@ -18117,19 +18304,21 @@ integer arithmetic is used; otherwise, this is equivalent to @pindex calc-expm1 @tindex expm1 The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes -@c{$e^x - 1$} -@cite{exp(x)-1}, but using an algorithm that produces a more accurate -answer when the result is close to zero, i.e., when @c{$e^x$} -@cite{exp(x)} is close -to one. +@texline @math{e^x - 1}, +@infoline @expr{exp(x)-1}, +but using an algorithm that produces a more accurate +answer when the result is close to zero, i.e., when +@texline @math{e^x} +@infoline @expr{exp(x)} +is close to one. @kindex f L @pindex calc-lnp1 @tindex lnp1 The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes -@c{$\ln(x+1)$} -@cite{ln(x+1)}, producing a more accurate answer when @cite{x} is close -to zero. +@texline @math{\ln(x+1)}, +@infoline @expr{ln(x+1)}, +producing a more accurate answer when @expr{x} is close to zero. @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions @section Trigonometric/Hyperbolic Functions @@ -18142,7 +18331,7 @@ The shift-@kbd{S} (@code{calc-sin}) [@code{sin}] command computes the sine of an angle or complex number. If the input is an HMS form, it is interpreted as degrees-minutes-seconds; otherwise, the input is interpreted according to the current angular mode. It is best to use Radians mode when operating -on complex numbers.@refill +on complex numbers. Calc's ``units'' mechanism includes angular units like @code{deg}, @code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated @@ -18153,20 +18342,16 @@ of the current angular mode. @xref{Basic Operations on Units}. Also, the symbolic variable @code{pi} is not ordinarily recognized in arguments to trigonometric functions, as in @samp{sin(3 pi / 4)}, but the @kbd{a s} (@code{calc-simplify}) command recognizes many such -formulas when the current angular mode is radians @emph{and} symbolic +formulas when the current angular mode is Radians @emph{and} Symbolic mode is enabled; this example would be replaced by @samp{sqrt(2) / 2}. @xref{Symbolic Mode}. Beware, this simplification occurs even if you have stored a different value in the variable @samp{pi}; this is one reason why changing built-in variables is a bad idea. Arguments of -the form @cite{x} plus a multiple of @c{$\pi/2$} -@cite{pi/2} are also simplified. -Calc includes similar formulas for @code{cos} and @code{tan}.@refill +the form @expr{x} plus a multiple of @cpiover{2} are also simplified. +Calc includes similar formulas for @code{cos} and @code{tan}. The @kbd{a s} command knows all angles which are integer multiples of -@c{$\pi/12$} -@cite{pi/12}, @c{$\pi/10$} -@cite{pi/10}, or @c{$\pi/8$} -@cite{pi/8} radians. In degrees mode, +@cpiover{12}, @cpiover{10}, or @cpiover{8} radians. In Degrees mode, analogous simplifications occur for integer multiples of 15 or 18 degrees, and for arguments plus multiples of 90 degrees. @@ -18265,10 +18450,10 @@ variants of these functions. @tindex arctan2 The @kbd{f T} (@code{calc-arctan2}) [@code{arctan2}] command takes two numbers from the stack and computes the arc tangent of their ratio. The -result is in the full range from @i{-180} (exclusive) to @i{+180} +result is in the full range from @mathit{-180} (exclusive) to @mathit{+180} (inclusive) degrees, or the analogous range in radians. A similar result would be obtained with @kbd{/} followed by @kbd{I T}, but the -value would only be in the range from @i{-90} to @i{+90} degrees +value would only be in the range from @mathit{-90} to @mathit{+90} degrees since the division loses information about the signs of the two components, and an error might result from an explicit division by zero which @code{arctan2} would avoid. By (arbitrary) definition, @@ -18291,7 +18476,7 @@ cosine of a number, returning them as a vector of the form @samp{[@var{cos}, @var{sin}]}. With the Inverse flag [@code{arcsincos}], this command takes a two-element vector as an argument and computes @code{arctan2} of the elements. -(This command does not accept the Hyperbolic flag.)@refill +(This command does not accept the Hyperbolic flag.) @node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions @section Advanced Mathematical Functions @@ -18316,8 +18501,9 @@ The @kbd{f g} (@code{calc-gamma}) [@code{gamma}] command computes the Euler gamma function. For positive integer arguments, this is related to the factorial function: @samp{gamma(n+1) = fact(n)}. For general complex arguments the gamma function can be defined by the following definite -integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$} -@cite{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}. +integral: +@texline @math{\Gamma(a) = \int_0^\infty t^{a-1} e^t dt}. +@infoline @expr{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}. (The actual implementation uses far more efficient computational methods.) @kindex f G @@ -18349,22 +18535,23 @@ integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$} @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 -the integral, @c{$P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)$} -@cite{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}. -This implies that @samp{gammaP(a,inf) = 1} for any @cite{a} (see the +the integral, +@texline @math{P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)}. +@infoline @expr{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}. +This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the definition of the normal gamma function). Several other varieties of incomplete gamma function are defined. -The complement of @cite{P(a,x)}, called @cite{Q(a,x) = 1-P(a,x)} by +The complement of @expr{P(a,x)}, called @expr{Q(a,x) = 1-P(a,x)} by some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command. You can think of this as taking the other half of the integral, from -@cite{x} to infinity. +@expr{x} to infinity. @ifinfo -The functions corresponding to the integrals that define @cite{P(a,x)} -and @cite{Q(a,x)} but without the normalizing @cite{1/gamma(a)} -factor are called @cite{g(a,x)} and @cite{G(a,x)}, respectively -(where @cite{g} and @cite{G} represent the lower- and upper-case Greek +The functions corresponding to the integrals that define @expr{P(a,x)} +and @expr{Q(a,x)} but without the normalizing @expr{1/gamma(a)} +factor are called @expr{g(a,x)} and @expr{G(a,x)}, respectively +(where @expr{g} and @expr{G} represent the lower- and upper-case Greek letter gamma). You can obtain these using the @kbd{H f G} [@code{gammag}] and @kbd{H I f G} [@code{gammaG}] commands. @end ifinfo @@ -18382,10 +18569,11 @@ You can obtain these using the \kbd{H f G} [\code{gammag}] and @tindex beta The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the Euler beta function, which is defined in terms of the gamma function as -@c{$B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)$} -@cite{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, or by -@c{$B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt$} -@cite{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}. +@texline @math{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)}, +@infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, +or by +@texline @math{B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt}. +@infoline @expr{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}. @kindex f B @kindex H f B @@ -18393,9 +18581,9 @@ Euler beta function, which is defined in terms of the gamma function as @tindex betaI @tindex betaB The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes -the incomplete beta function @cite{I(x,a,b)}. It is defined by -@c{$I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)$} -@cite{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}. +the incomplete beta function @expr{I(x,a,b)}. It is defined by +@texline @math{I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)}. +@infoline @expr{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}. Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding un-normalized version [@code{betaB}]. @@ -18405,12 +18593,13 @@ un-normalized version [@code{betaB}]. @tindex erf @tindex erfc The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the -error function @c{$\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt$} -@cite{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}. +error function +@texline @math{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt}. +@infoline @expr{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}. The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] is the corresponding integral from @samp{x} to infinity; the sum -@c{$\hbox{erf}(x) + \hbox{erfc}(x) = 1$} -@cite{erf(x) + erfc(x) = 1}. +@texline @math{\hbox{erf}(x) + \hbox{erfc}(x) = 1}. +@infoline @expr{erf(x) + erfc(x) = 1}. @kindex f j @kindex f y @@ -18422,10 +18611,10 @@ The @kbd{f j} (@code{calc-bessel-J}) [@code{besJ}] and @kbd{f y} (@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel functions of the first and second kinds, respectively. In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter -@cite{n} is often an integer, but is not required to be one. +@expr{n} is often an integer, but is not required to be one. Calc's implementation of the Bessel functions currently limits the precision to 8 digits, and may not be exact even to that precision. -Use with care!@refill +Use with care! @node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions @section Branch Cuts and Principal Values @@ -18458,9 +18647,9 @@ are designed with proper behavior around the branch cuts in mind, @emph{not} efficiency or accuracy. You may need to increase the floating precision and wait a while to get suitable answers from them. -For @samp{sqrt(a+bi)}: When @cite{a<0} and @cite{b} is small but positive -or zero, the result is close to the @cite{+i} axis. For @cite{b} small and -negative, the result is close to the @cite{-i} axis. The result always lies +For @samp{sqrt(a+bi)}: When @expr{a<0} and @expr{b} is small but positive +or zero, the result is close to the @expr{+i} axis. For @expr{b} small and +negative, the result is close to the @expr{-i} axis. The result always lies in the right half of the complex plane. For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}. @@ -18469,8 +18658,8 @@ Thus the branch cuts for @code{sqrt} and @code{ln} both lie on the negative real axis. The following table describes these branch cuts in another way. -If the real and imaginary parts of @cite{z} are as shown, then -the real and imaginary parts of @cite{f(z)} will be as shown. +If the real and imaginary parts of @expr{z} are as shown, then +the real and imaginary parts of @expr{f(z)} will be as shown. Here @code{eps} stands for a small positive value; each occurrence of @code{eps} may stand for a different small value. @@ -18485,35 +18674,35 @@ occurrence of @code{eps} may stand for a different small value. For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. One interesting consequence of this is that @samp{(-8)^1:3} does -not evaluate to @i{-2} as you might expect, but to the complex -number @cite{(1., 1.732)}. Both of these are valid cube roots -of @i{-8} (as is @cite{(1., -1.732)}); Calc chooses a perhaps +not evaluate to @mathit{-2} as you might expect, but to the complex +number @expr{(1., 1.732)}. Both of these are valid cube roots +of @mathit{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps less-obvious root for the sake of mathematical consistency. For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}. -The branch cuts are on the real axis, less than @i{-1} and greater than 1. +The branch cuts are on the real axis, less than @mathit{-1} and greater than 1. For @samp{arccos(z)}: This is defined by @samp{-i*ln(z + i*sqrt(1-z^2))}, or equivalently by @samp{pi/2 - arcsin(z)}. The branch cuts are on -the real axis, less than @i{-1} and greater than 1. +the real axis, less than @mathit{-1} and greater than 1. For @samp{arctan(z)}: This is defined by @samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}. The branch cuts are on the -imaginary axis, below @cite{-i} and above @cite{i}. +imaginary axis, below @expr{-i} and above @expr{i}. For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}. -The branch cuts are on the imaginary axis, below @cite{-i} and -above @cite{i}. +The branch cuts are on the imaginary axis, below @expr{-i} and +above @expr{i}. For @samp{arccosh(z)}: This is defined by @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the real axis less than 1. For @samp{arctanh(z)}: This is defined by @samp{(ln(1+z) - ln(1-z)) / 2}. -The branch cuts are on the real axis, less than @i{-1} and greater than 1. +The branch cuts are on the real axis, less than @mathit{-1} and greater than 1. The following tables for @code{arcsin}, @code{arccos}, and -@code{arctan} assume the current angular mode is radians. The +@code{arctan} assume the current angular mode is Radians. The hyperbolic functions operate independently of the angular mode. @smallexample @@ -18581,38 +18770,47 @@ are not rigorously specified at present. The @kbd{k r} (@code{calc-random}) [@code{random}] command produces random numbers of various sorts. -Given a positive numeric prefix argument @cite{M}, it produces a random -integer @cite{N} in the range @c{$0 \le N < M$} -@cite{0 <= N < M}. Each of the @cite{M} -values appears with equal probability.@refill +Given a positive numeric prefix argument @expr{M}, it produces a random +integer @expr{N} in the range +@texline @math{0 \le N < M}. +@infoline @expr{0 <= N < M}. +Each of the @expr{M} values appears with equal probability. With no numeric prefix argument, the @kbd{k r} command takes its argument -from the stack instead. Once again, if this is a positive integer @cite{M} -the result is a random integer less than @cite{M}. However, note that -while numeric prefix arguments are limited to six digits or so, an @cite{M} -taken from the stack can be arbitrarily large. If @cite{M} is negative, -the result is a random integer in the range @c{$M < N \le 0$} -@cite{M < N <= 0}. - -If the value on the stack is a floating-point number @cite{M}, the result -is a random floating-point number @cite{N} in the range @c{$0 \le N < M$} -@cite{0 <= N < M} -or @c{$M < N \le 0$} -@cite{M < N <= 0}, according to the sign of @cite{M}. - -If @cite{M} is zero, the result is a Gaussian-distributed random real +from the stack instead. Once again, if this is a positive integer @expr{M} +the result is a random integer less than @expr{M}. However, note that +while numeric prefix arguments are limited to six digits or so, an @expr{M} +taken from the stack can be arbitrarily large. If @expr{M} is negative, +the result is a random integer in the range +@texline @math{M < N \le 0}. +@infoline @expr{M < N <= 0}. + +If the value on the stack is a floating-point number @expr{M}, the result +is a random floating-point number @expr{N} in the range +@texline @math{0 \le N < M} +@infoline @expr{0 <= N < M} +or +@texline @math{M < N \le 0}, +@infoline @expr{M < N <= 0}, +according to the sign of @expr{M}. + +If @expr{M} is zero, the result is a Gaussian-distributed random real number; the distribution has a mean of zero and a standard deviation 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 @var{m} -and @c{$\sigma$} -@var{s} are both real numbers, the result uses a Gaussian -distribution with mean @var{m} and standard deviation @c{$\sigma$} +If @expr{M} is an error form +@texline @math{m} @code{+/-} @math{\sigma} +@infoline @samp{m +/- s} +where @var{m} and +@texline @math{\sigma} +@infoline @var{s} +are both real numbers, the result uses a Gaussian distribution with mean +@var{m} and standard deviation +@texline @math{\sigma}. @var{s}. -If @cite{M} is an interval form, the lower and upper bounds specify the +If @expr{M} is an interval form, the lower and upper bounds specify the acceptable limits of the random numbers. If both bounds are integers, the result is a random integer in the specified range. If either bound is floating-point, the result is a random real number in the specified @@ -18624,7 +18822,7 @@ million numbers from 1.00000 to 1.99999; @samp{random([1.0..2.0])} may additionally return 2.00000, but the probability of this happening is extremely small.) -If @cite{M} is a vector, the result is one element taken at random from +If @expr{M} is a vector, the result is one element taken at random from the vector. All elements of the vector are given equal probabilities. @vindex RandSeed @@ -18647,9 +18845,9 @@ number between zero and one. It is equivalent to @samp{random(1.0)}. @kindex k a @pindex calc-random-again The @kbd{k a} (@code{calc-random-again}) command produces another random -number, re-using the most recent value of @cite{M}. With a numeric +number, re-using the most recent value of @expr{M}. With a numeric prefix argument @var{n}, it produces @var{n} more random numbers using -that value of @cite{M}. +that value of @expr{M}. @kindex k h @pindex calc-shuffle @@ -18657,12 +18855,12 @@ that value of @cite{M}. The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several random values with no duplicates. The value on the top of the stack specifies the set from which the random values are drawn, and may be any -of the @cite{M} formats described above. The numeric prefix argument +of the @expr{M} formats described above. The numeric prefix argument gives the length of the desired list. (If you do not provide a numeric prefix argument, the length of the list is taken from the top of the -stack, and @cite{M} from second-to-top.) +stack, and @expr{M} from second-to-top.) -If @cite{M} is a floating-point number, zero, or an error form (so +If @expr{M} is a floating-point number, zero, or an error form (so that the random values are being drawn from the set of real numbers) there is little practical difference between using @kbd{k h} and using @kbd{k r} several times. But if the set of possible values consists @@ -18670,8 +18868,8 @@ of just a few integers, or the elements of a vector, then there is a very real chance that multiple @kbd{k r}'s will produce the same number more than once. The @kbd{k h} command produces a vector whose elements are always distinct. (Actually, there is a slight exception: -If @cite{M} is a vector, no given vector element will be drawn more -than once, but if several elements of @cite{M} are equal, they may +If @expr{M} is a vector, no given vector element will be drawn more +than once, but if several elements of @expr{M} are equal, they may each make it into the result vector.) One use of @kbd{k h} is to rearrange a list at random. This happens @@ -18679,12 +18877,12 @@ if the prefix argument is equal to the number of values in the list: @kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list @samp{[2.5, 1, 1.5, 3, 2]}. As a convenient feature, if the argument @var{n} is negative it is replaced by the size of the set represented -by @cite{M}. Naturally, this is allowed only when @cite{M} specifies +by @expr{M}. Naturally, this is allowed only when @expr{M} specifies a small discrete set of possibilities. To do the equivalent of @kbd{k h} but with duplications allowed, -given @cite{M} on the stack and with @var{n} just entered as a numeric -prefix, use @kbd{v b} to build a vector of copies of @cite{M}, then use +given @expr{M} on the stack and with @var{n} just entered as a numeric +prefix, use @kbd{v b} to build a vector of copies of @expr{M}, then use @kbd{V M k r} to ``map'' the normal @kbd{k r} function over the elements of this vector. @xref{Matrix Functions}. @@ -18721,10 +18919,12 @@ generators that are typically used to implement @code{random}. If @code{RandSeed} contains an integer, Calc uses this integer to seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, -computing @c{$X_{n-55} - X_{n-24}$} -@cite{X_n-55 - X_n-24}). This method expands the seed +computing +@texline @math{X_{n-55} - X_{n-24}}. +@infoline @expr{X_n-55 - X_n-24}). +This method expands the seed value into a large table which is maintained internally; the variable -@code{RandSeed} is changed from, e.g., 42 to the vector @cite{[42]} +@code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]} to indicate that the seed has been absorbed into this table. When @code{RandSeed} contains a vector, @kbd{k r} and related commands continue to use the same internal table as last time. There is no @@ -18756,16 +18956,21 @@ value. To create a random floating-point number with precision @var{p}, Calc simply creates a random @var{p}-digit integer and multiplies by -@c{$10^{-p}$} -@cite{10^-p}. The resulting random numbers should be very clean, but note +@texline @math{10^{-p}}. +@infoline @expr{10^-p}. +The resulting random numbers should be very clean, but note that relatively small numbers will have few significant random digits. In other words, with a precision of 12, you will occasionally get -numbers on the order of @c{$10^{-9}$} -@cite{10^-9} or @c{$10^{-10}$} -@cite{10^-10}, but those numbers -will only have two or three random digits since they correspond to small -integers times @c{$10^{-12}$} -@cite{10^-12}. +numbers on the order of +@texline @math{10^{-9}} +@infoline @expr{10^-9} +or +@texline @math{10^{-10}}, +@infoline @expr{10^-10}, +but those numbers will only have two or three random digits since they +correspond to small integers times +@texline @math{10^{-12}}. +@infoline @expr{10^-12}. To create a random integer in the interval @samp{[0 .. @var{m})}, Calc counts the digits in @var{m}, creates a random integer with three @@ -18799,7 +19004,7 @@ the GCD of two fractions is defined by taking the GCD of the numerators, and the LCM of the denominators. This definition is consistent with the idea that @samp{a / gcd(a,x)} should yield an integer for any @samp{a} and @samp{x}. For other types of arguments, -the operation is left in symbolic form.@refill +the operation is left in symbolic form. @kindex k l @pindex calc-lcm @@ -18807,15 +19012,16 @@ the operation is left in symbolic form.@refill The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the Least Common Multiple of two integers or fractions. The product of the LCM and GCD of two numbers is equal to the product of the -numbers.@refill +numbers. @kindex k E @pindex calc-extended-gcd @tindex egcd The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes -the GCD of two integers @cite{x} and @cite{y} and returns a vector -@cite{[g, a, b]} where @c{$g = \gcd(x,y) = a x + b y$} -@cite{g = gcd(x,y) = a x + b y}. +the GCD of two integers @expr{x} and @expr{y} and returns a vector +@expr{[g, a, b]} where +@texline @math{g = \gcd(x,y) = a x + b y}. +@infoline @expr{g = gcd(x,y) = a x + b y}. @kindex ! @pindex calc-factorial @@ -18832,7 +19038,7 @@ the number is a non-integral real number, the generalized factorial is used, as defined by the Euler Gamma function. Please note that computation of large factorials can be slow; using floating-point format will help since fewer digits must be maintained. The same is true of many of -the commands in this section.@refill +the commands in this section. @kindex k d @pindex calc-double-factorial @@ -18843,29 +19049,30 @@ the commands in this section.@refill @tindex !! The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command computes the ``double factorial'' of an integer. For an even integer, -this is the product of even integers from 2 to @cite{N}. For an odd -integer, this is the product of odd integers from 3 to @cite{N}. If +this is the product of even integers from 2 to @expr{N}. For an odd +integer, this is the product of odd integers from 3 to @expr{N}. If the argument is an integer-valued float, the result is a floating-point approximation. This function is undefined for negative even integers. -The notation @cite{N!!} is also recognized for double factorials.@refill +The notation @expr{N!!} is also recognized for double factorials. @kindex k c @pindex calc-choose @tindex choose The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the -binomial coefficient @cite{N}-choose-@cite{M}, where @cite{M} is the number -on the top of the stack and @cite{N} is second-to-top. If both arguments +binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number +on the top of the stack and @expr{N} is second-to-top. If both arguments are integers, the result is an exact integer. Otherwise, the result is a floating-point approximation. The binomial coefficient is defined for all -real numbers by @c{$N! \over M! (N-M)!\,$} -@cite{N! / M! (N-M)!}. +real numbers by +@texline @math{N! \over M! (N-M)!\,}. +@infoline @expr{N! / M! (N-M)!}. @kindex H k c @pindex calc-perm @tindex perm @ifinfo The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the -number-of-permutations function @cite{N! / (N-M)!}. +number-of-permutations function @expr{N! / (N-M)!}. @end ifinfo @tex The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the @@ -18878,11 +19085,11 @@ number-of-perm\-utations function $N! \over (N-M)!\,$. @tindex bern The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command computes a given Bernoulli number. The value at the top of the stack -is a nonnegative integer @cite{n} that specifies which Bernoulli number +is a nonnegative integer @expr{n} that specifies which Bernoulli number is desired. The @kbd{H k b} command computes a Bernoulli polynomial, -taking @cite{n} from the second-to-top position and @cite{x} from the -top of the stack. If @cite{x} is a variable or formula the result is -a polynomial in @cite{x}; if @cite{x} is a number the result is a number. +taking @expr{n} from the second-to-top position and @expr{x} from the +top of the stack. If @expr{x} is a variable or formula the result is +a polynomial in @expr{x}; if @expr{x} is a number the result is a number. @kindex k e @kindex H k e @@ -18899,13 +19106,15 @@ functions. @tindex stir1 @tindex stir2 The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command -computes a Stirling number of the first kind@c{ $n \brack m$} -@asis{}, given two integers -@cite{n} and @cite{m} on the stack. The @kbd{H k s} [@code{stir2}] -command computes a Stirling number of the second kind@c{ $n \brace m$} -@asis{}. These are -the number of @cite{m}-cycle permutations of @cite{n} objects, and -the number of ways to partition @cite{n} objects into @cite{m} +computes a Stirling number of the first +@texline kind@tie{}@math{n \brack m}, +@infoline kind, +given two integers @expr{n} and @expr{m} on the stack. The @kbd{H k s} +[@code{stir2}] command computes a Stirling number of the second +@texline kind@tie{}@math{n \brace m}. +@infoline kind. +These are the number of @expr{m}-cycle permutations of @expr{n} objects, +and the number of ways to partition @expr{n} objects into @expr{m} non-empty sets, respectively. @kindex k p @@ -18933,7 +19142,7 @@ The normal @kbd{k p} command performs one iteration of the primality test. Pressing @kbd{k p} repeatedly for the same integer will perform additional iterations. Also, @kbd{k p} with a numeric prefix performs the specified number of iterations. There is also an algebraic function -@samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @cite{n} +@samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @expr{n} is (probably) prime and 0 if not. @kindex k f @@ -18946,8 +19155,8 @@ result is a vector of the prime factors in increasing order. For larger inputs, prime factors above 5000 may not be found, in which case the last number in the vector will be an unfactored integer greater than 25 million (with a warning message). For negative integers, the first -element of the list will be @i{-1}. For inputs @i{-1}, @i{0}, and -@i{1}, the result is a list of the same number. +element of the list will be @mathit{-1}. For inputs @mathit{-1}, @mathit{0}, and +@mathit{1}, the result is a list of the same number. @kindex k n @pindex calc-next-prime @@ -18980,17 +19189,20 @@ analogously finds the next prime less than a given number. @pindex calc-totient @tindex totient The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the -Euler ``totient'' function@c{ $\phi(n)$} -@asis{}, the number of integers less than @cite{n} which -are relatively prime to @cite{n}. +Euler ``totient'' +@texline function@tie{}@math{\phi(n)}, +@infoline function, +the number of integers less than @expr{n} which +are relatively prime to @expr{n}. @kindex k m @pindex calc-moebius @tindex moebius The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the -@c{M\"obius $\mu$} -@asis{Moebius ``mu''} function. If the input number is a product of @cite{k} -distinct factors, this is @cite{(-1)^k}. If the input number has any +@texline M@"obius @math{\mu} +@infoline Moebius ``mu'' +function. If the input number is a product of @expr{k} +distinct factors, this is @expr{(-1)^k}. If the input number has any duplicate factors (i.e., can be divided by the same prime more than once), the result is zero. @@ -19000,14 +19212,14 @@ the result is zero. @noindent The functions in this section compute various probability distributions. For continuous distributions, this is the integral of the probability -density function from @cite{x} to infinity. (These are the ``upper +density function from @expr{x} to infinity. (These are the ``upper tail'' distribution functions; there are also corresponding ``lower -tail'' functions which integrate from minus infinity to @cite{x}.) +tail'' functions which integrate from minus infinity to @expr{x}.) For discrete distributions, the upper tail function gives the sum -from @cite{x} to infinity; the lower tail function gives the sum -from minus infinity up to, but not including,@w{ }@cite{x}. +from @expr{x} to infinity; the lower tail function gives the sum +from minus infinity up to, but not including,@w{ }@expr{x}. -To integrate from @cite{x} to @cite{y}, just use the distribution +To integrate from @expr{x} to @expr{y}, just use the distribution function twice and subtract. For example, the probability that a Gaussian random variable with mean 2 and standard deviation 1 will lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)} @@ -19037,7 +19249,7 @@ order of the arguments in algebraic form differs from the order of arguments as found on the stack. (The random variable comes last on the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5 k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to -recover the original arguments but substitute a new value for @cite{x}.) +recover the original arguments but substitute a new value for @expr{x}.) @kindex k C @pindex calc-utpc @@ -19051,9 +19263,10 @@ recover the original arguments but substitute a new value for @cite{x}.) @end ignore @tindex ltpc The @samp{utpc(x,v)} function uses the chi-square distribution with -@c{$\nu$} -@cite{v} degrees of freedom. It is the probability that a model is -correct if its chi-square statistic is @cite{x}. +@texline @math{\nu} +@infoline @expr{v} +degrees of freedom. It is the probability that a model is +correct if its chi-square statistic is @expr{x}. @kindex k F @pindex calc-utpf @@ -19067,11 +19280,14 @@ correct if its chi-square statistic is @cite{x}. @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$} -@cite{v1} and @c{$\nu_2$} -@cite{v2} +various statistical tests. The parameters +@texline @math{\nu_1} +@infoline @expr{v1} +and +@texline @math{\nu_2} +@infoline @expr{v2} are the degrees of freedom in the numerator and denominator, -respectively, used in computing the statistic @cite{F}. +respectively, used in computing the statistic @expr{F}. @kindex k N @pindex calc-utpn @@ -19085,10 +19301,11 @@ respectively, used in computing the statistic @cite{F}. @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$} -@cite{s}. It is the -probability that such a normal-distributed random variable would -exceed @cite{x}. +with mean @expr{m} and standard deviation +@texline @math{\sigma}. +@infoline @expr{s}. +It is the probability that such a normal-distributed random variable +would exceed @expr{x}. @kindex k P @pindex calc-utpp @@ -19102,7 +19319,7 @@ exceed @cite{x}. @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 +mean @expr{x}. It is the probability that @expr{n} or more such Poisson random events will occur. @kindex k T @@ -19117,16 +19334,22 @@ Poisson random events will occur. @end ignore @tindex ltpt The @samp{utpt(t,v)} function uses the Student's ``t'' distribution -with @c{$\nu$} -@cite{v} degrees of freedom. It is the probability that a -t-distributed random variable will be greater than @cite{t}. -(Note: This computes the distribution function @c{$A(t|\nu)$} -@cite{A(t|v)} -where @c{$A(0|\nu) = 1$} -@cite{A(0|v) = 1} and @c{$A(\infty|\nu) \to 0$} -@cite{A(inf|v) -> 0}. The -@code{UTPT} operation on the HP-48 uses a different definition -which returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) +with +@texline @math{\nu} +@infoline @expr{v} +degrees of freedom. It is the probability that a +t-distributed random variable will be greater than @expr{t}. +(Note: This computes the distribution function +@texline @math{A(t|\nu)} +@infoline @expr{A(t|v)} +where +@texline @math{A(0|\nu) = 1} +@infoline @expr{A(0|v) = 1} +and +@texline @math{A(\infty|\nu) \to 0}. +@infoline @expr{A(inf|v) -> 0}. +The @code{UTPT} operation on the HP-48 uses a different definition which +returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) While Calc does not provide inverses of the probability distribution functions, the @kbd{a R} command can be used to solve for the inverse. @@ -19193,7 +19416,7 @@ Negative packing modes create other kinds of composite objects: @item -1 Two values are collected to build a complex number. For example, @kbd{5 @key{RET} 7 C-u -1 v p} creates the complex number -@cite{(5, 7)}. The result is always a rectangular complex +@expr{(5, 7)}. The result is always a rectangular complex number. The two input values must both be real numbers, i.e., integers, fractions, or floats. If they are not, Calc will instead build a formula like @samp{a + (0, 1) b}. (The @@ -19243,8 +19466,8 @@ integer, is the exponent. The result is the mantissa times ten to the power of the exponent. @item -12 -This is treated the same as @i{-11} by the @kbd{v p} command. -When unpacking, @i{-12} specifies that a floating-point mantissa +This is treated the same as @mathit{-11} by the @kbd{v p} command. +When unpacking, @mathit{-12} specifies that a floating-point mantissa is desired. @item -13 @@ -19283,8 +19506,9 @@ returned in the form @samp{[@w{[a, b, c]}, [d, e, f]]}. If any elements of the vector are negative, other kinds of packing are done at that level as described above. For example, @samp{[2, 3, -4]} takes 12 objects and creates a -@c{$2\times3$} -@asis{2x3} matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. +@texline @math{2\times3} +@infoline 2x3 +matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. Also, @samp{[-4, -10]} will convert four integers into an error form consisting of two fractions: @samp{a:b +/- c:d}. @@ -19320,18 +19544,18 @@ the result of @kbd{C-u -4 v u} will be the two vectors @samp{[a, c^2, d]} and @w{@samp{[b, 0, 7]}}. Note that the prefix argument can have an effect even when the input is -not a vector. For example, if the input is the number @i{-5}, then -@kbd{c-u -1 v u} yields @i{-5} and 0 (the components of @i{-5} +not a vector. For example, if the input is the number @mathit{-5}, then +@kbd{c-u -1 v u} yields @mathit{-5} and 0 (the components of @mathit{-5} when viewed as a rectangular complex number); @kbd{C-u -2 v u} yields 5 -and 180 (assuming degrees mode); and @kbd{C-u -10 v u} yields @i{-5} -and 1 (the numerator and denominator of @i{-5}, viewed as a rational +and 180 (assuming Degrees mode); and @kbd{C-u -10 v u} yields @mathit{-5} +and 1 (the numerator and denominator of @mathit{-5}, viewed as a rational number). Plain @kbd{v u} with this input would complain that the input is not a composite object. -Unpacking mode @i{-11} converts a float into an integer mantissa and +Unpacking mode @mathit{-11} converts a float into an integer mantissa and an integer exponent, where the mantissa is not divisible by 10 (except that 0.0 is represented by a mantissa and exponent of 0). -Unpacking mode @i{-12} converts a float into a floating-point mantissa +Unpacking mode @mathit{-12} converts a float into a floating-point mantissa and integer exponent, where the mantissa (for non-zero numbers) is guaranteed to lie in the range [1 .. 10). In both cases, the mantissa is shifted left or right (and the exponent adjusted @@ -19384,7 +19608,7 @@ number, you can use @samp{unpack(-10, @var{x})_1}. @noindent Vectors and matrices can be added, -subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.@refill +subtracted, multiplied, and divided; @pxref{Basic Arithmetic}. @kindex | @pindex calc-concat @@ -19430,11 +19654,12 @@ prefix, if specified, must match the size of the vector. If the value on the stack is a scalar, it is used for each element on the diagonal, and the prefix argument is required. -To build a constant square matrix, e.g., a @c{$3\times3$} -@asis{3x3} matrix filled with ones, -use @kbd{0 M-3 v d 1 +}, i.e., build a zero matrix first and then add a -constant value to that matrix. (Another alternative would be to use -@kbd{v b} and @kbd{v a}; see below.) +To build a constant square matrix, e.g., a +@texline @math{3\times3} +@infoline 3x3 +matrix filled with ones, use @kbd{0 M-3 v d 1 +}, i.e., build a zero +matrix first and then add a constant value to that matrix. (Another +alternative would be to use @kbd{v b} and @kbd{v a}; see below.) @kindex v i @pindex calc-ident @@ -19445,14 +19670,14 @@ where the diagonal element is always one. If no prefix argument is given, this command prompts for one. In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)}, -except that @cite{a} is required to be a scalar (non-vector) quantity. -If @cite{n} is omitted, @samp{idn(a)} represents @cite{a} times an +except that @expr{a} is required to be a scalar (non-vector) quantity. +If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an identity matrix of unknown size. Calc can operate algebraically on such generic identity matrices, and if one is combined with a matrix whose size is known, it is converted automatically to an identity matrix of a suitable matching size. The @kbd{v i} command with an argument of zero creates a generic identity matrix, @samp{idn(1)}. -Note that in dimensioned matrix mode (@pxref{Matrix Mode}), generic +Note that in dimensioned Matrix mode (@pxref{Matrix Mode}), generic identity matrices are immediately expanded to the current default dimensions. @@ -19463,7 +19688,7 @@ The @kbd{v x} (@code{calc-index}) [@code{index}] function builds a vector of consecutive integers from 1 to @var{n}, where @var{n} is the numeric prefix argument. If you do not provide a prefix argument, you will be prompted to enter a suitable number. If @var{n} is negative, the result -is a vector of negative integers from @var{n} to @i{-1}. +is a vector of negative integers from @var{n} to @mathit{-1}. With a prefix argument of just @kbd{C-u}, the @kbd{v x} command takes three values from the stack: @var{n}, @var{start}, and @var{incr} (with @@ -19569,10 +19794,10 @@ submatrix is returned. @tindex _ Subscript notation in algebraic formulas (@samp{a_b}) stands for the Calc function @code{subscr}, which is synonymous with @code{mrow}. -Thus, @samp{[x, y, z]_k} produces @cite{x}, @cite{y}, or @cite{z} if -@cite{k} is one, two, or three, respectively. A double subscript +Thus, @samp{[x, y, z]_k} produces @expr{x}, @expr{y}, or @expr{z} if +@expr{k} is one, two, or three, respectively. A double subscript (@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will -access the element at row @cite{i}, column @cite{j} of a matrix. +access the element at row @expr{i}, column @expr{j} of a matrix. The @kbd{a _} (@code{calc-subscript}) command creates a subscript formula @samp{a_b} out of two stack entries. (It is on the @kbd{a} ``algebra'' prefix because subscripted variables are often used @@ -19599,13 +19824,13 @@ the analogous operation on columns of a matrix. Given a plain vector it extracts (or removes) one element, just like @kbd{v r}. If the index in @kbd{C-u v c} is an interval or vector and the argument is a matrix, the result is a submatrix with only the specified columns -retained (and possibly permuted in the case of a vector index).@refill +retained (and possibly permuted in the case of a vector index). To extract a matrix element at a given row and column, use @kbd{v r} to extract the row as a vector, then @kbd{v c} to extract the column element from that vector. In algebraic formulas, it is often more convenient to -use subscript notation: @samp{m_i_j} gives row @cite{i}, column @cite{j} -of matrix @cite{m}. +use subscript notation: @samp{m_i_j} gives row @expr{i}, column @expr{j} +of matrix @expr{m}. @kindex v s @pindex calc-subvector @@ -19648,15 +19873,17 @@ vectors one element at a time. The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the length of a vector. The length of a non-vector is considered to be zero. Note that matrices are just vectors of vectors for the purposes of this -command.@refill +command. @kindex H v l @tindex mdims With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector of the dimensions of a vector, matrix, or higher-order object. For example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since -its argument is a @c{$2\times3$} -@asis{2x3} matrix. +its argument is a +@texline @math{2\times3} +@infoline 2x3 +matrix. @kindex v f @pindex calc-vector-find @@ -19685,14 +19912,18 @@ If the number of columns does not evenly divide the number of elements in the vector, the last row will be short and the result will not be suitable for use as a matrix. For example, with the matrix @samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces -@samp{[[1, 2, 3, 4]]} (a @c{$1\times4$} -@asis{1x4} matrix), @kbd{v a 1} produces -@samp{[[1], [2], [3], [4]]} (a @c{$4\times1$} -@asis{4x1} matrix), @kbd{v a 2} produces -@samp{[[1, 2], [3, 4]]} (the original @c{$2\times2$} -@asis{2x2} matrix), @w{@kbd{v a 3}} produces -@samp{[[1, 2, 3], [4]]} (not a matrix), and @kbd{v a 0} produces -the flattened list @samp{[1, 2, @w{3, 4}]}. +@samp{[[1, 2, 3, 4]]} (a +@texline @math{1\times4} +@infoline 1x4 +matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a +@texline @math{4\times1} +@infoline 4x1 +matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original +@texline @math{2\times2} +@infoline 2x2 +matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a +matrix), and @kbd{v a 0} produces the flattened list +@samp{[1, 2, @w{3, 4}]}. @cindex Sorting data @kindex V S @@ -19848,7 +20079,7 @@ matrix actually uses LU-decomposition for greater accuracy and speed.) The following functions are applied element-wise if their arguments are vectors or matrices: @code{change-sign}, @code{conj}, @code{arg}, @code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean}, -@code{float}, @code{frac}. @xref{Function Index}.@refill +@code{float}, @code{frac}. @xref{Function Index}. @kindex V J @pindex calc-conj-transpose @@ -19870,7 +20101,7 @@ Frobenius norm of a vector or matrix argument. This is the square root of the sum of the squares of the absolute values of the elements of the vector or matrix. If the vector is interpreted as a point in two- or three-dimensional space, this is the distance -from that point to the origin.@refill +from that point to the origin. @kindex v n @pindex calc-rnorm @@ -19889,7 +20120,7 @@ The @kbd{V N} (@code{calc-cnorm}) [@code{cnorm}] command computes the column norm, or one-norm, of a vector or matrix. For a plain vector, this is the sum of the absolute values of the elements. For a matrix, this is the maximum of the column-absolute-value-sums. -General @cite{k}-norms for @cite{k} other than one or infinity are +General @expr{k}-norms for @expr{k} other than one or infinity are not provided. @kindex V C @@ -19915,8 +20146,8 @@ that once an inverse (or determinant) of a particular matrix has been computed, the inverse and determinant of the matrix can be recomputed quickly in the future. -If the argument to @kbd{&} is a plain number @cite{x}, this -command simply computes @cite{1/x}. This is okay, because the +If the argument to @kbd{&} is a plain number @expr{x}, this +command simply computes @expr{1/x}. This is okay, because the @samp{/} operator also does a matrix inversion when dividing one by a matrix. @@ -19958,7 +20189,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 @@ -19974,8 +20205,8 @@ The result is always a vector, except that if the set consists of a single interval, the interval itself is returned instead. @xref{Logical Operations}, for the @code{in} function which tests if -a certain value is a member of a given set. To test if the set @cite{A} -is a subset of the set @cite{B}, use @samp{vdiff(A, B) = []}. +a certain value is a member of a given set. To test if the set @expr{A} +is a subset of the set @expr{B}, use @samp{vdiff(A, B) = []}. @kindex V + @pindex calc-remove-duplicates @@ -20007,20 +20238,23 @@ and only if it is in both of the input sets. Thus if the input sets are disjoint, i.e., if they share no common elements, the result will be the empty vector @samp{[]}. Note that the characters @kbd{V} and @kbd{^} were chosen to be close to the conventional mathematical -notation for set union@c{ ($A \cup B$)} -@asis{} and intersection@c{ ($A \cap B$)} -@asis{}. +notation for set +@texline union@tie{}(@math{A \cup B}) +@infoline union +and +@texline intersection@tie{}(@math{A \cap B}). +@infoline intersection. @kindex V - @pindex calc-set-difference @tindex vdiff The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes the difference between two sets. An object is in the difference -@cite{A - B} if and only if it is in @cite{A} but not in @cite{B}. +@expr{A - B} if and only if it is in @expr{A} but not in @expr{B}. Thus subtracting @samp{[y,z]} from a set will remove the elements @samp{y} and @samp{z} if they are present. You can also think of this -as a general @dfn{set complement} operator; if @cite{A} is the set of -all possible values, then @cite{A - B} is the ``complement'' of @cite{B}. +as a general @dfn{set complement} operator; if @expr{A} is the set of +all possible values, then @expr{A - B} is the ``complement'' of @expr{B}. Obviously this is only practical if the set of all possible values in your problem is small enough to list in a Calc vector (or simple enough to express in a few intervals). @@ -20116,8 +20350,9 @@ the same set. The set may include positive infinity, but must not include any negative numbers. The input is interpreted as a set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware that a simple input like @samp{[100]} can result in a huge integer -representation (@c{$2^{100}$} -@cite{2^100}, a 31-digit integer, in this case). +representation +@texline (@math{2^{100}}, a 31-digit integer, in this case). +@infoline (@expr{2^100}, a 31-digit integer, in this case). @node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions @section Statistical Operations on Vectors @@ -20205,7 +20440,7 @@ computes the sum of the data values. The @kbd{u *} (@code{calc-vector-prod}) [@code{vprod}] command computes the product of the data values. If the input is a single flat vector, these are the same as @kbd{V R +} and @kbd{V R *} -(@pxref{Reducing and Mapping}).@refill +(@pxref{Reducing and Mapping}). @kindex u X @kindex u N @@ -20227,21 +20462,25 @@ plus or minus infinity. @cindex Mean of data values The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command computes the average (arithmetic mean) of the data values. -If the inputs are error forms @c{$x$ @code{+/-} $\sigma$} -@samp{x +/- s}, this is the weighted -mean of the @cite{x} values with weights @c{$1 / \sigma^2$} -@cite{1 / s^2}. +If the inputs are error forms +@texline @math{x \pm \sigma}, +@infoline @samp{x +/- s}, +this is the weighted mean of the @expr{x} values with weights +@texline @math{1 /\sigma^2}. +@infoline @expr{1 / s^2}. @tex \turnoffactive $$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over \displaystyle \sum { 1 \over \sigma_i^2 } } $$ @end tex If the inputs are not error forms, this is simply the sum of the -values divided by the count of the values.@refill +values divided by the count of the values. Note that a plain number can be considered an error form with -error @c{$\sigma = 0$} -@cite{s = 0}. If the input to @kbd{u M} is a mixture of +error +@texline @math{\sigma = 0}. +@infoline @expr{s = 0}. +If the input to @kbd{u M} is a mixture of plain numbers and error forms, the result is the mean of the plain numbers, ignoring all values with non-zero errors. (By the above definitions it's clear that a plain number effectively @@ -20250,7 +20489,7 @@ weight is completely negligible.) This function also works for distributions (error forms or 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 +@expr{a}. The mean of an interval is the mean of the minimum and maximum values of the interval. @kindex I u M @@ -20272,7 +20511,7 @@ numbers, the error is equal to the standard deviation of the values divided by the square root of the number of values. (This works out to be equivalent to calculating the standard deviation and then assuming each value's error is equal to this standard -deviation.)@refill +deviation.) @tex \turnoffactive $$ \sigma_\mu^2 = {\sigma^2 \over N} $$ @@ -20347,13 +20586,14 @@ for a vector of numbers simply by using the @kbd{A} command. @cindex Standard deviation @cindex Sample statistics The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command -computes the standard deviation@c{ $\sigma$} -@asis{} of the data values. If the -values are error forms, the errors are used as weights just -as for @kbd{u M}. This is the @emph{sample} standard deviation, -whose value is the square root of the sum of the squares of the -differences between the values and the mean of the @cite{N} values, -divided by @cite{N-1}. +computes the standard +@texline deviation@tie{}@math{\sigma} +@infoline deviation +of the data values. If the values are error forms, the errors are used +as weights just as for @kbd{u M}. This is the @emph{sample} standard +deviation, whose value is the square root of the sum of the squares of +the differences between the values and the mean of the @expr{N} values, +divided by @expr{N-1}. @tex \turnoffactive $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$ @@ -20362,10 +20602,11 @@ $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$ This function also applies to distributions. The standard deviation of a single error form is simply the error part. The standard deviation of a continuous interval happens to equal the difference between the -limits, divided by @c{$\sqrt{12}$} -@cite{sqrt(12)}. The standard deviation of an -integer interval is the same as the standard deviation of a vector -of those integers. +limits, divided by +@texline @math{\sqrt{12}}. +@infoline @expr{sqrt(12)}. +The standard deviation of an integer interval is the same as the +standard deviation of a vector of those integers. @kindex I u S @pindex calc-vector-pop-sdev @@ -20374,7 +20615,7 @@ of those integers. The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}] command computes the @emph{population} standard deviation. It is defined by the same formula as above but dividing -by @cite{N} instead of by @cite{N-1}. The population standard +by @expr{N} instead of by @expr{N-1}. The population standard deviation is used when the input represents the entire set of data values in the distribution; the sample standard deviation is used when the input represents a sample of the set of all @@ -20399,8 +20640,10 @@ population standard deviation of the equivalent vector of integers. The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}] commands compute the variance of the data values. The variance -is the square@c{ $\sigma^2$} -@asis{} of the standard deviation, i.e., the sum of the +is the +@texline square@tie{}@math{\sigma^2} +@infoline square +of the standard deviation, i.e., the sum of the squares of the deviations of the data values from the mean. (This definition also applies when the argument is a distribution.) @@ -20421,10 +20664,11 @@ The functions in this section take two arguments, which must be vectors of equal size. The vectors are each flattened in the same way as by the single-variable statistical functions. Given a numeric prefix argument of 1, these functions instead take one object from -the stack, which must be an @c{$N\times2$} -@asis{Nx2} matrix of data values. Once -again, variable names can be used in place of actual vectors and -matrices. +the stack, which must be an +@texline @math{N\times2} +@infoline Nx2 +matrix of data values. Once again, variable names can be used in place +of actual vectors and matrices. @kindex u C @pindex calc-vector-covariance @@ -20435,7 +20679,7 @@ computes the sample covariance of two vectors. The covariance of vectors @var{x} and @var{y} is the sum of the products of the differences between the elements of @var{x} and the mean of @var{x} times the differences between the corresponding elements of @var{y} -and the mean of @var{y}, all divided by @cite{N-1}. Note that +and the mean of @var{y}, all divided by @expr{N-1}. Note that the variance of a vector is just the covariance of the vector with itself. Once again, if the inputs are error forms the errors are used as weight factors. If both @var{x} and @var{y} @@ -20457,8 +20701,8 @@ $$ @tindex vpcov The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}] command computes the population covariance, which is the same as the -sample covariance computed by @kbd{u C} except dividing by @cite{N} -instead of @cite{N-1}. +sample covariance computed by @kbd{u C} except dividing by @expr{N} +instead of @expr{N-1}. @kindex H u C @pindex calc-vector-correlation @@ -20636,7 +20880,7 @@ and is either a variable whose name is the same as the function name, or a nameless function like @samp{<#^3+1>}. Operators that are normally 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 +@code{vconcat}. @ignore @starindex @@ -20673,24 +20917,26 @@ is duplicated for each element of the other vector. For example, With the 2 listed first, it would have computed a vector of powers of two. Mapping a user-defined function pops as many arguments from the stack as the function requires. If you give an undefined name, you will -be prompted for the number of arguments to use.@refill +be prompted for the number of arguments to use. If any argument to @kbd{V M} is a matrix, the operator is normally mapped across all elements of the matrix. For example, given the matrix -@cite{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to -produce another @c{$3\times2$} -@asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}. +@expr{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to +produce another +@texline @math{3\times2} +@infoline 3x2 +matrix, @expr{[[1, 2, 3], [4, 5, 6]]}. @tindex mapr The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the operator prompt) maps by rows instead. For example, @kbd{V M _ A} views the above matrix as a vector of two 3-element row vectors. It produces a new vector which contains the absolute values of those row vectors, -namely @cite{[3.74, 8.77]}. (Recall, the absolute value of a vector is +namely @expr{[3.74, 8.77]}. (Recall, the absolute value of a vector is defined as the square root of the sum of the squares of the elements.) Some operators accept vectors and return new vectors; for example, @kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row -of the matrix to get a new matrix, @cite{[[3, -2, 1], [-6, 5, -4]]}. +of the matrix to get a new matrix, @expr{[[3, -2, 1], [-6, 5, -4]]}. Sometimes a vector of vectors (representing, say, strings, sets, or lists) happens to look like a matrix. If so, remember to use @kbd{V M _} if you @@ -20703,7 +20949,7 @@ transposes the input matrix, maps by rows, and then, if the result is a matrix, transposes again. For example, @kbd{V M : A} takes the absolute values of the three columns of the matrix, treating each as a 2-vector, and @kbd{V M : v v} reverses the columns to get the matrix -@cite{[[-4, 5, -6], [1, -2, 3]]}. +@expr{[[-4, 5, -6], [1, -2, 3]]}. (The symbols @kbd{_} and @kbd{:} were chosen because they had row-like and column-like appearances, and were not already taken by useful @@ -20794,13 +21040,13 @@ vector @samp{[a - b + c - d, b - c + d, c - d, d]}. @tindex reduced @tindex rreduced As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For -example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will -compute @cite{a + b + c + d + e + f}. You can type @kbd{V R _} or +example, given the matrix @expr{[[a, b, c], [d, e, f]]}, @kbd{V R +} will +compute @expr{a + b + c + d + e + f}. You can type @kbd{V R _} or @kbd{V R :} to modify this behavior. The @kbd{V R _} [@code{reducea}] command reduces ``across'' the matrix; it reduces each row of the matrix as a vector, then collects the results. Thus @kbd{V R _ +} of this -matrix would produce @cite{[a + b + c, d + e + f]}. Similarly, @kbd{V R :} -[@code{reduced}] reduces down; @kbd{V R : +} would produce @cite{[a + d, +matrix would produce @expr{[a + b + c, d + e + f]}. Similarly, @kbd{V R :} +[@code{reduced}] reduces down; @kbd{V R : +} would produce @expr{[a + d, b + e, c + f]}. @tindex reducer @@ -20957,7 +21203,7 @@ influenced by the @kbd{d O} (@code{calc-flat-language}) mode; The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >} (@code{calc-matrix-right-justify}), and @w{@kbd{v =}} (@code{calc-matrix-center-justify}) control whether matrix elements -are justified to the left, right, or center of their columns.@refill +are justified to the left, right, or center of their columns. @kindex V [ @pindex calc-vector-brackets @@ -20974,7 +21220,7 @@ be used in preparation for yanking a matrix into a buffer running Mathematica. (In fact, the Mathematica language mode uses this mode; @pxref{Mathematica Language Mode}.) Note that, regardless of the display mode, either brackets or braces may be used to enter vectors, -and parentheses may never be used for this purpose.@refill +and parentheses may never be used for this purpose. @kindex V ] @pindex calc-matrix-brackets @@ -21027,7 +21273,7 @@ the others are useful for display only. @kindex V , @pindex calc-vector-commas The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and -off in vector and matrix display.@refill +off in vector and matrix display. In vectors of length one, and in all vectors when commas have been turned off, Calc adds extra parentheses around formulas that might @@ -21085,15 +21331,15 @@ commands use the @kbd{j} (for ``just a letter that wasn't used for anything else'') prefix. @xref{Editing Stack Entries}, to see how to manipulate formulas -using regular Emacs editing commands.@refill +using regular Emacs editing commands. When doing algebraic work, you may find several of the Calculator's -modes to be helpful, including algebraic-simplification mode (@kbd{m A}) -or no-simplification mode (@kbd{m O}), -algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and -symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions -of these modes. You may also wish to select ``big'' display mode (@kbd{d B}). -@xref{Normal Language Modes}.@refill +modes to be helpful, including Algebraic Simplification mode (@kbd{m A}) +or No-Simplification mode (@kbd{m O}), +Algebraic entry mode (@kbd{m a}), Fraction mode (@kbd{m f}), and +Symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions +of these modes. You may also wish to select Big display mode (@kbd{d B}). +@xref{Normal Language Modes}. @menu * Selecting Subformulas:: @@ -21146,7 +21392,7 @@ sub-formula, and press @w{@kbd{j s}} (@code{calc-select-here}). Calc will highlight the smallest portion of the formula that contains that character. By default the sub-formula is highlighted by blanking out 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. +display mode but is perhaps easiest in Big mode (@kbd{d B}). Suppose you enter the following formula: @smallexample @@ -21176,7 +21422,7 @@ to Every character not part of the sub-formula @samp{b} has been changed to a dot. The @samp{*} next to the line number is to remind you that the formula has a portion of it selected. (In this case, it's very -obvious, but it might not always be. If Embedded Mode is enabled, +obvious, but it might not always be. If Embedded mode is enabled, the word @samp{Sel} also appears in the mode line because the stack may not be visible. @pxref{Embedded Mode}.) @@ -21195,7 +21441,7 @@ the right of the @samp{b}, the selection would have been: @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 @@ -21251,7 +21497,7 @@ has a selection they have no effect. This is analogous to the behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection}; @pxref{Selections with Rewrite Rules}) and is mainly intended to be used in keyboard macros that implement your own selection-oriented -commands.@refill +commands. Selection of sub-formulas normally treats associative terms like @samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula. @@ -21349,7 +21595,7 @@ If there is no current selection, @kbd{j 1} through @kbd{j 9} select the @var{n}th top-level sub-formula. (In other words, they act as if the entire stack entry were selected first.) To select the @var{n}th sub-formula where @var{n} is greater than nine, you must instead invoke -@w{@kbd{j 1}} with @var{n} as a numeric prefix argument.@refill +@w{@kbd{j 1}} with @var{n} as a numeric prefix argument. @kindex j n @kindex j p @@ -21531,7 +21777,7 @@ the command will abort with an error message. Operations on sub-formulas sometimes leave the formula as a whole 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 +(@code{calc-change-sign}). @smallexample @group @@ -21629,7 +21875,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 @kbd{M-# M-#} +displays and edits the stored value of a variable. Press @kbd{C-c C-c} 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! @@ -21826,17 +22072,17 @@ but which also substitutes stored values for variables in the formula. Use @kbd{a v} if you want the variables to ignore their stored values. If you give a numeric prefix argument of 2 to @kbd{a v}, it simplifies -as if in algebraic simplification mode. This is equivalent to typing +as if in Algebraic Simplification mode. This is equivalent to typing @kbd{a s}; @pxref{Simplifying Formulas}. If you give a numeric prefix -of 3 or more, it uses extended simplification mode (@kbd{a e}). +of 3 or more, it uses Extended Simplification mode (@kbd{a e}). -If you give a negative prefix argument @i{-1}, @i{-2}, or @i{-3}, +If you give a negative prefix argument @mathit{-1}, @mathit{-2}, or @mathit{-3}, it simplifies in the corresponding mode but only works on the top-level function call of the formula. For example, @samp{(2 + 3) * (2 + 3)} will simplify to @samp{(2 + 3)^2}, without simplifying the sub-formulas @samp{2 + 3}. As another example, typing @kbd{V R +} to sum the vector @samp{[1, 2, 3, 4]} produces the formula @samp{reduce(add, [1, 2, 3, 4])} -in no-simplify mode. Using @kbd{a v} will evaluate this all the way to +in No-Simplify mode. Using @kbd{a v} will evaluate this all the way to 10; using @kbd{C-u - a v} will evaluate it only to @samp{1 + 2 + 3 + 4}. (@xref{Reducing and Mapping}.) @@ -21844,7 +22090,7 @@ in no-simplify mode. Using @kbd{a v} will evaluate this all the way to @tindex evalvn The @kbd{=} command corresponds to the @code{evalv} function, and the related @kbd{N} command, which is like @kbd{=} but temporarily -disables symbolic (@kbd{m s}) mode during the evaluation, corresponds +disables Symbolic mode (@kbd{m s}) during the evaluation, corresponds to the @code{evalvn} function. (These commands interpret their prefix arguments differently than @kbd{a v}; @kbd{=} treats the prefix as the number of stack elements to evaluate at once, and @kbd{N} treats @@ -21888,7 +22134,7 @@ a given function or operator to one or more equations. It is analogous to @kbd{V M}, which operates on vectors instead of equations. @pxref{Reducing and Mapping}. For example, @kbd{a M S} changes @samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with -@samp{x = y+1} and @cite{6} on the stack produces @samp{x+6 = y+7}. +@samp{x = y+1} and @expr{6} on the stack produces @samp{x+6 = y+7}. With two equations on the stack, @kbd{a M +} would add the lefthand sides together and the righthand sides together to get the two respective sides of a new equation. @@ -21937,7 +22183,7 @@ in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces Note that this is a purely structural substitution; the lone @samp{x} and the @samp{sin(2 x)} stayed the same because they did not look like @samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for -doing substitutions.@refill +doing substitutions. The @kbd{a b} command normally prompts for two formulas, the old one and the new one. If you enter a blank line for the first @@ -22004,26 +22250,27 @@ simplifications'' occur. @cindex Default simplifications This section describes the ``default simplifications,'' those which are normally applied to all results. For example, if you enter the variable -@cite{x} on the stack twice and push @kbd{+}, Calc's default -simplifications automatically change @cite{x + x} to @cite{2 x}. +@expr{x} on the stack twice and push @kbd{+}, Calc's default +simplifications automatically change @expr{x + x} to @expr{2 x}. The @kbd{m O} command turns off the default simplifications, so that -@cite{x + x} will remain in this form unless you give an explicit +@expr{x + x} will remain in this form unless you give an explicit ``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic Manipulation}. The @kbd{m D} command turns the default simplifications back on. The most basic default simplification is the evaluation of functions. -For example, @cite{2 + 3} is evaluated to @cite{5}, and @cite{@t{sqrt}(9)} -is evaluated to @cite{3}. Evaluation does not occur if the arguments -to a function are somehow of the wrong type (@cite{@t{tan}([2,3,4])}, -range (@cite{@t{tan}(90)}), or number (@cite{@t{tan}(3,5)}), or if the -function name is not recognized (@cite{@t{f}(5)}), or if ``symbolic'' -mode (@pxref{Symbolic Mode}) prevents evaluation (@cite{@t{sqrt}(2)}). +For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@t{sqrt}(9)} +is evaluated to @expr{3}. Evaluation does not occur if the arguments +to a function are somehow of the wrong type @expr{@t{tan}([2,3,4])}), +range (@expr{@t{tan}(90)}), or number (@expr{@t{tan}(3,5)}), +or if the function name is not recognized (@expr{@t{f}(5)}), or if +Symbolic mode (@pxref{Symbolic Mode}) prevents evaluation +(@expr{@t{sqrt}(2)}). Calc simplifies (evaluates) the arguments to a function before it -simplifies the function itself. Thus @cite{@t{sqrt}(5+4)} is -simplified to @cite{@t{sqrt}(9)} before the @code{sqrt} function +simplifies the function itself. Thus @expr{@t{sqrt}(5+4)} is +simplified to @expr{@t{sqrt}(9)} before the @code{sqrt} function itself is applied. There are very few exceptions to this rule: @code{quote}, @code{lambda}, and @code{condition} (the @code{::} operator) do not evaluate their arguments, @code{if} (the @code{? :} @@ -22062,9 +22309,9 @@ And now, on with the default simplifications: Arithmetic operators like @kbd{+} and @kbd{*} always take two arguments in Calc's internal form. Sums and products of three or more terms are arranged by the associative law of algebra into -a left-associative form for sums, @cite{((a + b) + c) + d}, and -a right-associative form for products, @cite{a * (b * (c * d))}. -Formulas like @cite{(a + b) + (c + d)} are rearranged to +a left-associative form for sums, @expr{((a + b) + c) + d}, and +a right-associative form for products, @expr{a * (b * (c * d))}. +Formulas like @expr{(a + b) + (c + d)} are rearranged to left-associative form, though this rarely matters since Calc's algebra commands are designed to hide the inner structure of sums and products as much as possible. Sums and products in @@ -22072,199 +22319,213 @@ their proper associative form will be written without parentheses in the examples below. Sums and products are @emph{not} rearranged according to the -commutative law (@cite{a + b} to @cite{b + a}) except in a few +commutative law (@expr{a + b} to @expr{b + a}) except in a few special cases described below. Some algebra programs always rearrange terms into a canonical order, which enables them to -see that @cite{a b + b a} can be simplified to @cite{2 a b}. +see that @expr{a b + b a} can be simplified to @expr{2 a b}. Calc assumes you have put the terms into the order you want and generally leaves that order alone, with the consequence that formulas like the above will only be simplified if you explicitly give the @kbd{a s} command. @xref{Algebraic Simplifications}. -Differences @cite{a - b} are treated like sums @cite{a + (-b)} +Differences @expr{a - b} are treated like sums @expr{a + (-b)} for purposes of simplification; one of the default simplifications -is to rewrite @cite{a + (-b)} or @cite{(-b) + a}, where @cite{-b} -represents a ``negative-looking'' term, into @cite{a - b} form. +is to rewrite @expr{a + (-b)} or @expr{(-b) + a}, where @expr{-b} +represents a ``negative-looking'' term, into @expr{a - b} form. ``Negative-looking'' means negative numbers, negated formulas like -@cite{-x}, and products or quotients in which either term is +@expr{-x}, and products or quotients in which either term is negative-looking. -Other simplifications involving negation are @cite{-(-x)} to @cite{x}; -@cite{-(a b)} or @cite{-(a/b)} where either @cite{a} or @cite{b} is +Other simplifications involving negation are @expr{-(-x)} to @expr{x}; +@expr{-(a b)} or @expr{-(a/b)} where either @expr{a} or @expr{b} is negative-looking, simplified by negating that term, or else where -@cite{a} or @cite{b} is any number, by negating that number; -@cite{-(a + b)} to @cite{-a - b}, and @cite{-(b - a)} to @cite{a - b}. -(This, and rewriting @cite{(-b) + a} to @cite{a - b}, are the only +@expr{a} or @expr{b} is any number, by negating that number; +@expr{-(a + b)} to @expr{-a - b}, and @expr{-(b - a)} to @expr{a - b}. +(This, and rewriting @expr{(-b) + a} to @expr{a - b}, are the only cases where the order of terms in a sum is changed by the default simplifications.) The distributive law is used to simplify sums in some cases: -@cite{a x + b x} to @cite{(a + b) x}, where @cite{a} represents -a number or an implicit 1 or @i{-1} (as in @cite{x} or @cite{-x}) -and similarly for @cite{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or +@expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents +a number or an implicit 1 or @mathit{-1} (as in @expr{x} or @expr{-x}) +and similarly for @expr{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or @kbd{j M} commands to merge sums with non-numeric coefficients using the distributive law. The distributive law is only used for sums of two terms, or -for adjacent terms in a larger sum. Thus @cite{a + b + b + c} -is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b} +for adjacent terms in a larger sum. Thus @expr{a + b + b + c} +is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b} is not simplified. The reason is that comparing all terms of a sum with one another would require time proportional to the square of the number of terms; Calc relegates potentially slow operations like this to commands that have to be invoked explicitly, like @kbd{a s}. -Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}. -A consequence of the above rules is that @cite{0 - a} is simplified -to @cite{-a}. +Finally, @expr{a + 0} and @expr{0 + a} are simplified to @expr{a}. +A consequence of the above rules is that @expr{0 - a} is simplified +to @expr{-a}. @tex \bigskip @end tex -The products @cite{1 a} and @cite{a 1} are simplified to @cite{a}; -@cite{(-1) a} and @cite{a (-1)} are simplified to @cite{-a}; -@cite{0 a} and @cite{a 0} are simplified to @cite{0}, except that -in matrix mode where @cite{a} is not provably scalar the result -is the generic zero matrix @samp{idn(0)}, and that if @cite{a} is +The products @expr{1 a} and @expr{a 1} are simplified to @expr{a}; +@expr{(-1) a} and @expr{a (-1)} are simplified to @expr{-a}; +@expr{0 a} and @expr{a 0} are simplified to @expr{0}, except that +in Matrix mode where @expr{a} is not provably scalar the result +is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is infinite the result is @samp{nan}. -Also, @cite{(-a) b} and @cite{a (-b)} are simplified to @cite{-(a b)}, +Also, @expr{(-a) b} and @expr{a (-b)} are simplified to @expr{-(a b)}, where this occurs for negated formulas but not for regular negative numbers. Products are commuted only to move numbers to the front: -@cite{a b 2} is commuted to @cite{2 a b}. +@expr{a b 2} is commuted to @expr{2 a b}. -The product @cite{a (b + c)} is distributed over the sum only if -@cite{a} and at least one of @cite{b} and @cite{c} are numbers: -@cite{2 (x + 3)} goes to @cite{2 x + 6}. The formula -@cite{(-a) (b - c)}, where @cite{-a} is a negative number, is -rewritten to @cite{a (c - b)}. +The product @expr{a (b + c)} is distributed over the sum only if +@expr{a} and at least one of @expr{b} and @expr{c} are numbers: +@expr{2 (x + 3)} goes to @expr{2 x + 6}. The formula +@expr{(-a) (b - c)}, where @expr{-a} is a negative number, is +rewritten to @expr{a (c - b)}. The distributive law of products and powers is used for adjacent -terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$} -@cite{x^(a+b)} -where @cite{a} is a number, or an implicit 1 (as in @cite{x}), -or the implicit one-half of @cite{@t{sqrt}(x)}, and similarly for -@cite{b}. The result is written using @samp{sqrt} or @samp{1/sqrt} -if the sum of the powers is @cite{1/2} or @cite{-1/2}, respectively. +terms of the product: @expr{x^a x^b} goes to +@texline @math{x^{a+b}} +@infoline @expr{x^(a+b)} +where @expr{a} is a number, or an implicit 1 (as in @expr{x}), +or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for +@expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt} +if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively. If the sum of the powers is zero, the product is simplified to -@cite{1} or to @samp{idn(1)} if matrix mode is enabled. +@expr{1} or to @samp{idn(1)} if Matrix mode is enabled. The product of a negative power times anything but another negative -power is changed to use division: @c{$x^{-2} y$} -@cite{x^(-2) y} goes to @cite{y / x^2} unless matrix mode is -in effect and neither @cite{x} nor @cite{y} are scalar (in which +power is changed to use division: +@texline @math{x^{-2} y} +@infoline @expr{x^(-2) y} +goes to @expr{y / x^2} unless Matrix mode is +in effect and neither @expr{x} nor @expr{y} are scalar (in which case it is considered unsafe to rearrange the order of the terms). -Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also -@cite{(a/b) c} is changed to @cite{(a c)/b} unless in matrix mode. +Finally, @expr{a (b/c)} is rewritten to @expr{(a b)/c}, and also +@expr{(a/b) c} is changed to @expr{(a c)/b} unless in Matrix mode. @tex \bigskip @end tex Simplifications for quotients are analogous to those for products. -The quotient @cite{0 / x} is simplified to @cite{0}, with the same -exceptions that were noted for @cite{0 x}. Likewise, @cite{x / 1} -and @cite{x / (-1)} are simplified to @cite{x} and @cite{-x}, +The quotient @expr{0 / x} is simplified to @expr{0}, with the same +exceptions that were noted for @expr{0 x}. Likewise, @expr{x / 1} +and @expr{x / (-1)} are simplified to @expr{x} and @expr{-x}, respectively. -The quotient @cite{x / 0} is left unsimplified or changed to an +The quotient @expr{x / 0} is left unsimplified or changed to an infinite quantity, as directed by the current infinite mode. @xref{Infinite Mode}. -The expression @c{$a / b^{-c}$} -@cite{a / b^(-c)} is changed to @cite{a b^c}, -where @cite{-c} is any negative-looking power. Also, @cite{1 / b^c} -is changed to @c{$b^{-c}$} -@cite{b^(-c)} for any power @cite{c}. - -Also, @cite{(-a) / b} and @cite{a / (-b)} go to @cite{-(a/b)}; -@cite{(a/b) / c} goes to @cite{a / (b c)}; and @cite{a / (b/c)} -goes to @cite{(a c) / b} unless matrix mode prevents this -rearrangement. Similarly, @cite{a / (b:c)} is simplified to -@cite{(c:b) a} for any fraction @cite{b:c}. - -The distributive law is applied to @cite{(a + b) / c} only if -@cite{c} and at least one of @cite{a} and @cite{b} are numbers. +The expression +@texline @math{a / b^{-c}} +@infoline @expr{a / b^(-c)} +is changed to @expr{a b^c}, where @expr{-c} is any negative-looking +power. Also, @expr{1 / b^c} is changed to +@texline @math{b^{-c}} +@infoline @expr{b^(-c)} +for any power @expr{c}. + +Also, @expr{(-a) / b} and @expr{a / (-b)} go to @expr{-(a/b)}; +@expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)} +goes to @expr{(a c) / b} unless Matrix mode prevents this +rearrangement. Similarly, @expr{a / (b:c)} is simplified to +@expr{(c:b) a} for any fraction @expr{b:c}. + +The distributive law is applied to @expr{(a + b) / c} only if +@expr{c} and at least one of @expr{a} and @expr{b} are numbers. Quotients of powers and square roots are distributed just as described for multiplication. Quotients of products cancel only in the leading terms of the -numerator and denominator. In other words, @cite{a x b / a y b} -is cancelled to @cite{x b / y b} but not to @cite{x / y}. Once +numerator and denominator. In other words, @expr{a x b / a y b} +is cancelled to @expr{x b / y b} but not to @expr{x / y}. Once again this is because full cancellation can be slow; use @kbd{a s} to cancel all terms of the quotient. Quotients of negative-looking values are simplified according -to @cite{(-a) / (-b)} to @cite{a / b}, @cite{(-a) / (b - c)} -to @cite{a / (c - b)}, and @cite{(a - b) / (-c)} to @cite{(b - a) / c}. +to @expr{(-a) / (-b)} to @expr{a / b}, @expr{(-a) / (b - c)} +to @expr{a / (c - b)}, and @expr{(a - b) / (-c)} to @expr{(b - a) / c}. @tex \bigskip @end tex -The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)} -in matrix mode. The formula @cite{0^x} is simplified to @cite{0} -unless @cite{x} is a negative number or complex number, in which +The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)} +in Matrix mode. The formula @expr{0^x} is simplified to @expr{0} +unless @expr{x} is a negative number or complex number, in which case the result is an infinity or an unsimplified formula according -to the current infinite mode. Note that @cite{0^0} is an +to the current infinite mode. Note that @expr{0^0} is an indeterminate form, as evidenced by the fact that the simplifications -for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}. - -Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c} -are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c} -is an integer, or if either @cite{a} or @cite{b} are nonnegative -real numbers. Powers of powers @cite{(a^b)^c} are simplified to -@c{$a^{b c}$} -@cite{a^(b c)} only when @cite{c} is an integer and @cite{b c} also +for @expr{x^0} and @expr{0^x} conflict when @expr{x=0}. + +Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c} +are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c} +is an integer, or if either @expr{a} or @expr{b} are nonnegative +real numbers. Powers of powers @expr{(a^b)^c} are simplified to +@texline @math{a^{b c}} +@infoline @expr{a^(b c)} +only when @expr{c} is an integer and @expr{b c} also evaluates to an integer. Without these restrictions these simplifications would not be safe because of problems with principal values. -(In other words, @c{$((-3)^{1/2})^2$} -@cite{((-3)^1:2)^2} is safe to simplify, but -@c{$((-3)^2)^{1/2}$} -@cite{((-3)^2)^1:2} is not.) @xref{Declarations}, for ways to inform -Calc that your variables satisfy these requirements. - -As a special case of this rule, @cite{@t{sqrt}(x)^n} is simplified to -@c{$x^{n/2}$} -@cite{x^(n/2)} only for even integers @cite{n}. - -If @cite{a} is known to be real, @cite{b} is an even integer, and -@cite{c} is a half- or quarter-integer, then @cite{(a^b)^c} is -simplified to @c{$@t{abs}(a^{b c})$} -@cite{@t{abs}(a^(b c))}. - -Also, @cite{(-a)^b} is simplified to @cite{a^b} if @cite{b} is an -even integer, or to @cite{-(a^b)} if @cite{b} is an odd integer, -for any negative-looking expression @cite{-a}. - -Square roots @cite{@t{sqrt}(x)} generally act like one-half powers -@c{$x^{1:2}$} -@cite{x^1:2} for the purposes of the above-listed simplifications. - -Also, note that @c{$1 / x^{1:2}$} -@cite{1 / x^1:2} is changed to @c{$x^{-1:2}$} -@cite{x^(-1:2)}, -but @cite{1 / @t{sqrt}(x)} is left alone. +(In other words, +@texline @math{((-3)^{1/2})^2} +@infoline @expr{((-3)^1:2)^2} +is safe to simplify, but +@texline @math{((-3)^2)^{1/2}} +@infoline @expr{((-3)^2)^1:2} +is not.) @xref{Declarations}, for ways to inform Calc that your +variables satisfy these requirements. + +As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to +@texline @math{x^{n/2}} +@infoline @expr{x^(n/2)} +only for even integers @expr{n}. + +If @expr{a} is known to be real, @expr{b} is an even integer, and +@expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is +simplified to @expr{@t{abs}(a^(b c))}. + +Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an +even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer, +for any negative-looking expression @expr{-a}. + +Square roots @expr{@t{sqrt}(x)} generally act like one-half powers +@texline @math{x^{1:2}} +@infoline @expr{x^1:2} +for the purposes of the above-listed simplifications. + +Also, note that +@texline @math{1 / x^{1:2}} +@infoline @expr{1 / x^1:2} +is changed to +@texline @math{x^{-1:2}}, +@infoline @expr{x^(-1:2)}, +but @expr{1 / @t{sqrt}(x)} is left alone. @tex \bigskip @end tex Generic identity matrices (@pxref{Matrix Mode}) are simplified by the -following rules: @cite{@t{idn}(a) + b} to @cite{a + b} if @cite{b} -is provably scalar, or expanded out if @cite{b} is a matrix; -@cite{@t{idn}(a) + @t{idn}(b)} to @cite{@t{idn}(a + b)}; -@cite{-@t{idn}(a)} to @cite{@t{idn}(-a)}; @cite{a @t{idn}(b)} to -@cite{@t{idn}(a b)} if @cite{a} is provably scalar, or to @cite{a b} -if @cite{a} is provably non-scalar; @cite{@t{idn}(a) @t{idn}(b)} -to @cite{@t{idn}(a b)}; analogous simplifications for quotients -involving @code{idn}; and @cite{@t{idn}(a)^n} to @cite{@t{idn}(a^n)} -where @cite{n} is an integer. +following rules: @expr{@t{idn}(a) + b} to @expr{a + b} if @expr{b} +is provably scalar, or expanded out if @expr{b} is a matrix; +@expr{@t{idn}(a) + @t{idn}(b)} to @expr{@t{idn}(a + b)}; +@expr{-@t{idn}(a)} to @expr{@t{idn}(-a)}; @expr{a @t{idn}(b)} to +@expr{@t{idn}(a b)} if @expr{a} is provably scalar, or to @expr{a b} +if @expr{a} is provably non-scalar; @expr{@t{idn}(a) @t{idn}(b)} to +@expr{@t{idn}(a b)}; analogous simplifications for quotients involving +@code{idn}; and @expr{@t{idn}(a)^n} to @expr{@t{idn}(a^n)} where +@expr{n} is an integer. @tex \bigskip @@ -22272,26 +22533,28 @@ where @cite{n} is an integer. The @code{floor} function and other integer truncation functions vanish if the argument is provably integer-valued, so that -@cite{@t{floor}(@t{round}(x))} simplifies to @cite{@t{round}(x)}. +@expr{@t{floor}(@t{round}(x))} simplifies to @expr{@t{round}(x)}. Also, combinations of @code{float}, @code{floor} and its friends, and @code{ffloor} and its friends, are simplified in appropriate ways. @xref{Integer Truncation}. -The expression @cite{@t{abs}(-x)} changes to @cite{@t{abs}(x)}. -The expression @cite{@t{abs}(@t{abs}(x))} changes to @cite{@t{abs}(x)}; -in fact, @cite{@t{abs}(x)} changes to @cite{x} or @cite{-x} if @cite{x} -is provably nonnegative or nonpositive (@pxref{Declarations}). +The expression @expr{@t{abs}(-x)} changes to @expr{@t{abs}(x)}. +The expression @expr{@t{abs}(@t{abs}(x))} changes to +@expr{@t{abs}(x)}; in fact, @expr{@t{abs}(x)} changes to @expr{x} or +@expr{-x} if @expr{x} is provably nonnegative or nonpositive +(@pxref{Declarations}). While most functions do not recognize the variable @code{i} as an imaginary number, the @code{arg} function does handle the two cases -@cite{@t{arg}(@t{i})} and @cite{@t{arg}(-@t{i})} just for convenience. +@expr{@t{arg}(@t{i})} and @expr{@t{arg}(-@t{i})} just for convenience. -The expression @cite{@t{conj}(@t{conj}(x))} simplifies to @cite{x}. +The expression @expr{@t{conj}(@t{conj}(x))} simplifies to @expr{x}. Various other expressions involving @code{conj}, @code{re}, and @code{im} are simplified, especially if some of the arguments are provably real or involve the constant @code{i}. For example, -@cite{@t{conj}(a + b i)} is changed to @cite{@t{conj}(a) - @t{conj}(b) i}, -or to @cite{a - b i} if @cite{a} and @cite{b} are known to be real. +@expr{@t{conj}(a + b i)} is changed to +@expr{@t{conj}(a) - @t{conj}(b) i}, or to @expr{a - b i} if @expr{a} +and @expr{b} are known to be real. Functions like @code{sin} and @code{arctan} generally don't have any default simplifications beyond simply evaluating the functions @@ -22299,18 +22562,18 @@ for suitable numeric arguments and infinity. The @kbd{a s} command described in the next section does provide some simplifications for these functions, though. -One important simplification that does occur is that @cite{@t{ln}(@t{e})} -is simplified to 1, and @cite{@t{ln}(@t{e}^x)} is simplified to @cite{x} -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! +One important simplification that does occur is that +@expr{@t{ln}(@t{e})} is simplified to 1, and @expr{@t{ln}(@t{e}^x)} is +simplified to @expr{x} for any @expr{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{(@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 -@cite{!!2} is 1, not 2. +@expr{!!x} to @expr{x}, this would not be valid in general because +@expr{!!2} is 1, not 2. Most other Calc functions have few if any default simplifications defined, aside of course from evaluation when the arguments are @@ -22347,13 +22610,13 @@ then the built-in simplifications, and so on. @end tex Sums are simplified in two ways. Constant terms are commuted to the -end of the sum, so that @cite{a + 2 + b} changes to @cite{a + b + 2}. +end of the sum, so that @expr{a + 2 + b} changes to @expr{a + b + 2}. The only exception is that a constant will not be commuted away -from the first position of a difference, i.e., @cite{2 - x} is not -commuted to @cite{-x + 2}. +from the first position of a difference, i.e., @expr{2 - x} is not +commuted to @expr{-x + 2}. Also, terms of sums are combined by the distributive law, as in -@cite{x + y + 2 x} to @cite{y + 3 x}. This always occurs for +@expr{x + y + 2 x} to @expr{y + 3 x}. This always occurs for adjacent terms, but @kbd{a s} compares all pairs of terms including non-adjacent ones. @@ -22362,10 +22625,10 @@ non-adjacent ones. @end tex Products are sorted into a canonical order using the commutative -law. For example, @cite{b c a} is commuted to @cite{a b c}. +law. For example, @expr{b c a} is commuted to @expr{a b c}. This allows easier comparison of products; for example, the default -simplifications will not change @cite{x y + y x} to @cite{2 x y}, -but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y}, +simplifications will not change @expr{x y + y x} to @expr{2 x y}, +but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y}, and then the default simplifications are able to recognize a sum of identical terms. @@ -22374,7 +22637,7 @@ property that real-valued numbers, interval forms and infinities come first, and are sorted into increasing order. The @kbd{V S} command uses the same ordering when sorting a vector. -Sorting of terms of products is inhibited when matrix mode is +Sorting of terms of products is inhibited when Matrix mode is turned on; in this case, Calc will never exchange the order of two terms unless it knows at least one of the terms is a scalar. @@ -22384,15 +22647,15 @@ use for adjacent terms of products. Even though sums are not sorted, the commutative law is still taken into account when terms of a product are being compared. -Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}. -A subtle point is that @cite{(x - y) (y - x)} will @emph{not} -be simplified to @cite{-(x - y)^2}; Calc does not notice that +Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}. +A subtle point is that @expr{(x - y) (y - x)} will @emph{not} +be simplified to @expr{-(x - y)^2}; Calc does not notice that one term can be written as a constant times the other, even if -that constant is @i{-1}. +that constant is @mathit{-1}. -A fraction times any expression, @cite{(a:b) x}, is changed to -a quotient involving integers: @cite{a x / b}. This is not -done for floating-point numbers like @cite{0.5}, however. This +A fraction times any expression, @expr{(a:b) x}, is changed to +a quotient involving integers: @expr{a x / b}. This is not +done for floating-point numbers like @expr{0.5}, however. This is one reason why you may find it convenient to turn Fraction mode on while doing algebra; @pxref{Fraction Mode}. @@ -22402,25 +22665,25 @@ on while doing algebra; @pxref{Fraction Mode}. Quotients are simplified by comparing all terms in the numerator with all terms in the denominator for possible cancellation using -the distributive law. For example, @cite{a x^2 b / c x^3 d} will -cancel @cite{x^2} from both sides to get @cite{a b / c x d}. -(The terms in the denominator will then be rearranged to @cite{c d x} +the distributive law. For example, @expr{a x^2 b / c x^3 d} will +cancel @expr{x^2} from both sides to get @expr{a b / c x d}. +(The terms in the denominator will then be rearranged to @expr{c d x} as described above.) If there is any common integer or fractional factor in the numerator and denominator, it is cancelled out; -for example, @cite{(4 x + 6) / 8 x} simplifies to @cite{(2 x + 3) / 4 x}. +for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}. Non-constant common factors are not found even by @kbd{a s}. To -cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first -use @kbd{j M} on the product @cite{a x} to Merge the numerator to -@cite{a (1+x)}, which can then be simplified successfully. +cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first +use @kbd{j M} on the product @expr{a x} to Merge the numerator to +@expr{a (1+x)}, which can then be simplified successfully. @tex \bigskip @end tex Integer powers of the variable @code{i} are simplified according -to the identity @cite{i^2 = -1}. If you store a new value other -than the complex number @cite{(0,1)} in @code{i}, this simplification +to the identity @expr{i^2 = -1}. If you store a new value other +than the complex number @expr{(0,1)} in @code{i}, this simplification will no longer occur. This is done by @kbd{a s} instead of by default in case someone (unwisely) uses the name @code{i} for a variable unrelated to complex numbers; it would be unfortunate if Calc @@ -22430,26 +22693,26 @@ user might not have been thinking of. Square roots of integer or rational arguments are simplified in several ways. (Note that these will be left unevaluated only in Symbolic mode.) First, square integer or rational factors are -pulled out so that @cite{@t{sqrt}(8)} is rewritten as -@c{$2\,\t{sqrt}(2)$} -@cite{2 sqrt(2)}. Conceptually speaking this implies factoring -the argument into primes and moving pairs of primes out of the -square root, but for reasons of efficiency Calc only looks for -primes up to 29. +pulled out so that @expr{@t{sqrt}(8)} is rewritten as +@texline @math{2\,\t{sqrt}(2)}. +@infoline @expr{2 sqrt(2)}. +Conceptually speaking this implies factoring the argument into primes +and moving pairs of primes out of the square root, but for reasons of +efficiency Calc only looks for primes up to 29. Square roots in the denominator of a quotient are moved to the -numerator: @cite{1 / @t{sqrt}(3)} changes to @cite{@t{sqrt}(3) / 3}. +numerator: @expr{1 / @t{sqrt}(3)} changes to @expr{@t{sqrt}(3) / 3}. The same effect occurs for the square root of a fraction: -@cite{@t{sqrt}(2:3)} changes to @cite{@t{sqrt}(6) / 3}. +@expr{@t{sqrt}(2:3)} changes to @expr{@t{sqrt}(6) / 3}. @tex \bigskip @end tex The @code{%} (modulo) operator is simplified in several ways -when the modulus @cite{M} is a positive real number. First, if -the argument is of the form @cite{x + n} for some real number -@cite{n}, then @cite{n} is itself reduced modulo @cite{M}. For +when the modulus @expr{M} is a positive real number. First, if +the argument is of the form @expr{x + n} for some real number +@expr{n}, then @expr{n} is itself reduced modulo @expr{M}. For example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}. If the argument is multiplied by a constant, and this constant @@ -22473,16 +22736,16 @@ declared to be an integer. @end tex Trigonometric functions are simplified in several ways. First, -@cite{@t{sin}(@t{arcsin}(x))} is simplified to @cite{x}, and +@expr{@t{sin}(@t{arcsin}(x))} is simplified to @expr{x}, and similarly for @code{cos} and @code{tan}. If the argument to -@code{sin} is negative-looking, it is simplified to @cite{-@t{sin}(x)}, -and similarly for @code{cos} and @code{tan}. Finally, certain -special values of the argument are recognized; +@code{sin} is negative-looking, it is simplified to +@expr{-@t{sin}(x),}, and similarly for @code{cos} and @code{tan}. +Finally, certain special values of the argument are recognized; @pxref{Trigonometric and Hyperbolic Functions}. Trigonometric functions of inverses of different trigonometric -functions can also be simplified, as in @cite{@t{sin}(@t{arccos}(x))} -to @cite{@t{sqrt}(1 - x^2)}. +functions can also be simplified, as in @expr{@t{sin}(@t{arccos}(x))} +to @expr{@t{sqrt}(1 - x^2)}. Hyperbolic functions of their inverses and of negative-looking arguments are also handled, as are exponentials of inverse @@ -22491,26 +22754,31 @@ hyperbolic functions. No simplifications for inverse trigonometric and hyperbolic functions are known, except for negative arguments of @code{arcsin}, @code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that -@cite{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to -@cite{x}, since this only correct within an integer multiple -of @c{$2 \pi$} -@cite{2 pi} radians or 360 degrees. However, -@cite{@t{arcsinh}(@t{sinh}(x))} is simplified to @cite{x} if -@cite{x} is known to be real. +@expr{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to +@expr{x}, since this only correct within an integer multiple of +@texline @math{2 \pi} +@infoline @expr{2 pi} +radians or 360 degrees. However, @expr{@t{arcsinh}(@t{sinh}(x))} is +simplified to @expr{x} if @expr{x} is known to be real. Several simplifications that apply to logarithms and exponentials -are that @cite{@t{exp}(@t{ln}(x))}, @c{$@t{e}^{\ln(x)}$} -@cite{e^@t{ln}(x)}, and -@c{$10^{{\rm log10}(x)}$} -@cite{10^@t{log10}(x)} all reduce to @cite{x}. -Also, @cite{@t{ln}(@t{exp}(x))}, etc., can reduce to @cite{x} if -@cite{x} is provably real. The form @cite{@t{exp}(x)^y} is simplified -to @cite{@t{exp}(x y)}. If @cite{x} is a suitable multiple of @c{$\pi i$} -@cite{pi i} -(as described above for the trigonometric functions), then @cite{@t{exp}(x)} -or @cite{e^x} will be expanded. Finally, @cite{@t{ln}(x)} is simplified -to a form involving @code{pi} and @code{i} where @cite{x} is provably -negative, positive imaginary, or negative imaginary. +are that @expr{@t{exp}(@t{ln}(x))}, +@texline @t{e}@math{^{\ln(x)}}, +@infoline @expr{e^@t{ln}(x)}, +and +@texline @math{10^{{\rm log10}(x)}} +@infoline @expr{10^@t{log10}(x)} +all reduce to @expr{x}. Also, @expr{@t{ln}(@t{exp}(x))}, etc., can +reduce to @expr{x} if @expr{x} is provably real. The form +@expr{@t{exp}(x)^y} is simplified to @expr{@t{exp}(x y)}. If @expr{x} +is a suitable multiple of +@texline @math{\pi i} +@infoline @expr{pi i} +(as described above for the trigonometric functions), then +@expr{@t{exp}(x)} or @expr{e^x} will be expanded. Finally, +@expr{@t{ln}(x)} is simplified to a form involving @code{pi} and +@code{i} where @expr{x} is provably negative, positive imaginary, or +negative imaginary. The error functions @code{erf} and @code{erfc} are simplified when their arguments are negative-looking or are calls to the @code{conj} @@ -22523,7 +22791,7 @@ function. Equations and inequalities are simplified by cancelling factors of products, quotients, or sums on both sides. Inequalities change sign if a negative multiplicative factor is cancelled. -Non-constant multiplicative factors as in @cite{a b = a c} are +Non-constant multiplicative factors as in @expr{a b = a c} are cancelled from equations only if they are provably nonzero (generally because they were declared so; @pxref{Declarations}). Factors are cancelled from inequalities only if they are nonzero and their @@ -22531,11 +22799,11 @@ sign is known. Simplification also replaces an equation or inequality with 1 or 0 (``true'' or ``false'') if it can through the use of -declarations. If @cite{x} is declared to be an integer greater -than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are -all simplified to 0, but @cite{x > 3} is simplified to 1. -By a similar analysis, @cite{abs(x) >= 0} is simplified to 1, -as is @cite{x^2 >= 0} if @cite{x} is known to be real. +declarations. If @expr{x} is declared to be an integer greater +than 5, then @expr{x < 3}, @expr{x = 3}, and @expr{x = 7.5} are +all simplified to 0, but @expr{x > 3} is simplified to 1. +By a similar analysis, @expr{abs(x) >= 0} is simplified to 1, +as is @expr{x^2 >= 0} if @expr{x} is known to be real. @node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas @subsection ``Unsafe'' Simplifications @@ -22557,8 +22825,8 @@ formula lie in the restricted ranges for which these simplifications are valid. The symbolic integrator uses @kbd{a e}; one effect of this is that the integrator's results must be used with caution. Where an integral table will often attach conditions like -``for positive @cite{a} only,'' Calc (like most other symbolic -integration programs) will simply produce an unqualified result.@refill +``for positive @expr{a} only,'' Calc (like most other symbolic +integration programs) will simply produce an unqualified result. Because @kbd{a e}'s simplifications are unsafe, it is sometimes better to type @kbd{C-u -3 a v}, which does extended simplification only @@ -22580,45 +22848,49 @@ by @kbd{a e}. Inverse trigonometric or hyperbolic functions, called with their corresponding non-inverse functions as arguments, are simplified -by @kbd{a e}. For example, @cite{@t{arcsin}(@t{sin}(x))} changes -to @cite{x}. Also, @cite{@t{arcsin}(@t{cos}(x))} and -@cite{@t{arccos}(@t{sin}(x))} both change to @cite{@t{pi}/2 - x}. +by @kbd{a e}. For example, @expr{@t{arcsin}(@t{sin}(x))} changes +to @expr{x}. Also, @expr{@t{arcsin}(@t{cos}(x))} and +@expr{@t{arccos}(@t{sin}(x))} both change to @expr{@t{pi}/2 - x}. These simplifications are unsafe because they are valid only for -values of @cite{x} in a certain range; outside that range, values +values of @expr{x} in a certain range; outside that range, values are folded down to the 360-degree range that the inverse trigonometric functions always produce. -Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$} -@cite{x^(a b)} -for all @cite{a} and @cite{b}. These results will be valid only -in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$} -@cite{(x^2)^1:2} -the powers cancel to get @cite{x}, which is valid for positive values -of @cite{x} but not for negative or complex values. - -Similarly, @cite{@t{sqrt}(x^a)} and @cite{@t{sqrt}(x)^a} are both -simplified (possibly unsafely) to @c{$x^{a/2}$} -@cite{x^(a/2)}. - -Forms like @cite{@t{sqrt}(1 - @t{sin}(x)^2)} are simplified to, e.g., -@cite{@t{cos}(x)}. Calc has identities of this sort for @code{sin}, +Powers of powers @expr{(x^a)^b} are simplified to +@texline @math{x^{a b}} +@infoline @expr{x^(a b)} +for all @expr{a} and @expr{b}. These results will be valid only +in a restricted range of @expr{x}; for example, in +@texline @math{(x^2)^{1:2}} +@infoline @expr{(x^2)^1:2} +the powers cancel to get @expr{x}, which is valid for positive values +of @expr{x} but not for negative or complex values. + +Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both +simplified (possibly unsafely) to +@texline @math{x^{a/2}}. +@infoline @expr{x^(a/2)}. + +Forms like @expr{@t{sqrt}(1 - sin(x)^2)} are simplified to, e.g., +@expr{@t{cos}(x)}. Calc has identities of this sort for @code{sin}, @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}. Arguments of square roots are partially factored to look for squared terms that can be extracted. For example, -@cite{@t{sqrt}(a^2 b^3 + a^3 b^2)} simplifies to @cite{a b @t{sqrt}(a+b)}. +@expr{@t{sqrt}(a^2 b^3 + a^3 b^2)} simplifies to +@expr{a b @t{sqrt}(a+b)}. -The simplifications of @cite{@t{ln}(@t{exp}(x))}, @cite{@t{ln}(@t{e}^x)}, -and @cite{@t{log10}(10^x)} to @cite{x} are also unsafe because -of problems with principal values (although these simplifications -are safe if @cite{x} is known to be real). +The simplifications of @expr{@t{ln}(@t{exp}(x))}, +@expr{@t{ln}(@t{e}^x)}, and @expr{@t{log10}(10^x)} to @expr{x} are also +unsafe because of problems with principal values (although these +simplifications are safe if @expr{x} is known to be real). Common factors are cancelled from products on both sides of an -equation, even if those factors may be zero: @cite{a x / b x} -to @cite{a / b}. Such factors are never cancelled from +equation, even if those factors may be zero: @expr{a x / b x} +to @expr{a / b}. Such factors are never cancelled from inequalities: Even @kbd{a e} is not bold enough to reduce -@cite{a x < b x} to @cite{a < b} (or @cite{a > b}, depending -on whether you believe @cite{x} is positive or negative). +@expr{a x < b x} to @expr{a < b} (or @expr{a > b}, depending +on whether you believe @expr{x} is positive or negative). The @kbd{a M /} command can be used to divide a factor out of both sides of an inequality. @@ -22638,12 +22910,12 @@ and @code{AlgSimpRules}. Scalar mode is automatically put into effect when simplifying units. @xref{Matrix Mode}. -Sums @cite{a + b} involving units are simplified by extracting the -units of @cite{a} as if by the @kbd{u x} command (call the result -@cite{u_a}), then simplifying the expression @cite{b / u_a} +Sums @expr{a + b} involving units are simplified by extracting the +units of @expr{a} as if by the @kbd{u x} command (call the result +@expr{u_a}), then simplifying the expression @expr{b / u_a} using @kbd{u b} and @kbd{u s}. If the result has units then the sum is inconsistent and is left alone. Otherwise, it is rewritten -in terms of the units @cite{u_a}. +in terms of the units @expr{u_a}. If units auto-ranging mode is enabled, products or quotients in which the first argument is a number which is out of range for the @@ -22655,39 +22927,44 @@ For example, @samp{2 km m} is simplified to @samp{2000 m^2}. However, compatible but different units like @code{ft} and @code{in} are not combined in this way. -Quotients @cite{a / b} are simplified in three additional ways. First, -if @cite{b} is a number or a product beginning with a number, Calc +Quotients @expr{a / b} are simplified in three additional ways. First, +if @expr{b} is a number or a product beginning with a number, Calc computes the reciprocal of this number and moves it to the numerator. Second, for each pair of unit names from the numerator and denominator of a quotient, if the units are compatible (e.g., they are both units of area) then they are replaced by the ratio between those units. For example, in @samp{3 s in N / kg cm} the units -@samp{in / cm} will be replaced by @cite{2.54}. +@samp{in / cm} will be replaced by @expr{2.54}. Third, if the units in the quotient exactly cancel out, so that a @kbd{u b} command on the quotient would produce a dimensionless number for an answer, then the quotient simplifies to that number. For powers and square roots, the ``unsafe'' simplifications -@cite{(a b)^c} to @cite{a^c b^c}, @cite{(a/b)^c} to @cite{a^c / b^c}, -and @cite{(a^b)^c} to @c{$a^{b c}$} -@cite{a^(b c)} are done if the powers are -real numbers. (These are safe in the context of units because -all numbers involved can reasonably be assumed to be real.) +@expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c}, +and @expr{(a^b)^c} to +@texline @math{a^{b c}} +@infoline @expr{a^(b c)} +are done if the powers are real numbers. (These are safe in the context +of units because all numbers involved can reasonably be assumed to be +real.) Also, if a unit name is raised to a fractional power, and the base units in that unit name all occur to powers which are a multiple of the denominator of the power, then the unit name is expanded out into its base units, which can then be simplified according to the previous paragraph. For example, @samp{acre^1.5} -is simplified by noting that @cite{1.5 = 3:2}, that @samp{acre} +is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre} is defined in terms of @samp{m^2}, and that the 2 in the power of -@code{m} is a multiple of 2 in @cite{3:2}. Thus, @code{acre^1.5} is -replaced by approximately @c{$(4046 m^2)^{1.5}$} -@cite{(4046 m^2)^1.5}, which is then -changed to @c{$4046^{1.5} \, (m^2)^{1.5}$} -@cite{4046^1.5 (m^2)^1.5}, then to @cite{257440 m^3}. +@code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is +replaced by approximately +@texline @math{(4046 m^2)^{1.5}} +@infoline @expr{(4046 m^2)^1.5}, +which is then changed to +@texline @math{4046^{1.5} \, (m^2)^{1.5}}, +@infoline @expr{4046^1.5 (m^2)^1.5}, +then to @expr{257440 m^3}. The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, as well as @code{floor} and the other integer truncation functions, @@ -22705,10 +22982,10 @@ with the angular mode temporarily set to radians. @section Polynomials A @dfn{polynomial} is a sum of terms which are coefficients times -various powers of a ``base'' variable. For example, @cite{2 x^2 + 3 x - 4} -is a polynomial in @cite{x}. Some formulas can be considered -polynomials in several different variables: @cite{1 + 2 x + 3 y + 4 x y^2} -is a polynomial in both @cite{x} and @cite{y}. Polynomial coefficients +various powers of a ``base'' variable. For example, @expr{2 x^2 + 3 x - 4} +is a polynomial in @expr{x}. Some formulas can be considered +polynomials in several different variables: @expr{1 + 2 x + 3 y + 4 x y^2} +is a polynomial in both @expr{x} and @expr{y}. Polynomial coefficients are often numbers, but they may in general be any formulas not involving the base variable. @@ -22717,9 +22994,9 @@ involving the base variable. @tindex factor The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a polynomial into a product of terms. For example, the polynomial -@cite{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another -example, @cite{a c + b d + b c + a d} is factored into the product -@cite{(a + b) (c + d)}. +@expr{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another +example, @expr{a c + b d + b c + a d} is factored into the product +@expr{(a + b) (c + d)}. Calc currently has three algorithms for factoring. Formulas which are linear in several variables, such as the second example above, are @@ -22727,7 +23004,7 @@ merged according to the distributive law. Formulas which are polynomials in a single variable, with constant integer or fractional coefficients, are factored into irreducible linear and/or quadratic terms. The first example above factors into three linear terms -(@cite{x}, @cite{x+1}, and @cite{x+1} again). Finally, formulas +(@expr{x}, @expr{x+1}, and @expr{x+1} again). Finally, formulas which do not fit the above criteria are handled by the algebraic rewrite mechanism. @@ -22759,7 +23036,7 @@ The rewrite-based factorization method uses rules stored in the variable @code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the operation of rewrite rules. The default @code{FactorRules} are able to factor quadratic forms symbolically into two linear terms, -@cite{(a x + b) (c x + d)}. You can edit these rules to include other +@expr{(a x + b) (c x + d)}. You can edit these rules to include other cases if you wish. To use the rules, Calc builds the formula @samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial base variable and @code{a}, @code{b}, etc., are polynomial coefficients @@ -22780,13 +23057,13 @@ The @kbd{H a f} [@code{factors}] command also factors a polynomial, but it returns a list of factors instead of an expression which is the product of the factors. Each factor is represented by a sub-vector of the factor, and the power with which it appears. For example, -@cite{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @cite{(x + 7) x^2 (x - 3)^2} -in @kbd{a f}, or to @cite{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}. +@expr{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @expr{(x + 7) x^2 (x - 3)^2} +in @kbd{a f}, or to @expr{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}. If there is an overall numeric factor, it always comes first in the list. The functions @code{factor} and @code{factors} allow a second argument -when written in algebraic form; @samp{factor(x,v)} factors @cite{x} with -respect to the specific variable @cite{v}. The default is to factor with -respect to all the variables that appear in @cite{x}. +when written in algebraic form; @samp{factor(x,v)} factors @expr{x} with +respect to the specific variable @expr{v}. The default is to factor with +respect to all the variables that appear in @expr{x}. @kindex a c @pindex calc-collect @@ -22794,12 +23071,12 @@ respect to all the variables that appear in @cite{x}. The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a formula as a polynomial in a given variable, ordered in decreasing powers of that -variable. For example, given @cite{1 + 2 x + 3 y + 4 x y^2} on -the stack, @kbd{a c x} would produce @cite{(2 + 4 y^2) x + (1 + 3 y)}, -and @kbd{a c y} would produce @cite{(4 x) y^2 + 3 y + (1 + 2 x)}. +variable. For example, given @expr{1 + 2 x + 3 y + 4 x y^2} on +the stack, @kbd{a c x} would produce @expr{(2 + 4 y^2) x + (1 + 3 y)}, +and @kbd{a c y} would produce @expr{(4 x) y^2 + 3 y + (1 + 2 x)}. The polynomial will be expanded out using the distributive law as -necessary: Collecting @cite{x} in @cite{(x - 1)^3} produces -@cite{x^3 - 3 x^2 + 3 x - 1}. Terms not involving @cite{x} will +necessary: Collecting @expr{x} in @expr{(x - 1)^3} produces +@expr{x^3 - 3 x^2 + 3 x - 1}. Terms not involving @expr{x} will not be expanded. The ``variable'' you specify at the prompt can actually be any @@ -22828,10 +23105,10 @@ also know many other kinds of expansions, such as do not do.) Calc's automatic simplifications will sometimes reverse a partial -expansion. For example, the first step in expanding @cite{(x+1)^3} is -to write @cite{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries +expansion. For example, the first step in expanding @expr{(x+1)^3} is +to write @expr{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries to put this formula onto the stack, though, Calc will automatically -simplify it back to @cite{(x+1)^3} form. The solution is to turn +simplify it back to @expr{(x+1)^3} form. The solution is to turn simplification off first (@pxref{Simplification Modes}), or to run @kbd{a x} without a numeric prefix argument so that it expands all the way in one step. @@ -22852,21 +23129,21 @@ chooses the base variable automatically. @tindex nrat The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command attempts to arrange a formula into a quotient of two polynomials. -For example, given @cite{1 + (a + b/c) / d}, the result would be -@cite{(b + a c + c d) / c d}. The quotient is reduced, so that -@kbd{a n} will simplify @cite{(x^2 + 2x + 1) / (x^2 - 1)} by dividing -out the common factor @cite{x + 1}, yielding @cite{(x + 1) / (x - 1)}. +For example, given @expr{1 + (a + b/c) / d}, the result would be +@expr{(b + a c + c d) / c d}. The quotient is reduced, so that +@kbd{a n} will simplify @expr{(x^2 + 2x + 1) / (x^2 - 1)} by dividing +out the common factor @expr{x + 1}, yielding @expr{(x + 1) / (x - 1)}. @kindex a \ @pindex calc-poly-div @tindex pdiv The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides -two polynomials @cite{u} and @cite{v}, yielding a new polynomial -@cite{q}. If several variables occur in the inputs, the inputs are +two polynomials @expr{u} and @expr{v}, yielding a new polynomial +@expr{q}. If several variables occur in the inputs, the inputs are considered multivariate polynomials. (Calc divides by the variable -with the largest power in @cite{u} first, or, in the case of equal +with the largest power in @expr{u} first, or, in the case of equal powers, chooses the variables in alphabetical order.) For example, -dividing @cite{x^2 + 3 x + 2} by @cite{x + 2} yields @cite{x + 1}. +dividing @expr{x^2 + 3 x + 2} by @expr{x + 2} yields @expr{x + 1}. 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. @@ -22880,9 +23157,9 @@ above. @pindex calc-poly-rem @tindex prem The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides -two polynomials and keeps the remainder @cite{r}. The quotient -@cite{q} is discarded. For any formulas @cite{a} and @cite{b}, the -results of @kbd{a \} and @kbd{a %} satisfy @cite{a = q b + r}. +two polynomials and keeps the remainder @expr{r}. The quotient +@expr{q} is discarded. For any formulas @expr{a} and @expr{b}, the +results of @kbd{a \} and @kbd{a %} satisfy @expr{a = q b + r}. (This is analogous to plain @kbd{\} and @kbd{%}, which compute the integer quotient and remainder from dividing two numbers.) @@ -22893,10 +23170,10 @@ integer quotient and remainder from dividing two numbers.) @tindex pdivide The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command divides two polynomials and reports both the quotient and the -remainder as a vector @cite{[q, r]}. The @kbd{H a /} [@code{pdivide}] +remainder as a vector @expr{[q, r]}. The @kbd{H a /} [@code{pdivide}] command divides two polynomials and constructs the formula -@cite{q + r/b} on the stack. (Naturally if the remainder is zero, -this will immediately simplify to @cite{q}.) +@expr{q + r/b} on the stack. (Naturally if the remainder is zero, +this will immediately simplify to @expr{q}.) @kindex a g @pindex calc-poly-gcd @@ -22968,14 +23245,15 @@ With a numeric prefix argument @var{n}, this command computes the @var{n}th derivative. When working with trigonometric functions, it is best to switch to -radians mode first (with @w{@kbd{m r}}). The derivative of @samp{sin(x)} +Radians mode first (with @w{@kbd{m r}}). The derivative of @samp{sin(x)} in degrees is @samp{(pi/180) cos(x)}, probably not the expected answer! If you use the @code{deriv} function directly in an algebraic formula, you can write @samp{deriv(f,x,x0)} which represents the derivative -of @cite{f} with respect to @cite{x}, evaluated at the point @c{$x=x_0$} -@cite{x=x0}. +of @expr{f} with respect to @expr{x}, evaluated at the point +@texline @math{x=x_0}. +@infoline @expr{x=x0}. If the formula being differentiated contains functions which Calc does not know, the derivatives of those functions are produced by adding @@ -22998,7 +23276,7 @@ respect to the other arguments are @samp{f'2(x,y,z)} and @samp{f'3(x,y,z)}. Various higher-order derivatives can be formed in the obvious way, e.g., @samp{f'@var{}'(x)} (the second derivative of @code{f}) or @samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each -argument once).@refill +argument once). @node Integration, Customizing the Integrator, Differentiation, Calculus @subsection Integration @@ -23013,11 +23291,12 @@ respect to a variable. The integrator is not guaranteed to work for all integrable functions, but it is able to integrate several large classes of formulas. In particular, any polynomial or rational function (a polynomial divided by a polynomial) is acceptable. (Rational functions -don't have to be in explicit quotient form, however; @c{$x/(1+x^{-2})$} -@cite{x/(1+x^-2)} +don't have to be in explicit quotient form, however; +@texline @math{x/(1+x^{-2})} +@infoline @expr{x/(1+x^-2)} is not strictly a quotient of polynomials, but it is equivalent to -@cite{x^3/(x^2+1)}, which is.) Also, square roots of terms involving -@cite{x} and @cite{x^2} may appear in rational functions being +@expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving +@expr{x} and @expr{x^2} may appear in rational functions being integrated. Finally, rational functions involving trigonometric or hyperbolic functions can be integrated. @@ -23028,7 +23307,7 @@ indefinite integral in terms of variable @code{v} instead of @code{x}. With four arguments, @samp{integ(f(x),x,a,b)} represents a definite integral from @code{a} to @code{b}. @end ifinfo -@tex +@tex If you use the @code{integ} function directly in an algebraic formula, you can also write @samp{integ(f,x,v)} which expresses the resulting indefinite integral in terms of variable @code{v} instead of @code{x}. @@ -23038,22 +23317,26 @@ integral $\int_a^b f(x) \, dx$. Please note that the current implementation of Calc's integrator sometimes produces results that are significantly more complex than they need to -be. For example, the integral Calc finds for @c{$1/(x+\sqrt{x^2+1})$} -@cite{1/(x+sqrt(x^2+1))} +be. For example, the integral Calc finds for +@texline @math{1/(x+\sqrt{x^2+1})} +@infoline @expr{1/(x+sqrt(x^2+1))} is several times more complicated than the answer Mathematica returns for the same input, although the two forms are numerically equivalent. Also, any indefinite integral should be considered to have an arbitrary constant of integration added to it, although Calc does not write an explicit constant of integration in its result. For example, -Calc's solution for @c{$1/(1+\tan x)$} -@cite{1/(1+tan(x))} differs from the solution given -in the @emph{CRC Math Tables} by a constant factor of @c{$\pi i / 2$} -@cite{pi i / 2}, +Calc's solution for +@texline @math{1/(1+\tan x)} +@infoline @expr{1/(1+tan(x))} +differs from the solution given in the @emph{CRC Math Tables} by a +constant factor of +@texline @math{\pi i / 2} +@infoline @expr{pi i / 2}, due to a different choice of constant of integration. The Calculator remembers all the integrals it has done. If conditions change in a way that would invalidate the old integrals, say, a switch -from degrees to radians mode, then they will be thrown out. If you +from Degrees to Radians mode, then they will be thrown out. If you suspect this is not happening when it should, use the @code{calc-flush-caches} command; @pxref{Caches}. @@ -23106,8 +23389,10 @@ in your @code{IntegRules}. @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 -integral'' function @c{${\rm Ei}(x)$} -@cite{Ei(x)} was invented to describe it. +integral'' function +@texline @math{{\rm Ei}(x)} +@infoline @expr{Ei(x)} +was invented to describe it. We can get Calc to do this integral in terms of a made-up @code{Ei} function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack @@ -23253,7 +23538,7 @@ of just a variable to produce a Taylor expansion about the point @var{a}. You may specify the number of terms with a numeric prefix argument; otherwise the command will prompt you for the number of terms. Note that many series expansions have coefficients of zero for some terms, so you -may appear to get fewer terms than you asked for.@refill +may appear to get fewer terms than you asked for. If the @kbd{a i} command is unable to find a symbolic integral for a function, you can get an approximation by integrating the function's @@ -23270,30 +23555,34 @@ Taylor series. @cindex Solving equations The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges an equation to solve for a specific variable. An equation is an -expression of the form @cite{L = R}. For example, the command @kbd{a S x} -will rearrange @cite{y = 3x + 6} to the form, @cite{x = y/3 - 2}. If the +expression of the form @expr{L = R}. For example, the command @kbd{a S x} +will rearrange @expr{y = 3x + 6} to the form, @expr{x = y/3 - 2}. If the input is not an equation, it is treated like an equation of the -form @cite{X = 0}. +form @expr{X = 0}. -This command also works for inequalities, as in @cite{y < 3x + 6}. +This command also works for inequalities, as in @expr{y < 3x + 6}. Some inequalities cannot be solved where the analogous equation could -be; for example, solving @c{$a < b \, c$} -@cite{a < b c} for @cite{b} is impossible -without knowing the sign of @cite{c}. In this case, @kbd{a S} will -produce the result @c{$b \mathbin{\hbox{\code{!=}}} a/c$} -@cite{b != a/c} (using the not-equal-to operator) -to signify that the direction of the inequality is now unknown. The -inequality @c{$a \le b \, c$} -@cite{a <= b c} is not even partially solved. -@xref{Declarations}, for a way to tell Calc that the signs of the -variables in a formula are in fact known. +be; for example, solving +@texline @math{a < b \, c} +@infoline @expr{a < b c} +for @expr{b} is impossible +without knowing the sign of @expr{c}. In this case, @kbd{a S} will +produce the result +@texline @math{b \mathbin{\hbox{\code{!=}}} a/c} +@infoline @expr{b != a/c} +(using the not-equal-to operator) to signify that the direction of the +inequality is now unknown. The inequality +@texline @math{a \le b \, c} +@infoline @expr{a <= b c} +is not even partially solved. @xref{Declarations}, for a way to tell +Calc that the signs of the variables in a formula are in fact known. Two useful commands for working with the result of @kbd{a S} are -@kbd{a .} (@pxref{Logical Operations}), which converts @cite{x = y/3 - 2} -to @cite{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates -another formula with @cite{x} set equal to @cite{y/3 - 2}. +@kbd{a .} (@pxref{Logical Operations}), which converts @expr{x = y/3 - 2} +to @expr{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates +another formula with @expr{x} set equal to @expr{y/3 - 2}. -@menu +@menu * Multiple Solutions:: * Solving Systems of Equations:: * Decomposing Polynomials:: @@ -23310,7 +23599,7 @@ Some equations have more than one solution. The Hyperbolic flag general family of solutions. It will invent variables @code{n1}, @code{n2}, @dots{}, which represent independent arbitrary integers, and @code{s1}, @code{s2}, @dots{}, which represent independent arbitrary -signs (either @i{+1} or @i{-1}). If you don't use the Hyperbolic +signs (either @mathit{+1} or @mathit{-1}). If you don't use the Hyperbolic flag, Calc will use zero in place of all arbitrary integers, and plus one in place of all arbitrary signs. Note that variables like @code{n1} and @code{s1} are not given any special interpretation in Calc except by @@ -23331,7 +23620,7 @@ There is a similar phenomenon going the other direction: Suppose we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides to get @samp{y = x^2}. This is correct, except that it introduces some dubious solutions. Consider solving @samp{sqrt(y) = -3}: -Calc will report @cite{y = 9} as a valid solution, which is true +Calc will report @expr{y = 9} as a valid solution, which is true in the mathematical sense of square-root, but false (there is no solution) for the actual Calc positive-valued @code{sqrt}. This happens for both @kbd{a S} and @kbd{H a S}. @@ -23362,7 +23651,7 @@ on variables, but you can use the @kbd{a b} (@code{calc-substitute}) command to substitute actual values for function calls like @samp{as(3)}. The @kbd{s G} (@code{calc-edit-GenCount}) command is a convenient -way to create or edit this variable. Press @kbd{M-# M-#} to finish. +way to create or edit this variable. Press @kbd{C-c C-c} to finish. If you have not stored a value in @code{GenCount}, or if the value in that variable is not a positive integer, the regular @@ -23375,7 +23664,7 @@ in that variable is not a positive integer, the regular With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression on top of the stack as a function of the specified variable and solves to find the inverse function, written in terms of the same variable. -For example, @kbd{I a S x} inverts @cite{2x + 6} to @cite{x/2 - 3}. +For example, @kbd{I a S x} inverts @expr{2x + 6} to @expr{x/2 - 3}. You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a fully general inverse, as described above. @@ -23399,18 +23688,18 @@ reported; @pxref{Declarations}.) Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver symbolic solutions if the polynomial has symbolic coefficients. Also note that Calc's solver is not able to get exact symbolic solutions -to all polynomials. Polynomials containing powers up to @cite{x^4} +to all polynomials. Polynomials containing powers up to @expr{x^4} can always be solved exactly; polynomials of higher degree sometimes -can be: @cite{x^6 + x^3 + 1} is converted to @cite{(x^3)^2 + (x^3) + 1}, -which can be solved for @cite{x^3} using the quadratic equation, and then -for @cite{x} by taking cube roots. But in many cases, like -@cite{x^6 + x + 1}, Calc does not know how to rewrite the polynomial +can be: @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1}, +which can be solved for @expr{x^3} using the quadratic equation, and then +for @expr{x} by taking cube roots. But in many cases, like +@expr{x^6 + x + 1}, Calc does not know how to rewrite the polynomial into a form it can solve. The @kbd{a P} command can still deliver a -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 +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 +formula on the stack with Symbolic mode temporarily off.) Naturally, +@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 @@ -23430,7 +23719,7 @@ and typing @kbd{a S x,y @key{RET}} produces the vector of solutions have the same length as the variables vector, and the variables will be listed in the same order there. Note that the solutions are not always simplified as far as possible; the solution for -@cite{x} here could be improved by an application of the @kbd{a n} +@expr{x} here could be improved by an application of the @kbd{a n} command. Calc's algorithm works by trying to eliminate one variable at a @@ -23491,23 +23780,23 @@ to satisfy the equations. @xref{Curve Fitting}. The @code{poly} function takes a polynomial and a variable as arguments, and returns a vector of polynomial coefficients (constant coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns -@cite{[0, 2, 0, 1]}. If the input is not a polynomial in @cite{x}, +@expr{[0, 2, 0, 1]}. If the input is not a polynomial in @expr{x}, the call to @code{poly} is left in symbolic form. If the input does -not involve the variable @cite{x}, the input is returned in a list +not involve the variable @expr{x}, the input is returned in a list of length one, representing a polynomial with only a constant -coefficient. The call @samp{poly(x, x)} returns the vector @cite{[0, 1]}. +coefficient. The call @samp{poly(x, x)} returns the vector @expr{[0, 1]}. The last element of the returned vector is guaranteed to be nonzero; -note that @samp{poly(0, x)} returns the empty vector @cite{[]}. -Note also that @cite{x} may actually be any formula; for example, -@samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @cite{[3, -1, 1]}. +note that @samp{poly(0, x)} returns the empty vector @expr{[]}. +Note also that @expr{x} may actually be any formula; for example, +@samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @expr{[3, -1, 1]}. @cindex Coefficients of polynomial @cindex Degree of polynomial -To get the @cite{x^k} coefficient of polynomial @cite{p}, use -@samp{poly(p, x)_(k+1)}. To get the degree of polynomial @cite{p}, +To get the @expr{x^k} coefficient of polynomial @expr{p}, use +@samp{poly(p, x)_(k+1)}. To get the degree of polynomial @expr{p}, 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. +gives the @expr{x^2} coefficient of this polynomial, 6. @ignore @starindex @@ -23532,13 +23821,13 @@ their arguments as polynomials, will not because the decomposition is considered trivial. For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]}, -since the expanded form of this polynomial is @cite{4 - 4 x + x^2}. +since the expanded form of this polynomial is @expr{4 - 4 x + x^2}. The term @var{x} may itself be a polynomial in @var{var}. This is done to reduce the size of the @var{c} vector. For example, @samp{gpoly(x^4 + x^2 - 1, x)} returns @samp{[x^2, [-1, 1, 1], 1]}, -since a quadratic polynomial in @cite{x^2} is easier to solve than -a quartic polynomial in @cite{x}. +since a quadratic polynomial in @expr{x^2} is easier to solve than +a quartic polynomial in @expr{x}. A few more examples of the kinds of polynomials @code{gpoly} can discover: @@ -23555,7 +23844,7 @@ x^(2a) + 2 x^a + 5 [x^a, [5, 2, 1], 1] The @code{poly} and @code{gpoly} functions accept a third integer argument which specifies the largest degree of polynomial that is acceptable. -If this is @cite{n}, then only @var{c} vectors of length @cite{n+1} +If this is @expr{n}, then only @var{c} vectors of length @expr{n+1} or less will be returned. Otherwise, the @code{poly} or @code{gpoly} call will remain in symbolic form. For example, the equation solver can handle quartics and smaller polynomials, so it calls @@ -23587,7 +23876,7 @@ 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))}, 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}. +value of @code{plead(p,x)} will be zero only if @expr{p = 0}. @ignore @starindex @@ -23656,7 +23945,7 @@ on numerical data.) The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a numerical solution (or @dfn{root}) of an equation. (This command treats inequalities the same as equations. If the input is any other kind -of formula, it is interpreted as an equation of the form @cite{X = 0}.) +of formula, it is interpreted as an equation of the form @expr{X = 0}.) The @kbd{a R} command requires an initial guess on the top of the stack, and a formula in the second-to-top position. It prompts for a @@ -23738,26 +24027,29 @@ 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 -have more than one minimum; some, like @c{$x \sin x$} -@cite{x sin(x)}, have infinitely -many. In fact, there is no easy way to define the ``global'' minimum -of @c{$x \sin x$} -@cite{x sin(x)} but Calc can still locate any particular local minimum +have more than one minimum; some, like +@texline @math{x \sin x}, +@infoline @expr{x sin(x)}, +have infinitely many. In fact, there is no easy way to define the +``global'' minimum of +@texline @math{x \sin x} +@infoline @expr{x sin(x)} +but Calc can still locate any particular local minimum for you. Calc basically goes downhill from the initial guess until it finds a point at which the function's value is greater both to the left and to the right. Calc does not use derivatives when minimizing a function. If your initial guess is an interval and it looks like the minimum occurs at one or the other endpoint of the interval, Calc will return -that endpoint only if that endpoint is closed; thus, minimizing @cite{17 x} -over @cite{[2..3]} will return @cite{[2, 38]}, but minimizing over -@cite{(2..3]} would report no minimum found. In general, you should +that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x} +over @expr{[2..3]} will return @expr{[2, 38]}, but minimizing over +@expr{(2..3]} would report no minimum found. In general, you should use closed intervals to find literally the minimum value in that -range of @cite{x}, or open intervals to find the local minimum, if +range of @expr{x}, or open intervals to find the local minimum, if any, that happens to lie in that range. Most functions are smooth and flat near their minimum values. Because @@ -23819,9 +24111,9 @@ multidimensional minimization is currently @emph{very} slow. @noindent The @kbd{a F} command fits a set of data to a @dfn{model formula}, -such as @cite{y = m x + b} where @cite{m} and @cite{b} are parameters +such as @expr{y = m x + b} where @expr{m} and @expr{b} are parameters to be determined. For a typical set of measured data there will be -no single @cite{m} and @cite{b} that exactly fit the data; in this +no single @expr{m} and @expr{b} that exactly fit the data; in this case, Calc chooses values of the parameters that provide the closest possible fit. @@ -23844,46 +24136,50 @@ possible fit. @cindex Linear regression @cindex Least-squares fits The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts -to fit a set of data (@cite{x} and @cite{y} vectors of numbers) to a -straight line, polynomial, or other function of @cite{x}. For the +to fit a set of data (@expr{x} and @expr{y} vectors of numbers) to a +straight line, polynomial, or other function of @expr{x}. For the moment we will consider only the case of fitting to a line, and we will ignore the issue of whether or not the model was in fact a good fit for the data. -In a standard linear least-squares fit, we have a set of @cite{(x,y)} -data points that we wish to fit to the model @cite{y = m x + b} -by adjusting the parameters @cite{m} and @cite{b} to make the @cite{y} +In a standard linear least-squares fit, we have a set of @expr{(x,y)} +data points that we wish to fit to the model @expr{y = m x + b} +by adjusting the parameters @expr{m} and @expr{b} to make the @expr{y} values calculated from the formula be as close as possible to the actual -@cite{y} values in the data set. (In a polynomial fit, the model is -instead, say, @cite{y = a x^3 + b x^2 + c x + d}. In a multilinear fit, -we have data points of the form @cite{(x_1,x_2,x_3,y)} and our model is -@cite{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.) - -In the model formula, variables like @cite{x} and @cite{x_2} are called -the @dfn{independent variables}, and @cite{y} is the @dfn{dependent -variable}. Variables like @cite{m}, @cite{a}, and @cite{b} are called +@expr{y} values in the data set. (In a polynomial fit, the model is +instead, say, @expr{y = a x^3 + b x^2 + c x + d}. In a multilinear fit, +we have data points of the form @expr{(x_1,x_2,x_3,y)} and our model is +@expr{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.) + +In the model formula, variables like @expr{x} and @expr{x_2} are called +the @dfn{independent variables}, and @expr{y} is the @dfn{dependent +variable}. Variables like @expr{m}, @expr{a}, and @expr{b} are called the @dfn{parameters} of the model. The @kbd{a F} command takes the data set to be fitted from the stack. By default, it expects the data in the form of a matrix. For example, -for a linear or polynomial fit, this would be a @c{$2\times N$} -@asis{2xN} matrix where -the first row is a list of @cite{x} values and the second row has the -corresponding @cite{y} values. For the multilinear fit shown above, -the matrix would have four rows (@cite{x_1}, @cite{x_2}, @cite{x_3}, and -@cite{y}, respectively). - -If you happen to have an @c{$N\times2$} -@asis{Nx2} matrix instead of a @c{$2\times N$} -@asis{2xN} matrix, -just press @kbd{v t} first to transpose the matrix. +for a linear or polynomial fit, this would be a +@texline @math{2\times N} +@infoline 2xN +matrix where the first row is a list of @expr{x} values and the second +row has the corresponding @expr{y} values. For the multilinear fit +shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2}, +@expr{x_3}, and @expr{y}, respectively). + +If you happen to have an +@texline @math{N\times2} +@infoline Nx2 +matrix instead of a +@texline @math{2\times N} +@infoline 2xN +matrix, just press @kbd{v t} first to transpose the matrix. After you type @kbd{a F}, Calc prompts you to select a model. For a linear fit, press the digit @kbd{1}. Calc then prompts for you to name the variables. By default it chooses -high letters like @cite{x} and @cite{y} for independent variables and -low letters like @cite{a} and @cite{b} for parameters. (The dependent +high letters like @expr{x} and @expr{y} for independent variables and +low letters like @expr{a} and @expr{b} for parameters. (The dependent variable doesn't need a name.) The two kinds of variables are separated by a semicolon. Since you generally care more about the names of the independent variables than of the parameters, Calc also allows you to @@ -23912,17 +24208,17 @@ $$ @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 @key{RET} to use -the default names. The result will be the formula @cite{3 + 2 x} +the default names. The result will be the formula @expr{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 +then found the optimal values of @expr{a} and @expr{b} to fit the data. (In this case, it was able to find an exact fit.) Calc then -substituted those values for @cite{a} and @cite{b} in the model +substituted those values for @expr{a} and @expr{b} in the model formula. The @kbd{a F} command puts two entries in the trail. One is, as always, a copy of the result that went to the stack; the other is a vector of the actual parameter values, written as equations: -@cite{[a = 3, b = 2]}, in case you'd rather read them in a list +@expr{[a = 3, b = 2]}, in case you'd rather read them in a list than pick them out of the formula. (You can type @kbd{t y} to move this vector to the stack; see @ref{Trail Commands}. @@ -23968,17 +24264,20 @@ $$ \chi^2 = \sum_{i=1}^N (y_i - (a + b x_i))^2 $$ @end tex @noindent -which is clearly zero if @cite{a + b x} exactly fits all data points, -and increases as various @cite{a + b x_i} values fail to match the -corresponding @cite{y_i} values. There are several reasons why the -summand is squared, one of them being to ensure that @c{$\chi^2 \ge 0$} -@cite{chi^2 >= 0}. -Least-squares fitting simply chooses the values of @cite{a} and @cite{b} -for which the error @c{$\chi^2$} -@cite{chi^2} is as small as possible. +which is clearly zero if @expr{a + b x} exactly fits all data points, +and increases as various @expr{a + b x_i} values fail to match the +corresponding @expr{y_i} values. There are several reasons why the +summand is squared, one of them being to ensure that +@texline @math{\chi^2 \ge 0}. +@infoline @expr{chi^2 >= 0}. +Least-squares fitting simply chooses the values of @expr{a} and @expr{b} +for which the error +@texline @math{\chi^2} +@infoline @expr{chi^2} +is as small as possible. Other kinds of models do the same thing but with a different model -formula in place of @cite{a + b x_i}. +formula in place of @expr{a + b x_i}. @tex \bigskip @@ -23991,9 +24290,9 @@ 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 @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, +items from the stack, an @var{n}-row matrix of @expr{x} values, and a +vector of @expr{y} values. If there is only one independent variable, +the @expr{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. @node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits, Curve Fitting @@ -24012,15 +24311,15 @@ we could fit the original data matrix from the previous section Note that since the constant and linear terms are enough to fit the data exactly, it's no surprise that Calc chose a tiny contribution -for @cite{x^2}. (The fact that it's not exactly zero is due only +for @expr{x^2}. (The fact that it's not exactly zero is due only to roundoff error. Since our data are exact integers, we could get -an exact answer by typing @kbd{m f} first to get fraction mode. -Then the @cite{x^2} term would vanish altogether. Usually, though, -the data being fitted will be approximate floats so fraction mode +an exact answer by typing @kbd{m f} first to get Fraction mode. +Then the @expr{x^2} term would vanish altogether. Usually, though, +the data being fitted will be approximate floats so Fraction mode won't help.) Doing the @kbd{a F 2} fit on the data set with 14 instead of 13 -gives a much larger @cite{x^2} contribution, as Calc bends the +gives a much larger @expr{x^2} contribution, as Calc bends the line slightly to improve the fit. @example @@ -24029,7 +24328,7 @@ line slightly to improve the fit. An important result from the theory of polynomial fitting is that it 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}. +of degree @mathit{@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: @@ -24038,10 +24337,10 @@ a polynomial that exactly matches all five data points: @end example The actual coefficients we get with a precision of 12, like -@cite{0.0416666663588}, clearly suffer from loss of precision. +@expr{0.0416666663588}, clearly suffer from loss of precision. It is a good idea to increase the working precision to several digits beyond what you need when you do a fitting operation. -Or, if your data are exact, use fraction mode to get exact +Or, if your data are exact, use Fraction mode to get exact results. You can type @kbd{i} instead of a digit at the model prompt to fit @@ -24061,8 +24360,8 @@ command described below. @xref{Interpolation}. @end tex Another generalization of the linear model is to assume the -@cite{y} values are a sum of linear contributions from several -@cite{x} values. This is a @dfn{multilinear} fit, and it is also +@expr{y} values are a sum of linear contributions from several +@expr{x} values. This is a @dfn{multilinear} fit, and it is also selected by the @kbd{1} digit key. (Calc decides whether the fit is linear or multilinear by counting the rows in the data matrix.) @@ -24077,9 +24376,9 @@ Given the data matrix, @end example @noindent -the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the -second row @cite{y}, and will fit the values in the third row to the -model @cite{a + b x + c y}. +the command @kbd{a F 1 @key{RET}} will call the first row @expr{x} and the +second row @expr{y}, and will fit the values in the third row to the +model @expr{a + b x + c y}. @example 8. + 3. x + 0.5 y @@ -24094,20 +24393,20 @@ Calc can do multilinear fits with any number of independent variables Yet another variation is @dfn{homogeneous} linear models, in which the constant term is known to be zero. In the linear case, this -means the model formula is simply @cite{a x}; in the multilinear -case, the model might be @cite{a x + b y + c z}; and in the polynomial -case, the model could be @cite{a x + b x^2 + c x^3}. You can get +means the model formula is simply @expr{a x}; in the multilinear +case, the model might be @expr{a x + b y + c z}; and in the polynomial +case, the model could be @expr{a x + b x^2 + c x^3}. You can get a homogeneous linear or multilinear model by pressing the letter @kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}. It is certainly possible to have other constrained linear models, -like @cite{2.3 + a x} or @cite{a - 4 x}. While there is no single +like @expr{2.3 + a x} or @expr{a - 4 x}. While there is no single key to select models like these, a later section shows how to enter any desired model by hand. In the first case, for example, you would enter @kbd{a F ' 2.3 + a x}. Another class of models that will work but must be entered by hand -are multinomial fits, e.g., @cite{a + b x + c y + d x^2 + e y^2 + f x y}. +are multinomial fits, e.g., @expr{a + b x + c y + d x^2 + e y^2 + f x y}. @node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and Multilinear Fits, Curve Fitting @subsection Error Estimates for Fits @@ -24134,9 +24433,11 @@ 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 -`@var{y_i}@w{ @t{+/-} }@c{$\sigma_i$} -@var{sigma_i}', then the @c{$\chi^2$} -@cite{chi^2} +@texline `@var{y_i}@w{ @t{+/-} }@math{\sigma_i}', +@infoline `@var{y_i}@w{ @t{+/-} }@var{sigma_i}', +then the +@texline @math{\chi^2} +@infoline @expr{chi^2} statistic is now, @ifinfo @@ -24157,26 +24458,31 @@ the fitting operation. If there are error forms on other rows of the data matrix, all the errors for a given data point are combined; the square root of the -sum of the squares of the errors forms the @c{$\sigma_i$} -@cite{sigma_i} used for -the data point. +sum of the squares of the errors forms the +@texline @math{\sigma_i} +@infoline @expr{sigma_i} +used for the data point. Both @kbd{a F} and @kbd{H a F} can accept error forms in the input matrix, although if you are concerned about error analysis you will probably use @kbd{H a F} so that the output also contains error estimates. -If the input contains error forms but all the @c{$\sigma_i$} -@cite{sigma_i} values are -the same, it is easy to see that the resulting fitted model will be -the same as if the input did not have error forms at all (@c{$\chi^2$} -@cite{chi^2} -is simply scaled uniformly by @c{$1 / \sigma^2$} -@cite{1 / sigma^2}, which doesn't affect -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 +If the input contains error forms but all the +@texline @math{\sigma_i} +@infoline @expr{sigma_i} +values are the same, it is easy to see that the resulting fitted model +will be the same as if the input did not have error forms at all +@texline (@math{\chi^2} +@infoline (@expr{chi^2} +is simply scaled uniformly by +@texline @math{1 / \sigma^2}, +@infoline @expr{1 / sigma^2}, +which doesn't affect 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 modeling of data for a discussion of where these error estimates come from and how they should be interpreted. @@ -24199,54 +24505,66 @@ produced. A vector of ``raw'' parameter values for the model. These are the polynomial coefficients or other parameters as plain numbers, in the same order as the parameters appeared in the final prompt of the -@kbd{I a F} command. For polynomials of degree @cite{d}, this vector -will have length @cite{M = d+1} with the constant term first. +@kbd{I a F} command. For polynomials of degree @expr{d}, this vector +will have length @expr{M = d+1} with the constant term first. @item -The covariance matrix @cite{C} computed from the fit. This is +The covariance matrix @expr{C} computed from the fit. This is 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. -The other elements are covariances @c{$\sigma_{ij}^2$} -@cite{sigma_i_j^2} that describe the -correlation between pairs of parameters. (A related set of -numbers, the @dfn{linear correlation coefficients} @c{$r_{ij}$} -@cite{r_i_j}, -are defined as @c{$\sigma_{ij}^2 / \sigma_i \, \sigma_j$} -@cite{sigma_i_j^2 / sigma_i sigma_j}.) +@texline @math{C_{jj}} +@infoline @expr{C_j_j} +are the variances +@texline @math{\sigma_j^2} +@infoline @expr{sigma_j^2} +of the parameters. The other elements are covariances +@texline @math{\sigma_{ij}^2} +@infoline @expr{sigma_i_j^2} +that describe the correlation between pairs of parameters. (A related +set of numbers, the @dfn{linear correlation coefficients} +@texline @math{r_{ij}}, +@infoline @expr{r_i_j}, +are defined as +@texline @math{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.) +@infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.) @item -A vector of @cite{M} ``parameter filter'' functions whose +A vector of @expr{M} ``parameter filter'' functions whose meanings are described below. If no filters are necessary this will instead be an empty vector; this is always the case for the polynomial and multilinear fits described so far. @item -The value of @c{$\chi^2$} -@cite{chi^2} for the fit, calculated by the formulas -shown above. This gives a measure of the quality of the fit; -statisticians consider @c{$\chi^2 \approx N - M$} -@cite{chi^2 = N - M} to indicate a moderately good fit -(where again @cite{N} is the number of data points and @cite{M} -is the number of parameters). +The value of +@texline @math{\chi^2} +@infoline @expr{chi^2} +for the fit, calculated by the formulas shown above. This gives a +measure of the quality of the fit; statisticians consider +@texline @math{\chi^2 \approx N - M} +@infoline @expr{chi^2 = N - M} +to indicate a moderately good fit (where again @expr{N} is the number of +data points and @expr{M} is the number of parameters). @item -A measure of goodness of fit expressed as a probability @cite{Q}. +A measure of goodness of fit expressed as a probability @expr{Q}. This is computed from the @code{utpc} probability distribution -function using @c{$\chi^2$} -@cite{chi^2} with @cite{N - M} degrees of freedom. A +function using +@texline @math{\chi^2} +@infoline @expr{chi^2} +with @expr{N - M} degrees of freedom. A value of 0.5 implies a good fit; some texts recommend that often -@cite{Q = 0.1} or even 0.001 can signify an acceptable fit. In -particular, @c{$\chi^2$} -@cite{chi^2} statistics assume the errors in your inputs +@expr{Q = 0.1} or even 0.001 can signify an acceptable fit. In +particular, +@texline @math{\chi^2} +@infoline @expr{chi^2} +statistics assume the errors in your inputs follow a normal (Gaussian) distribution; if they don't, you may -have to accept smaller values of @cite{Q}. +have to accept smaller values of @expr{Q}. -The @cite{Q} value is computed only if the input included error +The @expr{Q} value is computed only if the input included error estimates. Otherwise, Calc will report the symbol @code{nan} -for @cite{Q}. The reason is that in this case the @c{$\chi^2$} -@cite{chi^2} +for @expr{Q}. The reason is that in this case the +@texline @math{\chi^2} +@infoline @expr{chi^2} value has effectively been used to estimate the original errors in the input, and thus there is no redundant information left over to use for a confidence test. @@ -24264,30 +24582,31 @@ Here is a complete list of the standard models recognized by @kbd{a F}: @table @kbd @item 1 -Linear or multilinear. @i{a + b x + c y + d z}. +Linear or multilinear. @mathit{a + b x + c y + d z}. @item 2-9 -Polynomials. @i{a + b x + c x^2 + d x^3}. +Polynomials. @mathit{a + b x + c x^2 + d x^3}. @item e -Exponential. @i{a} @t{exp}@i{(b x)} @t{exp}@i{(c y)}. +Exponential. @mathit{a} @t{exp}@mathit{(b x)} @t{exp}@mathit{(c y)}. @item E -Base-10 exponential. @i{a} @t{10^}@i{(b x)} @t{10^}@i{(c y)}. +Base-10 exponential. @mathit{a} @t{10^}@mathit{(b x)} @t{10^}@mathit{(c y)}. @item x -Exponential (alternate notation). @t{exp}@i{(a + b x + c y)}. +Exponential (alternate notation). @t{exp}@mathit{(a + b x + c y)}. @item X -Base-10 exponential (alternate). @t{10^}@i{(a + b x + c y)}. +Base-10 exponential (alternate). @t{10^}@mathit{(a + b x + c y)}. @item l -Logarithmic. @i{a + b} @t{ln}@i{(x) + c} @t{ln}@i{(y)}. +Logarithmic. @mathit{a + b} @t{ln}@mathit{(x) + c} @t{ln}@mathit{(y)}. @item L -Base-10 logarithmic. @i{a + b} @t{log10}@i{(x) + c} @t{log10}@i{(y)}. +Base-10 logarithmic. @mathit{a + b} @t{log10}@mathit{(x) + c} @t{log10}@mathit{(y)}. @item ^ -General exponential. @i{a b^x c^y}. +General exponential. @mathit{a b^x c^y}. @item p -Power law. @i{a x^b y^c}. +Power law. @mathit{a x^b y^c}. @item q -Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}. +Quadratic. @mathit{a + b (x-c)^2 + d (x-e)^2}. @item g -Gaussian. @c{${a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)$} -@i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}. +Gaussian. +@texline @math{{a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)}. +@infoline @mathit{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}. @end table All of these models are used in the usual way; just press the appropriate @@ -24298,12 +24617,12 @@ the parameter values from the vector that is placed in the trail.) All models except Gaussian and polynomials can generalize as shown to any number of independent variables. Also, all the built-in models have an -additive or multiplicative parameter shown as @cite{a} in the above table +additive or multiplicative parameter shown as @expr{a} in the above table which can be replaced by zero or one, as appropriate, by typing @kbd{h} before the model key. Note that many of these models are essentially equivalent, but express -the parameters slightly differently. For example, @cite{a b^x} and +the parameters slightly differently. For example, @expr{a b^x} and the other two exponential models are all algebraic rearrangements of each other. Also, the ``quadratic'' model is just a degree-2 polynomial with the parameters expressed differently. Use whichever form best @@ -24313,8 +24632,8 @@ The HP-28/48 calculators support four different models for curve fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}. These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)}, @samp{a exp(b x)}, and @samp{a x^b}, respectively. In each case, -@cite{a} is what the HP-48 identifies as the ``intercept,'' and -@cite{b} is what it calls the ``slope.'' +@expr{a} is what the HP-48 identifies as the ``intercept,'' and +@expr{b} is what it calls the ``slope.'' @tex \bigskip @@ -24325,13 +24644,13 @@ If the model you want doesn't appear on this list, press @kbd{'} formula, such as @kbd{m x - b}, as the model. (Not all models will work, though---see the next section for details.) -The model can also be an equation like @cite{y = m x + b}. +The model can also be an equation like @expr{y = m x + b}. In this case, Calc thinks of all the rows of the data matrix on equal terms; this model effectively has two parameters -(@cite{m} and @cite{b}) and two independent variables (@cite{x} -and @cite{y}), with no ``dependent'' variables. Model equations -do not need to take this @cite{y =} form. For example, the -implicit line equation @cite{a x + b y = 1} works fine as a +(@expr{m} and @expr{b}) and two independent variables (@expr{x} +and @expr{y}), with no ``dependent'' variables. Model equations +do not need to take this @expr{y =} form. For example, the +implicit line equation @expr{a x + b y = 1} works fine as a model. When you enter a model, Calc makes an alphabetical list of all @@ -24341,12 +24660,12 @@ default parameters, independent variables, and dependent variable Calc assumes the dependent variable does not appear in the formula and thus does not need a name. -For example, if the model formula has the variables @cite{a,mu,sigma,t,x}, +For example, if the model formula has the variables @expr{a,mu,sigma,t,x}, and the data matrix has three rows (meaning two independent variables), -Calc will use @cite{a,mu,sigma} as the default parameters, and the -data rows will be named @cite{t} and @cite{x}, respectively. If you -enter an equation instead of a plain formula, Calc will use @cite{a,mu} -as the parameters, and @cite{sigma,t,x} as the three independent +Calc will use @expr{a,mu,sigma} as the default parameters, and the +data rows will be named @expr{t} and @expr{x}, respectively. If you +enter an equation instead of a plain formula, Calc will use @expr{a,mu} +as the parameters, and @expr{sigma,t,x} as the three independent variables. You can, of course, override these choices by entering something @@ -24370,11 +24689,11 @@ choose which variables in the formula are independent by default and which are parameters. Models taken from the stack can also be expressed as vectors of -two or three elements, @cite{[@var{model}, @var{vars}]} or -@cite{[@var{model}, @var{vars}, @var{params}]}. Each of @var{vars} +two or three elements, @expr{[@var{model}, @var{vars}]} or +@expr{[@var{model}, @var{vars}, @var{params}]}. Each of @var{vars} and @var{params} may be either a variable or a vector of variables. (If @var{params} is omitted, all variables in @var{model} except -those listed as @var{vars} are parameters.)@refill +those listed as @var{vars} are parameters.) When you enter a model manually with @kbd{'}, Calc puts a 3-vector describing the model in the trail so you can get it back if you wish. @@ -24399,17 +24718,19 @@ Calc uses the principal values of inverse functions like @code{ln} and @code{arcsin} when doing fits. For example, when you enter the model @samp{y = sin(a t + b)} Calc actually uses the easier form @samp{arcsin(y) = a t + b}. The @code{arcsin} function always -returns results in the range from @i{-90} to 90 degrees (or the +returns results in the range from @mathit{-90} to 90 degrees (or the equivalent range in radians). Suppose you had data that you believed to represent roughly three oscillations of a sine wave, -so that the argument of the sine might go from zero to @c{$3\times360$} -@i{3*360} degrees. +so that the argument of the sine might go from zero to +@texline @math{3\times360} +@infoline @mathit{3*360} +degrees. The above model would appear to be a good way to determine the true frequency and phase of the sine wave, but in practice it would fail utterly. The righthand side of the actual model -@samp{arcsin(y) = a t + b} will grow smoothly with @cite{t}, but -the lefthand side will bounce back and forth between @i{-90} and 90. -No values of @cite{a} and @cite{b} can make the two sides match, +@samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but +the lefthand side will bounce back and forth between @mathit{-90} and 90. +No values of @expr{a} and @expr{b} can make the two sides match, even approximately. There is no good solution to this problem at present. You could @@ -24426,14 +24747,14 @@ taking Fourier and related transforms.) @noindent Calc's internal least-squares fitter can only handle multilinear models. More precisely, it can handle any model of the form -@cite{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @cite{a,b,c} -are the parameters and @cite{x,y,z} are the independent variables +@expr{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @expr{a,b,c} +are the parameters and @expr{x,y,z} are the independent variables (of course there can be any number of each, not just three). In a simple multilinear or polynomial fit, it is easy to see how to convert the model into this form. For example, if the model -is @cite{a + b x + c x^2}, then @cite{f(x) = 1}, @cite{g(x) = x}, -and @cite{h(x) = x^2} are suitable functions. +is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x}, +and @expr{h(x) = x^2} are suitable functions. For other models, Calc uses a variety of algebraic manipulations to try to put the problem into the form @@ -24443,15 +24764,15 @@ Y(x,y,z) = A(a,b,c) F(x,y,z) + B(a,b,c) G(x,y,z) + C(a,b,c) H(x,y,z) @end smallexample @noindent -where @cite{Y,A,B,C,F,G,H} are arbitrary functions. It computes -@cite{Y}, @cite{F}, @cite{G}, and @cite{H} for all the data points, -does a standard linear fit to find the values of @cite{A}, @cite{B}, -and @cite{C}, then uses the equation solver to solve for @cite{a,b,c} -in terms of @cite{A,B,C}. +where @expr{Y,A,B,C,F,G,H} are arbitrary functions. It computes +@expr{Y}, @expr{F}, @expr{G}, and @expr{H} for all the data points, +does a standard linear fit to find the values of @expr{A}, @expr{B}, +and @expr{C}, then uses the equation solver to solve for @expr{a,b,c} +in terms of @expr{A,B,C}. A remarkable number of models can be cast into this general form. We'll look at two examples here to see how it works. The power-law -model @cite{y = a x^b} with two independent variables and two parameters +model @expr{y = a x^b} with two independent variables and two parameters can be rewritten as follows: @example @@ -24462,15 +24783,19 @@ ln(y) = ln(a) + b ln(x) @end example @noindent -which matches the desired form with @c{$Y = \ln(y)$} -@cite{Y = ln(y)}, @c{$A = \ln(a)$} -@cite{A = ln(a)}, -@cite{F = 1}, @cite{B = b}, and @c{$G = \ln(x)$} -@cite{G = ln(x)}. Calc thus computes -the logarithms of your @cite{y} and @cite{x} values, does a linear fit -for @cite{A} and @cite{B}, then solves to get @c{$a = \exp(A)$} -@cite{a = exp(A)} and -@cite{b = B}. +which matches the desired form with +@texline @math{Y = \ln(y)}, +@infoline @expr{Y = ln(y)}, +@texline @math{A = \ln(a)}, +@infoline @expr{A = ln(a)}, +@expr{F = 1}, @expr{B = b}, and +@texline @math{G = \ln(x)}. +@infoline @expr{G = ln(x)}. +Calc thus computes the logarithms of your @expr{y} and @expr{x} values, +does a linear fit for @expr{A} and @expr{B}, then solves to get +@texline @math{a = \exp(A)} +@infoline @expr{a = exp(A)} +and @expr{b = B}. Another interesting example is the ``quadratic'' model, which can be handled by expanding according to the distributive law. @@ -24481,27 +24806,27 @@ y = a + b c^2 - 2 b c x + b x^2 @end example @noindent -which matches with @cite{Y = y}, @cite{A = a + b c^2}, @cite{F = 1}, -@cite{B = -2 b c}, @cite{G = x} (the @i{-2} factor could just as easily -have been put into @cite{G} instead of @cite{B}), @cite{C = b}, and -@cite{H = x^2}. +which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1}, +@expr{B = -2 b c}, @expr{G = x} (the @mathit{-2} factor could just as easily +have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and +@expr{H = x^2}. The Gaussian model looks quite complicated, but a closer examination shows that it's actually similar to the quadratic model but with an -exponential that can be brought to the top and moved into @cite{Y}. +exponential that can be brought to the top and moved into @expr{Y}. An example of a model that cannot be put into general linear form is a Gaussian with a constant background added on, i.e., -@cite{d} + the regular Gaussian formula. If you have a model like +@expr{d} + the regular Gaussian formula. If you have a model like this, your best bet is to replace enough of your parameters with constants to make the model linearizable, then adjust the constants 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-@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. +Gaussian-plus-@var{d} model can be linearized by setting @expr{d} +(the background) to a constant, or by setting @expr{b} (the standard +deviation) and @expr{c} (the mean) to constants. To fit a model with constants substituted for some parameters, just store suitable values in those parameter variables, then omit them @@ -24513,8 +24838,9 @@ from the list of parameters when you answer the variables prompt. A last desperate step would be to use the general-purpose @code{minimize} function rather than @code{fit}. After all, both -functions solve the problem of minimizing an expression (the @c{$\chi^2$} -@cite{chi^2} +functions solve the problem of minimizing an expression (the +@texline @math{\chi^2} +@infoline @expr{chi^2} sum) by adjusting certain parameters in the expression. The @kbd{a F} command is able to use a vastly more efficient algorithm due to its special knowledge about linear chi-square sums, but the @kbd{a N} @@ -24523,9 +24849,10 @@ command can do the same thing by brute force. A compromise would be to pick out a few parameters without which the fit is linearizable, and use @code{minimize} on a call to @code{fit} which efficiently takes care of the rest of the parameters. The thing -to be minimized would be the value of @c{$\chi^2$} -@cite{chi^2} returned as -the fifth result of the @code{xfit} function: +to be minimized would be the value of +@texline @math{\chi^2} +@infoline @expr{chi^2} +returned as the fifth result of the @code{xfit} function: @smallexample minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) @@ -24534,7 +24861,7 @@ minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) @noindent where @code{gaus} represents the Gaussian model with background, @code{data} represents the data matrix, and @code{guess} represents -the initial guess for @cite{d} that @code{minimize} requires. +the initial guess for @expr{d} that @code{minimize} requires. This operation will only be, shall we say, extraordinarily slow rather than astronomically slow (as would be the case if @code{minimize} were used by itself to solve the problem). @@ -24545,17 +24872,17 @@ were used by itself to solve the problem). The @kbd{I a F} [@code{xfit}] command is somewhat trickier when nonlinear models are used. The second item in the result is the -vector of ``raw'' parameters @cite{A}, @cite{B}, @cite{C}. The +vector of ``raw'' parameters @expr{A}, @expr{B}, @expr{C}. The covariance matrix is written in terms of those raw parameters. The fifth item is a vector of @dfn{filter} expressions. This is the empty vector @samp{[]} if the raw parameters were the same -as the requested parameters, i.e., if @cite{A = a}, @cite{B = b}, +as the requested parameters, i.e., if @expr{A = a}, @expr{B = b}, and so on (which is always true if the model is already linear in the parameters as written, e.g., for polynomial fits). If the parameters had to be rearranged, the fifth item is instead a vector of one formula per parameter in the original model. The raw parameters are expressed in these ``filter'' formulas as -@samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} for @cite{B}, +@samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} for @expr{B}, and so on. When Calc needs to modify the model to return the result, it replaces @@ -24575,30 +24902,33 @@ figure out how to interpret the covariances in the presence of nontrivial filter functions. Things are also complicated when the input contains error forms. -Suppose there are three independent and dependent variables, @cite{x}, -@cite{y}, and @cite{z}, one or more of which are error forms in the +Suppose there are three independent and dependent variables, @expr{x}, +@expr{y}, and @expr{z}, one or more of which are error forms in the data. Calc combines all the error values by taking the square root -of the sum of the squares of the errors. It then changes @cite{x} -and @cite{y} to be plain numbers, and makes @cite{z} into an error -form with this combined error. The @cite{Y(x,y,z)} part of the +of the sum of the squares of the errors. It then changes @expr{x} +and @expr{y} to be plain numbers, and makes @expr{z} into an error +form with this combined error. The @expr{Y(x,y,z)} part of the linearized model is evaluated, and the result should be an error -form. The error part of that result is used for @c{$\sigma_i$} -@cite{sigma_i} for -the data point. If for some reason @cite{Y(x,y,z)} does not return -an error form, the combined error from @cite{z} is used directly -for @c{$\sigma_i$} -@cite{sigma_i}. Finally, @cite{z} is also stripped of its error -for use in computing @cite{F(x,y,z)}, @cite{G(x,y,z)} and so on; +form. The error part of that result is used for +@texline @math{\sigma_i} +@infoline @expr{sigma_i} +for the data point. If for some reason @expr{Y(x,y,z)} does not return +an error form, the combined error from @expr{z} is used directly for +@texline @math{\sigma_i}. +@infoline @expr{sigma_i}. +Finally, @expr{z} is also stripped of its error +for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on; the righthand side of the linearized model is computed in regular arithmetic with no error forms. (While these rules may seem complicated, they are designed to do -the most reasonable thing in the typical case that @cite{Y(x,y,z)} -depends only on the dependent variable @cite{z}, and in fact is -often simply equal to @cite{z}. For common cases like polynomials +the most reasonable thing in the typical case that @expr{Y(x,y,z)} +depends only on the dependent variable @expr{z}, and in fact is +often simply equal to @expr{z}. For common cases like polynomials and multilinear models, the combined error is simply used as the -@c{$\sigma$} -@cite{sigma} for the data point with no further ado.) +@texline @math{\sigma} +@infoline @expr{sigma} +for the data point with no further ado.) @tex \bigskip @@ -24655,7 +24985,7 @@ Parameter variables are renamed to function calls @samp{fitparam(1)}, @samp{fitparam(2)}, and so on, and independent variables are renamed 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 +model @expr{a x^b} is converted to @expr{y = a x^b}, then to @smallexample @group @@ -24675,11 +25005,11 @@ fitsystem(@var{Y}, @var{FGH}, @var{abc}) @end example @noindent -where @var{Y} is a formula that describes the function @cite{Y(x,y,z)}, -@var{FGH} is the vector of formulas @cite{[F(x,y,z), G(x,y,z), H(x,y,z)]}, +where @var{Y} is a formula that describes the function @expr{Y(x,y,z)}, +@var{FGH} is the vector of formulas @expr{[F(x,y,z), G(x,y,z), H(x,y,z)]}, and @var{abc} is the vector of parameter filters which refer to the -raw parameters as @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} -for @cite{B}, etc. While the number of raw parameters (the length of +raw parameters as @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} +for @expr{B}, etc. While the number of raw parameters (the length of the @var{FGH} vector) is usually the same as the number of original parameters (the length of the @var{abc} vector), this is not required. @@ -24702,7 +25032,7 @@ be put into @var{abc} or @var{FGH}). In particular, all non-constant powers are converted to logs-and-exponentials form, and the distributive law is used to expand products of sums. Quotients are rewritten to use the @samp{fitinv} function, where -@samp{fitinv(x)} represents @cite{1/x} while the @code{FitRules} +@samp{fitinv(x)} represents @expr{1/x} while the @code{FitRules} are operating. (The use of @code{fitinv} makes recognition of linear-looking forms easier.) If you modify @code{FitRules}, you will probably only need to modify the rules for this phase. @@ -24710,8 +25040,8 @@ will probably only need to modify the rules for this phase. Phase two, whose rules can actually also apply during phases one and three, first rewrites @code{fitmodel} to a two-argument form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is -initially zero and @var{model} has been changed from @cite{a=b} -to @cite{a-b} form. It then tries to peel off invertible functions +initially zero and @var{model} has been changed from @expr{a=b} +to @expr{a-b} form. It then tries to peel off invertible functions from the outside of @var{model} and put them into @var{Y} instead, calling the equation solver to invert the functions. Finally, when this is no longer possible, the @code{fitmodel} is changed to a @@ -24757,7 +25087,7 @@ least-squares solver wants to see. @tindex hasfitvars Two functions which are useful in connection with @code{FitRules} are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check -whether @cite{x} refers to any parameters or independent variables, +whether @expr{x} refers to any parameters or independent variables, respectively. Specifically, these functions return ``true'' if the argument contains any @code{fitparam} (or @code{fitvar}) function calls, and ``false'' otherwise. (Recall that ``true'' means a @@ -24805,48 +25135,48 @@ The @code{efit} (corresponding to @kbd{H a F}) and @code{xfit} @pindex calc-poly-interp @tindex polint The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does -a polynomial interpolation at a particular @cite{x} value. It takes +a polynomial interpolation at a particular @expr{x} value. It takes two arguments from the stack: A data matrix of the sort used by -@kbd{a F}, and a single number which represents the desired @cite{x} +@kbd{a F}, and a single number which represents the desired @expr{x} value. Calc effectively does an exact polynomial fit as if by @kbd{a F i}, -then substitutes the @cite{x} value into the result in order to get an -approximate @cite{y} value based on the fit. (Calc does not actually +then substitutes the @expr{x} value into the result in order to get an +approximate @expr{y} value based on the fit. (Calc does not actually use @kbd{a F i}, however; it uses a direct method which is both more efficient and more numerically stable.) -The result of @kbd{a p} is actually a vector of two values: The @cite{y} -value approximation, and an error measure @cite{dy} that reflects Calc's +The result of @kbd{a p} is actually a vector of two values: The @expr{y} +value approximation, and an error measure @expr{dy} that reflects Calc's estimation of the probable error of the approximation at that value of -@cite{x}. If the input @cite{x} is equal to any of the @cite{x} values -in the data matrix, the output @cite{y} will be the corresponding @cite{y} -value from the matrix, and the output @cite{dy} will be exactly zero. +@expr{x}. If the input @expr{x} is equal to any of the @expr{x} values +in the data matrix, the output @expr{y} will be the corresponding @expr{y} +value from the matrix, and the output @expr{dy} will be exactly zero. A prefix argument of 2 causes @kbd{a p} to take separate x- and y-vectors from the stack instead of one data matrix. -If @cite{x} is a vector of numbers, @kbd{a p} will return a matrix of -interpolated results for each of those @cite{x} values. (The matrix will -have two columns, the @cite{y} values and the @cite{dy} values.) -If @cite{x} is a formula instead of a number, the @code{polint} function +If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of +interpolated results for each of those @expr{x} values. (The matrix will +have two columns, the @expr{y} values and the @expr{dy} values.) +If @expr{x} is a formula instead of a number, the @code{polint} function remains in symbolic form; use the @kbd{a "} command to expand it out to a formula that describes the fit in symbolic terms. In all cases, the @kbd{a p} command leaves the data vectors or matrix -on the stack. Only the @cite{x} value is replaced by the result. +on the stack. Only the @expr{x} value is replaced by the result. @kindex H a p @tindex ratint The @kbd{H a p} [@code{ratint}] command does a rational function interpolation. It is used exactly like @kbd{a p}, except that it uses as its model the quotient of two polynomials. If there are -@cite{N} data points, the numerator and denominator polynomials will -each have degree @cite{N/2} (if @cite{N} is odd, the denominator will +@expr{N} data points, the numerator and denominator polynomials will +each have degree @expr{N/2} (if @expr{N} is odd, the denominator will have degree one higher than the numerator). Rational approximations have the advantage that they can accurately describe functions that have poles (points at which the function's value goes to infinity, so that the denominator polynomial of the approximation -goes to zero). If @cite{x} corresponds to a pole of the fitted rational +goes to zero). If @expr{x} corresponds to a pole of the fitted rational function, then the result will be a division by zero. If Infinite mode is enabled, the result will be @samp{[uinf, uinf]}. @@ -24880,9 +25210,9 @@ $$ \sum_{k=1}^5 k^2 = 55 $$ The choice of index variable is arbitrary, but it's best not to use a variable with a stored value. In particular, while @code{i} is often a favorite index variable, it should be avoided -in Calc because @code{i} has the imaginary constant @cite{(0, 1)} +in Calc because @code{i} has the imaginary constant @expr{(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)}! +be changed to a nonsensical sum over the ``variable'' @expr{(0, 1)}! If you really want to use @code{i} as an index variable, use @w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable. (@xref{Storing Variables}.) @@ -24916,7 +25246,7 @@ is one. If @var{low} is also omitted, the limits are @samp{-inf} and @samp{inf}, respectively. Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)} -returns @cite{1}. This is done by evaluating the sum in closed +returns @expr{1}. This is done by evaluating the sum in closed form (to @samp{1. - 0.5^n} in this case), then evaluating this formula with @code{n} set to @code{inf}. Calc's usual rules for ``infinite'' arithmetic can find the answer from there. If @@ -24950,35 +25280,36 @@ If the lower limit is greater than the upper limit (assuming a positive step size), the result is generally zero. However, Calc only guarantees a zero result when the upper limit is exactly one step less than the lower limit, i.e., if the number -of iterations is @i{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero +of iterations is @mathit{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero but the sum from @samp{n} to @samp{n-2} may report a nonzero value if Calc used a closed form solution. -Calc's logical predicates like @cite{a < b} return 1 for ``true'' +Calc's logical predicates like @expr{a < b} return 1 for ``true'' and 0 for ``false.'' @xref{Logical Operations}. This can be used to advantage for building conditional sums. For example, @samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all prime numbers from 1 to 20; the @code{prime} predicate returns 1 if its argument is prime and 0 otherwise. You can read this expression -as ``the sum of @cite{k^2}, where @cite{k} is prime.'' Indeed, +as ``the sum of @expr{k^2}, where @expr{k} is prime.'' Indeed, @samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes squared, since the limits default to plus and minus infinity, but there are no such sums that Calc's built-in rules can do in closed form. As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the -sum of @cite{f(k)} for all @cite{k} from 1 to @cite{n}, excluding -one value @cite{k_0}. Slightly more tricky is the summand +sum of @expr{f(k)} for all @expr{k} from 1 to @expr{n}, excluding +one value @expr{k_0}. Slightly more tricky is the summand @samp{(k != k_0) / (k - k_0)}, which is an attempt to describe -the sum of all @cite{1/(k-k_0)} except at @cite{k = k_0}, where -this would be a division by zero. But at @cite{k = k_0}, this -formula works out to the indeterminate form @cite{0 / 0}, which +the sum of all @expr{1/(k-k_0)} except at @expr{k = k_0}, where +this would be a division by zero. But at @expr{k = k_0}, this +formula works out to the indeterminate form @expr{0 / 0}, which Calc will not assume is zero. Better would be to use @samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does -an ``if-then-else'' test: This expression says, ``if @c{$k \ne k_0$} -@cite{k != k_0}, -then @cite{1/(k-k_0)}, else zero.'' Now the formula @cite{1/(k-k_0)} -will not even be evaluated by Calc when @cite{k = k_0}. +an ``if-then-else'' test: This expression says, ``if +@texline @math{k \ne k_0}, +@infoline @expr{k != k_0}, +then @expr{1/(k-k_0)}, else zero.'' Now the formula @expr{1/(k-k_0)} +will not even be evaluated by Calc when @expr{k = k_0}. @cindex Alternating sums @kindex a - @@ -25029,7 +25360,7 @@ for which @code{dnonzero} returns 1 is ``true,'' and anything for which @code{dnonzero} returns 0 or cannot decide is assumed ``false.'' Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then'' portion if its condition is provably true, but it will execute the -``else'' portion for any condition like @cite{a = b} that is not +``else'' portion for any condition like @expr{a = b} that is not provably true, even if it might be true. Algebraic functions that have conditions as arguments, like @code{? :} and @code{&&}, remain unevaluated if the condition is neither provably true nor provably @@ -25042,10 +25373,10 @@ false. @xref{Declarations}.) @tindex == The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function (which can also be written @samp{a = b} or @samp{a == b} in an algebraic -formula) is true if @cite{a} and @cite{b} are equal, either because they +formula) is true if @expr{a} and @expr{b} are equal, either because they are identical expressions, or because they are numbers which are numerically equal. (Thus the integer 1 is considered equal to the float -1.0.) If the equality of @cite{a} and @cite{b} cannot be determined, +1.0.) If the equality of @expr{a} and @expr{b} cannot be determined, the comparison is left in symbolic form. Note that as a command, this operation pops two values from the stack and pushes back either a 1 or a 0, or a formula @samp{a = b} if the values' equality cannot be determined. @@ -25073,9 +25404,9 @@ variables). @tindex neq @tindex != The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or -@samp{a != b} function, is true if @cite{a} and @cite{b} are not equal. +@samp{a != b} function, is true if @expr{a} and @expr{b} are not equal. This also works with more than two arguments; @samp{a != b != c != d} -tests that all four of @cite{a}, @cite{b}, @cite{c}, and @cite{d} are +tests that all four of @expr{a}, @expr{b}, @expr{c}, and @expr{d} are distinct numbers. @kindex a < @@ -25125,7 +25456,7 @@ distinct numbers. @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 +operation is true if @expr{a} is less than @expr{b}. Similar functions are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}], @kbd{a [} (@code{calc-less-equal}) [@samp{leq(a,b)} or @samp{a <= b}], and @kbd{a ]} (@code{calc-greater-equal}) [@samp{geq(a,b)} or @samp{a >= b}]. @@ -25159,8 +25490,8 @@ taking the lefthand side. @tindex && The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}] function is true if both of its arguments are true, i.e., are -non-zero numbers. In this case, the result will be either @cite{a} or -@cite{b}, chosen arbitrarily. If either argument is zero, the result is +non-zero numbers. In this case, the result will be either @expr{a} or +@expr{b}, chosen arbitrarily. If either argument is zero, the result is zero. Otherwise, the formula is left in symbolic form. @kindex a | @@ -25170,7 +25501,7 @@ zero. Otherwise, the formula is left in symbolic form. The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}] function is true if either or both of its arguments are true (nonzero). The result is whichever argument was nonzero, choosing arbitrarily if both -are nonzero. If both @cite{a} and @cite{b} are zero, the result is +are nonzero. If both @expr{a} and @expr{b} are zero, the result is zero. @kindex a ! @@ -25178,8 +25509,8 @@ zero. @tindex lnot @tindex ! The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}] -function is true if @cite{a} is false (zero), or false if @cite{a} is -true (nonzero). It is left in symbolic form if @cite{a} is not a +function is true if @expr{a} is false (zero), or false if @expr{a} is +true (nonzero). It is left in symbolic form if @expr{a} is not a number. @kindex a : @@ -25195,9 +25526,9 @@ number. @tindex : @cindex Arguments, not evaluated The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}] -function is equal to either @cite{b} or @cite{c} if @cite{a} is a nonzero -number or zero, respectively. If @cite{a} is not a number, the test is -left in symbolic form and neither @cite{b} nor @cite{c} is evaluated in +function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero +number or zero, respectively. If @expr{a} is not a number, the test is +left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in any way. In algebraic formulas, this is one of the few Calc functions whose arguments are not automatically evaluated when the function itself is evaluated. The others are @code{lambda}, @code{quote}, and @@ -25208,24 +25539,24 @@ will not work because the @samp{3:4} is parsed as a fraction instead of as three separate symbols. Type something like @samp{a ? 3 : 4} or @samp{a?(3):4} instead. -As a special case, if @cite{a} evaluates to a vector, then both @cite{b} -and @cite{c} are evaluated; the result is a vector of the same length -as @cite{a} whose elements are chosen from corresponding elements of -@cite{b} and @cite{c} according to whether each element of @cite{a} -is zero or nonzero. Each of @cite{b} and @cite{c} must be either a -vector of the same length as @cite{a}, or a non-vector which is matched -with all elements of @cite{a}. +As a special case, if @expr{a} evaluates to a vector, then both @expr{b} +and @expr{c} are evaluated; the result is a vector of the same length +as @expr{a} whose elements are chosen from corresponding elements of +@expr{b} and @expr{c} according to whether each element of @expr{a} +is zero or nonzero. Each of @expr{b} and @expr{c} must be either a +vector of the same length as @expr{a}, or a non-vector which is matched +with all elements of @expr{a}. @kindex a @{ @pindex calc-in-set @tindex in The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if -the number @cite{a} is in the set of numbers represented by @cite{b}. -If @cite{b} is an interval form, @cite{a} must be one of the values -encompassed by the interval. If @cite{b} is a vector, @cite{a} must be +the number @expr{a} is in the set of numbers represented by @expr{b}. +If @expr{b} is an interval form, @expr{a} must be one of the values +encompassed by the interval. If @expr{b} is a vector, @expr{a} must be equal to one of the elements of the vector. (If any vector elements are -intervals, @cite{a} must be in any of the intervals.) If @cite{b} is a -plain number, @cite{a} must be numerically equal to @cite{b}. +intervals, @expr{a} must be in any of the intervals.) If @expr{b} is a +plain number, @expr{a} must be numerically equal to @expr{b}. @xref{Set Operations}, for a group of commands that manipulate sets of this sort. @@ -25234,7 +25565,7 @@ of this sort. @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, +characterizes @expr{a}. If @expr{a} is a number, vector, or variable, the result will be one of the following numbers: @example @@ -25255,7 +25586,7 @@ the result will be one of the following numbers: 102 Matrix @end example -Otherwise, @cite{a} is a formula, and the result is a variable which +Otherwise, @expr{a} is a formula, and the result is a variable which represents the name of the top-level function call. @ignore @@ -25270,15 +25601,15 @@ represents the name of the top-level function call. @starindex @end ignore @tindex constant -The @samp{integer(a)} function returns true if @cite{a} is an integer. +The @samp{integer(a)} function returns true if @expr{a} is an integer. The @samp{real(a)} function -is true if @cite{a} is a real number, either integer, fraction, or -float. The @samp{constant(a)} function returns true if @cite{a} is +is true if @expr{a} is a real number, either integer, fraction, or +float. The @samp{constant(a)} function returns true if @expr{a} is any of the objects for which @code{typeof} would produce an integer code result except for variables, and provided that the components of an object like a vector or error form are themselves constant. Note that infinities do not satisfy any of these tests, nor do -special constants like @code{pi} and @code{e}.@refill +special constants like @code{pi} and @code{e}. @xref{Declarations}, for a set of similar functions that recognize formulas as well as actual numbers. For example, @samp{dint(floor(x))} @@ -25291,21 +25622,21 @@ literally an integer constant. @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 +@expr{b} appears in @expr{a}, or false otherwise. Unlike the other tests described here, this function returns a definite ``no'' answer 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}). +@code{refers} will be left unevaluated is if @expr{a} is a plain +variable (different from @expr{b}). @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}, +The @samp{negative(a)} function returns true if @expr{a} ``looks'' negative, +because it is a negative number, because it is of the form @expr{-x}, or because it is a product or quotient with a term that looks negative. This is most useful in rewrite rules. Beware that @samp{negative(a)} -evaluates to 1 or 0 for @emph{any} argument @cite{a}, so it can only +evaluates to 1 or 0 for @emph{any} argument @expr{a}, so it can only 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). @@ -25314,8 +25645,8 @@ as a rewrite rule condition). @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 +The @samp{variable(a)} function is true if @expr{a} is a variable, +or false if not. If @expr{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. @@ -25323,7 +25654,7 @@ are considered variables like any others by this test. @starindex @end ignore @tindex nonvar -The @samp{nonvar(a)} function is true if @cite{a} is a non-variable. +The @samp{nonvar(a)} function is true if @expr{a} is a non-variable. If its argument is a variable it is left unsimplified; it never actually returns zero. However, since Calc's condition-testing commands consider ``false'' anything not provably true, this is @@ -25348,15 +25679,15 @@ often good enough. @cindex Linearity testing The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt} check if an expression is ``linear,'' i.e., can be written in the form -@cite{a + b x} for some constants @cite{a} and @cite{b}, and some -variable or subformula @cite{x}. The function @samp{islin(f,x)} checks -if formula @cite{f} is linear in @cite{x}, returning 1 if so. For +@expr{a + b x} for some constants @expr{a} and @expr{b}, and some +variable or subformula @expr{x}. The function @samp{islin(f,x)} checks +if formula @expr{f} is linear in @expr{x}, returning 1 if so. For example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and @samp{islin(x y / 3 - 2, x)} all return 1. The @samp{lin(f,x)} function is similar, except that instead of returning 1 it returns the vector -@cite{[a, b, x]}. For the above examples, this vector would be -@cite{[0, 1, x]}, @cite{[0, -1, x]}, @cite{[3, 0, x]}, and -@cite{[-2, y/3, x]}, respectively. Both @code{lin} and @code{islin} +@expr{[a, b, x]}. For the above examples, this vector would be +@expr{[0, 1, x]}, @expr{[0, -1, x]}, @expr{[3, 0, x]}, and +@expr{[-2, y/3, x]}, respectively. Both @code{lin} and @code{islin} generally remain unevaluated for expressions which are not linear, e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))} @@ -25364,19 +25695,19 @@ returns true. The @code{linnt} and @code{islinnt} functions perform a similar check, but require a ``non-trivial'' linear form, which means that the -@cite{b} coefficient must be non-zero. For example, @samp{lin(2,x)} -returns @cite{[2, 0, x]} and @samp{lin(y,x)} returns @cite{[y, 0, x]}, +@expr{b} coefficient must be non-zero. For example, @samp{lin(2,x)} +returns @expr{[2, 0, x]} and @samp{lin(y,x)} returns @expr{[y, 0, x]}, but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated (in other words, these formulas are considered to be only ``trivially'' -linear in @cite{x}). +linear in @expr{x}). All four linearity-testing functions allow you to omit the second argument, in which case the input may be linear in any non-constant -formula. Here, the @cite{a=0}, @cite{b=1} case is also considered -trivial, and only constant values for @cite{a} and @cite{b} are -recognized. Thus, @samp{lin(2 x y)} returns @cite{[0, 2, x y]}, -@samp{lin(2 - x y)} returns @cite{[2, -1, x y]}, and @samp{lin(x y)} -returns @cite{[0, 1, x y]}. The @code{linnt} function would allow the +formula. Here, the @expr{a=0}, @expr{b=1} case is also considered +trivial, and only constant values for @expr{a} and @expr{b} are +recognized. Thus, @samp{lin(2 x y)} returns @expr{[0, 2, x y]}, +@samp{lin(2 - x y)} returns @expr{[2, -1, x y]}, and @samp{lin(x y)} +returns @expr{[0, 1, x y]}. The @code{linnt} function would allow the 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. @@ -25385,8 +25716,8 @@ case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false. @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. +The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero +number or provably nonzero formula, or 0 if @expr{a} is anything else. Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is used to make sure they are not evaluated prematurely. (Note that declarations are used when deciding whether a formula is true; @@ -25446,7 +25777,7 @@ This operator is equivalent to the function call @samp{assign(old, new)}. The @code{assign} function is undefined by itself in Calc, so an assignment formula such as a rewrite rule will be left alone by ordinary Calc commands. But certain commands, like the rewrite system, interpret -assignments in special ways.@refill +assignments in special ways. For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace every occurrence of the sine of something, squared, with one minus the @@ -25489,7 +25820,7 @@ invoke them by giving the variable name. The @kbd{s e} (@code{calc-edit-variable}) command is an easy way to create or edit a rule set stored in a variable. You may also wish to use @kbd{s p} (@code{calc-permanent-variable}) to save your rules permanently; -@pxref{Operations on Variables}.@refill +@pxref{Operations on Variables}. Rewrite rules are compiled into a special internal form for faster matching. If you enter a rule set directly it must be recompiled @@ -25506,10 +25837,10 @@ vector of two rules, the use of this notation is no longer recommended. @subsection Basic Rewrite Rules @noindent -To match a particular formula @cite{x} with a particular rewrite rule -@samp{@var{old} := @var{new}}, Calc compares the structure of @cite{x} with +To match a particular formula @expr{x} with a particular rewrite rule +@samp{@var{old} := @var{new}}, Calc compares the structure of @expr{x} with the structure of @var{old}. Variables that appear in @var{old} are -treated as @dfn{meta-variables}; the corresponding positions in @cite{x} +treated as @dfn{meta-variables}; the corresponding positions in @expr{x} may contain any sub-formulas. For example, the pattern @samp{f(x,y)} would match the expression @samp{f(12, a+1)} with the meta-variable @samp{x} corresponding to 12 and with @samp{y} corresponding to @@ -25519,7 +25850,7 @@ that will make the pattern match these expressions. Notice that if the pattern is a single meta-variable, it will match any expression. If a given meta-variable appears more than once in @var{old}, the -corresponding sub-formulas of @cite{x} must be identical. Thus +corresponding sub-formulas of @expr{x} must be identical. Thus the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and @samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}. (@xref{Conditional Rewrite Rules}, for a way to match the latter.) @@ -25563,14 +25894,14 @@ number or any other object known to be nonzero (@pxref{Declarations}), the rule is accepted. If the result is zero or if it is a symbolic formula that is not known to be nonzero, the rule is rejected. @xref{Logical Operations}, for a number of functions that return -1 or 0 according to the results of various tests.@refill +1 or 0 according to the results of various tests. -For example, the formula @samp{n > 0} simplifies to 1 or 0 if @cite{n} +For example, the formula @samp{n > 0} simplifies to 1 or 0 if @expr{n} is replaced by a positive or nonpositive number, respectively (or if -@cite{n} has been declared to be positive or nonpositive). Thus, +@expr{n} has been declared to be positive or nonpositive). Thus, the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to @samp{f(0, 4)} but not to @samp{f(-3, 2)} or @samp{f(12, a+1)} -(assuming no outstanding declarations for @cite{a}). In the case of +(assuming no outstanding declarations for @expr{a}). In the case of @samp{f(-3, 2)}, the condition can be shown not to be satisfied; in the case of @samp{f(12, a+1)}, the condition merely cannot be shown to be satisfied, but that is enough to reject the rule. @@ -25600,12 +25931,12 @@ decides when it is best to test each condition while a rule is being matched. Certain conditions are handled as special cases by the rewrite rule -system and are tested very efficiently: Where @cite{x} is any +system and are tested very efficiently: Where @expr{x} is any meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)}, -@samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @cite{y} +@samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @expr{y} is either a constant or another meta-variable and @samp{>=} may be replaced by any of the six relational operators, and @samp{x % a = b} -where @cite{a} and @cite{b} are constants. Other conditions, like +where @expr{a} and @expr{b} are constants. Other conditions, like @samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check since Calc must bring the whole evaluator and simplifier into play. @@ -25680,12 +26011,12 @@ like @samp{(x + y) + (z - w)}, are not tried. Note that @samp{*} is not commutative when applied to matrices, but rewrite rules pretend that it is. If you type @kbd{m v} to enable -matrix mode (@pxref{Matrix Mode}), rewrite rules will match @samp{*} +Matrix mode (@pxref{Matrix Mode}), rewrite rules will match @samp{*} literally, ignoring its usual commutativity property. (In the current implementation, the associativity also vanishes---it is as if the pattern had been enclosed in a @code{plain} marker; see below.) If you are applying rewrites to formulas with matrices, it's best to -enable matrix mode first to prevent algebraically incorrect rewrites +enable Matrix mode first to prevent algebraically incorrect rewrites from occurring. The pattern @samp{-x} will actually match any expression. For example, @@ -25814,7 +26145,7 @@ are linear in @samp{x}. You can also use the @code{lin} and @code{islin} functions with rewrite conditions to test for this; @pxref{Logical Operations}. These functions are not as convenient to use in rewrite rules, but they recognize more kinds of formulas as linear: -@samp{x/z} is considered linear with @cite{b = 1/z} by @code{lin}, +@samp{x/z} is considered linear with @expr{b = 1/z} by @code{lin}, but it will not match the above pattern because that pattern calls for a multiplication, not a division. @@ -25834,7 +26165,7 @@ opt(a) sin(x)^2 + opt(a) cos(x)^2 := a @end example Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2} -because one @cite{a} would have ``matched'' 1 while the other matched 6. +because one @expr{a} would have ``matched'' 1 while the other matched 6. Calc automatically converts a rule like @@ -25982,20 +26313,25 @@ work in the righthand side of a rule. @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 +rule. Here @expr{x} is the name of a variable containing another rule set; those rules are ``spliced into'' the rule set that imports them. For example, if @samp{[f(a+b) := f(a) + f(b), f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, then the rule set @samp{[f(0) := 0, import(linearF)]} will apply all three rules. It is possible to modify the imported rules slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports -the rule set @cite{x} with all occurrences of @c{$v_1$} -@cite{v1}, as either -a variable name or a function name, replaced with @c{$x_1$} -@cite{x1} and -so on. (If @c{$v_1$} -@cite{v1} is used as a function name, then @c{$x_1$} -@cite{x1} +the rule set @expr{x} with all occurrences of +@texline @math{v_1}, +@infoline @expr{v1}, +as either a variable name or a function name, replaced with +@texline @math{x_1} +@infoline @expr{x1} +and so on. (If +@texline @math{v_1} +@infoline @expr{v1} +is used as a function name, then +@texline @math{x_1} +@infoline @expr{x1} must be either a function name itself or a @w{@samp{< >}} nameless function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, import(linearF, f, g)]} applies the linearity rules to the function @@ -26010,7 +26346,7 @@ The special functions allowed in patterns are: @starindex @end ignore @tindex quote -This pattern matches exactly @cite{x}; variable names in @cite{x} are +This pattern matches exactly @expr{x}; variable names in @expr{x} are not interpreted as meta-variables. The only flexibility is that numbers are compared for numeric equality, so that the pattern @samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}. @@ -26024,10 +26360,10 @@ as a result in this case.) @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 +Here @expr{x} must be a function call @samp{f(x1,x2,@dots{})}. This +pattern matches a call to function @expr{f} with the specified argument patterns. No special knowledge of the properties of the -function @cite{f} is used in this case; @samp{+} is not commutative or +function @expr{f} is used in this case; @samp{+} is not commutative or associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}} are treated as patterns. If you wish them to be treated ``plainly'' as well, you must enclose them with more @code{plain} markers: @@ -26038,24 +26374,24 @@ as well, you must enclose them with more @code{plain} markers: @starindex @end ignore @tindex opt -Here @cite{x} must be a variable name. This must appear as an +Here @expr{x} must be a variable name. This must appear as an argument to a function or an element of a vector; it specifies that the argument or element is optional. As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||}, or as the second argument to @samp{/} or @samp{^}, the value @var{def} may be omitted. The pattern @samp{x + opt(y)} matches a sum by -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 +binding one summand to @expr{x} and the other to @expr{y}, and it +matches anything else by binding the whole expression to @expr{x} and +zero to @expr{y}. The other operators above work similarly. -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)}, -or @samp{f(a,b,c)}. Default values of zero and @cite{b} are +or @samp{f(a,b,c)}. Default values of zero and @expr{b} are supplied in this example for the omitted arguments. Note that -the literal variable @cite{b} will be the default in the latter -case, @emph{not} the value that matched the meta-variable @cite{b}. +the literal variable @expr{b} will be the default in the latter +case, @emph{not} the value that matched the meta-variable @expr{b}. In other words, the default @var{def} is effectively quoted. @item condition(x,c) @@ -26064,8 +26400,8 @@ In other words, the default @var{def} is effectively quoted. @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}. +This matches the pattern @expr{x}, with the attached condition +@expr{c}. It is the same as @samp{x :: c}. @item pand(x,y) @ignore @@ -26073,8 +26409,8 @@ This matches the pattern @cite{x}, with the attached condition @end ignore @tindex pand @tindex &&& -This matches anything that matches both pattern @cite{x} and -pattern @cite{y}. It is the same as @samp{x &&& y}. +This matches anything that matches both pattern @expr{x} and +pattern @expr{y}. It is the same as @samp{x &&& y}. @pxref{Composing Patterns in Rewrite Rules}. @item por(x,y) @@ -26083,8 +26419,8 @@ pattern @cite{y}. It is the same as @samp{x &&& y}. @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}}. +This matches anything that matches either pattern @expr{x} or +pattern @expr{y}. It is the same as @w{@samp{x ||| y}}. @item pnot(x) @ignore @@ -26092,7 +26428,7 @@ pattern @cite{y}. It is the same as @w{@samp{x ||| y}}. @end ignore @tindex pnot @tindex !!! -This matches anything that does not match pattern @cite{x}. +This matches anything that does not match pattern @expr{x}. It is the same as @samp{!!! x}. @item cons(h,t) @@ -26101,8 +26437,8 @@ It is the same as @samp{!!! x}. @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 -elements is matched to @cite{t}. Note that vectors of fixed +element is matched to @expr{h}; a vector of the remaining +elements is matched to @expr{t}. Note that vectors of fixed length can also be matched as actual vectors: The rule @samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent to the rule @samp{[a,b] := [a+b]}. @@ -26113,8 +26449,8 @@ to the rule @samp{[a,b] := [a+b]}. @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}. +is matched to @expr{h}, with the remaining elements matched +to @expr{t}. @item apply(f,args) @ignore @@ -26122,7 +26458,7 @@ to @cite{t}. @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 +the form of a variable, is matched to @expr{f}. The arguments of the function, as a vector of zero or more objects, are matched to @samp{args}. Constants, variables, and vectors do @emph{not} match an @code{apply} pattern. For example, @@ -26157,8 +26493,8 @@ You must use @code{apply} for meta-variables with function names on both sides of a rewrite rule: @samp{apply(f, [x]) := f(x+1)} is @emph{not} correct, because it rewrites @samp{spam(6)} into @samp{f(7)}. The righthand side should be @samp{apply(f, [x+1])}. -Also note that you will have to use no-simplify (@kbd{m O}) -mode when entering this rule so that the @code{apply} isn't +Also note that you will have to use No-Simplify mode (@kbd{m O}) +when entering this rule so that the @code{apply} isn't evaluated immediately to get the new rule @samp{f(x) := f(x+1)}. Or, use @kbd{s e} to enter the rule without going through the stack, or enter the rule as @samp{apply(f, [x]) := apply(f, [x+1]) @w{:: 1}}. @@ -26190,7 +26526,7 @@ protecting rules from evaluation.) @item plain(x) Special properties of and simplifications for the function call -@cite{x} are not used. One interesting case where @code{plain} +@expr{x} are not used. One interesting case where @code{plain} is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a shorthand notation for the @code{quote} function. This rule will not work as shown; instead of replacing @samp{q(foo)} with @@ -26198,7 +26534,7 @@ not work as shown; instead of replacing @samp{q(foo)} with rule would be @samp{q(x) := plain(quote(x))}. @item cons(h,t) -Where @cite{t} is a vector, this is converted into an expanded +Where @expr{t} is a vector, this is converted into an expanded vector during rewrite processing. Note that @code{cons} is a regular Calc function which normally does this anyway; the only way @code{cons} is treated specially by rewrites is that @code{cons} on the righthand @@ -26206,11 +26542,11 @@ side of a rule will be evaluated even if default simplifications have been turned off. @item rcons(t,h) -Analogous to @code{cons} except putting @cite{h} at the @emph{end} of -the vector @cite{t}. +Analogous to @code{cons} except putting @expr{h} at the @emph{end} of +the vector @expr{t}. @item apply(f,args) -Where @cite{f} is a variable and @var{args} is a vector, this +Where @expr{f} is a variable and @var{args} is a vector, this is converted to a function call. Once again, note that @code{apply} is also a regular Calc function. @@ -26219,7 +26555,7 @@ is also a regular Calc function. @starindex @end ignore @tindex eval -The formula @cite{x} is handled in the usual way, then the +The formula @expr{x} is handled in the usual way, then the default simplifications are applied to it even if they have been turned off normally. This allows you to treat any function similarly to the way @code{cons} and @code{apply} are always @@ -26232,7 +26568,7 @@ whereas @samp{eval(cons(2+3, []))} will be converted to @samp{[5]}. @starindex @end ignore @tindex evalsimp -The formula @cite{x} has meta-variables substituted in the usual +The formula @expr{x} has meta-variables substituted in the usual way, then algebraically simplified as if by the @kbd{a s} command. @item evalextsimp(x) @@ -26240,7 +26576,7 @@ way, then algebraically simplified as if by the @kbd{a s} command. @starindex @end ignore @tindex evalextsimp -The formula @cite{x} has meta-variables substituted in the normal +The formula @expr{x} has meta-variables substituted in the normal way, then ``extendedly'' simplified as if by the @kbd{a e} command. @item select(x) @@ -26255,22 +26591,22 @@ There are also some special functions you can use in conditions. @starindex @end ignore @tindex let -The expression @cite{x} is evaluated with meta-variables substituted. +The expression @expr{x} is evaluated with meta-variables substituted. The @kbd{a s} command's simplifications are @emph{not} applied by -default, but @cite{x} can include calls to @code{evalsimp} or +default, but @expr{x} can include calls to @code{evalsimp} or @code{evalextsimp} as described above to invoke higher levels of simplification. The -result of @cite{x} is then bound to the meta-variable @cite{v}. As +result of @expr{x} is then bound to the meta-variable @expr{v}. As usual, if this meta-variable has already been matched to something else the two values must be equal; if the meta-variable is new then it is bound to the result of the expression. This variable can then appear in later conditions, and on the righthand side of the rule. -In fact, @cite{v} may be any pattern in which case the result of -evaluating @cite{x} is matched to that pattern, binding any +In fact, @expr{v} may be any pattern in which case the result of +evaluating @expr{x} is matched to that pattern, binding any meta-variables that appear in that pattern. Note that @code{let} can only appear by itself as a condition, or as one term of an @samp{&&} which is a whole condition: It cannot be inside -an @samp{||} term or otherwise buried.@refill +an @samp{||} term or otherwise buried. The alternate, equivalent form @samp{let(v, x)} is also recognized. Note that the use of @samp{:=} by @code{let}, while still being @@ -26287,7 +26623,7 @@ to express this rule that didn't have to invert the matrix twice. Note that, because the meta-variable @samp{ia} is otherwise unbound in this rule, the @code{let} condition itself always ``succeeds'' because no matter what @samp{1/a} evaluates to, it can successfully -be bound to @code{ia}.@refill +be bound to @code{ia}. Here's another example, for integrating cosines of linear terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}. @@ -26298,7 +26634,7 @@ so this @code{let} both verifies that @code{y} is linear, and binds the coefficients @code{a} and @code{b} for use elsewhere in the rule. (It would have been possible to use @samp{sin(a x + b)/b} for the righthand side instead, but using @samp{sin(y)/b} avoids gratuitous -rearrangement of the argument of the sine.)@refill +rearrangement of the argument of the sine.) @ignore @starindex @@ -26359,7 +26695,7 @@ be added to the rule set and will continue to operate even if @starindex @end ignore @tindex remember -Remember the match as described above, but only if condition @cite{c} +Remember the match as described above, but only if condition @expr{c} is true. For example, @samp{remember(n % 4 = 0)} in the above factorial rule remembers only every fourth result. Note that @samp{remember(1)} is equivalent to @samp{remember}, and @samp{remember(0)} has no effect. @@ -26530,7 +26866,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! @@ -26893,7 +27229,7 @@ To apply these manually, you could put them in a variable called to expand trig functions. But if instead you store them in the variable @code{EvalRules}, they will automatically be applied to all sines and cosines of sums. Then, with @samp{2 x} and @samp{45} on -the stack, typing @kbd{+ S} will (assuming degrees mode) result in +the stack, typing @kbd{+ S} will (assuming Degrees mode) result in @samp{0.7071 sin(2 x) + 0.7071 cos(2 x)} automatically. As each level of a formula is evaluated, the rules from @@ -26921,7 +27257,7 @@ or ran too long'' message. Another subtle difference between @code{EvalRules} and regular rewrites concerns rules that rewrite a formula into an identical formula. For -example, @samp{f(n) := f(floor(n))} ``fails to match'' when @cite{n} is +example, @samp{f(n) := f(floor(n))} ``fails to match'' when @expr{n} is already an integer. But in @code{EvalRules} this case is detected only if the righthand side literally becomes the original formula before any further simplification. This means that @samp{f(n) := f(floor(n))} will @@ -26965,15 +27301,15 @@ Finally, another limitation is that Calc sometimes calls its built-in functions directly rather than going through the default simplifications. When it does this, @code{EvalRules} will not be able to override those functions. For example, when you take the absolute value of the complex -number @cite{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling +number @expr{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling the multiplication, addition, and square root functions directly rather than applying the default simplifications to this formula. So an @code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6} -would not apply. (However, if you put Calc into symbolic mode so that +would not apply. (However, if you put Calc into Symbolic mode so that @samp{sqrt(13)} will be left in symbolic form by the built-in square root function, your rule will be able to apply. But if the complex -number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated, -then symbolic mode will not help because @samp{sqrt(25)} can be +number were @expr{(3,4)}, so that @samp{sqrt(25)} must be calculated, +then Symbolic mode will not help because @samp{sqrt(25)} can be evaluated exactly to 5.) One subtle restriction that normally only manifests itself with @@ -27066,7 +27402,7 @@ Returning to the example of substituting the pattern finding suitable cases. Another solution would be to use the rule @samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification if necessary. This rule will be the most effective way to do the job, -but at the expense of making some changes that you might not desire.@refill +but at the expense of making some changes that you might not desire. Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}. To make this work with the @w{@kbd{j r}} command so that it can be @@ -27074,14 +27410,14 @@ easily targeted to a particular exponential in a large formula, you might wish to write the rule as @samp{select(exp(x+y)) := select(exp(x) exp(y))}. The @samp{select} markers will be ignored by the regular @kbd{a r} command -(@pxref{Selections with Rewrite Rules}).@refill +(@pxref{Selections with Rewrite Rules}). A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}. -This will simplify the formula whenever @cite{b} and/or @cite{c} can +This will simplify the formula whenever @expr{b} and/or @expr{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 +Symbolic mode has been enabled to keep the square root from being +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)}. @@ -27097,17 +27433,19 @@ 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 -The following rule set, contributed by @c{Fran\c cois} -@asis{Francois} Pinard, implements -@dfn{quaternions}, a generalization of the concept of complex numbers. -Quaternions have four components, and are here represented by function -calls @samp{quat(@var{w}, [@var{x}, @var{y}, @var{z}])} with ``real -part'' @var{w} and the three ``imaginary'' parts collected into a -vector. Various arithmetical operations on quaternions are supported. -To use these rules, either add them to @code{EvalRules}, or create a -command based on @kbd{a r} for simplifying quaternion formulas. -A convenient way to enter quaternions would be a command defined by -a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}. +The following rule set, contributed by +@texline Fran\c cois +@infoline Francois +Pinard, implements @dfn{quaternions}, a generalization of the concept of +complex numbers. Quaternions have four components, and are here +represented by function calls @samp{quat(@var{w}, [@var{x}, @var{y}, +@var{z}])} with ``real part'' @var{w} and the three ``imaginary'' parts +collected into a vector. Various arithmetical operations on quaternions +are supported. To use these rules, either add them to @code{EvalRules}, +or create a command based on @kbd{a r} for simplifying quaternion +formulas. A convenient way to enter quaternions would be a command +defined by a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) +@key{RET}}. @smallexample [ quat(w, x, y, z) := quat(w, [x, y, z]), @@ -27132,8 +27470,8 @@ a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}. @end smallexample Quaternions, like matrices, have non-commutative multiplication. -In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if -@cite{q1} and @cite{q2} are @code{quat} forms. The @samp{quat*quat} +In other words, @expr{q1 * q2 = q2 * q1} is not necessarily true if +@expr{q1} and @expr{q2} are @code{quat} forms. The @samp{quat*quat} rule above uses @code{plain} to prevent Calc from rearranging the product. It may also be wise to add the line @samp{[quat(), matrix]} to the @code{Decls} matrix, to ensure that Calc's other algebraic @@ -27180,15 +27518,15 @@ or a variable whose name is a prefix character like @samp{k} (for ``kilo'') or @samp{u} (for ``micro'') followed by a name in the unit table. A substantial table of built-in units is provided with Calc; @pxref{Predefined Units}. You can also define your own unit names; -@pxref{User-Defined Units}.@refill +@pxref{User-Defined Units}. Note that if the value part of a units expression is exactly @samp{1}, it will be removed by the Calculator's automatic algebra routines: The formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a display anomaly, however; @samp{mm} will work just fine as a -representation of one millimeter.@refill +representation of one millimeter. -You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working +You may find that Algebraic mode (@pxref{Algebraic Entry}) makes working with units expressions easier. Otherwise, you will have to remember to hit the apostrophe key every time you wish to enter units. @@ -27207,7 +27545,7 @@ to be compatible with another's. For example, @samp{5 m + 23 mm} will simplify to @samp{5.023 m}. When different but compatible units are added, the righthand term's units are converted to match those of the lefthand term. @xref{Simplification Modes}, for a way to have this done -automatically at all times.@refill +automatically at all times. Units simplification also handles quotients of two units with the same dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional @@ -27218,7 +27556,7 @@ powers of unit expressions, as in @samp{sqrt(9 mm^2)} to @samp{3 mm} and applied to units expressions, in which case the operation in question is applied only to the numeric part of the expression. Finally, trigonometric functions of quantities with units -of angle are evaluated, regardless of the current angular mode.@refill +of angle are evaluated, regardless of the current angular mode. @kindex u c @pindex calc-convert-units @@ -27299,7 +27637,7 @@ The @kbd{u t} (@code{calc-convert-temperature}) command converts absolute temperatures. The value on the stack must be a simple units expression with units of temperature only. This command would convert @samp{10 degC} to @samp{50 degF}, the equivalent temperature on the -Fahrenheit scale.@refill +Fahrenheit scale. @kindex u r @pindex calc-remove-units @@ -27310,7 +27648,7 @@ formula at the top of the stack. The @kbd{u x} (@code{calc-extract-units}) command extracts only the units portion of a formula. These commands essentially replace every term of the formula that does or doesn't (respectively) look like a unit name by the -constant 1, then resimplify the formula.@refill +constant 1, then resimplify the formula. @kindex u a @pindex calc-autorange-units @@ -27435,12 +27773,12 @@ also @code{tpt}, which stands for a printer's point as defined by the The unit @code{e} stands for the elementary (electron) unit of charge; because algebra command could mistake this for the special constant -@cite{e}, Calc provides the alternate unit name @code{ech} which is +@expr{e}, Calc provides the alternate unit name @code{ech} which is preferable to @code{e}. The name @code{g} stands for one gram of mass; there is also @code{gf}, one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.) -Meanwhile, one ``@cite{g}'' of acceleration is denoted @code{ga}. +Meanwhile, one ``@expr{g}'' of acceleration is denoted @code{ga}. The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is a metric ton of @samp{1000 kg}. @@ -27458,7 +27796,7 @@ in its normal terms, and @kbd{u b} expresses the definition in base units. Two units, @code{pi} and @code{fsc} (the fine structure constant, -approximately @i{1/137}) are dimensionless. The units simplification +approximately @mathit{1/137}) are dimensionless. The units simplification commands simply treat these names as equivalent to their corresponding values. However you can, for example, use @kbd{u c} to convert a pure number into multiples of the fine structure constant, or @kbd{u b} to @@ -27539,13 +27877,14 @@ possible to create user-defined temperature units. @kindex u p @pindex calc-permanent-units -@cindex @file{.emacs} file, user-defined units +@cindex Calc init file, user-defined units The @kbd{u p} (@code{calc-permanent-units}) command stores the user-defined -units in your @file{.emacs} file, so that the units will still be -available in subsequent Emacs sessions. If there was already a set of -user-defined units in your @file{.emacs} file, it is replaced by the -new set. (@xref{General Mode Commands}, for a way to tell Calc to use -a different file instead of @file{.emacs}.) +units in your Calc init file (the file given by the variable +@code{calc-settings-file}, typically @file{~/.calc.el}), so that the +units will still be available in subsequent Emacs sessions. If there +was already a set of user-defined units in your Calc init file, it +is replaced by the new set. (@xref{General Mode Commands}, for a way to +tell Calc to use a different file for the Calc init file.) @node Store and Recall, Graphics, Units, Top @chapter Storing and Recalling @@ -27577,14 +27916,8 @@ to variables use the @kbd{s} prefix key. The @kbd{s s} (@code{calc-store}) command stores the value at the top of the stack into a specified variable. It prompts you to enter the name of the variable. If you press a single digit, the value is stored -immediately in one of the ``quick'' variables @code{var-q0} through -@code{var-q9}. Or you can enter any variable name. The prefix @samp{var-} -is supplied for you; when a name appears in a formula (as in @samp{a+q2}) -the prefix @samp{var-} is also supplied there, so normally you can simply -forget about @samp{var-} everywhere. Its only purpose is to enable you to -use Calc variables without fear of accidentally clobbering some variable in -another Emacs package. If you really want to store in an arbitrary Lisp -variable, just backspace over the @samp{var-}. +immediately in one of the ``quick'' variables @code{q0} through +@code{q9}. Or you can enter any variable name. @kindex s t @pindex calc-store-into @@ -27672,12 +28005,15 @@ variable. The other arithmetic stores are @kbd{s -}, @kbd{s *}, @kbd{s /}, and @kbd{s ]} which decrease or increase a variable by one. All the arithmetic stores accept the Inverse prefix to reverse the -order of the operands. If @cite{v} represents the contents of the -variable, and @cite{a} is the value drawn from the stack, then regular -@w{@kbd{s -}} assigns @c{$v \coloneq v - a$} -@cite{v := v - a}, but @kbd{I s -} assigns -@c{$v \coloneq a - v$} -@cite{v := a - v}. While @kbd{I s *} might seem pointless, it is +order of the operands. If @expr{v} represents the contents of the +variable, and @expr{a} is the value drawn from the stack, then regular +@w{@kbd{s -}} assigns +@texline @math{v \coloneq v - a}, +@infoline @expr{v := v - a}, +but @kbd{I s -} assigns +@texline @math{v \coloneq a - v}. +@infoline @expr{v := a - v}. +While @kbd{I s *} might seem pointless, it is useful if matrix multiplication is involved. Actually, all the arithmetic stores use formulas designed to behave usefully both forwards and backwards: @@ -27704,7 +28040,7 @@ minus-two minus the variable. The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -}, etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous -arithmetic stores that don't remove the value @cite{a} from the stack. +arithmetic stores that don't remove the value @expr{a} from the stack. All arithmetic stores report the new value of the variable in the Trail for your information. They signal an error if the variable @@ -27730,8 +28066,8 @@ takes the hyperbolic arcsine of the variable contents. If the mapping function takes two or more arguments, the additional arguments are taken from the stack; the old value of the variable -is provided as the first argument. Thus @kbd{s m -} with @cite{a} -on the stack computes @cite{v - a}, just like @kbd{s -}. With the +is provided as the first argument. Thus @kbd{s m -} with @expr{a} +on the stack computes @expr{v - a}, just like @kbd{s -}. With the Inverse prefix, the variable's original value becomes the @emph{last} argument instead of the first. Thus @kbd{I s m -} is also equivalent to @kbd{I s -}. @@ -27754,7 +28090,7 @@ Until you store something in them, variables are ``void,'' that is, they contain no value at all. If they appear in an algebraic formula they will be left alone even if you press @kbd{=} (@code{calc-evaluate}). The @kbd{s u} (@code{calc-unstore}) command returns a variable to the -void state.@refill +void state. The only variables with predefined values are the ``special constants'' @code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}. You are free @@ -27765,11 +28101,10 @@ you change the value of one of these variables, or of one of the other special variables @code{inf}, @code{uinf}, and @code{nan} (which are normally void). -Note that @code{var-pi} doesn't actually have 3.14159265359 stored -in it, but rather a special magic value that evaluates to @c{$\pi$} -@cite{pi} -at the current precision. Likewise @code{var-e}, @code{var-i}, and -@code{var-phi} evaluate according to the current precision or polar mode. +Note that @code{pi} doesn't actually have 3.14159265359 stored +in it, but rather a special magic value that evaluates to @cpi{} +at the current precision. Likewise @code{e}, @code{i}, and +@code{phi} evaluate according to the current precision or polar mode. If you recall a value from @code{pi} and store it back, this magic property will be lost. @@ -27780,9 +28115,9 @@ value of one variable to another. It differs from a simple @kbd{s r} followed by an @kbd{s t} in two important ways. First, the value never goes on the stack and thus is never rounded, evaluated, or simplified in any way; it is not even rounded down to the current precision. -Second, the ``magic'' contents of a variable like @code{var-e} can +Second, the ``magic'' contents of a variable like @code{e} can be copied into another variable with this command, perhaps because -you need to unstore @code{var-e} right now but you wish to put it +you need to unstore @code{e} right now but you wish to put it back when you're done. The @kbd{s c} command is the only way to manipulate these magic values intact. @@ -27821,7 +28156,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 @kbd{M-# M-#} to finish, the variable will +empty when you press @kbd{C-c C-c} to finish, the variable will be made void. @xref{Editing Stack Entries}, for a general description of editing. @@ -27934,32 +28269,34 @@ names rather than prompting for the variable name. @pindex calc-permanent-variable @cindex Storing variables @cindex Permanent variables -@cindex @file{.emacs} file, veriables +@cindex Calc init 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 -re-execute @w{@kbd{s p}} later on to update the saved value, but the -only way to remove a saved variable is to edit your @file{.emacs} file +variable's value permanently in your Calc init file (the file given by +the variable @code{calc-settings-file}, typically @file{~/.calc.el}), so +that its value will still be available in future Emacs sessions. You +can re-execute @w{@kbd{s p}} later on to update the saved value, but the +only way to remove a saved variable is to edit your calc init file by hand. (@xref{General Mode Commands}, for a way to tell Calc to -use a different file instead of @file{.emacs}.) +use a different file for the Calc init file.) If you do not specify the name of a variable to save (i.e., -@kbd{s p @key{RET}}), all @samp{var-} variables with defined values +@kbd{s p @key{RET}}), all Calc variables with defined values are saved except for the special constants @code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}; the variables @code{TimeZone} and @code{PlotRejects}; @code{FitRules}, @code{DistribRules}, and other built-in rewrite rules; and @code{PlotData@var{n}} variables generated by the graphics commands. (You can still save these variables by -explicitly naming them in an @kbd{s p} command.)@refill +explicitly naming them in an @kbd{s p} command.) @kindex s i @pindex calc-insert-variables The @kbd{s i} (@code{calc-insert-variables}) command writes -the values of all @samp{var-} variables into a specified buffer. -The variables are written in the form of Lisp @code{setq} commands +the values of all Calc variables into a specified buffer. +The variables are written with the prefix @code{var-} in the form of +Lisp @code{setq} commands which store the values in string form. You can place these commands -in your @file{.emacs} buffer if you wish, though in this case it +in your Calc init file (or @file{.emacs}) if you wish, though in this case it would be easier to use @kbd{s p @key{RET}}. (Note that @kbd{s i} omits the same set of variables as @w{@kbd{s p @key{RET}}}; the difference is that @kbd{s i} will store the variables in any buffer, and it also @@ -27974,9 +28311,9 @@ stores in a more human-readable format.) @cindex Variables, temporary assignment @cindex Temporary assignment to variables If you have an expression like @samp{a+b^2} on the stack and you wish to -compute its value where @cite{b=3}, you can simply store 3 in @cite{b} and +compute its value where @expr{b=3}, you can simply store 3 in @expr{b} and then press @kbd{=} to reevaluate the formula. This has the side-effect -of leaving the stored value of 3 in @cite{b} for future operations. +of leaving the stored value of 3 in @expr{b} for future operations. The @kbd{s l} (@code{calc-let}) command evaluates a formula under a @emph{temporary} assignment of a variable. It stores the value on the @@ -27999,7 +28336,7 @@ 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 rather than temporarily assigning the variable and evaluating. For -example, letting @cite{n=2} in @samp{f(n pi)} with @kbd{a b} will +example, letting @expr{n=2} in @samp{f(n pi)} with @kbd{a b} will produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)} since the evaluation step will also evaluate @code{pi}. @@ -28013,7 +28350,7 @@ since the evaluation step will also evaluate @code{pi}. @cindex @samp{=>} operator The special algebraic symbol @samp{=>} is known as the @dfn{evaluates-to operator}. (It will show up as an @code{evalto} function call in -other language modes like Pascal and @TeX{}.) This is a binary +other language modes like Pascal and @LaTeX{}.) This is a binary operator, that is, it has a lefthand and a righthand argument, although it can be entered with the righthand argument omitted. @@ -28075,11 +28412,11 @@ including the current simplification mode. Recall that the formula @samp{x + y + x} is not handled by Calc's default simplifications, but the @kbd{a s} command will reduce it to the simpler form @samp{y + 2 x}. You can also type @kbd{m A} -to enable an algebraic-simplification mode in which the +to enable an Algebraic Simplification mode in which the equivalent of @kbd{a s} is used on all of Calc's results. If you enter @samp{x + y + x =>} normally, the result will be @samp{x + y + x => x + y + x}. If you change to -algebraic-simplification mode, the result will be +Algebraic Simplification mode, the result will be @samp{x + y + x => y + 2 x}. However, just pressing @kbd{a s} once will have no effect on @samp{x + y + x => x + y + x}, because the righthand side depends only on the lefthand side @@ -28118,17 +28455,17 @@ side effects. @pindex calc-assign @tindex assign @tindex := -Embedded Mode also uses @samp{=>} operators. In embedded mode, +Embedded mode also uses @samp{=>} operators. In Embedded mode, the lefthand side of an @samp{=>} operator can refer to variables assigned elsewhere in the file by @samp{:=} operators. The assignment operator @samp{a := 17} does not actually do anything -by itself. But Embedded Mode recognizes it and marks it as a sort +by itself. But Embedded mode recognizes it and marks it as a sort of file-local definition of the variable. You can enter @samp{:=} -operators in algebraic mode, or by using the @kbd{s :} +operators in Algebraic mode, or by using the @kbd{s :} (@code{calc-assign}) [@code{assign}] command which takes a variable and value from the stack and replaces them with an assignment. -@xref{TeX Language Mode}, for the way @samp{=>} appears in +@xref{TeX and LaTeX Language Modes}, for the way @samp{=>} appears in @TeX{} language output. The @dfn{eqn} mode gives similar treatment to @samp{=>}. @@ -28146,7 +28483,7 @@ Software Foundation's machine @samp{prep.ai.mit.edu}.) @vindex calc-gnuplot-name If you have GNUPLOT installed on your system but Calc is unable to find it, you may need to set the @code{calc-gnuplot-name} variable -in your @file{.emacs} file. You may also need to set some Lisp +in your Calc init file or @file{.emacs}. You may also need to set some Lisp variables to show Calc how to run GNUPLOT on your system; these are described under @kbd{g D} and @kbd{g O} below. If you are using the X window system, Calc will configure GNUPLOT for you @@ -28183,8 +28520,8 @@ The ``x'' entry may instead be an interval form, in which case suitable the interval (whether the interval is open or closed is ignored). The ``x'' entry may also be a number, in which case Calc uses the -sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc. -(Generally the number 0 or 1 would be used for @cite{x} in this case.) +sequence of ``x'' values @expr{x}, @expr{x+1}, @expr{x+2}, etc. +(Generally the number 0 or 1 would be used for @expr{x} in this case.) The ``y'' entry may be any formula instead of a vector. Calc effectively uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula; @@ -28207,7 +28544,7 @@ are used as the ``x'' and ``y'' coordinates of the curve, respectively. In this case the ``x'' vector or interval you specified is not directly visible in the graph. For example, if ``x'' is the interval @samp{[0..360]} and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph -will be a circle.@refill +will be a circle. Also, ``x'' and ``y'' may each be variable names, in which case Calc looks for suitable vectors, intervals, or formulas stored in those @@ -28262,9 +28599,11 @@ In the first case, ``x'' and ``y'' are each vectors (not necessarily of the same length); either or both may instead be interval forms. The ``z'' value must be a matrix with the same number of rows as elements in ``x'', and the same number of columns as elements in ``y''. The -result is a surface plot where @c{$z_{ij}$} -@cite{z_ij} is the height of the point -at coordinate @cite{(x_i, y_j)} on the surface. The 3D graph will +result is a surface plot where +@texline @math{z_{ij}} +@infoline @expr{z_ij} +is the height of the point +at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will be displayed from a certain default viewpoint; you can change this viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} buffer as described later. See the GNUPLOT 3.0 documentation for a @@ -28355,26 +28694,28 @@ itself, is what was added by @kbd{g a}. A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way stack entries are interpreted as curves. With a positive prefix -argument @cite{n}, the top @cite{n} stack entries are ``y'' values -for @cite{n} different curves which share a common ``x'' value in -the @cite{n+1}st stack entry. (Thus @kbd{g a} with no prefix +argument @expr{n}, the top @expr{n} stack entries are ``y'' values +for @expr{n} different curves which share a common ``x'' value in +the @expr{n+1}st stack entry. (Thus @kbd{g a} with no prefix argument is equivalent to @kbd{C-u 1 g a}.) A prefix of zero or plain @kbd{C-u} means to take two stack entries, ``x'' and ``y'' as usual, but to interpret ``y'' as a vector of ``y'' values for several curves that share a common ``x''. -A negative prefix argument tells Calc to read @cite{n} vectors from -the stack; each vector @cite{[x, y]} describes an independent curve. +A negative prefix argument tells Calc to read @expr{n} vectors from +the stack; each vector @expr{[x, y]} describes an independent curve. This is the only form of @kbd{g a} that creates several curves at once that don't have common ``x'' values. (Of course, the range of ``x'' values covered by all the curves ought to be roughly the same if they are to look nice on the same graph.) -For example, to plot @c{$\sin n x$} -@cite{sin(n x)} for integers @cite{n} +For example, to plot +@texline @math{\sin n x} +@infoline @expr{sin(n x)} +for integers @expr{n} from 1 to 5, you could use @kbd{v x} to create a vector of integers -(@cite{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)} +(@expr{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)} across this vector. The resulting vector of formulas is suitable for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f} command. @@ -28384,11 +28725,11 @@ command. The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve to the graph. It is not legal to intermix 2D and 3D curves in a single graph. This command takes three arguments, ``x'', ``y'', -and ``z'', from the stack. With a positive prefix @cite{n}, it -takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n} +and ``z'', from the stack. With a positive prefix @expr{n}, it +takes @expr{n+2} arguments (common ``x'' and ``y'', plus @expr{n} separate ``z''s). With a zero prefix, it takes three stack entries but the ``z'' entry is a vector of curve values. With a negative -prefix @cite{-n}, it takes @cite{n} vectors of the form @cite{[x, y, z]}. +prefix @expr{-n}, it takes @expr{n} vectors of the form @expr{[x, y, z]}. The @kbd{g A} command works by adding a @code{splot} (surface-plot) command to the @samp{*Gnuplot Commands*} buffer. @@ -28507,13 +28848,13 @@ a blank line, displays the default number of points used for all graphs created by @kbd{g a} that don't specify the resolution explicitly. With a negative prefix argument, this command changes or displays the default value (initially 5) used for 3D graphs created by @kbd{g A}. -Note that a 3D setting of 5 means that a total of @cite{5^2 = 25} points +Note that a 3D setting of 5 means that a total of @expr{5^2 = 25} points will be computed for the surface. Data values in the graph of a function are normally computed to a precision of five digits, regardless of the current precision at the time. This is usually more than adequate, but there are cases where -it will not be. For example, plotting @cite{1 + x} with @cite{x} in the +it will not be. For example, plotting @expr{1 + x} with @expr{x} in the interval @samp{[0 ..@: 1e-6]} will round all the data points down to 1.0! Putting the command @samp{set precision @var{n}} in the @samp{*Gnuplot Commands*} buffer will cause the data to be computed @@ -28621,7 +28962,7 @@ values, but if you store a vector of integers in one of these variables, the @kbd{g a} and @kbd{g f} commands will use those style numbers instead of the defaults for new curves that are added to the graph. An entry should be a positive integer for a specific style, or 0 to let -the style be chosen automatically, or @i{-1} to turn off lines or points +the style be chosen automatically, or @mathit{-1} to turn off lines or points 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. @@ -28659,9 +29000,11 @@ terminals with no special graphics facilities. It writes a crude picture of the graph composed of characters like @code{-} and @code{|} to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. The graph is made the same size as the Emacs screen, which on most -dumb terminals will be @c{$80\times24$} -@asis{80x24} characters. The graph is displayed in -an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit +dumb terminals will be +@texline @math{80\times24} +@infoline 80x24 +characters. The graph is displayed in +an Emacs ``recursive edit''; type @kbd{q} or @kbd{C-c C-c} to exit the recursive edit and return to Calc. Note that the @code{dumb} device is present only in GNUPLOT 3.0 and later versions. @@ -28819,7 +29162,7 @@ killing GNUPLOT because you think it has gotten stuck. The commands in this chapter move information between the Calculator and other Emacs editing buffers. -In many cases Embedded Mode is an easier and more natural way to +In many cases Embedded mode is an easier and more natural way to work with Calc from a regular editing buffer. @xref{Embedded Mode}. @menu @@ -28862,8 +29205,8 @@ encompass full lines.) The text is copied into the kill ring exactly as it appears on the screen, including line numbers if they are enabled. A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number -of lines killed. A positive argument kills the current line and @cite{n-1} -lines below it. A negative argument kills the @cite{-n} lines above the +of lines killed. A positive argument kills the current line and @expr{n-1} +lines below it. A negative argument kills the @expr{-n} lines above the current line. Again this mirrors the behavior of the standard Emacs @kbd{C-k} command. Although a whole line is always deleted, @kbd{C-k} with no argument copies only the number itself into the kill ring, whereas @@ -28906,9 +29249,9 @@ If the @kbd{M-# g} command works successfully, it does an automatic A numeric prefix argument grabs the specified number of lines around point, ignoring the mark. A positive prefix grabs from point to the -@cite{n}th following newline (so that @kbd{M-1 M-# g} grabs from point +@expr{n}th following newline (so that @kbd{M-1 M-# g} grabs from point to the end of the current line); a negative prefix grabs from point -back to the @cite{n+1}st preceding newline. In these cases the text +back to the @expr{n+1}st preceding newline. In these cases the text that is grabbed is exactly the same as the text that @kbd{C-k} would delete given that prefix argument. @@ -28964,12 +29307,13 @@ If you give a positive numeric prefix argument @var{n}, then each line will be split up into columns of width @var{n}; each column is parsed separately as a matrix element. If a line contained @w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8 -would correctly split the line into two error forms.@refill +would correctly split the line into two error forms. @xref{Matrix Functions}, to see how to pull the matrix apart into its -constituent rows and columns. (If it is a @c{$1\times1$} -@asis{1x1} matrix, just hit @kbd{v u} -(@code{calc-unpack}) twice.) +constituent rows and columns. (If it is a +@texline @math{1\times1} +@infoline 1x1 +matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.) @kindex M-# : @kindex M-# _ @@ -29022,7 +29366,7 @@ normally not included.) The number is @emph{not} removed from the stack. With a prefix argument, @kbd{y} inserts several numbers, one per line. A positive argument inserts the specified number of values from the top -of the stack. A negative argument inserts the @cite{n}th value from the +of the stack. A negative argument inserts the @expr{n}th value from the top of the stack. An argument of zero inserts the entire stack. Note that @kbd{y} with an argument of 1 is slightly different from @kbd{y} with no argument; the former always copies full lines, whereas the @@ -29037,7 +29381,7 @@ original data with the new data. One might wish to alter the matrix display style (@pxref{Vector and Matrix Formats}) or change the current display language (@pxref{Language Modes}) before doing this. Also, note that this command replaces a linear region of text (as grabbed by -@kbd{M-# g}), not a rectangle (as grabbed by @kbd{M-# r}).@refill +@kbd{M-# g}), not a rectangle (as grabbed by @kbd{M-# r}). If the editing buffer is in overwrite (as opposed to insert) mode, and the @kbd{C-u} prefix was not used, then the yanked number will @@ -29089,7 +29433,7 @@ just by double-clicking on it in the shell, then middle-clicking in the Calc window. @node Keypad Mode, Embedded Mode, Kill and Yank, Introduction -@chapter ``Keypad'' Mode +@chapter Keypad Mode @noindent @kindex M-# k @@ -29098,7 +29442,7 @@ The @kbd{M-# k} (@code{calc-keypad}) command starts the Calculator and displays a picture of a calculator-style keypad. If you are using the X window system, you can click on any of the ``keys'' in the keypad using the left mouse button to operate the calculator. -The original window remains the selected window; in keypad mode +The original window remains the selected window; in Keypad mode you can type in your file while simultaneously performing calculations with the mouse. @@ -29114,11 +29458,11 @@ the @samp{*Calc Keypad*} window, place the cursor on the desired ``key,'' and type @key{SPC} or @key{RET}. If you think this is easier than using Calc normally, go right ahead. -Calc commands are more or less the same in keypad mode. Certain +Calc commands are more or less the same in Keypad mode. Certain keypad keys differ slightly from the corresponding normal Calc keystrokes; all such deviations are described below. -Keypad Mode includes many more commands than will fit on the keypad +Keypad mode includes many more commands than will fit on the keypad at once. Click the right mouse button [@code{calc-keypad-menu}] to switch to the next menu. The bottom five rows of the keypad stay the same; the top three rows change to a new set of commands. @@ -29166,7 +29510,7 @@ original buffer. @end smallexample @noindent -This is the menu that appears the first time you start Keypad Mode. +This is the menu that appears the first time you start Keypad mode. It will show up in a vertical window on the right side of your screen. Above this menu is the traditional Calc stack display. On a 24-line screen you will be able to see the top three stack entries. @@ -29183,7 +29527,7 @@ At other times it changes the sign of the number on the top of the stack. The @key{INV} and @key{HYP} keys modify other keys. As well as -having the effects described elsewhere in this manual, Keypad Mode +having the effects described elsewhere in this manual, Keypad mode defines several other ``inverse'' operations. These are described below and in the following sections. @@ -29203,7 +29547,7 @@ The @key{EXEC} key prompts you to enter any keystroke sequence that would normally work in Calc mode. This can include a numeric prefix if you wish. It is also possible simply to switch into the Calc window and type commands in it; there is -nothing ``magic'' about this window when Keypad Mode is active. +nothing ``magic'' about this window when Keypad mode is active. The other keys in this display perform their obvious calculator functions. @key{CLN2} rounds the top-of-stack by temporarily @@ -29225,7 +29569,7 @@ is the same as @key{CONJ}. @item INV * is the same as @key{y^x}. @item INV / -is the same as @key{INV y^x} (the @cite{x}th root of @cite{y}). +is the same as @key{INV y^x} (the @expr{x}th root of @expr{y}). @item HYP/INV 1 are the same as @key{SIN} / @kbd{INV SIN}. @item HYP/INV 2 @@ -29291,7 +29635,7 @@ This menu provides various operations from the @kbd{f} and @kbd{k} prefix keys. @key{IMAG} multiplies the number on the stack by the imaginary -number @cite{i = (0, 1)}. +number @expr{i = (0, 1)}. @key{RE} extracts the real part a complex number. @kbd{INV RE} extracts the imaginary part. @@ -29304,8 +29648,9 @@ same limit as last time. @key{INV GCD} computes the LCM (least common multiple) function. -@key{INV FACT} is the gamma function. @c{$\Gamma(x) = (x-1)!$} -@cite{gamma(x) = (x-1)!}. +@key{INV FACT} is the gamma function. +@texline @math{\Gamma(x) = (x-1)!}. +@infoline @expr{gamma(x) = (x-1)!}. @key{PERM} is the number-of-permutations function, which is on the @kbd{H k c} key in normal Calc. @@ -29420,13 +29765,13 @@ the variables set to the various sets of numbers in those vectors. For example, you could simulate @key{MAP^} using @key{MAP$} with the formula @samp{x^y}. -The @kbd{"x"} key pushes the variable name @cite{x} onto the -stack. To build the formula @cite{x^2 + 6}, you would use the +The @kbd{"x"} key pushes the variable name @expr{x} onto the +stack. To build the formula @expr{x^2 + 6}, you would use the key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be suitable for use with the @key{MAP$} key described above. With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the -@kbd{"x"} key pushes the variable names @cite{y}, @cite{z}, and -@cite{t}, respectively. +@kbd{"x"} key pushes the variable names @expr{y}, @expr{z}, and +@expr{t}, respectively. @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode @section Modes Menu @@ -29481,16 +29826,16 @@ The @key{OVER} key duplicates the second-to-top stack element. The @key{STO} and @key{RCL} keys are analogous to @kbd{s t} and @kbd{s r} in regular Calc. @xref{Store and Recall}. Click the @key{STO} or @key{RCL} key, then one of the ten digits. (Named -variables are not available in Keypad Mode.) You can also use, +variables are not available in Keypad mode.) You can also use, for example, @kbd{STO + 3} to add to register 3. @node Embedded Mode, Programming, Keypad Mode, Top @chapter Embedded Mode @noindent -Embedded Mode in Calc provides an alternative to copying numbers +Embedded mode in Calc provides an alternative to copying numbers and formulas back and forth between editing buffers and the Calc -stack. In Embedded Mode, your editing buffer becomes temporarily +stack. In Embedded mode, your editing buffer becomes temporarily linked to the stack and this copying is taken care of automatically. @menu @@ -29515,7 +29860,7 @@ are visiting your own files. Calc normally scans backward and forward in the buffer for the nearest opening and closing @dfn{formula delimiters}. The simplest -delimiters are blank lines. Other delimiters that Embedded Mode +delimiters are blank lines. Other delimiters that Embedded mode understands are: @enumerate @@ -29523,7 +29868,7 @@ understands are: The @TeX{} and La@TeX{} math delimiters @samp{$ $}, @samp{$$ $$}, @samp{\[ \]}, and @samp{\( \)}; @item -Lines beginning with @samp{\begin} and @samp{\end}; +Lines beginning with @samp{\begin} and @samp{\end} (except matrix delimiters); @item Lines beginning with @samp{@@} (Texinfo delimiters). @item @@ -29591,7 +29936,7 @@ We define $F_n = F_(n-1)+F_(n-2)$ for all $n>2$. @end example @noindent -The formula @cite{n>2} will be pushed onto the Calc stack, and +The formula @expr{n>2} will be pushed onto the Calc stack, and the top of stack will be copied back into the editing buffer. This means that spaces will appear around the @samp{>} symbol to match Calc's usual display style: @@ -29660,16 +30005,16 @@ you haven't done anything with this formula yet. When Embedded mode ``activates'' a formula, i.e., when it examines the formula for the first time since the buffer was created or loaded, Calc tries to sense the language in which the formula was -written. If the formula contains any @TeX{}-like @samp{\} sequences, -it is parsed (i.e., read) in @TeX{} mode. If the formula appears to +written. If the formula contains any @LaTeX{}-like @samp{\} sequences, +it is parsed (i.e., read) in @LaTeX{} mode. If the formula appears to be written in multi-line Big mode, it is parsed in Big mode. Otherwise, it is parsed according to the current language mode. Note that Calc does not change the current language mode according -to what it finds. Even though it can read a @TeX{} formula when -not in @TeX{} mode, it will immediately rewrite this formula using -whatever language mode is in effect. You must then type @kbd{d T} -to switch Calc permanently into @TeX{} mode if that is what you +to what it finds. Even though it can read a @LaTeX{} formula when +not in @LaTeX{} mode, it will immediately rewrite this formula using +whatever language mode is in effect. You must then type @kbd{d L} +to switch Calc permanently into @LaTeX{} mode if that is what you desire. @tex @@ -29690,8 +30035,8 @@ version. Plain formulas are preceded and followed by @samp{%%%} signs by default. This notation has the advantage that the @samp{%} -character begins a comment in @TeX{}, so if your formula is -embedded in a @TeX{} document its plain version will be +character begins a comment in @TeX{} and @LaTeX{}, so if your formula is +embedded in a @TeX{} or @LaTeX{} document its plain version will be invisible in the final printed copy. @xref{Customizing Embedded Mode}, to see how to change the ``plain'' formula delimiters, say to something that @dfn{eqn} or some other @@ -29719,8 +30064,7 @@ in the file as well as the rounded-down number. Embedded buffers remember active formulas for as long as they exist in Emacs memory. Suppose you have an embedded formula -which is @c{$\pi$} -@cite{pi} to the normal 12 decimal places, and then +which is @cpi{} to the normal 12 decimal places, and then type @w{@kbd{C-u 5 d n}} to display only five decimal places. If you then type @kbd{d n}, all 12 places reappear because the full number is still there on the Calc stack. More surprisingly, @@ -29840,7 +30184,7 @@ by holding down Shift and Meta and alternately typing two keys.) The @kbd{M-# `} (@code{calc-embedded-edit}) command edits the embedded formula at the current point as if by @kbd{`} (@code{calc-edit}). Embedded mode does not have to be enabled for this to work. Press -@kbd{M-# M-#} to finish the edit, or @kbd{M-# x} to cancel. +@kbd{C-c C-c} to finish the edit, or @kbd{C-x k} to cancel. @node Assignments in Embedded Mode, Mode Settings in Embedded Mode, More About Embedded Mode, Embedded Mode @section Assignments in Embedded Mode @@ -29858,9 +30202,9 @@ foo := 5 @end example @noindent -records @cite{5} as the stored value of @code{foo} for the +records @expr{5} as the stored value of @code{foo} for the purposes of Embedded mode operations in the current buffer. It -does @emph{not} actually store @cite{5} as the ``global'' value +does @emph{not} actually store @expr{5} as the ``global'' value of @code{foo}, however. Regular Calc operations, and Embedded formulas in other buffers, will not see this assignment. @@ -29905,7 +30249,7 @@ 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. @@ -29929,7 +30273,7 @@ to edit the number using regular Emacs editing rather than Embedded mode. Then, we have to find a way to get Embedded mode to notice the change. The @kbd{M-# u} or @kbd{M-# =} (@code{calc-embedded-update-formula}) command is a convenient way -to do this.@refill +to do this. @example foo := 6 @@ -29982,7 +30326,7 @@ a few lines that look like this: @noindent where the leading and trailing @samp{---} can be replaced by any suitable strings (which must be the same on all three lines) -or omitted altogether; in a @TeX{} file, @samp{%} would be a good +or omitted altogether; in a @TeX{} or @LaTeX{} file, @samp{%} would be a good leading string and no trailing string would be necessary. In a C program, @samp{/*} and @samp{*/} would be good leading and trailing strings. @@ -30074,15 +30418,15 @@ use @kbd{M-# u} to update the buffer by hand. @section Mode Settings in Embedded Mode @noindent -Embedded Mode has a rather complicated mechanism for handling mode +Embedded mode has a rather complicated mechanism for handling mode settings in Embedded formulas. It is possible to put annotations in the file that specify mode settings either global to the entire file or local to a particular formula or formulas. In the latter case, different modes can be specified for use when a formula -is the enabled Embedded Mode formula. +is the enabled Embedded mode formula. -When you give any mode-setting command, like @kbd{m f} (for fraction -mode) or @kbd{d s} (for scientific notation), Embedded Mode adds +When you give any mode-setting command, like @kbd{m f} (for Fraction +mode) or @kbd{d s} (for scientific notation), Embedded mode adds a line like the following one to the file just before the opening delimiter of the formula. @@ -30135,7 +30479,7 @@ sure the value is of a legal type or range; if you write an annotation by hand, be sure to give a proper value or results will be unpredictable. Mode-setting annotations are case-sensitive. -While Embedded Mode is enabled, the word @code{Local} appears in +While Embedded mode is enabled, the word @code{Local} appears in the mode line. This is to show that mode setting commands generate annotations that are ``local'' to the current formula or set of formulas. The @kbd{m R} (@code{calc-mode-record-mode}) command @@ -30151,7 +30495,7 @@ that look like this, respectively: @end example The first kind of annotation will be used only while a formula -is enabled in Embedded Mode. The second kind will be used only +is enabled in Embedded mode. The second kind will be used only when the formula is @emph{not} enabled. (Whether the formula is ``active'' or not, i.e., whether Calc has seen this formula yet, is not relevant here.) @@ -30193,31 +30537,32 @@ We would have to go down to the other formula and press @kbd{M-# u} on it in order to get it to notice the new annotation. Two more mode-recording modes selectable by @kbd{m R} are @code{Save} -(which works even outside of Embedded Mode), in which mode settings -are recorded permanently in your Emacs startup file @file{~/.emacs} +(which works even outside of Embedded mode), in which mode settings +are recorded permanently in your Calc init file (the file given by the +variable @code{calc-settings-file}, typically @file{~/.calc.el}) rather than by annotating the current document, and no-recording mode (where there is no symbol like @code{Save} or @code{Local} in the mode line), in which mode-changing commands do not leave any annotations at all. -When Embedded Mode is not enabled, mode-recording modes except +When Embedded mode is not enabled, mode-recording modes except for @code{Save} have no effect. @node Customizing Embedded Mode, , Mode Settings in Embedded Mode, Embedded Mode @section Customizing Embedded Mode @noindent -You can modify Embedded Mode's behavior by setting various Lisp +You can modify Embedded mode's behavior by setting various Lisp variables described here. Use @kbd{M-x set-variable} or @kbd{M-x edit-options} to adjust a variable on the fly, or -put a suitable @code{setq} statement in your @file{~/.emacs} -file to set a variable permanently. (Another possibility would +put a suitable @code{setq} statement in your Calc init file (or +@file{~/.emacs}) to set a variable permanently. (Another possibility would be to use a file-local variable annotation at the end of the file; @pxref{File Variables, , Local Variables in Files, emacs, the Emacs manual}.) While none of these variables will be buffer-local by default, you -can make any of them local to any embedded-mode buffer. (Their +can make any of them local to any Embedded mode buffer. (Their values in the @samp{*Calculator*} buffer are never used.) @vindex calc-embedded-open-formula @@ -30306,7 +30651,7 @@ The default string is @code{"%%% "} (note the trailing space). @vindex calc-embedded-close-plain The @code{calc-embedded-close-plain} variable is a string which ends a ``plain'' formula. The default is @code{" %%%\n"}. Without -the trailing newline here, the first line of a ``big'' mode formula +the trailing newline here, the first line of a Big mode formula that followed might be shifted over with respect to the other lines. @vindex calc-embedded-open-new-formula @@ -30449,30 +30794,30 @@ key we defined above. @pindex calc-user-define-permanent @cindex Storing user definitions @cindex Permanent user definitions -@cindex @file{.emacs} file, user-defined commands +@cindex Calc init file, user-defined commands The @kbd{Z P} (@code{calc-user-define-permanent}) command makes a key binding permanent so that it will remain in effect even in future Emacs sessions. (It does this by adding a suitable bit of Lisp code into -your @file{.emacs} file.) For example, @kbd{Z P s} would register -our @code{sincos} command permanently. If you later wish to unregister -this command you must edit your @file{.emacs} file by hand. -(@xref{General Mode Commands}, for a way to tell Calc to use a -different file instead of @file{.emacs}.) +your Calc init file; that is, the file given by the variable +@code{calc-settings-file}, typically @file{~/.calc.el}.) For example, +@kbd{Z P s} would register our @code{sincos} command permanently. If +you later wish to unregister this command you must edit your Calc init +file by hand. (@xref{General Mode Commands}, for a way to tell Calc to +use a different file for the Calc init file.) The @kbd{Z P} command also saves the user definition, if any, for the command bound to the key. After @kbd{Z F} and @kbd{Z C}, a given user key could invoke a command, which in turn calls an algebraic function, which might have one or more special display formats. A single @kbd{Z P} command will save all of these definitions. - -To save a command or function without its key binding (or if there is -no key binding for the command or function), type @kbd{'} (the apostrophe) -when prompted for a key. Then, type the function name, or backspace -to change the @samp{calcFunc-} prefix to @samp{calc-} and enter a -command name. (If the command you give implies a function, the function -will be saved, and if the function has any display formats, those will -be saved, but not the other way around: Saving a function will not save -any commands or key bindings associated with the function.) +To save an algebraic function, type @kbd{'} (the apostrophe) +when prompted for a key, and type the function name. To save a command +without its key binding, type @kbd{M-x} and enter a function name. (The +@samp{calc-} prefix will automatically be inserted for you.) +(If the command you give implies a function, the function will be saved, +and if the function has any display formats, those will be saved, but +not the other way around: Saving a function will not save any commands +or key bindings associated with the function.) @kindex Z E @pindex calc-user-define-edit @@ -30496,7 +30841,7 @@ performing their usual functions. Press @kbd{C-x )} to end recording. Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to execute your keyboard macro by replaying the recorded keystrokes. @xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further -information.@refill +information. When you use @kbd{X} to invoke a keyboard macro, the entire macro is treated as a single command by the undo and trail features. The stack @@ -30542,7 +30887,7 @@ sequence. The default command name (if you answer the second prompt with just the @key{RET} key as in this example) will be something like @samp{calc-User-n}. The keyboard macro will now be available as both @kbd{z n} and @kbd{M-x calc-User-n}. You can backspace and enter a more -descriptive command name if you wish.@refill +descriptive command name if you wish. Macros defined by @kbd{Z K} act like single commands; they are executed in the same way as by the @kbd{X} key. If you wish to define the macro @@ -30554,33 +30899,19 @@ Once you have bound your keyboard macro to a key, you can use @cindex Keyboard macros, editing The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has -been defined by a keyboard macro tries to use the @code{edit-kbd-macro} -command to edit the macro. This command may be found in the -@file{macedit} package, a copy of which comes with Calc. It decomposes -the macro definition into full Emacs command names, like @code{calc-pop} -and @code{calc-add}. Type @kbd{M-# M-#} to finish editing and update -the definition stored on the key, or, to cancel the edit, type -@kbd{M-# x}.@refill - -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 @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 -@code{NUL} must be written in all uppercase, as must the prefixes @code{C-} -and @code{M-}. Spaces and line breaks are ignored. Other characters are +been defined by a keyboard macro tries to use the @code{edmacro} package +edit the macro. Type @kbd{C-c C-c} to finish editing and update +the definition stored on the key, or, to cancel the edit, kill the +buffer with @kbd{C-x k}. +The special characters @code{RET}, @code{LFD}, @code{TAB}, @code{SPC}, +@code{DEL}, and @code{NUL} must be entered as these three character +sequences, written in all uppercase, as must the prefixes @code{C-} 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] @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 -in ``raw'' form; the editing buffer simply contains characters like -@samp{1^M2+} (here @samp{^M} represents the carriage-return character). -Editing in this mode, you will have to use @kbd{C-q} to enter new -control characters into the buffer.@refill +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}}. @kindex M-# m @pindex read-kbd-macro @@ -30588,7 +30919,6 @@ The @kbd{M-# m} (@code{read-kbd-macro}) command reads an Emacs ``region'' of spelled-out keystrokes and defines it as the current keyboard macro. It is a convenient way to define a keyboard macro that has been stored in a file, or to define a macro without executing it at the same time. -The @kbd{M-# m} command works only if @file{macedit} is present. @node Conditionals in Macros, Loops in Macros, Naming Keyboard Macros, Keyboard Macros @subsection Conditionals in Keyboard Macros @@ -30684,7 +31014,7 @@ body is skipped altogether. For example, @kbd{1 @key{TAB} Z < 2 * Z >} computes two to a nonnegative integer power. First, we push 1 on the stack and then swap the integer argument back to the top. The @kbd{Z <} pops that argument leaving the 1 back on top of the stack. Then, we -repeat a multiply-by-two step however many times.@refill +repeat a multiply-by-two step however many times. Once again, the keyboard macro is executed as it is being entered. In this case it is especially important to set up reasonable initial @@ -30704,7 +31034,7 @@ if that object is true (a non-zero number), control jumps out of the innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;} -in the C language.@refill +in the C language. @kindex Z ( @kindex Z ) @@ -30718,7 +31048,7 @@ command pops initial and final values from the stack. It then creates a temporary internal counter and initializes it with the value @var{init}. The @kbd{Z (} command then repeatedly pushes the counter value onto the stack and executes @var{body} and @var{step}, adding @var{step} to the -counter each time until the loop finishes.@refill +counter each time until the loop finishes. @cindex Summations (by keyboard macros) By default, the loop finishes when the counter becomes greater than (or @@ -30733,7 +31063,7 @@ forced to use upward-counting conventions. In this case, if @var{initial} is greater than @var{final} the body will not be executed at all. Note that @var{step} may still be negative in this loop; the prefix argument merely constrains the loop-finished test. Likewise, a prefix -argument of @i{-1} forces downward-counting conventions. +argument of @mathit{-1} forces downward-counting conventions. @kindex Z @{ @kindex Z @} @@ -30767,7 +31097,7 @@ conditional and looping commands. @cindex Restoring saved modes Keyboard macros sometimes want to operate under known conditions without affecting surrounding conditions. For example, a keyboard -macro may wish to turn on Fraction Mode, or set a particular +macro may wish to turn on Fraction mode, or set a particular precision, independent of the user's normal setting for those modes. @@ -30816,7 +31146,7 @@ for all mode-setting commands inside the macro. In fact, @kbd{C-u Z `} is like @kbd{Z `} except that it sets the modes listed above to their default values. As usual, the matching @kbd{Z '} will restore the modes to their settings from before the @kbd{C-u Z `}. -Also, @w{@kbd{Z `}} with a negative prefix argument resets algebraic mode +Also, @w{@kbd{Z `}} with a negative prefix argument resets the algebraic mode to its default (off) but leaves the other modes the same as they were outside the construct. @@ -30845,7 +31175,7 @@ This command allows your keyboard macros to accept numbers or formulas as interactive input. All the normal conventions of algebraic input, including the use of @kbd{$} characters, are supported. -@xref{Kbd Macro Query, , , emacs, the Emacs Manual}, for a description of +@xref{Keyboard Macro Query, , , emacs, the Emacs Manual}, for a description of @kbd{C-x q} (@code{kbd-macro-query}), the standard Emacs way to accept keyboard input during a keyboard macro. In particular, you can use @kbd{C-x q} to enter a recursive edit, which allows the user to perform @@ -30912,13 +31242,15 @@ If you want to give the formula a long-style name only, you can press @kbd{Z F @key{RET} spam @key{RET}} defines the new command as @kbd{M-x calc-spam}, with no keyboard equivalent. -The third prompt is for a function name. The default is to use the same -name as the command name but with @samp{calcFunc-} in place of -@samp{calc-}. This is the name you will use if you want to enter your +The third prompt is for an algebraic function name. The default is to +use the same name as the command name but without the @samp{calc-} +prefix. (If this is of the form @samp{User-m}, the hyphen is removed so +it won't be taken for a minus sign in algebraic formulas.) +This is the name you will use if you want to enter your new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}. Then the new function can be invoked by pushing two numbers on the stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic -formula @samp{yow(x,y)}.@refill +formula @samp{yow(x,y)}. The fourth prompt is for the function's argument list. This is used to associate values on the stack with the variables that appear in the formula. @@ -30929,9 +31261,9 @@ two numbers from the stack, substitute these numbers for @samp{a} and @samp{b} (respectively) in the formula, then simplify the formula and push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m} would replace the 10 and 100 on the stack with the number 210, which is -@cite{a + 2 b} with @cite{a=10} and @cite{b=100}. Likewise, the formula -@samp{yow(10, 100)} will be evaluated by substituting @cite{a=10} and -@cite{b=100} in the definition. +@expr{a + 2 b} with @expr{a=10} and @expr{b=100}. Likewise, the formula +@samp{yow(10, 100)} will be evaluated by substituting @expr{a=10} and +@expr{b=100} in the definition. You can rearrange the order of the names before pressing @key{RET} to control which stack positions go to which variables in the formula. If @@ -30949,12 +31281,12 @@ using the argument list @samp{(a b)}. The final prompt is a y-or-n question concerning what to do if symbolic arguments are given to your function. If you answer @kbd{y}, then executing @kbd{z m} (using the original argument list @samp{(a b)}) with -arguments @cite{10} and @cite{x} will leave the function in symbolic +arguments @expr{10} and @expr{x} will leave the function in symbolic form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n}, then the formula will always be expanded, even for non-constant arguments: @samp{10 + 2 x}. If you never plan to feed algebraic formulas to your new function, it doesn't matter how you answer this -question.@refill +question. If you answered @kbd{y} to this question you can still cause a function call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}). @@ -30969,12 +31301,13 @@ key, and this command pushes the formula that was used to define that key onto the stack. Actually, it pushes a nameless function that specifies both the argument list and the defining formula. You will get an error message if the key is undefined, or if the key was not defined -by a @kbd{Z F} command.@refill +by a @kbd{Z F} command. The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has been defined by a formula uses a variant of the @code{calc-edit} command -to edit the defining formula. Press @kbd{M-# M-#} to finish editing and -store the new formula back in the definition, or @kbd{M-# x} to +to edit the defining formula. Press @kbd{C-c C-c} to finish editing and +store the new formula back in the definition, or kill the buffer with +@kbd{C-x k} to cancel the edit. (The argument list and other properties of the definition are unchanged; to adjust the argument list, you can use @kbd{Z G} to grab the function onto the stack, edit with @kbd{`}, and @@ -30989,7 +31322,7 @@ You may find it useful to turn off the default simplifications with used as a function definition. For example, the formula @samp{deriv(a^2,v)} which might be used to define a new function @samp{dsqr(a,v)} will be ``simplified'' to 0 immediately upon entry since @code{deriv} considers -@cite{a} to be constant with respect to @cite{v}. Turning off +@expr{a} to be constant with respect to @expr{v}. Turning off default simplifications cures this problem: The definition will be stored in symbolic form without ever activating the @code{deriv} function. Press @kbd{m D} to turn the default simplifications back on afterwards. @@ -31087,7 +31420,7 @@ The following standard Lisp functions are treated by @code{defmath}: @code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=}, @code{/=}, @code{1+}, @code{1-}, @code{logand}, @code{logior}, @code{logxor}, @code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for -@code{math-nearly-equal}, which is useful in implementing Taylor series.@refill +@code{math-nearly-equal}, which is useful in implementing Taylor series. For other functions @var{func}, if a function by the name @samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the @@ -31095,13 +31428,13 @@ name @samp{math-@var{func}} exists it is used, otherwise if @var{func} itself is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is used on the assumption that this is a to-be-defined math function. Also, if the function name is quoted as in @samp{('integerp a)} the function name is -always used exactly as written (but not quoted).@refill +always used exactly as written (but not quoted). Variable names have @samp{var-} prepended to them unless they appear in the function's argument list or in an enclosing @code{let}, @code{let*}, @code{for}, or @code{foreach} form, or their names already contain a @samp{-} character. Thus a reference to -@samp{foo} is the same as a reference to @samp{var-foo}.@refill +@samp{foo} is the same as a reference to @samp{var-foo}. A few other Lisp extensions are available in @code{defmath} definitions: @@ -31119,18 +31452,18 @@ Lisp @code{setf} function. (The name @code{setf} is recognized as a synonym of @code{setq}.) Specifically, the first argument of @code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form, in which case the effect is to store into the specified -element of a list. Thus, @samp{(setq (elt m i j) x)} stores @cite{x} +element of a list. Thus, @samp{(setq (elt m i j) x)} stores @expr{x} into one element of a matrix. @item A @code{for} looping construct is available. For example, @samp{(for ((i 0 10)) body)} executes @code{body} once for each -binding of @cite{i} from zero to 10. This is like a @code{let} -form in that @cite{i} is temporarily bound to the loop count +binding of @expr{i} from zero to 10. This is like a @code{let} +form in that @expr{i} is temporarily bound to the loop count without disturbing its value outside the @code{for} construct. Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)}, -are also available. For each value of @cite{i} from zero to 10, -@cite{j} counts from 0 to @cite{i-1} in steps of two. Note that +are also available. For each value of @expr{i} from zero to 10, +@expr{j} counts from 0 to @expr{i-1} in steps of two. Note that @code{for} has the same general outline as @code{let*}, except that each element of the header is a list of three or four things, not just two. @@ -31138,8 +31471,8 @@ things, not just two. @item The @code{foreach} construct loops over elements of a list. For example, @samp{(foreach ((x (cdr v))) body)} executes -@code{body} with @cite{x} bound to each element of Calc vector -@cite{v} in turn. The purpose of @code{cdr} here is to skip over +@code{body} with @expr{x} bound to each element of Calc vector +@expr{v} in turn. The purpose of @code{cdr} here is to skip over the initial @code{vec} symbol in the vector. @item @@ -31150,7 +31483,7 @@ loop. (Lisp loops otherwise always return @code{nil}.) @item The @code{return} function prematurely returns from the enclosing -function. For example, @samp{(return (+ x y))} returns @cite{x+y} +function. For example, @samp{(return (+ x y))} returns @expr{x+y} as the value of a function. You can use @code{return} anywhere inside the body of the function. @end itemize @@ -31185,12 +31518,17 @@ step of @code{myfact} could have been written :"n * myfact(n-1)" @end example +A good place to put your @code{defmath} commands is your Calc init file +(the file given by @code{calc-settings-file}, typically +@file{~/.calc.el}), which will not be loaded until Calc starts. If a file named @file{.emacs} exists in your home directory, Emacs reads and executes the Lisp forms in this file as it starts up. While it may -seem like a good idea to put your favorite @code{defmath} commands here, +seem reasonable to put your favorite @code{defmath} commands there, this has the unfortunate side-effect that parts of the Calculator must be loaded in to process the @code{defmath} commands whether or not you will -actually use the Calculator! A better effect can be had by writing +actually use the Calculator! If you want to put the @code{defmath} +commands there (for example, if you redefine @code{calc-settings-file} +to be @file{.emacs}), a better effect can be had by writing @example (put 'calc-define 'thing '(progn @@ -31502,7 +31840,7 @@ Emacs-style code string as well which comes just before @var{num} and In this example, the command @code{calc-foo} will evaluate the expression @samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if -executed with a numeric prefix argument of @cite{n}. +executed with a numeric prefix argument of @expr{n}. The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"} code as used with @code{defun}). It uses the numeric prefix argument as the @@ -31539,7 +31877,7 @@ The following qualifiers are recognized: The argument must not be an incomplete vector, interval, or complex number. (This is rarely needed since the Calculator itself will never call your function with an incomplete argument. But there is nothing stopping your -own Lisp code from calling your function with an incomplete argument.)@refill +own Lisp code from calling your function with an incomplete argument.) @item integer @findex integer @@ -31703,8 +32041,9 @@ same thing with a single division by 512. @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$} -@samp{sin(x)}: +well-known Taylor series expansion for +@texline @math{\sin x}: +@infoline @samp{sin(x)}: @smallexample (defmath mysin ((float (anglep x))) @@ -31726,8 +32065,7 @@ well-known Taylor series expansion for @c{$\sin x$} @end smallexample The actual @code{sin} function in Calc works by first reducing the problem -to a sine or cosine of a nonnegative number less than @c{$\pi \over 4$} -@cite{pi/4}. This +to a sine or cosine of a nonnegative number less than @cpiover{4}. This ensures that the Taylor series will converge quickly. Also, the calculation is carried out with two extra digits of precision to guard against cumulative round-off in @samp{sum}. Finally, complex arguments are allowed and handled @@ -31762,12 +32100,11 @@ numbers, @code{mysin-series} is the routine to compute the sine Taylor series as before, and @code{mycos-raw} is a function analogous to @code{mysin-raw} for cosines. -The strategy is to ensure that @cite{x} is nonnegative before calling +The strategy is to ensure that @expr{x} is nonnegative before calling @code{mysin-raw}. This function then recursively reduces its argument -to a suitable range, namely, plus-or-minus @c{$\pi \over 4$} -@cite{pi/4}. Note that each +to a suitable range, namely, plus-or-minus @cpiover{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 @@ -31889,7 +32226,7 @@ If the first argument to @code{calc-eval} is a list whose first element is a formula string, then @code{calc-eval} sets all the various Calc modes to their default values while the formula is evaluated and formatted. For example, the precision is set to 12 -digits, digit grouping is turned off, and the normal language +digits, digit grouping is turned off, and the Normal language mode is used. This same principle applies to the other options discussed below. @@ -31912,11 +32249,11 @@ It's usually best to use this form of @code{calc-eval} unless your program actually considers the interaction with Calc's mode settings to be a feature. This will avoid all sorts of potential ``gotchas''; consider what happens with @samp{(calc-eval "sqrt(2)" 'num)} -when the user has left Calc in symbolic mode or no-simplify mode. +when the user has left Calc in Symbolic mode or No-Simplify mode. As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")} -checks if the number in string @cite{a} is less than the one in -string @cite{b}. Without using a list, the integer 1 might +checks if the number in string @expr{a} is less than the one in +string @expr{b}. Without using a list, the integer 1 might come out in a variety of formats which would be hard to test for conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But see ``Predicates'' mode, below.) @@ -31942,7 +32279,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 @@ -32228,10 +32565,10 @@ which is not a Lisp list. Large integers are stored as lists of the form @samp{(bigpos @var{d0} @var{d1} @var{d2} @dots{})} for positive integers 1000000 or more, or @samp{(bigneg @var{d0} @var{d1} @var{d2} @dots{})} for negative integers -@i{-1000000} or less. Each @var{d} is a base-1000 ``digit,'' a Lisp integer +@mathit{-1000000} or less. Each @var{d} is a base-1000 ``digit,'' a Lisp integer from 0 to 999. The least significant digit is @var{d0}; the last digit, @var{dn}, which is always nonzero, is the most significant digit. For -example, the integer @i{-12345678} is stored as @samp{(bigneg 678 345 12)}. +example, the integer @mathit{-12345678} is stored as @samp{(bigneg 678 345 12)}. The distinction between small and large integers is entirely hidden from the user. In @code{defmath} definitions, the Lisp predicate @code{integerp} @@ -32252,17 +32589,17 @@ Floating-point numbers are stored in the form, @samp{(float @var{mant} @samp{10^@var{p}} in absolute value (@var{p} represents the current precision), and @var{exp} (the ``exponent'') is a fixnum. The value of the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number -@i{-3.14} is stored as @samp{(float -314 -2) = -314*10^-2}. Other constraints +@mathit{-3.14} is stored as @samp{(float -314 -2) = -314*10^-2}. Other constraints are that the number 0.0 is always stored as @samp{(float 0 0)}, and, except for the 0.0 case, the rightmost base-10 digit of @var{mant} is always nonzero. (If the rightmost digit is zero, the number is -rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)@refill +rearranged by dividing @var{mant} by ten and incrementing @var{exp}.) Rectangular complex numbers are stored in the form @samp{(cplx @var{re} @var{im})}, where @var{re} and @var{im} are each real numbers, either integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}. The @var{im} part is nonzero; complex numbers with zero imaginary -components are converted to real numbers automatically.@refill +components are converted to real numbers automatically. Polar complex numbers are stored in the form @samp{(polar @var{r} @var{theta})}, where @var{r} is a positive real value and @var{theta} @@ -32271,13 +32608,13 @@ usually normalized to lie in the interval @samp{(-180 ..@: 180)} degrees, or @samp{(-pi ..@: pi)} radians, according to the current angular mode. If the angle is 0 the value is converted to a real number automatically. (If the angle is 180 degrees, the value is usually also converted to a -negative real number.)@refill +negative real number.) Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m} @var{s})}, where @var{h} is an integer or an integer-valued float (i.e., a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number -in the range @samp{[0 ..@: 60)}.@refill +in the range @samp{[0 ..@: 60)}. Date forms are stored as @samp{(date @var{n})}, where @var{n} is a real number that counts days since midnight on the morning of @@ -32331,7 +32668,7 @@ which is evaluated when the constant's value is requested. Variables which represent units are not stored in any special way; they are units only because their names appear in the units table. If the value cell contains a string, it is parsed to get the variable's value when -the variable is used.@refill +the variable is used. A Lisp list with any other symbol as the first element is a function call. The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^}, @@ -32351,7 +32688,7 @@ object which represents their value, or a list of such objects if they wish to return multiple values. (The latter case is allowed only for functions which are the outer-level call in an expression whose value is about to be pushed on the stack; this feature is considered obsolete -and is not used by any built-in Calc functions.)@refill +and is not used by any built-in Calc functions.) @node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats, Internals @subsubsection Interactive Functions @@ -32387,7 +32724,7 @@ contains the variable's value) was stored and its previous value was previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})}, which means that to undo requires calling the function @samp{(@var{undo} @var{args} @dots{})} and, if the undo is later redone, calling -@samp{(@var{redo} @var{args} @dots{})}.@refill +@samp{(@var{redo} @var{args} @dots{})}. @end defun @defun calc-record-why msg args @@ -32402,7 +32739,7 @@ some sort. If @var{msg} is a symbol, it is the name of a Calc predicate (such as @code{integerp} or @code{numvecp}) which the arguments did not satisfy; it is expanded to a suitable string such as ``Expected an integer.'' The @code{reject-arg} function calls @code{calc-record-why} -automatically; @pxref{Predicates}.@refill +automatically; @pxref{Predicates}. @end defun @defun calc-is-inverse @@ -32429,7 +32766,7 @@ elements will be inserted into the stack so that the last element will end up at level @var{n}, the next-to-last at level @var{n}+1, etc. The elements of @var{vals} are assumed to be valid Calc objects, and are not evaluated, rounded, or renormalized in any way. If @var{vals} -is an empty list, nothing happens.@refill +is an empty list, nothing happens. The stack elements are pushed without any sub-formula selections. You can give an optional third argument to this function, which must @@ -32448,7 +32785,7 @@ one-element list) is returned. If @var{m} is greater than 1, the element will be next-to-last, etc. If @var{n} or @var{m} are out of range, the command is aborted with a suitable error message. If @var{n} is zero, the function returns an empty list. The stack elements are not -evaluated, rounded, or renormalized.@refill +evaluated, rounded, or renormalized. If any stack elements contain selections, and selections have not been disabled by the @kbd{j e} (@code{calc-enable-selections}) command, @@ -32488,7 +32825,7 @@ will be used. This function takes a Calc object and ``normalizes'' it. At the very least this involves re-rounding floating-point values according to the current precision and other similar jobs. Also, unless the user has -selected no-simplify mode (@pxref{Simplification Modes}), this involves +selected No-Simplify mode (@pxref{Simplification Modes}), this involves actually evaluating a formula object by executing the function calls it contains, and possibly also doing algebraic simplification, etc. @end defun @@ -32544,7 +32881,7 @@ This function implements a unary operator that allows a numeric prefix argument to apply the operator over many stack entries. If the prefix argument @var{arg} is @code{nil}, this uses @code{calc-enter-result} as outlined above. Otherwise, it maps the function over several stack -elements; @pxref{Prefix Arguments}. For example,@refill +elements; @pxref{Prefix Arguments}. For example, @smallexample (defun calc-zeta (arg) @@ -32564,8 +32901,8 @@ is applied to the top stack element, or, if @var{unary} is not specified, nothing happens. When the argument is two or more, the binary function @var{func} is reduced across the top @var{arg} stack elements; when the argument is negative, the function is -mapped between the next-to-top @i{-@var{arg}} stack elements and the -top element.@refill +mapped between the next-to-top @mathit{-@var{arg}} stack elements and the +top element. @end defun @defun calc-stack-size @@ -32579,7 +32916,7 @@ Move the point to the @var{n}th stack entry. If @var{n} is zero, this will be the @samp{.} line. If @var{n} is from 1 to the current stack size, this will be the beginning of the first line of that stack entry's display. If line numbers are enabled, this will move to the first character of the -line number, not the stack entry itself.@refill +line number, not the stack entry itself. @end defun @defun calc-substack-height n @@ -32589,7 +32926,7 @@ will be one (assuming no stack truncation). If all stack entries are one line long (i.e., no matrices are displayed), the return value will be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big mode, the return value includes the blank lines that separate stack -entries.)@refill +entries.) @end defun @defun calc-refresh @@ -32598,7 +32935,7 @@ This must be called after changing any parameter, such as the current display radix, which might change the appearance of existing stack entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing is suppressed, but a flag is set so that the entire stack will be refreshed -rather than just the top few elements when the macro finishes.)@refill +rather than just the top few elements when the macro finishes.) @end defun @node Predicates, Computational Lisp Functions, Stack Lisp Functions, Internals @@ -32777,7 +33114,7 @@ undefined or cannot be determined. Generally speaking, this works by checking whether @samp{@var{x} - @var{y}} is @code{negp}. In @code{defmath}, the expression @samp{(< x y)} will automatically be converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=}, -and @code{>=} are similarly converted in terms of @code{lessp}.@refill +and @code{>=} are similarly converted in terms of @code{lessp}. @end defun @defun beforep x y @@ -32809,7 +33146,7 @@ converted to @samp{(math-equal x y)}. Returns true if @var{x} and @var{n} are numerically equal, where @var{n} is a fixnum which is not a multiple of 10. This will automatically be used by @code{defmath} in place of the more general @code{math-equal} -whenever possible.@refill +whenever possible. @end defun @defun nearly-equal x y @@ -32846,18 +33183,18 @@ or a provably non-zero formula. Abort the current function evaluation due to unacceptable argument values. This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a Lisp error which @code{normalize} will trap. The net effect is that the -function call which led here will be left in symbolic form.@refill +function call which led here will be left in symbolic form. @end defun @defun inexact-value -If Symbolic Mode is enabled, this will signal an error that causes +If Symbolic mode is enabled, this will signal an error that causes @code{normalize} to leave the formula in symbolic form, with the message -``Inexact result.'' (This function has no effect when not in Symbolic Mode.) -Note that if your function calls @samp{(sin 5)} in Symbolic Mode, the +``Inexact result.'' (This function has no effect when not in Symbolic mode.) +Note that if your function calls @samp{(sin 5)} in Symbolic mode, the @code{sin} function will call @code{inexact-value}, which will cause your function to be left unsimplified. You may instead wish to call -@samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic Mode will -return the formula @samp{sin(5)} to your function.@refill +@samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic mode will +return the formula @samp{sin(5)} to your function. @end defun @defun overflow @@ -32878,13 +33215,13 @@ the main body of this manual may be called from Lisp; for example, if the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command, this means @code{calc-sqrt} is an interactive stack-based square-root command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt}) -is the actual Lisp function for taking square roots.@refill +is the actual Lisp function for taking square roots. The functions @code{math-add}, @code{math-sub}, @code{math-mul}, @code{math-div}, @code{math-mod}, and @code{math-neg} are not included in this list, since @code{defmath} allows you to write native Lisp @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, and unary @code{-}, -respectively, instead.@refill +respectively, instead. @defun normalize val (Full form: @code{math-normalize}.) @@ -32895,27 +33232,27 @@ if @var{val} is a bignum it will be normalized by clipping off trailing small. All the various data types are similarly converted to their standard forms. Variables are left alone, but function calls are actually evaluated in formulas. For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will -return 6.@refill +return 6. If a function call fails, because the function is void or has the wrong number of parameters, or because it returns @code{nil} or calls @code{reject-arg} or @code{inexact-result}, @code{normalize} returns -the formula still in symbolic form.@refill +the formula still in symbolic form. -If the current Simplification Mode is ``none'' or ``numeric arguments +If the current simplification mode is ``none'' or ``numeric arguments only,'' @code{normalize} will act appropriately. However, the more -powerful simplification modes (like algebraic simplification) are +powerful simplification modes (like Algebraic Simplification) are not handled by @code{normalize}. They are handled by @code{calc-normalize}, which calls @code{normalize} and possibly some other routines, such as @code{simplify} or @code{simplify-units}. Programs generally will never call @code{calc-normalize} except when popping or pushing values -on the stack.@refill +on the stack. @end defun @defun evaluate-expr expr Replace all variables in @var{expr} that have values with their values, then use @code{normalize} to simplify the result. This is what happens -when you press the @kbd{=} key interactively.@refill +when you press the @kbd{=} key interactively. @end defun @defmac with-extra-prec n body @@ -32983,10 +33320,10 @@ or formula, this calls @code{reject-arg}. @end defun @defun compare x y -Compare the numbers @var{x} and @var{y}, and return @i{-1} if +Compare the numbers @var{x} and @var{y}, and return @mathit{-1} if @samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})}, 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is -undefined or cannot be determined.@refill +undefined or cannot be determined. @end defun @defun numdigs n @@ -32996,7 +33333,7 @@ considered to have zero digits. @end defun @defun scale-int x n -Shift integer @var{x} left @var{n} decimal digits, or right @i{-@var{n}} +Shift integer @var{x} left @var{n} decimal digits, or right @mathit{-@var{n}} digits with truncation toward zero. @end defun @@ -33038,13 +33375,13 @@ For a more well-defined result, use @samp{(% @var{x} @var{y})}. @defun idivmod x y Divide integer @var{x} by integer @var{y}; return a cons cell whose @code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr} -is @samp{(imod @var{x} @var{y})}.@refill +is @samp{(imod @var{x} @var{y})}. @end defun @defun pow x y Compute @var{x} to the power @var{y}. In @code{defmath} code, this can also be written @samp{(^ @var{x} @var{y})} or -@w{@samp{(expt @var{x} @var{y})}}.@refill +@w{@samp{(expt @var{x} @var{y})}}. @end defun @defun abs-approx x @@ -33068,7 +33405,7 @@ Other related constant-generating functions are @code{two-pi}, @code{pi-over-2}, @code{pi-over-4}, @code{pi-over-180}, @code{sqrt-two-pi}, @code{e}, @code{sqrt-e}, @code{ln-2}, and @code{ln-10}. Each function returns a floating-point value in the current precision, and each uses -caching so that all calls after the first are essentially free.@refill +caching so that all calls after the first are essentially free. @end defun @defmac math-defcache @var{func} @var{initial} @var{form} @@ -33083,7 +33420,7 @@ with the current precision increased by four, and the result minus its two least significant digits is stored in the cache. For example, calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34 digits, rounds it down to 32 digits for future use, then rounds it -again to 30 digits for use in the present request.@refill +again to 30 digits for use in the present request. @end defmac @findex half-circle @@ -33092,7 +33429,7 @@ again to 30 digits for use in the present request.@refill If the current angular mode is Degrees or HMS, this function returns the integer 360. In Radians mode, this function returns either the corresponding value in radians to the current precision, or the formula -@samp{2*pi}, depending on the Symbolic Mode. There are also similar +@samp{2*pi}, depending on the Symbolic mode. There are also similar function @code{half-circle} and @code{quarter-circle}. @end defun @@ -33110,7 +33447,7 @@ return @code{nil}. @defun div-mod a b m Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if -there is no solution, or if any of the arguments are not integers.@refill +there is no solution, or if any of the arguments are not integers. @end defun @defun pow-mod a b m @@ -33150,12 +33487,12 @@ If @var{a} is a formula, this returns the formula @samp{deg(@var{a})}. @end defun @defun to-radians-2 a -Like @code{to-radians}, except that in Symbolic Mode a degrees to +Like @code{to-radians}, except that in Symbolic mode a degrees to radians conversion yields a formula like @samp{@var{a}*pi/180}. @end defun @defun from-radians-2 a -Like @code{from-radians}, except that in Symbolic Mode a radians to +Like @code{from-radians}, except that in Symbolic mode a radians to degrees conversion yields a formula like @samp{@var{a}*180/pi}. @end defun @@ -33185,7 +33522,7 @@ iterations, is @var{p} percent sure that the number is prime. The @var{iters} parameter is the number of Fermat iterations to use, in the case that this is necessary. If @code{prime-test} returns ``maybe,'' you can call it again with the same @var{n} to get a greater certainty; -@code{prime-test} remembers where it left off.@refill +@code{prime-test} remembers where it left off. @end defun @defun to-simple-fraction f @@ -33204,7 +33541,7 @@ function @code{frac}, and can be rather slow. @defun quarter-integer n If @var{n} is an integer or integer-valued float, this function returns zero. If @var{n} is a half-integer (i.e., an integer plus -@i{1:2} or 0.5), it returns 2. If @var{n} is a quarter-integer, +@mathit{1:2} or 0.5), it returns 2. If @var{n} is a quarter-integer, it returns 1 or 3. If @var{n} is anything else, this function returns @code{nil}. @end defun @@ -33236,7 +33573,7 @@ the result is the list @samp{(@var{r} @var{c})}. Higher-order tensors produce lists of more than two dimensions. Note that the object @samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size, and is treated by this and other Calc routines as a plain vector of two -elements.@refill +elements. @end defun @defun dimension-error @@ -33284,7 +33621,7 @@ for each pair of elements @var{ai} and @var{bi}. If either @var{a} or For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v} with each element increased by one. Note that using @samp{'+} would not work here, since @code{defmath} does not expand function names everywhere, -just where they are in the function position of a Lisp expression.@refill +just where they are in the function position of a Lisp expression. @end defun @defun reduce-vec f v @@ -33334,7 +33671,7 @@ If @var{m} is a matrix, return a copy of @var{m}. This maps element of the result matrix will be @code{eq} to the corresponding element of @var{m}, but none of the @code{cons} cells that make up the structure of the matrix will be @code{eq}. If @var{m} is a plain -vector, this is the same as @code{copy-sequence}.@refill +vector, this is the same as @code{copy-sequence}. @end defun @defun swap-rows m r1 r2 @@ -33343,7 +33680,7 @@ other words, unlike most of the other functions described here, this function changes @var{m} itself rather than building up a new result matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)} is true, with the side effect of exchanging the first two rows of -@var{m}.@refill +@var{m}. @end defun @node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp Functions, Internals @@ -33481,7 +33818,7 @@ to @samp{x}, which is only valid when @var{x} is positive.) This is implemented by temporarily binding the variable @code{math-living-dangerously} to @code{t} (using a @code{let} form) and calling @code{simplify}. Dangerous simplification rules are written to check this variable -before taking any action.@refill +before taking any action. @end defun @defun simplify-units expr @@ -33503,7 +33840,7 @@ the functions @var{funcs}. If the function body returns @code{nil}, or if it returns a result @code{equal} to the original @code{expr}, it is ignored and Calc goes on to try the next simplification rule that applies. If the function body returns something different, that new formula is -substituted for @var{expr} in the original formula.@refill +substituted for @var{expr} in the original formula. At each point in the formula, rules are tried in the order of the original calls to @code{math-defsimplify}; the search stops after the @@ -33536,7 +33873,7 @@ convenient. Here is a typical example of a simplification rule: This is really a pair of rules written with one @code{math-defsimplify} for convenience; the first replaces @samp{arcsinh(-x)} with @samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x}, -replaces @samp{arcsinh(sinh(x))} with @samp{x}.@refill +replaces @samp{arcsinh(sinh(x))} with @samp{x}. @end defmac @defun common-constant-factor expr @@ -33571,7 +33908,7 @@ Compute a ``rational GCD'' of @var{a} and @var{b}, which must both be rational numbers. This is the fraction composed of the GCD of the numerators of @var{a} and @var{b}, over the GCD of the denominators. It is used by @code{common-constant-factor}. Note that the standard -@code{gcd} function uses the LCM to combine the denominators.@refill +@code{gcd} function uses the LCM to combine the denominators. @end defun @defun map-tree func expr many @@ -33586,7 +33923,7 @@ is returned by @code{map-tree}. Note that, unlike simplification rules, @var{func} functions may @emph{not} make destructive changes to @var{expr}. If a third argument @var{many} is provided, it is an integer which says how many times @var{func} may be applied; the -default, as described above, is infinitely many times.@refill +default, as described above, is infinitely many times. @end defun @defun compile-rewrites rules @@ -33703,14 +34040,14 @@ relying on the general integration-by-substitution facility to handle cosines of more complicated arguments. An integration rule should return @code{nil} if it can't do the integral; if several rules are defined for the same function, they are tried in order until one returns a non-@code{nil} -result.@refill +result. @end defmac @defmac math-defintegral-2 funcs body Define a rule for integrating a function or functions of two arguments. This is exactly analogous to @code{math-defintegral}, except that @var{body} is written as the body of a function with two arguments, @var{u} and -@var{v}.@refill +@var{v}. @end defmac @defun solve-for lhs rhs var full @@ -33723,7 +34060,7 @@ different from the user-level @code{solve} and @code{finv} functions, which return a rearranged equation or a functional inverse, respectively. If @var{full} is non-@code{nil}, a full solution including dummy signs and dummy integers will be produced. User-defined inverses are provided -as properties in a manner similar to derivatives:@refill +as properties in a manner similar to derivatives: @smallexample (put 'calcFunc-ln 'math-inverse @@ -33759,12 +34096,12 @@ This function might seem at first to be identical to @code{expr-contains} uses @code{equal} to test for matches, whereas @code{calc-find-sub-formula} uses @code{eq}. In the formula @samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not -@code{eq} to each other.@refill +@code{eq} to each other. @end defun @defun expr-contains-count expr var Returns the number of occurrences of @var{var} as a subexpression -of @var{expr}, or @code{nil} if there are no occurrences.@refill +of @var{expr}, or @code{nil} if there are no occurrences. @end defun @defun expr-depends expr var @@ -33782,7 +34119,7 @@ contains only constants and functions with constant arguments. Returns a copy of @var{expr}, with all occurrences of @var{old} replaced by @var{new}. This treats @code{lambda} forms specially with respect to the dummy argument variables, so that the effect is always to return -@var{expr} evaluated at @var{old} = @var{new}.@refill +@var{expr} evaluated at @var{old} = @var{new}. @end defun @defun multi-subst expr old new @@ -33801,7 +34138,7 @@ number of objects and function calls that appear in @var{expr}. For @defun expr-height expr Returns the ``height'' of @var{expr}, which is the deepest level to which function calls are nested. (Note that @samp{@var{a} + @var{b}} -counts as a function call.) For primitive objects, this returns zero.@refill +counts as a function call.) For primitive objects, this returns zero. @end defun @defun polynomial-p expr var @@ -33813,7 +34150,7 @@ for @samp{(x^2 + 3)^3 + 4} this would return 6. This function returns (@code{calc-expand}), would consist of a sum of terms in which @var{var} appears only raised to nonnegative integer powers. Note that if @var{var} does not occur in @var{expr}, then @var{expr} is considered -a polynomial of degree 0.@refill +a polynomial of degree 0. @end defun @defun is-polynomial expr var degree loose @@ -33835,7 +34172,7 @@ is used in which coefficients are no longer required not to depend on themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin x))}. The result will never be @code{nil} in loose mode, since any -expression can be interpreted as a ``constant'' loose polynomial.@refill +expression can be interpreted as a ``constant'' loose polynomial. @end defun @defun polynomial-base expr pred @@ -33848,7 +34185,7 @@ the original @var{expr}) is a suitable polynomial in @var{subexpr}. The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})}; you can use @var{pred} to specify additional conditions. Or, you could have @var{pred} build up a list of every suitable @var{subexpr} that -is found.@refill +is found. @end defun @defun poly-simplify poly @@ -33860,7 +34197,7 @@ clipping off trailing zeros. Mix two polynomial lists @var{a} and @var{b} (in the form returned by @code{is-polynomial}) in a linear combination with coefficient expressions @var{ac} and @var{bc}. The result is a (not necessarily simplified) -polynomial list representing @samp{@var{ac} @var{a} + @var{bc} @var{b}}.@refill +polynomial list representing @samp{@var{ac} @var{a} + @var{bc} @var{b}}. @end defun @defun poly-mul a b @@ -33873,7 +34210,7 @@ Construct a Calc formula which represents the polynomial coefficient list @var{poly} applied to variable @var{var}. The @kbd{a c} (@code{calc-collect}) command uses @code{is-polynomial} to turn an expression into a coefficient list, then @code{build-polynomial-expr} -to turn the list back into an expression in regular form.@refill +to turn the list back into an expression in regular form. @end defun @defun check-unit-name var @@ -33890,7 +34227,7 @@ is not a variable or is not a unit name, return @code{nil}. Return true if @var{expr} contains any variables which can be interpreted as units. If @var{sub-exprs} is @code{t}, the entire expression is searched. If @var{sub-exprs} is @code{nil}, this -checks whether @var{expr} is directly a units expression.@refill +checks whether @var{expr} is directly a units expression. @end defun @defun single-units-in-expr-p expr @@ -33905,7 +34242,7 @@ Convert units expression @var{expr} to base units. If @var{which} is @code{nil}, use Calc's native base units. Otherwise, @var{which} can specify a units system, which is a list of two-element lists, where the first element is a Calc base symbol name and the second -is an expression to substitute for it.@refill +is an expression to substitute for it. @end defun @defun remove-units expr @@ -33941,7 +34278,7 @@ Read an algebraic expression from string @var{str}. If @var{str} does not have the form of a valid expression, return a list of the form @samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index into @var{str} of the general location of the error, and @var{msg} is -a string describing the problem.@refill +a string describing the problem. @end defun @defun read-exprs str @@ -33960,14 +34297,14 @@ given, it is a string which the minibuffer will initially contain. If @var{prompt} is given, it is the prompt string to use; the default is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will be returned exactly as parsed; otherwise, they will be passed through -@code{calc-normalize} first.@refill +@code{calc-normalize} first. To support the use of @kbd{$} characters in the algebraic entry, use @code{let} to bind @code{calc-dollar-values} to a list of the values to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind @code{calc-dollar-used} to 0. Upon return, @code{calc-dollar-used} will have been changed to the highest number of consecutive @kbd{$}s -that actually appeared in the input.@refill +that actually appeared in the input. @end defun @defun format-number a @@ -33983,7 +34320,7 @@ mostly to guarantee the string is of a form that can be re-parsed by complex number format, and point character, are ignored to ensure the result will be re-readable. The @var{prec} parameter is normally 0; if you pass a large integer like 1000 instead, the expression will be -surrounded by parentheses unless it is a plain number or variable name.@refill +surrounded by parentheses unless it is a plain number or variable name. @end defun @defun format-nice-expr a width @@ -33996,13 +34333,13 @@ 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} parameter, if given, is the target window size for which to format the expressions. If @var{w} is omitted, the width of the Calculator -window is used.@refill +window is used. @end defun @defun compose-expr a prec @@ -34050,7 +34387,7 @@ the baseline. For a one-line composition, this will be zero. @defun comp-first-char c If composition @var{c} is a ``flat'' composition, return the first (leftmost) character of the composition as an integer. Otherwise, -return @code{nil}.@refill +return @code{nil}. @end defun @defun comp-last-char c @@ -34060,7 +34397,7 @@ If composition @var{c} is a ``flat'' composition, return the last @comment @node Lisp Variables, Hooks, Formatting Lisp Functions, Internals @comment @subsubsection Lisp Variables -@comment +@comment @comment @noindent @comment (This section is currently unfinished.) @@ -34144,7 +34481,7 @@ text. (In fact it may still have leftover text from a previous @defvar calc-mode-save-hook This hook is called by the @code{calc-save-modes} command, after Calc's own mode features have been inserted into the -@file{.emacs} buffer and just before the ``End of mode settings'' +Calc init file and just before the ``End of mode settings'' message is inserted. @end defvar @@ -34230,7 +34567,7 @@ you should add a command to set the Lisp variable @code{calc-gnuplot-name} to the appropriate file name. You may also need to change the variables @code{calc-gnuplot-plot-command} and @code{calc-gnuplot-print-command} in order to get correct displays and hardcopies, respectively, of your -plots.@refill +plots. @ifinfo @example @@ -34245,7 +34582,7 @@ copy if you really need it. To print the manual, you will need the @TeX{} typesetting program (this is a free program by Donald Knuth 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 +as part of the @code{texinfo} package. 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 @@ -34287,11 +34624,11 @@ the same side, best if you plan to be binding single-sided pages. Another variable you might want to set is @code{calc-settings-file}, which holds the file name in which commands like @kbd{m m} and @kbd{Z P} store ``permanent'' definitions. The default value for this variable -is @code{"~/.emacs"}. If @code{calc-settings-file} does not contain -@code{".emacs"} as a substring, and if the variable +is @code{"~/.calc.el"}. If @code{calc-settings-file} is not your user +init file (typically @file{~/.emacs}) and if the variable @code{calc-loaded-settings-file} is @code{nil}, then Calc will automatically load your settings file (if it exists) the first time -Calc is invoked.@refill +Calc is invoked. @ifinfo @example @@ -34323,11 +34660,10 @@ press @kbd{M-# t} to begin. @appendix Reporting Bugs @noindent -If you find a bug in Calc, send e-mail to Colin Walters, +If you find a bug in Calc, send e-mail to Jay Belanger, @example -walters@@debian.org @r{or} -walters@@verbum.org +belanger@@truman.edu @end example @noindent @@ -34441,8 +34777,8 @@ keystrokes are not listed in this summary. @r{ @: M-# _ @: @: 36 @:calc-grab-sum-across@:} @r{ @: M-# ` @:editing @: 30 @:calc-embedded-edit@:} @r{ @: M-# 0 @:(zero) @: @:calc-reset@:} - -@c + +@c @r{ @: 0-9 @:number @: @:@:number} @r{ @: . @:number @: @:@:0.number} @r{ @: _ @:number @: @:-@:number} @@ -34453,12 +34789,12 @@ keystrokes are not listed in this summary. @r{ @: @@ ' " @: (in number)@: @:@:HMS form} @r{ @: h m s @: (in number)@: @:@:HMS form} -@c +@c @r{ @: ' @:formula @: 37,46 @:@:formula} @r{ @: $ @:formula @: 37,46 @:$@:formula} @r{ @: " @:string @: 37,46 @:@:string} - -@c + +@c @r{ a b@: + @: @: 2 @:add@:(a,b) a+b} @r{ a b@: - @: @: 2 @:sub@:(a,b) a@minus{}b} @r{ a b@: * @: @: 2 @:mul@:(a,b) a b, a*b} @@ -34476,8 +34812,8 @@ keystrokes are not listed in this summary. @r{ a@: ! @: @: 1 @:fact@:(a) a!} @r{ a@: = @: @: 1 @:evalv@:(a)} @r{ a@: M-% @: @: @:percent@:(a) a%} - -@c + +@c @r{ ... a@: @key{RET} @: @: 1 @:@:... a a} @r{ ... a@: @key{SPC} @: @: 1 @:@:... a a} @r{... a b@: @key{TAB} @: @: 3 @:@:... b a} @@ -34487,8 +34823,8 @@ keystrokes are not listed in this summary. @r{... a b@: M-@key{DEL} @: @: 1 @:@:... b} @r{ @: M-@key{RET} @: @: 4 @:calc-last-args@:} @r{ a@: ` @:editing @: 1,30 @:calc-edit@:} - -@c + +@c @r{ ... a@: C-d @: @: 1 @:@:...} @r{ @: C-k @: @: 27 @:calc-kill@:} @r{ @: C-w @: @: 27 @:calc-kill-region@:} @@ -34496,8 +34832,8 @@ keystrokes are not listed in this summary. @r{ @: C-_ @: @: 4 @:calc-undo@:} @r{ @: M-k @: @: 27 @:calc-copy-as-kill@:} @r{ @: M-w @: @: 27 @:calc-copy-region-as-kill@:} - -@c + +@c @r{ @: [ @: @: @:@:[...} @r{[.. a b@: ] @: @: @:@:[a,b]} @r{ @: ( @: @: @:@:(...} @@ -34506,15 +34842,15 @@ keystrokes are not listed in this summary. @r{ @: ; @: @: @:@:matrix or polar complex} @r{ @: .. @: @: @:@:interval} -@c +@c @r{ @: ~ @: @: @:calc-num-prefix@:} @r{ @: < @: @: 4 @:calc-scroll-left@:} @r{ @: > @: @: 4 @:calc-scroll-right@:} @r{ @: @{ @: @: 4 @:calc-scroll-down@:} @r{ @: @} @: @: 4 @:calc-scroll-up@:} @r{ @: ? @: @: @:calc-help@:} - -@c + +@c @r{ a@: n @: @: 1 @:neg@:(a) @minus{}a} @r{ @: o @: @: 4 @:calc-realign@:} @r{ @: p @:precision @: 31 @:calc-precision@:} @@ -34522,8 +34858,8 @@ keystrokes are not listed in this summary. @r{ @: w @: @: @:calc-why@:} @r{ @: x @:command @: @:M-x calc-@:command} @r{ a@: y @: @:1,28,49 @:calc-copy-to-buffer@:} - -@c + +@c @r{ a@: A @: @: 1 @:abs@:(a)} @r{ a b@: B @: @: 2 @:log@:(a,b)} @r{ a b@: I B @: @: 2 @:alog@:(a,b) b^a} @@ -34568,8 +34904,8 @@ keystrokes are not listed in this summary. @r{ a@: I H T @: @: 1 @:arctanh@:(a)} @r{ @: U @: @: 4 @:calc-undo@:} @r{ @: X @: @: 4 @:calc-call-last-kbd-macro@:} - -@c + +@c @r{ a b@: a = @: @: 2 @:eq@:(a,b) a=b} @r{ a b@: a # @: @: 2 @:neq@:(a,b) a!=b} @r{ a b@: a < @: @: 2 @:lt@:(a,b) a}} - -@c + +@c @r{ @: t [ @: @: 4 @:calc-trail-first@:} @r{ @: t ] @: @: 4 @:calc-trail-last@:} @r{ @: t < @: @: 4 @:calc-trail-scroll-left@:} @r{ @: t > @: @: 4 @:calc-trail-scroll-right@:} @r{ @: t . @: @: 12 @:calc-full-trail-vectors@:} - -@c + +@c @r{ @: t b @: @: 4 @:calc-trail-backward@:} @r{ @: t d @: @: 12,50 @:calc-trail-display@:} @r{ @: t f @: @: 4 @:calc-trail-forward@:} @@ -35030,8 +35367,8 @@ keystrokes are not listed in this summary. @r{ @: t r @:string @: @:calc-trail-isearch-backward@:} @r{ @: t s @:string @: @:calc-trail-isearch-forward@:} @r{ @: t y @: @: 4 @:calc-trail-yank@:} - -@c + +@c @r{ d@: t C @:oz, nz @: @:tzconv@:(d,oz,nz)} @r{d oz nz@: t C @:$ @: @:tzconv@:(d,oz,nz)} @r{ d@: t D @: @: 15 @:date@:(d)} @@ -35051,12 +35388,12 @@ keystrokes are not listed in this summary. @r{ d@: t U @: @: 16 @:unixtime@:(d,z)} @r{ d@: t W @: @: 17 @:newweek@:(d,w)} @r{ d@: t Y @: @: 17 @:newyear@:(d,n)} - -@c + +@c @r{ a b@: t + @: @: 2 @:badd@:(a,b)} @r{ a b@: t - @: @: 2 @:bsub@:(a,b)} - -@c + +@c @r{ @: u a @: @: 12 @:calc-autorange-units@:} @r{ a@: u b @: @: @:calc-base-units@:} @r{ a@: u c @:units @: 18 @:calc-convert-units@:} @@ -35071,8 +35408,8 @@ keystrokes are not listed in this summary. @r{ @: u v @: @: @:calc-enter-units-table@:} @r{ a@: u x @: @: @:calc-extract-units@:} @r{ a@: u 0-9 @: @: @:calc-quick-units@:} - -@c + +@c @r{ v1 v2@: u C @: @: 20 @:vcov@:(v1,v2)} @r{ v1 v2@: I u C @: @: 20 @:vpcov@:(v1,v2)} @r{ v1 v2@: H u C @: @: 20 @:vcorr@:(v1,v2)} @@ -35089,13 +35426,13 @@ keystrokes are not listed in this summary. @r{ v@: I H u S @: @: 19 @:vpvar@:(v)} @r{ @: u V @: @: @:calc-view-units-table@:} @r{ v@: u X @: @: 19 @:vmax@:(v)} - -@c + +@c @r{ v@: u + @: @: 19 @:vsum@:(v)} @r{ v@: u * @: @: 19 @:vprod@:(v)} @r{ v@: u # @: @: 19 @:vcount@:(v)} - -@c + +@c @r{ @: V ( @: @: 50 @:calc-vector-parens@:} @r{ @: V @{ @: @: 50 @:calc-vector-braces@:} @r{ @: V [ @: @: 50 @:calc-vector-brackets@:} @@ -35106,19 +35443,19 @@ keystrokes are not listed in this summary. @r{ @: V > @: @: 50 @:calc-matrix-right-justify@:} @r{ @: V / @: @: 12,50 @:calc-break-vectors@:} @r{ @: V . @: @: 12,50 @:calc-full-vectors@:} - -@c + +@c @r{ s t@: V ^ @: @: 2 @:vint@:(s,t)} @r{ s t@: V - @: @: 2 @:vdiff@:(s,t)} @r{ s@: V ~ @: @: 1 @:vcompl@:(s)} @r{ s@: V # @: @: 1 @:vcard@:(s)} @r{ s@: V : @: @: 1 @:vspan@:(s)} @r{ s@: V + @: @: 1 @:rdup@:(s)} - -@c + +@c @r{ m@: V & @: @: 1 @:inv@:(m) 1/m} - -@c + +@c @r{ v@: v a @:n @: @:arrange@:(v,n)} @r{ a@: v b @:n @: @:cvec@:(a,n)} @r{ v@: v c @:n >0 @: 21,31 @:mcol@:(v,n)} @@ -35151,8 +35488,8 @@ keystrokes are not listed in this summary. @r{ v@: v v @: @: 1 @:rev@:(v)} @r{ @: v x @:n @: 31 @:index@:(n)} @r{ n s i@: C-u v x @: @: @:index@:(n,s,i)} - -@c + +@c @r{ v@: V A @:op @: 22 @:apply@:(op,v)} @r{ v1 v2@: V C @: @: 2 @:cross@:(v1,v2)} @r{ m@: V D @: @: 1 @:det@:(m)} @@ -35181,20 +35518,20 @@ keystrokes are not listed in this summary. @r{ a@: I H V U @:op @: 22 @:afixp@:(op,a)} @r{ s t@: V V @: @: 2 @:vunion@:(s,t)} @r{ s t@: V X @: @: 2 @:vxor@:(s,t)} - -@c + +@c @r{ @: Y @: @: @:@:user commands} - -@c + +@c @r{ @: z @: @: @:@:user commands} - -@c + +@c @r{ c@: Z [ @: @: 45 @:calc-kbd-if@:} @r{ c@: Z | @: @: 45 @:calc-kbd-else-if@:} @r{ @: Z : @: @: @:calc-kbd-else@:} @r{ @: Z ] @: @: @:calc-kbd-end-if@:} - -@c + +@c @r{ @: Z @{ @: @: 4 @:calc-kbd-loop@:} @r{ c@: Z / @: @: 45 @:calc-kbd-break@:} @r{ @: Z @} @: @: @:calc-kbd-end-loop@:} @@ -35202,17 +35539,17 @@ keystrokes are not listed in this summary. @r{ @: Z > @: @: @:calc-kbd-end-repeat@:} @r{ n m@: Z ( @: @: @:calc-kbd-for@:} @r{ s@: Z ) @: @: @:calc-kbd-end-for@:} - -@c + +@c @r{ @: Z C-g @: @: @:@:cancel if/loop command} - -@c + +@c @r{ @: Z ` @: @: @:calc-kbd-push@:} @r{ @: Z ' @: @: @:calc-kbd-pop@:} @r{ a@: Z = @:message @: 28 @:calc-kbd-report@:} @r{ @: Z # @:prompt @: @:calc-kbd-query@:} - -@c + +@c @r{ comp@: Z C @:func, args @: 50 @:calc-user-define-composition@:} @r{ @: Z D @:key, command @: @:calc-user-define@:} @r{ @: Z E @:key, editing @: 30 @:calc-user-define-edit@:} @@ -35233,21 +35570,21 @@ NOTES @enumerate @c 1 @item -Positive prefix arguments apply to @cite{n} stack entries. -Negative prefix arguments apply to the @cite{-n}th stack entry. +Positive prefix arguments apply to @expr{n} stack entries. +Negative prefix arguments apply to the @expr{-n}th stack entry. A prefix of zero applies to the entire stack. (For @key{LFD} and @kbd{M-@key{DEL}}, the meaning of the sign is reversed.) @c 2 @item -Positive prefix arguments apply to @cite{n} stack entries. +Positive prefix arguments apply to @expr{n} stack entries. Negative prefix arguments apply to the top stack entry -and the next @cite{-n} stack entries. +and the next @expr{-n} stack entries. @c 3 @item -Positive prefix arguments rotate top @cite{n} stack entries by one. -Negative prefix arguments rotate the entire stack by @cite{-n}. +Positive prefix arguments rotate top @expr{n} stack entries by one. +Negative prefix arguments rotate the entire stack by @expr{-n}. A prefix of zero reverses the entire stack. @c 4 @@ -35256,8 +35593,8 @@ Prefix argument specifies a repeat count or distance. @c 5 @item -Positive prefix arguments specify a precision @cite{p}. -Negative prefix arguments reduce the current precision by @cite{-p}. +Positive prefix arguments specify a precision @expr{p}. +Negative prefix arguments reduce the current precision by @expr{-p}. @c 6 @item @@ -35275,17 +35612,17 @@ A negative prefix operates only on the top level of the input formula. @c 9 @item -Positive prefix arguments specify a word size of @cite{w} bits, unsigned. -Negative prefix arguments specify a word size of @cite{w} bits, signed. +Positive prefix arguments specify a word size of @expr{w} bits, unsigned. +Negative prefix arguments specify a word size of @expr{w} bits, signed. @c 10 @item -Prefix arguments specify the shift amount @cite{n}. The @cite{w} argument +Prefix arguments specify the shift amount @expr{n}. The @expr{w} argument cannot be specified in the keyboard version of this command. @c 11 @item -From the keyboard, @cite{d} is omitted and defaults to zero. +From the keyboard, @expr{d} is omitted and defaults to zero. @c 12 @item @@ -35298,16 +35635,16 @@ Some prefix argument values provide special variations of the mode. @c 14 @item -A prefix argument, if any, is used for @cite{m} instead of taking -@cite{m} from the stack. @cite{M} may take any of these values: +A prefix argument, if any, is used for @expr{m} instead of taking +@expr{m} from the stack. @expr{M} may take any of these values: @iftex {@advance@tableindent10pt @end iftex @table @asis @item Integer -Random integer in the interval @cite{[0 .. m)}. +Random integer in the interval @expr{[0 .. m)}. @item Float -Random floating-point number in the interval @cite{[0 .. m)}. +Random floating-point number in the interval @expr{[0 .. m)}. @item 0.0 Gaussian with mean 1 and standard deviation 0. @item Error form @@ -35347,20 +35684,21 @@ 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{$@var{n}\times2$} -@i{@var{N}x2} matrix from the -stack instead of two separate data vectors. +With a prefix argument of 1, take a single +@texline @var{n}@math{\times2} +@infoline @mathit{@var{N}x2} +matrix from the stack instead of two separate data vectors. @c 21 @item -The row or column number @cite{n} may be given as a numeric prefix -argument instead. A plain @kbd{C-u} prefix says to take @cite{n} -from the top of the stack. If @cite{n} is a vector or interval, +The row or column number @expr{n} may be given as a numeric prefix +argument instead. A plain @kbd{C-u} prefix says to take @expr{n} +from the top of the stack. If @expr{n} is a vector or interval, a subvector/submatrix of the input is created. @c 22 @item -The @cite{op} prompt can be answered with the key sequence for the +The @expr{op} prompt can be answered with the key sequence for the desired function, or with @kbd{x} or @kbd{z} followed by a function name, or with @kbd{$} to take a formula from the top of the stack, or with @kbd{'} and a typed formula. In the last two cases, the formula may @@ -35375,7 +35713,7 @@ stack by @kbd{V M} depends on the number of arguments of the function. One of the mapping direction keys @kbd{_} (horizontal, i.e., map by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or reduce down), or @kbd{=} (map or reduce by rows) may be used before -entering @cite{op}; these modify the function name by adding the letter +entering @expr{op}; these modify the function name by adding the letter @code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,'' or @code{d} for ``down.'' @@ -35413,7 +35751,7 @@ may be an integer or a vector of integers. @item -11 (@var{2}) Float with integer mantissa. @item -12 -(@var{2}) Float with mantissa in @cite{[1 .. 10)}. +(@var{2}) Float with mantissa in @expr{[1 .. 10)}. @item -13 (@var{1}) Date form (using date numbers). @item -14 @@ -35427,13 +35765,13 @@ may be an integer or a vector of integers. @c 25 @item -A prefix argument specifies the size @cite{n} of the matrix. With no -prefix argument, @cite{n} is omitted and the size is inferred from +A prefix argument specifies the size @expr{n} of the matrix. With no +prefix argument, @expr{n} is omitted and the size is inferred from the input vector. @c 26 @item -The prefix argument specifies the starting position @cite{n} (default 1). +The prefix argument specifies the starting position @expr{n} (default 1). @c 27 @item @@ -35449,9 +35787,9 @@ Variable name may be a single digit or a full name. @c 30 @item -Editing occurs in a separate buffer. Press @kbd{M-# M-#} (or @kbd{C-c C-c}, -@key{LFD}, or in some cases @key{RET}) to finish the edit, or press -@kbd{M-# x} to cancel the edit. The @key{LFD} key prevents evaluation +Editing occurs in a separate buffer. Press @kbd{C-c C-c} (or +@key{LFD}, or in some cases @key{RET}) to finish the edit, or kill the +buffer with @kbd{C-x k} to cancel the edit. The @key{LFD} key prevents evaluation of the result of the edit. @c 31 @@ -35499,16 +35837,16 @@ later prompts by popping additional stack entries. @c 39 @item -Answer for @cite{v} may also be of the form @cite{v = v_0} or -@cite{v - v_0}. +Answer for @expr{v} may also be of the form @expr{v = v_0} or +@expr{v - v_0}. @c 40 @item -With a positive prefix argument, stack contains many @cite{y}'s and one -common @cite{x}. With a zero prefix, stack contains a vector of -@cite{y}s and a common @cite{x}. With a negative prefix, stack -contains many @cite{[x,y]} vectors. (For 3D plots, substitute -@cite{z} for @cite{y} and @cite{x,y} for @cite{x}.) +With a positive prefix argument, stack contains many @expr{y}'s and one +common @expr{x}. With a zero prefix, stack contains a vector of +@expr{y}s and a common @expr{x}. With a negative prefix, stack +contains many @expr{[x,y]} vectors. (For 3D plots, substitute +@expr{z} for @expr{y} and @expr{x,y} for @expr{x}.) @c 41 @item @@ -35543,21 +35881,22 @@ in stack level three, and causes the formula to replace the top three stack levels. The notation @kbd{$3} refers to stack level three without causing that value to be removed from the stack. Use @key{LFD} in place of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET} -to evaluate variables.@refill +to evaluate variables. @c 47 @item The variable is replaced by the formula shown on the right. The Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} -assigns @c{$x \coloneq a-x$} -@cite{x := a-x}. +assigns +@texline @math{x \coloneq a-x}. +@infoline @expr{x := a-x}. @c 48 @item Press @kbd{?} repeatedly to see how to choose a model. Answer the -variables prompt with @cite{iv} or @cite{iv;pv} to specify +variables prompt with @expr{iv} or @expr{iv;pv} to specify independent and parameter variables. A positive prefix argument -takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix +takes @mathit{@var{n}+1} vectors from the stack; a zero prefix takes a matrix and a vector from the stack. @c 49 @@ -35634,7 +35973,7 @@ as Calc variables. Add a @samp{var-} prefix to get the name of the corresponding Lisp variable. The remaining variables are Lisp variables suitable for @code{setq}ing -in your @file{.emacs} file. +in your Calc init file or @file{.emacs} file. @printindex vr @@ -35656,3 +35995,6 @@ the corresponding full Lisp name is derived by adding a prefix of @bye +@ignore + arch-tag: 77a71809-fa4d-40be-b2cc-da3e8fb137c0 +@end ignore