/[emacs]/emacs/man/calc.texi
ViewVC logotype

Diff of /emacs/man/calc.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.24 by jpb, Thu Oct 21 21:34:39 2004 UTC revision 1.25 by jpb, Mon Dec 6 05:01:20 2004 UTC
# Line 7  Line 7 
7  @setchapternewpage odd  @setchapternewpage odd
8  @comment %**end of header (This is for running Texinfo on a region.)  @comment %**end of header (This is for running Texinfo on a region.)
9    
10    @c The following macros are used for conditional output for single lines.
11    @c @texline foo
12    @c    `foo' will appear only in TeX output
13    @c @infoline foo
14    @c    `foo' will appear only in non-TeX output
15    
16    @c In TeX output, @tmath{expr} will typeset expr in  math mode.
17    @c In any output, @expr{expr} will typeset an expression;
18    @c $x$ in TeX, @samp{x} otherwise.
19    
20    @iftex
21    @macro texline{stuff}
22    \stuff\
23    @end macro
24    @macro tmath{stuff}
25    @tex
26    $\stuff\$
27    @end tex
28    @end macro
29    @alias infoline=comment
30    @c @alias expr=math
31    @tex
32    \gdef\expr#1{\tex
33                 \let\t\ttfont
34                 \turnoffactive
35                 $#1$
36                 \endgroup}
37    @end tex
38    @macro cpi{}
39    @math{@pi{}}
40    @end macro
41    @macro cpiover{den}
42    @math{@pi/\den\}
43    @end macro
44    @end iftex
45    
46    @ifnottex
47    @alias texline=comment
48    @macro infoline{stuff}
49    \stuff\
50    @end macro
51    @alias expr=samp
52    @macro cpi{}
53    @expr{pi}
54    @end macro
55    @macro cpiover{den}
56    @expr{pi/\den\}
57    @end macro
58    @end ifnottex
59    
60    
61  @tex  @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.  
 %  
62  % Suggested by Karl Berry <karl@@freefriends.org>  % Suggested by Karl Berry <karl@@freefriends.org>
63  \gdef\!{\mskip-\thinmuskip}  \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{}  
64  @end tex  @end tex
65    
66  @c Fix some other things specifically for this manual.  @c Fix some other things specifically for this manual.
# Line 513  need to know. Line 540  need to know.
540  @cindex Marginal notes  @cindex Marginal notes
541  Every Calc keyboard command is listed in the Calc Summary, and also  Every Calc keyboard command is listed in the Calc Summary, and also
542  in the Key Index.  Algebraic functions, @kbd{M-x} commands, and  in the Key Index.  Algebraic functions, @kbd{M-x} commands, and
543  variables also have their own indices.  @c{Each}  variables also have their own indices.  
544  @asis{In the printed manual, each}  @texline Each
545    @infoline In the printed manual, each
546  paragraph that is referenced in the Key or Function Index is marked  paragraph that is referenced in the Key or Function Index is marked
547  in the margin with its index entry.  in the margin with its index entry.
548    
# Line 570  the corresponding function in an algebra Line 598  the corresponding function in an algebra
598  be @samp{cos(@var{x})}.  be @samp{cos(@var{x})}.
599    
600  A few commands don't have key equivalents:  @code{calc-sincos}  A few commands don't have key equivalents:  @code{calc-sincos}
601  [@code{sincos}].@refill  [@code{sincos}].
602    
603  @node Demonstration of Calc, Using Calc, Notations Used in This Manual, Getting Started  @node Demonstration of Calc, Using Calc, Notations Used in This Manual, Getting Started
604  @section A Demonstration of Calc  @section A Demonstration of Calc
# Line 595  Delete, and Space keys. Line 623  Delete, and Space keys.
623  then the command to operate on the numbers.  then the command to operate on the numbers.
624    
625  @noindent  @noindent
626  Type @kbd{2 @key{RET} 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$}  Type @kbd{2 @key{RET} 3 + Q} to compute
627  @asis{the square root of 2+3, which is 2.2360679775}.  @texline @tmath{\sqrt{2+3} = 2.2360679775}.
628    @infoline the square root of 2+3, which is 2.2360679775.
629    
630  @noindent  @noindent
631  Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$}  Type @kbd{P 2 ^} to compute
632  @asis{the value of `pi' squared, 9.86960440109}.  @texline @tmath{\pi^2 = 9.86960440109}.
633    @infoline the value of `pi' squared, 9.86960440109.
634    
635  @noindent  @noindent
636  Type @key{TAB} to exchange the order of these two results.  Type @key{TAB} to exchange the order of these two results.
# Line 617  conventional ``algebraic'' notation.  To Line 647  conventional ``algebraic'' notation.  To
647  use the apostrophe key.  use the apostrophe key.
648    
649  @noindent  @noindent
650  Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$}  Type @kbd{' sqrt(2+3) @key{RET}} to compute
651  @asis{the square root of 2+3}.  @texline @tmath{\sqrt{2+3}}.
652    @infoline the square root of 2+3.
653    
654  @noindent  @noindent
655  Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$}  Type @kbd{' pi^2 @key{RET}} to enter
656  @asis{`pi' squared}.  To evaluate this symbolic  @texline @tmath{\pi^2}.
657  formula as a number, type @kbd{=}.  @infoline `pi' squared.  
658    To evaluate this symbolic formula as a number, type @kbd{=}.
659    
660  @noindent  @noindent
661  Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent  Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent
# Line 680  the upper-leftmost @samp{1} and set the Line 712  the upper-leftmost @samp{1} and set the
712  the lower-right @samp{8} and press @kbd{M-# r}.  the lower-right @samp{8} and press @kbd{M-# r}.
713    
714  @noindent  @noindent
715  Type @kbd{v t} to transpose this @c{$3\times2$}  Type @kbd{v t} to transpose this
716  @asis{3x2} matrix into a @c{$2\times3$}  @texline @tmath{3\times2}
717  @asis{2x3} matrix.  Type  @infoline 3x2
718  @w{@kbd{v u}} to unpack the rows into two separate vectors.  Now type  matrix into a
719  @w{@kbd{V R + @key{TAB} V R +}} to compute the sums of the two original columns.  @texline @tmath{2\times3}
720  (There is also a special grab-and-sum-columns command, @kbd{M-# :}.)  @infoline 2x3
721    matrix.  Type @w{@kbd{v u}} to unpack the rows into two separate
722    vectors.  Now type @w{@kbd{V R + @key{TAB} V R +}} to compute the sums
723    of the two original columns. (There is also a special
724    grab-and-sum-columns command, @kbd{M-# :}.)
725    
726  @strong{Units conversion.}  Units are entered algebraically.  @strong{Units conversion.}  Units are entered algebraically.
727  Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour.  Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour.
# Line 701  or equations involving variables.  Type Line 737  or equations involving variables.  Type
737  to enter a pair of equations involving three variables.  to enter a pair of equations involving three variables.
738  (Note the leading apostrophe in this example; also, note that the space  (Note the leading apostrophe in this example; also, note that the space
739  between @samp{x y} is required.)  Type @w{@kbd{a S x,y @key{RET}}} to solve  between @samp{x y} is required.)  Type @w{@kbd{a S x,y @key{RET}}} to solve
740  these equations for the variables @cite{x} and @cite{y}.@refill  these equations for the variables @expr{x} and @expr{y}.
741    
742  @noindent  @noindent
743  Type @kbd{d B} to view the solutions in more readable notation.  Type @kbd{d B} to view the solutions in more readable notation.
# Line 710  to view them in the notation for the @Te Line 746  to view them in the notation for the @Te
746  Type @kbd{d N} to return to normal notation.  Type @kbd{d N} to return to normal notation.
747    
748  @noindent  @noindent
749  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.
750  (That's a letter @kbd{l}, not a numeral @kbd{1}.)  (That's a letter @kbd{l}, not a numeral @kbd{1}.)
751    
752  @iftex  @iftex
# Line 769  Once again, if you don't have a Meta key Line 805  Once again, if you don't have a Meta key
805  @key{ESC} first, then @kbd{#}, to accomplish the same thing.  If you  @key{ESC} first, then @kbd{#}, to accomplish the same thing.  If you
806  don't even have an @key{ESC} key, you can fake it by holding down  don't even have an @key{ESC} key, you can fake it by holding down
807  Control or @key{CTRL} while typing a left square bracket  Control or @key{CTRL} while typing a left square bracket
808  (that's @kbd{C-[} in Emacs notation).@refill  (that's @kbd{C-[} in Emacs notation).
809    
810  @kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for  @kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for
811  you to press a second key to complete the command.  In this case,  you to press a second key to complete the command.  In this case,
# Line 853  Calc commands use the digits, letters, a Line 889  Calc commands use the digits, letters, a
889  Shifted (i.e., upper-case) letters are different from lowercase  Shifted (i.e., upper-case) letters are different from lowercase
890  letters.  Some letters are @dfn{prefix} keys that begin two-letter  letters.  Some letters are @dfn{prefix} keys that begin two-letter
891  commands.  For example, @kbd{e} means ``enter exponent'' and shifted  commands.  For example, @kbd{e} means ``enter exponent'' and shifted
892  @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
893  the letter ``e'' takes on very different meanings:  @kbd{d e} means  the letter ``e'' takes on very different meanings:  @kbd{d e} means
894  ``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.''  ``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.''
895    
# Line 1317  With any prefix argument, reset everythi Line 1353  With any prefix argument, reset everythi
1353  @noindent  @noindent
1354  Calc was originally started as a two-week project to occupy a lull  Calc was originally started as a two-week project to occupy a lull
1355  in the author's schedule.  Basically, a friend asked if I remembered  in the author's schedule.  Basically, a friend asked if I remembered
1356  the value of @c{$2^{32}$}  the value of
1357  @cite{2^32}.  I didn't offhand, but I said, ``that's  @texline @tmath{2^{32}}.
1358  easy, just call up an @code{xcalc}.''  @code{Xcalc} duly reported  @infoline @expr{2^32}.  
1359  that the answer to our question was @samp{4.294967e+09}---with no way to  I didn't offhand, but I said, ``that's easy, just call up an
1360  see the full ten digits even though we knew they were there in the  @code{xcalc}.''  @code{Xcalc} duly reported that the answer to our
1361  program's memory!  I was so annoyed, I vowed to write a calculator  question was @samp{4.294967e+09}---with no way to see the full ten
1362  of my own, once and for all.  digits even though we knew they were there in the program's memory!  I
1363    was so annoyed, I vowed to write a calculator of my own, once and for
1364    all.
1365    
1366  I chose Emacs Lisp, a) because I had always been curious about it  I chose Emacs Lisp, a) because I had always been curious about it
1367  and b) because, being only a text editor extension language after  and b) because, being only a text editor extension language after
# Line 1373  algebra system for microcomputers. Line 1411  algebra system for microcomputers.
1411  Many people have contributed to Calc by reporting bugs and suggesting  Many people have contributed to Calc by reporting bugs and suggesting
1412  features, large and small.  A few deserve special mention:  Tim Peters,  features, large and small.  A few deserve special mention:  Tim Peters,
1413  who helped develop the ideas that led to the selection commands, rewrite  who helped develop the ideas that led to the selection commands, rewrite
1414  rules, and many other algebra features; @c{Fran\c cois}  rules, and many other algebra features;
1415  @asis{Francois} Pinard, who contributed  @texline Fran\c cois
1416  an early prototype of the Calc Summary appendix as well as providing  @infoline Francois
1417  valuable suggestions in many other areas of Calc; Carl Witty, whose eagle  Pinard, who contributed an early prototype of the Calc Summary appendix
1418  eyes discovered many typographical and factual errors in the Calc manual;  as well as providing valuable suggestions in many other areas of Calc;
1419  Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who  Carl Witty, whose eagle eyes discovered many typographical and factual
1420  made many suggestions relating to the algebra commands and contributed  errors in the Calc manual; Tim Kay, who drove the development of
1421  some code for polynomial operations; Randal Schwartz, who suggested the  Embedded mode; Ove Ewerlid, who made many suggestions relating to the
1422  @code{calc-eval} function; Robert J. Chassell, who suggested the Calc  algebra commands and contributed some code for polynomial operations;
1423  Tutorial and exercises; and Juha Sarlin, who first worked out how to split  Randal Schwartz, who suggested the @code{calc-eval} function; Robert
1424  Calc into quickly-loading parts.  Bob Weiner helped immensely with the  J. Chassell, who suggested the Calc Tutorial and exercises; and Juha
1425  Lucid Emacs port.  Sarlin, who first worked out how to split Calc into quickly-loading
1426    parts.  Bob Weiner helped immensely with the Lucid Emacs port.
1427    
1428  @cindex Bibliography  @cindex Bibliography
1429  @cindex Knuth, Art of Computer Programming  @cindex Knuth, Art of Computer Programming
# Line 1545  from the top of the stack. Line 1584  from the top of the stack.
1584    
1585  @cindex Operators  @cindex Operators
1586  @cindex Operands  @cindex Operands
1587  In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands}  In an operation like @expr{2+3}, the 2 and 3 are called the @dfn{operands}
1588  and the @cite{+} is the @dfn{operator}.  In an RPN calculator you always  and the @expr{+} is the @dfn{operator}.  In an RPN calculator you always
1589  enter the operands first, then the operator.  Each time you type a  enter the operands first, then the operator.  Each time you type a
1590  number, Calc adds or @dfn{pushes} it onto the top of the Stack.  number, Calc adds or @dfn{pushes} it onto the top of the Stack.
1591  When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate  When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate
# Line 1560  you wish; type @kbd{M-# c} to switch int Line 1599  you wish; type @kbd{M-# c} to switch int
1599  The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.  The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.
1600  The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,  The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,
1601  and pushes the result (5) back onto the stack.  Here's how the stack  and pushes the result (5) back onto the stack.  Here's how the stack
1602  will look at various points throughout the calculation:@refill  will look at various points throughout the calculation:
1603    
1604  @smallexample  @smallexample
1605  @group  @group
# Line 1581  less distracting in regular use. Line 1620  less distracting in regular use.
1620  @cindex Levels of stack  @cindex Levels of stack
1621  The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level  The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level
1622  numbers}.  Old RPN calculators always had four stack levels called  numbers}.  Old RPN calculators always had four stack levels called
1623  @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
1624  as large as you like, so it uses numbers instead of letters.  Some  as large as you like, so it uses numbers instead of letters.  Some
1625  stack-manipulation commands accept a numeric argument that says  stack-manipulation commands accept a numeric argument that says
1626  which stack level to work on.  Normal commands like @kbd{+} always  which stack level to work on.  Normal commands like @kbd{+} always
1627  work on the top few levels of the stack.@refill  work on the top few levels of the stack.
1628    
1629  @c [fix-ref Truncating the Stack]  @c [fix-ref Truncating the Stack]
1630  The Stack buffer is just an Emacs buffer, and you can move around in  The Stack buffer is just an Emacs buffer, and you can move around in
# Line 1602  You don't really need the second @key{RE Line 1641  You don't really need the second @key{RE
1641  @key{RET} +}.  That's because if you type any operator name or  @key{RET} +}.  That's because if you type any operator name or
1642  other non-numeric key when you are entering a number, the Calculator  other non-numeric key when you are entering a number, the Calculator
1643  automatically enters that number and then does the requested command.  automatically enters that number and then does the requested command.
1644  Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill  Thus @kbd{2 @key{RET} 3 +} will work just as well.
1645    
1646  Examples in this tutorial will often omit @key{RET} even when the  Examples in this tutorial will often omit @key{RET} even when the
1647  stack displays shown would only happen if you did press @key{RET}:  stack displays shown would only happen if you did press @key{RET}:
# Line 1636  Here's the first exercise:  What will th Line 1675  Here's the first exercise:  What will th
1675  multiplication.)  Figure it out by hand, then try it with Calc to see  multiplication.)  Figure it out by hand, then try it with Calc to see
1676  if you're right.  @xref{RPN Answer 1, 1}. (@bullet{})  if you're right.  @xref{RPN Answer 1, 1}. (@bullet{})
1677    
1678  (@bullet{}) @strong{Exercise 2.}  Compute @c{$(2\times4) + (7\times9.4) + {5\over4}$}  (@bullet{}) @strong{Exercise 2.}  Compute
1679  @cite{2*4 + 7*9.5 + 5/4} using the  @texline @tmath{(2\times4) + (7\times9.4) + {5\over4}}
1680  stack.  @xref{RPN Answer 2, 2}. (@bullet{})  @infoline @expr{2*4 + 7*9.5 + 5/4}
1681    using the stack.  @xref{RPN Answer 2, 2}. (@bullet{})
1682    
1683  The @key{DEL} key is called Backspace on some keyboards.  It is  The @key{DEL} key is called Backspace on some keyboards.  It is
1684  whatever key you would use to correct a simple typing error when  whatever key you would use to correct a simple typing error when
# Line 1690  the above example with @key{SPC} and the Line 1730  the above example with @key{SPC} and the
1730  Another stack manipulation key is @key{TAB}.  This exchanges the top  Another stack manipulation key is @key{TAB}.  This exchanges the top
1731  two stack entries.  Suppose you have computed @kbd{2 @key{RET} 3 +}  two stack entries.  Suppose you have computed @kbd{2 @key{RET} 3 +}
1732  to get 5, and then you realize what you really wanted to compute  to get 5, and then you realize what you really wanted to compute
1733  was @cite{20 / (2+3)}.  was @expr{20 / (2+3)}.
1734    
1735  @smallexample  @smallexample
1736  @group  @group
# Line 1798  What happens if you take the square root Line 1838  What happens if you take the square root
1838  @end smallexample  @end smallexample
1839    
1840  @noindent  @noindent
1841  The notation @cite{(a, b)} represents a complex number.  The notation @expr{(a, b)} represents a complex number.
1842  Complex numbers are more traditionally written @c{$a + b i$}  Complex numbers are more traditionally written @expr{a + b i};
 @cite{a + b i};  
1843  Calc can display in this format, too, but for now we'll stick to the  Calc can display in this format, too, but for now we'll stick to the
1844  @cite{(a, b)} notation.  @expr{(a, b)} notation.
1845    
1846  If you don't know how complex numbers work, you can safely ignore this  If you don't know how complex numbers work, you can safely ignore this
1847  feature.  Complex numbers only arise from operations that would be  feature.  Complex numbers only arise from operations that would be
# Line 1861  When you press @kbd{)} all the stack ent Line 1900  When you press @kbd{)} all the stack ent
1900  entry and the top are collected, so there's never really a reason  entry and the top are collected, so there's never really a reason
1901  to use the comma.  It's up to you.  to use the comma.  It's up to you.
1902    
1903  (@bullet{}) @strong{Exercise 4.}  To enter the complex number @cite{(2, 3)},  (@bullet{}) @strong{Exercise 4.}  To enter the complex number @expr{(2, 3)},
1904  your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}.  What happened?  your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}.  What happened?
1905  (Joe thought of a clever way to correct his mistake in only two  (Joe thought of a clever way to correct his mistake in only two
1906  keystrokes, but it didn't quite work.  Try it to find out why.)  keystrokes, but it didn't quite work.  Try it to find out why.)
# Line 1921  entire stack.) Line 1960  entire stack.)
1960  If you are not used to RPN notation, you may prefer to operate the  If you are not used to RPN notation, you may prefer to operate the
1961  Calculator in ``algebraic mode,'' which is closer to the way  Calculator in ``algebraic mode,'' which is closer to the way
1962  non-RPN calculators work.  In algebraic mode, you enter formulas  non-RPN calculators work.  In algebraic mode, you enter formulas
1963  in traditional @cite{2+3} notation.  in traditional @expr{2+3} notation.
1964    
1965  You don't really need any special ``mode'' to enter algebraic formulas.  You don't really need any special ``mode'' to enter algebraic formulas.
1966  You can enter a formula at any time by pressing the apostrophe (@kbd{'})  You can enter a formula at any time by pressing the apostrophe (@kbd{'})
# Line 2004  the function name corresponding to the s Line 2043  the function name corresponding to the s
2043  the notation @samp{sqrt(@var{x})}.  the notation @samp{sqrt(@var{x})}.
2044    
2045  Press the apostrophe, then type @kbd{sqrt(5*2) - 3}.  The result should  Press the apostrophe, then type @kbd{sqrt(5*2) - 3}.  The result should
2046  be @cite{0.16227766017}.  be @expr{0.16227766017}.
2047    
2048  Note that if the formula begins with a function name, you need to use  Note that if the formula begins with a function name, you need to use
2049  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}
# Line 2030  Still in algebraic mode, type: Line 2069  Still in algebraic mode, type:
2069    
2070  Algebraic mode allows us to enter complex numbers without pressing  Algebraic mode allows us to enter complex numbers without pressing
2071  an apostrophe first, but it also means we need to press @key{RET}  an apostrophe first, but it also means we need to press @key{RET}
2072  after every entry, even for a simple number like @cite{1}.  after every entry, even for a simple number like @expr{1}.
2073    
2074  (You can type @kbd{C-u m a} to enable a special ``incomplete algebraic  (You can type @kbd{C-u m a} to enable a special ``incomplete algebraic
2075  mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even  mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even
# Line 2050  intermediate results of a calculation as Line 2089  intermediate results of a calculation as
2089  accomplish this in Calc by performing your calculation as a series  accomplish this in Calc by performing your calculation as a series
2090  of algebraic entries, using the @kbd{$} sign to tie them together.  of algebraic entries, using the @kbd{$} sign to tie them together.
2091  In an algebraic formula, @kbd{$} represents the number on the top  In an algebraic formula, @kbd{$} represents the number on the top
2092  of the stack.  Here, we perform the calculation @c{$\sqrt{2\times4+1}$}  of the stack.  Here, we perform the calculation
2093  @cite{sqrt(2*4+1)},  @texline @tmath{\sqrt{2\times4+1}},
2094    @infoline @expr{sqrt(2*4+1)},
2095  which on a traditional calculator would be done by pressing  which on a traditional calculator would be done by pressing
2096  @kbd{2 * 4 + 1 =} and then the square-root key.  @kbd{2 * 4 + 1 =} and then the square-root key.
2097    
# Line 2190  the righthand formula has been evaluated Line 2230  the righthand formula has been evaluated
2230    
2231  @noindent  @noindent
2232  Notice that the instant we stored a new value in @code{a}, all  Notice that the instant we stored a new value in @code{a}, all
2233  @samp{=>} operators already on the stack that referred to @cite{a}  @samp{=>} operators already on the stack that referred to @expr{a}
2234  were updated to use the new value.  With @samp{=>}, you can push a  were updated to use the new value.  With @samp{=>}, you can push a
2235  set of formulas on the stack, then change the variables experimentally  set of formulas on the stack, then change the variables experimentally
2236  to see the effects on the formulas' values.  to see the effects on the formulas' values.
# Line 2257  mistakenly. Line 2297  mistakenly.
2297  @end smallexample  @end smallexample
2298    
2299  @noindent  @noindent
2300  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
2301  by something other than an undo command.  by something other than an undo command.
2302    
2303  @cindex Time travel  @cindex Time travel
# Line 2265  You can think of undo and redo as a sort Line 2305  You can think of undo and redo as a sort
2305  @kbd{U} to go backward in time, @kbd{D} to go forward.  If you go  @kbd{U} to go backward in time, @kbd{D} to go forward.  If you go
2306  backward and do something (like @kbd{*}) then, as any science fiction  backward and do something (like @kbd{*}) then, as any science fiction
2307  reader knows, you have changed your future and you cannot go forward  reader knows, you have changed your future and you cannot go forward
2308  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
2309  was an earlier undo command.  was an earlier undo command.
2310    
2311  You can always recall an earlier result using the Trail.  We've ignored  You can always recall an earlier result using the Trail.  We've ignored
# Line 2273  the trail so far, but it has been faithf Line 2313  the trail so far, but it has been faithf
2313  did since we loaded the Calculator.  If the Trail is not displayed,  did since we loaded the Calculator.  If the Trail is not displayed,
2314  press @kbd{t d} now to turn it on.  press @kbd{t d} now to turn it on.
2315    
2316  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
2317  undone by a @kbd{U} command, and was lost even to Redo when we pressed  undone by a @kbd{U} command, and was lost even to Redo when we pressed
2318  @kbd{*}, but it's still there in the trail.  There should be a little  @kbd{*}, but it's still there in the trail.  There should be a little
2319  @samp{>} arrow (the @dfn{trail pointer}) resting on the last trail  @samp{>} arrow (the @dfn{trail pointer}) resting on the last trail
2320  entry.  If there isn't, press @kbd{t ]} to reset the trail pointer.  entry.  If there isn't, press @kbd{t ]} to reset the trail pointer.
2321  Now, press @w{@kbd{t p}} to move the arrow onto the line containing  Now, press @w{@kbd{t p}} to move the arrow onto the line containing
2322  @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
2323  stack.  stack.
2324    
2325  If you press @kbd{t ]} again, you will see that even our Yank command  If you press @kbd{t ]} again, you will see that even our Yank command
# Line 2340  directly, but you can press @kbd{`} (the Line 2380  directly, but you can press @kbd{`} (the
2380  to edit a stack entry.  to edit a stack entry.
2381    
2382  Try entering @samp{3.141439} now.  If this is supposed to represent  Try entering @samp{3.141439} now.  If this is supposed to represent
2383  @c{$\pi$}  @cpi{}, it's got several errors.  Press @kbd{`} to edit this number.
 @cite{pi}, it's got several errors.  Press @kbd{`} to edit this number.  
2384  Now use the normal Emacs cursor motion and editing keys to change  Now use the normal Emacs cursor motion and editing keys to change
2385  the second 4 to a 5, and to transpose the 3 and the 9.  When you  the second 4 to a 5, and to transpose the 3 and the 9.  When you
2386  press @key{RET}, the number on the stack will be replaced by your  press @key{RET}, the number on the stack will be replaced by your
# Line 2370  Most of the symbols there are Emacs thin Line 2409  Most of the symbols there are Emacs thin
2409  about, but the @samp{12} and the @samp{Deg} are mode indicators.  about, but the @samp{12} and the @samp{Deg} are mode indicators.
2410  The @samp{12} means that calculations should always be carried to  The @samp{12} means that calculations should always be carried to
2411  12 significant figures.  That is why, when we type @kbd{1 @key{RET} 7 /},  12 significant figures.  That is why, when we type @kbd{1 @key{RET} 7 /},
2412  we get @cite{0.142857142857} with exactly 12 digits, not counting  we get @expr{0.142857142857} with exactly 12 digits, not counting
2413  leading and trailing zeros.  leading and trailing zeros.
2414    
2415  You can set the precision to anything you like by pressing @kbd{p},  You can set the precision to anything you like by pressing @kbd{p},
# Line 2387  then doing @kbd{1 @key{RET} 7 /} again: Line 2426  then doing @kbd{1 @key{RET} 7 /} again:
2426    
2427  Although the precision can be set arbitrarily high, Calc always  Although the precision can be set arbitrarily high, Calc always
2428  has to have @emph{some} value for the current precision.  After  has to have @emph{some} value for the current precision.  After
2429  all, the true value @cite{1/7} is an infinitely repeating decimal;  all, the true value @expr{1/7} is an infinitely repeating decimal;
2430  Calc has to stop somewhere.  Calc has to stop somewhere.
2431    
2432  Of course, calculations are slower the more digits you request.  Of course, calculations are slower the more digits you request.
2433  Press @w{@kbd{p 12}} now to set the precision back down to the default.  Press @w{@kbd{p 12}} now to set the precision back down to the default.
2434    
2435  Calculations always use the current precision.  For example, even  Calculations always use the current precision.  For example, even
2436  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
2437  we use it in a calculation in 12-digit mode it will be rounded  we use it in a calculation in 12-digit mode it will be rounded
2438  down to 12 digits before it is used.  Try it; press @key{RET} to  down to 12 digits before it is used.  Try it; press @key{RET} to
2439  duplicate the number, then @w{@kbd{1 +}}.  Notice that the @key{RET}  duplicate the number, then @w{@kbd{1 +}}.  Notice that the @key{RET}
# Line 2412  But the instant we pressed @kbd{+}, the Line 2451  But the instant we pressed @kbd{+}, the
2451    
2452  @noindent  @noindent
2453  In fact, since we added a digit on the left, we had to lose one  In fact, since we added a digit on the left, we had to lose one
2454  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}.
2455    
2456  How did we get more than 12 digits when we computed @samp{2^3^4}?  The  How did we get more than 12 digits when we computed @samp{2^3^4}?  The
2457  answer is that Calc makes a distinction between @dfn{integers} and  answer is that Calc makes a distinction between @dfn{integers} and
# Line 2463  want to see.  You can enter numbers in t Line 2502  want to see.  You can enter numbers in t
2502  @noindent  @noindent
2503  Hey, the answer is different!  Look closely at the middle columns  Hey, the answer is different!  Look closely at the middle columns
2504  of the two examples.  In the first, the stack contained the  of the two examples.  In the first, the stack contained the
2505  exact integer @cite{10000}, but in the second it contained  exact integer @expr{10000}, but in the second it contained
2506  a floating-point value with a decimal point.  When you raise a  a floating-point value with a decimal point.  When you raise a
2507  number to an integer power, Calc uses repeated squaring and  number to an integer power, Calc uses repeated squaring and
2508  multiplication to get the answer.  When you use a floating-point  multiplication to get the answer.  When you use a floating-point
# Line 2564  whole stack.  The @kbd{d n} command chan Line 2603  whole stack.  The @kbd{d n} command chan
2603  format; since it doesn't have an @kbd{H} prefix, it also updates all  format; since it doesn't have an @kbd{H} prefix, it also updates all
2604  the stack entries to be in @kbd{d n} format.  the stack entries to be in @kbd{d n} format.
2605    
2606  Notice that the integer @cite{12345} was not affected by any  Notice that the integer @expr{12345} was not affected by any
2607  of the float formats.  Integers are integers, and are always  of the float formats.  Integers are integers, and are always
2608  displayed exactly.  displayed exactly.
2609    
# Line 2712  angle is measured in degrees.  For examp Line 2751  angle is measured in degrees.  For examp
2751    
2752  @noindent  @noindent
2753  The shift-@kbd{S} command computes the sine of an angle.  The sine  The shift-@kbd{S} command computes the sine of an angle.  The sine
2754  of 45 degrees is @c{$\sqrt{2}/2$}  of 45 degrees is
2755  @cite{sqrt(2)/2}; squaring this yields @cite{2/4 = 0.5}.  @texline @tmath{\sqrt{2}/2};
2756  However, there has been a slight roundoff error because the  @infoline @expr{sqrt(2)/2};
2757  representation of @c{$\sqrt{2}/2$}  squaring this yields @expr{2/4 = 0.5}.  However, there has been a slight
2758  @cite{sqrt(2)/2} wasn't exact.  The @kbd{c 1}  roundoff error because the representation of
2759  command is a handy way to clean up numbers in this case; it  @texline @tmath{\sqrt{2}/2}
2760  temporarily reduces the precision by one digit while it  @infoline @expr{sqrt(2)/2}
2761    wasn't exact.  The @kbd{c 1} command is a handy way to clean up numbers
2762    in this case; it temporarily reduces the precision by one digit while it
2763  re-rounds the number on the top of the stack.  re-rounds the number on the top of the stack.
2764    
2765  @cindex Roundoff errors, examples  @cindex Roundoff errors, examples
# Line 2729  What happened?  @xref{Modes Answer 3, 3} Line 2770  What happened?  @xref{Modes Answer 3, 3}
2770    
2771  To do this calculation in radians, we would type @kbd{m r} first.  To do this calculation in radians, we would type @kbd{m r} first.
2772  (The indicator changes to @samp{Rad}.)  45 degrees corresponds to  (The indicator changes to @samp{Rad}.)  45 degrees corresponds to
2773  @c{$\pi\over4$}  @cpiover{4} radians.  To get @cpi{}, press the @kbd{P} key.  (Once
 @cite{pi/4} radians.  To get @c{$\pi$}  
 @cite{pi}, press the @kbd{P} key.  (Once  
2774  again, this is a shifted capital @kbd{P}.  Remember, unshifted  again, this is a shifted capital @kbd{P}.  Remember, unshifted
2775  @kbd{p} sets the precision.)  @kbd{p} sets the precision.)
2776    
# Line 2757  either radians or degrees, depending on Line 2796  either radians or degrees, depending on
2796  @end smallexample  @end smallexample
2797    
2798  @noindent  @noindent
2799  Here we compute the Inverse Sine of @c{$\sqrt{0.5}$}  Here we compute the Inverse Sine of
2800  @cite{sqrt(0.5)}, first in  @texline @tmath{\sqrt{0.5}},
2801  radians, then in degrees.  @infoline @expr{sqrt(0.5)},
2802    first in radians, then in degrees.
2803    
2804  Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees  Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees
2805  and vice-versa.  and vice-versa.
# Line 2939  provide a @kbd{\} command.  @xref{Arithm Line 2979  provide a @kbd{\} command.  @xref{Arithm
2979    
2980  We've already seen the @kbd{Q} (square root) and @kbd{S} (sine)  We've already seen the @kbd{Q} (square root) and @kbd{S} (sine)
2981  commands.  Other commands along those lines are @kbd{C} (cosine),  commands.  Other commands along those lines are @kbd{C} (cosine),
2982  @kbd{T} (tangent), @kbd{E} (@cite{e^x}) and @kbd{L} (natural  @kbd{T} (tangent), @kbd{E} (@expr{e^x}) and @kbd{L} (natural
2983  logarithm).  These can be modified by the @kbd{I} (inverse) and  logarithm).  These can be modified by the @kbd{I} (inverse) and
2984  @kbd{H} (hyperbolic) prefix keys.  @kbd{H} (hyperbolic) prefix keys.
2985    
2986  Let's compute the sine and cosine of an angle, and verify the  Let's compute the sine and cosine of an angle, and verify the
2987  identity @c{$\sin^2x + \cos^2x = 1$}  identity
2988  @cite{sin(x)^2 + cos(x)^2 = 1}.  We'll  @texline @tmath{\sin^2x + \cos^2x = 1}.
2989  arbitrarily pick @i{-64} degrees as a good value for @cite{x}.  With  @infoline @expr{sin(x)^2 + cos(x)^2 = 1}.  
2990  the angular mode set to degrees (type @w{@kbd{m d}}), do:  We'll arbitrarily pick @i{-64} degrees as a good value for @expr{x}.
2991    With the angular mode set to degrees (type @w{@kbd{m d}}), do:
2992    
2993  @smallexample  @smallexample
2994  @group  @group
# Line 2966  You can of course do these calculations Line 3007  You can of course do these calculations
3007  Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum  Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum
3008  of squares, command.  of squares, command.
3009    
3010  Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$}  Another identity is
3011  @cite{tan(x) = sin(x) / cos(x)}.  @texline @tmath{\displaystyle\tan x = {\sin x \over \cos x}}.
3012    @infoline @expr{tan(x) = sin(x) / cos(x)}.
3013  @smallexample  @smallexample
3014  @group  @group
3015    
# Line 2980  Another identity is @c{$\displaystyle\ta Line 3022  Another identity is @c{$\displaystyle\ta
3022  @end smallexample  @end smallexample
3023    
3024  A physical interpretation of this calculation is that if you move  A physical interpretation of this calculation is that if you move
3025  @cite{0.89879} units downward and @cite{0.43837} units to the right,  @expr{0.89879} units downward and @expr{0.43837} units to the right,
3026  your direction of motion is @i{-64} degrees from horizontal.  Suppose  your direction of motion is @i{-64} degrees from horizontal.  Suppose
3027  we move in the opposite direction, up and to the left:  we move in the opposite direction, up and to the left:
3028    
# Line 3029  the top two stack elements right after t Line 3071  the top two stack elements right after t
3071    
3072  A similar identity is supposed to hold for hyperbolic sines and cosines,  A similar identity is supposed to hold for hyperbolic sines and cosines,
3073  except that it is the @emph{difference}  except that it is the @emph{difference}
3074  @c{$\cosh^2x - \sinh^2x$}  @texline @tmath{\cosh^2x - \sinh^2x}
3075  @cite{cosh(x)^2 - sinh(x)^2} that always equals one.  @infoline @expr{cosh(x)^2 - sinh(x)^2}
3076  Let's try to verify this identity.@refill  that always equals one.  Let's try to verify this identity.
3077    
3078  @smallexample  @smallexample
3079  @group  @group
# Line 3057  enormously so.  Try it if you wish; sure Line 3099  enormously so.  Try it if you wish; sure
3099  0.99999, reasonably close to 1.  0.99999, reasonably close to 1.
3100    
3101  Of course, a more reasonable way to verify the identity is to use  Of course, a more reasonable way to verify the identity is to use
3102  a more reasonable value for @cite{x}!  a more reasonable value for @expr{x}!
3103    
3104  @cindex Common logarithm  @cindex Common logarithm
3105  Some Calculator commands use the Hyperbolic prefix for other purposes.  Some Calculator commands use the Hyperbolic prefix for other purposes.
3106  The logarithm and exponential functions, for example, work to the base  The logarithm and exponential functions, for example, work to the base
3107  @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
3108  prefix.  prefix.
3109    
3110  @smallexample  @smallexample
# Line 3095  value of @var{b}. Line 3137  value of @var{b}.
3137  Here we first use @kbd{B} to compute the base-10 logarithm, then use  Here we first use @kbd{B} to compute the base-10 logarithm, then use
3138  the ``hyperbolic'' exponential as a cheap hack to recover the number  the ``hyperbolic'' exponential as a cheap hack to recover the number
3139  1000, then use @kbd{B} again to compute the natural logarithm.  Note  1000, then use @kbd{B} again to compute the natural logarithm.  Note
3140  that @kbd{P} with the hyperbolic prefix pushes the constant @cite{e}  that @kbd{P} with the hyperbolic prefix pushes the constant @expr{e}
3141  onto the stack.  onto the stack.
3142    
3143  You may have noticed that both times we took the base-10 logarithm  You may have noticed that both times we took the base-10 logarithm
# Line 3136  in this case). Line 3178  in this case).
3178    
3179  If you take the factorial of a non-integer, Calc uses a generalized  If you take the factorial of a non-integer, Calc uses a generalized
3180  factorial function defined in terms of Euler's Gamma function  factorial function defined in terms of Euler's Gamma function
3181  @c{$\Gamma(n)$}  @texline @tmath{\Gamma(n)}
3182  @cite{gamma(n)}  @infoline @expr{gamma(n)}
3183  (which is itself available as the @kbd{f g} command).  (which is itself available as the @kbd{f g} command).
3184    
3185  @smallexample  @smallexample
# Line 3152  factorial function defined in terms of E Line 3194  factorial function defined in terms of E
3194  @end smallexample  @end smallexample
3195    
3196  @noindent  @noindent
3197  Here we verify the identity @c{$n! = \Gamma(n+1)$}  Here we verify the identity
3198  @cite{@var{n}!@: = gamma(@var{n}+1)}.  @texline @tmath{n! = \Gamma(n+1)}.
3199    @infoline @expr{@var{n}!@: = gamma(@var{n}+1)}.
3200    
3201  The binomial coefficient @var{n}-choose-@var{m}@c{ or $\displaystyle {n \choose m}$}  The binomial coefficient @var{n}-choose-@var{m}
3202  @asis{} is defined by  @texline or @tmath{\displaystyle {n \choose m}}
3203  @c{$\displaystyle {n! \over m! \, (n-m)!}$}  is defined by
3204  @cite{n!@: / m!@: (n-m)!} for all reals @cite{n} and  @texline @tmath{\displaystyle {n! \over m! \, (n-m)!}}
3205  @cite{m}.  The intermediate results in this formula can become quite  @infoline @expr{n!@: / m!@: (n-m)!}
3206  large even if the final result is small; the @kbd{k c} command computes  for all reals @expr{n} and @expr{m}.  The intermediate results in this
3207  a binomial coefficient in a way that avoids large intermediate  formula can become quite large even if the final result is small; the
3208  values.  @kbd{k c} command computes a binomial coefficient in a way that avoids
3209    large intermediate values.
3210    
3211  The @kbd{k} prefix key defines several common functions out of  The @kbd{k} prefix key defines several common functions out of
3212  combinatorics and number theory.  Here we compute the binomial  combinatorics and number theory.  Here we compute the binomial
# Line 3266  of the vectors. Line 3310  of the vectors.
3310  @cindex Dot product  @cindex Dot product
3311  The dot product of two vectors is equal to the product of their  The dot product of two vectors is equal to the product of their
3312  lengths times the cosine of the angle between them.  (Here the vector  lengths times the cosine of the angle between them.  (Here the vector
3313  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
3314  specified point in three-dimensional space.)  The @kbd{A}  specified point in three-dimensional space.)  The @kbd{A}
3315  (absolute value) command can be used to compute the length of a  (absolute value) command can be used to compute the length of a
3316  vector.  vector.
# Line 3379  the second example. Line 3423  the second example.
3423    
3424  When two matrices are multiplied, the lefthand matrix must have  When two matrices are multiplied, the lefthand matrix must have
3425  the same number of columns as the righthand matrix has rows.  the same number of columns as the righthand matrix has rows.
3426  Row @cite{i}, column @cite{j} of the result is effectively the  Row @expr{i}, column @expr{j} of the result is effectively the
3427  dot product of row @cite{i} of the left matrix by column @cite{j}  dot product of row @expr{i} of the left matrix by column @expr{j}
3428  of the right matrix.  of the right matrix.
3429    
3430  If we try to duplicate this matrix and multiply it by itself,  If we try to duplicate this matrix and multiply it by itself,
# Line 3441  rows in the matrix is different from the Line 3485  rows in the matrix is different from the
3485  vector.  vector.
3486    
3487  (@bullet{}) @strong{Exercise 1.}  Use @samp{*} to sum along the rows  (@bullet{}) @strong{Exercise 1.}  Use @samp{*} to sum along the rows
3488  of the above @c{$2\times3$}  of the above
3489  @asis{2x3} matrix to get @cite{[6, 15]}.  Now use @samp{*} to  @texline @tmath{2\times3}
3490  sum along the columns to get @cite{[5, 7, 9]}.  @infoline 2x3
3491    matrix to get @expr{[6, 15]}.  Now use @samp{*} to sum along the columns
3492    to get @expr{[5, 7, 9]}.
3493  @xref{Matrix Answer 1, 1}. (@bullet{})  @xref{Matrix Answer 1, 1}. (@bullet{})
3494    
3495  @cindex Identity matrix  @cindex Identity matrix
# Line 3566  inverse of the matrix.  Calc can do this Line 3612  inverse of the matrix.  Calc can do this
3612  @end smallexample  @end smallexample
3613    
3614  @noindent  @noindent
3615  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.
3616  (Dividing by a square matrix is equivalent to multiplying by its  (Dividing by a square matrix is equivalent to multiplying by its
3617  inverse.)  inverse.)
3618    
# Line 3590  the matrix and vector.  If we multiplied Line 3636  the matrix and vector.  If we multiplied
3636  assume the vector was a row vector in order to make the dimensions  assume the vector was a row vector in order to make the dimensions
3637  come out right, and the answer would be incorrect.  If you  come out right, and the answer would be incorrect.  If you
3638  don't feel safe letting Calc take either interpretation of your  don't feel safe letting Calc take either interpretation of your
3639  vectors, use explicit @c{$N\times1$}  vectors, use explicit
3640  @asis{Nx1} or @c{$1\times N$}  @texline @tmath{N\times1}
3641  @asis{1xN} matrices instead.  @infoline Nx1
3642  In this case, you would enter the original column vector as  or
3643  @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}.  @texline @tmath{1\times N}
3644    @infoline 1xN
3645    matrices instead.  In this case, you would enter the original column
3646    vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}.
3647    
3648  (@bullet{}) @strong{Exercise 2.}  Algebraic entry allows you to make  (@bullet{}) @strong{Exercise 2.}  Algebraic entry allows you to make
3649  vectors and matrices that include variables.  Solve the following  vectors and matrices that include variables.  Solve the following
3650  system of equations to get expressions for @cite{x} and @cite{y}  system of equations to get expressions for @expr{x} and @expr{y}
3651  in terms of @cite{a} and @cite{b}.  in terms of @expr{a} and @expr{b}.
3652    
3653  @ifinfo  @ifinfo
3654  @group  @group
# Line 3628  if it has more equations than variables. Line 3677  if it has more equations than variables.
3677  there are no values for the variables that will satisfy all the  there are no values for the variables that will satisfy all the
3678  equations at once, but it is still useful to find a set of values  equations at once, but it is still useful to find a set of values
3679  which ``nearly'' satisfy all the equations.  In terms of matrix equations,  which ``nearly'' satisfy all the equations.  In terms of matrix equations,
3680  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}
3681  is not square for an over-determined system.  Matrix inversion works  is not square for an over-determined system.  Matrix inversion works
3682  only for square matrices.  One common trick is to multiply both sides  only for square matrices.  One common trick is to multiply both sides
3683  on the left by the transpose of @cite{A}:  on the left by the transpose of @expr{A}:
3684  @ifinfo  @ifinfo
3685  @samp{trn(A)*A*X = trn(A)*B}.  @samp{trn(A)*A*X = trn(A)*B}.
3686  @end ifinfo  @end ifinfo
# Line 3639  on the left by the transpose of @cite{A} Line 3688  on the left by the transpose of @cite{A}
3688  \turnoffactive  \turnoffactive
3689  $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.  $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.
3690  @end tex  @end tex
3691  Now @c{$A^T A$}  Now
3692  @cite{trn(A)*A} is a square matrix so a solution is possible.  It  @texline @tmath{A^T A}
3693  turns out that the @cite{X} vector you compute in this way will be a  @infoline @expr{trn(A)*A}
3694  ``least-squares'' solution, which can be regarded as the ``closest''  is a square matrix so a solution is possible.  It turns out that the
3695  solution to the set of equations.  Use Calc to solve the following  @expr{X} vector you compute in this way will be a ``least-squares''
3696  over-determined system:@refill  solution, which can be regarded as the ``closest'' solution to the set
3697    of equations.  Use Calc to solve the following over-determined
3698    system:
3699    
3700  @ifinfo  @ifinfo
3701  @group  @group
# Line 3733  other a plain number.)  In the final ste Line 3784  other a plain number.)  In the final ste
3784  of each element.  of each element.
3785    
3786  (@bullet{}) @strong{Exercise 1.}  Compute a vector of powers of two  (@bullet{}) @strong{Exercise 1.}  Compute a vector of powers of two
3787  from @c{$2^{-4}$}  from
3788  @cite{2^-4} to @cite{2^4}.  @xref{List Answer 1, 1}. (@bullet{})  @texline @tmath{2^{-4}}
3789    @infoline @expr{2^-4}
3790    to @expr{2^4}.  @xref{List Answer 1, 1}. (@bullet{})
3791    
3792  You can also @dfn{reduce} a binary operator across a vector.  You can also @dfn{reduce} a binary operator across a vector.
3793  For example, reducing @samp{*} computes the product of all the  For example, reducing @samp{*} computes the product of all the
# Line 3868  the manual and find this table there.  ( Line 3921  the manual and find this table there.  (
3921  @kbd{List Tutorial}, to jump straight to this section.)  @kbd{List Tutorial}, to jump straight to this section.)
3922    
3923  Position the cursor at the upper-left corner of this table, just  Position the cursor at the upper-left corner of this table, just
3924  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.
3925  (On your system this may be @kbd{C-2}, @kbd{C-@key{SPC}}, or @kbd{NUL}.)  (On your system this may be @kbd{C-2}, @kbd{C-@key{SPC}}, or @kbd{NUL}.)
3926  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}.
3927  You have now defined this region as an Emacs ``rectangle.''  Still  You have now defined this region as an Emacs ``rectangle.''  Still
3928  in the Info buffer, type @kbd{M-# r}.  This command  in the Info buffer, type @kbd{M-# r}.  This command
3929  (@code{calc-grab-rectangle}) will pop you back into the Calculator, with  (@code{calc-grab-rectangle}) will pop you back into the Calculator, with
3930  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.
3931    
3932  @smallexample  @smallexample
3933  @group  @group
# Line 3919  Let's store these in quick variables 1 a Line 3972  Let's store these in quick variables 1 a
3972  (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the  (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the
3973  stored value from the stack.)  stored value from the stack.)
3974    
3975  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
3976    
3977  @ifinfo  @ifinfo
3978  @example  @example
# Line 3935  $$ m = {N \sum x y - \sum x \sum y  \ove Line 3988  $$ m = {N \sum x y - \sum x \sum y  \ove
3988  @end tex  @end tex
3989    
3990  @noindent  @noindent
3991  where @c{$\sum x$}  where
3992  @cite{sum(x)} represents the sum of all the values of @cite{x}.  @texline @tmath{\sum x}
3993  While there is an actual @code{sum} function in Calc, it's easier to  @infoline @expr{sum(x)}
3994  sum a vector using a simple reduction.  First, let's compute the four  represents the sum of all the values of @expr{x}.  While there is an
3995  different sums that this formula uses.  actual @code{sum} function in Calc, it's easier to sum a vector using a
3996    simple reduction.  First, let's compute the four different sums that
3997    this formula uses.
3998    
3999  @smallexample  @smallexample
4000  @group  @group
# Line 3973  respectively.  (We could have used \kbd{ Line 4028  respectively.  (We could have used \kbd{
4028  $\sum x y$.)  $\sum x y$.)
4029  @end tex  @end tex
4030    
4031  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
4032  the length of either of our lists.  the length of either of our lists.
4033    
4034  @smallexample  @smallexample
# Line 4012  Now we grind through the formula: Line 4067  Now we grind through the formula:
4067  @end group  @end group
4068  @end smallexample  @end smallexample
4069    
4070  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
4071  be found with the simple formula,  be found with the simple formula,
4072    
4073  @ifinfo  @ifinfo
# Line 4038  $$ b = {\sum y - m \sum x \over N} $$ Line 4093  $$ b = {\sum y - m \sum x \over N} $$
4093  @end group  @end group
4094  @end smallexample  @end smallexample
4095    
4096  Let's ``plot'' this straight line approximation, @c{$y \approx m x + b$}  Let's ``plot'' this straight line approximation,
4097  @cite{m x + b}, and compare it with the original data.@refill  @texline @tmath{y \approx m x + b},
4098    @infoline @expr{m x + b},
4099    and compare it with the original data.
4100    
4101  @smallexample  @smallexample
4102  @group  @group
# Line 4056  to a vector, can be done without mapping Line 4113  to a vector, can be done without mapping
4113  common operations from vector algebra.  As far as Calc is concerned,  common operations from vector algebra.  As far as Calc is concerned,
4114  we've just been doing geometry in 19-dimensional space!  we've just been doing geometry in 19-dimensional space!
4115    
4116  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
4117  a feel for the error of our fit.  Let's find the maximum error:  a feel for the error of our fit.  Let's find the maximum error:
4118    
4119  @smallexample  @smallexample
# Line 4131  when you are done to remove the X graphi Line 4188  when you are done to remove the X graphi
4188    
4189  (@bullet{}) @strong{Exercise 2.}  An earlier exercise showed how to do  (@bullet{}) @strong{Exercise 2.}  An earlier exercise showed how to do
4190  least squares fitting to a general system of equations.  Our 19 data  least squares fitting to a general system of equations.  Our 19 data
4191  points are really 19 equations of the form @cite{y_i = m x_i + b} for  points are really 19 equations of the form @expr{y_i = m x_i + b} for
4192  different pairs of @cite{(x_i,y_i)}.  Use the matrix-transpose method  different pairs of @expr{(x_i,y_i)}.  Use the matrix-transpose method
4193  to solve for @cite{m} and @cite{b}, duplicating the above result.  to solve for @expr{m} and @expr{b}, duplicating the above result.
4194  @xref{List Answer 2, 2}. (@bullet{})  @xref{List Answer 2, 2}. (@bullet{})
4195    
4196  @cindex Geometric mean  @cindex Geometric mean
# Line 4161  us that the alternating sum of binomial Line 4218  us that the alternating sum of binomial
4218  @var{n}-choose-0 minus @var{n}-choose-1 plus @var{n}-choose-2, and so  @var{n}-choose-0 minus @var{n}-choose-1 plus @var{n}-choose-2, and so
4219  on up to @var{n}-choose-@var{n},  on up to @var{n}-choose-@var{n},
4220  always comes out to zero.  Let's verify this  always comes out to zero.  Let's verify this
4221  for @cite{n=6}.@refill  for @expr{n=6}.
4222  @end ifinfo  @end ifinfo
4223  @tex  @tex
4224  As another example, a theorem about binomial coefficients tells  As another example, a theorem about binomial coefficients tells
# Line 4232  element of a plain vector.  With a negat Line 4289  element of a plain vector.  With a negat
4289  and @kbd{v c} instead delete one row, column, or vector element.  and @kbd{v c} instead delete one row, column, or vector element.
4290    
4291  @cindex Divisor functions  @cindex Divisor functions
4292  (@bullet{}) @strong{Exercise 4.}  The @cite{k}th @dfn{divisor function}  (@bullet{}) @strong{Exercise 4.}  The @expr{k}th @dfn{divisor function}
4293  @tex  @tex
4294  $\sigma_k(n)$  $\sigma_k(n)$
4295  @end tex  @end tex
4296  is the sum of the @cite{k}th powers of all the divisors of an  is the sum of the @expr{k}th powers of all the divisors of an
4297  integer @cite{n}.  Figure out a method for computing the divisor  integer @expr{n}.  Figure out a method for computing the divisor
4298  function for reasonably small values of @cite{n}.  As a test,  function for reasonably small values of @expr{n}.  As a test,
4299  the 0th and 1st divisor functions of 30 are 8 and 72, respectively.  the 0th and 1st divisor functions of 30 are 8 and 72, respectively.
4300  @xref{List Answer 4, 4}. (@bullet{})  @xref{List Answer 4, 4}. (@bullet{})
4301    
# Line 4290  command to enable multi-line display of Line 4347  command to enable multi-line display of
4347  @cindex Maximizing a function over a list of values  @cindex Maximizing a function over a list of values
4348  @c [fix-ref Numerical Solutions]  @c [fix-ref Numerical Solutions]
4349  (@bullet{}) @strong{Exercise 8.}  Compute a list of values of Bessel's  (@bullet{}) @strong{Exercise 8.}  Compute a list of values of Bessel's
4350  @c{$J_1(x)$}  @texline @tmath{J_1(x)}
4351  @cite{J1} function @samp{besJ(1,x)} for @cite{x} from 0 to 5  @infoline @expr{J1}
4352  in steps of 0.25.  function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25.
4353  Find the value of @cite{x} (from among the above set of values) for  Find the value of @expr{x} (from among the above set of values) for
4354  which @samp{besJ(1,x)} is a maximum.  Use an ``automatic'' method,  which @samp{besJ(1,x)} is a maximum.  Use an ``automatic'' method,
4355  i.e., just reading along the list by hand to find the largest value  i.e., just reading along the list by hand to find the largest value
4356  is not allowed!  (There is an @kbd{a X} command which does this kind  is not allowed!  (There is an @kbd{a X} command which does this kind
4357  of thing automatically; @pxref{Numerical Solutions}.)  of thing automatically; @pxref{Numerical Solutions}.)
4358  @xref{List Answer 8, 8}. (@bullet{})@refill  @xref{List Answer 8, 8}. (@bullet{})
4359    
4360  @cindex Digits, vectors of  @cindex Digits, vectors of
4361  (@bullet{}) @strong{Exercise 9.}  You are given an integer in the range  (@bullet{}) @strong{Exercise 9.}  You are given an integer in the range
4362  @c{$0 \le N < 10^m$}  @texline @tmath{0 \le N < 10^m}
4363  @cite{0 <= N < 10^m} for @cite{m=12} (i.e., an integer of less than  @infoline @expr{0 <= N < 10^m}
4364  twelve digits).  Convert this integer into a vector of @cite{m}  for @expr{m=12} (i.e., an integer of less than
4365    twelve digits).  Convert this integer into a vector of @expr{m}
4366  digits, each in the range from 0 to 9.  In vector-of-digits notation,  digits, each in the range from 0 to 9.  In vector-of-digits notation,
4367  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
4368  (since there could be a carry out of the most significant digit).  (since there could be a carry out of the most significant digit).
4369  Convert this vector back into a regular integer.  A good integer  Convert this vector back into a regular integer.  A good integer
4370  to try is 25129925999.  @xref{List Answer 9, 9}. (@bullet{})  to try is 25129925999.  @xref{List Answer 9, 9}. (@bullet{})
# Line 4316  to try is 25129925999.  @xref{List Answe Line 4374  to try is 25129925999.  @xref{List Answe
4374  happened?  How would you do this test?  @xref{List Answer 10, 10}. (@bullet{})  happened?  How would you do this test?  @xref{List Answer 10, 10}. (@bullet{})
4375    
4376  (@bullet{}) @strong{Exercise 11.}  The area of a circle of radius one  (@bullet{}) @strong{Exercise 11.}  The area of a circle of radius one
4377  is @c{$\pi$}  is @cpi{}.  The area of the
4378  @cite{pi}.  The area of the @c{$2\times2$}  @texline @tmath{2\times2}
4379  @asis{2x2} square that encloses that  @infoline 2x2
4380  circle is 4.  So if we throw @var{n} darts at random points in the square,  square that encloses that circle is 4.  So if we throw @var{n} darts at
4381  about @c{$\pi/4$}  random points in the square, about @cpiover{4} of them will land inside
4382  @cite{pi/4} of them will land inside the circle.  This gives us  the circle.  This gives us an entertaining way to estimate the value of
4383  an entertaining way to estimate the value of @c{$\pi$}  @cpi{}.  The @w{@kbd{k r}}
 @cite{pi}.  The @w{@kbd{k r}}  
4384  command picks a random number between zero and the value on the stack.  command picks a random number between zero and the value on the stack.
4385  We could get a random floating-point number between @i{-1} and 1 by typing  We could get a random floating-point number between @i{-1} and 1 by typing
4386  @w{@kbd{2.0 k r 1 -}}.  Build a vector of 100 random @cite{(x,y)} points in  @w{@kbd{2.0 k r 1 -}}.  Build a vector of 100 random @expr{(x,y)} points in
4387  this square, then use vector mapping and reduction to count how many  this square, then use vector mapping and reduction to count how many
4388  points lie inside the unit circle.  Hint:  Use the @kbd{v b} command.  points lie inside the unit circle.  Hint:  Use the @kbd{v b} command.
4389  @xref{List Answer 11, 11}. (@bullet{})  @xref{List Answer 11, 11}. (@bullet{})
4390    
4391  @cindex Matchstick problem  @cindex Matchstick problem
4392  (@bullet{}) @strong{Exercise 12.}  The @dfn{matchstick problem} provides  (@bullet{}) @strong{Exercise 12.}  The @dfn{matchstick problem} provides
4393  another way to calculate @c{$\pi$}  another way to calculate @cpi{}.  Say you have an infinite field
 @cite{pi}.  Say you have an infinite field  
4394  of vertical lines with a spacing of one inch.  Toss a one-inch matchstick  of vertical lines with a spacing of one inch.  Toss a one-inch matchstick
4395  onto the field.  The probability that the matchstick will land crossing  onto the field.  The probability that the matchstick will land crossing
4396  a line turns out to be @c{$2/\pi$}  a line turns out to be
4397  @cite{2/pi}.  Toss 100 matchsticks to estimate  @texline @tmath{2/\pi}.
4398  @c{$\pi$}  @infoline @expr{2/pi}.  
4399  @cite{pi}.  (If you want still more fun, the probability that the GCD  Toss 100 matchsticks to estimate @cpi{}.  (If you want still more fun,
4400  (@w{@kbd{k g}}) of two large integers is one turns out to be @c{$6/\pi^2$}  the probability that the GCD (@w{@kbd{k g}}) of two large integers is
4401  @cite{6/pi^2}.  one turns out to be
4402  That provides yet another way to estimate @c{$\pi$}  @texline @tmath{6/\pi^2}.
4403  @cite{pi}.)  @infoline @expr{6/pi^2}.
4404    That provides yet another way to estimate @cpi{}.)
4405  @xref{List Answer 12, 12}. (@bullet{})  @xref{List Answer 12, 12}. (@bullet{})
4406    
4407  (@bullet{}) @strong{Exercise 13.}  An algebraic entry of a string in  (@bullet{}) @strong{Exercise 13.}  An algebraic entry of a string in
4408  double-quote marks, @samp{"hello"}, creates a vector of the numerical  double-quote marks, @samp{"hello"}, creates a vector of the numerical
4409  (ASCII) codes of the characters (here, @cite{[104, 101, 108, 108, 111]}).  (ASCII) codes of the characters (here, @expr{[104, 101, 108, 108, 111]}).
4410  Sometimes it is convenient to compute a @dfn{hash code} of a string,  Sometimes it is convenient to compute a @dfn{hash code} of a string,
4411  which is just an integer that represents the value of that string.  which is just an integer that represents the value of that string.
4412  Two equal strings have the same hash code; two different strings  Two equal strings have the same hash code; two different strings
# Line 4358  over 400 function names, but Emacs can q Line 4415  over 400 function names, but Emacs can q
4415  any given name because it has sorted the functions into ``buckets'' by  any given name because it has sorted the functions into ``buckets'' by
4416  their hash codes.  Sometimes a few names will hash into the same bucket,  their hash codes.  Sometimes a few names will hash into the same bucket,
4417  but it is easier to search among a few names than among all the names.)  but it is easier to search among a few names than among all the names.)
4418  One popular hash function is computed as follows:  First set @cite{h = 0}.  One popular hash function is computed as follows:  First set @expr{h = 0}.
4419  Then, for each character from the string in turn, set @cite{h = 3h + c_i}  Then, for each character from the string in turn, set @expr{h = 3h + c_i}
4420  where @cite{c_i} is the character's ASCII code.  If we have 511 buckets,  where @expr{c_i} is the character's ASCII code.  If we have 511 buckets,
4421  we then take the hash code modulo 511 to get the bucket number.  Develop a  we then take the hash code modulo 511 to get the bucket number.  Develop a
4422  simple command or commands for converting string vectors into hash codes.  simple command or commands for converting string vectors into hash codes.
4423  The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo  The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo
# Line 4372  value and a number of steps @var{n} from Line 4429  value and a number of steps @var{n} from
4429  function you give to the starting value 0, 1, 2, up to @var{n} times  function you give to the starting value 0, 1, 2, up to @var{n} times
4430  and returns a vector of the results.  Use this command to create a  and returns a vector of the results.  Use this command to create a
4431  ``random walk'' of 50 steps.  Start with the two-dimensional point  ``random walk'' of 50 steps.  Start with the two-dimensional point
4432  @cite{(0,0)}; then take one step a random distance between @i{-1} and 1  @expr{(0,0)}; then take one step a random distance between @i{-1} and 1
4433  in both @cite{x} and @cite{y}; then take another step, and so on.  Use the  in both @expr{x} and @expr{y}; then take another step, and so on.  Use the
4434  @kbd{g f} command to display this random walk.  Now modify your random  @kbd{g f} command to display this random walk.  Now modify your random
4435  walk to walk a unit distance, but in a random direction, at each step.  walk to walk a unit distance, but in a random direction, at each step.
4436  (Hint:  The @code{sincos} function returns a vector of the cosine and  (Hint:  The @code{sincos} function returns a vector of the cosine and
# Line 4436  same, to within the current precision. Line 4493  same, to within the current precision.
4493    
4494  (@bullet{}) @strong{Exercise 1.}  A calculation has produced the  (@bullet{}) @strong{Exercise 1.}  A calculation has produced the
4495  result 1.26508260337.  You suspect it is the square root of the  result 1.26508260337.  You suspect it is the square root of the
4496  product of @c{$\pi$}  product of @cpi{} and some rational number.  Is it?  (Be sure
 @cite{pi} and some rational number.  Is it?  (Be sure  
4497  to allow for roundoff error!)  @xref{Types Answer 1, 1}. (@bullet{})  to allow for roundoff error!)  @xref{Types Answer 1, 1}. (@bullet{})
4498    
4499  @dfn{Complex numbers} can be stored in both rectangular and polar form.  @dfn{Complex numbers} can be stored in both rectangular and polar form.
# Line 4453  to allow for roundoff error!)  @xref{Typ Line 4509  to allow for roundoff error!)  @xref{Typ
4509    
4510  @noindent  @noindent
4511  The square root of @i{-9} is by default rendered in rectangular form  The square root of @i{-9} is by default rendered in rectangular form
4512  (@w{@cite{0 + 3i}}), but we can convert it to polar form (3 with a  (@w{@expr{0 + 3i}}), but we can convert it to polar form (3 with a
4513  phase angle of 90 degrees).  All the usual arithmetic and scientific  phase angle of 90 degrees).  All the usual arithmetic and scientific
4514  operations are defined on both types of complex numbers.  operations are defined on both types of complex numbers.
4515    
# Line 4509  to turn on ``infinite mode.'' Line 4565  to turn on ``infinite mode.''
4565  Dividing by zero normally is left unevaluated, but after @kbd{m i}  Dividing by zero normally is left unevaluated, but after @kbd{m i}
4566  it instead gives an infinite result.  The answer is actually  it instead gives an infinite result.  The answer is actually
4567  @code{uinf}, ``undirected infinity.''  If you look at a graph of  @code{uinf}, ``undirected infinity.''  If you look at a graph of
4568  @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
4569  plus infinity as you approach zero from above, but toward minus  plus infinity as you approach zero from above, but toward minus
4570  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},
4571  Calc knows that the answer is infinite but not in which direction.  Calc knows that the answer is infinite but not in which direction.
4572  That's what @code{uinf} means.  Notice that multiplying @code{uinf}  That's what @code{uinf} means.  Notice that multiplying @code{uinf}
4573  by a negative number still leaves plain @code{uinf}; there's no  by a negative number still leaves plain @code{uinf}; there's no
# Line 4641  a 60% chance that the result is correct Line 4697  a 60% chance that the result is correct
4697    
4698  @cindex Torus, volume of  @cindex Torus, volume of
4699  (@bullet{}) @strong{Exercise 7.}  The volume of a torus (a donut shape) is  (@bullet{}) @strong{Exercise 7.}  The volume of a torus (a donut shape) is
4700  @c{$2 \pi^2 R r^2$}  @texline @tmath{2 \pi^2 R r^2}
4701  @w{@cite{2 pi^2 R r^2}} where @cite{R} is the radius of the circle that  @infoline @w{@expr{2 pi^2 R r^2}}
4702  defines the center of the tube and @cite{r} is the radius of the tube  where @expr{R} is the radius of the circle that
4703  itself.  Suppose @cite{R} is 20 cm and @cite{r} is 4 cm, each known to  defines the center of the tube and @expr{r} is the radius of the tube
4704    itself.  Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to
4705  within 5 percent.  What is the volume and the relative uncertainty of  within 5 percent.  What is the volume and the relative uncertainty of
4706  the volume?  @xref{Types Answer 7, 7}. (@bullet{})  the volume?  @xref{Types Answer 7, 7}. (@bullet{})
4707    
# Line 4739  that arises in the second one. Line 4796  that arises in the second one.
4796    
4797  @cindex Fermat, primality test of  @cindex Fermat, primality test of
4798  (@bullet{}) @strong{Exercise 10.}  A theorem of Pierre de Fermat  (@bullet{}) @strong{Exercise 10.}  A theorem of Pierre de Fermat
4799  says that @c{\w{$x^{n-1} \bmod n = 1$}}  says that
4800  @cite{x^(n-1) mod n = 1} if @cite{n} is a prime number  @texline @w{@tmath{x^{n-1} \bmod n = 1}}
4801  and @cite{x} is an integer less than @cite{n}.  If @cite{n} is  @infoline @expr{x^(n-1) mod n = 1}
4802  @emph{not} a prime number, this will @emph{not} be true for most  if @expr{n} is a prime number and @expr{x} is an integer less than
4803  values of @cite{x}.  Thus we can test informally if a number is  @expr{n}.  If @expr{n} is @emph{not} a prime number, this will
4804  prime by trying this formula for several values of @cite{x}.  @emph{not} be true for most values of @expr{x}.  Thus we can test
4805  Use this test to tell whether the following numbers are prime:  informally if a number is prime by trying this formula for several
4806  811749613, 15485863.  @xref{Types Answer 10, 10}. (@bullet{})  values of @expr{x}.  Use this test to tell whether the following numbers
4807    are prime: 811749613, 15485863.  @xref{Types Answer 10, 10}. (@bullet{})
4808    
4809  It is possible to use HMS forms as parts of error forms, intervals,  It is possible to use HMS forms as parts of error forms, intervals,
4810  modulo forms, or as the phase part of a polar complex number.  modulo forms, or as the phase part of a polar complex number.
# Line 4766  of day on the stack as an HMS/modulo for Line 4824  of day on the stack as an HMS/modulo for
4824  This calculation tells me it is six hours and 22 minutes until midnight.  This calculation tells me it is six hours and 22 minutes until midnight.
4825    
4826  (@bullet{}) @strong{Exercise 11.}  A rule of thumb is that one year  (@bullet{}) @strong{Exercise 11.}  A rule of thumb is that one year
4827  is about @c{$\pi \times 10^7$}  is about
4828  @w{@cite{pi * 10^7}} seconds.  What time will it be that  @texline @tmath{\pi \times 10^7}
4829  many seconds from right now?  @xref{Types Answer 11, 11}. (@bullet{})  @infoline @w{@expr{pi * 10^7}}
4830    seconds.  What time will it be that many seconds from right now?
4831    @xref{Types Answer 11, 11}. (@bullet{})
4832    
4833  (@bullet{}) @strong{Exercise 12.}  You are preparing to order packaging  (@bullet{}) @strong{Exercise 12.}  You are preparing to order packaging
4834  for the CD release of the Extended Disco Version of @emph{Abbey Road}.  for the CD release of the Extended Disco Version of @emph{Abbey Road}.
# Line 4949  formulas.  Continuing with the formula f Line 5009  formulas.  Continuing with the formula f
5009    
5010  @noindent  @noindent
5011  First we ``expand'' using the distributive law, then we ``collect''  First we ``expand'' using the distributive law, then we ``collect''
5012  terms involving like powers of @cite{x}.  terms involving like powers of @expr{x}.
5013    
5014  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}
5015  is one-half.  is one-half.
5016    
5017  @smallexample  @smallexample
# Line 4976  unstore it with @kbd{s u x @key{RET}} be Line 5036  unstore it with @kbd{s u x @key{RET}} be
5036  properly.)  properly.)
5037    
5038  @cindex Maximum of a function using Calculus  @cindex Maximum of a function using Calculus
5039  Let's find the maximum value of our original expression when @cite{y}  Let's find the maximum value of our original expression when @expr{y}
5040  is one-half and @cite{x} ranges over all possible values.  We can  is one-half and @expr{x} ranges over all possible values.  We can
5041  do this by taking the derivative with respect to @cite{x} and examining  do this by taking the derivative with respect to @expr{x} and examining
5042  values of @cite{x} for which the derivative is zero.  If the second  values of @expr{x} for which the derivative is zero.  If the second
5043  derivative of the function at that value of @cite{x} is negative,  derivative of the function at that value of @expr{x} is negative,
5044  the function has a local maximum there.  the function has a local maximum there.
5045    
5046  @smallexample  @smallexample
# Line 4993  the function has a local maximum there. Line 5053  the function has a local maximum there.
5053  @end smallexample  @end smallexample
5054    
5055  @noindent  @noindent
5056  Well, the derivative is clearly zero when @cite{x} is zero.  To find  Well, the derivative is clearly zero when @expr{x} is zero.  To find
5057  the other root(s), let's divide through by @cite{x} and then solve:  the other root(s), let's divide through by @expr{x} and then solve:
5058    
5059  @smallexample  @smallexample
5060  @group  @group
# Line 5020  Notice the use of @kbd{a s} to ``simplif Line 5080  Notice the use of @kbd{a s} to ``simplif
5080  default algebraic simplifications don't do enough, you can use  default algebraic simplifications don't do enough, you can use
5081  @kbd{a s} to tell Calc to spend more time on the job.  @kbd{a s} to tell Calc to spend more time on the job.
5082    
5083  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}:
5084    
5085  @smallexample  @smallexample
5086  @group  @group
# Line 5050  to delete the @samp{x}.) Line 5110  to delete the @samp{x}.)
5110    
5111  @noindent  @noindent
5112  The first of these second derivatives is negative, so we know the function  The first of these second derivatives is negative, so we know the function
5113  has a maximum value at @cite{x = 1.19023}.  (The function also has a  has a maximum value at @expr{x = 1.19023}.  (The function also has a
5114  local @emph{minimum} at @cite{x = 0}.)  local @emph{minimum} at @expr{x = 0}.)
5115    
5116  When we solved for @cite{x}, we got only one value even though  When we solved for @expr{x}, we got only one value even though
5117  @cite{34 - 24 x^2 = 0} is a quadratic equation that ought to have  @expr{34 - 24 x^2 = 0} is a quadratic equation that ought to have
5118  two solutions.  The reason is that @w{@kbd{a S}} normally returns a  two solutions.  The reason is that @w{@kbd{a S}} normally returns a
5119  single ``principal'' solution.  If it needs to come up with an  single ``principal'' solution.  If it needs to come up with an
5120  arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}.  arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}.
5121  If it needs an arbitrary integer, it picks zero.  We can get a full  If it needs an arbitrary integer, it picks zero.  We can get a full
5122  solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.  solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.
5123    
# Line 5075  Calc has invented the variable @samp{s1} Line 5135  Calc has invented the variable @samp{s1}
5135  it is supposed to be either @i{+1} or @i{-1}.  Here we have used  it is supposed to be either @i{+1} or @i{-1}.  Here we have used
5136  the ``let'' command to evaluate the expression when the sign is negative.  the ``let'' command to evaluate the expression when the sign is negative.
5137  If we plugged this into our second derivative we would get the same,  If we plugged this into our second derivative we would get the same,
5138  negative, answer, so @cite{x = -1.19023} is also a maximum.  negative, answer, so @expr{x = -1.19023} is also a maximum.
5139    
5140  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}
5141  into the original formula.  into the original formula.
5142    
5143  @smallexample  @smallexample
# Line 5127  Calc has a built-in @kbd{a P} command th Line 5187  Calc has a built-in @kbd{a P} command th
5187  @w{@kbd{H a S}} and returns a vector of all the solutions.  It simply  @w{@kbd{H a S}} and returns a vector of all the solutions.  It simply
5188  automates the job we just did by hand.  Applied to our original  automates the job we just did by hand.  Applied to our original
5189  cubic polynomial, it would produce the vector of solutions  cubic polynomial, it would produce the vector of solutions
5190  @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
5191  which finds a local maximum of a function.  It uses a numerical search  which finds a local maximum of a function.  It uses a numerical search
5192  method rather than examining the derivatives, and thus requires you  method rather than examining the derivatives, and thus requires you
5193  to provide some kind of initial guess to show it where to look.)  to provide some kind of initial guess to show it where to look.)
# Line 5215  may prefer to remain in Big mode, but al Line 5275  may prefer to remain in Big mode, but al
5275  are shown in normal mode.)  are shown in normal mode.)
5276    
5277  @cindex Area under a curve  @cindex Area under a curve
5278  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}?
5279  This is simply the integral of the function:  This is simply the integral of the function:
5280    
5281  @smallexample  @smallexample
# Line 5228  This is simply the integral of the funct Line 5288  This is simply the integral of the funct
5288  @end smallexample  @end smallexample
5289    
5290  @noindent  @noindent
5291  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.
5292  One way to do it is again with vector mapping and reduction:  One way to do it is again with vector mapping and reduction:
5293    
5294  @smallexample  @smallexample
# Line 5240  One way to do it is again with vector ma Line 5300  One way to do it is again with vector ma
5300  @end group  @end group
5301  @end smallexample  @end smallexample
5302    
5303  (@bullet{}) @strong{Exercise 3.}  Find the integral from 1 to @cite{y}  (@bullet{}) @strong{Exercise 3.}  Find the integral from 1 to @expr{y}
5304  of @c{$x \sin \pi x$}  of
5305  @w{@cite{x sin(pi x)}} (where the sine is calculated in radians).  @texline @tmath{x \sin \pi x}
5306  Find the values of the integral for integers @cite{y} from 1 to 5.  @infoline @w{@expr{x sin(pi x)}}
5307  @xref{Algebra Answer 3, 3}. (@bullet{})  (where the sine is calculated in radians).  Find the values of the
5308    integral for integers @expr{y} from 1 to 5.  @xref{Algebra Answer 3,
5309    3}. (@bullet{})
5310    
5311  Calc's integrator can do many simple integrals symbolically, but many  Calc's integrator can do many simple integrals symbolically, but many
5312  others are beyond its capabilities.  Suppose we wish to find the area  others are beyond its capabilities.  Suppose we wish to find the area
5313  under the curve @c{$\sin x \ln x$}  under the curve
5314  @cite{sin(x) ln(x)} over the same range of @cite{x}.  If  @texline @tmath{\sin x \ln x}
5315  you entered this formula and typed @kbd{a i x @key{RET}} (don't bother to try  @infoline @expr{sin(x) ln(x)}
5316  this), Calc would work for a long time but would be unable to find a  over the same range of @expr{x}.  If you entered this formula and typed
5317  solution.  In fact, there is no closed-form solution to this integral.  @kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a
5318  Now what do we do?  long time but would be unable to find a solution.  In fact, there is no
5319    closed-form solution to this integral.  Now what do we do?
5320    
5321  @cindex Integration, numerical  @cindex Integration, numerical
5322  @cindex Numerical integration  @cindex Numerical integration
# Line 5322  we're not doing too well.  Let's try ano Line 5385  we're not doing too well.  Let's try ano
5385    
5386  @noindent  @noindent
5387  Here we have computed the Taylor series expansion of the function  Here we have computed the Taylor series expansion of the function
5388  about the point @cite{x=1}.  We can now integrate this polynomial  about the point @expr{x=1}.  We can now integrate this polynomial
5389  approximation, since polynomials are easy to integrate.  approximation, since polynomials are easy to integrate.
5390    
5391  @smallexample  @smallexample
# Line 5339  Better!  By increasing the precision and Line 5402  Better!  By increasing the precision and
5402  in the Taylor series, we can get a result as accurate as we like.  in the Taylor series, we can get a result as accurate as we like.
5403  (Taylor series converge better away from singularities in the  (Taylor series converge better away from singularities in the
5404  function such as the one at @code{ln(0)}, so it would also help to  function such as the one at @code{ln(0)}, so it would also help to
5405  expand the series about the points @cite{x=2} or @cite{x=1.5} instead  expand the series about the points @expr{x=2} or @expr{x=1.5} instead
5406  of @cite{x=1}.)  of @expr{x=1}.)
5407    
5408  @cindex Simpson's rule  @cindex Simpson's rule
5409  @cindex Integration by Simpson's rule  @cindex Integration by Simpson's rule
# Line 5370  $$ \displaylines{ Line 5433  $$ \displaylines{
5433  @end tex  @end tex
5434    
5435  @noindent  @noindent
5436  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}
5437  is the width of each slice.  These are 10 and 0.1 in our example.  is the width of each slice.  These are 10 and 0.1 in our example.
5438  For reference, here is the corresponding formula for the stairstep  For reference, here is the corresponding formula for the stairstep
5439  method:  method:
# Line 5389  $$ h (f(a) + f(a+h) + f(a+2h) + f(a+3h) Line 5452  $$ h (f(a) + f(a+h) + f(a+2h) + f(a+3h)
5452  \afterdisplay  \afterdisplay
5453  @end tex  @end tex
5454    
5455  Compute the integral from 1 to 2 of @c{$\sin x \ln x$}  Compute the integral from 1 to 2 of
5456  @cite{sin(x) ln(x)} using  @texline @tmath{\sin x \ln x}
5457  Simpson's rule with 10 slices.  @xref{Algebra Answer 4, 4}. (@bullet{})  @infoline @expr{sin(x) ln(x)}
5458    using Simpson's rule with 10 slices.  
5459    @xref{Algebra Answer 4, 4}. (@bullet{})
5460    
5461  Calc has a built-in @kbd{a I} command for doing numerical integration.  Calc has a built-in @kbd{a I} command for doing numerical integration.
5462  It uses @dfn{Romberg's method}, which is a more sophisticated cousin  It uses @dfn{Romberg's method}, which is a more sophisticated cousin
# Line 5639  constants @samp{e}, @samp{phi}, and so o Line 5704  constants @samp{e}, @samp{phi}, and so o
5704  A common error with rewrite  A common error with rewrite
5705  rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting  rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
5706  to match any @samp{f} with five arguments but in fact matching  to match any @samp{f} with five arguments but in fact matching
5707  only when the fifth argument is literally @samp{e}!@refill  only when the fifth argument is literally @samp{e}!
5708    
5709  @cindex Fibonacci numbers  @cindex Fibonacci numbers
5710  @ignore  @ignore
# Line 5789  on the stack and tried to use the rule Line 5854  on the stack and tried to use the rule
5854  @samp{opt(a) + opt(b) x := f(a, b, x)}.  What happened?  @samp{opt(a) + opt(b) x := f(a, b, x)}.  What happened?
5855  @xref{Rewrites Answer 3, 3}. (@bullet{})  @xref{Rewrites Answer 3, 3}. (@bullet{})
5856    
5857  (@bullet{}) @strong{Exercise 4.}  Starting with a positive integer @cite{a},  (@bullet{}) @strong{Exercise 4.}  Starting with a positive integer @expr{a},
5858  divide @cite{a} by two if it is even, otherwise compute @cite{3 a + 1}.  divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}.
5859  Now repeat this step over and over.  A famous unproved conjecture  Now repeat this step over and over.  A famous unproved conjecture
5860  is that for any starting @cite{a}, the sequence always eventually  is that for any starting @expr{a}, the sequence always eventually
5861  reaches 1.  Given the formula @samp{seq(@var{a}, 0)}, write a set of  reaches 1.  Given the formula @samp{seq(@var{a}, 0)}, write a set of
5862  rules that convert this into @samp{seq(1, @var{n})} where @var{n}  rules that convert this into @samp{seq(1, @var{n})} where @var{n}
5863  is the number of steps it took the sequence to reach the value 1.  is the number of steps it took the sequence to reach the value 1.
# Line 5801  configuration, and to stop with just the Line 5866  configuration, and to stop with just the
5866  Now make the result be a vector of values in the sequence, from @var{a}  Now make the result be a vector of values in the sequence, from @var{a}
5867  to 1.  (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x}  to 1.  (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x}
5868  and @var{y}.)  For example, rewriting @samp{seq(6)} should yield the  and @var{y}.)  For example, rewriting @samp{seq(6)} should yield the
5869  vector @cite{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.  vector @expr{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
5870  @xref{Rewrites Answer 4, 4}. (@bullet{})  @xref{Rewrites Answer 4, 4}. (@bullet{})
5871    
5872  (@bullet{}) @strong{Exercise 5.}  Define, using rewrite rules, a function  (@bullet{}) @strong{Exercise 5.}  Define, using rewrite rules, a function
5873  @samp{nterms(@var{x})} that returns the number of terms in the sum  @samp{nterms(@var{x})} that returns the number of terms in the sum
5874  @var{x}, or 1 if @var{x} is not a sum.  (A @dfn{sum} for our purposes  @var{x}, or 1 if @var{x} is not a sum.  (A @dfn{sum} for our purposes
5875  is one or more non-sum terms separated by @samp{+} or @samp{-} signs,  is one or more non-sum terms separated by @samp{+} or @samp{-} signs,
5876  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.)
5877  @xref{Rewrites Answer 5, 5}. (@bullet{})  @xref{Rewrites Answer 5, 5}. (@bullet{})
5878    
5879  (@bullet{}) @strong{Exercise 6.}  Calc considers the form @cite{0^0}  (@bullet{}) @strong{Exercise 6.}  Calc considers the form @expr{0^0}
5880  to be ``indeterminate,'' and leaves it unevaluated (assuming infinite  to be ``indeterminate,'' and leaves it unevaluated (assuming infinite
5881  mode is not enabled).  Some people prefer to define @cite{0^0 = 1},  mode is not enabled).  Some people prefer to define @expr{0^0 = 1},
5882  so that the identity @cite{x^0 = 1} can safely be used for all @cite{x}.  so that the identity @expr{x^0 = 1} can safely be used for all @expr{x}.
5883  Find a way to make Calc follow this convention.  What happens if you  Find a way to make Calc follow this convention.  What happens if you
5884  now type @kbd{m i} to turn on infinite mode?  now type @kbd{m i} to turn on infinite mode?
5885  @xref{Rewrites Answer 6, 6}. (@bullet{})  @xref{Rewrites Answer 6, 6}. (@bullet{})
5886    
5887  (@bullet{}) @strong{Exercise 7.}  A Taylor series for a function is an  (@bullet{}) @strong{Exercise 7.}  A Taylor series for a function is an
5888  infinite series that exactly equals the value of that function at  infinite series that exactly equals the value of that function at
5889  values of @cite{x} near zero.  values of @expr{x} near zero.
5890    
5891  @ifinfo  @ifinfo
5892  @example  @example
# Line 5829  cos(x) = 1 - x^2 / 2! + x^4 / 4! - x^6 / Line 5894  cos(x) = 1 - x^2 / 2! + x^4 / 4! - x^6 /
5894  @end example  @end example
5895  @end ifinfo  @end ifinfo
5896  @tex  @tex
5897  \turnoffactive \let\rm\goodrm  \turnoffactive
5898  \beforedisplay  \beforedisplay
5899  $$ \cos x = 1 - {x^2 \over 2!} + {x^4 \over 4!} - {x^6 \over 6!} + \cdots $$  $$ \cos x = 1 - {x^2 \over 2!} + {x^4 \over 4!} - {x^6 \over 6!} + \cdots $$
5900  \afterdisplay  \afterdisplay
5901  @end tex  @end tex
5902    
5903  The @kbd{a t} command produces a @dfn{truncated Taylor series} which  The @kbd{a t} command produces a @dfn{truncated Taylor series} which
5904  is obtained by dropping all the terms higher than, say, @cite{x^2}.  is obtained by dropping all the terms higher than, say, @expr{x^2}.
5905  Calc represents the truncated Taylor series as a polynomial in @cite{x}.  Calc represents the truncated Taylor series as a polynomial in @expr{x}.
5906  Mathematicians often write a truncated series using a ``big-O'' notation  Mathematicians often write a truncated series using a ``big-O'' notation
5907  that records what was the lowest term that was truncated.  that records what was the lowest term that was truncated.
5908    
# Line 5847  cos(x) = 1 - x^2 / 2! + O(x^3) Line 5912  cos(x) = 1 - x^2 / 2! + O(x^3)
5912  @end example  @end example
5913  @end ifinfo  @end ifinfo
5914  @tex  @tex
5915  \turnoffactive \let\rm\goodrm  \turnoffactive
5916  \beforedisplay  \beforedisplay
5917  $$ \cos x = 1 - {x^2 \over 2!} + O(x^3) $$  $$ \cos x = 1 - {x^2 \over 2!} + O(x^3) $$
5918  \afterdisplay  \afterdisplay
5919  @end tex  @end tex
5920    
5921  @noindent  @noindent
5922  The meaning of @cite{O(x^3)} is ``a quantity which is negligibly small  The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small
5923  if @cite{x^3} is considered negligibly small as @cite{x} goes to zero.''  if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.''
5924    
5925  The exercise is to create rewrite rules that simplify sums and products of  The exercise is to create rewrite rules that simplify sums and products of
5926  power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}.  power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}.
# Line 5934  in @samp{a + 1} for @samp{x} in the defi Line 5999  in @samp{a + 1} for @samp{x} in the defi
5999  @end ignore  @end ignore
6000  @tindex Si  @tindex Si
6001  (@bullet{}) @strong{Exercise 1.}  The ``sine integral'' function  (@bullet{}) @strong{Exercise 1.}  The ``sine integral'' function
6002  @c{${\rm Si}(x)$}  @texline @tmath{{\rm Si}(x)}
6003  @cite{Si(x)} is defined as the integral of @samp{sin(t)/t} for  @infoline @expr{Si(x)}
6004  @cite{t = 0} to @cite{x} in radians.  (It was invented because this  is defined as the integral of @samp{sin(t)/t} for
6005    @expr{t = 0} to @expr{x} in radians.  (It was invented because this
6006  integral has no solution in terms of basic functions; if you give it  integral has no solution in terms of basic functions; if you give it
6007  to Calc's @kbd{a i} command, it will ponder it for a long time and then  to Calc's @kbd{a i} command, it will ponder it for a long time and then
6008  give up.)  We can use the numerical integration command, however,  give up.)  We can use the numerical integration command, however,
# Line 6010  the following functions: Line 6076  the following functions:
6076    
6077  @enumerate  @enumerate
6078  @item  @item
6079  Compute @c{$\displaystyle{\sin x \over x}$}  Compute
6080  @cite{sin(x) / x}, where @cite{x} is the number on the  @texline @tmath{\displaystyle{\sin x \over x}},
6081  top of the stack.  @infoline @expr{sin(x) / x},
6082    where @expr{x} is the number on the top of the stack.
6083    
6084  @item  @item
6085  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
6086  the arguments are taken in the opposite order.  the arguments are taken in the opposite order.
6087    
6088  @item  @item
# Line 6044  inside keyboard macros, but actually wor Line 6111  inside keyboard macros, but actually wor
6111  @end smallexample  @end smallexample
6112    
6113  @noindent  @noindent
6114  Here we have computed the fourth derivative of @cite{x^6} by  Here we have computed the fourth derivative of @expr{x^6} by
6115  enclosing a derivative command in a ``repeat loop'' structure.  enclosing a derivative command in a ``repeat loop'' structure.
6116  This structure pops a repeat count from the stack, then  This structure pops a repeat count from the stack, then
6117  executes the body of the loop that many times.  executes the body of the loop that many times.
# Line 6074  key if you have one, makes a copy of the Line 6141  key if you have one, makes a copy of the
6141    
6142  @cindex Golden ratio  @cindex Golden ratio
6143  @cindex Phi, golden ratio  @cindex Phi, golden ratio
6144  A fascinating property of the Fibonacci numbers is that the @cite{n}th  A fascinating property of the Fibonacci numbers is that the @expr{n}th
6145  Fibonacci number can be found directly by computing @c{$\phi^n / \sqrt{5}$}  Fibonacci number can be found directly by computing
6146  @cite{phi^n / sqrt(5)}  @texline @tmath{\phi^n / \sqrt{5}}
6147  and then rounding to the nearest integer, where @c{$\phi$ (``phi'')}  @infoline @expr{phi^n / sqrt(5)}
6148  @cite{phi}, the  and then rounding to the nearest integer, where
6149  ``golden ratio,'' is @c{$(1 + \sqrt{5}) / 2$}  @texline @tmath{\phi} (``phi''),
6150  @cite{(1 + sqrt(5)) / 2}.  (For convenience, this constant is available  @infoline @expr{phi},
6151  from the @code{phi} variable, or the @kbd{I H P} command.)  the ``golden ratio,'' is
6152    @texline @tmath{(1 + \sqrt{5}) / 2}.
6153    @infoline @expr{(1 + sqrt(5)) / 2}.
6154    (For convenience, this constant is available from the @code{phi}
6155    variable, or the @kbd{I H P} command.)
6156    
6157  @smallexample  @smallexample
6158  @group  @group
# Line 6094  from the @code{phi} variable, or the @kb Line 6165  from the @code{phi} variable, or the @kb
6165    
6166  @cindex Continued fractions  @cindex Continued fractions
6167  (@bullet{}) @strong{Exercise 5.}  The @dfn{continued fraction}  (@bullet{}) @strong{Exercise 5.}  The @dfn{continued fraction}
6168  representation of @c{$\phi$}  representation of
6169  @cite{phi} is @c{$1 + 1/(1 + 1/(1 + 1/( \ldots )))$}  @texline @tmath{\phi}
6170  @cite{1 + 1/(1 + 1/(1 + 1/( ...@: )))}.  @infoline @expr{phi}
6171    is
6172    @texline @tmath{1 + 1/(1 + 1/(1 + 1/( \ldots )))}.
6173    @infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}.
6174  We can compute an approximate value by carrying this however far  We can compute an approximate value by carrying this however far
6175  and then replacing the innermost @c{$1/( \ldots )$}  and then replacing the innermost
6176  @cite{1/( ...@: )} by 1.  Approximate  @texline @tmath{1/( \ldots )}
6177  @c{$\phi$}  @infoline @expr{1/( ...@: )}
6178  @cite{phi} using a twenty-term continued fraction.  by 1.  Approximate
6179    @texline @tmath{\phi}
6180    @infoline @expr{phi}
6181    using a twenty-term continued fraction.
6182  @xref{Programming Answer 5, 5}. (@bullet{})  @xref{Programming Answer 5, 5}. (@bullet{})
6183    
6184  (@bullet{}) @strong{Exercise 6.}  Linear recurrences like the one for  (@bullet{}) @strong{Exercise 6.}  Linear recurrences like the one for
6185  Fibonacci numbers can be expressed in terms of matrices.  Given a  Fibonacci numbers can be expressed in terms of matrices.  Given a
6186  vector @w{@cite{[a, b]}} determine a matrix which, when multiplied by this  vector @w{@expr{[a, b]}} determine a matrix which, when multiplied by this
6187  vector, produces the vector @cite{[b, c]}, where @cite{a}, @cite{b} and  vector, produces the vector @expr{[b, c]}, where @expr{a}, @expr{b} and
6188  @cite{c} are three successive Fibonacci numbers.  Now write a program  @expr{c} are three successive Fibonacci numbers.  Now write a program
6189  that, given an integer @cite{n}, computes the @cite{n}th Fibonacci number  that, given an integer @expr{n}, computes the @expr{n}th Fibonacci number
6190  using matrix arithmetic.  @xref{Programming Answer 6, 6}. (@bullet{})  using matrix arithmetic.  @xref{Programming Answer 6, 6}. (@bullet{})
6191    
6192  @cindex Harmonic numbers  @cindex Harmonic numbers
# Line 6198  survive past the @kbd{Z '} command. Line 6275  survive past the @kbd{Z '} command.
6275  The @dfn{Bernoulli numbers} are a sequence with the interesting  The @dfn{Bernoulli numbers} are a sequence with the interesting
6276  property that all of the odd Bernoulli numbers are zero, and the  property that all of the odd Bernoulli numbers are zero, and the
6277  even ones, while difficult to compute, can be roughly approximated  even ones, while difficult to compute, can be roughly approximated
6278  by the formula @c{$\displaystyle{2 n! \over (2 \pi)^n}$}  by the formula
6279  @cite{2 n!@: / (2 pi)^n}.  Let's write a keyboard  @texline @tmath{\displaystyle{2 n! \over (2 \pi)^n}}.
6280  macro to compute (approximate) Bernoulli numbers.  (Calc has a  @infoline @expr{2 n!@: / (2 pi)^n}.  
6281  command, @kbd{k b}, to compute exact Bernoulli numbers, but  Let's write a keyboard macro to compute (approximate) Bernoulli numbers.
6282  this command is very slow for large @cite{n} since the higher  (Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but
6283  Bernoulli numbers are very large fractions.)  this command is very slow for large @expr{n} since the higher Bernoulli
6284    numbers are very large fractions.)
6285    
6286  @smallexample  @smallexample
6287  @group  @group
# Line 6223  if it pops zero or something that is not Line 6301  if it pops zero or something that is not
6301  Here we take our integer argument modulo 2; this will be nonzero  Here we take our integer argument modulo 2; this will be nonzero
6302  if we're asking for an odd Bernoulli number.  if we're asking for an odd Bernoulli number.
6303    
6304  The actual tenth Bernoulli number is @cite{5/66}.  The actual tenth Bernoulli number is @expr{5/66}.
6305    
6306  @smallexample  @smallexample
6307  @group  @group
# Line 6354  Z ' Line 6432  Z '
6432    
6433  (@bullet{}) @strong{Exercise 8.}  A general algorithm for solving  (@bullet{}) @strong{Exercise 8.}  A general algorithm for solving
6434  equations numerically is @dfn{Newton's Method}.  Given the equation  equations numerically is @dfn{Newton's Method}.  Given the equation
6435  @cite{f(x) = 0} for any function @cite{f}, and an initial guess  @expr{f(x) = 0} for any function @expr{f}, and an initial guess
6436  @cite{x_0} which is reasonably close to the desired solution, apply  @expr{x_0} which is reasonably close to the desired solution, apply
6437  this formula over and over:  this formula over and over:
6438    
6439  @ifinfo  @ifinfo
# Line 6365  new_x = x - f(x)/f'(x) Line 6443  new_x = x - f(x)/f'(x)
6443  @end ifinfo  @end ifinfo
6444  @tex  @tex
6445  \beforedisplay  \beforedisplay
6446  $$ x_{\goodrm new} = x - {f(x) \over f'(x)} $$  $$ x_{\rm new} = x - {f(x) \over f'(x)} $$
6447  \afterdisplay  \afterdisplay
6448  @end tex  @end tex
6449    
6450  @noindent  @noindent
6451  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}
6452  values will quickly converge to a solution, i.e., eventually  values will quickly converge to a solution, i.e., eventually
6453  @c{$x_{\rm new}$}  @texline @tmath{x_{\rm new}}
6454  @cite{new_x} and @cite{x} will be equal to within the limits  @infoline @expr{new_x}
6455    and @expr{x} will be equal to within the limits
6456  of the current precision.  Write a program which takes a formula  of the current precision.  Write a program which takes a formula
6457  involving the variable @cite{x}, and an initial guess @cite{x_0},  involving the variable @expr{x}, and an initial guess @expr{x_0},
6458  on the stack, and produces a value of @cite{x} for which the formula  on the stack, and produces a value of @expr{x} for which the formula
6459  is zero.  Use it to find a solution of @c{$\sin(\cos x) = 0.5$}  is zero.  Use it to find a solution of
6460  @cite{sin(cos(x)) = 0.5}  @texline @tmath{\sin(\cos x) = 0.5}
6461  near @cite{x = 4.5}.  (Use angles measured in radians.)  Note that  @infoline @expr{sin(cos(x)) = 0.5}
6462    near @expr{x = 4.5}.  (Use angles measured in radians.)  Note that
6463  the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's  the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's
6464  method when it is able.  @xref{Programming Answer 8, 8}. (@bullet{})  method when it is able.  @xref{Programming Answer 8, 8}. (@bullet{})
6465    
6466  @cindex Digamma function  @cindex Digamma function
6467  @cindex Gamma constant, Euler's  @cindex Gamma constant, Euler's
6468  @cindex Euler's gamma constant  @cindex Euler's gamma constant
6469  (@bullet{}) @strong{Exercise 9.}  The @dfn{digamma} function @c{$\psi(z)$ (``psi'')}  (@bullet{}) @strong{Exercise 9.}  The @dfn{digamma} function
6470  @cite{psi(z)}  @texline @tmath{\psi(z) (``psi'')}
6471  is defined as the derivative of @c{$\ln \Gamma(z)$}  @infoline @expr{psi(z)}
6472  @cite{ln(gamma(z))}.  For large  is defined as the derivative of
6473  values of @cite{z}, it can be approximated by the infinite sum  @texline @tmath{\ln \Gamma(z)}.
6474    @infoline @expr{ln(gamma(z))}.  
6475    For large values of @expr{z}, it can be approximated by the infinite sum
6476    
6477  @ifinfo  @ifinfo
6478  @example  @example
# Line 6398  psi(z) ~= ln(z) - 1/2z - sum(bern(2 n) / Line 6480  psi(z) ~= ln(z) - 1/2z - sum(bern(2 n) /
6480  @end example  @end example
6481  @end ifinfo  @end ifinfo
6482  @tex  @tex
 \let\rm\goodrm  
6483  \beforedisplay  \beforedisplay
6484  $$ \psi(z) \approx \ln z - {1\over2z} -  $$ \psi(z) \approx \ln z - {1\over2z} -
6485     \sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}}     \sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}}
# Line 6407  $$ Line 6488  $$
6488  @end tex  @end tex
6489    
6490  @noindent  @noindent
6491  where @c{$\sum$}  where
6492  @cite{sum} represents the sum over @cite{n} from 1 to infinity  @texline @tmath{\sum}
6493    @infoline @expr{sum}
6494    represents the sum over @expr{n} from 1 to infinity
6495  (or to some limit high enough to give the desired accuracy), and  (or to some limit high enough to give the desired accuracy), and
6496  the @code{bern} function produces (exact) Bernoulli numbers.  the @code{bern} function produces (exact) Bernoulli numbers.
6497  While this sum is not guaranteed to converge, in practice it is safe.  While this sum is not guaranteed to converge, in practice it is safe.
6498  An interesting mathematical constant is Euler's gamma, which is equal  An interesting mathematical constant is Euler's gamma, which is equal
6499  to about 0.5772.  One way to compute it is by the formula,  to about 0.5772.  One way to compute it is by the formula,
6500  @c{$\gamma = -\psi(1)$}  @texline @tmath{\gamma = -\psi(1)}.
6501  @cite{gamma = -psi(1)}.  Unfortunately, 1 isn't a large enough argument  @infoline @expr{gamma = -psi(1)}.  
6502  for the above formula to work (5 is a much safer value for @cite{z}).  Unfortunately, 1 isn't a large enough argument
6503  Fortunately, we can compute @c{$\psi(1)$}  for the above formula to work (5 is a much safer value for @expr{z}).
6504  @cite{psi(1)} from @c{$\psi(5)$}  Fortunately, we can compute
6505  @cite{psi(5)} using  @texline @tmath{\psi(1)}
6506  the recurrence @c{$\psi(z+1) = \psi(z) + {1 \over z}$}  @infoline @expr{psi(1)}
6507  @cite{psi(z+1) = psi(z) + 1/z}.  Your task:  Develop  from
6508  a program to compute @c{$\psi(z)$}  @texline @tmath{\psi(5)}
6509  @cite{psi(z)}; it should ``pump up'' @cite{z}  @infoline @expr{psi(5)}
6510    using the recurrence
6511    @texline @tmath{\psi(z+1) = \psi(z) + {1 \over z}}.
6512    @infoline @expr{psi(z+1) = psi(z) + 1/z}.  
6513    Your task:  Develop a program to compute
6514    @texline @tmath{\psi(z)};
6515    @infoline @expr{psi(z)};
6516    it should ``pump up'' @expr{z}
6517  if necessary to be greater than 5, then use the above summation  if necessary to be greater than 5, then use the above summation
6518  formula.  Use looping commands to compute the sum.  Use your function  formula.  Use looping commands to compute the sum.  Use your function
6519  to compute @c{$\gamma$}  to compute
6520  @cite{gamma} to twelve decimal places.  (Calc has a built-in command  @texline @tmath{\gamma}
6521    @infoline @expr{gamma}
6522    to twelve decimal places.  (Calc has a built-in command
6523  for Euler's constant, @kbd{I P}, which you can use to check your answer.)  for Euler's constant, @kbd{I P}, which you can use to check your answer.)
6524  @xref{Programming Answer 9, 9}. (@bullet{})  @xref{Programming Answer 9, 9}. (@bullet{})
6525    
6526  @cindex Polynomial, list of coefficients  @cindex Polynomial, list of coefficients
6527  (@bullet{}) @strong{Exercise 10.}  Given a polynomial in @cite{x} and  (@bullet{}) @strong{Exercise 10.}  Given a polynomial in @expr{x} and
6528  a number @cite{m} on the stack, where the polynomial is of degree  a number @expr{m} on the stack, where the polynomial is of degree
6529  @cite{m} or less (i.e., does not have any terms higher than @cite{x^m}),  @expr{m} or less (i.e., does not have any terms higher than @expr{x^m}),
6530  write a program to convert the polynomial into a list-of-coefficients  write a program to convert the polynomial into a list-of-coefficients
6531  notation.  For example, @cite{5 x^4 + (x + 1)^2} with @cite{m = 6}  notation.  For example, @expr{5 x^4 + (x + 1)^2} with @expr{m = 6}
6532  should produce the list @cite{[1, 2, 1, 0, 5, 0, 0]}.  Also develop  should produce the list @expr{[1, 2, 1, 0, 5, 0, 0]}.  Also develop
6533  a way to convert from this form back to the standard algebraic form.  a way to convert from this form back to the standard algebraic form.
6534  @xref{Programming Answer 10, 10}. (@bullet{})  @xref{Programming Answer 10, 10}. (@bullet{})
6535    
# Line 6478  to the same key with @kbd{Z K s}.  Now t Line 6570  to the same key with @kbd{Z K s}.  Now t
6570  the complete recursive program.  (Another way is to use @w{@kbd{Z E}}  the complete recursive program.  (Another way is to use @w{@kbd{Z E}}
6571  or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once,  or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once,
6572  thus avoiding the ``training'' phase.)  The task:  Write a program  thus avoiding the ``training'' phase.)  The task:  Write a program
6573  that computes Stirling numbers of the first kind, given @cite{n} and  that computes Stirling numbers of the first kind, given @expr{n} and
6574  @cite{m} on the stack.  Test it with @emph{small} inputs like  @expr{m} on the stack.  Test it with @emph{small} inputs like
6575  @cite{s(4,2)}.  (There is a built-in command for Stirling numbers,  @expr{s(4,2)}.  (There is a built-in command for Stirling numbers,
6576  @kbd{k s}, which you can use to check your answers.)  @kbd{k s}, which you can use to check your answers.)
6577  @xref{Programming Answer 11, 11}. (@bullet{})  @xref{Programming Answer 11, 11}. (@bullet{})
6578    
# Line 6492  program can: Line 6584  program can:
6584    
6585  (@bullet{}) @strong{Exercise 12.}  Write another program for  (@bullet{}) @strong{Exercise 12.}  Write another program for
6586  computing Stirling numbers of the first kind, this time using  computing Stirling numbers of the first kind, this time using
6587  rewrite rules.  Once again, @cite{n} and @cite{m} should be taken  rewrite rules.  Once again, @expr{n} and @expr{m} should be taken
6588  from the stack.  @xref{Programming Answer 12, 12}. (@bullet{})  from the stack.  @xref{Programming Answer 12, 12}. (@bullet{})
6589    
6590  @example  @example
# Line 6601  This section includes answers to all the Line 6693  This section includes answers to all the
6693  @noindent  @noindent
6694  @kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -}  @kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -}
6695    
6696  The result is @c{$1 - (2 \times (3 + 4)) = -13$}  The result is
6697  @cite{1 - (2 * (3 + 4)) = -13}.  @texline @tmath{1 - (2 \times (3 + 4)) = -13}.
6698    @infoline @expr{1 - (2 * (3 + 4)) = -13}.
6699    
6700  @node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises  @node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises
6701  @subsection RPN Tutorial Exercise 2  @subsection RPN Tutorial Exercise 2
6702    
6703  @noindent  @noindent
6704  @c{$2\times4 + 7\times9.5 + {5\over4} = 75.75$}  @texline @tmath{2\times4 + 7\times9.5 + {5\over4} = 75.75}
6705  @cite{2*4 + 7*9.5 + 5/4 = 75.75}  @infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75}
6706    
6707  After computing the intermediate term @c{$2\times4 = 8$}  After computing the intermediate term
6708  @cite{2*4 = 8}, you can leave  @texline @tmath{2\times4 = 8},
6709  that result on the stack while you compute the second term.  With  @infoline @expr{2*4 = 8},
6710  both of these results waiting on the stack you can then compute the  you can leave that result on the stack while you compute the second
6711  final term, then press @kbd{+ +} to add everything up.  term.  With both of these results waiting on the stack you can then
6712    compute the final term, then press @kbd{+ +} to add everything up.
6713    
6714  @smallexample  @smallexample
6715  @group  @group
# Line 6739  If the @kbd{Q} key is broken, you could Line 6833  If the @kbd{Q} key is broken, you could
6833  Or, RPN style, @kbd{0.5 ^}.  Or, RPN style, @kbd{0.5 ^}.
6834    
6835  (Actually, @samp{$^1:2}, using the fraction one-half as the power, is  (Actually, @samp{$^1:2}, using the fraction one-half as the power, is
6836  a closer equivalent, since @samp{9^0.5} yields @cite{3.0} whereas  a closer equivalent, since @samp{9^0.5} yields @expr{3.0} whereas
6837  @samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @cite{3}.)  @samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @expr{3}.)
6838    
6839  @node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to Exercises  @node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to Exercises
6840  @subsection Algebraic Entry Tutorial Exercise 2  @subsection Algebraic Entry Tutorial Exercise 2
# Line 6755  explicit @samp{*} symbol here:  @samp{2 Line 6849  explicit @samp{*} symbol here:  @samp{2
6849  @subsection Algebraic Entry Tutorial Exercise 3  @subsection Algebraic Entry Tutorial Exercise 3
6850    
6851  @noindent  @noindent
6852  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}.
6853  The ``function'' @samp{/} cannot be evaluated when its second argument  The ``function'' @samp{/} cannot be evaluated when its second argument
6854  is zero, so it is left in symbolic form.  When you now type @kbd{0 *},  is zero, so it is left in symbolic form.  When you now type @kbd{0 *},
6855  the result will be zero because Calc uses the general rule that ``zero  the result will be zero because Calc uses the general rule that ``zero
6856  times anything is zero.''  times anything is zero.''
6857    
6858  @c [fix-ref Infinities]  @c [fix-ref Infinities]
6859  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}
6860  results in a special symbol that represents ``infinity.''  If you  results in a special symbol that represents ``infinity.''  If you
6861  multiply infinity by zero, Calc uses another special new symbol to  multiply infinity by zero, Calc uses another special new symbol to
6862  show that the answer is ``indeterminate.''  @xref{Infinities}, for  show that the answer is ``indeterminate.''  @xref{Infinities}, for
# Line 6852  copied that number into a file and later Line 6946  copied that number into a file and later
6946  @subsection Modes Tutorial Exercise 3  @subsection Modes Tutorial Exercise 3
6947    
6948  @noindent  @noindent
6949  The answer he got was @cite{0.5000000000006399}.  The answer he got was @expr{0.5000000000006399}.
6950    
6951  The problem is not that the square operation is inexact, but that the  The problem is not that the square operation is inexact, but that the
6952  sine of 45 that was already on the stack was accurate to only 12 places.  sine of 45 that was already on the stack was accurate to only 12 places.
# Line 6917  There is no fractional form for the squa Line 7011  There is no fractional form for the squa
7011  @noindent  @noindent
7012  Dividing two integers that are larger than the current precision may  Dividing two integers that are larger than the current precision may
7013  give a floating-point result that is inaccurate even when rounded  give a floating-point result that is inaccurate even when rounded
7014  down to an integer.  Consider @cite{123456789 / 2} when the current  down to an integer.  Consider @expr{123456789 / 2} when the current
7015  precision is 6 digits.  The true answer is @cite{61728394.5}, but  precision is 6 digits.  The true answer is @expr{61728394.5}, but
7016  with a precision of 6 this will be rounded to @c{$12345700.0/2.0 = 61728500.0$}  with a precision of 6 this will be rounded to
7017  @cite{12345700.@: / 2.@: = 61728500.}.  @texline @tmath{12345700.0/2.0 = 61728500.0}.
7018    @infoline @expr{12345700.@: / 2.@: = 61728500.}.
7019  The result, when converted to an integer, will be off by 106.  The result, when converted to an integer, will be off by 106.
7020    
7021  Here are two solutions:  Raise the precision enough that the  Here are two solutions:  Raise the precision enough that the
7022  floating-point round-off error is strictly to the right of the  floating-point round-off error is strictly to the right of the
7023  decimal point.  Or, convert to fraction mode so that @cite{123456789 / 2}  decimal point.  Or, convert to fraction mode so that @expr{123456789 / 2}
7024  produces the exact fraction @cite{123456789:2}, which can be rounded  produces the exact fraction @expr{123456789:2}, which can be rounded
7025  down by the @kbd{F} command without ever switching to floating-point  down by the @kbd{F} command without ever switching to floating-point
7026  format.  format.
7027    
# Line 6934  format. Line 7029  format.
7029  @subsection Arithmetic Tutorial Exercise 2  @subsection Arithmetic Tutorial Exercise 2
7030    
7031  @noindent  @noindent
7032  @kbd{27 @key{RET} 9 B} could give the exact result @cite{3:2}, but it  @kbd{27 @key{RET} 9 B} could give the exact result @expr{3:2}, but it
7033  does a floating-point calculation instead and produces @cite{1.5}.  does a floating-point calculation instead and produces @expr{1.5}.
7034    
7035  Calc will find an exact result for a logarithm if the result is an integer  Calc will find an exact result for a logarithm if the result is an integer
7036  or the reciprocal of an integer.  But there is no efficient way to search  or the reciprocal of an integer.  But there is no efficient way to search
# Line 7029  Type @kbd{d N} to return to ``normal'' d Line 7124  Type @kbd{d N} to return to ``normal'' d
7124  @subsection Matrix Tutorial Exercise 3  @subsection Matrix Tutorial Exercise 3
7125    
7126  @noindent  @noindent
7127  To solve @c{$A^T A \, X = A^T B$}  To solve
7128  @cite{trn(A) * A * X = trn(A) * B}, first we compute  @texline @tmath{A^T A \, X = A^T B},
7129  @c{$A' = A^T A$}  @infoline @expr{trn(A) * A * X = trn(A) * B},
7130  @cite{A2 = trn(A) * A} and @c{$B' = A^T B$}  first we compute
7131  @cite{B2 = trn(A) * B}; now, we have a  @texline @tmath{A' = A^T A}
7132  system @c{$A' X = B'$}  @infoline @expr{A2 = trn(A) * A}
7133  @cite{A2 * X = B2} which we can solve using Calc's @samp{/}  and
7134  command.  @texline @tmath{B' = A^T B};
7135    @infoline @expr{B2 = trn(A) * B};
7136    now, we have a system
7137    @texline @tmath{A' X = B'}
7138    @infoline @expr{A2 * X = B2}
7139    which we can solve using Calc's @samp{/} command.
7140    
7141  @ifinfo  @ifinfo
7142  @example  @example
# Line 7066  $$ Line 7166  $$
7166    
7167  The first step is to enter the coefficient matrix.  We'll store it in  The first step is to enter the coefficient matrix.  We'll store it in
7168  quick variable number 7 for later reference.  Next, we compute the  quick variable number 7 for later reference.  Next, we compute the
7169  @c{$B'$}  @texline @tmath{B'}
7170  @cite{B2} vector.  @infoline @expr{B2}
7171    vector.
7172    
7173  @smallexample  @smallexample
7174  @group  @group
# Line 7082  quick variable number 7 for later refere Line 7183  quick variable number 7 for later refere
7183  @end smallexample  @end smallexample
7184    
7185  @noindent  @noindent
7186  Now we compute the matrix @c{$A'$}  Now we compute the matrix
7187  @cite{A2} and divide.  @texline @tmath{A'}
7188    @infoline @expr{A2}
7189    and divide.
7190    
7191  @smallexample  @smallexample
7192  @group  @group
# Line 7101  Now we compute the matrix @c{$A'$} Line 7204  Now we compute the matrix @c{$A'$}
7204  (The actual computed answer will be slightly inexact due to  (The actual computed answer will be slightly inexact due to
7205  round-off error.)  round-off error.)
7206    
7207  Notice that the answers are similar to those for the @c{$3\times3$}  Notice that the answers are similar to those for the
7208  @asis{3x3} system  @texline @tmath{3\times3}
7209  solved in the text.  That's because the fourth equation that was  @infoline 3x3
7210    system solved in the text.  That's because the fourth equation that was
7211  added to the system is almost identical to the first one multiplied  added to the system is almost identical to the first one multiplied
7212  by two.  (If it were identical, we would have gotten the exact same  by two.  (If it were identical, we would have gotten the exact same
7213  answer since the @c{$4\times3$}  answer since the
7214  @asis{4x3} system would be equivalent to the original @c{$3\times3$}  @texline @tmath{4\times3}
7215  @asis{3x3}  @infoline 4x3
7216    system would be equivalent to the original
7217    @texline @tmath{3\times3}
7218    @infoline 3x3
7219  system.)  system.)
7220    
7221  Since the first and fourth equations aren't quite equivalent, they  Since the first and fourth equations aren't quite equivalent, they
# Line 7129  the original system of equations to see Line 7236  the original system of equations to see
7236  @end smallexample  @end smallexample
7237    
7238  @noindent  @noindent
7239  This is reasonably close to our original @cite{B} vector,  This is reasonably close to our original @expr{B} vector,
7240  @cite{[6, 2, 3, 11]}.  @expr{[6, 2, 3, 11]}.
7241    
7242  @node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises  @node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises
7243  @subsection List Tutorial Exercise 1  @subsection List Tutorial Exercise 1
# Line 7168  vector. Line 7275  vector.
7275  @subsection List Tutorial Exercise 2  @subsection List Tutorial Exercise 2
7276    
7277  @noindent  @noindent
7278  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,
7279  the first job is to form the matrix that describes the problem.  the first job is to form the matrix that describes the problem.
7280    
7281  @ifinfo  @ifinfo
# Line 7183  $$ m \times x + b \times 1 = y $$ Line 7290  $$ m \times x + b \times 1 = y $$
7290  \afterdisplay  \afterdisplay
7291  @end tex  @end tex
7292    
7293  Thus we want a @c{$19\times2$}  Thus we want a
7294  @asis{19x2} matrix with our @cite{x} vector as one column and  @texline @tmath{19\times2}
7295    @infoline 19x2
7296    matrix with our @expr{x} vector as one column and
7297  ones as the other column.  So, first we build the column of ones, then  ones as the other column.  So, first we build the column of ones, then
7298  we combine the two columns to form our @cite{A} matrix.  we combine the two columns to form our @expr{A} matrix.
7299    
7300  @smallexample  @smallexample
7301  @group  @group
# Line 7200  we combine the two columns to form our @ Line 7309  we combine the two columns to form our @
7309  @end smallexample  @end smallexample
7310    
7311  @noindent  @noindent
7312  Now we compute @c{$A^T y$}  Now we compute
7313  @cite{trn(A) * y} and @c{$A^T A$}  @texline @tmath{A^T y}
7314  @cite{trn(A) * A} and divide.  @infoline @expr{trn(A) * y}
7315    and
7316    @texline @tmath{A^T A}
7317    @infoline @expr{trn(A) * A}
7318    and divide.
7319    
7320  @smallexample  @smallexample
7321  @group  @group
# Line 7227  Now we compute @c{$A^T y$} Line 7340  Now we compute @c{$A^T y$}
7340  @end group  @end group
7341  @end smallexample  @end smallexample
7342    
7343  Since we were solving equations of the form @c{$m \times x + b \times 1 = y$}  Since we were solving equations of the form
7344  @cite{m*x + b*1 = y}, these  @texline @tmath{m \times x + b \times 1 = y},
7345  numbers should be @cite{m} and @cite{b}, respectively.  Sure enough, they  @infoline @expr{m*x + b*1 = y},
7346  agree exactly with the result computed using @kbd{V M} and @kbd{V R}!  these numbers should be @expr{m} and @expr{b}, respectively.  Sure
7347    enough, they agree exactly with the result computed using @kbd{V M} and
7348    @kbd{V R}!
7349    
7350  The moral of this story:  @kbd{V M} and @kbd{V R} will probably solve  The moral of this story:  @kbd{V M} and @kbd{V R} will probably solve
7351  your problem, but there is often an easier way using the higher-level  your problem, but there is often an easier way using the higher-level
# Line 7288  then raise the number to that power.) Line 7403  then raise the number to that power.)
7403  @subsection List Tutorial Exercise 4  @subsection List Tutorial Exercise 4
7404    
7405  @noindent  @noindent
7406  A number @cite{j} is a divisor of @cite{n} if @c{$n \mathbin{\hbox{\code{\%}}} j = 0$}  A number @expr{j} is a divisor of @expr{n} if
7407  @samp{n % j = 0}.  The first  @texline @tmath{n \mathbin{\hbox{\code{\%}}} j = 0}.
7408  step is to get a vector that identifies the divisors.  @infoline @samp{n % j = 0}.  
7409    The first step is to get a vector that identifies the divisors.
7410    
7411  @smallexample  @smallexample
7412  @group  @group
# Line 7358  so that the mapping operation works; no Line 7474  so that the mapping operation works; no
7474  zero, so adding zeros on the left and right is safe.  From then on  zero, so adding zeros on the left and right is safe.  From then on
7475  the job is pretty straightforward.  the job is pretty straightforward.
7476    
7477  Incidentally, Calc provides the @c{\dfn{M\"obius} $\mu$}  Incidentally, Calc provides the
7478  @dfn{Moebius mu} function which is  @texline @dfn{M@"obius} @tmath{\mu}
7479  zero if and only if its argument is square-free.  It would be a much  @infoline @dfn{Moebius mu}
7480  more convenient way to do the above test in practice.  function which is zero if and only if its argument is square-free.  It
7481    would be a much more convenient way to do the above test in practice.
7482    
7483  @node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises  @node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises
7484  @subsection List Tutorial Exercise 6  @subsection List Tutorial Exercise 6
# Line 7389  exercise and type @kbd{1 -} to subtract Line 7506  exercise and type @kbd{1 -} to subtract
7506  @end smallexample  @end smallexample
7507    
7508  The numbers down the lefthand edge of the list we desire are called  The numbers down the lefthand edge of the list we desire are called
7509  the ``triangular numbers'' (now you know why!).  The @cite{n}th  the ``triangular numbers'' (now you know why!).  The @expr{n}th
7510  triangular number is the sum of the integers from 1 to @cite{n}, and  triangular number is the sum of the integers from 1 to @expr{n}, and
7511  can be computed directly by the formula @c{$n (n+1) \over 2$}  can be computed directly by the formula
7512  @cite{n * (n+1) / 2}.  @texline @tmath{n (n+1) \over 2}.
7513    @infoline @expr{n * (n+1) / 2}.
7514    
7515  @smallexample  @smallexample
7516  @group  @group
# Line 7446  since each element of the main vector is Line 7564  since each element of the main vector is
7564  @subsection List Tutorial Exercise 8  @subsection List Tutorial Exercise 8
7565    
7566  @noindent  @noindent
7567  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}.
7568    
7569  @smallexample  @smallexample
7570  @group  @group
# Line 7486  A way to isolate the maximum value is to Line 7604  A way to isolate the maximum value is to
7604    
7605  @noindent  @noindent
7606  It's a good idea to verify, as in the last step above, that only  It's a good idea to verify, as in the last step above, that only
7607  one value is equal to the maximum.  (After all, a plot of @c{$\sin x$}  one value is equal to the maximum.  (After all, a plot of
7608  @cite{sin(x)}  @texline @tmath{\sin x}
7609    @infoline @expr{sin(x)}
7610  might have many points all equal to the maximum value, 1.)  might have many points all equal to the maximum value, 1.)
7611    
7612  The vector we have now has a single 1 in the position that indicates  The vector we have now has a single 1 in the position that indicates
7613  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
7614  this back into the corresponding value itself.  this back into the corresponding value itself.
7615    
7616  @smallexample  @smallexample
# Line 7504  this back into the corresponding value i Line 7623  this back into the corresponding value i
7623  @end group  @end group
7624  @end smallexample  @end smallexample
7625    
7626  If @kbd{a =} had produced more than one @cite{1} value, this method  If @kbd{a =} had produced more than one @expr{1} value, this method
7627  would have given the sum of all maximum @cite{x} values; not very  would have given the sum of all maximum @expr{x} values; not very
7628  useful!  In this case we could have used @kbd{v m} (@code{calc-mask-vector})  useful!  In this case we could have used @kbd{v m} (@code{calc-mask-vector})
7629  instead.  This command deletes all elements of a ``data'' vector that  instead.  This command deletes all elements of a ``data'' vector that
7630  correspond to zeros in a ``mask'' vector, leaving us with, in this  correspond to zeros in a ``mask'' vector, leaving us with, in this
7631  example, a vector of maximum @cite{x} values.  example, a vector of maximum @expr{x} values.
7632    
7633  The built-in @kbd{a X} command maximizes a function using more  The built-in @kbd{a X} command maximizes a function using more
7634  efficient methods.  Just for illustration, let's use @kbd{a X}  efficient methods.  Just for illustration, let's use @kbd{a X}
# Line 7526  to maximize @samp{besJ(1,x)} over this s Line 7645  to maximize @samp{besJ(1,x)} over this s
7645  @end smallexample  @end smallexample
7646    
7647  @noindent  @noindent
7648  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}
7649  that maximizes the function, and the function's value at that maximum.  that maximizes the function, and the function's value at that maximum.
7650  As you can see, our simple search got quite close to the right answer.  As you can see, our simple search got quite close to the right answer.
7651    
# Line 7656  Another way to do this final step would Line 7775  Another way to do this final step would
7775  @subsection List Tutorial Exercise 10  @subsection List Tutorial Exercise 10
7776    
7777  @noindent  @noindent
7778  For the list @cite{[a, b, c, d]}, the result is @cite{((a = b) = c) = d},  For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d},
7779  which will compare @cite{a} and @cite{b} to produce a 1 or 0, which is  which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is
7780  then compared with @cite{c} to produce another 1 or 0, which is then  then compared with @expr{c} to produce another 1 or 0, which is then
7781  compared with @cite{d}.  This is not at all what Joe wanted.  compared with @expr{d}.  This is not at all what Joe wanted.
7782    
7783  Here's a more correct method:  Here's a more correct method:
7784    
# Line 7687  Here's a more correct method: Line 7806  Here's a more correct method:
7806  @subsection List Tutorial Exercise 11  @subsection List Tutorial Exercise 11
7807    
7808  @noindent  @noindent
7809  The circle of unit radius consists of those points @cite{(x,y)} for which  The circle of unit radius consists of those points @expr{(x,y)} for which
7810  @cite{x^2 + y^2 < 1}.  We start by generating a vector of @cite{x^2}  @expr{x^2 + y^2 < 1}.  We start by generating a vector of @expr{x^2}
7811  and a vector of @cite{y^2}.  and a vector of @expr{y^2}.
7812    
7813  We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}  We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
7814  commands.  commands.
# Line 7715  commands. Line 7834  commands.
7834  @end group  @end group
7835  @end smallexample  @end smallexample
7836    
7837  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
7838  get a vector of 1/0 truth values, then sum the truth values.  get a vector of 1/0 truth values, then sum the truth values.
7839    
7840  @smallexample  @smallexample
# Line 7728  get a vector of 1/0 truth values, then s Line 7847  get a vector of 1/0 truth values, then s
7847  @end smallexample  @end smallexample
7848    
7849  @noindent  @noindent
7850  The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$}  The ratio @expr{84/100} should approximate the ratio @cpiover{4}.
 @cite{pi/4}.  
7851    
7852  @smallexample  @smallexample
7853  @group  @group
# Line 7757  return to full-sized display of vectors. Line 7875  return to full-sized display of vectors.
7875  @noindent  @noindent
7876  This problem can be made a lot easier by taking advantage of some  This problem can be made a lot easier by taking advantage of some
7877  symmetries.  First of all, after some thought it's clear that the  symmetries.  First of all, after some thought it's clear that the
7878  @cite{y} axis can be ignored altogether.  Just pick a random @cite{x}  @expr{y} axis can be ignored altogether.  Just pick a random @expr{x}
7879  component for one end of the match, pick a random direction @c{$\theta$}  component for one end of the match, pick a random direction
7880  @cite{theta},  @texline @tmath{\theta},
7881  and see if @cite{x} and @c{$x + \cos \theta$}  @infoline @expr{theta},
7882  @cite{x + cos(theta)} (which is the @cite{x}  and see if @expr{x} and
7883  coordinate of the other endpoint) cross a line.  The lines are at  @texline @tmath{x + \cos \theta}
7884  integer coordinates, so this happens when the two numbers surround  @infoline @expr{x + cos(theta)}
7885  an integer.  (which is the @expr{x} coordinate of the other endpoint) cross a line.
7886    The lines are at integer coordinates, so this happens when the two
7887    numbers surround an integer.
7888    
7889  Since the two endpoints are equivalent, we may as well choose the leftmost  Since the two endpoints are equivalent, we may as well choose the leftmost
7890  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
7891  to the right, in the range -90 to 90 degrees.  (We could use radians, but  to the right, in the range -90 to 90 degrees.  (We could use radians, but
7892  it would feel like cheating to refer to @c{$\pi/2$}  it would feel like cheating to refer to @cpiover{2} radians while trying
7893  @cite{pi/2} radians while trying  to estimate @cpi{}!)
 to estimate @c{$\pi$}  
 @cite{pi}!)  
7894    
7895  In fact, since the field of lines is infinite we can choose the  In fact, since the field of lines is infinite we can choose the
7896  coordinates 0 and 1 for the lines on either side of the leftmost  coordinates 0 and 1 for the lines on either side of the leftmost
7897  endpoint.  The rightmost endpoint will be between 0 and 1 if the  endpoint.  The rightmost endpoint will be between 0 and 1 if the
7898  match does not cross a line, or between 1 and 2 if it does.  So:  match does not cross a line, or between 1 and 2 if it does.  So:
7899  Pick random @cite{x} and @c{$\theta$}  Pick random @expr{x} and
7900  @cite{theta}, compute @c{$x + \cos \theta$}  @texline @tmath{\theta},
7901  @cite{x + cos(theta)},  @infoline @expr{theta},
7902    compute
7903    @texline @tmath{x + \cos \theta},
7904    @infoline @expr{x + cos(theta)},
7905  and count how many of the results are greater than one.  Simple!  and count how many of the results are greater than one.  Simple!
7906    
7907  We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}  We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
# Line 7881  we omitted the closing @kbd{"}.  (The sa Line 8002  we omitted the closing @kbd{"}.  (The sa
8002  like @kbd{)} and @kbd{]} at the end of a formula.  like @kbd{)} and @kbd{]} at the end of a formula.
8003    
8004  We'll show two different approaches here.  In the first, we note that  We'll show two different approaches here.  In the first, we note that
8005  if the input vector is @cite{[a, b, c, d]}, then the hash code is  if the input vector is @expr{[a, b, c, d]}, then the hash code is
8006  @cite{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}.  In other words,  @expr{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}.  In other words,
8007  it's a sum of descending powers of three times the ASCII codes.  it's a sum of descending powers of three times the ASCII codes.
8008    
8009  @smallexample  @smallexample
# Line 7944  the operations are faster. Line 8065  the operations are faster.
8065  @end smallexample  @end smallexample
8066    
8067  Why does this work?  Think about a two-step computation:  Why does this work?  Think about a two-step computation:
8068  @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
8069  subtracting off enough 511's to put the result in the desired range.  subtracting off enough 511's to put the result in the desired range.
8070  So the result when we take the modulo after every step is,  So the result when we take the modulo after every step is,
8071    
# Line 7961  $$ 3 (3 a + b - 511 m) + c - 511 n $$ Line 8082  $$ 3 (3 a + b - 511 m) + c - 511 n $$
8082  @end tex  @end tex
8083    
8084  @noindent  @noindent
8085  for some suitable integers @cite{m} and @cite{n}.  Expanding out by  for some suitable integers @expr{m} and @expr{n}.  Expanding out by
8086  the distributive law yields  the distributive law yields
8087    
8088  @ifinfo  @ifinfo
# Line 7977  $$ 9 a + 3 b + c - 511\times3 m - 511 n Line 8098  $$ 9 a + 3 b + c - 511\times3 m - 511 n
8098  @end tex  @end tex
8099    
8100  @noindent  @noindent
8101  The @cite{m} term in the latter formula is redundant because any  The @expr{m} term in the latter formula is redundant because any
8102  contribution it makes could just as easily be made by the @cite{n}  contribution it makes could just as easily be made by the @expr{n}
8103  term.  So we can take it out to get an equivalent formula with  term.  So we can take it out to get an equivalent formula with
8104  @cite{n' = 3m + n},  @expr{n' = 3m + n},
8105    
8106  @ifinfo  @ifinfo
8107  @example  @example
# Line 8006  modulo some value @var{m}. Line 8127  modulo some value @var{m}.
8127  @subsection List Tutorial Exercise 14  @subsection List Tutorial Exercise 14
8128    
8129  We want to use @kbd{H V U} to nest a function which adds a random  We want to use @kbd{H V U} to nest a function which adds a random
8130  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
8131  otherwise the problem is quite straightforward.  otherwise the problem is quite straightforward.
8132    
8133  @smallexample  @smallexample
# Line 8024  Just as the text recommended, we used @s Line 8145  Just as the text recommended, we used @s
8145  notation to keep the two @code{random} calls from being evaluated  notation to keep the two @code{random} calls from being evaluated
8146  before nesting even begins.  before nesting even begins.
8147    
8148  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
8149  rules acts like a matrix.  We can transpose this matrix and unpack  rules acts like a matrix.  We can transpose this matrix and unpack
8150  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.
8151    
8152  @smallexample  @smallexample
8153  @group  @group
# Line 8038  to get a pair of vectors, @cite{x} and @ Line 8159  to get a pair of vectors, @cite{x} and @
8159  @end group  @end group
8160  @end smallexample  @end smallexample
8161    
8162  Incidentally, because the @cite{x} and @cite{y} are completely  Incidentally, because the @expr{x} and @expr{y} are completely
8163  independent in this case, we could have done two separate commands  independent in this case, we could have done two separate commands
8164  to create our @cite{x} and @cite{y} vectors of numbers directly.  to create our @expr{x} and @expr{y} vectors of numbers directly.
8165    
8166  To make a random walk of unit steps, we note that @code{sincos} of  To make a random walk of unit steps, we note that @code{sincos} of
8167  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
8168  length; in fact, the new nesting function is even briefer, though  length; in fact, the new nesting function is even briefer, though
8169  we might want to lower the precision a bit for it.  we might want to lower the precision a bit for it.
8170    
# Line 8071  Schwartz.) Line 8192  Schwartz.)
8192  @subsection Types Tutorial Exercise 1  @subsection Types Tutorial Exercise 1
8193    
8194  @noindent  @noindent
8195  If the number is the square root of @c{$\pi$}  If the number is the square root of @cpi{} times a rational number,
8196  @cite{pi} times a rational number,  then its square, divided by @cpi{}, should be a rational number.
 then its square, divided by @c{$\pi$}  
 @cite{pi}, should be a rational number.  
8197    
8198  @smallexample  @smallexample
8199  @group  @group
# Line 8106  precision slightly and try again: Line 8225  precision slightly and try again:
8225  @noindent  @noindent
8226  Aha!  It's unlikely that an irrational number would equal a fraction  Aha!  It's unlikely that an irrational number would equal a fraction
8227  this simple to within ten digits, so our original number was probably  this simple to within ten digits, so our original number was probably
8228  @c{$\sqrt{27 \pi / 53}$}  @texline @tmath{\sqrt{27 \pi / 53}}.
8229  @cite{sqrt(27 pi / 53)}.  @infoline @expr{sqrt(27 pi / 53)}.
8230    
8231  Notice that we didn't need to re-round the number when we reduced the  Notice that we didn't need to re-round the number when we reduced the
8232  precision.  Remember, arithmetic operations always round their inputs  precision.  Remember, arithmetic operations always round their inputs
# Line 8123  But if @w{@samp{17 inf = inf}}, then @sa Line 8242  But if @w{@samp{17 inf = inf}}, then @sa
8242  @samp{exp(inf) = inf}.  It's tempting to say that the exponential  @samp{exp(inf) = inf}.  It's tempting to say that the exponential
8243  of infinity must be ``bigger'' than ``regular'' infinity, but as  of infinity must be ``bigger'' than ``regular'' infinity, but as
8244  far as Calc is concerned all infinities are as just as big.  far as Calc is concerned all infinities are as just as big.
8245  In other words, as @cite{x} goes to infinity, @cite{e^x} also goes  In other words, as @expr{x} goes to infinity, @expr{e^x} also goes
8246  to infinity, but the fact the @cite{e^x} grows much faster than  to infinity, but the fact the @expr{e^x} grows much faster than
8247  @cite{x} is not relevant here.  @expr{x} is not relevant here.
8248    
8249  @samp{exp(-inf) = 0}.  Here we have a finite answer even though  @samp{exp(-inf) = 0}.  Here we have a finite answer even though
8250  the input is infinite.  the input is infinite.
8251    
8252  @samp{sqrt(-inf) = (0, 1) inf}.  Remember that @cite{(0, 1)}  @samp{sqrt(-inf) = (0, 1) inf}.  Remember that @expr{(0, 1)}
8253  represents the imaginary number @cite{i}.  Here's a derivation:  represents the imaginary number @expr{i}.  Here's a derivation:
8254  @samp{sqrt(-inf) = @w{sqrt((-1) * inf)} = sqrt(-1) * sqrt(inf)}.  @samp{sqrt(-inf) = @w{sqrt((-1) * inf)} = sqrt(-1) * sqrt(inf)}.
8255  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}
8256  because, once again, all infinities are the same size.  because, once again, all infinities are the same size.
8257    
8258  @samp{sqrt(uinf) = uinf}.  In fact, we do know something about the  @samp{sqrt(uinf) = uinf}.  In fact, we do know something about the
# Line 8141  direction because @code{sqrt} is defined Line 8260  direction because @code{sqrt} is defined
8260  right half of the complex plane.  But Calc has no notation for this,  right half of the complex plane.  But Calc has no notation for this,
8261  so it settles for the conservative answer @code{uinf}.  so it settles for the conservative answer @code{uinf}.
8262    
8263  @samp{abs(uinf) = inf}.  No matter which direction @cite{x} points,  @samp{abs(uinf) = inf}.  No matter which direction @expr{x} points,
8264  @samp{abs(x)} always points along the positive real axis.  @samp{abs(x)} always points along the positive real axis.
8265    
8266  @samp{ln(0) = -inf}.  Here we have an infinite answer to a finite  @samp{ln(0) = -inf}.  Here we have an infinite answer to a finite
8267  input.  As in the @cite{1 / 0} case, Calc will only use infinities  input.  As in the @expr{1 / 0} case, Calc will only use infinities
8268  here if you have turned on ``infinite'' mode.  Otherwise, it will  here if you have turned on ``infinite'' mode.  Otherwise, it will
8269  treat @samp{ln(0)} as an error.  treat @samp{ln(0)} as an error.
8270    
# Line 8154  treat @samp{ln(0)} as an error. Line 8273  treat @samp{ln(0)} as an error.
8273    
8274  @noindent  @noindent
8275  We can make @samp{inf - inf} be any real number we like, say,  We can make @samp{inf - inf} be any real number we like, say,
8276  @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
8277  infinity but not to the second.  This is just as true for complex  infinity but not to the second.  This is just as true for complex
8278  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.
8279  (And, similarly, @code{uinf} can stand for an infinity that points  (And, similarly, @code{uinf} can stand for an infinity that points
8280  in any direction in the complex plane, such as @samp{(0, 1) inf}).  in any direction in the complex plane, such as @samp{(0, 1) inf}).
8281    
# Line 8403  The same issue arises when you try to sq Line 8522  The same issue arises when you try to sq
8522  @subsection Types Tutorial Exercise 10  @subsection Types Tutorial Exercise 10
8523    
8524  @noindent  @noindent
8525  Testing the first number, we might arbitrarily choose 17 for @cite{x}.  Testing the first number, we might arbitrarily choose 17 for @expr{x}.
8526    
8527  @smallexample  @smallexample
8528  @group  @group
# Line 8435  use this method to test the second numbe Line 8554  use this method to test the second numbe
8554  @end smallexample  @end smallexample
8555    
8556  @noindent  @noindent
8557  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
8558  15485863 is prime.  (In fact, this number is the millionth prime.)  15485863 is prime.  (In fact, this number is the millionth prime.)
8559    
8560  Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $}  Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $}
# Line 8604  Thus Sam can take up to 14 pills without Line 8723  Thus Sam can take up to 14 pills without
8723    
8724  @noindent  @noindent
8725  @c [fix-ref Declarations]  @c [fix-ref Declarations]
8726  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
8727  Calculator, but @samp{sqrt(x^2)} is not.  (Consider what happens  Calculator, but @samp{sqrt(x^2)} is not.  (Consider what happens
8728  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
8729  simplified to @samp{abs(x)}, but for general complex arguments even  simplified to @samp{abs(x)}, but for general complex arguments even
8730  that is not safe.  (@xref{Declarations}, for a way to tell Calc  that is not safe.  (@xref{Declarations}, for a way to tell Calc
8731  that @cite{x} is known to be real.)  that @expr{x} is known to be real.)
8732    
8733  @node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to Exercises  @node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to Exercises
8734  @subsection Algebra Tutorial Exercise 2  @subsection Algebra Tutorial Exercise 2
8735    
8736  @noindent  @noindent
8737  Suppose our roots are @cite{[a, b, c]}.  We want a polynomial which  Suppose our roots are @expr{[a, b, c]}.  We want a polynomial which
8738  is zero when @cite{x} is any of these values.  The trivial polynomial  is zero when @expr{x} is any of these values.  The trivial polynomial
8739  @cite{x-a} is zero when @cite{x=a}, so the product @cite{(x-a)(x-b)(x-c)}  @expr{x-a} is zero when @expr{x=a}, so the product @expr{(x-a)(x-b)(x-c)}
8740  will do the job.  We can use @kbd{a c x} to write this in a more  will do the job.  We can use @kbd{a c x} to write this in a more
8741  familiar form.  familiar form.
8742    
# Line 8808  We'll use Big mode to make the formulas Line 8927  We'll use Big mode to make the formulas
8927  @end smallexample  @end smallexample
8928    
8929  @noindent  @noindent
8930  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}.
8931    
8932  @smallexample  @smallexample
8933  @group  @group
# Line 8858  The first rule turns a one-argument @cod Line 8977  The first rule turns a one-argument @cod
8977  into a three-argument @code{fib} that makes computation easier.  The  into a three-argument @code{fib} that makes computation easier.  The
8978  second rule converts back from three-argument form once the computation  second rule converts back from three-argument form once the computation
8979  is done.  The third rule does the computation itself.  It basically  is done.  The third rule does the computation itself.  It basically
8980  says that if @cite{x} and @cite{y} are two consecutive Fibonacci numbers,  says that if @expr{x} and @expr{y} are two consecutive Fibonacci numbers,
8981  then @cite{y} and @cite{x+y} are the next (overlapping) pair of Fibonacci  then @expr{y} and @expr{x+y} are the next (overlapping) pair of Fibonacci
8982  numbers.  numbers.
8983    
8984  Notice that because the number @cite{n} was ``validated'' by the  Notice that because the number @expr{n} was ``validated'' by the
8985  conditions on the first rule, there is no need to put conditions on  conditions on the first rule, there is no need to put conditions on
8986  the other rules because the rule set would never get that far unless  the other rules because the rule set would never get that far unless
8987  the input were valid.  That further speeds computation, since no  the input were valid.  That further speeds computation, since no
# Line 8959  The change to return a vector is quite s Line 9078  The change to return a vector is quite s
9078  @noindent  @noindent
9079  Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.  Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
9080    
9081  Notice that the @cite{n > 1} guard is no longer necessary on the last  Notice that the @expr{n > 1} guard is no longer necessary on the last
9082  rule since the @cite{n = 1} case is now detected by another rule.  rule since the @expr{n = 1} case is now detected by another rule.
9083  But a guard has been added to the initial rule to make sure the  But a guard has been added to the initial rule to make sure the
9084  initial value is suitable before the computation begins.  initial value is suitable before the computation begins.
9085    
# Line 8978  apply and the rewrites will stop right a Line 9097  apply and the rewrites will stop right a
9097  @starindex  @starindex
9098  @end ignore  @end ignore
9099  @tindex nterms  @tindex nterms
9100  If @cite{x} is the sum @cite{a + b}, then `@t{nterms(}@var{x}@t{)}' must  If @expr{x} is the sum @expr{a + b}, then `@t{nterms(}@var{x}@t{)}' must
9101  be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'.  If @cite{x}  be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'.  If @expr{x}
9102  is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1.  is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1.
9103    
9104  @smallexample  @smallexample
# Line 9026  But then: Line 9145  But then:
9145  Perhaps more surprisingly, this rule still works with infinite mode  Perhaps more surprisingly, this rule still works with infinite mode
9146  turned on.  Calc tries @code{EvalRules} before any built-in rules for  turned on.  Calc tries @code{EvalRules} before any built-in rules for
9147  a function.  This allows you to override the default behavior of any  a function.  This allows you to override the default behavior of any
9148  Calc feature:  Even though Calc now wants to evaluate @cite{0^0} to  Calc feature:  Even though Calc now wants to evaluate @expr{0^0} to
9149  @code{nan}, your rule gets there first and evaluates it to 1 instead.  @code{nan}, your rule gets there first and evaluates it to 1 instead.
9150    
9151  Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.  Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.
# Line 9085  The sixth rule is the corresponding rule Line 9204  The sixth rule is the corresponding rule
9204  Another way to solve this problem would be to create a new ``data type''  Another way to solve this problem would be to create a new ``data type''
9205  that represents truncated power series.  We might represent these as  that represents truncated power series.  We might represent these as
9206  function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is  function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is
9207  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
9208  on.  Rules would exist for sums and products of such @code{series}  on.  Rules would exist for sums and products of such @code{series}
9209  objects, and as an optional convenience could also know how to combine a  objects, and as an optional convenience could also know how to combine a
9210  @code{series} object with a normal polynomial.  (With this, and with a  @code{series} object with a normal polynomial.  (With this, and with a
# Line 9115  in Lisp.) Line 9234  in Lisp.)
9234  Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type  Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type
9235  @kbd{Z F}, and answer the questions.  Since this formula contains two  @kbd{Z F}, and answer the questions.  Since this formula contains two
9236  variables, the default argument list will be @samp{(t x)}.  We want to  variables, the default argument list will be @samp{(t x)}.  We want to
9237  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
9238  to be used within @code{ninteg}.  to be used within @code{ninteg}.
9239    
9240  The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}.  The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}.
# Line 9146  Each of these functions can be computed Line 9265  Each of these functions can be computed
9265  algebraic entry, whichever way you prefer:  algebraic entry, whichever way you prefer:
9266    
9267  @noindent  @noindent
9268  Computing @c{$\displaystyle{\sin x \over x}$}  Computing
9269  @cite{sin(x) / x}:  @texline @tmath{\displaystyle{\sin x \over x}}:
9270    @infoline @expr{sin(x) / x}:
9271    
9272  Using the stack:  @kbd{C-x (  @key{RET} S @key{TAB} /  C-x )}.  Using the stack:  @kbd{C-x (  @key{RET} S @key{TAB} /  C-x )}.
9273    
# Line 9207  Here is the matrix: Line 9327  Here is the matrix:
9327  @end example  @end example
9328    
9329  @noindent  @noindent
9330  Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @cite{n+1}  Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @expr{n+1}
9331  and @cite{n+2}.  Here's one program that does the job:  and @expr{n+2}.  Here's one program that does the job:
9332    
9333  @example  @example
9334  C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x )  C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x )
# Line 9216  C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @k Line 9336  C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @k
9336    
9337  @noindent  @noindent
9338  This program is quite efficient because Calc knows how to raise a  This program is quite efficient because Calc knows how to raise a
9339  matrix (or other value) to the power @cite{n} in only @c{$\log_2 n$}  matrix (or other value) to the power @expr{n} in only
9340  @cite{log(n,2)}  @texline @tmath{\log_2 n}
9341    @infoline @expr{log(n,2)}
9342  steps.  For example, this program can compute the 1000th Fibonacci  steps.  For example, this program can compute the 1000th Fibonacci
9343  number (a 209-digit integer!) in about 10 steps; even though the  number (a 209-digit integer!) in about 10 steps; even though the
9344  @kbd{Z < ... Z >} solution had much simpler steps, it would have  @kbd{Z < ... Z >} solution had much simpler steps, it would have
# Line 9268  harmonic number is 4.02. Line 9389  harmonic number is 4.02.
9389  @subsection Programming Tutorial Exercise 8  @subsection Programming Tutorial Exercise 8
9390    
9391  @noindent  @noindent
9392  The first step is to compute the derivative @cite{f'(x)} and thus  The first step is to compute the derivative @expr{f'(x)} and thus
9393  the formula @c{$\displaystyle{x - {f(x) \over f'(x)}}$}  the formula
9394  @cite{x - f(x)/f'(x)}.  @texline @tmath{\displaystyle{x - {f(x) \over f'(x)}}}.
9395    @infoline @expr{x - f(x)/f'(x)}.
9396    
9397  (Because this definition is long, it will be repeated in concise form  (Because this definition is long, it will be repeated in concise form
9398  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are
# Line 9317  repetitions are done.) Line 9439  repetitions are done.)
9439  @end group  @end group
9440  @end smallexample  @end smallexample
9441    
9442  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
9443  old one to see if we've converged.  old one to see if we've converged.
9444    
9445  @smallexample  @smallexample
# Line 9383  method (among others) to look for numeri Line 9505  method (among others) to look for numeri
9505  @subsection Programming Tutorial Exercise 9  @subsection Programming Tutorial Exercise 9
9506    
9507  @noindent  @noindent
9508  The first step is to adjust @cite{z} to be greater than 5.  A simple  The first step is to adjust @expr{z} to be greater than 5.  A simple
9509  ``for'' loop will do the job here.  If @cite{z} is less than 5, we  ``for'' loop will do the job here.  If @expr{z} is less than 5, we
9510  reduce the problem using @c{$\psi(z) = \psi(z+1) - 1/z$}  reduce the problem using
9511  @cite{psi(z) = psi(z+1) - 1/z}.  We go  @texline @tmath{\psi(z) = \psi(z+1) - 1/z}.
9512  on to compute @c{$\psi(z+1)$}  @infoline @expr{psi(z) = psi(z+1) - 1/z}.  We go
9513  @cite{psi(z+1)}, and remember to add back a factor of  on to compute
9514  @cite{-1/z} when we're done.  This step is repeated until @cite{z > 5}.  @texline @tmath{\psi(z+1)},
9515    @infoline @expr{psi(z+1)},
9516    and remember to add back a factor of @expr{-1/z} when we're done.  This
9517    step is repeated until @expr{z > 5}.
9518    
9519  (Because this definition is long, it will be repeated in concise form  (Because this definition is long, it will be repeated in concise form
9520  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are
# Line 9407  just for purposes of illustration.) Line 9532  just for purposes of illustration.)
9532  @end group  @end group
9533  @end smallexample  @end smallexample
9534    
9535  Here, variable 1 holds @cite{z} and variable 2 holds the adjustment  Here, variable 1 holds @expr{z} and variable 2 holds the adjustment
9536  factor.  If @cite{z < 5}, we use a loop to increase it.  factor.  If @expr{z < 5}, we use a loop to increase it.
9537    
9538  (By the way, we started with @samp{1.0} instead of the integer 1 because  (By the way, we started with @samp{1.0} instead of the integer 1 because
9539  otherwise the calculation below will try to do exact fractional arithmetic,  otherwise the calculation below will try to do exact fractional arithmetic,
# Line 9426  are exactly equal, not just equal to wit Line 9551  are exactly equal, not just equal to wit
9551  @end group  @end group
9552  @end smallexample  @end smallexample
9553    
9554  Now we compute the initial part of the sum:  @c{$\ln z - {1 \over 2z}$}  Now we compute the initial part of the sum:  
9555  @cite{ln(z) - 1/2z}  @texline @tmath{\ln z - {1 \over 2z}}
9556    @infoline @expr{ln(z) - 1/2z}
9557  minus the adjustment factor.  minus the adjustment factor.
9558    
9559  @smallexample  @smallexample
# Line 9441  minus the adjustment factor. Line 9567  minus the adjustment factor.
9567  @end smallexample  @end smallexample
9568    
9569  Now we evaluate the series.  We'll use another ``for'' loop counting  Now we evaluate the series.  We'll use another ``for'' loop counting
9570  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,
9571  @kbd{a +}, but we'll use loops just to get more practice with them.)  @kbd{a +}, but we'll use loops just to get more practice with them.)
9572    
9573  @smallexample  @smallexample
# Line 9468  up the value of @cite{2 n}.  (Calc does Line 9594  up the value of @cite{2 n}.  (Calc does
9594  @end group  @end group
9595  @end smallexample  @end smallexample
9596    
9597  This is the value of @c{$-\gamma$}  This is the value of
9598  @cite{- gamma}, with a slight bit of roundoff error.  @texline @tmath{-\gamma},
9599  To get a full 12 digits, let's use a higher precision:  @infoline @expr{- gamma},
9600    with a slight bit of roundoff error.  To get a full 12 digits, let's use
9601    a higher precision:
9602    
9603  @smallexample  @smallexample
9604  @group  @group
# Line 9500  C-x ) Line 9628  C-x )
9628  @subsection Programming Tutorial Exercise 10  @subsection Programming Tutorial Exercise 10
9629    
9630  @noindent  @noindent
9631  Taking the derivative of a term of the form @cite{x^n} will produce  Taking the derivative of a term of the form @expr{x^n} will produce
9632  a term like @c{$n x^{n-1}$}  a term like
9633  @cite{n x^(n-1)}.  Taking the derivative of a constant  @texline @tmath{n x^{n-1}}.
9634  produces zero.  From this it is easy to see that the @cite{n}th  @infoline @expr{n x^(n-1)}.  
9635  derivative of a polynomial, evaluated at @cite{x = 0}, will equal the  Taking the derivative of a constant
9636  coefficient on the @cite{x^n} term times @cite{n!}.  produces zero.  From this it is easy to see that the @expr{n}th
9637    derivative of a polynomial, evaluated at @expr{x = 0}, will equal the
9638    coefficient on the @expr{x^n} term times @expr{n!}.
9639    
9640  (Because this definition is long, it will be repeated in concise form  (Because this definition is long, it will be repeated in concise form
9641  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are  below.  You can use @w{@kbd{M-# m}} to load it from there.  While you are
# Line 9554  have written instead, @kbd{r 1 @key{TAB} Line 9684  have written instead, @kbd{r 1 @key{TAB}
9684  @end smallexample  @end smallexample
9685    
9686  To convert back, a simple method is just to map the coefficients  To convert back, a simple method is just to map the coefficients
9687  against a table of powers of @cite{x}.  against a table of powers of @expr{x}.
9688    
9689  @smallexample  @smallexample
9690  @group  @group
# Line 9614  sure the stack comes out right. Line 9744  sure the stack comes out right.
9744  The last step replaces the 2 that was eaten during the creation  The last step replaces the 2 that was eaten during the creation
9745  of the dummy @kbd{z s} command.  Now we move on to the real  of the dummy @kbd{z s} command.  Now we move on to the real
9746  definition.  The recurrence needs to be rewritten slightly,  definition.  The recurrence needs to be rewritten slightly,
9747  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)}.
9748    
9749  (Because this definition is long, it will be repeated in concise form  (Because this definition is long, it will be repeated in concise form
9750  below.  You can use @kbd{M-# m} to load it from there.)  below.  You can use @kbd{M-# m} to load it from there.)
# Line 9783  list of the results of all calculations Line 9913  list of the results of all calculations
9913  Calc Trail buffer uses a variant of Calc Mode, so Calculator commands  Calc Trail buffer uses a variant of Calc Mode, so Calculator commands
9914  still work when the trail buffer's window is selected.  It is possible  still work when the trail buffer's window is selected.  It is possible
9915  to turn the trail window off, but the @samp{*Calc Trail*} buffer itself  to turn the trail window off, but the @samp{*Calc Trail*} buffer itself
9916  still exists and is updated silently.  @xref{Trail Commands}.@refill  still exists and is updated silently.  @xref{Trail Commands}.
9917    
9918  @kindex M-# c  @kindex M-# c
9919  @kindex M-# M-#  @kindex M-# M-#
# Line 9805  for some commands this is the only form. Line 9935  for some commands this is the only form.
9935  key (@code{calc-execute-extended-command})  key (@code{calc-execute-extended-command})
9936  is like @kbd{M-x} except that it enters the initial string @samp{calc-}  is like @kbd{M-x} except that it enters the initial string @samp{calc-}
9937  for you.  For example, the following key sequences are equivalent:  for you.  For example, the following key sequences are equivalent:
9938  @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}}.
9939    
9940  @cindex Extensions module  @cindex Extensions module
9941  @cindex @file{calc-ext} module  @cindex @file{calc-ext} module
# Line 9818  of the Calculator in the common case whe Line 9948  of the Calculator in the common case whe
9948  little arithmetic.  If for some reason the Calculator fails to load an  little arithmetic.  If for some reason the Calculator fails to load an
9949  extension module automatically, you can force it to load all the  extension module automatically, you can force it to load all the
9950  extensions by using the @kbd{M-# L} (@code{calc-load-everything})  extensions by using the @kbd{M-# L} (@code{calc-load-everything})
9951  command.  @xref{Mode Settings}.@refill  command.  @xref{Mode Settings}.
9952    
9953  If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument,  If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument,
9954  the Calculator is loaded if necessary, but it is not actually started.  the Calculator is loaded if necessary, but it is not actually started.
9955  If the argument is positive, the @file{calc-ext} extensions are also  If the argument is positive, the @file{calc-ext} extensions are also
9956  loaded if necessary.  User-written Lisp code that wishes to make use  loaded if necessary.  User-written Lisp code that wishes to make use
9957  of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)}  of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)}
9958  to auto-load the Calculator.@refill  to auto-load the Calculator.
9959    
9960  @kindex M-# b  @kindex M-# b
9961  @pindex full-calc  @pindex full-calc
# Line 9872  If you type @kbd{M-x calc} again, the Ca Line 10002  If you type @kbd{M-x calc} again, the Ca
10002  contents of the stack intact.  Typing @kbd{M-# c} or @kbd{M-# M-#}  contents of the stack intact.  Typing @kbd{M-# c} or @kbd{M-# M-#}
10003  again from inside the Calculator buffer is equivalent to executing  again from inside the Calculator buffer is equivalent to executing
10004  @code{calc-quit}; you can think of @kbd{M-# M-#} as toggling the  @code{calc-quit}; you can think of @kbd{M-# M-#} as toggling the
10005  Calculator on and off.@refill  Calculator on and off.
10006    
10007  @kindex M-# x  @kindex M-# x
10008  The @kbd{M-# x} command also turns the Calculator off, no matter which  The @kbd{M-# x} command also turns the Calculator off, no matter which
# Line 9904  The @kbd{<} and @kbd{>} keys are bound t Line 10034  The @kbd{<} and @kbd{>} keys are bound t
10034  @code{calc-scroll-right}.  These are just like the normal horizontal  @code{calc-scroll-right}.  These are just like the normal horizontal
10035  scrolling commands except that they scroll one half-screen at a time by  scrolling commands except that they scroll one half-screen at a time by
10036  default.  (Calc formats its output to fit within the bounds of the  default.  (Calc formats its output to fit within the bounds of the
10037  window whenever it can.)@refill  window whenever it can.)
10038    
10039  @kindex @{  @kindex @{
10040  @kindex @}  @kindex @}
# Line 9913  window whenever it can.)@refill Line 10043  window whenever it can.)@refill
10043  @cindex Vertical scrolling  @cindex Vertical scrolling
10044  The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down}  The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down}
10045  and @code{calc-scroll-up}.  They scroll up or down by one-half the  and @code{calc-scroll-up}.  They scroll up or down by one-half the
10046  height of the Calc window.@refill  height of the Calc window.
10047    
10048  @kindex M-# 0  @kindex M-# 0
10049  @pindex calc-reset  @pindex calc-reset
# Line 10017  H a S runs calc-solve-for:  a `H a S' v Line 10147  H a S runs calc-solve-for:  a `H a S' v
10147    
10148  @noindent  @noindent
10149  which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for}  which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for}
10150  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},
10151  then applies the algebraic function @code{fsolve} to these values.  then applies the algebraic function @code{fsolve} to these values.
10152  The @samp{?=notes} message means you can now type @kbd{?} to see  The @samp{?=notes} message means you can now type @kbd{?} to see
10153  additional notes from the summary that apply to this command.  additional notes from the summary that apply to this command.
# Line 10074  The first three keystrokes ``push'' the Line 10204  The first three keystrokes ``push'' the
10204  @kbd{+} key always ``pops'' the top two numbers from the stack, adds them,  @kbd{+} key always ``pops'' the top two numbers from the stack, adds them,
10205  and pushes the result (3) back onto the stack.  This number is ready for  and pushes the result (3) back onto the stack.  This number is ready for
10206  further calculations:  @kbd{5 -} pushes 5 onto the stack, then pops the  further calculations:  @kbd{5 -} pushes 5 onto the stack, then pops the
10207  3 and 5, subtracts them, and pushes the result (@i{-2}).@refill  3 and 5, subtracts them, and pushes the result (@i{-2}).
10208    
10209  Note that the ``top'' of the stack actually appears at the @emph{bottom}  Note that the ``top'' of the stack actually appears at the @emph{bottom}
10210  of the buffer.  A line containing a single @samp{.} character signifies  of the buffer.  A line containing a single @samp{.} character signifies
# Line 10103  two consecutive numbers. Line 10233  two consecutive numbers.
10233  (After all, if you typed @kbd{1 2} by themselves the Calculator  (After all, if you typed @kbd{1 2} by themselves the Calculator
10234  would enter the number 12.)  If you press @key{RET} or @key{SPC} @emph{not}  would enter the number 12.)  If you press @key{RET} or @key{SPC} @emph{not}
10235  right after typing a number, the key duplicates the number on the top of  right after typing a number, the key duplicates the number on the top of
10236  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.
10237    
10238  The @key{DEL} key pops and throws away the top number on the stack.  The @key{DEL} key pops and throws away the top number on the stack.
10239  The @key{TAB} key swaps the top two objects on the stack.  The @key{TAB} key swaps the top two objects on the stack.
10240  @xref{Stack and Trail}, for descriptions of these and other stack-related  @xref{Stack and Trail}, for descriptions of these and other stack-related
10241  commands.@refill  commands.
10242    
10243  @node Numeric Entry, Algebraic Entry, Stack Basics, Introduction  @node Numeric Entry, Algebraic Entry, Stack Basics, Introduction
10244  @section Numeric Entry  @section Numeric Entry
# Line 10129  you press a numeric key which is not val Line 10259  you press a numeric key which is not val
10259  @cindex Negative numbers, entering  @cindex Negative numbers, entering
10260  @kindex _  @kindex _
10261  There are three different concepts corresponding to the word ``minus,''  There are three different concepts corresponding to the word ``minus,''
10262  typified by @cite{a-b} (subtraction), @cite{-x}  typified by @expr{a-b} (subtraction), @expr{-x}
10263  (change-sign), and @cite{-5} (negative number).  Calc uses three  (change-sign), and @expr{-5} (negative number).  Calc uses three
10264  different keys for these operations, respectively:  different keys for these operations, respectively:
10265  @kbd{-}, @kbd{n}, and @kbd{_} (the underscore).  The @kbd{-} key subtracts  @kbd{-}, @kbd{n}, and @kbd{_} (the underscore).  The @kbd{-} key subtracts
10266  the two numbers on the top of the stack.  The @kbd{n} key changes the sign  the two numbers on the top of the stack.  The @kbd{n} key changes the sign
# Line 10138  of the number on the top of the stack or Line 10268  of the number on the top of the stack or
10268  The @kbd{_} key begins entry of a negative number or changes the sign of  The @kbd{_} key begins entry of a negative number or changes the sign of
10269  the number currently being entered.  The following sequences all enter the  the number currently being entered.  The following sequences all enter the
10270  number @i{-5} onto the stack:  @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}},  number @i{-5} onto the stack:  @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}},
10271  @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.@refill  @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.
10272    
10273  Some other keys are active during numeric entry, such as @kbd{#} for  Some other keys are active during numeric entry, such as @kbd{#} for
10274  non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms.  non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms.
# Line 10158  During numeric entry, the only editing k Line 10288  During numeric entry, the only editing k
10288  Calculations can also be entered in algebraic form.  This is accomplished  Calculations can also be entered in algebraic form.  This is accomplished
10289  by typing the apostrophe key, @kbd{'}, followed by the expression in  by typing the apostrophe key, @kbd{'}, followed by the expression in
10290  standard format:  @kbd{@key{'} 2+3*4 @key{RET}} computes  standard format:  @kbd{@key{'} 2+3*4 @key{RET}} computes
10291  @c{$2+(3\times4) = 14$}  @texline @tmath{2+(3\times4) = 14}
10292  @cite{2+(3*4) = 14} and pushes that on the stack.  If you wish you can  @infoline @expr{2+(3*4) = 14}
10293    and pushes that on the stack.  If you wish you can
10294  ignore the RPN aspect of Calc altogether and simply enter algebraic  ignore the RPN aspect of Calc altogether and simply enter algebraic
10295  expressions in this way.  You may want to use @key{DEL} every so often to  expressions in this way.  You may want to use @key{DEL} every so often to
10296  clear previous results off the stack.@refill  clear previous results off the stack.
10297    
10298  You can press the apostrophe key during normal numeric entry to switch  You can press the apostrophe key during normal numeric entry to switch
10299  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
# Line 10185  you can omit the apostrophe.  Open paren Line 10316  you can omit the apostrophe.  Open paren
10316  begin algebraic entry.  You can still do RPN calculations in this mode,  begin algebraic entry.  You can still do RPN calculations in this mode,
10317  but you will have to press @key{RET} to terminate every number:  but you will have to press @key{RET} to terminate every number:
10318  @kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same  @kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
10319  thing as @kbd{2*3+4 @key{RET}}.@refill  thing as @kbd{2*3+4 @key{RET}}.
10320    
10321  @cindex Incomplete algebraic mode  @cindex Incomplete algebraic mode
10322  If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a}  If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a}
# Line 10221  stack with that formula rather than simp Line 10352  stack with that formula rather than simp
10352  stack.  Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2  stack.  Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2
10353  @key{RET}} replaces it with 6.  Note that the @kbd{$} key always  @key{RET}} replaces it with 6.  Note that the @kbd{$} key always
10354  initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the  initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
10355  first character in the new formula.@refill  first character in the new formula.
10356    
10357  Higher stack elements can be accessed from an entered formula with the  Higher stack elements can be accessed from an entered formula with the
10358  symbols @kbd{$$}, @kbd{$$$}, and so on.  The number of stack elements  symbols @kbd{$$}, @kbd{$$$}, and so on.  The number of stack elements
# Line 10229  removed (to be replaced by the entered v Line 10360  removed (to be replaced by the entered v
10360  signs in the longest such symbol in the formula.  For example, @samp{$$+$$$}  signs in the longest such symbol in the formula.  For example, @samp{$$+$$$}
10361  adds the second and third stack elements, replacing the top three elements  adds the second and third stack elements, replacing the top three elements
10362  with the answer.  (All information about the top stack element is thus lost  with the answer.  (All information about the top stack element is thus lost
10363  since no single @samp{$} appears in this formula.)@refill  since no single @samp{$} appears in this formula.)
10364    
10365  A slightly different way to refer to stack elements is with a dollar  A slightly different way to refer to stack elements is with a dollar
10366  sign followed by a number:  @samp{$1}, @samp{$2}, and so on are much  sign followed by a number:  @samp{$1}, @samp{$2}, and so on are much
# Line 10254  If you finish your algebraic entry by pr Line 10385  If you finish your algebraic entry by pr
10385  instead of @key{RET}, Calc disables the default simplifications  instead of @key{RET}, Calc disables the default simplifications
10386  (as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry  (as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry
10387  is being pushed on the stack.  Thus @kbd{' 1+2 @key{RET}} pushes 3  is being pushed on the stack.  Thus @kbd{' 1+2 @key{RET}} pushes 3
10388  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};
10389  you might then press @kbd{=} when it is time to evaluate this formula.  you might then press @kbd{=} when it is time to evaluate this formula.
10390    
10391  @node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction  @node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction
# Line 10333  Many Calculator commands use numeric pre Line 10464  Many Calculator commands use numeric pre
10464  @kbd{d s} (@code{calc-sci-notation}), set a parameter to the value of  @kbd{d s} (@code{calc-sci-notation}), set a parameter to the value of
10465  the prefix argument or use a default if you don't use a prefix.  the prefix argument or use a default if you don't use a prefix.
10466  Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument  Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument
10467  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.
10468    
10469  As a rule, stack-manipulation commands accept a numeric prefix argument  As a rule, stack-manipulation commands accept a numeric prefix argument
10470  which is interpreted as an index into the stack.  A positive argument  which is interpreted as an index into the stack.  A positive argument
# Line 10360  argument for some other purpose. Line 10491  argument for some other purpose.
10491  Numeric prefixes are specified the same way as always in Emacs:  Press  Numeric prefixes are specified the same way as always in Emacs:  Press
10492  a sequence of @key{META}-digits, or press @key{ESC} followed by digits,  a sequence of @key{META}-digits, or press @key{ESC} followed by digits,
10493  or press @kbd{C-u} followed by digits.  Some commands treat plain  or press @kbd{C-u} followed by digits.  Some commands treat plain
10494  @kbd{C-u} (without any actual digits) specially.@refill  @kbd{C-u} (without any actual digits) specially.
10495    
10496  @kindex ~  @kindex ~
10497  @pindex calc-num-prefix  @pindex calc-num-prefix
# Line 10368  You can type @kbd{~} (@code{calc-num-pre Line 10499  You can type @kbd{~} (@code{calc-num-pre
10499  top of the stack and enter it as the numeric prefix for the next command.  top of the stack and enter it as the numeric prefix for the next command.
10500  For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate  For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate
10501  (silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2  (silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2
10502  to the fourth power and set the precision to that value.@refill  to the fourth power and set the precision to that value.
10503    
10504  Conversely, if you have typed a numeric prefix argument the @kbd{~} key  Conversely, if you have typed a numeric prefix argument the @kbd{~} key
10505  pushes it onto the stack in the form of an integer.  pushes it onto the stack in the form of an integer.
# Line 10416  any other change, then it will be too la Line 10547  any other change, then it will be too la
10547  The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that  The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that
10548  it restores the arguments of the most recent command onto the stack;  it restores the arguments of the most recent command onto the stack;
10549  however, it does not remove the result of that command.  Given a numeric  however, it does not remove the result of that command.  Given a numeric
10550  prefix argument, this command applies to the @cite{n}th most recent  prefix argument, this command applies to the @expr{n}th most recent
10551  command which removed items from the stack; it pushes those items back  command which removed items from the stack; it pushes those items back
10552  onto the stack.  onto the stack.
10553    
# Line 10438  The standard Emacs @kbd{C-_} undo key is Line 10569  The standard Emacs @kbd{C-_} undo key is
10569  @cindex Why did an error occur?  @cindex Why did an error occur?
10570  Many situations that would produce an error message in other calculators  Many situations that would produce an error message in other calculators
10571  simply create unsimplified formulas in the Emacs Calculator.  For example,  simply create unsimplified formulas in the Emacs Calculator.  For example,
10572  @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
10573  the formula @samp{ln(0)}.  Floating-point overflow and underflow are also  the formula @samp{ln(0)}.  Floating-point overflow and underflow are also
10574  reasons for this to happen.  reasons for this to happen.
10575    
# Line 10543  possible in an attempt to recover from p Line 10674  possible in an attempt to recover from p
10674  ever halts incorrectly with the message ``Computation got stuck or  ever halts incorrectly with the message ``Computation got stuck or
10675  ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth})  ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth})
10676  to increase this limit.  (Of course, this will not help if the  to increase this limit.  (Of course, this will not help if the
10677  calculation really did get stuck due to some problem inside Calc.)@refill  calculation really did get stuck due to some problem inside Calc.)
10678    
10679  The limit is always increased (multiplied) by a factor of two.  There  The limit is always increased (multiplied) by a factor of two.  There
10680  is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which  is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which
# Line 10561  internal Lisp recursion limit.  The mini Line 10692  internal Lisp recursion limit.  The mini
10692  @cindex Flushing caches  @cindex Flushing caches
10693  Calc saves certain values after they have been computed once.  For  Calc saves certain values after they have been computed once.  For
10694  example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the  example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the
10695  constant @c{$\pi$}  constant @cpi{} to about 20 decimal places; if the current precision
10696  @cite{pi} to about 20 decimal places; if the current precision  is greater than this, it will recompute @cpi{} using a series
 is greater than this, it will recompute @c{$\pi$}  
 @cite{pi} using a series  
10697  approximation.  This value will not need to be recomputed ever again  approximation.  This value will not need to be recomputed ever again
10698  unless you raise the precision still further.  Many operations such as  unless you raise the precision still further.  Many operations such as
10699  logarithms and sines make use of similarly cached values such as  logarithms and sines make use of similarly cached values such as
10700  @c{$\pi \over 4$}  @cpiover{4} and
10701  @cite{pi/4} and @c{$\ln 2$}  @texline @tmath{\ln 2}.
10702  @cite{ln(2)}.  The visible effect of caching is that  @infoline @expr{ln(2)}.  
10703    The visible effect of caching is that
10704  high-precision computations may seem to do extra work the first time.  high-precision computations may seem to do extra work the first time.
10705  Other things cached include powers of two (for the binary arithmetic  Other things cached include powers of two (for the binary arithmetic
10706  functions), matrix inverses and determinants, symbolic integrals, and  functions), matrix inverses and determinants, symbolic integrals, and
# Line 10643  will be lost. Line 10773  will be lost.
10773  This chapter discusses the various types of objects that can be placed  This chapter discusses the various types of objects that can be placed
10774  on the Calculator stack, how they are displayed, and how they are  on the Calculator stack, how they are displayed, and how they are
10775  entered.  (@xref{Data Type Formats}, for information on how these data  entered.  (@xref{Data Type Formats}, for information on how these data
10776  types are represented as underlying Lisp objects.)@refill  types are represented as underlying Lisp objects.)
10777    
10778  Integers, fractions, and floats are various ways of describing real  Integers, fractions, and floats are various ways of describing real
10779  numbers.  HMS forms also for many purposes act as real numbers.  These  numbers.  HMS forms also for many purposes act as real numbers.  These
# Line 10686  floating-point form according to the cur Line 10816  floating-point form according to the cur
10816  A decimal integer is represented as an optional sign followed by a  A decimal integer is represented as an optional sign followed by a
10817  sequence of digits.  Grouping (@pxref{Grouping Digits}) can be used to  sequence of digits.  Grouping (@pxref{Grouping Digits}) can be used to
10818  insert a comma at every third digit for display purposes, but you  insert a comma at every third digit for display purposes, but you
10819  must not type commas during the entry of numbers.@refill  must not type commas during the entry of numbers.
10820    
10821  @kindex #  @kindex #
10822  A non-decimal integer is represented as an optional sign, a radix  A non-decimal integer is represented as an optional sign, a radix
# Line 10695  and above, the letters A through Z (uppe Line 10825  and above, the letters A through Z (uppe
10825  digits and do not terminate numeric entry mode.  @xref{Radix Modes}, for how  digits and do not terminate numeric entry mode.  @xref{Radix Modes}, for how
10826  to set the default radix for display of integers.  Numbers of any radix  to set the default radix for display of integers.  Numbers of any radix
10827  may be entered at any time.  If you press @kbd{#} at the beginning of a  may be entered at any time.  If you press @kbd{#} at the beginning of a
10828  number, the current display radix is used.@refill  number, the current display radix is used.
10829    
10830  @node Fractions, Floats, Integers, Data Types  @node Fractions, Floats, Integers, Data Types
10831  @section Fractions  @section Fractions
# Line 10708  performs RPN division; the following two Line 10838  performs RPN division; the following two
10838  @samp{2:3} on the stack:  @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /}  @samp{2:3} on the stack:  @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /}
10839  assuming Fraction Mode has been enabled.)  assuming Fraction Mode has been enabled.)
10840  When the Calculator produces a fractional result it always reduces it to  When the Calculator produces a fractional result it always reduces it to
10841  simplest form, which may in fact be an integer.@refill  simplest form, which may in fact be an integer.
10842    
10843  Fractions may also be entered in a three-part form, where @samp{2:3:4}  Fractions may also be entered in a three-part form, where @samp{2:3:4}
10844  represents two-and-three-quarters.  @xref{Fraction Formats}, for fraction  represents two-and-three-quarters.  @xref{Fraction Formats}, for fraction
10845  display formats.@refill  display formats.
10846    
10847  Non-decimal fractions are entered and displayed as  Non-decimal fractions are entered and displayed as
10848  @samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part  @samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part
10849  form).  The numerator and denominator always use the same radix.@refill  form).  The numerator and denominator always use the same radix.
10850    
10851  @node Floats, Complex Numbers, Fractions, Data Types  @node Floats, Complex Numbers, Fractions, Data Types
10852  @section Floats  @section Floats
# Line 10726  form).  The numerator and denominator al Line 10856  form).  The numerator and denominator al
10856  A floating-point number or @dfn{float} is a number stored in scientific  A floating-point number or @dfn{float} is a number stored in scientific
10857  notation.  The number of significant digits in the fractional part is  notation.  The number of significant digits in the fractional part is
10858  governed by the current floating precision (@pxref{Precision}).  The  governed by the current floating precision (@pxref{Precision}).  The
10859  range of acceptable values is from @c{$10^{-3999999}$}  range of acceptable values is from
10860  @cite{10^-3999999} (inclusive)  @texline @tmath{10^{-3999999}}
10861  to @c{$10^{4000000}$}  @infoline @expr{10^-3999999}
10862  @cite{10^4000000}  (inclusive) to
10863  (exclusive), plus the corresponding negative  @texline @tmath{10^{4000000}}
10864  values and zero.  @infoline @expr{10^4000000}
10865    (exclusive), plus the corresponding negative values and zero.
10866    
10867  Calculations that would exceed the allowable range of values (such  Calculations that would exceed the allowable range of values (such
10868  as @samp{exp(exp(20))}) are left in symbolic form by Calc.  The  as @samp{exp(exp(20))}) are left in symbolic form by Calc.  The
# Line 10772  final result accurate to the full reques Line 10903  final result accurate to the full reques
10903  accuracy is not rigorously guaranteed.  If you suspect the validity of a  accuracy is not rigorously guaranteed.  If you suspect the validity of a
10904  result, try doing the same calculation in a higher precision.  The  result, try doing the same calculation in a higher precision.  The
10905  Calculator's arithmetic is not intended to be IEEE-conformant in any  Calculator's arithmetic is not intended to be IEEE-conformant in any
10906  way.@refill  way.
10907    
10908  While floats are always @emph{stored} in decimal, they can be entered  While floats are always @emph{stored} in decimal, they can be entered
10909  and displayed in any radix just like integers and fractions.  The  and displayed in any radix just like integers and fractions.  The
# Line 10798  polar.  The default format is rectangula Line 10929  polar.  The default format is rectangula
10929  @samp{(@var{real},@var{imag})} where @var{real} is the real part and  @samp{(@var{real},@var{imag})} where @var{real} is the real part and
10930  @var{imag} is the imaginary part, each of which may be any real number.  @var{imag} is the imaginary part, each of which may be any real number.
10931  Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i}  Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i}
10932  notation; @pxref{Complex Formats}.@refill  notation; @pxref{Complex Formats}.
10933    
10934  Polar complex numbers are displayed in the form `@t{(}@var{r}@t{;}@c{$\theta$}  Polar complex numbers are displayed in the form
10935  @var{theta}@t{)}'  @texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}'
10936  where @var{r} is the nonnegative magnitude and @c{$\theta$}  @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'
10937  @var{theta} is the argument  where @var{r} is the nonnegative magnitude and
10938  or phase angle.  The range of @c{$\theta$}  @texline @tmath{\theta}
10939  @var{theta} depends on the current angular  @infoline @var{theta}
10940  mode (@pxref{Angular Modes}); it is generally between @i{-180} and  is the argument or phase angle.  The range of
10941  @i{+180} degrees or the equivalent range in radians.@refill  @texline @tmath{\theta}
10942    @infoline @var{theta}
10943    depends on the current angular mode (@pxref{Angular Modes}); it is
10944    generally between @i{-180} and @i{+180} degrees or the equivalent range
10945    in radians.
10946    
10947  Complex numbers are entered in stages using incomplete objects.  Complex numbers are entered in stages using incomplete objects.
10948  @xref{Incomplete Objects}.  @xref{Incomplete Objects}.
# Line 10819  a negative real), the current @dfn{Polar Line 10954  a negative real), the current @dfn{Polar
10954  type.  @xref{Polar Mode}.  type.  @xref{Polar Mode}.
10955    
10956  A complex result in which the imaginary part is zero (or the phase angle  A complex result in which the imaginary part is zero (or the phase angle
10957  is 0 or 180 degrees or @c{$\pi$}  is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real
 @cite{pi} radians) is automatically converted to a real  
10958  number.  number.
10959    
10960  @node Infinities, Vectors and Matrices, Complex Numbers, Data Types  @node Infinities, Vectors and Matrices, Complex Numbers, Data Types
# Line 10845  entered using algebraic entry. Line 10979  entered using algebraic entry.
10979  Mathematically speaking, it is not rigorously correct to treat  Mathematically speaking, it is not rigorously correct to treat
10980  ``infinity'' as if it were a number, but mathematicians often do  ``infinity'' as if it were a number, but mathematicians often do
10981  so informally.  When they say that @samp{1 / inf = 0}, what they  so informally.  When they say that @samp{1 / inf = 0}, what they
10982  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
10983  larger, becomes arbitrarily close to zero.  So you can imagine  larger, becomes arbitrarily close to zero.  So you can imagine
10984  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}
10985  would go all the way to zero.  Similarly, when they say that  would go all the way to zero.  Similarly, when they say that
10986  @samp{exp(inf) = inf}, they mean that @c{$e^x$}  @samp{exp(inf) = inf}, they mean that
10987  @cite{exp(x)} grows without  @texline @tmath{e^x}
10988  bound as @cite{x} grows.  The symbol @samp{-inf} likewise stands  @infoline @expr{exp(x)}
10989  for an infinitely negative real value; for example, we say that  grows without bound as @expr{x} grows.  The symbol @samp{-inf} likewise
10990    stands for an infinitely negative real value; for example, we say that
10991  @samp{exp(-inf) = 0}.  You can have an infinity pointing in any  @samp{exp(-inf) = 0}.  You can have an infinity pointing in any
10992  direction on the complex plane:  @samp{sqrt(-inf) = i inf}.  direction on the complex plane:  @samp{sqrt(-inf) = i inf}.
10993    
10994  The same concept of limits can be used to define @cite{1 / 0}.  We  The same concept of limits can be used to define @expr{1 / 0}.  We
10995  really want the value that @cite{1 / x} approaches as @cite{x}  really want the value that @expr{1 / x} approaches as @expr{x}
10996  approaches zero.  But if all we have is @cite{1 / 0}, we can't  approaches zero.  But if all we have is @expr{1 / 0}, we can't
10997  tell which direction @cite{x} was coming from.  If @cite{x} was  tell which direction @expr{x} was coming from.  If @expr{x} was
10998  positive and decreasing toward zero, then we should say that  positive and decreasing toward zero, then we should say that
10999  @samp{1 / 0 = inf}.  But if @cite{x} was negative and increasing  @samp{1 / 0 = inf}.  But if @expr{x} was negative and increasing
11000  toward zero, the answer is @samp{1 / 0 = -inf}.  In fact, @cite{x}  toward zero, the answer is @samp{1 / 0 = -inf}.  In fact, @expr{x}
11001  could be an imaginary number, giving the answer @samp{i inf} or  could be an imaginary number, giving the answer @samp{i inf} or
11002  @samp{-i inf}.  Calc uses the special symbol @samp{uinf} to mean  @samp{-i inf}.  Calc uses the special symbol @samp{uinf} to mean
11003  @dfn{undirected infinity}, i.e., a value which is infinitely  @dfn{undirected infinity}, i.e., a value which is infinitely
# Line 10870  large but with an unknown sign (or direc Line 11005  large but with an unknown sign (or direc
11005    
11006  Calc actually has three modes that say how infinities are handled.  Calc actually has three modes that say how infinities are handled.
11007  Normally, infinities never arise from calculations that didn't  Normally, infinities never arise from calculations that didn't
11008  already have them.  Thus, @cite{1 / 0} is treated simply as an  already have them.  Thus, @expr{1 / 0} is treated simply as an
11009  error and left unevaluated.  The @kbd{m i} (@code{calc-infinite-mode})  error and left unevaluated.  The @kbd{m i} (@code{calc-infinite-mode})
11010  command (@pxref{Infinite Mode}) enables a mode in which  command (@pxref{Infinite Mode}) enables a mode in which
11011  @cite{1 / 0} evaluates to @code{uinf} instead.  There is also  @expr{1 / 0} evaluates to @code{uinf} instead.  There is also
11012  an alternative type of infinite mode which says to treat zeros  an alternative type of infinite mode which says to treat zeros
11013  as if they were positive, so that @samp{1 / 0 = inf}.  While this  as if they were positive, so that @samp{1 / 0 = inf}.  While this
11014  is less mathematically correct, it may be the answer you want in  is less mathematically correct, it may be the answer you want in
# Line 10892  notation. Line 11027  notation.
11027  It's not so easy to define certain formulas like @samp{0 * inf} and  It's not so easy to define certain formulas like @samp{0 * inf} and
11028  @samp{inf / inf}.  Depending on where these zeros and infinities  @samp{inf / inf}.  Depending on where these zeros and infinities
11029  came from, the answer could be literally anything.  The latter  came from, the answer could be literally anything.  The latter
11030  formula could be the limit of @cite{x / x} (giving a result of one),  formula could be the limit of @expr{x / x} (giving a result of one),
11031  or @cite{2 x / x} (giving two), or @cite{x^2 / x} (giving @code{inf}),  or @expr{2 x / x} (giving two), or @expr{x^2 / x} (giving @code{inf}),
11032  or @cite{x / x^2} (giving zero).  Calc uses the symbol @code{nan}  or @expr{x / x^2} (giving zero).  Calc uses the symbol @code{nan}
11033  to represent such an @dfn{indeterminate} value.  (The name ``nan''  to represent such an @dfn{indeterminate} value.  (The name ``nan''
11034  comes from analogy with the ``NAN'' concept of IEEE standard  comes from analogy with the ``NAN'' concept of IEEE standard
11035  arithmetic; it stands for ``Not A Number.''  This is somewhat of a  arithmetic; it stands for ``Not A Number.''  This is somewhat of a
# Line 10938  Traditional vector and matrix arithmetic Line 11073  Traditional vector and matrix arithmetic
11073  @pxref{Basic Arithmetic} and @pxref{Matrix Functions}.  @pxref{Basic Arithmetic} and @pxref{Matrix Functions}.
11074  Many other operations are applied to vectors element-wise.  For example,  Many other operations are applied to vectors element-wise.  For example,
11075  the complex conjugate of a vector is a vector of the complex conjugates  the complex conjugate of a vector is a vector of the complex conjugates
11076  of its elements.@refill  of its elements.
11077    
11078  @ignore  @ignore
11079  @starindex  @starindex
11080  @end ignore  @end ignore
11081  @tindex vec  @tindex vec
11082  Algebraic functions for building vectors include @samp{vec(a, b, c)}  Algebraic functions for building vectors include @samp{vec(a, b, c)}
11083  to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an @c{$n\times m$}  to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an
11084  @asis{@var{n}x@var{m}}  @texline @tmath{n\times m}
11085    @infoline @var{n}x@var{m}
11086  matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers  matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers
11087  from 1 to @samp{n}.  from 1 to @samp{n}.
11088    
# Line 11077  The @var{secs} value is a real number be Line 11213  The @var{secs} value is a real number be
11213  (exclusive).  A positive HMS form is interpreted as @var{hours} +  (exclusive).  A positive HMS form is interpreted as @var{hours} +
11214  @var{mins}/60 + @var{secs}/3600.  A negative HMS form is interpreted  @var{mins}/60 + @var{secs}/3600.  A negative HMS form is interpreted
11215  as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600.  as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600.
11216  Display format for HMS forms is quite flexible.  @xref{HMS Formats}.@refill  Display format for HMS forms is quite flexible.  @xref{HMS Formats}.
11217    
11218  HMS forms can be added and subtracted.  When they are added to numbers,  HMS forms can be added and subtracted.  When they are added to numbers,
11219  the numbers are interpreted according to the current angular mode.  HMS  the numbers are interpreted according to the current angular mode.  HMS
# Line 11216  an integer multiple of) some value @var{ Line 11352  an integer multiple of) some value @var{
11352  often arises in number theory.  Modulo forms are written  often arises in number theory.  Modulo forms are written
11353  `@var{a} @t{mod} @var{M}',  `@var{a} @t{mod} @var{M}',
11354  where @var{a} and @var{M} are real numbers or HMS forms, and  where @var{a} and @var{M} are real numbers or HMS forms, and
11355  @c{$0 \le a < M$}  @texline @tmath{0 \le a < M}.
11356  @cite{0 <= a < @var{M}}.  @infoline @expr{0 <= a < @var{M}}.
11357  In many applications @cite{a} and @cite{M} will be  In many applications @expr{a} and @expr{M} will be
11358  integers but this is not required.@refill  integers but this is not required.
11359    
11360  Modulo forms are not to be confused with the modulo operator @samp{%}.  Modulo forms are not to be confused with the modulo operator @samp{%}.
11361  The expression @samp{27 % 10} means to compute 27 modulo 10 to produce  The expression @samp{27 % 10} means to compute 27 modulo 10 to produce
# Line 11228  The expression @samp{27 mod 10} produces Line 11364  The expression @samp{27 mod 10} produces
11364  further computations with this value are again reduced modulo 10 so that  further computations with this value are again reduced modulo 10 so that
11365  the result always lies in the desired range.  the result always lies in the desired range.
11366    
11367  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,
11368  the Calculator simply adds or multiplies the values, then reduces modulo  the Calculator simply adds or multiplies the values, then reduces modulo
11369  @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,
11370  the plain number is treated like a compatible modulo form.  It is also  the plain number is treated like a compatible modulo form.  It is also
11371  possible to raise modulo forms to powers; the result is the value raised  possible to raise modulo forms to powers; the result is the value raised
11372  to the power, then reduced modulo @cite{M}.  (When all values involved  to the power, then reduced modulo @expr{M}.  (When all values involved
11373  are integers, this calculation is done much more efficiently than  are integers, this calculation is done much more efficiently than
11374  actually computing the power and then reducing.)  actually computing the power and then reducing.)
11375    
11376  @cindex Modulo division  @cindex Modulo division
11377  Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}'  Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}'
11378  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
11379  integers.  The result is the modulo form which, when multiplied by  integers.  The result is the modulo form which, when multiplied by
11380  `@var{b} @t{mod} @var{M}', produces `@var{a} @t{mod} @var{M}'.  If  `@var{b} @t{mod} @var{M}', produces `@var{a} @t{mod} @var{M}'.  If
11381  there is no solution to this equation (which can happen only when  there is no solution to this equation (which can happen only when
11382  @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
11383  division is left in symbolic form.  Other operations, such as square  division is left in symbolic form.  Other operations, such as square
11384  roots, are not yet supported for modulo forms.  (Note that, although  roots, are not yet supported for modulo forms.  (Note that, although
11385  @w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root''  @w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root''
11386  in the sense of reducing @c{$\sqrt a$}  in the sense of reducing
11387  @cite{sqrt(a)} modulo @cite{M}, this is not a  @texline @tmath{\sqrt a}
11388  useful definition from the number-theoretical point of view.)@refill  @infoline @expr{sqrt(a)}
11389    modulo @expr{M}, this is not a useful definition from the
11390    number-theoretical point of view.)
11391    
11392  @ignore  @ignore
11393  @mindex M  @mindex M
# Line 11261  useful definition from the number-theore Line 11399  useful definition from the number-theore
11399  @tindex mod (operator)  @tindex mod (operator)
11400  To create a modulo form during numeric entry, press the shift-@kbd{M}  To create a modulo form during numeric entry, press the shift-@kbd{M}
11401  key to enter the word @samp{mod}.  As a special convenience, pressing  key to enter the word @samp{mod}.  As a special convenience, pressing
11402  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}
11403  that was most recently used before.  During algebraic entry, either  that was most recently used before.  During algebraic entry, either
11404  type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).  type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
11405  Once again, pressing this a second time enters the current modulo.@refill  Once again, pressing this a second time enters the current modulo.
11406    
11407  You can also use @kbd{v p} and @kbd{%} to modify modulo forms.  You can also use @kbd{v p} and @kbd{%} to modify modulo forms.
11408  @xref{Building Vectors}.  @xref{Basic Arithmetic}.  @xref{Building Vectors}.  @xref{Basic Arithmetic}.
11409    
11410  It is possible to mix HMS forms and modulo forms.  For example, an  It is possible to mix HMS forms and modulo forms.  For example, an
11411  HMS form modulo 24 could be used to manipulate clock times; an HMS  HMS form modulo 24 could be used to manipulate clock times; an HMS
11412  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}
11413  also be an HMS form eliminates troubles that would arise if the angular  also be an HMS form eliminates troubles that would arise if the angular
11414  mode were inadvertently set to Radians, in which case  mode were inadvertently set to Radians, in which case
11415  @w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo  @w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
# Line 11296  The algebraic function @samp{makemod(a, Line 11434  The algebraic function @samp{makemod(a,
11434  @cindex Standard deviations  @cindex Standard deviations
11435  An @dfn{error form} is a number with an associated standard  An @dfn{error form} is a number with an associated standard
11436  deviation, as in @samp{2.3 +/- 0.12}.  The notation  deviation, as in @samp{2.3 +/- 0.12}.  The notation
11437  `@var{x} @t{+/-} @c{$\sigma$}  @texline `@var{x} @t{+/-} @tmath{\sigma}'
11438  @asis{sigma}' stands for an uncertain value which follows a normal or  @infoline `@var{x} @t{+/-} sigma'
11439  Gaussian distribution of mean @cite{x} and standard deviation or  stands for an uncertain value which follows
11440  ``error'' @c{$\sigma$}  a normal or Gaussian distribution of mean @expr{x} and standard
11441  @cite{sigma}.  Both the mean and the error can be either numbers or  deviation or ``error''
11442    @texline @tmath{\sigma}.
11443    @infoline @expr{sigma}.
11444    Both the mean and the error can be either numbers or
11445  formulas.  Generally these are real numbers but the mean may also be  formulas.  Generally these are real numbers but the mean may also be
11446  complex.  If the error is negative or complex, it is changed to its  complex.  If the error is negative or complex, it is changed to its
11447  absolute value.  An error form with zero error is converted to a  absolute value.  An error form with zero error is converted to a
11448  regular number by the Calculator.@refill  regular number by the Calculator.
11449    
11450  All arithmetic and transcendental functions accept error forms as input.  All arithmetic and transcendental functions accept error forms as input.
11451  Operations on the mean-value part work just like operations on regular  Operations on the mean-value part work just like operations on regular
11452  numbers.  The error part for any function @cite{f(x)} (such as @c{$\sin x$}  numbers.  The error part for any function @expr{f(x)} (such as
11453  @cite{sin(x)})  @texline @tmath{\sin x}
11454  is defined by the error of @cite{x} times the derivative of @cite{f}  @infoline @expr{sin(x)})
11455  evaluated at the mean value of @cite{x}.  For a two-argument function  is defined by the error of @expr{x} times the derivative of @expr{f}
11456  @cite{f(x,y)} (such as addition) the error is the square root of the sum  evaluated at the mean value of @expr{x}.  For a two-argument function
11457  of the squares of the errors due to @cite{x} and @cite{y}.  @expr{f(x,y)} (such as addition) the error is the square root of the sum
11458    of the squares of the errors due to @expr{x} and @expr{y}.
11459  @tex  @tex
11460  $$ \eqalign{  $$ \eqalign{
11461    f(x \hbox{\code{ +/- }} \sigma)    f(x \hbox{\code{ +/- }} \sigma)
# Line 11327  $$ \eqalign{ Line 11469  $$ \eqalign{
11469  } $$  } $$
11470  @end tex  @end tex
11471  Note that this  Note that this
11472  definition assumes the errors in @cite{x} and @cite{y} are uncorrelated.  definition assumes the errors in @expr{x} and @expr{y} are uncorrelated.
11473  A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}  A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
11474  is not the same as @samp{(2 +/- 1)^2}; the former represents the product  is not the same as @samp{(2 +/- 1)^2}; the former represents the product
11475  of two independent values which happen to have the same probability  of two independent values which happen to have the same probability
11476  distributions, and the latter is the product of one random value with itself.  distributions, and the latter is the product of one random value with itself.
11477  The former will produce an answer with less error, since on the average  The former will produce an answer with less error, since on the average
11478  the two independent errors can be expected to cancel out.@refill  the two independent errors can be expected to cancel out.
11479    
11480  Consult a good text on error analysis for a discussion of the proper use  Consult a good text on error analysis for a discussion of the proper use
11481  of standard deviations.  Actual errors often are neither Gaussian-distributed  of standard deviations.  Actual errors often are neither Gaussian-distributed
11482  nor uncorrelated, and the above formulas are valid only when errors  nor uncorrelated, and the above formulas are valid only when errors
11483  are small.  As an example, the error arising from  are small.  As an example, the error arising from
11484  `@t{sin(}@var{x} @t{+/-} @c{$\sigma$}  @texline `@t{sin(}@var{x} @t{+/-} @tmath{\sigma}@t{)}'
11485  @var{sigma}@t{)}' is  @infoline `@t{sin(}@var{x} @t{+/-} @var{sigma}@t{)}'
11486  `@c{$\sigma$\nobreak}  is
11487  @var{sigma} @t{abs(cos(}@var{x}@t{))}'.  When @cite{x} is close to zero,  @texline `@tmath{\sigma} @t{abs(cos(}@var{x}@t{))}'.  
11488  @c{$\cos x$}  @infoline `@var{sigma} @t{abs(cos(}@var{x}@t{))}'.  
11489  @cite{cos(x)} is  When @expr{x} is close to zero,
11490  close to one so the error in the sine is close to @c{$\sigma$}  @texline @tmath{\cos x}
11491  @cite{sigma}; this makes sense, since @c{$\sin x$}  @infoline @expr{cos(x)}
11492  @cite{sin(x)} is approximately @cite{x} near zero, so a given  is close to one so the error in the sine is close to
11493  error in @cite{x} will produce about the same error in the sine.  Likewise,  @texline @tmath{\sigma};
11494  near 90 degrees @c{$\cos x$}  @infoline @expr{sigma};
11495  @cite{cos(x)} is nearly zero and so the computed error is  this makes sense, since
11496  small:  The sine curve is nearly flat in that region, so an error in @cite{x}  @texline @tmath{\sin x}
11497  has relatively little effect on the value of @c{$\sin x$}  @infoline @expr{sin(x)}
11498  @cite{sin(x)}.  However, consider  is approximately @expr{x} near zero, so a given error in @expr{x} will
11499  @samp{sin(90 +/- 1000)}.  The cosine of 90 is zero, so Calc will report  produce about the same error in the sine.  Likewise, near 90 degrees
11500  zero error!  We get an obviously wrong result because we have violated  @texline @tmath{\cos x}
11501  the small-error approximation underlying the error analysis.  If the error  @infoline @expr{cos(x)}
11502  in @cite{x} had been small, the error in @c{$\sin x$}  is nearly zero and so the computed error is
11503  @cite{sin(x)} would indeed have been negligible.@refill  small:  The sine curve is nearly flat in that region, so an error in @expr{x}
11504    has relatively little effect on the value of
11505    @texline @tmath{\sin x}.
11506    @infoline @expr{sin(x)}.  
11507    However, consider @samp{sin(90 +/- 1000)}.  The cosine of 90 is zero, so
11508    Calc will report zero error!  We get an obviously wrong result because
11509    we have violated the small-error approximation underlying the error
11510    analysis.  If the error in @expr{x} had been small, the error in
11511    @texline @tmath{\sin x}
11512    @infoline @expr{sin(x)}
11513    would indeed have been negligible.
11514    
11515  @ignore  @ignore
11516  @mindex p  @mindex p
# Line 11411  intervals of the type shown above, @dfn{ Line 11563  intervals of the type shown above, @dfn{
11563  @emph{exclusive}, and @dfn{semi-open} intervals in which one end  @emph{exclusive}, and @dfn{semi-open} intervals in which one end
11564  uses a round parenthesis and the other a square bracket.  In mathematical  uses a round parenthesis and the other a square bracket.  In mathematical
11565  terms,  terms,
11566  @samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas  @samp{[2 ..@: 4]} means @expr{2 <= x <= 4}, whereas
11567  @samp{[2 ..@: 4)} represents @cite{2 <= x < 4},  @samp{[2 ..@: 4)} represents @expr{2 <= x < 4},
11568  @samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and  @samp{(2 ..@: 4]} represents @expr{2 < x <= 4}, and
11569  @samp{(2 ..@: 4)} represents @cite{2 < x < 4}.@refill  @samp{(2 ..@: 4)} represents @expr{2 < x < 4}.
11570  @end ifinfo  @end ifinfo
11571  @tex  @tex
11572  Calc supports several varieties of intervals, including \dfn{closed}  Calc supports several varieties of intervals, including \dfn{closed}
# Line 11464  contain zero inside them Calc is forced Line 11616  contain zero inside them Calc is forced
11616    
11617  While it may seem that intervals and error forms are similar, they are  While it may seem that intervals and error forms are similar, they are
11618  based on entirely different concepts of inexact quantities.  An error  based on entirely different concepts of inexact quantities.  An error
11619  form `@var{x} @t{+/-} @c{$\sigma$}  form
11620  @var{sigma}' means a variable is random, and its value could  @texline `@var{x} @t{+/-} @tmath{\sigma}'
11621  be anything but is ``probably'' within one @c{$\sigma$}  @infoline `@var{x} @t{+/-} @var{sigma}'
11622  @var{sigma} of the mean value @cite{x}.  means a variable is random, and its value could
11623  An interval `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a variable's value  be anything but is ``probably'' within one
11624  is unknown, but guaranteed to lie in the specified range.  Error forms  @texline @tmath{\sigma}
11625  are statistical or ``average case'' approximations; interval arithmetic  @infoline @var{sigma}
11626  tends to produce ``worst case'' bounds on an answer.@refill  of the mean value @expr{x}. An interval
11627    `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a
11628    variable's value is unknown, but guaranteed to lie in the specified
11629    range.  Error forms are statistical or ``average case'' approximations;
11630    interval arithmetic tends to produce ``worst case'' bounds on an
11631    answer.
11632    
11633  Intervals may not contain complex numbers, but they may contain  Intervals may not contain complex numbers, but they may contain
11634  HMS forms or date forms.  HMS forms or date forms.
# Line 11537  pushes the complex number @samp{(1, 1.41 Line 11694  pushes the complex number @samp{(1, 1.41
11694  If several values lie on the stack in front of the incomplete object,  If several values lie on the stack in front of the incomplete object,
11695  all are collected and appended to the object.  Thus the @kbd{,} key  all are collected and appended to the object.  Thus the @kbd{,} key
11696  is redundant:  @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}.  Some people  is redundant:  @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}.  Some people
11697  prefer the equivalent @key{SPC} key to @key{RET}.@refill  prefer the equivalent @key{SPC} key to @key{RET}.
11698    
11699  As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or  As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
11700  @kbd{,} adds a zero or duplicates the preceding value in the list being  @kbd{,} adds a zero or duplicates the preceding value in the list being
# Line 11575  Calc also allows apostrophes and @code{# Line 11732  Calc also allows apostrophes and @code{#
11732  The Calc variable @code{foo} corresponds to the Emacs Lisp variable  The Calc variable @code{foo} corresponds to the Emacs Lisp variable
11733  @code{var-foo}.  Commands like @kbd{s s} (@code{calc-store}) that operate  @code{var-foo}.  Commands like @kbd{s s} (@code{calc-store}) that operate
11734  on variables can be made to use any arbitrary Lisp variable simply by  on variables can be made to use any arbitrary Lisp variable simply by
11735  backspacing over the @samp{var-} prefix in the minibuffer.@refill  backspacing over the @samp{var-} prefix in the minibuffer.
11736    
11737  In a command that takes a variable name, you can either type the full  In a command that takes a variable name, you can either type the full
11738  name of a variable, or type a single digit to use one of the special  name of a variable, or type a single digit to use one of the special
11739  convenience variables @code{var-q0} through @code{var-q9}.  For example,  convenience variables @code{var-q0} through @code{var-q9}.  For example,
11740  @kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and  @kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and
11741  @w{@kbd{3 s s foo @key{RET}}} stores that number in variable  @w{@kbd{3 s s foo @key{RET}}} stores that number in variable
11742  @code{var-foo}.@refill  @code{var-foo}.
11743    
11744  To push a variable itself (as opposed to the variable's value) on the  To push a variable itself (as opposed to the variable's value) on the
11745  stack, enter its name as an algebraic expression using the apostrophe  stack, enter its name as an algebraic expression using the apostrophe
# Line 11623  A few variables are called @dfn{special Line 11780  A few variables are called @dfn{special
11780  (@xref{Scientific Functions}.)  When they are evaluated with @kbd{=},  (@xref{Scientific Functions}.)  When they are evaluated with @kbd{=},
11781  their values are calculated if necessary according to the current precision  their values are calculated if necessary according to the current precision
11782  or complex polar mode.  If you wish to use these symbols for other purposes,  or complex polar mode.  If you wish to use these symbols for other purposes,
11783  simply undefine or redefine them using @code{calc-store}.@refill  simply undefine or redefine them using @code{calc-store}.
11784    
11785  The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for  The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
11786  infinite or indeterminate values.  It's best not to use them as  infinite or indeterminate values.  It's best not to use them as
# Line 11697  the C-style ``if'' operator @samp{a?b:c} Line 11854  the C-style ``if'' operator @samp{a?b:c}
11854  @samp{=>} [@code{evalto}].  @samp{=>} [@code{evalto}].
11855    
11856  Note that, unlike in usual computer notation, multiplication binds more  Note that, unlike in usual computer notation, multiplication binds more
11857  strongly than division:  @samp{a*b/c*d} is equivalent to @c{$a b \over c d$}  strongly than division:  @samp{a*b/c*d} is equivalent to
11858  @cite{(a*b)/(c*d)}.  @texline @tmath{a b \over c d}.
11859    @infoline @expr{(a*b)/(c*d)}.
11860    
11861  @cindex Multiplication, implicit  @cindex Multiplication, implicit
11862  @cindex Implicit multiplication  @cindex Implicit multiplication
# Line 11712  is interpreted as a function call, not a Line 11870  is interpreted as a function call, not a
11870  cases you must use a space if you omit the @samp{*}:  @samp{2a} is the  cases you must use a space if you omit the @samp{*}:  @samp{2a} is the
11871  same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}  same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
11872  is a variable called @code{ab}, @emph{not} the product of @samp{a} and  is a variable called @code{ab}, @emph{not} the product of @samp{a} and
11873  @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.
11874    
11875  @cindex Implicit comma in vectors  @cindex Implicit comma in vectors
11876  The rules are slightly different for vectors written with square brackets.  The rules are slightly different for vectors written with square brackets.
# Line 11724  Note that spaces around the brackets, an Line 11882  Note that spaces around the brackets, an
11882  ignored.  To force spaces to be interpreted as multiplication you can  ignored.  To force spaces to be interpreted as multiplication you can
11883  enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is  enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
11884  interpreted as @samp{[a*b, 2*c*d]}.  An implicit comma is also inserted  interpreted as @samp{[a*b, 2*c*d]}.  An implicit comma is also inserted
11885  between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill  between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.
11886    
11887  Vectors that contain commas (not embedded within nested parentheses or  Vectors that contain commas (not embedded within nested parentheses or
11888  brackets) do not treat spaces specially:  @samp{[a b, 2 c d]} is a vector  brackets) do not treat spaces specially:  @samp{[a b, 2 c d]} is a vector
# Line 11753  call is left as it is during algebraic m Line 11911  call is left as it is during algebraic m
11911  left alone.  Beware that many innocent-looking short names like @code{in}  left alone.  Beware that many innocent-looking short names like @code{in}
11912  and @code{re} have predefined meanings which could surprise you; however,  and @code{re} have predefined meanings which could surprise you; however,
11913  single letters or single letters followed by digits are always safe to  single letters or single letters followed by digits are always safe to
11914  use for your own function names.  @xref{Function Index}.@refill  use for your own function names.  @xref{Function Index}.
11915    
11916  In the documentation for particular commands, the notation @kbd{H S}  In the documentation for particular commands, the notation @kbd{H S}
11917  (@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the  (@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the
11918  command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all  command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all
11919  represent the same operation.@refill  represent the same operation.
11920    
11921  Commands that interpret (``parse'') text as algebraic formulas include  Commands that interpret (``parse'') text as algebraic formulas include
11922  algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse  algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
# Line 11823  For example, with @samp{10 20 30} on the Line 11981  For example, with @samp{10 20 30} on the
11981  @key{RET} creates @samp{10 20 30 30},  @key{RET} creates @samp{10 20 30 30},
11982  @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 30},
11983  @kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and  @kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and
11984  @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}.
11985    
11986  @kindex @key{LFD}  @kindex @key{LFD}
11987  @pindex calc-over  @pindex calc-over
# Line 11833  except that the sign of the numeric pref Line 11991  except that the sign of the numeric pref
11991  oppositely.  Also, with no prefix argument the default argument is 2.  oppositely.  Also, with no prefix argument the default argument is 2.
11992  Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}  Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}
11993  are both equivalent to @kbd{C-u - 2 @key{RET}}, producing  are both equivalent to @kbd{C-u - 2 @key{RET}}, producing
11994  @samp{10 20 30 20}.@refill  @samp{10 20 30 20}.
11995    
11996  @kindex @key{DEL}  @kindex @key{DEL}
11997  @kindex C-d  @kindex C-d
# Line 11851  For example, with @samp{10 20 30} on the Line 12009  For example, with @samp{10 20 30} on the
12009  @key{DEL} leaves @samp{10 20},  @key{DEL} leaves @samp{10 20},
12010  @kbd{C-u 2 @key{DEL}} leaves @samp{10},  @kbd{C-u 2 @key{DEL}} leaves @samp{10},
12011  @kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and  @kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and
12012  @kbd{C-u 0 @key{DEL}} leaves an empty stack.@refill  @kbd{C-u 0 @key{DEL}} leaves an empty stack.
12013    
12014  @kindex M-@key{DEL}  @kindex M-@key{DEL}
12015  @pindex calc-pop-above  @pindex calc-pop-above
# Line 11874  For example, with @samp{10 20 30 40 50} Line 12032  For example, with @samp{10 20 30 40 50}
12032  @key{TAB} creates @samp{10 20 30 50 40},  @key{TAB} creates @samp{10 20 30 50 40},
12033  @kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},  @kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},
12034  @kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and  @kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and
12035  @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}.
12036    
12037  @kindex M-@key{TAB}  @kindex M-@key{TAB}
12038  @pindex calc-roll-up  @pindex calc-roll-up
# Line 11885  For example, with @samp{10 20 30 40 50} Line 12043  For example, with @samp{10 20 30 40 50}
12043  @kbd{M-@key{TAB}} creates @samp{10 20 40 50 30},  @kbd{M-@key{TAB}} creates @samp{10 20 40 50 30},
12044  @kbd{C-u 4 M-@key{TAB}} creates @samp{10 30 40 50 20},  @kbd{C-u 4 M-@key{TAB}} creates @samp{10 30 40 50 20},
12045  @kbd{C-u - 2 M-@key{TAB}} creates @samp{30 40 50 10 20}, and  @kbd{C-u - 2 M-@key{TAB}} creates @samp{30 40 50 10 20}, and
12046  @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}.
12047    
12048  A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in  A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in
12049  terms of moving a particular element to a new position in the stack.  terms of moving a particular element to a new position in the stack.
# Line 11988  The @kbd{t i} (@code{calc-trail-in}) and Line 12146  The @kbd{t i} (@code{calc-trail-in}) and
12146  Calc Trail window.  In practice they are rarely used, since the commands  Calc Trail window.  In practice they are rarely used, since the commands
12147  shown below are a more convenient way to move around in the  shown below are a more convenient way to move around in the
12148  trail, and they work ``by remote control'' when the cursor is still  trail, and they work ``by remote control'' when the cursor is still
12149  in the Calculator window.@refill  in the Calculator window.
12150    
12151  @cindex Trail pointer  @cindex Trail pointer
12152  There is a @dfn{trail pointer} which selects some entry of the trail at  There is a @dfn{trail pointer} which selects some entry of the trail at
# Line 12011  trail pointer. Line 12169  trail pointer.
12169  @pindex calc-trail-scroll-right  @pindex calc-trail-scroll-right
12170  The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >}  The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >}
12171  (@code{calc-trail-scroll-right}) commands horizontally scroll the trail  (@code{calc-trail-scroll-right}) commands horizontally scroll the trail
12172  window left or right by one half of its width.@refill  window left or right by one half of its width.
12173    
12174  @kindex t n  @kindex t n
12175  @pindex calc-trail-next  @pindex calc-trail-next
# Line 12026  The @kbd{t n} (@code{calc-trail-next}) a Line 12184  The @kbd{t n} (@code{calc-trail-next}) a
12184  one line.  The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}  one line.  The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}
12185  (@code{calc-trail-backward}) commands move the trail pointer down or up  (@code{calc-trail-backward}) commands move the trail pointer down or up
12186  one screenful at a time.  All of these commands accept numeric prefix  one screenful at a time.  All of these commands accept numeric prefix
12187  arguments to move several lines or screenfuls at a time.@refill  arguments to move several lines or screenfuls at a time.
12188    
12189  @kindex t [  @kindex t [
12190  @pindex calc-trail-first  @pindex calc-trail-first
# Line 12038  The @kbd{t [} (@code{calc-trail-first}) Line 12196  The @kbd{t [} (@code{calc-trail-first})
12196  (@code{calc-trail-last}) commands move the trail pointer to the first or  (@code{calc-trail-last}) commands move the trail pointer to the first or
12197  last line of the trail.  The @kbd{t h} (@code{calc-trail-here}) command  last line of the trail.  The @kbd{t h} (@code{calc-trail-here}) command
12198  moves the trail pointer to the cursor position; unlike the other trail  moves the trail pointer to the cursor position; unlike the other trail
12199  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.
12200    
12201  @kindex t s  @kindex t s
12202  @pindex calc-trail-isearch-forward  @pindex calc-trail-isearch-forward
# Line 12050  The @kbd{t s} (@code{calc-trail-isearch- Line 12208  The @kbd{t s} (@code{calc-trail-isearch-
12208  search forward or backward through the trail.  You can press @key{RET}  search forward or backward through the trail.  You can press @key{RET}
12209  to terminate the search; the trail pointer moves to the current line.  to terminate the search; the trail pointer moves to the current line.
12210  If you cancel the search with @kbd{C-g}, the trail pointer stays where  If you cancel the search with @kbd{C-g}, the trail pointer stays where
12211  it was when the search began.@refill  it was when the search began.
12212  @end ifinfo  @end ifinfo
12213  @tex  @tex
12214  The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}  The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
# Line 12248  what you see is what you get.  Reducing Line 12406  what you see is what you get.  Reducing
12406  round values already on the stack, but those values will be rounded  round values already on the stack, but those values will be rounded
12407  down before being used in any calculation.  The @kbd{c 0} through  down before being used in any calculation.  The @kbd{c 0} through
12408  @kbd{c 9} commands (@pxref{Conversions}) can be used to round an  @kbd{c 9} commands (@pxref{Conversions}) can be used to round an
12409  existing value to a new precision.@refill  existing value to a new precision.
12410    
12411  @cindex Accuracy of calculations  @cindex Accuracy of calculations
12412  It is important to distinguish the concepts of @dfn{precision} and  It is important to distinguish the concepts of @dfn{precision} and
# Line 12291  There is no single-key equivalent to the Line 12449  There is no single-key equivalent to the
12449  Instead, you must first press @kbd{I} (@code{calc-inverse}) to set  Instead, you must first press @kbd{I} (@code{calc-inverse}) to set
12450  the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).  the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).
12451  The @kbd{I} key actually toggles the Inverse Flag.  When this flag  The @kbd{I} key actually toggles the Inverse Flag.  When this flag
12452  is set, the word @samp{Inv} appears in the mode line.@refill  is set, the word @samp{Inv} appears in the mode line.
12453    
12454  @kindex H  @kindex H
12455  @pindex calc-hyperbolic  @pindex calc-hyperbolic
# Line 12300  Hyperbolic Flag, which transforms @code{ Line 12458  Hyperbolic Flag, which transforms @code{
12458  If both of these flags are set at once, the effect will be  If both of these flags are set at once, the effect will be
12459  @code{calc-arcsinh}.  (The Hyperbolic flag is also used by some  @code{calc-arcsinh}.  (The Hyperbolic flag is also used by some
12460  non-trigonometric commands; for example @kbd{H L} computes a base-10,  non-trigonometric commands; for example @kbd{H L} computes a base-10,
12461  instead of base-@i{e}, logarithm.)@refill  instead of base-@i{e}, logarithm.)
12462    
12463  Command names like @code{calc-arcsin} are provided for completeness, and  Command names like @code{calc-arcsin} are provided for completeness, and
12464  may be executed with @kbd{x} or @kbd{M-x}.  Their effect is simply to  may be executed with @kbd{x} or @kbd{M-x}.  Their effect is simply to
# Line 12356  result is a complex number and the curre Line 12514  result is a complex number and the curre
12514  instead expressed in degrees.  (Complex-number calculations would  instead expressed in degrees.  (Complex-number calculations would
12515  normally be done in radians mode, though.  Complex numbers are converted  normally be done in radians mode, though.  Complex numbers are converted
12516  to degrees by calculating the complex result in radians and then  to degrees by calculating the complex result in radians and then
12517  multiplying by 180 over @c{$\pi$}  multiplying by 180 over @cpi{}.)
 @cite{pi}.)  
12518    
12519  @kindex m r  @kindex m r
12520  @pindex calc-radians-mode  @pindex calc-radians-mode
# Line 12368  multiplying by 180 over @c{$\pi$} Line 12525  multiplying by 180 over @c{$\pi$}
12525  The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),  The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),
12526  and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.  and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.
12527  The current angular mode is displayed on the Emacs mode line.  The current angular mode is displayed on the Emacs mode line.
12528  The default angular mode is degrees.@refill  The default angular mode is degrees.
12529    
12530  @node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes  @node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
12531  @subsection Polar Mode  @subsection Polar Mode
# Line 12396  of the above example situations would pr Line 12553  of the above example situations would pr
12553  Division of two integers normally yields a floating-point number if the  Division of two integers normally yields a floating-point number if the
12554  result cannot be expressed as an integer.  In some cases you would  result cannot be expressed as an integer.  In some cases you would
12555  rather get an exact fractional answer.  One way to accomplish this is  rather get an exact fractional answer.  One way to accomplish this is
12556  to multiply fractions instead:  @kbd{6 @key{RET} 1:4 *} produces @cite{3:2}  to multiply fractions instead:  @kbd{6 @key{RET} 1:4 *} produces @expr{3:2}
12557  even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}.  even though @kbd{6 @key{RET} 4 /} produces @expr{1.5}.
12558    
12559  @kindex m f  @kindex m f
12560  @pindex calc-frac-mode  @pindex calc-frac-mode
12561  To set the Calculator to produce fractional results for normal integer  To set the Calculator to produce fractional results for normal integer
12562  divisions, use the @kbd{m f} (@code{calc-frac-mode}) command.  divisions, use the @kbd{m f} (@code{calc-frac-mode}) command.
12563  For example, @cite{8/4} produces @cite{2} in either mode,  For example, @expr{8/4} produces @expr{2} in either mode,
12564  but @cite{6/4} produces @cite{3:2} in Fraction Mode, @cite{1.5} in  but @expr{6/4} produces @expr{3:2} in Fraction Mode, @expr{1.5} in
12565  Float Mode.@refill  Float Mode.
12566    
12567  At any time you can use @kbd{c f} (@code{calc-float}) to convert a  At any time you can use @kbd{c f} (@code{calc-float}) to convert a
12568  fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a  fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a
# Line 12416  float to a fraction.  @xref{Conversions} Line 12573  float to a fraction.  @xref{Conversions}
12573    
12574  @noindent  @noindent
12575  @cindex Infinite mode  @cindex Infinite mode
12576  The Calculator normally treats results like @cite{1 / 0} as errors;  The Calculator normally treats results like @expr{1 / 0} as errors;
12577  formulas like this are left in unsimplified form.  But Calc can be  formulas like this are left in unsimplified form.  But Calc can be
12578  put into a mode where such calculations instead produce ``infinite''  put into a mode where such calculations instead produce ``infinite''
12579  results.  results.
# Line 12432  will not be generated when infinite mode Line 12589  will not be generated when infinite mode
12589    
12590  With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},  With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
12591  an undirected infinity.  @xref{Infinities}, for a discussion of the  an undirected infinity.  @xref{Infinities}, for a discussion of the
12592  difference between @code{inf} and @code{uinf}.  Also, @cite{0 / 0}  difference between @code{inf} and @code{uinf}.  Also, @expr{0 / 0}
12593  evaluates to @code{nan}, the ``indeterminate'' symbol.  Various other  evaluates to @code{nan}, the ``indeterminate'' symbol.  Various other
12594  functions can also return infinities in this mode; for example,  functions can also return infinities in this mode; for example,
12595  @samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}.  Once again,  @samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}.  Once again,
# Line 12477  the expression at the top of the stack, Line 12634  the expression at the top of the stack,
12634  @code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).  @code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).
12635  Given a numeric prefix argument, it also  Given a numeric prefix argument, it also
12636  sets the floating-point precision to the specified value for the duration  sets the floating-point precision to the specified value for the duration
12637  of the command.@refill  of the command.
12638    
12639  To evaluate a formula numerically without expanding the variables it  To evaluate a formula numerically without expanding the variables it
12640  contains, you can use the key sequence @kbd{m s a v m s} (this uses  contains, you can use the key sequence @kbd{m s a v m s} (this uses
# Line 12504  multiplication to be commutative.  (Reca Line 12661  multiplication to be commutative.  (Reca
12661  @samp{A*B} is not the same as @samp{B*A}.)  This assumption affects  @samp{A*B} is not the same as @samp{B*A}.)  This assumption affects
12662  rewrite rules and algebraic simplification.  Another effect of this  rewrite rules and algebraic simplification.  Another effect of this
12663  mode is that calculations that would normally produce constants like  mode is that calculations that would normally produce constants like
12664  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
12665  produce function calls that represent ``generic'' zero or identity  produce function calls that represent ``generic'' zero or identity
12666  matrices: @samp{idn(0)}, @samp{idn(1)}.  The @code{idn} function  matrices: @samp{idn(0)}, @samp{idn(1)}.  The @code{idn} function
12667  @samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n}  @samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n}
# Line 12598  Type @kbd{m w} (@code{calc-working}) wit Line 12755  Type @kbd{m w} (@code{calc-working}) wit
12755  disable all ``working'' messages.  Use a numeric prefix of 1 to enable  disable all ``working'' messages.  Use a numeric prefix of 1 to enable
12756  only the plain @samp{Working...} message.  Use a numeric prefix of 2 to  only the plain @samp{Working...} message.  Use a numeric prefix of 2 to
12757  see intermediate results as well.  With no numeric prefix this displays  see intermediate results as well.  With no numeric prefix this displays
12758  the current mode.@refill  the current mode.
12759    
12760  While it may seem that the ``working'' messages will slow Calc down  While it may seem that the ``working'' messages will slow Calc down
12761  considerably, experiments have shown that their impact is actually  considerably, experiments have shown that their impact is actually
# Line 12613  The current @dfn{simplification mode} co Line 12770  The current @dfn{simplification mode} co
12770  are ``normalized'' when being taken from or pushed onto the stack.  are ``normalized'' when being taken from or pushed onto the stack.
12771  Some normalizations are unavoidable, such as rounding floating-point  Some normalizations are unavoidable, such as rounding floating-point
12772  results to the current precision, and reducing fractions to simplest  results to the current precision, and reducing fractions to simplest
12773  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}),
12774  are done by default but can be turned off when necessary.  are done by default but can be turned off when necessary.
12775    
12776  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
12777  stack, Calc pops these numbers, normalizes them, creates the formula  stack, Calc pops these numbers, normalizes them, creates the formula
12778  @cite{2+3}, normalizes it, and pushes the result.  Of course the standard  @expr{2+3}, normalizes it, and pushes the result.  Of course the standard
12779  rules for normalizing @cite{2+3} will produce the result @cite{5}.  rules for normalizing @expr{2+3} will produce the result @expr{5}.
12780    
12781  Simplification mode commands consist of the lower-case @kbd{m} prefix key  Simplification mode commands consist of the lower-case @kbd{m} prefix key
12782  followed by a shifted letter.  followed by a shifted letter.
# Line 12627  followed by a shifted letter. Line 12784  followed by a shifted letter.
12784  @kindex m O  @kindex m O
12785  @pindex calc-no-simplify-mode  @pindex calc-no-simplify-mode
12786  The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional  The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional
12787  simplifications.  These would leave a formula like @cite{2+3} alone.  In  simplifications.  These would leave a formula like @expr{2+3} alone.  In
12788  fact, nothing except simple numbers are ever affected by normalization  fact, nothing except simple numbers are ever affected by normalization
12789  in this mode.  in this mode.
12790    
# Line 12635  in this mode. Line 12792  in this mode.
12792  @pindex calc-num-simplify-mode  @pindex calc-num-simplify-mode
12793  The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification  The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification
12794  of any formulas except those for which all arguments are constants.  For  of any formulas except those for which all arguments are constants.  For
12795  example, @cite{1+2} is simplified to @cite{3}, and @cite{a+(2-2)} is  example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(2-2)} is
12796  simplified to @cite{a+0} but no further, since one argument of the sum  simplified to @expr{a+0} but no further, since one argument of the sum
12797  is not a constant.  Unfortunately, @cite{(a+2)-2} is @emph{not} simplified  is not a constant.  Unfortunately, @expr{(a+2)-2} is @emph{not} simplified
12798  because the top-level @samp{-} operator's arguments are not both  because the top-level @samp{-} operator's arguments are not both
12799  constant numbers (one of them is the formula @cite{a+2}).  constant numbers (one of them is the formula @expr{a+2}).
12800  A constant is a number or other numeric object (such as a constant  A constant is a number or other numeric object (such as a constant
12801  error form or modulo form), or a vector all of whose  error form or modulo form), or a vector all of whose
12802  elements are constant.@refill  elements are constant.
12803    
12804  @kindex m D  @kindex m D
12805  @pindex calc-default-simplify-mode  @pindex calc-default-simplify-mode
12806  The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the  The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the
12807  default simplifications for all formulas.  This includes many easy and  default simplifications for all formulas.  This includes many easy and
12808  fast algebraic simplifications such as @cite{a+0} to @cite{a}, and  fast algebraic simplifications such as @expr{a+0} to @expr{a}, and
12809  @cite{a + 2 a} to @cite{3 a}, as well as evaluating functions like  @expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like
12810  @cite{@t{deriv}(x^2, x)} to @cite{2 x}.  @texline @t{deriv}@expr{(x^2,x)}
12811    @infoline @expr{@t{deriv}(x^2, x)}
12812    to @expr{2 x}.
12813    
12814  @kindex m B  @kindex m B
12815  @pindex calc-bin-simplify-mode  @pindex calc-bin-simplify-mode
# Line 12681  simplification; it applies the command @ Line 12840  simplification; it applies the command @
12840  (@code{calc-simplify-units}), which in turn  (@code{calc-simplify-units}), which in turn
12841  is a superset of @kbd{a s}.  In this mode, variable names which  is a superset of @kbd{a s}.  In this mode, variable names which
12842  are identifiable as unit names (like @samp{mm} for ``millimeters'')  are identifiable as unit names (like @samp{mm} for ``millimeters'')
12843  are simplified with their unit definitions in mind.@refill  are simplified with their unit definitions in mind.
12844    
12845  A common technique is to set the simplification mode down to the lowest  A common technique is to set the simplification mode down to the lowest
12846  amount of simplification you will allow to be applied automatically, then  amount of simplification you will allow to be applied automatically, then
12847  use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to  use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to
12848  perform higher types of simplifications on demand.  @xref{Algebraic  perform higher types of simplifications on demand.  @xref{Algebraic
12849  Definitions}, for another sample use of no-simplification mode.@refill  Definitions}, for another sample use of no-simplification mode.
12850    
12851  @node Declarations, Display Modes, Simplification Modes, Mode Settings  @node Declarations, Display Modes, Simplification Modes, Mode Settings
12852  @section Declarations  @section Declarations
# Line 12949  The value is a constant with respect to Line 13108  The value is a constant with respect to
13108  Calc does not check the declarations for a variable when you store  Calc does not check the declarations for a variable when you store
13109  a value in it.  However, storing @i{-3.5} in a variable that has  a value in it.  However, storing @i{-3.5} in a variable that has
13110  been declared @code{pos}, @code{int}, or @code{matrix} may have  been declared @code{pos}, @code{int}, or @code{matrix} may have
13111  unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @cite{3.5}  unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5}
13112  if it substitutes the value first, or to @cite{-3.5} if @code{x}  if it substitutes the value first, or to @expr{-3.5} if @code{x}
13113  was declared @code{pos} and the formula @samp{sqrt(x^2)} is  was declared @code{pos} and the formula @samp{sqrt(x^2)} is
13114  simplified to @samp{x} before the value is substituted.  Before  simplified to @samp{x} before the value is substituted.  Before
13115  using a variable for a new purpose, it is best to use @kbd{s d}  using a variable for a new purpose, it is best to use @kbd{s d}
# Line 13018  includes integers, fractions, floats, re Line 13177  includes integers, fractions, floats, re
13177  @end ignore  @end ignore
13178  @tindex dimag  @tindex dimag
13179  The @code{dimag} function checks if its argument is imaginary,  The @code{dimag} function checks if its argument is imaginary,
13180  i.e., is mathematically equal to a real number times @cite{i}.  i.e., is mathematically equal to a real number times @expr{i}.
13181    
13182  @ignore  @ignore
13183  @starindex  @starindex
# Line 13036  The @code{dpos} function checks for posi Line 13195  The @code{dpos} function checks for posi
13195  The @code{dneg} function checks for negative reals.  The @code{dnonneg}  The @code{dneg} function checks for negative reals.  The @code{dnonneg}
13196  function checks for nonnegative reals, i.e., reals greater than or  function checks for nonnegative reals, i.e., reals greater than or
13197  equal to zero.  Note that the @kbd{a s} command can simplify an  equal to zero.  Note that the @kbd{a s} command can simplify an
13198  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
13199  @kbd{a s} is effectively applied to all conditions in rewrite rules,  @kbd{a s} is effectively applied to all conditions in rewrite rules,
13200  so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg}  so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg}
13201  are rarely necessary.  are rarely necessary.
# Line 13105  The commands in this section are two-key Line 13264  The commands in this section are two-key
13264  (@code{calc-line-breaking}) commands are described elsewhere;  (@code{calc-line-breaking}) commands are described elsewhere;
13265  @pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.  @pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
13266  Display formats for vectors and matrices are also covered elsewhere;  Display formats for vectors and matrices are also covered elsewhere;
13267  @pxref{Vector and Matrix Formats}.@refill  @pxref{Vector and Matrix Formats}.
13268    
13269  One thing all display modes have in common is their treatment of the  One thing all display modes have in common is their treatment of the
13270  @kbd{H} prefix.  This prefix causes any mode command that would normally  @kbd{H} prefix.  This prefix causes any mode command that would normally
# Line 13165  binary, octal, hexadecimal, and decimal Line 13324  binary, octal, hexadecimal, and decimal
13324  respectively.  Numbers can always be entered in any radix, though the  respectively.  Numbers can always be entered in any radix, though the
13325  current radix is used as a default if you press @kbd{#} without any initial  current radix is used as a default if you press @kbd{#} without any initial
13326  digits.  A number entered without a @kbd{#} is @emph{always} interpreted  digits.  A number entered without a @kbd{#} is @emph{always} interpreted
13327  as decimal.@refill  as decimal.
13328    
13329  @kindex d r  @kindex d r
13330  @pindex calc-radix  @pindex calc-radix
# Line 13180  Integers normally are displayed with how Line 13339  Integers normally are displayed with how
13339  represent the integer and no more.  The @kbd{d z} (@code{calc-leading-zeros})  represent the integer and no more.  The @kbd{d z} (@code{calc-leading-zeros})
13340  command causes integers to be padded out with leading zeros according to the  command causes integers to be padded out with leading zeros according to the
13341  current binary word size.  (@xref{Binary Functions}, for a discussion of  current binary word size.  (@xref{Binary Functions}, for a discussion of
13342  word size.)  If the absolute value of the word size is @cite{w}, all integers  word size.)  If the absolute value of the word size is @expr{w}, all integers
13343  are displayed with at least enough digits to represent @c{$2^w-1$}  are displayed with at least enough digits to represent
13344  @cite{(2^w)-1} in the  @texline @tmath{2^w-1}
13345  current radix.  (Larger integers will still be displayed in their entirety.)  @infoline @expr{(2^w)-1}
13346    in the current radix.  (Larger integers will still be displayed in their
13347    entirety.)
13348    
13349  @node Grouping Digits, Float Formats, Radix Modes, Display Modes  @node Grouping Digits, Float Formats, Radix Modes, Display Modes
13350  @subsection Grouping Digits  @subsection Grouping Digits
# Line 13202  separated by commas. Line 13363  separated by commas.
13363  The @kbd{d g} command toggles grouping on and off.  The @kbd{d g} command toggles grouping on and off.
13364  With a numerix prefix of 0, this command displays the current state of  With a numerix prefix of 0, this command displays the current state of
13365  the grouping flag; with an argument of minus one it disables grouping;  the grouping flag; with an argument of minus one it disables grouping;
13366  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}
13367  digits.  For floating-point numbers, grouping normally occurs only  digits.  For floating-point numbers, grouping normally occurs only
13368  before the decimal point.  A negative prefix argument @cite{-N} enables  before the decimal point.  A negative prefix argument @expr{-N} enables
13369  grouping every @cite{N} digits both before and after the decimal point.@refill  grouping every @expr{N} digits both before and after the decimal point.
13370    
13371  @kindex d ,  @kindex d ,
13372  @pindex calc-group-char  @pindex calc-group-char
# Line 13298  numbers, and commas to separate elements Line 13459  numbers, and commas to separate elements
13459  There are three supported notations for complex numbers in rectangular  There are three supported notations for complex numbers in rectangular
13460  form.  The default is as a pair of real numbers enclosed in parentheses  form.  The default is as a pair of real numbers enclosed in parentheses
13461  and separated by a comma: @samp{(a,b)}.  The @kbd{d c}  and separated by a comma: @samp{(a,b)}.  The @kbd{d c}
13462  (@code{calc-complex-notation}) command selects this style.@refill  (@code{calc-complex-notation}) command selects this style.
13463    
13464  @kindex d i  @kindex d i
13465  @pindex calc-i-notation  @pindex calc-i-notation
# Line 13307  and separated by a comma: @samp{(a,b)}. Line 13468  and separated by a comma: @samp{(a,b)}.
13468  The other notations are @kbd{d i} (@code{calc-i-notation}), in which  The other notations are @kbd{d i} (@code{calc-i-notation}), in which
13469  numbers are displayed in @samp{a+bi} form, and @kbd{d j}  numbers are displayed in @samp{a+bi} form, and @kbd{d j}
13470  (@code{calc-j-notation}) which displays the form @samp{a+bj} preferred  (@code{calc-j-notation}) which displays the form @samp{a+bj} preferred
13471  in some disciplines.@refill  in some disciplines.
13472    
13473  @cindex @code{i} variable  @cindex @code{i} variable
13474  @vindex i  @vindex i
# Line 13318  this formula and you have not changed th Line 13479  this formula and you have not changed th
13479  will be interpreted as @samp{(0,1)} and the formula will be simplified  will be interpreted as @samp{(0,1)} and the formula will be simplified
13480  to @samp{(2,3)}.  Other commands (like @code{calc-sin}) will @emph{not}  to @samp{(2,3)}.  Other commands (like @code{calc-sin}) will @emph{not}
13481  interpret the formula @samp{2 + 3 * i} as a complex number.  interpret the formula @samp{2 + 3 * i} as a complex number.
13482  @xref{Variables}, under ``special constants.''@refill  @xref{Variables}, under ``special constants.''
13483    
13484  @node Fraction Formats, HMS Formats, Complex Formats, Display Modes  @node Fraction Formats, HMS Formats, Complex Formats, Display Modes
13485  @subsection Fraction Formats  @subsection Fraction Formats
# Line 13346  a number.  For example:  @samp{:10} or @ Line 13507  a number.  For example:  @samp{:10} or @
13507  Calc adjusts all fractions that are displayed to have the specified  Calc adjusts all fractions that are displayed to have the specified
13508  denominator, if possible.  Otherwise it adjusts the denominator to  denominator, if possible.  Otherwise it adjusts the denominator to
13509  be a multiple of the specified value.  For example, in @samp{:6} mode  be a multiple of the specified value.  For example, in @samp{:6} mode
13510  the fraction @cite{1:6} will be unaffected, but @cite{2:3} will be  the fraction @expr{1:6} will be unaffected, but @expr{2:3} will be
13511  displayed as @cite{4:6}, @cite{1:2} will be displayed as @cite{3:6},  displayed as @expr{4:6}, @expr{1:2} will be displayed as @expr{3:6},
13512  and @cite{1:8} will be displayed as @cite{3:24}.  Integers are also  and @expr{1:8} will be displayed as @expr{3:24}.  Integers are also
13513  affected by this mode:  3 is displayed as @cite{18:6}.  Note that the  affected by this mode:  3 is displayed as @expr{18:6}.  Note that the
13514  format @samp{:1} writes fractions the same as @samp{:}, but it writes  format @samp{:1} writes fractions the same as @samp{:}, but it writes
13515  integers as @cite{n:1}.  integers as @expr{n:1}.
13516    
13517  The fraction format does not affect the way fractions or integers are  The fraction format does not affect the way fractions or integers are
13518  stored, only the way they appear on the screen.  The fraction format  stored, only the way they appear on the screen.  The fraction format
# Line 13710  operations.  This is similar to the Emac Line 13871  operations.  This is similar to the Emac
13871  that the values below the @samp{.} are @emph{visible}, just temporarily  that the values below the @samp{.} are @emph{visible}, just temporarily
13872  frozen.  This feature allows you to keep several independent calculations  frozen.  This feature allows you to keep several independent calculations
13873  running at once in different parts of the stack, or to apply a certain  running at once in different parts of the stack, or to apply a certain
13874  command to an element buried deep in the stack.@refill  command to an element buried deep in the stack.
13875    
13876  Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor  Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor
13877  is on.  Thus, this line and all those below it become hidden.  To un-hide  is on.  Thus, this line and all those below it become hidden.  To un-hide
13878  these lines, move down to the end of the buffer and press @w{@kbd{d t}}.  these lines, move down to the end of the buffer and press @w{@kbd{d t}}.
13879  With a positive numeric prefix argument @cite{n}, @kbd{d t} hides the  With a positive numeric prefix argument @expr{n}, @kbd{d t} hides the
13880  bottom @cite{n} values in the buffer.  With a negative argument, it hides  bottom @expr{n} values in the buffer.  With a negative argument, it hides
13881  all but the top @cite{n} values.  With an argument of zero, it hides zero  all but the top @expr{n} values.  With an argument of zero, it hides zero
13882  values, i.e., moves the @samp{.} all the way down to the bottom.@refill  values, i.e., moves the @samp{.} all the way down to the bottom.
13883    
13884  @kindex d [  @kindex d [
13885  @pindex calc-truncate-up  @pindex calc-truncate-up
# Line 13726  values, i.e., moves the @samp{.} all the Line 13887  values, i.e., moves the @samp{.} all the
13887  @pindex calc-truncate-down  @pindex calc-truncate-down
13888  The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]}  The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]}
13889  (@code{calc-truncate-down}) commands move the @samp{.} up or down one  (@code{calc-truncate-down}) commands move the @samp{.} up or down one
13890  line at a time (or several lines with a prefix argument).@refill  line at a time (or several lines with a prefix argument).
13891    
13892  @node Justification, Labels, Truncating the Stack, Display Modes  @node Justification, Labels, Truncating the Stack, Display Modes
13893  @subsection Justification  @subsection Justification
# Line 13743  control this arrangement by typing @kbd{ Line 13904  control this arrangement by typing @kbd{
13904  @kbd{d >} (@code{calc-right-justify}), or @kbd{d =}  @kbd{d >} (@code{calc-right-justify}), or @kbd{d =}
13905  (@code{calc-center-justify}).  For example, in right-justification mode,  (@code{calc-center-justify}).  For example, in right-justification mode,
13906  stack entries are displayed flush-right against the right edge of the  stack entries are displayed flush-right against the right edge of the
13907  window.@refill  window.
13908    
13909  If you change the width of the Calculator window you may have to type  If you change the width of the Calculator window you may have to type
13910  @kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered  @kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered
# Line 13933  One slight ambiguity of Big notation is Line 14094  One slight ambiguity of Big notation is
14094  @end example  @end example
14095    
14096  @noindent  @noindent
14097  can represent either the negative rational number @cite{-3:4}, or the  can represent either the negative rational number @expr{-3:4}, or the
14098  actual expression @samp{-(3/4)}; but the latter formula would normally  actual expression @samp{-(3/4)}; but the latter formula would normally
14099  never be displayed because it would immediately be evaluated to  never be displayed because it would immediately be evaluated to
14100  @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
14101  typical use.  typical use.
14102    
14103  Non-decimal numbers are displayed with subscripts.  Thus there is no  Non-decimal numbers are displayed with subscripts.  Thus there is no
# Line 14061  and displayed in @TeX{} notation, as in Line 14222  and displayed in @TeX{} notation, as in
14222  Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these  Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
14223  should be omitted when interfacing with Calc.  To Calc, the @samp{$} sign  should be omitted when interfacing with Calc.  To Calc, the @samp{$} sign
14224  has the same meaning it always does in algebraic formulas (a reference to  has the same meaning it always does in algebraic formulas (a reference to
14225  an existing entry on the stack).@refill  an existing entry on the stack).
14226    
14227  Complex numbers are displayed as in @samp{3 + 4i}.  Fractions and  Complex numbers are displayed as in @samp{3 + 4i}.  Fractions and
14228  quotients are written using @code{\over};  quotients are written using @code{\over};
# Line 14073  ceiling functions are written with @code Line 14234  ceiling functions are written with @code
14234  The words @code{\left} and @code{\right} are ignored when reading  The words @code{\left} and @code{\right} are ignored when reading
14235  formulas in @TeX{} mode.  Both @code{inf} and @code{uinf} are written  formulas in @TeX{} mode.  Both @code{inf} and @code{uinf} are written
14236  as @code{\infty}; when read, @code{\infty} always translates to  as @code{\infty}; when read, @code{\infty} always translates to
14237  @code{inf}.@refill  @code{inf}.
14238    
14239  Function calls are written the usual way, with the function name followed  Function calls are written the usual way, with the function name followed
14240  by the arguments in parentheses.  However, functions for which @TeX{} has  by the arguments in parentheses.  However, functions for which @TeX{} has
# Line 14081  special names (like @code{\sin}) will us Line 14242  special names (like @code{\sin}) will us
14242  parentheses for very simple arguments.  During input, curly braces and  parentheses for very simple arguments.  During input, curly braces and
14243  parentheses work equally well for grouping, but when the document is  parentheses work equally well for grouping, but when the document is
14244  formatted the curly braces will be invisible.  Thus the printed result is  formatted the curly braces will be invisible.  Thus the printed result is
14245  @c{$\sin{2 x}$}  @texline @tmath{\sin{2 x}}
14246  @cite{sin 2x} but @c{$\sin(2 + x)$}  @infoline @expr{sin 2x}
14247  @cite{sin(2 + x)}.  but
14248    @texline @tmath{\sin(2 + x)}.
14249    @infoline @expr{sin(2 + x)}.
14250    
14251  Function and variable names not treated specially by @TeX{} are simply  Function and variable names not treated specially by @TeX{} are simply
14252  written out as-is, which will cause them to come out in italic letters  written out as-is, which will cause them to come out in italic letters
# Line 14244  sin(a^2 / b_i) Line 14407  sin(a^2 / b_i)
14407  @end group  @end group
14408  @end example  @end example
14409  @tex  @tex
 \let\rm\goodrm  
14410  $$ \sin\left( a^2 \over b_i \right) $$  $$ \sin\left( a^2 \over b_i \right) $$
14411  @end tex  @end tex
14412  @sp 1  @sp 1
# Line 14282  $$ [|a|, \left| a \over b \right|, Line 14444  $$ [|a|, \left| a \over b \right|,
14444  @end group  @end group
14445  @end example  @end example
14446  @tex  @tex
14447  \turnoffactive\let\rm\goodrm  \turnoffactive
14448  $$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$  $$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$
14449  @end tex  @end tex
14450  @sp 2  @sp 2
# Line 14300  First with plain @kbd{d T}, then with @k Line 14462  First with plain @kbd{d T}, then with @k
14462  @end group  @end group
14463  @end example  @end example
14464  @tex  @tex
 \let\rm\goodrm  
14465  $$ [f(a), foo(bar), \sin{\pi}] $$  $$ [f(a), foo(bar), \sin{\pi}] $$
14466  $$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$  $$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$
14467  $$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$  $$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$
# Line 14453  written @code{Pi}, @code{E}, @code{I}, @ Line 14614  written @code{Pi}, @code{E}, @code{I}, @
14614  Mathematica mode.  Mathematica mode.
14615  Non-decimal numbers are written, e.g., @samp{16^^7fff}.  Floating-point  Non-decimal numbers are written, e.g., @samp{16^^7fff}.  Floating-point
14616  numbers in scientific notation are written @samp{1.23*10.^3}.  numbers in scientific notation are written @samp{1.23*10.^3}.
14617  Subscripts use double square brackets: @samp{a[[i]]}.@refill  Subscripts use double square brackets: @samp{a[[i]]}.
14618    
14619  @node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes  @node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes
14620  @subsection Maple Language Mode  @subsection Maple Language Mode
# Line 14594  mod    400 Line 14755  mod    400
14755  =>      40  =>      40
14756  @end example  @end example
14757    
14758  The general rule is that if an operator with precedence @cite{n}  The general rule is that if an operator with precedence @expr{n}
14759  occurs as an argument to an operator with precedence @cite{m}, then  occurs as an argument to an operator with precedence @expr{m}, then
14760  the argument is enclosed in parentheses if @cite{n < m}.  Top-level  the argument is enclosed in parentheses if @expr{n < m}.  Top-level
14761  expressions and expressions which are function arguments, vector  expressions and expressions which are function arguments, vector
14762  components, etc., are formatted with precedence zero (so that they  components, etc., are formatted with precedence zero (so that they
14763  normally never get additional parentheses).  normally never get additional parentheses).
# Line 15579  Command is @kbd{m p}. Line 15740  Command is @kbd{m p}.
15740    
15741  @item  @item
15742  Matrix/scalar mode.  Default value is @i{-1}.  Value is 0 for scalar  Matrix/scalar mode.  Default value is @i{-1}.  Value is 0 for scalar
15743  mode, @i{-2} for matrix mode, or @var{N} for @c{$N\times N$}  mode, @i{-2} for matrix mode, or @var{N} for
15744  @var{N}x@var{N} matrix mode.  Command is @kbd{m v}.  @texline @tmath{N\times N}
15745    @infoline @var{N}x@var{N}
15746    matrix mode.  Command is @kbd{m v}.
15747    
15748  @item  @item
15749  Simplification mode.  Default is 1.  Value is @i{-1} for off (@kbd{m O}),  Simplification mode.  Default is 1.  Value is @i{-1} for off (@kbd{m O}),
# Line 15906  error form to a plain symbolic formula ( Line 16069  error form to a plain symbolic formula (
16069  work, for the same reasons just mentioned for vectors.  Instead you must  work, for the same reasons just mentioned for vectors.  Instead you must
16070  write @samp{(a +/- b) + (c +/- 0)}.  write @samp{(a +/- b) + (c +/- 0)}.
16071    
16072  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},
16073  or if one argument is a modulo form and the other a plain number, the  or if one argument is a modulo form and the other a plain number, the
16074  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
16075  the two values.  the two values.
16076    
16077  If both arguments of @kbd{+} are intervals, the result is an interval  If both arguments of @kbd{+} are intervals, the result is an interval
# Line 15964  whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @s Line 16127  whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @s
16127  @end ignore  @end ignore
16128  @tindex /  @tindex /
16129  The @kbd{/} (@code{calc-divide}) command divides two numbers.  When  The @kbd{/} (@code{calc-divide}) command divides two numbers.  When
16130  dividing a scalar @cite{B} by a square matrix @cite{A}, the computation  dividing a scalar @expr{B} by a square matrix @expr{A}, the computation
16131  performed is @cite{B} times the inverse of @cite{A}.  This also occurs  performed is @expr{B} times the inverse of @expr{A}.  This also occurs
16132  if @cite{B} is itself a vector or matrix, in which case the effect is  if @expr{B} is itself a vector or matrix, in which case the effect is
16133  to solve the set of linear equations represented by @cite{B}.  If @cite{B}  to solve the set of linear equations represented by @expr{B}.  If @expr{B}
16134  is a matrix with the same number of rows as @cite{A}, or a plain vector  is a matrix with the same number of rows as @expr{A}, or a plain vector
16135  (which is interpreted here as a column vector), then the equation  (which is interpreted here as a column vector), then the equation
16136  @cite{A X = B} is solved for the vector or matrix @cite{X}.  Otherwise,  @expr{A X = B} is solved for the vector or matrix @expr{X}.  Otherwise,
16137  if @cite{B} is a non-square matrix with the same number of @emph{columns}  if @expr{B} is a non-square matrix with the same number of @emph{columns}
16138  as @cite{A}, the equation @cite{X A = B} is solved.  If you wish a vector  as @expr{A}, the equation @expr{X A = B} is solved.  If you wish a vector
16139  @cite{B} to be interpreted as a row vector to be solved as @cite{X A = B},  @expr{B} to be interpreted as a row vector to be solved as @expr{X A = B},
16140  make it into a one-row matrix with @kbd{C-u 1 v p} first.  To force a  make it into a one-row matrix with @kbd{C-u 1 v p} first.  To force a
16141  left-handed solution with a square matrix @cite{B}, transpose @cite{A} and  left-handed solution with a square matrix @expr{B}, transpose @expr{A} and
16142  @cite{B} before dividing, then transpose the result.  @expr{B} before dividing, then transpose the result.
16143    
16144  HMS forms can be divided by real numbers or by other HMS forms.  Error  HMS forms can be divided by real numbers or by other HMS forms.  Error
16145  forms can be divided in any combination of ways.  Modulo forms where both  forms can be divided in any combination of ways.  Modulo forms where both
# Line 16026  operation when the arguments are integer Line 16189  operation when the arguments are integer
16189  @tindex %  @tindex %
16190  The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'')  The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'')
16191  operation.  Mathematically, @samp{a%b = a - (a\b)*b}, and is defined  operation.  Mathematically, @samp{a%b = a - (a\b)*b}, and is defined
16192  for all real numbers @cite{a} and @cite{b} (except @cite{b=0}).  For  for all real numbers @expr{a} and @expr{b} (except @expr{b=0}).  For
16193  positive @cite{b}, the result will always be between 0 (inclusive) and  positive @expr{b}, the result will always be between 0 (inclusive) and
16194  @cite{b} (exclusive).  Modulo does not work for HMS forms and error forms.  @expr{b} (exclusive).  Modulo does not work for HMS forms and error forms.
16195  If @cite{a} is a modulo form, its modulo is changed to @cite{b}, which  If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which
16196  must be positive real number.  must be positive real number.
16197    
16198  @kindex :  @kindex :
# Line 16083  zero depending on the sign of @samp{a}. Line 16246  zero depending on the sign of @samp{a}.
16246  @tindex inv  @tindex inv
16247  @cindex Reciprocal  @cindex Reciprocal
16248  The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the  The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the
16249  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
16250  matrix, it computes the inverse of that matrix.  matrix, it computes the inverse of that matrix.
16251    
16252  @kindex Q  @kindex Q
# Line 16098  complex number whose form is determined Line 16261  complex number whose form is determined
16261  @tindex hypot  @tindex hypot
16262  The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square  The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square
16263  root of the sum of the squares of two numbers.  That is, @samp{hypot(a,b)}  root of the sum of the squares of two numbers.  That is, @samp{hypot(a,b)}
16264  is the length of the hypotenuse of a right triangle with sides @cite{a}  is the length of the hypotenuse of a right triangle with sides @expr{a}
16265  and @cite{b}.  If the arguments are complex numbers, their squared  and @expr{b}.  If the arguments are complex numbers, their squared
16266  magnitudes are used.  magnitudes are used.
16267    
16268  @kindex f Q  @kindex f Q
# Line 16124  The @kbd{f n} (@code{calc-min}) [@code{m Line 16287  The @kbd{f n} (@code{calc-min}) [@code{m
16287  respectively.  These commands also work on HMS forms, date forms,  respectively.  These commands also work on HMS forms, date forms,
16288  intervals, and infinities.  (In algebraic expressions, these functions  intervals, and infinities.  (In algebraic expressions, these functions
16289  take any number of arguments and return the maximum or minimum among  take any number of arguments and return the maximum or minimum among
16290  all the arguments.)@refill  all the arguments.)
16291    
16292  @kindex f M  @kindex f M
16293  @kindex f X  @kindex f X
# Line 16133  all the arguments.)@refill Line 16296  all the arguments.)@refill
16296  @pindex calc-xpon-part  @pindex calc-xpon-part
16297  @tindex xpon  @tindex xpon
16298  The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts  The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts
16299  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}
16300  (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part  (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part
16301  @cite{e}.  The original number is equal to @c{$m \times 10^e$}  @expr{e}.  The original number is equal to
16302  @cite{m * 10^e},  @texline @tmath{m \times 10^e},
16303  where @cite{m} is in the interval @samp{[1.0 ..@: 10.0)} except that  @infoline @expr{m * 10^e},
16304  @cite{m=e=0} if the original number is zero.  For integers  where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that
16305    @expr{m=e=0} if the original number is zero.  For integers
16306  and fractions, @code{mant} returns the number unchanged and @code{xpon}  and fractions, @code{mant} returns the number unchanged and @code{xpon}
16307  returns zero.  The @kbd{v u} (@code{calc-unpack}) command can also be  returns zero.  The @kbd{v u} (@code{calc-unpack}) command can also be
16308  used to ``unpack'' a floating-point number; this produces an integer  used to ``unpack'' a floating-point number; this produces an integer
16309  mantissa and exponent, with the constraint that the mantissa is not  mantissa and exponent, with the constraint that the mantissa is not
16310  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).
16311    
16312  @kindex f S  @kindex f S
16313  @pindex calc-scale-float  @pindex calc-scale-float
# Line 16152  The @kbd{f S} (@code{calc-scale-float}) Line 16316  The @kbd{f S} (@code{calc-scale-float})
16316  by a given power of ten.  Thus, @samp{scf(mant(x), xpon(x)) = x} for any  by a given power of ten.  Thus, @samp{scf(mant(x), xpon(x)) = x} for any
16317  real @samp{x}.  The second argument must be an integer, but the first  real @samp{x}.  The second argument must be an integer, but the first
16318  may actually be any numeric value.  For example, @samp{scf(5,-2) = 0.05}  may actually be any numeric value.  For example, @samp{scf(5,-2) = 0.05}
16319  or @samp{1:20} depending on the current Fraction Mode.@refill  or @samp{1:20} depending on the current Fraction Mode.
16320    
16321  @kindex f [  @kindex f [
16322  @kindex f ]  @kindex f ]
# Line 16167  floating-point numbers, the change is by Line 16331  floating-point numbers, the change is by
16331  For example, incrementing @samp{12.3456} when the current precision  For example, incrementing @samp{12.3456} when the current precision
16332  is 6 digits yields @samp{12.3457}.  If the current precision had been  is 6 digits yields @samp{12.3457}.  If the current precision had been
16333  8 digits, the result would have been @samp{12.345601}.  Incrementing  8 digits, the result would have been @samp{12.345601}.  Incrementing
16334  @samp{0.0} produces @c{$10^{-p}$}  @samp{0.0} produces
16335  @cite{10^-p}, where @cite{p} is the current  @texline @tmath{10^{-p}},
16336    @infoline @expr{10^-p},
16337    where @expr{p} is the current
16338  precision.  These operations are defined only on integers and floats.  precision.  These operations are defined only on integers and floats.
16339  With numeric prefix arguments, they change the number by @cite{n} units.  With numeric prefix arguments, they change the number by @expr{n} units.
16340    
16341  Note that incrementing followed by decrementing, or vice-versa, will  Note that incrementing followed by decrementing, or vice-versa, will
16342  almost but not quite always cancel out.  Suppose the precision is  almost but not quite always cancel out.  Suppose the precision is
# Line 16207  expressed as an integer-valued floating- Line 16373  expressed as an integer-valued floating-
16373  The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command  The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command
16374  truncates a real number to the next lower integer, i.e., toward minus  truncates a real number to the next lower integer, i.e., toward minus
16375  infinity.  Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces  infinity.  Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
16376  @i{-4}.@refill  @i{-4}.
16377    
16378  @kindex I F  @kindex I F
16379  @pindex calc-ceiling  @pindex calc-ceiling
# Line 16219  infinity.  Thus @kbd{3.6 F} produces 3, Line 16385  infinity.  Thus @kbd{3.6 F} produces 3,
16385  @kindex H I F  @kindex H I F
16386  The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}]  The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}]
16387  command truncates toward positive infinity.  Thus @kbd{3.6 I F} produces  command truncates toward positive infinity.  Thus @kbd{3.6 I F} produces
16388  4, and @kbd{_3.6 I F} produces @i{-3}.@refill  4, and @kbd{_3.6 I F} produces @i{-3}.
16389    
16390  @kindex R  @kindex R
16391  @pindex calc-round  @pindex calc-round
# Line 16233  The @kbd{R} (@code{calc-round}) [@code{r Line 16399  The @kbd{R} (@code{calc-round}) [@code{r
16399  rounds to the nearest integer.  When the fractional part is .5 exactly,  rounds to the nearest integer.  When the fractional part is .5 exactly,
16400  this command rounds away from zero.  (All other rounding in the  this command rounds away from zero.  (All other rounding in the
16401  Calculator uses this convention as well.)  Thus @kbd{3.5 R} produces 4  Calculator uses this convention as well.)  Thus @kbd{3.5 R} produces 4
16402  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 @i{-4}.
16403    
16404  @kindex I R  @kindex I R
16405  @pindex calc-trunc  @pindex calc-trunc
# Line 16246  but @kbd{3.4 R} produces 3; @kbd{_3.5 R} Line 16412  but @kbd{3.4 R} produces 3; @kbd{_3.5 R}
16412  The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}]  The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}]
16413  command truncates toward zero.  In other words, it ``chops off''  command truncates toward zero.  In other words, it ``chops off''
16414  everything after the decimal point.  Thus @kbd{3.6 I R} produces 3 and  everything after the decimal point.  Thus @kbd{3.6 I R} produces 3 and
16415  @kbd{_3.6 I R} produces @i{-3}.@refill  @kbd{_3.6 I R} produces @i{-3}.
16416    
16417  These functions may not be applied meaningfully to error forms, but they  These functions may not be applied meaningfully to error forms, but they
16418  do work for intervals.  As a convenience, applying @code{floor} to a  do work for intervals.  As a convenience, applying @code{floor} to a
# Line 16284  subtle point here is that the number bei Line 16450  subtle point here is that the number bei
16450  already have been rounded to the current precision before @code{rounde}  already have been rounded to the current precision before @code{rounde}
16451  begins.  For example, @samp{rounde(2.500001)} with a current precision  begins.  For example, @samp{rounde(2.500001)} with a current precision
16452  of 6 will incorrectly, or at least surprisingly, yield 2 because the  of 6 will incorrectly, or at least surprisingly, yield 2 because the
16453  argument will first have been rounded down to @cite{2.5} (which  argument will first have been rounded down to @expr{2.5} (which
16454  @code{rounde} sees as an exact tie between 2 and 3).  @code{rounde} sees as an exact tie between 2 and 3).
16455    
16456  Each of these functions, when written in algebraic formulas, allows  Each of these functions, when written in algebraic formulas, allows
# Line 16298  no second argument at all. Line 16464  no second argument at all.
16464  @cindex Fractional part of a number  @cindex Fractional part of a number
16465  To compute the fractional part of a number (i.e., the amount which, when  To compute the fractional part of a number (i.e., the amount which, when
16466  added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n}  added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n}
16467  modulo 1 using the @code{%} command.@refill  modulo 1 using the @code{%} command.
16468    
16469  Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm),  Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm),
16470  and @kbd{f Q} (integer square root) commands, which are analogous to  and @kbd{f Q} (integer square root) commands, which are analogous to
# Line 16313  arguments and return the result rounded Line 16479  arguments and return the result rounded
16479  @pindex calc-conj  @pindex calc-conj
16480  @tindex conj  @tindex conj
16481  The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the  The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the
16482  complex conjugate of a number.  For complex number @cite{a+bi}, the  complex conjugate of a number.  For complex number @expr{a+bi}, the
16483  complex conjugate is @cite{a-bi}.  If the argument is a real number,  complex conjugate is @expr{a-bi}.  If the argument is a real number,
16484  this command leaves it the same.  If the argument is a vector or matrix,  this command leaves it the same.  If the argument is a vector or matrix,
16485  this command replaces each element by its complex conjugate.  this command replaces each element by its complex conjugate.
16486    
# Line 16324  this command replaces each element by it Line 16490  this command replaces each element by it
16490  The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the  The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the
16491  ``argument'' or polar angle of a complex number.  For a number in polar  ``argument'' or polar angle of a complex number.  For a number in polar
16492  notation, this is simply the second component of the pair  notation, this is simply the second component of the pair
16493  `@t{(}@var{r}@t{;}@c{$\theta$}  @texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}'.
16494  @var{theta}@t{)}'.  @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'.
16495  The result is expressed according to the current angular mode and will  The result is expressed according to the current angular mode and will
16496  be in the range @i{-180} degrees (exclusive) to @i{+180} degrees  be in the range @i{-180} degrees (exclusive) to @i{+180} degrees
16497  (inclusive), or the equivalent range in radians.@refill  (inclusive), or the equivalent range in radians.
16498    
16499  @pindex calc-imaginary  @pindex calc-imaginary
16500  The @code{calc-imaginary} command multiplies the number on the  The @code{calc-imaginary} command multiplies the number on the
16501  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
16502  command is not normally bound to a key in Calc, but it is available  command is not normally bound to a key in Calc, but it is available
16503  on the @key{IMAG} button in Keypad Mode.  on the @key{IMAG} button in Keypad Mode.
16504    
# Line 16342  on the @key{IMAG} button in Keypad Mode. Line 16508  on the @key{IMAG} button in Keypad Mode.
16508  The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number  The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number
16509  by its real part.  This command has no effect on real numbers.  (As an  by its real part.  This command has no effect on real numbers.  (As an
16510  added convenience, @code{re} applied to a modulo form extracts  added convenience, @code{re} applied to a modulo form extracts
16511  the value part.)@refill  the value part.)
16512    
16513  @kindex f i  @kindex f i
16514  @pindex calc-im  @pindex calc-im
16515  @tindex im  @tindex im
16516  The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number  The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number
16517  by its imaginary part; real numbers are converted to zero.  With a vector  by its imaginary part; real numbers are converted to zero.  With a vector
16518  or matrix argument, these functions operate element-wise.@refill  or matrix argument, these functions operate element-wise.
16519    
16520  @ignore  @ignore
16521  @mindex v p  @mindex v p
# Line 16383  to another; they are two-key sequences b Line 16549  to another; they are two-key sequences b
16549  @tindex pfloat  @tindex pfloat
16550  The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the  The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the
16551  number on the top of the stack to floating-point form.  For example,  number on the top of the stack to floating-point form.  For example,
16552  @cite{23} is converted to @cite{23.0}, @cite{3:2} is converted to  @expr{23} is converted to @expr{23.0}, @expr{3:2} is converted to
16553  @cite{1.5}, and @cite{2.3} is left the same.  If the value is a composite  @expr{1.5}, and @expr{2.3} is left the same.  If the value is a composite
16554  object such as a complex number or vector, each of the components is  object such as a complex number or vector, each of the components is
16555  converted to floating-point.  If the value is a formula, all numbers  converted to floating-point.  If the value is a formula, all numbers
16556  in the formula are converted to floating-point.  Note that depending  in the formula are converted to floating-point.  Note that depending
16557  on the current floating-point precision, conversion to floating-point  on the current floating-point precision, conversion to floating-point
16558  format may lose information.@refill  format may lose information.
16559    
16560  As a special exception, integers which appear as powers or subscripts  As a special exception, integers which appear as powers or subscripts
16561  are not floated by @kbd{c f}.  If you really want to float a power,  are not floated by @kbd{c f}.  If you really want to float a power,
# Line 16442  which is analogous to @kbd{H c f} discus Line 16608  which is analogous to @kbd{H c f} discus
16608  The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a  The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a
16609  number into degrees form.  The value on the top of the stack may be an  number into degrees form.  The value on the top of the stack may be an
16610  HMS form (interpreted as degrees-minutes-seconds), or a real number which  HMS form (interpreted as degrees-minutes-seconds), or a real number which
16611  will be interpreted in radians regardless of the current angular mode.@refill  will be interpreted in radians regardless of the current angular mode.
16612    
16613  @kindex c r  @kindex c r
16614  @pindex calc-to-radians  @pindex calc-to-radians
# Line 16475  This command is equivalent to the @code{ Line 16641  This command is equivalent to the @code{
16641  functions in algebraic formulas, depending on the direction of  functions in algebraic formulas, depending on the direction of
16642  conversion.  (It uses @code{polar}, except that if the argument is  conversion.  (It uses @code{polar}, except that if the argument is
16643  already a polar complex number, it uses @code{rect} instead.  The  already a polar complex number, it uses @code{rect} instead.  The
16644  @kbd{I c p} command always uses @code{rect}.)@refill  @kbd{I c p} command always uses @code{rect}.)
16645    
16646  @kindex c c  @kindex c c
16647  @pindex calc-clean  @pindex calc-clean
# Line 16488  are normalized.  (Note that results will Line 16654  are normalized.  (Note that results will
16654  angular mode is different from the one under which the number was  angular mode is different from the one under which the number was
16655  produced!)  Integers and fractions are generally unaffected by this  produced!)  Integers and fractions are generally unaffected by this
16656  operation.  Vectors and formulas are cleaned by cleaning each component  operation.  Vectors and formulas are cleaned by cleaning each component
16657  number (i.e., pervasively).@refill  number (i.e., pervasively).
16658    
16659  If the simplification mode is set below the default level, it is raised  If the simplification mode is set below the default level, it is raised
16660  to the default level for the purposes of this command.  Thus, @kbd{c c}  to the default level for the purposes of this command.  Thus, @kbd{c c}
# Line 16809  command for this function; use @kbd{C-u Line 16975  command for this function; use @kbd{C-u
16975    
16976  There is no @code{newday} function at all because @kbd{F} [@code{floor}]  There is no @code{newday} function at all because @kbd{F} [@code{floor}]
16977  serves this purpose.  Similarly, instead of @code{incday} and  serves this purpose.  Similarly, instead of @code{incday} and
16978  @code{incweek} simply use @cite{d + n} or @cite{d + 7 n}.  @code{incweek} simply use @expr{d + n} or @expr{d + 7 n}.
16979    
16980  @xref{Basic Arithmetic}, for the @kbd{f ]} [@code{incr}] command  @xref{Basic Arithmetic}, for the @kbd{f ]} [@code{incr}] command
16981  which can adjust a date/time form by a certain number of seconds.  which can adjust a date/time form by a certain number of seconds.
# Line 16870  considered to be a holiday. Line 17036  considered to be a holiday.
17036    
17037  @item  @item
17038  Any Calc formula which evaluates to one of the above three things.  Any Calc formula which evaluates to one of the above three things.
17039  If the formula involves the variable @cite{y}, it stands for a  If the formula involves the variable @expr{y}, it stands for a
17040  yearly repeating holiday; @cite{y} will take on various year  yearly repeating holiday; @expr{y} will take on various year
17041  numbers like 1992.  For example, @samp{date(y, 12, 25)} specifies  numbers like 1992.  For example, @samp{date(y, 12, 25)} specifies
17042  Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies  Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies
17043  Thanksgiving (which is held on the fourth Thursday of November).  Thanksgiving (which is held on the fourth Thursday of November).
17044  If the formula involves the variable @cite{m}, that variable  If the formula involves the variable @expr{m}, that variable
17045  takes on month numbers from 1 to 12:  @samp{date(y, m, 15)} is  takes on month numbers from 1 to 12:  @samp{date(y, m, 15)} is
17046  a holiday that takes place on the 15th of every month.  a holiday that takes place on the 15th of every month.
17047    
# Line 17290  decrease:  @kbd{50 @key{RET} 40 b %} pro Line 17456  decrease:  @kbd{50 @key{RET} 40 b %} pro
17456  20% smaller than 50.  (The answers are different in magnitude  20% smaller than 50.  (The answers are different in magnitude
17457  because, in the first case, we're increasing by 25% of 40, but  because, in the first case, we're increasing by 25% of 40, but
17458  in the second case, we're decreasing by 20% of 50.)  The effect  in the second case, we're decreasing by 20% of 50.)  The effect
17459  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
17460  the answer to percentage form as if by @kbd{c %}.  the answer to percentage form as if by @kbd{c %}.
17461    
17462  @node Future Value, Present Value, Percentages, Financial Functions  @node Future Value, Present Value, Percentages, Financial Functions
# Line 17334  The algebraic functions @code{fv} and @c Line 17500  The algebraic functions @code{fv} and @c
17500  fourth argument, which is used as an initial lump sum in the sense  fourth argument, which is used as an initial lump sum in the sense
17501  of @code{fvl}.  In other words, @code{fv(@var{rate}, @var{n},  of @code{fvl}.  In other words, @code{fv(@var{rate}, @var{n},
17502  @var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment})  @var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment})
17503  + fvl(@var{rate}, @var{n}, @var{initial})}.@refill  + fvl(@var{rate}, @var{n}, @var{initial})}.
17504    
17505  To illustrate the relationships between these functions, we could  To illustrate the relationships between these functions, we could
17506  do the @code{fvb} calculation ``by hand'' using @code{fvl}.  The  do the @code{fvb} calculation ``by hand'' using @code{fvl}.  The
# Line 17352  are now at the ends of the periods.  The Line 17518  are now at the ends of the periods.  The
17518  as the beginning of the next, so what this really means is that we've  as the beginning of the next, so what this really means is that we've
17519  lost the payment at year zero (which contributed $1300.78), but we're  lost the payment at year zero (which contributed $1300.78), but we're
17520  now counting the payment at year five (which, since it didn't have  now counting the payment at year five (which, since it didn't have
17521  a chance to earn interest, counts as $1000).  Indeed, @cite{5569.96 =  a chance to earn interest, counts as $1000).  Indeed, @expr{5569.96 =
17522  5870.73 - 1300.78 + 1000} (give or take a bit of roundoff error).  5870.73 - 1300.78 + 1000} (give or take a bit of roundoff error).
17523    
17524  @node Present Value, Related Financial Functions, Future Value, Financial Functions  @node Present Value, Related Financial Functions, Future Value, Financial Functions
# Line 17382  considering, which is @code{fv(9%, 4, 20 Line 17548  considering, which is @code{fv(9%, 4, 20
17548  the return from leaving the money in the bank, which is  the return from leaving the money in the bank, which is
17549  @code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money  @code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money
17550  you would have to put up in advance.  The @code{pv} function  you would have to put up in advance.  The @code{pv} function
17551  finds the break-even point, @cite{x = 6479.44}, at which  finds the break-even point, @expr{x = 6479.44}, at which
17552  @code{fvl(9%, 4, 6479.44)} is also equal to 9146.26.  This is  @code{fvl(9%, 4, 6479.44)} is also equal to 9146.26.  This is
17553  the largest amount you should be willing to invest.  the largest amount you should be willing to invest.
17554    
# Line 17431  vector statistical functions like @code{ Line 17597  vector statistical functions like @code{
17597  payment arguments, each either a vector or a plain number, all these  payment arguments, each either a vector or a plain number, all these
17598  values are collected left-to-right into the complete list of payments.  values are collected left-to-right into the complete list of payments.
17599  A numeric prefix argument on the @kbd{b N} command says how many  A numeric prefix argument on the @kbd{b N} command says how many
17600  payment values or vectors to take from the stack.@refill  payment values or vectors to take from the stack.
17601    
17602  @kindex I b N  @kindex I b N
17603  @tindex npvb  @tindex npvb
# Line 17453  The @kbd{b M} (@code{calc-fin-pmt}) [@co Line 17619  The @kbd{b M} (@code{calc-fin-pmt}) [@co
17619  the amount of periodic payment necessary to amortize a loan.  the amount of periodic payment necessary to amortize a loan.
17620  Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the  Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the
17621  value of @var{payment} such that @code{pv(@var{rate}, @var{n},  value of @var{payment} such that @code{pv(@var{rate}, @var{n},
17622  @var{payment}) = @var{amount}}.@refill  @var{payment}) = @var{amount}}.
17623    
17624  @kindex I b M  @kindex I b M
17625  @tindex pmtb  @tindex pmtb
# Line 17475  Thus @code{nper(@var{rate}, @var{payment Line 17641  Thus @code{nper(@var{rate}, @var{payment
17641  the value of @var{n} such that @code{pv(@var{rate}, @var{n},  the value of @var{n} such that @code{pv(@var{rate}, @var{n},
17642  @var{payment}) = @var{amount}}.  If @var{payment} is too small  @var{payment}) = @var{amount}}.  If @var{payment} is too small
17643  ever to amortize a loan for @var{amount} at interest rate @var{rate},  ever to amortize a loan for @var{amount} at interest rate @var{rate},
17644  the @code{nper} function is left in symbolic form.@refill  the @code{nper} function is left in symbolic form.
17645    
17646  @kindex I b #  @kindex I b #
17647  @tindex nperb  @tindex nperb
17648  The @kbd{I b #} [@code{nperb}] command does the same computation  The @kbd{I b #} [@code{nperb}] command does the same computation
17649  but using @code{pvb} instead of @code{pv}.  You can give a fourth  but using @code{pvb} instead of @code{pv}.  You can give a fourth
17650  lump-sum argument to these functions, but the computation will be  lump-sum argument to these functions, but the computation will be
17651  rather slow in the four-argument case.@refill  rather slow in the four-argument case.
17652    
17653  @kindex H b #  @kindex H b #
17654  @tindex nperl  @tindex nperl
# Line 17490  The @kbd{H b #} [@code{nperl}] command d Line 17656  The @kbd{H b #} [@code{nperl}] command d
17656  using @code{pvl}.  By exchanging @var{payment} and @var{amount} you  using @code{pvl}.  By exchanging @var{payment} and @var{amount} you
17657  can also get the solution for @code{fvl}.  For example,  can also get the solution for @code{fvl}.  For example,
17658  @code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a  @code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a
17659  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.
17660    
17661  @kindex b T  @kindex b T
17662  @pindex calc-fin-rate  @pindex calc-fin-rate
# Line 17499  The @kbd{b T} (@code{calc-fin-rate}) [@c Line 17665  The @kbd{b T} (@code{calc-fin-rate}) [@c
17665  the rate of return on an investment.  This is also an inverse of @code{pv}:  the rate of return on an investment.  This is also an inverse of @code{pv}:
17666  @code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of  @code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of
17667  @var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) =  @var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) =
17668  @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%}.
17669    
17670  @kindex I b T  @kindex I b T
17671  @kindex H b T  @kindex H b T
# Line 17511  in place of @code{pv}.  Also, @code{rate Line 17677  in place of @code{pv}.  Also, @code{rate
17677  accept an optional fourth argument just like @code{pv} and @code{pvb}.  accept an optional fourth argument just like @code{pv} and @code{pvb}.
17678  To redo the above example from a different perspective,  To redo the above example from a different perspective,
17679  @code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an  @code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an
17680  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.
17681    
17682  @kindex b I  @kindex b I
17683  @pindex calc-fin-irr  @pindex calc-fin-irr
# Line 17573  For symmetry, the @code{sln} function wi Line 17739  For symmetry, the @code{sln} function wi
17739  parameter as well, although it will ignore its value except that the  parameter as well, although it will ignore its value except that the
17740  return value will as usual be zero if @var{period} is out of range.  return value will as usual be zero if @var{period} is out of range.
17741    
17742  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})
17743  and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),  and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),
17744  ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare  ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare
17745  the three depreciation methods:  the three depreciation methods:
# Line 17594  We see that @code{sln} depreciates by th Line 17760  We see that @code{sln} depreciates by th
17760  @kbd{syd} depreciates more at the beginning and less at the end,  @kbd{syd} depreciates more at the beginning and less at the end,
17761  and @kbd{ddb} weights the depreciation even more toward the beginning.  and @kbd{ddb} weights the depreciation even more toward the beginning.
17762    
17763  Summing columns with @kbd{V R : +} yields @cite{[10000, 10000, 10000]};  Summing columns with @kbd{V R : +} yields @expr{[10000, 10000, 10000]};
17764  the total depreciation in any method is (by definition) the  the total depreciation in any method is (by definition) the
17765  difference between the cost and the salvage value.  difference between the cost and the salvage value.
17766    
# Line 17716  $$ \code{ddb}(c, s, l, p) = { 2 (c - \hb Line 17882  $$ \code{ddb}(c, s, l, p) = { 2 (c - \hb
17882  @end tex  @end tex
17883    
17884  @noindent  @noindent
17885  In @code{pmt} and @code{pmtb}, @cite{x=0} if omitted.  In @code{pmt} and @code{pmtb}, @expr{x=0} if omitted.
17886    
17887  These functions accept any numeric objects, including error forms,  These functions accept any numeric objects, including error forms,
17888  intervals, and even (though not very usefully) complex numbers.  The  intervals, and even (though not very usefully) complex numbers.  The
# Line 17776  commands, respectively).  You may also w Line 17942  commands, respectively).  You may also w
17942  zeros with @kbd{d z}.  @xref{Radix Modes}.  zeros with @kbd{d z}.  @xref{Radix Modes}.
17943    
17944  @cindex Word size for binary operations  @cindex Word size for binary operations
17945  The Calculator maintains a current @dfn{word size} @cite{w}, an  The Calculator maintains a current @dfn{word size} @expr{w}, an
17946  arbitrary positive or negative integer.  For a positive word size, all  arbitrary positive or negative integer.  For a positive word size, all
17947  of the binary operations described here operate modulo @cite{2^w}.  In  of the binary operations described here operate modulo @expr{2^w}.  In
17948  particular, negative arguments are converted to positive integers modulo  particular, negative arguments are converted to positive integers modulo
17949  @cite{2^w} by all binary functions.@refill  @expr{2^w} by all binary functions.
17950    
17951  If the word size is negative, binary operations produce 2's complement  If the word size is negative, binary operations produce 2's complement
17952  integers from @c{$-2^{-w-1}$}  integers from
17953  @cite{-(2^(-w-1))} to @c{$2^{-w-1}-1$}  @texline @tmath{-2^{-w-1}}
17954  @cite{2^(-w-1)-1} inclusive.  Either  @infoline @expr{-(2^(-w-1))}
17955  mode accepts inputs in any range; the sign of @cite{w} affects only  to
17956  the results produced.  @texline @tmath{2^{-w-1}-1}
17957    @infoline @expr{2^(-w-1)-1}
17958    inclusive.  Either mode accepts inputs in any range; the sign of
17959    @expr{w} affects only the results produced.
17960    
17961  @kindex b c  @kindex b c
17962  @pindex calc-clip  @pindex calc-clip
17963  @tindex clip  @tindex clip
17964  The @kbd{b c} (@code{calc-clip})  The @kbd{b c} (@code{calc-clip})
17965  [@code{clip}] command can be used to clip a number by reducing it modulo  [@code{clip}] command can be used to clip a number by reducing it modulo
17966  @cite{2^w}.  The commands described in this chapter automatically clip  @expr{2^w}.  The commands described in this chapter automatically clip
17967  their results to the current word size.  Note that other operations like  their results to the current word size.  Note that other operations like
17968  addition do not use the current word size, since integer addition  addition do not use the current word size, since integer addition
17969  generally is not ``binary.''  (However, @pxref{Simplification Modes},  generally is not ``binary.''  (However, @pxref{Simplification Modes},
17970  @code{calc-bin-simplify-mode}.)  For example, with a word size of 8  @code{calc-bin-simplify-mode}.)  For example, with a word size of 8
17971  bits @kbd{b c} converts a number to the range 0 to 255; with a word  bits @kbd{b c} converts a number to the range 0 to 255; with a word
17972  size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.@refill  size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.
17973    
17974  @kindex b w  @kindex b w
17975  @pindex calc-word-size  @pindex calc-word-size
# Line 17820  will be used, but when @samp{and(a,b,-8) Line 17989  will be used, but when @samp{and(a,b,-8)
17989  in symbolic form unless the all of its argument(s) are integers or  in symbolic form unless the all of its argument(s) are integers or
17990  integer-valued floats.  integer-valued floats.
17991    
17992  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
17993  power of two, that power of two is taken as the word size unless a  power of two, that power of two is taken as the word size unless a
17994  numeric prefix argument overrides it.  The current word size is never  numeric prefix argument overrides it.  The current word size is never
17995  consulted when modulo-power-of-two forms are involved.  consulted when modulo-power-of-two forms are involved.
# Line 17830  consulted when modulo-power-of-two forms Line 17999  consulted when modulo-power-of-two forms
17999  @tindex and  @tindex and
18000  The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise  The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise
18001  AND of the two numbers on the top of the stack.  In other words, for each  AND of the two numbers on the top of the stack.  In other words, for each
18002  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
18003  bit of the result is 1 if and only if both input bits are 1:  bit of the result is 1 if and only if both input bits are 1:
18004  @samp{and(2#1100, 2#1010) = 2#1000}.  @samp{and(2#1100, 2#1010) = 2#1000}.
18005    
# Line 17965  flag keys must be used to get some of th Line 18134  flag keys must be used to get some of th
18134  @cindex Phi, golden ratio  @cindex Phi, golden ratio
18135  @cindex Golden ratio  @cindex Golden ratio
18136  One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes  One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes
18137  the value of @c{$\pi$}  the value of @cpi{} (at the current precision) onto the stack.  With the
18138  @cite{pi} (at the current precision) onto the stack.  With the  Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms.
18139  Hyperbolic flag, it pushes the value @cite{e}, the base of natural logarithms.  With the Inverse flag, it pushes Euler's constant
18140  With the Inverse flag, it pushes Euler's constant @c{$\gamma$}  @texline @tmath{\gamma}
18141  @cite{gamma} (about 0.5772).  With both Inverse and Hyperbolic, it  @infoline @expr{gamma}
18142  pushes the ``golden ratio'' @c{$\phi$}  (about 0.5772).  With both Inverse and Hyperbolic, it
18143  @cite{phi} (about 1.618).  (At present, Euler's constant is not available  pushes the ``golden ratio''
18144    @texline @tmath{\phi}
18145    @infoline @expr{phi}
18146    (about 1.618).  (At present, Euler's constant is not available
18147  to unlimited precision; Calc knows only the first 100 digits.)  to unlimited precision; Calc knows only the first 100 digits.)
18148  In Symbolic mode, these commands push the  In Symbolic mode, these commands push the
18149  actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi},  actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi},
18150  respectively, instead of their values; @pxref{Symbolic Mode}.@refill  respectively, instead of their values; @pxref{Symbolic Mode}.
18151    
18152  @ignore  @ignore
18153  @mindex Q  @mindex Q
# Line 18027  this is redundant with the @kbd{E} comma Line 18199  this is redundant with the @kbd{E} comma
18199  @end ignore  @end ignore
18200  @kindex I L  @kindex I L
18201  The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the  The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the
18202  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.
18203  The meanings of the Inverse and Hyperbolic flags follow from those for  The meanings of the Inverse and Hyperbolic flags follow from those for
18204  the @code{calc-ln} command.  the @code{calc-ln} command.
18205    
# Line 18048  The @kbd{H L} (@code{calc-log10}) [@code Line 18220  The @kbd{H L} (@code{calc-log10}) [@code
18220  (base-10) logarithm of a number.  (With the Inverse flag [@code{exp10}],  (base-10) logarithm of a number.  (With the Inverse flag [@code{exp10}],
18221  it raises ten to a given power.)  Note that the common logarithm of a  it raises ten to a given power.)  Note that the common logarithm of a
18222  complex number is computed by taking the natural logarithm and dividing  complex number is computed by taking the natural logarithm and dividing
18223  by @c{$\ln10$}  by
18224  @cite{ln(10)}.  @texline @tmath{\ln10}.
18225    @infoline @expr{ln(10)}.
18226    
18227  @kindex B  @kindex B
18228  @kindex I B  @kindex I B
# Line 18058  by @c{$\ln10$} Line 18231  by @c{$\ln10$}
18231  @tindex alog  @tindex alog
18232  The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm  The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm
18233  to any base.  For example, @kbd{1024 @key{RET} 2 B} produces 10, since  to any base.  For example, @kbd{1024 @key{RET} 2 B} produces 10, since
18234  @c{$2^{10} = 1024$}  @texline @tmath{2^{10} = 1024}.
18235  @cite{2^10 = 1024}.  In certain cases like @samp{log(3,9)}, the result  @infoline @expr{2^10 = 1024}.  
18236  will be either @cite{1:2} or @cite{0.5} depending on the current Fraction  In certain cases like @samp{log(3,9)}, the result
18237    will be either @expr{1:2} or @expr{0.5} depending on the current Fraction
18238  Mode setting.  With the Inverse flag [@code{alog}], this command is  Mode setting.  With the Inverse flag [@code{alog}], this command is
18239  similar to @kbd{^} except that the order of the arguments is reversed.  similar to @kbd{^} except that the order of the arguments is reversed.
18240    
# Line 18070  similar to @kbd{^} except that the order Line 18244  similar to @kbd{^} except that the order
18244  The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the  The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the
18245  integer logarithm of a number to any base.  The number and the base must  integer logarithm of a number to any base.  The number and the base must
18246  themselves be positive integers.  This is the true logarithm, rounded  themselves be positive integers.  This is the true logarithm, rounded
18247  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
18248  range from 1000 to 9999.  If both arguments are positive integers, exact  range from 1000 to 9999.  If both arguments are positive integers, exact
18249  integer arithmetic is used; otherwise, this is equivalent to  integer arithmetic is used; otherwise, this is equivalent to
18250  @samp{floor(log(x,b))}.  @samp{floor(log(x,b))}.
# Line 18079  integer arithmetic is used; otherwise, t Line 18253  integer arithmetic is used; otherwise, t
18253  @pindex calc-expm1  @pindex calc-expm1
18254  @tindex expm1  @tindex expm1
18255  The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes  The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes
18256  @c{$e^x - 1$}  @texline @tmath{e^x - 1},
18257  @cite{exp(x)-1}, but using an algorithm that produces a more accurate  @infoline @expr{exp(x)-1},
18258  answer when the result is close to zero, i.e., when @c{$e^x$}  but using an algorithm that produces a more accurate
18259  @cite{exp(x)} is close  answer when the result is close to zero, i.e., when
18260  to one.  @texline @tmath{e^x}
18261    @infoline @expr{exp(x)}
18262    is close to one.
18263    
18264  @kindex f L  @kindex f L
18265  @pindex calc-lnp1  @pindex calc-lnp1
18266  @tindex lnp1  @tindex lnp1
18267  The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes  The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes
18268  @c{$\ln(x+1)$}  @texline @tmath{\ln(x+1)},
18269  @cite{ln(x+1)}, producing a more accurate answer when @cite{x} is close  @infoline @expr{ln(x+1)},
18270  to zero.  producing a more accurate answer when @expr{x} is close to zero.
18271    
18272  @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions  @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions
18273  @section Trigonometric/Hyperbolic Functions  @section Trigonometric/Hyperbolic Functions
# Line 18104  The shift-@kbd{S} (@code{calc-sin}) [@co Line 18280  The shift-@kbd{S} (@code{calc-sin}) [@co
18280  of an angle or complex number.  If the input is an HMS form, it is interpreted  of an angle or complex number.  If the input is an HMS form, it is interpreted
18281  as degrees-minutes-seconds; otherwise, the input is interpreted according  as degrees-minutes-seconds; otherwise, the input is interpreted according
18282  to the current angular mode.  It is best to use Radians mode when operating  to the current angular mode.  It is best to use Radians mode when operating
18283  on complex numbers.@refill  on complex numbers.
18284    
18285  Calc's ``units'' mechanism includes angular units like @code{deg},  Calc's ``units'' mechanism includes angular units like @code{deg},
18286  @code{rad}, and @code{grad}.  While @samp{sin(45 deg)} is not evaluated  @code{rad}, and @code{grad}.  While @samp{sin(45 deg)} is not evaluated
# Line 18120  mode is enabled; this example would be r Line 18296  mode is enabled; this example would be r
18296  @xref{Symbolic Mode}.  Beware, this simplification occurs even if you  @xref{Symbolic Mode}.  Beware, this simplification occurs even if you
18297  have stored a different value in the variable @samp{pi}; this is one  have stored a different value in the variable @samp{pi}; this is one
18298  reason why changing built-in variables is a bad idea.  Arguments of  reason why changing built-in variables is a bad idea.  Arguments of
18299  the form @cite{x} plus a multiple of @c{$\pi/2$}  the form @expr{x} plus a multiple of @cpiover{2} are also simplified.
18300  @cite{pi/2} are also simplified.  Calc includes similar formulas for @code{cos} and @code{tan}.
 Calc includes similar formulas for @code{cos} and @code{tan}.@refill  
18301    
18302  The @kbd{a s} command knows all angles which are integer multiples of  The @kbd{a s} command knows all angles which are integer multiples of
18303  @c{$\pi/12$}  @cpiover{12}, @cpiover{10}, or @cpiover{8} radians.  In degrees mode,
 @cite{pi/12}, @c{$\pi/10$}  
 @cite{pi/10}, or @c{$\pi/8$}  
 @cite{pi/8} radians.  In degrees mode,  
18304  analogous simplifications occur for integer multiples of 15 or 18  analogous simplifications occur for integer multiples of 15 or 18
18305  degrees, and for arguments plus multiples of 90 degrees.  degrees, and for arguments plus multiples of 90 degrees.
18306    
# Line 18253  cosine of a number, returning them as a Line 18425  cosine of a number, returning them as a
18425  @samp{[@var{cos}, @var{sin}]}.  @samp{[@var{cos}, @var{sin}]}.
18426  With the Inverse flag [@code{arcsincos}], this command takes a two-element  With the Inverse flag [@code{arcsincos}], this command takes a two-element
18427  vector as an argument and computes @code{arctan2} of the elements.  vector as an argument and computes @code{arctan2} of the elements.
18428  (This command does not accept the Hyperbolic flag.)@refill  (This command does not accept the Hyperbolic flag.)
18429    
18430  @node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions  @node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions
18431  @section Advanced Mathematical Functions  @section Advanced Mathematical Functions
# Line 18278  The @kbd{f g} (@code{calc-gamma}) [@code Line 18450  The @kbd{f g} (@code{calc-gamma}) [@code
18450  gamma function.  For positive integer arguments, this is related to the  gamma function.  For positive integer arguments, this is related to the
18451  factorial function:  @samp{gamma(n+1) = fact(n)}.  For general complex  factorial function:  @samp{gamma(n+1) = fact(n)}.  For general complex
18452  arguments the gamma function can be defined by the following definite  arguments the gamma function can be defined by the following definite
18453  integral:  @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$}  integral:  
18454  @cite{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}.  @texline @tmath{\Gamma(a) = \int_0^\infty t^{a-1} e^t dt}.
18455    @infoline @expr{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}.  
18456  (The actual implementation uses far more efficient computational methods.)  (The actual implementation uses far more efficient computational methods.)
18457    
18458  @kindex f G  @kindex f G
# Line 18311  integral:  @c{$\Gamma(a) = \int_0^\infty Line 18484  integral:  @c{$\Gamma(a) = \int_0^\infty
18484  @tindex gammaG  @tindex gammaG
18485  The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes  The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes
18486  the incomplete gamma function, denoted @samp{P(a,x)}.  This is defined by  the incomplete gamma function, denoted @samp{P(a,x)}.  This is defined by
18487  the integral, @c{$P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)$}  the integral,
18488  @cite{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}.  @texline @tmath{P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)}.
18489  This implies that @samp{gammaP(a,inf) = 1} for any @cite{a} (see the  @infoline @expr{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}.
18490    This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the
18491  definition of the normal gamma function).  definition of the normal gamma function).
18492    
18493  Several other varieties of incomplete gamma function are defined.  Several other varieties of incomplete gamma function are defined.
18494  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
18495  some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command.  some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command.
18496  You can think of this as taking the other half of the integral, from  You can think of this as taking the other half of the integral, from
18497  @cite{x} to infinity.  @expr{x} to infinity.
18498    
18499  @ifinfo  @ifinfo
18500  The functions corresponding to the integrals that define @cite{P(a,x)}  The functions corresponding to the integrals that define @expr{P(a,x)}
18501  and @cite{Q(a,x)} but without the normalizing @cite{1/gamma(a)}  and @expr{Q(a,x)} but without the normalizing @expr{1/gamma(a)}
18502  factor are called @cite{g(a,x)} and @cite{G(a,x)}, respectively  factor are called @expr{g(a,x)} and @expr{G(a,x)}, respectively
18503  (where @cite{g} and @cite{G} represent the lower- and upper-case Greek  (where @expr{g} and @expr{G} represent the lower- and upper-case Greek
18504  letter gamma).  You can obtain these using the @kbd{H f G} [@code{gammag}]  letter gamma).  You can obtain these using the @kbd{H f G} [@code{gammag}]
18505  and @kbd{H I f G} [@code{gammaG}] commands.  and @kbd{H I f G} [@code{gammaG}] commands.
18506  @end ifinfo  @end ifinfo
# Line 18344  You can obtain these using the \kbd{H f Line 18518  You can obtain these using the \kbd{H f
18518  @tindex beta  @tindex beta
18519  The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the  The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the
18520  Euler beta function, which is defined in terms of the gamma function as  Euler beta function, which is defined in terms of the gamma function as
18521  @c{$B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)$}  @texline @tmath{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)},
18522  @cite{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, or by  @infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)},
18523  @c{$B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt$}  or by
18524  @cite{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}.  @texline @tmath{B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt}.
18525    @infoline @expr{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}.
18526    
18527  @kindex f B  @kindex f B
18528  @kindex H f B  @kindex H f B
# Line 18355  Euler beta function, which is defined in Line 18530  Euler beta function, which is defined in
18530  @tindex betaI  @tindex betaI
18531  @tindex betaB  @tindex betaB
18532  The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes  The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes
18533  the incomplete beta function @cite{I(x,a,b)}.  It is defined by  the incomplete beta function @expr{I(x,a,b)}.  It is defined by
18534  @c{$I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)$}  @texline @tmath{I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)}.
18535  @cite{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}.  @infoline @expr{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}.
18536  Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding  Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding
18537  un-normalized version [@code{betaB}].  un-normalized version [@code{betaB}].
18538    
# Line 18367  un-normalized version [@code{betaB}]. Line 18542  un-normalized version [@code{betaB}].
18542  @tindex erf  @tindex erf
18543  @tindex erfc  @tindex erfc
18544  The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the  The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the
18545  error function @c{$\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt$}  error function
18546  @cite{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}.  @texline @tmath{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt}.
18547    @infoline @expr{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}.
18548  The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}]  The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}]
18549  is the corresponding integral from @samp{x} to infinity; the sum  is the corresponding integral from @samp{x} to infinity; the sum
18550  @c{$\hbox{erf}(x) + \hbox{erfc}(x) = 1$}  @texline @tmath{\hbox{erf}(x) + \hbox{erfc}(x) = 1}.
18551  @cite{erf(x) + erfc(x) = 1}.  @infoline @expr{erf(x) + erfc(x) = 1}.
18552    
18553  @kindex f j  @kindex f j
18554  @kindex f y  @kindex f y
# Line 18384  The @kbd{f j} (@code{calc-bessel-J}) [@c Line 18560  The @kbd{f j} (@code{calc-bessel-J}) [@c
18560  (@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel  (@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel
18561  functions of the first and second kinds, respectively.  functions of the first and second kinds, respectively.
18562  In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter  In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter
18563  @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.
18564  Calc's implementation of the Bessel functions currently limits the  Calc's implementation of the Bessel functions currently limits the
18565  precision to 8 digits, and may not be exact even to that precision.  precision to 8 digits, and may not be exact even to that precision.
18566  Use with care!@refill  Use with care!
18567    
18568  @node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions  @node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions
18569  @section Branch Cuts and Principal Values  @section Branch Cuts and Principal Values
# Line 18420  are designed with proper behavior around Line 18596  are designed with proper behavior around
18596  efficiency or accuracy.  You may need to increase the floating precision  efficiency or accuracy.  You may need to increase the floating precision
18597  and wait a while to get suitable answers from them.  and wait a while to get suitable answers from them.
18598    
18599  For @samp{sqrt(a+bi)}:  When @cite{a<0} and @cite{b} is small but positive  For @samp{sqrt(a+bi)}:  When @expr{a<0} and @expr{b} is small but positive
18600  or zero, the result is close to the @cite{+i} axis.  For @cite{b} small and  or zero, the result is close to the @expr{+i} axis.  For @expr{b} small and
18601  negative, the result is close to the @cite{-i} axis.  The result always lies  negative, the result is close to the @expr{-i} axis.  The result always lies
18602  in the right half of the complex plane.  in the right half of the complex plane.
18603    
18604  For @samp{ln(a+bi)}:  The real part is defined as @samp{ln(abs(a+bi))}.  For @samp{ln(a+bi)}:  The real part is defined as @samp{ln(abs(a+bi))}.
# Line 18431  Thus the branch cuts for @code{sqrt} and Line 18607  Thus the branch cuts for @code{sqrt} and
18607  negative real axis.  negative real axis.
18608    
18609  The following table describes these branch cuts in another way.  The following table describes these branch cuts in another way.
18610  If the real and imaginary parts of @cite{z} are as shown, then  If the real and imaginary parts of @expr{z} are as shown, then
18611  the real and imaginary parts of @cite{f(z)} will be as shown.  the real and imaginary parts of @expr{f(z)} will be as shown.
18612  Here @code{eps} stands for a small positive value; each  Here @code{eps} stands for a small positive value; each
18613  occurrence of @code{eps} may stand for a different small value.  occurrence of @code{eps} may stand for a different small value.
18614    
# Line 18448  occurrence of @code{eps} may stand for a Line 18624  occurrence of @code{eps} may stand for a
18624  For @samp{z1^z2}:  This is defined by @samp{exp(ln(z1)*z2)}.  For @samp{z1^z2}:  This is defined by @samp{exp(ln(z1)*z2)}.
18625  One interesting consequence of this is that @samp{(-8)^1:3} does  One interesting consequence of this is that @samp{(-8)^1:3} does
18626  not evaluate to @i{-2} as you might expect, but to the complex  not evaluate to @i{-2} as you might expect, but to the complex
18627  number @cite{(1., 1.732)}.  Both of these are valid cube roots  number @expr{(1., 1.732)}.  Both of these are valid cube roots
18628  of @i{-8} (as is @cite{(1., -1.732)}); Calc chooses a perhaps  of @i{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps
18629  less-obvious root for the sake of mathematical consistency.  less-obvious root for the sake of mathematical consistency.
18630    
18631  For @samp{arcsin(z)}:  This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}.  For @samp{arcsin(z)}:  This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}.
# Line 18461  the real axis, less than @i{-1} and grea Line 18637  the real axis, less than @i{-1} and grea
18637    
18638  For @samp{arctan(z)}:  This is defined by  For @samp{arctan(z)}:  This is defined by
18639  @samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}.  The branch cuts are on the  @samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}.  The branch cuts are on the
18640  imaginary axis, below @cite{-i} and above @cite{i}.  imaginary axis, below @expr{-i} and above @expr{i}.
18641    
18642  For @samp{arcsinh(z)}:  This is defined by @samp{ln(z + sqrt(1+z^2))}.  For @samp{arcsinh(z)}:  This is defined by @samp{ln(z + sqrt(1+z^2))}.
18643  The branch cuts are on the imaginary axis, below @cite{-i} and  The branch cuts are on the imaginary axis, below @expr{-i} and
18644  above @cite{i}.  above @expr{i}.
18645    
18646  For @samp{arccosh(z)}:  This is defined by  For @samp{arccosh(z)}:  This is defined by
18647  @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}.  The branch cut is on the  @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}.  The branch cut is on the
# Line 18543  are not rigorously specified at present. Line 18719  are not rigorously specified at present.
18719  The @kbd{k r} (@code{calc-random}) [@code{random}] command produces  The @kbd{k r} (@code{calc-random}) [@code{random}] command produces
18720  random numbers of various sorts.  random numbers of various sorts.
18721    
18722  Given a positive numeric prefix argument @cite{M}, it produces a random  Given a positive numeric prefix argument @expr{M}, it produces a random
18723  integer @cite{N} in the range @c{$0 \le N < M$}  integer @expr{N} in the range
18724  @cite{0 <= N < M}.  Each of the @cite{M}  @texline @tmath{0 \le N < M}.
18725  values appears with equal probability.@refill  @infoline @expr{0 <= N < M}.  
18726    Each of the @expr{M} values appears with equal probability.
18727    
18728  With no numeric prefix argument, the @kbd{k r} command takes its argument  With no numeric prefix argument, the @kbd{k r} command takes its argument
18729  from the stack instead.  Once again, if this is a positive integer @cite{M}  from the stack instead.  Once again, if this is a positive integer @expr{M}
18730  the result is a random integer less than @cite{M}.  However, note that  the result is a random integer less than @expr{M}.  However, note that
18731  while numeric prefix arguments are limited to six digits or so, an @cite{M}  while numeric prefix arguments are limited to six digits or so, an @expr{M}
18732  taken from the stack can be arbitrarily large.  If @cite{M} is negative,  taken from the stack can be arbitrarily large.  If @expr{M} is negative,
18733  the result is a random integer in the range @c{$M < N \le 0$}  the result is a random integer in the range
18734  @cite{M < N <= 0}.  @texline @tmath{M < N \le 0}.
18735    @infoline @expr{M < N <= 0}.
18736  If the value on the stack is a floating-point number @cite{M}, the result  
18737  is a random floating-point number @cite{N} in the range @c{$0 \le N < M$}  If the value on the stack is a floating-point number @expr{M}, the result
18738  @cite{0 <= N < M}  is a random floating-point number @expr{N} in the range
18739  or @c{$M < N \le 0$}  @texline @tmath{0 \le N < M}
18740  @cite{M < N <= 0}, according to the sign of @cite{M}.  @infoline @expr{0 <= N < M}
18741    or
18742    @texline @tmath{M < N \le 0},
18743    @infoline @expr{M < N <= 0},
18744    according to the sign of @expr{M}.
18745    
18746  If @cite{M} is zero, the result is a Gaussian-distributed random real  If @expr{M} is zero, the result is a Gaussian-distributed random real
18747  number; the distribution has a mean of zero and a standard deviation  number; the distribution has a mean of zero and a standard deviation
18748  of one.  The algorithm used generates random numbers in pairs; thus,  of one.  The algorithm used generates random numbers in pairs; thus,
18749  every other call to this function will be especially fast.  every other call to this function will be especially fast.
18750    
18751  If @cite{M} is an error form @c{$m$ @code{+/-} $\sigma$}  If @expr{M} is an error form
18752  @samp{m +/- s} where @var{m}  @texline @tmath{m} @code{+/-} @tmath{\sigma}
18753  and @c{$\sigma$}  @infoline @samp{m +/- s}
18754  @var{s} are both real numbers, the result uses a Gaussian  where @var{m} and
18755  distribution with mean @var{m} and standard deviation @c{$\sigma$}  @texline @tmath{\sigma}
18756    @infoline @var{s}
18757    are both real numbers, the result uses a Gaussian distribution with mean
18758    @var{m} and standard deviation
18759    @texline @tmath{\sigma}.
18760  @var{s}.  @var{s}.
18761    
18762  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
18763  acceptable limits of the random numbers.  If both bounds are integers,  acceptable limits of the random numbers.  If both bounds are integers,
18764  the result is a random integer in the specified range.  If either bound  the result is a random integer in the specified range.  If either bound
18765  is floating-point, the result is a random real number in the specified  is floating-point, the result is a random real number in the specified
# Line 18586  million numbers from 1.00000 to 1.99999; Line 18771  million numbers from 1.00000 to 1.99999;
18771  additionally return 2.00000, but the probability of this happening is  additionally return 2.00000, but the probability of this happening is
18772  extremely small.)  extremely small.)
18773    
18774  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
18775  the vector.  All elements of the vector are given equal probabilities.  the vector.  All elements of the vector are given equal probabilities.
18776    
18777  @vindex RandSeed  @vindex RandSeed
# Line 18609  number between zero and one.  It is equi Line 18794  number between zero and one.  It is equi
18794  @kindex k a  @kindex k a
18795  @pindex calc-random-again  @pindex calc-random-again
18796  The @kbd{k a} (@code{calc-random-again}) command produces another random  The @kbd{k a} (@code{calc-random-again}) command produces another random
18797  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
18798  prefix argument @var{n}, it produces @var{n} more random numbers using  prefix argument @var{n}, it produces @var{n} more random numbers using
18799  that value of @cite{M}.  that value of @expr{M}.
18800    
18801  @kindex k h  @kindex k h
18802  @pindex calc-shuffle  @pindex calc-shuffle
# Line 18619  that value of @cite{M}. Line 18804  that value of @cite{M}.
18804  The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several  The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several
18805  random values with no duplicates.  The value on the top of the stack  random values with no duplicates.  The value on the top of the stack
18806  specifies the set from which the random values are drawn, and may be any  specifies the set from which the random values are drawn, and may be any
18807  of the @cite{M} formats described above.  The numeric prefix argument  of the @expr{M} formats described above.  The numeric prefix argument
18808  gives the length of the desired list.  (If you do not provide a numeric  gives the length of the desired list.  (If you do not provide a numeric
18809  prefix argument, the length of the list is taken from the top of the  prefix argument, the length of the list is taken from the top of the
18810  stack, and @cite{M} from second-to-top.)  stack, and @expr{M} from second-to-top.)
18811    
18812  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
18813  that the random values are being drawn from the set of real numbers)  that the random values are being drawn from the set of real numbers)
18814  there is little practical difference between using @kbd{k h} and using  there is little practical difference between using @kbd{k h} and using
18815  @kbd{k r} several times.  But if the set of possible values consists  @kbd{k r} several times.  But if the set of possible values consists
# Line 18632  of just a few integers, or the elements Line 18817  of just a few integers, or the elements
18817  a very real chance that multiple @kbd{k r}'s will produce the same  a very real chance that multiple @kbd{k r}'s will produce the same
18818  number more than once.  The @kbd{k h} command produces a vector whose  number more than once.  The @kbd{k h} command produces a vector whose
18819  elements are always distinct.  (Actually, there is a slight exception:  elements are always distinct.  (Actually, there is a slight exception:
18820  If @cite{M} is a vector, no given vector element will be drawn more  If @expr{M} is a vector, no given vector element will be drawn more
18821  than once, but if several elements of @cite{M} are equal, they may  than once, but if several elements of @expr{M} are equal, they may
18822  each make it into the result vector.)  each make it into the result vector.)
18823    
18824  One use of @kbd{k h} is to rearrange a list at random.  This happens  One use of @kbd{k h} is to rearrange a list at random.  This happens
# Line 18641  if the prefix argument is equal to the n Line 18826  if the prefix argument is equal to the n
18826  @kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list  @kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list
18827  @samp{[2.5, 1, 1.5, 3, 2]}.  As a convenient feature, if the argument  @samp{[2.5, 1, 1.5, 3, 2]}.  As a convenient feature, if the argument
18828  @var{n} is negative it is replaced by the size of the set represented  @var{n} is negative it is replaced by the size of the set represented
18829  by @cite{M}.  Naturally, this is allowed only when @cite{M} specifies  by @expr{M}.  Naturally, this is allowed only when @expr{M} specifies
18830  a small discrete set of possibilities.  a small discrete set of possibilities.
18831    
18832  To do the equivalent of @kbd{k h} but with duplications allowed,  To do the equivalent of @kbd{k h} but with duplications allowed,
18833  given @cite{M} on the stack and with @var{n} just entered as a numeric  given @expr{M} on the stack and with @var{n} just entered as a numeric
18834  prefix, use @kbd{v b} to build a vector of copies of @cite{M}, then use  prefix, use @kbd{v b} to build a vector of copies of @expr{M}, then use
18835  @kbd{V M k r} to ``map'' the normal @kbd{k r} function over the  @kbd{V M k r} to ``map'' the normal @kbd{k r} function over the
18836  elements of this vector.  @xref{Matrix Functions}.  elements of this vector.  @xref{Matrix Functions}.
18837    
# Line 18683  generators that are typically used to im Line 18868  generators that are typically used to im
18868    
18869  If @code{RandSeed} contains an integer, Calc uses this integer to  If @code{RandSeed} contains an integer, Calc uses this integer to
18870  seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A,  seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A,
18871  computing @c{$X_{n-55} - X_{n-24}$}  computing
18872  @cite{X_n-55 - X_n-24}).  This method expands the seed  @texline @tmath{X_{n-55} - X_{n-24}}.
18873    @infoline @expr{X_n-55 - X_n-24}).  
18874    This method expands the seed
18875  value into a large table which is maintained internally; the variable  value into a large table which is maintained internally; the variable
18876  @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]}
18877  to indicate that the seed has been absorbed into this table.  When  to indicate that the seed has been absorbed into this table.  When
18878  @code{RandSeed} contains a vector, @kbd{k r} and related commands  @code{RandSeed} contains a vector, @kbd{k r} and related commands
18879  continue to use the same internal table as last time.  There is no  continue to use the same internal table as last time.  There is no
# Line 18718  value. Line 18905  value.
18905    
18906  To create a random floating-point number with precision @var{p}, Calc  To create a random floating-point number with precision @var{p}, Calc
18907  simply creates a random @var{p}-digit integer and multiplies by  simply creates a random @var{p}-digit integer and multiplies by
18908  @c{$10^{-p}$}  @texline @tmath{10^{-p}}.
18909  @cite{10^-p}.  The resulting random numbers should be very clean, but note  @infoline @expr{10^-p}.  
18910    The resulting random numbers should be very clean, but note
18911  that relatively small numbers will have few significant random digits.  that relatively small numbers will have few significant random digits.
18912  In other words, with a precision of 12, you will occasionally get  In other words, with a precision of 12, you will occasionally get
18913  numbers on the order of @c{$10^{-9}$}  numbers on the order of
18914  @cite{10^-9} or @c{$10^{-10}$}  @texline @tmath{10^{-9}}
18915  @cite{10^-10}, but those numbers  @infoline @expr{10^-9}
18916  will only have two or three random digits since they correspond to small  or
18917  integers times @c{$10^{-12}$}  @texline @tmath{10^{-10}},
18918  @cite{10^-12}.  @infoline @expr{10^-10},
18919    but those numbers will only have two or three random digits since they
18920    correspond to small integers times
18921    @texline @tmath{10^{-12}}.
18922    @infoline @expr{10^-12}.
18923    
18924  To create a random integer in the interval @samp{[0 .. @var{m})}, Calc  To create a random integer in the interval @samp{[0 .. @var{m})}, Calc
18925  counts the digits in @var{m}, creates a random integer with three  counts the digits in @var{m}, creates a random integer with three
# Line 18761  the GCD of two fractions is defined by t Line 18953  the GCD of two fractions is defined by t
18953  numerators, and the LCM of the denominators.  This definition is  numerators, and the LCM of the denominators.  This definition is
18954  consistent with the idea that @samp{a / gcd(a,x)} should yield an  consistent with the idea that @samp{a / gcd(a,x)} should yield an
18955  integer for any @samp{a} and @samp{x}.  For other types of arguments,  integer for any @samp{a} and @samp{x}.  For other types of arguments,
18956  the operation is left in symbolic form.@refill  the operation is left in symbolic form.
18957    
18958  @kindex k l  @kindex k l
18959  @pindex calc-lcm  @pindex calc-lcm
# Line 18769  the operation is left in symbolic form.@ Line 18961  the operation is left in symbolic form.@
18961  The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the  The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the
18962  Least Common Multiple of two integers or fractions.  The product of  Least Common Multiple of two integers or fractions.  The product of
18963  the LCM and GCD of two numbers is equal to the product of the  the LCM and GCD of two numbers is equal to the product of the
18964  numbers.@refill  numbers.
18965    
18966  @kindex k E  @kindex k E
18967  @pindex calc-extended-gcd  @pindex calc-extended-gcd
18968  @tindex egcd  @tindex egcd
18969  The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes  The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes
18970  the GCD of two integers @cite{x} and @cite{y} and returns a vector  the GCD of two integers @expr{x} and @expr{y} and returns a vector
18971  @cite{[g, a, b]} where @c{$g = \gcd(x,y) = a x + b y$}  @expr{[g, a, b]} where
18972  @cite{g = gcd(x,y) = a x + b y}.  @texline @tmath{g = \gcd(x,y) = a x + b y}.
18973    @infoline @expr{g = gcd(x,y) = a x + b y}.
18974    
18975  @kindex !  @kindex !
18976  @pindex calc-factorial  @pindex calc-factorial
# Line 18794  the number is a non-integral real number Line 18987  the number is a non-integral real number
18987  as defined by the Euler Gamma function.  Please note that computation of  as defined by the Euler Gamma function.  Please note that computation of
18988  large factorials can be slow; using floating-point format will help  large factorials can be slow; using floating-point format will help
18989  since fewer digits must be maintained.  The same is true of many of  since fewer digits must be maintained.  The same is true of many of
18990  the commands in this section.@refill  the commands in this section.
18991    
18992  @kindex k d  @kindex k d
18993  @pindex calc-double-factorial  @pindex calc-double-factorial
# Line 18805  the commands in this section.@refill Line 18998  the commands in this section.@refill
18998  @tindex !!  @tindex !!
18999  The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command  The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command
19000  computes the ``double factorial'' of an integer.  For an even integer,  computes the ``double factorial'' of an integer.  For an even integer,
19001  this is the product of even integers from 2 to @cite{N}.  For an odd  this is the product of even integers from 2 to @expr{N}.  For an odd
19002  integer, this is the product of odd integers from 3 to @cite{N}.  If  integer, this is the product of odd integers from 3 to @expr{N}.  If
19003  the argument is an integer-valued float, the result is a floating-point  the argument is an integer-valued float, the result is a floating-point
19004  approximation.  This function is undefined for negative even integers.  approximation.  This function is undefined for negative even integers.
19005  The notation @cite{N!!} is also recognized for double factorials.@refill  The notation @expr{N!!} is also recognized for double factorials.
19006    
19007  @kindex k c  @kindex k c
19008  @pindex calc-choose  @pindex calc-choose
19009  @tindex choose  @tindex choose
19010  The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the  The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the
19011  binomial coefficient @cite{N}-choose-@cite{M}, where @cite{M} is the number  binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number
19012  on the top of the stack and @cite{N} is second-to-top.  If both arguments  on the top of the stack and @expr{N} is second-to-top.  If both arguments
19013  are integers, the result is an exact integer.  Otherwise, the result is a  are integers, the result is an exact integer.  Otherwise, the result is a
19014  floating-point approximation.  The binomial coefficient is defined for all  floating-point approximation.  The binomial coefficient is defined for all
19015  real numbers by @c{$N! \over M! (N-M)!\,$}  real numbers by
19016  @cite{N! / M! (N-M)!}.  @texline @tmath{N! \over M! (N-M)!\,}.
19017    @infoline @expr{N! / M! (N-M)!}.
19018    
19019  @kindex H k c  @kindex H k c
19020  @pindex calc-perm  @pindex calc-perm
19021  @tindex perm  @tindex perm
19022  @ifinfo  @ifinfo
19023  The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the  The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the
19024  number-of-permutations function @cite{N! / (N-M)!}.  number-of-permutations function @expr{N! / (N-M)!}.
19025  @end ifinfo  @end ifinfo
19026  @tex  @tex
19027  The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the  The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the
# Line 18840  number-of-perm\-utations function $N! \o Line 19034  number-of-perm\-utations function $N! \o
19034  @tindex bern  @tindex bern
19035  The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command  The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command
19036  computes a given Bernoulli number.  The value at the top of the stack  computes a given Bernoulli number.  The value at the top of the stack
19037  is a nonnegative integer @cite{n} that specifies which Bernoulli number  is a nonnegative integer @expr{n} that specifies which Bernoulli number
19038  is desired.  The @kbd{H k b} command computes a Bernoulli polynomial,  is desired.  The @kbd{H k b} command computes a Bernoulli polynomial,
19039  taking @cite{n} from the second-to-top position and @cite{x} from the  taking @expr{n} from the second-to-top position and @expr{x} from the
19040  top of the stack.  If @cite{x} is a variable or formula the result is  top of the stack.  If @expr{x} is a variable or formula the result is
19041  a polynomial in @cite{x}; if @cite{x} is a number the result is a number.  a polynomial in @expr{x}; if @expr{x} is a number the result is a number.
19042    
19043  @kindex k e  @kindex k e
19044  @kindex H k e  @kindex H k e
# Line 18861  functions. Line 19055  functions.
19055  @tindex stir1  @tindex stir1
19056  @tindex stir2  @tindex stir2
19057  The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command  The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command
19058  computes a Stirling number of the first kind@c{ $n \brack m$}  computes a Stirling number of the first
19059  @asis{}, given two integers  @texline kind@tie{}@tmath{n \brack m},
19060  @cite{n} and @cite{m} on the stack.  The @kbd{H k s} [@code{stir2}]  @infoline kind,
19061  command computes a Stirling number of the second kind@c{ $n \brace m$}  given two integers @expr{n} and @expr{m} on the stack.  The @kbd{H k s}
19062  @asis{}.  These are  [@code{stir2}] command computes a Stirling number of the second
19063  the number of @cite{m}-cycle permutations of @cite{n} objects, and  @texline kind@tie{}@tmath{n \brace m}.
19064  the number of ways to partition @cite{n} objects into @cite{m}  @infoline kind.
19065    These are the number of @expr{m}-cycle permutations of @expr{n} objects,
19066    and the number of ways to partition @expr{n} objects into @expr{m}
19067  non-empty sets, respectively.  non-empty sets, respectively.
19068    
19069  @kindex k p  @kindex k p
# Line 18895  The normal @kbd{k p} command performs on Line 19091  The normal @kbd{k p} command performs on
19091  test.  Pressing @kbd{k p} repeatedly for the same integer will perform  test.  Pressing @kbd{k p} repeatedly for the same integer will perform
19092  additional iterations.  Also, @kbd{k p} with a numeric prefix performs  additional iterations.  Also, @kbd{k p} with a numeric prefix performs
19093  the specified number of iterations.  There is also an algebraic function  the specified number of iterations.  There is also an algebraic function
19094  @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}
19095  is (probably) prime and 0 if not.  is (probably) prime and 0 if not.
19096    
19097  @kindex k f  @kindex k f
# Line 18942  analogously finds the next prime less th Line 19138  analogously finds the next prime less th
19138  @pindex calc-totient  @pindex calc-totient
19139  @tindex totient  @tindex totient
19140  The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the  The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the
19141  Euler ``totient'' function@c{ $\phi(n)$}  Euler ``totient''
19142  @asis{}, the number of integers less than @cite{n} which  @texline function@tie{}@tmath{\phi(n)},
19143  are relatively prime to @cite{n}.  @infoline function,
19144    the number of integers less than @expr{n} which
19145    are relatively prime to @expr{n}.
19146    
19147  @kindex k m  @kindex k m
19148  @pindex calc-moebius  @pindex calc-moebius
19149  @tindex moebius  @tindex moebius
19150  The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the  The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the
19151  @c{M\"obius $\mu$}  @texline M@"obius @tmath{\mu}
19152  @asis{Moebius ``mu''} function.  If the input number is a product of @cite{k}  @infoline Moebius ``mu''
19153  distinct factors, this is @cite{(-1)^k}.  If the input number has any  function.  If the input number is a product of @expr{k}
19154    distinct factors, this is @expr{(-1)^k}.  If the input number has any
19155  duplicate factors (i.e., can be divided by the same prime more than once),  duplicate factors (i.e., can be divided by the same prime more than once),
19156  the result is zero.  the result is zero.
19157    
# Line 18962  the result is zero. Line 19161  the result is zero.
19161  @noindent  @noindent
19162  The functions in this section compute various probability distributions.  The functions in this section compute various probability distributions.
19163  For continuous distributions, this is the integral of the probability  For continuous distributions, this is the integral of the probability
19164  density function from @cite{x} to infinity.  (These are the ``upper  density function from @expr{x} to infinity.  (These are the ``upper
19165  tail'' distribution functions; there are also corresponding ``lower  tail'' distribution functions; there are also corresponding ``lower
19166  tail'' functions which integrate from minus infinity to @cite{x}.)  tail'' functions which integrate from minus infinity to @expr{x}.)
19167  For discrete distributions, the upper tail function gives the sum  For discrete distributions, the upper tail function gives the sum
19168  from @cite{x} to infinity; the lower tail function gives the sum  from @expr{x} to infinity; the lower tail function gives the sum
19169  from minus infinity up to, but not including,@w{ }@cite{x}.  from minus infinity up to, but not including,@w{ }@expr{x}.
19170    
19171  To integrate from @cite{x} to @cite{y}, just use the distribution  To integrate from @expr{x} to @expr{y}, just use the distribution
19172  function twice and subtract.  For example, the probability that a  function twice and subtract.  For example, the probability that a
19173  Gaussian random variable with mean 2 and standard deviation 1 will  Gaussian random variable with mean 2 and standard deviation 1 will
19174  lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)}  lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)}
# Line 18999  order of the arguments in algebraic form Line 19198  order of the arguments in algebraic form
19198  arguments as found on the stack.  (The random variable comes last on  arguments as found on the stack.  (The random variable comes last on
19199  the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5  the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5
19200  k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to  k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to
19201  recover the original arguments but substitute a new value for @cite{x}.)  recover the original arguments but substitute a new value for @expr{x}.)
19202    
19203  @kindex k C  @kindex k C
19204  @pindex calc-utpc  @pindex calc-utpc
# Line 19013  recover the original arguments but subst Line 19212  recover the original arguments but subst
19212  @end ignore  @end ignore
19213  @tindex ltpc  @tindex ltpc
19214  The @samp{utpc(x,v)} function uses the chi-square distribution with  The @samp{utpc(x,v)} function uses the chi-square distribution with
19215  @c{$\nu$}  @texline @tmath{\nu}
19216  @cite{v} degrees of freedom.  It is the probability that a model is  @infoline @expr{v}
19217  correct if its chi-square statistic is @cite{x}.  degrees of freedom.  It is the probability that a model is
19218    correct if its chi-square statistic is @expr{x}.
19219    
19220  @kindex k F  @kindex k F
19221  @pindex calc-utpf  @pindex calc-utpf
# Line 19029  correct if its chi-square statistic is @ Line 19229  correct if its chi-square statistic is @
19229  @end ignore  @end ignore
19230  @tindex ltpf  @tindex ltpf
19231  The @samp{utpf(F,v1,v2)} function uses the F distribution, used in  The @samp{utpf(F,v1,v2)} function uses the F distribution, used in
19232  various statistical tests.  The parameters @c{$\nu_1$}  various statistical tests.  The parameters
19233  @cite{v1} and @c{$\nu_2$}  @texline @tmath{\nu_1}
19234  @cite{v2}  @infoline @expr{v1}
19235    and
19236    @texline @tmath{\nu_2}
19237    @infoline @expr{v2}
19238  are the degrees of freedom in the numerator and denominator,  are the degrees of freedom in the numerator and denominator,
19239  respectively, used in computing the statistic @cite{F}.  respectively, used in computing the statistic @expr{F}.
19240    
19241  @kindex k N  @kindex k N
19242  @pindex calc-utpn  @pindex calc-utpn
# Line 19047  respectively, used in computing the stat Line 19250  respectively, used in computing the stat
19250  @end ignore  @end ignore
19251  @tindex ltpn  @tindex ltpn
19252  The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution  The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution
19253  with mean @cite{m} and standard deviation @c{$\sigma$}  with mean @expr{m} and standard deviation
19254  @cite{s}.  It is the  @texline @tmath{\sigma}.
19255  probability that such a normal-distributed random variable would  @infoline @expr{s}.  
19256  exceed @cite{x}.  It is the probability that such a normal-distributed random variable
19257    would exceed @expr{x}.
19258    
19259  @kindex k P  @kindex k P
19260  @pindex calc-utpp  @pindex calc-utpp
# Line 19064  exceed @cite{x}. Line 19268  exceed @cite{x}.
19268  @end ignore  @end ignore
19269  @tindex ltpp  @tindex ltpp
19270  The @samp{utpp(n,x)} function uses a Poisson distribution with  The @samp{utpp(n,x)} function uses a Poisson distribution with
19271  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
19272  Poisson random events will occur.  Poisson random events will occur.
19273    
19274  @kindex k T  @kindex k T
# Line 19079  Poisson random events will occur. Line 19283  Poisson random events will occur.
19283  @end ignore  @end ignore
19284  @tindex ltpt  @tindex ltpt
19285  The @samp{utpt(t,v)} function uses the Student's ``t'' distribution  The @samp{utpt(t,v)} function uses the Student's ``t'' distribution
19286  with @c{$\nu$}  with
19287  @cite{v} degrees of freedom.  It is the probability that a  @texline @tmath{\nu}
19288  t-distributed random variable will be greater than @cite{t}.  @infoline @expr{v}
19289  (Note:  This computes the distribution function @c{$A(t|\nu)$}  degrees of freedom.  It is the probability that a
19290  @cite{A(t|v)}  t-distributed random variable will be greater than @expr{t}.
19291  where @c{$A(0|\nu) = 1$}  (Note:  This computes the distribution function
19292  @cite{A(0|v) = 1} and @c{$A(\infty|\nu) \to 0$}  @texline @tmath{A(t|\nu)}
19293  @cite{A(inf|v) -> 0}.  The  @infoline @expr{A(t|v)}
19294  @code{UTPT} operation on the HP-48 uses a different definition  where
19295  which returns half of Calc's value:  @samp{UTPT(t,v) = .5*utpt(t,v)}.)  @texline @tmath{A(0|\nu) = 1}
19296    @infoline @expr{A(0|v) = 1}
19297    and
19298    @texline @tmath{A(\infty|\nu) \to 0}.
19299    @infoline @expr{A(inf|v) -> 0}.  
19300    The @code{UTPT} operation on the HP-48 uses a different definition which
19301    returns half of Calc's value:  @samp{UTPT(t,v) = .5*utpt(t,v)}.)
19302    
19303  While Calc does not provide inverses of the probability distribution  While Calc does not provide inverses of the probability distribution
19304  functions, the @kbd{a R} command can be used to solve for the inverse.  functions, the @kbd{a R} command can be used to solve for the inverse.
# Line 19155  Negative packing modes create other kind Line 19365  Negative packing modes create other kind
19365  @item -1  @item -1
19366  Two values are collected to build a complex number.  For example,  Two values are collected to build a complex number.  For example,
19367  @kbd{5 @key{RET} 7 C-u -1 v p} creates the complex number  @kbd{5 @key{RET} 7 C-u -1 v p} creates the complex number
19368  @cite{(5, 7)}.  The result is always a rectangular complex  @expr{(5, 7)}.  The result is always a rectangular complex
19369  number.  The two input values must both be real numbers,  number.  The two input values must both be real numbers,
19370  i.e., integers, fractions, or floats.  If they are not, Calc  i.e., integers, fractions, or floats.  If they are not, Calc
19371  will instead build a formula like @samp{a + (0, 1) b}.  (The  will instead build a formula like @samp{a + (0, 1) b}.  (The
# Line 19245  returned in the form @samp{[@w{[a, b, c] Line 19455  returned in the form @samp{[@w{[a, b, c]
19455  If any elements of the vector are negative, other kinds of  If any elements of the vector are negative, other kinds of
19456  packing are done at that level as described above.  For  packing are done at that level as described above.  For
19457  example, @samp{[2, 3, -4]} takes 12 objects and creates a  example, @samp{[2, 3, -4]} takes 12 objects and creates a
19458  @c{$2\times3$}  @texline @tmath{2\times3}
19459  @asis{2x3} matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}.  @infoline 2x3
19460    matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}.
19461  Also, @samp{[-4, -10]} will convert four integers into an  Also, @samp{[-4, -10]} will convert four integers into an
19462  error form consisting of two fractions:  @samp{a:b +/- c:d}.  error form consisting of two fractions:  @samp{a:b +/- c:d}.
19463    
# Line 19346  number, you can use @samp{unpack(-10, @v Line 19557  number, you can use @samp{unpack(-10, @v
19557    
19558  @noindent  @noindent
19559  Vectors and matrices can be added,  Vectors and matrices can be added,
19560  subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.@refill  subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.
19561    
19562  @kindex |  @kindex |
19563  @pindex calc-concat  @pindex calc-concat
# Line 19392  prefix, if specified, must match the siz Line 19603  prefix, if specified, must match the siz
19603  the stack is a scalar, it is used for each element on the diagonal, and  the stack is a scalar, it is used for each element on the diagonal, and
19604  the prefix argument is required.  the prefix argument is required.
19605    
19606  To build a constant square matrix, e.g., a @c{$3\times3$}  To build a constant square matrix, e.g., a
19607  @asis{3x3} matrix filled with ones,  @texline @tmath{3\times3}
19608  use @kbd{0 M-3 v d 1 +}, i.e., build a zero matrix first and then add a  @infoline 3x3
19609  constant value to that matrix.  (Another alternative would be to use  matrix filled with ones, use @kbd{0 M-3 v d 1 +}, i.e., build a zero
19610  @kbd{v b} and @kbd{v a}; see below.)  matrix first and then add a constant value to that matrix.  (Another
19611    alternative would be to use @kbd{v b} and @kbd{v a}; see below.)
19612    
19613  @kindex v i  @kindex v i
19614  @pindex calc-ident  @pindex calc-ident
# Line 19407  where the diagonal element is always one Line 19619  where the diagonal element is always one
19619  this command prompts for one.  this command prompts for one.
19620    
19621  In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)},  In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)},
19622  except that @cite{a} is required to be a scalar (non-vector) quantity.  except that @expr{a} is required to be a scalar (non-vector) quantity.
19623  If @cite{n} is omitted, @samp{idn(a)} represents @cite{a} times an  If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an
19624  identity matrix of unknown size.  Calc can operate algebraically on  identity matrix of unknown size.  Calc can operate algebraically on
19625  such generic identity matrices, and if one is combined with a matrix  such generic identity matrices, and if one is combined with a matrix
19626  whose size is known, it is converted automatically to an identity  whose size is known, it is converted automatically to an identity
# Line 19531  submatrix is returned. Line 19743  submatrix is returned.
19743  @tindex _  @tindex _
19744  Subscript notation in algebraic formulas (@samp{a_b}) stands for the  Subscript notation in algebraic formulas (@samp{a_b}) stands for the
19745  Calc function @code{subscr}, which is synonymous with @code{mrow}.  Calc function @code{subscr}, which is synonymous with @code{mrow}.
19746  Thus, @samp{[x, y, z]_k} produces @cite{x}, @cite{y}, or @cite{z} if  Thus, @samp{[x, y, z]_k} produces @expr{x}, @expr{y}, or @expr{z} if
19747  @cite{k} is one, two, or three, respectively.  A double subscript  @expr{k} is one, two, or three, respectively.  A double subscript
19748  (@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will  (@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will
19749  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.
19750  The @kbd{a _} (@code{calc-subscript}) command creates a subscript  The @kbd{a _} (@code{calc-subscript}) command creates a subscript
19751  formula @samp{a_b} out of two stack entries.  (It is on the @kbd{a}  formula @samp{a_b} out of two stack entries.  (It is on the @kbd{a}
19752  ``algebra'' prefix because subscripted variables are often used  ``algebra'' prefix because subscripted variables are often used
# Line 19561  the analogous operation on columns of a Line 19773  the analogous operation on columns of a
19773  it extracts (or removes) one element, just like @kbd{v r}.  If the  it extracts (or removes) one element, just like @kbd{v r}.  If the
19774  index in @kbd{C-u v c} is an interval or vector and the argument is a  index in @kbd{C-u v c} is an interval or vector and the argument is a
19775  matrix, the result is a submatrix with only the specified columns  matrix, the result is a submatrix with only the specified columns
19776  retained (and possibly permuted in the case of a vector index).@refill  retained (and possibly permuted in the case of a vector index).
19777    
19778  To extract a matrix element at a given row and column, use @kbd{v r} to  To extract a matrix element at a given row and column, use @kbd{v r} to
19779  extract the row as a vector, then @kbd{v c} to extract the column element  extract the row as a vector, then @kbd{v c} to extract the column element
19780  from that vector.  In algebraic formulas, it is often more convenient to  from that vector.  In algebraic formulas, it is often more convenient to
19781  use subscript notation:  @samp{m_i_j} gives row @cite{i}, column @cite{j}  use subscript notation:  @samp{m_i_j} gives row @expr{i}, column @expr{j}
19782  of matrix @cite{m}.  of matrix @expr{m}.
19783    
19784  @kindex v s  @kindex v s
19785  @pindex calc-subvector  @pindex calc-subvector
# Line 19610  vectors one element at a time. Line 19822  vectors one element at a time.
19822  The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the  The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the
19823  length of a vector.  The length of a non-vector is considered to be zero.  length of a vector.  The length of a non-vector is considered to be zero.
19824  Note that matrices are just vectors of vectors for the purposes of this  Note that matrices are just vectors of vectors for the purposes of this
19825  command.@refill  command.
19826    
19827  @kindex H v l  @kindex H v l
19828  @tindex mdims  @tindex mdims
19829  With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector  With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector
19830  of the dimensions of a vector, matrix, or higher-order object.  For  of the dimensions of a vector, matrix, or higher-order object.  For
19831  example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since  example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since
19832  its argument is a @c{$2\times3$}  its argument is a
19833  @asis{2x3} matrix.  @texline @tmath{2\times3}
19834    @infoline 2x3
19835    matrix.
19836    
19837  @kindex v f  @kindex v f
19838  @pindex calc-vector-find  @pindex calc-vector-find
# Line 19647  If the number of columns does not evenly Line 19861  If the number of columns does not evenly
19861  in the vector, the last row will be short and the result will not be  in the vector, the last row will be short and the result will not be
19862  suitable for use as a matrix.  For example, with the matrix  suitable for use as a matrix.  For example, with the matrix
19863  @samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces  @samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces
19864  @samp{[[1, 2, 3, 4]]} (a @c{$1\times4$}  @samp{[[1, 2, 3, 4]]} (a
19865  @asis{1x4} matrix), @kbd{v a 1} produces  @texline @tmath{1\times4}
19866  @samp{[[1], [2], [3], [4]]} (a @c{$4\times1$}  @infoline 1x4
19867  @asis{4x1} matrix), @kbd{v a 2} produces  matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a
19868  @samp{[[1, 2], [3, 4]]} (the original @c{$2\times2$}  @texline @tmath{4\times1}
19869  @asis{2x2} matrix), @w{@kbd{v a 3}} produces  @infoline 4x1
19870  @samp{[[1, 2, 3], [4]]} (not a matrix), and @kbd{v a 0} produces  matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original
19871  the flattened list @samp{[1, 2, @w{3, 4}]}.  @texline @tmath{2\times2}
19872    @infoline 2x2
19873    matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a
19874    matrix), and @kbd{v a 0} produces the flattened list
19875    @samp{[1, 2, @w{3, 4}]}.
19876    
19877  @cindex Sorting data  @cindex Sorting data
19878  @kindex V S  @kindex V S
# Line 19810  matrix actually uses LU-decomposition fo Line 20028  matrix actually uses LU-decomposition fo
20028  The following functions are applied element-wise if their arguments are  The following functions are applied element-wise if their arguments are
20029  vectors or matrices: @code{change-sign}, @code{conj}, @code{arg},  vectors or matrices: @code{change-sign}, @code{conj}, @code{arg},
20030  @code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean},  @code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean},
20031  @code{float}, @code{frac}.  @xref{Function Index}.@refill  @code{float}, @code{frac}.  @xref{Function Index}.
20032    
20033  @kindex V J  @kindex V J
20034  @pindex calc-conj-transpose  @pindex calc-conj-transpose
# Line 19832  Frobenius norm of a vector or matrix arg Line 20050  Frobenius norm of a vector or matrix arg
20050  root of the sum of the squares of the absolute values of the  root of the sum of the squares of the absolute values of the
20051  elements of the vector or matrix.  If the vector is interpreted as  elements of the vector or matrix.  If the vector is interpreted as
20052  a point in two- or three-dimensional space, this is the distance  a point in two- or three-dimensional space, this is the distance
20053  from that point to the origin.@refill  from that point to the origin.
20054    
20055  @kindex v n  @kindex v n
20056  @pindex calc-rnorm  @pindex calc-rnorm
# Line 19851  The @kbd{V N} (@code{calc-cnorm}) [@code Line 20069  The @kbd{V N} (@code{calc-cnorm}) [@code
20069  the column norm, or one-norm, of a vector or matrix.  For a plain  the column norm, or one-norm, of a vector or matrix.  For a plain
20070  vector, this is the sum of the absolute values of the elements.  vector, this is the sum of the absolute values of the elements.
20071  For a matrix, this is the maximum of the column-absolute-value-sums.  For a matrix, this is the maximum of the column-absolute-value-sums.
20072  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
20073  not provided.  not provided.
20074    
20075  @kindex V C  @kindex V C
# Line 19877  that once an inverse (or determinant) of Line 20095  that once an inverse (or determinant) of
20095  computed, the inverse and determinant of the matrix can be recomputed  computed, the inverse and determinant of the matrix can be recomputed
20096  quickly in the future.  quickly in the future.
20097    
20098  If the argument to @kbd{&} is a plain number @cite{x}, this  If the argument to @kbd{&} is a plain number @expr{x}, this
20099  command simply computes @cite{1/x}.  This is okay, because the  command simply computes @expr{1/x}.  This is okay, because the
20100  @samp{/} operator also does a matrix inversion when dividing one  @samp{/} operator also does a matrix inversion when dividing one
20101  by a matrix.  by a matrix.
20102    
# Line 19936  The result is always a vector, except th Line 20154  The result is always a vector, except th
20154  single interval, the interval itself is returned instead.  single interval, the interval itself is returned instead.
20155    
20156  @xref{Logical Operations}, for the @code{in} function which tests if  @xref{Logical Operations}, for the @code{in} function which tests if
20157  a certain value is a member of a given set.  To test if the set @cite{A}  a certain value is a member of a given set.  To test if the set @expr{A}
20158  is a subset of the set @cite{B}, use @samp{vdiff(A, B) = []}.  is a subset of the set @expr{B}, use @samp{vdiff(A, B) = []}.
20159    
20160  @kindex V +  @kindex V +
20161  @pindex calc-remove-duplicates  @pindex calc-remove-duplicates
# Line 19969  and only if it is in both of the input s Line 20187  and only if it is in both of the input s
20187  sets are disjoint, i.e., if they share no common elements, the result  sets are disjoint, i.e., if they share no common elements, the result
20188  will be the empty vector @samp{[]}.  Note that the characters @kbd{V}  will be the empty vector @samp{[]}.  Note that the characters @kbd{V}
20189  and @kbd{^} were chosen to be close to the conventional mathematical  and @kbd{^} were chosen to be close to the conventional mathematical
20190  notation for set union@c{ ($A \cup B$)}  notation for set
20191  @asis{} and intersection@c{ ($A \cap B$)}  @texline union@tie{}(@tmath{A \cup B})
20192  @asis{}.  @infoline union
20193    and
20194    @texline intersection@tie{}(@tmath{A \cap B}).
20195    @infoline intersection.
20196    
20197  @kindex V -  @kindex V -
20198  @pindex calc-set-difference  @pindex calc-set-difference
20199  @tindex vdiff  @tindex vdiff
20200  The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes  The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes
20201  the difference between two sets.  An object is in the difference  the difference between two sets.  An object is in the difference
20202  @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}.
20203  Thus subtracting @samp{[y,z]} from a set will remove the elements  Thus subtracting @samp{[y,z]} from a set will remove the elements
20204  @samp{y} and @samp{z} if they are present.  You can also think of this  @samp{y} and @samp{z} if they are present.  You can also think of this
20205  as a general @dfn{set complement} operator; if @cite{A} is the set of  as a general @dfn{set complement} operator; if @expr{A} is the set of
20206  all possible values, then @cite{A - B} is the ``complement'' of @cite{B}.  all possible values, then @expr{A - B} is the ``complement'' of @expr{B}.
20207  Obviously this is only practical if the set of all possible values in  Obviously this is only practical if the set of all possible values in
20208  your problem is small enough to list in a Calc vector (or simple  your problem is small enough to list in a Calc vector (or simple
20209  enough to express in a few intervals).  enough to express in a few intervals).
# Line 20078  the same set.  The set may include posit Line 20299  the same set.  The set may include posit
20299  not include any negative numbers.  The input is interpreted as a  not include any negative numbers.  The input is interpreted as a
20300  set of integers in the sense of @kbd{V F} (@code{vfloor}).  Beware  set of integers in the sense of @kbd{V F} (@code{vfloor}).  Beware
20301  that a simple input like @samp{[100]} can result in a huge integer  that a simple input like @samp{[100]} can result in a huge integer
20302  representation (@c{$2^{100}$}  representation
20303  @cite{2^100}, a 31-digit integer, in this case).  @texline (@tmath{2^{100}}, a 31-digit integer, in this case).
20304    @infoline (@expr{2^100}, a 31-digit integer, in this case).
20305    
20306  @node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions  @node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions
20307  @section Statistical Operations on Vectors  @section Statistical Operations on Vectors
# Line 20167  computes the sum of the data values.  Th Line 20389  computes the sum of the data values.  Th
20389  (@code{calc-vector-prod}) [@code{vprod}] command computes the  (@code{calc-vector-prod}) [@code{vprod}] command computes the
20390  product of the data values.  If the input is a single flat vector,  product of the data values.  If the input is a single flat vector,
20391  these are the same as @kbd{V R +} and @kbd{V R *}  these are the same as @kbd{V R +} and @kbd{V R *}
20392  (@pxref{Reducing and Mapping}).@refill  (@pxref{Reducing and Mapping}).
20393    
20394  @kindex u X  @kindex u X
20395  @kindex u N  @kindex u N
# Line 20189  plus or minus infinity. Line 20411  plus or minus infinity.
20411  @cindex Mean of data values  @cindex Mean of data values
20412  The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command  The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command
20413  computes the average (arithmetic mean) of the data values.  computes the average (arithmetic mean) of the data values.
20414  If the inputs are error forms @c{$x$ @code{+/-} $\sigma$}  If the inputs are error forms
20415  @samp{x +/- s}, this is the weighted  @texline @tmath{x \pm \sigma},
20416  mean of the @cite{x} values with weights @c{$1 / \sigma^2$}  @infoline @samp{x +/- s},
20417  @cite{1 / s^2}.  this is the weighted mean of the @expr{x} values with weights
20418    @texline @tmath{1 /\sigma^2}.
20419    @infoline @expr{1 / s^2}.
20420  @tex  @tex
20421  \turnoffactive  \turnoffactive
20422  $$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over  $$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over
20423             \displaystyle \sum { 1 \over \sigma_i^2 } } $$             \displaystyle \sum { 1 \over \sigma_i^2 } } $$
20424  @end tex  @end tex
20425  If the inputs are not error forms, this is simply the sum of the  If the inputs are not error forms, this is simply the sum of the
20426  values divided by the count of the values.@refill  values divided by the count of the values.
20427    
20428  Note that a plain number can be considered an error form with  Note that a plain number can be considered an error form with
20429  error @c{$\sigma = 0$}  error
20430  @cite{s = 0}.  If the input to @kbd{u M} is a mixture of  @texline @tmath{\sigma = 0}.
20431    @infoline @expr{s = 0}.  
20432    If the input to @kbd{u M} is a mixture of
20433  plain numbers and error forms, the result is the mean of the  plain numbers and error forms, the result is the mean of the
20434  plain numbers, ignoring all values with non-zero errors.  (By the  plain numbers, ignoring all values with non-zero errors.  (By the
20435  above definitions it's clear that a plain number effectively  above definitions it's clear that a plain number effectively
# Line 20212  weight is completely negligible.) Line 20438  weight is completely negligible.)
20438    
20439  This function also works for distributions (error forms or  This function also works for distributions (error forms or
20440  intervals).  The mean of an error form `@var{a} @t{+/-} @var{b}' is simply  intervals).  The mean of an error form `@var{a} @t{+/-} @var{b}' is simply
20441  @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
20442  and maximum values of the interval.  and maximum values of the interval.
20443    
20444  @kindex I u M  @kindex I u M
# Line 20234  numbers, the error is equal to the stand Line 20460  numbers, the error is equal to the stand
20460  divided by the square root of the number of values.  (This works  divided by the square root of the number of values.  (This works
20461  out to be equivalent to calculating the standard deviation and  out to be equivalent to calculating the standard deviation and
20462  then assuming each value's error is equal to this standard  then assuming each value's error is equal to this standard
20463  deviation.)@refill  deviation.)
20464  @tex  @tex
20465  \turnoffactive  \turnoffactive
20466  $$ \sigma_\mu^2 = {\sigma^2 \over N} $$  $$ \sigma_\mu^2 = {\sigma^2 \over N} $$
# Line 20309  for a vector of numbers simply by using Line 20535  for a vector of numbers simply by using
20535  @cindex Standard deviation  @cindex Standard deviation
20536  @cindex Sample statistics  @cindex Sample statistics
20537  The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command  The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command
20538  computes the standard deviation@c{ $\sigma$}  computes the standard
20539  @asis{} of the data values.  If the  @texline deviation@tie{}@tmath{\sigma}
20540  values are error forms, the errors are used as weights just  @infoline deviation
20541  as for @kbd{u M}.  This is the @emph{sample} standard deviation,  of the data values.  If the values are error forms, the errors are used
20542  whose value is the square root of the sum of the squares of the  as weights just as for @kbd{u M}.  This is the @emph{sample} standard
20543  differences between the values and the mean of the @cite{N} values,  deviation, whose value is the square root of the sum of the squares of
20544  divided by @cite{N-1}.  the differences between the values and the mean of the @expr{N} values,
20545    divided by @expr{N-1}.
20546  @tex  @tex
20547  \turnoffactive  \turnoffactive
20548  $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$  $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$
# Line 20324  $$ \sigma^2 = {1 \over N - 1} \sum (x_i Line 20551  $$ \sigma^2 = {1 \over N - 1} \sum (x_i
20551  This function also applies to distributions.  The standard deviation  This function also applies to distributions.  The standard deviation
20552  of a single error form is simply the error part.  The standard deviation  of a single error form is simply the error part.  The standard deviation
20553  of a continuous interval happens to equal the difference between the  of a continuous interval happens to equal the difference between the
20554  limits, divided by @c{$\sqrt{12}$}  limits, divided by
20555  @cite{sqrt(12)}.  The standard deviation of an  @texline @tmath{\sqrt{12}}.
20556  integer interval is the same as the standard deviation of a vector  @infoline @expr{sqrt(12)}.  
20557  of those integers.  The standard deviation of an integer interval is the same as the
20558    standard deviation of a vector of those integers.
20559    
20560  @kindex I u S  @kindex I u S
20561  @pindex calc-vector-pop-sdev  @pindex calc-vector-pop-sdev
# Line 20336  of those integers. Line 20564  of those integers.
20564  The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}]  The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}]
20565  command computes the @emph{population} standard deviation.  command computes the @emph{population} standard deviation.
20566  It is defined by the same formula as above but dividing  It is defined by the same formula as above but dividing
20567  by @cite{N} instead of by @cite{N-1}.  The population standard  by @expr{N} instead of by @expr{N-1}.  The population standard
20568  deviation is used when the input represents the entire set of  deviation is used when the input represents the entire set of
20569  data values in the distribution; the sample standard deviation  data values in the distribution; the sample standard deviation
20570  is used when the input represents a sample of the set of all  is used when the input represents a sample of the set of all
# Line 20361  population standard deviation of the equ Line 20589  population standard deviation of the equ
20589  The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and  The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and
20590  @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}]  @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}]
20591  commands compute the variance of the data values.  The variance  commands compute the variance of the data values.  The variance
20592  is the square@c{ $\sigma^2$}  is the
20593  @asis{} of the standard deviation, i.e., the sum of the  @texline square@tie{}@tmath{\sigma^2}
20594    @infoline square
20595    of the standard deviation, i.e., the sum of the
20596  squares of the deviations of the data values from the mean.  squares of the deviations of the data values from the mean.
20597  (This definition also applies when the argument is a distribution.)  (This definition also applies when the argument is a distribution.)
20598    
# Line 20383  The functions in this section take two a Line 20613  The functions in this section take two a
20613  vectors of equal size.  The vectors are each flattened in the same  vectors of equal size.  The vectors are each flattened in the same
20614  way as by the single-variable statistical functions.  Given a numeric  way as by the single-variable statistical functions.  Given a numeric
20615  prefix argument of 1, these functions instead take one object from  prefix argument of 1, these functions instead take one object from
20616  the stack, which must be an @c{$N\times2$}  the stack, which must be an
20617  @asis{Nx2} matrix of data values.  Once  @texline @tmath{N\times2}
20618  again, variable names can be used in place of actual vectors and  @infoline Nx2
20619  matrices.  matrix of data values.  Once again, variable names can be used in place
20620    of actual vectors and matrices.
20621    
20622  @kindex u C  @kindex u C
20623  @pindex calc-vector-covariance  @pindex calc-vector-covariance
# Line 20397  computes the sample covariance of two ve Line 20628  computes the sample covariance of two ve
20628  of vectors @var{x} and @var{y} is the sum of the products of the  of vectors @var{x} and @var{y} is the sum of the products of the
20629  differences between the elements of @var{x} and the mean of @var{x}  differences between the elements of @var{x} and the mean of @var{x}
20630  times the differences between the corresponding elements of @var{y}  times the differences between the corresponding elements of @var{y}
20631  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
20632  the variance of a vector is just the covariance of the vector  the variance of a vector is just the covariance of the vector
20633  with itself.  Once again, if the inputs are error forms the  with itself.  Once again, if the inputs are error forms the
20634  errors are used as weight factors.  If both @var{x} and @var{y}  errors are used as weight factors.  If both @var{x} and @var{y}
# Line 20419  $$ Line 20650  $$
20650  @tindex vpcov  @tindex vpcov
20651  The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}]  The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}]
20652  command computes the population covariance, which is the same as the  command computes the population covariance, which is the same as the
20653  sample covariance computed by @kbd{u C} except dividing by @cite{N}  sample covariance computed by @kbd{u C} except dividing by @expr{N}
20654  instead of @cite{N-1}.  instead of @expr{N-1}.
20655    
20656  @kindex H u C  @kindex H u C
20657  @pindex calc-vector-correlation  @pindex calc-vector-correlation
# Line 20598  and is either a variable whose name is t Line 20829  and is either a variable whose name is t
20829  or a nameless function like @samp{<#^3+1>}.  Operators that are normally  or a nameless function like @samp{<#^3+1>}.  Operators that are normally
20830  written as algebraic symbols have the names @code{add}, @code{sub},  written as algebraic symbols have the names @code{add}, @code{sub},
20831  @code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and  @code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and
20832  @code{vconcat}.@refill  @code{vconcat}.
20833    
20834  @ignore  @ignore
20835  @starindex  @starindex
# Line 20635  is duplicated for each element of the ot Line 20866  is duplicated for each element of the ot
20866  With the 2 listed first, it would have computed a vector of powers of  With the 2 listed first, it would have computed a vector of powers of
20867  two.  Mapping a user-defined function pops as many arguments from the  two.  Mapping a user-defined function pops as many arguments from the
20868  stack as the function requires.  If you give an undefined name, you will  stack as the function requires.  If you give an undefined name, you will
20869  be prompted for the number of arguments to use.@refill  be prompted for the number of arguments to use.
20870    
20871  If any argument to @kbd{V M} is a matrix, the operator is normally mapped  If any argument to @kbd{V M} is a matrix, the operator is normally mapped
20872  across all elements of the matrix.  For example, given the matrix  across all elements of the matrix.  For example, given the matrix
20873  @cite{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to  @expr{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to
20874  produce another @c{$3\times2$}  produce another
20875  @asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}.  @texline @tmath{3\times2}
20876    @infoline 3x2
20877    matrix, @expr{[[1, 2, 3], [4, 5, 6]]}.
20878    
20879  @tindex mapr  @tindex mapr
20880  The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the  The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the
20881  operator prompt) maps by rows instead.  For example, @kbd{V M _ A} views  operator prompt) maps by rows instead.  For example, @kbd{V M _ A} views
20882  the above matrix as a vector of two 3-element row vectors.  It produces  the above matrix as a vector of two 3-element row vectors.  It produces
20883  a new vector which contains the absolute values of those row vectors,  a new vector which contains the absolute values of those row vectors,
20884  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
20885  defined as the square root of the sum of the squares of the elements.)  defined as the square root of the sum of the squares of the elements.)
20886  Some operators accept vectors and return new vectors; for example,  Some operators accept vectors and return new vectors; for example,
20887  @kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row  @kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row
20888  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]]}.
20889    
20890  Sometimes a vector of vectors (representing, say, strings, sets, or lists)  Sometimes a vector of vectors (representing, say, strings, sets, or lists)
20891  happens to look like a matrix.  If so, remember to use @kbd{V M _} if you  happens to look like a matrix.  If so, remember to use @kbd{V M _} if you
# Line 20665  transposes the input matrix, maps by row Line 20898  transposes the input matrix, maps by row
20898  matrix, transposes again.  For example, @kbd{V M : A} takes the absolute  matrix, transposes again.  For example, @kbd{V M : A} takes the absolute
20899  values of the three columns of the matrix, treating each as a 2-vector,  values of the three columns of the matrix, treating each as a 2-vector,
20900  and @kbd{V M : v v} reverses the columns to get the matrix  and @kbd{V M : v v} reverses the columns to get the matrix
20901  @cite{[[-4, 5, -6], [1, -2, 3]]}.  @expr{[[-4, 5, -6], [1, -2, 3]]}.
20902    
20903  (The symbols @kbd{_} and @kbd{:} were chosen because they had row-like  (The symbols @kbd{_} and @kbd{:} were chosen because they had row-like
20904  and column-like appearances, and were not already taken by useful  and column-like appearances, and were not already taken by useful
# Line 20756  vector @samp{[a - b + c - d, b - c + d, Line 20989  vector @samp{[a - b + c - d, b - c + d,
20989  @tindex reduced  @tindex reduced
20990  @tindex rreduced  @tindex rreduced
20991  As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise.  For  As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise.  For
20992  example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will  example, given the matrix @expr{[[a, b, c], [d, e, f]]}, @kbd{V R +} will
20993  compute @cite{a + b + c + d + e + f}.  You can type @kbd{V R _} or  compute @expr{a + b + c + d + e + f}.  You can type @kbd{V R _} or
20994  @kbd{V R :} to modify this behavior.  The @kbd{V R _} [@code{reducea}]  @kbd{V R :} to modify this behavior.  The @kbd{V R _} [@code{reducea}]
20995  command reduces ``across'' the matrix; it reduces each row of the matrix  command reduces ``across'' the matrix; it reduces each row of the matrix
20996  as a vector, then collects the results.  Thus @kbd{V R _ +} of this  as a vector, then collects the results.  Thus @kbd{V R _ +} of this
20997  matrix would produce @cite{[a + b + c, d + e + f]}.  Similarly, @kbd{V R :}  matrix would produce @expr{[a + b + c, d + e + f]}.  Similarly, @kbd{V R :}
20998  [@code{reduced}] reduces down; @kbd{V R : +} would produce @cite{[a + d,  [@code{reduced}] reduces down; @kbd{V R : +} would produce @expr{[a + d,
20999  b + e, c + f]}.  b + e, c + f]}.
21000    
21001  @tindex reducer  @tindex reducer
# Line 20919  influenced by the @kbd{d O} (@code{calc- Line 21152  influenced by the @kbd{d O} (@code{calc-
21152  The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >}  The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >}
21153  (@code{calc-matrix-right-justify}), and @w{@kbd{v =}}  (@code{calc-matrix-right-justify}), and @w{@kbd{v =}}
21154  (@code{calc-matrix-center-justify}) control whether matrix elements  (@code{calc-matrix-center-justify}) control whether matrix elements
21155  are justified to the left, right, or center of their columns.@refill  are justified to the left, right, or center of their columns.
21156    
21157  @kindex V [  @kindex V [
21158  @pindex calc-vector-brackets  @pindex calc-vector-brackets
# Line 20936  be used in preparation for yanking a mat Line 21169  be used in preparation for yanking a mat
21169  Mathematica.  (In fact, the Mathematica language mode uses this mode;  Mathematica.  (In fact, the Mathematica language mode uses this mode;
21170  @pxref{Mathematica Language Mode}.)  Note that, regardless of the  @pxref{Mathematica Language Mode}.)  Note that, regardless of the
21171  display mode, either brackets or braces may be used to enter vectors,  display mode, either brackets or braces may be used to enter vectors,
21172  and parentheses may never be used for this purpose.@refill  and parentheses may never be used for this purpose.
21173    
21174  @kindex V ]  @kindex V ]
21175  @pindex calc-matrix-brackets  @pindex calc-matrix-brackets
# Line 20989  the others are useful for display only. Line 21222  the others are useful for display only.
21222  @kindex V ,  @kindex V ,
21223  @pindex calc-vector-commas  @pindex calc-vector-commas
21224  The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and  The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and
21225  off in vector and matrix display.@refill  off in vector and matrix display.
21226    
21227  In vectors of length one, and in all vectors when commas have been  In vectors of length one, and in all vectors when commas have been
21228  turned off, Calc adds extra parentheses around formulas that might  turned off, Calc adds extra parentheses around formulas that might
# Line 21047  commands use the @kbd{j} (for ``just a l Line 21280  commands use the @kbd{j} (for ``just a l
21280  for anything else'') prefix.  for anything else'') prefix.
21281    
21282  @xref{Editing Stack Entries}, to see how to manipulate formulas  @xref{Editing Stack Entries}, to see how to manipulate formulas
21283  using regular Emacs editing commands.@refill  using regular Emacs editing commands.
21284    
21285  When doing algebraic work, you may find several of the Calculator's  When doing algebraic work, you may find several of the Calculator's
21286  modes to be helpful, including algebraic-simplification mode (@kbd{m A})  modes to be helpful, including algebraic-simplification mode (@kbd{m A})
# Line 21055  or no-simplification mode (@kbd{m O}), Line 21288  or no-simplification mode (@kbd{m O}),
21288  algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and  algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
21289  symbolic mode (@kbd{m s}).  @xref{Mode Settings}, for discussions  symbolic mode (@kbd{m s}).  @xref{Mode Settings}, for discussions
21290  of these modes.  You may also wish to select ``big'' display mode (@kbd{d B}).  of these modes.  You may also wish to select ``big'' display mode (@kbd{d B}).
21291  @xref{Normal Language Modes}.@refill  @xref{Normal Language Modes}.
21292    
21293  @menu  @menu
21294  * Selecting Subformulas::  * Selecting Subformulas::
# Line 21213  has a selection they have no effect.  Th Line 21446  has a selection they have no effect.  Th
21446  behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection};  behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection};
21447  @pxref{Selections with Rewrite Rules}) and is mainly intended to be  @pxref{Selections with Rewrite Rules}) and is mainly intended to be
21448  used in keyboard macros that implement your own selection-oriented  used in keyboard macros that implement your own selection-oriented
21449  commands.@refill  commands.
21450    
21451  Selection of sub-formulas normally treats associative terms like  Selection of sub-formulas normally treats associative terms like
21452  @samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula.  @samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula.
# Line 21311  If there is no current selection, @kbd{j Line 21544  If there is no current selection, @kbd{j
21544  the @var{n}th top-level sub-formula.  (In other words, they act as if  the @var{n}th top-level sub-formula.  (In other words, they act as if
21545  the entire stack entry were selected first.)  To select the @var{n}th  the entire stack entry were selected first.)  To select the @var{n}th
21546  sub-formula where @var{n} is greater than nine, you must instead invoke  sub-formula where @var{n} is greater than nine, you must instead invoke
21547  @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.
21548    
21549  @kindex j n  @kindex j n
21550  @kindex j p  @kindex j p
# Line 21493  the command will abort with an error mes Line 21726  the command will abort with an error mes
21726  Operations on sub-formulas sometimes leave the formula as a whole  Operations on sub-formulas sometimes leave the formula as a whole
21727  in an ``un-natural'' state.  Consider negating the @samp{2 x} term  in an ``un-natural'' state.  Consider negating the @samp{2 x} term
21728  of our sample formula by selecting it and pressing @kbd{n}  of our sample formula by selecting it and pressing @kbd{n}
21729  (@code{calc-change-sign}).@refill  (@code{calc-change-sign}).
21730    
21731  @smallexample  @smallexample
21732  @group  @group
# Line 21850  a given function or operator to one or m Line 22083  a given function or operator to one or m
22083  to @kbd{V M}, which operates on vectors instead of equations.  to @kbd{V M}, which operates on vectors instead of equations.
22084  @pxref{Reducing and Mapping}.  For example, @kbd{a M S} changes  @pxref{Reducing and Mapping}.  For example, @kbd{a M S} changes
22085  @samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with  @samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with
22086  @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}.
22087  With two equations on the stack, @kbd{a M +} would add the lefthand  With two equations on the stack, @kbd{a M +} would add the lefthand
22088  sides together and the righthand sides together to get the two  sides together and the righthand sides together to get the two
22089  respective sides of a new equation.  respective sides of a new equation.
# Line 21899  in @samp{2 sin(x)^2 + x sin(x) + sin(2 x Line 22132  in @samp{2 sin(x)^2 + x sin(x) + sin(2 x
22132  Note that this is a purely structural substitution; the lone @samp{x} and  Note that this is a purely structural substitution; the lone @samp{x} and
22133  the @samp{sin(2 x)} stayed the same because they did not look like  the @samp{sin(2 x)} stayed the same because they did not look like
22134  @samp{sin(x)}.  @xref{Rewrite Rules}, for a more general method for  @samp{sin(x)}.  @xref{Rewrite Rules}, for a more general method for
22135  doing substitutions.@refill  doing substitutions.
22136    
22137  The @kbd{a b} command normally prompts for two formulas, the old  The @kbd{a b} command normally prompts for two formulas, the old
22138  one and the new one.  If you enter a blank line for the first  one and the new one.  If you enter a blank line for the first
# Line 21966  simplifications'' occur. Line 22199  simplifications'' occur.
22199  @cindex Default simplifications  @cindex Default simplifications
22200  This section describes the ``default simplifications,'' those which are  This section describes the ``default simplifications,'' those which are
22201  normally applied to all results.  For example, if you enter the variable  normally applied to all results.  For example, if you enter the variable
22202  @cite{x} on the stack twice and push @kbd{+}, Calc's default  @expr{x} on the stack twice and push @kbd{+}, Calc's default
22203  simplifications automatically change @cite{x + x} to @cite{2 x}.  simplifications automatically change @expr{x + x} to @expr{2 x}.
22204    
22205  The @kbd{m O} command turns off the default simplifications, so that  The @kbd{m O} command turns off the default simplifications, so that
22206  @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
22207  ``simplify'' command like @kbd{=} or @kbd{a v}.  @xref{Algebraic  ``simplify'' command like @kbd{=} or @kbd{a v}.  @xref{Algebraic
22208  Manipulation}.  The @kbd{m D} command turns the default simplifications  Manipulation}.  The @kbd{m D} command turns the default simplifications
22209  back on.  back on.
22210    
22211  The most basic default simplification is the evaluation of functions.  The most basic default simplification is the evaluation of functions.
22212  For example, @cite{2 + 3} is evaluated to @cite{5}, and @cite{@t{sqrt}(9)}  For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@t{sqrt}(9)}
22213  is evaluated to @cite{3}.  Evaluation does not occur if the arguments  is evaluated to @expr{3}.  Evaluation does not occur if the arguments
22214  to a function are somehow of the wrong type (@cite{@t{tan}([2,3,4])}),  to a function are somehow of the wrong type @expr{@t{tan}([2,3,4])}),
22215  range (@cite{@t{tan}(90)}), or number (@cite{@t{tan}(3,5)}), or if the  range (@expr{@t{tan}(90)}), or number (@expr{@t{tan}(3,5)}),
22216  function name is not recognized (@cite{@t{f}(5)}), or if ``symbolic''  or if the function name is not recognized (@expr{@t{f}(5)}), or if
22217  mode (@pxref{Symbolic Mode}) prevents evaluation (@cite{@t{sqrt}(2)}).  ``symbolic'' mode (@pxref{Symbolic Mode}) prevents evaluation
22218    (@expr{@t{sqrt}(2)}).
22219    
22220  Calc simplifies (evaluates) the arguments to a function before it  Calc simplifies (evaluates) the arguments to a function before it
22221  simplifies the function itself.  Thus @cite{@t{sqrt}(5+4)} is  simplifies the function itself.  Thus @expr{@t{sqrt}(5+4)} is
22222  simplified to @cite{@t{sqrt}(9)} before the @code{sqrt} function  simplified to @expr{@t{sqrt}(9)} before the @code{sqrt} function
22223  itself is applied.  There are very few exceptions to this rule:  itself is applied.  There are very few exceptions to this rule:
22224  @code{quote}, @code{lambda}, and @code{condition} (the @code{::}  @code{quote}, @code{lambda}, and @code{condition} (the @code{::}
22225  operator) do not evaluate their arguments, @code{if} (the @code{? :}  operator) do not evaluate their arguments, @code{if} (the @code{? :}
# Line 22024  And now, on with the default simplificat Line 22258  And now, on with the default simplificat
22258  Arithmetic operators like @kbd{+} and @kbd{*} always take two  Arithmetic operators like @kbd{+} and @kbd{*} always take two
22259  arguments in Calc's internal form.  Sums and products of three or  arguments in Calc's internal form.  Sums and products of three or
22260  more terms are arranged by the associative law of algebra into  more terms are arranged by the associative law of algebra into
22261  a left-associative form for sums, @cite{((a + b) + c) + d}, and  a left-associative form for sums, @expr{((a + b) + c) + d}, and
22262  a right-associative form for products, @cite{a * (b * (c * d))}.  a right-associative form for products, @expr{a * (b * (c * d))}.
22263  Formulas like @cite{(a + b) + (c + d)} are rearranged to  Formulas like @expr{(a + b) + (c + d)} are rearranged to
22264  left-associative form, though this rarely matters since Calc's  left-associative form, though this rarely matters since Calc's
22265  algebra commands are designed to hide the inner structure of  algebra commands are designed to hide the inner structure of
22266  sums and products as much as possible.  Sums and products in  sums and products as much as possible.  Sums and products in
# Line 22034  their proper associative form will be wr Line 22268  their proper associative form will be wr
22268  in the examples below.  in the examples below.
22269    
22270  Sums and products are @emph{not} rearranged according to the  Sums and products are @emph{not} rearranged according to the
22271  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
22272  special cases described below.  Some algebra programs always  special cases described below.  Some algebra programs always
22273  rearrange terms into a canonical order, which enables them to  rearrange terms into a canonical order, which enables them to
22274  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}.
22275  Calc assumes you have put the terms into the order you want  Calc assumes you have put the terms into the order you want
22276  and generally leaves that order alone, with the consequence  and generally leaves that order alone, with the consequence
22277  that formulas like the above will only be simplified if you  that formulas like the above will only be simplified if you
22278  explicitly give the @kbd{a s} command.  @xref{Algebraic  explicitly give the @kbd{a s} command.  @xref{Algebraic
22279  Simplifications}.  Simplifications}.
22280    
22281  Differences @cite{a - b} are treated like sums @cite{a + (-b)}  Differences @expr{a - b} are treated like sums @expr{a + (-b)}
22282  for purposes of simplification; one of the default simplifications  for purposes of simplification; one of the default simplifications
22283  is to rewrite @cite{a + (-b)} or @cite{(-b) + a}, where @cite{-b}  is to rewrite @expr{a + (-b)} or @expr{(-b) + a}, where @expr{-b}
22284  represents a ``negative-looking'' term, into @cite{a - b} form.  represents a ``negative-looking'' term, into @expr{a - b} form.
22285  ``Negative-looking'' means negative numbers, negated formulas like  ``Negative-looking'' means negative numbers, negated formulas like
22286  @cite{-x}, and products or quotients in which either term is  @expr{-x}, and products or quotients in which either term is
22287  negative-looking.  negative-looking.
22288    
22289  Other simplifications involving negation are @cite{-(-x)} to @cite{x};  Other simplifications involving negation are @expr{-(-x)} to @expr{x};
22290  @cite{-(a b)} or @cite{-(a/b)} where either @cite{a} or @cite{b} is  @expr{-(a b)} or @expr{-(a/b)} where either @expr{a} or @expr{b} is
22291  negative-looking, simplified by negating that term, or else where  negative-looking, simplified by negating that term, or else where
22292  @cite{a} or @cite{b} is any number, by negating that number;  @expr{a} or @expr{b} is any number, by negating that number;
22293  @cite{-(a + b)} to @cite{-a - b}, and @cite{-(b - a)} to @cite{a - b}.  @expr{-(a + b)} to @expr{-a - b}, and @expr{-(b - a)} to @expr{a - b}.
22294  (This, and rewriting @cite{(-b) + a} to @cite{a - b}, are the only  (This, and rewriting @expr{(-b) + a} to @expr{a - b}, are the only
22295  cases where the order of terms in a sum is changed by the default  cases where the order of terms in a sum is changed by the default
22296  simplifications.)  simplifications.)
22297    
22298  The distributive law is used to simplify sums in some cases:  The distributive law is used to simplify sums in some cases:
22299  @cite{a x + b x} to @cite{(a + b) x}, where @cite{a} represents  @expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents
22300  a number or an implicit 1 or @i{-1} (as in @cite{x} or @cite{-x})  a number or an implicit 1 or @i{-1} (as in @expr{x} or @expr{-x})
22301  and similarly for @cite{b}.  Use the @kbd{a c}, @w{@kbd{a f}}, or  and similarly for @expr{b}.  Use the @kbd{a c}, @w{@kbd{a f}}, or
22302  @kbd{j M} commands to merge sums with non-numeric coefficients  @kbd{j M} commands to merge sums with non-numeric coefficients
22303  using the distributive law.  using the distributive law.
22304    
22305  The distributive law is only used for sums of two terms, or  The distributive law is only used for sums of two terms, or
22306  for adjacent terms in a larger sum.  Thus @cite{a + b + b + c}  for adjacent terms in a larger sum.  Thus @expr{a + b + b + c}
22307  is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b}  is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b}
22308  is not simplified.  The reason is that comparing all terms of a  is not simplified.  The reason is that comparing all terms of a
22309  sum with one another would require time proportional to the  sum with one another would require time proportional to the
22310  square of the number of terms; Calc relegates potentially slow  square of the number of terms; Calc relegates potentially slow
22311  operations like this to commands that have to be invoked  operations like this to commands that have to be invoked
22312  explicitly, like @kbd{a s}.  explicitly, like @kbd{a s}.
22313    
22314  Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}.  Finally, @expr{a + 0} and @expr{0 + a} are simplified to @expr{a}.
22315  A consequence of the above rules is that @cite{0 - a} is simplified  A consequence of the above rules is that @expr{0 - a} is simplified
22316  to @cite{-a}.  to @expr{-a}.
22317    
22318  @tex  @tex
22319  \bigskip  \bigskip
22320  @end tex  @end tex
22321    
22322  The products @cite{1 a} and @cite{a 1} are simplified to @cite{a};  The products @expr{1 a} and @expr{a 1} are simplified to @expr{a};
22323  @cite{(-1) a} and @cite{a (-1)} are simplified to @cite{-a};  @expr{(-1) a} and @expr{a (-1)} are simplified to @expr{-a};
22324  @cite{0 a} and @cite{a 0} are simplified to @cite{0}, except that  @expr{0 a} and @expr{a 0} are simplified to @expr{0}, except that
22325  in matrix mode where @cite{a} is not provably scalar the result  in matrix mode where @expr{a} is not provably scalar the result
22326  is the generic zero matrix @samp{idn(0)}, and that if @cite{a} is  is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is
22327  infinite the result is @samp{nan}.  infinite the result is @samp{nan}.
22328    
22329  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)},
22330  where this occurs for negated formulas but not for regular negative  where this occurs for negated formulas but not for regular negative
22331  numbers.  numbers.
22332    
22333  Products are commuted only to move numbers to the front:  Products are commuted only to move numbers to the front:
22334  @cite{a b 2} is commuted to @cite{2 a b}.  @expr{a b 2} is commuted to @expr{2 a b}.
22335    
22336  The product @cite{a (b + c)} is distributed over the sum only if  The product @expr{a (b + c)} is distributed over the sum only if
22337  @cite{a} and at least one of @cite{b} and @cite{c} are numbers:  @expr{a} and at least one of @expr{b} and @expr{c} are numbers:
22338  @cite{2 (x + 3)} goes to @cite{2 x + 6}.  The formula  @expr{2 (x + 3)} goes to @expr{2 x + 6}.  The formula
22339  @cite{(-a) (b - c)}, where @cite{-a} is a negative number, is  @expr{(-a) (b - c)}, where @expr{-a} is a negative number, is
22340  rewritten to @cite{a (c - b)}.  rewritten to @expr{a (c - b)}.
22341    
22342  The distributive law of products and powers is used for adjacent  The distributive law of products and powers is used for adjacent
22343  terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$}  terms of the product: @expr{x^a x^b} goes to
22344  @cite{x^(a+b)}  @texline @tmath{x^{a+b}}
22345  where @cite{a} is a number, or an implicit 1 (as in @cite{x}),  @infoline @expr{x^(a+b)}
22346  or the implicit one-half of @cite{@t{sqrt}(x)}, and similarly for  where @expr{a} is a number, or an implicit 1 (as in @expr{x}),
22347  @cite{b}.  The result is written using @samp{sqrt} or @samp{1/sqrt}  or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for
22348  if the sum of the powers is @cite{1/2} or @cite{-1/2}, respectively.  @expr{b}.  The result is written using @samp{sqrt} or @samp{1/sqrt}
22349    if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively.
22350  If the sum of the powers is zero, the product is simplified to  If the sum of the powers is zero, the product is simplified to
22351  @cite{1} or to @samp{idn(1)} if matrix mode is enabled.  @expr{1} or to @samp{idn(1)} if matrix mode is enabled.
22352    
22353  The product of a negative power times anything but another negative  The product of a negative power times anything but another negative
22354  power is changed to use division:  @c{$x^{-2} y$}  power is changed to use division:  
22355  @cite{x^(-2) y} goes to @cite{y / x^2} unless matrix mode is  @texline @tmath{x^{-2} y}
22356  in effect and neither @cite{x} nor @cite{y} are scalar (in which  @infoline @expr{x^(-2) y}
22357    goes to @expr{y / x^2} unless matrix mode is
22358    in effect and neither @expr{x} nor @expr{y} are scalar (in which
22359  case it is considered unsafe to rearrange the order of the terms).  case it is considered unsafe to rearrange the order of the terms).
22360    
22361  Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also  Finally, @expr{a (b/c)} is rewritten to @expr{(a b)/c}, and also
22362  @cite{(a/b) c} is changed to @cite{(a c)/b} unless in matrix mode.  @expr{(a/b) c} is changed to @expr{(a c)/b} unless in matrix mode.
22363    
22364  @tex  @tex
22365  \bigskip  \bigskip
22366  @end tex  @end tex
22367    
22368  Simplifications for quotients are analogous to those for products.  Simplifications for quotients are analogous to those for products.
22369  The quotient @cite{0 / x} is simplified to @cite{0}, with the same  The quotient @expr{0 / x} is simplified to @expr{0}, with the same
22370  exceptions that were noted for @cite{0 x}.  Likewise, @cite{x / 1}  exceptions that were noted for @expr{0 x}.  Likewise, @expr{x / 1}
22371  and @cite{x / (-1)} are simplified to @cite{x} and @cite{-x},  and @expr{x / (-1)} are simplified to @expr{x} and @expr{-x},
22372  respectively.  respectively.
22373    
22374  The quotient @cite{x / 0} is left unsimplified or changed to an  The quotient @expr{x / 0} is left unsimplified or changed to an
22375  infinite quantity, as directed by the current infinite mode.  infinite quantity, as directed by the current infinite mode.
22376  @xref{Infinite Mode}.  @xref{Infinite Mode}.
22377    
22378  The expression @c{$a / b^{-c}$}  The expression
22379  @cite{a / b^(-c)} is changed to @cite{a b^c},  @texline @tmath{a / b^{-c}}
22380  where @cite{-c} is any negative-looking power.  Also, @cite{1 / b^c}  @infoline @expr{a / b^(-c)}
22381  is changed to @c{$b^{-c}$}  is changed to @expr{a b^c}, where @expr{-c} is any negative-looking
22382  @cite{b^(-c)} for any power @cite{c}.  power.  Also, @expr{1 / b^c} is changed to
22383    @texline @tmath{b^{-c}}
22384  Also, @cite{(-a) / b} and @cite{a / (-b)} go to @cite{-(a/b)};  @infoline @expr{b^(-c)}
22385  @cite{(a/b) / c} goes to @cite{a / (b c)}; and @cite{a / (b/c)}  for any power @expr{c}.
22386  goes to @cite{(a c) / b} unless matrix mode prevents this  
22387  rearrangement.  Similarly, @cite{a / (b:c)} is simplified to  Also, @expr{(-a) / b} and @expr{a / (-b)} go to @expr{-(a/b)};
22388  @cite{(c:b) a} for any fraction @cite{b:c}.  @expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)}
22389    goes to @expr{(a c) / b} unless matrix mode prevents this
22390    rearrangement.  Similarly, @expr{a / (b:c)} is simplified to
22391    @expr{(c:b) a} for any fraction @expr{b:c}.
22392    
22393  The distributive law is applied to @cite{(a + b) / c} only if  The distributive law is applied to @expr{(a + b) / c} only if
22394  @cite{c} and at least one of @cite{a} and @cite{b} are numbers.  @expr{c} and at least one of @expr{a} and @expr{b} are numbers.
22395  Quotients of powers and square roots are distributed just as  Quotients of powers and square roots are distributed just as
22396  described for multiplication.  described for multiplication.
22397    
22398  Quotients of products cancel only in the leading terms of the  Quotients of products cancel only in the leading terms of the
22399  numerator and denominator.  In other words, @cite{a x b / a y b}  numerator and denominator.  In other words, @expr{a x b / a y b}
22400  is cancelled to @cite{x b / y b} but not to @cite{x / y}.  Once  is cancelled to @expr{x b / y b} but not to @expr{x / y}.  Once
22401  again this is because full cancellation can be slow; use @kbd{a s}  again this is because full cancellation can be slow; use @kbd{a s}
22402  to cancel all terms of the quotient.  to cancel all terms of the quotient.
22403    
22404  Quotients of negative-looking values are simplified according  Quotients of negative-looking values are simplified according
22405  to @cite{(-a) / (-b)} to @cite{a / b}, @cite{(-a) / (b - c)}  to @expr{(-a) / (-b)} to @expr{a / b}, @expr{(-a) / (b - c)}
22406  to @cite{a / (c - b)}, and @cite{(a - b) / (-c)} to @cite{(b - a) / c}.  to @expr{a / (c - b)}, and @expr{(a - b) / (-c)} to @expr{(b - a) / c}.
22407    
22408  @tex  @tex
22409  \bigskip  \bigskip
22410  @end tex  @end tex
22411    
22412  The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)}  The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)}
22413  in matrix mode.  The formula @cite{0^x} is simplified to @cite{0}  in matrix mode.  The formula @expr{0^x} is simplified to @expr{0}
22414  unless @cite{x} is a negative number or complex number, in which  unless @expr{x} is a negative number or complex number, in which
22415  case the result is an infinity or an unsimplified formula according  case the result is an infinity or an unsimplified formula according
22416  to the current infinite mode.  Note that @cite{0^0} is an  to the current infinite mode.  Note that @expr{0^0} is an
22417  indeterminate form, as evidenced by the fact that the simplifications  indeterminate form, as evidenced by the fact that the simplifications
22418  for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}.  for @expr{x^0} and @expr{0^x} conflict when @expr{x=0}.
22419    
22420  Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c}  Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c}
22421  are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c}  are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c}
22422  is an integer, or if either @cite{a} or @cite{b} are nonnegative  is an integer, or if either @expr{a} or @expr{b} are nonnegative
22423  real numbers.  Powers of powers @cite{(a^b)^c} are simplified to  real numbers.  Powers of powers @expr{(a^b)^c} are simplified to
22424  @c{$a^{b c}$}  @texline @tmath{a^{b c}}
22425  @cite{a^(b c)} only when @cite{c} is an integer and @cite{b c} also  @infoline @expr{a^(b c)}
22426    only when @expr{c} is an integer and @expr{b c} also
22427  evaluates to an integer.  Without these restrictions these simplifications  evaluates to an integer.  Without these restrictions these simplifications
22428  would not be safe because of problems with principal values.  would not be safe because of problems with principal values.
22429  (In other words, @c{$((-3)^{1/2})^2$}  (In other words,
22430  @cite{((-3)^1:2)^2} is safe to simplify, but  @texline @tmath{((-3)^{1/2})^2}
22431  @c{$((-3)^2)^{1/2}$}  @infoline @expr{((-3)^1:2)^2}
22432  @cite{((-3)^2)^1:2} is not.)  @xref{Declarations}, for ways to inform  is safe to simplify, but
22433  Calc that your variables satisfy these requirements.  @texline @tmath{((-3)^2)^{1/2}}
22434    @infoline @expr{((-3)^2)^1:2}
22435  As a special case of this rule, @cite{@t{sqrt}(x)^n} is simplified to  is not.)  @xref{Declarations}, for ways to inform Calc that your
22436  @c{$x^{n/2}$}  variables satisfy these requirements.
22437  @cite{x^(n/2)} only for even integers @cite{n}.  
22438    As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to
22439  If @cite{a} is known to be real, @cite{b} is an even integer, and  @texline @tmath{x^{n/2}}
22440  @cite{c} is a half- or quarter-integer, then @cite{(a^b)^c} is  @infoline @expr{x^(n/2)}
22441  simplified to @c{$@t{abs}(a^{b c})$}  only for even integers @expr{n}.
22442  @cite{@t{abs}(a^(b c))}.  
22443    If @expr{a} is known to be real, @expr{b} is an even integer, and
22444  Also, @cite{(-a)^b} is simplified to @cite{a^b} if @cite{b} is an  @expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is
22445  even integer, or to @cite{-(a^b)} if @cite{b} is an odd integer,  simplified to @expr{@t{abs}(a^(b c))}.
22446  for any negative-looking expression @cite{-a}.  
22447    Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an
22448  Square roots @cite{@t{sqrt}(x)} generally act like one-half powers  even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer,
22449  @c{$x^{1:2}$}  for any negative-looking expression @expr{-a}.
22450  @cite{x^1:2} for the purposes of the above-listed simplifications.  
22451    Square roots @expr{@t{sqrt}(x)} generally act like one-half powers
22452  Also, note that @c{$1 / x^{1:2}$}  @texline @tmath{x^{1:2}}
22453  @cite{1 / x^1:2} is changed to @c{$x^{-1:2}$}  @infoline @expr{x^1:2}
22454  @cite{x^(-1:2)},  for the purposes of the above-listed simplifications.
22455  but @cite{1 / @t{sqrt}(x)} is left alone.  
22456    Also, note that
22457    @texline @tmath{1 / x^{1:2}}
22458    @infoline @expr{1 / x^1:2}
22459    is changed to
22460    @texline @tmath{x^{-1:2}},
22461    @infoline @expr{x^(-1:2)},
22462    but @expr{1 / @t{sqrt}(x)} is left alone.
22463    
22464  @tex  @tex
22465  \bigskip  \bigskip
22466  @end tex  @end tex
22467    
22468  Generic identity matrices (@pxref{Matrix Mode}) are simplified by the  Generic identity matrices (@pxref{Matrix Mode}) are simplified by the
22469  following rules:  @cite{@t{idn}(a) + b} to @cite{a + b} if @cite{b}  following rules:  @expr{@t{idn}(a) + b} to @expr{a + b} if @expr{b}
22470  is provably scalar, or expanded out if @cite{b} is a matrix;  is provably scalar, or expanded out if @expr{b} is a matrix;
22471  @cite{@t{idn}(a) + @t{idn}(b)} to @cite{@t{idn}(a + b)};  @expr{@t{idn}(a) + @t{idn}(b)} to @expr{@t{idn}(a + b)};
22472  @cite{-@t{idn}(a)} to @cite{@t{idn}(-a)}; @cite{a @t{idn}(b)} to  @expr{-@t{idn}(a)} to @expr{@t{idn}(-a)}; @expr{a @t{idn}(b)} to
22473  @cite{@t{idn}(a b)} if @cite{a} is provably scalar, or to @cite{a b}  @expr{@t{idn}(a b)} if @expr{a} is provably scalar, or to @expr{a b}
22474  if @cite{a} is provably non-scalar; @cite{@t{idn}(a) @t{idn}(b)}  if @expr{a} is provably non-scalar;  @expr{@t{idn}(a) @t{idn}(b)} to
22475  to @cite{@t{idn}(a b)}; analogous simplifications for quotients  @expr{@t{idn}(a b)}; analogous simplifications for quotients involving
22476  involving @code{idn}; and @cite{@t{idn}(a)^n} to @cite{@t{idn}(a^n)}  @code{idn}; and @expr{@t{idn}(a)^n} to @expr{@t{idn}(a^n)} where
22477  where @cite{n} is an integer.  @expr{n} is an integer.
22478    
22479  @tex  @tex
22480  \bigskip  \bigskip
# Line 22234  where @cite{n} is an integer. Line 22482  where @cite{n} is an integer.
22482    
22483  The @code{floor} function and other integer truncation functions  The @code{floor} function and other integer truncation functions
22484  vanish if the argument is provably integer-valued, so that  vanish if the argument is provably integer-valued, so that
22485  @cite{@t{floor}(@t{round}(x))} simplifies to @cite{@t{round}(x)}.  @expr{@t{floor}(@t{round}(x))} simplifies to @expr{@t{round}(x)}.
22486  Also, combinations of @code{float}, @code{floor} and its friends,  Also, combinations of @code{float}, @code{floor} and its friends,
22487  and @code{ffloor} and its friends, are simplified in appropriate  and @code{ffloor} and its friends, are simplified in appropriate
22488  ways.  @xref{Integer Truncation}.  ways.  @xref{Integer Truncation}.
22489    
22490  The expression @cite{@t{abs}(-x)} changes to @cite{@t{abs}(x)}.  The expression @expr{@t{abs}(-x)} changes to @expr{@t{abs}(x)}.
22491  The expression @cite{@t{abs}(@t{abs}(x))} changes to @cite{@t{abs}(x)};  The expression @expr{@t{abs}(@t{abs}(x))} changes to
22492  in fact, @cite{@t{abs}(x)} changes to @cite{x} or @cite{-x} if @cite{x}  @expr{@t{abs}(x)};  in fact, @expr{@t{abs}(x)} changes to @expr{x} or
22493  is provably nonnegative or nonpositive (@pxref{Declarations}).  @expr{-x} if @expr{x} is provably nonnegative or nonpositive
22494    (@pxref{Declarations}).
22495    
22496  While most functions do not recognize the variable @code{i} as an  While most functions do not recognize the variable @code{i} as an
22497  imaginary number, the @code{arg} function does handle the two cases  imaginary number, the @code{arg} function does handle the two cases
22498  @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.
22499    
22500  The expression @cite{@t{conj}(@t{conj}(x))} simplifies to @cite{x}.  The expression @expr{@t{conj}(@t{conj}(x))} simplifies to @expr{x}.
22501  Various other expressions involving @code{conj}, @code{re}, and  Various other expressions involving @code{conj}, @code{re}, and
22502  @code{im} are simplified, especially if some of the arguments are  @code{im} are simplified, especially if some of the arguments are
22503  provably real or involve the constant @code{i}.  For example,  provably real or involve the constant @code{i}.  For example,
22504  @cite{@t{conj}(a + b i)} is changed to @cite{@t{conj}(a) - @t{conj}(b) i},  @expr{@t{conj}(a + b i)} is changed to
22505  or to @cite{a - b i} if @cite{a} and @cite{b} are known to be real.  @expr{@t{conj}(a) - @t{conj}(b) i},  or to @expr{a - b i} if @expr{a}
22506    and @expr{b} are known to be real.
22507    
22508  Functions like @code{sin} and @code{arctan} generally don't have  Functions like @code{sin} and @code{arctan} generally don't have
22509  any default simplifications beyond simply evaluating the functions  any default simplifications beyond simply evaluating the functions
# Line 22261  for suitable numeric arguments and infin Line 22511  for suitable numeric arguments and infin
22511  described in the next section does provide some simplifications for  described in the next section does provide some simplifications for
22512  these functions, though.  these functions, though.
22513    
22514  One important simplification that does occur is that @cite{@t{ln}(@t{e})}  One important simplification that does occur is that
22515  is simplified to 1, and @cite{@t{ln}(@t{e}^x)} is simplified to @cite{x}  @expr{@t{ln}(@t{e})} is simplified to 1, and @expr{@t{ln}(@t{e}^x)} is
22516  for any @cite{x}.  This occurs even if you have stored a different  simplified to @expr{x} for any @expr{x}.  This occurs even if you have
22517  value in the Calc variable @samp{e}; but this would be a bad idea  stored a different value in the Calc variable @samp{e}; but this would
22518  in any case if you were also using natural logarithms!  be a bad idea in any case if you were also using natural logarithms!
22519    
22520  Among the logical functions, @t{(@var{a} <= @var{b})} changes to  Among the logical functions, @t{(@var{a} <= @var{b})} changes to
22521  @t{@var{a} > @var{b}} and so on.  Equations and inequalities where both sides  @t{@var{a} > @var{b}} and so on.  Equations and inequalities where both sides
22522  are either negative-looking or zero are simplified by negating both sides  are either negative-looking or zero are simplified by negating both sides
22523  and reversing the inequality.  While it might seem reasonable to simplify  and reversing the inequality.  While it might seem reasonable to simplify
22524  @cite{!!x} to @cite{x}, this would not be valid in general because  @expr{!!x} to @expr{x}, this would not be valid in general because
22525  @cite{!!2} is 1, not 2.  @expr{!!2} is 1, not 2.
22526    
22527  Most other Calc functions have few if any default simplifications  Most other Calc functions have few if any default simplifications
22528  defined, aside of course from evaluation when the arguments are  defined, aside of course from evaluation when the arguments are
# Line 22309  then the built-in simplifications, and s Line 22559  then the built-in simplifications, and s
22559  @end tex  @end tex
22560    
22561  Sums are simplified in two ways.  Constant terms are commuted to the  Sums are simplified in two ways.  Constant terms are commuted to the
22562  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}.
22563  The only exception is that a constant will not be commuted away  The only exception is that a constant will not be commuted away
22564  from the first position of a difference, i.e., @cite{2 - x} is not  from the first position of a difference, i.e., @expr{2 - x} is not
22565  commuted to @cite{-x + 2}.  commuted to @expr{-x + 2}.
22566    
22567  Also, terms of sums are combined by the distributive law, as in  Also, terms of sums are combined by the distributive law, as in
22568  @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
22569  adjacent terms, but @kbd{a s} compares all pairs of terms including  adjacent terms, but @kbd{a s} compares all pairs of terms including
22570  non-adjacent ones.  non-adjacent ones.
22571    
# Line 22324  non-adjacent ones. Line 22574  non-adjacent ones.
22574  @end tex  @end tex
22575    
22576  Products are sorted into a canonical order using the commutative  Products are sorted into a canonical order using the commutative
22577  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}.
22578  This allows easier comparison of products; for example, the default  This allows easier comparison of products; for example, the default
22579  simplifications will not change @cite{x y + y x} to @cite{2 x y},  simplifications will not change @expr{x y + y x} to @expr{2 x y},
22580  but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y},  but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y},
22581  and then the default simplifications are able to recognize a sum  and then the default simplifications are able to recognize a sum
22582  of identical terms.  of identical terms.
22583    
# Line 22346  use for adjacent terms of products. Line 22596  use for adjacent terms of products.
22596    
22597  Even though sums are not sorted, the commutative law is still  Even though sums are not sorted, the commutative law is still
22598  taken into account when terms of a product are being compared.  taken into account when terms of a product are being compared.
22599  Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}.  Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}.
22600  A subtle point is that @cite{(x - y) (y - x)} will @emph{not}  A subtle point is that @expr{(x - y) (y - x)} will @emph{not}
22601  be simplified to @cite{-(x - y)^2}; Calc does not notice that  be simplified to @expr{-(x - y)^2}; Calc does not notice that
22602  one term can be written as a constant times the other, even if  one term can be written as a constant times the other, even if
22603  that constant is @i{-1}.  that constant is @i{-1}.
22604    
22605  A fraction times any expression, @cite{(a:b) x}, is changed to  A fraction times any expression, @expr{(a:b) x}, is changed to
22606  a quotient involving integers:  @cite{a x / b}.  This is not  a quotient involving integers:  @expr{a x / b}.  This is not
22607  done for floating-point numbers like @cite{0.5}, however.  This  done for floating-point numbers like @expr{0.5}, however.  This
22608  is one reason why you may find it convenient to turn Fraction mode  is one reason why you may find it convenient to turn Fraction mode
22609  on while doing algebra; @pxref{Fraction Mode}.  on while doing algebra; @pxref{Fraction Mode}.
22610    
# Line 22364  on while doing algebra; @pxref{Fraction Line 22614  on while doing algebra; @pxref{Fraction
22614    
22615  Quotients are simplified by comparing all terms in the numerator  Quotients are simplified by comparing all terms in the numerator
22616  with all terms in the denominator for possible cancellation using  with all terms in the denominator for possible cancellation using
22617  the distributive law.  For example, @cite{a x^2 b / c x^3 d} will  the distributive law.  For example, @expr{a x^2 b / c x^3 d} will
22618  cancel @cite{x^2} from both sides to get @cite{a b / c x d}.  cancel @expr{x^2} from both sides to get @expr{a b / c x d}.
22619  (The terms in the denominator will then be rearranged to @cite{c d x}  (The terms in the denominator will then be rearranged to @expr{c d x}
22620  as described above.)  If there is any common integer or fractional  as described above.)  If there is any common integer or fractional
22621  factor in the numerator and denominator, it is cancelled out;  factor in the numerator and denominator, it is cancelled out;
22622  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}.
22623    
22624  Non-constant common factors are not found even by @kbd{a s}.  To  Non-constant common factors are not found even by @kbd{a s}.  To
22625  cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first  cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first
22626  use @kbd{j M} on the product @cite{a x} to Merge the numerator to  use @kbd{j M} on the product @expr{a x} to Merge the numerator to
22627  @cite{a (1+x)}, which can then be simplified successfully.  @expr{a (1+x)}, which can then be simplified successfully.
22628    
22629  @tex  @tex
22630  \bigskip  \bigskip
22631  @end tex  @end tex
22632    
22633  Integer powers of the variable @code{i} are simplified according  Integer powers of the variable @code{i} are simplified according
22634  to the identity @cite{i^2 = -1}.  If you store a new value other  to the identity @expr{i^2 = -1}.  If you store a new value other
22635  than the complex number @cite{(0,1)} in @code{i}, this simplification  than the complex number @expr{(0,1)} in @code{i}, this simplification
22636  will no longer occur.  This is done by @kbd{a s} instead of by default  will no longer occur.  This is done by @kbd{a s} instead of by default
22637  in case someone (unwisely) uses the name @code{i} for a variable  in case someone (unwisely) uses the name @code{i} for a variable
22638  unrelated to complex numbers; it would be unfortunate if Calc  unrelated to complex numbers; it would be unfortunate if Calc
# Line 22392  user might not have been thinking of. Line 22642  user might not have been thinking of.
22642  Square roots of integer or rational arguments are simplified in  Square roots of integer or rational arguments are simplified in
22643  several ways.  (Note that these will be left unevaluated only in  several ways.  (Note that these will be left unevaluated only in
22644  Symbolic mode.)  First, square integer or rational factors are  Symbolic mode.)  First, square integer or rational factors are
22645  pulled out so that @cite{@t{sqrt}(8)} is rewritten as  pulled out so that @expr{@t{sqrt}(8)} is rewritten as
22646  @c{$2\,\t{sqrt}(2)$}  @texline @tmath{$2\,\t{sqrt}(2)$}.
22647  @cite{2 sqrt(2)}.  Conceptually speaking this implies factoring  @infoline @expr{2 sqrt(2)}.  
22648  the argument into primes and moving pairs of primes out of the  Conceptually speaking this implies factoring the argument into primes
22649  square root, but for reasons of efficiency Calc only looks for  and moving pairs of primes out of the square root, but for reasons of
22650  primes up to 29.  efficiency Calc only looks for primes up to 29.
22651    
22652  Square roots in the denominator of a quotient are moved to the  Square roots in the denominator of a quotient are moved to the
22653  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}.
22654  The same effect occurs for the square root of a fraction:  The same effect occurs for the square root of a fraction:
22655  @cite{@t{sqrt}(2:3)} changes to @cite{@t{sqrt}(6) / 3}.  @expr{@t{sqrt}(2:3)} changes to @expr{@t{sqrt}(6) / 3}.
22656    
22657  @tex  @tex
22658  \bigskip  \bigskip
22659  @end tex  @end tex
22660    
22661  The @code{%} (modulo) operator is simplified in several ways  The @code{%} (modulo) operator is simplified in several ways
22662  when the modulus @cite{M} is a positive real number.  First, if  when the modulus @expr{M} is a positive real number.  First, if
22663  the argument is of the form @cite{x + n} for some real number  the argument is of the form @expr{x + n} for some real number
22664  @cite{n}, then @cite{n} is itself reduced modulo @cite{M}.  For  @expr{n}, then @expr{n} is itself reduced modulo @expr{M}.  For
22665  example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}.  example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}.
22666    
22667  If the argument is multiplied by a constant, and this constant  If the argument is multiplied by a constant, and this constant
# Line 22435  declared to be an integer. Line 22685  declared to be an integer.
22685  @end tex  @end tex
22686    
22687  Trigonometric functions are simplified in several ways.  First,  Trigonometric functions are simplified in several ways.  First,
22688  @cite{@t{sin}(@t{arcsin}(x))} is simplified to @cite{x}, and  @expr{@t{sin}(@t{arcsin}(x))} is simplified to @expr{x}, and
22689  similarly for @code{cos} and @code{tan}.  If the argument to  similarly for @code{cos} and @code{tan}.  If the argument to
22690  @code{sin} is negative-looking, it is simplified to @cite{-@t{sin}(x)},  @code{sin} is negative-looking, it is simplified to
22691  and similarly for @code{cos} and @code{tan}.  Finally, certain  @expr{-@t{sin}(x),},  and similarly for @code{cos} and @code{tan}.
22692  special values of the argument are recognized;  Finally, certain special values of the argument are recognized;
22693  @pxref{Trigonometric and Hyperbolic Functions}.  @pxref{Trigonometric and Hyperbolic Functions}.
22694    
22695  Trigonometric functions of inverses of different trigonometric  Trigonometric functions of inverses of different trigonometric
22696  functions can also be simplified, as in @cite{@t{sin}(@t{arccos}(x))}  functions can also be simplified, as in @expr{@t{sin}(@t{arccos}(x))}
22697  to @cite{@t{sqrt}(1 - x^2)}.  to @expr{@t{sqrt}(1 - x^2)}.
22698    
22699  Hyperbolic functions of their inverses and of negative-looking  Hyperbolic functions of their inverses and of negative-looking
22700  arguments are also handled, as are exponentials of inverse  arguments are also handled, as are exponentials of inverse
# Line 22453  hyperbolic functions. Line 22703  hyperbolic functions.
22703  No simplifications for inverse trigonometric and hyperbolic  No simplifications for inverse trigonometric and hyperbolic
22704  functions are known, except for negative arguments of @code{arcsin},  functions are known, except for negative arguments of @code{arcsin},
22705  @code{arctan}, @code{arcsinh}, and @code{arctanh}.  Note that  @code{arctan}, @code{arcsinh}, and @code{arctanh}.  Note that
22706  @cite{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to  @expr{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to
22707  @cite{x}, since this only correct within an integer multiple  @expr{x}, since this only correct within an integer multiple of
22708  of @c{$2 \pi$}  @texline @tmath{2 \pi}
22709  @cite{2 pi} radians or 360 degrees.  However,  @infoline @expr{2 pi}
22710  @cite{@t{arcsinh}(@t{sinh}(x))} is simplified to @cite{x} if  radians or 360 degrees.  However, @expr{@t{arcsinh}(@t{sinh}(x))} is
22711  @cite{x} is known to be real.  simplified to @expr{x} if @expr{x} is known to be real.
22712    
22713  Several simplifications that apply to logarithms and exponentials  Several simplifications that apply to logarithms and exponentials
22714  are that @cite{@t{exp}(@t{ln}(x))}, @c{$@t{e}^{\ln(x)}$}  are that @expr{@t{exp}(@t{ln}(x))},
22715  @cite{e^@t{ln}(x)}, and  @texline @t{e}@tmath{^{\ln(x)}},
22716  @c{$10^{{\rm log10}(x)}$}  @infoline @expr{e^@t{ln}(x)},
22717  @cite{10^@t{log10}(x)} all reduce to @cite{x}.  and
22718  Also, @cite{@t{ln}(@t{exp}(x))}, etc., can reduce to @cite{x} if  @texline @tmath{10^{{\rm log10}(x)}}
22719  @cite{x} is provably real.  The form @cite{@t{exp}(x)^y} is simplified  @infoline @expr{10^@t{log10}(x)}
22720  to @cite{@t{exp}(x y)}.  If @cite{x} is a suitable multiple of @c{$\pi i$}  all reduce to @expr{x}.  Also, @expr{@t{ln}(@t{exp}(x))}, etc., can
22721  @cite{pi i}  reduce to @expr{x} if @expr{x} is provably real.  The form
22722  (as described above for the trigonometric functions), then @cite{@t{exp}(x)}  @expr{@t{exp}(x)^y} is simplified to @expr{@t{exp}(x y)}.  If @expr{x}
22723  or @cite{e^x} will be expanded.  Finally, @cite{@t{ln}(x)} is simplified  is a suitable multiple of
22724  to a form involving @code{pi} and @code{i} where @cite{x} is provably  @texline @tmath{\pi i}
22725  negative, positive imaginary, or negative imaginary.  @infoline @expr{pi i}
22726    (as described above for the trigonometric functions), then
22727    @expr{@t{exp}(x)} or @expr{e^x} will be expanded.  Finally,
22728    @expr{@t{ln}(x)} is simplified to a form involving @code{pi} and
22729    @code{i} where @expr{x} is provably negative, positive imaginary, or
22730    negative imaginary.
22731    
22732  The error functions @code{erf} and @code{erfc} are simplified when  The error functions @code{erf} and @code{erfc} are simplified when
22733  their arguments are negative-looking or are calls to the @code{conj}  their arguments are negative-looking or are calls to the @code{conj}
# Line 22485  function. Line 22740  function.
22740  Equations and inequalities are simplified by cancelling factors  Equations and inequalities are simplified by cancelling factors
22741  of products, quotients, or sums on both sides.  Inequalities  of products, quotients, or sums on both sides.  Inequalities
22742  change sign if a negative multiplicative factor is cancelled.  change sign if a negative multiplicative factor is cancelled.
22743  Non-constant multiplicative factors as in @cite{a b = a c} are  Non-constant multiplicative factors as in @expr{a b = a c} are
22744  cancelled from equations only if they are provably nonzero (generally  cancelled from equations only if they are provably nonzero (generally
22745  because they were declared so; @pxref{Declarations}).  Factors  because they were declared so; @pxref{Declarations}).  Factors
22746  are cancelled from inequalities only if they are nonzero and their  are cancelled from inequalities only if they are nonzero and their
# Line 22493  sign is known. Line 22748  sign is known.
22748    
22749  Simplification also replaces an equation or inequality with  Simplification also replaces an equation or inequality with
22750  1 or 0 (``true'' or ``false'') if it can through the use of  1 or 0 (``true'' or ``false'') if it can through the use of
22751  declarations.  If @cite{x} is declared to be an integer greater  declarations.  If @expr{x} is declared to be an integer greater
22752  than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are  than 5, then @expr{x < 3}, @expr{x = 3}, and @expr{x = 7.5} are
22753  all simplified to 0, but @cite{x > 3} is simplified to 1.  all simplified to 0, but @expr{x > 3} is simplified to 1.
22754  By a similar analysis, @cite{abs(x) >= 0} is simplified to 1,  By a similar analysis, @expr{abs(x) >= 0} is simplified to 1,
22755  as is @cite{x^2 >= 0} if @cite{x} is known to be real.  as is @expr{x^2 >= 0} if @expr{x} is known to be real.
22756    
22757  @node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas  @node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas
22758  @subsection ``Unsafe'' Simplifications  @subsection ``Unsafe'' Simplifications
# Line 22519  formula lie in the restricted ranges for Line 22774  formula lie in the restricted ranges for
22774  are valid.  The symbolic integrator uses @kbd{a e};  are valid.  The symbolic integrator uses @kbd{a e};
22775  one effect of this is that the integrator's results must be used with  one effect of this is that the integrator's results must be used with
22776  caution.  Where an integral table will often attach conditions like  caution.  Where an integral table will often attach conditions like
22777  ``for positive @cite{a} only,'' Calc (like most other symbolic  ``for positive @expr{a} only,'' Calc (like most other symbolic
22778  integration programs) will simply produce an unqualified result.@refill  integration programs) will simply produce an unqualified result.
22779    
22780  Because @kbd{a e}'s simplifications are unsafe, it is sometimes better  Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
22781  to type @kbd{C-u -3 a v}, which does extended simplification only  to type @kbd{C-u -3 a v}, which does extended simplification only
# Line 22542  by @kbd{a e}. Line 22797  by @kbd{a e}.
22797    
22798  Inverse trigonometric or hyperbolic functions, called with their  Inverse trigonometric or hyperbolic functions, called with their
22799  corresponding non-inverse functions as arguments, are simplified  corresponding non-inverse functions as arguments, are simplified
22800  by @kbd{a e}.  For example, @cite{@t{arcsin}(@t{sin}(x))} changes  by @kbd{a e}.  For example, @expr{@t{arcsin}(@t{sin}(x))} changes
22801  to @cite{x}.  Also, @cite{@t{arcsin}(@t{cos}(x))} and  to @expr{x}.  Also, @expr{@t{arcsin}(@t{cos}(x))} and
22802  @cite{@t{arccos}(@t{sin}(x))} both change to @cite{@t{pi}/2 - x}.  @expr{@t{arccos}(@t{sin}(x))} both change to @expr{@t{pi}/2 - x}.
22803  These simplifications are unsafe because they are valid only for  These simplifications are unsafe because they are valid only for
22804  values of @cite{x} in a certain range; outside that range, values  values of @expr{x} in a certain range; outside that range, values
22805  are folded down to the 360-degree range that the inverse trigonometric  are folded down to the 360-degree range that the inverse trigonometric
22806  functions always produce.  functions always produce.
22807    
22808  Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$}  Powers of powers @expr{(x^a)^b} are simplified to
22809  @cite{x^(a b)}  @texline @tmath{x^{a b}}
22810  for all @cite{a} and @cite{b}.  These results will be valid only  @infoline @expr{x^(a b)}
22811  in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$}  for all @expr{a} and @expr{b}.  These results will be valid only
22812  @cite{(x^2)^1:2}  in a restricted range of @expr{x}; for example, in
22813  the powers cancel to get @cite{x}, which is valid for positive values  @texline @tmath{(x^2)^{1:2}}
22814  of @cite{x} but not for negative or complex values.  @infoline @expr{(x^2)^1:2}
22815    the powers cancel to get @expr{x}, which is valid for positive values
22816  Similarly, @cite{@t{sqrt}(x^a)} and @cite{@t{sqrt}(x)^a} are both  of @expr{x} but not for negative or complex values.
22817  simplified (possibly unsafely) to @c{$x^{a/2}$}  
22818  @cite{x^(a/2)}.  Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both
22819    simplified (possibly unsafely) to
22820    @texline @tmath{x^{a/2}}.
22821    @infoline @expr{x^(a/2)}.
22822    
22823  Forms like @cite{@t{sqrt}(1 - @t{sin}(x)^2)} are simplified to, e.g.,  Forms like @expr{@t{sqrt}(1 - sin(x)^2)} are simplified to, e.g.,
22824  @cite{@t{cos}(x)}.  Calc has identities of this sort for @code{sin},  @expr{@t{cos}(x)}.  Calc has identities of this sort for @code{sin},
22825  @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.  @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.
22826    
22827  Arguments of square roots are partially factored to look for  Arguments of square roots are partially factored to look for
22828  squared terms that can be extracted.  For example,  squared terms that can be extracted.  For example,
22829  @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
22830    @expr{a b @t{sqrt}(a+b)}.
22831    
22832  The simplifications of @cite{@t{ln}(@t{exp}(x))}, @cite{@t{ln}(@t{e}^x)},  The simplifications of @expr{@t{ln}(@t{exp}(x))},
22833  and @cite{@t{log10}(10^x)} to @cite{x} are also unsafe because  @expr{@t{ln}(@t{e}^x)}, and @expr{@t{log10}(10^x)} to @expr{x} are also
22834  of problems with principal values (although these simplifications  unsafe because of problems with principal values (although these
22835  are safe if @cite{x} is known to be real).  simplifications are safe if @expr{x} is known to be real).
22836    
22837  Common factors are cancelled from products on both sides of an  Common factors are cancelled from products on both sides of an
22838  equation, even if those factors may be zero:  @cite{a x / b x}  equation, even if those factors may be zero:  @expr{a x / b x}
22839  to @cite{a / b}.  Such factors are never cancelled from  to @expr{a / b}.  Such factors are never cancelled from
22840  inequalities:  Even @kbd{a e} is not bold enough to reduce  inequalities:  Even @kbd{a e} is not bold enough to reduce
22841  @cite{a x < b x} to @cite{a < b} (or @cite{a > b}, depending  @expr{a x < b x} to @expr{a < b} (or @expr{a > b}, depending
22842  on whether you believe @cite{x} is positive or negative).  on whether you believe @expr{x} is positive or negative).
22843  The @kbd{a M /} command can be used to divide a factor out of  The @kbd{a M /} command can be used to divide a factor out of
22844  both sides of an inequality.  both sides of an inequality.
22845    
# Line 22600  and @code{AlgSimpRules}. Line 22859  and @code{AlgSimpRules}.
22859  Scalar mode is automatically put into effect when simplifying units.  Scalar mode is automatically put into effect when simplifying units.
22860  @xref{Matrix Mode}.  @xref{Matrix Mode}.
22861    
22862  Sums @cite{a + b} involving units are simplified by extracting the  Sums @expr{a + b} involving units are simplified by extracting the
22863  units of @cite{a} as if by the @kbd{u x} command (call the result  units of @expr{a} as if by the @kbd{u x} command (call the result
22864  @cite{u_a}), then simplifying the expression @cite{b / u_a}  @expr{u_a}), then simplifying the expression @expr{b / u_a}
22865  using @kbd{u b} and @kbd{u s}.  If the result has units then the sum  using @kbd{u b} and @kbd{u s}.  If the result has units then the sum
22866  is inconsistent and is left alone.  Otherwise, it is rewritten  is inconsistent and is left alone.  Otherwise, it is rewritten
22867  in terms of the units @cite{u_a}.  in terms of the units @expr{u_a}.
22868    
22869  If units auto-ranging mode is enabled, products or quotients in  If units auto-ranging mode is enabled, products or quotients in
22870  which the first argument is a number which is out of range for the  which the first argument is a number which is out of range for the
# Line 22617  For example, @samp{2 km m} is simplified Line 22876  For example, @samp{2 km m} is simplified
22876  However, compatible but different units like @code{ft} and @code{in}  However, compatible but different units like @code{ft} and @code{in}
22877  are not combined in this way.  are not combined in this way.
22878    
22879  Quotients @cite{a / b} are simplified in three additional ways.  First,  Quotients @expr{a / b} are simplified in three additional ways.  First,
22880  if @cite{b} is a number or a product beginning with a number, Calc  if @expr{b} is a number or a product beginning with a number, Calc
22881  computes the reciprocal of this number and moves it to the numerator.  computes the reciprocal of this number and moves it to the numerator.
22882    
22883  Second, for each pair of unit names from the numerator and denominator  Second, for each pair of unit names from the numerator and denominator
22884  of a quotient, if the units are compatible (e.g., they are both  of a quotient, if the units are compatible (e.g., they are both
22885  units of area) then they are replaced by the ratio between those  units of area) then they are replaced by the ratio between those
22886  units.  For example, in @samp{3 s in N / kg cm} the units  units.  For example, in @samp{3 s in N / kg cm} the units
22887  @samp{in / cm} will be replaced by @cite{2.54}.  @samp{in / cm} will be replaced by @expr{2.54}.
22888    
22889  Third, if the units in the quotient exactly cancel out, so that  Third, if the units in the quotient exactly cancel out, so that
22890  a @kbd{u b} command on the quotient would produce a dimensionless  a @kbd{u b} command on the quotient would produce a dimensionless
22891  number for an answer, then the quotient simplifies to that number.  number for an answer, then the quotient simplifies to that number.
22892    
22893  For powers and square roots, the ``unsafe'' simplifications  For powers and square roots, the ``unsafe'' simplifications
22894  @cite{(a b)^c} to @cite{a^c b^c}, @cite{(a/b)^c} to @cite{a^c / b^c},  @expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c},
22895  and @cite{(a^b)^c} to @c{$a^{b c}$}  and @expr{(a^b)^c} to
22896  @cite{a^(b c)} are done if the powers are  @texline @tmath{a^{b c}}
22897  real numbers.  (These are safe in the context of units because  @infoline @expr{a^(b c)}
22898  all numbers involved can reasonably be assumed to be real.)  are done if the powers are real numbers.  (These are safe in the context
22899    of units because all numbers involved can reasonably be assumed to be
22900    real.)
22901    
22902  Also, if a unit name is raised to a fractional power, and the  Also, if a unit name is raised to a fractional power, and the
22903  base units in that unit name all occur to powers which are a  base units in that unit name all occur to powers which are a
22904  multiple of the denominator of the power, then the unit name  multiple of the denominator of the power, then the unit name
22905  is expanded out into its base units, which can then be simplified  is expanded out into its base units, which can then be simplified
22906  according to the previous paragraph.  For example, @samp{acre^1.5}  according to the previous paragraph.  For example, @samp{acre^1.5}
22907  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}
22908  is defined in terms of @samp{m^2}, and that the 2 in the power of  is defined in terms of @samp{m^2}, and that the 2 in the power of
22909  @code{m} is a multiple of 2 in @cite{3:2}.  Thus, @code{acre^1.5} is  @code{m} is a multiple of 2 in @expr{3:2}.  Thus, @code{acre^1.5} is
22910  replaced by approximately @c{$(4046 m^2)^{1.5}$}  replaced by approximately
22911  @cite{(4046 m^2)^1.5}, which is then  @texline @tmath{(4046 m^2)^{1.5}}
22912  changed to @c{$4046^{1.5} \, (m^2)^{1.5}$}  @infoline @expr{(4046 m^2)^1.5},
22913  @cite{4046^1.5 (m^2)^1.5}, then to @cite{257440 m^3}.  which is then changed to
22914    @texline @tmath{4046^{1.5} \, (m^2)^{1.5}},
22915    @infoline @expr{4046^1.5 (m^2)^1.5},
22916    then to @expr{257440 m^3}.
22917    
22918  The functions @code{float}, @code{frac}, @code{clean}, @code{abs},  The functions @code{float}, @code{frac}, @code{clean}, @code{abs},
22919  as well as @code{floor} and the other integer truncation functions,  as well as @code{floor} and the other integer truncation functions,
# Line 22667  with the angular mode temporarily set to Line 22931  with the angular mode temporarily set to
22931  @section Polynomials  @section Polynomials
22932    
22933  A @dfn{polynomial} is a sum of terms which are coefficients times  A @dfn{polynomial} is a sum of terms which are coefficients times
22934  various powers of a ``base'' variable.  For example, @cite{2 x^2 + 3 x - 4}  various powers of a ``base'' variable.  For example, @expr{2 x^2 + 3 x - 4}
22935  is a polynomial in @cite{x}.  Some formulas can be considered  is a polynomial in @expr{x}.  Some formulas can be considered
22936  polynomials in several different variables:  @cite{1 + 2 x + 3 y + 4 x y^2}  polynomials in several different variables:  @expr{1 + 2 x + 3 y + 4 x y^2}
22937  is a polynomial in both @cite{x} and @cite{y}.  Polynomial coefficients  is a polynomial in both @expr{x} and @expr{y}.  Polynomial coefficients
22938  are often numbers, but they may in general be any formulas not  are often numbers, but they may in general be any formulas not
22939  involving the base variable.  involving the base variable.
22940    
# Line 22679  involving the base variable. Line 22943  involving the base variable.
22943  @tindex factor  @tindex factor
22944  The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a  The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a
22945  polynomial into a product of terms.  For example, the polynomial  polynomial into a product of terms.  For example, the polynomial
22946  @cite{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}.  As another  @expr{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}.  As another
22947  example, @cite{a c + b d + b c + a d} is factored into the product  example, @expr{a c + b d + b c + a d} is factored into the product
22948  @cite{(a + b) (c + d)}.  @expr{(a + b) (c + d)}.
22949    
22950  Calc currently has three algorithms for factoring.  Formulas which are  Calc currently has three algorithms for factoring.  Formulas which are
22951  linear in several variables, such as the second example above, are  linear in several variables, such as the second example above, are
# Line 22689  merged according to the distributive law Line 22953  merged according to the distributive law
22953  polynomials in a single variable, with constant integer or fractional  polynomials in a single variable, with constant integer or fractional
22954  coefficients, are factored into irreducible linear and/or quadratic  coefficients, are factored into irreducible linear and/or quadratic
22955  terms.  The first example above factors into three linear terms  terms.  The first example above factors into three linear terms
22956  (@cite{x}, @cite{x+1}, and @cite{x+1} again).  Finally, formulas  (@expr{x}, @expr{x+1}, and @expr{x+1} again).  Finally, formulas
22957  which do not fit the above criteria are handled by the algebraic  which do not fit the above criteria are handled by the algebraic
22958  rewrite mechanism.  rewrite mechanism.
22959    
# Line 22721  The rewrite-based factorization method u Line 22985  The rewrite-based factorization method u
22985  @code{FactorRules}.  @xref{Rewrite Rules}, for a discussion of the  @code{FactorRules}.  @xref{Rewrite Rules}, for a discussion of the
22986  operation of rewrite rules.  The default @code{FactorRules} are able  operation of rewrite rules.  The default @code{FactorRules} are able
22987  to factor quadratic forms symbolically into two linear terms,  to factor quadratic forms symbolically into two linear terms,
22988  @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
22989  cases if you wish.  To use the rules, Calc builds the formula  cases if you wish.  To use the rules, Calc builds the formula
22990  @samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial  @samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
22991  base variable and @code{a}, @code{b}, etc., are polynomial coefficients  base variable and @code{a}, @code{b}, etc., are polynomial coefficients
# Line 22742  The @kbd{H a f} [@code{factors}] command Line 23006  The @kbd{H a f} [@code{factors}] command
23006  but it returns a list of factors instead of an expression which is the  but it returns a list of factors instead of an expression which is the
23007  product of the factors.  Each factor is represented by a sub-vector  product of the factors.  Each factor is represented by a sub-vector
23008  of the factor, and the power with which it appears.  For example,  of the factor, and the power with which it appears.  For example,
23009  @cite{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @cite{(x + 7) x^2 (x - 3)^2}  @expr{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @expr{(x + 7) x^2 (x - 3)^2}
23010  in @kbd{a f}, or to @cite{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}.  in @kbd{a f}, or to @expr{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}.
23011  If there is an overall numeric factor, it always comes first in the list.  If there is an overall numeric factor, it always comes first in the list.
23012  The functions @code{factor} and @code{factors} allow a second argument  The functions @code{factor} and @code{factors} allow a second argument
23013  when written in algebraic form; @samp{factor(x,v)} factors @cite{x} with  when written in algebraic form; @samp{factor(x,v)} factors @expr{x} with
23014  respect to the specific variable @cite{v}.  The default is to factor with  respect to the specific variable @expr{v}.  The default is to factor with
23015  respect to all the variables that appear in @cite{x}.  respect to all the variables that appear in @expr{x}.
23016    
23017  @kindex a c  @kindex a c
23018  @pindex calc-collect  @pindex calc-collect
# Line 22756  respect to all the variables that appear Line 23020  respect to all the variables that appear
23020  The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a  The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a
23021  formula as a  formula as a
23022  polynomial in a given variable, ordered in decreasing powers of that  polynomial in a given variable, ordered in decreasing powers of that
23023  variable.  For example, given @cite{1 + 2 x + 3 y + 4 x y^2} on  variable.  For example, given @expr{1 + 2 x + 3 y + 4 x y^2} on
23024  the stack, @kbd{a c x} would produce @cite{(2 + 4 y^2) x + (1 + 3 y)},  the stack, @kbd{a c x} would produce @expr{(2 + 4 y^2) x + (1 + 3 y)},
23025  and @kbd{a c y} would produce @cite{(4 x) y^2 + 3 y + (1 + 2 x)}.  and @kbd{a c y} would produce @expr{(4 x) y^2 + 3 y + (1 + 2 x)}.
23026  The polynomial will be expanded out using the distributive law as  The polynomial will be expanded out using the distributive law as
23027  necessary:  Collecting @cite{x} in @cite{(x - 1)^3} produces  necessary:  Collecting @expr{x} in @expr{(x - 1)^3} produces
23028  @cite{x^3 - 3 x^2 + 3 x - 1}.  Terms not involving @cite{x} will  @expr{x^3 - 3 x^2 + 3 x - 1}.  Terms not involving @expr{x} will
23029  not be expanded.  not be expanded.
23030    
23031  The ``variable'' you specify at the prompt can actually be any  The ``variable'' you specify at the prompt can actually be any
# Line 22790  also know many other kinds of expansions Line 23054  also know many other kinds of expansions
23054  do not do.)  do not do.)
23055    
23056  Calc's automatic simplifications will sometimes reverse a partial  Calc's automatic simplifications will sometimes reverse a partial
23057  expansion.  For example, the first step in expanding @cite{(x+1)^3} is  expansion.  For example, the first step in expanding @expr{(x+1)^3} is
23058  to write @cite{(x+1) (x+1)^2}.  If @kbd{a x} stops there and tries  to write @expr{(x+1) (x+1)^2}.  If @kbd{a x} stops there and tries
23059  to put this formula onto the stack, though, Calc will automatically  to put this formula onto the stack, though, Calc will automatically
23060  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
23061  simplification off first (@pxref{Simplification Modes}), or to run  simplification off first (@pxref{Simplification Modes}), or to run
23062  @kbd{a x} without a numeric prefix argument so that it expands all  @kbd{a x} without a numeric prefix argument so that it expands all
23063  the way in one step.  the way in one step.
# Line 22814  chooses the base variable automatically. Line 23078  chooses the base variable automatically.
23078  @tindex nrat  @tindex nrat
23079  The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command  The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command
23080  attempts to arrange a formula into a quotient of two polynomials.  attempts to arrange a formula into a quotient of two polynomials.
23081  For example, given @cite{1 + (a + b/c) / d}, the result would be  For example, given @expr{1 + (a + b/c) / d}, the result would be
23082  @cite{(b + a c + c d) / c d}.  The quotient is reduced, so that  @expr{(b + a c + c d) / c d}.  The quotient is reduced, so that
23083  @kbd{a n} will simplify @cite{(x^2 + 2x + 1) / (x^2 - 1)} by dividing  @kbd{a n} will simplify @expr{(x^2 + 2x + 1) / (x^2 - 1)} by dividing
23084  out the common factor @cite{x + 1}, yielding @cite{(x + 1) / (x - 1)}.  out the common factor @expr{x + 1}, yielding @expr{(x + 1) / (x - 1)}.
23085    
23086  @kindex a \  @kindex a \
23087  @pindex calc-poly-div  @pindex calc-poly-div
23088  @tindex pdiv  @tindex pdiv
23089  The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides  The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides
23090  two polynomials @cite{u} and @cite{v}, yielding a new polynomial  two polynomials @expr{u} and @expr{v}, yielding a new polynomial
23091  @cite{q}.  If several variables occur in the inputs, the inputs are  @expr{q}.  If several variables occur in the inputs, the inputs are
23092  considered multivariate polynomials.  (Calc divides by the variable  considered multivariate polynomials.  (Calc divides by the variable
23093  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
23094  powers, chooses the variables in alphabetical order.)  For example,  powers, chooses the variables in alphabetical order.)  For example,
23095  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}.
23096  The remainder from the division, if any, is reported at the bottom  The remainder from the division, if any, is reported at the bottom
23097  of the screen and is also placed in the Trail along with the quotient.  of the screen and is also placed in the Trail along with the quotient.
23098    
# Line 22842  above. Line 23106  above.
23106  @pindex calc-poly-rem  @pindex calc-poly-rem
23107  @tindex prem  @tindex prem
23108  The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides  The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides
23109  two polynomials and keeps the remainder @cite{r}.  The quotient  two polynomials and keeps the remainder @expr{r}.  The quotient
23110  @cite{q} is discarded.  For any formulas @cite{a} and @cite{b}, the  @expr{q} is discarded.  For any formulas @expr{a} and @expr{b}, the
23111  results of @kbd{a \} and @kbd{a %} satisfy @cite{a = q b + r}.  results of @kbd{a \} and @kbd{a %} satisfy @expr{a = q b + r}.
23112  (This is analogous to plain @kbd{\} and @kbd{%}, which compute the  (This is analogous to plain @kbd{\} and @kbd{%}, which compute the
23113  integer quotient and remainder from dividing two numbers.)  integer quotient and remainder from dividing two numbers.)
23114    
# Line 22855  integer quotient and remainder from divi Line 23119  integer quotient and remainder from divi
23119  @tindex pdivide  @tindex pdivide
23120  The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command  The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command
23121  divides two polynomials and reports both the quotient and the  divides two polynomials and reports both the quotient and the
23122  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}]
23123  command divides two polynomials and constructs the formula  command divides two polynomials and constructs the formula
23124  @cite{q + r/b} on the stack.  (Naturally if the remainder is zero,  @expr{q + r/b} on the stack.  (Naturally if the remainder is zero,
23125  this will immediately simplify to @cite{q}.)  this will immediately simplify to @expr{q}.)
23126    
23127  @kindex a g  @kindex a g
23128  @pindex calc-poly-gcd  @pindex calc-poly-gcd
# Line 22936  answer! Line 23200  answer!
23200    
23201  If you use the @code{deriv} function directly in an algebraic formula,  If you use the @code{deriv} function directly in an algebraic formula,
23202  you can write @samp{deriv(f,x,x0)} which represents the derivative  you can write @samp{deriv(f,x,x0)} which represents the derivative
23203  of @cite{f} with respect to @cite{x}, evaluated at the point @c{$x=x_0$}  of @expr{f} with respect to @expr{x}, evaluated at the point
23204  @cite{x=x0}.  @texline @tmath{x=x_0}.
23205    @infoline @expr{x=x0}.
23206    
23207  If the formula being differentiated contains functions which Calc does  If the formula being differentiated contains functions which Calc does
23208  not know, the derivatives of those functions are produced by adding  not know, the derivatives of those functions are produced by adding
# Line 22960  respect to the other arguments are @samp Line 23225  respect to the other arguments are @samp
23225  Various higher-order derivatives can be formed in the obvious way, e.g.,  Various higher-order derivatives can be formed in the obvious way, e.g.,
23226  @samp{f'@var{}'(x)} (the second derivative of @code{f}) or  @samp{f'@var{}'(x)} (the second derivative of @code{f}) or
23227  @samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each  @samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each
23228  argument once).@refill  argument once).
23229    
23230  @node Integration, Customizing the Integrator, Differentiation, Calculus  @node Integration, Customizing the Integrator, Differentiation, Calculus
23231  @subsection Integration  @subsection Integration
# Line 22975  respect to a variable.  The integrator i Line 23240  respect to a variable.  The integrator i
23240  all integrable functions, but it is able to integrate several large  all integrable functions, but it is able to integrate several large
23241  classes of formulas.  In particular, any polynomial or rational function  classes of formulas.  In particular, any polynomial or rational function
23242  (a polynomial divided by a polynomial) is acceptable.  (Rational functions  (a polynomial divided by a polynomial) is acceptable.  (Rational functions
23243  don't have to be in explicit quotient form, however; @c{$x/(1+x^{-2})$}  don't have to be in explicit quotient form, however;
23244  @cite{x/(1+x^-2)}  @texline @tmath{x/(1+x^{-2})}
23245    @infoline @expr{x/(1+x^-2)}
23246  is not strictly a quotient of polynomials, but it is equivalent to  is not strictly a quotient of polynomials, but it is equivalent to
23247  @cite{x^3/(x^2+1)}, which is.)  Also, square roots of terms involving  @expr{x^3/(x^2+1)}, which is.)  Also, square roots of terms involving
23248  @cite{x} and @cite{x^2} may appear in rational functions being  @expr{x} and @expr{x^2} may appear in rational functions being
23249  integrated.  Finally, rational functions involving trigonometric or  integrated.  Finally, rational functions involving trigonometric or
23250  hyperbolic functions can be integrated.  hyperbolic functions can be integrated.
23251    
# Line 23000  integral $\int_a^b f(x) \, dx$. Line 23266  integral $\int_a^b f(x) \, dx$.
23266    
23267  Please note that the current implementation of Calc's integrator sometimes  Please note that the current implementation of Calc's integrator sometimes
23268  produces results that are significantly more complex than they need to  produces results that are significantly more complex than they need to
23269  be.  For example, the integral Calc finds for @c{$1/(x+\sqrt{x^2+1})$}  be.  For example, the integral Calc finds for
23270  @cite{1/(x+sqrt(x^2+1))}  @texline @tmath{1/(x+\sqrt{x^2+1})}
23271    @infoline @expr{1/(x+sqrt(x^2+1))}
23272  is several times more complicated than the answer Mathematica  is several times more complicated than the answer Mathematica
23273  returns for the same input, although the two forms are numerically  returns for the same input, although the two forms are numerically
23274  equivalent.  Also, any indefinite integral should be considered to have  equivalent.  Also, any indefinite integral should be considered to have
23275  an arbitrary constant of integration added to it, although Calc does not  an arbitrary constant of integration added to it, although Calc does not
23276  write an explicit constant of integration in its result.  For example,  write an explicit constant of integration in its result.  For example,
23277  Calc's solution for @c{$1/(1+\tan x)$}  Calc's solution for
23278  @cite{1/(1+tan(x))} differs from the solution given  @texline @tmath{1/(1+\tan x)}
23279  in the @emph{CRC Math Tables} by a constant factor of @c{$\pi i / 2$}  @infoline @expr{1/(1+tan(x))}
23280  @cite{pi i / 2},  differs from the solution given in the @emph{CRC Math Tables} by a
23281    constant factor of  
23282    @texline @tmath{\pi i / 2}
23283    @infoline @expr{pi i / 2},
23284  due to a different choice of constant of integration.  due to a different choice of constant of integration.
23285    
23286  The Calculator remembers all the integrals it has done.  If conditions  The Calculator remembers all the integrals it has done.  If conditions
# Line 23068  in your @code{IntegRules}. Line 23338  in your @code{IntegRules}.
23338  @tindex Ei  @tindex Ei
23339  As a more serious example, the expression @samp{exp(x)/x} cannot be  As a more serious example, the expression @samp{exp(x)/x} cannot be
23340  integrated in terms of the standard functions, so the ``exponential  integrated in terms of the standard functions, so the ``exponential
23341  integral'' function @c{${\rm Ei}(x)$}  integral'' function
23342  @cite{Ei(x)} was invented to describe it.  @texline @tmath{{\rm Ei}(x)}
23343    @infoline @expr{Ei(x)}
23344    was invented to describe it.
23345  We can get Calc to do this integral in terms of a made-up @code{Ei}  We can get Calc to do this integral in terms of a made-up @code{Ei}
23346  function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]}  function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]}
23347  to @code{IntegRules}.  Now entering @samp{exp(2x)/x} on the stack  to @code{IntegRules}.  Now entering @samp{exp(2x)/x} on the stack
# Line 23215  of just a variable to produce a Taylor e Line 23487  of just a variable to produce a Taylor e
23487  You may specify the number of terms with a numeric prefix argument;  You may specify the number of terms with a numeric prefix argument;
23488  otherwise the command will prompt you for the number of terms.  Note that  otherwise the command will prompt you for the number of terms.  Note that
23489  many series expansions have coefficients of zero for some terms, so you  many series expansions have coefficients of zero for some terms, so you
23490  may appear to get fewer terms than you asked for.@refill  may appear to get fewer terms than you asked for.
23491    
23492  If the @kbd{a i} command is unable to find a symbolic integral for a  If the @kbd{a i} command is unable to find a symbolic integral for a
23493  function, you can get an approximation by integrating the function's  function, you can get an approximation by integrating the function's
# Line 23232  Taylor series. Line 23504  Taylor series.
23504  @cindex Solving equations  @cindex Solving equations
23505  The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges  The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges
23506  an equation to solve for a specific variable.  An equation is an  an equation to solve for a specific variable.  An equation is an
23507  expression of the form @cite{L = R}.  For example, the command @kbd{a S x}  expression of the form @expr{L = R}.  For example, the command @kbd{a S x}
23508  will rearrange @cite{y = 3x + 6} to the form, @cite{x = y/3 - 2}.  If the  will rearrange @expr{y = 3x + 6} to the form, @expr{x = y/3 - 2}.  If the
23509  input is not an equation, it is treated like an equation of the  input is not an equation, it is treated like an equation of the
23510  form @cite{X = 0}.  form @expr{X = 0}.
23511    
23512  This command also works for inequalities, as in @cite{y < 3x + 6}.  This command also works for inequalities, as in @expr{y < 3x + 6}.
23513  Some inequalities cannot be solved where the analogous equation could  Some inequalities cannot be solved where the analogous equation could
23514  be; for example, solving @c{$a < b \, c$}  be; for example, solving
23515  @cite{a < b c} for @cite{b} is impossible  @texline @tmath{a < b \, c}
23516  without knowing the sign of @cite{c}.  In this case, @kbd{a S} will  @infoline @expr{a < b c}
23517  produce the result @c{$b \mathbin{\hbox{\code{!=}}} a/c$}  for @expr{b} is impossible
23518  @cite{b != a/c} (using the not-equal-to operator)  without knowing the sign of @expr{c}.  In this case, @kbd{a S} will
23519  to signify that the direction of the inequality is now unknown.  The  produce the result
23520  inequality @c{$a \le b \, c$}  @texline @tmath{b \mathbin{\hbox{\code{!=}}} a/c}
23521  @cite{a <= b c} is not even partially solved.  @infoline @expr{b != a/c}
23522  @xref{Declarations}, for a way to tell Calc that the signs of the  (using the not-equal-to operator) to signify that the direction of the
23523  variables in a formula are in fact known.  inequality is now unknown.  The inequality
23524    @texline @tmath{a \le b \, c}
23525    @infoline @expr{a <= b c}
23526    is not even partially solved.  @xref{Declarations}, for a way to tell
23527    Calc that the signs of the variables in a formula are in fact known.
23528    
23529  Two useful commands for working with the result of @kbd{a S} are  Two useful commands for working with the result of @kbd{a S} are
23530  @kbd{a .} (@pxref{Logical Operations}), which converts @cite{x = y/3 - 2}  @kbd{a .} (@pxref{Logical Operations}), which converts @expr{x = y/3 - 2}
23531  to @cite{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates  to @expr{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates
23532  another formula with @cite{x} set equal to @cite{y/3 - 2}.  another formula with @expr{x} set equal to @expr{y/3 - 2}.
23533    
23534  @menu  @menu
23535  * Multiple Solutions::  * Multiple Solutions::
# Line 23293  There is a similar phenomenon going the Line 23569  There is a similar phenomenon going the
23569  we solve @samp{sqrt(y) = x} for @code{y}.  Calc squares both sides  we solve @samp{sqrt(y) = x} for @code{y}.  Calc squares both sides
23570  to get @samp{y = x^2}.  This is correct, except that it introduces  to get @samp{y = x^2}.  This is correct, except that it introduces
23571  some dubious solutions.  Consider solving @samp{sqrt(y) = -3}:  some dubious solutions.  Consider solving @samp{sqrt(y) = -3}:
23572  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
23573  in the mathematical sense of square-root, but false (there is no  in the mathematical sense of square-root, but false (there is no
23574  solution) for the actual Calc positive-valued @code{sqrt}.  This  solution) for the actual Calc positive-valued @code{sqrt}.  This
23575  happens for both @kbd{a S} and @kbd{H a S}.  happens for both @kbd{a S} and @kbd{H a S}.
# Line 23337  in that variable is not a positive integ Line 23613  in that variable is not a positive integ
23613  With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression  With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression
23614  on top of the stack as a function of the specified variable and solves  on top of the stack as a function of the specified variable and solves
23615  to find the inverse function, written in terms of the same variable.  to find the inverse function, written in terms of the same variable.
23616  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}.
23617  You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a  You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a
23618  fully general inverse, as described above.  fully general inverse, as described above.
23619    
# Line 23361  reported; @pxref{Declarations}.) Line 23637  reported; @pxref{Declarations}.)
23637  Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver  Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver
23638  symbolic solutions if the polynomial has symbolic coefficients.  Also  symbolic solutions if the polynomial has symbolic coefficients.  Also
23639  note that Calc's solver is not able to get exact symbolic solutions  note that Calc's solver is not able to get exact symbolic solutions
23640  to all polynomials.  Polynomials containing powers up to @cite{x^4}  to all polynomials.  Polynomials containing powers up to @expr{x^4}
23641  can always be solved exactly; polynomials of higher degree sometimes  can always be solved exactly; polynomials of higher degree sometimes
23642  can be:  @cite{x^6 + x^3 + 1} is converted to @cite{(x^3)^2 + (x^3) + 1},  can be:  @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1},
23643  which can be solved for @cite{x^3} using the quadratic equation, and then  which can be solved for @expr{x^3} using the quadratic equation, and then
23644  for @cite{x} by taking cube roots.  But in many cases, like  for @expr{x} by taking cube roots.  But in many cases, like
23645  @cite{x^6 + x + 1}, Calc does not know how to rewrite the polynomial  @expr{x^6 + x + 1}, Calc does not know how to rewrite the polynomial
23646  into a form it can solve.  The @kbd{a P} command can still deliver a  into a form it can solve.  The @kbd{a P} command can still deliver a
23647  list of numerical roots, however, provided that symbolic mode (@kbd{m s})  list of numerical roots, however, provided that symbolic mode (@kbd{m s})
23648  is not turned on.  (If you work with symbolic mode on, recall that the  is not turned on.  (If you work with symbolic mode on, recall that the
# Line 23392  and typing @kbd{a S x,y @key{RET}} produ Line 23668  and typing @kbd{a S x,y @key{RET}} produ
23668  have the same length as the variables vector, and the variables  have the same length as the variables vector, and the variables
23669  will be listed in the same order there.  Note that the solutions  will be listed in the same order there.  Note that the solutions
23670  are not always simplified as far as possible; the solution for  are not always simplified as far as possible; the solution for
23671  @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}
23672  command.  command.
23673    
23674  Calc's algorithm works by trying to eliminate one variable at a  Calc's algorithm works by trying to eliminate one variable at a
# Line 23453  to satisfy the equations.  @xref{Curve F Line 23729  to satisfy the equations.  @xref{Curve F
23729  The @code{poly} function takes a polynomial and a variable as  The @code{poly} function takes a polynomial and a variable as
23730  arguments, and returns a vector of polynomial coefficients (constant  arguments, and returns a vector of polynomial coefficients (constant
23731  coefficient first).  For example, @samp{poly(x^3 + 2 x, x)} returns  coefficient first).  For example, @samp{poly(x^3 + 2 x, x)} returns
23732  @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},
23733  the call to @code{poly} is left in symbolic form.  If the input does  the call to @code{poly} is left in symbolic form.  If the input does
23734  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
23735  of length one, representing a polynomial with only a constant  of length one, representing a polynomial with only a constant
23736  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]}.
23737  The last element of the returned vector is guaranteed to be nonzero;  The last element of the returned vector is guaranteed to be nonzero;
23738  note that @samp{poly(0, x)} returns the empty vector @cite{[]}.  note that @samp{poly(0, x)} returns the empty vector @expr{[]}.
23739  Note also that @cite{x} may actually be any formula; for example,  Note also that @expr{x} may actually be any formula; for example,
23740  @samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @cite{[3, -1, 1]}.  @samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @expr{[3, -1, 1]}.
23741    
23742  @cindex Coefficients of polynomial  @cindex Coefficients of polynomial
23743  @cindex Degree of polynomial  @cindex Degree of polynomial
23744  To get the @cite{x^k} coefficient of polynomial @cite{p}, use  To get the @expr{x^k} coefficient of polynomial @expr{p}, use
23745  @samp{poly(p, x)_(k+1)}.  To get the degree of polynomial @cite{p},  @samp{poly(p, x)_(k+1)}.  To get the degree of polynomial @expr{p},
23746  use @samp{vlen(poly(p, x)) - 1}.  For example, @samp{poly((x+1)^4, x)}  use @samp{vlen(poly(p, x)) - 1}.  For example, @samp{poly((x+1)^4, x)}
23747  returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)}  returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)}
23748  gives the @cite{x^2} coefficient of this polynomial, 6.  gives the @expr{x^2} coefficient of this polynomial, 6.
23749    
23750  @ignore  @ignore
23751  @starindex  @starindex
# Line 23494  their arguments as polynomials, will not Line 23770  their arguments as polynomials, will not
23770  is considered trivial.  is considered trivial.
23771    
23772  For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]},  For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]},
23773  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}.
23774    
23775  The term @var{x} may itself be a polynomial in @var{var}.  This is  The term @var{x} may itself be a polynomial in @var{var}.  This is
23776  done to reduce the size of the @var{c} vector.  For example,  done to reduce the size of the @var{c} vector.  For example,
23777  @samp{gpoly(x^4 + x^2 - 1, x)} returns @samp{[x^2, [-1, 1, 1], 1]},  @samp{gpoly(x^4 + x^2 - 1, x)} returns @samp{[x^2, [-1, 1, 1], 1]},
23778  since a quadratic polynomial in @cite{x^2} is easier to solve than  since a quadratic polynomial in @expr{x^2} is easier to solve than
23779  a quartic polynomial in @cite{x}.  a quartic polynomial in @expr{x}.
23780    
23781  A few more examples of the kinds of polynomials @code{gpoly} can  A few more examples of the kinds of polynomials @code{gpoly} can
23782  discover:  discover:
# Line 23517  x^(2a) + 2 x^a + 5       [x^a, [5, 2, 1] Line 23793  x^(2a) + 2 x^a + 5       [x^a, [5, 2, 1]
23793    
23794  The @code{poly} and @code{gpoly} functions accept a third integer argument  The @code{poly} and @code{gpoly} functions accept a third integer argument
23795  which specifies the largest degree of polynomial that is acceptable.  which specifies the largest degree of polynomial that is acceptable.
23796  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}
23797  or less will be returned.  Otherwise, the @code{poly} or @code{gpoly}  or less will be returned.  Otherwise, the @code{poly} or @code{gpoly}
23798  call will remain in symbolic form.  For example, the equation solver  call will remain in symbolic form.  For example, the equation solver
23799  can handle quartics and smaller polynomials, so it calls  can handle quartics and smaller polynomials, so it calls
# Line 23549  The @code{plead} function finds the lead Line 23825  The @code{plead} function finds the lead
23825  Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},  Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},
23826  though again more efficient.  In particular, @samp{plead((2x+1)^10, x)}  though again more efficient.  In particular, @samp{plead((2x+1)^10, x)}
23827  returns 1024 without expanding out the list of coefficients.  The  returns 1024 without expanding out the list of coefficients.  The
23828  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}.
23829    
23830  @ignore  @ignore
23831  @starindex  @starindex
# Line 23618  on numerical data.) Line 23894  on numerical data.)
23894  The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a  The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a
23895  numerical solution (or @dfn{root}) of an equation.  (This command treats  numerical solution (or @dfn{root}) of an equation.  (This command treats
23896  inequalities the same as equations.  If the input is any other kind  inequalities the same as equations.  If the input is any other kind
23897  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}.)
23898    
23899  The @kbd{a R} command requires an initial guess on the top of the  The @kbd{a R} command requires an initial guess on the top of the
23900  stack, and a formula in the second-to-top position.  It prompts for a  stack, and a formula in the second-to-top position.  It prompts for a
# Line 23704  value of the variable which minimizes th Line 23980  value of the variable which minimizes th
23980  with the minimum value itself.  with the minimum value itself.
23981    
23982  Note that this command looks for a @emph{local} minimum.  Many functions  Note that this command looks for a @emph{local} minimum.  Many functions
23983  have more than one minimum; some, like @c{$x \sin x$}  have more than one minimum; some, like
23984  @cite{x sin(x)}, have infinitely  @texline @tmath{x \sin x},
23985  many.  In fact, there is no easy way to define the ``global'' minimum  @infoline @expr{x sin(x)},
23986  of @c{$x \sin x$}  have infinitely many.  In fact, there is no easy way to define the
23987  @cite{x sin(x)} but Calc can still locate any particular local minimum  ``global'' minimum of
23988    @texline @tmath{x \sin x}
23989    @infoline @expr{x sin(x)}
23990    but Calc can still locate any particular local minimum
23991  for you.  Calc basically goes downhill from the initial guess until it  for you.  Calc basically goes downhill from the initial guess until it
23992  finds a point at which the function's value is greater both to the left  finds a point at which the function's value is greater both to the left
23993  and to the right.  Calc does not use derivatives when minimizing a function.  and to the right.  Calc does not use derivatives when minimizing a function.
23994    
23995  If your initial guess is an interval and it looks like the minimum  If your initial guess is an interval and it looks like the minimum
23996  occurs at one or the other endpoint of the interval, Calc will return  occurs at one or the other endpoint of the interval, Calc will return
23997  that endpoint only if that endpoint is closed; thus, minimizing @cite{17 x}  that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x}
23998  over @cite{[2..3]} will return @cite{[2, 38]}, but minimizing over  over @expr{[2..3]} will return @expr{[2, 38]}, but minimizing over
23999  @cite{(2..3]} would report no minimum found.  In general, you should  @expr{(2..3]} would report no minimum found.  In general, you should
24000  use closed intervals to find literally the minimum value in that  use closed intervals to find literally the minimum value in that
24001  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
24002  any, that happens to lie in that range.  any, that happens to lie in that range.
24003    
24004  Most functions are smooth and flat near their minimum values.  Because  Most functions are smooth and flat near their minimum values.  Because
# Line 23781  multidimensional minimization is current Line 24060  multidimensional minimization is current
24060    
24061  @noindent  @noindent
24062  The @kbd{a F} command fits a set of data to a @dfn{model formula},  The @kbd{a F} command fits a set of data to a @dfn{model formula},
24063  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
24064  to be determined.  For a typical set of measured data there will be  to be determined.  For a typical set of measured data there will be
24065  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
24066  case, Calc chooses values of the parameters that provide the closest  case, Calc chooses values of the parameters that provide the closest
24067  possible fit.  possible fit.
24068    
# Line 23806  possible fit. Line 24085  possible fit.
24085  @cindex Linear regression  @cindex Linear regression
24086  @cindex Least-squares fits  @cindex Least-squares fits
24087  The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts  The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts
24088  to fit a set of data (@cite{x} and @cite{y} vectors of numbers) to a  to fit a set of data (@expr{x} and @expr{y} vectors of numbers) to a
24089  straight line, polynomial, or other function of @cite{x}.  For the  straight line, polynomial, or other function of @expr{x}.  For the
24090  moment we will consider only the case of fitting to a line, and we  moment we will consider only the case of fitting to a line, and we
24091  will ignore the issue of whether or not the model was in fact a good  will ignore the issue of whether or not the model was in fact a good
24092  fit for the data.  fit for the data.
24093    
24094  In a standard linear least-squares fit, we have a set of @cite{(x,y)}  In a standard linear least-squares fit, we have a set of @expr{(x,y)}
24095  data points that we wish to fit to the model @cite{y = m x + b}  data points that we wish to fit to the model @expr{y = m x + b}
24096  by adjusting the parameters @cite{m} and @cite{b} to make the @cite{y}  by adjusting the parameters @expr{m} and @expr{b} to make the @expr{y}
24097  values calculated from the formula be as close as possible to the actual  values calculated from the formula be as close as possible to the actual
24098  @cite{y} values in the data set.  (In a polynomial fit, the model is  @expr{y} values in the data set.  (In a polynomial fit, the model is
24099  instead, say, @cite{y = a x^3 + b x^2 + c x + d}.  In a multilinear fit,  instead, say, @expr{y = a x^3 + b x^2 + c x + d}.  In a multilinear fit,
24100  we have data points of the form @cite{(x_1,x_2,x_3,y)} and our model is  we have data points of the form @expr{(x_1,x_2,x_3,y)} and our model is
24101  @cite{y = a x_1 + b x_2 + c x_3 + d}.  These will be discussed later.)  @expr{y = a x_1 + b x_2 + c x_3 + d}.  These will be discussed later.)
24102    
24103  In the model formula, variables like @cite{x} and @cite{x_2} are called  In the model formula, variables like @expr{x} and @expr{x_2} are called
24104  the @dfn{independent variables}, and @cite{y} is the @dfn{dependent  the @dfn{independent variables}, and @expr{y} is the @dfn{dependent
24105  variable}.  Variables like @cite{m}, @cite{a}, and @cite{b} are called  variable}.  Variables like @expr{m}, @expr{a}, and @expr{b} are called
24106  the @dfn{parameters} of the model.  the @dfn{parameters} of the model.
24107    
24108  The @kbd{a F} command takes the data set to be fitted from the stack.  The @kbd{a F} command takes the data set to be fitted from the stack.
24109  By default, it expects the data in the form of a matrix.  For example,  By default, it expects the data in the form of a matrix.  For example,
24110  for a linear or polynomial fit, this would be a @c{$2\times N$}  for a linear or polynomial fit, this would be a
24111  @asis{2xN} matrix where  @texline @tmath{2\times N}
24112  the first row is a list of @cite{x} values and the second row has the  @infoline 2xN
24113  corresponding @cite{y} values.  For the multilinear fit shown above,  matrix where the first row is a list of @expr{x} values and the second
24114  the matrix would have four rows (@cite{x_1}, @cite{x_2}, @cite{x_3}, and  row has the corresponding @expr{y} values.  For the multilinear fit
24115  @cite{y}, respectively).  shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2},
24116    @expr{x_3}, and @expr{y}, respectively).
24117  If you happen to have an @c{$N\times2$}  
24118  @asis{Nx2} matrix instead of a @c{$2\times N$}  If you happen to have an
24119  @asis{2xN} matrix,  @texline @tmath{N\times2}
24120  just press @kbd{v t} first to transpose the matrix.  @infoline Nx2
24121    matrix instead of a
24122    @texline @tmath{2\times N}
24123    @infoline 2xN
24124    matrix, just press @kbd{v t} first to transpose the matrix.
24125    
24126  After you type @kbd{a F}, Calc prompts you to select a model.  For a  After you type @kbd{a F}, Calc prompts you to select a model.  For a
24127  linear fit, press the digit @kbd{1}.  linear fit, press the digit @kbd{1}.
24128    
24129  Calc then prompts for you to name the variables.  By default it chooses  Calc then prompts for you to name the variables.  By default it chooses
24130  high letters like @cite{x} and @cite{y} for independent variables and  high letters like @expr{x} and @expr{y} for independent variables and
24131  low letters like @cite{a} and @cite{b} for parameters.  (The dependent  low letters like @expr{a} and @expr{b} for parameters.  (The dependent
24132  variable doesn't need a name.)  The two kinds of variables are separated  variable doesn't need a name.)  The two kinds of variables are separated
24133  by a semicolon.  Since you generally care more about the names of the  by a semicolon.  Since you generally care more about the names of the
24134  independent variables than of the parameters, Calc also allows you to  independent variables than of the parameters, Calc also allows you to
# Line 23874  $$ Line 24157  $$
24157  @noindent  @noindent
24158  is on the stack and we wish to do a simple linear fit.  Type  is on the stack and we wish to do a simple linear fit.  Type
24159  @kbd{a F}, then @kbd{1} for the model, then @key{RET} to use  @kbd{a F}, then @kbd{1} for the model, then @key{RET} to use
24160  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}
24161  on the stack.  Calc has created the model expression @kbd{a + b x},  on the stack.  Calc has created the model expression @kbd{a + b x},
24162  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
24163  data.  (In this case, it was able to find an exact fit.)  Calc then  data.  (In this case, it was able to find an exact fit.)  Calc then
24164  substituted those values for @cite{a} and @cite{b} in the model  substituted those values for @expr{a} and @expr{b} in the model
24165  formula.  formula.
24166    
24167  The @kbd{a F} command puts two entries in the trail.  One is, as  The @kbd{a F} command puts two entries in the trail.  One is, as
24168  always, a copy of the result that went to the stack; the other is  always, a copy of the result that went to the stack; the other is
24169  a vector of the actual parameter values, written as equations:  a vector of the actual parameter values, written as equations:
24170  @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
24171  than pick them out of the formula.  (You can type @kbd{t y}  than pick them out of the formula.  (You can type @kbd{t y}
24172  to move this vector to the stack; see @ref{Trail Commands}.  to move this vector to the stack; see @ref{Trail Commands}.
24173    
# Line 23930  $$ \chi^2 = \sum_{i=1}^N (y_i - (a + b x Line 24213  $$ \chi^2 = \sum_{i=1}^N (y_i - (a + b x
24213  @end tex  @end tex
24214    
24215  @noindent  @noindent
24216  which is clearly zero if @cite{a + b x} exactly fits all data points,  which is clearly zero if @expr{a + b x} exactly fits all data points,
24217  and increases as various @cite{a + b x_i} values fail to match the  and increases as various @expr{a + b x_i} values fail to match the
24218  corresponding @cite{y_i} values.  There are several reasons why the  corresponding @expr{y_i} values.  There are several reasons why the
24219  summand is squared, one of them being to ensure that @c{$\chi^2 \ge 0$}  summand is squared, one of them being to ensure that
24220  @cite{chi^2 >= 0}.  @texline @tmath{\chi^2 \ge 0}.
24221  Least-squares fitting simply chooses the values of @cite{a} and @cite{b}  @infoline @expr{chi^2 >= 0}.
24222  for which the error @c{$\chi^2$}  Least-squares fitting simply chooses the values of @expr{a} and @expr{b}
24223  @cite{chi^2} is as small as possible.  for which the error
24224    @texline @tmath{\chi^2}
24225    @infoline @expr{chi^2}
24226    is as small as possible.
24227    
24228  Other kinds of models do the same thing but with a different model  Other kinds of models do the same thing but with a different model
24229  formula in place of @cite{a + b x_i}.  formula in place of @expr{a + b x_i}.
24230    
24231  @tex  @tex
24232  \bigskip  \bigskip
# Line 23953  of a data matrix.  In the linear case, @ Line 24239  of a data matrix.  In the linear case, @
24239  is always one independent variable and one dependent variable.  is always one independent variable and one dependent variable.
24240    
24241  A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two  A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two
24242  items from the stack, an @var{n}-row matrix of @cite{x} values, and a  items from the stack, an @var{n}-row matrix of @expr{x} values, and a
24243  vector of @cite{y} values.  If there is only one independent variable,  vector of @expr{y} values.  If there is only one independent variable,
24244  the @cite{x} values can be either a one-row matrix or a plain vector,  the @expr{x} values can be either a one-row matrix or a plain vector,
24245  in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix.  in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix.
24246    
24247  @node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits, Curve Fitting  @node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits, Curve Fitting
# Line 23974  we could fit the original data matrix fr Line 24260  we could fit the original data matrix fr
24260    
24261  Note that since the constant and linear terms are enough to fit the  Note that since the constant and linear terms are enough to fit the
24262  data exactly, it's no surprise that Calc chose a tiny contribution  data exactly, it's no surprise that Calc chose a tiny contribution
24263  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
24264  to roundoff error.  Since our data are exact integers, we could get  to roundoff error.  Since our data are exact integers, we could get
24265  an exact answer by typing @kbd{m f} first to get fraction mode.  an exact answer by typing @kbd{m f} first to get fraction mode.
24266  Then the @cite{x^2} term would vanish altogether.  Usually, though,  Then the @expr{x^2} term would vanish altogether.  Usually, though,
24267  the data being fitted will be approximate floats so fraction mode  the data being fitted will be approximate floats so fraction mode
24268  won't help.)  won't help.)
24269    
24270  Doing the @kbd{a F 2} fit on the data set with 14 instead of 13  Doing the @kbd{a F 2} fit on the data set with 14 instead of 13
24271  gives a much larger @cite{x^2} contribution, as Calc bends the  gives a much larger @expr{x^2} contribution, as Calc bends the
24272  line slightly to improve the fit.  line slightly to improve the fit.
24273    
24274  @example  @example
# Line 24000  a polynomial that exactly matches all fi Line 24286  a polynomial that exactly matches all fi
24286  @end example  @end example
24287    
24288  The actual coefficients we get with a precision of 12, like  The actual coefficients we get with a precision of 12, like
24289  @cite{0.0416666663588}, clearly suffer from loss of precision.  @expr{0.0416666663588}, clearly suffer from loss of precision.
24290  It is a good idea to increase the working precision to several  It is a good idea to increase the working precision to several
24291  digits beyond what you need when you do a fitting operation.  digits beyond what you need when you do a fitting operation.
24292  Or, if your data are exact, use fraction mode to get exact  Or, if your data are exact, use fraction mode to get exact
# Line 24023  command described below.  @xref{Interpol Line 24309  command described below.  @xref{Interpol
24309  @end tex  @end tex
24310    
24311  Another generalization of the linear model is to assume the  Another generalization of the linear model is to assume the
24312  @cite{y} values are a sum of linear contributions from several  @expr{y} values are a sum of linear contributions from several
24313  @cite{x} values.  This is a @dfn{multilinear} fit, and it is also  @expr{x} values.  This is a @dfn{multilinear} fit, and it is also
24314  selected by the @kbd{1} digit key.  (Calc decides whether the fit  selected by the @kbd{1} digit key.  (Calc decides whether the fit
24315  is linear or multilinear by counting the rows in the data matrix.)  is linear or multilinear by counting the rows in the data matrix.)
24316    
# Line 24039  Given the data matrix, Line 24325  Given the data matrix,
24325  @end example  @end example
24326    
24327  @noindent  @noindent
24328  the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the  the command @kbd{a F 1 @key{RET}} will call the first row @expr{x} and the
24329  second row @cite{y}, and will fit the values in the third row to the  second row @expr{y}, and will fit the values in the third row to the
24330  model @cite{a + b x + c y}.  model @expr{a + b x + c y}.
24331    
24332  @example  @example
24333  8. + 3. x + 0.5 y  8. + 3. x + 0.5 y
# Line 24056  Calc can do multilinear fits with any nu Line 24342  Calc can do multilinear fits with any nu
24342    
24343  Yet another variation is @dfn{homogeneous} linear models, in which  Yet another variation is @dfn{homogeneous} linear models, in which
24344  the constant term is known to be zero.  In the linear case, this  the constant term is known to be zero.  In the linear case, this
24345  means the model formula is simply @cite{a x}; in the multilinear  means the model formula is simply @expr{a x}; in the multilinear
24346  case, the model might be @cite{a x + b y + c z}; and in the polynomial  case, the model might be @expr{a x + b y + c z}; and in the polynomial
24347  case, the model could be @cite{a x + b x^2 + c x^3}.  You can get  case, the model could be @expr{a x + b x^2 + c x^3}.  You can get
24348  a homogeneous linear or multilinear model by pressing the letter  a homogeneous linear or multilinear model by pressing the letter
24349  @kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}.  @kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}.
24350    
24351  It is certainly possible to have other constrained linear models,  It is certainly possible to have other constrained linear models,
24352  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
24353  key to select models like these, a later section shows how to enter  key to select models like these, a later section shows how to enter
24354  any desired model by hand.  In the first case, for example, you  any desired model by hand.  In the first case, for example, you
24355  would enter @kbd{a F ' 2.3 + a x}.  would enter @kbd{a F ' 2.3 + a x}.
24356    
24357  Another class of models that will work but must be entered by hand  Another class of models that will work but must be entered by hand
24358  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}.
24359    
24360  @node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and Multilinear Fits, Curve Fitting  @node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and Multilinear Fits, Curve Fitting
24361  @subsection Error Estimates for Fits  @subsection Error Estimates for Fits
# Line 24096  contain error forms.  The data values mu Line 24382  contain error forms.  The data values mu
24382  or all be plain numbers.  Error forms can go anywhere but generally  or all be plain numbers.  Error forms can go anywhere but generally
24383  go on the numbers in the last row of the data matrix.  If the last  go on the numbers in the last row of the data matrix.  If the last
24384  row contains error forms  row contains error forms
24385  `@var{y_i}@w{ @t{+/-} }@c{$\sigma_i$}  @texline `@var{y_i}@w{ @t{+/-} }@tmath{\sigma_i}',
24386  @var{sigma_i}', then the @c{$\chi^2$}  @infoline `@var{y_i}@w{ @t{+/-} }@var{sigma_i}',
24387  @cite{chi^2}  then the
24388    @texline @tmath{\chi^2}
24389    @infoline @expr{chi^2}
24390  statistic is now,  statistic is now,
24391    
24392  @ifinfo  @ifinfo
# Line 24119  the fitting operation. Line 24407  the fitting operation.
24407    
24408  If there are error forms on other rows of the data matrix, all the  If there are error forms on other rows of the data matrix, all the
24409  errors for a given data point are combined; the square root of the  errors for a given data point are combined; the square root of the
24410  sum of the squares of the errors forms the @c{$\sigma_i$}  sum of the squares of the errors forms the
24411  @cite{sigma_i} used for  @texline @tmath{\sigma_i}
24412  the data point.  @infoline @expr{sigma_i}
24413    used for the data point.
24414    
24415  Both @kbd{a F} and @kbd{H a F} can accept error forms in the input  Both @kbd{a F} and @kbd{H a F} can accept error forms in the input
24416  matrix, although if you are concerned about error analysis you will  matrix, although if you are concerned about error analysis you will
24417  probably use @kbd{H a F} so that the output also contains error  probably use @kbd{H a F} so that the output also contains error
24418  estimates.  estimates.
24419    
24420  If the input contains error forms but all the @c{$\sigma_i$}  If the input contains error forms but all the
24421  @cite{sigma_i} values are  @texline @tmath{\sigma_i}
24422  the same, it is easy to see that the resulting fitted model will be  @infoline @expr{sigma_i}
24423  the same as if the input did not have error forms at all (@c{$\chi^2$}  values are the same, it is easy to see that the resulting fitted model
24424  @cite{chi^2}  will be the same as if the input did not have error forms at all
24425  is simply scaled uniformly by @c{$1 / \sigma^2$}  @texline (@tmath{\chi^2}
24426  @cite{1 / sigma^2}, which doesn't affect  @infoline (@expr{chi^2}
24427  where it has a minimum).  But there @emph{will} be a difference  is simply scaled uniformly by
24428  in the estimated errors of the coefficients reported by @kbd{H a F}.  @texline @tmath{1 / \sigma^2},
24429    @infoline @expr{1 / sigma^2},
24430    which doesn't affect where it has a minimum).  But there @emph{will} be
24431    a difference in the estimated errors of the coefficients reported by
24432    @kbd{H a F}.
24433    
24434  Consult any text on statistical modeling of data for a discussion  Consult any text on statistical modeling of data for a discussion
24435  of where these error estimates come from and how they should be  of where these error estimates come from and how they should be
# Line 24161  produced. Line 24454  produced.
24454  A vector of ``raw'' parameter values for the model.  These are the  A vector of ``raw'' parameter values for the model.  These are the
24455  polynomial coefficients or other parameters as plain numbers, in the  polynomial coefficients or other parameters as plain numbers, in the
24456  same order as the parameters appeared in the final prompt of the  same order as the parameters appeared in the final prompt of the
24457  @kbd{I a F} command.  For polynomials of degree @cite{d}, this vector  @kbd{I a F} command.  For polynomials of degree @expr{d}, this vector
24458  will have length @cite{M = d+1} with the constant term first.  will have length @expr{M = d+1} with the constant term first.
24459    
24460  @item  @item
24461  The covariance matrix @cite{C} computed from the fit.  This is  The covariance matrix @expr{C} computed from the fit.  This is
24462  an @var{m}x@var{m} symmetric matrix; the diagonal elements  an @var{m}x@var{m} symmetric matrix; the diagonal elements
24463  @c{$C_{jj}$}  @texline @tmath{C_{jj}}
24464  @cite{C_j_j} are the variances @c{$\sigma_j^2$}  @infoline @expr{C_j_j}
24465  @cite{sigma_j^2} of the parameters.  are the variances
24466  The other elements are covariances @c{$\sigma_{ij}^2$}  @texline @tmath{\sigma_j^2}
24467  @cite{sigma_i_j^2} that describe the  @infoline @expr{sigma_j^2}
24468  correlation between pairs of parameters.  (A related set of  of the parameters.  The other elements are covariances
24469  numbers, the @dfn{linear correlation coefficients} @c{$r_{ij}$}  @texline @tmath{\sigma_{ij}^2}
24470  @cite{r_i_j},  @infoline @expr{sigma_i_j^2}
24471  are defined as @c{$\sigma_{ij}^2 / \sigma_i \, \sigma_j$}  that describe the correlation between pairs of parameters.  (A related
24472  @cite{sigma_i_j^2 / sigma_i sigma_j}.)  set of numbers, the @dfn{linear correlation coefficients}
24473    @texline @tmath{r_{ij}},
24474    @infoline @expr{r_i_j},
24475    are defined as
24476    @texline @tmath{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.)
24477    @infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.)
24478    
24479  @item  @item
24480  A vector of @cite{M} ``parameter filter'' functions whose  A vector of @expr{M} ``parameter filter'' functions whose
24481  meanings are described below.  If no filters are necessary this  meanings are described below.  If no filters are necessary this
24482  will instead be an empty vector; this is always the case for the  will instead be an empty vector; this is always the case for the
24483  polynomial and multilinear fits described so far.  polynomial and multilinear fits described so far.
24484    
24485  @item  @item
24486  The value of @c{$\chi^2$}  The value of
24487  @cite{chi^2} for the fit, calculated by the formulas  @texline @tmath{\chi^2}
24488  shown above.  This gives a measure of the quality of the fit;  @infoline @expr{chi^2}
24489  statisticians consider @c{$\chi^2 \approx N - M$}  for the fit, calculated by the formulas shown above.  This gives a
24490  @cite{chi^2 = N - M} to indicate a moderately good fit  measure of the quality of the fit; statisticians consider
24491  (where again @cite{N} is the number of data points and @cite{M}  @texline @tmath{\chi^2 \approx N - M}
24492  is the number of parameters).  @infoline @expr{chi^2 = N - M}
24493    to indicate a moderately good fit (where again @expr{N} is the number of
24494    data points and @expr{M} is the number of parameters).
24495    
24496  @item  @item
24497  A measure of goodness of fit expressed as a probability @cite{Q}.  A measure of goodness of fit expressed as a probability @expr{Q}.
24498  This is computed from the @code{utpc} probability distribution  This is computed from the @code{utpc} probability distribution
24499  function using @c{$\chi^2$}  function using
24500  @cite{chi^2} with @cite{N - M} degrees of freedom.  A  @texline @tmath{\chi^2}
24501    @infoline @expr{chi^2}
24502    with @expr{N - M} degrees of freedom.  A
24503  value of 0.5 implies a good fit; some texts recommend that often  value of 0.5 implies a good fit; some texts recommend that often
24504  @cite{Q = 0.1} or even 0.001 can signify an acceptable fit.  In  @expr{Q = 0.1} or even 0.001 can signify an acceptable fit.  In
24505  particular, @c{$\chi^2$}  particular,
24506  @cite{chi^2} statistics assume the errors in your inputs  @texline @tmath{\chi^2}
24507    @infoline @expr{chi^2}
24508    statistics assume the errors in your inputs
24509  follow a normal (Gaussian) distribution; if they don't, you may  follow a normal (Gaussian) distribution; if they don't, you may
24510  have to accept smaller values of @cite{Q}.  have to accept smaller values of @expr{Q}.
24511    
24512  The @cite{Q} value is computed only if the input included error  The @expr{Q} value is computed only if the input included error
24513  estimates.  Otherwise, Calc will report the symbol @code{nan}  estimates.  Otherwise, Calc will report the symbol @code{nan}
24514  for @cite{Q}.  The reason is that in this case the @c{$\chi^2$}  for @expr{Q}.  The reason is that in this case the
24515  @cite{chi^2}  @texline @tmath{\chi^2}
24516    @infoline @expr{chi^2}
24517  value has effectively been used to estimate the original errors  value has effectively been used to estimate the original errors
24518  in the input, and thus there is no redundant information left  in the input, and thus there is no redundant information left
24519  over to use for a confidence test.  over to use for a confidence test.
# Line 24248  Power law.  @i{a x^b y^c}. Line 24553  Power law.  @i{a x^b y^c}.
24553  @item q  @item q
24554  Quadratic.  @i{a + b (x-c)^2 + d (x-e)^2}.  Quadratic.  @i{a + b (x-c)^2 + d (x-e)^2}.
24555  @item g  @item g
24556  Gaussian.  @c{${a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)$}  Gaussian.  
24557  @i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}.  @texline @tmath{{a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)}.
24558    @infoline @i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}.
24559  @end table  @end table
24560    
24561  All of these models are used in the usual way; just press the appropriate  All of these models are used in the usual way; just press the appropriate
# Line 24260  the parameter values from the vector tha Line 24566  the parameter values from the vector tha
24566    
24567  All models except Gaussian and polynomials can generalize as shown to any  All models except Gaussian and polynomials can generalize as shown to any
24568  number of independent variables.  Also, all the built-in models have an  number of independent variables.  Also, all the built-in models have an
24569  additive or multiplicative parameter shown as @cite{a} in the above table  additive or multiplicative parameter shown as @expr{a} in the above table
24570  which can be replaced by zero or one, as appropriate, by typing @kbd{h}  which can be replaced by zero or one, as appropriate, by typing @kbd{h}
24571  before the model key.  before the model key.
24572    
24573  Note that many of these models are essentially equivalent, but express  Note that many of these models are essentially equivalent, but express
24574  the parameters slightly differently.  For example, @cite{a b^x} and  the parameters slightly differently.  For example, @expr{a b^x} and
24575  the other two exponential models are all algebraic rearrangements of  the other two exponential models are all algebraic rearrangements of
24576  each other.  Also, the ``quadratic'' model is just a degree-2 polynomial  each other.  Also, the ``quadratic'' model is just a degree-2 polynomial
24577  with the parameters expressed differently.  Use whichever form best  with the parameters expressed differently.  Use whichever form best
# Line 24275  The HP-28/48 calculators support four di Line 24581  The HP-28/48 calculators support four di
24581  fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}.  fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}.
24582  These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)},  These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)},
24583  @samp{a exp(b x)}, and @samp{a x^b}, respectively.  In each case,  @samp{a exp(b x)}, and @samp{a x^b}, respectively.  In each case,
24584  @cite{a} is what the HP-48 identifies as the ``intercept,'' and  @expr{a} is what the HP-48 identifies as the ``intercept,'' and
24585  @cite{b} is what it calls the ``slope.''  @expr{b} is what it calls the ``slope.''
24586    
24587  @tex  @tex
24588  \bigskip  \bigskip
# Line 24287  If the model you want doesn't appear on Line 24593  If the model you want doesn't appear on
24593  formula, such as @kbd{m x - b}, as the model.  (Not all models  formula, such as @kbd{m x - b}, as the model.  (Not all models
24594  will work, though---see the next section for details.)  will work, though---see the next section for details.)
24595    
24596  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}.
24597  In this case, Calc thinks of all the rows of the data matrix on  In this case, Calc thinks of all the rows of the data matrix on
24598  equal terms; this model effectively has two parameters  equal terms; this model effectively has two parameters
24599  (@cite{m} and @cite{b}) and two independent variables (@cite{x}  (@expr{m} and @expr{b}) and two independent variables (@expr{x}
24600  and @cite{y}), with no ``dependent'' variables.  Model equations  and @expr{y}), with no ``dependent'' variables.  Model equations
24601  do not need to take this @cite{y =} form.  For example, the  do not need to take this @expr{y =} form.  For example, the
24602  implicit line equation @cite{a x + b y = 1} works fine as a  implicit line equation @expr{a x + b y = 1} works fine as a
24603  model.  model.
24604    
24605  When you enter a model, Calc makes an alphabetical list of all  When you enter a model, Calc makes an alphabetical list of all
# Line 24303  default parameters, independent variable Line 24609  default parameters, independent variable
24609  Calc assumes the dependent variable does not appear in the formula  Calc assumes the dependent variable does not appear in the formula
24610  and thus does not need a name.  and thus does not need a name.
24611    
24612  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},
24613  and the data matrix has three rows (meaning two independent variables),  and the data matrix has three rows (meaning two independent variables),
24614  Calc will use @cite{a,mu,sigma} as the default parameters, and the  Calc will use @expr{a,mu,sigma} as the default parameters, and the
24615  data rows will be named @cite{t} and @cite{x}, respectively.  If you  data rows will be named @expr{t} and @expr{x}, respectively.  If you
24616  enter an equation instead of a plain formula, Calc will use @cite{a,mu}  enter an equation instead of a plain formula, Calc will use @expr{a,mu}
24617  as the parameters, and @cite{sigma,t,x} as the three independent  as the parameters, and @expr{sigma,t,x} as the three independent
24618  variables.  variables.
24619    
24620  You can, of course, override these choices by entering something  You can, of course, override these choices by entering something
# Line 24332  choose which variables in the formula ar Line 24638  choose which variables in the formula ar
24638  which are parameters.  which are parameters.
24639    
24640  Models taken from the stack can also be expressed as vectors of  Models taken from the stack can also be expressed as vectors of
24641  two or three elements, @cite{[@var{model}, @var{vars}]} or  two or three elements, @expr{[@var{model}, @var{vars}]} or
24642  @cite{[@var{model}, @var{vars}, @var{params}]}.  Each of @var{vars}  @expr{[@var{model}, @var{vars}, @var{params}]}.  Each of @var{vars}
24643  and @var{params} may be either a variable or a vector of variables.  and @var{params} may be either a variable or a vector of variables.
24644  (If @var{params} is omitted, all variables in @var{model} except  (If @var{params} is omitted, all variables in @var{model} except
24645  those listed as @var{vars} are parameters.)@refill  those listed as @var{vars} are parameters.)
24646    
24647  When you enter a model manually with @kbd{'}, Calc puts a 3-vector  When you enter a model manually with @kbd{'}, Calc puts a 3-vector
24648  describing the model in the trail so you can get it back if you wish.  describing the model in the trail so you can get it back if you wish.
# Line 24364  form @samp{arcsin(y) = a t + b}.  The @c Line 24670  form @samp{arcsin(y) = a t + b}.  The @c
24670  returns results in the range from @i{-90} to 90 degrees (or the  returns results in the range from @i{-90} to 90 degrees (or the
24671  equivalent range in radians).  Suppose you had data that you  equivalent range in radians).  Suppose you had data that you
24672  believed to represent roughly three oscillations of a sine wave,  believed to represent roughly three oscillations of a sine wave,
24673  so that the argument of the sine might go from zero to @c{$3\times360$}  so that the argument of the sine might go from zero to
24674  @i{3*360} degrees.  @texline @tmath{3\times360}
24675    @infoline @i{3*360}
24676    degrees.
24677  The above model would appear to be a good way to determine the  The above model would appear to be a good way to determine the
24678  true frequency and phase of the sine wave, but in practice it  true frequency and phase of the sine wave, but in practice it
24679  would fail utterly.  The righthand side of the actual model  would fail utterly.  The righthand side of the actual model
24680  @samp{arcsin(y) = a t + b} will grow smoothly with @cite{t}, but  @samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but
24681  the lefthand side will bounce back and forth between @i{-90} and 90.  the lefthand side will bounce back and forth between @i{-90} and 90.
24682  No values of @cite{a} and @cite{b} can make the two sides match,  No values of @expr{a} and @expr{b} can make the two sides match,
24683  even approximately.  even approximately.
24684    
24685  There is no good solution to this problem at present.  You could  There is no good solution to this problem at present.  You could
# Line 24388  taking Fourier and related transforms.) Line 24696  taking Fourier and related transforms.)
24696  @noindent  @noindent
24697  Calc's internal least-squares fitter can only handle multilinear  Calc's internal least-squares fitter can only handle multilinear
24698  models.  More precisely, it can handle any model of the form  models.  More precisely, it can handle any model of the form
24699  @cite{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @cite{a,b,c}  @expr{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @expr{a,b,c}
24700  are the parameters and @cite{x,y,z} are the independent variables  are the parameters and @expr{x,y,z} are the independent variables
24701  (of course there can be any number of each, not just three).  (of course there can be any number of each, not just three).
24702    
24703  In a simple multilinear or polynomial fit, it is easy to see how  In a simple multilinear or polynomial fit, it is easy to see how
24704  to convert the model into this form.  For example, if the model  to convert the model into this form.  For example, if the model
24705  is @cite{a + b x + c x^2}, then @cite{f(x) = 1}, @cite{g(x) = x},  is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x},
24706  and @cite{h(x) = x^2} are suitable functions.  and @expr{h(x) = x^2} are suitable functions.
24707    
24708  For other models, Calc uses a variety of algebraic manipulations  For other models, Calc uses a variety of algebraic manipulations
24709  to try to put the problem into the form  to try to put the problem into the form
# Line 24405  Y(x,y,z) = A(a,b,c) F(x,y,z) + B(a,b,c) Line 24713  Y(x,y,z) = A(a,b,c) F(x,y,z) + B(a,b,c)
24713  @end smallexample  @end smallexample
24714    
24715  @noindent  @noindent
24716  where @cite{Y,A,B,C,F,G,H} are arbitrary functions.  It computes  where @expr{Y,A,B,C,F,G,H} are arbitrary functions.  It computes
24717  @cite{Y}, @cite{F}, @cite{G}, and @cite{H} for all the data points,  @expr{Y}, @expr{F}, @expr{G}, and @expr{H} for all the data points,
24718  does a standard linear fit to find the values of @cite{A}, @cite{B},  does a standard linear fit to find the values of @expr{A}, @expr{B},
24719  and @cite{C}, then uses the equation solver to solve for @cite{a,b,c}  and @expr{C}, then uses the equation solver to solve for @expr{a,b,c}
24720  in terms of @cite{A,B,C}.  in terms of @expr{A,B,C}.
24721    
24722  A remarkable number of models can be cast into this general form.  A remarkable number of models can be cast into this general form.
24723  We'll look at two examples here to see how it works.  The power-law  We'll look at two examples here to see how it works.  The power-law
24724  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
24725  can be rewritten as follows:  can be rewritten as follows:
24726    
24727  @example  @example
# Line 24424  ln(y) = ln(a) + b ln(x) Line 24732  ln(y) = ln(a) + b ln(x)
24732  @end example  @end example
24733    
24734  @noindent  @noindent
24735  which matches the desired form with @c{$Y = \ln(y)$}  which matches the desired form with
24736  @cite{Y = ln(y)}, @c{$A = \ln(a)$}  @texline @tmath{Y = \ln(y)},
24737  @cite{A = ln(a)},  @infoline @expr{Y = ln(y)},
24738  @cite{F = 1}, @cite{B = b}, and @c{$G = \ln(x)$}  @texline @tmath{A = \ln(a)},
24739  @cite{G = ln(x)}.  Calc thus computes  @infoline @expr{A = ln(a)},
24740  the logarithms of your @cite{y} and @cite{x} values, does a linear fit  @expr{F = 1}, @expr{B = b}, and
24741  for @cite{A} and @cite{B}, then solves to get @c{$a = \exp(A)$}  @texline @tmath{G = \ln(x)}.
24742  @cite{a = exp(A)} and  @infoline @expr{G = ln(x)}.  
24743  @cite{b = B}.  Calc thus computes the logarithms of your @expr{y} and @expr{x} values,
24744    does a linear fit for @expr{A} and @expr{B}, then solves to get
24745    @texline @tmath{a = \exp(A)}
24746    @infoline @expr{a = exp(A)}
24747    and @expr{b = B}.
24748    
24749  Another interesting example is the ``quadratic'' model, which can  Another interesting example is the ``quadratic'' model, which can
24750  be handled by expanding according to the distributive law.  be handled by expanding according to the distributive law.
# Line 24443  y = a + b c^2 - 2 b c x + b x^2 Line 24755  y = a + b c^2 - 2 b c x + b x^2
24755  @end example  @end example
24756    
24757  @noindent  @noindent
24758  which matches with @cite{Y = y}, @cite{A = a + b c^2}, @cite{F = 1},  which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1},
24759  @cite{B = -2 b c}, @cite{G = x} (the @i{-2} factor could just as easily  @expr{B = -2 b c}, @expr{G = x} (the @i{-2} factor could just as easily
24760  have been put into @cite{G} instead of @cite{B}), @cite{C = b}, and  have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and
24761  @cite{H = x^2}.  @expr{H = x^2}.
24762    
24763  The Gaussian model looks quite complicated, but a closer examination  The Gaussian model looks quite complicated, but a closer examination
24764  shows that it's actually similar to the quadratic model but with an  shows that it's actually similar to the quadratic model but with an
24765  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}.
24766    
24767  An example of a model that cannot be put into general linear  An example of a model that cannot be put into general linear
24768  form is a Gaussian with a constant background added on, i.e.,  form is a Gaussian with a constant background added on, i.e.,
24769  @cite{d} + the regular Gaussian formula.  If you have a model like  @expr{d} + the regular Gaussian formula.  If you have a model like
24770  this, your best bet is to replace enough of your parameters with  this, your best bet is to replace enough of your parameters with
24771  constants to make the model linearizable, then adjust the constants  constants to make the model linearizable, then adjust the constants
24772  manually by doing a series of fits.  You can compare the fits by  manually by doing a series of fits.  You can compare the fits by
24773  graphing them, by examining the goodness-of-fit measures returned by  graphing them, by examining the goodness-of-fit measures returned by
24774  @kbd{I a F}, or by some other method suitable to your application.  @kbd{I a F}, or by some other method suitable to your application.
24775  Note that some models can be linearized in several ways.  The  Note that some models can be linearized in several ways.  The
24776  Gaussian-plus-@var{d} model can be linearized by setting @cite{d}  Gaussian-plus-@var{d} model can be linearized by setting @expr{d}
24777  (the background) to a constant, or by setting @cite{b} (the standard  (the background) to a constant, or by setting @expr{b} (the standard
24778  deviation) and @cite{c} (the mean) to constants.  deviation) and @expr{c} (the mean) to constants.
24779    
24780  To fit a model with constants substituted for some parameters, just  To fit a model with constants substituted for some parameters, just
24781  store suitable values in those parameter variables, then omit them  store suitable values in those parameter variables, then omit them
# Line 24475  from the list of parameters when you ans Line 24787  from the list of parameters when you ans
24787    
24788  A last desperate step would be to use the general-purpose  A last desperate step would be to use the general-purpose
24789  @code{minimize} function rather than @code{fit}.  After all, both  @code{minimize} function rather than @code{fit}.  After all, both
24790  functions solve the problem of minimizing an expression (the @c{$\chi^2$}  functions solve the problem of minimizing an expression (the
24791  @cite{chi^2}  @texline @tmath{\chi^2}
24792    @infoline @expr{chi^2}
24793  sum) by adjusting certain parameters in the expression.  The @kbd{a F}  sum) by adjusting certain parameters in the expression.  The @kbd{a F}
24794  command is able to use a vastly more efficient algorithm due to its  command is able to use a vastly more efficient algorithm due to its
24795  special knowledge about linear chi-square sums, but the @kbd{a N}  special knowledge about linear chi-square sums, but the @kbd{a N}
# Line 24485  command can do the same thing by brute f Line 24798  command can do the same thing by brute f
24798  A compromise would be to pick out a few parameters without which the  A compromise would be to pick out a few parameters without which the
24799  fit is linearizable, and use @code{minimize} on a call to @code{fit}  fit is linearizable, and use @code{minimize} on a call to @code{fit}
24800  which efficiently takes care of the rest of the parameters.  The thing  which efficiently takes care of the rest of the parameters.  The thing
24801  to be minimized would be the value of @c{$\chi^2$}  to be minimized would be the value of
24802  @cite{chi^2} returned as  @texline @tmath{\chi^2}
24803  the fifth result of the @code{xfit} function:  @infoline @expr{chi^2}
24804    returned as the fifth result of the @code{xfit} function:
24805    
24806  @smallexample  @smallexample
24807  minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)  minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)
# Line 24496  minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c Line 24810  minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c
24810  @noindent  @noindent
24811  where @code{gaus} represents the Gaussian model with background,  where @code{gaus} represents the Gaussian model with background,
24812  @code{data} represents the data matrix, and @code{guess} represents  @code{data} represents the data matrix, and @code{guess} represents
24813  the initial guess for @cite{d} that @code{minimize} requires.  the initial guess for @expr{d} that @code{minimize} requires.
24814  This operation will only be, shall we say, extraordinarily slow  This operation will only be, shall we say, extraordinarily slow
24815  rather than astronomically slow (as would be the case if @code{minimize}  rather than astronomically slow (as would be the case if @code{minimize}
24816  were used by itself to solve the problem).  were used by itself to solve the problem).
# Line 24507  were used by itself to solve the problem Line 24821  were used by itself to solve the problem
24821    
24822  The @kbd{I a F} [@code{xfit}] command is somewhat trickier when  The @kbd{I a F} [@code{xfit}] command is somewhat trickier when
24823  nonlinear models are used.  The second item in the result is the  nonlinear models are used.  The second item in the result is the
24824  vector of ``raw'' parameters @cite{A}, @cite{B}, @cite{C}.  The  vector of ``raw'' parameters @expr{A}, @expr{B}, @expr{C}.  The
24825  covariance matrix is written in terms of those raw parameters.  covariance matrix is written in terms of those raw parameters.
24826  The fifth item is a vector of @dfn{filter} expressions.  This  The fifth item is a vector of @dfn{filter} expressions.  This
24827  is the empty vector @samp{[]} if the raw parameters were the same  is the empty vector @samp{[]} if the raw parameters were the same
24828  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},
24829  and so on (which is always true if the model is already linear  and so on (which is always true if the model is already linear
24830  in the parameters as written, e.g., for polynomial fits).  If the  in the parameters as written, e.g., for polynomial fits).  If the
24831  parameters had to be rearranged, the fifth item is instead a vector  parameters had to be rearranged, the fifth item is instead a vector
24832  of one formula per parameter in the original model.  The raw  of one formula per parameter in the original model.  The raw
24833  parameters are expressed in these ``filter'' formulas as  parameters are expressed in these ``filter'' formulas as
24834  @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} for @cite{B},  @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} for @expr{B},
24835  and so on.  and so on.
24836    
24837  When Calc needs to modify the model to return the result, it replaces  When Calc needs to modify the model to return the result, it replaces
# Line 24537  figure out how to interpret the covarian Line 24851  figure out how to interpret the covarian
24851  nontrivial filter functions.  nontrivial filter functions.
24852    
24853  Things are also complicated when the input contains error forms.  Things are also complicated when the input contains error forms.
24854  Suppose there are three independent and dependent variables, @cite{x},  Suppose there are three independent and dependent variables, @expr{x},
24855  @cite{y}, and @cite{z}, one or more of which are error forms in the  @expr{y}, and @expr{z}, one or more of which are error forms in the
24856  data.  Calc combines all the error values by taking the square root  data.  Calc combines all the error values by taking the square root
24857  of the sum of the squares of the errors.  It then changes @cite{x}  of the sum of the squares of the errors.  It then changes @expr{x}
24858  and @cite{y} to be plain numbers, and makes @cite{z} into an error  and @expr{y} to be plain numbers, and makes @expr{z} into an error
24859  form with this combined error.  The @cite{Y(x,y,z)} part of the  form with this combined error.  The @expr{Y(x,y,z)} part of the
24860  linearized model is evaluated, and the result should be an error  linearized model is evaluated, and the result should be an error
24861  form.  The error part of that result is used for @c{$\sigma_i$}  form.  The error part of that result is used for
24862  @cite{sigma_i} for  @texline @tmath{\sigma_i}
24863  the data point.  If for some reason @cite{Y(x,y,z)} does not return  @infoline @expr{sigma_i}
24864  an error form, the combined error from @cite{z} is used directly  for the data point.  If for some reason @expr{Y(x,y,z)} does not return
24865  for @c{$\sigma_i$}  an error form, the combined error from @expr{z} is used directly for
24866  @cite{sigma_i}.  Finally, @cite{z} is also stripped of its error  @texline @tmath{\sigma_i}.
24867  for use in computing @cite{F(x,y,z)}, @cite{G(x,y,z)} and so on;  @infoline @expr{sigma_i}.  
24868    Finally, @expr{z} is also stripped of its error
24869    for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on;
24870  the righthand side of the linearized model is computed in regular  the righthand side of the linearized model is computed in regular
24871  arithmetic with no error forms.  arithmetic with no error forms.
24872    
24873  (While these rules may seem complicated, they are designed to do  (While these rules may seem complicated, they are designed to do
24874  the most reasonable thing in the typical case that @cite{Y(x,y,z)}  the most reasonable thing in the typical case that @expr{Y(x,y,z)}
24875  depends only on the dependent variable @cite{z}, and in fact is  depends only on the dependent variable @expr{z}, and in fact is
24876  often simply equal to @cite{z}.  For common cases like polynomials  often simply equal to @expr{z}.  For common cases like polynomials
24877  and multilinear models, the combined error is simply used as the  and multilinear models, the combined error is simply used as the
24878  @c{$\sigma$}  @texline @tmath{\sigma}
24879  @cite{sigma} for the data point with no further ado.)  @infoline @expr{sigma}
24880    for the data point with no further ado.)
24881    
24882  @tex  @tex
24883  \bigskip  \bigskip
# Line 24617  Parameter variables are renamed to funct Line 24934  Parameter variables are renamed to funct
24934  @samp{fitparam(2)}, and so on, and independent variables are renamed  @samp{fitparam(2)}, and so on, and independent variables are renamed
24935  to @samp{fitvar(1)}, @samp{fitvar(2)}, etc.  The dependent variable  to @samp{fitvar(1)}, @samp{fitvar(2)}, etc.  The dependent variable
24936  is the highest-numbered @code{fitvar}.  For example, the power law  is the highest-numbered @code{fitvar}.  For example, the power law
24937  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
24938    
24939  @smallexample  @smallexample
24940  @group  @group
# Line 24637  fitsystem(@var{Y}, @var{FGH}, @var{abc}) Line 24954  fitsystem(@var{Y}, @var{FGH}, @var{abc})
24954  @end example  @end example
24955    
24956  @noindent  @noindent
24957  where @var{Y} is a formula that describes the function @cite{Y(x,y,z)},  where @var{Y} is a formula that describes the function @expr{Y(x,y,z)},
24958  @var{FGH} is the vector of formulas @cite{[F(x,y,z), G(x,y,z), H(x,y,z)]},  @var{FGH} is the vector of formulas @expr{[F(x,y,z), G(x,y,z), H(x,y,z)]},
24959  and @var{abc} is the vector of parameter filters which refer to the  and @var{abc} is the vector of parameter filters which refer to the
24960  raw parameters as @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)}  raw parameters as @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)}
24961  for @cite{B}, etc.  While the number of raw parameters (the length of  for @expr{B}, etc.  While the number of raw parameters (the length of
24962  the @var{FGH} vector) is usually the same as the number of original  the @var{FGH} vector) is usually the same as the number of original
24963  parameters (the length of the @var{abc} vector), this is not required.  parameters (the length of the @var{abc} vector), this is not required.
24964    
# Line 24664  be put into @var{abc} or @var{FGH}).  In Line 24981  be put into @var{abc} or @var{FGH}).  In
24981  non-constant powers are converted to logs-and-exponentials form,  non-constant powers are converted to logs-and-exponentials form,
24982  and the distributive law is used to expand products of sums.  and the distributive law is used to expand products of sums.
24983  Quotients are rewritten to use the @samp{fitinv} function, where  Quotients are rewritten to use the @samp{fitinv} function, where
24984  @samp{fitinv(x)} represents @cite{1/x} while the @code{FitRules}  @samp{fitinv(x)} represents @expr{1/x} while the @code{FitRules}
24985  are operating.  (The use of @code{fitinv} makes recognition of  are operating.  (The use of @code{fitinv} makes recognition of
24986  linear-looking forms easier.)  If you modify @code{FitRules}, you  linear-looking forms easier.)  If you modify @code{FitRules}, you
24987  will probably only need to modify the rules for this phase.  will probably only need to modify the rules for this phase.
# Line 24672  will probably only need to modify the ru Line 24989  will probably only need to modify the ru
24989  Phase two, whose rules can actually also apply during phases one  Phase two, whose rules can actually also apply during phases one
24990  and three, first rewrites @code{fitmodel} to a two-argument  and three, first rewrites @code{fitmodel} to a two-argument
24991  form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is  form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is
24992  initially zero and @var{model} has been changed from @cite{a=b}  initially zero and @var{model} has been changed from @expr{a=b}
24993  to @cite{a-b} form.  It then tries to peel off invertible functions  to @expr{a-b} form.  It then tries to peel off invertible functions
24994  from the outside of @var{model} and put them into @var{Y} instead,  from the outside of @var{model} and put them into @var{Y} instead,
24995  calling the equation solver to invert the functions.  Finally, when  calling the equation solver to invert the functions.  Finally, when
24996  this is no longer possible, the @code{fitmodel} is changed to a  this is no longer possible, the @code{fitmodel} is changed to a
# Line 24719  least-squares solver wants to see. Line 25036  least-squares solver wants to see.
25036  @tindex hasfitvars  @tindex hasfitvars
25037  Two functions which are useful in connection with @code{FitRules}  Two functions which are useful in connection with @code{FitRules}
25038  are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check  are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check
25039  whether @cite{x} refers to any parameters or independent variables,  whether @expr{x} refers to any parameters or independent variables,
25040  respectively.  Specifically, these functions return ``true'' if the  respectively.  Specifically, these functions return ``true'' if the
25041  argument contains any @code{fitparam} (or @code{fitvar}) function  argument contains any @code{fitparam} (or @code{fitvar}) function
25042  calls, and ``false'' otherwise.  (Recall that ``true'' means a  calls, and ``false'' otherwise.  (Recall that ``true'' means a
# Line 24767  The @code{efit} (corresponding to @kbd{H Line 25084  The @code{efit} (corresponding to @kbd{H
25084  @pindex calc-poly-interp  @pindex calc-poly-interp
25085  @tindex polint  @tindex polint
25086  The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does  The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does
25087  a polynomial interpolation at a particular @cite{x} value.  It takes  a polynomial interpolation at a particular @expr{x} value.  It takes
25088  two arguments from the stack:  A data matrix of the sort used by  two arguments from the stack:  A data matrix of the sort used by
25089  @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}
25090  value.  Calc effectively does an exact polynomial fit as if by @kbd{a F i},  value.  Calc effectively does an exact polynomial fit as if by @kbd{a F i},
25091  then substitutes the @cite{x} value into the result in order to get an  then substitutes the @expr{x} value into the result in order to get an
25092  approximate @cite{y} value based on the fit.  (Calc does not actually  approximate @expr{y} value based on the fit.  (Calc does not actually
25093  use @kbd{a F i}, however; it uses a direct method which is both more  use @kbd{a F i}, however; it uses a direct method which is both more
25094  efficient and more numerically stable.)  efficient and more numerically stable.)
25095    
25096  The result of @kbd{a p} is actually a vector of two values:  The @cite{y}  The result of @kbd{a p} is actually a vector of two values:  The @expr{y}
25097  value approximation, and an error measure @cite{dy} that reflects Calc's  value approximation, and an error measure @expr{dy} that reflects Calc's
25098  estimation of the probable error of the approximation at that value of  estimation of the probable error of the approximation at that value of
25099  @cite{x}.  If the input @cite{x} is equal to any of the @cite{x} values  @expr{x}.  If the input @expr{x} is equal to any of the @expr{x} values
25100  in the data matrix, the output @cite{y} will be the corresponding @cite{y}  in the data matrix, the output @expr{y} will be the corresponding @expr{y}
25101  value from the matrix, and the output @cite{dy} will be exactly zero.  value from the matrix, and the output @expr{dy} will be exactly zero.
25102    
25103  A prefix argument of 2 causes @kbd{a p} to take separate x- and  A prefix argument of 2 causes @kbd{a p} to take separate x- and
25104  y-vectors from the stack instead of one data matrix.  y-vectors from the stack instead of one data matrix.
25105    
25106  If @cite{x} is a vector of numbers, @kbd{a p} will return a matrix of  If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of
25107  interpolated results for each of those @cite{x} values.  (The matrix will  interpolated results for each of those @expr{x} values.  (The matrix will
25108  have two columns, the @cite{y} values and the @cite{dy} values.)  have two columns, the @expr{y} values and the @expr{dy} values.)
25109  If @cite{x} is a formula instead of a number, the @code{polint} function  If @expr{x} is a formula instead of a number, the @code{polint} function
25110  remains in symbolic form; use the @kbd{a "} command to expand it out to  remains in symbolic form; use the @kbd{a "} command to expand it out to
25111  a formula that describes the fit in symbolic terms.  a formula that describes the fit in symbolic terms.
25112    
25113  In all cases, the @kbd{a p} command leaves the data vectors or matrix  In all cases, the @kbd{a p} command leaves the data vectors or matrix
25114  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.
25115    
25116  @kindex H a p  @kindex H a p
25117  @tindex ratint  @tindex ratint
25118  The @kbd{H a p} [@code{ratint}] command does a rational function  The @kbd{H a p} [@code{ratint}] command does a rational function
25119  interpolation.  It is used exactly like @kbd{a p}, except that it  interpolation.  It is used exactly like @kbd{a p}, except that it
25120  uses as its model the quotient of two polynomials.  If there are  uses as its model the quotient of two polynomials.  If there are
25121  @cite{N} data points, the numerator and denominator polynomials will  @expr{N} data points, the numerator and denominator polynomials will
25122  each have degree @cite{N/2} (if @cite{N} is odd, the denominator will  each have degree @expr{N/2} (if @expr{N} is odd, the denominator will
25123  have degree one higher than the numerator).  have degree one higher than the numerator).
25124    
25125  Rational approximations have the advantage that they can accurately  Rational approximations have the advantage that they can accurately
25126  describe functions that have poles (points at which the function's value  describe functions that have poles (points at which the function's value
25127  goes to infinity, so that the denominator polynomial of the approximation  goes to infinity, so that the denominator polynomial of the approximation
25128  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
25129  function, then the result will be a division by zero.  If Infinite mode  function, then the result will be a division by zero.  If Infinite mode
25130  is enabled, the result will be @samp{[uinf, uinf]}.  is enabled, the result will be @samp{[uinf, uinf]}.
25131    
# Line 24842  $$ \sum_{k=1}^5 k^2 = 55 $$ Line 25159  $$ \sum_{k=1}^5 k^2 = 55 $$
25159  The choice of index variable is arbitrary, but it's best not to  The choice of index variable is arbitrary, but it's best not to
25160  use a variable with a stored value.  In particular, while  use a variable with a stored value.  In particular, while
25161  @code{i} is often a favorite index variable, it should be avoided  @code{i} is often a favorite index variable, it should be avoided
25162  in Calc because @code{i} has the imaginary constant @cite{(0, 1)}  in Calc because @code{i} has the imaginary constant @expr{(0, 1)}
25163  as a value.  If you pressed @kbd{=} on a sum over @code{i}, it would  as a value.  If you pressed @kbd{=} on a sum over @code{i}, it would
25164  be changed to a nonsensical sum over the ``variable'' @cite{(0, 1)}!  be changed to a nonsensical sum over the ``variable'' @expr{(0, 1)}!
25165  If you really want to use @code{i} as an index variable, use  If you really want to use @code{i} as an index variable, use
25166  @w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable.  @w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable.
25167  (@xref{Storing Variables}.)  (@xref{Storing Variables}.)
# Line 24878  is one.  If @var{low} is also omitted, t Line 25195  is one.  If @var{low} is also omitted, t
25195  and @samp{inf}, respectively.  and @samp{inf}, respectively.
25196    
25197  Infinite sums can sometimes be evaluated:  @samp{sum(.5^k, k, 1, inf)}  Infinite sums can sometimes be evaluated:  @samp{sum(.5^k, k, 1, inf)}
25198  returns @cite{1}.  This is done by evaluating the sum in closed  returns @expr{1}.  This is done by evaluating the sum in closed
25199  form (to @samp{1. - 0.5^n} in this case), then evaluating this  form (to @samp{1. - 0.5^n} in this case), then evaluating this
25200  formula with @code{n} set to @code{inf}.  Calc's usual rules  formula with @code{n} set to @code{inf}.  Calc's usual rules
25201  for ``infinite'' arithmetic can find the answer from there.  If  for ``infinite'' arithmetic can find the answer from there.  If
# Line 24916  of iterations is @i{-1}.  Thus @samp{sum Line 25233  of iterations is @i{-1}.  Thus @samp{sum
25233  but the sum from @samp{n} to @samp{n-2} may report a nonzero value  but the sum from @samp{n} to @samp{n-2} may report a nonzero value
25234  if Calc used a closed form solution.  if Calc used a closed form solution.
25235    
25236  Calc's logical predicates like @cite{a < b} return 1 for ``true''  Calc's logical predicates like @expr{a < b} return 1 for ``true''
25237  and 0 for ``false.''  @xref{Logical Operations}.  This can be  and 0 for ``false.''  @xref{Logical Operations}.  This can be
25238  used to advantage for building conditional sums.  For example,  used to advantage for building conditional sums.  For example,
25239  @samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all  @samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all
25240  prime numbers from 1 to 20; the @code{prime} predicate returns 1 if  prime numbers from 1 to 20; the @code{prime} predicate returns 1 if
25241  its argument is prime and 0 otherwise.  You can read this expression  its argument is prime and 0 otherwise.  You can read this expression
25242  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,
25243  @samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes  @samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes
25244  squared, since the limits default to plus and minus infinity, but  squared, since the limits default to plus and minus infinity, but
25245  there are no such sums that Calc's built-in rules can do in  there are no such sums that Calc's built-in rules can do in
25246  closed form.  closed form.
25247    
25248  As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the  As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the
25249  sum of @cite{f(k)} for all @cite{k} from 1 to @cite{n}, excluding  sum of @expr{f(k)} for all @expr{k} from 1 to @expr{n}, excluding
25250  one value @cite{k_0}.  Slightly more tricky is the summand  one value @expr{k_0}.  Slightly more tricky is the summand
25251  @samp{(k != k_0) / (k - k_0)}, which is an attempt to describe  @samp{(k != k_0) / (k - k_0)}, which is an attempt to describe
25252  the sum of all @cite{1/(k-k_0)} except at @cite{k = k_0}, where  the sum of all @expr{1/(k-k_0)} except at @expr{k = k_0}, where
25253  this would be a division by zero.  But at @cite{k = k_0}, this  this would be a division by zero.  But at @expr{k = k_0}, this
25254  formula works out to the indeterminate form @cite{0 / 0}, which  formula works out to the indeterminate form @expr{0 / 0}, which
25255  Calc will not assume is zero.  Better would be to use  Calc will not assume is zero.  Better would be to use
25256  @samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does  @samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does
25257  an ``if-then-else'' test:  This expression says, ``if @c{$k \ne k_0$}  an ``if-then-else'' test:  This expression says, ``if
25258  @cite{k != k_0},  @texline @tmath{k \ne k_0},
25259  then @cite{1/(k-k_0)}, else zero.''  Now the formula @cite{1/(k-k_0)}  @infoline @expr{k != k_0},
25260  will not even be evaluated by Calc when @cite{k = k_0}.  then @expr{1/(k-k_0)}, else zero.''  Now the formula @expr{1/(k-k_0)}
25261    will not even be evaluated by Calc when @expr{k = k_0}.
25262    
25263  @cindex Alternating sums  @cindex Alternating sums
25264  @kindex a -  @kindex a -
# Line 24991  for which @code{dnonzero} returns 1 is ` Line 25309  for which @code{dnonzero} returns 1 is `
25309  which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''  which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''
25310  Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then''  Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then''
25311  portion if its condition is provably true, but it will execute the  portion if its condition is provably true, but it will execute the
25312  ``else'' portion for any condition like @cite{a = b} that is not  ``else'' portion for any condition like @expr{a = b} that is not
25313  provably true, even if it might be true.  Algebraic functions that  provably true, even if it might be true.  Algebraic functions that
25314  have conditions as arguments, like @code{? :} and @code{&&}, remain  have conditions as arguments, like @code{? :} and @code{&&}, remain
25315  unevaluated if the condition is neither provably true nor provably  unevaluated if the condition is neither provably true nor provably
# Line 25004  false.  @xref{Declarations}.) Line 25322  false.  @xref{Declarations}.)
25322  @tindex ==  @tindex ==
25323  The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function  The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function
25324  (which can also be written @samp{a = b} or @samp{a == b} in an algebraic  (which can also be written @samp{a = b} or @samp{a == b} in an algebraic
25325  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
25326  are identical expressions, or because they are numbers which are  are identical expressions, or because they are numbers which are
25327  numerically equal.  (Thus the integer 1 is considered equal to the float  numerically equal.  (Thus the integer 1 is considered equal to the float
25328  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,
25329  the comparison is left in symbolic form.  Note that as a command, this  the comparison is left in symbolic form.  Note that as a command, this
25330  operation pops two values from the stack and pushes back either a 1 or  operation pops two values from the stack and pushes back either a 1 or
25331  a 0, or a formula @samp{a = b} if the values' equality cannot be determined.  a 0, or a formula @samp{a = b} if the values' equality cannot be determined.
# Line 25035  variables). Line 25353  variables).
25353  @tindex neq  @tindex neq
25354  @tindex !=  @tindex !=
25355  The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or  The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or
25356  @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.
25357  This also works with more than two arguments; @samp{a != b != c != d}  This also works with more than two arguments; @samp{a != b != c != d}
25358  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
25359  distinct numbers.  distinct numbers.
25360    
25361  @kindex a <  @kindex a <
# Line 25087  distinct numbers. Line 25405  distinct numbers.
25405  @end ignore  @end ignore
25406  @tindex >=  @tindex >=
25407  The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}]  The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}]
25408  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
25409  are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}],  are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}],
25410  @kbd{a [} (@code{calc-less-equal}) [@samp{leq(a,b)} or @samp{a <= b}], and  @kbd{a [} (@code{calc-less-equal}) [@samp{leq(a,b)} or @samp{a <= b}], and
25411  @kbd{a ]} (@code{calc-greater-equal}) [@samp{geq(a,b)} or @samp{a >= b}].  @kbd{a ]} (@code{calc-greater-equal}) [@samp{geq(a,b)} or @samp{a >= b}].
# Line 25121  taking the lefthand side. Line 25439  taking the lefthand side.
25439  @tindex &&  @tindex &&
25440  The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}]  The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}]
25441  function is true if both of its arguments are true, i.e., are  function is true if both of its arguments are true, i.e., are
25442  non-zero numbers.  In this case, the result will be either @cite{a} or  non-zero numbers.  In this case, the result will be either @expr{a} or
25443  @cite{b}, chosen arbitrarily.  If either argument is zero, the result is  @expr{b}, chosen arbitrarily.  If either argument is zero, the result is
25444  zero.  Otherwise, the formula is left in symbolic form.  zero.  Otherwise, the formula is left in symbolic form.
25445    
25446  @kindex a |  @kindex a |
# Line 25132  zero.  Otherwise, the formula is left in Line 25450  zero.  Otherwise, the formula is left in
25450  The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}]  The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}]
25451  function is true if either or both of its arguments are true (nonzero).  function is true if either or both of its arguments are true (nonzero).
25452  The result is whichever argument was nonzero, choosing arbitrarily if both  The result is whichever argument was nonzero, choosing arbitrarily if both
25453  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
25454  zero.  zero.
25455    
25456  @kindex a !  @kindex a !
# Line 25140  zero. Line 25458  zero.
25458  @tindex lnot  @tindex lnot
25459  @tindex !  @tindex !
25460  The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}]  The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}]
25461  function is true if @cite{a} is false (zero), or false if @cite{a} is  function is true if @expr{a} is false (zero), or false if @expr{a} is
25462  true (nonzero).  It is left in symbolic form if @cite{a} is not a  true (nonzero).  It is left in symbolic form if @expr{a} is not a
25463  number.  number.
25464    
25465  @kindex a :  @kindex a :
# Line 25157  number. Line 25475  number.
25475  @tindex :  @tindex :
25476  @cindex Arguments, not evaluated  @cindex Arguments, not evaluated
25477  The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}]  The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}]
25478  function is equal to either @cite{b} or @cite{c} if @cite{a} is a nonzero  function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero
25479  number or zero, respectively.  If @cite{a} is not a number, the test is  number or zero, respectively.  If @expr{a} is not a number, the test is
25480  left in symbolic form and neither @cite{b} nor @cite{c} is evaluated in  left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in
25481  any way.  In algebraic formulas, this is one of the few Calc functions  any way.  In algebraic formulas, this is one of the few Calc functions
25482  whose arguments are not automatically evaluated when the function itself  whose arguments are not automatically evaluated when the function itself
25483  is evaluated.  The others are @code{lambda}, @code{quote}, and  is evaluated.  The others are @code{lambda}, @code{quote}, and
# Line 25170  will not work because the @samp{3:4} is Line 25488  will not work because the @samp{3:4} is
25488  as three separate symbols.  Type something like @samp{a ? 3 : 4} or  as three separate symbols.  Type something like @samp{a ? 3 : 4} or
25489  @samp{a?(3):4} instead.  @samp{a?(3):4} instead.
25490    
25491  As a special case, if @cite{a} evaluates to a vector, then both @cite{b}  As a special case, if @expr{a} evaluates to a vector, then both @expr{b}
25492  and @cite{c} are evaluated; the result is a vector of the same length  and @expr{c} are evaluated; the result is a vector of the same length
25493  as @cite{a} whose elements are chosen from corresponding elements of  as @expr{a} whose elements are chosen from corresponding elements of
25494  @cite{b} and @cite{c} according to whether each element of @cite{a}  @expr{b} and @expr{c} according to whether each element of @expr{a}
25495  is zero or nonzero.  Each of @cite{b} and @cite{c} must be either a  is zero or nonzero.  Each of @expr{b} and @expr{c} must be either a
25496  vector of the same length as @cite{a}, or a non-vector which is matched  vector of the same length as @expr{a}, or a non-vector which is matched
25497  with all elements of @cite{a}.  with all elements of @expr{a}.
25498    
25499  @kindex a @{  @kindex a @{
25500  @pindex calc-in-set  @pindex calc-in-set
25501  @tindex in  @tindex in
25502  The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if  The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if
25503  the number @cite{a} is in the set of numbers represented by @cite{b}.  the number @expr{a} is in the set of numbers represented by @expr{b}.
25504  If @cite{b} is an interval form, @cite{a} must be one of the values  If @expr{b} is an interval form, @expr{a} must be one of the values
25505  encompassed by the interval.  If @cite{b} is a vector, @cite{a} must be  encompassed by the interval.  If @expr{b} is a vector, @expr{a} must be
25506  equal to one of the elements of the vector.  (If any vector elements are  equal to one of the elements of the vector.  (If any vector elements are
25507  intervals, @cite{a} must be in any of the intervals.)  If @cite{b} is a  intervals, @expr{a} must be in any of the intervals.)  If @expr{b} is a
25508  plain number, @cite{a} must be numerically equal to @cite{b}.  plain number, @expr{a} must be numerically equal to @expr{b}.
25509  @xref{Set Operations}, for a group of commands that manipulate sets  @xref{Set Operations}, for a group of commands that manipulate sets
25510  of this sort.  of this sort.
25511    
# Line 25196  of this sort. Line 25514  of this sort.
25514  @end ignore  @end ignore
25515  @tindex typeof  @tindex typeof
25516  The @samp{typeof(a)} function produces an integer or variable which  The @samp{typeof(a)} function produces an integer or variable which
25517  characterizes @cite{a}.  If @cite{a} is a number, vector, or variable,  characterizes @expr{a}.  If @expr{a} is a number, vector, or variable,
25518  the result will be one of the following numbers:  the result will be one of the following numbers:
25519    
25520  @example  @example
# Line 25217  the result will be one of the following Line 25535  the result will be one of the following
25535  102  Matrix  102  Matrix
25536  @end example  @end example
25537    
25538  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
25539  represents the name of the top-level function call.  represents the name of the top-level function call.
25540    
25541  @ignore  @ignore
# Line 25232  represents the name of the top-level fun Line 25550  represents the name of the top-level fun
25550  @starindex  @starindex
25551  @end ignore  @end ignore
25552  @tindex constant  @tindex constant
25553  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.
25554  The @samp{real(a)} function  The @samp{real(a)} function
25555  is true if @cite{a} is a real number, either integer, fraction, or  is true if @expr{a} is a real number, either integer, fraction, or
25556  float.  The @samp{constant(a)} function returns true if @cite{a} is  float.  The @samp{constant(a)} function returns true if @expr{a} is
25557  any of the objects for which @code{typeof} would produce an integer  any of the objects for which @code{typeof} would produce an integer
25558  code result except for variables, and provided that the components of  code result except for variables, and provided that the components of
25559  an object like a vector or error form are themselves constant.  an object like a vector or error form are themselves constant.
25560  Note that infinities do not satisfy any of these tests, nor do  Note that infinities do not satisfy any of these tests, nor do
25561  special constants like @code{pi} and @code{e}.@refill  special constants like @code{pi} and @code{e}.
25562    
25563  @xref{Declarations}, for a set of similar functions that recognize  @xref{Declarations}, for a set of similar functions that recognize
25564  formulas as well as actual numbers.  For example, @samp{dint(floor(x))}  formulas as well as actual numbers.  For example, @samp{dint(floor(x))}
# Line 25253  literally an integer constant. Line 25571  literally an integer constant.
25571  @end ignore  @end ignore
25572  @tindex refers  @tindex refers
25573  The @samp{refers(a,b)} function is true if the variable (or sub-expression)  The @samp{refers(a,b)} function is true if the variable (or sub-expression)
25574  @cite{b} appears in @cite{a}, or false otherwise.  Unlike the other  @expr{b} appears in @expr{a}, or false otherwise.  Unlike the other
25575  tests described here, this function returns a definite ``no'' answer  tests described here, this function returns a definite ``no'' answer
25576  even if its arguments are still in symbolic form.  The only case where  even if its arguments are still in symbolic form.  The only case where
25577  @code{refers} will be left unevaluated is if @cite{a} is a plain  @code{refers} will be left unevaluated is if @expr{a} is a plain
25578  variable (different from @cite{b}).  variable (different from @expr{b}).
25579    
25580  @ignore  @ignore
25581  @starindex  @starindex
25582  @end ignore  @end ignore
25583  @tindex negative  @tindex negative
25584  The @samp{negative(a)} function returns true if @cite{a} ``looks'' negative,  The @samp{negative(a)} function returns true if @expr{a} ``looks'' negative,
25585  because it is a negative number, because it is of the form @cite{-x},  because it is a negative number, because it is of the form @expr{-x},
25586  or because it is a product or quotient with a term that looks negative.  or because it is a product or quotient with a term that looks negative.
25587  This is most useful in rewrite rules.  Beware that @samp{negative(a)}  This is most useful in rewrite rules.  Beware that @samp{negative(a)}
25588  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
25589  be stored in a formula if the default simplifications are turned off  be stored in a formula if the default simplifications are turned off
25590  first with @kbd{m O} (or if it appears in an unevaluated context such  first with @kbd{m O} (or if it appears in an unevaluated context such
25591  as a rewrite rule condition).  as a rewrite rule condition).
# Line 25276  as a rewrite rule condition). Line 25594  as a rewrite rule condition).
25594  @starindex  @starindex
25595  @end ignore  @end ignore
25596  @tindex variable  @tindex variable
25597  The @samp{variable(a)} function is true if @cite{a} is a variable,  The @samp{variable(a)} function is true if @expr{a} is a variable,
25598  or false if not.  If @cite{a} is a function call, this test is left  or false if not.  If @expr{a} is a function call, this test is left
25599  in symbolic form.  Built-in variables like @code{pi} and @code{inf}  in symbolic form.  Built-in variables like @code{pi} and @code{inf}
25600  are considered variables like any others by this test.  are considered variables like any others by this test.
25601    
# Line 25285  are considered variables like any others Line 25603  are considered variables like any others
25603  @starindex  @starindex
25604  @end ignore  @end ignore
25605  @tindex nonvar  @tindex nonvar
25606  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.
25607  If its argument is a variable it is left unsimplified; it never  If its argument is a variable it is left unsimplified; it never
25608  actually returns zero.  However, since Calc's condition-testing  actually returns zero.  However, since Calc's condition-testing
25609  commands consider ``false'' anything not provably true, this is  commands consider ``false'' anything not provably true, this is
# Line 25310  often good enough. Line 25628  often good enough.
25628  @cindex Linearity testing  @cindex Linearity testing
25629  The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt}  The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt}
25630  check if an expression is ``linear,'' i.e., can be written in the form  check if an expression is ``linear,'' i.e., can be written in the form
25631  @cite{a + b x} for some constants @cite{a} and @cite{b}, and some  @expr{a + b x} for some constants @expr{a} and @expr{b}, and some
25632  variable or subformula @cite{x}.  The function @samp{islin(f,x)} checks  variable or subformula @expr{x}.  The function @samp{islin(f,x)} checks
25633  if formula @cite{f} is linear in @cite{x}, returning 1 if so.  For  if formula @expr{f} is linear in @expr{x}, returning 1 if so.  For
25634  example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and  example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and
25635  @samp{islin(x y / 3 - 2, x)} all return 1.  The @samp{lin(f,x)} function  @samp{islin(x y / 3 - 2, x)} all return 1.  The @samp{lin(f,x)} function
25636  is similar, except that instead of returning 1 it returns the vector  is similar, except that instead of returning 1 it returns the vector
25637  @cite{[a, b, x]}.  For the above examples, this vector would be  @expr{[a, b, x]}.  For the above examples, this vector would be
25638  @cite{[0, 1, x]}, @cite{[0, -1, x]}, @cite{[3, 0, x]}, and  @expr{[0, 1, x]}, @expr{[0, -1, x]}, @expr{[3, 0, x]}, and
25639  @cite{[-2, y/3, x]}, respectively.  Both @code{lin} and @code{islin}  @expr{[-2, y/3, x]}, respectively.  Both @code{lin} and @code{islin}
25640  generally remain unevaluated for expressions which are not linear,  generally remain unevaluated for expressions which are not linear,
25641  e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}.  The second  e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}.  The second
25642  argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))}  argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))}
# Line 25326  returns true. Line 25644  returns true.
25644    
25645  The @code{linnt} and @code{islinnt} functions perform a similar check,  The @code{linnt} and @code{islinnt} functions perform a similar check,
25646  but require a ``non-trivial'' linear form, which means that the  but require a ``non-trivial'' linear form, which means that the
25647  @cite{b} coefficient must be non-zero.  For example, @samp{lin(2,x)}  @expr{b} coefficient must be non-zero.  For example, @samp{lin(2,x)}
25648  returns @cite{[2, 0, x]} and @samp{lin(y,x)} returns @cite{[y, 0, x]},  returns @expr{[2, 0, x]} and @samp{lin(y,x)} returns @expr{[y, 0, x]},
25649  but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated  but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated
25650  (in other words, these formulas are considered to be only ``trivially''  (in other words, these formulas are considered to be only ``trivially''
25651  linear in @cite{x}).  linear in @expr{x}).
25652    
25653  All four linearity-testing functions allow you to omit the second  All four linearity-testing functions allow you to omit the second
25654  argument, in which case the input may be linear in any non-constant  argument, in which case the input may be linear in any non-constant
25655  formula.  Here, the @cite{a=0}, @cite{b=1} case is also considered  formula.  Here, the @expr{a=0}, @expr{b=1} case is also considered
25656  trivial, and only constant values for @cite{a} and @cite{b} are  trivial, and only constant values for @expr{a} and @expr{b} are
25657  recognized.  Thus, @samp{lin(2 x y)} returns @cite{[0, 2, x y]},  recognized.  Thus, @samp{lin(2 x y)} returns @expr{[0, 2, x y]},
25658  @samp{lin(2 - x y)} returns @cite{[2, -1, x y]}, and @samp{lin(x y)}  @samp{lin(2 - x y)} returns @expr{[2, -1, x y]}, and @samp{lin(x y)}
25659  returns @cite{[0, 1, x y]}.  The @code{linnt} function would allow the  returns @expr{[0, 1, x y]}.  The @code{linnt} function would allow the
25660  first two cases but not the third.  Also, neither @code{lin} nor  first two cases but not the third.  Also, neither @code{lin} nor
25661  @code{linnt} accept plain constants as linear in the one-argument  @code{linnt} accept plain constants as linear in the one-argument
25662  case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.  case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
# Line 25347  case: @samp{islin(2,x)} is true, but @sa Line 25665  case: @samp{islin(2,x)} is true, but @sa
25665  @starindex  @starindex
25666  @end ignore  @end ignore
25667  @tindex istrue  @tindex istrue
25668  The @samp{istrue(a)} function returns 1 if @cite{a} is a nonzero  The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero
25669  number or provably nonzero formula, or 0 if @cite{a} is anything else.  number or provably nonzero formula, or 0 if @expr{a} is anything else.
25670  Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is  Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is
25671  used to make sure they are not evaluated prematurely.  (Note that  used to make sure they are not evaluated prematurely.  (Note that
25672  declarations are used when deciding whether a formula is true;  declarations are used when deciding whether a formula is true;
# Line 25408  This operator is equivalent to the funct Line 25726  This operator is equivalent to the funct
25726  The @code{assign} function is undefined by itself in Calc, so an  The @code{assign} function is undefined by itself in Calc, so an
25727  assignment formula such as a rewrite rule will be left alone by ordinary  assignment formula such as a rewrite rule will be left alone by ordinary
25728  Calc commands.  But certain commands, like the rewrite system, interpret  Calc commands.  But certain commands, like the rewrite system, interpret
25729  assignments in special ways.@refill  assignments in special ways.
25730    
25731  For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace  For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace
25732  every occurrence of the sine of something, squared, with one minus the  every occurrence of the sine of something, squared, with one minus the
# Line 25451  invoke them by giving the variable name. Line 25769  invoke them by giving the variable name.
25769  (@code{calc-edit-variable}) command is an easy way to create or edit a  (@code{calc-edit-variable}) command is an easy way to create or edit a
25770  rule set stored in a variable.  You may also wish to use @kbd{s p}  rule set stored in a variable.  You may also wish to use @kbd{s p}
25771  (@code{calc-permanent-variable}) to save your rules permanently;  (@code{calc-permanent-variable}) to save your rules permanently;
25772  @pxref{Operations on Variables}.@refill  @pxref{Operations on Variables}.
25773    
25774  Rewrite rules are compiled into a special internal form for faster  Rewrite rules are compiled into a special internal form for faster
25775  matching.  If you enter a rule set directly it must be recompiled  matching.  If you enter a rule set directly it must be recompiled
# Line 25468  vector of two rules, the use of this not Line 25786  vector of two rules, the use of this not
25786  @subsection Basic Rewrite Rules  @subsection Basic Rewrite Rules
25787    
25788  @noindent  @noindent
25789  To match a particular formula @cite{x} with a particular rewrite rule  To match a particular formula @expr{x} with a particular rewrite rule
25790  @samp{@var{old} := @var{new}}, Calc compares the structure of @cite{x} with  @samp{@var{old} := @var{new}}, Calc compares the structure of @expr{x} with
25791  the structure of @var{old}.  Variables that appear in @var{old} are  the structure of @var{old}.  Variables that appear in @var{old} are
25792  treated as @dfn{meta-variables}; the corresponding positions in @cite{x}  treated as @dfn{meta-variables}; the corresponding positions in @expr{x}
25793  may contain any sub-formulas.  For example, the pattern @samp{f(x,y)}  may contain any sub-formulas.  For example, the pattern @samp{f(x,y)}
25794  would match the expression @samp{f(12, a+1)} with the meta-variable  would match the expression @samp{f(12, a+1)} with the meta-variable
25795  @samp{x} corresponding to 12 and with @samp{y} corresponding to  @samp{x} corresponding to 12 and with @samp{y} corresponding to
# Line 25481  that will make the pattern match these e Line 25799  that will make the pattern match these e
25799  the pattern is a single meta-variable, it will match any expression.  the pattern is a single meta-variable, it will match any expression.
25800    
25801  If a given meta-variable appears more than once in @var{old}, the  If a given meta-variable appears more than once in @var{old}, the
25802  corresponding sub-formulas of @cite{x} must be identical.  Thus  corresponding sub-formulas of @expr{x} must be identical.  Thus
25803  the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and  the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and
25804  @samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}.  @samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}.
25805  (@xref{Conditional Rewrite Rules}, for a way to match the latter.)  (@xref{Conditional Rewrite Rules}, for a way to match the latter.)
# Line 25525  number or any other object known to be n Line 25843  number or any other object known to be n
25843  the rule is accepted.  If the result is zero or if it is a symbolic  the rule is accepted.  If the result is zero or if it is a symbolic
25844  formula that is not known to be nonzero, the rule is rejected.  formula that is not known to be nonzero, the rule is rejected.
25845  @xref{Logical Operations}, for a number of functions that return  @xref{Logical Operations}, for a number of functions that return
25846  1 or 0 according to the results of various tests.@refill  1 or 0 according to the results of various tests.
25847    
25848  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}
25849  is replaced by a positive or nonpositive number, respectively (or if  is replaced by a positive or nonpositive number, respectively (or if
25850  @cite{n} has been declared to be positive or nonpositive).  Thus,  @expr{n} has been declared to be positive or nonpositive).  Thus,
25851  the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to  the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to
25852  @samp{f(0, 4)} but not to @samp{f(-3, 2)} or @samp{f(12, a+1)}  @samp{f(0, 4)} but not to @samp{f(-3, 2)} or @samp{f(12, a+1)}
25853  (assuming no outstanding declarations for @cite{a}).  In the case of  (assuming no outstanding declarations for @expr{a}).  In the case of
25854  @samp{f(-3, 2)}, the condition can be shown not to be satisfied; in  @samp{f(-3, 2)}, the condition can be shown not to be satisfied; in
25855  the case of @samp{f(12, a+1)}, the condition merely cannot be shown  the case of @samp{f(12, a+1)}, the condition merely cannot be shown
25856  to be satisfied, but that is enough to reject the rule.  to be satisfied, but that is enough to reject the rule.
# Line 25562  decides when it is best to test each con Line 25880  decides when it is best to test each con
25880  matched.  matched.
25881    
25882  Certain conditions are handled as special cases by the rewrite rule  Certain conditions are handled as special cases by the rewrite rule
25883  system and are tested very efficiently:  Where @cite{x} is any  system and are tested very efficiently:  Where @expr{x} is any
25884  meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)},  meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)},
25885  @samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @cite{y}  @samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @expr{y}
25886  is either a constant or another meta-variable and @samp{>=} may be  is either a constant or another meta-variable and @samp{>=} may be
25887  replaced by any of the six relational operators, and @samp{x % a = b}  replaced by any of the six relational operators, and @samp{x % a = b}
25888  where @cite{a} and @cite{b} are constants.  Other conditions, like  where @expr{a} and @expr{b} are constants.  Other conditions, like
25889  @samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check  @samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check
25890  since Calc must bring the whole evaluator and simplifier into play.  since Calc must bring the whole evaluator and simplifier into play.
25891    
# Line 25776  are linear in @samp{x}.  You can also us Line 26094  are linear in @samp{x}.  You can also us
26094  functions with rewrite conditions to test for this; @pxref{Logical  functions with rewrite conditions to test for this; @pxref{Logical
26095  Operations}.  These functions are not as convenient to use in rewrite  Operations}.  These functions are not as convenient to use in rewrite
26096  rules, but they recognize more kinds of formulas as linear:  rules, but they recognize more kinds of formulas as linear:
26097  @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},
26098  but it will not match the above pattern because that pattern calls  but it will not match the above pattern because that pattern calls
26099  for a multiplication, not a division.  for a multiplication, not a division.
26100    
# Line 25796  opt(a) sin(x)^2 + opt(a) cos(x)^2  :=  a Line 26114  opt(a) sin(x)^2 + opt(a) cos(x)^2  :=  a
26114  @end example  @end example
26115    
26116  Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2}  Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2}
26117  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.
26118    
26119  Calc automatically converts a rule like  Calc automatically converts a rule like
26120    
# Line 25944  work in the righthand side of a rule. Line 26262  work in the righthand side of a rule.
26262  @end ignore  @end ignore
26263  @tindex import  @tindex import
26264  One kind of marker, @samp{import(x)}, takes the place of a whole  One kind of marker, @samp{import(x)}, takes the place of a whole
26265  rule.  Here @cite{x} is the name of a variable containing another  rule.  Here @expr{x} is the name of a variable containing another
26266  rule set; those rules are ``spliced into'' the rule set that  rule set; those rules are ``spliced into'' the rule set that
26267  imports them.  For example, if @samp{[f(a+b) := f(a) + f(b),  imports them.  For example, if @samp{[f(a+b) := f(a) + f(b),
26268  f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},  f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},
26269  then the rule set @samp{[f(0) := 0, import(linearF)]} will apply  then the rule set @samp{[f(0) := 0, import(linearF)]} will apply
26270  all three rules.  It is possible to modify the imported rules  all three rules.  It is possible to modify the imported rules
26271  slightly:  @samp{import(x, v1, x1, v2, x2, @dots{})} imports  slightly:  @samp{import(x, v1, x1, v2, x2, @dots{})} imports
26272  the rule set @cite{x} with all occurrences of @c{$v_1$}  the rule set @expr{x} with all occurrences of
26273  @cite{v1}, as either  @texline @tmath{v_1},
26274  a variable name or a function name, replaced with @c{$x_1$}  @infoline @expr{v1},
26275  @cite{x1} and  as either a variable name or a function name, replaced with
26276  so on.  (If @c{$v_1$}  @texline @tmath{x_1}
26277  @cite{v1} is used as a function name, then @c{$x_1$}  @infoline @expr{x1}
26278  @cite{x1}  and so on.  (If
26279    @texline @tmath{v_1}
26280    @infoline @expr{v1}
26281    is used as a function name, then
26282    @texline @tmath{x_1}
26283    @infoline @expr{x1}
26284  must be either a function name itself or a @w{@samp{< >}} nameless  must be either a function name itself or a @w{@samp{< >}} nameless
26285  function; @pxref{Specifying Operators}.)  For example, @samp{[g(0) := 0,  function; @pxref{Specifying Operators}.)  For example, @samp{[g(0) := 0,
26286  import(linearF, f, g)]} applies the linearity rules to the function  import(linearF, f, g)]} applies the linearity rules to the function
# Line 25972  The special functions allowed in pattern Line 26295  The special functions allowed in pattern
26295  @starindex  @starindex
26296  @end ignore  @end ignore
26297  @tindex quote  @tindex quote
26298  This pattern matches exactly @cite{x}; variable names in @cite{x} are  This pattern matches exactly @expr{x}; variable names in @expr{x} are
26299  not interpreted as meta-variables.  The only flexibility is that  not interpreted as meta-variables.  The only flexibility is that
26300  numbers are compared for numeric equality, so that the pattern  numbers are compared for numeric equality, so that the pattern
26301  @samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}.  @samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}.
# Line 25986  as a result in this case.) Line 26309  as a result in this case.)
26309  @starindex  @starindex
26310  @end ignore  @end ignore
26311  @tindex plain  @tindex plain
26312  Here @cite{x} must be a function call @samp{f(x1,x2,@dots{})}.  This  Here @expr{x} must be a function call @samp{f(x1,x2,@dots{})}.  This
26313  pattern matches a call to function @cite{f} with the specified  pattern matches a call to function @expr{f} with the specified
26314  argument patterns.  No special knowledge of the properties of the  argument patterns.  No special knowledge of the properties of the
26315  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
26316  associative.  Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}}  associative.  Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}}
26317  are treated as patterns.  If you wish them to be treated ``plainly''  are treated as patterns.  If you wish them to be treated ``plainly''
26318  as well, you must enclose them with more @code{plain} markers:  as well, you must enclose them with more @code{plain} markers:
# Line 26000  as well, you must enclose them with more Line 26323  as well, you must enclose them with more
26323  @starindex  @starindex
26324  @end ignore  @end ignore
26325  @tindex opt  @tindex opt
26326  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
26327  argument to a function or an element of a vector; it specifies that  argument to a function or an element of a vector; it specifies that
26328  the argument or element is optional.  the argument or element is optional.
26329  As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||},  As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||},
26330  or as the second argument to @samp{/} or @samp{^}, the value @var{def}  or as the second argument to @samp{/} or @samp{^}, the value @var{def}
26331  may be omitted.  The pattern @samp{x + opt(y)} matches a sum by  may be omitted.  The pattern @samp{x + opt(y)} matches a sum by
26332  binding one summand to @cite{x} and the other to @cite{y}, and it  binding one summand to @expr{x} and the other to @expr{y}, and it
26333  matches anything else by binding the whole expression to @cite{x} and  matches anything else by binding the whole expression to @expr{x} and
26334  zero to @cite{y}.  The other operators above work similarly.@refill  zero to @expr{y}.  The other operators above work similarly.
26335    
26336  For general miscellaneous functions, the default value @code{def}  For general miscellaneous functions, the default value @code{def}
26337  must be specified.  Optional arguments are dropped starting with  must be specified.  Optional arguments are dropped starting with
26338  the rightmost one during matching.  For example, the pattern  the rightmost one during matching.  For example, the pattern
26339  @samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)},  @samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)},
26340  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
26341  supplied in this example for the omitted arguments.  Note that  supplied in this example for the omitted arguments.  Note that
26342  the literal variable @cite{b} will be the default in the latter  the literal variable @expr{b} will be the default in the latter
26343  case, @emph{not} the value that matched the meta-variable @cite{b}.  case, @emph{not} the value that matched the meta-variable @expr{b}.
26344  In other words, the default @var{def} is effectively quoted.  In other words, the default @var{def} is effectively quoted.
26345    
26346  @item condition(x,c)  @item condition(x,c)
# Line 26026  In other words, the default @var{def} is Line 26349  In other words, the default @var{def} is
26349  @end ignore  @end ignore
26350  @tindex condition  @tindex condition
26351  @tindex ::  @tindex ::
26352  This matches the pattern @cite{x}, with the attached condition  This matches the pattern @expr{x}, with the attached condition
26353  @cite{c}.  It is the same as @samp{x :: c}.  @expr{c}.  It is the same as @samp{x :: c}.
26354    
26355  @item pand(x,y)  @item pand(x,y)
26356  @ignore  @ignore
# Line 26035  This matches the pattern @cite{x}, with Line 26358  This matches the pattern @cite{x}, with
26358  @end ignore  @end ignore
26359  @tindex pand  @tindex pand
26360  @tindex &&&  @tindex &&&
26361  This matches anything that matches both pattern @cite{x} and  This matches anything that matches both pattern @expr{x} and
26362  pattern @cite{y}.  It is the same as @samp{x &&& y}.  pattern @expr{y}.  It is the same as @samp{x &&& y}.
26363  @pxref{Composing Patterns in Rewrite Rules}.  @pxref{Composing Patterns in Rewrite Rules}.
26364    
26365  @item por(x,y)  @item por(x,y)
# Line 26045  pattern @cite{y}.  It is the same as @sa Line 26368  pattern @cite{y}.  It is the same as @sa
26368  @end ignore  @end ignore
26369  @tindex por  @tindex por
26370  @tindex |||  @tindex |||
26371  This matches anything that matches either pattern @cite{x} or  This matches anything that matches either pattern @expr{x} or
26372  pattern @cite{y}.  It is the same as @w{@samp{x ||| y}}.  pattern @expr{y}.  It is the same as @w{@samp{x ||| y}}.
26373    
26374  @item pnot(x)  @item pnot(x)
26375  @ignore  @ignore
# Line 26054  pattern @cite{y}.  It is the same as @w{ Line 26377  pattern @cite{y}.  It is the same as @w{
26377  @end ignore  @end ignore
26378  @tindex pnot  @tindex pnot
26379  @tindex !!!  @tindex !!!
26380  This matches anything that does not match pattern @cite{x}.  This matches anything that does not match pattern @expr{x}.
26381  It is the same as @samp{!!! x}.  It is the same as @samp{!!! x}.
26382    
26383  @item cons(h,t)  @item cons(h,t)
# Line 26063  It is the same as @samp{!!! x}. Line 26386  It is the same as @samp{!!! x}.
26386  @end ignore  @end ignore
26387  @tindex cons (rewrites)  @tindex cons (rewrites)
26388  This matches any vector of one or more elements.  The first  This matches any vector of one or more elements.  The first
26389  element is matched to @cite{h}; a vector of the remaining  element is matched to @expr{h}; a vector of the remaining
26390  elements is matched to @cite{t}.  Note that vectors of fixed  elements is matched to @expr{t}.  Note that vectors of fixed
26391  length can also be matched as actual vectors:  The rule  length can also be matched as actual vectors:  The rule
26392  @samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent  @samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent
26393  to the rule @samp{[a,b] := [a+b]}.  to the rule @samp{[a,b] := [a+b]}.
# Line 26075  to the rule @samp{[a,b] := [a+b]}. Line 26398  to the rule @samp{[a,b] := [a+b]}.
26398  @end ignore  @end ignore
26399  @tindex rcons (rewrites)  @tindex rcons (rewrites)
26400  This is like @code{cons}, except that the @emph{last} element  This is like @code{cons}, except that the @emph{last} element
26401  is matched to @cite{h}, with the remaining elements matched  is matched to @expr{h}, with the remaining elements matched
26402  to @cite{t}.  to @expr{t}.
26403    
26404  @item apply(f,args)  @item apply(f,args)
26405  @ignore  @ignore
# Line 26084  to @cite{t}. Line 26407  to @cite{t}.
26407  @end ignore  @end ignore
26408  @tindex apply (rewrites)  @tindex apply (rewrites)
26409  This matches any function call.  The name of the function, in  This matches any function call.  The name of the function, in
26410  the form of a variable, is matched to @cite{f}.  The arguments  the form of a variable, is matched to @expr{f}.  The arguments
26411  of the function, as a vector of zero or more objects, are  of the function, as a vector of zero or more objects, are
26412  matched to @samp{args}.  Constants, variables, and vectors  matched to @samp{args}.  Constants, variables, and vectors
26413  do @emph{not} match an @code{apply} pattern.  For example,  do @emph{not} match an @code{apply} pattern.  For example,
# Line 26152  protecting rules from evaluation.) Line 26475  protecting rules from evaluation.)
26475    
26476  @item plain(x)  @item plain(x)
26477  Special properties of and simplifications for the function call  Special properties of and simplifications for the function call
26478  @cite{x} are not used.  One interesting case where @code{plain}  @expr{x} are not used.  One interesting case where @code{plain}
26479  is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a  is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a
26480  shorthand notation for the @code{quote} function.  This rule will  shorthand notation for the @code{quote} function.  This rule will
26481  not work as shown; instead of replacing @samp{q(foo)} with  not work as shown; instead of replacing @samp{q(foo)} with
# Line 26160  not work as shown; instead of replacing Line 26483  not work as shown; instead of replacing
26483  rule would be @samp{q(x) := plain(quote(x))}.  rule would be @samp{q(x) := plain(quote(x))}.
26484    
26485  @item cons(h,t)  @item cons(h,t)
26486  Where @cite{t} is a vector, this is converted into an expanded  Where @expr{t} is a vector, this is converted into an expanded
26487  vector during rewrite processing.  Note that @code{cons} is a regular  vector during rewrite processing.  Note that @code{cons} is a regular
26488  Calc function which normally does this anyway; the only way @code{cons}  Calc function which normally does this anyway; the only way @code{cons}
26489  is treated specially by rewrites is that @code{cons} on the righthand  is treated specially by rewrites is that @code{cons} on the righthand
# Line 26168  side of a rule will be evaluated even if Line 26491  side of a rule will be evaluated even if
26491  have been turned off.  have been turned off.
26492    
26493  @item rcons(t,h)  @item rcons(t,h)
26494  Analogous to @code{cons} except putting @cite{h} at the @emph{end} of  Analogous to @code{cons} except putting @expr{h} at the @emph{end} of
26495  the vector @cite{t}.  the vector @expr{t}.
26496    
26497  @item apply(f,args)  @item apply(f,args)
26498  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
26499  is converted to a function call.  Once again, note that @code{apply}  is converted to a function call.  Once again, note that @code{apply}
26500  is also a regular Calc function.  is also a regular Calc function.
26501    
# Line 26181  is also a regular Calc function. Line 26504  is also a regular Calc function.
26504  @starindex  @starindex
26505  @end ignore  @end ignore
26506  @tindex eval  @tindex eval
26507  The formula @cite{x} is handled in the usual way, then the  The formula @expr{x} is handled in the usual way, then the
26508  default simplifications are applied to it even if they have  default simplifications are applied to it even if they have
26509  been turned off normally.  This allows you to treat any function  been turned off normally.  This allows you to treat any function
26510  similarly to the way @code{cons} and @code{apply} are always  similarly to the way @code{cons} and @code{apply} are always
# Line 26194  whereas @samp{eval(cons(2+3, []))} will Line 26517  whereas @samp{eval(cons(2+3, []))} will
26517  @starindex  @starindex
26518  @end ignore  @end ignore
26519  @tindex evalsimp  @tindex evalsimp
26520  The formula @cite{x} has meta-variables substituted in the usual  The formula @expr{x} has meta-variables substituted in the usual
26521  way, then algebraically simplified as if by the @kbd{a s} command.  way, then algebraically simplified as if by the @kbd{a s} command.
26522    
26523  @item evalextsimp(x)  @item evalextsimp(x)
# Line 26202  way, then algebraically simplified as if Line 26525  way, then algebraically simplified as if
26525  @starindex  @starindex
26526  @end ignore  @end ignore
26527  @tindex evalextsimp  @tindex evalextsimp
26528  The formula @cite{x} has meta-variables substituted in the normal  The formula @expr{x} has meta-variables substituted in the normal
26529  way, then ``extendedly'' simplified as if by the @kbd{a e} command.  way, then ``extendedly'' simplified as if by the @kbd{a e} command.
26530    
26531  @item select(x)  @item select(x)
# Line 26217  There are also some special functions yo Line 26540  There are also some special functions yo
26540  @starindex  @starindex
26541  @end ignore  @end ignore
26542  @tindex let  @tindex let
26543  The expression @cite{x} is evaluated with meta-variables substituted.  The expression @expr{x} is evaluated with meta-variables substituted.
26544  The @kbd{a s} command's simplifications are @emph{not} applied by  The @kbd{a s} command's simplifications are @emph{not} applied by
26545  default, but @cite{x} can include calls to @code{evalsimp} or  default, but @expr{x} can include calls to @code{evalsimp} or
26546  @code{evalextsimp} as described above to invoke higher levels  @code{evalextsimp} as described above to invoke higher levels
26547  of simplification.  The  of simplification.  The
26548  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
26549  usual, if this meta-variable has already been matched to something  usual, if this meta-variable has already been matched to something
26550  else the two values must be equal; if the meta-variable is new then  else the two values must be equal; if the meta-variable is new then
26551  it is bound to the result of the expression.  This variable can then  it is bound to the result of the expression.  This variable can then
26552  appear in later conditions, and on the righthand side of the rule.  appear in later conditions, and on the righthand side of the rule.
26553  In fact, @cite{v} may be any pattern in which case the result of  In fact, @expr{v} may be any pattern in which case the result of
26554  evaluating @cite{x} is matched to that pattern, binding any  evaluating @expr{x} is matched to that pattern, binding any
26555  meta-variables that appear in that pattern.  Note that @code{let}  meta-variables that appear in that pattern.  Note that @code{let}
26556  can only appear by itself as a condition, or as one term of an  can only appear by itself as a condition, or as one term of an
26557  @samp{&&} which is a whole condition:  It cannot be inside  @samp{&&} which is a whole condition:  It cannot be inside
26558  an @samp{||} term or otherwise buried.@refill  an @samp{||} term or otherwise buried.
26559    
26560  The alternate, equivalent form @samp{let(v, x)} is also recognized.  The alternate, equivalent form @samp{let(v, x)} is also recognized.
26561  Note that the use of @samp{:=} by @code{let}, while still being  Note that the use of @samp{:=} by @code{let}, while still being
# Line 26249  to express this rule that didn't have to Line 26572  to express this rule that didn't have to
26572  Note that, because the meta-variable @samp{ia} is otherwise unbound  Note that, because the meta-variable @samp{ia} is otherwise unbound
26573  in this rule, the @code{let} condition itself always ``succeeds''  in this rule, the @code{let} condition itself always ``succeeds''
26574  because no matter what @samp{1/a} evaluates to, it can successfully  because no matter what @samp{1/a} evaluates to, it can successfully
26575  be bound to @code{ia}.@refill  be bound to @code{ia}.
26576    
26577  Here's another example, for integrating cosines of linear  Here's another example, for integrating cosines of linear
26578  terms:  @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}.  terms:  @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}.
# Line 26260  so this @code{let} both verifies that @c Line 26583  so this @code{let} both verifies that @c
26583  the coefficients @code{a} and @code{b} for use elsewhere in the rule.  the coefficients @code{a} and @code{b} for use elsewhere in the rule.
26584  (It would have been possible to use @samp{sin(a x + b)/b} for the  (It would have been possible to use @samp{sin(a x + b)/b} for the
26585  righthand side instead, but using @samp{sin(y)/b} avoids gratuitous  righthand side instead, but using @samp{sin(y)/b} avoids gratuitous
26586  rearrangement of the argument of the sine.)@refill  rearrangement of the argument of the sine.)
26587    
26588  @ignore  @ignore
26589  @starindex  @starindex
# Line 26321  be added to the rule set and will contin Line 26644  be added to the rule set and will contin
26644  @starindex  @starindex
26645  @end ignore  @end ignore
26646  @tindex remember  @tindex remember
26647  Remember the match as described above, but only if condition @cite{c}  Remember the match as described above, but only if condition @expr{c}
26648  is true.  For example, @samp{remember(n % 4 = 0)} in the above factorial  is true.  For example, @samp{remember(n % 4 = 0)} in the above factorial
26649  rule remembers only every fourth result.  Note that @samp{remember(1)}  rule remembers only every fourth result.  Note that @samp{remember(1)}
26650  is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.  is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.
# Line 26883  or ran too long'' message. Line 27206  or ran too long'' message.
27206    
27207  Another subtle difference between @code{EvalRules} and regular rewrites  Another subtle difference between @code{EvalRules} and regular rewrites
27208  concerns rules that rewrite a formula into an identical formula.  For  concerns rules that rewrite a formula into an identical formula.  For
27209  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
27210  already an integer.  But in @code{EvalRules} this case is detected only  already an integer.  But in @code{EvalRules} this case is detected only
27211  if the righthand side literally becomes the original formula before any  if the righthand side literally becomes the original formula before any
27212  further simplification.  This means that @samp{f(n) := f(floor(n))} will  further simplification.  This means that @samp{f(n) := f(floor(n))} will
# Line 26927  Finally, another limitation is that Calc Line 27250  Finally, another limitation is that Calc
27250  functions directly rather than going through the default simplifications.  functions directly rather than going through the default simplifications.
27251  When it does this, @code{EvalRules} will not be able to override those  When it does this, @code{EvalRules} will not be able to override those
27252  functions.  For example, when you take the absolute value of the complex  functions.  For example, when you take the absolute value of the complex
27253  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
27254  the multiplication, addition, and square root functions directly rather  the multiplication, addition, and square root functions directly rather
27255  than applying the default simplifications to this formula.  So an  than applying the default simplifications to this formula.  So an
27256  @code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}  @code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}
27257  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
27258  @samp{sqrt(13)} will be left in symbolic form by the built-in square  @samp{sqrt(13)} will be left in symbolic form by the built-in square
27259  root function, your rule will be able to apply.  But if the complex  root function, your rule will be able to apply.  But if the complex
27260  number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated,  number were @expr{(3,4)}, so that @samp{sqrt(25)} must be calculated,
27261  then symbolic mode will not help because @samp{sqrt(25)} can be  then symbolic mode will not help because @samp{sqrt(25)} can be
27262  evaluated exactly to 5.)  evaluated exactly to 5.)
27263    
# Line 27028  Returning to the example of substituting Line 27351  Returning to the example of substituting
27351  finding suitable cases.  Another solution would be to use the rule  finding suitable cases.  Another solution would be to use the rule
27352  @samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification  @samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification
27353  if necessary.  This rule will be the most effective way to do the job,  if necessary.  This rule will be the most effective way to do the job,
27354  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.
27355    
27356  Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.  Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
27357  To make this work with the @w{@kbd{j r}} command so that it can be  To make this work with the @w{@kbd{j r}} command so that it can be
# Line 27036  easily targeted to a particular exponent Line 27359  easily targeted to a particular exponent
27359  you might wish to write the rule as @samp{select(exp(x+y)) :=  you might wish to write the rule as @samp{select(exp(x+y)) :=
27360  select(exp(x) exp(y))}.  The @samp{select} markers will be  select(exp(x) exp(y))}.  The @samp{select} markers will be
27361  ignored by the regular @kbd{a r} command  ignored by the regular @kbd{a r} command
27362  (@pxref{Selections with Rewrite Rules}).@refill  (@pxref{Selections with Rewrite Rules}).
27363    
27364  A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}.  A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}.
27365  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
27366  be made simpler by squaring.  For example, applying this rule to  be made simpler by squaring.  For example, applying this rule to
27367  @samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming  @samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming
27368  Symbolic Mode has been enabled to keep the square root from being  Symbolic Mode has been enabled to keep the square root from being
# Line 27059  the keyboard macro @kbd{' tri($) @key{RE Line 27382  the keyboard macro @kbd{' tri($) @key{RE
27382  @code{tri} to the value on the top of the stack.  @xref{Programming}.  @code{tri} to the value on the top of the stack.  @xref{Programming}.
27383    
27384  @cindex Quaternions  @cindex Quaternions
27385  The following rule set, contributed by @c{Fran\c cois}  The following rule set, contributed by
27386  @asis{Francois} Pinard, implements  @texline Fran\c cois
27387  @dfn{quaternions}, a generalization of the concept of complex numbers.  @infoline Francois
27388  Quaternions have four components, and are here represented by function  Pinard, implements @dfn{quaternions}, a generalization of the concept of
27389  calls @samp{quat(@var{w}, [@var{x}, @var{y}, @var{z}])} with ``real  complex numbers.  Quaternions have four components, and are here
27390  part'' @var{w} and the three ``imaginary'' parts collected into a  represented by function calls @samp{quat(@var{w}, [@var{x}, @var{y},
27391  vector.  Various arithmetical operations on quaternions are supported.  @var{z}])} with ``real part'' @var{w} and the three ``imaginary'' parts
27392  To use these rules, either add them to @code{EvalRules}, or create a  collected into a vector.  Various arithmetical operations on quaternions
27393  command based on @kbd{a r} for simplifying quaternion formulas.  are supported.  To use these rules, either add them to @code{EvalRules},
27394  A convenient way to enter quaternions would be a command defined by  or create a command based on @kbd{a r} for simplifying quaternion
27395  a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}.  formulas.  A convenient way to enter quaternions would be a command
27396    defined by a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $])
27397    @key{RET}}.
27398    
27399  @smallexample  @smallexample
27400  [ quat(w, x, y, z) := quat(w, [x, y, z]),  [ quat(w, x, y, z) := quat(w, [x, y, z]),
# Line 27094  a keyboard macro containing: @kbd{' quat Line 27419  a keyboard macro containing: @kbd{' quat
27419  @end smallexample  @end smallexample
27420    
27421  Quaternions, like matrices, have non-commutative multiplication.  Quaternions, like matrices, have non-commutative multiplication.
27422  In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if  In other words, @expr{q1 * q2 = q2 * q1} is not necessarily true if
27423  @cite{q1} and @cite{q2} are @code{quat} forms.  The @samp{quat*quat}  @expr{q1} and @expr{q2} are @code{quat} forms.  The @samp{quat*quat}
27424  rule above uses @code{plain} to prevent Calc from rearranging the  rule above uses @code{plain} to prevent Calc from rearranging the
27425  product.  It may also be wise to add the line @samp{[quat(), matrix]}  product.  It may also be wise to add the line @samp{[quat(), matrix]}
27426  to the @code{Decls} matrix, to ensure that Calc's other algebraic  to the @code{Decls} matrix, to ensure that Calc's other algebraic
# Line 27142  or a variable whose name is a prefix cha Line 27467  or a variable whose name is a prefix cha
27467  or @samp{u} (for ``micro'') followed by a name in the unit table.  or @samp{u} (for ``micro'') followed by a name in the unit table.
27468  A substantial table of built-in units is provided with Calc;  A substantial table of built-in units is provided with Calc;
27469  @pxref{Predefined Units}.  You can also define your own unit names;  @pxref{Predefined Units}.  You can also define your own unit names;
27470  @pxref{User-Defined Units}.@refill  @pxref{User-Defined Units}.
27471    
27472  Note that if the value part of a units expression is exactly @samp{1},  Note that if the value part of a units expression is exactly @samp{1},
27473  it will be removed by the Calculator's automatic algebra routines:  The  it will be removed by the Calculator's automatic algebra routines:  The
27474  formula @samp{1 mm} is ``simplified'' to @samp{mm}.  This is only a  formula @samp{1 mm} is ``simplified'' to @samp{mm}.  This is only a
27475  display anomaly, however; @samp{mm} will work just fine as a  display anomaly, however; @samp{mm} will work just fine as a
27476  representation of one millimeter.@refill  representation of one millimeter.
27477    
27478  You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working  You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working
27479  with units expressions easier.  Otherwise, you will have to remember  with units expressions easier.  Otherwise, you will have to remember
# Line 27169  to be compatible with another's.  For ex Line 27494  to be compatible with another's.  For ex
27494  simplify to @samp{5.023 m}.  When different but compatible units are  simplify to @samp{5.023 m}.  When different but compatible units are
27495  added, the righthand term's units are converted to match those of the  added, the righthand term's units are converted to match those of the
27496  lefthand term.  @xref{Simplification Modes}, for a way to have this done  lefthand term.  @xref{Simplification Modes}, for a way to have this done
27497  automatically at all times.@refill  automatically at all times.
27498    
27499  Units simplification also handles quotients of two units with the same  Units simplification also handles quotients of two units with the same
27500  dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional  dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional
# Line 27180  powers of unit expressions, as in @samp{ Line 27505  powers of unit expressions, as in @samp{
27505  applied to units expressions, in which case  applied to units expressions, in which case
27506  the operation in question is applied only to the numeric part of the  the operation in question is applied only to the numeric part of the
27507  expression.  Finally, trigonometric functions of quantities with units  expression.  Finally, trigonometric functions of quantities with units
27508  of angle are evaluated, regardless of the current angular mode.@refill  of angle are evaluated, regardless of the current angular mode.
27509    
27510  @kindex u c  @kindex u c
27511  @pindex calc-convert-units  @pindex calc-convert-units
# Line 27261  The @kbd{u t} (@code{calc-convert-temper Line 27586  The @kbd{u t} (@code{calc-convert-temper
27586  absolute temperatures.  The value on the stack must be a simple units  absolute temperatures.  The value on the stack must be a simple units
27587  expression with units of temperature only.  This command would convert  expression with units of temperature only.  This command would convert
27588  @samp{10 degC} to @samp{50 degF}, the equivalent temperature on the  @samp{10 degC} to @samp{50 degF}, the equivalent temperature on the
27589  Fahrenheit scale.@refill  Fahrenheit scale.
27590    
27591  @kindex u r  @kindex u r
27592  @pindex calc-remove-units  @pindex calc-remove-units
# Line 27272  formula at the top of the stack.  The @k Line 27597  formula at the top of the stack.  The @k
27597  (@code{calc-extract-units}) command extracts only the units portion of a  (@code{calc-extract-units}) command extracts only the units portion of a
27598  formula.  These commands essentially replace every term of the formula  formula.  These commands essentially replace every term of the formula
27599  that does or doesn't (respectively) look like a unit name by the  that does or doesn't (respectively) look like a unit name by the
27600  constant 1, then resimplify the formula.@refill  constant 1, then resimplify the formula.
27601    
27602  @kindex u a  @kindex u a
27603  @pindex calc-autorange-units  @pindex calc-autorange-units
# Line 27397  also @code{tpt}, which stands for a prin Line 27722  also @code{tpt}, which stands for a prin
27722    
27723  The unit @code{e} stands for the elementary (electron) unit of charge;  The unit @code{e} stands for the elementary (electron) unit of charge;
27724  because algebra command could mistake this for the special constant  because algebra command could mistake this for the special constant
27725  @cite{e}, Calc provides the alternate unit name @code{ech} which is  @expr{e}, Calc provides the alternate unit name @code{ech} which is
27726  preferable to @code{e}.  preferable to @code{e}.
27727    
27728  The name @code{g} stands for one gram of mass; there is also @code{gf},  The name @code{g} stands for one gram of mass; there is also @code{gf},
27729  one gram of force.  (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.)  one gram of force.  (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.)
27730  Meanwhile, one ``@cite{g}'' of acceleration is denoted @code{ga}.  Meanwhile, one ``@expr{g}'' of acceleration is denoted @code{ga}.
27731    
27732  The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is  The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
27733  a metric ton of @samp{1000 kg}.  a metric ton of @samp{1000 kg}.
# Line 27634  variable.  The other arithmetic stores a Line 27959  variable.  The other arithmetic stores a
27959  and @kbd{s ]} which decrease or increase a variable by one.  and @kbd{s ]} which decrease or increase a variable by one.
27960    
27961  All the arithmetic stores accept the Inverse prefix to reverse the  All the arithmetic stores accept the Inverse prefix to reverse the
27962  order of the operands.  If @cite{v} represents the contents of the  order of the operands.  If @expr{v} represents the contents of the
27963  variable, and @cite{a} is the value drawn from the stack, then regular  variable, and @expr{a} is the value drawn from the stack, then regular
27964  @w{@kbd{s -}} assigns @c{$v \coloneq v - a$}  @w{@kbd{s -}} assigns
27965  @cite{v := v - a}, but @kbd{I s -} assigns  @texline @tmath{v \coloneq v - a},
27966  @c{$v \coloneq a - v$}  @infoline @expr{v := v - a},
27967  @cite{v := a - v}.  While @kbd{I s *} might seem pointless, it is  but @kbd{I s -} assigns
27968    @texline @tmath{v \coloneq a - v}.
27969    @infoline @expr{v := a - v}.  
27970    While @kbd{I s *} might seem pointless, it is
27971  useful if matrix multiplication is involved.  Actually, all the  useful if matrix multiplication is involved.  Actually, all the
27972  arithmetic stores use formulas designed to behave usefully both  arithmetic stores use formulas designed to behave usefully both
27973  forwards and backwards:  forwards and backwards:
# Line 27666  minus-two minus the variable. Line 27994  minus-two minus the variable.
27994    
27995  The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -},  The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -},
27996  etc.  The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous  etc.  The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous
27997  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.
27998    
27999  All arithmetic stores report the new value of the variable in the  All arithmetic stores report the new value of the variable in the
28000  Trail for your information.  They signal an error if the variable  Trail for your information.  They signal an error if the variable
# Line 27692  takes the hyperbolic arcsine of the vari Line 28020  takes the hyperbolic arcsine of the vari
28020    
28021  If the mapping function takes two or more arguments, the additional  If the mapping function takes two or more arguments, the additional
28022  arguments are taken from the stack; the old value of the variable  arguments are taken from the stack; the old value of the variable
28023  is provided as the first argument.  Thus @kbd{s m -} with @cite{a}  is provided as the first argument.  Thus @kbd{s m -} with @expr{a}
28024  on the stack computes @cite{v - a}, just like @kbd{s -}.  With the  on the stack computes @expr{v - a}, just like @kbd{s -}.  With the
28025  Inverse prefix, the variable's original value becomes the @emph{last}  Inverse prefix, the variable's original value becomes the @emph{last}
28026  argument instead of the first.  Thus @kbd{I s m -} is also  argument instead of the first.  Thus @kbd{I s m -} is also
28027  equivalent to @kbd{I s -}.  equivalent to @kbd{I s -}.
# Line 27716  Until you store something in them, varia Line 28044  Until you store something in them, varia
28044  contain no value at all.  If they appear in an algebraic formula they  contain no value at all.  If they appear in an algebraic formula they
28045  will be left alone even if you press @kbd{=} (@code{calc-evaluate}).  will be left alone even if you press @kbd{=} (@code{calc-evaluate}).
28046  The @kbd{s u} (@code{calc-unstore}) command returns a variable to the  The @kbd{s u} (@code{calc-unstore}) command returns a variable to the
28047  void state.@refill  void state.
28048    
28049  The only variables with predefined values are the ``special constants''  The only variables with predefined values are the ``special constants''
28050  @code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}.  You are free  @code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}.  You are free
# Line 27728  special variables @code{inf}, @code{uinf Line 28056  special variables @code{inf}, @code{uinf
28056  normally void).  normally void).
28057    
28058  Note that @code{var-pi} doesn't actually have 3.14159265359 stored  Note that @code{var-pi} doesn't actually have 3.14159265359 stored
28059  in it, but rather a special magic value that evaluates to @c{$\pi$}  in it, but rather a special magic value that evaluates to @cpi{}
 @cite{pi}  
28060  at the current precision.  Likewise @code{var-e}, @code{var-i}, and  at the current precision.  Likewise @code{var-e}, @code{var-i}, and
28061  @code{var-phi} evaluate according to the current precision or polar mode.  @code{var-phi} evaluate according to the current precision or polar mode.
28062  If you recall a value from @code{pi} and store it back, this magic  If you recall a value from @code{pi} and store it back, this magic
# Line 27913  and @code{PlotRejects}; Line 28240  and @code{PlotRejects};
28240  @code{FitRules}, @code{DistribRules}, and other built-in rewrite  @code{FitRules}, @code{DistribRules}, and other built-in rewrite
28241  rules; and @code{PlotData@var{n}} variables generated  rules; and @code{PlotData@var{n}} variables generated
28242  by the graphics commands.  (You can still save these variables by  by the graphics commands.  (You can still save these variables by
28243  explicitly naming them in an @kbd{s p} command.)@refill  explicitly naming them in an @kbd{s p} command.)
28244    
28245  @kindex s i  @kindex s i
28246  @pindex calc-insert-variables  @pindex calc-insert-variables
# Line 27936  stores in a more human-readable format.) Line 28263  stores in a more human-readable format.)
28263  @cindex Variables, temporary assignment  @cindex Variables, temporary assignment
28264  @cindex Temporary assignment to variables  @cindex Temporary assignment to variables
28265  If you have an expression like @samp{a+b^2} on the stack and you wish to  If you have an expression like @samp{a+b^2} on the stack and you wish to
28266  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
28267  then press @kbd{=} to reevaluate the formula.  This has the side-effect  then press @kbd{=} to reevaluate the formula.  This has the side-effect
28268  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.
28269    
28270  The @kbd{s l} (@code{calc-let}) command evaluates a formula under a  The @kbd{s l} (@code{calc-let}) command evaluates a formula under a
28271  @emph{temporary} assignment of a variable.  It stores the value on the  @emph{temporary} assignment of a variable.  It stores the value on the
# Line 27961  and typing @kbd{s l b @key{RET}}. Line 28288  and typing @kbd{s l b @key{RET}}.
28288  The @kbd{a b} (@code{calc-substitute}) command is another way to substitute  The @kbd{a b} (@code{calc-substitute}) command is another way to substitute
28289  a variable with a value in a formula.  It does an actual substitution  a variable with a value in a formula.  It does an actual substitution
28290  rather than temporarily assigning the variable and evaluating.  For  rather than temporarily assigning the variable and evaluating.  For
28291  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
28292  produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}  produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}
28293  since the evaluation step will also evaluate @code{pi}.  since the evaluation step will also evaluate @code{pi}.
28294    
# Line 28145  The ``x'' entry may instead be an interv Line 28472  The ``x'' entry may instead be an interv
28472  the interval (whether the interval is open or closed is ignored).  the interval (whether the interval is open or closed is ignored).
28473    
28474  The ``x'' entry may also be a number, in which case Calc uses the  The ``x'' entry may also be a number, in which case Calc uses the
28475  sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc.  sequence of ``x'' values @expr{x}, @expr{x+1}, @expr{x+2}, etc.
28476  (Generally the number 0 or 1 would be used for @cite{x} in this case.)  (Generally the number 0 or 1 would be used for @expr{x} in this case.)
28477    
28478  The ``y'' entry may be any formula instead of a vector.  Calc effectively  The ``y'' entry may be any formula instead of a vector.  Calc effectively
28479  uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula;  uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula;
# Line 28169  are used as the ``x'' and ``y'' coordina Line 28496  are used as the ``x'' and ``y'' coordina
28496  In this case the ``x'' vector or interval you specified is not directly  In this case the ``x'' vector or interval you specified is not directly
28497  visible in the graph.  For example, if ``x'' is the interval @samp{[0..360]}  visible in the graph.  For example, if ``x'' is the interval @samp{[0..360]}
28498  and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph  and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
28499  will be a circle.@refill  will be a circle.
28500    
28501  Also, ``x'' and ``y'' may each be variable names, in which case Calc  Also, ``x'' and ``y'' may each be variable names, in which case Calc
28502  looks for suitable vectors, intervals, or formulas stored in those  looks for suitable vectors, intervals, or formulas stored in those
# Line 28224  In the first case, ``x'' and ``y'' are e Line 28551  In the first case, ``x'' and ``y'' are e
28551  the same length); either or both may instead be interval forms.  The  the same length); either or both may instead be interval forms.  The
28552  ``z'' value must be a matrix with the same number of rows as elements  ``z'' value must be a matrix with the same number of rows as elements
28553  in ``x'', and the same number of columns as elements in ``y''.  The  in ``x'', and the same number of columns as elements in ``y''.  The
28554  result is a surface plot where @c{$z_{ij}$}  result is a surface plot where
28555  @cite{z_ij} is the height of the point  @texline @tmath{z_{ij}}
28556  at coordinate @cite{(x_i, y_j)} on the surface.  The 3D graph will  @infoline @expr{z_ij}
28557    is the height of the point
28558    at coordinate @expr{(x_i, y_j)} on the surface.  The 3D graph will
28559  be displayed from a certain default viewpoint; you can change this  be displayed from a certain default viewpoint; you can change this
28560  viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}  viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}
28561  buffer as described later.  See the GNUPLOT 3.0 documentation for a  buffer as described later.  See the GNUPLOT 3.0 documentation for a
# Line 28317  itself, is what was added by @kbd{g a}. Line 28646  itself, is what was added by @kbd{g a}.
28646    
28647  A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way  A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way
28648  stack entries are interpreted as curves.  With a positive prefix  stack entries are interpreted as curves.  With a positive prefix
28649  argument @cite{n}, the top @cite{n} stack entries are ``y'' values  argument @expr{n}, the top @expr{n} stack entries are ``y'' values
28650  for @cite{n} different curves which share a common ``x'' value in  for @expr{n} different curves which share a common ``x'' value in
28651  the @cite{n+1}st stack entry.  (Thus @kbd{g a} with no prefix  the @expr{n+1}st stack entry.  (Thus @kbd{g a} with no prefix
28652  argument is equivalent to @kbd{C-u 1 g a}.)  argument is equivalent to @kbd{C-u 1 g a}.)
28653    
28654  A prefix of zero or plain @kbd{C-u} means to take two stack entries,  A prefix of zero or plain @kbd{C-u} means to take two stack entries,
28655  ``x'' and ``y'' as usual, but to interpret ``y'' as a vector of  ``x'' and ``y'' as usual, but to interpret ``y'' as a vector of
28656  ``y'' values for several curves that share a common ``x''.  ``y'' values for several curves that share a common ``x''.
28657    
28658  A negative prefix argument tells Calc to read @cite{n} vectors from  A negative prefix argument tells Calc to read @expr{n} vectors from
28659  the stack; each vector @cite{[x, y]} describes an independent curve.  the stack; each vector @expr{[x, y]} describes an independent curve.
28660  This is the only form of @kbd{g a} that creates several curves at once  This is the only form of @kbd{g a} that creates several curves at once
28661  that don't have common ``x'' values.  (Of course, the range of ``x''  that don't have common ``x'' values.  (Of course, the range of ``x''
28662  values covered by all the curves ought to be roughly the same if  values covered by all the curves ought to be roughly the same if
28663  they are to look nice on the same graph.)  they are to look nice on the same graph.)
28664    
28665  For example, to plot @c{$\sin n x$}  For example, to plot
28666  @cite{sin(n x)} for integers @cite{n}  @texline @tmath{\sin n x}
28667    @infoline @expr{sin(n x)}
28668    for integers @expr{n}
28669  from 1 to 5, you could use @kbd{v x} to create a vector of integers  from 1 to 5, you could use @kbd{v x} to create a vector of integers
28670  (@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)}
28671  across this vector.  The resulting vector of formulas is suitable  across this vector.  The resulting vector of formulas is suitable
28672  for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f}  for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f}
28673  command.  command.
# Line 28346  command. Line 28677  command.
28677  The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve  The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve
28678  to the graph.  It is not legal to intermix 2D and 3D curves in a  to the graph.  It is not legal to intermix 2D and 3D curves in a
28679  single graph.  This command takes three arguments, ``x'', ``y'',  single graph.  This command takes three arguments, ``x'', ``y'',
28680  and ``z'', from the stack.  With a positive prefix @cite{n}, it  and ``z'', from the stack.  With a positive prefix @expr{n}, it
28681  takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n}  takes @expr{n+2} arguments (common ``x'' and ``y'', plus @expr{n}
28682  separate ``z''s).  With a zero prefix, it takes three stack entries  separate ``z''s).  With a zero prefix, it takes three stack entries
28683  but the ``z'' entry is a vector of curve values.  With a negative  but the ``z'' entry is a vector of curve values.  With a negative
28684  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]}.
28685  The @kbd{g A} command works by adding a @code{splot} (surface-plot)  The @kbd{g A} command works by adding a @code{splot} (surface-plot)
28686  command to the @samp{*Gnuplot Commands*} buffer.  command to the @samp{*Gnuplot Commands*} buffer.
28687    
# Line 28469  a blank line, displays the default numbe Line 28800  a blank line, displays the default numbe
28800  graphs created by @kbd{g a} that don't specify the resolution explicitly.  graphs created by @kbd{g a} that don't specify the resolution explicitly.
28801  With a negative prefix argument, this command changes or displays  With a negative prefix argument, this command changes or displays
28802  the default value (initially 5) used for 3D graphs created by @kbd{g A}.  the default value (initially 5) used for 3D graphs created by @kbd{g A}.
28803  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
28804  will be computed for the surface.  will be computed for the surface.
28805    
28806  Data values in the graph of a function are normally computed to a  Data values in the graph of a function are normally computed to a
28807  precision of five digits, regardless of the current precision at the  precision of five digits, regardless of the current precision at the
28808  time. This is usually more than adequate, but there are cases where  time. This is usually more than adequate, but there are cases where
28809  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
28810  interval @samp{[0 ..@: 1e-6]} will round all the data points down  interval @samp{[0 ..@: 1e-6]} will round all the data points down
28811  to 1.0!  Putting the command @samp{set precision @var{n}} in the  to 1.0!  Putting the command @samp{set precision @var{n}} in the
28812  @samp{*Gnuplot Commands*} buffer will cause the data to be computed  @samp{*Gnuplot Commands*} buffer will cause the data to be computed
# Line 28621  terminals with no special graphics facil Line 28952  terminals with no special graphics facil
28952  picture of the graph composed of characters like @code{-} and @code{|}  picture of the graph composed of characters like @code{-} and @code{|}
28953  to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.  to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.
28954  The graph is made the same size as the Emacs screen, which on most  The graph is made the same size as the Emacs screen, which on most
28955  dumb terminals will be @c{$80\times24$}  dumb terminals will be
28956  @asis{80x24} characters.  The graph is displayed in  @texline @tmath{80\times24}
28957    @infoline 80x24
28958    characters.  The graph is displayed in
28959  an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit  an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit
28960  the recursive edit and return to Calc.  Note that the @code{dumb}  the recursive edit and return to Calc.  Note that the @code{dumb}
28961  device is present only in GNUPLOT 3.0 and later versions.  device is present only in GNUPLOT 3.0 and later versions.
# Line 28824  encompass full lines.)  The text is copi Line 29157  encompass full lines.)  The text is copi
29157  it appears on the screen, including line numbers if they are enabled.  it appears on the screen, including line numbers if they are enabled.
29158    
29159  A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number  A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number
29160  of lines killed.  A positive argument kills the current line and @cite{n-1}  of lines killed.  A positive argument kills the current line and @expr{n-1}
29161  lines below it.  A negative argument kills the @cite{-n} lines above the  lines below it.  A negative argument kills the @expr{-n} lines above the
29162  current line.  Again this mirrors the behavior of the standard Emacs  current line.  Again this mirrors the behavior of the standard Emacs
29163  @kbd{C-k} command.  Although a whole line is always deleted, @kbd{C-k}  @kbd{C-k} command.  Although a whole line is always deleted, @kbd{C-k}
29164  with no argument copies only the number itself into the kill ring, whereas  with no argument copies only the number itself into the kill ring, whereas
# Line 28868  If the @kbd{M-# g} command works success Line 29201  If the @kbd{M-# g} command works success
29201    
29202  A numeric prefix argument grabs the specified number of lines around  A numeric prefix argument grabs the specified number of lines around
29203  point, ignoring the mark.  A positive prefix grabs from point to the  point, ignoring the mark.  A positive prefix grabs from point to the
29204  @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
29205  to the end of the current line); a negative prefix grabs from point  to the end of the current line); a negative prefix grabs from point
29206  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
29207  that is grabbed is exactly the same as the text that @kbd{C-k} would  that is grabbed is exactly the same as the text that @kbd{C-k} would
29208  delete given that prefix argument.  delete given that prefix argument.
29209    
# Line 28926  If you give a positive numeric prefix ar Line 29259  If you give a positive numeric prefix ar
29259  will be split up into columns of width @var{n}; each column is parsed  will be split up into columns of width @var{n}; each column is parsed
29260  separately as a matrix element.  If a line contained  separately as a matrix element.  If a line contained
29261  @w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8  @w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8
29262  would correctly split the line into two error forms.@refill  would correctly split the line into two error forms.
29263    
29264  @xref{Matrix Functions}, to see how to pull the matrix apart into its  @xref{Matrix Functions}, to see how to pull the matrix apart into its
29265  constituent rows and columns.  (If it is a @c{$1\times1$}  constituent rows and columns.  (If it is a
29266  @asis{1x1} matrix, just hit @kbd{v u}  @texline @tmath{1\times1}
29267  (@code{calc-unpack}) twice.)  @infoline 1x1
29268    matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.)
29269    
29270  @kindex M-# :  @kindex M-# :
29271  @kindex M-# _  @kindex M-# _
# Line 28984  normally not included.)  The number is @ Line 29318  normally not included.)  The number is @
29318    
29319  With a prefix argument, @kbd{y} inserts several numbers, one per line.  With a prefix argument, @kbd{y} inserts several numbers, one per line.
29320  A positive argument inserts the specified number of values from the top  A positive argument inserts the specified number of values from the top
29321  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
29322  top of the stack.  An argument of zero inserts the entire stack.  Note  top of the stack.  An argument of zero inserts the entire stack.  Note
29323  that @kbd{y} with an argument of 1 is slightly different from @kbd{y}  that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
29324  with no argument; the former always copies full lines, whereas the  with no argument; the former always copies full lines, whereas the
# Line 28999  original data with the new data.  One mi Line 29333  original data with the new data.  One mi
29333  display style (@pxref{Vector and Matrix Formats}) or change the current  display style (@pxref{Vector and Matrix Formats}) or change the current
29334  display language (@pxref{Language Modes}) before doing this.  Also, note  display language (@pxref{Language Modes}) before doing this.  Also, note
29335  that this command replaces a linear region of text (as grabbed by  that this command replaces a linear region of text (as grabbed by
29336  @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}).
29337    
29338  If the editing buffer is in overwrite (as opposed to insert) mode,  If the editing buffer is in overwrite (as opposed to insert) mode,
29339  and the @kbd{C-u} prefix was not used, then the yanked number will  and the @kbd{C-u} prefix was not used, then the yanked number will
# Line 29187  is the same as @key{CONJ}. Line 29521  is the same as @key{CONJ}.
29521  @item INV *  @item INV *
29522  is the same as @key{y^x}.  is the same as @key{y^x}.
29523  @item INV /  @item INV /
29524  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}).
29525  @item HYP/INV 1  @item HYP/INV 1
29526  are the same as @key{SIN} / @kbd{INV SIN}.  are the same as @key{SIN} / @kbd{INV SIN}.
29527  @item HYP/INV 2  @item HYP/INV 2
# Line 29253  This menu provides various operations fr Line 29587  This menu provides various operations fr
29587  prefix keys.  prefix keys.
29588    
29589  @key{IMAG} multiplies the number on the stack by the imaginary  @key{IMAG} multiplies the number on the stack by the imaginary
29590  number @cite{i = (0, 1)}.  number @expr{i = (0, 1)}.
29591    
29592  @key{RE} extracts the real part a complex number.  @kbd{INV RE}  @key{RE} extracts the real part a complex number.  @kbd{INV RE}
29593  extracts the imaginary part.  extracts the imaginary part.
# Line 29266  same limit as last time. Line 29600  same limit as last time.
29600    
29601  @key{INV GCD} computes the LCM (least common multiple) function.  @key{INV GCD} computes the LCM (least common multiple) function.
29602    
29603  @key{INV FACT} is the gamma function.  @c{$\Gamma(x) = (x-1)!$}  @key{INV FACT} is the gamma function.  
29604  @cite{gamma(x) = (x-1)!}.  @texline @tmath{\Gamma(x) = (x-1)!}.
29605    @infoline @expr{gamma(x) = (x-1)!}.
29606    
29607  @key{PERM} is the number-of-permutations function, which is on the  @key{PERM} is the number-of-permutations function, which is on the
29608  @kbd{H k c} key in normal Calc.  @kbd{H k c} key in normal Calc.
# Line 29382  the variables set to the various sets of Line 29717  the variables set to the various sets of
29717  For example, you could simulate @key{MAP^} using @key{MAP$} with  For example, you could simulate @key{MAP^} using @key{MAP$} with
29718  the formula @samp{x^y}.  the formula @samp{x^y}.
29719    
29720  The @kbd{"x"} key pushes the variable name @cite{x} onto the  The @kbd{"x"} key pushes the variable name @expr{x} onto the
29721  stack.  To build the formula @cite{x^2 + 6}, you would use the  stack.  To build the formula @expr{x^2 + 6}, you would use the
29722  key sequence @kbd{"x" 2 y^x 6 +}.  This formula would then be  key sequence @kbd{"x" 2 y^x 6 +}.  This formula would then be
29723  suitable for use with the @key{MAP$} key described above.  suitable for use with the @key{MAP$} key described above.
29724  With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the  With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the
29725  @kbd{"x"} key pushes the variable names @cite{y}, @cite{z}, and  @kbd{"x"} key pushes the variable names @expr{y}, @expr{z}, and
29726  @cite{t}, respectively.  @expr{t}, respectively.
29727    
29728  @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode  @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode
29729  @section Modes Menu  @section Modes Menu
# Line 29553  We define $F_n = F_(n-1)+F_(n-2)$ for al Line 29888  We define $F_n = F_(n-1)+F_(n-2)$ for al
29888  @end example  @end example
29889    
29890  @noindent  @noindent
29891  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
29892  the top of stack will be copied back into the editing buffer.  the top of stack will be copied back into the editing buffer.
29893  This means that spaces will appear around the @samp{>} symbol  This means that spaces will appear around the @samp{>} symbol
29894  to match Calc's usual display style:  to match Calc's usual display style:
# Line 29681  in the file as well as the rounded-down Line 30016  in the file as well as the rounded-down
30016    
30017  Embedded buffers remember active formulas for as long as they  Embedded buffers remember active formulas for as long as they
30018  exist in Emacs memory.  Suppose you have an embedded formula  exist in Emacs memory.  Suppose you have an embedded formula
30019  which is @c{$\pi$}  which is @cpi{} to the normal 12 decimal places, and then
 @cite{pi} to the normal 12 decimal places, and then  
30020  type @w{@kbd{C-u 5 d n}} to display only five decimal places.  type @w{@kbd{C-u 5 d n}} to display only five decimal places.
30021  If you then type @kbd{d n}, all 12 places reappear because the  If you then type @kbd{d n}, all 12 places reappear because the
30022  full number is still there on the Calc stack.  More surprisingly,  full number is still there on the Calc stack.  More surprisingly,
# Line 29820  foo := 5 Line 30154  foo := 5
30154  @end example  @end example
30155    
30156  @noindent  @noindent
30157  records @cite{5} as the stored value of @code{foo} for the  records @expr{5} as the stored value of @code{foo} for the
30158  purposes of Embedded mode operations in the current buffer.  It  purposes of Embedded mode operations in the current buffer.  It
30159  does @emph{not} actually store @cite{5} as the ``global'' value  does @emph{not} actually store @expr{5} as the ``global'' value
30160  of @code{foo}, however.  Regular Calc operations, and Embedded  of @code{foo}, however.  Regular Calc operations, and Embedded
30161  formulas in other buffers, will not see this assignment.  formulas in other buffers, will not see this assignment.
30162    
# Line 29891  to edit the number using regular Emacs e Line 30225  to edit the number using regular Emacs e
30225  mode.  Then, we have to find a way to get Embedded mode to notice  mode.  Then, we have to find a way to get Embedded mode to notice
30226  the change.  The @kbd{M-# u} or @kbd{M-# =}  the change.  The @kbd{M-# u} or @kbd{M-# =}
30227  (@code{calc-embedded-update-formula}) command is a convenient way  (@code{calc-embedded-update-formula}) command is a convenient way
30228  to do this.@refill  to do this.
30229    
30230  @example  @example
30231  foo := 6  foo := 6
# Line 30458  performing their usual functions.  Press Line 30792  performing their usual functions.  Press
30792  Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to  Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to
30793  execute your keyboard macro by replaying the recorded keystrokes.  execute your keyboard macro by replaying the recorded keystrokes.
30794  @xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further  @xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further
30795  information.@refill  information.
30796    
30797  When you use @kbd{X} to invoke a keyboard macro, the entire macro is  When you use @kbd{X} to invoke a keyboard macro, the entire macro is
30798  treated as a single command by the undo and trail features.  The stack  treated as a single command by the undo and trail features.  The stack
# Line 30504  sequence.  The default command name (if Line 30838  sequence.  The default command name (if
30838  just the @key{RET} key as in this example) will be something like  just the @key{RET} key as in this example) will be something like
30839  @samp{calc-User-n}.  The keyboard macro will now be available as both  @samp{calc-User-n}.  The keyboard macro will now be available as both
30840  @kbd{z n} and @kbd{M-x calc-User-n}.  You can backspace and enter a more  @kbd{z n} and @kbd{M-x calc-User-n}.  You can backspace and enter a more
30841  descriptive command name if you wish.@refill  descriptive command name if you wish.
30842    
30843  Macros defined by @kbd{Z K} act like single commands; they are executed  Macros defined by @kbd{Z K} act like single commands; they are executed
30844  in the same way as by the @kbd{X} key.  If you wish to define the macro  in the same way as by the @kbd{X} key.  If you wish to define the macro
# Line 30522  command to edit the macro.  This command Line 30856  command to edit the macro.  This command
30856  the macro definition into full Emacs command names, like @code{calc-pop}  the macro definition into full Emacs command names, like @code{calc-pop}
30857  and @code{calc-add}.  Type @kbd{M-# M-#} to finish editing and update  and @code{calc-add}.  Type @kbd{M-# M-#} to finish editing and update
30858  the definition stored on the key, or, to cancel the edit, type  the definition stored on the key, or, to cancel the edit, type
30859  @kbd{M-# x}.@refill  @kbd{M-# x}.
30860    
30861  If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard  If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard
30862  macro is edited in spelled-out keystroke form.  For example, the editing  macro is edited in spelled-out keystroke form.  For example, the editing
# Line 30536  copied verbatim into the keyboard macro. Line 30870  copied verbatim into the keyboard macro.
30870  same as is used in all of this manual's examples, except that the manual  same as is used in all of this manual's examples, except that the manual
30871  takes some liberties with spaces:  When we say @kbd{' [1 2 3] @key{RET}}, we take  takes some liberties with spaces:  When we say @kbd{' [1 2 3] @key{RET}}, we take
30872  it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}},  it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}},
30873  which is what @code{read-kbd-macro} wants to see.@refill  which is what @code{read-kbd-macro} wants to see.
30874    
30875  If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro  If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro
30876  in ``raw'' form; the editing buffer simply contains characters like  in ``raw'' form; the editing buffer simply contains characters like
30877  @samp{1^M2+} (here @samp{^M} represents the carriage-return character).  @samp{1^M2+} (here @samp{^M} represents the carriage-return character).
30878  Editing in this mode, you will have to use @kbd{C-q} to enter new  Editing in this mode, you will have to use @kbd{C-q} to enter new
30879  control characters into the buffer.@refill  control characters into the buffer.
30880    
30881  @kindex M-# m  @kindex M-# m
30882  @pindex read-kbd-macro  @pindex read-kbd-macro
# Line 30646  body is skipped altogether.  For example Line 30980  body is skipped altogether.  For example
30980  computes two to a nonnegative integer power.  First, we push 1 on the  computes two to a nonnegative integer power.  First, we push 1 on the
30981  stack and then swap the integer argument back to the top.  The @kbd{Z <}  stack and then swap the integer argument back to the top.  The @kbd{Z <}
30982  pops that argument leaving the 1 back on top of the stack.  Then, we  pops that argument leaving the 1 back on top of the stack.  Then, we
30983  repeat a multiply-by-two step however many times.@refill  repeat a multiply-by-two step however many times.
30984    
30985  Once again, the keyboard macro is executed as it is being entered.  Once again, the keyboard macro is executed as it is being entered.
30986  In this case it is especially important to set up reasonable initial  In this case it is especially important to set up reasonable initial
# Line 30666  if that object is true (a non-zero numbe Line 31000  if that object is true (a non-zero numbe
31000  innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues  innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues
31001  after the @kbd{Z >}.  If the object is false, the @kbd{Z /} has no  after the @kbd{Z >}.  If the object is false, the @kbd{Z /} has no
31002  effect.  Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;}  effect.  Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;}
31003  in the C language.@refill  in the C language.
31004    
31005  @kindex Z (  @kindex Z (
31006  @kindex Z )  @kindex Z )
# Line 30680  command pops initial and final values fr Line 31014  command pops initial and final values fr
31014  a temporary internal counter and initializes it with the value @var{init}.  a temporary internal counter and initializes it with the value @var{init}.
31015  The @kbd{Z (} command then repeatedly pushes the counter value onto the  The @kbd{Z (} command then repeatedly pushes the counter value onto the
31016  stack and executes @var{body} and @var{step}, adding @var{step} to the  stack and executes @var{body} and @var{step}, adding @var{step} to the
31017  counter each time until the loop finishes.@refill  counter each time until the loop finishes.
31018    
31019  @cindex Summations (by keyboard macros)  @cindex Summations (by keyboard macros)
31020  By default, the loop finishes when the counter becomes greater than (or  By default, the loop finishes when the counter becomes greater than (or
# Line 30880  name as the command name but with @samp{ Line 31214  name as the command name but with @samp{
31214  new function in an algebraic formula.  Suppose we enter @kbd{yow @key{RET}}.  new function in an algebraic formula.  Suppose we enter @kbd{yow @key{RET}}.
31215  Then the new function can be invoked by pushing two numbers on the  Then the new function can be invoked by pushing two numbers on the
31216  stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic  stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic
31217  formula @samp{yow(x,y)}.@refill  formula @samp{yow(x,y)}.
31218    
31219  The fourth prompt is for the function's argument list.  This is used to  The fourth prompt is for the function's argument list.  This is used to
31220  associate values on the stack with the variables that appear in the formula.  associate values on the stack with the variables that appear in the formula.
# Line 30891  two numbers from the stack, substitute t Line 31225  two numbers from the stack, substitute t
31225  @samp{b} (respectively) in the formula, then simplify the formula and  @samp{b} (respectively) in the formula, then simplify the formula and
31226  push the result on the stack.  In other words, @kbd{10 @key{RET} 100 z m}  push the result on the stack.  In other words, @kbd{10 @key{RET} 100 z m}
31227  would replace the 10 and 100 on the stack with the number 210, which is  would replace the 10 and 100 on the stack with the number 210, which is
31228  @cite{a + 2 b} with @cite{a=10} and @cite{b=100}.  Likewise, the formula  @expr{a + 2 b} with @expr{a=10} and @expr{b=100}.  Likewise, the formula
31229  @samp{yow(10, 100)} will be evaluated by substituting @cite{a=10} and  @samp{yow(10, 100)} will be evaluated by substituting @expr{a=10} and
31230  @cite{b=100} in the definition.  @expr{b=100} in the definition.
31231    
31232  You can rearrange the order of the names before pressing @key{RET} to  You can rearrange the order of the names before pressing @key{RET} to
31233  control which stack positions go to which variables in the formula.  If  control which stack positions go to which variables in the formula.  If
# Line 30911  using the argument list @samp{(a b)}. Line 31245  using the argument list @samp{(a b)}.
31245  The final prompt is a y-or-n question concerning what to do if symbolic  The final prompt is a y-or-n question concerning what to do if symbolic
31246  arguments are given to your function.  If you answer @kbd{y}, then  arguments are given to your function.  If you answer @kbd{y}, then
31247  executing @kbd{z m} (using the original argument list @samp{(a b)}) with  executing @kbd{z m} (using the original argument list @samp{(a b)}) with
31248  arguments @cite{10} and @cite{x} will leave the function in symbolic  arguments @expr{10} and @expr{x} will leave the function in symbolic
31249  form, i.e., @samp{yow(10,x)}.  On the other hand, if you answer @kbd{n},  form, i.e., @samp{yow(10,x)}.  On the other hand, if you answer @kbd{n},
31250  then the formula will always be expanded, even for non-constant  then the formula will always be expanded, even for non-constant
31251  arguments: @samp{10 + 2 x}.  If you never plan to feed algebraic  arguments: @samp{10 + 2 x}.  If you never plan to feed algebraic
31252  formulas to your new function, it doesn't matter how you answer this  formulas to your new function, it doesn't matter how you answer this
31253  question.@refill  question.
31254    
31255  If you answered @kbd{y} to this question you can still cause a function  If you answered @kbd{y} to this question you can still cause a function
31256  call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}).  call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}).
# Line 30931  key, and this command pushes the formula Line 31265  key, and this command pushes the formula
31265  key onto the stack.  Actually, it pushes a nameless function that  key onto the stack.  Actually, it pushes a nameless function that
31266  specifies both the argument list and the defining formula.  You will get  specifies both the argument list and the defining formula.  You will get
31267  an error message if the key is undefined, or if the key was not defined  an error message if the key is undefined, or if the key was not defined
31268  by a @kbd{Z F} command.@refill  by a @kbd{Z F} command.
31269    
31270  The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has  The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has
31271  been defined by a formula uses a variant of the @code{calc-edit} command  been defined by a formula uses a variant of the @code{calc-edit} command
# Line 30951  You may find it useful to turn off the d Line 31285  You may find it useful to turn off the d
31285  used as a function definition.  For example, the formula @samp{deriv(a^2,v)}  used as a function definition.  For example, the formula @samp{deriv(a^2,v)}
31286  which might be used to define a new function @samp{dsqr(a,v)} will be  which might be used to define a new function @samp{dsqr(a,v)} will be
31287  ``simplified'' to 0 immediately upon entry since @code{deriv} considers  ``simplified'' to 0 immediately upon entry since @code{deriv} considers
31288  @cite{a} to be constant with respect to @cite{v}.  Turning off  @expr{a} to be constant with respect to @expr{v}.  Turning off
31289  default simplifications cures this problem:  The definition will be stored  default simplifications cures this problem:  The definition will be stored
31290  in symbolic form without ever activating the @code{deriv} function.  Press  in symbolic form without ever activating the @code{deriv} function.  Press
31291  @kbd{m D} to turn the default simplifications back on afterwards.  @kbd{m D} to turn the default simplifications back on afterwards.
# Line 31049  The following standard Lisp functions ar Line 31383  The following standard Lisp functions ar
31383  @code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=},  @code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=},
31384  @code{/=}, @code{1+}, @code{1-}, @code{logand}, @code{logior}, @code{logxor},  @code{/=}, @code{1+}, @code{1-}, @code{logand}, @code{logior}, @code{logxor},
31385  @code{logandc2}, @code{lognot}.  Also, @code{~=} is an abbreviation for  @code{logandc2}, @code{lognot}.  Also, @code{~=} is an abbreviation for
31386  @code{math-nearly-equal}, which is useful in implementing Taylor series.@refill  @code{math-nearly-equal}, which is useful in implementing Taylor series.
31387    
31388  For other functions @var{func}, if a function by the name  For other functions @var{func}, if a function by the name
31389  @samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the  @samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the
# Line 31057  name @samp{math-@var{func}} exists it is Line 31391  name @samp{math-@var{func}} exists it is
31391  is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is  is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is
31392  used on the assumption that this is a to-be-defined math function.  Also, if  used on the assumption that this is a to-be-defined math function.  Also, if
31393  the function name is quoted as in @samp{('integerp a)} the function name is  the function name is quoted as in @samp{('integerp a)} the function name is
31394  always used exactly as written (but not quoted).@refill  always used exactly as written (but not quoted).
31395    
31396  Variable names have @samp{var-} prepended to them unless they appear in  Variable names have @samp{var-} prepended to them unless they appear in
31397  the function's argument list or in an enclosing @code{let}, @code{let*},  the function's argument list or in an enclosing @code{let}, @code{let*},
31398  @code{for}, or @code{foreach} form,  @code{for}, or @code{foreach} form,
31399  or their names already contain a @samp{-} character.  Thus a reference to  or their names already contain a @samp{-} character.  Thus a reference to
31400  @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}.
31401    
31402  A few other Lisp extensions are available in @code{defmath} definitions:  A few other Lisp extensions are available in @code{defmath} definitions:
31403    
# Line 31081  Lisp @code{setf} function.  (The name @c Line 31415  Lisp @code{setf} function.  (The name @c
31415  a synonym of @code{setq}.)  Specifically, the first argument of  a synonym of @code{setq}.)  Specifically, the first argument of
31416  @code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form,  @code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form,
31417  in which case the effect is to store into the specified  in which case the effect is to store into the specified
31418  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}
31419  into one element of a matrix.  into one element of a matrix.
31420    
31421  @item  @item
31422  A @code{for} looping construct is available.  For example,  A @code{for} looping construct is available.  For example,
31423  @samp{(for ((i 0 10)) body)} executes @code{body} once for each  @samp{(for ((i 0 10)) body)} executes @code{body} once for each
31424  binding of @cite{i} from zero to 10.  This is like a @code{let}  binding of @expr{i} from zero to 10.  This is like a @code{let}
31425  form in that @cite{i} is temporarily bound to the loop count  form in that @expr{i} is temporarily bound to the loop count
31426  without disturbing its value outside the @code{for} construct.  without disturbing its value outside the @code{for} construct.
31427  Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)},  Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)},
31428  are also available.  For each value of @cite{i} from zero to 10,  are also available.  For each value of @expr{i} from zero to 10,
31429  @cite{j} counts from 0 to @cite{i-1} in steps of two.  Note that  @expr{j} counts from 0 to @expr{i-1} in steps of two.  Note that
31430  @code{for} has the same general outline as @code{let*}, except  @code{for} has the same general outline as @code{let*}, except
31431  that each element of the header is a list of three or four  that each element of the header is a list of three or four
31432  things, not just two.  things, not just two.
# Line 31100  things, not just two. Line 31434  things, not just two.
31434  @item  @item
31435  The @code{foreach} construct loops over elements of a list.  The @code{foreach} construct loops over elements of a list.
31436  For example, @samp{(foreach ((x (cdr v))) body)} executes  For example, @samp{(foreach ((x (cdr v))) body)} executes
31437  @code{body} with @cite{x} bound to each element of Calc vector  @code{body} with @expr{x} bound to each element of Calc vector
31438  @cite{v} in turn.  The purpose of @code{cdr} here is to skip over  @expr{v} in turn.  The purpose of @code{cdr} here is to skip over
31439  the initial @code{vec} symbol in the vector.  the initial @code{vec} symbol in the vector.
31440    
31441  @item  @item
# Line 31112  loop.  (Lisp loops otherwise always retu Line 31446  loop.  (Lisp loops otherwise always retu
31446    
31447  @item  @item
31448  The @code{return} function prematurely returns from the enclosing  The @code{return} function prematurely returns from the enclosing
31449  function.  For example, @samp{(return (+ x y))} returns @cite{x+y}  function.  For example, @samp{(return (+ x y))} returns @expr{x+y}
31450  as the value of a function.  You can use @code{return} anywhere  as the value of a function.  You can use @code{return} anywhere
31451  inside the body of the function.  inside the body of the function.
31452  @end itemize  @end itemize
# Line 31464  Emacs-style code string as well which co Line 31798  Emacs-style code string as well which co
31798    
31799  In this example, the command @code{calc-foo} will evaluate the expression  In this example, the command @code{calc-foo} will evaluate the expression
31800  @samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if  @samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if
31801  executed with a numeric prefix argument of @cite{n}.  executed with a numeric prefix argument of @expr{n}.
31802    
31803  The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}  The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}
31804  code as used with @code{defun}).  It uses the numeric prefix argument as the  code as used with @code{defun}).  It uses the numeric prefix argument as the
# Line 31501  The following qualifiers are recognized: Line 31835  The following qualifiers are recognized:
31835  The argument must not be an incomplete vector, interval, or complex number.  The argument must not be an incomplete vector, interval, or complex number.
31836  (This is rarely needed since the Calculator itself will never call your  (This is rarely needed since the Calculator itself will never call your
31837  function with an incomplete argument.  But there is nothing stopping your  function with an incomplete argument.  But there is nothing stopping your
31838  own Lisp code from calling your function with an incomplete argument.)@refill  own Lisp code from calling your function with an incomplete argument.)
31839    
31840  @item integer  @item integer
31841  @findex integer  @findex integer
# Line 31665  same thing with a single division by 512 Line 31999  same thing with a single division by 512
31999  @end ignore  @end ignore
32000  @tindex mysin  @tindex mysin
32001  A somewhat limited sine function could be defined as follows, using the  A somewhat limited sine function could be defined as follows, using the
32002  well-known Taylor series expansion for @c{$\sin x$}  well-known Taylor series expansion for
32003  @samp{sin(x)}:  @texline @tmath{\sin x}:
32004    @infoline @samp{sin(x)}:
32005    
32006  @smallexample  @smallexample
32007  (defmath mysin ((float (anglep x)))  (defmath mysin ((float (anglep x)))
# Line 31688  well-known Taylor series expansion for @ Line 32023  well-known Taylor series expansion for @
32023  @end smallexample  @end smallexample
32024    
32025  The actual @code{sin} function in Calc works by first reducing the problem  The actual @code{sin} function in Calc works by first reducing the problem
32026  to a sine or cosine of a nonnegative number less than @c{$\pi \over 4$}  to a sine or cosine of a nonnegative number less than @cpiover{4}.  This
 @cite{pi/4}.  This  
32027  ensures that the Taylor series will converge quickly.  Also, the calculation  ensures that the Taylor series will converge quickly.  Also, the calculation
32028  is carried out with two extra digits of precision to guard against cumulative  is carried out with two extra digits of precision to guard against cumulative
32029  round-off in @samp{sum}.  Finally, complex arguments are allowed and handled  round-off in @samp{sum}.  Finally, complex arguments are allowed and handled
# Line 31724  numbers, @code{mysin-series} is the rout Line 32058  numbers, @code{mysin-series} is the rout
32058  series as before, and @code{mycos-raw} is a function analogous to  series as before, and @code{mycos-raw} is a function analogous to
32059  @code{mysin-raw} for cosines.  @code{mysin-raw} for cosines.
32060    
32061  The strategy is to ensure that @cite{x} is nonnegative before calling  The strategy is to ensure that @expr{x} is nonnegative before calling
32062  @code{mysin-raw}.  This function then recursively reduces its argument  @code{mysin-raw}.  This function then recursively reduces its argument
32063  to a suitable range, namely, plus-or-minus @c{$\pi \over 4$}  to a suitable range, namely, plus-or-minus @cpiover{4}.  Note that each
 @cite{pi/4}.  Note that each  
32064  test, and particularly the first comparison against 7, is designed so  test, and particularly the first comparison against 7, is designed so
32065  that small roundoff errors cannot produce an infinite loop.  (Suppose  that small roundoff errors cannot produce an infinite loop.  (Suppose
32066  we compared with @samp{(two-pi)} instead; if due to roundoff problems  we compared with @samp{(two-pi)} instead; if due to roundoff problems
# Line 31877  consider what happens with @samp{(calc-e Line 32210  consider what happens with @samp{(calc-e
32210  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.
32211    
32212  As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")}  As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")}
32213  checks if the number in string @cite{a} is less than the one in  checks if the number in string @expr{a} is less than the one in
32214  string @cite{b}.  Without using a list, the integer 1 might  string @expr{b}.  Without using a list, the integer 1 might
32215  come out in a variety of formats which would be hard to test for  come out in a variety of formats which would be hard to test for
32216  conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}.  (But  conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}.  (But
32217  see ``Predicates'' mode, below.)  see ``Predicates'' mode, below.)
# Line 32218  the float is @samp{@var{mant} * 10^@var{ Line 32551  the float is @samp{@var{mant} * 10^@var{
32551  are that the number 0.0 is always stored as @samp{(float 0 0)}, and,  are that the number 0.0 is always stored as @samp{(float 0 0)}, and,
32552  except for the 0.0 case, the rightmost base-10 digit of @var{mant} is  except for the 0.0 case, the rightmost base-10 digit of @var{mant} is
32553  always nonzero.  (If the rightmost digit is zero, the number is  always nonzero.  (If the rightmost digit is zero, the number is
32554  rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)@refill  rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)
32555    
32556  Rectangular complex numbers are stored in the form @samp{(cplx @var{re}  Rectangular complex numbers are stored in the form @samp{(cplx @var{re}
32557  @var{im})}, where @var{re} and @var{im} are each real numbers, either  @var{im})}, where @var{re} and @var{im} are each real numbers, either
32558  integers, fractions, or floats.  The value is @samp{@var{re} + @var{im}i}.  integers, fractions, or floats.  The value is @samp{@var{re} + @var{im}i}.
32559  The @var{im} part is nonzero; complex numbers with zero imaginary  The @var{im} part is nonzero; complex numbers with zero imaginary
32560  components are converted to real numbers automatically.@refill  components are converted to real numbers automatically.
32561    
32562  Polar complex numbers are stored in the form @samp{(polar @var{r}  Polar complex numbers are stored in the form @samp{(polar @var{r}
32563  @var{theta})}, where @var{r} is a positive real value and @var{theta}  @var{theta})}, where @var{r} is a positive real value and @var{theta}
# Line 32233  usually normalized to lie in the interva Line 32566  usually normalized to lie in the interva
32566  or @samp{(-pi ..@: pi)} radians, according to the current angular mode.  or @samp{(-pi ..@: pi)} radians, according to the current angular mode.
32567  If the angle is 0 the value is converted to a real number automatically.  If the angle is 0 the value is converted to a real number automatically.
32568  (If the angle is 180 degrees, the value is usually also converted to a  (If the angle is 180 degrees, the value is usually also converted to a
32569  negative real number.)@refill  negative real number.)
32570    
32571  Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m}  Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m}
32572  @var{s})}, where @var{h} is an integer or an integer-valued float (i.e.,  @var{s})}, where @var{h} is an integer or an integer-valued float (i.e.,
32573  a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued  a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued
32574  float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number  float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number
32575  in the range @samp{[0 ..@: 60)}.@refill  in the range @samp{[0 ..@: 60)}.
32576    
32577  Date forms are stored as @samp{(date @var{n})}, where @var{n} is  Date forms are stored as @samp{(date @var{n})}, where @var{n} is
32578  a real number that counts days since midnight on the morning of  a real number that counts days since midnight on the morning of
# Line 32293  which is evaluated when the constant's v Line 32626  which is evaluated when the constant's v
32626  which represent units are not stored in any special way; they are units  which represent units are not stored in any special way; they are units
32627  only because their names appear in the units table.  If the value  only because their names appear in the units table.  If the value
32628  cell contains a string, it is parsed to get the variable's value when  cell contains a string, it is parsed to get the variable's value when
32629  the variable is used.@refill  the variable is used.
32630    
32631  A Lisp list with any other symbol as the first element is a function call.  A Lisp list with any other symbol as the first element is a function call.
32632  The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^},  The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^},
# Line 32313  object which represents their value, or Line 32646  object which represents their value, or
32646  wish to return multiple values.  (The latter case is allowed only for  wish to return multiple values.  (The latter case is allowed only for
32647  functions which are the outer-level call in an expression whose value is  functions which are the outer-level call in an expression whose value is
32648  about to be pushed on the stack; this feature is considered obsolete  about to be pushed on the stack; this feature is considered obsolete
32649  and is not used by any built-in Calc functions.)@refill  and is not used by any built-in Calc functions.)
32650    
32651  @node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats, Internals  @node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats, Internals
32652  @subsubsection Interactive Functions  @subsubsection Interactive Functions
# Line 32349  contains the variable's value) was store Line 32682  contains the variable's value) was store
32682  previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})},  previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})},
32683  which means that to undo requires calling the function @samp{(@var{undo}  which means that to undo requires calling the function @samp{(@var{undo}
32684  @var{args} @dots{})} and, if the undo is later redone, calling  @var{args} @dots{})} and, if the undo is later redone, calling
32685  @samp{(@var{redo} @var{args} @dots{})}.@refill  @samp{(@var{redo} @var{args} @dots{})}.
32686  @end defun  @end defun
32687    
32688  @defun calc-record-why msg args  @defun calc-record-why msg args
# Line 32364  some sort.  If @var{msg} is a symbol, it Line 32697  some sort.  If @var{msg} is a symbol, it
32697  (such as @code{integerp} or @code{numvecp}) which the arguments did not  (such as @code{integerp} or @code{numvecp}) which the arguments did not
32698  satisfy; it is expanded to a suitable string such as ``Expected an  satisfy; it is expanded to a suitable string such as ``Expected an
32699  integer.''  The @code{reject-arg} function calls @code{calc-record-why}  integer.''  The @code{reject-arg} function calls @code{calc-record-why}
32700  automatically; @pxref{Predicates}.@refill  automatically; @pxref{Predicates}.
32701  @end defun  @end defun
32702    
32703  @defun calc-is-inverse  @defun calc-is-inverse
# Line 32391  elements will be inserted into the stack Line 32724  elements will be inserted into the stack
32724  end up at level @var{n}, the next-to-last at level @var{n}+1, etc.  end up at level @var{n}, the next-to-last at level @var{n}+1, etc.
32725  The elements of @var{vals} are assumed to be valid Calc objects, and  The elements of @var{vals} are assumed to be valid Calc objects, and
32726  are not evaluated, rounded, or renormalized in any way.  If @var{vals}  are not evaluated, rounded, or renormalized in any way.  If @var{vals}
32727  is an empty list, nothing happens.@refill  is an empty list, nothing happens.
32728    
32729  The stack elements are pushed without any sub-formula selections.  The stack elements are pushed without any sub-formula selections.
32730  You can give an optional third argument to this function, which must  You can give an optional third argument to this function, which must
# Line 32410  one-element list) is returned.  If @var{ Line 32743  one-element list) is returned.  If @var{
32743  element will be next-to-last, etc.  If @var{n} or @var{m} are out of  element will be next-to-last, etc.  If @var{n} or @var{m} are out of
32744  range, the command is aborted with a suitable error message.  If @var{n}  range, the command is aborted with a suitable error message.  If @var{n}
32745  is zero, the function returns an empty list.  The stack elements are not  is zero, the function returns an empty list.  The stack elements are not
32746  evaluated, rounded, or renormalized.@refill  evaluated, rounded, or renormalized.
32747    
32748  If any stack elements contain selections, and selections have not  If any stack elements contain selections, and selections have not
32749  been disabled by the @kbd{j e} (@code{calc-enable-selections}) command,  been disabled by the @kbd{j e} (@code{calc-enable-selections}) command,
# Line 32506  This function implements a unary operato Line 32839  This function implements a unary operato
32839  argument to apply the operator over many stack entries.  If the prefix  argument to apply the operator over many stack entries.  If the prefix
32840  argument @var{arg} is @code{nil}, this uses @code{calc-enter-result}  argument @var{arg} is @code{nil}, this uses @code{calc-enter-result}
32841  as outlined above.  Otherwise, it maps the function over several stack  as outlined above.  Otherwise, it maps the function over several stack
32842  elements; @pxref{Prefix Arguments}.  For example,@refill  elements; @pxref{Prefix Arguments}.  For example,
32843    
32844  @smallexample  @smallexample
32845  (defun calc-zeta (arg)  (defun calc-zeta (arg)
# Line 32527  specified, nothing happens.  When the ar Line 32860  specified, nothing happens.  When the ar
32860  the binary function @var{func} is reduced across the top @var{arg}  the binary function @var{func} is reduced across the top @var{arg}
32861  stack elements; when the argument is negative, the function is  stack elements; when the argument is negative, the function is
32862  mapped between the next-to-top @i{-@var{arg}} stack elements and the  mapped between the next-to-top @i{-@var{arg}} stack elements and the
32863  top element.@refill  top element.
32864  @end defun  @end defun
32865    
32866  @defun calc-stack-size  @defun calc-stack-size
# Line 32541  Move the point to the @var{n}th stack en Line 32874  Move the point to the @var{n}th stack en
32874  will be the @samp{.} line.  If @var{n} is from 1 to the current stack size,  will be the @samp{.} line.  If @var{n} is from 1 to the current stack size,
32875  this will be the beginning of the first line of that stack entry's display.  this will be the beginning of the first line of that stack entry's display.
32876  If line numbers are enabled, this will move to the first character of the  If line numbers are enabled, this will move to the first character of the
32877  line number, not the stack entry itself.@refill  line number, not the stack entry itself.
32878  @end defun  @end defun
32879    
32880  @defun calc-substack-height n  @defun calc-substack-height n
# Line 32551  will be one (assuming no stack truncatio Line 32884  will be one (assuming no stack truncatio
32884  one line long (i.e., no matrices are displayed), the return value will  one line long (i.e., no matrices are displayed), the return value will
32885  be equal @var{n}+1 as long as @var{n} is in range.  (Note that in Big  be equal @var{n}+1 as long as @var{n} is in range.  (Note that in Big
32886  mode, the return value includes the blank lines that separate stack  mode, the return value includes the blank lines that separate stack
32887  entries.)@refill  entries.)
32888  @end defun  @end defun
32889    
32890  @defun calc-refresh  @defun calc-refresh
# Line 32560  This must be called after changing any p Line 32893  This must be called after changing any p
32893  display radix, which might change the appearance of existing stack  display radix, which might change the appearance of existing stack
32894  entries.  (During a keyboard macro invoked by the @kbd{X} key, refreshing  entries.  (During a keyboard macro invoked by the @kbd{X} key, refreshing
32895  is suppressed, but a flag is set so that the entire stack will be refreshed  is suppressed, but a flag is set so that the entire stack will be refreshed
32896  rather than just the top few elements when the macro finishes.)@refill  rather than just the top few elements when the macro finishes.)
32897  @end defun  @end defun
32898    
32899  @node Predicates, Computational Lisp Functions, Stack Lisp Functions, Internals  @node Predicates, Computational Lisp Functions, Stack Lisp Functions, Internals
# Line 32739  undefined or cannot be determined.  Gene Line 33072  undefined or cannot be determined.  Gene
33072  by checking whether @samp{@var{x} - @var{y}} is @code{negp}.  In  by checking whether @samp{@var{x} - @var{y}} is @code{negp}.  In
33073  @code{defmath}, the expression @samp{(< x y)} will automatically be  @code{defmath}, the expression @samp{(< x y)} will automatically be
33074  converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=},  converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=},
33075  and @code{>=} are similarly converted in terms of @code{lessp}.@refill  and @code{>=} are similarly converted in terms of @code{lessp}.
33076  @end defun  @end defun
33077    
33078  @defun beforep x y  @defun beforep x y
# Line 32771  converted to @samp{(math-equal x y)}. Line 33104  converted to @samp{(math-equal x y)}.
33104  Returns true if @var{x} and @var{n} are numerically equal, where @var{n}  Returns true if @var{x} and @var{n} are numerically equal, where @var{n}
33105  is a fixnum which is not a multiple of 10.  This will automatically be  is a fixnum which is not a multiple of 10.  This will automatically be
33106  used by @code{defmath} in place of the more general @code{math-equal}  used by @code{defmath} in place of the more general @code{math-equal}
33107  whenever possible.@refill  whenever possible.
33108  @end defun  @end defun
33109    
33110  @defun nearly-equal x y  @defun nearly-equal x y
# Line 32808  or a provably non-zero formula. Line 33141  or a provably non-zero formula.
33141  Abort the current function evaluation due to unacceptable argument values.  Abort the current function evaluation due to unacceptable argument values.
33142  This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a  This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a
33143  Lisp error which @code{normalize} will trap.  The net effect is that the  Lisp error which @code{normalize} will trap.  The net effect is that the
33144  function call which led here will be left in symbolic form.@refill  function call which led here will be left in symbolic form.
33145  @end defun  @end defun
33146    
33147  @defun inexact-value  @defun inexact-value
# Line 32819  Note that if your function calls @samp{( Line 33152  Note that if your function calls @samp{(
33152  @code{sin} function will call @code{inexact-value}, which will cause your  @code{sin} function will call @code{inexact-value}, which will cause your
33153  function to be left unsimplified.  You may instead wish to call  function to be left unsimplified.  You may instead wish to call
33154  @samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic Mode will  @samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic Mode will
33155  return the formula @samp{sin(5)} to your function.@refill  return the formula @samp{sin(5)} to your function.
33156  @end defun  @end defun
33157    
33158  @defun overflow  @defun overflow
# Line 32840  the main body of this manual may be call Line 33173  the main body of this manual may be call
33173  the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command,  the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command,
33174  this means @code{calc-sqrt} is an interactive stack-based square-root  this means @code{calc-sqrt} is an interactive stack-based square-root
33175  command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt})  command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt})
33176  is the actual Lisp function for taking square roots.@refill  is the actual Lisp function for taking square roots.
33177    
33178  The functions @code{math-add}, @code{math-sub}, @code{math-mul},  The functions @code{math-add}, @code{math-sub}, @code{math-mul},
33179  @code{math-div}, @code{math-mod}, and @code{math-neg} are not included  @code{math-div}, @code{math-mod}, and @code{math-neg} are not included
33180  in this list, since @code{defmath} allows you to write native Lisp  in this list, since @code{defmath} allows you to write native Lisp
33181  @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, and unary @code{-},  @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, and unary @code{-},
33182  respectively, instead.@refill  respectively, instead.
33183    
33184  @defun normalize val  @defun normalize val
33185  (Full form: @code{math-normalize}.)  (Full form: @code{math-normalize}.)
# Line 32857  if @var{val} is a bignum it will be norm Line 33190  if @var{val} is a bignum it will be norm
33190  small.  All the various data types are similarly converted to their standard  small.  All the various data types are similarly converted to their standard
33191  forms.  Variables are left alone, but function calls are actually evaluated  forms.  Variables are left alone, but function calls are actually evaluated
33192  in formulas.  For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will  in formulas.  For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will
33193  return 6.@refill  return 6.
33194    
33195  If a function call fails, because the function is void or has the wrong  If a function call fails, because the function is void or has the wrong
33196  number of parameters, or because it returns @code{nil} or calls  number of parameters, or because it returns @code{nil} or calls
33197  @code{reject-arg} or @code{inexact-result}, @code{normalize} returns  @code{reject-arg} or @code{inexact-result}, @code{normalize} returns
33198  the formula still in symbolic form.@refill  the formula still in symbolic form.
33199    
33200  If the current Simplification Mode is ``none'' or ``numeric arguments  If the current Simplification Mode is ``none'' or ``numeric arguments
33201  only,'' @code{normalize} will act appropriately.  However, the more  only,'' @code{normalize} will act appropriately.  However, the more
# Line 32871  not handled by @code{normalize}.  They a Line 33204  not handled by @code{normalize}.  They a
33204  which calls @code{normalize} and possibly some other routines, such  which calls @code{normalize} and possibly some other routines, such
33205  as @code{simplify} or @code{simplify-units}.  Programs generally will  as @code{simplify} or @code{simplify-units}.  Programs generally will
33206  never call @code{calc-normalize} except when popping or pushing values  never call @code{calc-normalize} except when popping or pushing values
33207  on the stack.@refill  on the stack.
33208  @end defun  @end defun
33209    
33210  @defun evaluate-expr expr  @defun evaluate-expr expr
33211  Replace all variables in @var{expr} that have values with their values,  Replace all variables in @var{expr} that have values with their values,
33212  then use @code{normalize} to simplify the result.  This is what happens  then use @code{normalize} to simplify the result.  This is what happens
33213  when you press the @kbd{=} key interactively.@refill  when you press the @kbd{=} key interactively.
33214  @end defun  @end defun
33215    
33216  @defmac with-extra-prec n body  @defmac with-extra-prec n body
# Line 32948  or formula, this calls @code{reject-arg} Line 33281  or formula, this calls @code{reject-arg}
33281  Compare the numbers @var{x} and @var{y}, and return @i{-1} if  Compare the numbers @var{x} and @var{y}, and return @i{-1} if
33282  @samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})},  @samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})},
33283  0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is  0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is
33284  undefined or cannot be determined.@refill  undefined or cannot be determined.
33285  @end defun  @end defun
33286    
33287  @defun numdigs n  @defun numdigs n
# Line 33000  For a more well-defined result, use @sam Line 33333  For a more well-defined result, use @sam
33333  @defun idivmod x y  @defun idivmod x y
33334  Divide integer @var{x} by integer @var{y}; return a cons cell whose  Divide integer @var{x} by integer @var{y}; return a cons cell whose
33335  @code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}  @code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}
33336  is @samp{(imod @var{x} @var{y})}.@refill  is @samp{(imod @var{x} @var{y})}.
33337  @end defun  @end defun
33338    
33339  @defun pow x y  @defun pow x y
33340  Compute @var{x} to the power @var{y}.  In @code{defmath} code, this can  Compute @var{x} to the power @var{y}.  In @code{defmath} code, this can
33341  also be written @samp{(^ @var{x} @var{y})} or  also be written @samp{(^ @var{x} @var{y})} or
33342  @w{@samp{(expt @var{x} @var{y})}}.@refill  @w{@samp{(expt @var{x} @var{y})}}.
33343  @end defun  @end defun
33344    
33345  @defun abs-approx x  @defun abs-approx x
# Line 33030  Other related constant-generating functi Line 33363  Other related constant-generating functi
33363  @code{pi-over-2}, @code{pi-over-4}, @code{pi-over-180}, @code{sqrt-two-pi},  @code{pi-over-2}, @code{pi-over-4}, @code{pi-over-180}, @code{sqrt-two-pi},
33364  @code{e}, @code{sqrt-e}, @code{ln-2}, and @code{ln-10}.  Each function  @code{e}, @code{sqrt-e}, @code{ln-2}, and @code{ln-10}.  Each function
33365  returns a floating-point value in the current precision, and each uses  returns a floating-point value in the current precision, and each uses
33366  caching so that all calls after the first are essentially free.@refill  caching so that all calls after the first are essentially free.
33367  @end defun  @end defun
33368    
33369  @defmac math-defcache @var{func} @var{initial} @var{form}  @defmac math-defcache @var{func} @var{initial} @var{form}
# Line 33045  with the current precision increased by Line 33378  with the current precision increased by
33378  two least significant digits is stored in the cache.  For example,  two least significant digits is stored in the cache.  For example,
33379  calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34  calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34
33380  digits, rounds it down to 32 digits for future use, then rounds it  digits, rounds it down to 32 digits for future use, then rounds it
33381  again to 30 digits for use in the present request.@refill  again to 30 digits for use in the present request.
33382  @end defmac  @end defmac
33383    
33384  @findex half-circle  @findex half-circle
# Line 33072  return @code{nil}. Line 33405  return @code{nil}.
33405    
33406  @defun div-mod a b m  @defun div-mod a b m
33407  Divide @var{a} by @var{b}, modulo @var{m}.  This returns @code{nil} if  Divide @var{a} by @var{b}, modulo @var{m}.  This returns @code{nil} if
33408  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.
33409  @end defun  @end defun
33410    
33411  @defun pow-mod a b m  @defun pow-mod a b m
# Line 33147  iterations, is @var{p} percent sure that Line 33480  iterations, is @var{p} percent sure that
33480  @var{iters} parameter is the number of Fermat iterations to use, in the  @var{iters} parameter is the number of Fermat iterations to use, in the
33481  case that this is necessary.  If @code{prime-test} returns ``maybe,''  case that this is necessary.  If @code{prime-test} returns ``maybe,''
33482  you can call it again with the same @var{n} to get a greater certainty;  you can call it again with the same @var{n} to get a greater certainty;
33483  @code{prime-test} remembers where it left off.@refill  @code{prime-test} remembers where it left off.
33484  @end defun  @end defun
33485    
33486  @defun to-simple-fraction f  @defun to-simple-fraction f
# Line 33198  the result is the list @samp{(@var{r} @v Line 33531  the result is the list @samp{(@var{r} @v
33531  produce lists of more than two dimensions.  Note that the object  produce lists of more than two dimensions.  Note that the object
33532  @samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,  @samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,
33533  and is treated by this and other Calc routines as a plain vector of two  and is treated by this and other Calc routines as a plain vector of two
33534  elements.@refill  elements.
33535  @end defun  @end defun
33536    
33537  @defun dimension-error  @defun dimension-error
# Line 33246  for each pair of elements @var{ai} and @ Line 33579  for each pair of elements @var{ai} and @
33579  For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v}  For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v}
33580  with each element increased by one.  Note that using @samp{'+} would not  with each element increased by one.  Note that using @samp{'+} would not
33581  work here, since @code{defmath} does not expand function names everywhere,  work here, since @code{defmath} does not expand function names everywhere,
33582  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.
33583  @end defun  @end defun
33584    
33585  @defun reduce-vec f v  @defun reduce-vec f v
# Line 33296  If @var{m} is a matrix, return a copy of Line 33629  If @var{m} is a matrix, return a copy of
33629  element of the result matrix will be @code{eq} to the corresponding  element of the result matrix will be @code{eq} to the corresponding
33630  element of @var{m}, but none of the @code{cons} cells that make up  element of @var{m}, but none of the @code{cons} cells that make up
33631  the structure of the matrix will be @code{eq}.  If @var{m} is a plain  the structure of the matrix will be @code{eq}.  If @var{m} is a plain
33632  vector, this is the same as @code{copy-sequence}.@refill  vector, this is the same as @code{copy-sequence}.
33633  @end defun  @end defun
33634    
33635  @defun swap-rows m r1 r2  @defun swap-rows m r1 r2
# Line 33305  other words, unlike most of the other fu Line 33638  other words, unlike most of the other fu
33638  function changes @var{m} itself rather than building up a new result  function changes @var{m} itself rather than building up a new result
33639  matrix.  The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)}  matrix.  The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)}
33640  is true, with the side effect of exchanging the first two rows of  is true, with the side effect of exchanging the first two rows of
33641  @var{m}.@refill  @var{m}.
33642  @end defun  @end defun
33643    
33644  @node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp Functions, Internals  @node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp Functions, Internals
# Line 33443  to @samp{x}, which is only valid when @v Line 33776  to @samp{x}, which is only valid when @v
33776  implemented by temporarily binding the variable @code{math-living-dangerously}  implemented by temporarily binding the variable @code{math-living-dangerously}
33777  to @code{t} (using a @code{let} form) and calling @code{simplify}.  to @code{t} (using a @code{let} form) and calling @code{simplify}.
33778  Dangerous simplification rules are written to check this variable  Dangerous simplification rules are written to check this variable
33779  before taking any action.@refill  before taking any action.
33780  @end defun  @end defun
33781    
33782  @defun simplify-units expr  @defun simplify-units expr
# Line 33465  the functions @var{funcs}.  If the funct Line 33798  the functions @var{funcs}.  If the funct
33798  if it returns a result @code{equal} to the original @code{expr}, it is  if it returns a result @code{equal} to the original @code{expr}, it is
33799  ignored and Calc goes on to try the next simplification rule that applies.  ignored and Calc goes on to try the next simplification rule that applies.
33800  If the function body returns something different, that new formula is  If the function body returns something different, that new formula is
33801  substituted for @var{expr} in the original formula.@refill  substituted for @var{expr} in the original formula.
33802    
33803  At each point in the formula, rules are tried in the order of the  At each point in the formula, rules are tried in the order of the
33804  original calls to @code{math-defsimplify}; the search stops after the  original calls to @code{math-defsimplify}; the search stops after the
# Line 33498  convenient.  Here is a typical example o Line 33831  convenient.  Here is a typical example o
33831  This is really a pair of rules written with one @code{math-defsimplify}  This is really a pair of rules written with one @code{math-defsimplify}
33832  for convenience; the first replaces @samp{arcsinh(-x)} with  for convenience; the first replaces @samp{arcsinh(-x)} with
33833  @samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x},  @samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x},
33834  replaces @samp{arcsinh(sinh(x))} with @samp{x}.@refill  replaces @samp{arcsinh(sinh(x))} with @samp{x}.
33835  @end defmac  @end defmac
33836    
33837  @defun common-constant-factor expr  @defun common-constant-factor expr
# Line 33533  Compute a ``rational GCD'' of @var{a} an Line 33866  Compute a ``rational GCD'' of @var{a} an
33866  rational numbers.  This is the fraction composed of the GCD of the  rational numbers.  This is the fraction composed of the GCD of the
33867  numerators of @var{a} and @var{b}, over the GCD of the denominators.  numerators of @var{a} and @var{b}, over the GCD of the denominators.
33868  It is used by @code{common-constant-factor}.  Note that the standard  It is used by @code{common-constant-factor}.  Note that the standard
33869  @code{gcd} function uses the LCM to combine the denominators.@refill  @code{gcd} function uses the LCM to combine the denominators.
33870  @end defun  @end defun
33871    
33872  @defun map-tree func expr many  @defun map-tree func expr many
# Line 33548  is returned by @code{map-tree}.  Note th Line 33881  is returned by @code{map-tree}.  Note th
33881  @var{func} functions may @emph{not} make destructive changes to  @var{func} functions may @emph{not} make destructive changes to
33882  @var{expr}.  If a third argument @var{many} is provided, it is an  @var{expr}.  If a third argument @var{many} is provided, it is an
33883  integer which says how many times @var{func} may be applied; the  integer which says how many times @var{func} may be applied; the
33884  default, as described above, is infinitely many times.@refill  default, as described above, is infinitely many times.
33885  @end defun  @end defun
33886    
33887  @defun compile-rewrites rules  @defun compile-rewrites rules
# Line 33665  relying on the general integration-by-su Line 33998  relying on the general integration-by-su
33998  cosines of more complicated arguments.  An integration rule should return  cosines of more complicated arguments.  An integration rule should return
33999  @code{nil} if it can't do the integral; if several rules are defined for  @code{nil} if it can't do the integral; if several rules are defined for
34000  the same function, they are tried in order until one returns a non-@code{nil}  the same function, they are tried in order until one returns a non-@code{nil}
34001  result.@refill  result.
34002  @end defmac  @end defmac
34003    
34004  @defmac math-defintegral-2 funcs body  @defmac math-defintegral-2 funcs body
34005  Define a rule for integrating a function or functions of two arguments.  Define a rule for integrating a function or functions of two arguments.
34006  This is exactly analogous to @code{math-defintegral}, except that @var{body}  This is exactly analogous to @code{math-defintegral}, except that @var{body}
34007  is written as the body of a function with two arguments, @var{u} and  is written as the body of a function with two arguments, @var{u} and
34008  @var{v}.@refill  @var{v}.
34009  @end defmac  @end defmac
34010    
34011  @defun solve-for lhs rhs var full  @defun solve-for lhs rhs var full
# Line 33685  different from the user-level @code{solv Line 34018  different from the user-level @code{solv
34018  which return a rearranged equation or a functional inverse, respectively.  which return a rearranged equation or a functional inverse, respectively.
34019  If @var{full} is non-@code{nil}, a full solution including dummy signs  If @var{full} is non-@code{nil}, a full solution including dummy signs
34020  and dummy integers will be produced.  User-defined inverses are provided  and dummy integers will be produced.  User-defined inverses are provided
34021  as properties in a manner similar to derivatives:@refill  as properties in a manner similar to derivatives:
34022    
34023  @smallexample  @smallexample
34024  (put 'calcFunc-ln 'math-inverse  (put 'calcFunc-ln 'math-inverse
# Line 33721  This function might seem at first to be Line 34054  This function might seem at first to be
34054  @code{expr-contains} uses @code{equal} to test for matches, whereas  @code{expr-contains} uses @code{equal} to test for matches, whereas
34055  @code{calc-find-sub-formula} uses @code{eq}.  In the formula  @code{calc-find-sub-formula} uses @code{eq}.  In the formula
34056  @samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not  @samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not
34057  @code{eq} to each other.@refill  @code{eq} to each other.
34058  @end defun  @end defun
34059    
34060  @defun expr-contains-count expr var  @defun expr-contains-count expr var
34061  Returns the number of occurrences of @var{var} as a subexpression  Returns the number of occurrences of @var{var} as a subexpression
34062  of @var{expr}, or @code{nil} if there are no occurrences.@refill  of @var{expr}, or @code{nil} if there are no occurrences.
34063  @end defun  @end defun
34064    
34065  @defun expr-depends expr var  @defun expr-depends expr var
# Line 33744  contains only constants and functions wi Line 34077  contains only constants and functions wi
34077  Returns a copy of @var{expr}, with all occurrences of @var{old} replaced  Returns a copy of @var{expr}, with all occurrences of @var{old} replaced
34078  by @var{new}.  This treats @code{lambda} forms specially with respect  by @var{new}.  This treats @code{lambda} forms specially with respect
34079  to the dummy argument variables, so that the effect is always to return  to the dummy argument variables, so that the effect is always to return
34080  @var{expr} evaluated at @var{old} = @var{new}.@refill  @var{expr} evaluated at @var{old} = @var{new}.
34081  @end defun  @end defun
34082    
34083  @defun multi-subst expr old new  @defun multi-subst expr old new
# Line 33763  number of objects and function calls tha Line 34096  number of objects and function calls tha
34096  @defun expr-height expr  @defun expr-height expr
34097  Returns the ``height'' of @var{expr}, which is the deepest level to  Returns the ``height'' of @var{expr}, which is the deepest level to
34098  which function calls are nested.  (Note that @samp{@var{a} + @var{b}}  which function calls are nested.  (Note that @samp{@var{a} + @var{b}}
34099  counts as a function call.)  For primitive objects, this returns zero.@refill  counts as a function call.)  For primitive objects, this returns zero.
34100  @end defun  @end defun
34101    
34102  @defun polynomial-p expr var  @defun polynomial-p expr var
# Line 33775  for @samp{(x^2 + 3)^3 + 4} this would re Line 34108  for @samp{(x^2 + 3)^3 + 4} this would re
34108  (@code{calc-expand}), would consist of a sum of terms in which @var{var}  (@code{calc-expand}), would consist of a sum of terms in which @var{var}
34109  appears only raised to nonnegative integer powers.  Note that if  appears only raised to nonnegative integer powers.  Note that if
34110  @var{var} does not occur in @var{expr}, then @var{expr} is considered  @var{var} does not occur in @var{expr}, then @var{expr} is considered
34111  a polynomial of degree 0.@refill  a polynomial of degree 0.
34112  @end defun  @end defun
34113    
34114  @defun is-polynomial expr var degree loose  @defun is-polynomial expr var degree loose
# Line 33797  is used in which coefficients are no lon Line 34130  is used in which coefficients are no lon
34130  themselves.  For example, @samp{sin(x) x^2 + cos(x)} is a loose  themselves.  For example, @samp{sin(x) x^2 + cos(x)} is a loose
34131  polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin  polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin
34132  x))}.  The result will never be @code{nil} in loose mode, since any  x))}.  The result will never be @code{nil} in loose mode, since any
34133  expression can be interpreted as a ``constant'' loose polynomial.@refill  expression can be interpreted as a ``constant'' loose polynomial.
34134  @end defun  @end defun
34135    
34136  @defun polynomial-base expr pred  @defun polynomial-base expr pred
# Line 33810  the original @var{expr}) is a suitable p Line 34143  the original @var{expr}) is a suitable p
34143  The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})};  The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})};
34144  you can use @var{pred} to specify additional conditions.  Or, you could  you can use @var{pred} to specify additional conditions.  Or, you could
34145  have @var{pred} build up a list of every suitable @var{subexpr} that  have @var{pred} build up a list of every suitable @var{subexpr} that
34146  is found.@refill  is found.
34147  @end defun  @end defun
34148    
34149  @defun poly-simplify poly  @defun poly-simplify poly
# Line 33822  clipping off trailing zeros. Line 34155  clipping off trailing zeros.
34155  Mix two polynomial lists @var{a} and @var{b} (in the form returned by  Mix two polynomial lists @var{a} and @var{b} (in the form returned by
34156  @code{is-polynomial}) in a linear combination with coefficient expressions  @code{is-polynomial}) in a linear combination with coefficient expressions
34157  @var{ac} and @var{bc}.  The result is a (not necessarily simplified)  @var{ac} and @var{bc}.  The result is a (not necessarily simplified)
34158  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}}.
34159  @end defun  @end defun
34160    
34161  @defun poly-mul a b  @defun poly-mul a b
# Line 33835  Construct a Calc formula which represent Line 34168  Construct a Calc formula which represent
34168  list @var{poly} applied to variable @var{var}.  The @kbd{a c}  list @var{poly} applied to variable @var{var}.  The @kbd{a c}
34169  (@code{calc-collect}) command uses @code{is-polynomial} to turn an  (@code{calc-collect}) command uses @code{is-polynomial} to turn an
34170  expression into a coefficient list, then @code{build-polynomial-expr}  expression into a coefficient list, then @code{build-polynomial-expr}
34171  to turn the list back into an expression in regular form.@refill  to turn the list back into an expression in regular form.
34172  @end defun  @end defun
34173    
34174  @defun check-unit-name var  @defun check-unit-name var
# Line 33852  is not a variable or is not a unit name, Line 34185  is not a variable or is not a unit name,
34185  Return true if @var{expr} contains any variables which can be  Return true if @var{expr} contains any variables which can be
34186  interpreted as units.  If @var{sub-exprs} is @code{t}, the entire  interpreted as units.  If @var{sub-exprs} is @code{t}, the entire
34187  expression is searched.  If @var{sub-exprs} is @code{nil}, this  expression is searched.  If @var{sub-exprs} is @code{nil}, this
34188  checks whether @var{expr} is directly a units expression.@refill  checks whether @var{expr} is directly a units expression.
34189  @end defun  @end defun
34190    
34191  @defun single-units-in-expr-p expr  @defun single-units-in-expr-p expr
# Line 33867  Convert units expression @var{expr} to b Line 34200  Convert units expression @var{expr} to b
34200  is @code{nil}, use Calc's native base units.  Otherwise, @var{which}  is @code{nil}, use Calc's native base units.  Otherwise, @var{which}
34201  can specify a units system, which is a list of two-element lists,  can specify a units system, which is a list of two-element lists,
34202  where the first element is a Calc base symbol name and the second  where the first element is a Calc base symbol name and the second
34203  is an expression to substitute for it.@refill  is an expression to substitute for it.
34204  @end defun  @end defun
34205    
34206  @defun remove-units expr  @defun remove-units expr
# Line 33903  Read an algebraic expression from string Line 34236  Read an algebraic expression from string
34236  not have the form of a valid expression, return a list of the form  not have the form of a valid expression, return a list of the form
34237  @samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index  @samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index
34238  into @var{str} of the general location of the error, and @var{msg} is  into @var{str} of the general location of the error, and @var{msg} is
34239  a string describing the problem.@refill  a string describing the problem.
34240  @end defun  @end defun
34241    
34242  @defun read-exprs str  @defun read-exprs str
# Line 33922  given, it is a string which the minibuff Line 34255  given, it is a string which the minibuff
34255  If @var{prompt} is given, it is the prompt string to use; the default  If @var{prompt} is given, it is the prompt string to use; the default
34256  is ``Algebraic:''.  If @var{no-norm} is @code{t}, the formulas will  is ``Algebraic:''.  If @var{no-norm} is @code{t}, the formulas will
34257  be returned exactly as parsed; otherwise, they will be passed through  be returned exactly as parsed; otherwise, they will be passed through
34258  @code{calc-normalize} first.@refill  @code{calc-normalize} first.
34259    
34260  To support the use of @kbd{$} characters in the algebraic entry, use  To support the use of @kbd{$} characters in the algebraic entry, use
34261  @code{let} to bind @code{calc-dollar-values} to a list of the values  @code{let} to bind @code{calc-dollar-values} to a list of the values
34262  to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind  to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind
34263  @code{calc-dollar-used} to 0.  Upon return, @code{calc-dollar-used}  @code{calc-dollar-used} to 0.  Upon return, @code{calc-dollar-used}
34264  will have been changed to the highest number of consecutive @kbd{$}s  will have been changed to the highest number of consecutive @kbd{$}s
34265  that actually appeared in the input.@refill  that actually appeared in the input.
34266  @end defun  @end defun
34267    
34268  @defun format-number a  @defun format-number a
# Line 33945  mostly to guarantee the string is of a f Line 34278  mostly to guarantee the string is of a f
34278  complex number format, and point character, are ignored to ensure the  complex number format, and point character, are ignored to ensure the
34279  result will be re-readable.  The @var{prec} parameter is normally 0; if  result will be re-readable.  The @var{prec} parameter is normally 0; if
34280  you pass a large integer like 1000 instead, the expression will be  you pass a large integer like 1000 instead, the expression will be
34281  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.
34282  @end defun  @end defun
34283    
34284  @defun format-nice-expr a width  @defun format-nice-expr a width
# Line 33964  grouping.  Multi-line objects like matri Line 34297  grouping.  Multi-line objects like matri
34297  contain newline characters to separate the lines.  The @var{w}  contain newline characters to separate the lines.  The @var{w}
34298  parameter, if given, is the target window size for which to format  parameter, if given, is the target window size for which to format
34299  the expressions.  If @var{w} is omitted, the width of the Calculator  the expressions.  If @var{w} is omitted, the width of the Calculator
34300  window is used.@refill  window is used.
34301  @end defun  @end defun
34302    
34303  @defun compose-expr a prec  @defun compose-expr a prec
# Line 34012  the baseline.  For a one-line compositio Line 34345  the baseline.  For a one-line compositio
34345  @defun comp-first-char c  @defun comp-first-char c
34346  If composition @var{c} is a ``flat'' composition, return the first  If composition @var{c} is a ``flat'' composition, return the first
34347  (leftmost) character of the composition as an integer.  Otherwise,  (leftmost) character of the composition as an integer.  Otherwise,
34348  return @code{nil}.@refill  return @code{nil}.
34349  @end defun  @end defun
34350    
34351  @defun comp-last-char c  @defun comp-last-char c
# Line 34192  you should add a command to set the Lisp Line 34525  you should add a command to set the Lisp
34525  to the appropriate file name.  You may also need to change the variables  to the appropriate file name.  You may also need to change the variables
34526  @code{calc-gnuplot-plot-command} and @code{calc-gnuplot-print-command} in  @code{calc-gnuplot-plot-command} and @code{calc-gnuplot-print-command} in
34527  order to get correct displays and hardcopies, respectively, of your  order to get correct displays and hardcopies, respectively, of your
34528  plots.@refill  plots.
34529    
34530  @ifinfo  @ifinfo
34531  @example  @example
# Line 34207  copy if you really need it.  To print th Line 34540  copy if you really need it.  To print th
34540  @TeX{} typesetting program (this is a free program by Donald Knuth  @TeX{} typesetting program (this is a free program by Donald Knuth
34541  at Stanford University) as well as the @file{texindex} program and  at Stanford University) as well as the @file{texindex} program and
34542  @file{texinfo.tex} file, both of which can be obtained from the FSF  @file{texinfo.tex} file, both of which can be obtained from the FSF
34543  as part of the @code{texinfo} package.@refill  as part of the @code{texinfo} package.
34544    
34545  To print the Calc manual in one huge 470 page tome, you will need the  To print the Calc manual in one huge 470 page tome, you will need the
34546  source code to this manual, @file{calc.texi}, available as part of the  source code to this manual, @file{calc.texi}, available as part of the
# Line 34253  is @code{"~/.emacs"}.  If @code{calc-set Line 34586  is @code{"~/.emacs"}.  If @code{calc-set
34586  @code{".emacs"} as a substring, and if the variable  @code{".emacs"} as a substring, and if the variable
34587  @code{calc-loaded-settings-file} is @code{nil}, then Calc will  @code{calc-loaded-settings-file} is @code{nil}, then Calc will
34588  automatically load your settings file (if it exists) the first time  automatically load your settings file (if it exists) the first time
34589  Calc is invoked.@refill  Calc is invoked.
34590    
34591  @ifinfo  @ifinfo
34592  @example  @example
# Line 35194  NOTES Line 35527  NOTES
35527  @enumerate  @enumerate
35528  @c 1  @c 1
35529  @item  @item
35530  Positive prefix arguments apply to @cite{n} stack entries.  Positive prefix arguments apply to @expr{n} stack entries.
35531  Negative prefix arguments apply to the @cite{-n}th stack entry.  Negative prefix arguments apply to the @expr{-n}th stack entry.
35532  A prefix of zero applies to the entire stack.  (For @key{LFD} and  A prefix of zero applies to the entire stack.  (For @key{LFD} and
35533  @kbd{M-@key{DEL}}, the meaning of the sign is reversed.)  @kbd{M-@key{DEL}}, the meaning of the sign is reversed.)
35534    
35535  @c 2  @c 2
35536  @item  @item
35537  Positive prefix arguments apply to @cite{n} stack entries.  Positive prefix arguments apply to @expr{n} stack entries.
35538  Negative prefix arguments apply to the top stack entry  Negative prefix arguments apply to the top stack entry
35539  and the next @cite{-n} stack entries.  and the next @expr{-n} stack entries.
35540    
35541  @c 3  @c 3
35542  @item  @item
35543  Positive prefix arguments rotate top @cite{n} stack entries by one.  Positive prefix arguments rotate top @expr{n} stack entries by one.
35544  Negative prefix arguments rotate the entire stack by @cite{-n}.  Negative prefix arguments rotate the entire stack by @expr{-n}.
35545  A prefix of zero reverses the entire stack.  A prefix of zero reverses the entire stack.
35546    
35547  @c 4  @c 4
# Line 35217  Prefix argument specifies a repeat count Line 35550  Prefix argument specifies a repeat count
35550    
35551  @c 5  @c 5
35552  @item  @item
35553  Positive prefix arguments specify a precision @cite{p}.  Positive prefix arguments specify a precision @expr{p}.
35554  Negative prefix arguments reduce the current precision by @cite{-p}.  Negative prefix arguments reduce the current precision by @expr{-p}.
35555    
35556  @c 6  @c 6
35557  @item  @item
# Line 35236  A negative prefix operates only on the t Line 35569  A negative prefix operates only on the t
35569    
35570  @c 9  @c 9
35571  @item  @item
35572  Positive prefix arguments specify a word size of @cite{w} bits, unsigned.  Positive prefix arguments specify a word size of @expr{w} bits, unsigned.
35573  Negative prefix arguments specify a word size of @cite{w} bits, signed.  Negative prefix arguments specify a word size of @expr{w} bits, signed.
35574    
35575  @c 10  @c 10
35576  @item  @item
35577  Prefix arguments specify the shift amount @cite{n}.  The @cite{w} argument  Prefix arguments specify the shift amount @expr{n}.  The @expr{w} argument
35578  cannot be specified in the keyboard version of this command.  cannot be specified in the keyboard version of this command.
35579    
35580  @c 11  @c 11
35581  @item  @item
35582  From the keyboard, @cite{d} is omitted and defaults to zero.  From the keyboard, @expr{d} is omitted and defaults to zero.
35583    
35584  @c 12  @c 12
35585  @item  @item
# Line 35259  Some prefix argument values provide spec Line 35592  Some prefix argument values provide spec
35592    
35593  @c 14  @c 14
35594  @item  @item
35595  A prefix argument, if any, is used for @cite{m} instead of taking  A prefix argument, if any, is used for @expr{m} instead of taking
35596  @cite{m} from the stack.  @cite{M} may take any of these values:  @expr{m} from the stack.  @expr{M} may take any of these values:
35597  @iftex  @iftex
35598  {@advance@tableindent10pt  {@advance@tableindent10pt
35599  @end iftex  @end iftex
35600  @table @asis  @table @asis
35601  @item Integer  @item Integer
35602  Random integer in the interval @cite{[0 .. m)}.  Random integer in the interval @expr{[0 .. m)}.
35603  @item Float  @item Float
35604  Random floating-point number in the interval @cite{[0 .. m)}.  Random floating-point number in the interval @expr{[0 .. m)}.
35605  @item 0.0  @item 0.0
35606  Gaussian with mean 1 and standard deviation 0.  Gaussian with mean 1 and standard deviation 0.
35607  @item Error form  @item Error form
# Line 35308  input data set.  Each entry may be a sin Line 35641  input data set.  Each entry may be a sin
35641    
35642  @c 20  @c 20
35643  @item  @item
35644  With a prefix argument of 1, take a single @c{$@var{n}\times2$}  With a prefix argument of 1, take a single
35645  @i{@var{N}x2} matrix from the  @texline @tmath{@var{n}\times2}
35646  stack instead of two separate data vectors.  @infoline @i{@var{N}x2}
35647    matrix from the stack instead of two separate data vectors.
35648    
35649  @c 21  @c 21
35650  @item  @item
35651  The row or column number @cite{n} may be given as a numeric prefix  The row or column number @expr{n} may be given as a numeric prefix
35652  argument instead.  A plain @kbd{C-u} prefix says to take @cite{n}  argument instead.  A plain @kbd{C-u} prefix says to take @expr{n}
35653  from the top of the stack.  If @cite{n} is a vector or interval,  from the top of the stack.  If @expr{n} is a vector or interval,
35654  a subvector/submatrix of the input is created.  a subvector/submatrix of the input is created.
35655    
35656  @c 22  @c 22
35657  @item  @item
35658  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
35659  desired function, or with @kbd{x} or @kbd{z} followed by a function name,  desired function, or with @kbd{x} or @kbd{z} followed by a function name,
35660  or with @kbd{$} to take a formula from the top of the stack, or with  or with @kbd{$} to take a formula from the top of the stack, or with
35661  @kbd{'} and a typed formula.  In the last two cases, the formula may  @kbd{'} and a typed formula.  In the last two cases, the formula may
# Line 35336  stack by @kbd{V M} depends on the number Line 35670  stack by @kbd{V M} depends on the number
35670  One of the mapping direction keys @kbd{_} (horizontal, i.e., map  One of the mapping direction keys @kbd{_} (horizontal, i.e., map
35671  by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or  by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or
35672  reduce down), or @kbd{=} (map or reduce by rows) may be used before  reduce down), or @kbd{=} (map or reduce by rows) may be used before
35673  entering @cite{op}; these modify the function name by adding the letter  entering @expr{op}; these modify the function name by adding the letter
35674  @code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,''  @code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,''
35675  or @code{d} for ``down.''  or @code{d} for ``down.''
35676    
# Line 35374  may be an integer or a vector of integer Line 35708  may be an integer or a vector of integer
35708  @item -11  @item -11
35709  (@var{2})  Float with integer mantissa.  (@var{2})  Float with integer mantissa.
35710  @item -12  @item -12
35711  (@var{2})  Float with mantissa in @cite{[1 .. 10)}.  (@var{2})  Float with mantissa in @expr{[1 .. 10)}.
35712  @item -13  @item -13
35713  (@var{1})  Date form (using date numbers).  (@var{1})  Date form (using date numbers).
35714  @item -14  @item -14
# Line 35388  may be an integer or a vector of integer Line 35722  may be an integer or a vector of integer
35722    
35723  @c 25  @c 25
35724  @item  @item
35725  A prefix argument specifies the size @cite{n} of the matrix.  With no  A prefix argument specifies the size @expr{n} of the matrix.  With no
35726  prefix argument, @cite{n} is omitted and the size is inferred from  prefix argument, @expr{n} is omitted and the size is inferred from
35727  the input vector.  the input vector.
35728    
35729  @c 26  @c 26
35730  @item  @item
35731  The prefix argument specifies the starting position @cite{n} (default 1).  The prefix argument specifies the starting position @expr{n} (default 1).
35732    
35733  @c 27  @c 27
35734  @item  @item
# Line 35460  later prompts by popping additional stac Line 35794  later prompts by popping additional stac
35794    
35795  @c 39  @c 39
35796  @item  @item
35797  Answer for @cite{v} may also be of the form @cite{v = v_0} or  Answer for @expr{v} may also be of the form @expr{v = v_0} or
35798  @cite{v - v_0}.  @expr{v - v_0}.
35799    
35800  @c 40  @c 40
35801  @item  @item
35802  With a positive prefix argument, stack contains many @cite{y}'s and one  With a positive prefix argument, stack contains many @expr{y}'s and one
35803  common @cite{x}.  With a zero prefix, stack contains a vector of  common @expr{x}.  With a zero prefix, stack contains a vector of
35804  @cite{y}s and a common @cite{x}.  With a negative prefix, stack  @expr{y}s and a common @expr{x}.  With a negative prefix, stack
35805  contains many @cite{[x,y]} vectors.  (For 3D plots, substitute  contains many @expr{[x,y]} vectors.  (For 3D plots, substitute
35806  @cite{z} for @cite{y} and @cite{x,y} for @cite{x}.)  @expr{z} for @expr{y} and @expr{x,y} for @expr{x}.)
35807    
35808  @c 41  @c 41
35809  @item  @item
# Line 35504  in stack level three, and causes the for Line 35838  in stack level three, and causes the for
35838  stack levels.  The notation @kbd{$3} refers to stack level three without  stack levels.  The notation @kbd{$3} refers to stack level three without
35839  causing that value to be removed from the stack.  Use @key{LFD} in place  causing that value to be removed from the stack.  Use @key{LFD} in place
35840  of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET}  of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET}
35841  to evaluate variables.@refill  to evaluate variables.
35842    
35843  @c 47  @c 47
35844  @item  @item
35845  The variable is replaced by the formula shown on the right.  The  The variable is replaced by the formula shown on the right.  The
35846  Inverse flag reverses the order of the operands, e.g., @kbd{I s - x}  Inverse flag reverses the order of the operands, e.g., @kbd{I s - x}
35847  assigns @c{$x \coloneq a-x$}  assigns
35848  @cite{x := a-x}.  @texline @tmath{x \coloneq a-x}.
35849    @infoline @expr{x := a-x}.
35850    
35851  @c 48  @c 48
35852  @item  @item
35853  Press @kbd{?} repeatedly to see how to choose a model.  Answer the  Press @kbd{?} repeatedly to see how to choose a model.  Answer the
35854  variables prompt with @cite{iv} or @cite{iv;pv} to specify  variables prompt with @expr{iv} or @expr{iv;pv} to specify
35855  independent and parameter variables.  A positive prefix argument  independent and parameter variables.  A positive prefix argument
35856  takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix  takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix
35857  and a vector from the stack.  and a vector from the stack.

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26