[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacsdiffs] Changes to emacs/man/calc.texi [emacsunicode2]
From: 
Miles Bader 
Subject: 
[Emacsdiffs] Changes to emacs/man/calc.texi [emacsunicode2] 
Date: 
Wed, 08 Dec 2004 02:04:00 0500 
Index: emacs/man/calc.texi
diff c emacs/man/calc.texi:1.15.6.5 emacs/man/calc.texi:1.15.6.6
*** emacs/man/calc.texi:1.15.6.5 Fri Oct 22 10:13:37 2004
 emacs/man/calc.texi Wed Dec 8 05:02:23 2004
***************
*** 7,39 ****
@setchapternewpage odd
@comment %**end of header (This is for running Texinfo on a region.)
@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 littleused existing commands.
 %
% Suggested by Karl Berry <karl@@freefriends.org>
\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{texstuff} \n @whatever{infostuff}.
 \gdef\c{\futurelet\next\mycxxx}
 \gdef\mycxxx{%
 \ifx\next\bgroup \goodtex\let\next\mycxxy
 \else\ifx\next\mindex \let\next\relax
 \else\ifx\next\kindex \let\next\relax
 \else\ifx\next\starindex \let\next\relax \else \let\next\comment
 \fi\fi\fi\fi \next
 }
 \gdef\mycxxy#1#2{#1\Etex\mycxxz}
 \gdef\mycxxz#1{}
@end tex
@c Fix some other things specifically for this manual.
 7,66 
@setchapternewpage odd
@comment %**end of header (This is for running Texinfo on a region.)
+ @c The following macros are used for conditional output for single lines.
+ @c @texline foo
+ @c `foo' will appear only in TeX output
+ @c @infoline foo
+ @c `foo' will appear only in nonTeX output
+
+ @c In TeX output, @tmath{expr} will typeset expr in math mode.
+ @c In any output, @expr{expr} will typeset an expression;
+ @c $x$ in TeX, @samp{x} otherwise.
+
+ @iftex
+ @macro texline{stuff}
+ \stuff\
+ @end macro
+ @macro tmath{stuff}
+ @tex
+ $\stuff\$
+ @end tex
+ @end macro
+ @alias infoline=comment
+ @c @alias expr=math
+ @tex
+ \gdef\expr#1{\tex
+ \let\t\ttfont
+ \turnoffactive
+ $#1$
+ \endgroup}
+ @end tex
+ @macro cpi{}
+ @address@hidden
+ @end macro
+ @macro cpiover{den}
+ @address@hidden/\den\}
+ @end macro
+ @end iftex
+
+ @ifnottex
+ @alias texline=comment
+ @macro infoline{stuff}
+ \stuff\
+ @end macro
+ @alias expr=samp
+ @macro cpi{}
+ @expr{pi}
+ @end macro
+ @macro cpiover{den}
+ @expr{pi/\den\}
+ @end macro
+ @end ifnottex
+
+
@tex
% Suggested by Karl Berry <karl@@freefriends.org>
\gdef\!{\mskip\thinmuskip}
@end tex
@c Fix some other things specifically for this manual.
***************
*** 513,520 ****
@cindex Marginal notes
Every Calc keyboard command is listed in the Calc Summary, and also
in the Key Index. Algebraic functions, @kbd{Mx} commands, and
! variables also have their own indices. @c{Each}
! @asis{In the printed manual, each}
paragraph that is referenced in the Key or Function Index is marked
in the margin with its index entry.
 540,548 
@cindex Marginal notes
Every Calc keyboard command is listed in the Calc Summary, and also
in the Key Index. Algebraic functions, @kbd{Mx} commands, and
! variables also have their own indices.
! @texline Each
! @infoline In the printed manual, each
paragraph that is referenced in the Key or Function Index is marked
in the margin with its index entry.
***************
*** 570,576 ****
be @samp{cos(@var{x})}.
A few commands don't have key equivalents: @code{calcsincos}
! address@hidden@refill
@node Demonstration of Calc, Using Calc, Notations Used in This Manual,
Getting Started
@section A Demonstration of Calc
 598,604 
be @samp{cos(@var{x})}.
A few commands don't have key equivalents: @code{calcsincos}
! address@hidden
@node Demonstration of Calc, Using Calc, Notations Used in This Manual,
Getting Started
@section A Demonstration of Calc
***************
*** 595,606 ****
then the command to operate on the numbers.
@noindent
! Type @kbd{2 @key{RET} 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$}
! @asis{the square root of 2+3, which is 2.2360679775}.
@noindent
! Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$}
! @asis{the value of `pi' squared, 9.86960440109}.
@noindent
Type @key{TAB} to exchange the order of these two results.
 623,636 
then the command to operate on the numbers.
@noindent
! Type @kbd{2 @key{RET} 3 + Q} to compute
! @texline @tmath{\sqrt{2+3} = 2.2360679775}.
! @infoline the square root of 2+3, which is 2.2360679775.
@noindent
! Type @kbd{P 2 ^} to compute
! @texline @tmath{\pi^2 = 9.86960440109}.
! @infoline the value of `pi' squared, 9.86960440109.
@noindent
Type @key{TAB} to exchange the order of these two results.
***************
*** 617,629 ****
use the apostrophe key.
@noindent
! Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$}
! @asis{the square root of 2+3}.
@noindent
! Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$}
! @asis{`pi' squared}. To evaluate this symbolic
! formula as a number, type @kbd{=}.
@noindent
Type @kbd{' arcsinh($  $$) @key{RET}} to subtract the secondmostrecent
 647,661 
use the apostrophe key.
@noindent
! Type @kbd{' sqrt(2+3) @key{RET}} to compute
! @texline @tmath{\sqrt{2+3}}.
! @infoline the square root of 2+3.
@noindent
! Type @kbd{' pi^2 @key{RET}} to enter
! @texline @tmath{\pi^2}.
! @infoline `pi' squared.
! To evaluate this symbolic formula as a number, type @kbd{=}.
@noindent
Type @kbd{' arcsinh($  $$) @key{RET}} to subtract the secondmostrecent
***************
*** 680,691 ****
the lowerright @samp{8} and press @kbd{M# r}.
@noindent
! Type @kbd{v t} to transpose this @c{$3\times2$}
! @asis{3x2} matrix into a @c{$2\times3$}
! @asis{2x3} matrix. Type
! @address@hidden u}} to unpack the rows into two separate vectors. Now type
! @address@hidden R + @key{TAB} V R +}} to compute the sums of the two original
columns.
! (There is also a special grabandsumcolumns command, @kbd{M# :}.)
@strong{Units conversion.} Units are entered algebraically.
Type @address@hidden' 43 mi/hr @key{RET}}} to enter the quantity 43
milesperhour.
 712,727 
the lowerright @samp{8} and press @kbd{M# r}.
@noindent
! Type @kbd{v t} to transpose this
! @texline @tmath{3\times2}
! @infoline 3x2
! matrix into a
! @texline @tmath{2\times3}
! @infoline 2x3
! matrix. Type @address@hidden u}} to unpack the rows into two separate
! vectors. Now type @address@hidden R + @key{TAB} V R +}} to compute the sums
! of the two original columns. (There is also a special
! grabandsumcolumns command, @kbd{M# :}.)
@strong{Units conversion.} Units are entered algebraically.
Type @address@hidden' 43 mi/hr @key{RET}}} to enter the quantity 43
milesperhour.
***************
*** 701,707 ****
to enter a pair of equations involving three variables.
(Note the leading apostrophe in this example; also, note that the space
between @samp{x y} is required.) Type @address@hidden S x,y @key{RET}}} to
solve
! these equations for the variables @cite{x} and @address@hidden
@noindent
Type @kbd{d B} to view the solutions in more readable notation.
 737,743 
to enter a pair of equations involving three variables.
(Note the leading apostrophe in this example; also, note that the space
between @samp{x y} is required.) Type @address@hidden S x,y @key{RET}}} to
solve
! these equations for the variables @expr{x} and @expr{y}.
@noindent
Type @kbd{d B} to view the solutions in more readable notation.
***************
*** 710,716 ****
Type @kbd{d N} to return to normal notation.
@noindent
! Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @cite{a = 7.5} in these
formulas.
(That's a letter @kbd{l}, not a numeral @kbd{1}.)
@iftex
 746,752 
Type @kbd{d N} to return to normal notation.
@noindent
! Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @expr{a = 7.5} in these
formulas.
(That's a letter @kbd{l}, not a numeral @kbd{1}.)
@iftex
***************
*** 739,750 ****
different kinds of tasks. As well as Calc's standard interface,
there are Quick Mode, Keypad Mode, and Embedded Mode.
 @c [fixref Installation]
 Calc must be @dfn{installed} before it can be used. @xref{Installation},
 for instructions on setting up and installing Calc. We will assume
 you or someone on your system has already installed Calc as described
 there.

@menu
* Starting Calc::
* The Standard Interface::
 775,780 
***************
*** 769,775 ****
@key{ESC} first, then @kbd{#}, to accomplish the same thing. If you
don't even have an @key{ESC} key, you can fake it by holding down
Control or @key{CTRL} while typing a left square bracket
! (that's @kbd{C[} in Emacs notation)address@hidden
@kbd{M#} is a @dfn{prefix key}; when you press it, Emacs waits for
you to press a second key to complete the command. In this case,
 799,805 
@key{ESC} first, then @kbd{#}, to accomplish the same thing. If you
don't even have an @key{ESC} key, you can fake it by holding down
Control or @key{CTRL} while typing a left square bracket
! (that's @kbd{C[} in Emacs notation).
@kbd{M#} is a @dfn{prefix key}; when you press it, Emacs waits for
you to press a second key to complete the command. In this case,
***************
*** 853,859 ****
Shifted (i.e., uppercase) letters are different from lowercase
letters. Some letters are @dfn{prefix} keys that begin twoletter
commands. For example, @kbd{e} means ``enter exponent'' and shifted
! @kbd{E} means @cite{e^x}. With the @kbd{d} (``display modes'') prefix
the letter ``e'' takes on very different meanings: @kbd{d e} means
``engineering notation'' and @kbd{d E} means address@hidden language mode.''
 883,889 
Shifted (i.e., uppercase) letters are different from lowercase
letters. Some letters are @dfn{prefix} keys that begin twoletter
commands. For example, @kbd{e} means ``enter exponent'' and shifted
! @kbd{E} means @expr{e^x}. With the @kbd{d} (``display modes'') prefix
the letter ``e'' takes on very different meanings: @kbd{d e} means
``engineering notation'' and @kbd{d E} means address@hidden language mode.''
***************
*** 1317,1329 ****
@noindent
Calc was originally started as a twoweek project to occupy a lull
in the author's schedule. Basically, a friend asked if I remembered
! the value of @c{$2^{32}$}
! @cite{2^32}. I didn't offhand, but I said, ``that's
! easy, just call up an @code{xcalc}.'' @code{Xcalc} duly reported
! that the answer to our question was @samp{4.294967e+09}with no way to
! see the full ten digits even though we knew they were there in the
! program's memory! I was so annoyed, I vowed to write a calculator
! of my own, once and for all.
I chose Emacs Lisp, a) because I had always been curious about it
and b) because, being only a text editor extension language after
 1347,1361 
@noindent
Calc was originally started as a twoweek project to occupy a lull
in the author's schedule. Basically, a friend asked if I remembered
! the value of
! @texline @tmath{2^{32}}.
! @infoline @expr{2^32}.
! I didn't offhand, but I said, ``that's easy, just call up an
! @code{xcalc}.'' @code{Xcalc} duly reported that the answer to our
! question was @samp{4.294967e+09}with no way to see the full ten
! digits even though we knew they were there in the program's memory! I
! was so annoyed, I vowed to write a calculator of my own, once and for
! all.
I chose Emacs Lisp, a) because I had always been curious about it
and b) because, being only a text editor extension language after
***************
*** 1373,1390 ****
Many people have contributed to Calc by reporting bugs and suggesting
features, large and small. A few deserve special mention: Tim Peters,
who helped develop the ideas that led to the selection commands, rewrite
! rules, and many other algebra features; @c{Fran\c cois}
! @asis{Francois} Pinard, who contributed
! an early prototype of the Calc Summary appendix as well as providing
! valuable suggestions in many other areas of Calc; Carl Witty, whose eagle
! eyes discovered many typographical and factual errors in the Calc manual;
! Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who
! made many suggestions relating to the algebra commands and contributed
! some code for polynomial operations; Randal Schwartz, who suggested the
! @code{calceval} function; Robert J. Chassell, who suggested the Calc
! Tutorial and exercises; and Juha Sarlin, who first worked out how to split
! Calc into quicklyloading parts. Bob Weiner helped immensely with the
! Lucid Emacs port.
@cindex Bibliography
@cindex Knuth, Art of Computer Programming
 1405,1423 
Many people have contributed to Calc by reporting bugs and suggesting
features, large and small. A few deserve special mention: Tim Peters,
who helped develop the ideas that led to the selection commands, rewrite
! rules, and many other algebra features;
! @texline Fran\c cois
! @infoline Francois
! Pinard, who contributed an early prototype of the Calc Summary appendix
! as well as providing valuable suggestions in many other areas of Calc;
! Carl Witty, whose eagle eyes discovered many typographical and factual
! errors in the Calc manual; Tim Kay, who drove the development of
! Embedded mode; Ove Ewerlid, who made many suggestions relating to the
! algebra commands and contributed some code for polynomial operations;
! Randal Schwartz, who suggested the @code{calceval} function; Robert
! J. Chassell, who suggested the Calc Tutorial and exercises; and Juha
! Sarlin, who first worked out how to split Calc into quicklyloading
! parts. Bob Weiner helped immensely with the Lucid Emacs port.
@cindex Bibliography
@cindex Knuth, Art of Computer Programming
***************
*** 1545,1552 ****
@cindex Operators
@cindex Operands
! In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands}
! and the @cite{+} is the @dfn{operator}. In an RPN calculator you always
enter the operands first, then the operator. Each time you type a
number, Calc adds or @dfn{pushes} it onto the top of the Stack.
When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate
 1578,1585 
@cindex Operators
@cindex Operands
! In an operation like @expr{2+3}, the 2 and 3 are called the @dfn{operands}
! and the @expr{+} is the @dfn{operator}. In an RPN calculator you always
enter the operands first, then the operator. Each time you type a
number, Calc adds or @dfn{pushes} it onto the top of the Stack.
When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate
***************
*** 1560,1566 ****
The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.
The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,
and pushes the result (5) back onto the stack. Here's how the stack
! will look at various points throughout the calculation:@refill
@smallexample
@group
 1593,1599 
The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.
The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,
and pushes the result (5) back onto the stack. Here's how the stack
! will look at various points throughout the calculation:
@smallexample
@group
***************
*** 1581,1591 ****
@cindex Levels of stack
The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level
numbers}. Old RPN calculators always had four stack levels called
! @cite{x}, @cite{y}, @cite{z}, and @cite{t}. Calc's stack can grow
as large as you like, so it uses numbers instead of letters. Some
stackmanipulation commands accept a numeric argument that says
which stack level to work on. Normal commands like @kbd{+} always
! work on the top few levels of the address@hidden
@c [fixref Truncating the Stack]
The Stack buffer is just an Emacs buffer, and you can move around in
 1614,1624 
@cindex Levels of stack
The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level
numbers}. Old RPN calculators always had four stack levels called
! @expr{x}, @expr{y}, @expr{z}, and @expr{t}. Calc's stack can grow
as large as you like, so it uses numbers instead of letters. Some
stackmanipulation commands accept a numeric argument that says
which stack level to work on. Normal commands like @kbd{+} always
! work on the top few levels of the stack.
@c [fixref Truncating the Stack]
The Stack buffer is just an Emacs buffer, and you can move around in
***************
*** 1602,1608 ****
@key{RET} +}. That's because if you type any operator name or
other nonnumeric key when you are entering a number, the Calculator
automatically enters that number and then does the requested command.
! Thus @kbd{2 @key{RET} 3 +} will work just as address@hidden
Examples in this tutorial will often omit @key{RET} even when the
stack displays shown would only happen if you did press @key{RET}:
 1635,1641 
@key{RET} +}. That's because if you type any operator name or
other nonnumeric key when you are entering a number, the Calculator
automatically enters that number and then does the requested command.
! Thus @kbd{2 @key{RET} 3 +} will work just as well.
Examples in this tutorial will often omit @key{RET} even when the
stack displays shown would only happen if you did press @key{RET}:
***************
*** 1636,1644 ****
multiplication.) Figure it out by hand, then try it with Calc to see
if you're right. @xref{RPN Answer 1, 1}. (@bullet{})
! (@bullet{}) @strong{Exercise 2.} Compute @c{$(2\times4) + (7\times9.4) +
{5\over4}$}
! @cite{2*4 + 7*9.5 + 5/4} using the
! stack. @xref{RPN Answer 2, 2}. (@bullet{})
The @key{DEL} key is called Backspace on some keyboards. It is
whatever key you would use to correct a simple typing error when
 1669,1678 
multiplication.) Figure it out by hand, then try it with Calc to see
if you're right. @xref{RPN Answer 1, 1}. (@bullet{})
! (@bullet{}) @strong{Exercise 2.} Compute
! @texline @tmath{(2\times4) + (7\times9.4) + {5\over4}}
! @infoline @expr{2*4 + 7*9.5 + 5/4}
! using the stack. @xref{RPN Answer 2, 2}. (@bullet{})
The @key{DEL} key is called Backspace on some keyboards. It is
whatever key you would use to correct a simple typing error when
***************
*** 1690,1696 ****
Another stack manipulation key is @key{TAB}. This exchanges the top
two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +}
to get 5, and then you realize what you really wanted to compute
! was @cite{20 / (2+3)}.
@smallexample
@group
 1724,1730 
Another stack manipulation key is @key{TAB}. This exchanges the top
two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +}
to get 5, and then you realize what you really wanted to compute
! was @expr{20 / (2+3)}.
@smallexample
@group
***************
*** 1798,1808 ****
@end smallexample
@noindent
! The notation @cite{(a, b)} represents a complex number.
! Complex numbers are more traditionally written @c{$a + b i$}
! @cite{a + b i};
Calc can display in this format, too, but for now we'll stick to the
! @cite{(a, b)} notation.
If you don't know how complex numbers work, you can safely ignore this
feature. Complex numbers only arise from operations that would be
 1832,1841 
@end smallexample
@noindent
! The notation @expr{(a, b)} represents a complex number.
! Complex numbers are more traditionally written @expr{a + b i};
Calc can display in this format, too, but for now we'll stick to the
! @expr{(a, b)} notation.
If you don't know how complex numbers work, you can safely ignore this
feature. Complex numbers only arise from operations that would be
***************
*** 1861,1867 ****
entry and the top are collected, so there's never really a reason
to use the comma. It's up to you.
! (@bullet{}) @strong{Exercise 4.} To enter the complex number @cite{(2, 3)},
your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened?
(Joe thought of a clever way to correct his mistake in only two
keystrokes, but it didn't quite work. Try it to find out why.)
 1894,1900 
entry and the top are collected, so there's never really a reason
to use the comma. It's up to you.
! (@bullet{}) @strong{Exercise 4.} To enter the complex number @expr{(2, 3)},
your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened?
(Joe thought of a clever way to correct his mistake in only two
keystrokes, but it didn't quite work. Try it to find out why.)
***************
*** 1921,1927 ****
If you are not used to RPN notation, you may prefer to operate the
Calculator in ``algebraic mode,'' which is closer to the way
nonRPN calculators work. In algebraic mode, you enter formulas
! in traditional @cite{2+3} notation.
You don't really need any special ``mode'' to enter algebraic formulas.
You can enter a formula at any time by pressing the apostrophe (@kbd{'})
 1954,1960 
If you are not used to RPN notation, you may prefer to operate the
Calculator in ``algebraic mode,'' which is closer to the way
nonRPN calculators work. In algebraic mode, you enter formulas
! in traditional @expr{2+3} notation.
You don't really need any special ``mode'' to enter algebraic formulas.
You can enter a formula at any time by pressing the apostrophe (@kbd{'})
***************
*** 2004,2010 ****
the notation @samp{sqrt(@var{x})}.
Press the apostrophe, then type @kbd{sqrt(5*2)  3}. The result should
! be @cite{0.16227766017}.
Note that if the formula begins with a function name, you need to use
the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin}
 2037,2043 
the notation @samp{sqrt(@var{x})}.
Press the apostrophe, then type @kbd{sqrt(5*2)  3}. The result should
! be @expr{0.16227766017}.
Note that if the formula begins with a function name, you need to use
the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin}
***************
*** 2030,2036 ****
Algebraic mode allows us to enter complex numbers without pressing
an apostrophe first, but it also means we need to press @key{RET}
! after every entry, even for a simple number like @cite{1}.
(You can type @kbd{Cu m a} to enable a special ``incomplete algebraic
mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even
 2063,2069 
Algebraic mode allows us to enter complex numbers without pressing
an apostrophe first, but it also means we need to press @key{RET}
! after every entry, even for a simple number like @expr{1}.
(You can type @kbd{Cu m a} to enable a special ``incomplete algebraic
mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even
***************
*** 2050,2057 ****
accomplish this in Calc by performing your calculation as a series
of algebraic entries, using the @kbd{$} sign to tie them together.
In an algebraic formula, @kbd{$} represents the number on the top
! of the stack. Here, we perform the calculation @c{$\sqrt{2\times4+1}$}
! @cite{sqrt(2*4+1)},
which on a traditional calculator would be done by pressing
@kbd{2 * 4 + 1 =} and then the squareroot key.
 2083,2091 
accomplish this in Calc by performing your calculation as a series
of algebraic entries, using the @kbd{$} sign to tie them together.
In an algebraic formula, @kbd{$} represents the number on the top
! of the stack. Here, we perform the calculation
! @texline @tmath{\sqrt{2\times4+1}},
! @infoline @expr{sqrt(2*4+1)},
which on a traditional calculator would be done by pressing
@kbd{2 * 4 + 1 =} and then the squareroot key.
***************
*** 2190,2196 ****
@noindent
Notice that the instant we stored a new value in @code{a}, all
! @samp{=>} operators already on the stack that referred to @cite{a}
were updated to use the new value. With @samp{=>}, you can push a
set of formulas on the stack, then change the variables experimentally
to see the effects on the formulas' values.
 2224,2230 
@noindent
Notice that the instant we stored a new value in @code{a}, all
! @samp{=>} operators already on the stack that referred to @expr{a}
were updated to use the new value. With @samp{=>}, you can push a
set of formulas on the stack, then change the variables experimentally
to see the effects on the formulas' values.
***************
*** 2257,2263 ****
@end smallexample
@noindent
! It was not possible to redo past the @cite{6}, since that was placed there
by something other than an undo command.
@cindex Time travel
 2291,2297 
@end smallexample
@noindent
! It was not possible to redo past the @expr{6}, since that was placed there
by something other than an undo command.
@cindex Time travel
***************
*** 2265,2271 ****
@kbd{U} to go backward in time, @kbd{D} to go forward. If you go
backward and do something (like @kbd{*}) then, as any science fiction
reader knows, you have changed your future and you cannot go forward
! again. Thus, the inability to redo past the @cite{6} even though there
was an earlier undo command.
You can always recall an earlier result using the Trail. We've ignored
 2299,2305 
@kbd{U} to go backward in time, @kbd{D} to go forward. If you go
backward and do something (like @kbd{*}) then, as any science fiction
reader knows, you have changed your future and you cannot go forward
! again. Thus, the inability to redo past the @expr{6} even though there
was an earlier undo command.
You can always recall an earlier result using the Trail. We've ignored
***************
*** 2273,2285 ****
did since we loaded the Calculator. If the Trail is not displayed,
press @kbd{t d} now to turn it on.
! Let's try grabbing an earlier result. The @cite{8} we computed was
undone by a @kbd{U} command, and was lost even to Redo when we pressed
@kbd{*}, but it's still there in the trail. There should be a little
@samp{>} arrow (the @dfn{trail pointer}) resting on the last trail
entry. If there isn't, press @kbd{t ]} to reset the trail pointer.
Now, press @address@hidden p}} to move the arrow onto the line containing
! @cite{8}, and press @address@hidden y}} to ``yank'' that number back onto the
stack.
If you press @kbd{t ]} again, you will see that even our Yank command
 2307,2319 
did since we loaded the Calculator. If the Trail is not displayed,
press @kbd{t d} now to turn it on.
! Let's try grabbing an earlier result. The @expr{8} we computed was
undone by a @kbd{U} command, and was lost even to Redo when we pressed
@kbd{*}, but it's still there in the trail. There should be a little
@samp{>} arrow (the @dfn{trail pointer}) resting on the last trail
entry. If there isn't, press @kbd{t ]} to reset the trail pointer.
Now, press @address@hidden p}} to move the arrow onto the line containing
! @expr{8}, and press @address@hidden y}} to ``yank'' that number back onto the
stack.
If you press @kbd{t ]} again, you will see that even our Yank command
***************
*** 2340,2347 ****
to edit a stack entry.
Try entering @samp{3.141439} now. If this is supposed to represent
! @c{$\pi$}
! @cite{pi}, it's got several errors. Press @kbd{`} to edit this number.
Now use the normal Emacs cursor motion and editing keys to change
the second 4 to a 5, and to transpose the 3 and the 9. When you
press @key{RET}, the number on the stack will be replaced by your
 2374,2380 
to edit a stack entry.
Try entering @samp{3.141439} now. If this is supposed to represent
! @cpi{}, it's got several errors. Press @kbd{`} to edit this number.
Now use the normal Emacs cursor motion and editing keys to change
the second 4 to a 5, and to transpose the 3 and the 9. When you
press @key{RET}, the number on the stack will be replaced by your
***************
*** 2370,2376 ****
about, but the @samp{12} and the @samp{Deg} are mode indicators.
The @samp{12} means that calculations should always be carried to
12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /},
! we get @cite{0.142857142857} with exactly 12 digits, not counting
leading and trailing zeros.
You can set the precision to anything you like by pressing @kbd{p},
 2403,2409 
about, but the @samp{12} and the @samp{Deg} are mode indicators.
The @samp{12} means that calculations should always be carried to
12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /},
! we get @expr{0.142857142857} with exactly 12 digits, not counting
leading and trailing zeros.
You can set the precision to anything you like by pressing @kbd{p},
***************
*** 2387,2400 ****
Although the precision can be set arbitrarily high, Calc always
has to have @emph{some} value for the current precision. After
! all, the true value @cite{1/7} is an infinitely repeating decimal;
Calc has to stop somewhere.
Of course, calculations are slower the more digits you request.
Press @address@hidden 12}} now to set the precision back down to the default.
Calculations always use the current precision. For example, even
! though we have a 30digit value for @cite{1/7} on the stack, if
we use it in a calculation in 12digit mode it will be rounded
down to 12 digits before it is used. Try it; press @key{RET} to
duplicate the number, then @address@hidden +}}. Notice that the @key{RET}
 2420,2433 
Although the precision can be set arbitrarily high, Calc always
has to have @emph{some} value for the current precision. After
! all, the true value @expr{1/7} is an infinitely repeating decimal;
Calc has to stop somewhere.
Of course, calculations are slower the more digits you request.
Press @address@hidden 12}} now to set the precision back down to the default.
Calculations always use the current precision. For example, even
! though we have a 30digit value for @expr{1/7} on the stack, if
we use it in a calculation in 12digit mode it will be rounded
down to 12 digits before it is used. Try it; press @key{RET} to
duplicate the number, then @address@hidden +}}. Notice that the @key{RET}
***************
*** 2412,2418 ****
@noindent
In fact, since we added a digit on the left, we had to lose one
! digit on the right from even the 12digit value of @cite{1/7}.
How did we get more than 12 digits when we computed @samp{2^3^4}? The
answer is that Calc makes a distinction between @dfn{integers} and
 2445,2451 
@noindent
In fact, since we added a digit on the left, we had to lose one
! digit on the right from even the 12digit value of @expr{1/7}.
How did we get more than 12 digits when we computed @samp{2^3^4}? The
answer is that Calc makes a distinction between @dfn{integers} and
***************
*** 2463,2469 ****
@noindent
Hey, the answer is different! Look closely at the middle columns
of the two examples. In the first, the stack contained the
! exact integer @cite{10000}, but in the second it contained
a floatingpoint value with a decimal point. When you raise a
number to an integer power, Calc uses repeated squaring and
multiplication to get the answer. When you use a floatingpoint
 2496,2502 
@noindent
Hey, the answer is different! Look closely at the middle columns
of the two examples. In the first, the stack contained the
! exact integer @expr{10000}, but in the second it contained
a floatingpoint value with a decimal point. When you raise a
number to an integer power, Calc uses repeated squaring and
multiplication to get the answer. When you use a floatingpoint
***************
*** 2564,2570 ****
format; since it doesn't have an @kbd{H} prefix, it also updates all
the stack entries to be in @kbd{d n} format.
! Notice that the integer @cite{12345} was not affected by any
of the float formats. Integers are integers, and are always
displayed exactly.
 2597,2603 
format; since it doesn't have an @kbd{H} prefix, it also updates all
the stack entries to be in @kbd{d n} format.
! Notice that the integer @expr{12345} was not affected by any
of the float formats. Integers are integers, and are always
displayed exactly.
***************
*** 2712,2724 ****
@noindent
The address@hidden command computes the sine of an angle. The sine
! of 45 degrees is @c{$\sqrt{2}/2$}
! @cite{sqrt(2)/2}; squaring this yields @cite{2/4 = 0.5}.
! However, there has been a slight roundoff error because the
! representation of @c{$\sqrt{2}/2$}
! @cite{sqrt(2)/2} wasn't exact. The @kbd{c 1}
! command is a handy way to clean up numbers in this case; it
! temporarily reduces the precision by one digit while it
rerounds the number on the top of the stack.
@cindex Roundoff errors, examples
 2745,2759 
@noindent
The address@hidden command computes the sine of an angle. The sine
! of 45 degrees is
! @texline @tmath{\sqrt{2}/2};
! @infoline @expr{sqrt(2)/2};
! squaring this yields @expr{2/4 = 0.5}. However, there has been a slight
! roundoff error because the representation of
! @texline @tmath{\sqrt{2}/2}
! @infoline @expr{sqrt(2)/2}
! wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers
! in this case; it temporarily reduces the precision by one digit while it
rerounds the number on the top of the stack.
@cindex Roundoff errors, examples
***************
*** 2729,2737 ****
To do this calculation in radians, we would type @kbd{m r} first.
(The indicator changes to @samp{Rad}.) 45 degrees corresponds to
! @c{$\pi\over4$}
! @cite{pi/4} radians. To get @c{$\pi$}
! @cite{pi}, press the @kbd{P} key. (Once
again, this is a shifted capital @kbd{P}. Remember, unshifted
@kbd{p} sets the precision.)
 2764,2770 
To do this calculation in radians, we would type @kbd{m r} first.
(The indicator changes to @samp{Rad}.) 45 degrees corresponds to
! @cpiover{4} radians. To get @cpi{}, press the @kbd{P} key. (Once
again, this is a shifted capital @kbd{P}. Remember, unshifted
@kbd{p} sets the precision.)
***************
*** 2757,2765 ****
@end smallexample
@noindent
! Here we compute the Inverse Sine of @c{$\sqrt{0.5}$}
! @cite{sqrt(0.5)}, first in
! radians, then in degrees.
Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees
and viceversa.
 2790,2799 
@end smallexample
@noindent
! Here we compute the Inverse Sine of
! @texline @tmath{\sqrt{0.5}},
! @infoline @expr{sqrt(0.5)},
! first in radians, then in degrees.
Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees
and viceversa.
***************
*** 2939,2953 ****
We've already seen the @kbd{Q} (square root) and @kbd{S} (sine)
commands. Other commands along those lines are @kbd{C} (cosine),
! @kbd{T} (tangent), @kbd{E} (@cite{e^x}) and @kbd{L} (natural
logarithm). These can be modified by the @kbd{I} (inverse) and
@kbd{H} (hyperbolic) prefix keys.
Let's compute the sine and cosine of an angle, and verify the
! identity @c{$\sin^2x + \cos^2x = 1$}
! @cite{sin(x)^2 + cos(x)^2 = 1}. We'll
! arbitrarily pick @i{64} degrees as a good value for @cite{x}. With
! the angular mode set to degrees (type @address@hidden d}}), do:
@smallexample
@group
 2973,2988 
We've already seen the @kbd{Q} (square root) and @kbd{S} (sine)
commands. Other commands along those lines are @kbd{C} (cosine),
! @kbd{T} (tangent), @kbd{E} (@expr{e^x}) and @kbd{L} (natural
logarithm). These can be modified by the @kbd{I} (inverse) and
@kbd{H} (hyperbolic) prefix keys.
Let's compute the sine and cosine of an angle, and verify the
! identity
! @texline @tmath{\sin^2x + \cos^2x = 1}.
! @infoline @expr{sin(x)^2 + cos(x)^2 = 1}.
! We'll arbitrarily pick @i{64} degrees as a good value for @expr{x}.
! With the angular mode set to degrees (type @address@hidden d}}), do:
@smallexample
@group
***************
*** 2966,2973 ****
Remember, @kbd{f h} is the @code{calchypot}, or squareroot of sum
of squares, command.
! Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$}
! @cite{tan(x) = sin(x) / cos(x)}.
@smallexample
@group
 3001,3009 
Remember, @kbd{f h} is the @code{calchypot}, or squareroot of sum
of squares, command.
! Another identity is
! @texline @tmath{\displaystyle\tan x = {\sin x \over \cos x}}.
! @infoline @expr{tan(x) = sin(x) / cos(x)}.
@smallexample
@group
***************
*** 2980,2986 ****
@end smallexample
A physical interpretation of this calculation is that if you move
! @cite{0.89879} units downward and @cite{0.43837} units to the right,
your direction of motion is @i{64} degrees from horizontal. Suppose
we move in the opposite direction, up and to the left:
 3016,3022 
@end smallexample
A physical interpretation of this calculation is that if you move
! @expr{0.89879} units downward and @expr{0.43837} units to the right,
your direction of motion is @i{64} degrees from horizontal. Suppose
we move in the opposite direction, up and to the left:
***************
*** 3029,3037 ****
A similar identity is supposed to hold for hyperbolic sines and cosines,
except that it is the @emph{difference}
! @c{$\cosh^2x  \sinh^2x$}
! @cite{cosh(x)^2  sinh(x)^2} that always equals one.
! Let's try to verify this address@hidden
@smallexample
@group
 3065,3073 
A similar identity is supposed to hold for hyperbolic sines and cosines,
except that it is the @emph{difference}
! @texline @tmath{\cosh^2x  \sinh^2x}
! @infoline @expr{cosh(x)^2  sinh(x)^2}
! that always equals one. Let's try to verify this identity.
@smallexample
@group
***************
*** 3057,3068 ****
0.99999, reasonably close to 1.
Of course, a more reasonable way to verify the identity is to use
! a more reasonable value for @cite{x}!
@cindex Common logarithm
Some Calculator commands use the Hyperbolic prefix for other purposes.
The logarithm and exponential functions, for example, work to the base
! @cite{e} normally but use base10 instead if you use the Hyperbolic
prefix.
@smallexample
 3093,3104 
0.99999, reasonably close to 1.
Of course, a more reasonable way to verify the identity is to use
! a more reasonable value for @expr{x}!
@cindex Common logarithm
Some Calculator commands use the Hyperbolic prefix for other purposes.
The logarithm and exponential functions, for example, work to the base
! @expr{e} normally but use base10 instead if you use the Hyperbolic
prefix.
@smallexample
***************
*** 3095,3101 ****
Here we first use @kbd{B} to compute the base10 logarithm, then use
the ``hyperbolic'' exponential as a cheap hack to recover the number
1000, then use @kbd{B} again to compute the natural logarithm. Note
! that @kbd{P} with the hyperbolic prefix pushes the constant @cite{e}
onto the stack.
You may have noticed that both times we took the base10 logarithm
 3131,3137 
Here we first use @kbd{B} to compute the base10 logarithm, then use
the ``hyperbolic'' exponential as a cheap hack to recover the number
1000, then use @kbd{B} again to compute the natural logarithm. Note
! that @kbd{P} with the hyperbolic prefix pushes the constant @expr{e}
onto the stack.
You may have noticed that both times we took the base10 logarithm
***************
*** 3136,3143 ****
If you take the factorial of a noninteger, Calc uses a generalized
factorial function defined in terms of Euler's Gamma function
! @c{$\Gamma(n)$}
! @cite{gamma(n)}
(which is itself available as the @kbd{f g} command).
@smallexample
 3172,3179 
If you take the factorial of a noninteger, Calc uses a generalized
factorial function defined in terms of Euler's Gamma function
! @texline @tmath{\Gamma(n)}
! @infoline @expr{gamma(n)}
(which is itself available as the @kbd{f g} command).
@smallexample
***************
*** 3152,3168 ****
@end smallexample
@noindent
! Here we verify the identity @c{$n! = \Gamma(n+1)$}
! @address@hidden@: = gamma(@var{n}+1)}.
! The binomial coefficient @address@hidden@c{ or $\displaystyle {n \choose m}$}
! @asis{} is defined by
! @c{$\displaystyle {n! \over m! \, (nm)!}$}
! @cite{n!@: / m!@: (nm)!} for all reals @cite{n} and
! @cite{m}. The intermediate results in this formula can become quite
! large even if the final result is small; the @kbd{k c} command computes
! a binomial coefficient in a way that avoids large intermediate
! values.
The @kbd{k} prefix key defines several common functions out of
combinatorics and number theory. Here we compute the binomial
 3188,3206 
@end smallexample
@noindent
! Here we verify the identity
! @texline @tmath{n! = \Gamma(n+1)}.
! @infoline @address@hidden@: = gamma(@var{n}+1)}.
! The binomial coefficient @address@hidden
! @texline or @tmath{\displaystyle {n \choose m}}
! is defined by
! @texline @tmath{\displaystyle {n! \over m! \, (nm)!}}
! @infoline @expr{n!@: / m!@: (nm)!}
! for all reals @expr{n} and @expr{m}. The intermediate results in this
! formula can become quite large even if the final result is small; the
! @kbd{k c} command computes a binomial coefficient in a way that avoids
! large intermediate values.
The @kbd{k} prefix key defines several common functions out of
combinatorics and number theory. Here we compute the binomial
***************
*** 3266,3272 ****
@cindex Dot product
The dot product of two vectors is equal to the product of their
lengths times the cosine of the angle between them. (Here the vector
! is interpreted as a line from the origin @cite{(0,0,0)} to the
specified point in threedimensional space.) The @kbd{A}
(absolute value) command can be used to compute the length of a
vector.
 3304,3310 
@cindex Dot product
The dot product of two vectors is equal to the product of their
lengths times the cosine of the angle between them. (Here the vector
! is interpreted as a line from the origin @expr{(0,0,0)} to the
specified point in threedimensional space.) The @kbd{A}
(absolute value) command can be used to compute the length of a
vector.
***************
*** 3379,3386 ****
When two matrices are multiplied, the lefthand matrix must have
the same number of columns as the righthand matrix has rows.
! Row @cite{i}, column @cite{j} of the result is effectively the
! dot product of row @cite{i} of the left matrix by column @cite{j}
of the right matrix.
If we try to duplicate this matrix and multiply it by itself,
 3417,3424 
When two matrices are multiplied, the lefthand matrix must have
the same number of columns as the righthand matrix has rows.
! Row @expr{i}, column @expr{j} of the result is effectively the
! dot product of row @expr{i} of the left matrix by column @expr{j}
of the right matrix.
If we try to duplicate this matrix and multiply it by itself,
***************
*** 3441,3449 ****
vector.
(@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows
! of the above @c{$2\times3$}
! @asis{2x3} matrix to get @cite{[6, 15]}. Now use @samp{*} to
! sum along the columns to get @cite{[5, 7, 9]}.
@xref{Matrix Answer 1, 1}. (@bullet{})
@cindex Identity matrix
 3479,3489 
vector.
(@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows
! of the above
! @texline @tmath{2\times3}
! @infoline 2x3
! matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns
! to get @expr{[5, 7, 9]}.
@xref{Matrix Answer 1, 1}. (@bullet{})
@cindex Identity matrix
***************
*** 3566,3572 ****
@end smallexample
@noindent
! The result is the @cite{[a, b, c]} vector that solves the equations.
(Dividing by a square matrix is equivalent to multiplying by its
inverse.)
 3606,3612 
@end smallexample
@noindent
! The result is the @expr{[a, b, c]} vector that solves the equations.
(Dividing by a square matrix is equivalent to multiplying by its
inverse.)
***************
*** 3590,3605 ****
assume the vector was a row vector in order to make the dimensions
come out right, and the answer would be incorrect. If you
don't feel safe letting Calc take either interpretation of your
! vectors, use explicit @c{$N\times1$}
! @asis{Nx1} or @c{$1\times N$}
! @asis{1xN} matrices instead.
! In this case, you would enter the original column vector as
! @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}.
(@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make
vectors and matrices that include variables. Solve the following
! system of equations to get expressions for @cite{x} and @cite{y}
! in terms of @cite{a} and @cite{b}.
@ifinfo
@group
 3630,3648 
assume the vector was a row vector in order to make the dimensions
come out right, and the answer would be incorrect. If you
don't feel safe letting Calc take either interpretation of your
! vectors, use explicit
! @texline @tmath{N\times1}
! @infoline Nx1
! or
! @texline @tmath{1\times N}
! @infoline 1xN
! matrices instead. In this case, you would enter the original column
! vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}.
(@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make
vectors and matrices that include variables. Solve the following
! system of equations to get expressions for @expr{x} and @expr{y}
! in terms of @expr{a} and @expr{b}.
@ifinfo
@group
***************
*** 3628,3637 ****
there are no values for the variables that will satisfy all the
equations at once, but it is still useful to find a set of values
which ``nearly'' satisfy all the equations. In terms of matrix equations,
! you can't solve @cite{A X = B} directly because the matrix @cite{A}
is not square for an overdetermined system. Matrix inversion works
only for square matrices. One common trick is to multiply both sides
! on the left by the transpose of @cite{A}:
@ifinfo
@samp{trn(A)*A*X = trn(A)*B}.
@end ifinfo
 3671,3680 
there are no values for the variables that will satisfy all the
equations at once, but it is still useful to find a set of values
which ``nearly'' satisfy all the equations. In terms of matrix equations,
! you can't solve @expr{A X = B} directly because the matrix @expr{A}
is not square for an overdetermined system. Matrix inversion works
only for square matrices. One common trick is to multiply both sides
! on the left by the transpose of @expr{A}:
@ifinfo
@samp{trn(A)*A*X = trn(A)*B}.
@end ifinfo
***************
*** 3639,3650 ****
\turnoffactive
$A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.
@end tex
! Now @c{$A^T A$}
! @cite{trn(A)*A} is a square matrix so a solution is possible. It
! turns out that the @cite{X} vector you compute in this way will be a
! ``leastsquares'' solution, which can be regarded as the ``closest''
! solution to the set of equations. Use Calc to solve the following
! overdetermined system:@refill
@ifinfo
@group
 3682,3695 
\turnoffactive
$A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.
@end tex
! Now
! @texline @tmath{A^T A}
! @infoline @expr{trn(A)*A}
! is a square matrix so a solution is possible. It turns out that the
! @expr{X} vector you compute in this way will be a ``leastsquares''
! solution, which can be regarded as the ``closest'' solution to the set
! of equations. Use Calc to solve the following overdetermined
! system:
@ifinfo
@group
***************
*** 3733,3740 ****
of each element.
(@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two
! from @c{$2^{4}$}
! @cite{2^4} to @cite{2^4}. @xref{List Answer 1, 1}. (@bullet{})
You can also @dfn{reduce} a binary operator across a vector.
For example, reducing @samp{*} computes the product of all the
 3778,3787 
of each element.
(@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two
! from
! @texline @tmath{2^{4}}
! @infoline @expr{2^4}
! to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{})
You can also @dfn{reduce} a binary operator across a vector.
For example, reducing @samp{*} computes the product of all the
***************
*** 3868,3880 ****
@kbd{List Tutorial}, to jump straight to this section.)
Position the cursor at the upperleft corner of this table, just
! to the left of the @cite{1.34}. Press @kbd{C@@} to set the mark.
(On your system this may be @kbd{C2}, @address@hidden, or @kbd{NUL}.)
! Now position the cursor to the lowerright, just after the @cite{1.354}.
You have now defined this region as an Emacs ``rectangle.'' Still
in the Info buffer, type @kbd{M# r}. This command
(@code{calcgrabrectangle}) will pop you back into the Calculator, with
! the contents of the rectangle you specified in the form of a address@hidden
@smallexample
@group
 3915,3927 
@kbd{List Tutorial}, to jump straight to this section.)
Position the cursor at the upperleft corner of this table, just
! to the left of the @expr{1.34}. Press @kbd{C@@} to set the mark.
(On your system this may be @kbd{C2}, @address@hidden, or @kbd{NUL}.)
! Now position the cursor to the lowerright, just after the @expr{1.354}.
You have now defined this region as an Emacs ``rectangle.'' Still
in the Info buffer, type @kbd{M# r}. This command
(@code{calcgrabrectangle}) will pop you back into the Calculator, with
! the contents of the rectangle you specified in the form of a matrix.
@smallexample
@group
***************
*** 3919,3925 ****
(Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the
stored value from the stack.)
! In a least squares fit, the slope @cite{m} is given by the formula
@ifinfo
@example
 3966,3972 
(Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the
stored value from the stack.)
! In a least squares fit, the slope @expr{m} is given by the formula
@ifinfo
@example
***************
*** 3935,3945 ****
@end tex
@noindent
! where @c{$\sum x$}
! @cite{sum(x)} represents the sum of all the values of @cite{x}.
! While there is an actual @code{sum} function in Calc, it's easier to
! sum a vector using a simple reduction. First, let's compute the four
! different sums that this formula uses.
@smallexample
@group
 3982,3994 
@end tex
@noindent
! where
! @texline @tmath{\sum x}
! @infoline @expr{sum(x)}
! represents the sum of all the values of @expr{x}. While there is an
! actual @code{sum} function in Calc, it's easier to sum a vector using a
! simple reduction. First, let's compute the four different sums that
! this formula uses.
@smallexample
@group
***************
*** 3973,3979 ****
$\sum x y$.)
@end tex
! Finally, we also need @cite{N}, the number of data points. This is just
the length of either of our lists.
@smallexample
 4022,4028 
$\sum x y$.)
@end tex
! Finally, we also need @expr{N}, the number of data points. This is just
the length of either of our lists.
@smallexample
***************
*** 4012,4018 ****
@end group
@end smallexample
! That gives us the slope @cite{m}. The yintercept @cite{b} can now
be found with the simple formula,
@ifinfo
 4061,4067 
@end group
@end smallexample
! That gives us the slope @expr{m}. The yintercept @expr{b} can now
be found with the simple formula,
@ifinfo
***************
*** 4038,4045 ****
@end group
@end smallexample
! Let's ``plot'' this straight line approximation, @c{$y \approx m x + b$}
! @cite{m x + b}, and compare it with the original address@hidden
@smallexample
@group
 4087,4096 
@end group
@end smallexample
! Let's ``plot'' this straight line approximation,
! @texline @tmath{y \approx m x + b},
! @infoline @expr{m x + b},
! and compare it with the original data.
@smallexample
@group
***************
*** 4056,4062 ****
common operations from vector algebra. As far as Calc is concerned,
we've just been doing geometry in 19dimensional space!
! We can subtract this vector from our original @cite{y} vector to get
a feel for the error of our fit. Let's find the maximum error:
@smallexample
 4107,4113 
common operations from vector algebra. As far as Calc is concerned,
we've just been doing geometry in 19dimensional space!
! We can subtract this vector from our original @expr{y} vector to get
a feel for the error of our fit. Let's find the maximum error:
@smallexample
***************
*** 4131,4139 ****
(@bullet{}) @strong{Exercise 2.} An earlier exercise showed how to do
least squares fitting to a general system of equations. Our 19 data
! points are really 19 equations of the form @cite{y_i = m x_i + b} for
! different pairs of @cite{(x_i,y_i)}. Use the matrixtranspose method
! to solve for @cite{m} and @cite{b}, duplicating the above result.
@xref{List Answer 2, 2}. (@bullet{})
@cindex Geometric mean
 4182,4190 
(@bullet{}) @strong{Exercise 2.} An earlier exercise showed how to do
least squares fitting to a general system of equations. Our 19 data
! points are really 19 equations of the form @expr{y_i = m x_i + b} for
! different pairs of @expr{(x_i,y_i)}. Use the matrixtranspose method
! to solve for @expr{m} and @expr{b}, duplicating the above result.
@xref{List Answer 2, 2}. (@bullet{})
@cindex Geometric mean
***************
*** 4161,4167 ****
@var{n}choose0 minus @var{n}choose1 plus @var{n}choose2, and so
on up to @address@hidden,
always comes out to zero. Let's verify this
! for @address@hidden
@end ifinfo
@tex
As another example, a theorem about binomial coefficients tells
 4212,4218 
@var{n}choose0 minus @var{n}choose1 plus @var{n}choose2, and so
on up to @address@hidden,
always comes out to zero. Let's verify this
! for @expr{n=6}.
@end ifinfo
@tex
As another example, a theorem about binomial coefficients tells
***************
*** 4232,4244 ****
and @kbd{v c} instead delete one row, column, or vector element.
@cindex Divisor functions
! (@bullet{}) @strong{Exercise 4.} The @cite{k}th @dfn{divisor function}
@tex
$\sigma_k(n)$
@end tex
! is the sum of the @cite{k}th powers of all the divisors of an
! integer @cite{n}. Figure out a method for computing the divisor
! function for reasonably small values of @cite{n}. As a test,
the 0th and 1st divisor functions of 30 are 8 and 72, respectively.
@xref{List Answer 4, 4}. (@bullet{})
 4283,4295 
and @kbd{v c} instead delete one row, column, or vector element.
@cindex Divisor functions
! (@bullet{}) @strong{Exercise 4.} The @expr{k}th @dfn{divisor function}
@tex
$\sigma_k(n)$
@end tex
! is the sum of the @expr{k}th powers of all the divisors of an
! integer @expr{n}. Figure out a method for computing the divisor
! function for reasonably small values of @expr{n}. As a test,
the 0th and 1st divisor functions of 30 are 8 and 72, respectively.
@xref{List Answer 4, 4}. (@bullet{})
***************
*** 4290,4312 ****
@cindex Maximizing a function over a list of values
@c [fixref Numerical Solutions]
(@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's
! @c{$J_1(x)$}
! @cite{J1} function @samp{besJ(1,x)} for @cite{x} from 0 to 5
! in steps of 0.25.
! Find the value of @cite{x} (from among the above set of values) for
which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method,
i.e., just reading along the list by hand to find the largest value
is not allowed! (There is an @kbd{a X} command which does this kind
of thing automatically; @pxref{Numerical Solutions}.)
! @xref{List Answer 8, 8}. (@bullet{})@refill
@cindex Digits, vectors of
(@bullet{}) @strong{Exercise 9.} You are given an integer in the range
! @c{$0 \le N < 10^m$}
! @cite{0 <= N < 10^m} for @cite{m=12} (i.e., an integer of less than
! twelve digits). Convert this integer into a vector of @cite{m}
digits, each in the range from 0 to 9. In vectorofdigits notation,
! add one to this integer to produce a vector of @cite{m+1} digits
(since there could be a carry out of the most significant digit).
Convert this vector back into a regular integer. A good integer
to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{})
 4341,4364 
@cindex Maximizing a function over a list of values
@c [fixref Numerical Solutions]
(@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's
! @texline @tmath{J_1(x)}
! @infoline @expr{J1}
! function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25.
! Find the value of @expr{x} (from among the above set of values) for
which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method,
i.e., just reading along the list by hand to find the largest value
is not allowed! (There is an @kbd{a X} command which does this kind
of thing automatically; @pxref{Numerical Solutions}.)
! @xref{List Answer 8, 8}. (@bullet{})
@cindex Digits, vectors of
(@bullet{}) @strong{Exercise 9.} You are given an integer in the range
! @texline @tmath{0 \le N < 10^m}
! @infoline @expr{0 <= N < 10^m}
! for @expr{m=12} (i.e., an integer of less than
! twelve digits). Convert this integer into a vector of @expr{m}
digits, each in the range from 0 to 9. In vectorofdigits notation,
! add one to this integer to produce a vector of @expr{m+1} digits
(since there could be a carry out of the most significant digit).
Convert this vector back into a regular integer. A good integer
to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{})
***************
*** 4316,4355 ****
happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{})
(@bullet{}) @strong{Exercise 11.} The area of a circle of radius one
! is @c{$\pi$}
! @cite{pi}. The area of the @c{$2\times2$}
! @asis{2x2} square that encloses that
! circle is 4. So if we throw @var{n} darts at random points in the square,
! about @c{$\pi/4$}
! @cite{pi/4} of them will land inside the circle. This gives us
! an entertaining way to estimate the value of @c{$\pi$}
! @cite{pi}. The @address@hidden r}}
command picks a random number between zero and the value on the stack.
We could get a random floatingpoint number between @i{1} and 1 by typing
! @address@hidden k r 1 }}. Build a vector of 100 random @cite{(x,y)} points
in
this square, then use vector mapping and reduction to count how many
points lie inside the unit circle. Hint: Use the @kbd{v b} command.
@xref{List Answer 11, 11}. (@bullet{})
@cindex Matchstick problem
(@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides
! another way to calculate @c{$\pi$}
! @cite{pi}. Say you have an infinite field
of vertical lines with a spacing of one inch. Toss a oneinch matchstick
onto the field. The probability that the matchstick will land crossing
! a line turns out to be @c{$2/\pi$}
! @cite{2/pi}. Toss 100 matchsticks to estimate
! @c{$\pi$}
! @cite{pi}. (If you want still more fun, the probability that the GCD
! (@address@hidden g}}) of two large integers is one turns out to be
@c{$6/\pi^2$}
! @cite{6/pi^2}.
! That provides yet another way to estimate @c{$\pi$}
! @cite{pi}.)
@xref{List Answer 12, 12}. (@bullet{})
(@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in
doublequote marks, @samp{"hello"}, creates a vector of the numerical
! (ASCII) codes of the characters (here, @cite{[104, 101, 108, 108, 111]}).
Sometimes it is convenient to compute a @dfn{hash code} of a string,
which is just an integer that represents the value of that string.
Two equal strings have the same hash code; two different strings
 4368,4406 
happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{})
(@bullet{}) @strong{Exercise 11.} The area of a circle of radius one
! is @cpi{}. The area of the
! @texline @tmath{2\times2}
! @infoline 2x2
! square that encloses that circle is 4. So if we throw @var{n} darts at
! random points in the square, about @cpiover{4} of them will land inside
! the circle. This gives us an entertaining way to estimate the value of
! @cpi{}. The @address@hidden r}}
command picks a random number between zero and the value on the stack.
We could get a random floatingpoint number between @i{1} and 1 by typing
! @address@hidden k r 1 }}. Build a vector of 100 random @expr{(x,y)} points
in
this square, then use vector mapping and reduction to count how many
points lie inside the unit circle. Hint: Use the @kbd{v b} command.
@xref{List Answer 11, 11}. (@bullet{})
@cindex Matchstick problem
(@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides
! another way to calculate @cpi{}. Say you have an infinite field
of vertical lines with a spacing of one inch. Toss a oneinch matchstick
onto the field. The probability that the matchstick will land crossing
! a line turns out to be
! @texline @tmath{2/\pi}.
! @infoline @expr{2/pi}.
! Toss 100 matchsticks to estimate @cpi{}. (If you want still more fun,
! the probability that the GCD (@address@hidden g}}) of two large integers is
! one turns out to be
! @texline @tmath{6/\pi^2}.
! @infoline @expr{6/pi^2}.
! That provides yet another way to estimate @cpi{}.)
@xref{List Answer 12, 12}. (@bullet{})
(@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in
doublequote marks, @samp{"hello"}, creates a vector of the numerical
! (ASCII) codes of the characters (here, @expr{[104, 101, 108, 108, 111]}).
Sometimes it is convenient to compute a @dfn{hash code} of a string,
which is just an integer that represents the value of that string.
Two equal strings have the same hash code; two different strings
***************
*** 4358,4366 ****
any given name because it has sorted the functions into ``buckets'' by
their hash codes. Sometimes a few names will hash into the same bucket,
but it is easier to search among a few names than among all the names.)
! One popular hash function is computed as follows: First set @cite{h = 0}.
! Then, for each character from the string in turn, set @cite{h = 3h + c_i}
! where @cite{c_i} is the character's ASCII code. If we have 511 buckets,
we then take the hash code modulo 511 to get the bucket number. Develop a
simple command or commands for converting string vectors into hash codes.
The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo
 4409,4417 
any given name because it has sorted the functions into ``buckets'' by
their hash codes. Sometimes a few names will hash into the same bucket,
but it is easier to search among a few names than among all the names.)
! One popular hash function is computed as follows: First set @expr{h = 0}.
! Then, for each character from the string in turn, set @expr{h = 3h + c_i}
! where @expr{c_i} is the character's ASCII code. If we have 511 buckets,
we then take the hash code modulo 511 to get the bucket number. Develop a
simple command or commands for converting string vectors into hash codes.
The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo
***************
*** 4372,4379 ****
function you give to the starting value 0, 1, 2, up to @var{n} times
and returns a vector of the results. Use this command to create a
``random walk'' of 50 steps. Start with the twodimensional point
! @cite{(0,0)}; then take one step a random distance between @i{1} and 1
! in both @cite{x} and @cite{y}; then take another step, and so on. Use the
@kbd{g f} command to display this random walk. Now modify your random
walk to walk a unit distance, but in a random direction, at each step.
(Hint: The @code{sincos} function returns a vector of the cosine and
 4423,4430 
function you give to the starting value 0, 1, 2, up to @var{n} times
and returns a vector of the results. Use this command to create a
``random walk'' of 50 steps. Start with the twodimensional point
! @expr{(0,0)}; then take one step a random distance between @i{1} and 1
! in both @expr{x} and @expr{y}; then take another step, and so on. Use the
@kbd{g f} command to display this random walk. Now modify your random
walk to walk a unit distance, but in a random direction, at each step.
(Hint: The @code{sincos} function returns a vector of the cosine and
***************
*** 4436,4443 ****
(@bullet{}) @strong{Exercise 1.} A calculation has produced the
result 1.26508260337. You suspect it is the square root of the
! product of @c{$\pi$}
! @cite{pi} and some rational number. Is it? (Be sure
to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{})
@dfn{Complex numbers} can be stored in both rectangular and polar form.
 4487,4493 
(@bullet{}) @strong{Exercise 1.} A calculation has produced the
result 1.26508260337. You suspect it is the square root of the
! product of @cpi{} and some rational number. Is it? (Be sure
to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{})
@dfn{Complex numbers} can be stored in both rectangular and polar form.
***************
*** 4453,4459 ****
@noindent
The square root of @i{9} is by default rendered in rectangular form
! (@address@hidden + 3i}}), but we can convert it to polar form (3 with a
phase angle of 90 degrees). All the usual arithmetic and scientific
operations are defined on both types of complex numbers.
 4503,4509 
@noindent
The square root of @i{9} is by default rendered in rectangular form
! (@address@hidden + 3i}}), but we can convert it to polar form (3 with a
phase angle of 90 degrees). All the usual arithmetic and scientific
operations are defined on both types of complex numbers.
***************
*** 4509,4517 ****
Dividing by zero normally is left unevaluated, but after @kbd{m i}
it instead gives an infinite result. The answer is actually
@code{uinf}, ``undirected infinity.'' If you look at a graph of
! @cite{1 / x} around @address@hidden = 0}}, you'll see that it goes toward
plus infinity as you approach zero from above, but toward minus
! infinity as you approach from below. Since we said only @cite{1 / 0},
Calc knows that the answer is infinite but not in which direction.
That's what @code{uinf} means. Notice that multiplying @code{uinf}
by a negative number still leaves plain @code{uinf}; there's no
 4559,4567 
Dividing by zero normally is left unevaluated, but after @kbd{m i}
it instead gives an infinite result. The answer is actually
@code{uinf}, ``undirected infinity.'' If you look at a graph of
! @expr{1 / x} around @address@hidden = 0}}, you'll see that it goes toward
plus infinity as you approach zero from above, but toward minus
! infinity as you approach from below. Since we said only @expr{1 / 0},
Calc knows that the answer is infinite but not in which direction.
That's what @code{uinf} means. Notice that multiplying @code{uinf}
by a negative number still leaves plain @code{uinf}; there's no
***************
*** 4641,4650 ****
@cindex Torus, volume of
(@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is
! @c{$2 \pi^2 R r^2$}
! @address@hidden pi^2 R r^2}} where @cite{R} is the radius of the circle that
! defines the center of the tube and @cite{r} is the radius of the tube
! itself. Suppose @cite{R} is 20 cm and @cite{r} is 4 cm, each known to
within 5 percent. What is the volume and the relative uncertainty of
the volume? @xref{Types Answer 7, 7}. (@bullet{})
 4691,4701 
@cindex Torus, volume of
(@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is
! @texline @tmath{2 \pi^2 R r^2}
! @infoline @address@hidden pi^2 R r^2}}
! where @expr{R} is the radius of the circle that
! defines the center of the tube and @expr{r} is the radius of the tube
! itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to
within 5 percent. What is the volume and the relative uncertainty of
the volume? @xref{Types Answer 7, 7}. (@bullet{})
***************
*** 4739,4752 ****
@cindex Fermat, primality test of
(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat
! says that @c{\w{$x^{n1} \bmod n = 1$}}
! @cite{x^(n1) mod n = 1} if @cite{n} is a prime number
! and @cite{x} is an integer less than @cite{n}. If @cite{n} is
! @emph{not} a prime number, this will @emph{not} be true for most
! values of @cite{x}. Thus we can test informally if a number is
! prime by trying this formula for several values of @cite{x}.
! Use this test to tell whether the following numbers are prime:
! 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{})
It is possible to use HMS forms as parts of error forms, intervals,
modulo forms, or as the phase part of a polar complex number.
 4790,4804 
@cindex Fermat, primality test of
(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat
! says that
! @texline @address@hidden \bmod n = 1}}
! @infoline @expr{x^(n1) mod n = 1}
! if @expr{n} is a prime number and @expr{x} is an integer less than
! @expr{n}. If @expr{n} is @emph{not} a prime number, this will
! @emph{not} be true for most values of @expr{x}. Thus we can test
! informally if a number is prime by trying this formula for several
! values of @expr{x}. Use this test to tell whether the following numbers
! are prime: 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{})
It is possible to use HMS forms as parts of error forms, intervals,
modulo forms, or as the phase part of a polar complex number.
***************
*** 4766,4774 ****
This calculation tells me it is six hours and 22 minutes until midnight.
(@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year
! is about @c{$\pi \times 10^7$}
! @address@hidden * 10^7}} seconds. What time will it be that
! many seconds from right now? @xref{Types Answer 11, 11}. (@bullet{})
(@bullet{}) @strong{Exercise 12.} You are preparing to order packaging
for the CD release of the Extended Disco Version of @emph{Abbey Road}.
 4818,4828 
This calculation tells me it is six hours and 22 minutes until midnight.
(@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year
! is about
! @texline @tmath{\pi \times 10^7}
! @infoline @address@hidden * 10^7}}
! seconds. What time will it be that many seconds from right now?
! @xref{Types Answer 11, 11}. (@bullet{})
(@bullet{}) @strong{Exercise 12.} You are preparing to order packaging
for the CD release of the Extended Disco Version of @emph{Abbey Road}.
***************
*** 4949,4957 ****
@noindent
First we ``expand'' using the distributive law, then we ``collect''
! terms involving like powers of @cite{x}.
! Let's find the value of this expression when @cite{x} is 2 and @cite{y}
is onehalf.
@smallexample
 5003,5011 
@noindent
First we ``expand'' using the distributive law, then we ``collect''
! terms involving like powers of @expr{x}.
! Let's find the value of this expression when @expr{x} is 2 and @expr{y}
is onehalf.
@smallexample
***************
*** 4976,4986 ****
properly.)
@cindex Maximum of a function using Calculus
! Let's find the maximum value of our original expression when @cite{y}
! is onehalf and @cite{x} ranges over all possible values. We can
! do this by taking the derivative with respect to @cite{x} and examining
! values of @cite{x} for which the derivative is zero. If the second
! derivative of the function at that value of @cite{x} is negative,
the function has a local maximum there.
@smallexample
 5030,5040 
properly.)
@cindex Maximum of a function using Calculus
! Let's find the maximum value of our original expression when @expr{y}
! is onehalf and @expr{x} ranges over all possible values. We can
! do this by taking the derivative with respect to @expr{x} and examining
! values of @expr{x} for which the derivative is zero. If the second
! derivative of the function at that value of @expr{x} is negative,
the function has a local maximum there.
@smallexample
***************
*** 4993,5000 ****
@end smallexample
@noindent
! Well, the derivative is clearly zero when @cite{x} is zero. To find
! the other root(s), let's divide through by @cite{x} and then solve:
@smallexample
@group
 5047,5054 
@end smallexample
@noindent
! Well, the derivative is clearly zero when @expr{x} is zero. To find
! the other root(s), let's divide through by @expr{x} and then solve:
@smallexample
@group
***************
*** 5020,5026 ****
default algebraic simplifications don't do enough, you can use
@kbd{a s} to tell Calc to spend more time on the job.
! Now we compute the second derivative and plug in our values of @cite{x}:
@smallexample
@group
 5074,5080 
default algebraic simplifications don't do enough, you can use
@kbd{a s} to tell Calc to spend more time on the job.
! Now we compute the second derivative and plug in our values of @expr{x}:
@smallexample
@group
***************
*** 5050,5063 ****
@noindent
The first of these second derivatives is negative, so we know the function
! has a maximum value at @cite{x = 1.19023}. (The function also has a
! local @emph{minimum} at @cite{x = 0}.)
! When we solved for @cite{x}, we got only one value even though
! @cite{34  24 x^2 = 0} is a quadratic equation that ought to have
two solutions. The reason is that @address@hidden S}} normally returns a
single ``principal'' solution. If it needs to come up with an
! arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}.
If it needs an arbitrary integer, it picks zero. We can get a full
solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.
 5104,5117 
@noindent
The first of these second derivatives is negative, so we know the function
! has a maximum value at @expr{x = 1.19023}. (The function also has a
! local @emph{minimum} at @expr{x = 0}.)
! When we solved for @expr{x}, we got only one value even though
! @expr{34  24 x^2 = 0} is a quadratic equation that ought to have
two solutions. The reason is that @address@hidden S}} normally returns a
single ``principal'' solution. If it needs to come up with an
! arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}.
If it needs an arbitrary integer, it picks zero. We can get a full
solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.
***************
*** 5075,5083 ****
it is supposed to be either @i{+1} or @i{1}. Here we have used
the ``let'' command to evaluate the expression when the sign is negative.
If we plugged this into our second derivative we would get the same,
! negative, answer, so @cite{x = 1.19023} is also a maximum.
! To find the actual maximum value, we must plug our two values of @cite{x}
into the original formula.
@smallexample
 5129,5137 
it is supposed to be either @i{+1} or @i{1}. Here we have used
the ``let'' command to evaluate the expression when the sign is negative.
If we plugged this into our second derivative we would get the same,
! negative, answer, so @expr{x = 1.19023} is also a maximum.
! To find the actual maximum value, we must plug our two values of @expr{x}
into the original formula.
@smallexample
***************
*** 5127,5133 ****
@address@hidden a S}} and returns a vector of all the solutions. It simply
automates the job we just did by hand. Applied to our original
cubic polynomial, it would produce the vector of solutions
! @cite{[1.19023, 1.19023, 0]}. (There is also an @kbd{a X} command
which finds a local maximum of a function. It uses a numerical search
method rather than examining the derivatives, and thus requires you
to provide some kind of initial guess to show it where to look.)
 5181,5187 
@address@hidden a S}} and returns a vector of all the solutions. It simply
automates the job we just did by hand. Applied to our original
cubic polynomial, it would produce the vector of solutions
! @expr{[1.19023, 1.19023, 0]}. (There is also an @kbd{a X} command
which finds a local maximum of a function. It uses a numerical search
method rather than examining the derivatives, and thus requires you
to provide some kind of initial guess to show it where to look.)
***************
*** 5215,5221 ****
are shown in normal mode.)
@cindex Area under a curve
! What is the area under the portion of this curve from @cite{x = 1} to
@cite{2}?
This is simply the integral of the function:
@smallexample
 5269,5275 
are shown in normal mode.)
@cindex Area under a curve
! What is the area under the portion of this curve from @expr{x = 1} to
@expr{2}?
This is simply the integral of the function:
@smallexample
***************
*** 5228,5234 ****
@end smallexample
@noindent
! We want to evaluate this at our two values for @cite{x} and subtract.
One way to do it is again with vector mapping and reduction:
@smallexample
 5282,5288 
@end smallexample
@noindent
! We want to evaluate this at our two values for @expr{x} and subtract.
One way to do it is again with vector mapping and reduction:
@smallexample
***************
*** 5240,5259 ****
@end group
@end smallexample
! (@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @cite{y}
! of @c{$x \sin \pi x$}
! @address@hidden sin(pi x)}} (where the sine is calculated in radians).
! Find the values of the integral for integers @cite{y} from 1 to 5.
! @xref{Algebra Answer 3, 3}. (@bullet{})
Calc's integrator can do many simple integrals symbolically, but many
others are beyond its capabilities. Suppose we wish to find the area
! under the curve @c{$\sin x \ln x$}
! @cite{sin(x) ln(x)} over the same range of @cite{x}. If
! you entered this formula and typed @kbd{a i x @key{RET}} (don't bother to try
! this), Calc would work for a long time but would be unable to find a
! solution. In fact, there is no closedform solution to this integral.
! Now what do we do?
@cindex Integration, numerical
@cindex Numerical integration
 5294,5316 
@end group
@end smallexample
! (@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @expr{y}
! of
! @texline @tmath{x \sin \pi x}
! @infoline @address@hidden sin(pi x)}}
! (where the sine is calculated in radians). Find the values of the
! integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3,
! 3}. (@bullet{})
Calc's integrator can do many simple integrals symbolically, but many
others are beyond its capabilities. Suppose we wish to find the area
! under the curve
! @texline @tmath{\sin x \ln x}
! @infoline @expr{sin(x) ln(x)}
! over the same range of @expr{x}. If you entered this formula and typed
! @kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a
! long time but would be unable to find a solution. In fact, there is no
! closedform solution to this integral. Now what do we do?
@cindex Integration, numerical
@cindex Numerical integration
***************
*** 5322,5328 ****
@noindent
Here we have computed the Taylor series expansion of the function
! about the point @cite{x=1}. We can now integrate this polynomial
approximation, since polynomials are easy to integrate.
@smallexample
 5379,5385 
@noindent
Here we have computed the Taylor series expansion of the function
! about the point @expr{x=1}. We can now integrate this polynomial
approximation, since polynomials are easy to integrate.
@smallexample
***************
*** 5339,5346 ****
in the Taylor series, we can get a result as accurate as we like.
(Taylor series converge better away from singularities in the
function such as the one at @code{ln(0)}, so it would also help to
! expand the series about the points @cite{x=2} or @cite{x=1.5} instead
! of @cite{x=1}.)
@cindex Simpson's rule
@cindex Integration by Simpson's rule
 5396,5403 
in the Taylor series, we can get a result as accurate as we like.
(Taylor series converge better away from singularities in the
function such as the one at @code{ln(0)}, so it would also help to
! expand the series about the points @expr{x=2} or @expr{x=1.5} instead
! of @expr{x=1}.)
@cindex Simpson's rule
@cindex Integration by Simpson's rule
***************
*** 5370,5376 ****
@end tex
@noindent
! where @cite{n} (which must be even) is the number of slices and @cite{h}
is the width of each slice. These are 10 and 0.1 in our example.
For reference, here is the corresponding formula for the stairstep
method:
 5427,5433 
@end tex
@noindent
! where @expr{n} (which must be even) is the number of slices and @expr{h}
is the width of each slice. These are 10 and 0.1 in our example.
For reference, here is the corresponding formula for the stairstep
method:
***************
*** 5389,5397 ****
\afterdisplay
@end tex
! Compute the integral from 1 to 2 of @c{$\sin x \ln x$}
! @cite{sin(x) ln(x)} using
! Simpson's rule with 10 slices. @xref{Algebra Answer 4, 4}. (@bullet{})
Calc has a builtin @kbd{a I} command for doing numerical integration.
It uses @dfn{Romberg's method}, which is a more sophisticated cousin
 5446,5456 
\afterdisplay
@end tex
! Compute the integral from 1 to 2 of
! @texline @tmath{\sin x \ln x}
! @infoline @expr{sin(x) ln(x)}
! using Simpson's rule with 10 slices.
! @xref{Algebra Answer 4, 4}. (@bullet{})
Calc has a builtin @kbd{a I} command for doing numerical integration.
It uses @dfn{Romberg's method}, which is a more sophisticated cousin
***************
*** 5639,5645 ****
A common error with rewrite
rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
to match any @samp{f} with five arguments but in fact matching
! only when the fifth argument is literally @address@hidden
@cindex Fibonacci numbers
@ignore
 5698,5704 
A common error with rewrite
rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
to match any @samp{f} with five arguments but in fact matching
! only when the fifth argument is literally @samp{e}!
@cindex Fibonacci numbers
@ignore
***************
*** 5789,5798 ****
@samp{opt(a) + opt(b) x := f(a, b, x)}. What happened?
@xref{Rewrites Answer 3, 3}. (@bullet{})
! (@bullet{}) @strong{Exercise 4.} Starting with a positive integer @cite{a},
! divide @cite{a} by two if it is even, otherwise compute @cite{3 a + 1}.
Now repeat this step over and over. A famous unproved conjecture
! is that for any starting @cite{a}, the sequence always eventually
reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of
rules that convert this into @samp{seq(1, @var{n})} where @var{n}
is the number of steps it took the sequence to reach the value 1.
 5848,5857 
@samp{opt(a) + opt(b) x := f(a, b, x)}. What happened?
@xref{Rewrites Answer 3, 3}. (@bullet{})
! (@bullet{}) @strong{Exercise 4.} Starting with a positive integer @expr{a},
! divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}.
Now repeat this step over and over. A famous unproved conjecture
! is that for any starting @expr{a}, the sequence always eventually
reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of
rules that convert this into @samp{seq(1, @var{n})} where @var{n}
is the number of steps it took the sequence to reach the value 1.
***************
*** 5801,5827 ****
Now make the result be a vector of values in the sequence, from @var{a}
to 1. (The formula @address@hidden@var{y}} appends the vectors @var{x}
and @var{y}.) For example, rewriting @samp{seq(6)} should yield the
! vector @cite{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
@xref{Rewrites Answer 4, 4}. (@bullet{})
(@bullet{}) @strong{Exercise 5.} Define, using rewrite rules, a function
@samp{nterms(@var{x})} that returns the number of terms in the sum
@var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes
is one or more nonsum terms separated by @samp{+} or @samp{} signs,
! so that @cite{2  3 (x + y) + x y} is a sum of three terms.)
@xref{Rewrites Answer 5, 5}. (@bullet{})
! (@bullet{}) @strong{Exercise 6.} Calc considers the form @cite{0^0}
to be ``indeterminate,'' and leaves it unevaluated (assuming infinite
! mode is not enabled). Some people prefer to define @cite{0^0 = 1},
! so that the identity @cite{x^0 = 1} can safely be used for all @cite{x}.
Find a way to make Calc follow this convention. What happens if you
now type @kbd{m i} to turn on infinite mode?
@xref{Rewrites Answer 6, 6}. (@bullet{})
(@bullet{}) @strong{Exercise 7.} A Taylor series for a function is an
infinite series that exactly equals the value of that function at
! values of @cite{x} near zero.
@ifinfo
@example
 5860,5886 
Now make the result be a vector of values in the sequence, from @var{a}
to 1. (The formula @address@hidden@var{y}} appends the vectors @var{x}
and @var{y}.) For example, rewriting @samp{seq(6)} should yield the
! vector @expr{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
@xref{Rewrites Answer 4, 4}. (@bullet{})
(@bullet{}) @strong{Exercise 5.} Define, using rewrite rules, a function
@samp{nterms(@var{x})} that returns the number of terms in the sum
@var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes
is one or more nonsum terms separated by @samp{+} or @samp{} signs,
! so that @expr{2  3 (x + y) + x y} is a sum of three terms.)
@xref{Rewrites Answer 5, 5}. (@bullet{})
! (@bullet{}) @strong{Exercise 6.} Calc considers the form @expr{0^0}
to be ``indeterminate,'' and leaves it unevaluated (assuming infinite
! mode is not enabled). Some people prefer to define @expr{0^0 = 1},
! so that the identity @expr{x^0 = 1} can safely be used for all @expr{x}.
Find a way to make Calc follow this convention. What happens if you
now type @kbd{m i} to turn on infinite mode?
@xref{Rewrites Answer 6, 6}. (@bullet{})
(@bullet{}) @strong{Exercise 7.} A Taylor series for a function is an
infinite series that exactly equals the value of that function at
! values of @expr{x} near zero.
@ifinfo
@example
***************
*** 5829,5843 ****
@end example
@end ifinfo
@tex
! \turnoffactive \let\rm\goodrm
\beforedisplay
$$ \cos x = 1  {x^2 \over 2!} + {x^4 \over 4!}  {x^6 \over 6!} + \cdots $$
\afterdisplay
@end tex
The @kbd{a t} command produces a @dfn{truncated Taylor series} which
! is obtained by dropping all the terms higher than, say, @cite{x^2}.
! Calc represents the truncated Taylor series as a polynomial in @cite{x}.
Mathematicians often write a truncated series using a ``bigO'' notation
that records what was the lowest term that was truncated.
 5888,5902 
@end example
@end ifinfo
@tex
! \turnoffactive
\beforedisplay
$$ \cos x = 1  {x^2 \over 2!} + {x^4 \over 4!}  {x^6 \over 6!} + \cdots $$
\afterdisplay
@end tex
The @kbd{a t} command produces a @dfn{truncated Taylor series} which
! is obtained by dropping all the terms higher than, say, @expr{x^2}.
! Calc represents the truncated Taylor series as a polynomial in @expr{x}.
Mathematicians often write a truncated series using a ``bigO'' notation
that records what was the lowest term that was truncated.
***************
*** 5847,5861 ****
@end example
@end ifinfo
@tex
! \turnoffactive \let\rm\goodrm
\beforedisplay
$$ \cos x = 1  {x^2 \over 2!} + O(x^3) $$
\afterdisplay
@end tex
@noindent
! The meaning of @cite{O(x^3)} is ``a quantity which is negligibly small
! if @cite{x^3} is considered negligibly small as @cite{x} goes to zero.''
The exercise is to create rewrite rules that simplify sums and products of
power series represented as @address@hidden + O(@address@hidden)}.
 5906,5920 
@end example
@end ifinfo
@tex
! \turnoffactive
\beforedisplay
$$ \cos x = 1  {x^2 \over 2!} + O(x^3) $$
\afterdisplay
@end tex
@noindent
! The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small
! if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.''
The exercise is to create rewrite rules that simplify sums and products of
power series represented as @address@hidden + O(@address@hidden)}.
***************
*** 5934,5942 ****
@end ignore
@tindex Si
(@bullet{}) @strong{Exercise 1.} The ``sine integral'' function
! @c{${\rm Si}(x)$}
! @cite{Si(x)} is defined as the integral of @samp{sin(t)/t} for
! @cite{t = 0} to @cite{x} in radians. (It was invented because this
integral has no solution in terms of basic functions; if you give it
to Calc's @kbd{a i} command, it will ponder it for a long time and then
give up.) We can use the numerical integration command, however,
 5993,6002 
@end ignore
@tindex Si
(@bullet{}) @strong{Exercise 1.} The ``sine integral'' function
! @texline @tmath{{\rm Si}(x)}
! @infoline @expr{Si(x)}
! is defined as the integral of @samp{sin(t)/t} for
! @expr{t = 0} to @expr{x} in radians. (It was invented because this
integral has no solution in terms of basic functions; if you give it
to Calc's @kbd{a i} command, it will ponder it for a long time and then
give up.) We can use the numerical integration command, however,
***************
*** 6010,6021 ****
@enumerate
@item
! Compute @c{$\displaystyle{\sin x \over x}$}
! @cite{sin(x) / x}, where @cite{x} is the number on the
! top of the stack.
@item
! Compute the address@hidden logarithm, just like the @kbd{B} key except
the arguments are taken in the opposite order.
@item
 6070,6082 
@enumerate
@item
! Compute
! @texline @tmath{\displaystyle{\sin x \over x}},
! @infoline @expr{sin(x) / x},
! where @expr{x} is the number on the top of the stack.
@item
! Compute the address@hidden logarithm, just like the @kbd{B} key except
the arguments are taken in the opposite order.
@item
***************
*** 6044,6050 ****
@end smallexample
@noindent
! Here we have computed the fourth derivative of @cite{x^6} by
enclosing a derivative command in a ``repeat loop'' structure.
This structure pops a repeat count from the stack, then
executes the body of the loop that many times.
 6105,6111 
@end smallexample
@noindent
! Here we have computed the fourth derivative of @expr{x^6} by
enclosing a derivative command in a ``repeat loop'' structure.
This structure pops a repeat count from the stack, then
executes the body of the loop that many times.
***************
*** 6074,6087 ****
@cindex Golden ratio
@cindex Phi, golden ratio
! A fascinating property of the Fibonacci numbers is that the @cite{n}th
! Fibonacci number can be found directly by computing @c{$\phi^n / \sqrt{5}$}
! @cite{phi^n / sqrt(5)}
! and then rounding to the nearest integer, where @c{$\phi$ (``phi'')}
! @cite{phi}, the
! ``golden ratio,'' is @c{$(1 + \sqrt{5}) / 2$}
! @cite{(1 + sqrt(5)) / 2}. (For convenience, this constant is available
! from the @code{phi} variable, or the @kbd{I H P} command.)
@smallexample
@group
 6135,6152 
@cindex Golden ratio
@cindex Phi, golden ratio
! A fascinating property of the Fibonacci numbers is that the @expr{n}th
! Fibonacci number can be found directly by computing
! @texline @tmath{\phi^n / \sqrt{5}}
! @infoline @expr{phi^n / sqrt(5)}
! and then rounding to the nearest integer, where
! @texline @tmath{\phi} (``phi''),
! @infoline @expr{phi},
! the ``golden ratio,'' is
! @texline @tmath{(1 + \sqrt{5}) / 2}.
! @infoline @expr{(1 + sqrt(5)) / 2}.
! (For convenience, this constant is available from the @code{phi}
! variable, or the @kbd{I H P} command.)
@smallexample
@group
***************
*** 6094,6115 ****
@cindex Continued fractions
(@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction}
! representation of @c{$\phi$}
! @cite{phi} is @c{$1 + 1/(1 + 1/(1 + 1/( \ldots )))$}
! @cite{1 + 1/(1 + 1/(1 + 1/( ...@: )))}.
We can compute an approximate value by carrying this however far
! and then replacing the innermost @c{$1/( \ldots )$}
! @cite{1/( ...@: )} by 1. Approximate
! @c{$\phi$}
! @cite{phi} using a twentyterm continued fraction.
@xref{Programming Answer 5, 5}. (@bullet{})
(@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for
Fibonacci numbers can be expressed in terms of matrices. Given a
! vector @address@hidden, b]}} determine a matrix which, when multiplied by this
! vector, produces the vector @cite{[b, c]}, where @cite{a}, @cite{b} and
! @cite{c} are three successive Fibonacci numbers. Now write a program
! that, given an integer @cite{n}, computes the @cite{n}th Fibonacci number
using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{})
@cindex Harmonic numbers
 6159,6186 
@cindex Continued fractions
(@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction}
! representation of
! @texline @tmath{\phi}
! @infoline @expr{phi}
! is
! @texline @tmath{1 + 1/(1 + 1/(1 + 1/( \ldots )))}.
! @infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}.
We can compute an approximate value by carrying this however far
! and then replacing the innermost
! @texline @tmath{1/( \ldots )}
! @infoline @expr{1/( ...@: )}
! by 1. Approximate
! @texline @tmath{\phi}
! @infoline @expr{phi}
! using a twentyterm continued fraction.
@xref{Programming Answer 5, 5}. (@bullet{})
(@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for
Fibonacci numbers can be expressed in terms of matrices. Given a
! vector @address@hidden, b]}} determine a matrix which, when multiplied by this
! vector, produces the vector @expr{[b, c]}, where @expr{a}, @expr{b} and
! @expr{c} are three successive Fibonacci numbers. Now write a program
! that, given an integer @expr{n}, computes the @expr{n}th Fibonacci number
using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{})
@cindex Harmonic numbers
***************
*** 6198,6209 ****
The @dfn{Bernoulli numbers} are a sequence with the interesting
property that all of the odd Bernoulli numbers are zero, and the
even ones, while difficult to compute, can be roughly approximated
! by the formula @c{$\displaystyle{2 n! \over (2 \pi)^n}$}
! @cite{2 n!@: / (2 pi)^n}. Let's write a keyboard
! macro to compute (approximate) Bernoulli numbers. (Calc has a
! command, @kbd{k b}, to compute exact Bernoulli numbers, but
! this command is very slow for large @cite{n} since the higher
! Bernoulli numbers are very large fractions.)
@smallexample
@group
 6269,6281 
The @dfn{Bernoulli numbers} are a sequence with the interesting
property that all of the odd Bernoulli numbers are zero, and the
even ones, while difficult to compute, can be roughly approximated
! by the formula
! @texline @tmath{\displaystyle{2 n! \over (2 \pi)^n}}.
! @infoline @expr{2 n!@: / (2 pi)^n}.
! Let's write a keyboard macro to compute (approximate) Bernoulli numbers.
! (Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but
! this command is very slow for large @expr{n} since the higher Bernoulli
! numbers are very large fractions.)
@smallexample
@group
***************
*** 6223,6229 ****
Here we take our integer argument modulo 2; this will be nonzero
if we're asking for an odd Bernoulli number.
! The actual tenth Bernoulli number is @cite{5/66}.
@smallexample
@group
 6295,6301 
Here we take our integer argument modulo 2; this will be nonzero
if we're asking for an odd Bernoulli number.
! The actual tenth Bernoulli number is @expr{5/66}.
@smallexample
@group
***************
*** 6354,6361 ****
(@bullet{}) @strong{Exercise 8.} A general algorithm for solving
equations numerically is @dfn{Newton's Method}. Given the equation
! @cite{f(x) = 0} for any function @cite{f}, and an initial guess
! @cite{x_0} which is reasonably close to the desired solution, apply
this formula over and over:
@ifinfo
 6426,6433 
(@bullet{}) @strong{Exercise 8.} A general algorithm for solving
equations numerically is @dfn{Newton's Method}. Given the equation
! @expr{f(x) = 0} for any function @expr{f}, and an initial guess
! @expr{x_0} which is reasonably close to the desired solution, apply
this formula over and over:
@ifinfo
***************
*** 6365,6396 ****
@end ifinfo
@tex
\beforedisplay
! $$ x_{\goodrm new} = x  {f(x) \over f'(x)} $$
\afterdisplay
@end tex
@noindent
! where @cite{f'(x)} is the derivative of @cite{f}. The @cite{x}
values will quickly converge to a solution, i.e., eventually
! @c{$x_{\rm new}$}
! @cite{new_x} and @cite{x} will be equal to within the limits
of the current precision. Write a program which takes a formula
! involving the variable @cite{x}, and an initial guess @cite{x_0},
! on the stack, and produces a value of @cite{x} for which the formula
! is zero. Use it to find a solution of @c{$\sin(\cos x) = 0.5$}
! @cite{sin(cos(x)) = 0.5}
! near @cite{x = 4.5}. (Use angles measured in radians.) Note that
the builtin @address@hidden R}} (@code{calcfindroot}) command uses Newton's
method when it is able. @xref{Programming Answer 8, 8}. (@bullet{})
@cindex Digamma function
@cindex Gamma constant, Euler's
@cindex Euler's gamma constant
! (@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function @c{$\psi(z)$
(``psi'')}
! @cite{psi(z)}
! is defined as the derivative of @c{$\ln \Gamma(z)$}
! @cite{ln(gamma(z))}. For large
! values of @cite{z}, it can be approximated by the infinite sum
@ifinfo
@example
 6437,6472 
@end ifinfo
@tex
\beforedisplay
! $$ x_{\rm new} = x  {f(x) \over f'(x)} $$
\afterdisplay
@end tex
@noindent
! where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x}
values will quickly converge to a solution, i.e., eventually
! @texline @tmath{x_{\rm new}}
! @infoline @expr{new_x}
! and @expr{x} will be equal to within the limits
of the current precision. Write a program which takes a formula
! involving the variable @expr{x}, and an initial guess @expr{x_0},
! on the stack, and produces a value of @expr{x} for which the formula
! is zero. Use it to find a solution of
! @texline @tmath{\sin(\cos x) = 0.5}
! @infoline @expr{sin(cos(x)) = 0.5}
! near @expr{x = 4.5}. (Use angles measured in radians.) Note that
the builtin @address@hidden R}} (@code{calcfindroot}) command uses Newton's
method when it is able. @xref{Programming Answer 8, 8}. (@bullet{})
@cindex Digamma function
@cindex Gamma constant, Euler's
@cindex Euler's gamma constant
! (@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function
! @texline @tmath{\psi(z) (``psi'')}
! @infoline @expr{psi(z)}
! is defined as the derivative of
! @texline @tmath{\ln \Gamma(z)}.
! @infoline @expr{ln(gamma(z))}.
! For large values of @expr{z}, it can be approximated by the infinite sum
@ifinfo
@example
***************
*** 6398,6404 ****
@end example
@end ifinfo
@tex
 \let\rm\goodrm
\beforedisplay
$$ \psi(z) \approx \ln z  {1\over2z} 
\sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}}
 6474,6479 
***************
*** 6407,6443 ****
@end tex
@noindent
! where @c{$\sum$}
! @cite{sum} represents the sum over @cite{n} from 1 to infinity
(or to some limit high enough to give the desired accuracy), and
the @code{bern} function produces (exact) Bernoulli numbers.
While this sum is not guaranteed to converge, in practice it is safe.
An interesting mathematical constant is Euler's gamma, which is equal
to about 0.5772. One way to compute it is by the formula,
! @c{$\gamma = \psi(1)$}
! @cite{gamma = psi(1)}. Unfortunately, 1 isn't a large enough argument
! for the above formula to work (5 is a much safer value for @cite{z}).
! Fortunately, we can compute @c{$\psi(1)$}
! @cite{psi(1)} from @c{$\psi(5)$}
! @cite{psi(5)} using
! the recurrence @c{$\psi(z+1) = \psi(z) + {1 \over z}$}
! @cite{psi(z+1) = psi(z) + 1/z}. Your task: Develop
! a program to compute @c{$\psi(z)$}
! @cite{psi(z)}; it should ``pump up'' @cite{z}
if necessary to be greater than 5, then use the above summation
formula. Use looping commands to compute the sum. Use your function
! to compute @c{$\gamma$}
! @cite{gamma} to twelve decimal places. (Calc has a builtin command
for Euler's constant, @kbd{I P}, which you can use to check your answer.)
@xref{Programming Answer 9, 9}. (@bullet{})
@cindex Polynomial, list of coefficients
! (@bullet{}) @strong{Exercise 10.} Given a polynomial in @cite{x} and
! a number @cite{m} on the stack, where the polynomial is of degree
! @cite{m} or less (i.e., does not have any terms higher than @cite{x^m}),
write a program to convert the polynomial into a listofcoefficients
! notation. For example, @cite{5 x^4 + (x + 1)^2} with @cite{m = 6}
! should produce the list @cite{[1, 2, 1, 0, 5, 0, 0]}. Also develop
a way to convert from this form back to the standard algebraic form.
@xref{Programming Answer 10, 10}. (@bullet{})
 6482,6529 
@end tex
@noindent
! where
! @texline @tmath{\sum}
! @infoline @expr{sum}
! represents the sum over @expr{n} from 1 to infinity
(or to some limit high enough to give the desired accuracy), and
the @code{bern} function produces (exact) Bernoulli numbers.
While this sum is not guaranteed to converge, in practice it is safe.
An interesting mathematical constant is Euler's gamma, which is equal
to about 0.5772. One way to compute it is by the formula,
! @texline @tmath{\gamma = \psi(1)}.
! @infoline @expr{gamma = psi(1)}.
! Unfortunately, 1 isn't a large enough argument
! for the above formula to work (5 is a much safer value for @expr{z}).
! Fortunately, we can compute
! @texline @tmath{\psi(1)}
! @infoline @expr{psi(1)}
! from
! @texline @tmath{\psi(5)}
! @infoline @expr{psi(5)}
! using the recurrence
! @texline @tmath{\psi(z+1) = \psi(z) + {1 \over z}}.
! @infoline @expr{psi(z+1) = psi(z) + 1/z}.
! Your task: Develop a program to compute
! @texline @tmath{\psi(z)};
! @infoline @expr{psi(z)};
! it should ``pump up'' @expr{z}
if necessary to be greater than 5, then use the above summation
formula. Use looping commands to compute the sum. Use your function
! to compute
! @texline @tmath{\gamma}
! @infoline @expr{gamma}
! to twelve decimal places. (Calc has a builtin command
for Euler's constant, @kbd{I P}, which you can use to check your answer.)
@xref{Programming Answer 9, 9}. (@bullet{})
@cindex Polynomial, list of coefficients
! (@bullet{}) @strong{Exercise 10.} Given a polynomial in @expr{x} and
! a number @expr{m} on the stack, where the polynomial is of degree
! @expr{m} or less (i.e., does not have any terms higher than @expr{x^m}),
write a program to convert the polynomial into a listofcoefficients
! notation. For example, @expr{5 x^4 + (x + 1)^2} with @expr{m = 6}
! should produce the list @expr{[1, 2, 1, 0, 5, 0, 0]}. Also develop
a way to convert from this form back to the standard algebraic form.
@xref{Programming Answer 10, 10}. (@bullet{})
***************
*** 6478,6486 ****
the complete recursive program. (Another way is to use @address@hidden E}}
or @kbd{M# m} (@code{readkbdmacro}) to read the whole macro at once,
thus avoiding the ``training'' phase.) The task: Write a program
! that computes Stirling numbers of the first kind, given @cite{n} and
! @cite{m} on the stack. Test it with @emph{small} inputs like
! @cite{s(4,2)}. (There is a builtin command for Stirling numbers,
@kbd{k s}, which you can use to check your answers.)
@xref{Programming Answer 11, 11}. (@bullet{})
 6564,6572 
the complete recursive program. (Another way is to use @address@hidden E}}
or @kbd{M# m} (@code{readkbdmacro}) to read the whole macro at once,
thus avoiding the ``training'' phase.) The task: Write a program
! that computes Stirling numbers of the first kind, given @expr{n} and
! @expr{m} on the stack. Test it with @emph{small} inputs like
! @expr{s(4,2)}. (There is a builtin command for Stirling numbers,
@kbd{k s}, which you can use to check your answers.)
@xref{Programming Answer 11, 11}. (@bullet{})
***************
*** 6492,6498 ****
(@bullet{}) @strong{Exercise 12.} Write another program for
computing Stirling numbers of the first kind, this time using
! rewrite rules. Once again, @cite{n} and @cite{m} should be taken
from the stack. @xref{Programming Answer 12, 12}. (@bullet{})
@example
 6578,6584 
(@bullet{}) @strong{Exercise 12.} Write another program for
computing Stirling numbers of the first kind, this time using
! rewrite rules. Once again, @expr{n} and @expr{m} should be taken
from the stack. @xref{Programming Answer 12, 12}. (@bullet{})
@example
***************
*** 6601,6621 ****
@noindent
@kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * }
! The result is @c{$1  (2 \times (3 + 4)) = 13$}
! @cite{1  (2 * (3 + 4)) = 13}.
@node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises
@subsection RPN Tutorial Exercise 2
@noindent
! @c{$2\times4 + 7\times9.5 + {5\over4} = 75.75$}
! @cite{2*4 + 7*9.5 + 5/4 = 75.75}
! After computing the intermediate term @c{$2\times4 = 8$}
! @cite{2*4 = 8}, you can leave
! that result on the stack while you compute the second term. With
! both of these results waiting on the stack you can then compute the
! final term, then press @kbd{+ +} to add everything up.
@smallexample
@group
 6687,6709 
@noindent
@kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * }
! The result is
! @texline @tmath{1  (2 \times (3 + 4)) = 13}.
! @infoline @expr{1  (2 * (3 + 4)) = 13}.
@node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises
@subsection RPN Tutorial Exercise 2
@noindent
! @texline @tmath{2\times4 + 7\times9.5 + {5\over4} = 75.75}
! @infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75}
! After computing the intermediate term
! @texline @tmath{2\times4 = 8},
! @infoline @expr{2*4 = 8},
! you can leave that result on the stack while you compute the second
! term. With both of these results waiting on the stack you can then
! compute the final term, then press @kbd{+ +} to add everything up.
@smallexample
@group
***************
*** 6739,6746 ****
Or, RPN style, @kbd{0.5 ^}.
(Actually, @samp{$^1:2}, using the fraction onehalf as the power, is
! a closer equivalent, since @samp{9^0.5} yields @cite{3.0} whereas
! @samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @cite{3}.)
@node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to
Exercises
@subsection Algebraic Entry Tutorial Exercise 2
 6827,6834 
Or, RPN style, @kbd{0.5 ^}.
(Actually, @samp{$^1:2}, using the fraction onehalf as the power, is
! a closer equivalent, since @samp{9^0.5} yields @expr{3.0} whereas
! @samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @expr{3}.)
@node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to
Exercises
@subsection Algebraic Entry Tutorial Exercise 2
***************
*** 6755,6768 ****
@subsection Algebraic Entry Tutorial Exercise 3
@noindent
! The result from @kbd{1 @key{RET} 0 /} will be the formula @cite{1 / 0}.
The ``function'' @samp{/} cannot be evaluated when its second argument
is zero, so it is left in symbolic form. When you now type @kbd{0 *},
the result will be zero because Calc uses the general rule that ``zero
times anything is zero.''
@c [fixref Infinities]
! The @kbd{m i} command enables an @dfn{infinite mode} in which @cite{1 / 0}
results in a special symbol that represents ``infinity.'' If you
multiply infinity by zero, Calc uses another special new symbol to
show that the answer is ``indeterminate.'' @xref{Infinities}, for
 6843,6856 
@subsection Algebraic Entry Tutorial Exercise 3
@noindent
! The result from @kbd{1 @key{RET} 0 /} will be the formula @expr{1 / 0}.
The ``function'' @samp{/} cannot be evaluated when its second argument
is zero, so it is left in symbolic form. When you now type @kbd{0 *},
the result will be zero because Calc uses the general rule that ``zero
times anything is zero.''
@c [fixref Infinities]
! The @kbd{m i} command enables an @dfn{infinite mode} in which @expr{1 / 0}
results in a special symbol that represents ``infinity.'' If you
multiply infinity by zero, Calc uses another special new symbol to
show that the answer is ``indeterminate.'' @xref{Infinities}, for
***************
*** 6852,6858 ****
@subsection Modes Tutorial Exercise 3
@noindent
! The answer he got was @cite{0.5000000000006399}.
The problem is not that the square operation is inexact, but that the
sine of 45 that was already on the stack was accurate to only 12 places.
 6940,6946 
@subsection Modes Tutorial Exercise 3
@noindent
! The answer he got was @expr{0.5000000000006399}.
The problem is not that the square operation is inexact, but that the
sine of 45 that was already on the stack was accurate to only 12 places.
***************
*** 6917,6932 ****
@noindent
Dividing two integers that are larger than the current precision may
give a floatingpoint result that is inaccurate even when rounded
! down to an integer. Consider @cite{123456789 / 2} when the current
! precision is 6 digits. The true answer is @cite{61728394.5}, but
! with a precision of 6 this will be rounded to @c{$12345700.0/2.0 =
61728500.0$}
! @cite{12345700.@: / 2.@: = 61728500.}.
The result, when converted to an integer, will be off by 106.
Here are two solutions: Raise the precision enough that the
floatingpoint roundoff error is strictly to the right of the
! decimal point. Or, convert to fraction mode so that @cite{123456789 / 2}
! produces the exact fraction @cite{123456789:2}, which can be rounded
down by the @kbd{F} command without ever switching to floatingpoint
format.
 7005,7021 
@noindent
Dividing two integers that are larger than the current precision may
give a floatingpoint result that is inaccurate even when rounded
! down to an integer. Consider @expr{123456789 / 2} when the current
! precision is 6 digits. The true answer is @expr{61728394.5}, but
! with a precision of 6 this will be rounded to
! @texline @tmath{12345700.0/2.0 = 61728500.0}.
! @infoline @expr{12345700.@: / 2.@: = 61728500.}.
The result, when converted to an integer, will be off by 106.
Here are two solutions: Raise the precision enough that the
floatingpoint roundoff error is strictly to the right of the
! decimal point. Or, convert to fraction mode so that @expr{123456789 / 2}
! produces the exact fraction @expr{123456789:2}, which can be rounded
down by the @kbd{F} command without ever switching to floatingpoint
format.
***************
*** 6934,6941 ****
@subsection Arithmetic Tutorial Exercise 2
@noindent
! @kbd{27 @key{RET} 9 B} could give the exact result @cite{3:2}, but it
! does a floatingpoint calculation instead and produces @cite{1.5}.
Calc will find an exact result for a logarithm if the result is an integer
or the reciprocal of an integer. But there is no efficient way to search
 7023,7030 
@subsection Arithmetic Tutorial Exercise 2
@noindent
! @kbd{27 @key{RET} 9 B} could give the exact result @expr{3:2}, but it
! does a floatingpoint calculation instead and produces @expr{1.5}.
Calc will find an exact result for a logarithm if the result is an integer
or the reciprocal of an integer. But there is no efficient way to search
***************
*** 7029,7042 ****
@subsection Matrix Tutorial Exercise 3
@noindent
! To solve @c{$A^T A \, X = A^T B$}
! @cite{trn(A) * A * X = trn(A) * B}, first we compute
! @c{$A' = A^T A$}
! @cite{A2 = trn(A) * A} and @c{$B' = A^T B$}
! @cite{B2 = trn(A) * B}; now, we have a
! system @c{$A' X = B'$}
! @cite{A2 * X = B2} which we can solve using Calc's @samp{/}
! command.
@ifinfo
@example
 7118,7136 
@subsection Matrix Tutorial Exercise 3
@noindent
! To solve
! @texline @tmath{A^T A \, X = A^T B},
! @infoline @expr{trn(A) * A * X = trn(A) * B},
! first we compute
! @texline @tmath{A' = A^T A}
! @infoline @expr{A2 = trn(A) * A}
! and
! @texline @tmath{B' = A^T B};
! @infoline @expr{B2 = trn(A) * B};
! now, we have a system
! @texline @tmath{A' X = B'}
! @infoline @expr{A2 * X = B2}
! which we can solve using Calc's @samp{/} command.
@ifinfo
@example
***************
*** 7066,7073 ****
The first step is to enter the coefficient matrix. We'll store it in
quick variable number 7 for later reference. Next, we compute the
! @c{$B'$}
! @cite{B2} vector.
@smallexample
@group
 7160,7168 
The first step is to enter the coefficient matrix. We'll store it in
quick variable number 7 for later reference. Next, we compute the
! @texline @tmath{B'}
! @infoline @expr{B2}
! vector.
@smallexample
@group
***************
*** 7082,7089 ****
@end smallexample
@noindent
! Now we compute the matrix @c{$A'$}
! @cite{A2} and divide.
@smallexample
@group
 7177,7186 
@end smallexample
@noindent
! Now we compute the matrix
! @texline @tmath{A'}
! @infoline @expr{A2}
! and divide.
@smallexample
@group
***************
*** 7101,7114 ****
(The actual computed answer will be slightly inexact due to
roundoff error.)
! Notice that the answers are similar to those for the @c{$3\times3$}
! @asis{3x3} system
! solved in the text. That's because the fourth equation that was
added to the system is almost identical to the first one multiplied
by two. (If it were identical, we would have gotten the exact same
! answer since the @c{$4\times3$}
! @asis{4x3} system would be equivalent to the original @c{$3\times3$}
! @asis{3x3}
system.)
Since the first and fourth equations aren't quite equivalent, they
 7198,7215 
(The actual computed answer will be slightly inexact due to
roundoff error.)
! Notice that the answers are similar to those for the
! @texline @tmath{3\times3}
! @infoline 3x3
! system solved in the text. That's because the fourth equation that was
added to the system is almost identical to the first one multiplied
by two. (If it were identical, we would have gotten the exact same
! answer since the
! @texline @tmath{4\times3}
! @infoline 4x3
! system would be equivalent to the original
! @texline @tmath{3\times3}
! @infoline 3x3
system.)
Since the first and fourth equations aren't quite equivalent, they
***************
*** 7129,7136 ****
@end smallexample
@noindent
! This is reasonably close to our original @cite{B} vector,
! @cite{[6, 2, 3, 11]}.
@node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises
@subsection List Tutorial Exercise 1
 7230,7237 
@end smallexample
@noindent
! This is reasonably close to our original @expr{B} vector,
! @expr{[6, 2, 3, 11]}.
@node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises
@subsection List Tutorial Exercise 1
***************
*** 7168,7174 ****
@subsection List Tutorial Exercise 2
@noindent
! Given @cite{x} and @cite{y} vectors in quick variables 1 and 2 as before,
the first job is to form the matrix that describes the problem.
@ifinfo
 7269,7275 
@subsection List Tutorial Exercise 2
@noindent
! Given @expr{x} and @expr{y} vectors in quick variables 1 and 2 as before,
the first job is to form the matrix that describes the problem.
@ifinfo
***************
*** 7183,7192 ****
\afterdisplay
@end tex
! Thus we want a @c{$19\times2$}
! @asis{19x2} matrix with our @cite{x} vector as one column and
ones as the other column. So, first we build the column of ones, then
! we combine the two columns to form our @cite{A} matrix.
@smallexample
@group
 7284,7295 
\afterdisplay
@end tex
! Thus we want a
! @texline @tmath{19\times2}
! @infoline 19x2
! matrix with our @expr{x} vector as one column and
ones as the other column. So, first we build the column of ones, then
! we combine the two columns to form our @expr{A} matrix.
@smallexample
@group
***************
*** 7200,7208 ****
@end smallexample
@noindent
! Now we compute @c{$A^T y$}
! @cite{trn(A) * y} and @c{$A^T A$}
! @cite{trn(A) * A} and divide.
@smallexample
@group
 7303,7315 
@end smallexample
@noindent
! Now we compute
! @texline @tmath{A^T y}
! @infoline @expr{trn(A) * y}
! and
! @texline @tmath{A^T A}
! @infoline @expr{trn(A) * A}
! and divide.
@smallexample
@group
***************
*** 7227,7236 ****
@end group
@end smallexample
! Since we were solving equations of the form @c{$m \times x + b \times 1 = y$}
! @cite{m*x + b*1 = y}, these
! numbers should be @cite{m} and @cite{b}, respectively. Sure enough, they
! agree exactly with the result computed using @kbd{V M} and @kbd{V R}!
The moral of this story: @kbd{V M} and @kbd{V R} will probably solve
your problem, but there is often an easier way using the higherlevel
 7334,7345 
@end group
@end smallexample
! Since we were solving equations of the form
! @texline @tmath{m \times x + b \times 1 = y},
! @infoline @expr{m*x + b*1 = y},
! these numbers should be @expr{m} and @expr{b}, respectively. Sure
! enough, they agree exactly with the result computed using @kbd{V M} and
! @kbd{V R}!
The moral of this story: @kbd{V M} and @kbd{V R} will probably solve
your problem, but there is often an easier way using the higherlevel
***************
*** 7288,7296 ****
@subsection List Tutorial Exercise 4
@noindent
! A number @cite{j} is a divisor of @cite{n} if @c{$n
\mathbin{\hbox{\code{\%}}} j = 0$}
! @samp{n % j = 0}. The first
! step is to get a vector that identifies the divisors.
@smallexample
@group
 7397,7406 
@subsection List Tutorial Exercise 4
@noindent
! A number @expr{j} is a divisor of @expr{n} if
! @texline @tmath{n \mathbin{\hbox{\code{\%}}} j = 0}.
! @infoline @samp{n % j = 0}.
! The first step is to get a vector that identifies the divisors.
@smallexample
@group
***************
*** 7358,7367 ****
zero, so adding zeros on the left and right is safe. From then on
the job is pretty straightforward.
! Incidentally, Calc provides the @c{\dfn{M\"obius} $\mu$}
! @dfn{Moebius mu} function which is
! zero if and only if its argument is squarefree. It would be a much
! more convenient way to do the above test in practice.
@node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises
@subsection List Tutorial Exercise 6
 7468,7478 
zero, so adding zeros on the left and right is safe. From then on
the job is pretty straightforward.
! Incidentally, Calc provides the
! @texline @dfn{M@"obius} @tmath{\mu}
! @infoline @dfn{Moebius mu}
! function which is zero if and only if its argument is squarefree. It
! would be a much more convenient way to do the above test in practice.
@node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises
@subsection List Tutorial Exercise 6
***************
*** 7389,7398 ****
@end smallexample
The numbers down the lefthand edge of the list we desire are called
! the ``triangular numbers'' (now you know why!). The @cite{n}th
! triangular number is the sum of the integers from 1 to @cite{n}, and
! can be computed directly by the formula @c{$n (n+1) \over 2$}
! @cite{n * (n+1) / 2}.
@smallexample
@group
 7500,7510 
@end smallexample
The numbers down the lefthand edge of the list we desire are called
! the ``triangular numbers'' (now you know why!). The @expr{n}th
! triangular number is the sum of the integers from 1 to @expr{n}, and
! can be computed directly by the formula
! @texline @tmath{n (n+1) \over 2}.
! @infoline @expr{n * (n+1) / 2}.
@smallexample
@group
***************
*** 7446,7452 ****
@subsection List Tutorial Exercise 8
@noindent
! The first step is to build a list of values of @cite{x}.
@smallexample
@group
 7558,7564 
@subsection List Tutorial Exercise 8
@noindent
! The first step is to build a list of values of @expr{x}.
@smallexample
@group
***************
*** 7486,7497 ****
@noindent
It's a good idea to verify, as in the last step above, that only
! one value is equal to the maximum. (After all, a plot of @c{$\sin x$}
! @cite{sin(x)}
might have many points all equal to the maximum value, 1.)
The vector we have now has a single 1 in the position that indicates
! the maximum value of @cite{x}. Now it is a simple matter to convert
this back into the corresponding value itself.
@smallexample
 7598,7610 
@noindent
It's a good idea to verify, as in the last step above, that only
! one value is equal to the maximum. (After all, a plot of
! @texline @tmath{\sin x}
! @infoline @expr{sin(x)}
might have many points all equal to the maximum value, 1.)
The vector we have now has a single 1 in the position that indicates
! the maximum value of @expr{x}. Now it is a simple matter to convert
this back into the corresponding value itself.
@smallexample
***************
*** 7504,7515 ****
@end group
@end smallexample
! If @kbd{a =} had produced more than one @cite{1} value, this method
! would have given the sum of all maximum @cite{x} values; not very
useful! In this case we could have used @kbd{v m} (@code{calcmaskvector})
instead. This command deletes all elements of a ``data'' vector that
correspond to zeros in a ``mask'' vector, leaving us with, in this
! example, a vector of maximum @cite{x} values.
The builtin @kbd{a X} command maximizes a function using more
efficient methods. Just for illustration, let's use @kbd{a X}
 7617,7628 
@end group
@end smallexample
! If @kbd{a =} had produced more than one @expr{1} value, this method
! would have given the sum of all maximum @expr{x} values; not very
useful! In this case we could have used @kbd{v m} (@code{calcmaskvector})
instead. This command deletes all elements of a ``data'' vector that
correspond to zeros in a ``mask'' vector, leaving us with, in this
! example, a vector of maximum @expr{x} values.
The builtin @kbd{a X} command maximizes a function using more
efficient methods. Just for illustration, let's use @kbd{a X}
***************
*** 7526,7532 ****
@end smallexample
@noindent
! The output from @kbd{a X} is a vector containing the value of @cite{x}
that maximizes the function, and the function's value at that maximum.
As you can see, our simple search got quite close to the right answer.
 7639,7645 
@end smallexample
@noindent
! The output from @kbd{a X} is a vector containing the value of @expr{x}
that maximizes the function, and the function's value at that maximum.
As you can see, our simple search got quite close to the right answer.
***************
*** 7656,7665 ****
@subsection List Tutorial Exercise 10
@noindent
! For the list @cite{[a, b, c, d]}, the result is @cite{((a = b) = c) = d},
! which will compare @cite{a} and @cite{b} to produce a 1 or 0, which is
! then compared with @cite{c} to produce another 1 or 0, which is then
! compared with @cite{d}. This is not at all what Joe wanted.
Here's a more correct method:
 7769,7778 
@subsection List Tutorial Exercise 10
@noindent
! For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d},
! which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is
! then compared with @expr{c} to produce another 1 or 0, which is then
! compared with @expr{d}. This is not at all what Joe wanted.
Here's a more correct method:
***************
*** 7687,7695 ****
@subsection List Tutorial Exercise 11
@noindent
! The circle of unit radius consists of those points @cite{(x,y)} for which
! @cite{x^2 + y^2 < 1}. We start by generating a vector of @cite{x^2}
! and a vector of @cite{y^2}.
We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
commands.
 7800,7808 
@subsection List Tutorial Exercise 11
@noindent
! The circle of unit radius consists of those points @expr{(x,y)} for which
! @expr{x^2 + y^2 < 1}. We start by generating a vector of @expr{x^2}
! and a vector of @expr{y^2}.
We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
commands.
***************
*** 7715,7721 ****
@end group
@end smallexample
! Now we sum the @cite{x^2} and @cite{y^2} values, compare with 1 to
get a vector of 1/0 truth values, then sum the truth values.
@smallexample
 7828,7834 
@end group
@end smallexample
! Now we sum the @expr{x^2} and @expr{y^2} values, compare with 1 to
get a vector of 1/0 truth values, then sum the truth values.
@smallexample
***************
*** 7728,7735 ****
@end smallexample
@noindent
! The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$}
! @cite{pi/4}.
@smallexample
@group
 7841,7847 
@end smallexample
@noindent
! The ratio @expr{84/100} should approximate the ratio @cpiover{4}.
@smallexample
@group
***************
*** 7757,7786 ****
@noindent
This problem can be made a lot easier by taking advantage of some
symmetries. First of all, after some thought it's clear that the
! @cite{y} axis can be ignored altogether. Just pick a random @cite{x}
! component for one end of the match, pick a random direction @c{$\theta$}
! @cite{theta},
! and see if @cite{x} and @c{$x + \cos \theta$}
! @cite{x + cos(theta)} (which is the @cite{x}
! coordinate of the other endpoint) cross a line. The lines are at
! integer coordinates, so this happens when the two numbers surround
! an integer.
Since the two endpoints are equivalent, we may as well choose the leftmost
! of the two endpoints as @cite{x}. Then @cite{theta} is an angle pointing
to the right, in the range 90 to 90 degrees. (We could use radians, but
! it would feel like cheating to refer to @c{$\pi/2$}
! @cite{pi/2} radians while trying
! to estimate @c{$\pi$}
! @cite{pi}!)
In fact, since the field of lines is infinite we can choose the
coordinates 0 and 1 for the lines on either side of the leftmost
endpoint. The rightmost endpoint will be between 0 and 1 if the
match does not cross a line, or between 1 and 2 if it does. So:
! Pick random @cite{x} and @c{$\theta$}
! @cite{theta}, compute @c{$x + \cos \theta$}
! @cite{x + cos(theta)},
and count how many of the results are greater than one. Simple!
We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
 7869,7901 
@noindent
This problem can be made a lot easier by taking advantage of some
symmetries. First of all, after some thought it's clear that the
! @expr{y} axis can be ignored altogether. Just pick a random @expr{x}
! component for one end of the match, pick a random direction
! @texline @tmath{\theta},
! @infoline @expr{theta},
! and see if @expr{x} and
! @texline @tmath{x + \cos \theta}
! @infoline @expr{x + cos(theta)}
! (which is the @expr{x} coordinate of the other endpoint) cross a line.
! The lines are at integer coordinates, so this happens when the two
! numbers surround an integer.
Since the two endpoints are equivalent, we may as well choose the leftmost
! of the two endpoints as @expr{x}. Then @expr{theta} is an angle pointing
to the right, in the range 90 to 90 degrees. (We could use radians, but
! it would feel like cheating to refer to @cpiover{2} radians while trying
! to estimate @cpi{}!)
In fact, since the field of lines is infinite we can choose the
coordinates 0 and 1 for the lines on either side of the leftmost
endpoint. The rightmost endpoint will be between 0 and 1 if the
match does not cross a line, or between 1 and 2 if it does. So:
! Pick random @expr{x} and
! @texline @tmath{\theta},
! @infoline @expr{theta},
! compute
! @texline @tmath{x + \cos \theta},
! @infoline @expr{x + cos(theta)},
and count how many of the results are greater than one. Simple!
We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
***************
*** 7881,7888 ****
like @kbd{)} and @kbd{]} at the end of a formula.
We'll show two different approaches here. In the first, we note that
! if the input vector is @cite{[a, b, c, d]}, then the hash code is
! @cite{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}. In other words,
it's a sum of descending powers of three times the ASCII codes.
@smallexample
 7996,8003 
like @kbd{)} and @kbd{]} at the end of a formula.
We'll show two different approaches here. In the first, we note that
! if the input vector is @expr{[a, b, c, d]}, then the hash code is
! @expr{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}. In other words,
it's a sum of descending powers of three times the ASCII codes.
@smallexample
***************
*** 7944,7950 ****
@end smallexample
Why does this work? Think about a twostep computation:
! @address@hidden (3a + b) + c}}. Taking a result modulo 511 basically means
subtracting off enough 511's to put the result in the desired range.
So the result when we take the modulo after every step is,
 8059,8065 
@end smallexample
Why does this work? Think about a twostep computation:
! @address@hidden (3a + b) + c}}. Taking a result modulo 511 basically means
subtracting off enough 511's to put the result in the desired range.
So the result when we take the modulo after every step is,
***************
*** 7961,7967 ****
@end tex
@noindent
! for some suitable integers @cite{m} and @cite{n}. Expanding out by
the distributive law yields
@ifinfo
 8076,8082 
@end tex
@noindent
! for some suitable integers @expr{m} and @expr{n}. Expanding out by
the distributive law yields
@ifinfo
***************
*** 7977,7986 ****
@end tex
@noindent
! The @cite{m} term in the latter formula is redundant because any
! contribution it makes could just as easily be made by the @cite{n}
term. So we can take it out to get an equivalent formula with
! @cite{n' = 3m + n},
@ifinfo
@example
 8092,8101 
@end tex
@noindent
! The @expr{m} term in the latter formula is redundant because any
! contribution it makes could just as easily be made by the @expr{n}
term. So we can take it out to get an equivalent formula with
! @expr{n' = 3m + n},
@ifinfo
@example
***************
*** 8006,8012 ****
@subsection List Tutorial Exercise 14
We want to use @kbd{H V U} to nest a function which adds a random
! step to an @cite{(x,y)} coordinate. The function is a bit long, but
otherwise the problem is quite straightforward.
@smallexample
 8121,8127 
@subsection List Tutorial Exercise 14
We want to use @kbd{H V U} to nest a function which adds a random
! step to an @expr{(x,y)} coordinate. The function is a bit long, but
otherwise the problem is quite straightforward.
@smallexample
***************
*** 8024,8032 ****
notation to keep the two @code{random} calls from being evaluated
before nesting even begins.
! We now have a vector of @cite{[x, y]} subvectors, which by Calc's
rules acts like a matrix. We can transpose this matrix and unpack
! to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing.
@smallexample
@group
 8139,8147 
notation to keep the two @code{random} calls from being evaluated
before nesting even begins.
! We now have a vector of @expr{[x, y]} subvectors, which by Calc's
rules acts like a matrix. We can transpose this matrix and unpack
! to get a pair of vectors, @expr{x} and @expr{y}, suitable for graphing.
@smallexample
@group
***************
*** 8038,8049 ****
@end group
@end smallexample
! Incidentally, because the @cite{x} and @cite{y} are completely
independent in this case, we could have done two separate commands
! to create our @cite{x} and @cite{y} vectors of numbers directly.
To make a random walk of unit steps, we note that @code{sincos} of
! a random direction exactly gives us an @cite{[x, y]} step of unit
length; in fact, the new nesting function is even briefer, though
we might want to lower the precision a bit for it.
 8153,8164 
@end group
@end smallexample
! Incidentally, because the @expr{x} and @expr{y} are completely
independent in this case, we could have done two separate commands
! to create our @expr{x} and @expr{y} vectors of numbers directly.
To make a random walk of unit steps, we note that @code{sincos} of
! a random direction exactly gives us an @expr{[x, y]} step of unit
length; in fact, the new nesting function is even briefer, though
we might want to lower the precision a bit for it.
***************
*** 8071,8080 ****
@subsection Types Tutorial Exercise 1
@noindent
! If the number is the square root of @c{$\pi$}
! @cite{pi} times a rational number,
! then its square, divided by @c{$\pi$}
! @cite{pi}, should be a rational number.
@smallexample
@group
 8186,8193 
@subsection Types Tutorial Exercise 1
@noindent
! If the number is the square root of @cpi{} times a rational number,
! then its square, divided by @cpi{}, should be a rational number.
@smallexample
@group
***************
*** 8106,8113 ****
@noindent
Aha! It's unlikely that an irrational number would equal a fraction
this simple to within ten digits, so our original number was probably
! @c{$\sqrt{27 \pi / 53}$}
! @cite{sqrt(27 pi / 53)}.
Notice that we didn't need to reround the number when we reduced the
precision. Remember, arithmetic operations always round their inputs
 8219,8226 
@noindent
Aha! It's unlikely that an irrational number would equal a fraction
this simple to within ten digits, so our original number was probably
! @texline @tmath{\sqrt{27 \pi / 53}}.
! @infoline @expr{sqrt(27 pi / 53)}.
Notice that we didn't need to reround the number when we reduced the
precision. Remember, arithmetic operations always round their inputs
***************
*** 8123,8139 ****
@samp{exp(inf) = inf}. It's tempting to say that the exponential
of infinity must be ``bigger'' than ``regular'' infinity, but as
far as Calc is concerned all infinities are as just as big.
! In other words, as @cite{x} goes to infinity, @cite{e^x} also goes
! to infinity, but the fact the @cite{e^x} grows much faster than
! @cite{x} is not relevant here.
@samp{exp(inf) = 0}. Here we have a finite answer even though
the input is infinite.
! @samp{sqrt(inf) = (0, 1) inf}. Remember that @cite{(0, 1)}
! represents the imaginary number @cite{i}. Here's a derivation:
@samp{sqrt(inf) = @w{sqrt((1) * inf)} = sqrt(1) * sqrt(inf)}.
! The first part is, by definition, @cite{i}; the second is @code{inf}
because, once again, all infinities are the same size.
@samp{sqrt(uinf) = uinf}. In fact, we do know something about the
 8236,8252 
@samp{exp(inf) = inf}. It's tempting to say that the exponential
of infinity must be ``bigger'' than ``regular'' infinity, but as
far as Calc is concerned all infinities are as just as big.
! In other words, as @expr{x} goes to infinity, @expr{e^x} also goes
! to infinity, but the fact the @expr{e^x} grows much faster than
! @expr{x} is not relevant here.
@samp{exp(inf) = 0}. Here we have a finite answer even though
the input is infinite.
! @samp{sqrt(inf) = (0, 1) inf}. Remember that @expr{(0, 1)}
! represents the imaginary number @expr{i}. Here's a derivation:
@samp{sqrt(inf) = @w{sqrt((1) * inf)} = sqrt(1) * sqrt(inf)}.
! The first part is, by definition, @expr{i}; the second is @code{inf}
because, once again, all infinities are the same size.
@samp{sqrt(uinf) = uinf}. In fact, we do know something about the
***************
*** 8141,8151 ****
right half of the complex plane. But Calc has no notation for this,
so it settles for the conservative answer @code{uinf}.
! @samp{abs(uinf) = inf}. No matter which direction @cite{x} points,
@samp{abs(x)} always points along the positive real axis.
@samp{ln(0) = inf}. Here we have an infinite answer to a finite
! input. As in the @cite{1 / 0} case, Calc will only use infinities
here if you have turned on ``infinite'' mode. Otherwise, it will
treat @samp{ln(0)} as an error.
 8254,8264 
right half of the complex plane. But Calc has no notation for this,
so it settles for the conservative answer @code{uinf}.
! @samp{abs(uinf) = inf}. No matter which direction @expr{x} points,
@samp{abs(x)} always points along the positive real axis.
@samp{ln(0) = inf}. Here we have an infinite answer to a finite
! input. As in the @expr{1 / 0} case, Calc will only use infinities
here if you have turned on ``infinite'' mode. Otherwise, it will
treat @samp{ln(0)} as an error.
***************
*** 8154,8162 ****
@noindent
We can make @samp{inf  inf} be any real number we like, say,
! @cite{a}, just by claiming that we added @cite{a} to the first
infinity but not to the second. This is just as true for complex
! values of @cite{a}, so @code{nan} can stand for a complex number.
(And, similarly, @code{uinf} can stand for an infinity that points
in any direction in the complex plane, such as @samp{(0, 1) inf}).
 8267,8275 
@noindent
We can make @samp{inf  inf} be any real number we like, say,
! @expr{a}, just by claiming that we added @expr{a} to the first
infinity but not to the second. This is just as true for complex
! values of @expr{a}, so @code{nan} can stand for a complex number.
(And, similarly, @code{uinf} can stand for an infinity that points
in any direction in the complex plane, such as @samp{(0, 1) inf}).
***************
*** 8403,8409 ****
@subsection Types Tutorial Exercise 10
@noindent
! Testing the first number, we might arbitrarily choose 17 for @cite{x}.
@smallexample
@group
 8516,8522 
@subsection Types Tutorial Exercise 10
@noindent
! Testing the first number, we might arbitrarily choose 17 for @expr{x}.
@smallexample
@group
***************
*** 8435,8441 ****
@end smallexample
@noindent
! The result is three ones (modulo @cite{n}), so it's very probable that
15485863 is prime. (In fact, this number is the millionth prime.)
Note that the functions @samp{($$^($1)) mod $} or @samp{$$^($1) % $}
 8548,8554 
@end smallexample
@noindent
! The result is three ones (modulo @expr{n}), so it's very probable that
15485863 is prime. (In fact, this number is the millionth prime.)
Note that the functions @samp{($$^($1)) mod $} or @samp{$$^($1) % $}
***************
*** 8604,8623 ****
@noindent
@c [fixref Declarations]
! The result @samp{sqrt(x)^2} is simplified back to @cite{x} by the
Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens
! if @address@hidden = 4}}.) If @cite{x} is real, this formula could be
simplified to @samp{abs(x)}, but for general complex arguments even
that is not safe. (@xref{Declarations}, for a way to tell Calc
! that @cite{x} is known to be real.)
@node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to
Exercises
@subsection Algebra Tutorial Exercise 2
@noindent
! Suppose our roots are @cite{[a, b, c]}. We want a polynomial which
! is zero when @cite{x} is any of these values. The trivial polynomial
! @cite{xa} is zero when @cite{x=a}, so the product @cite{(xa)(xb)(xc)}
will do the job. We can use @kbd{a c x} to write this in a more
familiar form.
 8717,8736 
@noindent
@c [fixref Declarations]
! The result @samp{sqrt(x)^2} is simplified back to @expr{x} by the
Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens
! if @address@hidden = 4}}.) If @expr{x} is real, this formula could be
simplified to @samp{abs(x)}, but for general complex arguments even
that is not safe. (@xref{Declarations}, for a way to tell Calc
! that @expr{x} is known to be real.)
@node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to
Exercises
@subsection Algebra Tutorial Exercise 2
@noindent
! Suppose our roots are @expr{[a, b, c]}. We want a polynomial which
! is zero when @expr{x} is any of these values. The trivial polynomial
! @expr{xa} is zero when @expr{x=a}, so the product @expr{(xa)(xb)(xc)}
will do the job. We can use @kbd{a c x} to write this in a more
familiar form.
***************
*** 8808,8814 ****
@end smallexample
@noindent
! Multiplying by the conjugate helps because @cite{(a+b) (ab) = a^2  b^2}.
@smallexample
@group
 8921,8927 
@end smallexample
@noindent
! Multiplying by the conjugate helps because @expr{(a+b) (ab) = a^2  b^2}.
@smallexample
@group
***************
*** 8858,8868 ****
into a threeargument @code{fib} that makes computation easier. The
second rule converts back from threeargument form once the computation
is done. The third rule does the computation itself. It basically
! says that if @cite{x} and @cite{y} are two consecutive Fibonacci numbers,
! then @cite{y} and @cite{x+y} are the next (overlapping) pair of Fibonacci
numbers.
! Notice that because the number @cite{n} was ``validated'' by the
conditions on the first rule, there is no need to put conditions on
the other rules because the rule set would never get that far unless
the input were valid. That further speeds computation, since no
 8971,8981 
into a threeargument @code{fib} that makes computation easier. The
second rule converts back from threeargument form once the computation
is done. The third rule does the computation itself. It basically
! says that if @expr{x} and @expr{y} are two consecutive Fibonacci numbers,
! then @expr{y} and @expr{x+y} are the next (overlapping) pair of Fibonacci
numbers.
! Notice that because the number @expr{n} was ``validated'' by the
conditions on the first rule, there is no need to put conditions on
the other rules because the rule set would never get that far unless
the input were valid. That further speeds computation, since no
***************
*** 8959,8966 ****
@noindent
Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
! Notice that the @cite{n > 1} guard is no longer necessary on the last
! rule since the @cite{n = 1} case is now detected by another rule.
But a guard has been added to the initial rule to make sure the
initial value is suitable before the computation begins.
 9072,9079 
@noindent
Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
! Notice that the @expr{n > 1} guard is no longer necessary on the last
! rule since the @expr{n = 1} case is now detected by another rule.
But a guard has been added to the initial rule to make sure the
initial value is suitable before the computation begins.
***************
*** 8978,8985 ****
@starindex
@end ignore
@tindex nterms
! If @cite{x} is the sum @cite{a + b}, then address@hidden(address@hidden@t{)}'
must
! be address@hidden(address@hidden@t{)}' plus
address@hidden(address@hidden@t{)}'. If @cite{x}
is not a sum, then address@hidden(address@hidden@t{)}' = 1.
@smallexample
 9091,9098 
@starindex
@end ignore
@tindex nterms
! If @expr{x} is the sum @expr{a + b}, then address@hidden(address@hidden@t{)}'
must
! be address@hidden(address@hidden@t{)}' plus
address@hidden(address@hidden@t{)}'. If @expr{x}
is not a sum, then address@hidden(address@hidden@t{)}' = 1.
@smallexample
***************
*** 9026,9032 ****
Perhaps more surprisingly, this rule still works with infinite mode
turned on. Calc tries @code{EvalRules} before any builtin rules for
a function. This allows you to override the default behavior of any
! Calc feature: Even though Calc now wants to evaluate @cite{0^0} to
@code{nan}, your rule gets there first and evaluates it to 1 instead.
Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.
 9139,9145 
Perhaps more surprisingly, this rule still works with infinite mode
turned on. Calc tries @code{EvalRules} before any builtin rules for
a function. This allows you to override the default behavior of any
! Calc feature: Even though Calc now wants to evaluate @expr{0^0} to
@code{nan}, your rule gets there first and evaluates it to 1 instead.
Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.
***************
*** 9085,9091 ****
Another way to solve this problem would be to create a new ``data type''
that represents truncated power series. We might represent these as
function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is
! a vector of coefficients for @cite{x^0}, @cite{x^1}, @cite{x^2}, and so
on. Rules would exist for sums and products of such @code{series}
objects, and as an optional convenience could also know how to combine a
@code{series} object with a normal polynomial. (With this, and with a
 9198,9204 
Another way to solve this problem would be to create a new ``data type''
that represents truncated power series. We might represent these as
function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is
! a vector of coefficients for @expr{x^0}, @expr{x^1}, @expr{x^2}, and so
on. Rules would exist for sums and products of such @code{series}
objects, and as an optional convenience could also know how to combine a
@code{series} object with a normal polynomial. (With this, and with a
***************
*** 9115,9121 ****
Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type
@kbd{Z F}, and answer the questions. Since this formula contains two
variables, the default argument list will be @samp{(t x)}. We want to
! change this to @samp{(x)} since @cite{t} is really a dummy variable
to be used within @code{ninteg}.
The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} Cb Cb @key{DEL}
@key{DEL} @key{RET} y}.
 9228,9234 
Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type
@kbd{Z F}, and answer the questions. Since this formula contains two
variables, the default argument list will be @samp{(t x)}. We want to
! change this to @samp{(x)} since @expr{t} is really a dummy variable
to be used within @code{ninteg}.
The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} Cb Cb @key{DEL}
@key{DEL} @key{RET} y}.
***************
*** 9146,9153 ****
algebraic entry, whichever way you prefer:
@noindent
! Computing @c{$\displaystyle{\sin x \over x}$}
! @cite{sin(x) / x}:
Using the stack: @kbd{Cx ( @key{RET} S @key{TAB} / Cx )}.
 9259,9267 
algebraic entry, whichever way you prefer:
@noindent
! Computing
! @texline @tmath{\displaystyle{\sin x \over x}}:
! @infoline @expr{sin(x) / x}:
Using the stack: @kbd{Cx ( @key{RET} S @key{TAB} / Cx )}.
***************
*** 9207,9214 ****
@end example
@noindent
! Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @cite{n+1}
! and @cite{n+2}. Here's one program that does the job:
@example
Cx ( ' [0, 1; 1, 1] ^ ($1) * [1, 1] @key{RET} v u @key{DEL} Cx )
 9321,9328 
@end example
@noindent
! Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @expr{n+1}
! and @expr{n+2}. Here's one program that does the job:
@example
Cx ( ' [0, 1; 1, 1] ^ ($1) * [1, 1] @key{RET} v u @key{DEL} Cx )
***************
*** 9216,9223 ****
@noindent
This program is quite efficient because Calc knows how to raise a
! matrix (or other value) to the power @cite{n} in only @c{$\log_2 n$}
! @cite{log(n,2)}
steps. For example, this program can compute the 1000th Fibonacci
number (a 209digit integer!) in about 10 steps; even though the
@kbd{Z < ... Z >} solution had much simpler steps, it would have
 9330,9338 
@noindent
This program is quite efficient because Calc knows how to raise a
! matrix (or other value) to the power @expr{n} in only
! @texline @tmath{\log_2 n}
! @infoline @expr{log(n,2)}
steps. For example, this program can compute the 1000th Fibonacci
number (a 209digit integer!) in about 10 steps; even though the
@kbd{Z < ... Z >} solution had much simpler steps, it would have
***************
*** 9268,9276 ****
@subsection Programming Tutorial Exercise 8
@noindent
! The first step is to compute the derivative @cite{f'(x)} and thus
! the formula @c{$\displaystyle{x  {f(x) \over f'(x)}}$}
! @cite{x  f(x)/f'(x)}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
 9383,9392 
@subsection Programming Tutorial Exercise 8
@noindent
! The first step is to compute the derivative @expr{f'(x)} and thus
! the formula
! @texline @tmath{\displaystyle{x  {f(x) \over f'(x)}}}.
! @infoline @expr{x  f(x)/f'(x)}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
***************
*** 9317,9323 ****
@end group
@end smallexample
! This is the new guess for @cite{x}. Now we compare it with the
old one to see if we've converged.
@smallexample
 9433,9439 
@end group
@end smallexample
! This is the new guess for @expr{x}. Now we compare it with the
old one to see if we've converged.
@smallexample
***************
*** 9383,9395 ****
@subsection Programming Tutorial Exercise 9
@noindent
! The first step is to adjust @cite{z} to be greater than 5. A simple
! ``for'' loop will do the job here. If @cite{z} is less than 5, we
! reduce the problem using @c{$\psi(z) = \psi(z+1)  1/z$}
! @cite{psi(z) = psi(z+1)  1/z}. We go
! on to compute @c{$\psi(z+1)$}
! @cite{psi(z+1)}, and remember to add back a factor of
! @cite{1/z} when we're done. This step is repeated until @cite{z > 5}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
 9499,9514 
@subsection Programming Tutorial Exercise 9
@noindent
! The first step is to adjust @expr{z} to be greater than 5. A simple
! ``for'' loop will do the job here. If @expr{z} is less than 5, we
! reduce the problem using
! @texline @tmath{\psi(z) = \psi(z+1)  1/z}.
! @infoline @expr{psi(z) = psi(z+1)  1/z}. We go
! on to compute
! @texline @tmath{\psi(z+1)},
! @infoline @expr{psi(z+1)},
! and remember to add back a factor of @expr{1/z} when we're done. This
! step is repeated until @expr{z > 5}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
***************
*** 9407,9414 ****
@end group
@end smallexample
! Here, variable 1 holds @cite{z} and variable 2 holds the adjustment
! factor. If @cite{z < 5}, we use a loop to increase it.
(By the way, we started with @samp{1.0} instead of the integer 1 because
otherwise the calculation below will try to do exact fractional arithmetic,
 9526,9533 
@end group
@end smallexample
! Here, variable 1 holds @expr{z} and variable 2 holds the adjustment
! factor. If @expr{z < 5}, we use a loop to increase it.
(By the way, we started with @samp{1.0} instead of the integer 1 because
otherwise the calculation below will try to do exact fractional arithmetic,
***************
*** 9426,9433 ****
@end group
@end smallexample
! Now we compute the initial part of the sum: @c{$\ln z  {1 \over 2z}$}
! @cite{ln(z)  1/2z}
minus the adjustment factor.
@smallexample
 9545,9553 
@end group
@end smallexample
! Now we compute the initial part of the sum:
! @texline @tmath{\ln z  {1 \over 2z}}
! @infoline @expr{ln(z)  1/2z}
minus the adjustment factor.
@smallexample
***************
*** 9441,9447 ****
@end smallexample
Now we evaluate the series. We'll use another ``for'' loop counting
! up the value of @cite{2 n}. (Calc does have a summation command,
@kbd{a +}, but we'll use loops just to get more practice with them.)
@smallexample
 9561,9567 
@end smallexample
Now we evaluate the series. We'll use another ``for'' loop counting
! up the value of @expr{2 n}. (Calc does have a summation command,
@kbd{a +}, but we'll use loops just to get more practice with them.)
@smallexample
***************
*** 9468,9476 ****
@end group
@end smallexample
! This is the value of @c{$\gamma$}
! @cite{ gamma}, with a slight bit of roundoff error.
! To get a full 12 digits, let's use a higher precision:
@smallexample
@group
 9588,9598 
@end group
@end smallexample
! This is the value of
! @texline @tmath{\gamma},
! @infoline @expr{ gamma},
! with a slight bit of roundoff error. To get a full 12 digits, let's use
! a higher precision:
@smallexample
@group
***************
*** 9500,9511 ****
@subsection Programming Tutorial Exercise 10
@noindent
! Taking the derivative of a term of the form @cite{x^n} will produce
! a term like @c{$n x^{n1}$}
! @cite{n x^(n1)}. Taking the derivative of a constant
! produces zero. From this it is easy to see that the @cite{n}th
! derivative of a polynomial, evaluated at @cite{x = 0}, will equal the
! coefficient on the @cite{x^n} term times @cite{n!}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
 9622,9635 
@subsection Programming Tutorial Exercise 10
@noindent
! Taking the derivative of a term of the form @expr{x^n} will produce
! a term like
! @texline @tmath{n x^{n1}}.
! @infoline @expr{n x^(n1)}.
! Taking the derivative of a constant
! produces zero. From this it is easy to see that the @expr{n}th
! derivative of a polynomial, evaluated at @expr{x = 0}, will equal the
! coefficient on the @expr{x^n} term times @expr{n!}.
(Because this definition is long, it will be repeated in concise form
below. You can use @address@hidden m}} to load it from there. While you are
***************
*** 9554,9560 ****
@end smallexample
To convert back, a simple method is just to map the coefficients
! against a table of powers of @cite{x}.
@smallexample
@group
 9678,9684 
@end smallexample
To convert back, a simple method is just to map the coefficients
! against a table of powers of @expr{x}.
@smallexample
@group
***************
*** 9614,9620 ****
The last step replaces the 2 that was eaten during the creation
of the dummy @kbd{z s} command. Now we move on to the real
definition. The recurrence needs to be rewritten slightly,
! to the form @cite{s(n,m) = s(n1,m1)  (n1) s(n1,m)}.
(Because this definition is long, it will be repeated in concise form
below. You can use @kbd{M# m} to load it from there.)
 9738,9744 
The last step replaces the 2 that was eaten during the creation
of the dummy @kbd{z s} command. Now we move on to the real
definition. The recurrence needs to be rewritten slightly,
! to the form @expr{s(n,m) = s(n1,m1)  (n1) s(n1,m)}.
(Because this definition is long, it will be repeated in concise form
below. You can use @kbd{M# m} to load it from there.)
***************
*** 9783,9789 ****
Calc Trail buffer uses a variant of Calc Mode, so Calculator commands
still work when the trail buffer's window is selected. It is possible
to turn the trail window off, but the @samp{*Calc Trail*} buffer itself
! still exists and is updated silently. @xref{Trail address@hidden
@kindex M# c
@kindex M# M#
 9907,9913 
Calc Trail buffer uses a variant of Calc Mode, so Calculator commands
still work when the trail buffer's window is selected. It is possible
to turn the trail window off, but the @samp{*Calc Trail*} buffer itself
! still exists and is updated silently. @xref{Trail Commands}.
@kindex M# c
@kindex M# M#
***************
*** 9805,9811 ****
key (@code{calcexecuteextendedcommand})
is like @kbd{Mx} except that it enters the initial string @samp{calc}
for you. For example, the following key sequences are equivalent:
! @kbd{S}, @kbd{Mx calcsin @key{RET}}, @kbd{x sin @address@hidden
@cindex Extensions module
@cindex @file{calcext} module
 9929,9935 
key (@code{calcexecuteextendedcommand})
is like @kbd{Mx} except that it enters the initial string @samp{calc}
for you. For example, the following key sequences are equivalent:
! @kbd{S}, @kbd{Mx calcsin @key{RET}}, @kbd{x sin @key{RET}}.
@cindex Extensions module
@cindex @file{calcext} module
***************
*** 9818,9831 ****
little arithmetic. If for some reason the Calculator fails to load an
extension module automatically, you can force it to load all the
extensions by using the @kbd{M# L} (@code{calcloadeverything})
! command. @xref{Mode address@hidden
If you type @kbd{Mx calc} or @kbd{M# c} with any numeric prefix argument,
the Calculator is loaded if necessary, but it is not actually started.
If the argument is positive, the @file{calcext} extensions are also
loaded if necessary. Userwritten Lisp code that wishes to make use
of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)}
! to autoload the address@hidden
@kindex M# b
@pindex fullcalc
 9942,9955 
little arithmetic. If for some reason the Calculator fails to load an
extension module automatically, you can force it to load all the
extensions by using the @kbd{M# L} (@code{calcloadeverything})
! command. @xref{Mode Settings}.
If you type @kbd{Mx calc} or @kbd{M# c} with any numeric prefix argument,
the Calculator is loaded if necessary, but it is not actually started.
If the argument is positive, the @file{calcext} extensions are also
loaded if necessary. Userwritten Lisp code that wishes to make use
of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)}
! to autoload the Calculator.
@kindex M# b
@pindex fullcalc
***************
*** 9872,9878 ****
contents of the stack intact. Typing @kbd{M# c} or @kbd{M# M#}
again from inside the Calculator buffer is equivalent to executing
@code{calcquit}; you can think of @kbd{M# M#} as toggling the
! Calculator on and address@hidden
@kindex M# x
The @kbd{M# x} command also turns the Calculator off, no matter which
 9996,10002 
contents of the stack intact. Typing @kbd{M# c} or @kbd{M# M#}
again from inside the Calculator buffer is equivalent to executing
@code{calcquit}; you can think of @kbd{M# M#} as toggling the
! Calculator on and off.
@kindex M# x
The @kbd{M# x} command also turns the Calculator off, no matter which
***************
*** 9904,9910 ****
@code{calcscrollright}. These are just like the normal horizontal
scrolling commands except that they scroll one halfscreen at a time by
default. (Calc formats its output to fit within the bounds of the
! window whenever it can.)@refill
@kindex @{
@kindex @}
 10028,10034 
@code{calcscrollright}. These are just like the normal horizontal
scrolling commands except that they scroll one halfscreen at a time by
default. (Calc formats its output to fit within the bounds of the
! window whenever it can.)
@kindex @{
@kindex @}
***************
*** 9913,9919 ****
@cindex Vertical scrolling
The @address@hidden and @address@hidden keys are bound to
@code{calcscrolldown}
and @code{calcscrollup}. They scroll up or down by onehalf the
! height of the Calc address@hidden
@kindex M# 0
@pindex calcreset
 10037,10043 
@cindex Vertical scrolling
The @address@hidden and @address@hidden keys are bound to
@code{calcscrolldown}
and @code{calcscrollup}. They scroll up or down by onehalf the
! height of the Calc window.
@kindex M# 0
@pindex calcreset
***************
*** 10017,10023 ****
@noindent
which means the command @kbd{H a S} or @kbd{H Mx calcsolvefor}
! takes a value @cite{a} from the stack, prompts for a value @cite{v},
then applies the algebraic function @code{fsolve} to these values.
The @samp{?=notes} message means you can now type @kbd{?} to see
additional notes from the summary that apply to this command.
 10141,10147 
@noindent
which means the command @kbd{H a S} or @kbd{H Mx calcsolvefor}
! takes a value @expr{a} from the stack, prompts for a value @expr{v},
then applies the algebraic function @code{fsolve} to these values.
The @samp{?=notes} message means you can now type @kbd{?} to see
additional notes from the summary that apply to this command.
***************
*** 10074,10080 ****
@kbd{+} key always ``pops'' the top two numbers from the stack, adds them,
and pushes the result (3) back onto the stack. This number is ready for
further calculations: @kbd{5 } pushes 5 onto the stack, then pops the
! 3 and 5, subtracts them, and pushes the result (@i{2})address@hidden
Note that the ``top'' of the stack actually appears at the @emph{bottom}
of the buffer. A line containing a single @samp{.} character signifies
 10198,10204 
@kbd{+} key always ``pops'' the top two numbers from the stack, adds them,
and pushes the result (3) back onto the stack. This number is ready for
further calculations: @kbd{5 } pushes 5 onto the stack, then pops the
! 3 and 5, subtracts them, and pushes the result (@i{2}).
Note that the ``top'' of the stack actually appears at the @emph{bottom}
of the buffer. A line containing a single @samp{.} character signifies
***************
*** 10103,10114 ****
(After all, if you typed @kbd{1 2} by themselves the Calculator
would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not}
right after typing a number, the key duplicates the number on the top of
! the stack. @address@hidden *} is thus a handy way to square a address@hidden
The @key{DEL} key pops and throws away the top number on the stack.
The @key{TAB} key swaps the top two objects on the stack.
@xref{Stack and Trail}, for descriptions of these and other stackrelated
! address@hidden
@node Numeric Entry, Algebraic Entry, Stack Basics, Introduction
@section Numeric Entry
 10227,10238 
(After all, if you typed @kbd{1 2} by themselves the Calculator
would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not}
right after typing a number, the key duplicates the number on the top of
! the stack. @address@hidden *} is thus a handy way to square a number.
The @key{DEL} key pops and throws away the top number on the stack.
The @key{TAB} key swaps the top two objects on the stack.
@xref{Stack and Trail}, for descriptions of these and other stackrelated
! commands.
@node Numeric Entry, Algebraic Entry, Stack Basics, Introduction
@section Numeric Entry
***************
*** 10129,10136 ****
@cindex Negative numbers, entering
@kindex _
There are three different concepts corresponding to the word ``minus,''
! typified by @cite{ab} (subtraction), @cite{x}
! (changesign), and @cite{5} (negative number). Calc uses three
different keys for these operations, respectively:
@kbd{}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{} key subtracts
the two numbers on the top of the stack. The @kbd{n} key changes the sign
 10253,10260 
@cindex Negative numbers, entering
@kindex _
There are three different concepts corresponding to the word ``minus,''
! typified by @expr{ab} (subtraction), @expr{x}
! (changesign), and @expr{5} (negative number). Calc uses three
different keys for these operations, respectively:
@kbd{}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{} key subtracts
the two numbers on the top of the stack. The @kbd{n} key changes the sign
***************
*** 10138,10144 ****
The @kbd{_} key begins entry of a negative number or changes the sign of
the number currently being entered. The following sequences all enter the
number @i{5} onto the stack: @kbd{0 @key{RET} 5 }, @kbd{5 n @key{RET}},
! @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @address@hidden
Some other keys are active during numeric entry, such as @kbd{#} for
nondecimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms.
 10262,10268 
The @kbd{_} key begins entry of a negative number or changes the sign of
the number currently being entered. The following sequences all enter the
number @i{5} onto the stack: @kbd{0 @key{RET} 5 }, @kbd{5 n @key{RET}},
! @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.
Some other keys are active during numeric entry, such as @kbd{#} for
nondecimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms.
***************
*** 10158,10168 ****
Calculations can also be entered in algebraic form. This is accomplished
by typing the apostrophe key, @kbd{'}, followed by the expression in
standard format: @address@hidden'} 2+3*4 @key{RET}} computes
! @c{$2+(3\times4) = 14$}
! @cite{2+(3*4) = 14} and pushes that on the stack. If you wish you can
ignore the RPN aspect of Calc altogether and simply enter algebraic
expressions in this way. You may want to use @key{DEL} every so often to
! clear previous results off the address@hidden
You can press the apostrophe key during normal numeric entry to switch
the halfentered number into algebraic entry mode. One reason to do this
 10282,10293 
Calculations can also be entered in algebraic form. This is accomplished
by typing the apostrophe key, @kbd{'}, followed by the expression in
standard format: @address@hidden'} 2+3*4 @key{RET}} computes
! @texline @tmath{2+(3\times4) = 14}
! @infoline @expr{2+(3*4) = 14}
! and pushes that on the stack. If you wish you can
ignore the RPN aspect of Calc altogether and simply enter algebraic
expressions in this way. You may want to use @key{DEL} every so often to
! clear previous results off the stack.
You can press the apostrophe key during normal numeric entry to switch
the halfentered number into algebraic entry mode. One reason to do this
***************
*** 10185,10191 ****
begin algebraic entry. You can still do RPN calculations in this mode,
but you will have to press @key{RET} to terminate every number:
@kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
! thing as @kbd{2*3+4 @address@hidden
@cindex Incomplete algebraic mode
If you give a numeric prefix argument like @kbd{Cu} to the @kbd{m a}
 10310,10316 
begin algebraic entry. You can still do RPN calculations in this mode,
but you will have to press @key{RET} to terminate every number:
@kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
! thing as @kbd{2*3+4 @key{RET}}.
@cindex Incomplete algebraic mode
If you give a numeric prefix argument like @kbd{Cu} to the @kbd{m a}
***************
*** 10221,10227 ****
stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2
@key{RET}} replaces it with 6. Note that the @kbd{$} key always
initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
! first character in the new address@hidden
Higher stack elements can be accessed from an entered formula with the
symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements
 10346,10352 
stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2
@key{RET}} replaces it with 6. Note that the @kbd{$} key always
initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
! first character in the new formula.
Higher stack elements can be accessed from an entered formula with the
symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements
***************
*** 10229,10235 ****
signs in the longest such symbol in the formula. For example, @samp{$$+$$$}
adds the second and third stack elements, replacing the top three elements
with the answer. (All information about the top stack element is thus lost
! since no single @samp{$} appears in this formula.)@refill
A slightly different way to refer to stack elements is with a dollar
sign followed by a number: @samp{$1}, @samp{$2}, and so on are much
 10354,10360 
signs in the longest such symbol in the formula. For example, @samp{$$+$$$}
adds the second and third stack elements, replacing the top three elements
with the answer. (All information about the top stack element is thus lost
! since no single @samp{$} appears in this formula.)
A slightly different way to refer to stack elements is with a dollar
sign followed by a number: @samp{$1}, @samp{$2}, and so on are much
***************
*** 10254,10260 ****
instead of @key{RET}, Calc disables the default simplifications
(as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry
is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3
! on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @cite{1+2};
you might then press @kbd{=} when it is time to evaluate this formula.
@node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction
 10379,10385 
instead of @key{RET}, Calc disables the default simplifications
(as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry
is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3
! on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @expr{1+2};
you might then press @kbd{=} when it is time to evaluate this formula.
@node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction
***************
*** 10333,10339 ****
@kbd{d s} (@code{calcscinotation}), set a parameter to the value of
the prefix argument or use a default if you don't use a prefix.
Others (like @kbd{d f} (@code{calcfixnotation})) require an argument
! and prompt for a number if you don't give one as a address@hidden
As a rule, stackmanipulation commands accept a numeric prefix argument
which is interpreted as an index into the stack. A positive argument
 10458,10464 
@kbd{d s} (@code{calcscinotation}), set a parameter to the value of
the prefix argument or use a default if you don't use a prefix.
Others (like @kbd{d f} (@code{calcfixnotation})) require an argument
! and prompt for a number if you don't give one as a prefix.
As a rule, stackmanipulation commands accept a numeric prefix argument
which is interpreted as an index into the stack. A positive argument
***************
*** 10360,10366 ****
Numeric prefixes are specified the same way as always in Emacs: Press
a sequence of @key{META}digits, or press @key{ESC} followed by digits,
or press @kbd{Cu} followed by digits. Some commands treat plain
! @kbd{Cu} (without any actual digits) address@hidden
@kindex ~
@pindex calcnumprefix
 10485,10491 
Numeric prefixes are specified the same way as always in Emacs: Press
a sequence of @key{META}digits, or press @key{ESC} followed by digits,
or press @kbd{Cu} followed by digits. Some commands treat plain
! @kbd{Cu} (without any actual digits) specially.
@kindex ~
@pindex calcnumprefix
***************
*** 10368,10374 ****
top of the stack and enter it as the numeric prefix for the next command.
For example, @kbd{Cu 16 p} sets the precision to 16 digits; an alternate
(silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2
! to the fourth power and set the precision to that address@hidden
Conversely, if you have typed a numeric prefix argument the @kbd{~} key
pushes it onto the stack in the form of an integer.
 10493,10499 
top of the stack and enter it as the numeric prefix for the next command.
For example, @kbd{Cu 16 p} sets the precision to 16 digits; an alternate
(silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2
! to the fourth power and set the precision to that value.
Conversely, if you have typed a numeric prefix argument the @kbd{~} key
pushes it onto the stack in the form of an integer.
***************
*** 10416,10422 ****
The @address@hidden key (@code{calclastargs}) is like undo in that
it restores the arguments of the most recent command onto the stack;
however, it does not remove the result of that command. Given a numeric
! prefix argument, this command applies to the @cite{n}th most recent
command which removed items from the stack; it pushes those items back
onto the stack.
 10541,10547 
The @address@hidden key (@code{calclastargs}) is like undo in that
it restores the arguments of the most recent command onto the stack;
however, it does not remove the result of that command. Given a numeric
! prefix argument, this command applies to the @expr{n}th most recent
command which removed items from the stack; it pushes those items back
onto the stack.
***************
*** 10438,10444 ****
@cindex Why did an error occur?
Many situations that would produce an error message in other calculators
simply create unsimplified formulas in the Emacs Calculator. For example,
! @kbd{1 @key{RET} 0 /} pushes the formula @cite{1 / 0}; @address@hidden L}}
pushes
the formula @samp{ln(0)}. Floatingpoint overflow and underflow are also
reasons for this to happen.
 10563,10569 
@cindex Why did an error occur?
Many situations that would produce an error message in other calculators
simply create unsimplified formulas in the Emacs Calculator. For example,
! @kbd{1 @key{RET} 0 /} pushes the formula @expr{1 / 0}; @address@hidden L}}
pushes
the formula @samp{ln(0)}. Floatingpoint overflow and underflow are also
reasons for this to happen.
***************
*** 10543,10549 ****
ever halts incorrectly with the message ``Computation got stuck or
ran too long,'' use the @kbd{M} command (@code{calcmorerecursiondepth})
to increase this limit. (Of course, this will not help if the
! calculation really did get stuck due to some problem inside Calc.)@refill
The limit is always increased (multiplied) by a factor of two. There
is also an @kbd{I M} (@code{calclessrecursiondepth}) command which
 10668,10674 
ever halts incorrectly with the message ``Computation got stuck or
ran too long,'' use the @kbd{M} command (@code{calcmorerecursiondepth})
to increase this limit. (Of course, this will not help if the
! calculation really did get stuck due to some problem inside Calc.)
The limit is always increased (multiplied) by a factor of two. There
is also an @kbd{I M} (@code{calclessrecursiondepth}) command which
***************
*** 10561,10576 ****
@cindex Flushing caches
Calc saves certain values after they have been computed once. For
example, the @kbd{P} (@code{calcpi}) command initially ``knows'' the
! constant @c{$\pi$}
! @cite{pi} to about 20 decimal places; if the current precision
! is greater than this, it will recompute @c{$\pi$}
! @cite{pi} using a series
approximation. This value will not need to be recomputed ever again
unless you raise the precision still further. Many operations such as
logarithms and sines make use of similarly cached values such as
! @c{$\pi \over 4$}
! @cite{pi/4} and @c{$\ln 2$}
! @cite{ln(2)}. The visible effect of caching is that
highprecision computations may seem to do extra work the first time.
Other things cached include powers of two (for the binary arithmetic
functions), matrix inverses and determinants, symbolic integrals, and
 10686,10700 
@cindex Flushing caches
Calc saves certain values after they have been computed once. For
example, the @kbd{P} (@code{calcpi}) command initially ``knows'' the
! constant @cpi{} to about 20 decimal places; if the current precision
! is greater than this, it will recompute @cpi{} using a series
approximation. This value will not need to be recomputed ever again
unless you raise the precision still further. Many operations such as
logarithms and sines make use of similarly cached values such as
! @cpiover{4} and
! @texline @tmath{\ln 2}.
! @infoline @expr{ln(2)}.
! The visible effect of caching is that
highprecision computations may seem to do extra work the first time.
Other things cached include powers of two (for the binary arithmetic
functions), matrix inverses and determinants, symbolic integrals, and
***************
*** 10643,10649 ****
This chapter discusses the various types of objects that can be placed
on the Calculator stack, how they are displayed, and how they are
entered. (@xref{Data Type Formats}, for information on how these data
! types are represented as underlying Lisp objects.)@refill
Integers, fractions, and floats are various ways of describing real
numbers. HMS forms also for many purposes act as real numbers. These
 10767,10773 
This chapter discusses the various types of objects that can be placed
on the Calculator stack, how they are displayed, and how they are
entered. (@xref{Data Type Formats}, for information on how these data
! types are represented as underlying Lisp objects.)
Integers, fractions, and floats are various ways of describing real
numbers. HMS forms also for many purposes act as real numbers. These
***************
*** 10686,10692 ****
A decimal integer is represented as an optional sign followed by a
sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to
insert a comma at every third digit for display purposes, but you
! must not type commas during the entry of address@hidden
@kindex #
A nondecimal integer is represented as an optional sign, a radix
 10810,10816 
A decimal integer is represented as an optional sign followed by a
sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to
insert a comma at every third digit for display purposes, but you
! must not type commas during the entry of numbers.
@kindex #
A nondecimal integer is represented as an optional sign, a radix
***************
*** 10695,10701 ****
digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how
to set the default radix for display of integers. Numbers of any radix
may be entered at any time. If you press @kbd{#} at the beginning of a
! number, the current display radix is address@hidden
@node Fractions, Floats, Integers, Data Types
@section Fractions
 10819,10825 
digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how
to set the default radix for display of integers. Numbers of any radix
may be entered at any time. If you press @kbd{#} at the beginning of a
! number, the current display radix is used.
@node Fractions, Floats, Integers, Data Types
@section Fractions
***************
*** 10708,10722 ****
@samp{2:3} on the stack: @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /}
assuming Fraction Mode has been enabled.)
When the Calculator produces a fractional result it always reduces it to
! simplest form, which may in fact be an address@hidden
Fractions may also be entered in a threepart form, where @samp{2:3:4}
represents twoandthreequarters. @xref{Fraction Formats}, for fraction
! display address@hidden
Nondecimal fractions are entered and displayed as
@address@hidden@var{num}:@var{denom}} (or in the analogous threepart
! form). The numerator and denominator always use the same address@hidden
@node Floats, Complex Numbers, Fractions, Data Types
@section Floats
 10832,10846 
@samp{2:3} on the stack: @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /}
assuming Fraction Mode has been enabled.)
When the Calculator produces a fractional result it always reduces it to
! simplest form, which may in fact be an integer.
Fractions may also be entered in a threepart form, where @samp{2:3:4}
represents twoandthreequarters. @xref{Fraction Formats}, for fraction
! display formats.
Nondecimal fractions are entered and displayed as
@address@hidden@var{num}:@var{denom}} (or in the analogous threepart
! form). The numerator and denominator always use the same radix.
@node Floats, Complex Numbers, Fractions, Data Types
@section Floats
***************
*** 10726,10737 ****
A floatingpoint number or @dfn{float} is a number stored in scientific
notation. The number of significant digits in the fractional part is
governed by the current floating precision (@pxref{Precision}). The
! range of acceptable values is from @c{$10^{3999999}$}
! @cite{10^3999999} (inclusive)
! to @c{$10^{4000000}$}
! @cite{10^4000000}
! (exclusive), plus the corresponding negative
! values and zero.
Calculations that would exceed the allowable range of values (such
as @samp{exp(exp(20))}) are left in symbolic form by Calc. The
 10850,10862 
A floatingpoint number or @dfn{float} is a number stored in scientific
notation. The number of significant digits in the fractional part is
governed by the current floating precision (@pxref{Precision}). The
! range of acceptable values is from
! @texline @tmath{10^{3999999}}
! @infoline @expr{10^3999999}
! (inclusive) to
! @texline @tmath{10^{4000000}}
! @infoline @expr{10^4000000}
! (exclusive), plus the corresponding negative values and zero.
Calculations that would exceed the allowable range of values (such
as @samp{exp(exp(20))}) are left in symbolic form by Calc. The
***************
*** 10772,10778 ****
accuracy is not rigorously guaranteed. If you suspect the validity of a
result, try doing the same calculation in a higher precision. The
Calculator's arithmetic is not intended to be IEEEconformant in any
! address@hidden
While floats are always @emph{stored} in decimal, they can be entered
and displayed in any radix just like integers and fractions. The
 10897,10903 
accuracy is not rigorously guaranteed. If you suspect the validity of a
result, try doing the same calculation in a higher precision. The
Calculator's arithmetic is not intended to be IEEEconformant in any
! way.
While floats are always @emph{stored} in decimal, they can be entered
and displayed in any radix just like integers and fractions. The
***************
*** 10798,10813 ****
@samp{(@var{real},@var{imag})} where @var{real} is the real part and
@var{imag} is the imaginary part, each of which may be any real number.
Rectangular complex numbers can also be displayed in @address@hidden@var{b}i}
! notation; @pxref{Complex address@hidden
! Polar complex numbers are displayed in the form
address@hidden(address@hidden@t{;address@hidden
! @address@hidden)}'
! where @var{r} is the nonnegative magnitude and @c{$\theta$}
! @var{theta} is the argument
! or phase angle. The range of @c{$\theta$}
! @var{theta} depends on the current angular
! mode (@pxref{Angular Modes}); it is generally between @i{180} and
! @i{+180} degrees or the equivalent range in address@hidden
Complex numbers are entered in stages using incomplete objects.
@xref{Incomplete Objects}.
 10923,10942 
@samp{(@var{real},@var{imag})} where @var{real} is the real part and
@var{imag} is the imaginary part, each of which may be any real number.
Rectangular complex numbers can also be displayed in @address@hidden@var{b}i}
! notation; @pxref{Complex Formats}.
! Polar complex numbers are displayed in the form
! @texline address@hidden(address@hidden@t{;address@hidden@t{)}'
! @infoline address@hidden(address@hidden@t{;address@hidden@t{)}'
! where @var{r} is the nonnegative magnitude and
! @texline @tmath{\theta}
! @infoline @var{theta}
! is the argument or phase angle. The range of
! @texline @tmath{\theta}
! @infoline @var{theta}
! depends on the current angular mode (@pxref{Angular Modes}); it is
! generally between @i{180} and @i{+180} degrees or the equivalent range
! in radians.
Complex numbers are entered in stages using incomplete objects.
@xref{Incomplete Objects}.
***************
*** 10819,10826 ****
type. @xref{Polar Mode}.
A complex result in which the imaginary part is zero (or the phase angle
! is 0 or 180 degrees or @c{$\pi$}
! @cite{pi} radians) is automatically converted to a real
number.
@node Infinities, Vectors and Matrices, Complex Numbers, Data Types
 10948,10954 
type. @xref{Polar Mode}.
A complex result in which the imaginary part is zero (or the phase angle
! is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real
number.
@node Infinities, Vectors and Matrices, Complex Numbers, Data Types
***************
*** 10845,10868 ****
Mathematically speaking, it is not rigorously correct to treat
``infinity'' as if it were a number, but mathematicians often do
so informally. When they say that @samp{1 / inf = 0}, what they
! really mean is that @cite{1 / x}, as @cite{x} becomes larger and
larger, becomes arbitrarily close to zero. So you can imagine
! that if @cite{x} got ``all the way to infinity,'' then @cite{1 / x}
would go all the way to zero. Similarly, when they say that
! @samp{exp(inf) = inf}, they mean that @c{$e^x$}
! @cite{exp(x)} grows without
! bound as @cite{x} grows. The symbol @samp{inf} likewise stands
! for an infinitely negative real value; for example, we say that
@samp{exp(inf) = 0}. You can have an infinity pointing in any
direction on the complex plane: @samp{sqrt(inf) = i inf}.
! The same concept of limits can be used to define @cite{1 / 0}. We
! really want the value that @cite{1 / x} approaches as @cite{x}
! approaches zero. But if all we have is @cite{1 / 0}, we can't
! tell which direction @cite{x} was coming from. If @cite{x} was
positive and decreasing toward zero, then we should say that
! @samp{1 / 0 = inf}. But if @cite{x} was negative and increasing
! toward zero, the answer is @samp{1 / 0 = inf}. In fact, @cite{x}
could be an imaginary number, giving the answer @samp{i inf} or
@samp{i inf}. Calc uses the special symbol @samp{uinf} to mean
@dfn{undirected infinity}, i.e., a value which is infinitely
 10973,10997 
Mathematically speaking, it is not rigorously correct to treat
``infinity'' as if it were a number, but mathematicians often do
so informally. When they say that @samp{1 / inf = 0}, what they
! really mean is that @expr{1 / x}, as @expr{x} becomes larger and
larger, becomes arbitrarily close to zero. So you can imagine
! that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x}
would go all the way to zero. Similarly, when they say that
! @samp{exp(inf) = inf}, they mean that
! @texline @tmath{e^x}
! @infoline @expr{exp(x)}
! grows without bound as @expr{x} grows. The symbol @samp{inf} likewise
! stands for an infinitely negative real value; for example, we say that
@samp{exp(inf) = 0}. You can have an infinity pointing in any
direction on the complex plane: @samp{sqrt(inf) = i inf}.
! The same concept of limits can be used to define @expr{1 / 0}. We
! really want the value that @expr{1 / x} approaches as @expr{x}
! approaches zero. But if all we have is @expr{1 / 0}, we can't
! tell which direction @expr{x} was coming from. If @expr{x} was
positive and decreasing toward zero, then we should say that
! @samp{1 / 0 = inf}. But if @expr{x} was negative and increasing
! toward zero, the answer is @samp{1 / 0 = inf}. In fact, @expr{x}
could be an imaginary number, giving the answer @samp{i inf} or
@samp{i inf}. Calc uses the special symbol @samp{uinf} to mean
@dfn{undirected infinity}, i.e., a value which is infinitely
***************
*** 10870,10879 ****
Calc actually has three modes that say how infinities are handled.
Normally, infinities never arise from calculations that didn't
! already have them. Thus, @cite{1 / 0} is treated simply as an
error and left unevaluated. The @kbd{m i} (@code{calcinfinitemode})
command (@pxref{Infinite Mode}) enables a mode in which
! @cite{1 / 0} evaluates to @code{uinf} instead. There is also
an alternative type of infinite mode which says to treat zeros
as if they were positive, so that @samp{1 / 0 = inf}. While this
is less mathematically correct, it may be the answer you want in
 10999,11008 
Calc actually has three modes that say how infinities are handled.
Normally, infinities never arise from calculations that didn't
! already have them. Thus, @expr{1 / 0} is treated simply as an
error and left unevaluated. The @kbd{m i} (@code{calcinfinitemode})
command (@pxref{Infinite Mode}) enables a mode in which
! @expr{1 / 0} evaluates to @code{uinf} instead. There is also
an alternative type of infinite mode which says to treat zeros
as if they were positive, so that @samp{1 / 0 = inf}. While this
is less mathematically correct, it may be the answer you want in
***************
*** 10892,10900 ****
It's not so easy to define certain formulas like @samp{0 * inf} and
@samp{inf / inf}. Depending on where these zeros and infinities
came from, the answer could be literally anything. The latter
! formula could be the limit of @cite{x / x} (giving a result of one),
! or @cite{2 x / x} (giving two), or @cite{x^2 / x} (giving @code{inf}),
! or @cite{x / x^2} (giving zero). Calc uses the symbol @code{nan}
to represent such an @dfn{indeterminate} value. (The name ``nan''
comes from analogy with the ``NAN'' concept of IEEE standard
arithmetic; it stands for ``Not A Number.'' This is somewhat of a
 11021,11029 
It's not so easy to define certain formulas like @samp{0 * inf} and
@samp{inf / inf}. Depending on where these zeros and infinities
came from, the answer could be literally anything. The latter
! formula could be the limit of @expr{x / x} (giving a result of one),
! or @expr{2 x / x} (giving two), or @expr{x^2 / x} (giving @code{inf}),
! or @expr{x / x^2} (giving zero). Calc uses the symbol @code{nan}
to represent such an @dfn{indeterminate} value. (The name ``nan''
comes from analogy with the ``NAN'' concept of IEEE standard
arithmetic; it stands for ``Not A Number.'' This is somewhat of a
***************
*** 10938,10952 ****
@pxref{Basic Arithmetic} and @pxref{Matrix Functions}.
Many other operations are applied to vectors elementwise. For example,
the complex conjugate of a vector is a vector of the complex conjugates
! of its address@hidden
@ignore
@starindex
@end ignore
@tindex vec
Algebraic functions for building vectors include @samp{vec(a, b, c)}
! to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an @c{$n\times m$}
! @address@hidden@var{m}}
matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers
from 1 to @samp{n}.
 11067,11082 
@pxref{Basic Arithmetic} and @pxref{Matrix Functions}.
Many other operations are applied to vectors elementwise. For example,
the complex conjugate of a vector is a vector of the complex conjugates
! of its elements.
@ignore
@starindex
@end ignore
@tindex vec
Algebraic functions for building vectors include @samp{vec(a, b, c)}
! to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an
! @texline @tmath{n\times m}
! @infoline @address@hidden
matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers
from 1 to @samp{n}.
***************
*** 11077,11083 ****
(exclusive). A positive HMS form is interpreted as @var{hours} +
@var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted
as @i{ @var{hours}} @i{} @var{mins}/60 @i{} @var{secs}/3600.
! Display format for HMS forms is quite flexible. @xref{HMS address@hidden
HMS forms can be added and subtracted. When they are added to numbers,
the numbers are interpreted according to the current angular mode. HMS
 11207,11213 
(exclusive). A positive HMS form is interpreted as @var{hours} +
@var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted
as @i{ @var{hours}} @i{} @var{mins}/60 @i{} @var{secs}/3600.
! Display format for HMS forms is quite flexible. @xref{HMS Formats}.
HMS forms can be added and subtracted. When they are added to numbers,
the numbers are interpreted according to the current angular mode. HMS
***************
*** 11216,11225 ****
often arises in number theory. Modulo forms are written
address@hidden @t{mod} @var{M}',
where @var{a} and @var{M} are real numbers or HMS forms, and
! @c{$0 \le a < M$}
! @cite{0 <= a < @var{M}}.
! In many applications @cite{a} and @cite{M} will be
! integers but this is not address@hidden
Modulo forms are not to be confused with the modulo operator @samp{%}.
The expression @samp{27 % 10} means to compute 27 modulo 10 to produce
 11346,11355 
often arises in number theory. Modulo forms are written
address@hidden @t{mod} @var{M}',
where @var{a} and @var{M} are real numbers or HMS forms, and
! @texline @tmath{0 \le a < M}.
! @infoline @expr{0 <= a < @var{M}}.
! In many applications @expr{a} and @expr{M} will be
! integers but this is not required.
Modulo forms are not to be confused with the modulo operator @samp{%}.
The expression @samp{27 % 10} means to compute 27 modulo 10 to produce
***************
*** 11228,11255 ****
further computations with this value are again reduced modulo 10 so that
the result always lies in the desired range.
! When two modulo forms with identical @cite{M}'s are added or multiplied,
the Calculator simply adds or multiplies the values, then reduces modulo
! @cite{M}. If one argument is a modulo form and the other a plain number,
the plain number is treated like a compatible modulo form. It is also
possible to raise modulo forms to powers; the result is the value raised
! to the power, then reduced modulo @cite{M}. (When all values involved
are integers, this calculation is done much more efficiently than
actually computing the power and then reducing.)
@cindex Modulo division
Two modulo forms address@hidden @t{mod} @var{M}' and address@hidden @t{mod}
@var{M}'
! can be divided if @cite{a}, @cite{b}, and @cite{M} are all
integers. The result is the modulo form which, when multiplied by
address@hidden @t{mod} @var{M}', produces address@hidden @t{mod} @var{M}'. If
there is no solution to this equation (which can happen only when
! @cite{M} is nonprime), or if any of the arguments are nonintegers, the
division is left in symbolic form. Other operations, such as square
roots, are not yet supported for modulo forms. (Note that, although
@address@hidden(address@hidden @t{mod} @address@hidden)^.5}'} will compute a
``modulo square root''
! in the sense of reducing @c{$\sqrt a$}
! @cite{sqrt(a)} modulo @cite{M}, this is not a
! useful definition from the numbertheoretical point of view.)@refill
@ignore
@mindex M
 11358,11387 
further computations with this value are again reduced modulo 10 so that
the result always lies in the desired range.
! When two modulo forms with identical @expr{M}'s are added or multiplied,
the Calculator simply adds or multiplies the values, then reduces modulo
! @expr{M}. If one argument is a modulo form and the other a plain number,
the plain number is treated like a compatible modulo form. It is also
possible to raise modulo forms to powers; the result is the value raised
! to the power, then reduced modulo @expr{M}. (When all values involved
are integers, this calculation is done much more efficiently than
actually computing the power and then reducing.)
@cindex Modulo division
Two modulo forms address@hidden @t{mod} @var{M}' and address@hidden @t{mod}
@var{M}'
! can be divided if @expr{a}, @expr{b}, and @expr{M} are all
integers. The result is the modulo form which, when multiplied by
address@hidden @t{mod} @var{M}', produces address@hidden @t{mod} @var{M}'. If
there is no solution to this equation (which can happen only when
! @expr{M} is nonprime), or if any of the arguments are nonintegers, the
division is left in symbolic form. Other operations, such as square
roots, are not yet supported for modulo forms. (Note that, although
@address@hidden(address@hidden @t{mod} @address@hidden)^.5}'} will compute a
``modulo square root''
! in the sense of reducing
! @texline @tmath{\sqrt a}
! @infoline @expr{sqrt(a)}
! modulo @expr{M}, this is not a useful definition from the
! numbertheoretical point of view.)
@ignore
@mindex M
***************
*** 11261,11277 ****
@tindex mod (operator)
To create a modulo form during numeric entry, press the address@hidden
key to enter the word @samp{mod}. As a special convenience, pressing
! address@hidden a second time automatically enters the value of @cite{M}
that was most recently used before. During algebraic entry, either
type @samp{mod} by hand or press @kbd{Mm} (that's @address@hidden).
! Once again, pressing this a second time enters the current address@hidden
You can also use @kbd{v p} and @kbd{%} to modify modulo forms.
@xref{Building Vectors}. @xref{Basic Arithmetic}.
It is possible to mix HMS forms and modulo forms. For example, an
HMS form modulo 24 could be used to manipulate clock times; an HMS
! form modulo 360 would be suitable for angles. Making the modulo @cite{M}
also be an HMS form eliminates troubles that would arise if the angular
mode were inadvertently set to Radians, in which case
@address@hidden@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
 11393,11409 
@tindex mod (operator)
To create a modulo form during numeric entry, press the address@hidden
key to enter the word @samp{mod}. As a special convenience, pressing
! address@hidden a second time automatically enters the value of @expr{M}
that was most recently used before. During algebraic entry, either
type @samp{mod} by hand or press @kbd{Mm} (that's @address@hidden).
! Once again, pressing this a second time enters the current modulo.
You can also use @kbd{v p} and @kbd{%} to modify modulo forms.
@xref{Building Vectors}. @xref{Basic Arithmetic}.
It is possible to mix HMS forms and modulo forms. For example, an
HMS form modulo 24 could be used to manipulate clock times; an HMS
! form modulo 360 would be suitable for angles. Making the modulo @expr{M}
also be an HMS form eliminates troubles that would arise if the angular
mode were inadvertently set to Radians, in which case
@address@hidden@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
***************
*** 11296,11319 ****
@cindex Standard deviations
An @dfn{error form} is a number with an associated standard
deviation, as in @samp{2.3 +/ 0.12}. The notation
! address@hidden @t{+/} @c{$\sigma$}
! @asis{sigma}' stands for an uncertain value which follows a normal or
! Gaussian distribution of mean @cite{x} and standard deviation or
! ``error'' @c{$\sigma$}
! @cite{sigma}. Both the mean and the error can be either numbers or
formulas. Generally these are real numbers but the mean may also be
complex. If the error is negative or complex, it is changed to its
absolute value. An error form with zero error is converted to a
! regular number by the address@hidden
All arithmetic and transcendental functions accept error forms as input.
Operations on the meanvalue part work just like operations on regular
! numbers. The error part for any function @cite{f(x)} (such as @c{$\sin x$}
! @cite{sin(x)})
! is defined by the error of @cite{x} times the derivative of @cite{f}
! evaluated at the mean value of @cite{x}. For a twoargument function
! @cite{f(x,y)} (such as addition) the error is the square root of the sum
! of the squares of the errors due to @cite{x} and @cite{y}.
@tex
$$ \eqalign{
f(x \hbox{\code{ +/ }} \sigma)
 11428,11455 
@cindex Standard deviations
An @dfn{error form} is a number with an associated standard
deviation, as in @samp{2.3 +/ 0.12}. The notation
! @texline address@hidden @t{+/} @tmath{\sigma}'
! @infoline address@hidden @t{+/} sigma'
! stands for an uncertain value which follows
! a normal or Gaussian distribution of mean @expr{x} and standard
! deviation or ``error''
! @texline @tmath{\sigma}.
! @infoline @expr{sigma}.
! Both the mean and the error can be either numbers or
formulas. Generally these are real numbers but the mean may also be
complex. If the error is negative or complex, it is changed to its
absolute value. An error form with zero error is converted to a
! regular number by the Calculator.
All arithmetic and transcendental functions accept error forms as input.
Operations on the meanvalue part work just like operations on regular
! numbers. The error part for any function @expr{f(x)} (such as
! @texline @tmath{\sin x}
! @infoline @expr{sin(x)})
! is defined by the error of @expr{x} times the derivative of @expr{f}
! evaluated at the mean value of @expr{x}. For a twoargument function
! @expr{f(x,y)} (such as addition) the error is the square root of the sum
! of the squares of the errors due to @expr{x} and @expr{y}.
@tex
$$ \eqalign{
f(x \hbox{\code{ +/ }} \sigma)
***************
*** 11327,11364 ****
} $$
@end tex
Note that this
! definition assumes the errors in @cite{x} and @cite{y} are uncorrelated.
A side effect of this definition is that @samp{(2 +/ 1) * (2 +/ 1)}
is not the same as @samp{(2 +/ 1)^2}; the former represents the product
of two independent values which happen to have the same probability
distributions, and the latter is the product of one random value with itself.
The former will produce an answer with less error, since on the average
! the two independent errors can be expected to cancel address@hidden
Consult a good text on error analysis for a discussion of the proper use
of standard deviations. Actual errors often are neither Gaussiandistributed
nor uncorrelated, and the above formulas are valid only when errors
are small. As an example, the error arising from
! address@hidden(address@hidden @t{+/} @c{$\sigma$}
! @address@hidden)}' is
! address@hidden
! @var{sigma} @t{abs(cos(address@hidden@t{))}'. When @cite{x} is close to zero,
! @c{$\cos x$}
! @cite{cos(x)} is
! close to one so the error in the sine is close to @c{$\sigma$}
! @cite{sigma}; this makes sense, since @c{$\sin x$}
! @cite{sin(x)} is approximately @cite{x} near zero, so a given
! error in @cite{x} will produce about the same error in the sine. Likewise,
! near 90 degrees @c{$\cos x$}
! @cite{cos(x)} is nearly zero and so the computed error is
! small: The sine curve is nearly flat in that region, so an error in @cite{x}
! has relatively little effect on the value of @c{$\sin x$}
! @cite{sin(x)}. However, consider
! @samp{sin(90 +/ 1000)}. The cosine of 90 is zero, so Calc will report
! zero error! We get an obviously wrong result because we have violated
! the smallerror approximation underlying the error analysis. If the error
! in @cite{x} had been small, the error in @c{$\sin x$}
! @cite{sin(x)} would indeed have been address@hidden
@ignore
@mindex p
 11463,11510 
} $$
@end tex
Note that this
! definition assumes the errors in @expr{x} and @expr{y} are uncorrelated.
A side effect of this definition is that @samp{(2 +/ 1) * (2 +/ 1)}
is not the same as @samp{(2 +/ 1)^2}; the former represents the product
of two independent values which happen to have the same probability
distributions, and the latter is the product of one random value with itself.
The former will produce an answer with less error, since on the average
! the two independent errors can be expected to cancel out.
Consult a good text on error analysis for a discussion of the proper use
of standard deviations. Actual errors often are neither Gaussiandistributed
nor uncorrelated, and the above formulas are valid only when errors
are small. As an example, the error arising from
! @texline address@hidden(address@hidden @t{+/} @address@hidden)}'
! @infoline address@hidden(address@hidden @t{+/} @address@hidden)}'
! is
! @texline address@hidden @t{abs(cos(address@hidden@t{))}'.
! @infoline address@hidden @t{abs(cos(address@hidden@t{))}'.
! When @expr{x} is close to zero,
! @texline @tmath{\cos x}
! @infoline @expr{cos(x)}
! is close to one so the error in the sine is close to
! @texline @tmath{\sigma};
! @infoline @expr{sigma};
! this makes sense, since
! @texline @tmath{\sin x}
! @infoline @expr{sin(x)}
! is approximately @expr{x} near zero, so a given error in @expr{x} will
! produce about the same error in the sine. Likewise, near 90 degrees
! @texline @tmath{\cos x}
! @infoline @expr{cos(x)}
! is nearly zero and so the computed error is
! small: The sine curve is nearly flat in that region, so an error in @expr{x}
! has relatively little effect on the value of
! @texline @tmath{\sin x}.
! @infoline @expr{sin(x)}.
! However, consider @samp{sin(90 +/ 1000)}. The cosine of 90 is zero, so
! Calc will report zero error! We get an obviously wrong result because
! we have violated the smallerror approximation underlying the error
! analysis. If the error in @expr{x} had been small, the error in
! @texline @tmath{\sin x}
! @infoline @expr{sin(x)}
! would indeed have been negligible.
@ignore
@mindex p
***************
*** 11411,11420 ****
@emph{exclusive}, and @dfn{semiopen} intervals in which one end
uses a round parenthesis and the other a square bracket. In mathematical
terms,
! @samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas
! @samp{[2 ..@: 4)} represents @cite{2 <= x < 4},
! @samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and
! @samp{(2 ..@: 4)} represents @cite{2 < x < address@hidden
@end ifinfo
@tex
Calc supports several varieties of intervals, including \dfn{closed}
 11557,11566 
@emph{exclusive}, and @dfn{semiopen} intervals in which one end
uses a round parenthesis and the other a square bracket. In mathematical
terms,
! @samp{[2 ..@: 4]} means @expr{2 <= x <= 4}, whereas
! @samp{[2 ..@: 4)} represents @expr{2 <= x < 4},
! @samp{(2 ..@: 4]} represents @expr{2 < x <= 4}, and
! @samp{(2 ..@: 4)} represents @expr{2 < x < 4}.
@end ifinfo
@tex
Calc supports several varieties of intervals, including \dfn{closed}
***************
*** 11464,11477 ****
While it may seem that intervals and error forms are similar, they are
based on entirely different concepts of inexact quantities. An error
! form address@hidden @t{+/} @c{$\sigma$}
! @var{sigma}' means a variable is random, and its value could
! be anything but is ``probably'' within one @c{$\sigma$}
! @var{sigma} of the mean value @cite{x}.
! An interval address@hidden@var{a} @t{..@:} @address@hidden' means a
variable's value
! is unknown, but guaranteed to lie in the specified range. Error forms
! are statistical or ``average case'' approximations; interval arithmetic
! tends to produce ``worst case'' bounds on an address@hidden
Intervals may not contain complex numbers, but they may contain
HMS forms or date forms.
 11610,11628 
While it may seem that intervals and error forms are similar, they are
based on entirely different concepts of inexact quantities. An error
! form
! @texline address@hidden @t{+/} @tmath{\sigma}'
! @infoline address@hidden @t{+/} @var{sigma}'
! means a variable is random, and its value could
! be anything but is ``probably'' within one
! @texline @tmath{\sigma}
! @infoline @var{sigma}
! of the mean value @expr{x}. An interval
! address@hidden@var{a} @t{..@:} @address@hidden' means a
! variable's value is unknown, but guaranteed to lie in the specified
! range. Error forms are statistical or ``average case'' approximations;
! interval arithmetic tends to produce ``worst case'' bounds on an
! answer.
Intervals may not contain complex numbers, but they may contain
HMS forms or date forms.
***************
*** 11537,11543 ****
If several values lie on the stack in front of the incomplete object,
all are collected and appended to the object. Thus the @kbd{,} key
is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people
! prefer the equivalent @key{SPC} key to @address@hidden
As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
@kbd{,} adds a zero or duplicates the preceding value in the list being
 11688,11694 
If several values lie on the stack in front of the incomplete object,
all are collected and appended to the object. Thus the @kbd{,} key
is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people
! prefer the equivalent @key{SPC} key to @key{RET}.
As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
@kbd{,} adds a zero or duplicates the preceding value in the list being
***************
*** 11575,11588 ****
The Calc variable @code{foo} corresponds to the Emacs Lisp variable
@code{varfoo}. Commands like @kbd{s s} (@code{calcstore}) that operate
on variables can be made to use any arbitrary Lisp variable simply by
! backspacing over the @samp{var} prefix in the address@hidden
In a command that takes a variable name, you can either type the full
name of a variable, or type a single digit to use one of the special
convenience variables @code{varq0} through @code{varq9}. For example,
@kbd{3 s s 2} stores the number 3 in variable @code{varq2}, and
@address@hidden s s foo @key{RET}}} stores that number in variable
! @address@hidden
To push a variable itself (as opposed to the variable's value) on the
stack, enter its name as an algebraic expression using the apostrophe
 11726,11739 
The Calc variable @code{foo} corresponds to the Emacs Lisp variable
@code{varfoo}. Commands like @kbd{s s} (@code{calcstore}) that operate
on variables can be made to use any arbitrary Lisp variable simply by
! backspacing over the @samp{var} prefix in the minibuffer.
In a command that takes a variable name, you can either type the full
name of a variable, or type a single digit to use one of the special
convenience variables @code{varq0} through @code{varq9}. For example,
@kbd{3 s s 2} stores the number 3 in variable @code{varq2}, and
@address@hidden s s foo @key{RET}}} stores that number in variable
! @code{varfoo}.
To push a variable itself (as opposed to the variable's value) on the
stack, enter its name as an algebraic expression using the apostrophe
***************
*** 11623,11629 ****
(@xref{Scientific Functions}.) When they are evaluated with @kbd{=},
their values are calculated if necessary according to the current precision
or complex polar mode. If you wish to use these symbols for other purposes,
! simply undefine or redefine them using @address@hidden
The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
infinite or indeterminate values. It's best not to use them as
 11774,11780 
(@xref{Scientific Functions}.) When they are evaluated with @kbd{=},
their values are calculated if necessary according to the current precision
or complex polar mode. If you wish to use these symbols for other purposes,
! simply undefine or redefine them using @code{calcstore}.
The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
infinite or indeterminate values. It's best not to use them as
***************
*** 11697,11704 ****
@samp{=>} address@hidden
Note that, unlike in usual computer notation, multiplication binds more
! strongly than division: @samp{a*b/c*d} is equivalent to @c{$a b \over c d$}
! @cite{(a*b)/(c*d)}.
@cindex Multiplication, implicit
@cindex Implicit multiplication
 11848,11856 
@samp{=>} address@hidden
Note that, unlike in usual computer notation, multiplication binds more
! strongly than division: @samp{a*b/c*d} is equivalent to
! @texline @tmath{a b \over c d}.
! @infoline @expr{(a*b)/(c*d)}.
@cindex Multiplication, implicit
@cindex Implicit multiplication
***************
*** 11712,11718 ****
cases you must use a space if you omit the @samp{*}: @samp{2a} is the
same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
is a variable called @code{ab}, @emph{not} the product of @samp{a} and
! @samp{b}! Also note that @samp{f (x)} is still a function address@hidden
@cindex Implicit comma in vectors
The rules are slightly different for vectors written with square brackets.
 11864,11870 
cases you must use a space if you omit the @samp{*}: @samp{2a} is the
same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
is a variable called @code{ab}, @emph{not} the product of @samp{a} and
! @samp{b}! Also note that @samp{f (x)} is still a function call.
@cindex Implicit comma in vectors
The rules are slightly different for vectors written with square brackets.
***************
*** 11724,11730 ****
ignored. To force spaces to be interpreted as multiplication you can
enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted
! between @samp{][}, as in the matrix @samp{[[1 2][3 address@hidden
Vectors that contain commas (not embedded within nested parentheses or
brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector
 11876,11882 
ignored. To force spaces to be interpreted as multiplication you can
enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted
! between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.
Vectors that contain commas (not embedded within nested parentheses or
brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector
***************
*** 11753,11764 ****
left alone. Beware that many innocentlooking short names like @code{in}
and @code{re} have predefined meanings which could surprise you; however,
single letters or single letters followed by digits are always safe to
! use for your own function names. @xref{Function address@hidden
In the documentation for particular commands, the notation @kbd{H S}
(@code{calcsinh}) address@hidden means that the key sequence @kbd{H S}, the
command @kbd{Mx calcsinh}, and the algebraic function @code{sinh(x)} all
! represent the same address@hidden
Commands that interpret (``parse'') text as algebraic formulas include
algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
 11905,11916 
left alone. Beware that many innocentlooking short names like @code{in}
and @code{re} have predefined meanings which could surprise you; however,
single letters or single letters followed by digits are always safe to
! use for your own function names. @xref{Function Index}.
In the documentation for particular commands, the notation @kbd{H S}
(@code{calcsinh}) address@hidden means that the key sequence @kbd{H S}, the
command @kbd{Mx calcsinh}, and the algebraic function @code{sinh(x)} all
! represent the same operation.
Commands that interpret (``parse'') text as algebraic formulas include
algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
***************
*** 11823,11829 ****
@key{RET} creates @samp{10 20 30 30},
@kbd{Cu 2 @key{RET}} creates @samp{10 20 30 20 30},
@kbd{Cu  2 @key{RET}} creates @samp{10 20 30 20}, and
! @kbd{Cu 0 @key{RET}} creates @samp{10 20 30 10 20 address@hidden
@kindex @key{LFD}
@pindex calcover
 11975,11981 
@key{RET} creates @samp{10 20 30 30},
@kbd{Cu 2 @key{RET}} creates @samp{10 20 30 20 30},
@kbd{Cu  2 @key{RET}} creates @samp{10 20 30 20}, and
! @kbd{Cu 0 @key{RET}} creates @samp{10 20 30 10 20 30}.
@kindex @key{LFD}
@pindex calcover
***************
*** 11833,11839 ****
oppositely. Also, with no prefix argument the default argument is 2.
Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{Cu 2 @key{LFD}}
are both equivalent to @kbd{Cu  2 @key{RET}}, producing
! @samp{10 20 30 address@hidden
@kindex @key{DEL}
@kindex Cd
 11985,11991 
oppositely. Also, with no prefix argument the default argument is 2.
Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{Cu 2 @key{LFD}}
are both equivalent to @kbd{Cu  2 @key{RET}}, producing
! @samp{10 20 30 20}.
@kindex @key{DEL}
@kindex Cd
***************
*** 11851,11857 ****
@key{DEL} leaves @samp{10 20},
@kbd{Cu 2 @key{DEL}} leaves @samp{10},
@kbd{Cu  2 @key{DEL}} leaves @samp{10 30}, and
! @kbd{Cu 0 @key{DEL}} leaves an empty address@hidden
@kindex address@hidden
@pindex calcpopabove
 12003,12009 
@key{DEL} leaves @samp{10 20},
@kbd{Cu 2 @key{DEL}} leaves @samp{10},
@kbd{Cu  2 @key{DEL}} leaves @samp{10 30}, and
! @kbd{Cu 0 @key{DEL}} leaves an empty stack.
@kindex address@hidden
@pindex calcpopabove
***************
*** 11874,11880 ****
@key{TAB} creates @samp{10 20 30 50 40},
@kbd{Cu 3 @key{TAB}} creates @samp{10 20 50 30 40},
@kbd{Cu  2 @key{TAB}} creates @samp{40 50 10 20 30}, and
! @kbd{Cu 0 @key{TAB}} creates @samp{50 40 30 20 address@hidden
@kindex address@hidden
@pindex calcrollup
 12026,12032 
@key{TAB} creates @samp{10 20 30 50 40},
@kbd{Cu 3 @key{TAB}} creates @samp{10 20 50 30 40},
@kbd{Cu  2 @key{TAB}} creates @samp{40 50 10 20 30}, and
! @kbd{Cu 0 @key{TAB}} creates @samp{50 40 30 20 10}.
@kindex address@hidden
@pindex calcrollup
***************
*** 11885,11891 ****
@address@hidden creates @samp{10 20 40 50 30},
@kbd{Cu 4 address@hidden creates @samp{10 30 40 50 20},
@kbd{Cu  2 address@hidden creates @samp{30 40 50 10 20}, and
! @kbd{Cu 0 address@hidden creates @samp{50 40 30 20 address@hidden
A good way to view the operation of @key{TAB} and @address@hidden is in
terms of moving a particular element to a new position in the stack.
 12037,12043 
@address@hidden creates @samp{10 20 40 50 30},
@kbd{Cu 4 address@hidden creates @samp{10 30 40 50 20},
@kbd{Cu  2 address@hidden creates @samp{30 40 50 10 20}, and
! @kbd{Cu 0 address@hidden creates @samp{50 40 30 20 10}.
A good way to view the operation of @key{TAB} and @address@hidden is in
terms of moving a particular element to a new position in the stack.
***************
*** 11988,11994 ****
Calc Trail window. In practice they are rarely used, since the commands
shown below are a more convenient way to move around in the
trail, and they work ``by remote control'' when the cursor is still
! in the Calculator address@hidden
@cindex Trail pointer
There is a @dfn{trail pointer} which selects some entry of the trail at
 12140,12146 
Calc Trail window. In practice they are rarely used, since the commands
shown below are a more convenient way to move around in the
trail, and they work ``by remote control'' when the cursor is still
! in the Calculator window.
@cindex Trail pointer
There is a @dfn{trail pointer} which selects some entry of the trail at
***************
*** 12011,12017 ****
@pindex calctrailscrollright
The @kbd{t <} (@code{calctrailscrollleft}) and @kbd{t >}
(@code{calctrailscrollright}) commands horizontally scroll the trail
! window left or right by one half of its address@hidden
@kindex t n
@pindex calctrailnext
 12163,12169 
@pindex calctrailscrollright
The @kbd{t <} (@code{calctrailscrollleft}) and @kbd{t >}
(@code{calctrailscrollright}) commands horizontally scroll the trail
! window left or right by one half of its width.
@kindex t n
@pindex calctrailnext
***************
*** 12026,12032 ****
one line. The @kbd{t f} (@code{calctrailforward}) and @kbd{t b}
(@code{calctrailbackward}) commands move the trail pointer down or up
one screenful at a time. All of these commands accept numeric prefix
! arguments to move several lines or screenfuls at a address@hidden
@kindex t [
@pindex calctrailfirst
 12178,12184 
one line. The @kbd{t f} (@code{calctrailforward}) and @kbd{t b}
(@code{calctrailbackward}) commands move the trail pointer down or up
one screenful at a time. All of these commands accept numeric prefix
! arguments to move several lines or screenfuls at a time.
@kindex t [
@pindex calctrailfirst
***************
*** 12038,12044 ****
(@code{calctraillast}) commands move the trail pointer to the first or
last line of the trail. The @kbd{t h} (@code{calctrailhere}) command
moves the trail pointer to the cursor position; unlike the other trail
! commands, @kbd{t h} works only when Calc Trail is the selected address@hidden
@kindex t s
@pindex calctrailisearchforward
 12190,12196 
(@code{calctraillast}) commands move the trail pointer to the first or
last line of the trail. The @kbd{t h} (@code{calctrailhere}) command
moves the trail pointer to the cursor position; unlike the other trail
! commands, @kbd{t h} works only when Calc Trail is the selected window.
@kindex t s
@pindex calctrailisearchforward
***************
*** 12050,12056 ****
search forward or backward through the trail. You can press @key{RET}
to terminate the search; the trail pointer moves to the current line.
If you cancel the search with @kbd{Cg}, the trail pointer stays where
! it was when the search address@hidden
@end ifinfo
@tex
The @kbd{t s} (@code{calctrailisearchforward}) and @kbd{t r}
 12202,12208 
search forward or backward through the trail. You can press @key{RET}
to terminate the search; the trail pointer moves to the current line.
If you cancel the search with @kbd{Cg}, the trail pointer stays where
! it was when the search began.
@end ifinfo
@tex
The @kbd{t s} (@code{calctrailisearchforward}) and @kbd{t r}
***************
*** 12248,12254 ****
round values already on the stack, but those values will be rounded
down before being used in any calculation. The @kbd{c 0} through
@kbd{c 9} commands (@pxref{Conversions}) can be used to round an
! existing value to a new address@hidden
@cindex Accuracy of calculations
It is important to distinguish the concepts of @dfn{precision} and
 12400,12406 
round values already on the stack, but those values will be rounded
down before being used in any calculation. The @kbd{c 0} through
@kbd{c 9} commands (@pxref{Conversions}) can be used to round an
! existing value to a new precision.
@cindex Accuracy of calculations
It is important to distinguish the concepts of @dfn{precision} and
***************
*** 12291,12297 ****
Instead, you must first press @kbd{I} (@code{calcinverse}) to set
the @dfn{Inverse Flag}, then press @kbd{S} (@code{calcsin}).
The @kbd{I} key actually toggles the Inverse Flag. When this flag
! is set, the word @samp{Inv} appears in the mode address@hidden
@kindex H
@pindex calchyperbolic
 12443,12449 
Instead, you must first press @kbd{I} (@code{calcinverse}) to set
the @dfn{Inverse Flag}, then press @kbd{S} (@code{calcsin}).
The @kbd{I} key actually toggles the Inverse Flag. When this flag
! is set, the word @samp{Inv} appears in the mode line.
@kindex H
@pindex calchyperbolic
***************
*** 12300,12306 ****
If both of these flags are set at once, the effect will be
@code{calcarcsinh}. (The Hyperbolic flag is also used by some
nontrigonometric commands; for example @kbd{H L} computes a base10,
! instead of address@hidden, logarithm.)@refill
Command names like @code{calcarcsin} are provided for completeness, and
may be executed with @kbd{x} or @kbd{Mx}. Their effect is simply to
 12452,12458 
If both of these flags are set at once, the effect will be
@code{calcarcsinh}. (The Hyperbolic flag is also used by some
nontrigonometric commands; for example @kbd{H L} computes a base10,
! instead of address@hidden, logarithm.)
Command names like @code{calcarcsin} are provided for completeness, and
may be executed with @kbd{x} or @kbd{Mx}. Their effect is simply to
***************
*** 12356,12363 ****
instead expressed in degrees. (Complexnumber calculations would
normally be done in radians mode, though. Complex numbers are converted
to degrees by calculating the complex result in radians and then
! multiplying by 180 over @c{$\pi$}
! @cite{pi}.)
@kindex m r
@pindex calcradiansmode
 12508,12514 
instead expressed in degrees. (Complexnumber calculations would
normally be done in radians mode, though. Complex numbers are converted
to degrees by calculating the complex result in radians and then
! multiplying by 180 over @cpi{}.)
@kindex m r
@pindex calcradiansmode
***************
*** 12368,12374 ****
The @kbd{m r} (@code{calcradiansmode}), @kbd{m d}
(@code{calcdegreesmode}),
and @kbd{m h} (@code{calchmsmode}) commands control the angular mode.
The current angular mode is displayed on the Emacs mode line.
! The default angular mode is address@hidden
@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
@subsection Polar Mode
 12519,12525 
The @kbd{m r} (@code{calcradiansmode}), @kbd{m d}
(@code{calcdegreesmode}),
and @kbd{m h} (@code{calchmsmode}) commands control the angular mode.
The current angular mode is displayed on the Emacs mode line.
! The default angular mode is degrees.
@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
@subsection Polar Mode
***************
*** 12396,12411 ****
Division of two integers normally yields a floatingpoint number if the
result cannot be expressed as an integer. In some cases you would
rather get an exact fractional answer. One way to accomplish this is
! to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @cite{3:2}
! even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}.
@kindex m f
@pindex calcfracmode
To set the Calculator to produce fractional results for normal integer
divisions, use the @kbd{m f} (@code{calcfracmode}) command.
! For example, @cite{8/4} produces @cite{2} in either mode,
! but @cite{6/4} produces @cite{3:2} in Fraction Mode, @cite{1.5} in
! Float address@hidden
At any time you can use @kbd{c f} (@code{calcfloat}) to convert a
fraction to a float, or @kbd{c F} (@code{calcfraction}) to convert a
 12547,12562 
Division of two integers normally yields a floatingpoint number if the
result cannot be expressed as an integer. In some cases you would
rather get an exact fractional answer. One way to accomplish this is
! to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @expr{3:2}
! even though @kbd{6 @key{RET} 4 /} produces @expr{1.5}.
@kindex m f
@pindex calcfracmode
To set the Calculator to produce fractional results for normal integer
divisions, use the @kbd{m f} (@code{calcfracmode}) command.
! For example, @expr{8/4} produces @expr{2} in either mode,
! but @expr{6/4} produces @expr{3:2} in Fraction Mode, @expr{1.5} in
! Float Mode.
At any time you can use @kbd{c f} (@code{calcfloat}) to convert a
fraction to a float, or @kbd{c F} (@code{calcfraction}) to convert a
***************
*** 12416,12422 ****
@noindent
@cindex Infinite mode
! The Calculator normally treats results like @cite{1 / 0} as errors;
formulas like this are left in unsimplified form. But Calc can be
put into a mode where such calculations instead produce ``infinite''
results.
 12567,12573 
@noindent
@cindex Infinite mode
! The Calculator normally treats results like @expr{1 / 0} as errors;
formulas like this are left in unsimplified form. But Calc can be
put into a mode where such calculations instead produce ``infinite''
results.
***************
*** 12432,12438 ****
With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
an undirected infinity. @xref{Infinities}, for a discussion of the
! difference between @code{inf} and @code{uinf}. Also, @cite{0 / 0}
evaluates to @code{nan}, the ``indeterminate'' symbol. Various other
functions can also return infinities in this mode; for example,
@samp{ln(0) = inf}, and @samp{gamma(7) = uinf}. Once again,
 12583,12589 
With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
an undirected infinity. @xref{Infinities}, for a discussion of the
! difference between @code{inf} and @code{uinf}. Also, @expr{0 / 0}
evaluates to @code{nan}, the ``indeterminate'' symbol. Various other
functions can also return infinities in this mode; for example,
@samp{ln(0) = inf}, and @samp{gamma(7) = uinf}. Once again,
***************
*** 12477,12483 ****
@code{calcsymbolicmode} and executing @kbd{=} (@code{calcevaluate}).
Given a numeric prefix argument, it also
sets the floatingpoint precision to the specified value for the duration
! of the address@hidden
To evaluate a formula numerically without expanding the variables it
contains, you can use the key sequence @kbd{m s a v m s} (this uses
 12628,12634 
@code{calcsymbolicmode} and executing @kbd{=} (@code{calcevaluate}).
Given a numeric prefix argument, it also
sets the floatingpoint precision to the specified value for the duration
! of the command.
To evaluate a formula numerically without expanding the variables it
contains, you can use the key sequence @kbd{m s a v m s} (this uses
***************
*** 12504,12510 ****
@samp{A*B} is not the same as @samp{B*A}.) This assumption affects
rewrite rules and algebraic simplification. Another effect of this
mode is that calculations that would normally produce constants like
! 0 and 1 (e.g., @cite{a  a} and @cite{a / a}, respectively) will now
produce function calls that represent ``generic'' zero or identity
matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function
@samp{idn(@var{a},@var{n})} returns @var{a} times an @address@hidden
 12655,12661 
@samp{A*B} is not the same as @samp{B*A}.) This assumption affects
rewrite rules and algebraic simplification. Another effect of this
mode is that calculations that would normally produce constants like
! 0 and 1 (e.g., @expr{a  a} and @expr{a / a}, respectively) will now
produce function calls that represent ``generic'' zero or identity
matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function
@samp{idn(@var{a},@var{n})} returns @var{a} times an @address@hidden
***************
*** 12598,12604 ****
disable all ``working'' messages. Use a numeric prefix of 1 to enable
only the plain @samp{Working...} message. Use a numeric prefix of 2 to
see intermediate results as well. With no numeric prefix this displays
! the current address@hidden
While it may seem that the ``working'' messages will slow Calc down
considerably, experiments have shown that their impact is actually
 12749,12755 
disable all ``working'' messages. Use a numeric prefix of 1 to enable
only the plain @samp{Working...} message. Use a numeric prefix of 2 to
see intermediate results as well. With no numeric prefix this displays
! the current mode.
While it may seem that the ``working'' messages will slow Calc down
considerably, experiments have shown that their impact is actually
***************
*** 12613,12625 ****
are ``normalized'' when being taken from or pushed onto the stack.
Some normalizations are unavoidable, such as rounding floatingpoint
results to the current precision, and reducing fractions to simplest
! form. Others, such as simplifying a formula like @cite{a+a} (or @cite{2+3}),
are done by default but can be turned off when necessary.
! When you press a key like @kbd{+} when @cite{2} and @cite{3} are on the
stack, Calc pops these numbers, normalizes them, creates the formula
! @cite{2+3}, normalizes it, and pushes the result. Of course the standard
! rules for normalizing @cite{2+3} will produce the result @cite{5}.
Simplification mode commands consist of the lowercase @kbd{m} prefix key
followed by a shifted letter.
 12764,12776 
are ``normalized'' when being taken from or pushed onto the stack.
Some normalizations are unavoidable, such as rounding floatingpoint
results to the current precision, and reducing fractions to simplest
! form. Others, such as simplifying a formula like @expr{a+a} (or @expr{2+3}),
are done by default but can be turned off when necessary.
! When you press a key like @kbd{+} when @expr{2} and @expr{3} are on the
stack, Calc pops these numbers, normalizes them, creates the formula
! @expr{2+3}, normalizes it, and pushes the result. Of course the standard
! rules for normalizing @expr{2+3} will produce the result @expr{5}.
Simplification mode commands consist of the lowercase @kbd{m} prefix key
followed by a shifted letter.
***************
*** 12627,12633 ****
@kindex m O
@pindex calcnosimplifymode
The @kbd{m O} (@code{calcnosimplifymode}) command turns off all optional
! simplifications. These would leave a formula like @cite{2+3} alone. In
fact, nothing except simple numbers are ever affected by normalization
in this mode.
 12778,12784 
@kindex m O
@pindex calcnosimplifymode
The @kbd{m O} (@code{calcnosimplifymode}) command turns off all optional
! simplifications. These would leave a formula like @expr{2+3} alone. In
fact, nothing except simple numbers are ever affected by normalization
in this mode.
***************
*** 12635,12656 ****
@pindex calcnumsimplifymode
The @kbd{m N} (@code{calcnumsimplifymode}) command turns off simplification
of any formulas except those for which all arguments are constants. For
! example, @cite{1+2} is simplified to @cite{3}, and @cite{a+(22)} is
! simplified to @cite{a+0} but no further, since one argument of the sum
! is not a constant. Unfortunately, @cite{(a+2)2} is @emph{not} simplified
because the toplevel @samp{} operator's arguments are not both
! constant numbers (one of them is the formula @cite{a+2}).
A constant is a number or other numeric object (such as a constant
error form or modulo form), or a vector all of whose
! elements are address@hidden
@kindex m D
@pindex calcdefaultsimplifymode
The @kbd{m D} (@code{calcdefaultsimplifymode}) command restores the
default simplifications for all formulas. This includes many easy and
! fast algebraic simplifications such as @cite{a+0} to @cite{a}, and
! @cite{a + 2 a} to @cite{3 a}, as well as evaluating functions like
! @address@hidden(x^2, x)} to @cite{2 x}.
@kindex m B
@pindex calcbinsimplifymode
 12786,12809 
@pindex calcnumsimplifymode
The @kbd{m N} (@code{calcnumsimplifymode}) command turns off simplification
of any formulas except those for which all arguments are constants. For
! example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(22)} is
! simplified to @expr{a+0} but no further, since one argument of the sum
! is not a constant. Unfortunately, @expr{(a+2)2} is @emph{not} simplified
because the toplevel @samp{} operator's arguments are not both
! constant numbers (one of them is the formula @expr{a+2}).
A constant is a number or other numeric object (such as a constant
error form or modulo form), or a vector all of whose
! elements are constant.
@kindex m D
@pindex calcdefaultsimplifymode
The @kbd{m D} (@code{calcdefaultsimplifymode}) command restores the
default simplifications for all formulas. This includes many easy and
! fast algebraic simplifications such as @expr{a+0} to @expr{a}, and
! @expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like
! @texline @address@hidden(x^2,x)}
! @infoline @address@hidden(x^2, x)}
! to @expr{2 x}.
@kindex m B
@pindex calcbinsimplifymode
***************
*** 12681,12693 ****
(@code{calcsimplifyunits}), which in turn
is a superset of @kbd{a s}. In this mode, variable names which
are identifiable as unit names (like @samp{mm} for ``millimeters'')
! are simplified with their unit definitions in address@hidden
A common technique is to set the simplification mode down to the lowest
amount of simplification you will allow to be applied automatically, then
use manual commands like @kbd{a s} and @kbd{c c} (@code{calcclean}) to
perform higher types of simplifications on demand. @xref{Algebraic
! Definitions}, for another sample use of nosimplification address@hidden
@node Declarations, Display Modes, Simplification Modes, Mode Settings
@section Declarations
 12834,12846 
(@code{calcsimplifyunits}), which in turn
is a superset of @kbd{a s}. In this mode, variable names which
are identifiable as unit names (like @samp{mm} for ``millimeters'')
! are simplified with their unit definitions in mind.
A common technique is to set the simplification mode down to the lowest
amount of simplification you will allow to be applied automatically, then
use manual commands like @kbd{a s} and @kbd{c c} (@code{calcclean}) to
perform higher types of simplifications on demand. @xref{Algebraic
! Definitions}, for another sample use of nosimplification mode.
@node Declarations, Display Modes, Simplification Modes, Mode Settings
@section Declarations
***************
*** 12949,12956 ****
Calc does not check the declarations for a variable when you store
a value in it. However, storing @i{3.5} in a variable that has
been declared @code{pos}, @code{int}, or @code{matrix} may have
! unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @cite{3.5}
! if it substitutes the value first, or to @cite{3.5} if @code{x}
was declared @code{pos} and the formula @samp{sqrt(x^2)} is
simplified to @samp{x} before the value is substituted. Before
using a variable for a new purpose, it is best to use @kbd{s d}
 13102,13109 
Calc does not check the declarations for a variable when you store
a value in it. However, storing @i{3.5} in a variable that has
been declared @code{pos}, @code{int}, or @code{matrix} may have
! unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5}
! if it substitutes the value first, or to @expr{3.5} if @code{x}
was declared @code{pos} and the formula @samp{sqrt(x^2)} is
simplified to @samp{x} before the value is substituted. Before
using a variable for a new purpose, it is best to use @kbd{s d}
***************
*** 13018,13024 ****
@end ignore
@tindex dimag
The @code{dimag} function checks if its argument is imaginary,
! i.e., is mathematically equal to a real number times @cite{i}.
@ignore
@starindex
 13171,13177 
@end ignore
@tindex dimag
The @code{dimag} function checks if its argument is imaginary,
! i.e., is mathematically equal to a real number times @expr{i}.
@ignore
@starindex
***************
*** 13036,13042 ****
The @code{dneg} function checks for negative reals. The @code{dnonneg}
function checks for nonnegative reals, i.e., reals greater than or
equal to zero. Note that the @kbd{a s} command can simplify an
! expression like @cite{x > 0} to 1 or 0 using @code{dpos}, and that
@kbd{a s} is effectively applied to all conditions in rewrite rules,
so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg}
are rarely necessary.
 13189,13195 
The @code{dneg} function checks for negative reals. The @code{dnonneg}
function checks for nonnegative reals, i.e., reals greater than or
equal to zero. Note that the @kbd{a s} command can simplify an
! expression like @expr{x > 0} to 1 or 0 using @code{dpos}, and that
@kbd{a s} is effectively applied to all conditions in rewrite rules,
so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg}
are rarely necessary.
***************
*** 13105,13111 ****
(@code{calclinebreaking}) commands are described elsewhere;
@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
Display formats for vectors and matrices are also covered elsewhere;
! @pxref{Vector and Matrix address@hidden
One thing all display modes have in common is their treatment of the
@kbd{H} prefix. This prefix causes any mode command that would normally
 13258,13264 
(@code{calclinebreaking}) commands are described elsewhere;
@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
Display formats for vectors and matrices are also covered elsewhere;
! @pxref{Vector and Matrix Formats}.
One thing all display modes have in common is their treatment of the
@kbd{H} prefix. This prefix causes any mode command that would normally
***************
*** 13165,13171 ****
respectively. Numbers can always be entered in any radix, though the
current radix is used as a default if you press @kbd{#} without any initial
digits. A number entered without a @kbd{#} is @emph{always} interpreted
! as address@hidden
@kindex d r
@pindex calcradix
 13318,13324 
respectively. Numbers can always be entered in any radix, though the
current radix is used as a default if you press @kbd{#} without any initial
digits. A number entered without a @kbd{#} is @emph{always} interpreted
! as decimal.
@kindex d r
@pindex calcradix
***************
*** 13180,13189 ****
represent the integer and no more. The @kbd{d z} (@code{calcleadingzeros})
command causes integers to be padded out with leading zeros according to the
current binary word size. (@xref{Binary Functions}, for a discussion of
! word size.) If the absolute value of the word size is @cite{w}, all integers
! are displayed with at least enough digits to represent @c{$2^w1$}
! @cite{(2^w)1} in the
! current radix. (Larger integers will still be displayed in their entirety.)
@node Grouping Digits, Float Formats, Radix Modes, Display Modes
@subsection Grouping Digits
 13333,13344 
represent the integer and no more. The @kbd{d z} (@code{calcleadingzeros})
command causes integers to be padded out with leading zeros according to the
current binary word size. (@xref{Binary Functions}, for a discussion of
! word size.) If the absolute value of the word size is @expr{w}, all integers
! are displayed with at least enough digits to represent
! @texline @tmath{2^w1}
! @infoline @expr{(2^w)1}
! in the current radix. (Larger integers will still be displayed in their
! entirety.)
@node Grouping Digits, Float Formats, Radix Modes, Display Modes
@subsection Grouping Digits
***************
*** 13202,13211 ****
The @kbd{d g} command toggles grouping on and off.
With a numerix prefix of 0, this command displays the current state of
the grouping flag; with an argument of minus one it disables grouping;
! with a positive argument @cite{N} it enables grouping on every @cite{N}
digits. For floatingpoint numbers, grouping normally occurs only
! before the decimal point. A negative prefix argument @cite{N} enables
! grouping every @cite{N} digits both before and after the decimal
address@hidden
@kindex d ,
@pindex calcgroupchar
 13357,13366 
The @kbd{d g} command toggles grouping on and off.
With a numerix prefix of 0, this command displays the current state of
the grouping flag; with an argument of minus one it disables grouping;
! with a positive argument @expr{N} it enables grouping on every @expr{N}
digits. For floatingpoint numbers, grouping normally occurs only
! before the decimal point. A negative prefix argument @expr{N} enables
! grouping every @expr{N} digits both before and after the decimal point.
@kindex d ,
@pindex calcgroupchar
***************
*** 13298,13304 ****
There are three supported notations for complex numbers in rectangular
form. The default is as a pair of real numbers enclosed in parentheses
and separated by a comma: @samp{(a,b)}. The @kbd{d c}
! (@code{calccomplexnotation}) command selects this address@hidden
@kindex d i
@pindex calcinotation
 13453,13459 
There are three supported notations for complex numbers in rectangular
form. The default is as a pair of real numbers enclosed in parentheses
and separated by a comma: @samp{(a,b)}. The @kbd{d c}
! (@code{calccomplexnotation}) command selects this style.
@kindex d i
@pindex calcinotation
***************
*** 13307,13313 ****
The other notations are @kbd{d i} (@code{calcinotation}), in which
numbers are displayed in @samp{a+bi} form, and @kbd{d j}
(@code{calcjnotation}) which displays the form @samp{a+bj} preferred
! in some address@hidden
@cindex @code{i} variable
@vindex i
 13462,13468 
The other notations are @kbd{d i} (@code{calcinotation}), in which
numbers are displayed in @samp{a+bi} form, and @kbd{d j}
(@code{calcjnotation}) which displays the form @samp{a+bj} preferred
! in some disciplines.
@cindex @code{i} variable
@vindex i
***************
*** 13318,13324 ****
will be interpreted as @samp{(0,1)} and the formula will be simplified
to @samp{(2,3)}. Other commands (like @code{calcsin}) will @emph{not}
interpret the formula @samp{2 + 3 * i} as a complex number.
! @xref{Variables}, under ``special constants.''@refill
@node Fraction Formats, HMS Formats, Complex Formats, Display Modes
@subsection Fraction Formats
 13473,13479 
will be interpreted as @samp{(0,1)} and the formula will be simplified
to @samp{(2,3)}. Other commands (like @code{calcsin}) will @emph{not}
interpret the formula @samp{2 + 3 * i} as a complex number.
! @xref{Variables}, under ``special constants.''
@node Fraction Formats, HMS Formats, Complex Formats, Display Modes
@subsection Fraction Formats
***************
*** 13346,13357 ****
Calc adjusts all fractions that are displayed to have the specified
denominator, if possible. Otherwise it adjusts the denominator to
be a multiple of the specified value. For example, in @samp{:6} mode
! the fraction @cite{1:6} will be unaffected, but @cite{2:3} will be
! displayed as @cite{4:6}, @cite{1:2} will be displayed as @cite{3:6},
! and @cite{1:8} will be displayed as @cite{3:24}. Integers are also
! affected by this mode: 3 is displayed as @cite{18:6}. Note that the
format @samp{:1} writes fractions the same as @samp{:}, but it writes
! integers as @cite{n:1}.
The fraction format does not affect the way fractions or integers are
stored, only the way they appear on the screen. The fraction format
 13501,13512 
Calc adjusts all fractions that are displayed to have the specified
denominator, if possible. Otherwise it adjusts the denominator to
be a multiple of the specified value. For example, in @samp{:6} mode
! the fraction @expr{1:6} will be unaffected, but @expr{2:3} will be
! displayed as @expr{4:6}, @expr{1:2} will be displayed as @expr{3:6},
! and @expr{1:8} will be displayed as @expr{3:24}. Integers are also
! affected by this mode: 3 is displayed as @expr{18:6}. Note that the
format @samp{:1} writes fractions the same as @samp{:}, but it writes
! integers as @expr{n:1}.
The fraction format does not affect the way fractions or integers are
stored, only the way they appear on the screen. The fraction format
***************
*** 13710,13724 ****
that the values below the @samp{.} are @emph{visible}, just temporarily
frozen. This feature allows you to keep several independent calculations
running at once in different parts of the stack, or to apply a certain
! command to an element buried deep in the address@hidden
Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor
is on. Thus, this line and all those below it become hidden. To unhide
these lines, move down to the end of the buffer and press @address@hidden t}}.
! With a positive numeric prefix argument @cite{n}, @kbd{d t} hides the
! bottom @cite{n} values in the buffer. With a negative argument, it hides
! all but the top @cite{n} values. With an argument of zero, it hides zero
! values, i.e., moves the @samp{.} all the way down to the address@hidden
@kindex d [
@pindex calctruncateup
 13865,13879 
that the values below the @samp{.} are @emph{visible}, just temporarily
frozen. This feature allows you to keep several independent calculations
running at once in different parts of the stack, or to apply a certain
! command to an element buried deep in the stack.
Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor
is on. Thus, this line and all those below it become hidden. To unhide
these lines, move down to the end of the buffer and press @address@hidden t}}.
! With a positive numeric prefix argument @expr{n}, @kbd{d t} hides the
! bottom @expr{n} values in the buffer. With a negative argument, it hides
! all but the top @expr{n} values. With an argument of zero, it hides zero
! values, i.e., moves the @samp{.} all the way down to the bottom.
@kindex d [
@pindex calctruncateup
***************
*** 13726,13732 ****
@pindex calctruncatedown
The @kbd{d [} (@code{calctruncateup}) and @kbd{d ]}
(@code{calctruncatedown}) commands move the @samp{.} up or down one
! line at a time (or several lines with a prefix argument)address@hidden
@node Justification, Labels, Truncating the Stack, Display Modes
@subsection Justification
 13881,13887 
@pindex calctruncatedown
The @kbd{d [} (@code{calctruncateup}) and @kbd{d ]}
(@code{calctruncatedown}) commands move the @samp{.} up or down one
! line at a time (or several lines with a prefix argument).
@node Justification, Labels, Truncating the Stack, Display Modes
@subsection Justification
***************
*** 13743,13749 ****
@kbd{d >} (@code{calcrightjustify}), or @kbd{d =}
(@code{calccenterjustify}). For example, in rightjustification mode,
stack entries are displayed flushright against the right edge of the
! address@hidden
If you change the width of the Calculator window you may have to type
@kbd{d @key{SPC}} (@code{calcrefresh}) to realign rightjustified or
centered
 13898,13904 
@kbd{d >} (@code{calcrightjustify}), or @kbd{d =}
(@code{calccenterjustify}). For example, in rightjustification mode,
stack entries are displayed flushright against the right edge of the
! window.
If you change the width of the Calculator window you may have to type
@kbd{d @key{SPC}} (@code{calcrefresh}) to realign rightjustified or
centered
***************
*** 13933,13942 ****
@end example
@noindent
! can represent either the negative rational number @cite{3:4}, or the
actual expression @samp{(3/4)}; but the latter formula would normally
never be displayed because it would immediately be evaluated to
! @cite{3:4} or @cite{0.75}, so this ambiguity is not a problem in
typical use.
Nondecimal numbers are displayed with subscripts. Thus there is no
 14088,14097 
@end example
@noindent
! can represent either the negative rational number @expr{3:4}, or the
actual expression @samp{(3/4)}; but the latter formula would normally
never be displayed because it would immediately be evaluated to
! @expr{3:4} or @expr{0.75}, so this ambiguity is not a problem in
typical use.
Nondecimal numbers are displayed with subscripts. Thus there is no
***************
*** 14061,14067 ****
Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
should be omitted when interfacing with Calc. To Calc, the @samp{$} sign
has the same meaning it always does in algebraic formulas (a reference to
! an existing entry on the stack)address@hidden
Complex numbers are displayed as in @samp{3 + 4i}. Fractions and
quotients are written using @code{\over};
 14216,14222 
Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
should be omitted when interfacing with Calc. To Calc, the @samp{$} sign
has the same meaning it always does in algebraic formulas (a reference to
! an existing entry on the stack).
Complex numbers are displayed as in @samp{3 + 4i}. Fractions and
quotients are written using @code{\over};
***************
*** 14073,14079 ****
The words @code{\left} and @code{\right} are ignored when reading
formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written
as @code{\infty}; when read, @code{\infty} always translates to
! @address@hidden
Function calls are written the usual way, with the function name followed
by the arguments in parentheses. However, functions for which @TeX{} has
 14228,14234 
The words @code{\left} and @code{\right} are ignored when reading
formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written
as @code{\infty}; when read, @code{\infty} always translates to
! @code{inf}.
Function calls are written the usual way, with the function name followed
by the arguments in parentheses. However, functions for which @TeX{} has
***************
*** 14081,14089 ****
parentheses for very simple arguments. During input, curly braces and
parentheses work equally well for grouping, but when the document is
formatted the curly braces will be invisible. Thus the printed result is
! @c{$\sin{2 x}$}
! @cite{sin 2x} but @c{$\sin(2 + x)$}
! @cite{sin(2 + x)}.
Function and variable names not treated specially by @TeX{} are simply
written out asis, which will cause them to come out in italic letters
 14236,14246 
parentheses for very simple arguments. During input, curly braces and
parentheses work equally well for grouping, but when the document is
formatted the curly braces will be invisible. Thus the printed result is
! @texline @tmath{\sin{2 x}}
! @infoline @expr{sin 2x}
! but
! @texline @tmath{\sin(2 + x)}.
! @infoline @expr{sin(2 + x)}.
Function and variable names not treated specially by @TeX{} are simply
written out asis, which will cause them to come out in italic letters
***************
*** 14244,14250 ****
@end group
@end example
@tex
 \let\rm\goodrm
$$ \sin\left( a^2 \over b_i \right) $$
@end tex
@sp 1
 14401,14406 
***************
*** 14282,14288 ****
@end group
@end example
@tex
! \turnoffactive\let\rm\goodrm
$$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$
@end tex
@sp 2
 14438,14444 
@end group
@end example
@tex
! \turnoffactive
$$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$
@end tex
@sp 2
***************
*** 14300,14306 ****
@end group
@end example
@tex
 \let\rm\goodrm
$$ [f(a), foo(bar), \sin{\pi}] $$
$$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$
$$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$
 14456,14461 
***************
*** 14453,14459 ****
Mathematica mode.
Nondecimal numbers are written, e.g., @samp{16^^7fff}. Floatingpoint
numbers in scientific notation are written @samp{1.23*10.^3}.
! Subscripts use double square brackets: @address@hidden
@node Maple Language Mode, Compositions, Mathematica Language Mode, Language
Modes
@subsection Maple Language Mode
 14608,14614 
Mathematica mode.
Nondecimal numbers are written, e.g., @samp{16^^7fff}. Floatingpoint
numbers in scientific notation are written @samp{1.23*10.^3}.
! Subscripts use double square brackets: @samp{a[[i]]}.
@node Maple Language Mode, Compositions, Mathematica Language Mode, Language
Modes
@subsection Maple Language Mode
***************
*** 14594,14602 ****
=> 40
@end example
! The general rule is that if an operator with precedence @cite{n}
! occurs as an argument to an operator with precedence @cite{m}, then
! the argument is enclosed in parentheses if @cite{n < m}. Toplevel
expressions and expressions which are function arguments, vector
components, etc., are formatted with precedence zero (so that they
normally never get additional parentheses).
 14749,14757 
=> 40
@end example
! The general rule is that if an operator with precedence @expr{n}
! occurs as an argument to an operator with precedence @expr{m}, then
! the argument is enclosed in parentheses if @expr{n < m}. Toplevel
expressions and expressions which are function arguments, vector
components, etc., are formatted with precedence zero (so that they
normally never get additional parentheses).
***************
*** 15579,15586 ****
@item
Matrix/scalar mode. Default value is @i{1}. Value is 0 for scalar
! mode, @i{2} for matrix mode, or @var{N} for @c{$N\times N$}
! @address@hidden matrix mode. Command is @kbd{m v}.
@item
Simplification mode. Default is 1. Value is @i{1} for off (@kbd{m O}),
 15734,15743 
@item
Matrix/scalar mode. Default value is @i{1}. Value is 0 for scalar
! mode, @i{2} for matrix mode, or @var{N} for
! @texline @tmath{N\times N}
! @infoline @address@hidden
! matrix mode. Command is @kbd{m v}.
@item
Simplification mode. Default is 1. Value is @i{1} for off (@kbd{m O}),
***************
*** 15906,15914 ****
work, for the same reasons just mentioned for vectors. Instead you must
write @samp{(a +/ b) + (c +/ 0)}.
! If both arguments of @kbd{+} are modulo forms with equal values of @cite{M},
or if one argument is a modulo form and the other a plain number, the
! result is a modulo form which represents the sum, modulo @cite{M}, of
the two values.
If both arguments of @kbd{+} are intervals, the result is an interval
 16063,16071 
work, for the same reasons just mentioned for vectors. Instead you must
write @samp{(a +/ b) + (c +/ 0)}.
! If both arguments of @kbd{+} are modulo forms with equal values of @expr{M},
or if one argument is a modulo form and the other a plain number, the
! result is a modulo form which represents the sum, modulo @expr{M}, of
the two values.
If both arguments of @kbd{+} are intervals, the result is an interval
***************
*** 15964,15982 ****
@end ignore
@tindex /
The @kbd{/} (@code{calcdivide}) command divides two numbers. When
! dividing a scalar @cite{B} by a square matrix @cite{A}, the computation
! performed is @cite{B} times the inverse of @cite{A}. This also occurs
! if @cite{B} is itself a vector or matrix, in which case the effect is
! to solve the set of linear equations represented by @cite{B}. If @cite{B}
! is a matrix with the same number of rows as @cite{A}, or a plain vector
(which is interpreted here as a column vector), then the equation
! @cite{A X = B} is solved for the vector or matrix @cite{X}. Otherwise,
! if @cite{B} is a nonsquare matrix with the same number of @emph{columns}
! as @cite{A}, the equation @cite{X A = B} is solved. If you wish a vector
! @cite{B} to be interpreted as a row vector to be solved as @cite{X A = B},
make it into a onerow matrix with @kbd{Cu 1 v p} first. To force a
! lefthanded solution with a square matrix @cite{B}, transpose @cite{A} and
! @cite{B} before dividing, then transpose the result.
HMS forms can be divided by real numbers or by other HMS forms. Error
forms can be divided in any combination of ways. Modulo forms where both
 16121,16139 
@end ignore
@tindex /
The @kbd{/} (@code{calcdivide}) command divides two numbers. When
! dividing a scalar @expr{B} by a square matrix @expr{A}, the computation
! performed is @expr{B} times the inverse of @expr{A}. This also occurs
! if @expr{B} is itself a vector or matrix, in which case the effect is
! to solve the set of linear equations represented by @expr{B}. If @expr{B}
! is a matrix with the same number of rows as @expr{A}, or a plain vector
(which is interpreted here as a column vector), then the equation
! @expr{A X = B} is solved for the vector or matrix @expr{X}. Otherwise,
! if @expr{B} is a nonsquare matrix with the same number of @emph{columns}
! as @expr{A}, the equation @expr{X A = B} is solved. If you wish a vector
! @expr{B} to be interpreted as a row vector to be solved as @expr{X A = B},
make it into a onerow matrix with @kbd{Cu 1 v p} first. To force a
! lefthanded solution with a square matrix @expr{B}, transpose @expr{A} and
! @expr{B} before dividing, then transpose the result.
HMS forms can be divided by real numbers or by other HMS forms. Error
forms can be divided in any combination of ways. Modulo forms where both
***************
*** 16026,16035 ****
@tindex %
The @kbd{%} (@code{calcmod}) command performs a ``modulo'' (or ``remainder'')
operation. Mathematically, @samp{a%b = a  (a\b)*b}, and is defined
! for all real numbers @cite{a} and @cite{b} (except @cite{b=0}). For
! positive @cite{b}, the result will always be between 0 (inclusive) and
! @cite{b} (exclusive). Modulo does not work for HMS forms and error forms.
! If @cite{a} is a modulo form, its modulo is changed to @cite{b}, which
must be positive real number.
@kindex :
 16183,16192 
@tindex %
The @kbd{%} (@code{calcmod}) command performs a ``modulo'' (or ``remainder'')
operation. Mathematically, @samp{a%b = a  (a\b)*b}, and is defined
! for all real numbers @expr{a} and @expr{b} (except @expr{b=0}). For
! positive @expr{b}, the result will always be between 0 (inclusive) and
! @expr{b} (exclusive). Modulo does not work for HMS forms and error forms.
! If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which
must be positive real number.
@kindex :
***************
*** 16083,16089 ****
@tindex inv
@cindex Reciprocal
The @kbd{&} (@code{calcinv}) address@hidden command computes the
! reciprocal of a number, i.e., @cite{1 / x}. Operating on a square
matrix, it computes the inverse of that matrix.
@kindex Q
 16240,16246 
@tindex inv
@cindex Reciprocal
The @kbd{&} (@code{calcinv}) address@hidden command computes the
! reciprocal of a number, i.e., @expr{1 / x}. Operating on a square
matrix, it computes the inverse of that matrix.
@kindex Q
***************
*** 16098,16105 ****
@tindex hypot
The @kbd{f h} (@code{calchypot}) address@hidden command computes the square
root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)}
! is the length of the hypotenuse of a right triangle with sides @cite{a}
! and @cite{b}. If the arguments are complex numbers, their squared
magnitudes are used.
@kindex f Q
 16255,16262 
@tindex hypot
The @kbd{f h} (@code{calchypot}) address@hidden command computes the square
root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)}
! is the length of the hypotenuse of a right triangle with sides @expr{a}
! and @expr{b}. If the arguments are complex numbers, their squared
magnitudes are used.
@kindex f Q
***************
*** 16124,16130 ****
respectively. These commands also work on HMS forms, date forms,
intervals, and infinities. (In algebraic expressions, these functions
take any number of arguments and return the maximum or minimum among
! all the arguments.)@refill
@kindex f M
@kindex f X
 16281,16287 
respectively. These commands also work on HMS forms, date forms,
intervals, and infinities. (In algebraic expressions, these functions
take any number of arguments and return the maximum or minimum among
! all the arguments.)
@kindex f M
@kindex f X
***************
*** 16133,16149 ****
@pindex calcxponpart
@tindex xpon
The @kbd{f M} (@code{calcmantpart}) address@hidden function extracts
! the ``mantissa'' part @cite{m} of its floatingpoint argument; @kbd{f X}
(@code{calcxponpart}) address@hidden extracts the ``exponent'' part
! @cite{e}. The original number is equal to @c{$m \times 10^e$}
! @cite{m * 10^e},
! where @cite{m} is in the interval @samp{[1.0 ..@: 10.0)} except that
! @cite{m=e=0} if the original number is zero. For integers
and fractions, @code{mant} returns the number unchanged and @code{xpon}
returns zero. The @kbd{v u} (@code{calcunpack}) command can also be
used to ``unpack'' a floatingpoint number; this produces an integer
mantissa and exponent, with the constraint that the mantissa is not
! a multiple of ten (again except for the @cite{m=e=0} case)address@hidden
@kindex f S
@pindex calcscalefloat
 16290,16307 
@pindex calcxponpart
@tindex xpon
The @kbd{f M} (@code{calcmantpart}) address@hidden function extracts
! the ``mantissa'' part @expr{m} of its floatingpoint argument; @kbd{f X}
(@code{calcxponpart}) address@hidden extracts the ``exponent'' part
! @expr{e}. The original number is equal to
! @texline @tmath{m \times 10^e},
! @infoline @expr{m * 10^e},
! where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that
! @expr{m=e=0} if the original number is zero. For integers
and fractions, @code{mant} returns the number unchanged and @code{xpon}
returns zero. The @kbd{v u} (@code{calcunpack}) command can also be
used to ``unpack'' a floatingpoint number; this produces an integer
mantissa and exponent, with the constraint that the mantissa is not
! a multiple of ten (again except for the @expr{m=e=0} case).
@kindex f S
@pindex calcscalefloat
***************
*** 16152,16158 ****
by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any
real @samp{x}. The second argument must be an integer, but the first
may actually be any numeric value. For example, @samp{scf(5,2) = 0.05}
! or @samp{1:20} depending on the current Fraction address@hidden
@kindex f [
@kindex f ]
 16310,16316 
by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any
real @samp{x}. The second argument must be an integer, but the first
may actually be any numeric value. For example, @samp{scf(5,2) = 0.05}
! or @samp{1:20} depending on the current Fraction Mode.
@kindex f [
@kindex f ]
***************
*** 16167,16176 ****
For example, incrementing @samp{12.3456} when the current precision
is 6 digits yields @samp{12.3457}. If the current precision had been
8 digits, the result would have been @samp{12.345601}. Incrementing
! @samp{0.0} produces @c{$10^{p}$}
! @cite{10^p}, where @cite{p} is the current
precision. These operations are defined only on integers and floats.
! With numeric prefix arguments, they change the number by @cite{n} units.
Note that incrementing followed by decrementing, or viceversa, will
almost but not quite always cancel out. Suppose the precision is
 16325,16336 
For example, incrementing @samp{12.3456} when the current precision
is 6 digits yields @samp{12.3457}. If the current precision had been
8 digits, the result would have been @samp{12.345601}. Incrementing
! @samp{0.0} produces
! @texline @tmath{10^{p}},
! @infoline @expr{10^p},
! where @expr{p} is the current
precision. These operations are defined only on integers and floats.
! With numeric prefix arguments, they change the number by @expr{n} units.
Note that incrementing followed by decrementing, or viceversa, will
almost but not quite always cancel out. Suppose the precision is
***************
*** 16207,16213 ****
The @kbd{F} (@code{calcfloor}) address@hidden or @code{ffloor}] command
truncates a real number to the next lower integer, i.e., toward minus
infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
! @address@hidden
@kindex I F
@pindex calcceiling
 16367,16373 
The @kbd{F} (@code{calcfloor}) address@hidden or @code{ffloor}] command
truncates a real number to the next lower integer, i.e., toward minus
infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
! @i{4}.
@kindex I F
@pindex calcceiling
***************
*** 16219,16225 ****
@kindex H I F
The @kbd{I F} (@code{calcceiling}) address@hidden or @code{fceil}]
command truncates toward positive infinity. Thus @kbd{3.6 I F} produces
! 4, and @kbd{_3.6 I F} produces @address@hidden
@kindex R
@pindex calcround
 16379,16385 
@kindex H I F
The @kbd{I F} (@code{calcceiling}) address@hidden or @code{fceil}]
command truncates toward positive infinity. Thus @kbd{3.6 I F} produces
! 4, and @kbd{_3.6 I F} produces @i{3}.
@kindex R
@pindex calcround
***************
*** 16233,16239 ****
rounds to the nearest integer. When the fractional part is .5 exactly,
this command rounds away from zero. (All other rounding in the
Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4
! but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @address@hidden
@kindex I R
@pindex calctrunc
 16393,16399 
rounds to the nearest integer. When the fractional part is .5 exactly,
this command rounds away from zero. (All other rounding in the
Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4
! but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{4}.
@kindex I R
@pindex calctrunc
***************
*** 16246,16252 ****
The @kbd{I R} (@code{calctrunc}) address@hidden or @code{ftrunc}]
command truncates toward zero. In other words, it ``chops off''
everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and
! @kbd{_3.6 I R} produces @address@hidden
These functions may not be applied meaningfully to error forms, but they
do work for intervals. As a convenience, applying @code{floor} to a
 16406,16412 
The @kbd{I R} (@code{calctrunc}) address@hidden or @code{ftrunc}]
command truncates toward zero. In other words, it ``chops off''
everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and
! @kbd{_3.6 I R} produces @i{3}.
These functions may not be applied meaningfully to error forms, but they
do work for intervals. As a convenience, applying @code{floor} to a
***************
*** 16284,16290 ****
already have been rounded to the current precision before @code{rounde}
begins. For example, @samp{rounde(2.500001)} with a current precision
of 6 will incorrectly, or at least surprisingly, yield 2 because the
! argument will first have been rounded down to @cite{2.5} (which
@code{rounde} sees as an exact tie between 2 and 3).
Each of these functions, when written in algebraic formulas, allows
 16444,16450 
already have been rounded to the current precision before @code{rounde}
begins. For example, @samp{rounde(2.500001)} with a current precision
of 6 will incorrectly, or at least surprisingly, yield 2 because the
! argument will first have been rounded down to @expr{2.5} (which
@code{rounde} sees as an exact tie between 2 and 3).
Each of these functions, when written in algebraic formulas, allows
***************
*** 16298,16304 ****
@cindex Fractional part of a number
To compute the fractional part of a number (i.e., the amount which, when
added to address@hidden(address@hidden@t{)}', will produce @var{n}) just take
@var{n}
! modulo 1 using the @code{%} address@hidden
Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm),
and @kbd{f Q} (integer square root) commands, which are analogous to
 16458,16464 
@cindex Fractional part of a number
To compute the fractional part of a number (i.e., the amount which, when
added to address@hidden(address@hidden@t{)}', will produce @var{n}) just take
@var{n}
! modulo 1 using the @code{%} command.
Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm),
and @kbd{f Q} (integer square root) commands, which are analogous to
***************
*** 16313,16320 ****
@pindex calcconj
@tindex conj
The @kbd{J} (@code{calcconj}) address@hidden command computes the
! complex conjugate of a number. For complex number @cite{a+bi}, the
! complex conjugate is @cite{abi}. If the argument is a real number,
this command leaves it the same. If the argument is a vector or matrix,
this command replaces each element by its complex conjugate.
 16473,16480 
@pindex calcconj
@tindex conj
The @kbd{J} (@code{calcconj}) address@hidden command computes the
! complex conjugate of a number. For complex number @expr{a+bi}, the
! complex conjugate is @expr{abi}. If the argument is a real number,
this command leaves it the same. If the argument is a vector or matrix,
this command replaces each element by its complex conjugate.
***************
*** 16324,16338 ****
The @kbd{G} (@code{calcargument}) address@hidden command computes the
``argument'' or polar angle of a complex number. For a number in polar
notation, this is simply the second component of the pair
! address@hidden(address@hidden@t{;address@hidden
! @address@hidden)}'.
The result is expressed according to the current angular mode and will
be in the range @i{180} degrees (exclusive) to @i{+180} degrees
! (inclusive), or the equivalent range in address@hidden
@pindex calcimaginary
The @code{calcimaginary} command multiplies the number on the
! top of the stack by the imaginary number @cite{i = (0,1)}. This
command is not normally bound to a key in Calc, but it is available
on the @key{IMAG} button in Keypad Mode.
 16484,16498 
The @kbd{G} (@code{calcargument}) address@hidden command computes the
``argument'' or polar angle of a complex number. For a number in polar
notation, this is simply the second component of the pair
! @texline address@hidden(address@hidden@t{;address@hidden@t{)}'.
! @infoline address@hidden(address@hidden@t{;address@hidden@t{)}'.
The result is expressed according to the current angular mode and will
be in the range @i{180} degrees (exclusive) to @i{+180} degrees
! (inclusive), or the equivalent range in radians.
@pindex calcimaginary
The @code{calcimaginary} command multiplies the number on the
! top of the stack by the imaginary number @expr{i = (0,1)}. This
command is not normally bound to a key in Calc, but it is available
on the @key{IMAG} button in Keypad Mode.
***************
*** 16342,16355 ****
The @kbd{f r} (@code{calcre}) address@hidden command replaces a complex
number
by its real part. This command has no effect on real numbers. (As an
added convenience, @code{re} applied to a modulo form extracts
! the value part.)@refill
@kindex f i
@pindex calcim
@tindex im
The @kbd{f i} (@code{calcim}) address@hidden command replaces a complex
number
by its imaginary part; real numbers are converted to zero. With a vector
! or matrix argument, these functions operate address@hidden
@ignore
@mindex v p
 16502,16515 
The @kbd{f r} (@code{calcre}) address@hidden command replaces a complex
number
by its real part. This command has no effect on real numbers. (As an
added convenience, @code{re} applied to a modulo form extracts
! the value part.)
@kindex f i
@pindex calcim
@tindex im
The @kbd{f i} (@code{calcim}) address@hidden command replaces a complex
number
by its imaginary part; real numbers are converted to zero. With a vector
! or matrix argument, these functions operate elementwise.
@ignore
@mindex v p
***************
*** 16383,16395 ****
@tindex pfloat
The @kbd{c f} (@code{calcfloat}) address@hidden command converts the
number on the top of the stack to floatingpoint form. For example,
! @cite{23} is converted to @cite{23.0}, @cite{3:2} is converted to
! @cite{1.5}, and @cite{2.3} is left the same. If the value is a composite
object such as a complex number or vector, each of the components is
converted to floatingpoint. If the value is a formula, all numbers
in the formula are converted to floatingpoint. Note that depending
on the current floatingpoint precision, conversion to floatingpoint
! format may lose address@hidden
As a special exception, integers which appear as powers or subscripts
are not floated by @kbd{c f}. If you really want to float a power,
 16543,16555 
@tindex pfloat
The @kbd{c f} (@code{calcfloat}) address@hidden command converts the
number on the top of the stack to floatingpoint form. For example,
! @expr{23} is converted to @expr{23.0}, @expr{3:2} is converted to
! @expr{1.5}, and @expr{2.3} is left the same. If the value is a composite
object such as a complex number or vector, each of the components is
converted to floatingpoint. If the value is a formula, all numbers
in the formula are converted to floatingpoint. Note that depending
on the current floatingpoint precision, conversion to floatingpoint
! format may lose information.
As a special exception, integers which appear as powers or subscripts
are not floated by @kbd{c f}. If you really want to float a power,
***************
*** 16442,16448 ****
The @kbd{c d} (@code{calctodegrees}) address@hidden command converts a
number into degrees form. The value on the top of the stack may be an
HMS form (interpreted as degreesminutesseconds), or a real number which
! will be interpreted in radians regardless of the current angular
address@hidden
@kindex c r
@pindex calctoradians
 16602,16608 
The @kbd{c d} (@code{calctodegrees}) address@hidden command converts a
number into degrees form. The value on the top of the stack may be an
HMS form (interpreted as degreesminutesseconds), or a real number which
! will be interpreted in radians regardless of the current angular mode.
@kindex c r
@pindex calctoradians
***************
*** 16475,16481 ****
functions in algebraic formulas, depending on the direction of
conversion. (It uses @code{polar}, except that if the argument is
already a polar complex number, it uses @code{rect} instead. The
! @kbd{I c p} command always uses @code{rect}.)@refill
@kindex c c
@pindex calcclean
 16635,16641 
functions in algebraic formulas, depending on the direction of
conversion. (It uses @code{polar}, except that if the argument is
already a polar complex number, it uses @code{rect} instead. The
! @kbd{I c p} command always uses @code{rect}.)
@kindex c c
@pindex calcclean
***************
*** 16488,16494 ****
angular mode is different from the one under which the number was
produced!) Integers and fractions are generally unaffected by this
operation. Vectors and formulas are cleaned by cleaning each component
! number (i.e., pervasively)address@hidden
If the simplification mode is set below the default level, it is raised
to the default level for the purposes of this command. Thus, @kbd{c c}
 16648,16654 
angular mode is different from the one under which the number was
produced!) Integers and fractions are generally unaffected by this
operation. Vectors and formulas are cleaned by cleaning each component
! number (i.e., pervasively).
If the simplification mode is set below the default level, it is raised
to the default level for the purposes of this command. Thus, @kbd{c c}
***************
*** 16809,16815 ****
There is no @code{newday} function at all because @kbd{F} address@hidden
serves this purpose. Similarly, instead of @code{incday} and
! @code{incweek} simply use @cite{d + n} or @cite{d + 7 n}.
@xref{Basic Arithmetic}, for the @kbd{f ]} address@hidden command
which can adjust a date/time form by a certain number of seconds.
 16969,16975 
There is no @code{newday} function at all because @kbd{F} address@hidden
serves this purpose. Similarly, instead of @code{incday} and
! @code{incweek} simply use @expr{d + n} or @expr{d + 7 n}.
@xref{Basic Arithmetic}, for the @kbd{f ]} address@hidden command
which can adjust a date/time form by a certain number of seconds.
***************
*** 16870,16881 ****
@item
Any Calc formula which evaluates to one of the above three things.
! If the formula involves the variable @cite{y}, it stands for a
! yearly repeating holiday; @cite{y} will take on various year
numbers like 1992. For example, @samp{date(y, 12, 25)} specifies
Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies
Thanksgiving (which is held on the fourth Thursday of November).
! If the formula involves the variable @cite{m}, that variable
takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is
a holiday that takes place on the 15th of every month.
 17030,17041 
@item
Any Calc formula which evaluates to one of the above three things.
! If the formula involves the variable @expr{y}, it stands for a
! yearly repeating holiday; @expr{y} will take on various year
numbers like 1992. For example, @samp{date(y, 12, 25)} specifies
Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies
Thanksgiving (which is held on the fourth Thursday of November).
! If the formula involves the variable @expr{m}, that variable
takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is
a holiday that takes place on the 15th of every month.
***************
*** 17290,17296 ****
20% smaller than 50. (The answers are different in magnitude
because, in the first case, we're increasing by 25% of 40, but
in the second case, we're decreasing by 20% of 50.) The effect
! of @kbd{40 @key{RET} 50 b %} is to compute @cite{(5040)/40}, converting
the answer to percentage form as if by @kbd{c %}.
@node Future Value, Present Value, Percentages, Financial Functions
 17450,17456 
20% smaller than 50. (The answers are different in magnitude
because, in the first case, we're increasing by 25% of 40, but
in the second case, we're decreasing by 20% of 50.) The effect
! of @kbd{40 @key{RET} 50 b %} is to compute @expr{(5040)/40}, converting
the answer to percentage form as if by @kbd{c %}.
@node Future Value, Present Value, Percentages, Financial Functions
***************
*** 17334,17340 ****
fourth argument, which is used as an initial lump sum in the sense
of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n},
@var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment})
! + fvl(@var{rate}, @var{n}, @var{initial})address@hidden
To illustrate the relationships between these functions, we could
do the @code{fvb} calculation ``by hand'' using @code{fvl}. The
 17494,17500 
fourth argument, which is used as an initial lump sum in the sense
of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n},
@var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment})
! + fvl(@var{rate}, @var{n}, @var{initial})}.
To illustrate the relationships between these functions, we could
do the @code{fvb} calculation ``by hand'' using @code{fvl}. The
***************
*** 17352,17358 ****
as the beginning of the next, so what this really means is that we've
lost the payment at year zero (which contributed $1300.78), but we're
now counting the payment at year five (which, since it didn't have
! a chance to earn interest, counts as $1000). Indeed, @cite{5569.96 =
5870.73  1300.78 + 1000} (give or take a bit of roundoff error).
@node Present Value, Related Financial Functions, Future Value, Financial
Functions
 17512,17518 
as the beginning of the next, so what this really means is that we've
lost the payment at year zero (which contributed $1300.78), but we're
now counting the payment at year five (which, since it didn't have
! a chance to earn interest, counts as $1000). Indeed, @expr{5569.96 =
5870.73  1300.78 + 1000} (give or take a bit of roundoff error).
@node Present Value, Related Financial Functions, Future Value, Financial
Functions
***************
*** 17382,17388 ****
the return from leaving the money in the bank, which is
@code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money
you would have to put up in advance. The @code{pv} function
! finds the breakeven point, @cite{x = 6479.44}, at which
@code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is
the largest amount you should be willing to invest.
 17542,17548 
the return from leaving the money in the bank, which is
@code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money
you would have to put up in advance. The @code{pv} function
! finds the breakeven point, @expr{x = 6479.44}, at which
@code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is
the largest amount you should be willing to invest.
***************
*** 17431,17437 ****
payment arguments, each either a vector or a plain number, all these
values are collected lefttoright into the complete list of payments.
A numeric prefix argument on the @kbd{b N} command says how many
! payment values or vectors to take from the address@hidden
@kindex I b N
@tindex npvb
 17591,17597 
payment arguments, each either a vector or a plain number, all these
values are collected lefttoright into the complete list of payments.
A numeric prefix argument on the @kbd{b N} command says how many
! payment values or vectors to take from the stack.
@kindex I b N
@tindex npvb
***************
*** 17453,17459 ****
the amount of periodic payment necessary to amortize a loan.
Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the
value of @var{payment} such that @code{pv(@var{rate}, @var{n},
! @var{payment}) = @address@hidden
@kindex I b M
@tindex pmtb
 17613,17619 
the amount of periodic payment necessary to amortize a loan.
Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the
value of @var{payment} such that @code{pv(@var{rate}, @var{n},
! @var{payment}) = @var{amount}}.
@kindex I b M
@tindex pmtb
***************
*** 17475,17488 ****
the value of @var{n} such that @code{pv(@var{rate}, @var{n},
@var{payment}) = @var{amount}}. If @var{payment} is too small
ever to amortize a loan for @var{amount} at interest rate @var{rate},
! the @code{nper} function is left in symbolic address@hidden
@kindex I b #
@tindex nperb
The @kbd{I b #} address@hidden command does the same computation
but using @code{pvb} instead of @code{pv}. You can give a fourth
lumpsum argument to these functions, but the computation will be
! rather slow in the fourargument address@hidden
@kindex H b #
@tindex nperl
 17635,17648 
the value of @var{n} such that @code{pv(@var{rate}, @var{n},
@var{payment}) = @var{amount}}. If @var{payment} is too small
ever to amortize a loan for @var{amount} at interest rate @var{rate},
! the @code{nper} function is left in symbolic form.
@kindex I b #
@tindex nperb
The @kbd{I b #} address@hidden command does the same computation
but using @code{pvb} instead of @code{pv}. You can give a fourth
lumpsum argument to these functions, but the computation will be
! rather slow in the fourargument case.
@kindex H b #
@tindex nperl
***************
*** 17490,17496 ****
using @code{pvl}. By exchanging @var{payment} and @var{amount} you
can also get the solution for @code{fvl}. For example,
@code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a
! bank account earning 8%, it will take nine years to grow to address@hidden
@kindex b T
@pindex calcfinrate
 17650,17656 
using @code{pvl}. By exchanging @var{payment} and @var{amount} you
can also get the solution for @code{fvl}. For example,
@code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a
! bank account earning 8%, it will take nine years to grow to $2000.
@kindex b T
@pindex calcfinrate
***************
*** 17499,17505 ****
the rate of return on an investment. This is also an inverse of @code{pv}:
@code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of
@var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) =
! @var{amount}}. The result is expressed as a formula like @address@hidden
@kindex I b T
@kindex H b T
 17659,17665 
the rate of return on an investment. This is also an inverse of @code{pv}:
@code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of
@var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) =
! @var{amount}}. The result is expressed as a formula like @samp{6.3%}.
@kindex I b T
@kindex H b T
***************
*** 17511,17517 ****
accept an optional fourth argument just like @code{pv} and @code{pvb}.
To redo the above example from a different perspective,
@code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an
! interest rate of 8% in order to double your account in nine address@hidden
@kindex b I
@pindex calcfinirr
 17671,17677 
accept an optional fourth argument just like @code{pv} and @code{pvb}.
To redo the above example from a different perspective,
@code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an
! interest rate of 8% in order to double your account in nine years.
@kindex b I
@pindex calcfinirr
***************
*** 17573,17579 ****
parameter as well, although it will ignore its value except that the
return value will as usual be zero if @var{period} is out of range.
! For example, pushing the vector @cite{[1,2,3,4,5]} (perhaps with @kbd{v x 5})
and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),
ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare
the three depreciation methods:
 17733,17739 
parameter as well, although it will ignore its value except that the
return value will as usual be zero if @var{period} is out of range.
! For example, pushing the vector @expr{[1,2,3,4,5]} (perhaps with @kbd{v x 5})
and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),
ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare
the three depreciation methods:
***************
*** 17594,17600 ****
@kbd{syd} depreciates more at the beginning and less at the end,
and @kbd{ddb} weights the depreciation even more toward the beginning.
! Summing columns with @kbd{V R : +} yields @cite{[10000, 10000, 10000]};
the total depreciation in any method is (by definition) the
difference between the cost and the salvage value.
 17754,17760 
@kbd{syd} depreciates more at the beginning and less at the end,
and @kbd{ddb} weights the depreciation even more toward the beginning.
! Summing columns with @kbd{V R : +} yields @expr{[10000, 10000, 10000]};
the total depreciation in any method is (by definition) the
difference between the cost and the salvage value.
***************
*** 17716,17722 ****
@end tex
@noindent
! In @code{pmt} and @code{pmtb}, @cite{x=0} if omitted.
These functions accept any numeric objects, including error forms,
intervals, and even (though not very usefully) complex numbers. The
 17876,17882 
@end tex
@noindent
! In @code{pmt} and @code{pmtb}, @expr{x=0} if omitted.
These functions accept any numeric objects, including error forms,
intervals, and even (though not very usefully) complex numbers. The
***************
*** 17776,17806 ****
zeros with @kbd{d z}. @xref{Radix Modes}.
@cindex Word size for binary operations
! The Calculator maintains a current @dfn{word size} @cite{w}, an
arbitrary positive or negative integer. For a positive word size, all
! of the binary operations described here operate modulo @cite{2^w}. In
particular, negative arguments are converted to positive integers modulo
! @cite{2^w} by all binary address@hidden
If the word size is negative, binary operations produce 2's complement
! integers from @c{$2^{w1}$}
! @cite{(2^(w1))} to @c{$2^{w1}1$}
! @cite{2^(w1)1} inclusive. Either
! mode accepts inputs in any range; the sign of @cite{w} affects only
! the results produced.
@kindex b c
@pindex calcclip
@tindex clip
The @kbd{b c} (@code{calcclip})
address@hidden command can be used to clip a number by reducing it modulo
! @cite{2^w}. The commands described in this chapter automatically clip
their results to the current word size. Note that other operations like
addition do not use the current word size, since integer addition
generally is not ``binary.'' (However, @pxref{Simplification Modes},
@code{calcbinsimplifymode}.) For example, with a word size of 8
bits @kbd{b c} converts a number to the range 0 to 255; with a word
! size of @i{8} @kbd{b c} converts to the range @i{128} to address@hidden
@kindex b w
@pindex calcwordsize
 17936,17969 
zeros with @kbd{d z}. @xref{Radix Modes}.
@cindex Word size for binary operations
! The Calculator maintains a current @dfn{word size} @expr{w}, an
arbitrary positive or negative integer. For a positive word size, all
! of the binary operations described here operate modulo @expr{2^w}. In
particular, negative arguments are converted to positive integers modulo
! @expr{2^w} by all binary functions.
If the word size is negative, binary operations produce 2's complement
! integers from
! @texline @tmath{2^{w1}}
! @infoline @expr{(2^(w1))}
! to
! @texline @tmath{2^{w1}1}
! @infoline @expr{2^(w1)1}
! inclusive. Either mode accepts inputs in any range; the sign of
! @expr{w} affects only the results produced.
@kindex b c
@pindex calcclip
@tindex clip
The @kbd{b c} (@code{calcclip})
address@hidden command can be used to clip a number by reducing it modulo
! @expr{2^w}. The commands described in this chapter automatically clip
their results to the current word size. Note that other operations like
addition do not use the current word size, since integer addition
generally is not ``binary.'' (However, @pxref{Simplification Modes},
@code{calcbinsimplifymode}.) For example, with a word size of 8
bits @kbd{b c} converts a number to the range 0 to 255; with a word
! size of @i{8} @kbd{b c} converts to the range @i{128} to 127.
@kindex b w
@pindex calcwordsize
***************
*** 17820,17826 ****
in symbolic form unless the all of its argument(s) are integers or
integervalued floats.
! If either or both arguments are modulo forms for which @cite{M} is a
power of two, that power of two is taken as the word size unless a
numeric prefix argument overrides it. The current word size is never
consulted when modulopoweroftwo forms are involved.
 17983,17989 
in symbolic form unless the all of its argument(s) are integers or
integervalued floats.
! If either or both arguments are modulo forms for which @expr{M} is a
power of two, that power of two is taken as the word size unless a
numeric prefix argument overrides it. The current word size is never
consulted when modulopoweroftwo forms are involved.
***************
*** 17830,17836 ****
@tindex and
The @kbd{b a} (@code{calcand}) address@hidden command computes the bitwise
AND of the two numbers on the top of the stack. In other words, for each
! of the @cite{w} binary digits of the two numbers (pairwise), the corresponding
bit of the result is 1 if and only if both input bits are 1:
@samp{and(2#1100, 2#1010) = 2#1000}.
 17993,17999 
@tindex and
The @kbd{b a} (@code{calcand}) address@hidden command computes the bitwise
AND of the two numbers on the top of the stack. In other words, for each
! of the @expr{w} binary digits of the two numbers (pairwise), the corresponding
bit of the result is 1 if and only if both input bits are 1:
@samp{and(2#1100, 2#1010) = 2#1000}.
***************
*** 17965,17981 ****
@cindex Phi, golden ratio
@cindex Golden ratio
One miscellaneous command is address@hidden (@code{calcpi}), which pushes
! the value of @c{$\pi$}
! @cite{pi} (at the current precision) onto the stack. With the
! Hyperbolic flag, it pushes the value @cite{e}, the base of natural logarithms.
! With the Inverse flag, it pushes Euler's constant @c{$\gamma$}
! @cite{gamma} (about 0.5772). With both Inverse and Hyperbolic, it
! pushes the ``golden ratio'' @c{$\phi$}
! @cite{phi} (about 1.618). (At present, Euler's constant is not available
to unlimited precision; Calc knows only the first 100 digits.)
In Symbolic mode, these commands push the
actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi},
! respectively, instead of their values; @pxref{Symbolic address@hidden
@ignore
@mindex Q
 18128,18147 
@cindex Phi, golden ratio
@cindex Golden ratio
One miscellaneous command is address@hidden (@code{calcpi}), which pushes
! the value of @cpi{} (at the current precision) onto the stack. With the
! Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms.
! With the Inverse flag, it pushes Euler's constant
! @texline @tmath{\gamma}
! @infoline @expr{gamma}
! (about 0.5772). With both Inverse and Hyperbolic, it
! pushes the ``golden ratio''
! @texline @tmath{\phi}
! @infoline @expr{phi}
! (about 1.618). (At present, Euler's constant is not available
to unlimited precision; Calc knows only the first 100 digits.)
In Symbolic mode, these commands push the
actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi},
! respectively, instead of their values; @pxref{Symbolic Mode}.
@ignore
@mindex Q
***************
*** 18027,18033 ****
@end ignore
@kindex I L
The address@hidden (@code{calcexp}) address@hidden command computes the
! exponential, i.e., @cite{e} raised to the power of the number on the stack.
The meanings of the Inverse and Hyperbolic flags follow from those for
the @code{calcln} command.
 18193,18199 
@end ignore
@kindex I L
The address@hidden (@code{calcexp}) address@hidden command computes the
! exponential, i.e., @expr{e} raised to the power of the number on the stack.
The meanings of the Inverse and Hyperbolic flags follow from those for
the @code{calcln} command.
***************
*** 18048,18055 ****
(base10) logarithm of a number. (With the Inverse flag address@hidden,
it raises ten to a given power.) Note that the common logarithm of a
complex number is computed by taking the natural logarithm and dividing
! by @c{$\ln10$}
! @cite{ln(10)}.
@kindex B
@kindex I B
 18214,18222 
(base10) logarithm of a number. (With the Inverse flag address@hidden,
it raises ten to a given power.) Note that the common logarithm of a
complex number is computed by taking the natural logarithm and dividing
! by
! @texline @tmath{\ln10}.
! @infoline @expr{ln(10)}.
@kindex B
@kindex I B
***************
*** 18058,18066 ****
@tindex alog
The @kbd{B} (@code{calclog}) address@hidden command computes a logarithm
to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since
! @c{$2^{10} = 1024$}
! @cite{2^10 = 1024}. In certain cases like @samp{log(3,9)}, the result
! will be either @cite{1:2} or @cite{0.5} depending on the current Fraction
Mode setting. With the Inverse flag address@hidden, this command is
similar to @kbd{^} except that the order of the arguments is reversed.
 18225,18234 
@tindex alog
The @kbd{B} (@code{calclog}) address@hidden command computes a logarithm
to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since
! @texline @tmath{2^{10} = 1024}.
! @infoline @expr{2^10 = 1024}.
! In certain cases like @samp{log(3,9)}, the result
! will be either @expr{1:2} or @expr{0.5} depending on the current Fraction
Mode setting. With the Inverse flag address@hidden, this command is
similar to @kbd{^} except that the order of the arguments is reversed.
***************
*** 18070,18076 ****
The @kbd{f I} (@code{calcilog}) address@hidden command computes the
integer logarithm of a number to any base. The number and the base must
themselves be positive integers. This is the true logarithm, rounded
! down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @cite{x} in the
range from 1000 to 9999. If both arguments are positive integers, exact
integer arithmetic is used; otherwise, this is equivalent to
@samp{floor(log(x,b))}.
 18238,18244 
The @kbd{f I} (@code{calcilog}) address@hidden command computes the
integer logarithm of a number to any base. The number and the base must
themselves be positive integers. This is the true logarithm, rounded
! down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @expr{x} in the
range from 1000 to 9999. If both arguments are positive integers, exact
integer arithmetic is used; otherwise, this is equivalent to
@samp{floor(log(x,b))}.
***************
*** 18079,18097 ****
@pindex calcexpm1
@tindex expm1
The @kbd{f E} (@code{calcexpm1}) address@hidden command computes
! @c{$e^x  1$}
! @cite{exp(x)1}, but using an algorithm that produces a more accurate
! answer when the result is close to zero, i.e., when @c{$e^x$}
! @cite{exp(x)} is close
! to one.
@kindex f L
@pindex calclnp1
@tindex lnp1
The @kbd{f L} (@code{calclnp1}) address@hidden command computes
! @c{$\ln(x+1)$}
! @cite{ln(x+1)}, producing a more accurate answer when @cite{x} is close
! to zero.
@node Trigonometric and Hyperbolic Functions, Advanced Math Functions,
Logarithmic Functions, Scientific Functions
@section Trigonometric/Hyperbolic Functions
 18247,18267 
@pindex calcexpm1
@tindex expm1
The @kbd{f E} (@code{calcexpm1}) address@hidden command computes
! @texline @tmath{e^x  1},
! @infoline @expr{exp(x)1},
! but using an algorithm that produces a more accurate
! answer when the result is close to zero, i.e., when
! @texline @tmath{e^x}
! @infoline @expr{exp(x)}
! is close to one.
@kindex f L
@pindex calclnp1
@tindex lnp1
The @kbd{f L} (@code{calclnp1}) address@hidden command computes
! @texline @tmath{\ln(x+1)},
! @infoline @expr{ln(x+1)},
! producing a more accurate answer when @expr{x} is close to zero.
@node Trigonometric and Hyperbolic Functions, Advanced Math Functions,
Logarithmic Functions, Scientific Functions
@section Trigonometric/Hyperbolic Functions
***************
*** 18104,18110 ****
of an angle or complex number. If the input is an HMS form, it is interpreted
as degreesminutesseconds; otherwise, the input is interpreted according
to the current angular mode. It is best to use Radians mode when operating
! on complex address@hidden
Calc's ``units'' mechanism includes angular units like @code{deg},
@code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated
 18274,18280 
of an angle or complex number. If the input is an HMS form, it is interpreted
as degreesminutesseconds; otherwise, the input is interpreted according
to the current angular mode. It is best to use Radians mode when operating
! on complex numbers.
Calc's ``units'' mechanism includes angular units like @code{deg},
@code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated
***************
*** 18120,18134 ****
@xref{Symbolic Mode}. Beware, this simplification occurs even if you
have stored a different value in the variable @samp{pi}; this is one
reason why changing builtin variables is a bad idea. Arguments of
! the form @cite{x} plus a multiple of @c{$\pi/2$}
! @cite{pi/2} are also simplified.
! Calc includes similar formulas for @code{cos} and @address@hidden
The @kbd{a s} command knows all angles which are integer multiples of
! @c{$\pi/12$}
! @cite{pi/12}, @c{$\pi/10$}
! @cite{pi/10}, or @c{$\pi/8$}
! @cite{pi/8} radians. In degrees mode,
analogous simplifications occur for integer multiples of 15 or 18
degrees, and for arguments plus multiples of 90 degrees.
 18290,18300 
@xref{Symbolic Mode}. Beware, this simplification occurs even if you
have stored a different value in the variable @samp{pi}; this is one
reason why changing builtin variables is a bad idea. Arguments of
! the form @expr{x} plus a multiple of @cpiover{2} are also simplified.
! Calc includes similar formulas for @code{cos} and @code{tan}.
The @kbd{a s} command knows all angles which are integer multiples of
! @cpiover{12}, @cpiover{10}, or @cpiover{8} radians. In degrees mode,
analogous simplifications occur for integer multiples of 15 or 18
degrees, and for arguments plus multiples of 90 degrees.
***************
*** 18253,18259 ****
@address@hidden, @var{sin}]}.
With the Inverse flag address@hidden, this command takes a twoelement
vector as an argument and computes @code{arctan2} of the elements.
! (This command does not accept the Hyperbolic flag.)@refill
@node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic
Functions, Scientific Functions
@section Advanced Mathematical Functions
 18419,18425 
@address@hidden, @var{sin}]}.
With the Inverse flag address@hidden, this command takes a twoelement
vector as an argument and computes @code{arctan2} of the elements.
! (This command does not accept the Hyperbolic flag.)
@node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic
Functions, Scientific Functions
@section Advanced Mathematical Functions
***************
*** 18278,18285 ****
gamma function. For positive integer arguments, this is related to the
factorial function: @samp{gamma(n+1) = fact(n)}. For general complex
arguments the gamma function can be defined by the following definite
! integral: @c{$\Gamma(a) = \int_0^\infty t^{a1} e^t dt$}
! @cite{gamma(a) = integ(t^(a1) exp(t), t, 0, inf)}.
(The actual implementation uses far more efficient computational methods.)
@kindex f G
 18444,18452 
gamma function. For positive integer arguments, this is related to the
factorial function: @samp{gamma(n+1) = fact(n)}. For general complex
arguments the gamma function can be defined by the following definite
! integral:
! @texline @tmath{\Gamma(a) = \int_0^\infty t^{a1} e^t dt}.
! @infoline @expr{gamma(a) = integ(t^(a1) exp(t), t, 0, inf)}.
(The actual implementation uses far more efficient computational methods.)
@kindex f G
***************
*** 18311,18332 ****
@tindex gammaG
The @kbd{f G} (@code{calcincgamma}) address@hidden command computes
the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by
! the integral, @c{$P(a,x) = \left( \int_0^x t^{a1} e^t dt \right) /
\Gamma(a)$}
! @cite{gammaP(a,x) = integ(t^(a1) exp(t), t, 0, x) / gamma(a)}.
! This implies that @samp{gammaP(a,inf) = 1} for any @cite{a} (see the
definition of the normal gamma function).
Several other varieties of incomplete gamma function are defined.
! The complement of @cite{P(a,x)}, called @cite{Q(a,x) = 1P(a,x)} by
some authors, is computed by the @kbd{I f G} address@hidden command.
You can think of this as taking the other half of the integral, from
! @cite{x} to infinity.
@ifinfo
! The functions corresponding to the integrals that define @cite{P(a,x)}
! and @cite{Q(a,x)} but without the normalizing @cite{1/gamma(a)}
! factor are called @cite{g(a,x)} and @cite{G(a,x)}, respectively
! (where @cite{g} and @cite{G} represent the lower and uppercase Greek
letter gamma). You can obtain these using the @kbd{H f G} address@hidden
and @kbd{H I f G} address@hidden commands.
@end ifinfo
 18478,18500 
@tindex gammaG
The @kbd{f G} (@code{calcincgamma}) address@hidden command computes
the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by
! the integral,
! @texline @tmath{P(a,x) = \left( \int_0^x t^{a1} e^t dt \right) / \Gamma(a)}.
! @infoline @expr{gammaP(a,x) = integ(t^(a1) exp(t), t, 0, x) / gamma(a)}.
! This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the
definition of the normal gamma function).
Several other varieties of incomplete gamma function are defined.
! The complement of @expr{P(a,x)}, called @expr{Q(a,x) = 1P(a,x)} by
some authors, is computed by the @kbd{I f G} address@hidden command.
You can think of this as taking the other half of the integral, from
! @expr{x} to infinity.
@ifinfo
! The functions corresponding to the integrals that define @expr{P(a,x)}
! and @expr{Q(a,x)} but without the normalizing @expr{1/gamma(a)}
! factor are called @expr{g(a,x)} and @expr{G(a,x)}, respectively
! (where @expr{g} and @expr{G} represent the lower and uppercase Greek
letter gamma). You can obtain these using the @kbd{H f G} address@hidden
and @kbd{H I f G} address@hidden commands.
@end ifinfo
***************
*** 18344,18353 ****
@tindex beta
The @kbd{f b} (@code{calcbeta}) address@hidden command computes the
Euler beta function, which is defined in terms of the gamma function as
! @c{$B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)$}
! @cite{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, or by
! @c{$B(a,b) = \int_0^1 t^{a1} (1t)^{b1} dt$}
! @cite{beta(a,b) = integ(t^(a1) (1t)^(b1), t, 0, 1)}.
@kindex f B
@kindex H f B
 18512,18522 
@tindex beta
The @kbd{f b} (@code{calcbeta}) address@hidden command computes the
Euler beta function, which is defined in terms of the gamma function as
! @texline @tmath{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)},
! @infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)},
! or by
! @texline @tmath{B(a,b) = \int_0^1 t^{a1} (1t)^{b1} dt}.
! @infoline @expr{beta(a,b) = integ(t^(a1) (1t)^(b1), t, 0, 1)}.
@kindex f B
@kindex H f B
***************
*** 18355,18363 ****
@tindex betaI
@tindex betaB
The @kbd{f B} (@code{calcincbeta}) address@hidden command computes
! the incomplete beta function @cite{I(x,a,b)}. It is defined by
! @c{$I(x,a,b) = \left( \int_0^x t^{a1} (1t)^{b1} dt \right) / B(a,b)$}
! @cite{betaI(x,a,b) = integ(t^(a1) (1t)^(b1), t, 0, x) / beta(a,b)}.
Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding
unnormalized version address@hidden
 18524,18532 
@tindex betaI
@tindex betaB
The @kbd{f B} (@code{calcincbeta}) address@hidden command computes
! the incomplete beta function @expr{I(x,a,b)}. It is defined by
! @texline @tmath{I(x,a,b) = \left( \int_0^x t^{a1} (1t)^{b1} dt \right) /
B(a,b)}.
! @infoline @expr{betaI(x,a,b) = integ(t^(a1) (1t)^(b1), t, 0, x) /
beta(a,b)}.
Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding
unnormalized version address@hidden
***************
*** 18367,18378 ****
@tindex erf
@tindex erfc
The @kbd{f e} (@code{calcerf}) address@hidden command computes the
! error function @c{$\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{t^2} dt$}
! @cite{erf(x) = 2 integ(exp((t^2)), t, 0, x) / sqrt(pi)}.
The complementary error function @kbd{I f e} (@code{calcerfc}) address@hidden
is the corresponding integral from @samp{x} to infinity; the sum
! @c{$\hbox{erf}(x) + \hbox{erfc}(x) = 1$}
! @cite{erf(x) + erfc(x) = 1}.
@kindex f j
@kindex f y
 18536,18548 
@tindex erf
@tindex erfc
The @kbd{f e} (@code{calcerf}) address@hidden command computes the
! error function
! @texline @tmath{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{t^2} dt}.
! @infoline @expr{erf(x) = 2 integ(exp((t^2)), t, 0, x) / sqrt(pi)}.
The complementary error function @kbd{I f e} (@code{calcerfc}) address@hidden
is the corresponding integral from @samp{x} to infinity; the sum
! @texline @tmath{\hbox{erf}(x) + \hbox{erfc}(x) = 1}.
! @infoline @expr{erf(x) + erfc(x) = 1}.
@kindex f j
@kindex f y
***************
*** 18384,18393 ****
(@code{calcbesselY}) address@hidden commands compute the Bessel
functions of the first and second kinds, respectively.
In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter
! @cite{n} is often an integer, but is not required to be one.
Calc's implementation of the Bessel functions currently limits the
precision to 8 digits, and may not be exact even to that precision.
! Use with address@hidden
@node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific
Functions
@section Branch Cuts and Principal Values
 18554,18563 
(@code{calcbesselY}) address@hidden commands compute the Bessel
functions of the first and second kinds, respectively.
In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter
! @expr{n} is often an integer, but is not required to be one.
Calc's implementation of the Bessel functions currently limits the
precision to 8 digits, and may not be exact even to that precision.
! Use with care!
@node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific
Functions
@section Branch Cuts and Principal Values
***************
*** 18420,18428 ****
efficiency or accuracy. You may need to increase the floating precision
and wait a while to get suitable answers from them.
! For @samp{sqrt(a+bi)}: When @cite{a<0} and @cite{b} is small but positive
! or zero, the result is close to the @cite{+i} axis. For @cite{b} small and
! negative, the result is close to the @cite{i} axis. The result always lies
in the right half of the complex plane.
For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}.
 18590,18598 
efficiency or accuracy. You may need to increase the floating precision
and wait a while to get suitable answers from them.
! For @samp{sqrt(a+bi)}: When @expr{a<0} and @expr{b} is small but positive
! or zero, the result is close to the @expr{+i} axis. For @expr{b} small and
! negative, the result is close to the @expr{i} axis. The result always lies
in the right half of the complex plane.
For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}.
***************
*** 18431,18438 ****
negative real axis.
The following table describes these branch cuts in another way.
! If the real and imaginary parts of @cite{z} are as shown, then
! the real and imaginary parts of @cite{f(z)} will be as shown.
Here @code{eps} stands for a small positive value; each
occurrence of @code{eps} may stand for a different small value.
 18601,18608 
negative real axis.
The following table describes these branch cuts in another way.
! If the real and imaginary parts of @expr{z} are as shown, then
! the real and imaginary parts of @expr{f(z)} will be as shown.
Here @code{eps} stands for a small positive value; each
occurrence of @code{eps} may stand for a different small value.
***************
*** 18448,18455 ****
For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}.
One interesting consequence of this is that @samp{(8)^1:3} does
not evaluate to @i{2} as you might expect, but to the complex
! number @cite{(1., 1.732)}. Both of these are valid cube roots
! of @i{8} (as is @cite{(1., 1.732)}); Calc chooses a perhaps
lessobvious root for the sake of mathematical consistency.
For @samp{arcsin(z)}: This is defined by @samp{i*ln(i*z + sqrt(1z^2))}.
 18618,18625 
For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}.
One interesting consequence of this is that @samp{(8)^1:3} does
not evaluate to @i{2} as you might expect, but to the complex
! number @expr{(1., 1.732)}. Both of these are valid cube roots
! of @i{8} (as is @expr{(1., 1.732)}); Calc chooses a perhaps
lessobvious root for the sake of mathematical consistency.
For @samp{arcsin(z)}: This is defined by @samp{i*ln(i*z + sqrt(1z^2))}.
***************
*** 18461,18471 ****
For @samp{arctan(z)}: This is defined by
@samp{(ln(1+i*z)  ln(1i*z)) / (2*i)}. The branch cuts are on the
! imaginary axis, below @cite{i} and above @cite{i}.
For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}.
! The branch cuts are on the imaginary axis, below @cite{i} and
! above @cite{i}.
For @samp{arccosh(z)}: This is defined by
@samp{ln(z + (z+1)*sqrt((z1)/(z+1)))}. The branch cut is on the
 18631,18641 
For @samp{arctan(z)}: This is defined by
@samp{(ln(1+i*z)  ln(1i*z)) / (2*i)}. The branch cuts are on the
! imaginary axis, below @expr{i} and above @expr{i}.
For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}.
! The branch cuts are on the imaginary axis, below @expr{i} and
! above @expr{i}.
For @samp{arccosh(z)}: This is defined by
@samp{ln(z + (z+1)*sqrt((z1)/(z+1)))}. The branch cut is on the
***************
*** 18543,18580 ****
The @kbd{k r} (@code{calcrandom}) address@hidden command produces
random numbers of various sorts.
! Given a positive numeric prefix argument @cite{M}, it produces a random
! integer @cite{N} in the range @c{$0 \le N < M$}
! @cite{0 <= N < M}. Each of the @cite{M}
! values appears with equal address@hidden
With no numeric prefix argument, the @kbd{k r} command takes its argument
! from the stack instead. Once again, if this is a positive integer @cite{M}
! the result is a random integer less than @cite{M}. However, note that
! while numeric prefix arguments are limited to six digits or so, an @cite{M}
! taken from the stack can be arbitrarily large. If @cite{M} is negative,
! the result is a random integer in the range @c{$M < N \le 0$}
! @cite{M < N <= 0}.
!
! If the value on the stack is a floatingpoint number @cite{M}, the result
! is a random floatingpoint number @cite{N} in the range @c{$0 \le N < M$}
! @cite{0 <= N < M}
! or @c{$M < N \le 0$}
! @cite{M < N <= 0}, according to the sign of @cite{M}.
! If @cite{M} is zero, the result is a Gaussiandistributed random real
number; the distribution has a mean of zero and a standard deviation
of one. The algorithm used generates random numbers in pairs; thus,
every other call to this function will be especially fast.
! If @cite{M} is an error form @c{$m$ @code{+/} $\sigma$}
! @samp{m +/ s} where @var{m}
! and @c{$\sigma$}
! @var{s} are both real numbers, the result uses a Gaussian
! distribution with mean @var{m} and standard deviation @c{$\sigma$}
@var{s}.
! If @cite{M} is an interval form, the lower and upper bounds specify the
acceptable limits of the random numbers. If both bounds are integers,
the result is a random integer in the specified range. If either bound
is floatingpoint, the result is a random real number in the specified
 18713,18759 
The @kbd{k r} (@code{calcrandom}) address@hidden command produces
random numbers of various sorts.
! Given a positive numeric prefix argument @expr{M}, it produces a random
! integer @expr{N} in the range
! @texline @tmath{0 \le N < M}.
! @infoline @expr{0 <= N < M}.
! Each of the @expr{M} values appears with equal probability.
With no numeric prefix argument, the @kbd{k r} command takes its argument
! from the stack instead. Once again, if this is a positive integer @expr{M}
! the result is a random integer less than @expr{M}. However, note that
! while numeric prefix arguments are limited to six digits or so, an @expr{M}
! taken from the stack can be arbitrarily large. If @expr{M} is negative,
! the result is a random integer in the range
! @texline @tmath{M < N \le 0}.
! @infoline @expr{M < N <= 0}.
!
! If the value on the stack is a floatingpoint number @expr{M}, the result
! is a random floatingpoint number @expr{N} in the range
! @texline @tmath{0 \le N < M}
! @infoline @expr{0 <= N < M}
! or
! @texline @tmath{M < N \le 0},
! @infoline @expr{M < N <= 0},
! according to the sign of @expr{M}.
! If @expr{M} is zero, the result is a Gaussiandistributed random real
number; the distribution has a mean of zero and a standard deviation
of one. The algorithm used generates random numbers in pairs; thus,
every other call to this function will be especially fast.
! If @expr{M} is an error form
! @texline @tmath{m} @code{+/} @tmath{\sigma}
! @infoline @samp{m +/ s}
! where @var{m} and
! @texline @tmath{\sigma}
! @infoline @var{s}
! are both real numbers, the result uses a Gaussian distribution with mean
! @var{m} and standard deviation
! @texline @tmath{\sigma}.
@var{s}.
! If @expr{M} is an interval form, the lower and upper bounds specify the
acceptable limits of the random numbers. If both bounds are integers,
the result is a random integer in the specified range. If either bound
is floatingpoint, the result is a random real number in the specified
***************
*** 18586,18592 ****
additionally return 2.00000, but the probability of this happening is
extremely small.)
! If @cite{M} is a vector, the result is one element taken at random from
the vector. All elements of the vector are given equal probabilities.
@vindex RandSeed
 18765,18771 
additionally return 2.00000, but the probability of this happening is
extremely small.)
! If @expr{M} is a vector, the result is one element taken at random from
the vector. All elements of the vector are given equal probabilities.
@vindex RandSeed
***************
*** 18609,18617 ****
@kindex k a
@pindex calcrandomagain
The @kbd{k a} (@code{calcrandomagain}) command produces another random
! number, reusing the most recent value of @cite{M}. With a numeric
prefix argument @var{n}, it produces @var{n} more random numbers using
! that value of @cite{M}.
@kindex k h
@pindex calcshuffle
 18788,18796 
@kindex k a
@pindex calcrandomagain
The @kbd{k a} (@code{calcrandomagain}) command produces another random
! number, reusing the most recent value of @expr{M}. With a numeric
prefix argument @var{n}, it produces @var{n} more random numbers using
! that value of @expr{M}.
@kindex k h
@pindex calcshuffle
***************
*** 18619,18630 ****
The @kbd{k h} (@code{calcshuffle}) command produces a vector of several
random values with no duplicates. The value on the top of the stack
specifies the set from which the random values are drawn, and may be any
! of the @cite{M} formats described above. The numeric prefix argument
gives the length of the desired list. (If you do not provide a numeric
prefix argument, the length of the list is taken from the top of the
! stack, and @cite{M} from secondtotop.)
! If @cite{M} is a floatingpoint number, zero, or an error form (so
that the random values are being drawn from the set of real numbers)
there is little practical difference between using @kbd{k h} and using
@kbd{k r} several times. But if the set of possible values consists
 18798,18809 
The @kbd{k h} (@code{calcshuffle}) command produces a vector of several
random values with no duplicates. The value on the top of the stack
specifies the set from which the random values are drawn, and may be any
! of the @expr{M} formats described above. The numeric prefix argument
gives the length of the desired list. (If you do not provide a numeric
prefix argument, the length of the list is taken from the top of the
! stack, and @expr{M} from secondtotop.)
! If @expr{M} is a floatingpoint number, zero, or an error form (so
that the random values are being drawn from the set of real numbers)
there is little practical difference between using @kbd{k h} and using
@kbd{k r} several times. But if the set of possible values consists
***************
*** 18632,18639 ****
a very real chance that multiple @kbd{k r}'s will produce the same
number more than once. The @kbd{k h} command produces a vector whose
elements are always distinct. (Actually, there is a slight exception:
! If @cite{M} is a vector, no given vector element will be drawn more
! than once, but if several elements of @cite{M} are equal, they may
each make it into the result vector.)
One use of @kbd{k h} is to rearrange a list at random. This happens
 18811,18818 
a very real chance that multiple @kbd{k r}'s will produce the same
number more than once. The @kbd{k h} command produces a vector whose
elements are always distinct. (Actually, there is a slight exception:
! If @expr{M} is a vector, no given vector element will be drawn more
! than once, but if several elements of @expr{M} are equal, they may
each make it into the result vector.)
One use of @kbd{k h} is to rearrange a list at random. This happens
***************
*** 18641,18652 ****
@kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list
@samp{[2.5, 1, 1.5, 3, 2]}. As a convenient feature, if the argument
@var{n} is negative it is replaced by the size of the set represented
! by @cite{M}. Naturally, this is allowed only when @cite{M} specifies
a small discrete set of possibilities.
To do the equivalent of @kbd{k h} but with duplications allowed,
! given @cite{M} on the stack and with @var{n} just entered as a numeric
! prefix, use @kbd{v b} to build a vector of copies of @cite{M}, then use
@kbd{V M k r} to ``map'' the normal @kbd{k r} function over the
elements of this vector. @xref{Matrix Functions}.
 18820,18831 
@kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list
@samp{[2.5, 1, 1.5, 3, 2]}. As a convenient feature, if the argument
@var{n} is negative it is replaced by the size of the set represented
! by @expr{M}. Naturally, this is allowed only when @expr{M} specifies
a small discrete set of possibilities.
To do the equivalent of @kbd{k h} but with duplications allowed,
! given @expr{M} on the stack and with @var{n} just entered as a numeric
! prefix, use @kbd{v b} to build a vector of copies of @expr{M}, then use
@kbd{V M k r} to ``map'' the normal @kbd{k r} function over the
elements of this vector. @xref{Matrix Functions}.
***************
*** 18683,18692 ****
If @code{RandSeed} contains an integer, Calc uses this integer to
seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A,
! computing @c{$X_{n55}  X_{n24}$}
! @cite{X_n55  X_n24}). This method expands the seed
value into a large table which is maintained internally; the variable
! @code{RandSeed} is changed from, e.g., 42 to the vector @cite{[42]}
to indicate that the seed has been absorbed into this table. When
@code{RandSeed} contains a vector, @kbd{k r} and related commands
continue to use the same internal table as last time. There is no
 18862,18873 
If @code{RandSeed} contains an integer, Calc uses this integer to
seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A,
! computing
! @texline @tmath{X_{n55}  X_{n24}}.
! @infoline @expr{X_n55  X_n24}).
! This method expands the seed
value into a large table which is maintained internally; the variable
! @code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]}
to indicate that the seed has been absorbed into this table. When
@code{RandSeed} contains a vector, @kbd{k r} and related commands
continue to use the same internal table as last time. There is no
***************
*** 18718,18733 ****
To create a random floatingpoint number with precision @var{p}, Calc
simply creates a random @var{p}digit integer and multiplies by
! @c{$10^{p}$}
! @cite{10^p}. The resulting random numbers should be very clean, but note
that relatively small numbers will have few significant random digits.
In other words, with a precision of 12, you will occasionally get
! numbers on the order of @c{$10^{9}$}
! @cite{10^9} or @c{$10^{10}$}
! @cite{10^10}, but those numbers
! will only have two or three random digits since they correspond to small
! integers times @c{$10^{12}$}
! @cite{10^12}.
To create a random integer in the interval @samp{[0 .. @var{m})}, Calc
counts the digits in @var{m}, creates a random integer with three
 18899,18919 
To create a random floatingpoint number with precision @var{p}, Calc
simply creates a random @var{p}digit integer and multiplies by
! @texline @tmath{10^{p}}.
! @infoline @expr{10^p}.
! The resulting random numbers should be very clean, but note
that relatively small numbers will have few significant random digits.
In other words, with a precision of 12, you will occasionally get
! numbers on the order of
! @texline @tmath{10^{9}}
! @infoline @expr{10^9}
! or
! @texline @tmath{10^{10}},
! @infoline @expr{10^10},
! but those numbers will only have two or three random digits since they
! correspond to small integers times
! @texline @tmath{10^{12}}.
! @infoline @expr{10^12}.
To create a random integer in the interval @samp{[0 .. @var{m})}, Calc
counts the digits in @var{m}, creates a random integer with three
***************
*** 18761,18767 ****
numerators, and the LCM of the denominators. This definition is
consistent with the idea that @samp{a / gcd(a,x)} should yield an
integer for any @samp{a} and @samp{x}. For other types of arguments,
! the operation is left in symbolic address@hidden
@kindex k l
@pindex calclcm
 18947,18953 
numerators, and the LCM of the denominators. This definition is
consistent with the idea that @samp{a / gcd(a,x)} should yield an
integer for any @samp{a} and @samp{x}. For other types of arguments,
! the operation is left in symbolic form.
@kindex k l
@pindex calclcm
***************
*** 18769,18783 ****
The @kbd{k l} (@code{calclcm}) address@hidden command computes the
Least Common Multiple of two integers or fractions. The product of
the LCM and GCD of two numbers is equal to the product of the
! address@hidden
@kindex k E
@pindex calcextendedgcd
@tindex egcd
The @kbd{k E} (@code{calcextendedgcd}) address@hidden command computes
! the GCD of two integers @cite{x} and @cite{y} and returns a vector
! @cite{[g, a, b]} where @c{$g = \gcd(x,y) = a x + b y$}
! @cite{g = gcd(x,y) = a x + b y}.
@kindex !
@pindex calcfactorial
 18955,18970 
The @kbd{k l} (@code{calclcm}) address@hidden command computes the
Least Common Multiple of two integers or fractions. The product of
the LCM and GCD of two numbers is equal to the product of the
! numbers.
@kindex k E
@pindex calcextendedgcd
@tindex egcd
The @kbd{k E} (@code{calcextendedgcd}) address@hidden command computes
! the GCD of two integers @expr{x} and @expr{y} and returns a vector
! @expr{[g, a, b]} where
! @texline @tmath{g = \gcd(x,y) = a x + b y}.
! @infoline @expr{g = gcd(x,y) = a x + b y}.
@kindex !
@pindex calcfactorial
***************
*** 18794,18800 ****
as defined by the Euler Gamma function. Please note that computation of
large factorials can be slow; using floatingpoint format will help
since fewer digits must be maintained. The same is true of many of
! the commands in this address@hidden
@kindex k d
@pindex calcdoublefactorial
 18981,18987 
as defined by the Euler Gamma function. Please note that computation of
large factorials can be slow; using floatingpoint format will help
since fewer digits must be maintained. The same is true of many of
! the commands in this section.
@kindex k d
@pindex calcdoublefactorial
***************
*** 18805,18833 ****
@tindex !!
The @kbd{k d} (@code{calcdoublefactorial}) address@hidden command
computes the ``double factorial'' of an integer. For an even integer,
! this is the product of even integers from 2 to @cite{N}. For an odd
! integer, this is the product of odd integers from 3 to @cite{N}. If
the argument is an integervalued float, the result is a floatingpoint
approximation. This function is undefined for negative even integers.
! The notation @cite{N!!} is also recognized for double address@hidden
@kindex k c
@pindex calcchoose
@tindex choose
The @kbd{k c} (@code{calcchoose}) address@hidden command computes the
! binomial coefficient @address@hidden, where @cite{M} is the number
! on the top of the stack and @cite{N} is secondtotop. If both arguments
are integers, the result is an exact integer. Otherwise, the result is a
floatingpoint approximation. The binomial coefficient is defined for all
! real numbers by @c{$N! \over M! (NM)!\,$}
! @cite{N! / M! (NM)!}.
@kindex H k c
@pindex calcperm
@tindex perm
@ifinfo
The @kbd{H k c} (@code{calcperm}) address@hidden command computes the
! numberofpermutations function @cite{N! / (NM)!}.
@end ifinfo
@tex
The \kbd{H k c} (\code{calcperm}) [\code{perm}] command computes the
 18992,19021 
@tindex !!
The @kbd{k d} (@code{calcdoublefactorial}) address@hidden command
computes the ``double factorial'' of an integer. For an even integer,
! this is the product of even integers from 2 to @expr{N}. For an odd
! integer, this is the product of odd integers from 3 to @expr{N}. If
the argument is an integervalued float, the result is a floatingpoint
approximation. This function is undefined for negative even integers.
! The notation @expr{N!!} is also recognized for double factorials.
@kindex k c
@pindex calcchoose
@tindex choose
The @kbd{k c} (@code{calcchoose}) address@hidden command computes the
! binomial coefficient @address@hidden, where @expr{M} is the number
! on the top of the stack and @expr{N} is secondtotop. If both arguments
are integers, the result is an exact integer. Otherwise, the result is a
floatingpoint approximation. The binomial coefficient is defined for all
! real numbers by
! @texline @tmath{N! \over M! (NM)!\,}.
! @infoline @expr{N! / M! (NM)!}.
@kindex H k c
@pindex calcperm
@tindex perm
@ifinfo
The @kbd{H k c} (@code{calcperm}) address@hidden command computes the
! numberofpermutations function @expr{N! / (NM)!}.
@end ifinfo
@tex
The \kbd{H k c} (\code{calcperm}) [\code{perm}] command computes the
***************
*** 18840,18850 ****
@tindex bern
The @kbd{k b} (@code{calcbernoullinumber}) address@hidden command
computes a given Bernoulli number. The value at the top of the stack
! is a nonnegative integer @cite{n} that specifies which Bernoulli number
is desired. The @kbd{H k b} command computes a Bernoulli polynomial,
! taking @cite{n} from the secondtotop position and @cite{x} from the
! top of the stack. If @cite{x} is a variable or formula the result is
! a polynomial in @cite{x}; if @cite{x} is a number the result is a number.
@kindex k e
@kindex H k e
 19028,19038 
@tindex bern
The @kbd{k b} (@code{calcbernoullinumber}) address@hidden command
computes a given Bernoulli number. The value at the top of the stack
! is a nonnegative integer @expr{n} that specifies which Bernoulli number
is desired. The @kbd{H k b} command computes a Bernoulli polynomial,
! taking @expr{n} from the secondtotop position and @expr{x} from the
! top of the stack. If @expr{x} is a variable or formula the result is
! a polynomial in @expr{x}; if @expr{x} is a number the result is a number.
@kindex k e
@kindex H k e
***************
*** 18861,18873 ****
@tindex stir1
@tindex stir2
The @kbd{k s} (@code{calcstirlingnumber}) address@hidden command
! computes a Stirling number of the first address@hidden $n \brack m$}
! @asis{}, given two integers
! @cite{n} and @cite{m} on the stack. The @kbd{H k s} address@hidden
! command computes a Stirling number of the second address@hidden $n \brace m$}
! @asis{}. These are
! the number of @cite{m}cycle permutations of @cite{n} objects, and
! the number of ways to partition @cite{n} objects into @cite{m}
nonempty sets, respectively.
@kindex k p
 19049,19063 
@tindex stir1
@tindex stir2
The @kbd{k s} (@code{calcstirlingnumber}) address@hidden command
! computes a Stirling number of the first
! @texline address@hidden@tmath{n \brack m},
! @infoline kind,
! given two integers @expr{n} and @expr{m} on the stack. The @kbd{H k s}
! address@hidden command computes a Stirling number of the second
! @texline address@hidden@tmath{n \brace m}.
! @infoline kind.
! These are the number of @expr{m}cycle permutations of @expr{n} objects,
! and the number of ways to partition @expr{n} objects into @expr{m}
nonempty sets, respectively.
@kindex k p
***************
*** 18895,18901 ****
test. Pressing @kbd{k p} repeatedly for the same integer will perform
additional iterations. Also, @kbd{k p} with a numeric prefix performs
the specified number of iterations. There is also an algebraic function
! @samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @cite{n}
is (probably) prime and 0 if not.
@kindex k f
 19085,19091 
test. Pressing @kbd{k p} repeatedly for the same integer will perform
additional iterations. Also, @kbd{k p} with a numeric prefix performs
the specified number of iterations. There is also an algebraic function
! @samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @expr{n}
is (probably) prime and 0 if not.
@kindex k f
***************
*** 18942,18958 ****
@pindex calctotient
@tindex totient
The @kbd{k t} (@code{calctotient}) address@hidden command computes the
! Euler ``totient'' address@hidden $\phi(n)$}
! @asis{}, the number of integers less than @cite{n} which
! are relatively prime to @cite{n}.
@kindex k m
@pindex calcmoebius
@tindex moebius
The @kbd{k m} (@code{calcmoebius}) address@hidden command computes the
! @c{M\"obius $\mu$}
! @asis{Moebius ``mu''} function. If the input number is a product of @cite{k}
! distinct factors, this is @cite{(1)^k}. If the input number has any
duplicate factors (i.e., can be divided by the same prime more than once),
the result is zero.
 19132,19151 
@pindex calctotient
@tindex totient
The @kbd{k t} (@code{calctotient}) address@hidden command computes the
! Euler ``totient''
! @texline address@hidden@tmath{\phi(n)},
! @infoline function,
! the number of integers less than @expr{n} which
! are relatively prime to @expr{n}.
@kindex k m
@pindex calcmoebius
@tindex moebius
The @kbd{k m} (@code{calcmoebius}) address@hidden command computes the
! @texline M@"obius @tmath{\mu}
! @infoline Moebius ``mu''
! function. If the input number is a product of @expr{k}
! distinct factors, this is @expr{(1)^k}. If the input number has any
duplicate factors (i.e., can be divided by the same prime more than once),
the result is zero.
***************
*** 18962,18975 ****
@noindent
The functions in this section compute various probability distributions.
For continuous distributions, this is the integral of the probability
! density function from @cite{x} to infinity. (These are the ``upper
tail'' distribution functions; there are also corresponding ``lower
! tail'' functions which integrate from minus infinity to @cite{x}.)
For discrete distributions, the upper tail function gives the sum
! from @cite{x} to infinity; the lower tail function gives the sum
! from minus infinity up to, but not including,@w{ address@hidden
! To integrate from @cite{x} to @cite{y}, just use the distribution
function twice and subtract. For example, the probability that a
Gaussian random variable with mean 2 and standard deviation 1 will
lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1)  utpn(2.8,2,1)}
 19155,19168 
@noindent
The functions in this section compute various probability distributions.
For continuous distributions, this is the integral of the probability
! density function from @expr{x} to infinity. (These are the ``upper
tail'' distribution functions; there are also corresponding ``lower
! tail'' functions which integrate from minus infinity to @expr{x}.)
For discrete distributions, the upper tail function gives the sum
! from @expr{x} to infinity; the lower tail function gives the sum
! from minus infinity up to, but not including,@w{ address@hidden
! To integrate from @expr{x} to @expr{y}, just use the distribution
function twice and subtract. For example, the probability that a
Gaussian random variable with mean 2 and standard deviation 1 will
lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1)  utpn(2.8,2,1)}
***************
*** 18999,19005 ****
arguments as found on the stack. (The random variable comes last on
the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5
k N address@hidden @key{DEL} 2.8 k N }, using @address@hidden @key{DEL}} to
! recover the original arguments but substitute a new value for @cite{x}.)
@kindex k C
@pindex calcutpc
 19192,19198 
arguments as found on the stack. (The random variable comes last on
the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5
k N address@hidden @key{DEL} 2.8 k N }, using @address@hidden @key{DEL}} to
! recover the original arguments but substitute a new value for @expr{x}.)
@kindex k C
@pindex calcutpc
***************
*** 19013,19021 ****
@end ignore
@tindex ltpc
The @samp{utpc(x,v)} function uses the chisquare distribution with
! @c{$\nu$}
! @cite{v} degrees of freedom. It is the probability that a model is
! correct if its chisquare statistic is @cite{x}.
@kindex k F
@pindex calcutpf
 19206,19215 
@end ignore
@tindex ltpc
The @samp{utpc(x,v)} function uses the chisquare distribution with
! @texline @tmath{\nu}
! @infoline @expr{v}
! degrees of freedom. It is the probability that a model is
! correct if its chisquare statistic is @expr{x}.
@kindex k F
@pindex calcutpf
***************
*** 19029,19039 ****
@end ignore
@tindex ltpf
The @samp{utpf(F,v1,v2)} function uses the F distribution, used in
! various statistical tests. The parameters @c{$\nu_1$}
! @cite{v1} and @c{$\nu_2$}
! @cite{v2}
are the degrees of freedom in the numerator and denominator,
! respectively, used in computing the statistic @cite{F}.
@kindex k N
@pindex calcutpn
 19223,19236 
@end ignore
@tindex ltpf
The @samp{utpf(F,v1,v2)} function uses the F distribution, used in
! various statistical tests. The parameters
! @texline @tmath{\nu_1}
! @infoline @expr{v1}
! and
! @texline @tmath{\nu_2}
! @infoline @expr{v2}
are the degrees of freedom in the numerator and denominator,
! respectively, used in computing the statistic @expr{F}.
@kindex k N
@pindex calcutpn
***************
*** 19047,19056 ****
@end ignore
@tindex ltpn
The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution
! with mean @cite{m} and standard deviation @c{$\sigma$}
! @cite{s}. It is the
! probability that such a normaldistributed random variable would
! exceed @cite{x}.
@kindex k P
@pindex calcutpp
 19244,19254 
@end ignore
@tindex ltpn
The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution
! with mean @expr{m} and standard deviation
! @texline @tmath{\sigma}.
! @infoline @expr{s}.
! It is the probability that such a normaldistributed random variable
! would exceed @expr{x}.
@kindex k P
@pindex calcutpp
***************
*** 19064,19070 ****
@end ignore
@tindex ltpp
The @samp{utpp(n,x)} function uses a Poisson distribution with
! mean @cite{x}. It is the probability that @cite{n} or more such
Poisson random events will occur.
@kindex k T
 19262,19268 
@end ignore
@tindex ltpp
The @samp{utpp(n,x)} function uses a Poisson distribution with
! mean @expr{x}. It is the probability that @expr{n} or more such
Poisson random events will occur.
@kindex k T
***************
*** 19079,19094 ****
@end ignore
@tindex ltpt
The @samp{utpt(t,v)} function uses the Student's ``t'' distribution
! with @c{$\nu$}
! @cite{v} degrees of freedom. It is the probability that a
! tdistributed random variable will be greater than @cite{t}.
! (Note: This computes the distribution function @c{$A(t\nu)$}
! @cite{A(tv)}
! where @c{$A(0\nu) = 1$}
! @cite{A(0v) = 1} and @c{$A(\infty\nu) \to 0$}
! @cite{A(infv) > 0}. The
! @code{UTPT} operation on the HP48 uses a different definition
! which returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.)
While Calc does not provide inverses of the probability distribution
functions, the @kbd{a R} command can be used to solve for the inverse.
 19277,19298 
@end ignore
@tindex ltpt
The @samp{utpt(t,v)} function uses the Student's ``t'' distribution
! with
! @texline @tmath{\nu}
! @infoline @expr{v}
! degrees of freedom. It is the probability that a
! tdistributed random variable will be greater than @expr{t}.
! (Note: This computes the distribution function
! @texline @tmath{A(t\nu)}
! @infoline @expr{A(tv)}
! where
! @texline @tmath{A(0\nu) = 1}
! @infoline @expr{A(0v) = 1}
! and
! @texline @tmath{A(\infty\nu) \to 0}.
! @infoline @expr{A(infv) > 0}.
! The @code{UTPT} operation on the HP48 uses a different definition which
! returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.)
While Calc does not provide inverses of the probability distribution
functions, the @kbd{a R} command can be used to solve for the inverse.
***************
*** 19155,19161 ****
@item 1
Two values are collected to build a complex number. For example,
@kbd{5 @key{RET} 7 Cu 1 v p} creates the complex number
! @cite{(5, 7)}. The result is always a rectangular complex
number. The two input values must both be real numbers,
i.e., integers, fractions, or floats. If they are not, Calc
will instead build a formula like @samp{a + (0, 1) b}. (The
 19359,19365 
@item 1
Two values are collected to build a complex number. For example,
@kbd{5 @key{RET} 7 Cu 1 v p} creates the complex number
! @expr{(5, 7)}. The result is always a rectangular complex
number. The two input values must both be real numbers,
i.e., integers, fractions, or floats. If they are not, Calc
will instead build a formula like @samp{a + (0, 1) b}. (The
***************
*** 19245,19252 ****
If any elements of the vector are negative, other kinds of
packing are done at that level as described above. For
example, @samp{[2, 3, 4]} takes 12 objects and creates a
! @c{$2\times3$}
! @asis{2x3} matrix of error forms: @samp{[[a +/ b, c +/ d ... ]]}.
Also, @samp{[4, 10]} will convert four integers into an
error form consisting of two fractions: @samp{a:b +/ c:d}.
 19449,19457 
If any elements of the vector are negative, other kinds of
packing are done at that level as described above. For
example, @samp{[2, 3, 4]} takes 12 objects and creates a
! @texline @tmath{2\times3}
! @infoline 2x3
! matrix of error forms: @samp{[[a +/ b, c +/ d ... ]]}.
Also, @samp{[4, 10]} will convert four integers into an
error form consisting of two fractions: @samp{a:b +/ c:d}.
***************
*** 19346,19352 ****
@noindent
Vectors and matrices can be added,
! subtracted, multiplied, and divided; @pxref{Basic address@hidden
@kindex 
@pindex calcconcat
 19551,19557 
@noindent
Vectors and matrices can be added,
! subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.
@kindex 
@pindex calcconcat
***************
*** 19392,19402 ****
the stack is a scalar, it is used for each element on the diagonal, and
the prefix argument is required.
! To build a constant square matrix, e.g., a @c{$3\times3$}
! @asis{3x3} matrix filled with ones,
! use @kbd{0 M3 v d 1 +}, i.e., build a zero matrix first and then add a
! constant value to that matrix. (Another alternative would be to use
! @kbd{v b} and @kbd{v a}; see below.)
@kindex v i
@pindex calcident
 19597,19608 
the stack is a scalar, it is used for each element on the diagonal, and
the prefix argument is required.
! To build a constant square matrix, e.g., a
! @texline @tmath{3\times3}
! @infoline 3x3
! matrix filled with ones, use @kbd{0 M3 v d 1 +}, i.e., build a zero
! matrix first and then add a constant value to that matrix. (Another
! alternative would be to use @kbd{v b} and @kbd{v a}; see below.)
@kindex v i
@pindex calcident
***************
*** 19407,19414 ****
this command prompts for one.
In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)},
! except that @cite{a} is required to be a scalar (nonvector) quantity.
! If @cite{n} is omitted, @samp{idn(a)} represents @cite{a} times an
identity matrix of unknown size. Calc can operate algebraically on
such generic identity matrices, and if one is combined with a matrix
whose size is known, it is converted automatically to an identity
 19613,19620 
this command prompts for one.
In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)},
! except that @expr{a} is required to be a scalar (nonvector) quantity.
! If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an
identity matrix of unknown size. Calc can operate algebraically on
such generic identity matrices, and if one is combined with a matrix
whose size is known, it is converted automatically to an identity
***************
*** 19531,19540 ****
@tindex _
Subscript notation in algebraic formulas (@samp{a_b}) stands for the
Calc function @code{subscr}, which is synonymous with @code{mrow}.
! Thus, @samp{[x, y, z]_k} produces @cite{x}, @cite{y}, or @cite{z} if
! @cite{k} is one, two, or three, respectively. A double subscript
(@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will
! access the element at row @cite{i}, column @cite{j} of a matrix.
The @kbd{a _} (@code{calcsubscript}) command creates a subscript
formula @samp{a_b} out of two stack entries. (It is on the @kbd{a}
``algebra'' prefix because subscripted variables are often used
 19737,19746 
@tindex _
Subscript notation in algebraic formulas (@samp{a_b}) stands for the
Calc function @code{subscr}, which is synonymous with @code{mrow}.
! Thus, @samp{[x, y, z]_k} produces @expr{x}, @expr{y}, or @expr{z} if
! @expr{k} is one, two, or three, respectively. A double subscript
(@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will
! access the element at row @expr{i}, column @expr{j} of a matrix.
The @kbd{a _} (@code{calcsubscript}) command creates a subscript
formula @samp{a_b} out of two stack entries. (It is on the @kbd{a}
``algebra'' prefix because subscripted variables are often used
***************
*** 19561,19573 ****
it extracts (or removes) one element, just like @kbd{v r}. If the
index in @kbd{Cu v c} is an interval or vector and the argument is a
matrix, the result is a submatrix with only the specified columns
! retained (and possibly permuted in the case of a vector index)address@hidden
To extract a matrix element at a given row and column, use @kbd{v r} to
extract the row as a vector, then @kbd{v c} to extract the column element
from that vector. In algebraic formulas, it is often more convenient to
! use subscript notation: @samp{m_i_j} gives row @cite{i}, column @cite{j}
! of matrix @cite{m}.
@kindex v s
@pindex calcsubvector
 19767,19779 
it extracts (or removes) one element, just like @kbd{v r}. If the
index in @kbd{Cu v c} is an interval or vector and the argument is a
matrix, the result is a submatrix with only the specified columns
! retained (and possibly permuted in the case of a vector index).
To extract a matrix element at a given row and column, use @kbd{v r} to
extract the row as a vector, then @kbd{v c} to extract the column element
from that vector. In algebraic formulas, it is often more convenient to
! use subscript notation: @samp{m_i_j} gives row @expr{i}, column @expr{j}
! of matrix @expr{m}.
@kindex v s
@pindex calcsubvector
***************
*** 19610,19624 ****
The @kbd{v l} (@code{calcvlength}) address@hidden command computes the
length of a vector. The length of a nonvector is considered to be zero.
Note that matrices are just vectors of vectors for the purposes of this
! address@hidden
@kindex H v l
@tindex mdims
With the Hyperbolic flag, @kbd{H v l} address@hidden computes a vector
of the dimensions of a vector, matrix, or higherorder object. For
example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since
! its argument is a @c{$2\times3$}
! @asis{2x3} matrix.
@kindex v f
@pindex calcvectorfind
 19816,19832 
The @kbd{v l} (@code{calcvlength}) address@hidden command computes the
length of a vector. The length of a nonvector is considered to be zero.
Note that matrices are just vectors of vectors for the purposes of this
! command.
@kindex H v l
@tindex mdims
With the Hyperbolic flag, @kbd{H v l} address@hidden computes a vector
of the dimensions of a vector, matrix, or higherorder object. For
example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since
! its argument is a
! @texline @tmath{2\times3}
! @infoline 2x3
! matrix.
@kindex v f
@pindex calcvectorfind
***************
*** 19647,19660 ****
in the vector, the last row will be short and the result will not be
suitable for use as a matrix. For example, with the matrix
@samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces
! @samp{[[1, 2, 3, 4]]} (a @c{$1\times4$}
! @asis{1x4} matrix), @kbd{v a 1} produces
! @samp{[[1], [2], [3], [4]]} (a @c{$4\times1$}
! @asis{4x1} matrix), @kbd{v a 2} produces
! @samp{[[1, 2], [3, 4]]} (the original @c{$2\times2$}
! @asis{2x2} matrix), @address@hidden a 3}} produces
! @samp{[[1, 2, 3], [4]]} (not a matrix), and @kbd{v a 0} produces
! the flattened list @samp{[1, 2, @w{3, 4}]}.
@cindex Sorting data
@kindex V S
 19855,19872 
in the vector, the last row will be short and the result will not be
suitable for use as a matrix. For example, with the matrix
@samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces
! @samp{[[1, 2, 3, 4]]} (a
! @texline @tmath{1\times4}
! @infoline 1x4
! matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a
! @texline @tmath{4\times1}
! @infoline 4x1
! matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original
! @texline @tmath{2\times2}
! @infoline 2x2
! matrix), @address@hidden a 3}} produces @samp{[[1, 2, 3], [4]]} (not a
! matrix), and @kbd{v a 0} produces the flattened list
! @samp{[1, 2, @w{3, 4}]}.
@cindex Sorting data
@kindex V S
***************
*** 19810,19816 ****
The following functions are applied elementwise if their arguments are
vectors or matrices: @code{changesign}, @code{conj}, @code{arg},
@code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean},
! @code{float}, @code{frac}. @xref{Function address@hidden
@kindex V J
@pindex calcconjtranspose
 20022,20028 
The following functions are applied elementwise if their arguments are
vectors or matrices: @code{changesign}, @code{conj}, @code{arg},
@code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean},
! @code{float}, @code{frac}. @xref{Function Index}.
@kindex V J
@pindex calcconjtranspose
***************
*** 19832,19838 ****
root of the sum of the squares of the absolute values of the
elements of the vector or matrix. If the vector is interpreted as
a point in two or threedimensional space, this is the distance
! from that point to the address@hidden
@kindex v n
@pindex calcrnorm
 20044,20050 
root of the sum of the squares of the absolute values of the
elements of the vector or matrix. If the vector is interpreted as
a point in two or threedimensional space, this is the distance
! from that point to the origin.
@kindex v n
@pindex calcrnorm
***************
*** 19851,19857 ****
the column norm, or onenorm, of a vector or matrix. For a plain
vector, this is the sum of the absolute values of the elements.
For a matrix, this is the maximum of the columnabsolutevaluesums.
! General @cite{k}norms for @cite{k} other than one or infinity are
not provided.
@kindex V C
 20063,20069 
the column norm, or onenorm, of a vector or matrix. For a plain
vector, this is the sum of the absolute values of the elements.
For a matrix, this is the maximum of the columnabsolutevaluesums.
! General @expr{k}norms for @expr{k} other than one or infinity are
not provided.
@kindex V C
***************
*** 19877,19884 ****
computed, the inverse and determinant of the matrix can be recomputed
quickly in the future.
! If the argument to @kbd{&} is a plain number @cite{x}, this
! command simply computes @cite{1/x}. This is okay, because the
@samp{/} operator also does a matrix inversion when dividing one
by a matrix.
 20089,20096 
computed, the inverse and determinant of the matrix can be recomputed
quickly in the future.
! If the argument to @kbd{&} is a plain number @expr{x}, this
! command simply computes @expr{1/x}. This is okay, because the
@samp{/} operator also does a matrix inversion when dividing one
by a matrix.
***************
*** 19936,19943 ****
single interval, the interval itself is returned instead.
@xref{Logical Operations}, for the @code{in} function which tests if
! a certain value is a member of a given set. To test if the set @cite{A}
! is a subset of the set @cite{B}, use @samp{vdiff(A, B) = []}.
@kindex V +
@pindex calcremoveduplicates
 20148,20155 
single interval, the interval itself is returned instead.
@xref{Logical Operations}, for the @code{in} function which tests if
! a certain value is a member of a given set. To test if the set @expr{A}
! is a subset of the set @expr{B}, use @samp{vdiff(A, B) = []}.
@kindex V +
@pindex calcremoveduplicates
***************
*** 19969,19988 ****
sets are disjoint, i.e., if they share no common elements, the result
will be the empty vector @samp{[]}. Note that the characters @kbd{V}
and @kbd{^} were chosen to be close to the conventional mathematical
! notation for set address@hidden ($A \cup B$)}
! @asis{} and address@hidden ($A \cap B$)}
! @asis{}.
@kindex V 
@pindex calcsetdifference
@tindex vdiff
The @kbd{V } (@code{calcsetdifference}) address@hidden command computes
the difference between two sets. An object is in the difference
! @cite{A  B} if and only if it is in @cite{A} but not in @cite{B}.
Thus subtracting @samp{[y,z]} from a set will remove the elements
@samp{y} and @samp{z} if they are present. You can also think of this
! as a general @dfn{set complement} operator; if @cite{A} is the set of
! all possible values, then @cite{A  B} is the ``complement'' of @cite{B}.
Obviously this is only practical if the set of all possible values in
your problem is small enough to list in a Calc vector (or simple
enough to express in a few intervals).
 20181,20203 
sets are disjoint, i.e., if they share no common elements, the result
will be the empty vector @samp{[]}. Note that the characters @kbd{V}
and @kbd{^} were chosen to be close to the conventional mathematical
! notation for set
! @texline address@hidden(@tmath{A \cup B})
! @infoline union
! and
! @texline address@hidden(@tmath{A \cap B}).
! @infoline intersection.
@kindex V 
@pindex calcsetdifference
@tindex vdiff
The @kbd{V } (@code{calcsetdifference}) address@hidden command computes
the difference between two sets. An object is in the difference
! @expr{A  B} if and only if it is in @expr{A} but not in @expr{B}.
Thus subtracting @samp{[y,z]} from a set will remove the elements
@samp{y} and @samp{z} if they are present. You can also think of this
! as a general @dfn{set complement} operator; if @expr{A} is the set of
! all possible values, then @expr{A  B} is the ``complement'' of @expr{B}.
Obviously this is only practical if the set of all possible values in
your problem is small enough to list in a Calc vector (or simple
enough to express in a few intervals).
***************
*** 20078,20085 ****
not include any negative numbers. The input is interpreted as a
set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware
that a simple input like @samp{[100]} can result in a huge integer
! representation (@c{$2^{100}$}
! @cite{2^100}, a 31digit integer, in this case).
@node Statistical Operations, Reducing and Mapping, Set Operations, Matrix
Functions
@section Statistical Operations on Vectors
 20293,20301 
not include any negative numbers. The input is interpreted as a
set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware
that a simple input like @samp{[100]} can result in a huge integer
! representation
! @texline (@tmath{2^{100}}, a 31digit integer, in this case).
! @infoline (@expr{2^100}, a 31digit integer, in this case).
@node Statistical Operations, Reducing and Mapping, Set Operations, Matrix
Functions
@section Statistical Operations on Vectors
***************
*** 20167,20173 ****
(@code{calcvectorprod}) address@hidden command computes the
product of the data values. If the input is a single flat vector,
these are the same as @kbd{V R +} and @kbd{V R *}
! (@pxref{Reducing and Mapping})address@hidden
@kindex u X
@kindex u N
 20383,20389 
(@code{calcvectorprod}) address@hidden command computes the
product of the data values. If the input is a single flat vector,
these are the same as @kbd{V R +} and @kbd{V R *}
! (@pxref{Reducing and Mapping}).
@kindex u X
@kindex u N
***************
*** 20189,20209 ****
@cindex Mean of data values
The @kbd{u M} (@code{calcvectormean}) address@hidden command
computes the average (arithmetic mean) of the data values.
! If the inputs are error forms @c{$x$ @code{+/} $\sigma$}
! @samp{x +/ s}, this is the weighted
! mean of the @cite{x} values with weights @c{$1 / \sigma^2$}
! @cite{1 / s^2}.
@tex
\turnoffactive
$$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over
\displaystyle \sum { 1 \over \sigma_i^2 } } $$
@end tex
If the inputs are not error forms, this is simply the sum of the
! values divided by the count of the address@hidden
Note that a plain number can be considered an error form with
! error @c{$\sigma = 0$}
! @cite{s = 0}. If the input to @kbd{u M} is a mixture of
plain numbers and error forms, the result is the mean of the
plain numbers, ignoring all values with nonzero errors. (By the
above definitions it's clear that a plain number effectively
 20405,20429 
@cindex Mean of data values
The @kbd{u M} (@code{calcvectormean}) address@hidden command
computes the average (arithmetic mean) of the data values.
! If the inputs are error forms
! @texline @tmath{x \pm \sigma},
! @infoline @samp{x +/ s},
! this is the weighted mean of the @expr{x} values with weights
! @texline @tmath{1 /\sigma^2}.
! @infoline @expr{1 / s^2}.
@tex
\turnoffactive
$$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over
\displaystyle \sum { 1 \over \sigma_i^2 } } $$
@end tex
If the inputs are not error forms, this is simply the sum of the
! values divided by the count of the values.
Note that a plain number can be considered an error form with
! error
! @texline @tmath{\sigma = 0}.
! @infoline @expr{s = 0}.
! If the input to @kbd{u M} is a mixture of
plain numbers and error forms, the result is the mean of the
plain numbers, ignoring all values with nonzero errors. (By the
above definitions it's clear that a plain number effectively
***************
*** 20212,20218 ****
This function also works for distributions (error forms or
intervals). The mean of an error form address@hidden @t{+/} @var{b}' is
simply
! @cite{a}. The mean of an interval is the mean of the minimum
and maximum values of the interval.
@kindex I u M
 20432,20438 
This function also works for distributions (error forms or
intervals). The mean of an error form address@hidden @t{+/} @var{b}' is
simply
! @expr{a}. The mean of an interval is the mean of the minimum
and maximum values of the interval.
@kindex I u M
***************
*** 20234,20240 ****
divided by the square root of the number of values. (This works
out to be equivalent to calculating the standard deviation and
then assuming each value's error is equal to this standard
! deviation.)@refill
@tex
\turnoffactive
$$ \sigma_\mu^2 = {\sigma^2 \over N} $$
 20454,20460 
divided by the square root of the number of values. (This works
out to be equivalent to calculating the standard deviation and
then assuming each value's error is equal to this standard
! deviation.)
@tex
\turnoffactive
$$ \sigma_\mu^2 = {\sigma^2 \over N} $$
***************
*** 20309,20321 ****
@cindex Standard deviation
@cindex Sample statistics
The @kbd{u S} (@code{calcvectorsdev}) address@hidden command
! computes the standard address@hidden $\sigma$}
! @asis{} of the data values. If the
! values are error forms, the errors are used as weights just
! as for @kbd{u M}. This is the @emph{sample} standard deviation,
! whose value is the square root of the sum of the squares of the
! differences between the values and the mean of the @cite{N} values,
! divided by @cite{N1}.
@tex
\turnoffactive
$$ \sigma^2 = {1 \over N  1} \sum (x_i  \mu)^2 $$
 20529,20542 
@cindex Standard deviation
@cindex Sample statistics
The @kbd{u S} (@code{calcvectorsdev}) address@hidden command
! computes the standard
! @texline address@hidden@tmath{\sigma}
! @infoline deviation
! of the data values. If the values are error forms, the errors are used
! as weights just as for @kbd{u M}. This is the @emph{sample} standard
! deviation, whose value is the square root of the sum of the squares of
! the differences between the values and the mean of the @expr{N} values,
! divided by @expr{N1}.
@tex
\turnoffactive
$$ \sigma^2 = {1 \over N  1} \sum (x_i  \mu)^2 $$
***************
*** 20324,20333 ****
This function also applies to distributions. The standard deviation
of a single error form is simply the error part. The standard deviation
of a continuous interval happens to equal the difference between the
! limits, divided by @c{$\sqrt{12}$}
! @cite{sqrt(12)}. The standard deviation of an
! integer interval is the same as the standard deviation of a vector
! of those integers.
@kindex I u S
@pindex calcvectorpopsdev
 20545,20555 
This function also applies to distributions. The standard deviation
of a single error form is simply the error part. The standard deviation
of a continuous interval happens to equal the difference between the
! limits, divided by
! @texline @tmath{\sqrt{12}}.
! @infoline @expr{sqrt(12)}.
! The standard deviation of an integer interval is the same as the
! standard deviation of a vector of those integers.
@kindex I u S
@pindex calcvectorpopsdev
***************
*** 20336,20342 ****
The @kbd{I u S} (@code{calcvectorpopsdev}) address@hidden
command computes the @emph{population} standard deviation.
It is defined by the same formula as above but dividing
! by @cite{N} instead of by @cite{N1}. The population standard
deviation is used when the input represents the entire set of
data values in the distribution; the sample standard deviation
is used when the input represents a sample of the set of all
 20558,20564 
The @kbd{I u S} (@code{calcvectorpopsdev}) address@hidden
command computes the @emph{population} standard deviation.
It is defined by the same formula as above but dividing
! by @expr{N} instead of by @expr{N1}. The population standard
deviation is used when the input represents the entire set of
data values in the distribution; the sample standard deviation
is used when the input represents a sample of the set of all
***************
*** 20361,20368 ****
The @kbd{H u S} (@code{calcvectorvariance}) address@hidden and
@kbd{H I u S} (@code{calcvectorpopvariance}) address@hidden
commands compute the variance of the data values. The variance
! is the address@hidden $\sigma^2$}
! @asis{} of the standard deviation, i.e., the sum of the
squares of the deviations of the data values from the mean.
(This definition also applies when the argument is a distribution.)
 20583,20592 
The @kbd{H u S} (@code{calcvectorvariance}) address@hidden and
@kbd{H I u S} (@code{calcvectorpopvariance}) address@hidden
commands compute the variance of the data values. The variance
! is the
! @texline address@hidden@tmath{\sigma^2}
! @infoline square
! of the standard deviation, i.e., the sum of the
squares of the deviations of the data values from the mean.
(This definition also applies when the argument is a distribution.)
***************
*** 20383,20392 ****
vectors of equal size. The vectors are each flattened in the same
way as by the singlevariable statistical functions. Given a numeric
prefix argument of 1, these functions instead take one object from
! the stack, which must be an @c{$N\times2$}
! @asis{Nx2} matrix of data values. Once
! again, variable names can be used in place of actual vectors and
! matrices.
@kindex u C
@pindex calcvectorcovariance
 20607,20617 
vectors of equal size. The vectors are each flattened in the same
way as by the singlevariable statistical functions. Given a numeric
prefix argument of 1, these functions instead take one object from
! the stack, which must be an
! @texline @tmath{N\times2}
! @infoline Nx2
! matrix of data values. Once again, variable names can be used in place
! of actual vectors and matrices.
@kindex u C
@pindex calcvectorcovariance
***************
*** 20397,20403 ****
of vectors @var{x} and @var{y} is the sum of the products of the
differences between the elements of @var{x} and the mean of @var{x}
times the differences between the corresponding elements of @var{y}
! and the mean of @var{y}, all divided by @cite{N1}. Note that
the variance of a vector is just the covariance of the vector
with itself. Once again, if the inputs are error forms the
errors are used as weight factors. If both @var{x} and @var{y}
 20622,20628 
of vectors @var{x} and @var{y} is the sum of the products of the
differences between the elements of @var{x} and the mean of @var{x}
times the differences between the corresponding elements of @var{y}
! and the mean of @var{y}, all divided by @expr{N1}. Note that
the variance of a vector is just the covariance of the vector
with itself. Once again, if the inputs are error forms the
errors are used as weight factors. If both @var{x} and @var{y}
***************
*** 20419,20426 ****
@tindex vpcov
The @kbd{I u C} (@code{calcvectorpopcovariance}) address@hidden
command computes the population covariance, which is the same as the
! sample covariance computed by @kbd{u C} except dividing by @cite{N}
! instead of @cite{N1}.
@kindex H u C
@pindex calcvectorcorrelation
 20644,20651 
@tindex vpcov
The @kbd{I u C} (@code{calcvectorpopcovariance}) address@hidden
command computes the population covariance, which is the same as the
! sample covariance computed by @kbd{u C} except dividing by @expr{N}
! instead of @expr{N1}.
@kindex H u C
@pindex calcvectorcorrelation
***************
*** 20598,20604 ****
or a nameless function like @samp{<#^3+1>}. Operators that are normally
written as algebraic symbols have the names @code{add}, @code{sub},
@code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and
! @address@hidden
@ignore
@starindex
 20823,20829 
or a nameless function like @samp{<#^3+1>}. Operators that are normally
written as algebraic symbols have the names @code{add}, @code{sub},
@code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and
! @code{vconcat}.
@ignore
@starindex
***************
*** 20635,20658 ****
With the 2 listed first, it would have computed a vector of powers of
two. Mapping a userdefined function pops as many arguments from the
stack as the function requires. If you give an undefined name, you will
! be prompted for the number of arguments to address@hidden
If any argument to @kbd{V M} is a matrix, the operator is normally mapped
across all elements of the matrix. For example, given the matrix
! @cite{[[1, 2, 3], [4, 5, 6]]}, @kbd{V M A} takes six absolute values to
! produce another @c{$3\times2$}
! @asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}.
@tindex mapr
The command @kbd{V M _} address@hidden (i.e., type an underscore at the
operator prompt) maps by rows instead. For example, @kbd{V M _ A} views
the above matrix as a vector of two 3element row vectors. It produces
a new vector which contains the absolute values of those row vectors,
! namely @cite{[3.74, 8.77]}. (Recall, the absolute value of a vector is
defined as the square root of the sum of the squares of the elements.)
Some operators accept vectors and return new vectors; for example,
@kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row
! of the matrix to get a new matrix, @cite{[[3, 2, 1], [6, 5, 4]]}.
Sometimes a vector of vectors (representing, say, strings, sets, or lists)
happens to look like a matrix. If so, remember to use @kbd{V M _} if you
 20860,20885 
With the 2 listed first, it would have computed a vector of powers of
two. Mapping a userdefined function pops as many arguments from the
stack as the function requires. If you give an undefined name, you will
! be prompted for the number of arguments to use.
If any argument to @kbd{V M} is a matrix, the operator is normally mapped
across all elements of the matrix. For example, given the matrix
! @expr{[[1, 2, 3], [4, 5, 6]]}, @kbd{V M A} takes six absolute values to
! produce another
! @texline @tmath{3\times2}
! @infoline 3x2
! matrix, @expr{[[1, 2, 3], [4, 5, 6]]}.
@tindex mapr
The command @kbd{V M _} address@hidden (i.e., type an underscore at the
operator prompt) maps by rows instead. For example, @kbd{V M _ A} views
the above matrix as a vector of two 3element row vectors. It produces
a new vector which contains the absolute values of those row vectors,
! namely @expr{[3.74, 8.77]}. (Recall, the absolute value of a vector is
defined as the square root of the sum of the squares of the elements.)
Some operators accept vectors and return new vectors; for example,
@kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row
! of the matrix to get a new matrix, @expr{[[3, 2, 1], [6, 5, 4]]}.
Sometimes a vector of vectors (representing, say, strings, sets, or lists)
happens to look like a matrix. If so, remember to use @kbd{V M _} if you
***************
*** 20665,20671 ****
matrix, transposes again. For example, @kbd{V M : A} takes the absolute
values of the three columns of the matrix, treating each as a 2vector,
and @kbd{V M : v v} reverses the columns to get the matrix
! @cite{[[4, 5, 6], [1, 2, 3]]}.
(The symbols @kbd{_} and @kbd{:} were chosen because they had rowlike
and columnlike appearances, and were not already taken by useful
 20892,20898 
matrix, transposes again. For example, @kbd{V M : A} takes the absolute
values of the three columns of the matrix, treating each as a 2vector,
and @kbd{V M : v v} reverses the columns to get the matrix
! @expr{[[4, 5, 6], [1, 2, 3]]}.
(The symbols @kbd{_} and @kbd{:} were chosen because they had rowlike
and columnlike appearances, and were not already taken by useful
***************
*** 20756,20768 ****
@tindex reduced
@tindex rreduced
As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For
! example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will
! compute @cite{a + b + c + d + e + f}. You can type @kbd{V R _} or
@kbd{V R :} to modify this behavior. The @kbd{V R _} address@hidden
command reduces ``across'' the matrix; it reduces each row of the matrix
as a vector, then collects the results. Thus @kbd{V R _ +} of this
! matrix would produce @cite{[a + b + c, d + e + f]}. Similarly, @kbd{V R :}
! address@hidden reduces down; @kbd{V R : +} would produce @cite{[a + d,
b + e, c + f]}.
@tindex reducer
 20983,20995 
@tindex reduced
@tindex rreduced
As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For
! example, given the matrix @expr{[[a, b, c], [d, e, f]]}, @kbd{V R +} will
! compute @expr{a + b + c + d + e + f}. You can type @kbd{V R _} or
@kbd{V R :} to modify this behavior. The @kbd{V R _} address@hidden
command reduces ``across'' the matrix; it reduces each row of the matrix
as a vector, then collects the results. Thus @kbd{V R _ +} of this
! matrix would produce @expr{[a + b + c, d + e + f]}. Similarly, @kbd{V R :}
! address@hidden reduces down; @kbd{V R : +} would produce @expr{[a + d,
b + e, c + f]}.
@tindex reducer
***************
*** 20919,20925 ****
The commands @kbd{v <} (@code{calcmatrixleftjustify}), @kbd{v >}
(@code{calcmatrixrightjustify}), and @address@hidden =}}
(@code{calcmatrixcenterjustify}) control whether matrix elements
! are justified to the left, right, or center of their address@hidden
@kindex V [
@pindex calcvectorbrackets
 21146,21152 
The commands @kbd{v <} (@code{calcmatrixleftjustify}), @kbd{v >}
(@code{calcmatrixrightjustify}), and @address@hidden =}}
(@code{calcmatrixcenterjustify}) control whether matrix elements
! are justified to the left, right, or center of their columns.
@kindex V [
@pindex calcvectorbrackets
***************
*** 20936,20942 ****
Mathematica. (In fact, the Mathematica language mode uses this mode;
@pxref{Mathematica Language Mode}.) Note that, regardless of the
display mode, either brackets or braces may be used to enter vectors,
! and parentheses may never be used for this address@hidden
@kindex V ]
@pindex calcmatrixbrackets
 21163,21169 
Mathematica. (In fact, the Mathematica language mode uses this mode;
@pxref{Mathematica Language Mode}.) Note that, regardless of the
display mode, either brackets or braces may be used to enter vectors,
! and parentheses may never be used for this purpose.
@kindex V ]
@pindex calcmatrixbrackets
***************
*** 20989,20995 ****
@kindex V ,
@pindex calcvectorcommas
The @kbd{v ,} (@code{calcvectorcommas}) command turns commas on and
! off in vector and matrix address@hidden
In vectors of length one, and in all vectors when commas have been
turned off, Calc adds extra parentheses around formulas that might
 21216,21222 
@kindex V ,
@pindex calcvectorcommas
The @kbd{v ,} (@code{calcvectorcommas}) command turns commas on and
! off in vector and matrix display.
In vectors of length one, and in all vectors when commas have been
turned off, Calc adds extra parentheses around formulas that might
***************
*** 21047,21053 ****
for anything else'') prefix.
@xref{Editing Stack Entries}, to see how to manipulate formulas
! using regular Emacs editing address@hidden
When doing algebraic work, you may find several of the Calculator's
modes to be helpful, including algebraicsimplification mode (@kbd{m A})
 21274,21280 
for anything else'') prefix.
@xref{Editing Stack Entries}, to see how to manipulate formulas
! using regular Emacs editing commands.
When doing algebraic work, you may find several of the Calculator's
modes to be helpful, including algebraicsimplification mode (@kbd{m A})
***************
*** 21055,21061 ****
algebraicentry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions
of these modes. You may also wish to select ``big'' display mode (@kbd{d B}).
! @xref{Normal Language address@hidden
@menu
* Selecting Subformulas::
 21282,21288 
algebraicentry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions
of these modes. You may also wish to select ``big'' display mode (@kbd{d B}).
! @xref{Normal Language Modes}.
@menu
* Selecting Subformulas::
***************
*** 21213,21219 ****
behavior of some commands such as @kbd{j r} (@code{calcrewriteselection};
@pxref{Selections with Rewrite Rules}) and is mainly intended to be
used in keyboard macros that implement your own selectionoriented
! address@hidden
Selection of subformulas normally treats associative terms like
@samp{a + b  c + d} and @samp{x * y * z} as single levels of the formula.
 21440,21446 
behavior of some commands such as @kbd{j r} (@code{calcrewriteselection};
@pxref{Selections with Rewrite Rules}) and is mainly intended to be
used in keyboard macros that implement your own selectionoriented
! commands.
Selection of subformulas normally treats associative terms like
@samp{a + b  c + d} and @samp{x * y * z} as single levels of the formula.
***************
*** 21311,21317 ****
the @var{n}th toplevel subformula. (In other words, they act as if
the entire stack entry were selected first.) To select the @var{n}th
subformula where @var{n} is greater than nine, you must instead invoke
! @address@hidden 1}} with @var{n} as a numeric prefix address@hidden
@kindex j n
@kindex j p
 21538,21544 
the @var{n}th toplevel subformula. (In other words, they act as if
the entire stack entry were selected first.) To select the @var{n}th
subformula where @var{n} is greater than nine, you must instead invoke
! @address@hidden 1}} with @var{n} as a numeric prefix argument.
@kindex j n
@kindex j p
***************
*** 21493,21499 ****
Operations on subformulas sometimes leave the formula as a whole
in an ``unnatural'' state. Consider negating the @samp{2 x} term
of our sample formula by selecting it and pressing @kbd{n}
! (@code{calcchangesign})address@hidden
@smallexample
@group
 21720,21726 
Operations on subformulas sometimes leave the formula as a whole
in an ``unnatural'' state. Consider negating the @samp{2 x} term
of our sample formula by selecting it and pressing @kbd{n}
! (@code{calcchangesign}).
@smallexample
@group
***************
*** 21850,21856 ****
to @kbd{V M}, which operates on vectors instead of equations.
@pxref{Reducing and Mapping}. For example, @kbd{a M S} changes
@samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with
! @samp{x = y+1} and @cite{6} on the stack produces @samp{x+6 = y+7}.
With two equations on the stack, @kbd{a M +} would add the lefthand
sides together and the righthand sides together to get the two
respective sides of a new equation.
 22077,22083 
to @kbd{V M}, which operates on vectors instead of equations.
@pxref{Reducing and Mapping}. For example, @kbd{a M S} changes
@samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with
! @samp{x = y+1} and @expr{6} on the stack produces @samp{x+6 = y+7}.
With two equations on the stack, @kbd{a M +} would add the lefthand
sides together and the righthand sides together to get the two
respective sides of a new equation.
***************
*** 21899,21905 ****
Note that this is a purely structural substitution; the lone @samp{x} and
the @samp{sin(2 x)} stayed the same because they did not look like
@samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for
! doing address@hidden
The @kbd{a b} command normally prompts for two formulas, the old
one and the new one. If you enter a blank line for the first
 22126,22132 
Note that this is a purely structural substitution; the lone @samp{x} and
the @samp{sin(2 x)} stayed the same because they did not look like
@samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for
! doing substitutions.
The @kbd{a b} command normally prompts for two formulas, the old
one and the new one. If you enter a blank line for the first
***************
*** 21966,21991 ****
@cindex Default simplifications
This section describes the ``default simplifications,'' those which are
normally applied to all results. For example, if you enter the variable
! @cite{x} on the stack twice and push @kbd{+}, Calc's default
! simplifications automatically change @cite{x + x} to @cite{2 x}.
The @kbd{m O} command turns off the default simplifications, so that
! @cite{x + x} will remain in this form unless you give an explicit
``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic
Manipulation}. The @kbd{m D} command turns the default simplifications
back on.
The most basic default simplification is the evaluation of functions.
! For example, @cite{2 + 3} is evaluated to @cite{5}, and @address@hidden(9)}
! is evaluated to @cite{3}. Evaluation does not occur if the arguments
! to a function are somehow of the wrong type (@address@hidden([2,3,4])}),
! range (@address@hidden(90)}), or number (@address@hidden(3,5)}), or if the
! function name is not recognized (@address@hidden(5)}), or if ``symbolic''
! mode (@pxref{Symbolic Mode}) prevents evaluation (@address@hidden(2)}).
Calc simplifies (evaluates) the arguments to a function before it
! simplifies the function itself. Thus @address@hidden(5+4)} is
! simplified to @address@hidden(9)} before the @code{sqrt} function
itself is applied. There are very few exceptions to this rule:
@code{quote}, @code{lambda}, and @code{condition} (the @code{::}
operator) do not evaluate their arguments, @code{if} (the @code{? :}
 22193,22219 
@cindex Default simplifications
This section describes the ``default simplifications,'' those which are
normally applied to all results. For example, if you enter the variable
! @expr{x} on the stack twice and push @kbd{+}, Calc's default
! simplifications automatically change @expr{x + x} to @expr{2 x}.
The @kbd{m O} command turns off the default simplifications, so that
! @expr{x + x} will remain in this form unless you give an explicit
``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic
Manipulation}. The @kbd{m D} command turns the default simplifications
back on.
The most basic default simplification is the evaluation of functions.
! For example, @expr{2 + 3} is evaluated to @expr{5}, and @address@hidden(9)}
! is evaluated to @expr{3}. Evaluation does not occur if the arguments
! to a function are somehow of the wrong type @address@hidden([2,3,4])}),
! range (@address@hidden(90)}), or number (@address@hidden(3,5)}),
! or if the function name is not recognized (@address@hidden(5)}), or if
! ``symbolic'' mode (@pxref{Symbolic Mode}) prevents evaluation
! (@address@hidden(2)}).
Calc simplifies (evaluates) the arguments to a function before it
! simplifies the function itself. Thus @address@hidden(5+4)} is
! simplified to @address@hidden(9)} before the @code{sqrt} function
itself is applied. There are very few exceptions to this rule:
@code{quote}, @code{lambda}, and @code{condition} (the @code{::}
operator) do not evaluate their arguments, @code{if} (the @code{? :}
***************
*** 22024,22032 ****
Arithmetic operators like @kbd{+} and @kbd{*} always take two
arguments in Calc's internal form. Sums and products of three or
more terms are arranged by the associative law of algebra into
! a leftassociative form for sums, @cite{((a + b) + c) + d}, and
! a rightassociative form for products, @cite{a * (b * (c * d))}.
! Formulas like @cite{(a + b) + (c + d)} are rearranged to
leftassociative form, though this rarely matters since Calc's
algebra commands are designed to hide the inner structure of
sums and products as much as possible. Sums and products in
 22252,22260 
Arithmetic operators like @kbd{+} and @kbd{*} always take two
arguments in Calc's internal form. Sums and products of three or
more terms are arranged by the associative law of algebra into
! a leftassociative form for sums, @expr{((a + b) + c) + d}, and
! a rightassociative form for products, @expr{a * (b * (c * d))}.
! Formulas like @expr{(a + b) + (c + d)} are rearranged to
leftassociative form, though this rarely matters since Calc's
algebra commands are designed to hide the inner structure of
sums and products as much as possible. Sums and products in
***************
*** 22034,22232 ****
in the examples below.
Sums and products are @emph{not} rearranged according to the
! commutative law (@cite{a + b} to @cite{b + a}) except in a few
special cases described below. Some algebra programs always
rearrange terms into a canonical order, which enables them to
! see that @cite{a b + b a} can be simplified to @cite{2 a b}.
Calc assumes you have put the terms into the order you want
and generally leaves that order alone, with the consequence
that formulas like the above will only be simplified if you
explicitly give the @kbd{a s} command. @xref{Algebraic
Simplifications}.
! Differences @cite{a  b} are treated like sums @cite{a + (b)}
for purposes of simplification; one of the default simplifications
! is to rewrite @cite{a + (b)} or @cite{(b) + a}, where @cite{b}
! represents a ``negativelooking'' term, into @cite{a  b} form.
``Negativelooking'' means negative numbers, negated formulas like
! @cite{x}, and products or quotients in which either term is
negativelooking.
! Other simplifications involving negation are @cite{(x)} to @cite{x};
! @cite{(a b)} or @cite{(a/b)} where either @cite{a} or @cite{b} is
negativelooking, simplified by negating that term, or else where
! @cite{a} or @cite{b} is any number, by negating that number;
! @cite{(a + b)} to @cite{a  b}, and @cite{(b  a)} to @cite{a  b}.
! (This, and rewriting @cite{(b) + a} to @cite{a  b}, are the only
cases where the order of terms in a sum is changed by the default
simplifications.)
The distributive law is used to simplify sums in some cases:
! @cite{a x + b x} to @cite{(a + b) x}, where @cite{a} represents
! a number or an implicit 1 or @i{1} (as in @cite{x} or @cite{x})
! and similarly for @cite{b}. Use the @kbd{a c}, @address@hidden f}}, or
@kbd{j M} commands to merge sums with nonnumeric coefficients
using the distributive law.
The distributive law is only used for sums of two terms, or
! for adjacent terms in a larger sum. Thus @cite{a + b + b + c}
! is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b}
is not simplified. The reason is that comparing all terms of a
sum with one another would require time proportional to the
square of the number of terms; Calc relegates potentially slow
operations like this to commands that have to be invoked
explicitly, like @kbd{a s}.
! Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}.
! A consequence of the above rules is that @cite{0  a} is simplified
! to @cite{a}.
@tex
\bigskip
@end tex
! The products @cite{1 a} and @cite{a 1} are simplified to @cite{a};
! @cite{(1) a} and @cite{a (1)} are simplified to @cite{a};
! @cite{0 a} and @cite{a 0} are simplified to @cite{0}, except that
! in matrix mode where @cite{a} is not provably scalar the result
! is the generic zero matrix @samp{idn(0)}, and that if @cite{a} is
infinite the result is @samp{nan}.
! Also, @cite{(a) b} and @cite{a (b)} are simplified to @cite{(a b)},
where this occurs for negated formulas but not for regular negative
numbers.
Products are commuted only to move numbers to the front:
! @cite{a b 2} is commuted to @cite{2 a b}.
! The product @cite{a (b + c)} is distributed over the sum only if
! @cite{a} and at least one of @cite{b} and @cite{c} are numbers:
! @cite{2 (x + 3)} goes to @cite{2 x + 6}. The formula
! @cite{(a) (b  c)}, where @cite{a} is a negative number, is
! rewritten to @cite{a (c  b)}.
The distributive law of products and powers is used for adjacent
! terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$}
! @cite{x^(a+b)}
! where @cite{a} is a number, or an implicit 1 (as in @cite{x}),
! or the implicit onehalf of @address@hidden(x)}, and similarly for
! @cite{b}. The result is written using @samp{sqrt} or @samp{1/sqrt}
! if the sum of the powers is @cite{1/2} or @cite{1/2}, respectively.
If the sum of the powers is zero, the product is simplified to
! @cite{1} or to @samp{idn(1)} if matrix mode is enabled.
The product of a negative power times anything but another negative
! power is changed to use division: @c{$x^{2} y$}
! @cite{x^(2) y} goes to @cite{y / x^2} unless matrix mode is
! in effect and neither @cite{x} nor @cite{y} are scalar (in which
case it is considered unsafe to rearrange the order of the terms).
! Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also
! @cite{(a/b) c} is changed to @cite{(a c)/b} unless in matrix mode.
@tex
\bigskip
@end tex
Simplifications for quotients are analogous to those for products.
! The quotient @cite{0 / x} is simplified to @cite{0}, with the same
! exceptions that were noted for @cite{0 x}. Likewise, @cite{x / 1}
! and @cite{x / (1)} are simplified to @cite{x} and @cite{x},
respectively.
! The quotient @cite{x / 0} is left unsimplified or changed to an
infinite quantity, as directed by the current infinite mode.
@xref{Infinite Mode}.
! The expression @c{$a / b^{c}$}
! @cite{a / b^(c)} is changed to @cite{a b^c},
! where @cite{c} is any negativelooking power. Also, @cite{1 / b^c}
! is changed to @c{$b^{c}$}
! @cite{b^(c)} for any power @cite{c}.
!
! Also, @cite{(a) / b} and @cite{a / (b)} go to @cite{(a/b)};
! @cite{(a/b) / c} goes to @cite{a / (b c)}; and @cite{a / (b/c)}
! goes to @cite{(a c) / b} unless matrix mode prevents this
! rearrangement. Similarly, @cite{a / (b:c)} is simplified to
! @cite{(c:b) a} for any fraction @cite{b:c}.
! The distributive law is applied to @cite{(a + b) / c} only if
! @cite{c} and at least one of @cite{a} and @cite{b} are numbers.
Quotients of powers and square roots are distributed just as
described for multiplication.
Quotients of products cancel only in the leading terms of the
! numerator and denominator. In other words, @cite{a x b / a y b}
! is cancelled to @cite{x b / y b} but not to @cite{x / y}. Once
again this is because full cancellation can be slow; use @kbd{a s}
to cancel all terms of the quotient.
Quotients of negativelooking values are simplified according
! to @cite{(a) / (b)} to @cite{a / b}, @cite{(a) / (b  c)}
! to @cite{a / (c  b)}, and @cite{(a  b) / (c)} to @cite{(b  a) / c}.
@tex
\bigskip
@end tex
! The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)}
! in matrix mode. The formula @cite{0^x} is simplified to @cite{0}
! unless @cite{x} is a negative number or complex number, in which
case the result is an infinity or an unsimplified formula according
! to the current infinite mode. Note that @cite{0^0} is an
indeterminate form, as evidenced by the fact that the simplifications
! for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}.
! Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c}
! are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c}
! is an integer, or if either @cite{a} or @cite{b} are nonnegative
! real numbers. Powers of powers @cite{(a^b)^c} are simplified to
! @c{$a^{b c}$}
! @cite{a^(b c)} only when @cite{c} is an integer and @cite{b c} also
evaluates to an integer. Without these restrictions these simplifications
would not be safe because of problems with principal values.
! (In other words, @c{$((3)^{1/2})^2$}
! @cite{((3)^1:2)^2} is safe to simplify, but
! @c{$((3)^2)^{1/2}$}
! @cite{((3)^2)^1:2} is not.) @xref{Declarations}, for ways to inform
! Calc that your variables satisfy these requirements.
!
! As a special case of this rule, @address@hidden(x)^n} is simplified to
! @c{$x^{n/2}$}
! @cite{x^(n/2)} only for even integers @cite{n}.
!
! If @cite{a} is known to be real, @cite{b} is an even integer, and
! @cite{c} is a half or quarterinteger, then @cite{(a^b)^c} is
! simplified to @address@hidden(a^{b c})$}
! @address@hidden(a^(b c))}.
!
! Also, @cite{(a)^b} is simplified to @cite{a^b} if @cite{b} is an
! even integer, or to @cite{(a^b)} if @cite{b} is an odd integer,
! for any negativelooking expression @cite{a}.
!
! Square roots @address@hidden(x)} generally act like onehalf powers
! @c{$x^{1:2}$}
! @cite{x^1:2} for the purposes of the abovelisted simplifications.
!
! Also, note that @c{$1 / x^{1:2}$}
! @cite{1 / x^1:2} is changed to @c{$x^{1:2}$}
! @cite{x^(1:2)},
! but @cite{1 / @t{sqrt}(x)} is left alone.
@tex
\bigskip
@end tex
Generic identity matrices (@pxref{Matrix Mode}) are simplified by the
! following rules: @address@hidden(a) + b} to @cite{a + b} if @cite{b}
! is provably scalar, or expanded out if @cite{b} is a matrix;
! @address@hidden(a) + @t{idn}(b)} to @address@hidden(a + b)};
! @address@hidden(a)} to @address@hidden(a)}; @cite{a @t{idn}(b)} to
! @address@hidden(a b)} if @cite{a} is provably scalar, or to @cite{a b}
! if @cite{a} is provably nonscalar; @address@hidden(a) @t{idn}(b)}
! to @address@hidden(a b)}; analogous simplifications for quotients
! involving @code{idn}; and @address@hidden(a)^n} to @address@hidden(a^n)}
! where @cite{n} is an integer.
@tex
\bigskip
 22262,22474 
in the examples below.
Sums and products are @emph{not} rearranged according to the
! commutative law (@expr{a + b} to @expr{b + a}) except in a few
special cases described below. Some algebra programs always
rearrange terms into a canonical order, which enables them to
! see that @expr{a b + b a} can be simplified to @expr{2 a b}.
Calc assumes you have put the terms into the order you want
and generally leaves that order alone, with the consequence
that formulas like the above will only be simplified if you
explicitly give the @kbd{a s} command. @xref{Algebraic
Simplifications}.
! Differences @expr{a  b} are treated like sums @expr{a + (b)}
for purposes of simplification; one of the default simplifications
! is to rewrite @expr{a + (b)} or @expr{(b) + a}, where @expr{b}
! represents a ``negativelooking'' term, into @expr{a  b} form.
``Negativelooking'' means negative numbers, negated formulas like
! @expr{x}, and products or quotients in which either term is
negativelooking.
! Other simplifications involving negation are @expr{(x)} to @expr{x};
! @expr{(a b)} or @expr{(a/b)} where either @expr{a} or @expr{b} is
negativelooking, simplified by negating that term, or else where
! @expr{a} or @expr{b} is any number, by negating that number;
! @expr{(a + b)} to @expr{a  b}, and @expr{(b  a)} to @expr{a  b}.
! (This, and rewriting @expr{(b) + a} to @expr{a  b}, are the only
cases where the order of terms in a sum is changed by the default
simplifications.)
The distributive law is used to simplify sums in some cases:
! @expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents
! a number or an implicit 1 or @i{1} (as in @expr{x} or @expr{x})
! and similarly for @expr{b}. Use the @kbd{a c}, @address@hidden f}}, or
@kbd{j M} commands to merge sums with nonnumeric coefficients
using the distributive law.
The distributive law is only used for sums of two terms, or
! for adjacent terms in a larger sum. Thus @expr{a + b + b + c}
! is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b}
is not simplified. The reason is that comparing all terms of a
sum with one another would require time proportional to the
square of the number of terms; Calc relegates potentially slow
operations like this to commands that have to be invoked
explicitly, like @kbd{a s}.
! Finally, @expr{a + 0} and @expr{0 + a} are simplified to @expr{a}.
! A consequence of the above rules is that @expr{0  a} is simplified
! to @expr{a}.
@tex
\bigskip
@end tex
! The products @expr{1 a} and @expr{a 1} are simplified to @expr{a};
! @expr{(1) a} and @expr{a (1)} are simplified to @expr{a};
! @expr{0 a} and @expr{a 0} are simplified to @expr{0}, except that
! in matrix mode where @expr{a} is not provably scalar the result
! is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is
infinite the result is @samp{nan}.
! Also, @expr{(a) b} and @expr{a (b)} are simplified to @expr{(a b)},
where this occurs for negated formulas but not for regular negative
numbers.
Products are commuted only to move numbers to the front:
! @expr{a b 2} is commuted to @expr{2 a b}.
! The product @expr{a (b + c)} is distributed over the sum only if
! @expr{a} and at least one of @expr{b} and @expr{c} are numbers:
! @expr{2 (x + 3)} goes to @expr{2 x + 6}. The formula
! @expr{(a) (b  c)}, where @expr{a} is a negative number, is
! rewritten to @expr{a (c  b)}.
The distributive law of products and powers is used for adjacent
! terms of the product: @expr{x^a x^b} goes to
! @texline @tmath{x^{a+b}}
! @infoline @expr{x^(a+b)}
! where @expr{a} is a number, or an implicit 1 (as in @expr{x}),
! or the implicit onehalf of @address@hidden(x)}, and similarly for
! @expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt}
! if the sum of the powers is @expr{1/2} or @expr{1/2}, respectively.
If the sum of the powers is zero, the product is simplified to
! @expr{1} or to @samp{idn(1)} if matrix mode is enabled.
The product of a negative power times anything but another negative
! power is changed to use division:
! @texline @tmath{x^{2} y}
! @infoline @expr{x^(2) y}
! goes to @expr{y / x^2} unless matrix mode is
! in effect and neither @expr{x} nor @expr{y} are scalar (in which
case it is considered unsafe to rearrange the order of the terms).
! Finally, @expr{a (b/c)} is rewritten to @expr{(a b)/c}, and also
! @expr{(a/b) c} is changed to @expr{(a c)/b} unless in matrix mode.
@tex
\bigskip
@end tex
Simplifications for quotients are analogous to those for products.
! The quotient @expr{0 / x} is simplified to @expr{0}, with the same
! exceptions that were noted for @expr{0 x}. Likewise, @expr{x / 1}
! and @expr{x / (1)} are simplified to @expr{x} and @expr{x},
respectively.
! The quotient @expr{x / 0} is left unsimplified or changed to an
infinite quantity, as directed by the current infinite mode.
@xref{Infinite Mode}.
! The expression
! @texline @tmath{a / b^{c}}
! @infoline @expr{a / b^(c)}
! is changed to @expr{a b^c}, where @expr{c} is any negativelooking
! power. Also, @expr{1 / b^c} is changed to
! @texline @tmath{b^{c}}
! @infoline @expr{b^(c)}
! for any power @expr{c}.
!
! Also, @expr{(a) / b} and @expr{a / (b)} go to @expr{(a/b)};
! @expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)}
! goes to @expr{(a c) / b} unless matrix mode prevents this
! rearrangement. Similarly, @expr{a / (b:c)} is simplified to
! @expr{(c:b) a} for any fraction @expr{b:c}.
! The distributive law is applied to @expr{(a + b) / c} only if
! @expr{c} and at least one of @expr{a} and @expr{b} are numbers.
Quotients of powers and square roots are distributed just as
described for multiplication.
Quotients of products cancel only in the leading terms of the
! numerator and denominator. In other words, @expr{a x b / a y b}
! is cancelled to @expr{x b / y b} but not to @expr{x / y}. Once
again this is because full cancellation can be slow; use @kbd{a s}
to cancel all terms of the quotient.
Quotients of negativelooking values are simplified according
! to @expr{(a) / (b)} to @expr{a / b}, @expr{(a) / (b  c)}
! to @expr{a / (c  b)}, and @expr{(a  b) / (c)} to @expr{(b  a) / c}.
@tex
\bigskip
@end tex
! The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)}
! in matrix mode. The formula @expr{0^x} is simplified to @expr{0}
! unless @expr{x} is a negative number or complex number, in which
case the result is an infinity or an unsimplified formula according
! to the current infinite mode. Note that @expr{0^0} is an
indeterminate form, as evidenced by the fact that the simplifications
! for @expr{x^0} and @expr{0^x} conflict when @expr{x=0}.
! Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c}
! are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c}
! is an integer, or if either @expr{a} or @expr{b} are nonnegative
! real numbers. Powers of powers @expr{(a^b)^c} are simplified to
! @texline @tmath{a^{b c}}
! @infoline @expr{a^(b c)}
! only when @expr{c} is an integer and @expr{b c} also
evaluates to an integer. Without these restrictions these simplifications
would not be safe because of problems with principal values.
! (In other words,
! @texline @tmath{((3)^{1/2})^2}
! @infoline @expr{((3)^1:2)^2}
! is safe to simplify, but
! @texline @tmath{((3)^2)^{1/2}}
! @infoline @expr{((3)^2)^1:2}
! is not.) @xref{Declarations}, for ways to inform Calc that your
! variables satisfy these requirements.
!
! As a special case of this rule, @address@hidden(x)^n} is simplified to
! @texline @tmath{x^{n/2}}
! @infoline @expr{x^(n/2)}
! only for even integers @expr{n}.
!
! If @expr{a} is known to be real, @expr{b} is an even integer, and
! @expr{c} is a half or quarterinteger, then @expr{(a^b)^c} is
! simplified to @address@hidden(a^(b c))}.
!
! Also, @expr{(a)^b} is simplified to @expr{a^b} if @expr{b} is an
! even integer, or to @expr{(a^b)} if @expr{b} is an odd integer,
! for any negativelooking expression @expr{a}.
!
! Square roots @address@hidden(x)} generally act like onehalf powers
! @texline @tmath{x^{1:2}}
! @infoline @expr{x^1:2}
! for the purposes of the abovelisted simplifications.
!
! Also, note that
! @texline @tmath{1 / x^{1:2}}
! @infoline @expr{1 / x^1:2}
! is changed to
! @texline @tmath{x^{1:2}},
! @infoline @expr{x^(1:2)},
! but @expr{1 / @t{sqrt}(x)} is left alone.
@tex
\bigskip
@end tex
Generic identity matrices (@pxref{Matrix Mode}) are simplified by the
! following rules: @address@hidden(a) + b} to @expr{a + b} if @expr{b}
! is provably scalar, or expanded out if @expr{b} is a matrix;
! @address@hidden(a) + @t{idn}(b)} to @address@hidden(a + b)};
! @address@hidden(a)} to @address@hidden(a)}; @expr{a @t{idn}(b)} to
! @address@hidden(a b)} if @expr{a} is provably scalar, or to @expr{a b}
! if @expr{a} is provably nonscalar; @address@hidden(a) @t{idn}(b)} to
! @address@hidden(a b)}; analogous simplifications for quotients involving
! @code{idn}; and @address@hidden(a)^n} to @address@hidden(a^n)} where
! @expr{n} is an integer.
@tex
\bigskip
***************
*** 22234,22259 ****
The @code{floor} function and other integer truncation functions
vanish if the argument is provably integervalued, so that
! @address@hidden(@t{round}(x))} simplifies to @address@hidden(x)}.
Also, combinations of @code{float}, @code{floor} and its friends,
and @code{ffloor} and its friends, are simplified in appropriate
ways. @xref{Integer Truncation}.
! The expression @address@hidden(x)} changes to @address@hidden(x)}.
! The expression @address@hidden(@t{abs}(x))} changes to @address@hidden(x)};
! in fact, @address@hidden(x)} changes to @cite{x} or @cite{x} if @cite{x}
! is provably nonnegative or nonpositive (@pxref{Declarations}).
While most functions do not recognize the variable @code{i} as an
imaginary number, the @code{arg} function does handle the two cases
! @address@hidden(@t{i})} and @address@hidden(address@hidden)} just for
convenience.
! The expression @address@hidden(@t{conj}(x))} simplifies to @cite{x}.
Various other expressions involving @code{conj}, @code{re}, and
@code{im} are simplified, especially if some of the arguments are
provably real or involve the constant @code{i}. For example,
! @address@hidden(a + b i)} is changed to @address@hidden(a)  @t{conj}(b) i},
! or to @cite{a  b i} if @cite{a} and @cite{b} are known to be real.
Functions like @code{sin} and @code{arctan} generally don't have
any default simplifications beyond simply evaluating the functions
 22476,22503 
The @code{floor} function and other integer truncation functions
vanish if the argument is provably integervalued, so that
! @address@hidden(@t{round}(x))} simplifies to @address@hidden(x)}.
Also, combinations of @code{float}, @code{floor} and its friends,
and @code{ffloor} and its friends, are simplified in appropriate
ways. @xref{Integer Truncation}.
! The expression @address@hidden(x)} changes to @address@hidden(x)}.
! The expression @address@hidden(@t{abs}(x))} changes to
! @address@hidden(x)}; in fact, @address@hidden(x)} changes to @expr{x} or
! @expr{x} if @expr{x} is provably nonnegative or nonpositive
! (@pxref{Declarations}).
While most functions do not recognize the variable @code{i} as an
imaginary number, the @code{arg} function does handle the two cases
! @address@hidden(@t{i})} and @address@hidden(address@hidden)} just for
convenience.
! The expression @address@hidden(@t{conj}(x))} simplifies to @expr{x}.
Various other expressions involving @code{conj}, @code{re}, and
@code{im} are simplified, especially if some of the arguments are
provably real or involve the constant @code{i}. For example,
! @address@hidden(a + b i)} is changed to
! @address@hidden(a)  @t{conj}(b) i}, or to @expr{a  b i} if @expr{a}
! and @expr{b} are known to be real.
Functions like @code{sin} and @code{arctan} generally don't have
any default simplifications beyond simply evaluating the functions
***************
*** 22261,22278 ****
described in the next section does provide some simplifications for
these functions, though.
! One important simplification that does occur is that @address@hidden(@t{e})}
! is simplified to 1, and @address@hidden(@t{e}^x)} is simplified to @cite{x}
! for any @cite{x}. This occurs even if you have stored a different
! value in the Calc variable @samp{e}; but this would be a bad idea
! in any case if you were also using natural logarithms!
Among the logical functions, @t{(@var{a} <= @var{b})} changes to
@address@hidden > @var{b}} and so on. Equations and inequalities where both
sides
are either negativelooking or zero are simplified by negating both sides
and reversing the inequality. While it might seem reasonable to simplify
! @cite{!!x} to @cite{x}, this would not be valid in general because
! @cite{!!2} is 1, not 2.
Most other Calc functions have few if any default simplifications
defined, aside of course from evaluation when the arguments are
 22505,22522 
described in the next section does provide some simplifications for
these functions, though.
! One important simplification that does occur is that
! @address@hidden(@t{e})} is simplified to 1, and @address@hidden(@t{e}^x)} is
! simplified to @expr{x} for any @expr{x}. This occurs even if you have
! stored a different value in the Calc variable @samp{e}; but this would
! be a bad idea in any case if you were also using natural logarithms!
Among the logical functions, @t{(@var{a} <= @var{b})} changes to
@address@hidden > @var{b}} and so on. Equations and inequalities where both
sides
are either negativelooking or zero are simplified by negating both sides
and reversing the inequality. While it might seem reasonable to simplify
! @expr{!!x} to @expr{x}, this would not be valid in general because
! @expr{!!2} is 1, not 2.
Most other Calc functions have few if any default simplifications
defined, aside of course from evaluation when the arguments are
***************
*** 22309,22321 ****
@end tex
Sums are simplified in two ways. Constant terms are commuted to the
! end of the sum, so that @cite{a + 2 + b} changes to @cite{a + b + 2}.
The only exception is that a constant will not be commuted away
! from the first position of a difference, i.e., @cite{2  x} is not
! commuted to @cite{x + 2}.
Also, terms of sums are combined by the distributive law, as in
! @cite{x + y + 2 x} to @cite{y + 3 x}. This always occurs for
adjacent terms, but @kbd{a s} compares all pairs of terms including
nonadjacent ones.
 22553,22565 
@end tex
Sums are simplified in two ways. Constant terms are commuted to the
! end of the sum, so that @expr{a + 2 + b} changes to @expr{a + b + 2}.
The only exception is that a constant will not be commuted away
! from the first position of a difference, i.e., @expr{2  x} is not
! commuted to @expr{x + 2}.
Also, terms of sums are combined by the distributive law, as in
! @expr{x + y + 2 x} to @expr{y + 3 x}. This always occurs for
adjacent terms, but @kbd{a s} compares all pairs of terms including
nonadjacent ones.
***************
*** 22324,22333 ****
@end tex
Products are sorted into a canonical order using the commutative
! law. For example, @cite{b c a} is commuted to @cite{a b c}.
This allows easier comparison of products; for example, the default
! simplifications will not change @cite{x y + y x} to @cite{2 x y},
! but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y},
and then the default simplifications are able to recognize a sum
of identical terms.
 22568,22577 
@end tex
Products are sorted into a canonical order using the commutative
! law. For example, @expr{b c a} is commuted to @expr{a b c}.
This allows easier comparison of products; for example, the default
! simplifications will not change @expr{x y + y x} to @expr{2 x y},
! but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y},
and then the default simplifications are able to recognize a sum
of identical terms.
***************
*** 22346,22360 ****
Even though sums are not sorted, the commutative law is still
taken into account when terms of a product are being compared.
! Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}.
! A subtle point is that @cite{(x  y) (y  x)} will @emph{not}
! be simplified to @cite{(x  y)^2}; Calc does not notice that
one term can be written as a constant times the other, even if
that constant is @i{1}.
! A fraction times any expression, @cite{(a:b) x}, is changed to
! a quotient involving integers: @cite{a x / b}. This is not
! done for floatingpoint numbers like @cite{0.5}, however. This
is one reason why you may find it convenient to turn Fraction mode
on while doing algebra; @pxref{Fraction Mode}.
 22590,22604 
Even though sums are not sorted, the commutative law is still
taken into account when terms of a product are being compared.
! Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}.
! A subtle point is that @expr{(x  y) (y  x)} will @emph{not}
! be simplified to @expr{(x  y)^2}; Calc does not notice that
one term can be written as a constant times the other, even if
that constant is @i{1}.
! A fraction times any expression, @expr{(a:b) x}, is changed to
! a quotient involving integers: @expr{a x / b}. This is not
! done for floatingpoint numbers like @expr{0.5}, however. This
is one reason why you may find it convenient to turn Fraction mode
on while doing algebra; @pxref{Fraction Mode}.
***************
*** 22364,22388 ****
Quotients are simplified by comparing all terms in the numerator
with all terms in the denominator for possible cancellation using
! the distributive law. For example, @cite{a x^2 b / c x^3 d} will
! cancel @cite{x^2} from both sides to get @cite{a b / c x d}.
! (The terms in the denominator will then be rearranged to @cite{c d x}
as described above.) If there is any common integer or fractional
factor in the numerator and denominator, it is cancelled out;
! for example, @cite{(4 x + 6) / 8 x} simplifies to @cite{(2 x + 3) / 4 x}.
Nonconstant common factors are not found even by @kbd{a s}. To
! cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first
! use @kbd{j M} on the product @cite{a x} to Merge the numerator to
! @cite{a (1+x)}, which can then be simplified successfully.
@tex
\bigskip
@end tex
Integer powers of the variable @code{i} are simplified according
! to the identity @cite{i^2 = 1}. If you store a new value other
! than the complex number @cite{(0,1)} in @code{i}, this simplification
will no longer occur. This is done by @kbd{a s} instead of by default
in case someone (unwisely) uses the name @code{i} for a variable
unrelated to complex numbers; it would be unfortunate if Calc
 22608,22632 
Quotients are simplified by comparing all terms in the numerator
with all terms in the denominator for possible cancellation using
! the distributive law. For example, @expr{a x^2 b / c x^3 d} will
! cancel @expr{x^2} from both sides to get @expr{a b / c x d}.
! (The terms in the denominator will then be rearranged to @expr{c d x}
as described above.) If there is any common integer or fractional
factor in the numerator and denominator, it is cancelled out;
! for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}.
Nonconstant common factors are not found even by @kbd{a s}. To
! cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first
! use @kbd{j M} on the product @expr{a x} to Merge the numerator to
! @expr{a (1+x)}, which can then be simplified successfully.
@tex
\bigskip
@end tex
Integer powers of the variable @code{i} are simplified according
! to the identity @expr{i^2 = 1}. If you store a new value other
! than the complex number @expr{(0,1)} in @code{i}, this simplification
will no longer occur. This is done by @kbd{a s} instead of by default
in case someone (unwisely) uses the name @code{i} for a variable
unrelated to complex numbers; it would be unfortunate if Calc
***************
*** 22392,22417 ****
Square roots of integer or rational arguments are simplified in
several ways. (Note that these will be left unevaluated only in
Symbolic mode.) First, square integer or rational factors are
! pulled out so that @address@hidden(8)} is rewritten as
! @c{$2\,\t{sqrt}(2)$}
! @cite{2 sqrt(2)}. Conceptually speaking this implies factoring
! the argument into primes and moving pairs of primes out of the
! square root, but for reasons of efficiency Calc only looks for
! primes up to 29.
Square roots in the denominator of a quotient are moved to the
! numerator: @cite{1 / @t{sqrt}(3)} changes to @address@hidden(3) / 3}.
The same effect occurs for the square root of a fraction:
! @address@hidden(2:3)} changes to @address@hidden(6) / 3}.
@tex
\bigskip
@end tex
The @code{%} (modulo) operator is simplified in several ways
! when the modulus @cite{M} is a positive real number. First, if
! the argument is of the form @cite{x + n} for some real number
! @cite{n}, then @cite{n} is itself reduced modulo @cite{M}. For
example, @samp{(x  23) % 10} is simplified to @samp{(x + 7) % 10}.
If the argument is multiplied by a constant, and this constant
 22636,22661 
Square roots of integer or rational arguments are simplified in
several ways. (Note that these will be left unevaluated only in
Symbolic mode.) First, square integer or rational factors are
! pulled out so that @address@hidden(8)} is rewritten as
! @texline @tmath{$2\,\t{sqrt}(2)$}.
! @infoline @expr{2 sqrt(2)}.
! Conceptually speaking this implies factoring the argument into primes
! and moving pairs of primes out of the square root, but for reasons of
! efficiency Calc only looks for primes up to 29.
Square roots in the denominator of a quotient are moved to the
! numerator: @expr{1 / @t{sqrt}(3)} changes to @address@hidden(3) / 3}.
The same effect occurs for the square root of a fraction:
! @address@hidden(2:3)} changes to @address@hidden(6) / 3}.
@tex
\bigskip
@end tex
The @code{%} (modulo) operator is simplified in several ways
! when the modulus @expr{M} is a positive real number. First, if
! the argument is of the form @expr{x + n} for some real number
! @expr{n}, then @expr{n} is itself reduced modulo @expr{M}. For
example, @samp{(x  23) % 10} is simplified to @samp{(x + 7) % 10}.
If the argument is multiplied by a constant, and this constant
***************
*** 22435,22450 ****
@end tex
Trigonometric functions are simplified in several ways. First,
! @address@hidden(@t{arcsin}(x))} is simplified to @cite{x}, and
similarly for @code{cos} and @code{tan}. If the argument to
! @code{sin} is negativelooking, it is simplified to @address@hidden(x)},
! and similarly for @code{cos} and @code{tan}. Finally, certain
! special values of the argument are recognized;
@pxref{Trigonometric and Hyperbolic Functions}.
Trigonometric functions of inverses of different trigonometric
! functions can also be simplified, as in @address@hidden(@t{arccos}(x))}
! to @address@hidden(1  x^2)}.
Hyperbolic functions of their inverses and of negativelooking
arguments are also handled, as are exponentials of inverse
 22679,22694 
@end tex
Trigonometric functions are simplified in several ways. First,
! @address@hidden(@t{arcsin}(x))} is simplified to @expr{x}, and
similarly for @code{cos} and @code{tan}. If the argument to
! @code{sin} is negativelooking, it is simplified to
! @address@hidden(x),}, and similarly for @code{cos} and @code{tan}.
! Finally, certain special values of the argument are recognized;
@pxref{Trigonometric and Hyperbolic Functions}.
Trigonometric functions of inverses of different trigonometric
! functions can also be simplified, as in @address@hidden(@t{arccos}(x))}
! to @address@hidden(1  x^2)}.
Hyperbolic functions of their inverses and of negativelooking
arguments are also handled, as are exponentials of inverse
***************
*** 22453,22478 ****
No simplifications for inverse trigonometric and hyperbolic
functions are known, except for negative arguments of @code{arcsin},
@code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that
! @address@hidden(@t{sin}(x))} can @emph{not} safely change to
! @cite{x}, since this only correct within an integer multiple
! of @c{$2 \pi$}
! @cite{2 pi} radians or 360 degrees. However,
! @address@hidden(@t{sinh}(x))} is simplified to @cite{x} if
! @cite{x} is known to be real.
Several simplifications that apply to logarithms and exponentials
! are that @address@hidden(@t{ln}(x))}, @address@hidden(x)}$}
! @address@hidden(x)}, and
! @c{$10^{{\rm log10}(x)}$}
! @address@hidden(x)} all reduce to @cite{x}.
! Also, @address@hidden(@t{exp}(x))}, etc., can reduce to @cite{x} if
! @cite{x} is provably real. The form @address@hidden(x)^y} is simplified
! to @address@hidden(x y)}. If @cite{x} is a suitable multiple of @c{$\pi i$}
! @cite{pi i}
! (as described above for the trigonometric functions), then @address@hidden(x)}
! or @cite{e^x} will be expanded. Finally, @address@hidden(x)} is simplified
! to a form involving @code{pi} and @code{i} where @cite{x} is provably
! negative, positive imaginary, or negative imaginary.
The error functions @code{erf} and @code{erfc} are simplified when
their arguments are negativelooking or are calls to the @code{conj}
 22697,22727 
No simplifications for inverse trigonometric and hyperbolic
functions are known, except for negative arguments of @code{arcsin},
@code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that
! @address@hidden(@t{sin}(x))} can @emph{not} safely change to
! @expr{x}, since this only correct within an integer multiple of
! @texline @tmath{2 \pi}
! @infoline @expr{2 pi}
! radians or 360 degrees. However, @address@hidden(@t{sinh}(x))} is
! simplified to @expr{x} if @expr{x} is known to be real.
Several simplifications that apply to logarithms and exponentials
! are that @address@hidden(@t{ln}(x))},
! @texline @address@hidden(x)}},
! @infoline @address@hidden(x)},
! and
! @texline @tmath{10^{{\rm log10}(x)}}
! @infoline @address@hidden(x)}
! all reduce to @expr{x}. Also, @address@hidden(@t{exp}(x))}, etc., can
! reduce to @expr{x} if @expr{x} is provably real. The form
! @address@hidden(x)^y} is simplified to @address@hidden(x y)}. If @expr{x}
! is a suitable multiple of
! @texline @tmath{\pi i}
! @infoline @expr{pi i}
! (as described above for the trigonometric functions), then
! @address@hidden(x)} or @expr{e^x} will be expanded. Finally,
! @address@hidden(x)} is simplified to a form involving @code{pi} and
! @code{i} where @expr{x} is provably negative, positive imaginary, or
! negative imaginary.
The error functions @code{erf} and @code{erfc} are simplified when
their arguments are negativelooking or are calls to the @code{conj}
***************
*** 22485,22491 ****
Equations and inequalities are simplified by cancelling factors
of products, quotients, or sums on both sides. Inequalities
change sign if a negative multiplicative factor is cancelled.
! Nonconstant multiplicative factors as in @cite{a b = a c} are
cancelled from equations only if they are provably nonzero (generally
because they were declared so; @pxref{Declarations}). Factors
are cancelled from inequalities only if they are nonzero and their
 22734,22740 
Equations and inequalities are simplified by cancelling factors
of products, quotients, or sums on both sides. Inequalities
change sign if a negative multiplicative factor is cancelled.
! Nonconstant multiplicative factors as in @expr{a b = a c} are
cancelled from equations only if they are provably nonzero (generally
because they were declared so; @pxref{Declarations}). Factors
are cancelled from inequalities only if they are nonzero and their
***************
*** 22493,22503 ****
Simplification also replaces an equation or inequality with
1 or 0 (``true'' or ``false'') if it can through the use of
! declarations. If @cite{x} is declared to be an integer greater
! than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are
! all simplified to 0, but @cite{x > 3} is simplified to 1.
! By a similar analysis, @cite{abs(x) >= 0} is simplified to 1,
! as is @cite{x^2 >= 0} if @cite{x} is known to be real.
@node Unsafe Simplifications, Simplification of Units, Algebraic
Simplifications, Simplifying Formulas
@subsection ``Unsafe'' Simplifications
 22742,22752 
Simplification also replaces an equation or inequality with
1 or 0 (``true'' or ``false'') if it can through the use of
! declarations. If @expr{x} is declared to be an integer greater
! than 5, then @expr{x < 3}, @expr{x = 3}, and @expr{x = 7.5} are
! all simplified to 0, but @expr{x > 3} is simplified to 1.
! By a similar analysis, @expr{abs(x) >= 0} is simplified to 1,
! as is @expr{x^2 >= 0} if @expr{x} is known to be real.
@node Unsafe Simplifications, Simplification of Units, Algebraic
Simplifications, Simplifying Formulas
@subsection ``Unsafe'' Simplifications
***************
*** 22519,22526 ****
are valid. The symbolic integrator uses @kbd{a e};
one effect of this is that the integrator's results must be used with
caution. Where an integral table will often attach conditions like
! ``for positive @cite{a} only,'' Calc (like most other symbolic
! integration programs) will simply produce an unqualified address@hidden
Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
to type @kbd{Cu 3 a v}, which does extended simplification only
 22768,22775 
are valid. The symbolic integrator uses @kbd{a e};
one effect of this is that the integrator's results must be used with
caution. Where an integral table will often attach conditions like
! ``for positive @expr{a} only,'' Calc (like most other symbolic
! integration programs) will simply produce an unqualified result.
Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
to type @kbd{Cu 3 a v}, which does extended simplification only
***************
*** 22542,22586 ****
Inverse trigonometric or hyperbolic functions, called with their
corresponding noninverse functions as arguments, are simplified
! by @kbd{a e}. For example, @address@hidden(@t{sin}(x))} changes
! to @cite{x}. Also, @address@hidden(@t{cos}(x))} and
! @address@hidden(@t{sin}(x))} both change to @address@hidden/2  x}.
These simplifications are unsafe because they are valid only for
! values of @cite{x} in a certain range; outside that range, values
are folded down to the 360degree range that the inverse trigonometric
functions always produce.
! Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$}
! @cite{x^(a b)}
! for all @cite{a} and @cite{b}. These results will be valid only
! in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$}
! @cite{(x^2)^1:2}
! the powers cancel to get @cite{x}, which is valid for positive values
! of @cite{x} but not for negative or complex values.
!
! Similarly, @address@hidden(x^a)} and @address@hidden(x)^a} are both
! simplified (possibly unsafely) to @c{$x^{a/2}$}
! @cite{x^(a/2)}.
! Forms like @address@hidden(1  @t{sin}(x)^2)} are simplified to, e.g.,
! @address@hidden(x)}. Calc has identities of this sort for @code{sin},
@code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.
Arguments of square roots are partially factored to look for
squared terms that can be extracted. For example,
! @address@hidden(a^2 b^3 + a^3 b^2)} simplifies to @cite{a b @t{sqrt}(a+b)}.
! The simplifications of @address@hidden(@t{exp}(x))},
@address@hidden(@t{e}^x)},
! and @address@hidden(10^x)} to @cite{x} are also unsafe because
! of problems with principal values (although these simplifications
! are safe if @cite{x} is known to be real).
Common factors are cancelled from products on both sides of an
! equation, even if those factors may be zero: @cite{a x / b x}
! to @cite{a / b}. Such factors are never cancelled from
inequalities: Even @kbd{a e} is not bold enough to reduce
! @cite{a x < b x} to @cite{a < b} (or @cite{a > b}, depending
! on whether you believe @cite{x} is positive or negative).
The @kbd{a M /} command can be used to divide a factor out of
both sides of an inequality.
 22791,22839 
Inverse trigonometric or hyperbolic functions, called with their
corresponding noninverse functions as arguments, are simplified
! by @kbd{a e}. For example, @address@hidden(@t{sin}(x))} changes
! to @expr{x}. Also, @address@hidden(@t{cos}(x))} and
! @address@hidden(@t{sin}(x))} both change to @address@hidden/2  x}.
These simplifications are unsafe because they are valid only for
! values of @expr{x} in a certain range; outside that range, values
are folded down to the 360degree range that the inverse trigonometric
functions always produce.
! Powers of powers @expr{(x^a)^b} are simplified to
! @texline @tmath{x^{a b}}
! @infoline @expr{x^(a b)}
! for all @expr{a} and @expr{b}. These results will be valid only
! in a restricted range of @expr{x}; for example, in
! @texline @tmath{(x^2)^{1:2}}
! @infoline @expr{(x^2)^1:2}
! the powers cancel to get @expr{x}, which is valid for positive values
! of @expr{x} but not for negative or complex values.
!
! Similarly, @address@hidden(x^a)} and @address@hidden(x)^a} are both
! simplified (possibly unsafely) to
! @texline @tmath{x^{a/2}}.
! @infoline @expr{x^(a/2)}.
! Forms like @address@hidden(1  sin(x)^2)} are simplified to, e.g.,
! @address@hidden(x)}. Calc has identities of this sort for @code{sin},
@code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.
Arguments of square roots are partially factored to look for
squared terms that can be extracted. For example,
! @address@hidden(a^2 b^3 + a^3 b^2)} simplifies to
! @expr{a b @t{sqrt}(a+b)}.
! The simplifications of @address@hidden(@t{exp}(x))},
! @address@hidden(@t{e}^x)}, and @address@hidden(10^x)} to @expr{x} are also
! unsafe because of problems with principal values (although these
! simplifications are safe if @expr{x} is known to be real).
Common factors are cancelled from products on both sides of an
! equation, even if those factors may be zero: @expr{a x / b x}
! to @expr{a / b}. Such factors are never cancelled from
inequalities: Even @kbd{a e} is not bold enough to reduce
! @expr{a x < b x} to @expr{a < b} (or @expr{a > b}, depending
! on whether you believe @expr{x} is positive or negative).
The @kbd{a M /} command can be used to divide a factor out of
both sides of an inequality.
***************
*** 22600,22611 ****
Scalar mode is automatically put into effect when simplifying units.
@xref{Matrix Mode}.
! Sums @cite{a + b} involving units are simplified by extracting the
! units of @cite{a} as if by the @kbd{u x} command (call the result
! @cite{u_a}), then simplifying the expression @cite{b / u_a}
using @kbd{u b} and @kbd{u s}. If the result has units then the sum
is inconsistent and is left alone. Otherwise, it is rewritten
! in terms of the units @cite{u_a}.
If units autoranging mode is enabled, products or quotients in
which the first argument is a number which is out of range for the
 22853,22864 
Scalar mode is automatically put into effect when simplifying units.
@xref{Matrix Mode}.
! Sums @expr{a + b} involving units are simplified by extracting the
! units of @expr{a} as if by the @kbd{u x} command (call the result
! @expr{u_a}), then simplifying the expression @expr{b / u_a}
using @kbd{u b} and @kbd{u s}. If the result has units then the sum
is inconsistent and is left alone. Otherwise, it is rewritten
! in terms of the units @expr{u_a}.
If units autoranging mode is enabled, products or quotients in
which the first argument is a number which is out of range for the
***************
*** 22617,22655 ****
However, compatible but different units like @code{ft} and @code{in}
are not combined in this way.
! Quotients @cite{a / b} are simplified in three additional ways. First,
! if @cite{b} is a number or a product beginning with a number, Calc
computes the reciprocal of this number and moves it to the numerator.
Second, for each pair of unit names from the numerator and denominator
of a quotient, if the units are compatible (e.g., they are both
units of area) then they are replaced by the ratio between those
units. For example, in @samp{3 s in N / kg cm} the units
! @samp{in / cm} will be replaced by @cite{2.54}.
Third, if the units in the quotient exactly cancel out, so that
a @kbd{u b} command on the quotient would produce a dimensionless
number for an answer, then the quotient simplifies to that number.
For powers and square roots, the ``unsafe'' simplifications
! @cite{(a b)^c} to @cite{a^c b^c}, @cite{(a/b)^c} to @cite{a^c / b^c},
! and @cite{(a^b)^c} to @c{$a^{b c}$}
! @cite{a^(b c)} are done if the powers are
! real numbers. (These are safe in the context of units because
! all numbers involved can reasonably be assumed to be real.)
Also, if a unit name is raised to a fractional power, and the
base units in that unit name all occur to powers which are a
multiple of the denominator of the power, then the unit name
is expanded out into its base units, which can then be simplified
according to the previous paragraph. For example, @samp{acre^1.5}
! is simplified by noting that @cite{1.5 = 3:2}, that @samp{acre}
is defined in terms of @samp{m^2}, and that the 2 in the power of
! @code{m} is a multiple of 2 in @cite{3:2}. Thus, @code{acre^1.5} is
! replaced by approximately @c{$(4046 m^2)^{1.5}$}
! @cite{(4046 m^2)^1.5}, which is then
! changed to @c{$4046^{1.5} \, (m^2)^{1.5}$}
! @cite{4046^1.5 (m^2)^1.5}, then to @cite{257440 m^3}.
The functions @code{float}, @code{frac}, @code{clean}, @code{abs},
as well as @code{floor} and the other integer truncation functions,
 22870,22913 
However, compatible but different units like @code{ft} and @code{in}
are not combined in this way.
! Quotients @expr{a / b} are simplified in three additional ways. First,
! if @expr{b} is a number or a product beginning with a number, Calc
computes the reciprocal of this number and moves it to the numerator.
Second, for each pair of unit names from the numerator and denominator
of a quotient, if the units are compatible (e.g., they are both
units of area) then they are replaced by the ratio between those
units. For example, in @samp{3 s in N / kg cm} the units
! @samp{in / cm} will be replaced by @expr{2.54}.
Third, if the units in the quotient exactly cancel out, so that
a @kbd{u b} command on the quotient would produce a dimensionless
number for an answer, then the quotient simplifies to that number.
For powers and square roots, the ``unsafe'' simplifications
! @expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c},
! and @expr{(a^b)^c} to
! @texline @tmath{a^{b c}}
! @infoline @expr{a^(b c)}
! are done if the powers are real numbers. (These are safe in the context
! of units because all numbers involved can reasonably be assumed to be
! real.)
Also, if a unit name is raised to a fractional power, and the
base units in that unit name all occur to powers which are a
multiple of the denominator of the power, then the unit name
is expanded out into its base units, which can then be simplified
according to the previous paragraph. For example, @samp{acre^1.5}
! is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre}
is defined in terms of @samp{m^2}, and that the 2 in the power of
! @code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is
! replaced by approximately
! @texline @tmath{(4046 m^2)^{1.5}}
! @infoline @expr{(4046 m^2)^1.5},
! which is then changed to
! @texline @tmath{4046^{1.5} \, (m^2)^{1.5}},
! @infoline @expr{4046^1.5 (m^2)^1.5},
! then to @expr{257440 m^3}.
The functions @code{float}, @code{frac}, @code{clean}, @code{abs},
as well as @code{floor} and the other integer truncation functions,
***************
*** 22667,22676 ****
@section Polynomials
A @dfn{polynomial} is a sum of terms which are coefficients times
! various powers of a ``base'' variable. For example, @cite{2 x^2 + 3 x  4}
! is a polynomial in @cite{x}. Some formulas can be considered
! polynomials in several different variables: @cite{1 + 2 x + 3 y + 4 x y^2}
! is a polynomial in both @cite{x} and @cite{y}. Polynomial coefficients
are often numbers, but they may in general be any formulas not
involving the base variable.
 22925,22934 
@section Polynomials
A @dfn{polynomial} is a sum of terms which are coefficients times
! various powers of a ``base'' variable. For example, @expr{2 x^2 + 3 x  4}
! is a polynomial in @expr{x}. Some formulas can be considered
! polynomials in several different variables: @expr{1 + 2 x + 3 y + 4 x y^2}
! is a polynomial in both @expr{x} and @expr{y}. Polynomial coefficients
are often numbers, but they may in general be any formulas not
involving the base variable.
***************
*** 22679,22687 ****
@tindex factor
The @kbd{a f} (@code{calcfactor}) address@hidden command factors a
polynomial into a product of terms. For example, the polynomial
! @cite{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another
! example, @cite{a c + b d + b c + a d} is factored into the product
! @cite{(a + b) (c + d)}.
Calc currently has three algorithms for factoring. Formulas which are
linear in several variables, such as the second example above, are
 22937,22945 
@tindex factor
The @kbd{a f} (@code{calcfactor}) address@hidden command factors a
polynomial into a product of terms. For example, the polynomial
! @expr{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another
! example, @expr{a c + b d + b c + a d} is factored into the product
! @expr{(a + b) (c + d)}.
Calc currently has three algorithms for factoring. Formulas which are
linear in several variables, such as the second example above, are
***************
*** 22689,22695 ****
polynomials in a single variable, with constant integer or fractional
coefficients, are factored into irreducible linear and/or quadratic
terms. The first example above factors into three linear terms
! (@cite{x}, @cite{x+1}, and @cite{x+1} again). Finally, formulas
which do not fit the above criteria are handled by the algebraic
rewrite mechanism.
 22947,22953 
polynomials in a single variable, with constant integer or fractional
coefficients, are factored into irreducible linear and/or quadratic
terms. The first example above factors into three linear terms
! (@expr{x}, @expr{x+1}, and @expr{x+1} again). Finally, formulas
which do not fit the above criteria are handled by the algebraic
rewrite mechanism.
***************
*** 22721,22727 ****
@code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the
operation of rewrite rules. The default @code{FactorRules} are able
to factor quadratic forms symbolically into two linear terms,
! @cite{(a x + b) (c x + d)}. You can edit these rules to include other
cases if you wish. To use the rules, Calc builds the formula
@samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
base variable and @code{a}, @code{b}, etc., are polynomial coefficients
 22979,22985 
@code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the
operation of rewrite rules. The default @code{FactorRules} are able
to factor quadratic forms symbolically into two linear terms,
! @expr{(a x + b) (c x + d)}. You can edit these rules to include other
cases if you wish. To use the rules, Calc builds the formula
@samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
base variable and @code{a}, @code{b}, etc., are polynomial coefficients
***************
*** 22742,22754 ****
but it returns a list of factors instead of an expression which is the
product of the factors. Each factor is represented by a subvector
of the factor, and the power with which it appears. For example,
! @cite{x^5 + x^4  33 x^3 + 63 x^2} factors to @cite{(x + 7) x^2 (x  3)^2}
! in @kbd{a f}, or to @cite{[ [x, 2], [x+7, 1], [x3, 2] ]} in @kbd{H a f}.
If there is an overall numeric factor, it always comes first in the list.
The functions @code{factor} and @code{factors} allow a second argument
! when written in algebraic form; @samp{factor(x,v)} factors @cite{x} with
! respect to the specific variable @cite{v}. The default is to factor with
! respect to all the variables that appear in @cite{x}.
@kindex a c
@pindex calccollect
 23000,23012 
but it returns a list of factors instead of an expression which is the
product of the factors. Each factor is represented by a subvector
of the factor, and the power with which it appears. For example,
! @expr{x^5 + x^4  33 x^3 + 63 x^2} factors to @expr{(x + 7) x^2 (x  3)^2}
! in @kbd{a f}, or to @expr{[ [x, 2], [x+7, 1], [x3, 2] ]} in @kbd{H a f}.
If there is an overall numeric factor, it always comes first in the list.
The functions @code{factor} and @code{factors} allow a second argument
! when written in algebraic form; @samp{factor(x,v)} factors @expr{x} with
! respect to the specific variable @expr{v}. The default is to factor with
! respect to all the variables that appear in @expr{x}.
@kindex a c
@pindex calccollect
***************
*** 22756,22767 ****
The @kbd{a c} (@code{calccollect}) address@hidden command rearranges a
formula as a
polynomial in a given variable, ordered in decreasing powers of that
! variable. For example, given @cite{1 + 2 x + 3 y + 4 x y^2} on
! the stack, @kbd{a c x} would produce @cite{(2 + 4 y^2) x + (1 + 3 y)},
! and @kbd{a c y} would produce @cite{(4 x) y^2 + 3 y + (1 + 2 x)}.
The polynomial will be expanded out using the distributive law as
! necessary: Collecting @cite{x} in @cite{(x  1)^3} produces
! @cite{x^3  3 x^2 + 3 x  1}. Terms not involving @cite{x} will
not be expanded.
The ``variable'' you specify at the prompt can actually be any
 23014,23025 
The @kbd{a c} (@code{calccollect}) address@hidden command rearranges a
formula as a
polynomial in a given variable, ordered in decreasing powers of that
! variable. For example, given @expr{1 + 2 x + 3 y + 4 x y^2} on
! the stack, @kbd{a c x} would produce @expr{(2 + 4 y^2) x + (1 + 3 y)},
! and @kbd{a c y} would produce @expr{(4 x) y^2 + 3 y + (1 + 2 x)}.
The polynomial will be expanded out using the distributive law as
! necessary: Collecting @expr{x} in @expr{(x  1)^3} produces
! @expr{x^3  3 x^2 + 3 x  1}. Terms not involving @expr{x} will
not be expanded.
The ``variable'' you specify at the prompt can actually be any
***************
*** 22790,22799 ****
do not do.)
Calc's automatic simplifications will sometimes reverse a partial
! expansion. For example, the first step in expanding @cite{(x+1)^3} is
! to write @cite{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries
to put this formula onto the stack, though, Calc will automatically
! simplify it back to @cite{(x+1)^3} form. The solution is to turn
simplification off first (@pxref{Simplification Modes}), or to run
@kbd{a x} without a numeric prefix argument so that it expands all
the way in one step.
 23048,23057 
do not do.)
Calc's automatic simplifications will sometimes reverse a partial
! expansion. For example, the first step in expanding @expr{(x+1)^3} is
! to write @expr{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries
to put this formula onto the stack, though, Calc will automatically
! simplify it back to @expr{(x+1)^3} form. The solution is to turn
simplification off first (@pxref{Simplification Modes}), or to run
@kbd{a x} without a numeric prefix argument so that it expands all
the way in one step.
***************
*** 22814,22834 ****
@tindex nrat
The @kbd{a n} (@code{calcnormalizerat}) address@hidden command
attempts to arrange a formula into a quotient of two polynomials.
! For example, given @cite{1 + (a + b/c) / d}, the result would be
! @cite{(b + a c + c d) / c d}. The quotient is reduced, so that
! @kbd{a n} will simplify @cite{(x^2 + 2x + 1) / (x^2  1)} by dividing
! out the common factor @cite{x + 1}, yielding @cite{(x + 1) / (x  1)}.
@kindex a \
@pindex calcpolydiv
@tindex pdiv
The @kbd{a \} (@code{calcpolydiv}) address@hidden command divides
! two polynomials @cite{u} and @cite{v}, yielding a new polynomial
! @cite{q}. If several variables occur in the inputs, the inputs are
considered multivariate polynomials. (Calc divides by the variable
! with the largest power in @cite{u} first, or, in the case of equal
powers, chooses the variables in alphabetical order.) For example,
! dividing @cite{x^2 + 3 x + 2} by @cite{x + 2} yields @cite{x + 1}.
The remainder from the division, if any, is reported at the bottom
of the screen and is also placed in the Trail along with the quotient.
 23072,23092 
@tindex nrat
The @kbd{a n} (@code{calcnormalizerat}) address@hidden command
attempts to arrange a formula into a quotient of two polynomials.
! For example, given @expr{1 + (a + b/c) / d}, the result would be
! @expr{(b + a c + c d) / c d}. The quotient is reduced, so that
! @kbd{a n} will simplify @expr{(x^2 + 2x + 1) / (x^2  1)} by dividing
! out the common factor @expr{x + 1}, yielding @expr{(x + 1) / (x  1)}.
@kindex a \
@pindex calcpolydiv
@tindex pdiv
The @kbd{a \} (@code{calcpolydiv}) address@hidden command divides
! two polynomials @expr{u} and @expr{v}, yielding a new polynomial
! @expr{q}. If several variables occur in the inputs, the inputs are
considered multivariate polynomials. (Calc divides by the variable
! with the largest power in @expr{u} first, or, in the case of equal
powers, chooses the variables in alphabetical order.) For example,
! dividing @expr{x^2 + 3 x + 2} by @expr{x + 2} yields @expr{x + 1}.
The remainder from the division, if any, is reported at the bottom
of the screen and is also placed in the Trail along with the quotient.
***************
*** 22842,22850 ****
@pindex calcpolyrem
@tindex prem
The @kbd{a %} (@code{calcpolyrem}) address@hidden command divides
! two polynomials and keeps the remainder @cite{r}. The quotient
! @cite{q} is discarded. For any formulas @cite{a} and @cite{b}, the
! results of @kbd{a \} and @kbd{a %} satisfy @cite{a = q b + r}.
(This is analogous to plain @kbd{\} and @kbd{%}, which compute the
integer quotient and remainder from dividing two numbers.)
 23100,23108 
@pindex calcpolyrem
@tindex prem
The @kbd{a %} (@code{calcpolyrem}) address@hidden command divides
! two polynomials and keeps the remainder @expr{r}. The quotient
! @expr{q} is discarded. For any formulas @expr{a} and @expr{b}, the
! results of @kbd{a \} and @kbd{a %} satisfy @expr{a = q b + r}.
(This is analogous to plain @kbd{\} and @kbd{%}, which compute the
integer quotient and remainder from dividing two numbers.)
***************
*** 22855,22864 ****
@tindex pdivide
The @kbd{a /} (@code{calcpolydivrem}) address@hidden command
divides two polynomials and reports both the quotient and the
! remainder as a vector @cite{[q, r]}. The @kbd{H a /} address@hidden
command divides two polynomials and constructs the formula
! @cite{q + r/b} on the stack. (Naturally if the remainder is zero,
! this will immediately simplify to @cite{q}.)
@kindex a g
@pindex calcpolygcd
 23113,23122 
@tindex pdivide
The @kbd{a /} (@code{calcpolydivrem}) address@hidden command
divides two polynomials and reports both the quotient and the
! remainder as a vector @expr{[q, r]}. The @kbd{H a /} address@hidden
command divides two polynomials and constructs the formula
! @expr{q + r/b} on the stack. (Naturally if the remainder is zero,
! this will immediately simplify to @expr{q}.)
@kindex a g
@pindex calcpolygcd
***************
*** 22936,22943 ****
If you use the @code{deriv} function directly in an algebraic formula,
you can write @samp{deriv(f,x,x0)} which represents the derivative
! of @cite{f} with respect to @cite{x}, evaluated at the point @c{$x=x_0$}
! @cite{x=x0}.
If the formula being differentiated contains functions which Calc does
not know, the derivatives of those functions are produced by adding
 23194,23202 
If you use the @code{deriv} function directly in an algebraic formula,
you can write @samp{deriv(f,x,x0)} which represents the derivative
! of @expr{f} with respect to @expr{x}, evaluated at the point
! @texline @tmath{x=x_0}.
! @infoline @expr{x=x0}.
If the formula being differentiated contains functions which Calc does
not know, the derivatives of those functions are produced by adding
***************
*** 22960,22966 ****
Various higherorder derivatives can be formed in the obvious way, e.g.,
@samp{f'@var{}'(x)} (the second derivative of @code{f}) or
@samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each
! argument once)address@hidden
@node Integration, Customizing the Integrator, Differentiation, Calculus
@subsection Integration
 23219,23225 
Various higherorder derivatives can be formed in the obvious way, e.g.,
@samp{f'@var{}'(x)} (the second derivative of @code{f}) or
@samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each
! argument once).
@node Integration, Customizing the Integrator, Differentiation, Calculus
@subsection Integration
***************
*** 22975,22985 ****
all integrable functions, but it is able to integrate several large
classes of formulas. In particular, any polynomial or rational function
(a polynomial divided by a polynomial) is acceptable. (Rational functions
! don't have to be in explicit quotient form, however; @c{$x/(1+x^{2})$}
! @cite{x/(1+x^2)}
is not strictly a quotient of polynomials, but it is equivalent to
! @cite{x^3/(x^2+1)}, which is.) Also, square roots of terms involving
! @cite{x} and @cite{x^2} may appear in rational functions being
integrated. Finally, rational functions involving trigonometric or
hyperbolic functions can be integrated.
 23234,23245 
all integrable functions, but it is able to integrate several large
classes of formulas. In particular, any polynomial or rational function
(a polynomial divided by a polynomial) is acceptable. (Rational functions
! don't have to be in explicit quotient form, however;
! @texline @tmath{x/(1+x^{2})}
! @infoline @expr{x/(1+x^2)}
is not strictly a quotient of polynomials, but it is equivalent to
! @expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving
! @expr{x} and @expr{x^2} may appear in rational functions being
integrated. Finally, rational functions involving trigonometric or
hyperbolic functions can be integrated.
***************
*** 23000,23016 ****
Please note that the current implementation of Calc's integrator sometimes
produces results that are significantly more complex than they need to
! be. For example, the integral Calc finds for @c{$1/(x+\sqrt{x^2+1})$}
! @cite{1/(x+sqrt(x^2+1))}
is several times more complicated than the answer Mathematica
returns for the same input, although the two forms are numerically
equivalent. Also, any indefinite integral should be considered to have
an arbitrary constant of integration added to it, although Calc does not
write an explicit constant of integration in its result. For example,
! Calc's solution for @c{$1/(1+\tan x)$}
! @cite{1/(1+tan(x))} differs from the solution given
! in the @emph{CRC Math Tables} by a constant factor of @c{$\pi i / 2$}
! @cite{pi i / 2},
due to a different choice of constant of integration.
The Calculator remembers all the integrals it has done. If conditions
 23260,23280 
Please note that the current implementation of Calc's integrator sometimes
produces results that are significantly more complex than they need to
! be. For example, the integral Calc finds for
! @texline @tmath{1/(x+\sqrt{x^2+1})}
! @infoline @expr{1/(x+sqrt(x^2+1))}
is several times more complicated than the answer Mathematica
returns for the same input, although the two forms are numerically
equivalent. Also, any indefinite integral should be considered to have
an arbitrary constant of integration added to it, although Calc does not
write an explicit constant of integration in its result. For example,
! Calc's solution for
! @texline @tmath{1/(1+\tan x)}
! @infoline @expr{1/(1+tan(x))}
! differs from the solution given in the @emph{CRC Math Tables} by a
! constant factor of
! @texline @tmath{\pi i / 2}
! @infoline @expr{pi i / 2},
due to a different choice of constant of integration.
The Calculator remembers all the integrals it has done. If conditions
***************
*** 23068,23075 ****
@tindex Ei
As a more serious example, the expression @samp{exp(x)/x} cannot be
integrated in terms of the standard functions, so the ``exponential
! integral'' function @c{${\rm Ei}(x)$}
! @cite{Ei(x)} was invented to describe it.
We can get Calc to do this integral in terms of a madeup @code{Ei}
function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]}
to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack
 23332,23341 
@tindex Ei
As a more serious example, the expression @samp{exp(x)/x} cannot be
integrated in terms of the standard functions, so the ``exponential
! integral'' function
! @texline @tmath{{\rm Ei}(x)}
! @infoline @expr{Ei(x)}
! was invented to describe it.
We can get Calc to do this integral in terms of a madeup @code{Ei}
function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]}
to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack
***************
*** 23215,23221 ****
You may specify the number of terms with a numeric prefix argument;
otherwise the command will prompt you for the number of terms. Note that
many series expansions have coefficients of zero for some terms, so you
! may appear to get fewer terms than you asked address@hidden
If the @kbd{a i} command is unable to find a symbolic integral for a
function, you can get an approximation by integrating the function's
 23481,23487 
You may specify the number of terms with a numeric prefix argument;
otherwise the command will prompt you for the number of terms. Note that
many series expansions have coefficients of zero for some terms, so you
! may appear to get fewer terms than you asked for.
If the @kbd{a i} command is unable to find a symbolic integral for a
function, you can get an approximation by integrating the function's
***************
*** 23232,23259 ****
@cindex Solving equations
The @kbd{a S} (@code{calcsolvefor}) address@hidden command rearranges
an equation to solve for a specific variable. An equation is an
! expression of the form @cite{L = R}. For example, the command @kbd{a S x}
! will rearrange @cite{y = 3x + 6} to the form, @cite{x = y/3  2}. If the
input is not an equation, it is treated like an equation of the
! form @cite{X = 0}.
! This command also works for inequalities, as in @cite{y < 3x + 6}.
Some inequalities cannot be solved where the analogous equation could
! be; for example, solving @c{$a < b \, c$}
! @cite{a < b c} for @cite{b} is impossible
! without knowing the sign of @cite{c}. In this case, @kbd{a S} will
! produce the result @c{$b \mathbin{\hbox{\code{!=}}} a/c$}
! @cite{b != a/c} (using the notequalto operator)
! to signify that the direction of the inequality is now unknown. The
! inequality @c{$a \le b \, c$}
! @cite{a <= b c} is not even partially solved.
! @xref{Declarations}, for a way to tell Calc that the signs of the
! variables in a formula are in fact known.
Two useful commands for working with the result of @kbd{a S} are
! @kbd{a .} (@pxref{Logical Operations}), which converts @cite{x = y/3  2}
! to @cite{y/3  2}, and @kbd{s l} (@pxref{Let Command}) which evaluates
! another formula with @cite{x} set equal to @cite{y/3  2}.
@menu
* Multiple Solutions::
 23498,23529 
@cindex Solving equations
The @kbd{a S} (@code{calcsolvefor}) address@hidden command rearranges
an equation to solve for a specific variable. An equation is an
! expression of the form @expr{L = R}. For example, the command @kbd{a S x}
! will rearrange @expr{y = 3x + 6} to the form, @expr{x = y/3  2}. If the
input is not an equation, it is treated like an equation of the
! form @expr{X = 0}.
! This command also works for inequalities, as in @expr{y < 3x + 6}.
Some inequalities cannot be solved where the analogous equation could
! be; for example, solving
! @texline @tmath{a < b \, c}
! @infoline @expr{a < b c}
! for @expr{b} is impossible
! without knowing the sign of @expr{c}. In this case, @kbd{a S} will
! produce the result
! @texline @tmath{b \mathbin{\hbox{\code{!=}}} a/c}
! @infoline @expr{b != a/c}
! (using the notequalto operator) to signify that the direction of the
! inequality is now unknown. The inequality
! @texline @tmath{a \le b \, c}
! @infoline @expr{a <= b c}
! is not even partially solved. @xref{Declarations}, for a way to tell
! Calc that the signs of the variables in a formula are in fact known.
Two useful commands for working with the result of @kbd{a S} are
! @kbd{a .} (@pxref{Logical Operations}), which converts @expr{x = y/3  2}
! to @expr{y/3  2}, and @kbd{s l} (@pxref{Let Command}) which evaluates
! another formula with @expr{x} set equal to @expr{y/3  2}.
@menu
* Multiple Solutions::
***************
*** 23293,23299 ****
we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides
to get @samp{y = x^2}. This is correct, except that it introduces
some dubious solutions. Consider solving @samp{sqrt(y) = 3}:
! Calc will report @cite{y = 9} as a valid solution, which is true
in the mathematical sense of squareroot, but false (there is no
solution) for the actual Calc positivevalued @code{sqrt}. This
happens for both @kbd{a S} and @kbd{H a S}.
 23563,23569 
we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides
to get @samp{y = x^2}. This is correct, except that it introduces
some dubious solutions. Consider solving @samp{sqrt(y) = 3}:
! Calc will report @expr{y = 9} as a valid solution, which is true
in the mathematical sense of squareroot, but false (there is no
solution) for the actual Calc positivevalued @code{sqrt}. This
happens for both @kbd{a S} and @kbd{H a S}.
***************
*** 23337,23343 ****
With the Inverse flag, @kbd{I a S} address@hidden treats the expression
on top of the stack as a function of the specified variable and solves
to find the inverse function, written in terms of the same variable.
! For example, @kbd{I a S x} inverts @cite{2x + 6} to @cite{x/2  3}.
You can use both Inverse and Hyperbolic address@hidden to obtain a
fully general inverse, as described above.
 23607,23613 
With the Inverse flag, @kbd{I a S} address@hidden treats the expression
on top of the stack as a function of the specified variable and solves
to find the inverse function, written in terms of the same variable.
! For example, @kbd{I a S x} inverts @expr{2x + 6} to @expr{x/2  3}.
You can use both Inverse and Hyperbolic address@hidden to obtain a
fully general inverse, as described above.
***************
*** 23361,23372 ****
Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver
symbolic solutions if the polynomial has symbolic coefficients. Also
note that Calc's solver is not able to get exact symbolic solutions
! to all polynomials. Polynomials containing powers up to @cite{x^4}
can always be solved exactly; polynomials of higher degree sometimes
! can be: @cite{x^6 + x^3 + 1} is converted to @cite{(x^3)^2 + (x^3) + 1},
! which can be solved for @cite{x^3} using the quadratic equation, and then
! for @cite{x} by taking cube roots. But in many cases, like
! @cite{x^6 + x + 1}, Calc does not know how to rewrite the polynomial
into a form it can solve. The @kbd{a P} command can still deliver a
list of numerical roots, however, provided that symbolic mode (@kbd{m s})
is not turned on. (If you work with symbolic mode on, recall that the
 23631,23642 
Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver
symbolic solutions if the polynomial has symbolic coefficients. Also
note that Calc's solver is not able to get exact symbolic solutions
! to all polynomials. Polynomials containing powers up to @expr{x^4}
can always be solved exactly; polynomials of higher degree sometimes
! can be: @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1},
! which can be solved for @expr{x^3} using the quadratic equation, and then
! for @expr{x} by taking cube roots. But in many cases, like
! @expr{x^6 + x + 1}, Calc does not know how to rewrite the polynomial
into a form it can solve. The @kbd{a P} command can still deliver a
list of numerical roots, however, provided that symbolic mode (@kbd{m s})
is not turned on. (If you work with symbolic mode on, recall that the
***************
*** 23392,23398 ****
have the same length as the variables vector, and the variables
will be listed in the same order there. Note that the solutions
are not always simplified as far as possible; the solution for
! @cite{x} here could be improved by an application of the @kbd{a n}
command.
Calc's algorithm works by trying to eliminate one variable at a
 23662,23668 
have the same length as the variables vector, and the variables
will be listed in the same order there. Note that the solutions
are not always simplified as far as possible; the solution for
! @expr{x} here could be improved by an application of the @kbd{a n}
command.
Calc's algorithm works by trying to eliminate one variable at a
***************
*** 23453,23475 ****
The @code{poly} function takes a polynomial and a variable as
arguments, and returns a vector of polynomial coefficients (constant
coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns
! @cite{[0, 2, 0, 1]}. If the input is not a polynomial in @cite{x},
the call to @code{poly} is left in symbolic form. If the input does
! not involve the variable @cite{x}, the input is returned in a list
of length one, representing a polynomial with only a constant
! coefficient. The call @samp{poly(x, x)} returns the vector @cite{[0, 1]}.
The last element of the returned vector is guaranteed to be nonzero;
! note that @samp{poly(0, x)} returns the empty vector @cite{[]}.
! Note also that @cite{x} may actually be any formula; for example,
! @samp{poly(sin(x)^2  sin(x) + 3, sin(x))} returns @cite{[3, 1, 1]}.
@cindex Coefficients of polynomial
@cindex Degree of polynomial
! To get the @cite{x^k} coefficient of polynomial @cite{p}, use
! @samp{poly(p, x)_(k+1)}. To get the degree of polynomial @cite{p},
use @samp{vlen(poly(p, x))  1}. For example, @samp{poly((x+1)^4, x)}
returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)}
! gives the @cite{x^2} coefficient of this polynomial, 6.
@ignore
@starindex
 23723,23745 
The @code{poly} function takes a polynomial and a variable as
arguments, and returns a vector of polynomial coefficients (constant
coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns
! @expr{[0, 2, 0, 1]}. If the input is not a polynomial in @expr{x},
the call to @code{poly} is left in symbolic form. If the input does
! not involve the variable @expr{x}, the input is returned in a list
of length one, representing a polynomial with only a constant
! coefficient. The call @samp{poly(x, x)} returns the vector @expr{[0, 1]}.
The last element of the returned vector is guaranteed to be nonzero;
! note that @samp{poly(0, x)} returns the empty vector @expr{[]}.
! Note also that @expr{x} may actually be any formula; for example,
! @samp{poly(sin(x)^2  sin(x) + 3, sin(x))} returns @expr{[3, 1, 1]}.
@cindex Coefficients of polynomial
@cindex Degree of polynomial
! To get the @expr{x^k} coefficient of polynomial @expr{p}, use
! @samp{poly(p, x)_(k+1)}. To get the degree of polynomial @expr{p},
use @samp{vlen(poly(p, x))  1}. For example, @samp{poly((x+1)^4, x)}
returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)}
! gives the @expr{x^2} coefficient of this polynomial, 6.
@ignore
@starindex
***************
*** 23494,23506 ****
is considered trivial.
For example, @samp{gpoly((x2)^2, x)} returns @samp{[x, [4, 4, 1], 1]},
! since the expanded form of this polynomial is @cite{4  4 x + x^2}.
The term @var{x} may itself be a polynomial in @var{var}. This is
done to reduce the size of the @var{c} vector. For example,
@samp{gpoly(x^4 + x^2  1, x)} returns @samp{[x^2, [1, 1, 1], 1]},
! since a quadratic polynomial in @cite{x^2} is easier to solve than
! a quartic polynomial in @cite{x}.
A few more examples of the kinds of polynomials @code{gpoly} can
discover:
 23764,23776 
is considered trivial.
For example, @samp{gpoly((x2)^2, x)} returns @samp{[x, [4, 4, 1], 1]},
! since the expanded form of this polynomial is @expr{4  4 x + x^2}.
The term @var{x} may itself be a polynomial in @var{var}. This is
done to reduce the size of the @var{c} vector. For example,
@samp{gpoly(x^4 + x^2  1, x)} returns @samp{[x^2, [1, 1, 1], 1]},
! since a quadratic polynomial in @expr{x^2} is easier to solve than
! a quartic polynomial in @expr{x}.
A few more examples of the kinds of polynomials @code{gpoly} can
discover:
***************
*** 23517,23523 ****
The @code{poly} and @code{gpoly} functions accept a third integer argument
which specifies the largest degree of polynomial that is acceptable.
! If this is @cite{n}, then only @var{c} vectors of length @cite{n+1}
or less will be returned. Otherwise, the @code{poly} or @code{gpoly}
call will remain in symbolic form. For example, the equation solver
can handle quartics and smaller polynomials, so it calls
 23787,23793 
The @code{poly} and @code{gpoly} functions accept a third integer argument
which specifies the largest degree of polynomial that is acceptable.
! If this is @expr{n}, then only @var{c} vectors of length @expr{n+1}
or less will be returned. Otherwise, the @code{poly} or @code{gpoly}
call will remain in symbolic form. For example, the equation solver
can handle quartics and smaller polynomials, so it calls
***************
*** 23549,23555 ****
Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},
though again more efficient. In particular, @samp{plead((2x+1)^10, x)}
returns 1024 without expanding out the list of coefficients. The
! value of @code{plead(p,x)} will be zero only if @cite{p = 0}.
@ignore
@starindex
 23819,23825 
Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},
though again more efficient. In particular, @samp{plead((2x+1)^10, x)}
returns 1024 without expanding out the list of coefficients. The
! value of @code{plead(p,x)} will be zero only if @expr{p = 0}.
@ignore
@starindex
***************
*** 23618,23624 ****
The @kbd{a R} (@code{calcfindroot}) address@hidden command finds a
numerical solution (or @dfn{root}) of an equation. (This command treats
inequalities the same as equations. If the input is any other kind
! of formula, it is interpreted as an equation of the form @cite{X = 0}.)
The @kbd{a R} command requires an initial guess on the top of the
stack, and a formula in the secondtotop position. It prompts for a
 23888,23894 
The @kbd{a R} (@code{calcfindroot}) address@hidden command finds a
numerical solution (or @dfn{root}) of an equation. (This command treats
inequalities the same as equations. If the input is any other kind
! of formula, it is interpreted as an equation of the form @expr{X = 0}.)
The @kbd{a R} command requires an initial guess on the top of the
stack, and a formula in the secondtotop position. It prompts for a
***************
*** 23704,23725 ****
with the minimum value itself.
Note that this command looks for a @emph{local} minimum. Many functions
! have more than one minimum; some, like @c{$x \sin x$}
! @cite{x sin(x)}, have infinitely
! many. In fact, there is no easy way to define the ``global'' minimum
! of @c{$x \sin x$}
! @cite{x sin(x)} but Calc can still locate any particular local minimum
for you. Calc basically goes downhill from the initial guess until it
finds a point at which the function's value is greater both to the left
and to the right. Calc does not use derivatives when minimizing a function.
If your initial guess is an interval and it looks like the minimum
occurs at one or the other endpoint of the interval, Calc will return
! that endpoint only if that endpoint is closed; thus, minimizing @cite{17 x}
! over @cite{[2..3]} will return @cite{[2, 38]}, but minimizing over
! @cite{(2..3]} would report no minimum found. In general, you should
use closed intervals to find literally the minimum value in that
! range of @cite{x}, or open intervals to find the local minimum, if
any, that happens to lie in that range.
Most functions are smooth and flat near their minimum values. Because
 23974,23998 
with the minimum value itself.
Note that this command looks for a @emph{local} minimum. Many functions
! have more than one minimum; some, like
! @texline @tmath{x \sin x},
! @infoline @expr{x sin(x)},
! have infinitely many. In fact, there is no easy way to define the
! ``global'' minimum of
! @texline @tmath{x \sin x}
! @infoline @expr{x sin(x)}
! but Calc can still locate any particular local minimum
for you. Calc basically goes downhill from the initial guess until it
finds a point at which the function's value is greater both to the left
and to the right. Calc does not use derivatives when minimizing a function.
If your initial guess is an interval and it looks like the minimum
occurs at one or the other endpoint of the interval, Calc will return
! that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x}
! over @expr{[2..3]} will return @expr{[2, 38]}, but minimizing over
! @expr{(2..3]} would report no minimum found. In general, you should
use closed intervals to find literally the minimum value in that
! range of @expr{x}, or open intervals to find the local minimum, if
any, that happens to lie in that range.
Most functions are smooth and flat near their minimum values. Because
***************
*** 23781,23789 ****
@noindent
The @kbd{a F} command fits a set of data to a @dfn{model formula},
! such as @cite{y = m x + b} where @cite{m} and @cite{b} are parameters
to be determined. For a typical set of measured data there will be
! no single @cite{m} and @cite{b} that exactly fit the data; in this
case, Calc chooses values of the parameters that provide the closest
possible fit.
 24054,24062 
@noindent
The @kbd{a F} command fits a set of data to a @dfn{model formula},
! such as @expr{y = m x + b} where @expr{m} and @expr{b} are parameters
to be determined. For a typical set of measured data there will be
! no single @expr{m} and @expr{b} that exactly fit the data; in this
case, Calc chooses values of the parameters that provide the closest
possible fit.
***************
*** 23806,23851 ****
@cindex Linear regression
@cindex Leastsquares fits
The @kbd{a F} (@code{calccurvefit}) address@hidden command attempts
! to fit a set of data (@cite{x} and @cite{y} vectors of numbers) to a
! straight line, polynomial, or other function of @cite{x}. For the
moment we will consider only the case of fitting to a line, and we
will ignore the issue of whether or not the model was in fact a good
fit for the data.
! In a standard linear leastsquares fit, we have a set of @cite{(x,y)}
! data points that we wish to fit to the model @cite{y = m x + b}
! by adjusting the parameters @cite{m} and @cite{b} to make the @cite{y}
values calculated from the formula be as close as possible to the actual
! @cite{y} values in the data set. (In a polynomial fit, the model is
! instead, say, @cite{y = a x^3 + b x^2 + c x + d}. In a multilinear fit,
! we have data points of the form @cite{(x_1,x_2,x_3,y)} and our model is
! @cite{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.)
!
! In the model formula, variables like @cite{x} and @cite{x_2} are called
! the @dfn{independent variables}, and @cite{y} is the @dfn{dependent
! variable}. Variables like @cite{m}, @cite{a}, and @cite{b} are called
the @dfn{parameters} of the model.
The @kbd{a F} command takes the data set to be fitted from the stack.
By default, it expects the data in the form of a matrix. For example,
! for a linear or polynomial fit, this would be a @c{$2\times N$}
! @asis{2xN} matrix where
! the first row is a list of @cite{x} values and the second row has the
! corresponding @cite{y} values. For the multilinear fit shown above,
! the matrix would have four rows (@cite{x_1}, @cite{x_2}, @cite{x_3}, and
! @cite{y}, respectively).
!
! If you happen to have an @c{$N\times2$}
! @asis{Nx2} matrix instead of a @c{$2\times N$}
! @asis{2xN} matrix,
! just press @kbd{v t} first to transpose the matrix.
After you type @kbd{a F}, Calc prompts you to select a model. For a
linear fit, press the digit @kbd{1}.
Calc then prompts for you to name the variables. By default it chooses
! high letters like @cite{x} and @cite{y} for independent variables and
! low letters like @cite{a} and @cite{b} for parameters. (The dependent
variable doesn't need a name.) The two kinds of variables are separated
by a semicolon. Since you generally care more about the names of the
independent variables than of the parameters, Calc also allows you to
 24079,24128 
@cindex Linear regression
@cindex Leastsquares fits
The @kbd{a F} (@code{calccurvefit}) address@hidden command attempts
! to fit a set of data (@expr{x} and @expr{y} vectors of numbers) to a
! straight line, polynomial, or other function of @expr{x}. For the
moment we will consider only the case of fitting to a line, and we
will ignore the issue of whether or not the model was in fact a good
fit for the data.
! In a standard linear leastsquares fit, we have a set of @expr{(x,y)}
! data points that we wish to fit to the model @expr{y = m x + b}
! by adjusting the parameters @expr{m} and @expr{b} to make the @expr{y}
values calculated from the formula be as close as possible to the actual
! @expr{y} values in the data set. (In a polynomial fit, the model is
! instead, say, @expr{y = a x^3 + b x^2 + c x + d}. In a multilinear fit,
! we have data points of the form @expr{(x_1,x_2,x_3,y)} and our model is
! @expr{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.)
!
! In the model formula, variables like @expr{x} and @expr{x_2} are called
! the @dfn{independent variables}, and @expr{y} is the @dfn{dependent
! variable}. Variables like @expr{m}, @expr{a}, and @expr{b} are called
the @dfn{parameters} of the model.
The @kbd{a F} command takes the data set to be fitted from the stack.
By default, it expects the data in the form of a matrix. For example,
! for a linear or polynomial fit, this would be a
! @texline @tmath{2\times N}
! @infoline 2xN
! matrix where the first row is a list of @expr{x} values and the second
! row has the corresponding @expr{y} values. For the multilinear fit
! shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2},
! @expr{x_3}, and @expr{y}, respectively).
!
! If you happen to have an
! @texline @tmath{N\times2}
! @infoline Nx2
! matrix instead of a
! @texline @tmath{2\times N}
! @infoline 2xN
! matrix, just press @kbd{v t} first to transpose the matrix.
After you type @kbd{a F}, Calc prompts you to select a model. For a
linear fit, press the digit @kbd{1}.
Calc then prompts for you to name the variables. By default it chooses
! high letters like @expr{x} and @expr{y} for independent variables and
! low letters like @expr{a} and @expr{b} for parameters. (The dependent
variable doesn't need a name.) The two kinds of variables are separated
by a semicolon. Since you generally care more about the names of the
independent variables than of the parameters, Calc also allows you to
***************
*** 23874,23890 ****
@noindent
is on the stack and we wish to do a simple linear fit. Type
@kbd{a F}, then @kbd{1} for the model, then @key{RET} to use
! the default names. The result will be the formula @cite{3 + 2 x}
on the stack. Calc has created the model expression @kbd{a + b x},
! then found the optimal values of @cite{a} and @cite{b} to fit the
data. (In this case, it was able to find an exact fit.) Calc then
! substituted those values for @cite{a} and @cite{b} in the model
formula.
The @kbd{a F} command puts two entries in the trail. One is, as
always, a copy of the result that went to the stack; the other is
a vector of the actual parameter values, written as equations:
! @cite{[a = 3, b = 2]}, in case you'd rather read them in a list
than pick them out of the formula. (You can type @kbd{t y}
to move this vector to the stack; see @ref{Trail Commands}.
 24151,24167 
@noindent
is on the stack and we wish to do a simple linear fit. Type
@kbd{a F}, then @kbd{1} for the model, then @key{RET} to use
! the default names. The result will be the formula @expr{3 + 2 x}
on the stack. Calc has created the model expression @kbd{a + b x},
! then found the optimal values of @expr{a} and @expr{b} to fit the
data. (In this case, it was able to find an exact fit.) Calc then
! substituted those values for @expr{a} and @expr{b} in the model
formula.
The @kbd{a F} command puts two entries in the trail. One is, as
always, a copy of the result that went to the stack; the other is
a vector of the actual parameter values, written as equations:
! @expr{[a = 3, b = 2]}, in case you'd rather read them in a list
than pick them out of the formula. (You can type @kbd{t y}
to move this vector to the stack; see @ref{Trail Commands}.
***************
*** 23930,23946 ****
@end tex
@noindent
! which is clearly zero if @cite{a + b x} exactly fits all data points,
! and increases as various @cite{a + b x_i} values fail to match the
! corresponding @cite{y_i} values. There are several reasons why the
! summand is squared, one of them being to ensure that @c{$\chi^2 \ge 0$}
! @cite{chi^2 >= 0}.
! Leastsquares fitting simply chooses the values of @cite{a} and @cite{b}
! for which the error @c{$\chi^2$}
! @cite{chi^2} is as small as possible.
Other kinds of models do the same thing but with a different model
! formula in place of @cite{a + b x_i}.
@tex
\bigskip
 24207,24226 
@end tex
@noindent
! which is clearly zero if @expr{a + b x} exactly fits all data points,
! and increases as various @expr{a + b x_i} values fail to match the
! corresponding @expr{y_i} values. There are several reasons why the
! summand is squared, one of them being to ensure that
! @texline @tmath{\chi^2 \ge 0}.
! @infoline @expr{chi^2 >= 0}.
! Leastsquares fitting simply chooses the values of @expr{a} and @expr{b}
! for which the error
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
! is as small as possible.
Other kinds of models do the same thing but with a different model
! formula in place of @expr{a + b x_i}.
@tex
\bigskip
***************
*** 23953,23961 ****
is always one independent variable and one dependent variable.
A prefix of zero or plain @kbd{Cu} is a compromise; Calc takes two
! items from the stack, an @var{n}row matrix of @cite{x} values, and a
! vector of @cite{y} values. If there is only one independent variable,
! the @cite{x} values can be either a onerow matrix or a plain vector,
in which case the @kbd{Cu} prefix is the same as a @address@hidden 2}}
prefix.
@node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits,
Curve Fitting
 24233,24241 
is always one independent variable and one dependent variable.
A prefix of zero or plain @kbd{Cu} is a compromise; Calc takes two
! items from the stack, an @var{n}row matrix of @expr{x} values, and a
! vector of @expr{y} values. If there is only one independent variable,
! the @expr{x} values can be either a onerow matrix or a plain vector,
in which case the @kbd{Cu} prefix is the same as a @address@hidden 2}}
prefix.
@node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits,
Curve Fitting
***************
*** 23974,23988 ****
Note that since the constant and linear terms are enough to fit the
data exactly, it's no surprise that Calc chose a tiny contribution
! for @cite{x^2}. (The fact that it's not exactly zero is due only
to roundoff error. Since our data are exact integers, we could get
an exact answer by typing @kbd{m f} first to get fraction mode.
! Then the @cite{x^2} term would vanish altogether. Usually, though,
the data being fitted will be approximate floats so fraction mode
won't help.)
Doing the @kbd{a F 2} fit on the data set with 14 instead of 13
! gives a much larger @cite{x^2} contribution, as Calc bends the
line slightly to improve the fit.
@example
 24254,24268 
Note that since the constant and linear terms are enough to fit the
data exactly, it's no surprise that Calc chose a tiny contribution
! for @expr{x^2}. (The fact that it's not exactly zero is due only
to roundoff error. Since our data are exact integers, we could get
an exact answer by typing @kbd{m f} first to get fraction mode.
! Then the @expr{x^2} term would vanish altogether. Usually, though,
the data being fitted will be approximate floats so fraction mode
won't help.)
Doing the @kbd{a F 2} fit on the data set with 14 instead of 13
! gives a much larger @expr{x^2} contribution, as Calc bends the
line slightly to improve the fit.
@example
***************
*** 24000,24006 ****
@end example
The actual coefficients we get with a precision of 12, like
! @cite{0.0416666663588}, clearly suffer from loss of precision.
It is a good idea to increase the working precision to several
digits beyond what you need when you do a fitting operation.
Or, if your data are exact, use fraction mode to get exact
 24280,24286 
@end example
The actual coefficients we get with a precision of 12, like
! @expr{0.0416666663588}, clearly suffer from loss of precision.
It is a good idea to increase the working precision to several
digits beyond what you need when you do a fitting operation.
Or, if your data are exact, use fraction mode to get exact
***************
*** 24023,24030 ****
@end tex
Another generalization of the linear model is to assume the
! @cite{y} values are a sum of linear contributions from several
! @cite{x} values. This is a @dfn{multilinear} fit, and it is also
selected by the @kbd{1} digit key. (Calc decides whether the fit
is linear or multilinear by counting the rows in the data matrix.)
 24303,24310 
@end tex
Another generalization of the linear model is to assume the
! @expr{y} values are a sum of linear contributions from several
! @expr{x} values. This is a @dfn{multilinear} fit, and it is also
selected by the @kbd{1} digit key. (Calc decides whether the fit
is linear or multilinear by counting the rows in the data matrix.)
***************
*** 24039,24047 ****
@end example
@noindent
! the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the
! second row @cite{y}, and will fit the values in the third row to the
! model @cite{a + b x + c y}.
@example
8. + 3. x + 0.5 y
 24319,24327 
@end example
@noindent
! the command @kbd{a F 1 @key{RET}} will call the first row @expr{x} and the
! second row @expr{y}, and will fit the values in the third row to the
! model @expr{a + b x + c y}.
@example
8. + 3. x + 0.5 y
***************
*** 24056,24075 ****
Yet another variation is @dfn{homogeneous} linear models, in which
the constant term is known to be zero. In the linear case, this
! means the model formula is simply @cite{a x}; in the multilinear
! case, the model might be @cite{a x + b y + c z}; and in the polynomial
! case, the model could be @cite{a x + b x^2 + c x^3}. You can get
a homogeneous linear or multilinear model by pressing the letter
@kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}.
It is certainly possible to have other constrained linear models,
! like @cite{2.3 + a x} or @cite{a  4 x}. While there is no single
key to select models like these, a later section shows how to enter
any desired model by hand. In the first case, for example, you
would enter @kbd{a F ' 2.3 + a x}.
Another class of models that will work but must be entered by hand
! are multinomial fits, e.g., @cite{a + b x + c y + d x^2 + e y^2 + f x y}.
@node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and
Multilinear Fits, Curve Fitting
@subsection Error Estimates for Fits
 24336,24355 
Yet another variation is @dfn{homogeneous} linear models, in which
the constant term is known to be zero. In the linear case, this
! means the model formula is simply @expr{a x}; in the multilinear
! case, the model might be @expr{a x + b y + c z}; and in the polynomial
! case, the model could be @expr{a x + b x^2 + c x^3}. You can get
a homogeneous linear or multilinear model by pressing the letter
@kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}.
It is certainly possible to have other constrained linear models,
! like @expr{2.3 + a x} or @expr{a  4 x}. While there is no single
key to select models like these, a later section shows how to enter
any desired model by hand. In the first case, for example, you
would enter @kbd{a F ' 2.3 + a x}.
Another class of models that will work but must be entered by hand
! are multinomial fits, e.g., @expr{a + b x + c y + d x^2 + e y^2 + f x y}.
@node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and
Multilinear Fits, Curve Fitting
@subsection Error Estimates for Fits
***************
*** 24096,24104 ****
or all be plain numbers. Error forms can go anywhere but generally
go on the numbers in the last row of the data matrix. If the last
row contains error forms
! address@hidden@w{ @t{+/} address@hidden
! @var{sigma_i}', then the @c{$\chi^2$}
! @cite{chi^2}
statistic is now,
@ifinfo
 24376,24386 
or all be plain numbers. Error forms can go anywhere but generally
go on the numbers in the last row of the data matrix. If the last
row contains error forms
! @texline address@hidden@w{ @t{+/} address@hidden',
! @infoline address@hidden@w{ @t{+/} address@hidden',
! then the
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
statistic is now,
@ifinfo
***************
*** 24119,24142 ****
If there are error forms on other rows of the data matrix, all the
errors for a given data point are combined; the square root of the
! sum of the squares of the errors forms the @c{$\sigma_i$}
! @cite{sigma_i} used for
! the data point.
Both @kbd{a F} and @kbd{H a F} can accept error forms in the input
matrix, although if you are concerned about error analysis you will
probably use @kbd{H a F} so that the output also contains error
estimates.
! If the input contains error forms but all the @c{$\sigma_i$}
! @cite{sigma_i} values are
! the same, it is easy to see that the resulting fitted model will be
! the same as if the input did not have error forms at all (@c{$\chi^2$}
! @cite{chi^2}
! is simply scaled uniformly by @c{$1 / \sigma^2$}
! @cite{1 / sigma^2}, which doesn't affect
! where it has a minimum). But there @emph{will} be a difference
! in the estimated errors of the coefficients reported by @kbd{H a F}.
Consult any text on statistical modeling of data for a discussion
of where these error estimates come from and how they should be
 24401,24429 
If there are error forms on other rows of the data matrix, all the
errors for a given data point are combined; the square root of the
! sum of the squares of the errors forms the
! @texline @tmath{\sigma_i}
! @infoline @expr{sigma_i}
! used for the data point.
Both @kbd{a F} and @kbd{H a F} can accept error forms in the input
matrix, although if you are concerned about error analysis you will
probably use @kbd{H a F} so that the output also contains error
estimates.
! If the input contains error forms but all the
! @texline @tmath{\sigma_i}
! @infoline @expr{sigma_i}
! values are the same, it is easy to see that the resulting fitted model
! will be the same as if the input did not have error forms at all
! @texline (@tmath{\chi^2}
! @infoline (@expr{chi^2}
! is simply scaled uniformly by
! @texline @tmath{1 / \sigma^2},
! @infoline @expr{1 / sigma^2},
! which doesn't affect where it has a minimum). But there @emph{will} be
! a difference in the estimated errors of the coefficients reported by
! @kbd{H a F}.
Consult any text on statistical modeling of data for a discussion
of where these error estimates come from and how they should be
***************
*** 24161,24214 ****
A vector of ``raw'' parameter values for the model. These are the
polynomial coefficients or other parameters as plain numbers, in the
same order as the parameters appeared in the final prompt of the
! @kbd{I a F} command. For polynomials of degree @cite{d}, this vector
! will have length @cite{M = d+1} with the constant term first.
@item
! The covariance matrix @cite{C} computed from the fit. This is
an @address@hidden symmetric matrix; the diagonal elements
! @c{$C_{jj}$}
! @cite{C_j_j} are the variances @c{$\sigma_j^2$}
! @cite{sigma_j^2} of the parameters.
! The other elements are covariances @c{$\sigma_{ij}^2$}
! @cite{sigma_i_j^2} that describe the
! correlation between pairs of parameters. (A related set of
! numbers, the @dfn{linear correlation coefficients} @c{$r_{ij}$}
! @cite{r_i_j},
! are defined as @c{$\sigma_{ij}^2 / \sigma_i \, \sigma_j$}
! @cite{sigma_i_j^2 / sigma_i sigma_j}.)
@item
! A vector of @cite{M} ``parameter filter'' functions whose
meanings are described below. If no filters are necessary this
will instead be an empty vector; this is always the case for the
polynomial and multilinear fits described so far.
@item
! The value of @c{$\chi^2$}
! @cite{chi^2} for the fit, calculated by the formulas
! shown above. This gives a measure of the quality of the fit;
! statisticians consider @c{$\chi^2 \approx N  M$}
! @cite{chi^2 = N  M} to indicate a moderately good fit
! (where again @cite{N} is the number of data points and @cite{M}
! is the number of parameters).
@item
! A measure of goodness of fit expressed as a probability @cite{Q}.
This is computed from the @code{utpc} probability distribution
! function using @c{$\chi^2$}
! @cite{chi^2} with @cite{N  M} degrees of freedom. A
value of 0.5 implies a good fit; some texts recommend that often
! @cite{Q = 0.1} or even 0.001 can signify an acceptable fit. In
! particular, @c{$\chi^2$}
! @cite{chi^2} statistics assume the errors in your inputs
follow a normal (Gaussian) distribution; if they don't, you may
! have to accept smaller values of @cite{Q}.
! The @cite{Q} value is computed only if the input included error
estimates. Otherwise, Calc will report the symbol @code{nan}
! for @cite{Q}. The reason is that in this case the @c{$\chi^2$}
! @cite{chi^2}
value has effectively been used to estimate the original errors
in the input, and thus there is no redundant information left
over to use for a confidence test.
 24448,24513 
A vector of ``raw'' parameter values for the model. These are the
polynomial coefficients or other parameters as plain numbers, in the
same order as the parameters appeared in the final prompt of the
! @kbd{I a F} command. For polynomials of degree @expr{d}, this vector
! will have length @expr{M = d+1} with the constant term first.
@item
! The covariance matrix @expr{C} computed from the fit. This is
an @address@hidden symmetric matrix; the diagonal elements
! @texline @tmath{C_{jj}}
! @infoline @expr{C_j_j}
! are the variances
! @texline @tmath{\sigma_j^2}
! @infoline @expr{sigma_j^2}
! of the parameters. The other elements are covariances
! @texline @tmath{\sigma_{ij}^2}
! @infoline @expr{sigma_i_j^2}
! that describe the correlation between pairs of parameters. (A related
! set of numbers, the @dfn{linear correlation coefficients}
! @texline @tmath{r_{ij}},
! @infoline @expr{r_i_j},
! are defined as
! @texline @tmath{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.)
! @infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.)
@item
! A vector of @expr{M} ``parameter filter'' functions whose
meanings are described below. If no filters are necessary this
will instead be an empty vector; this is always the case for the
polynomial and multilinear fits described so far.
@item
! The value of
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
! for the fit, calculated by the formulas shown above. This gives a
! measure of the quality of the fit; statisticians consider
! @texline @tmath{\chi^2 \approx N  M}
! @infoline @expr{chi^2 = N  M}
! to indicate a moderately good fit (where again @expr{N} is the number of
! data points and @expr{M} is the number of parameters).
@item
! A measure of goodness of fit expressed as a probability @expr{Q}.
This is computed from the @code{utpc} probability distribution
! function using
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
! with @expr{N  M} degrees of freedom. A
value of 0.5 implies a good fit; some texts recommend that often
! @expr{Q = 0.1} or even 0.001 can signify an acceptable fit. In
! particular,
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
! statistics assume the errors in your inputs
follow a normal (Gaussian) distribution; if they don't, you may
! have to accept smaller values of @expr{Q}.
! The @expr{Q} value is computed only if the input included error
estimates. Otherwise, Calc will report the symbol @code{nan}
! for @expr{Q}. The reason is that in this case the
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
value has effectively been used to estimate the original errors
in the input, and thus there is no redundant information left
over to use for a confidence test.
***************
*** 24248,24255 ****
@item q
Quadratic. @i{a + b (xc)^2 + d (xe)^2}.
@item g
! Gaussian. @c{${a \over b \sqrt{2 \pi}} \exp\left( {1 \over 2} \left( x  c
\over b \right)^2 \right)$}
! @i{(a / b sqrt(2 pi)) exp(0.5*((xc)/b)^2)}.
@end table
All of these models are used in the usual way; just press the appropriate
 24547,24555 
@item q
Quadratic. @i{a + b (xc)^2 + d (xe)^2}.
@item g
! Gaussian.
! @texline @tmath{{a \over b \sqrt{2 \pi}} \exp\left( {1 \over 2} \left( x  c
\over b \right)^2 \right)}.
! @infoline @i{(a / b sqrt(2 pi)) exp(0.5*((xc)/b)^2)}.
@end table
All of these models are used in the usual way; just press the appropriate
***************
*** 24260,24271 ****
All models except Gaussian and polynomials can generalize as shown to any
number of independent variables. Also, all the builtin models have an
! additive or multiplicative parameter shown as @cite{a} in the above table
which can be replaced by zero or one, as appropriate, by typing @kbd{h}
before the model key.
Note that many of these models are essentially equivalent, but express
! the parameters slightly differently. For example, @cite{a b^x} and
the other two exponential models are all algebraic rearrangements of
each other. Also, the ``quadratic'' model is just a degree2 polynomial
with the parameters expressed differently. Use whichever form best
 24560,24571 
All models except Gaussian and polynomials can generalize as shown to any
number of independent variables. Also, all the builtin models have an
! additive or multiplicative parameter shown as @expr{a} in the above table
which can be replaced by zero or one, as appropriate, by typing @kbd{h}
before the model key.
Note that many of these models are essentially equivalent, but express
! the parameters slightly differently. For example, @expr{a b^x} and
the other two exponential models are all algebraic rearrangements of
each other. Also, the ``quadratic'' model is just a degree2 polynomial
with the parameters expressed differently. Use whichever form best
***************
*** 24275,24282 ****
fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}.
These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)},
@samp{a exp(b x)}, and @samp{a x^b}, respectively. In each case,
! @cite{a} is what the HP48 identifies as the ``intercept,'' and
! @cite{b} is what it calls the ``slope.''
@tex
\bigskip
 24575,24582 
fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}.
These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)},
@samp{a exp(b x)}, and @samp{a x^b}, respectively. In each case,
! @expr{a} is what the HP48 identifies as the ``intercept,'' and
! @expr{b} is what it calls the ``slope.''
@tex
\bigskip
***************
*** 24287,24299 ****
formula, such as @kbd{m x  b}, as the model. (Not all models
will work, thoughsee the next section for details.)
! The model can also be an equation like @cite{y = m x + b}.
In this case, Calc thinks of all the rows of the data matrix on
equal terms; this model effectively has two parameters
! (@cite{m} and @cite{b}) and two independent variables (@cite{x}
! and @cite{y}), with no ``dependent'' variables. Model equations
! do not need to take this @cite{y =} form. For example, the
! implicit line equation @cite{a x + b y = 1} works fine as a
model.
When you enter a model, Calc makes an alphabetical list of all
 24587,24599 
formula, such as @kbd{m x  b}, as the model. (Not all models
will work, thoughsee the next section for details.)
! The model can also be an equation like @expr{y = m x + b}.
In this case, Calc thinks of all the rows of the data matrix on
equal terms; this model effectively has two parameters
! (@expr{m} and @expr{b}) and two independent variables (@expr{x}
! and @expr{y}), with no ``dependent'' variables. Model equations
! do not need to take this @expr{y =} form. For example, the
! implicit line equation @expr{a x + b y = 1} works fine as a
model.
When you enter a model, Calc makes an alphabetical list of all
***************
*** 24303,24314 ****
Calc assumes the dependent variable does not appear in the formula
and thus does not need a name.
! For example, if the model formula has the variables @cite{a,mu,sigma,t,x},
and the data matrix has three rows (meaning two independent variables),
! Calc will use @cite{a,mu,sigma} as the default parameters, and the
! data rows will be named @cite{t} and @cite{x}, respectively. If you
! enter an equation instead of a plain formula, Calc will use @cite{a,mu}
! as the parameters, and @cite{sigma,t,x} as the three independent
variables.
You can, of course, override these choices by entering something
 24603,24614 
Calc assumes the dependent variable does not appear in the formula
and thus does not need a name.
! For example, if the model formula has the variables @expr{a,mu,sigma,t,x},
and the data matrix has three rows (meaning two independent variables),
! Calc will use @expr{a,mu,sigma} as the default parameters, and the
! data rows will be named @expr{t} and @expr{x}, respectively. If you
! enter an equation instead of a plain formula, Calc will use @expr{a,mu}
! as the parameters, and @expr{sigma,t,x} as the three independent
variables.
You can, of course, override these choices by entering something
***************
*** 24332,24342 ****
which are parameters.
Models taken from the stack can also be expressed as vectors of
! two or three elements, @address@hidden, @var{vars}]} or
! @address@hidden, @var{vars}, @var{params}]}. Each of @var{vars}
and @var{params} may be either a variable or a vector of variables.
(If @var{params} is omitted, all variables in @var{model} except
! those listed as @var{vars} are parameters.)@refill
When you enter a model manually with @kbd{'}, Calc puts a 3vector
describing the model in the trail so you can get it back if you wish.
 24632,24642 
which are parameters.
Models taken from the stack can also be expressed as vectors of
! two or three elements, @address@hidden, @var{vars}]} or
! @address@hidden, @var{vars}, @var{params}]}. Each of @var{vars}
and @var{params} may be either a variable or a vector of variables.
(If @var{params} is omitted, all variables in @var{model} except
! those listed as @var{vars} are parameters.)
When you enter a model manually with @kbd{'}, Calc puts a 3vector
describing the model in the trail so you can get it back if you wish.
***************
*** 24364,24377 ****
returns results in the range from @i{90} to 90 degrees (or the
equivalent range in radians). Suppose you had data that you
believed to represent roughly three oscillations of a sine wave,
! so that the argument of the sine might go from zero to @c{$3\times360$}
! @i{3*360} degrees.
The above model would appear to be a good way to determine the
true frequency and phase of the sine wave, but in practice it
would fail utterly. The righthand side of the actual model
! @samp{arcsin(y) = a t + b} will grow smoothly with @cite{t}, but
the lefthand side will bounce back and forth between @i{90} and 90.
! No values of @cite{a} and @cite{b} can make the two sides match,
even approximately.
There is no good solution to this problem at present. You could
 24664,24679 
returns results in the range from @i{90} to 90 degrees (or the
equivalent range in radians). Suppose you had data that you
believed to represent roughly three oscillations of a sine wave,
! so that the argument of the sine might go from zero to
! @texline @tmath{3\times360}
! @infoline @i{3*360}
! degrees.
The above model would appear to be a good way to determine the
true frequency and phase of the sine wave, but in practice it
would fail utterly. The righthand side of the actual model
! @samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but
the lefthand side will bounce back and forth between @i{90} and 90.
! No values of @expr{a} and @expr{b} can make the two sides match,
even approximately.
There is no good solution to this problem at present. You could
***************
*** 24388,24401 ****
@noindent
Calc's internal leastsquares fitter can only handle multilinear
models. More precisely, it can handle any model of the form
! @cite{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @cite{a,b,c}
! are the parameters and @cite{x,y,z} are the independent variables
(of course there can be any number of each, not just three).
In a simple multilinear or polynomial fit, it is easy to see how
to convert the model into this form. For example, if the model
! is @cite{a + b x + c x^2}, then @cite{f(x) = 1}, @cite{g(x) = x},
! and @cite{h(x) = x^2} are suitable functions.
For other models, Calc uses a variety of algebraic manipulations
to try to put the problem into the form
 24690,24703 
@noindent
Calc's internal leastsquares fitter can only handle multilinear
models. More precisely, it can handle any model of the form
! @expr{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @expr{a,b,c}
! are the parameters and @expr{x,y,z} are the independent variables
(of course there can be any number of each, not just three).
In a simple multilinear or polynomial fit, it is easy to see how
to convert the model into this form. For example, if the model
! is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x},
! and @expr{h(x) = x^2} are suitable functions.
For other models, Calc uses a variety of algebraic manipulations
to try to put the problem into the form
***************
*** 24405,24419 ****
@end smallexample
@noindent
! where @cite{Y,A,B,C,F,G,H} are arbitrary functions. It computes
! @cite{Y}, @cite{F}, @cite{G}, and @cite{H} for all the data points,
! does a standard linear fit to find the values of @cite{A}, @cite{B},
! and @cite{C}, then uses the equation solver to solve for @cite{a,b,c}
! in terms of @cite{A,B,C}.
A remarkable number of models can be cast into this general form.
We'll look at two examples here to see how it works. The powerlaw
! model @cite{y = a x^b} with two independent variables and two parameters
can be rewritten as follows:
@example
 24707,24721 
@end smallexample
@noindent
! where @expr{Y,A,B,C,F,G,H} are arbitrary functions. It computes
! @expr{Y}, @expr{F}, @expr{G}, and @expr{H} for all the data points,
! does a standard linear fit to find the values of @expr{A}, @expr{B},
! and @expr{C}, then uses the equation solver to solve for @expr{a,b,c}
! in terms of @expr{A,B,C}.
A remarkable number of models can be cast into this general form.
We'll look at two examples here to see how it works. The powerlaw
! model @expr{y = a x^b} with two independent variables and two parameters
can be rewritten as follows:
@example
***************
*** 24424,24438 ****
@end example
@noindent
! which matches the desired form with @c{$Y = \ln(y)$}
! @cite{Y = ln(y)}, @c{$A = \ln(a)$}
! @cite{A = ln(a)},
! @cite{F = 1}, @cite{B = b}, and @c{$G = \ln(x)$}
! @cite{G = ln(x)}. Calc thus computes
! the logarithms of your @cite{y} and @cite{x} values, does a linear fit
! for @cite{A} and @cite{B}, then solves to get @c{$a = \exp(A)$}
! @cite{a = exp(A)} and
! @cite{b = B}.
Another interesting example is the ``quadratic'' model, which can
be handled by expanding according to the distributive law.
 24726,24744 
@end example
@noindent
! which matches the desired form with
! @texline @tmath{Y = \ln(y)},
! @infoline @expr{Y = ln(y)},
! @texline @tmath{A = \ln(a)},
! @infoline @expr{A = ln(a)},
! @expr{F = 1}, @expr{B = b}, and
! @texline @tmath{G = \ln(x)}.
! @infoline @expr{G = ln(x)}.
! Calc thus computes the logarithms of your @expr{y} and @expr{x} values,
! does a linear fit for @expr{A} and @expr{B}, then solves to get
! @texline @tmath{a = \exp(A)}
! @infoline @expr{a = exp(A)}
! and @expr{b = B}.
Another interesting example is the ``quadratic'' model, which can
be handled by expanding according to the distributive law.
***************
*** 24443,24469 ****
@end example
@noindent
! which matches with @cite{Y = y}, @cite{A = a + b c^2}, @cite{F = 1},
! @cite{B = 2 b c}, @cite{G = x} (the @i{2} factor could just as easily
! have been put into @cite{G} instead of @cite{B}), @cite{C = b}, and
! @cite{H = x^2}.
The Gaussian model looks quite complicated, but a closer examination
shows that it's actually similar to the quadratic model but with an
! exponential that can be brought to the top and moved into @cite{Y}.
An example of a model that cannot be put into general linear
form is a Gaussian with a constant background added on, i.e.,
! @cite{d} + the regular Gaussian formula. If you have a model like
this, your best bet is to replace enough of your parameters with
constants to make the model linearizable, then adjust the constants
manually by doing a series of fits. You can compare the fits by
graphing them, by examining the goodnessoffit measures returned by
@kbd{I a F}, or by some other method suitable to your application.
Note that some models can be linearized in several ways. The
! address@hidden model can be linearized by setting @cite{d}
! (the background) to a constant, or by setting @cite{b} (the standard
! deviation) and @cite{c} (the mean) to constants.
To fit a model with constants substituted for some parameters, just
store suitable values in those parameter variables, then omit them
 24749,24775 
@end example
@noindent
! which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1},
! @expr{B = 2 b c}, @expr{G = x} (the @i{2} factor could just as easily
! have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and
! @expr{H = x^2}.
The Gaussian model looks quite complicated, but a closer examination
shows that it's actually similar to the quadratic model but with an
! exponential that can be brought to the top and moved into @expr{Y}.
An example of a model that cannot be put into general linear
form is a Gaussian with a constant background added on, i.e.,
! @expr{d} + the regular Gaussian formula. If you have a model like
this, your best bet is to replace enough of your parameters with
constants to make the model linearizable, then adjust the constants
manually by doing a series of fits. You can compare the fits by
graphing them, by examining the goodnessoffit measures returned by
@kbd{I a F}, or by some other method suitable to your application.
Note that some models can be linearized in several ways. The
! address@hidden model can be linearized by setting @expr{d}
! (the background) to a constant, or by setting @expr{b} (the standard
! deviation) and @expr{c} (the mean) to constants.
To fit a model with constants substituted for some parameters, just
store suitable values in those parameter variables, then omit them
***************
*** 24475,24482 ****
A last desperate step would be to use the generalpurpose
@code{minimize} function rather than @code{fit}. After all, both
! functions solve the problem of minimizing an expression (the @c{$\chi^2$}
! @cite{chi^2}
sum) by adjusting certain parameters in the expression. The @kbd{a F}
command is able to use a vastly more efficient algorithm due to its
special knowledge about linear chisquare sums, but the @kbd{a N}
 24781,24789 
A last desperate step would be to use the generalpurpose
@code{minimize} function rather than @code{fit}. After all, both
! functions solve the problem of minimizing an expression (the
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
sum) by adjusting certain parameters in the expression. The @kbd{a F}
command is able to use a vastly more efficient algorithm due to its
special knowledge about linear chisquare sums, but the @kbd{a N}
***************
*** 24485,24493 ****
A compromise would be to pick out a few parameters without which the
fit is linearizable, and use @code{minimize} on a call to @code{fit}
which efficiently takes care of the rest of the parameters. The thing
! to be minimized would be the value of @c{$\chi^2$}
! @cite{chi^2} returned as
! the fifth result of the @code{xfit} function:
@smallexample
minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)
 24792,24801 
A compromise would be to pick out a few parameters without which the
fit is linearizable, and use @code{minimize} on a call to @code{fit}
which efficiently takes care of the rest of the parameters. The thing
! to be minimized would be the value of
! @texline @tmath{\chi^2}
! @infoline @expr{chi^2}
! returned as the fifth result of the @code{xfit} function:
@smallexample
minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)
***************
*** 24496,24502 ****
@noindent
where @code{gaus} represents the Gaussian model with background,
@code{data} represents the data matrix, and @code{guess} represents
! the initial guess for @cite{d} that @code{minimize} requires.
This operation will only be, shall we say, extraordinarily slow
rather than astronomically slow (as would be the case if @code{minimize}
were used by itself to solve the problem).
 24804,24810 
@noindent
where @code{gaus} represents the Gaussian model with background,
@code{data} represents the data matrix, and @code{guess} represents
! the initial guess for @expr{d} that @code{minimize} requires.
This operation will only be, shall we say, extraordinarily slow
rather than astronomically slow (as would be the case if @code{minimize}
were used by itself to solve the problem).
***************
*** 24507,24523 ****
The @kbd{I a F} address@hidden command is somewhat trickier when
nonlinear models are used. The second item in the result is the
! vector of ``raw'' parameters @cite{A}, @cite{B}, @cite{C}. The
covariance matrix is written in terms of those raw parameters.
The fifth item is a vector of @dfn{filter} expressions. This
is the empty vector @samp{[]} if the raw parameters were the same
! as the requested parameters, i.e., if @cite{A = a}, @cite{B = b},
and so on (which is always true if the model is already linear
in the parameters as written, e.g., for polynomial fits). If the
parameters had to be rearranged, the fifth item is instead a vector
of one formula per parameter in the original model. The raw
parameters are expressed in these ``filter'' formulas as
! @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} for @cite{B},
and so on.
When Calc needs to modify the model to return the result, it replaces
 24815,24831 
The @kbd{I a F} address@hidden command is somewhat trickier when
nonlinear models are used. The second item in the result is the
! vector of ``raw'' parameters @expr{A}, @expr{B}, @expr{C}. The
covariance matrix is written in terms of those raw parameters.
The fifth item is a vector of @dfn{filter} expressions. This
is the empty vector @samp{[]} if the raw parameters were the same
! as the requested parameters, i.e., if @expr{A = a}, @expr{B = b},
and so on (which is always true if the model is already linear
in the parameters as written, e.g., for polynomial fits). If the
parameters had to be rearranged, the fifth item is instead a vector
of one formula per parameter in the original model. The raw
parameters are expressed in these ``filter'' formulas as
! @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} for @expr{B},
and so on.
When Calc needs to modify the model to return the result, it replaces
***************
*** 24537,24566 ****
nontrivial filter functions.
Things are also complicated when the input contains error forms.
! Suppose there are three independent and dependent variables, @cite{x},
! @cite{y}, and @cite{z}, one or more of which are error forms in the
data. Calc combines all the error values by taking the square root
! of the sum of the squares of the errors. It then changes @cite{x}
! and @cite{y} to be plain numbers, and makes @cite{z} into an error
! form with this combined error. The @cite{Y(x,y,z)} part of the
linearized model is evaluated, and the result should be an error
! form. The error part of that result is used for @c{$\sigma_i$}
! @cite{sigma_i} for
! the data point. If for some reason @cite{Y(x,y,z)} does not return
! an error form, the combined error from @cite{z} is used directly
! for @c{$\sigma_i$}
! @cite{sigma_i}. Finally, @cite{z} is also stripped of its error
! for use in computing @cite{F(x,y,z)}, @cite{G(x,y,z)} and so on;
the righthand side of the linearized model is computed in regular
arithmetic with no error forms.
(While these rules may seem complicated, they are designed to do
! the most reasonable thing in the typical case that @cite{Y(x,y,z)}
! depends only on the dependent variable @cite{z}, and in fact is
! often simply equal to @cite{z}. For common cases like polynomials
and multilinear models, the combined error is simply used as the
! @c{$\sigma$}
! @cite{sigma} for the data point with no further ado.)
@tex
\bigskip
 24845,24877 
nontrivial filter functions.
Things are also complicated when the input contains error forms.
! Suppose there are three independent and dependent variables, @expr{x},
! @expr{y}, and @expr{z}, one or more of which are error forms in the
data. Calc combines all the error values by taking the square root
! of the sum of the squares of the errors. It then changes @expr{x}
! and @expr{y} to be plain numbers, and makes @expr{z} into an error
! form with this combined error. The @expr{Y(x,y,z)} part of the
linearized model is evaluated, and the result should be an error
! form. The error part of that result is used for
! @texline @tmath{\sigma_i}
! @infoline @expr{sigma_i}
! for the data point. If for some reason @expr{Y(x,y,z)} does not return
! an error form, the combined error from @expr{z} is used directly for
! @texline @tmath{\sigma_i}.
! @infoline @expr{sigma_i}.
! Finally, @expr{z} is also stripped of its error
! for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on;
the righthand side of the linearized model is computed in regular
arithmetic with no error forms.
(While these rules may seem complicated, they are designed to do
! the most reasonable thing in the typical case that @expr{Y(x,y,z)}
! depends only on the dependent variable @expr{z}, and in fact is
! often simply equal to @expr{z}. For common cases like polynomials
and multilinear models, the combined error is simply used as the
! @texline @tmath{\sigma}
! @infoline @expr{sigma}
! for the data point with no further ado.)
@tex
\bigskip
***************
*** 24617,24623 ****
@samp{fitparam(2)}, and so on, and independent variables are renamed
to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable
is the highestnumbered @code{fitvar}. For example, the power law
! model @cite{a x^b} is converted to @cite{y = a x^b}, then to
@smallexample
@group
 24928,24934 
@samp{fitparam(2)}, and so on, and independent variables are renamed
to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable
is the highestnumbered @code{fitvar}. For example, the power law
! model @expr{a x^b} is converted to @expr{y = a x^b}, then to
@smallexample
@group
***************
*** 24637,24647 ****
@end example
@noindent
! where @var{Y} is a formula that describes the function @cite{Y(x,y,z)},
! @var{FGH} is the vector of formulas @cite{[F(x,y,z), G(x,y,z), H(x,y,z)]},
and @var{abc} is the vector of parameter filters which refer to the
! raw parameters as @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)}
! for @cite{B}, etc. While the number of raw parameters (the length of
the @var{FGH} vector) is usually the same as the number of original
parameters (the length of the @var{abc} vector), this is not required.
 24948,24958 
@end example
@noindent
! where @var{Y} is a formula that describes the function @expr{Y(x,y,z)},
! @var{FGH} is the vector of formulas @expr{[F(x,y,z), G(x,y,z), H(x,y,z)]},
and @var{abc} is the vector of parameter filters which refer to the
! raw parameters as @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)}
! for @expr{B}, etc. While the number of raw parameters (the length of
the @var{FGH} vector) is usually the same as the number of original
parameters (the length of the @var{abc} vector), this is not required.
***************
*** 24664,24670 ****
nonconstant powers are converted to logsandexponentials form,
and the distributive law is used to expand products of sums.
Quotients are rewritten to use the @samp{fitinv} function, where
! @samp{fitinv(x)} represents @cite{1/x} while the @code{FitRules}
are operating. (The use of @code{fitinv} makes recognition of
linearlooking forms easier.) If you modify @code{FitRules}, you
will probably only need to modify the rules for this phase.
 24975,24981 
nonconstant powers are converted to logsandexponentials form,
and the distributive law is used to expand products of sums.
Quotients are rewritten to use the @samp{fitinv} function, where
! @samp{fitinv(x)} represents @expr{1/x} while the @code{FitRules}
are operating. (The use of @code{fitinv} makes recognition of
linearlooking forms easier.) If you modify @code{FitRules}, you
will probably only need to modify the rules for this phase.
***************
*** 24672,24679 ****
Phase two, whose rules can actually also apply during phases one
and three, first rewrites @code{fitmodel} to a twoargument
form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is
! initially zero and @var{model} has been changed from @cite{a=b}
! to @cite{ab} form. It then tries to peel off invertible functions
from the outside of @var{model} and put them into @var{Y} instead,
calling the equation solver to invert the functions. Finally, when
this is no longer possible, the @code{fitmodel} is changed to a
 24983,24990 
Phase two, whose rules can actually also apply during phases one
and three, first rewrites @code{fitmodel} to a twoargument
form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is
! initially zero and @var{model} has been changed from @expr{a=b}
! to @expr{ab} form. It then tries to peel off invertible functions
from the outside of @var{model} and put them into @var{Y} instead,
calling the equation solver to invert the functions. Finally, when
this is no longer possible, the @code{fitmodel} is changed to a
***************
*** 24719,24725 ****
@tindex hasfitvars
Two functions which are useful in connection with @code{FitRules}
are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check
! whether @cite{x} refers to any parameters or independent variables,
respectively. Specifically, these functions return ``true'' if the
argument contains any @code{fitparam} (or @code{fitvar}) function
calls, and ``false'' otherwise. (Recall that ``true'' means a
 25030,25036 
@tindex hasfitvars
Two functions which are useful in connection with @code{FitRules}
are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check
! whether @expr{x} refers to any parameters or independent variables,
respectively. Specifically, these functions return ``true'' if the
argument contains any @code{fitparam} (or @code{fitvar}) function
calls, and ``false'' otherwise. (Recall that ``true'' means a
***************
*** 24767,24814 ****
@pindex calcpolyinterp
@tindex polint
The @kbd{a p} (@code{calcpolyinterp}) address@hidden command does
! a polynomial interpolation at a particular @cite{x} value. It takes
two arguments from the stack: A data matrix of the sort used by
! @kbd{a F}, and a single number which represents the desired @cite{x}
value. Calc effectively does an exact polynomial fit as if by @kbd{a F i},
! then substitutes the @cite{x} value into the result in order to get an
! approximate @cite{y} value based on the fit. (Calc does not actually
use @kbd{a F i}, however; it uses a direct method which is both more
efficient and more numerically stable.)
! The result of @kbd{a p} is actually a vector of two values: The @cite{y}
! value approximation, and an error measure @cite{dy} that reflects Calc's
estimation of the probable error of the approximation at that value of
! @cite{x}. If the input @cite{x} is equal to any of the @cite{x} values
! in the data matrix, the output @cite{y} will be the corresponding @cite{y}
! value from the matrix, and the output @cite{dy} will be exactly zero.
A prefix argument of 2 causes @kbd{a p} to take separate x and
yvectors from the stack instead of one data matrix.
! If @cite{x} is a vector of numbers, @kbd{a p} will return a matrix of
! interpolated results for each of those @cite{x} values. (The matrix will
! have two columns, the @cite{y} values and the @cite{dy} values.)
! If @cite{x} is a formula instead of a number, the @code{polint} function
remains in symbolic form; use the @kbd{a "} command to expand it out to
a formula that describes the fit in symbolic terms.
In all cases, the @kbd{a p} command leaves the data vectors or matrix
! on the stack. Only the @cite{x} value is replaced by the result.
@kindex H a p
@tindex ratint
The @kbd{H a p} address@hidden command does a rational function
interpolation. It is used exactly like @kbd{a p}, except that it
uses as its model the quotient of two polynomials. If there are
! @cite{N} data points, the numerator and denominator polynomials will
! each have degree @cite{N/2} (if @cite{N} is odd, the denominator will
have degree one higher than the numerator).
Rational approximations have the advantage that they can accurately
describe functions that have poles (points at which the function's value
goes to infinity, so that the denominator polynomial of the approximation
! goes to zero). If @cite{x} corresponds to a pole of the fitted rational
function, then the result will be a division by zero. If Infinite mode
is enabled, the result will be @samp{[uinf, uinf]}.
 25078,25125 
@pindex calcpolyinterp
@tindex polint
The @kbd{a p} (@code{calcpolyinterp}) address@hidden command does
! a polynomial interpolation at a particular @expr{x} value. It takes
two arguments from the stack: A data matrix of the sort used by
! @kbd{a F}, and a single number which represents the desired @expr{x}
value. Calc effectively does an exact polynomial fit as if by @kbd{a F i},
! then substitutes the @expr{x} value into the result in order to get an
! approximate @expr{y} value based on the fit. (Calc does not actually
use @kbd{a F i}, however; it uses a direct method which is both more
efficient and more numerically stable.)
! The result of @kbd{a p} is actually a vector of two values: The @expr{y}
! value approximation, and an error measure @expr{dy} that reflects Calc's
estimation of the probable error of the approximation at that value of
! @expr{x}. If the input @expr{x} is equal to any of the @expr{x} values
! in the data matrix, the output @expr{y} will be the corresponding @expr{y}
! value from the matrix, and the output @expr{dy} will be exactly zero.
A prefix argument of 2 causes @kbd{a p} to take separate x and
yvectors from the stack instead of one data matrix.
! If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of
! interpolated results for each of those @expr{x} values. (The matrix will
! have two columns, the @expr{y} values and the @expr{dy} values.)
! If @expr{x} is a formula instead of a number, the @code{polint} function
remains in symbolic form; use the @kbd{a "} command to expand it out to
a formula that describes the fit in symbolic terms.
In all cases, the @kbd{a p} command leaves the data vectors or matrix
! on the stack. Only the @expr{x} value is replaced by the result.
@kindex H a p
@tindex ratint
The @kbd{H a p} address@hidden command does a rational function
interpolation. It is used exactly like @kbd{a p}, except that it
uses as its model the quotient of two polynomials. If there are
! @expr{N} data points, the numerator and denominator polynomials will
! each have degree @expr{N/2} (if @expr{N} is odd, the denominator will
have degree one higher than the numerator).
Rational approximations have the advantage that they can accurately
describe functions that have poles (points at which the function's value
goes to infinity, so that the denominator polynomial of the approximation
! goes to zero). If @expr{x} corresponds to a pole of the fitted rational
function, then the result will be a division by zero. If Infinite mode
is enabled, the result will be @samp{[uinf, uinf]}.
***************
*** 24842,24850 ****
The choice of index variable is arbitrary, but it's best not to
use a variable with a stored value. In particular, while
@code{i} is often a favorite index variable, it should be avoided
! in Calc because @code{i} has the imaginary constant @cite{(0, 1)}
as a value. If you pressed @kbd{=} on a sum over @code{i}, it would
! be changed to a nonsensical sum over the ``variable'' @cite{(0, 1)}!
If you really want to use @code{i} as an index variable, use
@address@hidden u i @key{RET}}} first to ``unstore'' this variable.
(@xref{Storing Variables}.)
 25153,25161 
The choice of index variable is arbitrary, but it's best not to
use a variable with a stored value. In particular, while
@code{i} is often a favorite index variable, it should be avoided
! in Calc because @code{i} has the imaginary constant @expr{(0, 1)}
as a value. If you pressed @kbd{=} on a sum over @code{i}, it would
! be changed to a nonsensical sum over the ``variable'' @expr{(0, 1)}!
If you really want to use @code{i} as an index variable, use
@address@hidden u i @key{RET}}} first to ``unstore'' this variable.
(@xref{Storing Variables}.)
***************
*** 24878,24884 ****
and @samp{inf}, respectively.
Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)}
! returns @cite{1}. This is done by evaluating the sum in closed
form (to @samp{1.  0.5^n} in this case), then evaluating this
formula with @code{n} set to @code{inf}. Calc's usual rules
for ``infinite'' arithmetic can find the answer from there. If
 25189,25195 
and @samp{inf}, respectively.
Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)}
! returns @expr{1}. This is done by evaluating the sum in closed
form (to @samp{1.  0.5^n} in this case), then evaluating this
formula with @code{n} set to @code{inf}. Calc's usual rules
for ``infinite'' arithmetic can find the answer from there. If
***************
*** 24916,24946 ****
but the sum from @samp{n} to @samp{n2} may report a nonzero value
if Calc used a closed form solution.
! Calc's logical predicates like @cite{a < b} return 1 for ``true''
and 0 for ``false.'' @xref{Logical Operations}. This can be
used to advantage for building conditional sums. For example,
@samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all
prime numbers from 1 to 20; the @code{prime} predicate returns 1 if
its argument is prime and 0 otherwise. You can read this expression
! as ``the sum of @cite{k^2}, where @cite{k} is prime.'' Indeed,
@samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes
squared, since the limits default to plus and minus infinity, but
there are no such sums that Calc's builtin rules can do in
closed form.
As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the
! sum of @cite{f(k)} for all @cite{k} from 1 to @cite{n}, excluding
! one value @cite{k_0}. Slightly more tricky is the summand
@samp{(k != k_0) / (k  k_0)}, which is an attempt to describe
! the sum of all @cite{1/(kk_0)} except at @cite{k = k_0}, where
! this would be a division by zero. But at @cite{k = k_0}, this
! formula works out to the indeterminate form @cite{0 / 0}, which
Calc will not assume is zero. Better would be to use
@samp{(k != k_0) ? 1/(kk_0) : 0}; the @samp{? :} operator does
! an ``ifthenelse'' test: This expression says, ``if @c{$k \ne k_0$}
! @cite{k != k_0},
! then @cite{1/(kk_0)}, else zero.'' Now the formula @cite{1/(kk_0)}
! will not even be evaluated by Calc when @cite{k = k_0}.
@cindex Alternating sums
@kindex a 
 25227,25258 
but the sum from @samp{n} to @samp{n2} may report a nonzero value
if Calc used a closed form solution.
! Calc's logical predicates like @expr{a < b} return 1 for ``true''
and 0 for ``false.'' @xref{Logical Operations}. This can be
used to advantage for building conditional sums. For example,
@samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all
prime numbers from 1 to 20; the @code{prime} predicate returns 1 if
its argument is prime and 0 otherwise. You can read this expression
! as ``the sum of @expr{k^2}, where @expr{k} is prime.'' Indeed,
@samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes
squared, since the limits default to plus and minus infinity, but
there are no such sums that Calc's builtin rules can do in
closed form.
As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the
! sum of @expr{f(k)} for all @expr{k} from 1 to @expr{n}, excluding
! one value @expr{k_0}. Slightly more tricky is the summand
@samp{(k != k_0) / (k  k_0)}, which is an attempt to describe
! the sum of all @expr{1/(kk_0)} except at @expr{k = k_0}, where
! this would be a division by zero. But at @expr{k = k_0}, this
! formula works out to the indeterminate form @expr{0 / 0}, which
Calc will not assume is zero. Better would be to use
@samp{(k != k_0) ? 1/(kk_0) : 0}; the @samp{? :} operator does
! an ``ifthenelse'' test: This expression says, ``if
! @texline @tmath{k \ne k_0},
! @infoline @expr{k != k_0},
! then @expr{1/(kk_0)}, else zero.'' Now the formula @expr{1/(kk_0)}
! will not even be evaluated by Calc when @expr{k = k_0}.
@cindex Alternating sums
@kindex a 
***************
*** 24991,24997 ****
which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''
Note that this means that @address@hidden [ Z ]}} will execute the ``then''
portion if its condition is provably true, but it will execute the
! ``else'' portion for any condition like @cite{a = b} that is not
provably true, even if it might be true. Algebraic functions that
have conditions as arguments, like @code{? :} and @code{&&}, remain
unevaluated if the condition is neither provably true nor provably
 25303,25309 
which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''
Note that this means that @address@hidden [ Z ]}} will execute the ``then''
portion if its condition is provably true, but it will execute the
! ``else'' portion for any condition like @expr{a = b} that is not
provably true, even if it might be true. Algebraic functions that
have conditions as arguments, like @code{? :} and @code{&&}, remain
unevaluated if the condition is neither provably true nor provably
***************
*** 25004,25013 ****
@tindex ==
The @kbd{a =} (@code{calcequalto}) command, or @samp{eq(a,b)} function
(which can also be written @samp{a = b} or @samp{a == b} in an algebraic
! formula) is true if @cite{a} and @cite{b} are equal, either because they
are identical expressions, or because they are numbers which are
numerically equal. (Thus the integer 1 is considered equal to the float
! 1.0.) If the equality of @cite{a} and @cite{b} cannot be determined,
the comparison is left in symbolic form. Note that as a command, this
operation pops two values from the stack and pushes back either a 1 or
a 0, or a formula @samp{a = b} if the values' equality cannot be determined.
 25316,25325 
@tindex ==
The @kbd{a =} (@code{calcequalto}) command, or @samp{eq(a,b)} function
(which can also be written @samp{a = b} or @samp{a == b} in an algebraic
! formula) is true if @expr{a} and @expr{b} are equal, either because they
are identical expressions, or because they are numbers which are
numerically equal. (Thus the integer 1 is considered equal to the float
! 1.0.) If the equality of @expr{a} and @expr{b} cannot be determined,
the comparison is left in symbolic form. Note that as a command, this
operation pops two values from the stack and pushes back either a 1 or
a 0, or a formula @samp{a = b} if the values' equality cannot be determined.
***************
*** 25035,25043 ****
@tindex neq
@tindex !=
The @kbd{a #} (@code{calcnotequalto}) command, or @samp{neq(a,b)} or
! @samp{a != b} function, is true if @cite{a} and @cite{b} are not equal.
This also works with more than two arguments; @samp{a != b != c != d}
! tests that all four of @cite{a}, @cite{b}, @cite{c}, and @cite{d} are
distinct numbers.
@kindex a <
 25347,25355 
@tindex neq
@tindex !=
The @kbd{a #} (@code{calcnotequalto}) command, or @samp{neq(a,b)} or
! @samp{a != b} function, is true if @expr{a} and @expr{b} are not equal.
This also works with more than two arguments; @samp{a != b != c != d}
! tests that all four of @expr{a}, @expr{b}, @expr{c}, and @expr{d} are
distinct numbers.
@kindex a <
***************
*** 25087,25093 ****
@end ignore
@tindex >=
The @kbd{a <} (@code{calclessthan}) address@hidden(a,b)} or @samp{a < b}]
! operation is true if @cite{a} is less than @cite{b}. Similar functions
are @kbd{a >} (@code{calcgreaterthan}) address@hidden(a,b)} or @samp{a >
b}],
@kbd{a [} (@code{calclessequal}) address@hidden(a,b)} or @samp{a <= b}], and
@kbd{a ]} (@code{calcgreaterequal}) address@hidden(a,b)} or @samp{a >= b}].
 25399,25405 
@end ignore
@tindex >=
The @kbd{a <} (@code{calclessthan}) address@hidden(a,b)} or @samp{a < b}]
! operation is true if @expr{a} is less than @expr{b}. Similar functions
are @kbd{a >} (@code{calcgreaterthan}) address@hidden(a,b)} or @samp{a >
b}],
@kbd{a [} (@code{calclessequal}) address@hidden(a,b)} or @samp{a <= b}], and
@kbd{a ]} (@code{calcgreaterequal}) address@hidden(a,b)} or @samp{a >= b}].
***************
*** 25121,25128 ****
@tindex &&
The @kbd{a &} (@code{calclogicaland}) address@hidden(a,b)} or @samp{a && b}]
function is true if both of its arguments are true, i.e., are
! nonzero numbers. In this case, the result will be either @cite{a} or
! @cite{b}, chosen arbitrarily. If either argument is zero, the result is
zero. Otherwise, the formula is left in symbolic form.
@kindex a 
 25433,25440 
@tindex &&
The @kbd{a &} (@code{calclogicaland}) address@hidden(a,b)} or @samp{a && b}]
function is true if both of its arguments are true, i.e., are
! nonzero numbers. In this case, the result will be either @expr{a} or
! @expr{b}, chosen arbitrarily. If either argument is zero, the result is
zero. Otherwise, the formula is left in symbolic form.
@kindex a 
***************
*** 25132,25138 ****
The @kbd{a } (@code{calclogicalor}) address@hidden(a,b)} or @samp{a  b}]
function is true if either or both of its arguments are true (nonzero).
The result is whichever argument was nonzero, choosing arbitrarily if both
! are nonzero. If both @cite{a} and @cite{b} are zero, the result is
zero.
@kindex a !
 25444,25450 
The @kbd{a } (@code{calclogicalor}) address@hidden(a,b)} or @samp{a  b}]
function is true if either or both of its arguments are true (nonzero).
The result is whichever argument was nonzero, choosing arbitrarily if both
! are nonzero. If both @expr{a} and @expr{b} are zero, the result is
zero.
@kindex a !
***************
*** 25140,25147 ****
@tindex lnot
@tindex !
The @kbd{a !} (@code{calclogicalnot}) address@hidden(a)} or @samp{!@: a}]
! function is true if @cite{a} is false (zero), or false if @cite{a} is
! true (nonzero). It is left in symbolic form if @cite{a} is not a
number.
@kindex a :
 25452,25459 
@tindex lnot
@tindex !
The @kbd{a !} (@code{calclogicalnot}) address@hidden(a)} or @samp{!@: a}]
! function is true if @expr{a} is false (zero), or false if @expr{a} is
! true (nonzero). It is left in symbolic form if @expr{a} is not a
number.
@kindex a :
***************
*** 25157,25165 ****
@tindex :
@cindex Arguments, not evaluated
The @kbd{a :} (@code{calclogicalif}) address@hidden(a,b,c)} or @samp{a ? b
:@: c}]
! function is equal to either @cite{b} or @cite{c} if @cite{a} is a nonzero
! number or zero, respectively. If @cite{a} is not a number, the test is
! left in symbolic form and neither @cite{b} nor @cite{c} is evaluated in
any way. In algebraic formulas, this is one of the few Calc functions
whose arguments are not automatically evaluated when the function itself
is evaluated. The others are @code{lambda}, @code{quote}, and
 25469,25477 
@tindex :
@cindex Arguments, not evaluated
The @kbd{a :} (@code{calclogicalif}) address@hidden(a,b,c)} or @samp{a ? b
:@: c}]
! function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero
! number or zero, respectively. If @expr{a} is not a number, the test is
! left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in
any way. In algebraic formulas, this is one of the few Calc functions
whose arguments are not automatically evaluated when the function itself
is evaluated. The others are @code{lambda}, @code{quote}, and
***************
*** 25170,25193 ****
as three separate symbols. Type something like @samp{a ? 3 : 4} or
@samp{a?(3):4} instead.
! As a special case, if @cite{a} evaluates to a vector, then both @cite{b}
! and @cite{c} are evaluated; the result is a vector of the same length
! as @cite{a} whose elements are chosen from corresponding elements of
! @cite{b} and @cite{c} according to whether each element of @cite{a}
! is zero or nonzero. Each of @cite{b} and @cite{c} must be either a
! vector of the same length as @cite{a}, or a nonvector which is matched
! with all elements of @cite{a}.
@kindex a @{
@pindex calcinset
@tindex in
The @kbd{a @{} (@code{calcinset}) address@hidden(a,b)}] function is true if
! the number @cite{a} is in the set of numbers represented by @cite{b}.
! If @cite{b} is an interval form, @cite{a} must be one of the values
! encompassed by the interval. If @cite{b} is a vector, @cite{a} must be
equal to one of the elements of the vector. (If any vector elements are
! intervals, @cite{a} must be in any of the intervals.) If @cite{b} is a
! plain number, @cite{a} must be numerically equal to @cite{b}.
@xref{Set Operations}, for a group of commands that manipulate sets
of this sort.
 25482,25505 
as three separate symbols. Type something like @samp{a ? 3 : 4} or
@samp{a?(3):4} instead.
! As a special case, if @expr{a} evaluates to a vector, then both @expr{b}
! and @expr{c} are evaluated; the result is a vector of the same length
! as @expr{a} whose elements are chosen from corresponding elements of
! @expr{b} and @expr{c} according to whether each element of @expr{a}
! is zero or nonzero. Each of @expr{b} and @expr{c} must be either a
! vector of the same length as @expr{a}, or a nonvector which is matched
! with all elements of @expr{a}.
@kindex a @{
@pindex calcinset
@tindex in
The @kbd{a @{} (@code{calcinset}) address@hidden(a,b)}] function is true if
! the number @expr{a} is in the set of numbers represented by @expr{b}.
! If @expr{b} is an interval form, @expr{a} must be one of the values
! encompassed by the interval. If @expr{b} is a vector, @expr{a} must be
equal to one of the elements of the vector. (If any vector elements are
! intervals, @expr{a} must be in any of the intervals.) If @expr{b} is a
! plain number, @expr{a} must be numerically equal to @expr{b}.
@xref{Set Operations}, for a group of commands that manipulate sets
of this sort.
***************
*** 25196,25202 ****
@end ignore
@tindex typeof
The @samp{typeof(a)} function produces an integer or variable which
! characterizes @cite{a}. If @cite{a} is a number, vector, or variable,
the result will be one of the following numbers:
@example
 25508,25514 
@end ignore
@tindex typeof
The @samp{typeof(a)} function produces an integer or variable which
! characterizes @expr{a}. If @expr{a} is a number, vector, or variable,
the result will be one of the following numbers:
@example
***************
*** 25217,25223 ****
102 Matrix
@end example
! Otherwise, @cite{a} is a formula, and the result is a variable which
represents the name of the toplevel function call.
@ignore
 25529,25535 
102 Matrix
@end example
! Otherwise, @expr{a} is a formula, and the result is a variable which
represents the name of the toplevel function call.
@ignore
***************
*** 25232,25246 ****
@starindex
@end ignore
@tindex constant
! The @samp{integer(a)} function returns true if @cite{a} is an integer.
The @samp{real(a)} function
! is true if @cite{a} is a real number, either integer, fraction, or
! float. The @samp{constant(a)} function returns true if @cite{a} is
any of the objects for which @code{typeof} would produce an integer
code result except for variables, and provided that the components of
an object like a vector or error form are themselves constant.
Note that infinities do not satisfy any of these tests, nor do
! special constants like @code{pi} and @address@hidden
@xref{Declarations}, for a set of similar functions that recognize
formulas as well as actual numbers. For example, @samp{dint(floor(x))}
 25544,25558 
@starindex
@end ignore
@tindex constant
! The @samp{integer(a)} function returns true if @expr{a} is an integer.
The @samp{real(a)} function
! is true if @expr{a} is a real number, either integer, fraction, or
! float. The @samp{constant(a)} function returns true if @expr{a} is
any of the objects for which @code{typeof} would produce an integer
code result except for variables, and provided that the components of
an object like a vector or error form are themselves constant.
Note that infinities do not satisfy any of these tests, nor do
! special constants like @code{pi} and @code{e}.
@xref{Declarations}, for a set of similar functions that recognize
formulas as well as actual numbers. For example, @samp{dint(floor(x))}
***************
*** 25253,25273 ****
@end ignore
@tindex refers
The @samp{refers(a,b)} function is true if the variable (or subexpression)
! @cite{b} appears in @cite{a}, or false otherwise. Unlike the other
tests described here, this function returns a definite ``no'' answer
even if its arguments are still in symbolic form. The only case where
! @code{refers} will be left unevaluated is if @cite{a} is a plain
! variable (different from @cite{b}).
@ignore
@starindex
@end ignore
@tindex negative
! The @samp{negative(a)} function returns true if @cite{a} ``looks'' negative,
! because it is a negative number, because it is of the form @cite{x},
or because it is a product or quotient with a term that looks negative.
This is most useful in rewrite rules. Beware that @samp{negative(a)}
! evaluates to 1 or 0 for @emph{any} argument @cite{a}, so it can only
be stored in a formula if the default simplifications are turned off
first with @kbd{m O} (or if it appears in an unevaluated context such
as a rewrite rule condition).
 25565,25585 
@end ignore
@tindex refers
The @samp{refers(a,b)} function is true if the variable (or subexpression)
! @expr{b} appears in @expr{a}, or false otherwise. Unlike the other
tests described here, this function returns a definite ``no'' answer
even if its arguments are still in symbolic form. The only case where
! @code{refers} will be left unevaluated is if @expr{a} is a plain
! variable (different from @expr{b}).
@ignore
@starindex
@end ignore
@tindex negative
! The @samp{negative(a)} function returns true if @expr{a} ``looks'' negative,
! because it is a negative number, because it is of the form @expr{x},
or because it is a product or quotient with a term that looks negative.
This is most useful in rewrite rules. Beware that @samp{negative(a)}
! evaluates to 1 or 0 for @emph{any} argument @expr{a}, so it can only
be stored in a formula if the default simplifications are turned off
first with @kbd{m O} (or if it appears in an unevaluated context such
as a rewrite rule condition).
***************
*** 25276,25283 ****
@starindex
@end ignore
@tindex variable
! The @samp{variable(a)} function is true if @cite{a} is a variable,
! or false if not. If @cite{a} is a function call, this test is left
in symbolic form. Builtin variables like @code{pi} and @code{inf}
are considered variables like any others by this test.
 25588,25595 
@starindex
@end ignore
@tindex variable
! The @samp{variable(a)} function is true if @expr{a} is a variable,
! or false if not. If @expr{a} is a function call, this test is left
in symbolic form. Builtin variables like @code{pi} and @code{inf}
are considered variables like any others by this test.
***************
*** 25285,25291 ****
@starindex
@end ignore
@tindex nonvar
! The @samp{nonvar(a)} function is true if @cite{a} is a nonvariable.
If its argument is a variable it is left unsimplified; it never
actually returns zero. However, since Calc's conditiontesting
commands consider ``false'' anything not provably true, this is
 25597,25603 
@starindex
@end ignore
@tindex nonvar
! The @samp{nonvar(a)} function is true if @expr{a} is a nonvariable.
If its argument is a variable it is left unsimplified; it never
actually returns zero. However, since Calc's conditiontesting
commands consider ``false'' anything not provably true, this is
***************
*** 25310,25324 ****
@cindex Linearity testing
The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt}
check if an expression is ``linear,'' i.e., can be written in the form
! @cite{a + b x} for some constants @cite{a} and @cite{b}, and some
! variable or subformula @cite{x}. The function @samp{islin(f,x)} checks
! if formula @cite{f} is linear in @cite{x}, returning 1 if so. For
example, @samp{islin(x,x)}, @samp{islin(x,x)}, @samp{islin(3,x)}, and
@samp{islin(x y / 3  2, x)} all return 1. The @samp{lin(f,x)} function
is similar, except that instead of returning 1 it returns the vector
! @cite{[a, b, x]}. For the above examples, this vector would be
! @cite{[0, 1, x]}, @cite{[0, 1, x]}, @cite{[3, 0, x]}, and
! @cite{[2, y/3, x]}, respectively. Both @code{lin} and @code{islin}
generally remain unevaluated for expressions which are not linear,
e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second
argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))}
 25622,25636 
@cindex Linearity testing
The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt}
check if an expression is ``linear,'' i.e., can be written in the form
! @expr{a + b x} for some constants @expr{a} and @expr{b}, and some
! variable or subformula @expr{x}. The function @samp{islin(f,x)} checks
! if formula @expr{f} is linear in @expr{x}, returning 1 if so. For
example, @samp{islin(x,x)}, @samp{islin(x,x)}, @samp{islin(3,x)}, and
@samp{islin(x y / 3  2, x)} all return 1. The @samp{lin(f,x)} function
is similar, except that instead of returning 1 it returns the vector
! @expr{[a, b, x]}. For the above examples, this vector would be
! @expr{[0, 1, x]}, @expr{[0, 1, x]}, @expr{[3, 0, x]}, and
! @expr{[2, y/3, x]}, respectively. Both @code{lin} and @code{islin}
generally remain unevaluated for expressions which are not linear,
e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second
argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))}
***************
*** 25326,25344 ****
The @code{linnt} and @code{islinnt} functions perform a similar check,
but require a ``nontrivial'' linear form, which means that the
! @cite{b} coefficient must be nonzero. For example, @samp{lin(2,x)}
! returns @cite{[2, 0, x]} and @samp{lin(y,x)} returns @cite{[y, 0, x]},
but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated
(in other words, these formulas are considered to be only ``trivially''
! linear in @cite{x}).
All four linearitytesting functions allow you to omit the second
argument, in which case the input may be linear in any nonconstant
! formula. Here, the @cite{a=0}, @cite{b=1} case is also considered
! trivial, and only constant values for @cite{a} and @cite{b} are
! recognized. Thus, @samp{lin(2 x y)} returns @cite{[0, 2, x y]},
! @samp{lin(2  x y)} returns @cite{[2, 1, x y]}, and @samp{lin(x y)}
! returns @cite{[0, 1, x y]}. The @code{linnt} function would allow the
first two cases but not the third. Also, neither @code{lin} nor
@code{linnt} accept plain constants as linear in the oneargument
case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
 25638,25656 
The @code{linnt} and @code{islinnt} functions perform a similar check,
but require a ``nontrivial'' linear form, which means that the
! @expr{b} coefficient must be nonzero. For example, @samp{lin(2,x)}
! returns @expr{[2, 0, x]} and @samp{lin(y,x)} returns @expr{[y, 0, x]},
but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated
(in other words, these formulas are considered to be only ``trivially''
! linear in @expr{x}).
All four linearitytesting functions allow you to omit the second
argument, in which case the input may be linear in any nonconstant
! formula. Here, the @expr{a=0}, @expr{b=1} case is also considered
! trivial, and only constant values for @expr{a} and @expr{b} are
! recognized. Thus, @samp{lin(2 x y)} returns @expr{[0, 2, x y]},
! @samp{lin(2  x y)} returns @expr{[2, 1, x y]}, and @samp{lin(x y)}
! returns @expr{[0, 1, x y]}. The @code{linnt} function would allow the
first two cases but not the third. Also, neither @code{lin} nor
@code{linnt} accept plain constants as linear in the oneargument
case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
***************
*** 25347,25354 ****
@starindex
@end ignore
@tindex istrue
! The @samp{istrue(a)} function returns 1 if @cite{a} is a nonzero
! number or provably nonzero formula, or 0 if @cite{a} is anything else.
Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is
used to make sure they are not evaluated prematurely. (Note that
declarations are used when deciding whether a formula is true;
 25659,25666 
@starindex
@end ignore
@tindex istrue
! The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero
! number or provably nonzero formula, or 0 if @expr{a} is anything else.
Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is
used to make sure they are not evaluated prematurely. (Note that
declarations are used when deciding whether a formula is true;
***************
*** 25408,25414 ****
The @code{assign} function is undefined by itself in Calc, so an
assignment formula such as a rewrite rule will be left alone by ordinary
Calc commands. But certain commands, like the rewrite system, interpret
! assignments in special address@hidden
For example, the rule @samp{sin(x)^2 := 1cos(x)^2} says to replace
every occurrence of the sine of something, squared, with one minus the
 25720,25726 
The @code{assign} function is undefined by itself in Calc, so an
assignment formula such as a rewrite rule will be left alone by ordinary
Calc commands. But certain commands, like the rewrite system, interpret
! assignments in special ways.
For example, the rule @samp{sin(x)^2 := 1cos(x)^2} says to replace
every occurrence of the sine of something, squared, with one minus the
***************
*** 25451,25457 ****
(@code{calceditvariable}) command is an easy way to create or edit a
rule set stored in a variable. You may also wish to use @kbd{s p}
(@code{calcpermanentvariable}) to save your rules permanently;
! @pxref{Operations on address@hidden
Rewrite rules are compiled into a special internal form for faster
matching. If you enter a rule set directly it must be recompiled
 25763,25769 
(@code{calceditvariable}) command is an easy way to create or edit a
rule set stored in a variable. You may also wish to use @kbd{s p}
(@code{calcpermanentvariable}) to save your rules permanently;
! @pxref{Operations on Variables}.
Rewrite rules are compiled into a special internal form for faster
matching. If you enter a rule set directly it must be recompiled
***************
*** 25468,25477 ****
@subsection Basic Rewrite Rules
@noindent
! To match a particular formula @cite{x} with a particular rewrite rule
! @address@hidden := @var{new}}, Calc compares the structure of @cite{x} with
the structure of @var{old}. Variables that appear in @var{old} are
! treated as @dfn{metavariables}; the corresponding positions in @cite{x}
may contain any subformulas. For example, the pattern @samp{f(x,y)}
would match the expression @samp{f(12, a+1)} with the metavariable
@samp{x} corresponding to 12 and with @samp{y} corresponding to
 25780,25789 
@subsection Basic Rewrite Rules
@noindent
! To match a particular formula @expr{x} with a particular rewrite rule
! @address@hidden := @var{new}}, Calc compares the structure of @expr{x} with
the structure of @var{old}. Variables that appear in @var{old} are
! treated as @dfn{metavariables}; the corresponding positions in @expr{x}
may contain any subformulas. For example, the pattern @samp{f(x,y)}
would match the expression @samp{f(12, a+1)} with the metavariable
@samp{x} corresponding to 12 and with @samp{y} corresponding to
***************
*** 25481,25487 ****
the pattern is a single metavariable, it will match any expression.
If a given metavariable appears more than once in @var{old}, the
! corresponding subformulas of @cite{x} must be identical. Thus
the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and
@samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}.
(@xref{Conditional Rewrite Rules}, for a way to match the latter.)
 25793,25799 
the pattern is a single metavariable, it will match any expression.
If a given metavariable appears more than once in @var{old}, the
! corresponding subformulas of @expr{x} must be identical. Thus
the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and
@samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}.
(@xref{Conditional Rewrite Rules}, for a way to match the latter.)
***************
*** 25525,25538 ****
the rule is accepted. If the result is zero or if it is a symbolic
formula that is not known to be nonzero, the rule is rejected.
@xref{Logical Operations}, for a number of functions that return
! 1 or 0 according to the results of various address@hidden
! For example, the formula @samp{n > 0} simplifies to 1 or 0 if @cite{n}
is replaced by a positive or nonpositive number, respectively (or if
! @cite{n} has been declared to be positive or nonpositive). Thus,
the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to
@samp{f(0, 4)} but not to @samp{f(3, 2)} or @samp{f(12, a+1)}
! (assuming no outstanding declarations for @cite{a}). In the case of
@samp{f(3, 2)}, the condition can be shown not to be satisfied; in
the case of @samp{f(12, a+1)}, the condition merely cannot be shown
to be satisfied, but that is enough to reject the rule.
 25837,25850 
the rule is accepted. If the result is zero or if it is a symbolic
formula that is not known to be nonzero, the rule is rejected.
@xref{Logical Operations}, for a number of functions that return
! 1 or 0 according to the results of various tests.
! For example, the formula @samp{n > 0} simplifies to 1 or 0 if @expr{n}
is replaced by a positive or nonpositive number, respectively (or if
! @expr{n} has been declared to be positive or nonpositive). Thus,
the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to
@samp{f(0, 4)} but not to @samp{f(3, 2)} or @samp{f(12, a+1)}
! (assuming no outstanding declarations for @expr{a}). In the case of
@samp{f(3, 2)}, the condition can be shown not to be satisfied; in
the case of @samp{f(12, a+1)}, the condition merely cannot be shown
to be satisfied, but that is enough to reject the rule.
***************
*** 25562,25573 ****
matched.
Certain conditions are handled as special cases by the rewrite rule
! system and are tested very efficiently: Where @cite{x} is any
metavariable, these conditions are @samp{integer(x)}, @samp{real(x)},
! @samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @cite{y}
is either a constant or another metavariable and @samp{>=} may be
replaced by any of the six relational operators, and @samp{x % a = b}
! where @cite{a} and @cite{b} are constants. Other conditions, like
@samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check
since Calc must bring the whole evaluator and simplifier into play.
 25874,25885 
matched.
Certain conditions are handled as special cases by the rewrite rule
! system and are tested very efficiently: Where @expr{x} is any
metavariable, these conditions are @samp{integer(x)}, @samp{real(x)},
! @samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @expr{y}
is either a constant or another metavariable and @samp{>=} may be
replaced by any of the six relational operators, and @samp{x % a = b}
! where @expr{a} and @expr{b} are constants. Other conditions, like
@samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check
since Calc must bring the whole evaluator and simplifier into play.
***************
*** 25776,25782 ****
functions with rewrite conditions to test for this; @pxref{Logical
Operations}. These functions are not as convenient to use in rewrite
rules, but they recognize more kinds of formulas as linear:
! @samp{x/z} is considered linear with @cite{b = 1/z} by @code{lin},
but it will not match the above pattern because that pattern calls
for a multiplication, not a division.
 26088,26094 
functions with rewrite conditions to test for this; @pxref{Logical
Operations}. These functions are not as convenient to use in rewrite
rules, but they recognize more kinds of formulas as linear:
! @samp{x/z} is considered linear with @expr{b = 1/z} by @code{lin},
but it will not match the above pattern because that pattern calls
for a multiplication, not a division.
***************
*** 25796,25802 ****
@end example
Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2}
! because one @cite{a} would have ``matched'' 1 while the other matched 6.
Calc automatically converts a rule like
 26108,26114 
@end example
Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2}
! because one @expr{a} would have ``matched'' 1 while the other matched 6.
Calc automatically converts a rule like
***************
*** 25944,25963 ****
@end ignore
@tindex import
One kind of marker, @samp{import(x)}, takes the place of a whole
! rule. Here @cite{x} is the name of a variable containing another
rule set; those rules are ``spliced into'' the rule set that
imports them. For example, if @samp{[f(a+b) := f(a) + f(b),
f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},
then the rule set @samp{[f(0) := 0, import(linearF)]} will apply
all three rules. It is possible to modify the imported rules
slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports
! the rule set @cite{x} with all occurrences of @c{$v_1$}
! @cite{v1}, as either
! a variable name or a function name, replaced with @c{$x_1$}
! @cite{x1} and
! so on. (If @c{$v_1$}
! @cite{v1} is used as a function name, then @c{$x_1$}
! @cite{x1}
must be either a function name itself or a @address@hidden< >}} nameless
function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0,
import(linearF, f, g)]} applies the linearity rules to the function
 26256,26280 
@end ignore
@tindex import
One kind of marker, @samp{import(x)}, takes the place of a whole
! rule. Here @expr{x} is the name of a variable containing another
rule set; those rules are ``spliced into'' the rule set that
imports them. For example, if @samp{[f(a+b) := f(a) + f(b),
f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},
then the rule set @samp{[f(0) := 0, import(linearF)]} will apply
all three rules. It is possible to modify the imported rules
slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports
! the rule set @expr{x} with all occurrences of
! @texline @tmath{v_1},
! @infoline @expr{v1},
! as either a variable name or a function name, replaced with
! @texline @tmath{x_1}
! @infoline @expr{x1}
! and so on. (If
! @texline @tmath{v_1}
! @infoline @expr{v1}
! is used as a function name, then
! @texline @tmath{x_1}
! @infoline @expr{x1}
must be either a function name itself or a @address@hidden< >}} nameless
function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0,
import(linearF, f, g)]} applies the linearity rules to the function
***************
*** 25972,25978 ****
@starindex
@end ignore
@tindex quote
! This pattern matches exactly @cite{x}; variable names in @cite{x} are
not interpreted as metavariables. The only flexibility is that
numbers are compared for numeric equality, so that the pattern
@samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}.
 26289,26295 
@starindex
@end ignore
@tindex quote
! This pattern matches exactly @expr{x}; variable names in @expr{x} are
not interpreted as metavariables. The only flexibility is that
numbers are compared for numeric equality, so that the pattern
@samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}.
***************
*** 25986,25995 ****
@starindex
@end ignore
@tindex plain
! Here @cite{x} must be a function call @samp{f(x1,x2,@dots{})}. This
! pattern matches a call to function @cite{f} with the specified
argument patterns. No special knowledge of the properties of the
! function @cite{f} is used in this case; @samp{+} is not commutative or
associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}}
are treated as patterns. If you wish them to be treated ``plainly''
as well, you must enclose them with more @code{plain} markers:
 26303,26312 
@starindex
@end ignore
@tindex plain
! Here @expr{x} must be a function call @samp{f(x1,x2,@dots{})}. This
! pattern matches a call to function @expr{f} with the specified
argument patterns. No special knowledge of the properties of the
! function @expr{f} is used in this case; @samp{+} is not commutative or
associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}}
are treated as patterns. If you wish them to be treated ``plainly''
as well, you must enclose them with more @code{plain} markers:
***************
*** 26000,26023 ****
@starindex
@end ignore
@tindex opt
! Here @cite{x} must be a variable name. This must appear as an
argument to a function or an element of a vector; it specifies that
the argument or element is optional.
As an argument to @samp{+}, @samp{}, @samp{*}, @samp{&&}, or @samp{},
or as the second argument to @samp{/} or @samp{^}, the value @var{def}
may be omitted. The pattern @samp{x + opt(y)} matches a sum by
! binding one summand to @cite{x} and the other to @cite{y}, and it
! matches anything else by binding the whole expression to @cite{x} and
! zero to @cite{y}. The other operators above work address@hidden
For general miscellaneous functions, the default value @code{def}
must be specified. Optional arguments are dropped starting with
the rightmost one during matching. For example, the pattern
@samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)},
! or @samp{f(a,b,c)}. Default values of zero and @cite{b} are
supplied in this example for the omitted arguments. Note that
! the literal variable @cite{b} will be the default in the latter
! case, @emph{not} the value that matched the metavariable @cite{b}.
In other words, the default @var{def} is effectively quoted.
@item condition(x,c)
 26317,26340 
@starindex
@end ignore
@tindex opt
! Here @expr{x} must be a variable name. This must appear as an
argument to a function or an element of a vector; it specifies that
the argument or element is optional.
As an argument to @samp{+}, @samp{}, @samp{*}, @samp{&&}, or @samp{},
or as the second argument to @samp{/} or @samp{^}, the value @var{def}
may be omitted. The pattern @samp{x + opt(y)} matches a sum by
! binding one summand to @expr{x} and the other to @expr{y}, and it
! matches anything else by binding the whole expression to @expr{x} and
! zero to @expr{y}. The other operators above work similarly.
For general miscellaneous functions, the default value @code{def}
must be specified. Optional arguments are dropped starting with
the rightmost one during matching. For example, the pattern
@samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)},
! or @samp{f(a,b,c)}. Default values of zero and @expr{b} are
supplied in this example for the omitted arguments. Note that
! the literal variable @expr{b} will be the default in the latter
! case, @emph{not} the value that matched the metavariable @expr{b}.
In other words, the default @var{def} is effectively quoted.
@item condition(x,c)
***************
*** 26026,26033 ****
@end ignore
@tindex condition
@tindex ::
! This matches the pattern @cite{x}, with the attached condition
! @cite{c}. It is the same as @samp{x :: c}.
@item pand(x,y)
@ignore
 26343,26350 
@end ignore
@tindex condition
@tindex ::
! This matches the pattern @expr{x}, with the attached condition
! @expr{c}. It is the same as @samp{x :: c}.
@item pand(x,y)
@ignore
***************
*** 26035,26042 ****
@end ignore
@tindex pand
@tindex &&&
! This matches anything that matches both pattern @cite{x} and
! pattern @cite{y}. It is the same as @samp{x &&& y}.
@pxref{Composing Patterns in Rewrite Rules}.
@item por(x,y)
 26352,26359 
@end ignore
@tindex pand
@tindex &&&
! This matches anything that matches both pattern @expr{x} and
! pattern @expr{y}. It is the same as @samp{x &&& y}.
@pxref{Composing Patterns in Rewrite Rules}.
@item por(x,y)
***************
*** 26045,26052 ****
@end ignore
@tindex por
@tindex 
! This matches anything that matches either pattern @cite{x} or
! pattern @cite{y}. It is the same as @address@hidden  y}}.
@item pnot(x)
@ignore
 26362,26369 
@end ignore
@tindex por
@tindex 
! This matches anything that matches either pattern @expr{x} or
! pattern @expr{y}. It is the same as @address@hidden  y}}.
@item pnot(x)
@ignore
***************
*** 26054,26060 ****
@end ignore
@tindex pnot
@tindex !!!
! This matches anything that does not match pattern @cite{x}.
It is the same as @samp{!!! x}.
@item cons(h,t)
 26371,26377 
@end ignore
@tindex pnot
@tindex !!!
! This matches anything that does not match pattern @expr{x}.
It is the same as @samp{!!! x}.
@item cons(h,t)
***************
*** 26063,26070 ****
@end ignore
@tindex cons (rewrites)
This matches any vector of one or more elements. The first
! element is matched to @cite{h}; a vector of the remaining
! elements is matched to @cite{t}. Note that vectors of fixed
length can also be matched as actual vectors: The rule
@samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent
to the rule @samp{[a,b] := [a+b]}.
 26380,26387 
@end ignore
@tindex cons (rewrites)
This matches any vector of one or more elements. The first
! element is matched to @expr{h}; a vector of the remaining
! elements is matched to @expr{t}. Note that vectors of fixed
length can also be matched as actual vectors: The rule
@samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent
to the rule @samp{[a,b] := [a+b]}.
***************
*** 26075,26082 ****
@end ignore
@tindex rcons (rewrites)
This is like @code{cons}, except that the @emph{last} element
! is matched to @cite{h}, with the remaining elements matched
! to @cite{t}.
@item apply(f,args)
@ignore
 26392,26399 
@end ignore
@tindex rcons (rewrites)
This is like @code{cons}, except that the @emph{last} element
! is matched to @expr{h}, with the remaining elements matched
! to @expr{t}.
@item apply(f,args)
@ignore
***************
*** 26084,26090 ****
@end ignore
@tindex apply (rewrites)
This matches any function call. The name of the function, in
! the form of a variable, is matched to @cite{f}. The arguments
of the function, as a vector of zero or more objects, are
matched to @samp{args}. Constants, variables, and vectors
do @emph{not} match an @code{apply} pattern. For example,
 26401,26407 
@end ignore
@tindex apply (rewrites)
This matches any function call. The name of the function, in
! the form of a variable, is matched to @expr{f}. The arguments
of the function, as a vector of zero or more objects, are
matched to @samp{args}. Constants, variables, and vectors
do @emph{not} match an @code{apply} pattern. For example,
***************
*** 26152,26158 ****
@item plain(x)
Special properties of and simplifications for the function call
! @cite{x} are not used. One interesting case where @code{plain}
is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a
shorthand notation for the @code{quote} function. This rule will
not work as shown; instead of replacing @samp{q(foo)} with
 26469,26475 
@item plain(x)
Special properties of and simplifications for the function call
! @expr{x} are not used. One interesting case where @code{plain}
is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a
shorthand notation for the @code{quote} function. This rule will
not work as shown; instead of replacing @samp{q(foo)} with
***************
*** 26160,26166 ****
rule would be @samp{q(x) := plain(quote(x))}.
@item cons(h,t)
! Where @cite{t} is a vector, this is converted into an expanded
vector during rewrite processing. Note that @code{cons} is a regular
Calc function which normally does this anyway; the only way @code{cons}
is treated specially by rewrites is that @code{cons} on the righthand
 26477,26483 
rule would be @samp{q(x) := plain(quote(x))}.
@item cons(h,t)
! Where @expr{t} is a vector, this is converted into an expanded
vector during rewrite processing. Note that @code{cons} is a regular
Calc function which normally does this anyway; the only way @code{cons}
is treated specially by rewrites is that @code{cons} on the righthand
***************
*** 26168,26178 ****
have been turned off.
@item rcons(t,h)
! Analogous to @code{cons} except putting @cite{h} at the @emph{end} of
! the vector @cite{t}.
@item apply(f,args)
! Where @cite{f} is a variable and @var{args} is a vector, this
is converted to a function call. Once again, note that @code{apply}
is also a regular Calc function.
 26485,26495 
have been turned off.
@item rcons(t,h)
! Analogous to @code{cons} except putting @expr{h} at the @emph{end} of
! the vector @expr{t}.
@item apply(f,args)
! Where @expr{f} is a variable and @var{args} is a vector, this
is converted to a function call. Once again, note that @code{apply}
is also a regular Calc function.
***************
*** 26181,26187 ****
@starindex
@end ignore
@tindex eval
! The formula @cite{x} is handled in the usual way, then the
default simplifications are applied to it even if they have
been turned off normally. This allows you to treat any function
similarly to the way @code{cons} and @code{apply} are always
 26498,26504 
@starindex
@end ignore
@tindex eval
! The formula @expr{x} is handled in the usual way, then the
default simplifications are applied to it even if they have
been turned off normally. This allows you to treat any function
similarly to the way @code{cons} and @code{apply} are always
***************
*** 26194,26200 ****
@starindex
@end ignore
@tindex evalsimp
! The formula @cite{x} has metavariables substituted in the usual
way, then algebraically simplified as if by the @kbd{a s} command.
@item evalextsimp(x)
 26511,26517 
@starindex
@end ignore
@tindex evalsimp
! The formula @expr{x} has metavariables substituted in the usual
way, then algebraically simplified as if by the @kbd{a s} command.
@item evalextsimp(x)
***************
*** 26202,26208 ****
@starindex
@end ignore
@tindex evalextsimp
! The formula @cite{x} has metavariables substituted in the normal
way, then ``extendedly'' simplified as if by the @kbd{a e} command.
@item select(x)
 26519,26525 
@starindex
@end ignore
@tindex evalextsimp
! The formula @expr{x} has metavariables substituted in the normal
way, then ``extendedly'' simplified as if by the @kbd{a e} command.
@item select(x)
***************
*** 26217,26238 ****
@starindex
@end ignore
@tindex let
! The expression @cite{x} is evaluated with metavariables substituted.
The @kbd{a s} command's simplifications are @emph{not} applied by
! default, but @cite{x} can include calls to @code{evalsimp} or
@code{evalextsimp} as described above to invoke higher levels
of simplification. The
! result of @cite{x} is then bound to the metavariable @cite{v}. As
usual, if this metavariable has already been matched to something
else the two values must be equal; if the metavariable is new then
it is bound to the result of the expression. This variable can then
appear in later conditions, and on the righthand side of the rule.
! In fact, @cite{v} may be any pattern in which case the result of
! evaluating @cite{x} is matched to that pattern, binding any
metavariables that appear in that pattern. Note that @code{let}
can only appear by itself as a condition, or as one term of an
@samp{&&} which is a whole condition: It cannot be inside
! an @samp{} term or otherwise address@hidden
The alternate, equivalent form @samp{let(v, x)} is also recognized.
Note that the use of @samp{:=} by @code{let}, while still being
 26534,26555 
@starindex
@end ignore
@tindex let
! The expression @expr{x} is evaluated with metavariables substituted.
The @kbd{a s} command's simplifications are @emph{not} applied by
! default, but @expr{x} can include calls to @code{evalsimp} or
@code{evalextsimp} as described above to invoke higher levels
of simplification. The
! result of @expr{x} is then bound to the metavariable @expr{v}. As
usual, if this metavariable has already been matched to something
else the two values must be equal; if the metavariable is new then
it is bound to the result of the expression. This variable can then
appear in later conditions, and on the righthand side of the rule.
! In fact, @expr{v} may be any pattern in which case the result of
! evaluating @expr{x} is matched to that pattern, binding any
metavariables that appear in that pattern. Note that @code{let}
can only appear by itself as a condition, or as one term of an
@samp{&&} which is a whole condition: It cannot be inside
! an @samp{} term or otherwise buried.
The alternate, equivalent form @samp{let(v, x)} is also recognized.
Note that the use of @samp{:=} by @code{let}, while still being
***************
*** 26249,26255 ****
Note that, because the metavariable @samp{ia} is otherwise unbound
in this rule, the @code{let} condition itself always ``succeeds''
because no matter what @samp{1/a} evaluates to, it can successfully
! be bound to @address@hidden
Here's another example, for integrating cosines of linear
terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}.
 26566,26572 
Note that, because the metavariable @samp{ia} is otherwise unbound
in this rule, the @code{let} condition itself always ``succeeds''
because no matter what @samp{1/a} evaluates to, it can successfully
! be bound to @code{ia}.
Here's another example, for integrating cosines of linear
terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}.
***************
*** 26260,26266 ****
the coefficients @code{a} and @code{b} for use elsewhere in the rule.
(It would have been possible to use @samp{sin(a x + b)/b} for the
righthand side instead, but using @samp{sin(y)/b} avoids gratuitous
! rearrangement of the argument of the sine.)@refill
@ignore
@starindex
 26577,26583 
the coefficients @code{a} and @code{b} for use elsewhere in the rule.
(It would have been possible to use @samp{sin(a x + b)/b} for the
righthand side instead, but using @samp{sin(y)/b} avoids gratuitous
! rearrangement of the argument of the sine.)
@ignore
@starindex
***************
*** 26321,26327 ****
@starindex
@end ignore
@tindex remember
! Remember the match as described above, but only if condition @cite{c}
is true. For example, @samp{remember(n % 4 = 0)} in the above factorial
rule remembers only every fourth result. Note that @samp{remember(1)}
is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.
 26638,26644 
@starindex
@end ignore
@tindex remember
! Remember the match as described above, but only if condition @expr{c}
is true. For example, @samp{remember(n % 4 = 0)} in the above factorial
rule remembers only every fourth result. Note that @samp{remember(1)}
is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.
***************
*** 26883,26889 ****
Another subtle difference between @code{EvalRules} and regular rewrites
concerns rules that rewrite a formula into an identical formula. For
! example, @samp{f(n) := f(floor(n))} ``fails to match'' when @cite{n} is
already an integer. But in @code{EvalRules} this case is detected only
if the righthand side literally becomes the original formula before any
further simplification. This means that @samp{f(n) := f(floor(n))} will
 27200,27206 
Another subtle difference between @code{EvalRules} and regular rewrites
concerns rules that rewrite a formula into an identical formula. For
! example, @samp{f(n) := f(floor(n))} ``fails to match'' when @expr{n} is
already an integer. But in @code{EvalRules} this case is detected only
if the righthand side literally becomes the original formula before any
further simplification. This means that @samp{f(n) := f(floor(n))} will
***************
*** 26927,26940 ****
functions directly rather than going through the default simplifications.
When it does this, @code{EvalRules} will not be able to override those
functions. For example, when you take the absolute value of the complex
! number @cite{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling
the multiplication, addition, and square root functions directly rather
than applying the default simplifications to this formula. So an
@code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}
would not apply. (However, if you put Calc into symbolic mode so that
@samp{sqrt(13)} will be left in symbolic form by the builtin square
root function, your rule will be able to apply. But if the complex
! number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated,
then symbolic mode will not help because @samp{sqrt(25)} can be
evaluated exactly to 5.)
 27244,27257 
functions directly rather than going through the default simplifications.
When it does this, @code{EvalRules} will not be able to override those
functions. For example, when you take the absolute value of the complex
! number @expr{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling
the multiplication, addition, and square root functions directly rather
than applying the default simplifications to this formula. So an
@code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}
would not apply. (However, if you put Calc into symbolic mode so that
@samp{sqrt(13)} will be left in symbolic form by the builtin square
root function, your rule will be able to apply. But if the complex
! number were @expr{(3,4)}, so that @samp{sqrt(25)} must be calculated,
then symbolic mode will not help because @samp{sqrt(25)} can be
evaluated exactly to 5.)
***************
*** 27028,27034 ****
finding suitable cases. Another solution would be to use the rule
@samp{cos(x)^2 := 1  sin(x)^2}, followed by algebraic simplification
if necessary. This rule will be the most effective way to do the job,
! but at the expense of making some changes that you might not address@hidden
Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
To make this work with the @address@hidden r}} command so that it can be
 27345,27351 
finding suitable cases. Another solution would be to use the rule
@samp{cos(x)^2 := 1  sin(x)^2}, followed by algebraic simplification
if necessary. This rule will be the most effective way to do the job,
! but at the expense of making some changes that you might not desire.
Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
To make this work with the @address@hidden r}} command so that it can be
***************
*** 27036,27045 ****
you might wish to write the rule as @samp{select(exp(x+y)) :=
select(exp(x) exp(y))}. The @samp{select} markers will be
ignored by the regular @kbd{a r} command
! (@pxref{Selections with Rewrite Rules})address@hidden
A surprisingly useful rewrite rule is @samp{a/(bc) := a*(b+c)/(b^2c^2)}.
! This will simplify the formula whenever @cite{b} and/or @cite{c} can
be made simpler by squaring. For example, applying this rule to
@samp{2 / (sqrt(2) + 3)} yields @samp{6:7  2:7 sqrt(2)} (assuming
Symbolic Mode has been enabled to keep the square root from being
 27353,27362 
you might wish to write the rule as @samp{select(exp(x+y)) :=
select(exp(x) exp(y))}. The @samp{select} markers will be
ignored by the regular @kbd{a r} command
! (@pxref{Selections with Rewrite Rules}).
A surprisingly useful rewrite rule is @samp{a/(bc) := a*(b+c)/(b^2c^2)}.
! This will simplify the formula whenever @expr{b} and/or @expr{c} can
be made simpler by squaring. For example, applying this rule to
@samp{2 / (sqrt(2) + 3)} yields @samp{6:7  2:7 sqrt(2)} (assuming
Symbolic Mode has been enabled to keep the square root from being
***************
*** 27059,27075 ****
@code{tri} to the value on the top of the stack. @xref{Programming}.
@cindex Quaternions
! The following rule set, contributed by @c{Fran\c cois}
! @asis{Francois} Pinard, implements
! @dfn{quaternions}, a generalization of the concept of complex numbers.
! Quaternions have four components, and are here represented by function
! calls @samp{quat(@var{w}, address@hidden, @var{y}, @var{z}])} with ``real
! part'' @var{w} and the three ``imaginary'' parts collected into a
! vector. Various arithmetical operations on quaternions are supported.
! To use these rules, either add them to @code{EvalRules}, or create a
! command based on @kbd{a r} for simplifying quaternion formulas.
! A convenient way to enter quaternions would be a command defined by
! a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}.
@smallexample
[ quat(w, x, y, z) := quat(w, [x, y, z]),
 27376,27394 
@code{tri} to the value on the top of the stack. @xref{Programming}.
@cindex Quaternions
! The following rule set, contributed by
! @texline Fran\c cois
! @infoline Francois
! Pinard, implements @dfn{quaternions}, a generalization of the concept of
! complex numbers. Quaternions have four components, and are here
! represented by function calls @samp{quat(@var{w}, address@hidden, @var{y},
! @var{z}])} with ``real part'' @var{w} and the three ``imaginary'' parts
! collected into a vector. Various arithmetical operations on quaternions
! are supported. To use these rules, either add them to @code{EvalRules},
! or create a command based on @kbd{a r} for simplifying quaternion
! formulas. A convenient way to enter quaternions would be a command
! defined by a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $])
! @key{RET}}.
@smallexample
[ quat(w, x, y, z) := quat(w, [x, y, z]),
***************
*** 27094,27101 ****
@end smallexample
Quaternions, like matrices, have noncommutative multiplication.
! In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if
! @cite{q1} and @cite{q2} are @code{quat} forms. The @samp{quat*quat}
rule above uses @code{plain} to prevent Calc from rearranging the
product. It may also be wise to add the line @samp{[quat(), matrix]}
to the @code{Decls} matrix, to ensure that Calc's other algebraic
 27413,27420 
@end smallexample
Quaternions, like matrices, have noncommutative multiplication.
! In other words, @expr{q1 * q2 = q2 * q1} is not necessarily true if
! @expr{q1} and @expr{q2} are @code{quat} forms. The @samp{quat*quat}
rule above uses @code{plain} to prevent Calc from rearranging the
product. It may also be wise to add the line @samp{[quat(), matrix]}
to the @code{Decls} matrix, to ensure that Calc's other algebraic
***************
*** 27142,27154 ****
or @samp{u} (for ``micro'') followed by a name in the unit table.
A substantial table of builtin units is provided with Calc;
@pxref{Predefined Units}. You can also define your own unit names;
! @pxref{UserDefined address@hidden
Note that if the value part of a units expression is exactly @samp{1},
it will be removed by the Calculator's automatic algebra routines: The
formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a
display anomaly, however; @samp{mm} will work just fine as a
! representation of one address@hidden
You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working
with units expressions easier. Otherwise, you will have to remember
 27461,27473 
or @samp{u} (for ``micro'') followed by a name in the unit table.
A substantial table of builtin units is provided with Calc;
@pxref{Predefined Units}. You can also define your own unit names;
! @pxref{UserDefined Units}.
Note that if the value part of a units expression is exactly @samp{1},
it will be removed by the Calculator's automatic algebra routines: The
formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a
display anomaly, however; @samp{mm} will work just fine as a
! representation of one millimeter.
You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working
with units expressions easier. Otherwise, you will have to remember
***************
*** 27169,27175 ****
simplify to @samp{5.023 m}. When different but compatible units are
added, the righthand term's units are converted to match those of the
lefthand term. @xref{Simplification Modes}, for a way to have this done
! automatically at all address@hidden
Units simplification also handles quotients of two units with the same
dimensionality, as in @address@hidden in s/L cm}} to @samp{5.08 s/L};
fractional
 27488,27494 
simplify to @samp{5.023 m}. When different but compatible units are
added, the righthand term's units are converted to match those of the
lefthand term. @xref{Simplification Modes}, for a way to have this done
! automatically at all times.
Units simplification also handles quotients of two units with the same
dimensionality, as in @address@hidden in s/L cm}} to @samp{5.08 s/L};
fractional
***************
*** 27180,27186 ****
applied to units expressions, in which case
the operation in question is applied only to the numeric part of the
expression. Finally, trigonometric functions of quantities with units
! of angle are evaluated, regardless of the current angular address@hidden
@kindex u c
@pindex calcconvertunits
 27499,27505 
applied to units expressions, in which case
the operation in question is applied only to the numeric part of the
expression. Finally, trigonometric functions of quantities with units
! of angle are evaluated, regardless of the current angular mode.
@kindex u c
@pindex calcconvertunits
***************
*** 27261,27267 ****
absolute temperatures. The value on the stack must be a simple units
expression with units of temperature only. This command would convert
@samp{10 degC} to @samp{50 degF}, the equivalent temperature on the
! Fahrenheit address@hidden
@kindex u r
@pindex calcremoveunits
 27580,27586 
absolute temperatures. The value on the stack must be a simple units
expression with units of temperature only. This command would convert
@samp{10 degC} to @samp{50 degF}, the equivalent temperature on the
! Fahrenheit scale.
@kindex u r
@pindex calcremoveunits
***************
*** 27272,27278 ****
(@code{calcextractunits}) command extracts only the units portion of a
formula. These commands essentially replace every term of the formula
that does or doesn't (respectively) look like a unit name by the
! constant 1, then resimplify the address@hidden
@kindex u a
@pindex calcautorangeunits
 27591,27597 
(@code{calcextractunits}) command extracts only the units portion of a
formula. These commands essentially replace every term of the formula
that does or doesn't (respectively) look like a unit name by the
! constant 1, then resimplify the formula.
@kindex u a
@pindex calcautorangeunits
***************
*** 27397,27408 ****
The unit @code{e} stands for the elementary (electron) unit of charge;
because algebra command could mistake this for the special constant
! @cite{e}, Calc provides the alternate unit name @code{ech} which is
preferable to @code{e}.
The name @code{g} stands for one gram of mass; there is also @code{gf},
one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.)
! Meanwhile, one address@hidden'' of acceleration is denoted @code{ga}.
The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
a metric ton of @samp{1000 kg}.
 27716,27727 
The unit @code{e} stands for the elementary (electron) unit of charge;
because algebra command could mistake this for the special constant
! @expr{e}, Calc provides the alternate unit name @code{ech} which is
preferable to @code{e}.
The name @code{g} stands for one gram of mass; there is also @code{gf},
one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.)
! Meanwhile, one address@hidden'' of acceleration is denoted @code{ga}.
The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
a metric ton of @samp{1000 kg}.
***************
*** 27634,27645 ****
and @kbd{s ]} which decrease or increase a variable by one.
All the arithmetic stores accept the Inverse prefix to reverse the
! order of the operands. If @cite{v} represents the contents of the
! variable, and @cite{a} is the value drawn from the stack, then regular
! @address@hidden }} assigns @c{$v \coloneq v  a$}
! @cite{v := v  a}, but @kbd{I s } assigns
! @c{$v \coloneq a  v$}
! @cite{v := a  v}. While @kbd{I s *} might seem pointless, it is
useful if matrix multiplication is involved. Actually, all the
arithmetic stores use formulas designed to behave usefully both
forwards and backwards:
 27953,27967 
and @kbd{s ]} which decrease or increase a variable by one.
All the arithmetic stores accept the Inverse prefix to reverse the
! order of the operands. If @expr{v} represents the contents of the
! variable, and @expr{a} is the value drawn from the stack, then regular
! @address@hidden }} assigns
! @texline @tmath{v \coloneq v  a},
! @infoline @expr{v := v  a},
! but @kbd{I s } assigns
! @texline @tmath{v \coloneq a  v}.
! @infoline @expr{v := a  v}.
! While @kbd{I s *} might seem pointless, it is
useful if matrix multiplication is involved. Actually, all the
arithmetic stores use formulas designed to behave usefully both
forwards and backwards:
***************
*** 27666,27672 ****
The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t },
etc. The commands @kbd{s s +}, @kbd{s s }, and so on are analogous
! arithmetic stores that don't remove the value @cite{a} from the stack.
All arithmetic stores report the new value of the variable in the
Trail for your information. They signal an error if the variable
 27988,27994 
The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t },
etc. The commands @kbd{s s +}, @kbd{s s }, and so on are analogous
! arithmetic stores that don't remove the value @expr{a} from the stack.
All arithmetic stores report the new value of the variable in the
Trail for your information. They signal an error if the variable
***************
*** 27692,27699 ****
If the mapping function takes two or more arguments, the additional
arguments are taken from the stack; the old value of the variable
! is provided as the first argument. Thus @kbd{s m } with @cite{a}
! on the stack computes @cite{v  a}, just like @kbd{s }. With the
Inverse prefix, the variable's original value becomes the @emph{last}
argument instead of the first. Thus @kbd{I s m } is also
equivalent to @kbd{I s }.
 28014,28021 
If the mapping function takes two or more arguments, the additional
arguments are taken from the stack; the old value of the variable
! is provided as the first argument. Thus @kbd{s m } with @expr{a}
! on the stack computes @expr{v  a}, just like @kbd{s }. With the
Inverse prefix, the variable's original value becomes the @emph{last}
argument instead of the first. Thus @kbd{I s m } is also
equivalent to @kbd{I s }.
***************
*** 27716,27722 ****
contain no value at all. If they appear in an algebraic formula they
will be left alone even if you press @kbd{=} (@code{calcevaluate}).
The @kbd{s u} (@code{calcunstore}) command returns a variable to the
! void address@hidden
The only variables with predefined values are the ``special constants''
@code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}. You are free
 28038,28044 
contain no value at all. If they appear in an algebraic formula they
will be left alone even if you press @kbd{=} (@code{calcevaluate}).
The @kbd{s u} (@code{calcunstore}) command returns a variable to the
! void state.
The only variables with predefined values are the ``special constants''
@code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}. You are free
***************
*** 27728,27735 ****
normally void).
Note that @code{varpi} doesn't actually have 3.14159265359 stored
! in it, but rather a special magic value that evaluates to @c{$\pi$}
! @cite{pi}
at the current precision. Likewise @code{vare}, @code{vari}, and
@code{varphi} evaluate according to the current precision or polar mode.
If you recall a value from @code{pi} and store it back, this magic
 28050,28056 
normally void).
Note that @code{varpi} doesn't actually have 3.14159265359 stored
! in it, but rather a special magic value that evaluates to @cpi{}
at the current precision. Likewise @code{vare}, @code{vari}, and
@code{varphi} evaluate according to the current precision or polar mode.
If you recall a value from @code{pi} and store it back, this magic
***************
*** 27913,27919 ****
@code{FitRules}, @code{DistribRules}, and other builtin rewrite
rules; and @address@hidden variables generated
by the graphics commands. (You can still save these variables by
! explicitly naming them in an @kbd{s p} command.)@refill
@kindex s i
@pindex calcinsertvariables
 28234,28240 
@code{FitRules}, @code{DistribRules}, and other builtin rewrite
rules; and @address@hidden variables generated
by the graphics commands. (You can still save these variables by
! explicitly naming them in an @kbd{s p} command.)
@kindex s i
@pindex calcinsertvariables
***************
*** 27936,27944 ****
@cindex Variables, temporary assignment
@cindex Temporary assignment to variables
If you have an expression like @samp{a+b^2} on the stack and you wish to
! compute its value where @cite{b=3}, you can simply store 3 in @cite{b} and
then press @kbd{=} to reevaluate the formula. This has the sideeffect
! of leaving the stored value of 3 in @cite{b} for future operations.
The @kbd{s l} (@code{calclet}) command evaluates a formula under a
@emph{temporary} assignment of a variable. It stores the value on the
 28257,28265 
@cindex Variables, temporary assignment
@cindex Temporary assignment to variables
If you have an expression like @samp{a+b^2} on the stack and you wish to
! compute its value where @expr{b=3}, you can simply store 3 in @expr{b} and
then press @kbd{=} to reevaluate the formula. This has the sideeffect
! of leaving the stored value of 3 in @expr{b} for future operations.
The @kbd{s l} (@code{calclet}) command evaluates a formula under a
@emph{temporary} assignment of a variable. It stores the value on the
***************
*** 27961,27967 ****
The @kbd{a b} (@code{calcsubstitute}) command is another way to substitute
a variable with a value in a formula. It does an actual substitution
rather than temporarily assigning the variable and evaluating. For
! example, letting @cite{n=2} in @samp{f(n pi)} with @kbd{a b} will
produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}
since the evaluation step will also evaluate @code{pi}.
 28282,28288 
The @kbd{a b} (@code{calcsubstitute}) command is another way to substitute
a variable with a value in a formula. It does an actual substitution
rather than temporarily assigning the variable and evaluating. For
! example, letting @expr{n=2} in @samp{f(n pi)} with @kbd{a b} will
produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}
since the evaluation step will also evaluate @code{pi}.
***************
*** 28145,28152 ****
the interval (whether the interval is open or closed is ignored).
The ``x'' entry may also be a number, in which case Calc uses the
! sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc.
! (Generally the number 0 or 1 would be used for @cite{x} in this case.)
The ``y'' entry may be any formula instead of a vector. Calc effectively
uses @kbd{N} (@code{calcevalnum}) to evaluate variables in the formula;
 28466,28473 
the interval (whether the interval is open or closed is ignored).
The ``x'' entry may also be a number, in which case Calc uses the
! sequence of ``x'' values @expr{x}, @expr{x+1}, @expr{x+2}, etc.
! (Generally the number 0 or 1 would be used for @expr{x} in this case.)
The ``y'' entry may be any formula instead of a vector. Calc effectively
uses @kbd{N} (@code{calcevalnum}) to evaluate variables in the formula;
***************
*** 28169,28175 ****
In this case the ``x'' vector or interval you specified is not directly
visible in the graph. For example, if ``x'' is the interval @samp{[0..360]}
and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
! will be a address@hidden
Also, ``x'' and ``y'' may each be variable names, in which case Calc
looks for suitable vectors, intervals, or formulas stored in those
 28490,28496 
In this case the ``x'' vector or interval you specified is not directly
visible in the graph. For example, if ``x'' is the interval @samp{[0..360]}
and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
! will be a circle.
Also, ``x'' and ``y'' may each be variable names, in which case Calc
looks for suitable vectors, intervals, or formulas stored in those
***************
*** 28224,28232 ****
the same length); either or both may instead be interval forms. The
``z'' value must be a matrix with the same number of rows as elements
in ``x'', and the same number of columns as elements in ``y''. The
! result is a surface plot where @c{$z_{ij}$}
! @cite{z_ij} is the height of the point
! at coordinate @cite{(x_i, y_j)} on the surface. The 3D graph will
be displayed from a certain default viewpoint; you can change this
viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}
buffer as described later. See the GNUPLOT 3.0 documentation for a
 28545,28555 
the same length); either or both may instead be interval forms. The
``z'' value must be a matrix with the same number of rows as elements
in ``x'', and the same number of columns as elements in ``y''. The
! result is a surface plot where
! @texline @tmath{z_{ij}}
! @infoline @expr{z_ij}
! is the height of the point
! at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will
be displayed from a certain default viewpoint; you can change this
viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}
buffer as described later. See the GNUPLOT 3.0 documentation for a
***************
*** 28317,28342 ****
A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way
stack entries are interpreted as curves. With a positive prefix
! argument @cite{n}, the top @cite{n} stack entries are ``y'' values
! for @cite{n} different curves which share a common ``x'' value in
! the @cite{n+1}st stack entry. (Thus @kbd{g a} with no prefix
argument is equivalent to @kbd{Cu 1 g a}.)
A prefix of zero or plain @kbd{Cu} means to take two stack entries,
``x'' and ``y'' as usual, but to interpret ``y'' as a vector of
``y'' values for several curves that share a common ``x''.
! A negative prefix argument tells Calc to read @cite{n} vectors from
! the stack; each vector @cite{[x, y]} describes an independent curve.
This is the only form of @kbd{g a} that creates several curves at once
that don't have common ``x'' values. (Of course, the range of ``x''
values covered by all the curves ought to be roughly the same if
they are to look nice on the same graph.)
! For example, to plot @c{$\sin n x$}
! @cite{sin(n x)} for integers @cite{n}
from 1 to 5, you could use @kbd{v x} to create a vector of integers
! (@cite{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)}
across this vector. The resulting vector of formulas is suitable
for use as the ``y'' argument to a @kbd{Cu g a} or @kbd{Cu g f}
command.
 28640,28667 
A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way
stack entries are interpreted as curves. With a positive prefix
! argument @expr{n}, the top @expr{n} stack entries are ``y'' values
! for @expr{n} different curves which share a common ``x'' value in
! the @expr{n+1}st stack entry. (Thus @kbd{g a} with no prefix
argument is equivalent to @kbd{Cu 1 g a}.)
A prefix of zero or plain @kbd{Cu} means to take two stack entries,
``x'' and ``y'' as usual, but to interpret ``y'' as a vector of
``y'' values for several curves that share a common ``x''.
! A negative prefix argument tells Calc to read @expr{n} vectors from
! the stack; each vector @expr{[x, y]} describes an independent curve.
This is the only form of @kbd{g a} that creates several curves at once
that don't have common ``x'' values. (Of course, the range of ``x''
values covered by all the curves ought to be roughly the same if
they are to look nice on the same graph.)
! For example, to plot
! @texline @tmath{\sin n x}
! @infoline @expr{sin(n x)}
! for integers @expr{n}
from 1 to 5, you could use @kbd{v x} to create a vector of integers
! (@expr{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)}
across this vector. The resulting vector of formulas is suitable
for use as the ``y'' argument to a @kbd{Cu g a} or @kbd{Cu g f}
command.
***************
*** 28346,28356 ****
The @kbd{g A} (@code{calcgraphadd3d}) command adds a 3D curve
to the graph. It is not legal to intermix 2D and 3D curves in a
single graph. This command takes three arguments, ``x'', ``y'',
! and ``z'', from the stack. With a positive prefix @cite{n}, it
! takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n}
separate ``z''s). With a zero prefix, it takes three stack entries
but the ``z'' entry is a vector of curve values. With a negative
! prefix @cite{n}, it takes @cite{n} vectors of the form @cite{[x, y, z]}.
The @kbd{g A} command works by adding a @code{splot} (surfaceplot)
command to the @samp{*Gnuplot Commands*} buffer.
 28671,28681 
The @kbd{g A} (@code{calcgraphadd3d}) command adds a 3D curve
to the graph. It is not legal to intermix 2D and 3D curves in a
single graph. This command takes three arguments, ``x'', ``y'',
! and ``z'', from the stack. With a positive prefix @expr{n}, it
! takes @expr{n+2} arguments (common ``x'' and ``y'', plus @expr{n}
separate ``z''s). With a zero prefix, it takes three stack entries
but the ``z'' entry is a vector of curve values. With a negative
! prefix @expr{n}, it takes @expr{n} vectors of the form @expr{[x, y, z]}.
The @kbd{g A} command works by adding a @code{splot} (surfaceplot)
command to the @samp{*Gnuplot Commands*} buffer.
***************
*** 28469,28481 ****
graphs created by @kbd{g a} that don't specify the resolution explicitly.
With a negative prefix argument, this command changes or displays
the default value (initially 5) used for 3D graphs created by @kbd{g A}.
! Note that a 3D setting of 5 means that a total of @cite{5^2 = 25} points
will be computed for the surface.
Data values in the graph of a function are normally computed to a
precision of five digits, regardless of the current precision at the
time. This is usually more than adequate, but there are cases where
! it will not be. For example, plotting @cite{1 + x} with @cite{x} in the
interval @samp{[0 ..@: 1e6]} will round all the data points down
to 1.0! Putting the command @samp{set precision @var{n}} in the
@samp{*Gnuplot Commands*} buffer will cause the data to be computed
 28794,28806 
graphs created by @kbd{g a} that don't specify the resolution explicitly.
With a negative prefix argument, this command changes or displays
the default value (initially 5) used for 3D graphs created by @kbd{g A}.
! Note that a 3D setting of 5 means that a total of @expr{5^2 = 25} points
will be computed for the surface.
Data values in the graph of a function are normally computed to a
precision of five digits, regardless of the current precision at the
time. This is usually more than adequate, but there are cases where
! it will not be. For example, plotting @expr{1 + x} with @expr{x} in the
interval @samp{[0 ..@: 1e6]} will round all the data points down
to 1.0! Putting the command @samp{set precision @var{n}} in the
@samp{*Gnuplot Commands*} buffer will cause the data to be computed
***************
*** 28621,28628 ****
picture of the graph composed of characters like @code{} and @code{}
to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.
The graph is made the same size as the Emacs screen, which on most
! dumb terminals will be @c{$80\times24$}
! @asis{80x24} characters. The graph is displayed in
an Emacs ``recursive edit''; type @kbd{q} or @kbd{M# M#} to exit
the recursive edit and return to Calc. Note that the @code{dumb}
device is present only in GNUPLOT 3.0 and later versions.
 28946,28955 
picture of the graph composed of characters like @code{} and @code{}
to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.
The graph is made the same size as the Emacs screen, which on most
! dumb terminals will be
! @texline @tmath{80\times24}
! @infoline 80x24
! characters. The graph is displayed in
an Emacs ``recursive edit''; type @kbd{q} or @kbd{M# M#} to exit
the recursive edit and return to Calc. Note that the @code{dumb}
device is present only in GNUPLOT 3.0 and later versions.
***************
*** 28824,28831 ****
it appears on the screen, including line numbers if they are enabled.
A numeric prefix argument to @kbd{Ck} or @kbd{Mk} affects the number
! of lines killed. A positive argument kills the current line and @cite{n1}
! lines below it. A negative argument kills the @cite{n} lines above the
current line. Again this mirrors the behavior of the standard Emacs
@kbd{Ck} command. Although a whole line is always deleted, @kbd{Ck}
with no argument copies only the number itself into the kill ring, whereas
 29151,29158 
it appears on the screen, including line numbers if they are enabled.
A numeric prefix argument to @kbd{Ck} or @kbd{Mk} affects the number
! of lines killed. A positive argument kills the current line and @expr{n1}
! lines below it. A negative argument kills the @expr{n} lines above the
current line. Again this mirrors the behavior of the standard Emacs
@kbd{Ck} command. Although a whole line is always deleted, @kbd{Ck}
with no argument copies only the number itself into the kill ring, whereas
***************
*** 28868,28876 ****
A numeric prefix argument grabs the specified number of lines around
point, ignoring the mark. A positive prefix grabs from point to the
! @cite{n}th following newline (so that @kbd{M1 M# g} grabs from point
to the end of the current line); a negative prefix grabs from point
! back to the @cite{n+1}st preceding newline. In these cases the text
that is grabbed is exactly the same as the text that @kbd{Ck} would
delete given that prefix argument.
 29195,29203 
A numeric prefix argument grabs the specified number of lines around
point, ignoring the mark. A positive prefix grabs from point to the
! @expr{n}th following newline (so that @kbd{M1 M# g} grabs from point
to the end of the current line); a negative prefix grabs from point
! back to the @expr{n+1}st preceding newline. In these cases the text
that is grabbed is exactly the same as the text that @kbd{Ck} would
delete given that prefix argument.
***************
*** 28926,28937 ****
will be split up into columns of width @var{n}; each column is parsed
separately as a matrix element. If a line contained
@address@hidden +/ 3 4 +/ 5}}, then grabbing with a prefix argument of 8
! would correctly split the line into two error address@hidden
@xref{Matrix Functions}, to see how to pull the matrix apart into its
! constituent rows and columns. (If it is a @c{$1\times1$}
! @asis{1x1} matrix, just hit @kbd{v u}
! (@code{calcunpack}) twice.)
@kindex M# :
@kindex M# _
 29253,29265 
will be split up into columns of width @var{n}; each column is parsed
separately as a matrix element. If a line contained
@address@hidden +/ 3 4 +/ 5}}, then grabbing with a prefix argument of 8
! would correctly split the line into two error forms.
@xref{Matrix Functions}, to see how to pull the matrix apart into its
! constituent rows and columns. (If it is a
! @texline @tmath{1\times1}
! @infoline 1x1
! matrix, just hit @kbd{v u} (@code{calcunpack}) twice.)
@kindex M# :
@kindex M# _
***************
*** 28984,28990 ****
With a prefix argument, @kbd{y} inserts several numbers, one per line.
A positive argument inserts the specified number of values from the top
! of the stack. A negative argument inserts the @cite{n}th value from the
top of the stack. An argument of zero inserts the entire stack. Note
that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
with no argument; the former always copies full lines, whereas the
 29312,29318 
With a prefix argument, @kbd{y} inserts several numbers, one per line.
A positive argument inserts the specified number of values from the top
! of the stack. A negative argument inserts the @expr{n}th value from the
top of the stack. An argument of zero inserts the entire stack. Note
that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
with no argument; the former always copies full lines, whereas the
***************
*** 28999,29005 ****
display style (@pxref{Vector and Matrix Formats}) or change the current
display language (@pxref{Language Modes}) before doing this. Also, note
that this command replaces a linear region of text (as grabbed by
! @kbd{M# g}), not a rectangle (as grabbed by @kbd{M# r})address@hidden
If the editing buffer is in overwrite (as opposed to insert) mode,
and the @kbd{Cu} prefix was not used, then the yanked number will
 29327,29333 
display style (@pxref{Vector and Matrix Formats}) or change the current
display language (@pxref{Language Modes}) before doing this. Also, note
that this command replaces a linear region of text (as grabbed by
! @kbd{M# g}), not a rectangle (as grabbed by @kbd{M# r}).
If the editing buffer is in overwrite (as opposed to insert) mode,
and the @kbd{Cu} prefix was not used, then the yanked number will
***************
*** 29187,29193 ****
@item INV *
is the same as @key{y^x}.
@item INV /
! is the same as @key{INV y^x} (the @cite{x}th root of @cite{y}).
@item HYP/INV 1
are the same as @key{SIN} / @kbd{INV SIN}.
@item HYP/INV 2
 29515,29521 
@item INV *
is the same as @key{y^x}.
@item INV /
! is the same as @key{INV y^x} (the @expr{x}th root of @expr{y}).
@item HYP/INV 1
are the same as @key{SIN} / @kbd{INV SIN}.
@item HYP/INV 2
***************
*** 29253,29259 ****
prefix keys.
@key{IMAG} multiplies the number on the stack by the imaginary
! number @cite{i = (0, 1)}.
@key{RE} extracts the real part a complex number. @kbd{INV RE}
extracts the imaginary part.
 29581,29587 
prefix keys.
@key{IMAG} multiplies the number on the stack by the imaginary
! number @expr{i = (0, 1)}.
@key{RE} extracts the real part a complex number. @kbd{INV RE}
extracts the imaginary part.
***************
*** 29266,29273 ****
@key{INV GCD} computes the LCM (least common multiple) function.
! @key{INV FACT} is the gamma function. @c{$\Gamma(x) = (x1)!$}
! @cite{gamma(x) = (x1)!}.
@key{PERM} is the numberofpermutations function, which is on the
@kbd{H k c} key in normal Calc.
 29594,29602 
@key{INV GCD} computes the LCM (least common multiple) function.
! @key{INV FACT} is the gamma function.
! @texline @tmath{\Gamma(x) = (x1)!}.
! @infoline @expr{gamma(x) = (x1)!}.
@key{PERM} is the numberofpermutations function, which is on the
@kbd{H k c} key in normal Calc.
***************
*** 29382,29394 ****
For example, you could simulate @key{MAP^} using @key{MAP$} with
the formula @samp{x^y}.
! The @kbd{"x"} key pushes the variable name @cite{x} onto the
! stack. To build the formula @cite{x^2 + 6}, you would use the
key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be
suitable for use with the @key{MAP$} key described above.
With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the
! @kbd{"x"} key pushes the variable names @cite{y}, @cite{z}, and
! @cite{t}, respectively.
@node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode
@section Modes Menu
 29711,29723 
For example, you could simulate @key{MAP^} using @key{MAP$} with
the formula @samp{x^y}.
! The @kbd{"x"} key pushes the variable name @expr{x} onto the
! stack. To build the formula @expr{x^2 + 6}, you would use the
key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be
suitable for use with the @key{MAP$} key described above.
With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the
! @kbd{"x"} key pushes the variable names @expr{y}, @expr{z}, and
! @expr{t}, respectively.
@node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode
@section Modes Menu
***************
*** 29553,29559 ****
@end example
@noindent
! The formula @cite{n>2} will be pushed onto the Calc stack, and
the top of stack will be copied back into the editing buffer.
This means that spaces will appear around the @samp{>} symbol
to match Calc's usual display style:
 29882,29888 
@end example
@noindent
! The formula @expr{n>2} will be pushed onto the Calc stack, and
the top of stack will be copied back into the editing buffer.
This means that spaces will appear around the @samp{>} symbol
to match Calc's usual display style:
***************
*** 29681,29688 ****
Embedded buffers remember active formulas for as long as they
exist in Emacs memory. Suppose you have an embedded formula
! which is @c{$\pi$}
! @cite{pi} to the normal 12 decimal places, and then
type @address@hidden 5 d n}} to display only five decimal places.
If you then type @kbd{d n}, all 12 places reappear because the
full number is still there on the Calc stack. More surprisingly,
 30010,30016 
Embedded buffers remember active formulas for as long as they
exist in Emacs memory. Suppose you have an embedded formula
! which is @cpi{} to the normal 12 decimal places, and then
type @address@hidden 5 d n}} to display only five decimal places.
If you then type @kbd{d n}, all 12 places reappear because the
full number is still there on the Calc stack. More surprisingly,
***************
*** 29820,29828 ****
@end example
@noindent
! records @cite{5} as the stored value of @code{foo} for the
purposes of Embedded mode operations in the current buffer. It
! does @emph{not} actually store @cite{5} as the ``global'' value
of @code{foo}, however. Regular Calc operations, and Embedded
formulas in other buffers, will not see this assignment.
 30148,30156 
@end example
@noindent
! records @expr{5} as the stored value of @code{foo} for the
purposes of Embedded mode operations in the current buffer. It
! does @emph{not} actually store @expr{5} as the ``global'' value
of @code{foo}, however. Regular Calc operations, and Embedded
formulas in other buffers, will not see this assignment.
***************
*** 29891,29897 ****
mode. Then, we have to find a way to get Embedded mode to notice
the change. The @kbd{M# u} or @kbd{M# =}
(@code{calcembeddedupdateformula}) command is a convenient way
! to do address@hidden
@example
foo := 6
 30219,30225 
mode. Then, we have to find a way to get Embedded mode to notice
the change. The @kbd{M# u} or @kbd{M# =}
(@code{calcembeddedupdateformula}) command is a convenient way
! to do this.
@example
foo := 6
***************
*** 30458,30464 ****
Press address@hidden (or the standard Emacs key sequence @kbd{Cx e}) to
execute your keyboard macro by replaying the recorded keystrokes.
@xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further
! address@hidden
When you use @kbd{X} to invoke a keyboard macro, the entire macro is
treated as a single command by the undo and trail features. The stack
 30786,30792 
Press address@hidden (or the standard Emacs key sequence @kbd{Cx e}) to
execute your keyboard macro by replaying the recorded keystrokes.
@xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further
! information.
When you use @kbd{X} to invoke a keyboard macro, the entire macro is
treated as a single command by the undo and trail features. The stack
***************
*** 30504,30510 ****
just the @key{RET} key as in this example) will be something like
@samp{calcUsern}. The keyboard macro will now be available as both
@kbd{z n} and @kbd{Mx calcUsern}. You can backspace and enter a more
! descriptive command name if you address@hidden
Macros defined by @kbd{Z K} act like single commands; they are executed
in the same way as by the @kbd{X} key. If you wish to define the macro
 30832,30838 
just the @key{RET} key as in this example) will be something like
@samp{calcUsern}. The keyboard macro will now be available as both
@kbd{z n} and @kbd{Mx calcUsern}. You can backspace and enter a more
! descriptive command name if you wish.
Macros defined by @kbd{Z K} act like single commands; they are executed
in the same way as by the @kbd{X} key. If you wish to define the macro
***************
*** 30522,30528 ****
the macro definition into full Emacs command names, like @code{calcpop}
and @code{calcadd}. Type @kbd{M# M#} to finish editing and update
the definition stored on the key, or, to cancel the edit, type
! @kbd{M# address@hidden
If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard
macro is edited in spelledout keystroke form. For example, the editing
 30850,30856 
the macro definition into full Emacs command names, like @code{calcpop}
and @code{calcadd}. Type @kbd{M# M#} to finish editing and update
the definition stored on the key, or, to cancel the edit, type
! @kbd{M# x}.
If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard
macro is edited in spelledout keystroke form. For example, the editing
***************
*** 30536,30548 ****
same as is used in all of this manual's examples, except that the manual
takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we
take
it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2
@key{SPC} 3] @key{RET}},
! which is what @code{readkbdmacro} wants to address@hidden
If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro
in ``raw'' form; the editing buffer simply contains characters like
@samp{1^M2+} (here @samp{^M} represents the carriagereturn character).
Editing in this mode, you will have to use @kbd{Cq} to enter new
! control characters into the address@hidden
@kindex M# m
@pindex readkbdmacro
 30864,30876 
same as is used in all of this manual's examples, except that the manual
takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we
take
it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2
@key{SPC} 3] @key{RET}},
! which is what @code{readkbdmacro} wants to see.
If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro
in ``raw'' form; the editing buffer simply contains characters like
@samp{1^M2+} (here @samp{^M} represents the carriagereturn character).
Editing in this mode, you will have to use @kbd{Cq} to enter new
! control characters into the buffer.
@kindex M# m
@pindex readkbdmacro
***************
*** 30646,30652 ****
computes two to a nonnegative integer power. First, we push 1 on the
stack and then swap the integer argument back to the top. The @kbd{Z <}
pops that argument leaving the 1 back on top of the stack. Then, we
! repeat a multiplybytwo step however many address@hidden
Once again, the keyboard macro is executed as it is being entered.
In this case it is especially important to set up reasonable initial
 30974,30980 
computes two to a nonnegative integer power. First, we push 1 on the
stack and then swap the integer argument back to the top. The @kbd{Z <}
pops that argument leaving the 1 back on top of the stack. Then, we
! repeat a multiplybytwo step however many times.
Once again, the keyboard macro is executed as it is being entered.
In this case it is especially important to set up reasonable initial
***************
*** 30666,30672 ****
innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues
after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no
effect. Thus @address@hidden Z /} is similar to @samp{if (@var{cond}) break;}
! in the C address@hidden
@kindex Z (
@kindex Z )
 30994,31000 
innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues
after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no
effect. Thus @address@hidden Z /} is similar to @samp{if (@var{cond}) break;}
! in the C language.
@kindex Z (
@kindex Z )
***************
*** 30680,30686 ****
a temporary internal counter and initializes it with the value @var{init}.
The @kbd{Z (} command then repeatedly pushes the counter value onto the
stack and executes @var{body} and @var{step}, adding @var{step} to the
! counter each time until the loop address@hidden
@cindex Summations (by keyboard macros)
By default, the loop finishes when the counter becomes greater than (or
 31008,31014 
a temporary internal counter and initializes it with the value @var{init}.
The @kbd{Z (} command then repeatedly pushes the counter value onto the
stack and executes @var{body} and @var{step}, adding @var{step} to the
! counter each time until the loop finishes.
@cindex Summations (by keyboard macros)
By default, the loop finishes when the counter becomes greater than (or
***************
*** 30880,30886 ****
new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}.
Then the new function can be invoked by pushing two numbers on the
stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic
! formula @samp{yow(x,y)address@hidden
The fourth prompt is for the function's argument list. This is used to
associate values on the stack with the variables that appear in the formula.
 31208,31214 
new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}.
Then the new function can be invoked by pushing two numbers on the
stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic
! formula @samp{yow(x,y)}.
The fourth prompt is for the function's argument list. This is used to
associate values on the stack with the variables that appear in the formula.
***************
*** 30891,30899 ****
@samp{b} (respectively) in the formula, then simplify the formula and
push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m}
would replace the 10 and 100 on the stack with the number 210, which is
! @cite{a + 2 b} with @cite{a=10} and @cite{b=100}. Likewise, the formula
! @samp{yow(10, 100)} will be evaluated by substituting @cite{a=10} and
! @cite{b=100} in the definition.
You can rearrange the order of the names before pressing @key{RET} to
control which stack positions go to which variables in the formula. If
 31219,31227 
@samp{b} (respectively) in the formula, then simplify the formula and
push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m}
would replace the 10 and 100 on the stack with the number 210, which is
! @expr{a + 2 b} with @expr{a=10} and @expr{b=100}. Likewise, the formula
! @samp{yow(10, 100)} will be evaluated by substituting @expr{a=10} and
! @expr{b=100} in the definition.
You can rearrange the order of the names before pressing @key{RET} to
control which stack positions go to which variables in the formula. If
***************
*** 30911,30922 ****
The final prompt is a yorn question concerning what to do if symbolic
arguments are given to your function. If you answer @kbd{y}, then
executing @kbd{z m} (using the original argument list @samp{(a b)}) with
! arguments @cite{10} and @cite{x} will leave the function in symbolic
form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n},
then the formula will always be expanded, even for nonconstant
arguments: @samp{10 + 2 x}. If you never plan to feed algebraic
formulas to your new function, it doesn't matter how you answer this
! address@hidden
If you answered @kbd{y} to this question you can still cause a function
call to be expanded by typing @kbd{a "} (@code{calcexpandformula}).
 31239,31250 
The final prompt is a yorn question concerning what to do if symbolic
arguments are given to your function. If you answer @kbd{y}, then
executing @kbd{z m} (using the original argument list @samp{(a b)}) with
! arguments @expr{10} and @expr{x} will leave the function in symbolic
form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n},
then the formula will always be expanded, even for nonconstant
arguments: @samp{10 + 2 x}. If you never plan to feed algebraic
formulas to your new function, it doesn't matter how you answer this
! question.
If you answered @kbd{y} to this question you can still cause a function
call to be expanded by typing @kbd{a "} (@code{calcexpandformula}).
***************
*** 30931,30937 ****
key onto the stack. Actually, it pushes a nameless function that
specifies both the argument list and the defining formula. You will get
an error message if the key is undefined, or if the key was not defined
! by a @kbd{Z F} address@hidden
The @kbd{Z E} (@code{calcuserdefineedit}) command on a key that has
been defined by a formula uses a variant of the @code{calcedit} command
 31259,31265 
key onto the stack. Actually, it pushes a nameless function that
specifies both the argument list and the defining formula. You will get
an error message if the key is undefined, or if the key was not defined
! by a @kbd{Z F} command.
The @kbd{Z E} (@code{calcuserdefineedit}) command on a key that has
been defined by a formula uses a variant of the @code{calcedit} command
***************
*** 30951,30957 ****
used as a function definition. For example, the formula @samp{deriv(a^2,v)}
which might be used to define a new function @samp{dsqr(a,v)} will be
``simplified'' to 0 immediately upon entry since @code{deriv} considers
! @cite{a} to be constant with respect to @cite{v}. Turning off
default simplifications cures this problem: The definition will be stored
in symbolic form without ever activating the @code{deriv} function. Press
@kbd{m D} to turn the default simplifications back on afterwards.
 31279,31285 
used as a function definition. For example, the formula @samp{deriv(a^2,v)}
which might be used to define a new function @samp{dsqr(a,v)} will be
``simplified'' to 0 immediately upon entry since @code{deriv} considers
! @expr{a} to be constant with respect to @expr{v}. Turning off
default simplifications cures this problem: The definition will be stored
in symbolic form without ever activating the @code{deriv} function. Press
@kbd{m D} to turn the default simplifications back on afterwards.
***************
*** 31049,31055 ****
@code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=},
@code{/=}, @code{1+}, @code{1}, @code{logand}, @code{logior}, @code{logxor},
@code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for
! @code{mathnearlyequal}, which is useful in implementing Taylor
address@hidden
For other functions @var{func}, if a function by the name
@address@hidden exists it is used, otherwise if a function by the
 31377,31383 
@code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=},
@code{/=}, @code{1+}, @code{1}, @code{logand}, @code{logior}, @code{logxor},
@code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for
! @code{mathnearlyequal}, which is useful in implementing Taylor series.
For other functions @var{func}, if a function by the name
@address@hidden exists it is used, otherwise if a function by the
***************
*** 31057,31069 ****
is defined as a function it is used, otherwise @address@hidden is
used on the assumption that this is a tobedefined math function. Also, if
the function name is quoted as in @samp{('integerp a)} the function name is
! always used exactly as written (but not quoted)address@hidden
Variable names have @samp{var} prepended to them unless they appear in
the function's argument list or in an enclosing @code{let}, @code{let*},
@code{for}, or @code{foreach} form,
or their names already contain a @samp{} character. Thus a reference to
! @samp{foo} is the same as a reference to @address@hidden
A few other Lisp extensions are available in @code{defmath} definitions:
 31385,31397 
is defined as a function it is used, otherwise @address@hidden is
used on the assumption that this is a tobedefined math function. Also, if
the function name is quoted as in @samp{('integerp a)} the function name is
! always used exactly as written (but not quoted).
Variable names have @samp{var} prepended to them unless they appear in
the function's argument list or in an enclosing @code{let}, @code{let*},
@code{for}, or @code{foreach} form,
or their names already contain a @samp{} character. Thus a reference to
! @samp{foo} is the same as a reference to @samp{varfoo}.
A few other Lisp extensions are available in @code{defmath} definitions:
***************
*** 31081,31098 ****
a synonym of @code{setq}.) Specifically, the first argument of
@code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form,
in which case the effect is to store into the specified
! element of a list. Thus, @samp{(setq (elt m i j) x)} stores @cite{x}
into one element of a matrix.
@item
A @code{for} looping construct is available. For example,
@samp{(for ((i 0 10)) body)} executes @code{body} once for each
! binding of @cite{i} from zero to 10. This is like a @code{let}
! form in that @cite{i} is temporarily bound to the loop count
without disturbing its value outside the @code{for} construct.
Nested loops, as in @samp{(for ((i 0 10) (j 0 (1 i) 2)) body)},
! are also available. For each value of @cite{i} from zero to 10,
! @cite{j} counts from 0 to @cite{i1} in steps of two. Note that
@code{for} has the same general outline as @code{let*}, except
that each element of the header is a list of three or four
things, not just two.
 31409,31426 
a synonym of @code{setq}.) Specifically, the first argument of
@code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form,
in which case the effect is to store into the specified
! element of a list. Thus, @samp{(setq (elt m i j) x)} stores @expr{x}
into one element of a matrix.
@item
A @code{for} looping construct is available. For example,
@samp{(for ((i 0 10)) body)} executes @code{body} once for each
! binding of @expr{i} from zero to 10. This is like a @code{let}
! form in that @expr{i} is temporarily bound to the loop count
without disturbing its value outside the @code{for} construct.
Nested loops, as in @samp{(for ((i 0 10) (j 0 (1 i) 2)) body)},
! are also available. For each value of @expr{i} from zero to 10,
! @expr{j} counts from 0 to @expr{i1} in steps of two. Note that
@code{for} has the same general outline as @code{let*}, except
that each element of the header is a list of three or four
things, not just two.
***************
*** 31100,31107 ****
@item
The @code{foreach} construct loops over elements of a list.
For example, @samp{(foreach ((x (cdr v))) body)} executes
! @code{body} with @cite{x} bound to each element of Calc vector
! @cite{v} in turn. The purpose of @code{cdr} here is to skip over
the initial @code{vec} symbol in the vector.
@item
 31428,31435 
@item
The @code{foreach} construct loops over elements of a list.
For example, @samp{(foreach ((x (cdr v))) body)} executes
! @code{body} with @expr{x} bound to each element of Calc vector
! @expr{v} in turn. The purpose of @code{cdr} here is to skip over
the initial @code{vec} symbol in the vector.
@item
***************
*** 31112,31118 ****
@item
The @code{return} function prematurely returns from the enclosing
! function. For example, @samp{(return (+ x y))} returns @cite{x+y}
as the value of a function. You can use @code{return} anywhere
inside the body of the function.
@end itemize
 31440,31446 
@item
The @code{return} function prematurely returns from the enclosing
! function. For example, @samp{(return (+ x y))} returns @expr{x+y}
as the value of a function. You can use @code{return} anywhere
inside the body of the function.
@end itemize
***************
*** 31464,31470 ****
In this example, the command @code{calcfoo} will evaluate the expression
@samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if
! executed with a numeric prefix argument of @cite{n}.
The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}
code as used with @code{defun}). It uses the numeric prefix argument as the
 31792,31798 
In this example, the command @code{calcfoo} will evaluate the expression
@samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if
! executed with a numeric prefix argument of @expr{n}.
The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}
code as used with @code{defun}). It uses the numeric prefix argument as the
***************
*** 31501,31507 ****
The argument must not be an incomplete vector, interval, or complex number.
(This is rarely needed since the Calculator itself will never call your
function with an incomplete argument. But there is nothing stopping your
! own Lisp code from calling your function with an incomplete argument.)@refill
@item integer
@findex integer
 31829,31835 
The argument must not be an incomplete vector, interval, or complex number.
(This is rarely needed since the Calculator itself will never call your
function with an incomplete argument. But there is nothing stopping your
! own Lisp code from calling your function with an incomplete argument.)
@item integer
@findex integer
***************
*** 31665,31672 ****
@end ignore
@tindex mysin
A somewhat limited sine function could be defined as follows, using the
! wellknown Taylor series expansion for @c{$\sin x$}
! @samp{sin(x)}:
@smallexample
(defmath mysin ((float (anglep x)))
 31993,32001 
@end ignore
@tindex mysin
A somewhat limited sine function could be defined as follows, using the
! wellknown Taylor series expansion for
! @texline @tmath{\sin x}:
! @infoline @samp{sin(x)}:
@smallexample
(defmath mysin ((float (anglep x)))
***************
*** 31688,31695 ****
@end smallexample
The actual @code{sin} function in Calc works by first reducing the problem
! to a sine or cosine of a nonnegative number less than @c{$\pi \over 4$}
! @cite{pi/4}. This
ensures that the Taylor series will converge quickly. Also, the calculation
is carried out with two extra digits of precision to guard against cumulative
roundoff in @samp{sum}. Finally, complex arguments are allowed and handled
 32017,32023 
@end smallexample
The actual @code{sin} function in Calc works by first reducing the problem
! to a sine or cosine of a nonnegative number less than @cpiover{4}. This
ensures that the Taylor series will converge quickly. Also, the calculation
is carried out with two extra digits of precision to guard against cumulative
roundoff in @samp{sum}. Finally, complex arguments are allowed and handled
***************
*** 31724,31733 ****
series as before, and @code{mycosraw} is a function analogous to
@code{mysinraw} for cosines.
! The strategy is to ensure that @cite{x} is nonnegative before calling
@code{mysinraw}. This function then recursively reduces its argument
! to a suitable range, namely, plusorminus @c{$\pi \over 4$}
! @cite{pi/4}. Note that each
test, and particularly the first comparison against 7, is designed so
that small roundoff errors cannot produce an infinite loop. (Suppose
we compared with @samp{(twopi)} instead; if due to roundoff problems
 32052,32060 
series as before, and @code{mycosraw} is a function analogous to
@code{mysinraw} for cosines.
! The strategy is to ensure that @expr{x} is nonnegative before calling
@code{mysinraw}. This function then recursively reduces its argument
! to a suitable range, namely, plusorminus @cpiover{4}. Note that each
test, and particularly the first comparison against 7, is designed so
that small roundoff errors cannot produce an infinite loop. (Suppose
we compared with @samp{(twopi)} instead; if due to roundoff problems
***************
*** 31877,31884 ****
when the user has left Calc in symbolic mode or nosimplify mode.
As another example, @samp{(equal (calceval '("$<$$") nil a b) "1")}
! checks if the number in string @cite{a} is less than the one in
! string @cite{b}. Without using a list, the integer 1 might
come out in a variety of formats which would be hard to test for
conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But
see ``Predicates'' mode, below.)
 32204,32211 
when the user has left Calc in symbolic mode or nosimplify mode.
As another example, @samp{(equal (calceval '("$<$$") nil a b) "1")}
! checks if the number in string @expr{a} is less than the one in
! string @expr{b}. Without using a list, the integer 1 might
come out in a variety of formats which would be hard to test for
conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But
see ``Predicates'' mode, below.)
***************
*** 32218,32230 ****
are that the number 0.0 is always stored as @samp{(float 0 0)}, and,
except for the 0.0 case, the rightmost base10 digit of @var{mant} is
always nonzero. (If the rightmost digit is zero, the number is
! rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)@refill
Rectangular complex numbers are stored in the form @samp{(cplx @var{re}
@var{im})}, where @var{re} and @var{im} are each real numbers, either
integers, fractions, or floats. The value is @address@hidden + @var{im}i}.
The @var{im} part is nonzero; complex numbers with zero imaginary
! components are converted to real numbers address@hidden
Polar complex numbers are stored in the form @samp{(polar @var{r}
@var{theta})}, where @var{r} is a positive real value and @var{theta}
 32545,32557 
are that the number 0.0 is always stored as @samp{(float 0 0)}, and,
except for the 0.0 case, the rightmost base10 digit of @var{mant} is
always nonzero. (If the rightmost digit is zero, the number is
! rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)
Rectangular complex numbers are stored in the form @samp{(cplx @var{re}
@var{im})}, where @var{re} and @var{im} are each real numbers, either
integers, fractions, or floats. The value is @address@hidden + @var{im}i}.
The @var{im} part is nonzero; complex numbers with zero imaginary
! components are converted to real numbers automatically.
Polar complex numbers are stored in the form @samp{(polar @var{r}
@var{theta})}, where @var{r} is a positive real value and @var{theta}
***************
*** 32233,32245 ****
or @samp{(pi ..@: pi)} radians, according to the current angular mode.
If the angle is 0 the value is converted to a real number automatically.
(If the angle is 180 degrees, the value is usually also converted to a
! negative real number.)@refill
Hoursminutesseconds forms are stored as @samp{(hms @var{h} @var{m}
@var{s})}, where @var{h} is an integer or an integervalued float (i.e.,
a float with @address@hidden >= 0}), @var{m} is an integer or integervalued
float in the range @address@hidden ..@: 60)}}, and @var{s} is any real number
! in the range @samp{[0 ..@: 60)address@hidden
Date forms are stored as @samp{(date @var{n})}, where @var{n} is
a real number that counts days since midnight on the morning of
 32560,32572 
or @samp{(pi ..@: pi)} radians, according to the current angular mode.
If the angle is 0 the value is converted to a real number automatically.
(If the angle is 180 degrees, the value is usually also converted to a
! negative real number.)
Hoursminutesseconds forms are stored as @samp{(hms @var{h} @var{m}
@var{s})}, where @var{h} is an integer or an integervalued float (i.e.,
a float with @address@hidden >= 0}), @var{m} is an integer or integervalued
float in the range @address@hidden ..@: 60)}}, and @var{s} is any real number
! in the range @samp{[0 ..@: 60)}.
Date forms are stored as @samp{(date @var{n})}, where @var{n} is
a real number that counts days since midnight on the morning of
***************
*** 32293,32299 ****
which represent units are not stored in any special way; they are units
only because their names appear in the units table. If the value
cell contains a string, it is parsed to get the variable's value when
! the variable is address@hidden
A Lisp list with any other symbol as the first element is a function call.
The symbols @code{+}, @code{}, @code{*}, @code{/}, @code{%}, @code{^},
 32620,32626 
which represent units are not stored in any special way; they are units
only because their names appear in the units table. If the value
cell contains a string, it is parsed to get the variable's value when
! the variable is used.
A Lisp list with any other symbol as the first element is a function call.
The symbols @code{+}, @code{}, @code{*}, @code{/}, @code{%}, @code{^},
***************
*** 32313,32319 ****
wish to return multiple values. (The latter case is allowed only for
functions which are the outerlevel call in an expression whose value is
about to be pushed on the stack; this feature is considered obsolete
! and is not used by any builtin Calc functions.)@refill
@node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats,
Internals
@subsubsection Interactive Functions
 32640,32646 
wish to return multiple values. (The latter case is allowed only for
functions which are the outerlevel call in an expression whose value is
about to be pushed on the stack; this feature is considered obsolete
! and is not used by any builtin Calc functions.)
@node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats,
Internals
@subsubsection Interactive Functions
***************
*** 32349,32355 ****
previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})},
which means that to undo requires calling the function @samp{(@var{undo}
@var{args} @dots{})} and, if the undo is later redone, calling
! @samp{(@var{redo} @var{args} @dots{})address@hidden
@end defun
@defun calcrecordwhy msg args
 32676,32682 
previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})},
which means that to undo requires calling the function @samp{(@var{undo}
@var{args} @dots{})} and, if the undo is later redone, calling
! @samp{(@var{redo} @var{args} @dots{})}.
@end defun
@defun calcrecordwhy msg args
***************
*** 32364,32370 ****
(such as @code{integerp} or @code{numvecp}) which the arguments did not
satisfy; it is expanded to a suitable string such as ``Expected an
integer.'' The @code{rejectarg} function calls @code{calcrecordwhy}
! automatically; @address@hidden
@end defun
@defun calcisinverse
 32691,32697 
(such as @code{integerp} or @code{numvecp}) which the arguments did not
satisfy; it is expanded to a suitable string such as ``Expected an
integer.'' The @code{rejectarg} function calls @code{calcrecordwhy}
! automatically; @pxref{Predicates}.
@end defun
@defun calcisinverse
***************
*** 32391,32397 ****
end up at level @var{n}, the nexttolast at level @var{n}+1, etc.
The elements of @var{vals} are assumed to be valid Calc objects, and
are not evaluated, rounded, or renormalized in any way. If @var{vals}
! is an empty list, nothing address@hidden
The stack elements are pushed without any subformula selections.
You can give an optional third argument to this function, which must
 32718,32724 
end up at level @var{n}, the nexttolast at level @var{n}+1, etc.
The elements of @var{vals} are assumed to be valid Calc objects, and
are not evaluated, rounded, or renormalized in any way. If @var{vals}
! is an empty list, nothing happens.
The stack elements are pushed without any subformula selections.
You can give an optional third argument to this function, which must
***************
*** 32410,32416 ****
element will be nexttolast, etc. If @var{n} or @var{m} are out of
range, the command is aborted with a suitable error message. If @var{n}
is zero, the function returns an empty list. The stack elements are not
! evaluated, rounded, or address@hidden
If any stack elements contain selections, and selections have not
been disabled by the @kbd{j e} (@code{calcenableselections}) command,
 32737,32743 
element will be nexttolast, etc. If @var{n} or @var{m} are out of
range, the command is aborted with a suitable error message. If @var{n}
is zero, the function returns an empty list. The stack elements are not
! evaluated, rounded, or renormalized.
If any stack elements contain selections, and selections have not
been disabled by the @kbd{j e} (@code{calcenableselections}) command,
***************
*** 32506,32512 ****
argument to apply the operator over many stack entries. If the prefix
argument @var{arg} is @code{nil}, this uses @code{calcenterresult}
as outlined above. Otherwise, it maps the function over several stack
! elements; @pxref{Prefix Arguments}. For example,@refill
@smallexample
(defun calczeta (arg)
 32833,32839 
argument to apply the operator over many stack entries. If the prefix
argument @var{arg} is @code{nil}, this uses @code{calcenterresult}
as outlined above. Otherwise, it maps the function over several stack
! elements; @pxref{Prefix Arguments}. For example,
@smallexample
(defun calczeta (arg)
***************
*** 32527,32533 ****
the binary function @var{func} is reduced across the top @var{arg}
stack elements; when the argument is negative, the function is
mapped between the nexttotop @address@hidden stack elements and the
! top address@hidden
@end defun
@defun calcstacksize
 32854,32860 
the binary function @var{func} is reduced across the top @var{arg}
stack elements; when the argument is negative, the function is
mapped between the nexttotop @address@hidden stack elements and the
! top element.
@end defun
@defun calcstacksize
***************
*** 32541,32547 ****
will be the @samp{.} line. If @var{n} is from 1 to the current stack size,
this will be the beginning of the first line of that stack entry's display.
If line numbers are enabled, this will move to the first character of the
! line number, not the stack entry address@hidden
@end defun
@defun calcsubstackheight n
 32868,32874 
will be the @samp{.} line. If @var{n} is from 1 to the current stack size,
this will be the beginning of the first line of that stack entry's display.
If line numbers are enabled, this will move to the first character of the
! line number, not the stack entry itself.
@end defun
@defun calcsubstackheight n
***************
*** 32551,32557 ****
one line long (i.e., no matrices are displayed), the return value will
be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big
mode, the return value includes the blank lines that separate stack
! entries.)@refill
@end defun
@defun calcrefresh
 32878,32884 
one line long (i.e., no matrices are displayed), the return value will
be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big
mode, the return value includes the blank lines that separate stack
! entries.)
@end defun
@defun calcrefresh
***************
*** 32560,32566 ****
display radix, which might change the appearance of existing stack
entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing
is suppressed, but a flag is set so that the entire stack will be refreshed
! rather than just the top few elements when the macro finishes.)@refill
@end defun
@node Predicates, Computational Lisp Functions, Stack Lisp Functions,
Internals
 32887,32893 
display radix, which might change the appearance of existing stack
entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing
is suppressed, but a flag is set so that the entire stack will be refreshed
! rather than just the top few elements when the macro finishes.)
@end defun
@node Predicates, Computational Lisp Functions, Stack Lisp Functions,
Internals
***************
*** 32739,32745 ****
by checking whether @address@hidden  @var{y}} is @code{negp}. In
@code{defmath}, the expression @samp{(< x y)} will automatically be
converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=},
! and @code{>=} are similarly converted in terms of @address@hidden
@end defun
@defun beforep x y
 33066,33072 
by checking whether @address@hidden  @var{y}} is @code{negp}. In
@code{defmath}, the expression @samp{(< x y)} will automatically be
converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=},
! and @code{>=} are similarly converted in terms of @code{lessp}.
@end defun
@defun beforep x y
***************
*** 32771,32777 ****
Returns true if @var{x} and @var{n} are numerically equal, where @var{n}
is a fixnum which is not a multiple of 10. This will automatically be
used by @code{defmath} in place of the more general @code{mathequal}
! whenever address@hidden
@end defun
@defun nearlyequal x y
 33098,33104 
Returns true if @var{x} and @var{n} are numerically equal, where @var{n}
is a fixnum which is not a multiple of 10. This will automatically be
used by @code{defmath} in place of the more general @code{mathequal}
! whenever possible.
@end defun
@defun nearlyequal x y
***************
*** 32808,32814 ****
Abort the current function evaluation due to unacceptable argument values.
This calls @samp{(calcrecordwhy @var{pred} @var{val})}, then signals a
Lisp error which @code{normalize} will trap. The net effect is that the
! function call which led here will be left in symbolic address@hidden
@end defun
@defun inexactvalue
 33135,33141 
Abort the current function evaluation due to unacceptable argument values.
This calls @samp{(calcrecordwhy @var{pred} @var{val})}, then signals a
Lisp error which @code{normalize} will trap. The net effect is that the
! function call which led here will be left in symbolic form.
@end defun
@defun inexactvalue
***************
*** 32819,32825 ****
@code{sin} function will call @code{inexactvalue}, which will cause your
function to be left unsimplified. You may instead wish to call
@samp{(normalize (list 'calcFuncsin 5))}, which in Symbolic Mode will
! return the formula @samp{sin(5)} to your address@hidden
@end defun
@defun overflow
 33146,33152 
@code{sin} function will call @code{inexactvalue}, which will cause your
function to be left unsimplified. You may instead wish to call
@samp{(normalize (list 'calcFuncsin 5))}, which in Symbolic Mode will
! return the formula @samp{sin(5)} to your function.
@end defun
@defun overflow
***************
*** 32840,32852 ****
the documentation refers to the @code{calcsqrt} address@hidden command,
this means @code{calcsqrt} is an interactive stackbased squareroot
command and @code{sqrt} (which @code{defmath} expands to @code{calcFuncsqrt})
! is the actual Lisp function for taking square address@hidden
The functions @code{mathadd}, @code{mathsub}, @code{mathmul},
@code{mathdiv}, @code{mathmod}, and @code{mathneg} are not included
in this list, since @code{defmath} allows you to write native Lisp
@code{+}, @code{}, @code{*}, @code{/}, @code{%}, and unary @code{},
! respectively, address@hidden
@defun normalize val
(Full form: @code{mathnormalize}.)
 33167,33179 
the documentation refers to the @code{calcsqrt} address@hidden command,
this means @code{calcsqrt} is an interactive stackbased squareroot
command and @code{sqrt} (which @code{defmath} expands to @code{calcFuncsqrt})
! is the actual Lisp function for taking square roots.
The functions @code{mathadd}, @code{mathsub}, @code{mathmul},
@code{mathdiv}, @code{mathmod}, and @code{mathneg} are not included
in this list, since @code{defmath} allows you to write native Lisp
@code{+}, @code{}, @code{*}, @code{/}, @code{%}, and unary @code{},
! respectively, instead.
@defun normalize val
(Full form: @code{mathnormalize}.)
***************
*** 32857,32868 ****
small. All the various data types are similarly converted to their standard
forms. Variables are left alone, but function calls are actually evaluated
in formulas. For example, normalizing @samp{(+ 2 (calcFuncabs 4))} will
! return address@hidden
If a function call fails, because the function is void or has the wrong
number of parameters, or because it returns @code{nil} or calls
@code{rejectarg} or @code{inexactresult}, @code{normalize} returns
! the formula still in symbolic address@hidden
If the current Simplification Mode is ``none'' or ``numeric arguments
only,'' @code{normalize} will act appropriately. However, the more
 33184,33195 
small. All the various data types are similarly converted to their standard
forms. Variables are left alone, but function calls are actually evaluated
in formulas. For example, normalizing @samp{(+ 2 (calcFuncabs 4))} will
! return 6.
If a function call fails, because the function is void or has the wrong
number of parameters, or because it returns @code{nil} or calls
@code{rejectarg} or @code{inexactresult}, @code{normalize} returns
! the formula still in symbolic form.
If the current Simplification Mode is ``none'' or ``numeric arguments
only,'' @code{normalize} will act appropriately. However, the more
***************
*** 32871,32883 ****
which calls @code{normalize} and possibly some other routines, such
as @code{simplify} or @code{simplifyunits}. Programs generally will
never call @code{calcnormalize} except when popping or pushing values
! on the address@hidden
@end defun
@defun evaluateexpr expr
Replace all variables in @var{expr} that have values with their values,
then use @code{normalize} to simplify the result. This is what happens
! when you press the @kbd{=} key address@hidden
@end defun
@defmac withextraprec n body
 33198,33210 
which calls @code{normalize} and possibly some other routines, such
as @code{simplify} or @code{simplifyunits}. Programs generally will
never call @code{calcnormalize} except when popping or pushing values
! on the stack.
@end defun
@defun evaluateexpr expr
Replace all variables in @var{expr} that have values with their values,
then use @code{normalize} to simplify the result. This is what happens
! when you press the @kbd{=} key interactively.
@end defun
@defmac withextraprec n body
***************
*** 32948,32954 ****
Compare the numbers @var{x} and @var{y}, and return @i{1} if
@samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})},
0 if @samp{(mathequal @var{x} @var{y})}, or 2 if the order is
! undefined or cannot be address@hidden
@end defun
@defun numdigs n
 33275,33281 
Compare the numbers @var{x} and @var{y}, and return @i{1} if
@samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})},
0 if @samp{(mathequal @var{x} @var{y})}, or 2 if the order is
! undefined or cannot be determined.
@end defun
@defun numdigs n
***************
*** 33000,33012 ****
@defun idivmod x y
Divide integer @var{x} by integer @var{y}; return a cons cell whose
@code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}
! is @samp{(imod @var{x} @var{y})address@hidden
@end defun
@defun pow x y
Compute @var{x} to the power @var{y}. In @code{defmath} code, this can
also be written @samp{(^ @var{x} @var{y})} or
! @address@hidden(expt @var{x} @var{y})address@hidden
@end defun
@defun absapprox x
 33327,33339 
@defun idivmod x y
Divide integer @var{x} by integer @var{y}; return a cons cell whose
@code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}
! is @samp{(imod @var{x} @var{y})}.
@end defun
@defun pow x y
Compute @var{x} to the power @var{y}. In @code{defmath} code, this can
also be written @samp{(^ @var{x} @var{y})} or
! @address@hidden(expt @var{x} @var{y})}}.
@end defun
@defun absapprox x
***************
*** 33030,33036 ****
@code{piover2}, @code{piover4}, @code{piover180}, @code{sqrttwopi},
@code{e}, @code{sqrte}, @code{ln2}, and @code{ln10}. Each function
returns a floatingpoint value in the current precision, and each uses
! caching so that all calls after the first are essentially address@hidden
@end defun
@defmac mathdefcache @var{func} @var{initial} @var{form}
 33357,33363 
@code{piover2}, @code{piover4}, @code{piover180}, @code{sqrttwopi},
@code{e}, @code{sqrte}, @code{ln2}, and @code{ln10}. Each function
returns a floatingpoint value in the current precision, and each uses
! caching so that all calls after the first are essentially free.
@end defun
@defmac mathdefcache @var{func} @var{initial} @var{form}
***************
*** 33045,33051 ****
two least significant digits is stored in the cache. For example,
calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34
digits, rounds it down to 32 digits for future use, then rounds it
! again to 30 digits for use in the present address@hidden
@end defmac
@findex halfcircle
 33372,33378 
two least significant digits is stored in the cache. For example,
calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34
digits, rounds it down to 32 digits for future use, then rounds it
! again to 30 digits for use in the present request.
@end defmac
@findex halfcircle
***************
*** 33072,33078 ****
@defun divmod a b m
Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if
! there is no solution, or if any of the arguments are not address@hidden
@end defun
@defun powmod a b m
 33399,33405 
@defun divmod a b m
Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if
! there is no solution, or if any of the arguments are not integers.
@end defun
@defun powmod a b m
***************
*** 33147,33153 ****
@var{iters} parameter is the number of Fermat iterations to use, in the
case that this is necessary. If @code{primetest} returns ``maybe,''
you can call it again with the same @var{n} to get a greater certainty;
! @code{primetest} remembers where it left address@hidden
@end defun
@defun tosimplefraction f
 33474,33480 
@var{iters} parameter is the number of Fermat iterations to use, in the
case that this is necessary. If @code{primetest} returns ``maybe,''
you can call it again with the same @var{n} to get a greater certainty;
! @code{primetest} remembers where it left off.
@end defun
@defun tosimplefraction f
***************
*** 33198,33204 ****
produce lists of more than two dimensions. Note that the object
@samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,
and is treated by this and other Calc routines as a plain vector of two
! address@hidden
@end defun
@defun dimensionerror
 33525,33531 
produce lists of more than two dimensions. Note that the object
@samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,
and is treated by this and other Calc routines as a plain vector of two
! elements.
@end defun
@defun dimensionerror
***************
*** 33246,33252 ****
For example, @samp{(mapvec2 'mathadd v 1)} returns the vector @var{v}
with each element increased by one. Note that using @samp{'+} would not
work here, since @code{defmath} does not expand function names everywhere,
! just where they are in the function position of a Lisp address@hidden
@end defun
@defun reducevec f v
 33573,33579 
For example, @samp{(mapvec2 'mathadd v 1)} returns the vector @var{v}
with each element increased by one. Note that using @samp{'+} would not
work here, since @code{defmath} does not expand function names everywhere,
! just where they are in the function position of a Lisp expression.
@end defun
@defun reducevec f v
***************
*** 33296,33302 ****
element of the result matrix will be @code{eq} to the corresponding
element of @var{m}, but none of the @code{cons} cells that make up
the structure of the matrix will be @code{eq}. If @var{m} is a plain
! vector, this is the same as @address@hidden
@end defun
@defun swaprows m r1 r2
 33623,33629 
element of the result matrix will be @code{eq} to the corresponding
element of @var{m}, but none of the @code{cons} cells that make up
the structure of the matrix will be @code{eq}. If @var{m} is a plain
! vector, this is the same as @code{copysequence}.
@end defun
@defun swaprows m r1 r2
***************
*** 33305,33311 ****
function changes @var{m} itself rather than building up a new result
matrix. The return value is @var{m}, i.e., @samp{(eq (swaprows m 1 2) m)}
is true, with the side effect of exchanging the first two rows of
! @address@hidden
@end defun
@node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp
Functions, Internals
 33632,33638 
function changes @var{m} itself rather than building up a new result
matrix. The return value is @var{m}, i.e., @samp{(eq (swaprows m 1 2) m)}
is true, with the side effect of exchanging the first two rows of
! @var{m}.
@end defun
@node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp
Functions, Internals
***************
*** 33443,33449 ****
implemented by temporarily binding the variable @code{mathlivingdangerously}
to @code{t} (using a @code{let} form) and calling @code{simplify}.
Dangerous simplification rules are written to check this variable
! before taking any address@hidden
@end defun
@defun simplifyunits expr
 33770,33776 
implemented by temporarily binding the variable @code{mathlivingdangerously}
to @code{t} (using a @code{let} form) and calling @code{simplify}.
Dangerous simplification rules are written to check this variable
! before taking any action.
@end defun
@defun simplifyunits expr
***************
*** 33465,33471 ****
if it returns a result @code{equal} to the original @code{expr}, it is
ignored and Calc goes on to try the next simplification rule that applies.
If the function body returns something different, that new formula is
! substituted for @var{expr} in the original address@hidden
At each point in the formula, rules are tried in the order of the
original calls to @code{mathdefsimplify}; the search stops after the
 33792,33798 
if it returns a result @code{equal} to the original @code{expr}, it is
ignored and Calc goes on to try the next simplification rule that applies.
If the function body returns something different, that new formula is
! substituted for @var{expr} in the original formula.
At each point in the formula, rules are tried in the order of the
original calls to @code{mathdefsimplify}; the search stops after the
***************
*** 33498,33504 ****
This is really a pair of rules written with one @code{mathdefsimplify}
for convenience; the first replaces @samp{arcsinh(x)} with
@samp{arcsinh(x)}, and the second, which is safe only for real @samp{x},
! replaces @samp{arcsinh(sinh(x))} with @address@hidden
@end defmac
@defun commonconstantfactor expr
 33825,33831 
This is really a pair of rules written with one @code{mathdefsimplify}
for convenience; the first replaces @samp{arcsinh(x)} with
@samp{arcsinh(x)}, and the second, which is safe only for real @samp{x},
! replaces @samp{arcsinh(sinh(x))} with @samp{x}.
@end defmac
@defun commonconstantfactor expr
***************
*** 33533,33539 ****
rational numbers. This is the fraction composed of the GCD of the
numerators of @var{a} and @var{b}, over the GCD of the denominators.
It is used by @code{commonconstantfactor}. Note that the standard
! @code{gcd} function uses the LCM to combine the address@hidden
@end defun
@defun maptree func expr many
 33860,33866 
rational numbers. This is the fraction composed of the GCD of the
numerators of @var{a} and @var{b}, over the GCD of the denominators.
It is used by @code{commonconstantfactor}. Note that the standard
! @code{gcd} function uses the LCM to combine the denominators.
@end defun
@defun maptree func expr many
***************
*** 33548,33554 ****
@var{func} functions may @emph{not} make destructive changes to
@var{expr}. If a third argument @var{many} is provided, it is an
integer which says how many times @var{func} may be applied; the
! default, as described above, is infinitely many address@hidden
@end defun
@defun compilerewrites rules
 33875,33881 
@var{func} functions may @emph{not} make destructive changes to
@var{expr}. If a third argument @var{many} is provided, it is an
integer which says how many times @var{func} may be applied; the
! default, as described above, is infinitely many times.
@end defun
@defun compilerewrites rules
***************
*** 33665,33678 ****
cosines of more complicated arguments. An integration rule should return
@code{nil} if it can't do the integral; if several rules are defined for
the same function, they are tried in order until one returns a address@hidden
! address@hidden
@end defmac
@defmac mathdefintegral2 funcs body
Define a rule for integrating a function or functions of two arguments.
This is exactly analogous to @code{mathdefintegral}, except that @var{body}
is written as the body of a function with two arguments, @var{u} and
! @address@hidden
@end defmac
@defun solvefor lhs rhs var full
 33992,34005 
cosines of more complicated arguments. An integration rule should return
@code{nil} if it can't do the integral; if several rules are defined for
the same function, they are tried in order until one returns a address@hidden
! result.
@end defmac
@defmac mathdefintegral2 funcs body
Define a rule for integrating a function or functions of two arguments.
This is exactly analogous to @code{mathdefintegral}, except that @var{body}
is written as the body of a function with two arguments, @var{u} and
! @var{v}.
@end defmac
@defun solvefor lhs rhs var full
***************
*** 33685,33691 ****
which return a rearranged equation or a functional inverse, respectively.
If @var{full} is address@hidden, a full solution including dummy signs
and dummy integers will be produced. Userdefined inverses are provided
! as properties in a manner similar to derivatives:@refill
@smallexample
(put 'calcFuncln 'mathinverse
 34012,34018 
which return a rearranged equation or a functional inverse, respectively.
If @var{full} is address@hidden, a full solution including dummy signs
and dummy integers will be produced. Userdefined inverses are provided
! as properties in a manner similar to derivatives:
@smallexample
(put 'calcFuncln 'mathinverse
***************
*** 33721,33732 ****
@code{exprcontains} uses @code{equal} to test for matches, whereas
@code{calcfindsubformula} uses @code{eq}. In the formula
@samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not
! @code{eq} to each address@hidden
@end defun
@defun exprcontainscount expr var
Returns the number of occurrences of @var{var} as a subexpression
! of @var{expr}, or @code{nil} if there are no address@hidden
@end defun
@defun exprdepends expr var
 34048,34059 
@code{exprcontains} uses @code{equal} to test for matches, whereas
@code{calcfindsubformula} uses @code{eq}. In the formula
@samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not
! @code{eq} to each other.
@end defun
@defun exprcontainscount expr var
Returns the number of occurrences of @var{var} as a subexpression
! of @var{expr}, or @code{nil} if there are no occurrences.
@end defun
@defun exprdepends expr var
***************
*** 33744,33750 ****
Returns a copy of @var{expr}, with all occurrences of @var{old} replaced
by @var{new}. This treats @code{lambda} forms specially with respect
to the dummy argument variables, so that the effect is always to return
! @var{expr} evaluated at @var{old} = @address@hidden
@end defun
@defun multisubst expr old new
 34071,34077 
Returns a copy of @var{expr}, with all occurrences of @var{old} replaced
by @var{new}. This treats @code{lambda} forms specially with respect
to the dummy argument variables, so that the effect is always to return
! @var{expr} evaluated at @var{old} = @var{new}.
@end defun
@defun multisubst expr old new
***************
*** 33763,33769 ****
@defun exprheight expr
Returns the ``height'' of @var{expr}, which is the deepest level to
which function calls are nested. (Note that @address@hidden + @var{b}}
! counts as a function call.) For primitive objects, this returns
address@hidden
@end defun
@defun polynomialp expr var
 34090,34096 
@defun exprheight expr
Returns the ``height'' of @var{expr}, which is the deepest level to
which function calls are nested. (Note that @address@hidden + @var{b}}
! counts as a function call.) For primitive objects, this returns zero.
@end defun
@defun polynomialp expr var
***************
*** 33775,33781 ****
(@code{calcexpand}), would consist of a sum of terms in which @var{var}
appears only raised to nonnegative integer powers. Note that if
@var{var} does not occur in @var{expr}, then @var{expr} is considered
! a polynomial of degree address@hidden
@end defun
@defun ispolynomial expr var degree loose
 34102,34108 
(@code{calcexpand}), would consist of a sum of terms in which @var{var}
appears only raised to nonnegative integer powers. Note that if
@var{var} does not occur in @var{expr}, then @var{expr} is considered
! a polynomial of degree 0.
@end defun
@defun ispolynomial expr var degree loose
***************
*** 33797,33803 ****
themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose
polynomial with coefficients @samp{((calcFunccos x) 0 (calcFuncsin
x))}. The result will never be @code{nil} in loose mode, since any
! expression can be interpreted as a ``constant'' loose address@hidden
@end defun
@defun polynomialbase expr pred
 34124,34130 
themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose
polynomial with coefficients @samp{((calcFunccos x) 0 (calcFuncsin
x))}. The result will never be @code{nil} in loose mode, since any
! expression can be interpreted as a ``constant'' loose polynomial.
@end defun
@defun polynomialbase expr pred
***************
*** 33810,33816 ****
The default predicate uses @samp{(polynomialp mpbtopexpr @var{subexpr})};
you can use @var{pred} to specify additional conditions. Or, you could
have @var{pred} build up a list of every suitable @var{subexpr} that
! is address@hidden
@end defun
@defun polysimplify poly
 34137,34143 
The default predicate uses @samp{(polynomialp mpbtopexpr @var{subexpr})};
you can use @var{pred} to specify additional conditions. Or, you could
have @var{pred} build up a list of every suitable @var{subexpr} that
! is found.
@end defun
@defun polysimplify poly
***************
*** 33822,33828 ****
Mix two polynomial lists @var{a} and @var{b} (in the form returned by
@code{ispolynomial}) in a linear combination with coefficient expressions
@var{ac} and @var{bc}. The result is a (not necessarily simplified)
! polynomial list representing @address@hidden @var{a} + @var{bc}
@address@hidden
@end defun
@defun polymul a b
 34149,34155 
Mix two polynomial lists @var{a} and @var{b} (in the form returned by
@code{ispolynomial}) in a linear combination with coefficient expressions
@var{ac} and @var{bc}. The result is a (not necessarily simplified)
! polynomial list representing @address@hidden @var{a} + @var{bc} @var{b}}.
@end defun
@defun polymul a b
***************
*** 33835,33841 ****
list @var{poly} applied to variable @var{var}. The @kbd{a c}
(@code{calccollect}) command uses @code{ispolynomial} to turn an
expression into a coefficient list, then @code{buildpolynomialexpr}
! to turn the list back into an expression in regular address@hidden
@end defun
@defun checkunitname var
 34162,34168 
list @var{poly} applied to variable @var{var}. The @kbd{a c}
(@code{calccollect}) command uses @code{ispolynomial} to turn an
expression into a coefficient list, then @code{buildpolynomialexpr}
! to turn the list back into an expression in regular form.
@end defun
@defun checkunitname var
***************
*** 33852,33858 ****
Return true if @var{expr} contains any variables which can be
interpreted as units. If @var{subexprs} is @code{t}, the entire
expression is searched. If @var{subexprs} is @code{nil}, this
! checks whether @var{expr} is directly a units address@hidden
@end defun
@defun singleunitsinexprp expr
 34179,34185 
Return true if @var{expr} contains any variables which can be
interpreted as units. If @var{subexprs} is @code{t}, the entire
expression is searched. If @var{subexprs} is @code{nil}, this
! checks whether @var{expr} is directly a units expression.
@end defun
@defun singleunitsinexprp expr
***************
*** 33867,33873 ****
is @code{nil}, use Calc's native base units. Otherwise, @var{which}
can specify a units system, which is a list of twoelement lists,
where the first element is a Calc base symbol name and the second
! is an expression to substitute for address@hidden
@end defun
@defun removeunits expr
 34194,34200 
is @code{nil}, use Calc's native base units. Otherwise, @var{which}
can specify a units system, which is a list of twoelement lists,
where the first element is a Calc base symbol name and the second
! is an expression to substitute for it.
@end defun
@defun removeunits expr
***************
*** 33903,33909 ****
not have the form of a valid expression, return a list of the form
@samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index
into @var{str} of the general location of the error, and @var{msg} is
! a string describing the address@hidden
@end defun
@defun readexprs str
 34230,34236 
not have the form of a valid expression, return a list of the form
@samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index
into @var{str} of the general location of the error, and @var{msg} is
! a string describing the problem.
@end defun
@defun readexprs str
***************
*** 33922,33935 ****
If @var{prompt} is given, it is the prompt string to use; the default
is ``Algebraic:''. If @var{nonorm} is @code{t}, the formulas will
be returned exactly as parsed; otherwise, they will be passed through
! @code{calcnormalize} address@hidden
To support the use of @kbd{$} characters in the algebraic entry, use
@code{let} to bind @code{calcdollarvalues} to a list of the values
to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind
@code{calcdollarused} to 0. Upon return, @code{calcdollarused}
will have been changed to the highest number of consecutive @kbd{$}s
! that actually appeared in the address@hidden
@end defun
@defun formatnumber a
 34249,34262 
If @var{prompt} is given, it is the prompt string to use; the default
is ``Algebraic:''. If @var{nonorm} is @code{t}, the formulas will
be returned exactly as parsed; otherwise, they will be passed through
! @code{calcnormalize} first.
To support the use of @kbd{$} characters in the algebraic entry, use
@code{let} to bind @code{calcdollarvalues} to a list of the values
to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind
@code{calcdollarused} to 0. Upon return, @code{calcdollarused}
will have been changed to the highest number of consecutive @kbd{$}s
! that actually appeared in the input.
@end defun
@defun formatnumber a
***************
*** 33945,33951 ****
complex number format, and point character, are ignored to ensure the
result will be rereadable. The @var{prec} parameter is normally 0; if
you pass a large integer like 1000 instead, the expression will be
! surrounded by parentheses unless it is a plain number or variable
address@hidden
@end defun
@defun formatniceexpr a width
 34272,34278 
complex number format, and point character, are ignored to ensure the
result will be rereadable. The @var{prec} parameter is normally 0; if
you pass a large integer like 1000 instead, the expression will be
! surrounded by parentheses unless it is a plain number or variable name.
@end defun
@defun formatniceexpr a width
***************
*** 33964,33970 ****
contain newline characters to separate the lines. The @var{w}
parameter, if given, is the target window size for which to format
the expressions. If @var{w} is omitted, the width of the Calculator
! window is address@hidden
@end defun
@defun composeexpr a prec
 34291,34297 
contain newline characters to separate the lines. The @var{w}
parameter, if given, is the target window size for which to format
the expressions. If @var{w} is omitted, the width of the Calculator
! window is used.
@end defun
@defun composeexpr a prec
***************
*** 34012,34018 ****
@defun compfirstchar c
If composition @var{c} is a ``flat'' composition, return the first
(leftmost) character of the composition as an integer. Otherwise,
! return @address@hidden
@end defun
@defun complastchar c
 34339,34345 
@defun compfirstchar c
If composition @var{c} is a ``flat'' composition, return the first
(leftmost) character of the composition as an integer. Otherwise,
! return @code{nil}.
@end defun
@defun complastchar c
***************
*** 34192,34198 ****
to the appropriate file name. You may also need to change the variables
@code{calcgnuplotplotcommand} and @code{calcgnuplotprintcommand} in
order to get correct displays and hardcopies, respectively, of your
! address@hidden
@ifinfo
@example
 34519,34525 
to the appropriate file name. You may also need to change the variables
@code{calcgnuplotplotcommand} and @code{calcgnuplotprintcommand} in
order to get correct displays and hardcopies, respectively, of your
! plots.
@ifinfo
@example
***************
*** 34207,34213 ****
@TeX{} typesetting program (this is a free program by Donald Knuth
at Stanford University) as well as the @file{texindex} program and
@file{texinfo.tex} file, both of which can be obtained from the FSF
! as part of the @code{texinfo} address@hidden
To print the Calc manual in one huge 470 page tome, you will need the
source code to this manual, @file{calc.texi}, available as part of the
 34534,34540 
@TeX{} typesetting program (this is a free program by Donald Knuth
at Stanford University) as well as the @file{texindex} program and
@file{texinfo.tex} file, both of which can be obtained from the FSF
! as part of the @code{texinfo} package.
To print the Calc manual in one huge 470 page tome, you will need the
source code to this manual, @file{calc.texi}, available as part of the
***************
*** 34253,34259 ****
@code{".emacs"} as a substring, and if the variable
@code{calcloadedsettingsfile} is @code{nil}, then Calc will
automatically load your settings file (if it exists) the first time
! Calc is address@hidden
@ifinfo
@example
 34580,34586 
@code{".emacs"} as a substring, and if the variable
@code{calcloadedsettingsfile} is @code{nil}, then Calc will
automatically load your settings file (if it exists) the first time
! Calc is invoked.
@ifinfo
@example
***************
*** 35194,35214 ****
@enumerate
@c 1
@item
! Positive prefix arguments apply to @cite{n} stack entries.
! Negative prefix arguments apply to the @cite{n}th stack entry.
A prefix of zero applies to the entire stack. (For @key{LFD} and
@address@hidden, the meaning of the sign is reversed.)
@c 2
@item
! Positive prefix arguments apply to @cite{n} stack entries.
Negative prefix arguments apply to the top stack entry
! and the next @cite{n} stack entries.
@c 3
@item
! Positive prefix arguments rotate top @cite{n} stack entries by one.
! Negative prefix arguments rotate the entire stack by @cite{n}.
A prefix of zero reverses the entire stack.
@c 4
 35521,35541 
@enumerate
@c 1
@item
! Positive prefix arguments apply to @expr{n} stack entries.
! Negative prefix arguments apply to the @expr{n}th stack entry.
A prefix of zero applies to the entire stack. (For @key{LFD} and
@address@hidden, the meaning of the sign is reversed.)
@c 2
@item
! Positive prefix arguments apply to @expr{n} stack entries.
Negative prefix arguments apply to the top stack entry
! and the next @expr{n} stack entries.
@c 3
@item
! Positive prefix arguments rotate top @expr{n} stack entries by one.
! Negative prefix arguments rotate the entire stack by @expr{n}.
A prefix of zero reverses the entire stack.
@c 4
***************
*** 35217,35224 ****
@c 5
@item
! Positive prefix arguments specify a precision @cite{p}.
! Negative prefix arguments reduce the current precision by @cite{p}.
@c 6
@item
 35544,35551 
@c 5
@item
! Positive prefix arguments specify a precision @expr{p}.
! Negative prefix arguments reduce the current precision by @expr{p}.
@c 6
@item
***************
*** 35236,35252 ****
@c 9
@item
! Positive prefix arguments specify a word size of @cite{w} bits, unsigned.
! Negative prefix arguments specify a word size of @cite{w} bits, signed.
@c 10
@item
! Prefix arguments specify the shift amount @cite{n}. The @cite{w} argument
cannot be specified in the keyboard version of this command.
@c 11
@item
! From the keyboard, @cite{d} is omitted and defaults to zero.
@c 12
@item
 35563,35579 
@c 9
@item
! Positive prefix arguments specify a word size of @expr{w} bits, unsigned.
! Negative prefix arguments specify a word size of @expr{w} bits, signed.
@c 10
@item
! Prefix arguments specify the shift amount @expr{n}. The @expr{w} argument
cannot be specified in the keyboard version of this command.
@c 11
@item
! From the keyboard, @expr{d} is omitted and defaults to zero.
@c 12
@item
***************
*** 35259,35274 ****
@c 14
@item
! A prefix argument, if any, is used for @cite{m} instead of taking
! @cite{m} from the stack. @cite{M} may take any of these values:
@iftex
address@hidden@tableindent10pt
@end iftex
@table @asis
@item Integer
! Random integer in the interval @cite{[0 .. m)}.
@item Float
! Random floatingpoint number in the interval @cite{[0 .. m)}.
@item 0.0
Gaussian with mean 1 and standard deviation 0.
@item Error form
 35586,35601 
@c 14
@item
! A prefix argument, if any, is used for @expr{m} instead of taking
! @expr{m} from the stack. @expr{M} may take any of these values:
@iftex
address@hidden@tableindent10pt
@end iftex
@table @asis
@item Integer
! Random integer in the interval @expr{[0 .. m)}.
@item Float
! Random floatingpoint number in the interval @expr{[0 .. m)}.
@item 0.0
Gaussian with mean 1 and standard deviation 0.
@item Error form
***************
*** 35308,35327 ****
@c 20
@item
! With a prefix argument of 1, take a single @address@hidden
! @address@hidden matrix from the
! stack instead of two separate data vectors.
@c 21
@item
! The row or column number @cite{n} may be given as a numeric prefix
! argument instead. A plain @kbd{Cu} prefix says to take @cite{n}
! from the top of the stack. If @cite{n} is a vector or interval,
a subvector/submatrix of the input is created.
@c 22
@item
! The @cite{op} prompt can be answered with the key sequence for the
desired function, or with @kbd{x} or @kbd{z} followed by a function name,
or with @kbd{$} to take a formula from the top of the stack, or with
@kbd{'} and a typed formula. In the last two cases, the formula may
 35635,35655 
@c 20
@item
! With a prefix argument of 1, take a single
! @texline @address@hidden
! @infoline @address@hidden
! matrix from the stack instead of two separate data vectors.
@c 21
@item
! The row or column number @expr{n} may be given as a numeric prefix
! argument instead. A plain @kbd{Cu} prefix says to take @expr{n}
! from the top of the stack. If @expr{n} is a vector or interval,
a subvector/submatrix of the input is created.
@c 22
@item
! The @expr{op} prompt can be answered with the key sequence for the
desired function, or with @kbd{x} or @kbd{z} followed by a function name,
or with @kbd{$} to take a formula from the top of the stack, or with
@kbd{'} and a typed formula. In the last two cases, the formula may
***************
*** 35336,35342 ****
One of the mapping direction keys @kbd{_} (horizontal, i.e., map
by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or
reduce down), or @kbd{=} (map or reduce by rows) may be used before
! entering @cite{op}; these modify the function name by adding the letter
@code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,''
or @code{d} for ``down.''
 35664,35670 
One of the mapping direction keys @kbd{_} (horizontal, i.e., map
by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or
reduce down), or @kbd{=} (map or reduce by rows) may be used before
! entering @expr{op}; these modify the function name by adding the letter
@code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,''
or @code{d} for ``down.''
***************
*** 35374,35380 ****
@item 11
(@var{2}) Float with integer mantissa.
@item 12
! (@var{2}) Float with mantissa in @cite{[1 .. 10)}.
@item 13
(@var{1}) Date form (using date numbers).
@item 14
 35702,35708 
@item 11
(@var{2}) Float with integer mantissa.
@item 12
! (@var{2}) Float with mantissa in @expr{[1 .. 10)}.
@item 13
(@var{1}) Date form (using date numbers).
@item 14
***************
*** 35388,35400 ****
@c 25
@item
! A prefix argument specifies the size @cite{n} of the matrix. With no
! prefix argument, @cite{n} is omitted and the size is inferred from
the input vector.
@c 26
@item
! The prefix argument specifies the starting position @cite{n} (default 1).
@c 27
@item
 35716,35728 
@c 25
@item
! A prefix argument specifies the size @expr{n} of the matrix. With no
! prefix argument, @expr{n} is omitted and the size is inferred from
the input vector.
@c 26
@item
! The prefix argument specifies the starting position @expr{n} (default 1).
@c 27
@item
***************
*** 35460,35475 ****
@c 39
@item
! Answer for @cite{v} may also be of the form @cite{v = v_0} or
! @cite{v  v_0}.
@c 40
@item
! With a positive prefix argument, stack contains many @cite{y}'s and one
! common @cite{x}. With a zero prefix, stack contains a vector of
! @cite{y}s and a common @cite{x}. With a negative prefix, stack
! contains many @cite{[x,y]} vectors. (For 3D plots, substitute
! @cite{z} for @cite{y} and @cite{x,y} for @cite{x}.)
@c 41
@item
 35788,35803 
@c 39
@item
! Answer for @expr{v} may also be of the form @expr{v = v_0} or
! @expr{v  v_0}.
@c 40
@item
! With a positive prefix argument, stack contains many @expr{y}'s and one
! common @expr{x}. With a zero prefix, stack contains a vector of
! @expr{y}s and a common @expr{x}. With a negative prefix, stack
! contains many @expr{[x,y]} vectors. (For 3D plots, substitute
! @expr{z} for @expr{y} and @expr{x,y} for @expr{x}.)
@c 41
@item
***************
*** 35504,35522 ****
stack levels. The notation @kbd{$3} refers to stack level three without
causing that value to be removed from the stack. Use @key{LFD} in place
of @key{RET} to prevent evaluation; use @kbd{M=} in place of @key{RET}
! to evaluate address@hidden
@c 47
@item
The variable is replaced by the formula shown on the right. The
Inverse flag reverses the order of the operands, e.g., @kbd{I s  x}
! assigns @c{$x \coloneq ax$}
! @cite{x := ax}.
@c 48
@item
Press @kbd{?} repeatedly to see how to choose a model. Answer the
! variables prompt with @cite{iv} or @cite{iv;pv} to specify
independent and parameter variables. A positive prefix argument
takes @address@hidden vectors from the stack; a zero prefix takes a matrix
and a vector from the stack.
 35832,35851 
stack levels. The notation @kbd{$3} refers to stack level three without
causing that value to be removed from the stack. Use @key{LFD} in place
of @key{RET} to prevent evaluation; use @kbd{M=} in place of @key{RET}
! to evaluate variables.
@c 47
@item
The variable is replaced by the formula shown on the right. The
Inverse flag reverses the order of the operands, e.g., @kbd{I s  x}
! assigns
! @texline @tmath{x \coloneq ax}.
! @infoline @expr{x := ax}.
@c 48
@item
Press @kbd{?} repeatedly to see how to choose a model. Answer the
! variables prompt with @expr{iv} or @expr{iv;pv} to specify
independent and parameter variables. A positive prefix argument
takes @address@hidden vectors from the stack; a zero prefix takes a matrix
and a vector from the stack.
[Prev in Thread] 
Current Thread 
[Next in Thread] 
 [Emacsdiffs] Changes to emacs/man/calc.texi [emacsunicode2],
Miles Bader <=