aboutsummaryrefslogtreecommitdiffstats
path: root/man
diff options
context:
space:
mode:
authorJay Belanger2004-12-06 05:01:20 +0000
committerJay Belanger2004-12-06 05:01:20 +0000
commita4231b040c816e810514d1fa045daaff3d1229f8 (patch)
tree80d375272e71d627fa95e1db7ac46432343b1cb6 /man
parentcc60c723223998a93a059d669ccfdc7e9aa3e050 (diff)
downloademacs-a4231b040c816e810514d1fa045daaff3d1229f8.tar.gz
emacs-a4231b040c816e810514d1fa045daaff3d1229f8.zip
Remove @refill commands.
Use more Texinfo macros instead of TeX defs.
Diffstat (limited to 'man')
-rw-r--r--man/calc.texi4441
1 files changed, 2388 insertions, 2053 deletions
diff --git a/man/calc.texi b/man/calc.texi
index e1fdea44dd0..e38168aee47 100644
--- a/man/calc.texi
+++ b/man/calc.texi
@@ -7,33 +7,60 @@
7@setchapternewpage odd 7@setchapternewpage odd
8@comment %**end of header (This is for running Texinfo on a region.) 8@comment %**end of header (This is for running Texinfo on a region.)
9 9
10@c The following macros are used for conditional output for single lines.
11@c @texline foo
12@c `foo' will appear only in TeX output
13@c @infoline foo
14@c `foo' will appear only in non-TeX output
15
16@c In TeX output, @tmath{expr} will typeset expr in math mode.
17@c In any output, @expr{expr} will typeset an expression;
18@c $x$ in TeX, @samp{x} otherwise.
19
20@iftex
21@macro texline{stuff}
22\stuff\
23@end macro
24@macro tmath{stuff}
25@tex
26$\stuff\$
27@end tex
28@end macro
29@alias infoline=comment
30@c @alias expr=math
31@tex
32\gdef\expr#1{\tex
33 \let\t\ttfont
34 \turnoffactive
35 $#1$
36 \endgroup}
37@end tex
38@macro cpi{}
39@math{@pi{}}
40@end macro
41@macro cpiover{den}
42@math{@pi/\den\}
43@end macro
44@end iftex
45
46@ifnottex
47@alias texline=comment
48@macro infoline{stuff}
49\stuff\
50@end macro
51@alias expr=samp
52@macro cpi{}
53@expr{pi}
54@end macro
55@macro cpiover{den}
56@expr{pi/\den\}
57@end macro
58@end ifnottex
59
60
10@tex 61@tex
11% Some special kludges to make TeX formatting prettier.
12% Because makeinfo.c exists, we can't just define new commands.
13% So instead, we take over little-used existing commands.
14%
15% Suggested by Karl Berry <karl@@freefriends.org> 62% Suggested by Karl Berry <karl@@freefriends.org>
16\gdef\!{\mskip-\thinmuskip} 63\gdef\!{\mskip-\thinmuskip}
17% Redefine @cite{text} to act like $text$ in regular TeX.
18% Info will typeset this same as @samp{text}.
19\gdef\goodtex{\tex \let\rm\goodrm \let\t\ttfont \turnoffactive}
20\gdef\goodrm{\fam0\tenrm}
21\gdef\cite{\goodtex$\citexxx}
22\gdef\citexxx#1{#1$\Etex}
23\global\let\oldxrefX=\xrefX
24\gdef\xrefX[#1]{\begingroup\let\cite=\dfn\oldxrefX[#1]\endgroup}
25
26% Redefine @c{tex-stuff} \n @whatever{info-stuff}.
27\gdef\c{\futurelet\next\mycxxx}
28\gdef\mycxxx{%
29 \ifx\next\bgroup \goodtex\let\next\mycxxy
30 \else\ifx\next\mindex \let\next\relax
31 \else\ifx\next\kindex \let\next\relax
32 \else\ifx\next\starindex \let\next\relax \else \let\next\comment
33 \fi\fi\fi\fi \next
34}
35\gdef\mycxxy#1#2{#1\Etex\mycxxz}
36\gdef\mycxxz#1{}
37@end tex 64@end tex
38 65
39@c Fix some other things specifically for this manual. 66@c Fix some other things specifically for this manual.
@@ -513,8 +540,9 @@ need to know.
513@cindex Marginal notes 540@cindex Marginal notes
514Every Calc keyboard command is listed in the Calc Summary, and also 541Every Calc keyboard command is listed in the Calc Summary, and also
515in the Key Index. Algebraic functions, @kbd{M-x} commands, and 542in the Key Index. Algebraic functions, @kbd{M-x} commands, and
516variables also have their own indices. @c{Each} 543variables also have their own indices.
517@asis{In the printed manual, each} 544@texline Each
545@infoline In the printed manual, each
518paragraph that is referenced in the Key or Function Index is marked 546paragraph that is referenced in the Key or Function Index is marked
519in the margin with its index entry. 547in the margin with its index entry.
520 548
@@ -570,7 +598,7 @@ the corresponding function in an algebraic-style formula would
570be @samp{cos(@var{x})}. 598be @samp{cos(@var{x})}.
571 599
572A few commands don't have key equivalents: @code{calc-sincos} 600A few commands don't have key equivalents: @code{calc-sincos}
573[@code{sincos}].@refill 601[@code{sincos}].
574 602
575@node Demonstration of Calc, Using Calc, Notations Used in This Manual, Getting Started 603@node Demonstration of Calc, Using Calc, Notations Used in This Manual, Getting Started
576@section A Demonstration of Calc 604@section A Demonstration of Calc
@@ -595,12 +623,14 @@ Delete, and Space keys.
595then the command to operate on the numbers. 623then the command to operate on the numbers.
596 624
597@noindent 625@noindent
598Type @kbd{2 @key{RET} 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$} 626Type @kbd{2 @key{RET} 3 + Q} to compute
599@asis{the square root of 2+3, which is 2.2360679775}. 627@texline @tmath{\sqrt{2+3} = 2.2360679775}.
628@infoline the square root of 2+3, which is 2.2360679775.
600 629
601@noindent 630@noindent
602Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$} 631Type @kbd{P 2 ^} to compute
603@asis{the value of `pi' squared, 9.86960440109}. 632@texline @tmath{\pi^2 = 9.86960440109}.
633@infoline the value of `pi' squared, 9.86960440109.
604 634
605@noindent 635@noindent
606Type @key{TAB} to exchange the order of these two results. 636Type @key{TAB} to exchange the order of these two results.
@@ -617,13 +647,15 @@ conventional ``algebraic'' notation. To enter an algebraic formula,
617use the apostrophe key. 647use the apostrophe key.
618 648
619@noindent 649@noindent
620Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$} 650Type @kbd{' sqrt(2+3) @key{RET}} to compute
621@asis{the square root of 2+3}. 651@texline @tmath{\sqrt{2+3}}.
652@infoline the square root of 2+3.
622 653
623@noindent 654@noindent
624Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$} 655Type @kbd{' pi^2 @key{RET}} to enter
625@asis{`pi' squared}. To evaluate this symbolic 656@texline @tmath{\pi^2}.
626formula as a number, type @kbd{=}. 657@infoline `pi' squared.
658To evaluate this symbolic formula as a number, type @kbd{=}.
627 659
628@noindent 660@noindent
629Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent 661Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent
@@ -680,12 +712,16 @@ the upper-leftmost @samp{1} and set the mark, then move to just after
680the lower-right @samp{8} and press @kbd{M-# r}. 712the lower-right @samp{8} and press @kbd{M-# r}.
681 713
682@noindent 714@noindent
683Type @kbd{v t} to transpose this @c{$3\times2$} 715Type @kbd{v t} to transpose this
684@asis{3x2} matrix into a @c{$2\times3$} 716@texline @tmath{3\times2}
685@asis{2x3} matrix. Type 717@infoline 3x2
686@w{@kbd{v u}} to unpack the rows into two separate vectors. Now type 718matrix into a
687@w{@kbd{V R + @key{TAB} V R +}} to compute the sums of the two original columns. 719@texline @tmath{2\times3}
688(There is also a special grab-and-sum-columns command, @kbd{M-# :}.) 720@infoline 2x3
721matrix. Type @w{@kbd{v u}} to unpack the rows into two separate
722vectors. Now type @w{@kbd{V R + @key{TAB} V R +}} to compute the sums
723of the two original columns. (There is also a special
724grab-and-sum-columns command, @kbd{M-# :}.)
689 725
690@strong{Units conversion.} Units are entered algebraically. 726@strong{Units conversion.} Units are entered algebraically.
691Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour. 727Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour.
@@ -701,7 +737,7 @@ or equations involving variables. Type @kbd{@w{' [x + y} = a, x y = 1] @key{RET
701to enter a pair of equations involving three variables. 737to enter a pair of equations involving three variables.
702(Note the leading apostrophe in this example; also, note that the space 738(Note the leading apostrophe in this example; also, note that the space
703between @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve 739between @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve
704these equations for the variables @cite{x} and @cite{y}.@refill 740these equations for the variables @expr{x} and @expr{y}.
705 741
706@noindent 742@noindent
707Type @kbd{d B} to view the solutions in more readable notation. 743Type @kbd{d B} to view the solutions in more readable notation.
@@ -710,7 +746,7 @@ to view them in the notation for the @TeX{} typesetting system.
710Type @kbd{d N} to return to normal notation. 746Type @kbd{d N} to return to normal notation.
711 747
712@noindent 748@noindent
713Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @cite{a = 7.5} in these formulas. 749Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @expr{a = 7.5} in these formulas.
714(That's a letter @kbd{l}, not a numeral @kbd{1}.) 750(That's a letter @kbd{l}, not a numeral @kbd{1}.)
715 751
716@iftex 752@iftex
@@ -769,7 +805,7 @@ Once again, if you don't have a Meta key on your keyboard you can type
769@key{ESC} first, then @kbd{#}, to accomplish the same thing. If you 805@key{ESC} first, then @kbd{#}, to accomplish the same thing. If you
770don't even have an @key{ESC} key, you can fake it by holding down 806don't even have an @key{ESC} key, you can fake it by holding down
771Control or @key{CTRL} while typing a left square bracket 807Control or @key{CTRL} while typing a left square bracket
772(that's @kbd{C-[} in Emacs notation).@refill 808(that's @kbd{C-[} in Emacs notation).
773 809
774@kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for 810@kbd{M-#} is a @dfn{prefix key}; when you press it, Emacs waits for
775you to press a second key to complete the command. In this case, 811you to press a second key to complete the command. In this case,
@@ -853,7 +889,7 @@ Calc commands use the digits, letters, and punctuation keys.
853Shifted (i.e., upper-case) letters are different from lowercase 889Shifted (i.e., upper-case) letters are different from lowercase
854letters. Some letters are @dfn{prefix} keys that begin two-letter 890letters. Some letters are @dfn{prefix} keys that begin two-letter
855commands. For example, @kbd{e} means ``enter exponent'' and shifted 891commands. For example, @kbd{e} means ``enter exponent'' and shifted
856@kbd{E} means @cite{e^x}. With the @kbd{d} (``display modes'') prefix 892@kbd{E} means @expr{e^x}. With the @kbd{d} (``display modes'') prefix
857the letter ``e'' takes on very different meanings: @kbd{d e} means 893the letter ``e'' takes on very different meanings: @kbd{d e} means
858``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.'' 894``engineering notation'' and @kbd{d E} means ``@dfn{eqn} language mode.''
859 895
@@ -1317,13 +1353,15 @@ With any prefix argument, reset everything but the stack.
1317@noindent 1353@noindent
1318Calc was originally started as a two-week project to occupy a lull 1354Calc was originally started as a two-week project to occupy a lull
1319in the author's schedule. Basically, a friend asked if I remembered 1355in the author's schedule. Basically, a friend asked if I remembered
1320the value of @c{$2^{32}$} 1356the value of
1321@cite{2^32}. I didn't offhand, but I said, ``that's 1357@texline @tmath{2^{32}}.
1322easy, just call up an @code{xcalc}.'' @code{Xcalc} duly reported 1358@infoline @expr{2^32}.
1323that the answer to our question was @samp{4.294967e+09}---with no way to 1359I didn't offhand, but I said, ``that's easy, just call up an
1324see the full ten digits even though we knew they were there in the 1360@code{xcalc}.'' @code{Xcalc} duly reported that the answer to our
1325program's memory! I was so annoyed, I vowed to write a calculator 1361question was @samp{4.294967e+09}---with no way to see the full ten
1326of my own, once and for all. 1362digits even though we knew they were there in the program's memory! I
1363was so annoyed, I vowed to write a calculator of my own, once and for
1364all.
1327 1365
1328I chose Emacs Lisp, a) because I had always been curious about it 1366I chose Emacs Lisp, a) because I had always been curious about it
1329and b) because, being only a text editor extension language after 1367and b) because, being only a text editor extension language after
@@ -1373,18 +1411,19 @@ algebra system for microcomputers.
1373Many people have contributed to Calc by reporting bugs and suggesting 1411Many people have contributed to Calc by reporting bugs and suggesting
1374features, large and small. A few deserve special mention: Tim Peters, 1412features, large and small. A few deserve special mention: Tim Peters,
1375who helped develop the ideas that led to the selection commands, rewrite 1413who helped develop the ideas that led to the selection commands, rewrite
1376rules, and many other algebra features; @c{Fran\c cois} 1414rules, and many other algebra features;
1377@asis{Francois} Pinard, who contributed 1415@texline Fran\c cois
1378an early prototype of the Calc Summary appendix as well as providing 1416@infoline Francois
1379valuable suggestions in many other areas of Calc; Carl Witty, whose eagle 1417Pinard, who contributed an early prototype of the Calc Summary appendix
1380eyes discovered many typographical and factual errors in the Calc manual; 1418as well as providing valuable suggestions in many other areas of Calc;
1381Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who 1419Carl Witty, whose eagle eyes discovered many typographical and factual
1382made many suggestions relating to the algebra commands and contributed 1420errors in the Calc manual; Tim Kay, who drove the development of
1383some code for polynomial operations; Randal Schwartz, who suggested the 1421Embedded mode; Ove Ewerlid, who made many suggestions relating to the
1384@code{calc-eval} function; Robert J. Chassell, who suggested the Calc 1422algebra commands and contributed some code for polynomial operations;
1385Tutorial and exercises; and Juha Sarlin, who first worked out how to split 1423Randal Schwartz, who suggested the @code{calc-eval} function; Robert
1386Calc into quickly-loading parts. Bob Weiner helped immensely with the 1424J. Chassell, who suggested the Calc Tutorial and exercises; and Juha
1387Lucid Emacs port. 1425Sarlin, who first worked out how to split Calc into quickly-loading
1426parts. Bob Weiner helped immensely with the Lucid Emacs port.
1388 1427
1389@cindex Bibliography 1428@cindex Bibliography
1390@cindex Knuth, Art of Computer Programming 1429@cindex Knuth, Art of Computer Programming
@@ -1545,8 +1584,8 @@ from the top of the stack.
1545 1584
1546@cindex Operators 1585@cindex Operators
1547@cindex Operands 1586@cindex Operands
1548In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands} 1587In an operation like @expr{2+3}, the 2 and 3 are called the @dfn{operands}
1549and the @cite{+} is the @dfn{operator}. In an RPN calculator you always 1588and the @expr{+} is the @dfn{operator}. In an RPN calculator you always
1550enter the operands first, then the operator. Each time you type a 1589enter the operands first, then the operator. Each time you type a
1551number, Calc adds or @dfn{pushes} it onto the top of the Stack. 1590number, Calc adds or @dfn{pushes} it onto the top of the Stack.
1552When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate 1591When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate
@@ -1560,7 +1599,7 @@ you wish; type @kbd{M-# c} to switch into the Calc window (you can type
1560The first four keystrokes ``push'' the numbers 2 and 3 onto the stack. 1599The first four keystrokes ``push'' the numbers 2 and 3 onto the stack.
1561The @kbd{+} key ``pops'' the top two numbers from the stack, adds them, 1600The @kbd{+} key ``pops'' the top two numbers from the stack, adds them,
1562and pushes the result (5) back onto the stack. Here's how the stack 1601and pushes the result (5) back onto the stack. Here's how the stack
1563will look at various points throughout the calculation:@refill 1602will look at various points throughout the calculation:
1564 1603
1565@smallexample 1604@smallexample
1566@group 1605@group
@@ -1581,11 +1620,11 @@ less distracting in regular use.
1581@cindex Levels of stack 1620@cindex Levels of stack
1582The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level 1621The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level
1583numbers}. Old RPN calculators always had four stack levels called 1622numbers}. Old RPN calculators always had four stack levels called
1584@cite{x}, @cite{y}, @cite{z}, and @cite{t}. Calc's stack can grow 1623@expr{x}, @expr{y}, @expr{z}, and @expr{t}. Calc's stack can grow
1585as large as you like, so it uses numbers instead of letters. Some 1624as large as you like, so it uses numbers instead of letters. Some
1586stack-manipulation commands accept a numeric argument that says 1625stack-manipulation commands accept a numeric argument that says
1587which stack level to work on. Normal commands like @kbd{+} always 1626which stack level to work on. Normal commands like @kbd{+} always
1588work on the top few levels of the stack.@refill 1627work on the top few levels of the stack.
1589 1628
1590@c [fix-ref Truncating the Stack] 1629@c [fix-ref Truncating the Stack]
1591The Stack buffer is just an Emacs buffer, and you can move around in 1630The Stack buffer is just an Emacs buffer, and you can move around in
@@ -1602,7 +1641,7 @@ You don't really need the second @key{RET} in @kbd{2 @key{RET} 3
1602@key{RET} +}. That's because if you type any operator name or 1641@key{RET} +}. That's because if you type any operator name or
1603other non-numeric key when you are entering a number, the Calculator 1642other non-numeric key when you are entering a number, the Calculator
1604automatically enters that number and then does the requested command. 1643automatically enters that number and then does the requested command.
1605Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill 1644Thus @kbd{2 @key{RET} 3 +} will work just as well.
1606 1645
1607Examples in this tutorial will often omit @key{RET} even when the 1646Examples in this tutorial will often omit @key{RET} even when the
1608stack displays shown would only happen if you did press @key{RET}: 1647stack displays shown would only happen if you did press @key{RET}:
@@ -1636,9 +1675,10 @@ Here's the first exercise: What will the keystrokes @kbd{1 @key{RET} 2
1636multiplication.) Figure it out by hand, then try it with Calc to see 1675multiplication.) Figure it out by hand, then try it with Calc to see
1637if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) 1676if you're right. @xref{RPN Answer 1, 1}. (@bullet{})
1638 1677
1639(@bullet{}) @strong{Exercise 2.} Compute @c{$(2\times4) + (7\times9.4) + {5\over4}$} 1678(@bullet{}) @strong{Exercise 2.} Compute
1640@cite{2*4 + 7*9.5 + 5/4} using the 1679@texline @tmath{(2\times4) + (7\times9.4) + {5\over4}}
1641stack. @xref{RPN Answer 2, 2}. (@bullet{}) 1680@infoline @expr{2*4 + 7*9.5 + 5/4}
1681using the stack. @xref{RPN Answer 2, 2}. (@bullet{})
1642 1682
1643The @key{DEL} key is called Backspace on some keyboards. It is 1683The @key{DEL} key is called Backspace on some keyboards. It is
1644whatever key you would use to correct a simple typing error when 1684whatever key you would use to correct a simple typing error when
@@ -1690,7 +1730,7 @@ the above example with @key{SPC} and the effect would be the same.
1690Another stack manipulation key is @key{TAB}. This exchanges the top 1730Another stack manipulation key is @key{TAB}. This exchanges the top
1691two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +} 1731two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +}
1692to get 5, and then you realize what you really wanted to compute 1732to get 5, and then you realize what you really wanted to compute
1693was @cite{20 / (2+3)}. 1733was @expr{20 / (2+3)}.
1694 1734
1695@smallexample 1735@smallexample
1696@group 1736@group
@@ -1798,11 +1838,10 @@ What happens if you take the square root of a negative number?
1798@end smallexample 1838@end smallexample
1799 1839
1800@noindent 1840@noindent
1801The notation @cite{(a, b)} represents a complex number. 1841The notation @expr{(a, b)} represents a complex number.
1802Complex numbers are more traditionally written @c{$a + b i$} 1842Complex numbers are more traditionally written @expr{a + b i};
1803@cite{a + b i};
1804Calc can display in this format, too, but for now we'll stick to the 1843Calc can display in this format, too, but for now we'll stick to the
1805@cite{(a, b)} notation. 1844@expr{(a, b)} notation.
1806 1845
1807If you don't know how complex numbers work, you can safely ignore this 1846If you don't know how complex numbers work, you can safely ignore this
1808feature. Complex numbers only arise from operations that would be 1847feature. Complex numbers only arise from operations that would be
@@ -1861,7 +1900,7 @@ When you press @kbd{)} all the stack entries between the incomplete
1861entry and the top are collected, so there's never really a reason 1900entry and the top are collected, so there's never really a reason
1862to use the comma. It's up to you. 1901to use the comma. It's up to you.
1863 1902
1864(@bullet{}) @strong{Exercise 4.} To enter the complex number @cite{(2, 3)}, 1903(@bullet{}) @strong{Exercise 4.} To enter the complex number @expr{(2, 3)},
1865your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened? 1904your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened?
1866(Joe thought of a clever way to correct his mistake in only two 1905(Joe thought of a clever way to correct his mistake in only two
1867keystrokes, but it didn't quite work. Try it to find out why.) 1906keystrokes, but it didn't quite work. Try it to find out why.)
@@ -1921,7 +1960,7 @@ entire stack.)
1921If you are not used to RPN notation, you may prefer to operate the 1960If you are not used to RPN notation, you may prefer to operate the
1922Calculator in ``algebraic mode,'' which is closer to the way 1961Calculator in ``algebraic mode,'' which is closer to the way
1923non-RPN calculators work. In algebraic mode, you enter formulas 1962non-RPN calculators work. In algebraic mode, you enter formulas
1924in traditional @cite{2+3} notation. 1963in traditional @expr{2+3} notation.
1925 1964
1926You don't really need any special ``mode'' to enter algebraic formulas. 1965You don't really need any special ``mode'' to enter algebraic formulas.
1927You can enter a formula at any time by pressing the apostrophe (@kbd{'}) 1966You can enter a formula at any time by pressing the apostrophe (@kbd{'})
@@ -2004,7 +2043,7 @@ the function name corresponding to the square-root key @kbd{Q} is
2004the notation @samp{sqrt(@var{x})}. 2043the notation @samp{sqrt(@var{x})}.
2005 2044
2006Press the apostrophe, then type @kbd{sqrt(5*2) - 3}. The result should 2045Press the apostrophe, then type @kbd{sqrt(5*2) - 3}. The result should
2007be @cite{0.16227766017}. 2046be @expr{0.16227766017}.
2008 2047
2009Note that if the formula begins with a function name, you need to use 2048Note that if the formula begins with a function name, you need to use
2010the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin} 2049the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin}
@@ -2030,7 +2069,7 @@ Still in algebraic mode, type:
2030 2069
2031Algebraic mode allows us to enter complex numbers without pressing 2070Algebraic mode allows us to enter complex numbers without pressing
2032an apostrophe first, but it also means we need to press @key{RET} 2071an apostrophe first, but it also means we need to press @key{RET}
2033after every entry, even for a simple number like @cite{1}. 2072after every entry, even for a simple number like @expr{1}.
2034 2073
2035(You can type @kbd{C-u m a} to enable a special ``incomplete algebraic 2074(You can type @kbd{C-u m a} to enable a special ``incomplete algebraic
2036mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even 2075mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even
@@ -2050,8 +2089,9 @@ intermediate results of a calculation as you go along. You can
2050accomplish this in Calc by performing your calculation as a series 2089accomplish this in Calc by performing your calculation as a series
2051of algebraic entries, using the @kbd{$} sign to tie them together. 2090of algebraic entries, using the @kbd{$} sign to tie them together.
2052In an algebraic formula, @kbd{$} represents the number on the top 2091In an algebraic formula, @kbd{$} represents the number on the top
2053of the stack. Here, we perform the calculation @c{$\sqrt{2\times4+1}$} 2092of the stack. Here, we perform the calculation
2054@cite{sqrt(2*4+1)}, 2093@texline @tmath{\sqrt{2\times4+1}},
2094@infoline @expr{sqrt(2*4+1)},
2055which on a traditional calculator would be done by pressing 2095which on a traditional calculator would be done by pressing
2056@kbd{2 * 4 + 1 =} and then the square-root key. 2096@kbd{2 * 4 + 1 =} and then the square-root key.
2057 2097
@@ -2190,7 +2230,7 @@ the righthand formula has been evaluated as if by typing @kbd{=}.
2190 2230
2191@noindent 2231@noindent
2192Notice that the instant we stored a new value in @code{a}, all 2232Notice that the instant we stored a new value in @code{a}, all
2193@samp{=>} operators already on the stack that referred to @cite{a} 2233@samp{=>} operators already on the stack that referred to @expr{a}
2194were updated to use the new value. With @samp{=>}, you can push a 2234were updated to use the new value. With @samp{=>}, you can push a
2195set of formulas on the stack, then change the variables experimentally 2235set of formulas on the stack, then change the variables experimentally
2196to see the effects on the formulas' values. 2236to see the effects on the formulas' values.
@@ -2257,7 +2297,7 @@ mistakenly.
2257@end smallexample 2297@end smallexample
2258 2298
2259@noindent 2299@noindent
2260It was not possible to redo past the @cite{6}, since that was placed there 2300It was not possible to redo past the @expr{6}, since that was placed there
2261by something other than an undo command. 2301by something other than an undo command.
2262 2302
2263@cindex Time travel 2303@cindex Time travel
@@ -2265,7 +2305,7 @@ You can think of undo and redo as a sort of ``time machine.'' Press
2265@kbd{U} to go backward in time, @kbd{D} to go forward. If you go 2305@kbd{U} to go backward in time, @kbd{D} to go forward. If you go
2266backward and do something (like @kbd{*}) then, as any science fiction 2306backward and do something (like @kbd{*}) then, as any science fiction
2267reader knows, you have changed your future and you cannot go forward 2307reader knows, you have changed your future and you cannot go forward
2268again. Thus, the inability to redo past the @cite{6} even though there 2308again. Thus, the inability to redo past the @expr{6} even though there
2269was an earlier undo command. 2309was an earlier undo command.
2270 2310
2271You can always recall an earlier result using the Trail. We've ignored 2311You can always recall an earlier result using the Trail. We've ignored
@@ -2273,13 +2313,13 @@ the trail so far, but it has been faithfully recording everything we
2273did since we loaded the Calculator. If the Trail is not displayed, 2313did since we loaded the Calculator. If the Trail is not displayed,
2274press @kbd{t d} now to turn it on. 2314press @kbd{t d} now to turn it on.
2275 2315
2276Let's try grabbing an earlier result. The @cite{8} we computed was 2316Let's try grabbing an earlier result. The @expr{8} we computed was
2277undone by a @kbd{U} command, and was lost even to Redo when we pressed 2317undone by a @kbd{U} command, and was lost even to Redo when we pressed
2278@kbd{*}, but it's still there in the trail. There should be a little 2318@kbd{*}, but it's still there in the trail. There should be a little
2279@samp{>} arrow (the @dfn{trail pointer}) resting on the last trail 2319@samp{>} arrow (the @dfn{trail pointer}) resting on the last trail
2280entry. If there isn't, press @kbd{t ]} to reset the trail pointer. 2320entry. If there isn't, press @kbd{t ]} to reset the trail pointer.
2281Now, press @w{@kbd{t p}} to move the arrow onto the line containing 2321Now, press @w{@kbd{t p}} to move the arrow onto the line containing
2282@cite{8}, and press @w{@kbd{t y}} to ``yank'' that number back onto the 2322@expr{8}, and press @w{@kbd{t y}} to ``yank'' that number back onto the
2283stack. 2323stack.
2284 2324
2285If you press @kbd{t ]} again, you will see that even our Yank command 2325If you press @kbd{t ]} again, you will see that even our Yank command
@@ -2340,8 +2380,7 @@ directly, but you can press @kbd{`} (the backquote or accent grave)
2340to edit a stack entry. 2380to edit a stack entry.
2341 2381
2342Try entering @samp{3.141439} now. If this is supposed to represent 2382Try entering @samp{3.141439} now. If this is supposed to represent
2343@c{$\pi$} 2383@cpi{}, it's got several errors. Press @kbd{`} to edit this number.
2344@cite{pi}, it's got several errors. Press @kbd{`} to edit this number.
2345Now use the normal Emacs cursor motion and editing keys to change 2384Now use the normal Emacs cursor motion and editing keys to change
2346the second 4 to a 5, and to transpose the 3 and the 9. When you 2385the second 4 to a 5, and to transpose the 3 and the 9. When you
2347press @key{RET}, the number on the stack will be replaced by your 2386press @key{RET}, the number on the stack will be replaced by your
@@ -2370,7 +2409,7 @@ Most of the symbols there are Emacs things you don't need to worry
2370about, but the @samp{12} and the @samp{Deg} are mode indicators. 2409about, but the @samp{12} and the @samp{Deg} are mode indicators.
2371The @samp{12} means that calculations should always be carried to 2410The @samp{12} means that calculations should always be carried to
237212 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /}, 241112 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /},
2373we get @cite{0.142857142857} with exactly 12 digits, not counting 2412we get @expr{0.142857142857} with exactly 12 digits, not counting
2374leading and trailing zeros. 2413leading and trailing zeros.
2375 2414
2376You can set the precision to anything you like by pressing @kbd{p}, 2415You can set the precision to anything you like by pressing @kbd{p},
@@ -2387,14 +2426,14 @@ then doing @kbd{1 @key{RET} 7 /} again:
2387 2426
2388Although the precision can be set arbitrarily high, Calc always 2427Although the precision can be set arbitrarily high, Calc always
2389has to have @emph{some} value for the current precision. After 2428has to have @emph{some} value for the current precision. After
2390all, the true value @cite{1/7} is an infinitely repeating decimal; 2429all, the true value @expr{1/7} is an infinitely repeating decimal;
2391Calc has to stop somewhere. 2430Calc has to stop somewhere.
2392 2431
2393Of course, calculations are slower the more digits you request. 2432Of course, calculations are slower the more digits you request.
2394Press @w{@kbd{p 12}} now to set the precision back down to the default. 2433Press @w{@kbd{p 12}} now to set the precision back down to the default.
2395 2434
2396Calculations always use the current precision. For example, even 2435Calculations always use the current precision. For example, even
2397though we have a 30-digit value for @cite{1/7} on the stack, if 2436though we have a 30-digit value for @expr{1/7} on the stack, if
2398we use it in a calculation in 12-digit mode it will be rounded 2437we use it in a calculation in 12-digit mode it will be rounded
2399down to 12 digits before it is used. Try it; press @key{RET} to 2438down to 12 digits before it is used. Try it; press @key{RET} to
2400duplicate the number, then @w{@kbd{1 +}}. Notice that the @key{RET} 2439duplicate the number, then @w{@kbd{1 +}}. Notice that the @key{RET}
@@ -2412,7 +2451,7 @@ But the instant we pressed @kbd{+}, the number was rounded down.
2412 2451
2413@noindent 2452@noindent
2414In fact, since we added a digit on the left, we had to lose one 2453In fact, since we added a digit on the left, we had to lose one
2415digit on the right from even the 12-digit value of @cite{1/7}. 2454digit on the right from even the 12-digit value of @expr{1/7}.
2416 2455
2417How did we get more than 12 digits when we computed @samp{2^3^4}? The 2456How did we get more than 12 digits when we computed @samp{2^3^4}? The
2418answer is that Calc makes a distinction between @dfn{integers} and 2457answer is that Calc makes a distinction between @dfn{integers} and
@@ -2463,7 +2502,7 @@ want to see. You can enter numbers in this notation, too.
2463@noindent 2502@noindent
2464Hey, the answer is different! Look closely at the middle columns 2503Hey, the answer is different! Look closely at the middle columns
2465of the two examples. In the first, the stack contained the 2504of the two examples. In the first, the stack contained the
2466exact integer @cite{10000}, but in the second it contained 2505exact integer @expr{10000}, but in the second it contained
2467a floating-point value with a decimal point. When you raise a 2506a floating-point value with a decimal point. When you raise a
2468number to an integer power, Calc uses repeated squaring and 2507number to an integer power, Calc uses repeated squaring and
2469multiplication to get the answer. When you use a floating-point 2508multiplication to get the answer. When you use a floating-point
@@ -2564,7 +2603,7 @@ whole stack. The @kbd{d n} command changes back to the normal float
2564format; since it doesn't have an @kbd{H} prefix, it also updates all 2603format; since it doesn't have an @kbd{H} prefix, it also updates all
2565the stack entries to be in @kbd{d n} format. 2604the stack entries to be in @kbd{d n} format.
2566 2605
2567Notice that the integer @cite{12345} was not affected by any 2606Notice that the integer @expr{12345} was not affected by any
2568of the float formats. Integers are integers, and are always 2607of the float formats. Integers are integers, and are always
2569displayed exactly. 2608displayed exactly.
2570 2609
@@ -2712,13 +2751,15 @@ angle is measured in degrees. For example,
2712 2751
2713@noindent 2752@noindent
2714The shift-@kbd{S} command computes the sine of an angle. The sine 2753The shift-@kbd{S} command computes the sine of an angle. The sine
2715of 45 degrees is @c{$\sqrt{2}/2$} 2754of 45 degrees is
2716@cite{sqrt(2)/2}; squaring this yields @cite{2/4 = 0.5}. 2755@texline @tmath{\sqrt{2}/2};
2717However, there has been a slight roundoff error because the 2756@infoline @expr{sqrt(2)/2};
2718representation of @c{$\sqrt{2}/2$} 2757squaring this yields @expr{2/4 = 0.5}. However, there has been a slight
2719@cite{sqrt(2)/2} wasn't exact. The @kbd{c 1} 2758roundoff error because the representation of
2720command is a handy way to clean up numbers in this case; it 2759@texline @tmath{\sqrt{2}/2}
2721temporarily reduces the precision by one digit while it 2760@infoline @expr{sqrt(2)/2}
2761wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers
2762in this case; it temporarily reduces the precision by one digit while it
2722re-rounds the number on the top of the stack. 2763re-rounds the number on the top of the stack.
2723 2764
2724@cindex Roundoff errors, examples 2765@cindex Roundoff errors, examples
@@ -2729,9 +2770,7 @@ What happened? @xref{Modes Answer 3, 3}. (@bullet{})
2729 2770
2730To do this calculation in radians, we would type @kbd{m r} first. 2771To do this calculation in radians, we would type @kbd{m r} first.
2731(The indicator changes to @samp{Rad}.) 45 degrees corresponds to 2772(The indicator changes to @samp{Rad}.) 45 degrees corresponds to
2732@c{$\pi\over4$} 2773@cpiover{4} radians. To get @cpi{}, press the @kbd{P} key. (Once
2733@cite{pi/4} radians. To get @c{$\pi$}
2734@cite{pi}, press the @kbd{P} key. (Once
2735again, this is a shifted capital @kbd{P}. Remember, unshifted 2774again, this is a shifted capital @kbd{P}. Remember, unshifted
2736@kbd{p} sets the precision.) 2775@kbd{p} sets the precision.)
2737 2776
@@ -2757,9 +2796,10 @@ either radians or degrees, depending on the current angular mode.
2757@end smallexample 2796@end smallexample
2758 2797
2759@noindent 2798@noindent
2760Here we compute the Inverse Sine of @c{$\sqrt{0.5}$} 2799Here we compute the Inverse Sine of
2761@cite{sqrt(0.5)}, first in 2800@texline @tmath{\sqrt{0.5}},
2762radians, then in degrees. 2801@infoline @expr{sqrt(0.5)},
2802first in radians, then in degrees.
2763 2803
2764Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees 2804Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees
2765and vice-versa. 2805and vice-versa.
@@ -2939,15 +2979,16 @@ provide a @kbd{\} command. @xref{Arithmetic Answer 1, 1}. (@bullet{})
2939 2979
2940We've already seen the @kbd{Q} (square root) and @kbd{S} (sine) 2980We've already seen the @kbd{Q} (square root) and @kbd{S} (sine)
2941commands. Other commands along those lines are @kbd{C} (cosine), 2981commands. Other commands along those lines are @kbd{C} (cosine),
2942@kbd{T} (tangent), @kbd{E} (@cite{e^x}) and @kbd{L} (natural 2982@kbd{T} (tangent), @kbd{E} (@expr{e^x}) and @kbd{L} (natural
2943logarithm). These can be modified by the @kbd{I} (inverse) and 2983logarithm). These can be modified by the @kbd{I} (inverse) and
2944@kbd{H} (hyperbolic) prefix keys. 2984@kbd{H} (hyperbolic) prefix keys.
2945 2985
2946Let's compute the sine and cosine of an angle, and verify the 2986Let's compute the sine and cosine of an angle, and verify the
2947identity @c{$\sin^2x + \cos^2x = 1$} 2987identity
2948@cite{sin(x)^2 + cos(x)^2 = 1}. We'll 2988@texline @tmath{\sin^2x + \cos^2x = 1}.
2949arbitrarily pick @i{-64} degrees as a good value for @cite{x}. With 2989@infoline @expr{sin(x)^2 + cos(x)^2 = 1}.
2950the angular mode set to degrees (type @w{@kbd{m d}}), do: 2990We'll arbitrarily pick @i{-64} degrees as a good value for @expr{x}.
2991With the angular mode set to degrees (type @w{@kbd{m d}}), do:
2951 2992
2952@smallexample 2993@smallexample
2953@group 2994@group
@@ -2966,8 +3007,9 @@ You can of course do these calculations to any precision you like.)
2966Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum 3007Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum
2967of squares, command. 3008of squares, command.
2968 3009
2969Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} 3010Another identity is
2970@cite{tan(x) = sin(x) / cos(x)}. 3011@texline @tmath{\displaystyle\tan x = {\sin x \over \cos x}}.
3012@infoline @expr{tan(x) = sin(x) / cos(x)}.
2971@smallexample 3013@smallexample
2972@group 3014@group
2973 3015
@@ -2980,7 +3022,7 @@ Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$}
2980@end smallexample 3022@end smallexample
2981 3023
2982A physical interpretation of this calculation is that if you move 3024A physical interpretation of this calculation is that if you move
2983@cite{0.89879} units downward and @cite{0.43837} units to the right, 3025@expr{0.89879} units downward and @expr{0.43837} units to the right,
2984your direction of motion is @i{-64} degrees from horizontal. Suppose 3026your direction of motion is @i{-64} degrees from horizontal. Suppose
2985we move in the opposite direction, up and to the left: 3027we move in the opposite direction, up and to the left:
2986 3028
@@ -3029,9 +3071,9 @@ the top two stack elements right after the @kbd{U U}, then a pair of
3029 3071
3030A similar identity is supposed to hold for hyperbolic sines and cosines, 3072A similar identity is supposed to hold for hyperbolic sines and cosines,
3031except that it is the @emph{difference} 3073except that it is the @emph{difference}
3032@c{$\cosh^2x - \sinh^2x$} 3074@texline @tmath{\cosh^2x - \sinh^2x}
3033@cite{cosh(x)^2 - sinh(x)^2} that always equals one. 3075@infoline @expr{cosh(x)^2 - sinh(x)^2}
3034Let's try to verify this identity.@refill 3076that always equals one. Let's try to verify this identity.
3035 3077
3036@smallexample 3078@smallexample
3037@group 3079@group
@@ -3057,12 +3099,12 @@ enormously so. Try it if you wish; sure enough, the answer is
30570.99999, reasonably close to 1. 30990.99999, reasonably close to 1.
3058 3100
3059Of course, a more reasonable way to verify the identity is to use 3101Of course, a more reasonable way to verify the identity is to use
3060a more reasonable value for @cite{x}! 3102a more reasonable value for @expr{x}!
3061 3103
3062@cindex Common logarithm 3104@cindex Common logarithm
3063Some Calculator commands use the Hyperbolic prefix for other purposes. 3105Some Calculator commands use the Hyperbolic prefix for other purposes.
3064The logarithm and exponential functions, for example, work to the base 3106The logarithm and exponential functions, for example, work to the base
3065@cite{e} normally but use base-10 instead if you use the Hyperbolic 3107@expr{e} normally but use base-10 instead if you use the Hyperbolic
3066prefix. 3108prefix.
3067 3109
3068@smallexample 3110@smallexample
@@ -3095,7 +3137,7 @@ value of @var{b}.
3095Here we first use @kbd{B} to compute the base-10 logarithm, then use 3137Here we first use @kbd{B} to compute the base-10 logarithm, then use
3096the ``hyperbolic'' exponential as a cheap hack to recover the number 3138the ``hyperbolic'' exponential as a cheap hack to recover the number
30971000, then use @kbd{B} again to compute the natural logarithm. Note 31391000, then use @kbd{B} again to compute the natural logarithm. Note
3098that @kbd{P} with the hyperbolic prefix pushes the constant @cite{e} 3140that @kbd{P} with the hyperbolic prefix pushes the constant @expr{e}
3099onto the stack. 3141onto the stack.
3100 3142
3101You may have noticed that both times we took the base-10 logarithm 3143You may have noticed that both times we took the base-10 logarithm
@@ -3136,8 +3178,8 @@ in this case).
3136 3178
3137If you take the factorial of a non-integer, Calc uses a generalized 3179If you take the factorial of a non-integer, Calc uses a generalized
3138factorial function defined in terms of Euler's Gamma function 3180factorial function defined in terms of Euler's Gamma function
3139@c{$\Gamma(n)$} 3181@texline @tmath{\Gamma(n)}
3140@cite{gamma(n)} 3182@infoline @expr{gamma(n)}
3141(which is itself available as the @kbd{f g} command). 3183(which is itself available as the @kbd{f g} command).
3142 3184
3143@smallexample 3185@smallexample
@@ -3152,17 +3194,19 @@ factorial function defined in terms of Euler's Gamma function
3152@end smallexample 3194@end smallexample
3153 3195
3154@noindent 3196@noindent
3155Here we verify the identity @c{$n! = \Gamma(n+1)$} 3197Here we verify the identity
3156@cite{@var{n}!@: = gamma(@var{n}+1)}. 3198@texline @tmath{n! = \Gamma(n+1)}.
3199@infoline @expr{@var{n}!@: = gamma(@var{n}+1)}.
3157 3200
3158The binomial coefficient @var{n}-choose-@var{m}@c{ or $\displaystyle {n \choose m}$} 3201The binomial coefficient @var{n}-choose-@var{m}
3159@asis{} is defined by 3202@texline or @tmath{\displaystyle {n \choose m}}
3160@c{$\displaystyle {n! \over m! \, (n-m)!}$} 3203is defined by
3161@cite{n!@: / m!@: (n-m)!} for all reals @cite{n} and 3204@texline @tmath{\displaystyle {n! \over m! \, (n-m)!}}
3162@cite{m}. The intermediate results in this formula can become quite 3205@infoline @expr{n!@: / m!@: (n-m)!}
3163large even if the final result is small; the @kbd{k c} command computes 3206for all reals @expr{n} and @expr{m}. The intermediate results in this
3164a binomial coefficient in a way that avoids large intermediate 3207formula can become quite large even if the final result is small; the
3165values. 3208@kbd{k c} command computes a binomial coefficient in a way that avoids
3209large intermediate values.
3166 3210
3167The @kbd{k} prefix key defines several common functions out of 3211The @kbd{k} prefix key defines several common functions out of
3168combinatorics and number theory. Here we compute the binomial 3212combinatorics and number theory. Here we compute the binomial
@@ -3266,7 +3310,7 @@ of the vectors.
3266@cindex Dot product 3310@cindex Dot product
3267The dot product of two vectors is equal to the product of their 3311The dot product of two vectors is equal to the product of their
3268lengths times the cosine of the angle between them. (Here the vector 3312lengths times the cosine of the angle between them. (Here the vector
3269is interpreted as a line from the origin @cite{(0,0,0)} to the 3313is interpreted as a line from the origin @expr{(0,0,0)} to the
3270specified point in three-dimensional space.) The @kbd{A} 3314specified point in three-dimensional space.) The @kbd{A}
3271(absolute value) command can be used to compute the length of a 3315(absolute value) command can be used to compute the length of a
3272vector. 3316vector.
@@ -3379,8 +3423,8 @@ the second example.
3379 3423
3380When two matrices are multiplied, the lefthand matrix must have 3424When two matrices are multiplied, the lefthand matrix must have
3381the same number of columns as the righthand matrix has rows. 3425the same number of columns as the righthand matrix has rows.
3382Row @cite{i}, column @cite{j} of the result is effectively the 3426Row @expr{i}, column @expr{j} of the result is effectively the
3383dot product of row @cite{i} of the left matrix by column @cite{j} 3427dot product of row @expr{i} of the left matrix by column @expr{j}
3384of the right matrix. 3428of the right matrix.
3385 3429
3386If we try to duplicate this matrix and multiply it by itself, 3430If we try to duplicate this matrix and multiply it by itself,
@@ -3441,9 +3485,11 @@ rows in the matrix is different from the number of elements in the
3441vector. 3485vector.
3442 3486
3443(@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows 3487(@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows
3444of the above @c{$2\times3$} 3488of the above
3445@asis{2x3} matrix to get @cite{[6, 15]}. Now use @samp{*} to 3489@texline @tmath{2\times3}
3446sum along the columns to get @cite{[5, 7, 9]}. 3490@infoline 2x3
3491matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns
3492to get @expr{[5, 7, 9]}.
3447@xref{Matrix Answer 1, 1}. (@bullet{}) 3493@xref{Matrix Answer 1, 1}. (@bullet{})
3448 3494
3449@cindex Identity matrix 3495@cindex Identity matrix
@@ -3566,7 +3612,7 @@ inverse of the matrix. Calc can do this all in one step:
3566@end smallexample 3612@end smallexample
3567 3613
3568@noindent 3614@noindent
3569The result is the @cite{[a, b, c]} vector that solves the equations. 3615The result is the @expr{[a, b, c]} vector that solves the equations.
3570(Dividing by a square matrix is equivalent to multiplying by its 3616(Dividing by a square matrix is equivalent to multiplying by its
3571inverse.) 3617inverse.)
3572 3618
@@ -3590,16 +3636,19 @@ the matrix and vector. If we multiplied in the other order, Calc would
3590assume the vector was a row vector in order to make the dimensions 3636assume the vector was a row vector in order to make the dimensions
3591come out right, and the answer would be incorrect. If you 3637come out right, and the answer would be incorrect. If you
3592don't feel safe letting Calc take either interpretation of your 3638don't feel safe letting Calc take either interpretation of your
3593vectors, use explicit @c{$N\times1$} 3639vectors, use explicit
3594@asis{Nx1} or @c{$1\times N$} 3640@texline @tmath{N\times1}
3595@asis{1xN} matrices instead. 3641@infoline Nx1
3596In this case, you would enter the original column vector as 3642or
3597@samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. 3643@texline @tmath{1\times N}
3644@infoline 1xN
3645matrices instead. In this case, you would enter the original column
3646vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}.
3598 3647
3599(@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make 3648(@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make
3600vectors and matrices that include variables. Solve the following 3649vectors and matrices that include variables. Solve the following
3601system of equations to get expressions for @cite{x} and @cite{y} 3650system of equations to get expressions for @expr{x} and @expr{y}
3602in terms of @cite{a} and @cite{b}. 3651in terms of @expr{a} and @expr{b}.
3603 3652
3604@ifinfo 3653@ifinfo
3605@group 3654@group
@@ -3628,10 +3677,10 @@ if it has more equations than variables. It is often the case that
3628there are no values for the variables that will satisfy all the 3677there are no values for the variables that will satisfy all the
3629equations at once, but it is still useful to find a set of values 3678equations at once, but it is still useful to find a set of values
3630which ``nearly'' satisfy all the equations. In terms of matrix equations, 3679which ``nearly'' satisfy all the equations. In terms of matrix equations,
3631you can't solve @cite{A X = B} directly because the matrix @cite{A} 3680you can't solve @expr{A X = B} directly because the matrix @expr{A}
3632is not square for an over-determined system. Matrix inversion works 3681is not square for an over-determined system. Matrix inversion works
3633only for square matrices. One common trick is to multiply both sides 3682only for square matrices. One common trick is to multiply both sides
3634on the left by the transpose of @cite{A}: 3683on the left by the transpose of @expr{A}:
3635@ifinfo 3684@ifinfo
3636@samp{trn(A)*A*X = trn(A)*B}. 3685@samp{trn(A)*A*X = trn(A)*B}.
3637@end ifinfo 3686@end ifinfo
@@ -3639,12 +3688,14 @@ on the left by the transpose of @cite{A}:
3639\turnoffactive 3688\turnoffactive
3640$A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}. 3689$A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.
3641@end tex 3690@end tex
3642Now @c{$A^T A$} 3691Now
3643@cite{trn(A)*A} is a square matrix so a solution is possible. It 3692@texline @tmath{A^T A}
3644turns out that the @cite{X} vector you compute in this way will be a 3693@infoline @expr{trn(A)*A}
3645``least-squares'' solution, which can be regarded as the ``closest'' 3694is a square matrix so a solution is possible. It turns out that the
3646solution to the set of equations. Use Calc to solve the following 3695@expr{X} vector you compute in this way will be a ``least-squares''
3647over-determined system:@refill 3696solution, which can be regarded as the ``closest'' solution to the set
3697of equations. Use Calc to solve the following over-determined
3698system:
3648 3699
3649@ifinfo 3700@ifinfo
3650@group 3701@group
@@ -3733,8 +3784,10 @@ other a plain number.) In the final step, we take the square root
3733of each element. 3784of each element.
3734 3785
3735(@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two 3786(@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two
3736from @c{$2^{-4}$} 3787from
3737@cite{2^-4} to @cite{2^4}. @xref{List Answer 1, 1}. (@bullet{}) 3788@texline @tmath{2^{-4}}
3789@infoline @expr{2^-4}
3790to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{})
3738 3791
3739You can also @dfn{reduce} a binary operator across a vector. 3792You can also @dfn{reduce} a binary operator across a vector.
3740For example, reducing @samp{*} computes the product of all the 3793For example, reducing @samp{*} computes the product of all the
@@ -3868,13 +3921,13 @@ the manual and find this table there. (Press @kbd{g}, then type
3868@kbd{List Tutorial}, to jump straight to this section.) 3921@kbd{List Tutorial}, to jump straight to this section.)
3869 3922
3870Position the cursor at the upper-left corner of this table, just 3923Position the cursor at the upper-left corner of this table, just
3871to the left of the @cite{1.34}. Press @kbd{C-@@} to set the mark. 3924to the left of the @expr{1.34}. Press @kbd{C-@@} to set the mark.
3872(On your system this may be @kbd{C-2}, @kbd{C-@key{SPC}}, or @kbd{NUL}.) 3925(On your system this may be @kbd{C-2}, @kbd{C-@key{SPC}}, or @kbd{NUL}.)
3873Now position the cursor to the lower-right, just after the @cite{1.354}. 3926Now position the cursor to the lower-right, just after the @expr{1.354}.
3874You have now defined this region as an Emacs ``rectangle.'' Still 3927You have now defined this region as an Emacs ``rectangle.'' Still
3875in the Info buffer, type @kbd{M-# r}. This command 3928in the Info buffer, type @kbd{M-# r}. This command
3876(@code{calc-grab-rectangle}) will pop you back into the Calculator, with 3929(@code{calc-grab-rectangle}) will pop you back into the Calculator, with
3877the contents of the rectangle you specified in the form of a matrix.@refill 3930the contents of the rectangle you specified in the form of a matrix.
3878 3931
3879@smallexample 3932@smallexample
3880@group 3933@group
@@ -3919,7 +3972,7 @@ Let's store these in quick variables 1 and 2, respectively.
3919(Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the 3972(Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the
3920stored value from the stack.) 3973stored value from the stack.)
3921 3974
3922In a least squares fit, the slope @cite{m} is given by the formula 3975In a least squares fit, the slope @expr{m} is given by the formula
3923 3976
3924@ifinfo 3977@ifinfo
3925@example 3978@example
@@ -3935,11 +3988,13 @@ $$ m = {N \sum x y - \sum x \sum y \over
3935@end tex 3988@end tex
3936 3989
3937@noindent 3990@noindent
3938where @c{$\sum x$} 3991where
3939@cite{sum(x)} represents the sum of all the values of @cite{x}. 3992@texline @tmath{\sum x}
3940While there is an actual @code{sum} function in Calc, it's easier to 3993@infoline @expr{sum(x)}
3941sum a vector using a simple reduction. First, let's compute the four 3994represents the sum of all the values of @expr{x}. While there is an
3942different sums that this formula uses. 3995actual @code{sum} function in Calc, it's easier to sum a vector using a
3996simple reduction. First, let's compute the four different sums that
3997this formula uses.
3943 3998
3944@smallexample 3999@smallexample
3945@group 4000@group
@@ -3973,7 +4028,7 @@ respectively. (We could have used \kbd{*} to compute $\sum x^2$ and
3973$\sum x y$.) 4028$\sum x y$.)
3974@end tex 4029@end tex
3975 4030
3976Finally, we also need @cite{N}, the number of data points. This is just 4031Finally, we also need @expr{N}, the number of data points. This is just
3977the length of either of our lists. 4032the length of either of our lists.
3978 4033
3979@smallexample 4034@smallexample
@@ -4012,7 +4067,7 @@ Now we grind through the formula:
4012@end group 4067@end group
4013@end smallexample 4068@end smallexample
4014 4069
4015That gives us the slope @cite{m}. The y-intercept @cite{b} can now 4070That gives us the slope @expr{m}. The y-intercept @expr{b} can now
4016be found with the simple formula, 4071be found with the simple formula,
4017 4072
4018@ifinfo 4073@ifinfo
@@ -4038,8 +4093,10 @@ $$ b = {\sum y - m \sum x \over N} $$
4038@end group 4093@end group
4039@end smallexample 4094@end smallexample
4040 4095
4041Let's ``plot'' this straight line approximation, @c{$y \approx m x + b$} 4096Let's ``plot'' this straight line approximation,
4042@cite{m x + b}, and compare it with the original data.@refill 4097@texline @tmath{y \approx m x + b},
4098@infoline @expr{m x + b},
4099and compare it with the original data.
4043 4100
4044@smallexample 4101@smallexample
4045@group 4102@group
@@ -4056,7 +4113,7 @@ to a vector, can be done without mapping commands since these are
4056common operations from vector algebra. As far as Calc is concerned, 4113common operations from vector algebra. As far as Calc is concerned,
4057we've just been doing geometry in 19-dimensional space! 4114we've just been doing geometry in 19-dimensional space!
4058 4115
4059We can subtract this vector from our original @cite{y} vector to get 4116We can subtract this vector from our original @expr{y} vector to get
4060a feel for the error of our fit. Let's find the maximum error: 4117a feel for the error of our fit. Let's find the maximum error:
4061 4118
4062@smallexample 4119@smallexample
@@ -4131,9 +4188,9 @@ when you are done to remove the X graphics window and terminate GNUPLOT.
4131 4188
4132(@bullet{}) @strong{Exercise 2.} An earlier exercise showed how to do 4189(@bullet{}) @strong{Exercise 2.} An earlier exercise showed how to do
4133least squares fitting to a general system of equations. Our 19 data 4190least squares fitting to a general system of equations. Our 19 data
4134points are really 19 equations of the form @cite{y_i = m x_i + b} for 4191points are really 19 equations of the form @expr{y_i = m x_i + b} for
4135different pairs of @cite{(x_i,y_i)}. Use the matrix-transpose method 4192different pairs of @expr{(x_i,y_i)}. Use the matrix-transpose method
4136to solve for @cite{m} and @cite{b}, duplicating the above result. 4193to solve for @expr{m} and @expr{b}, duplicating the above result.
4137@xref{List Answer 2, 2}. (@bullet{}) 4194@xref{List Answer 2, 2}. (@bullet{})
4138 4195
4139@cindex Geometric mean 4196@cindex Geometric mean
@@ -4161,7 +4218,7 @@ us that the alternating sum of binomial coefficients
4161@var{n}-choose-0 minus @var{n}-choose-1 plus @var{n}-choose-2, and so 4218@var{n}-choose-0 minus @var{n}-choose-1 plus @var{n}-choose-2, and so
4162on up to @var{n}-choose-@var{n}, 4219on up to @var{n}-choose-@var{n},
4163always comes out to zero. Let's verify this 4220always comes out to zero. Let's verify this
4164for @cite{n=6}.@refill 4221for @expr{n=6}.
4165@end ifinfo 4222@end ifinfo
4166@tex 4223@tex
4167As another example, a theorem about binomial coefficients tells 4224As another example, a theorem about binomial coefficients tells
@@ -4232,13 +4289,13 @@ element of a plain vector. With a negative argument, @kbd{v r}
4232and @kbd{v c} instead delete one row, column, or vector element. 4289and @kbd{v c} instead delete one row, column, or vector element.
4233 4290
4234@cindex Divisor functions 4291@cindex Divisor functions
4235(@bullet{}) @strong{Exercise 4.} The @cite{k}th @dfn{divisor function} 4292(@bullet{}) @strong{Exercise 4.} The @expr{k}th @dfn{divisor function}
4236@tex 4293@tex
4237$\sigma_k(n)$ 4294$\sigma_k(n)$
4238@end tex 4295@end tex
4239is the sum of the @cite{k}th powers of all the divisors of an 4296is the sum of the @expr{k}th powers of all the divisors of an
4240integer @cite{n}. Figure out a method for computing the divisor 4297integer @expr{n}. Figure out a method for computing the divisor
4241function for reasonably small values of @cite{n}. As a test, 4298function for reasonably small values of @expr{n}. As a test,
4242the 0th and 1st divisor functions of 30 are 8 and 72, respectively. 4299the 0th and 1st divisor functions of 30 are 8 and 72, respectively.
4243@xref{List Answer 4, 4}. (@bullet{}) 4300@xref{List Answer 4, 4}. (@bullet{})
4244 4301
@@ -4290,23 +4347,24 @@ command to enable multi-line display of vectors.)
4290@cindex Maximizing a function over a list of values 4347@cindex Maximizing a function over a list of values
4291@c [fix-ref Numerical Solutions] 4348@c [fix-ref Numerical Solutions]
4292(@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's 4349(@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's
4293@c{$J_1(x)$} 4350@texline @tmath{J_1(x)}
4294@cite{J1} function @samp{besJ(1,x)} for @cite{x} from 0 to 5 4351@infoline @expr{J1}
4295in steps of 0.25. 4352function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25.
4296Find the value of @cite{x} (from among the above set of values) for 4353Find the value of @expr{x} (from among the above set of values) for
4297which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, 4354which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method,
4298i.e., just reading along the list by hand to find the largest value 4355i.e., just reading along the list by hand to find the largest value
4299is not allowed! (There is an @kbd{a X} command which does this kind 4356is not allowed! (There is an @kbd{a X} command which does this kind
4300of thing automatically; @pxref{Numerical Solutions}.) 4357of thing automatically; @pxref{Numerical Solutions}.)
4301@xref{List Answer 8, 8}. (@bullet{})@refill 4358@xref{List Answer 8, 8}. (@bullet{})
4302 4359
4303@cindex Digits, vectors of 4360@cindex Digits, vectors of
4304(@bullet{}) @strong{Exercise 9.} You are given an integer in the range 4361(@bullet{}) @strong{Exercise 9.} You are given an integer in the range
4305@c{$0 \le N < 10^m$} 4362@texline @tmath{0 \le N < 10^m}
4306@cite{0 <= N < 10^m} for @cite{m=12} (i.e., an integer of less than 4363@infoline @expr{0 <= N < 10^m}
4307twelve digits). Convert this integer into a vector of @cite{m} 4364for @expr{m=12} (i.e., an integer of less than
4365twelve digits). Convert this integer into a vector of @expr{m}
4308digits, each in the range from 0 to 9. In vector-of-digits notation, 4366digits, each in the range from 0 to 9. In vector-of-digits notation,
4309add one to this integer to produce a vector of @cite{m+1} digits 4367add one to this integer to produce a vector of @expr{m+1} digits
4310(since there could be a carry out of the most significant digit). 4368(since there could be a carry out of the most significant digit).
4311Convert this vector back into a regular integer. A good integer 4369Convert this vector back into a regular integer. A good integer
4312to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) 4370to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{})
@@ -4316,40 +4374,39 @@ to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{})
4316happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) 4374happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{})
4317 4375
4318(@bullet{}) @strong{Exercise 11.} The area of a circle of radius one 4376(@bullet{}) @strong{Exercise 11.} The area of a circle of radius one
4319is @c{$\pi$} 4377is @cpi{}. The area of the
4320@cite{pi}. The area of the @c{$2\times2$} 4378@texline @tmath{2\times2}
4321@asis{2x2} square that encloses that 4379@infoline 2x2
4322circle is 4. So if we throw @var{n} darts at random points in the square, 4380square that encloses that circle is 4. So if we throw @var{n} darts at
4323about @c{$\pi/4$} 4381random points in the square, about @cpiover{4} of them will land inside
4324@cite{pi/4} of them will land inside the circle. This gives us 4382the circle. This gives us an entertaining way to estimate the value of
4325an entertaining way to estimate the value of @c{$\pi$} 4383@cpi{}. The @w{@kbd{k r}}
4326@cite{pi}. The @w{@kbd{k r}}
4327command picks a random number between zero and the value on the stack. 4384command picks a random number between zero and the value on the stack.
4328We could get a random floating-point number between @i{-1} and 1 by typing 4385We could get a random floating-point number between @i{-1} and 1 by typing
4329@w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @cite{(x,y)} points in 4386@w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @expr{(x,y)} points in
4330this square, then use vector mapping and reduction to count how many 4387this square, then use vector mapping and reduction to count how many
4331points lie inside the unit circle. Hint: Use the @kbd{v b} command. 4388points lie inside the unit circle. Hint: Use the @kbd{v b} command.
4332@xref{List Answer 11, 11}. (@bullet{}) 4389@xref{List Answer 11, 11}. (@bullet{})
4333 4390
4334@cindex Matchstick problem 4391@cindex Matchstick problem
4335(@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides 4392(@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides
4336another way to calculate @c{$\pi$} 4393another way to calculate @cpi{}. Say you have an infinite field
4337@cite{pi}. Say you have an infinite field
4338of vertical lines with a spacing of one inch. Toss a one-inch matchstick 4394of vertical lines with a spacing of one inch. Toss a one-inch matchstick
4339onto the field. The probability that the matchstick will land crossing 4395onto the field. The probability that the matchstick will land crossing
4340a line turns out to be @c{$2/\pi$} 4396a line turns out to be
4341@cite{2/pi}. Toss 100 matchsticks to estimate 4397@texline @tmath{2/\pi}.
4342@c{$\pi$} 4398@infoline @expr{2/pi}.
4343@cite{pi}. (If you want still more fun, the probability that the GCD 4399Toss 100 matchsticks to estimate @cpi{}. (If you want still more fun,
4344(@w{@kbd{k g}}) of two large integers is one turns out to be @c{$6/\pi^2$} 4400the probability that the GCD (@w{@kbd{k g}}) of two large integers is
4345@cite{6/pi^2}. 4401one turns out to be
4346That provides yet another way to estimate @c{$\pi$} 4402@texline @tmath{6/\pi^2}.
4347@cite{pi}.) 4403@infoline @expr{6/pi^2}.
4404That provides yet another way to estimate @cpi{}.)
4348@xref{List Answer 12, 12}. (@bullet{}) 4405@xref{List Answer 12, 12}. (@bullet{})
4349 4406
4350(@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in 4407(@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in
4351double-quote marks, @samp{"hello"}, creates a vector of the numerical 4408double-quote marks, @samp{"hello"}, creates a vector of the numerical
4352(ASCII) codes of the characters (here, @cite{[104, 101, 108, 108, 111]}). 4409(ASCII) codes of the characters (here, @expr{[104, 101, 108, 108, 111]}).
4353Sometimes it is convenient to compute a @dfn{hash code} of a string, 4410Sometimes it is convenient to compute a @dfn{hash code} of a string,
4354which is just an integer that represents the value of that string. 4411which is just an integer that represents the value of that string.
4355Two equal strings have the same hash code; two different strings 4412Two equal strings have the same hash code; two different strings
@@ -4358,9 +4415,9 @@ over 400 function names, but Emacs can quickly find the definition for
4358any given name because it has sorted the functions into ``buckets'' by 4415any given name because it has sorted the functions into ``buckets'' by
4359their hash codes. Sometimes a few names will hash into the same bucket, 4416their hash codes. Sometimes a few names will hash into the same bucket,
4360but it is easier to search among a few names than among all the names.) 4417but it is easier to search among a few names than among all the names.)
4361One popular hash function is computed as follows: First set @cite{h = 0}. 4418One popular hash function is computed as follows: First set @expr{h = 0}.
4362Then, for each character from the string in turn, set @cite{h = 3h + c_i} 4419Then, for each character from the string in turn, set @expr{h = 3h + c_i}
4363where @cite{c_i} is the character's ASCII code. If we have 511 buckets, 4420where @expr{c_i} is the character's ASCII code. If we have 511 buckets,
4364we then take the hash code modulo 511 to get the bucket number. Develop a 4421we then take the hash code modulo 511 to get the bucket number. Develop a
4365simple command or commands for converting string vectors into hash codes. 4422simple command or commands for converting string vectors into hash codes.
4366The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo 4423The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo
@@ -4372,8 +4429,8 @@ value and a number of steps @var{n} from the stack; it then applies the
4372function you give to the starting value 0, 1, 2, up to @var{n} times 4429function you give to the starting value 0, 1, 2, up to @var{n} times
4373and returns a vector of the results. Use this command to create a 4430and returns a vector of the results. Use this command to create a
4374``random walk'' of 50 steps. Start with the two-dimensional point 4431``random walk'' of 50 steps. Start with the two-dimensional point
4375@cite{(0,0)}; then take one step a random distance between @i{-1} and 1 4432@expr{(0,0)}; then take one step a random distance between @i{-1} and 1
4376in both @cite{x} and @cite{y}; then take another step, and so on. Use the 4433in both @expr{x} and @expr{y}; then take another step, and so on. Use the
4377@kbd{g f} command to display this random walk. Now modify your random 4434@kbd{g f} command to display this random walk. Now modify your random
4378walk to walk a unit distance, but in a random direction, at each step. 4435walk to walk a unit distance, but in a random direction, at each step.
4379(Hint: The @code{sincos} function returns a vector of the cosine and 4436(Hint: The @code{sincos} function returns a vector of the cosine and
@@ -4436,8 +4493,7 @@ same, to within the current precision.
4436 4493
4437(@bullet{}) @strong{Exercise 1.} A calculation has produced the 4494(@bullet{}) @strong{Exercise 1.} A calculation has produced the
4438result 1.26508260337. You suspect it is the square root of the 4495result 1.26508260337. You suspect it is the square root of the
4439product of @c{$\pi$} 4496product of @cpi{} and some rational number. Is it? (Be sure
4440@cite{pi} and some rational number. Is it? (Be sure
4441to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{}) 4497to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{})
4442 4498
4443@dfn{Complex numbers} can be stored in both rectangular and polar form. 4499@dfn{Complex numbers} can be stored in both rectangular and polar form.
@@ -4453,7 +4509,7 @@ to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{})
4453 4509
4454@noindent 4510@noindent
4455The square root of @i{-9} is by default rendered in rectangular form 4511The square root of @i{-9} is by default rendered in rectangular form
4456(@w{@cite{0 + 3i}}), but we can convert it to polar form (3 with a 4512(@w{@expr{0 + 3i}}), but we can convert it to polar form (3 with a
4457phase angle of 90 degrees). All the usual arithmetic and scientific 4513phase angle of 90 degrees). All the usual arithmetic and scientific
4458operations are defined on both types of complex numbers. 4514operations are defined on both types of complex numbers.
4459 4515
@@ -4509,9 +4565,9 @@ to turn on ``infinite mode.''
4509Dividing by zero normally is left unevaluated, but after @kbd{m i} 4565Dividing by zero normally is left unevaluated, but after @kbd{m i}
4510it instead gives an infinite result. The answer is actually 4566it instead gives an infinite result. The answer is actually
4511@code{uinf}, ``undirected infinity.'' If you look at a graph of 4567@code{uinf}, ``undirected infinity.'' If you look at a graph of
4512@cite{1 / x} around @w{@cite{x = 0}}, you'll see that it goes toward 4568@expr{1 / x} around @w{@expr{x = 0}}, you'll see that it goes toward
4513plus infinity as you approach zero from above, but toward minus 4569plus infinity as you approach zero from above, but toward minus
4514infinity as you approach from below. Since we said only @cite{1 / 0}, 4570infinity as you approach from below. Since we said only @expr{1 / 0},
4515Calc knows that the answer is infinite but not in which direction. 4571Calc knows that the answer is infinite but not in which direction.
4516That's what @code{uinf} means. Notice that multiplying @code{uinf} 4572That's what @code{uinf} means. Notice that multiplying @code{uinf}
4517by a negative number still leaves plain @code{uinf}; there's no 4573by a negative number still leaves plain @code{uinf}; there's no
@@ -4641,10 +4697,11 @@ a 60% chance that the result is correct within 0.59 degrees.
4641 4697
4642@cindex Torus, volume of 4698@cindex Torus, volume of
4643(@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is 4699(@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is
4644@c{$2 \pi^2 R r^2$} 4700@texline @tmath{2 \pi^2 R r^2}
4645@w{@cite{2 pi^2 R r^2}} where @cite{R} is the radius of the circle that 4701@infoline @w{@expr{2 pi^2 R r^2}}
4646defines the center of the tube and @cite{r} is the radius of the tube 4702where @expr{R} is the radius of the circle that
4647itself. Suppose @cite{R} is 20 cm and @cite{r} is 4 cm, each known to 4703defines the center of the tube and @expr{r} is the radius of the tube
4704itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to
4648within 5 percent. What is the volume and the relative uncertainty of 4705within 5 percent. What is the volume and the relative uncertainty of
4649the volume? @xref{Types Answer 7, 7}. (@bullet{}) 4706the volume? @xref{Types Answer 7, 7}. (@bullet{})
4650 4707
@@ -4739,14 +4796,15 @@ that arises in the second one.
4739 4796
4740@cindex Fermat, primality test of 4797@cindex Fermat, primality test of
4741(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat 4798(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat
4742says that @c{\w{$x^{n-1} \bmod n = 1$}} 4799says that
4743@cite{x^(n-1) mod n = 1} if @cite{n} is a prime number 4800@texline @w{@tmath{x^{n-1} \bmod n = 1}}
4744and @cite{x} is an integer less than @cite{n}. If @cite{n} is 4801@infoline @expr{x^(n-1) mod n = 1}
4745@emph{not} a prime number, this will @emph{not} be true for most 4802if @expr{n} is a prime number and @expr{x} is an integer less than
4746values of @cite{x}. Thus we can test informally if a number is 4803@expr{n}. If @expr{n} is @emph{not} a prime number, this will
4747prime by trying this formula for several values of @cite{x}. 4804@emph{not} be true for most values of @expr{x}. Thus we can test
4748Use this test to tell whether the following numbers are prime: 4805informally if a number is prime by trying this formula for several
4749811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{}) 4806values of @expr{x}. Use this test to tell whether the following numbers
4807are prime: 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{})
4750 4808
4751It is possible to use HMS forms as parts of error forms, intervals, 4809It is possible to use HMS forms as parts of error forms, intervals,
4752modulo forms, or as the phase part of a polar complex number. 4810modulo forms, or as the phase part of a polar complex number.
@@ -4766,9 +4824,11 @@ of day on the stack as an HMS/modulo form.
4766This calculation tells me it is six hours and 22 minutes until midnight. 4824This calculation tells me it is six hours and 22 minutes until midnight.
4767 4825
4768(@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year 4826(@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year
4769is about @c{$\pi \times 10^7$} 4827is about
4770@w{@cite{pi * 10^7}} seconds. What time will it be that 4828@texline @tmath{\pi \times 10^7}
4771many seconds from right now? @xref{Types Answer 11, 11}. (@bullet{}) 4829@infoline @w{@expr{pi * 10^7}}
4830seconds. What time will it be that many seconds from right now?
4831@xref{Types Answer 11, 11}. (@bullet{})
4772 4832
4773(@bullet{}) @strong{Exercise 12.} You are preparing to order packaging 4833(@bullet{}) @strong{Exercise 12.} You are preparing to order packaging
4774for the CD release of the Extended Disco Version of @emph{Abbey Road}. 4834for the CD release of the Extended Disco Version of @emph{Abbey Road}.
@@ -4949,9 +5009,9 @@ formulas. Continuing with the formula from the last example,
4949 5009
4950@noindent 5010@noindent
4951First we ``expand'' using the distributive law, then we ``collect'' 5011First we ``expand'' using the distributive law, then we ``collect''
4952terms involving like powers of @cite{x}. 5012terms involving like powers of @expr{x}.
4953 5013
4954Let's find the value of this expression when @cite{x} is 2 and @cite{y} 5014Let's find the value of this expression when @expr{x} is 2 and @expr{y}
4955is one-half. 5015is one-half.
4956 5016
4957@smallexample 5017@smallexample
@@ -4976,11 +5036,11 @@ unstore it with @kbd{s u x @key{RET}} before the above example will work
4976properly.) 5036properly.)
4977 5037
4978@cindex Maximum of a function using Calculus 5038@cindex Maximum of a function using Calculus
4979Let's find the maximum value of our original expression when @cite{y} 5039Let's find the maximum value of our original expression when @expr{y}
4980is one-half and @cite{x} ranges over all possible values. We can 5040is one-half and @expr{x} ranges over all possible values. We can
4981do this by taking the derivative with respect to @cite{x} and examining 5041do this by taking the derivative with respect to @expr{x} and examining
4982values of @cite{x} for which the derivative is zero. If the second 5042values of @expr{x} for which the derivative is zero. If the second
4983derivative of the function at that value of @cite{x} is negative, 5043derivative of the function at that value of @expr{x} is negative,
4984the function has a local maximum there. 5044the function has a local maximum there.
4985 5045
4986@smallexample 5046@smallexample
@@ -4993,8 +5053,8 @@ the function has a local maximum there.
4993@end smallexample 5053@end smallexample
4994 5054
4995@noindent 5055@noindent
4996Well, the derivative is clearly zero when @cite{x} is zero. To find 5056Well, the derivative is clearly zero when @expr{x} is zero. To find
4997the other root(s), let's divide through by @cite{x} and then solve: 5057the other root(s), let's divide through by @expr{x} and then solve:
4998 5058
4999@smallexample 5059@smallexample
5000@group 5060@group
@@ -5020,7 +5080,7 @@ Notice the use of @kbd{a s} to ``simplify'' the formula. When the
5020default algebraic simplifications don't do enough, you can use 5080default algebraic simplifications don't do enough, you can use
5021@kbd{a s} to tell Calc to spend more time on the job. 5081@kbd{a s} to tell Calc to spend more time on the job.
5022 5082
5023Now we compute the second derivative and plug in our values of @cite{x}: 5083Now we compute the second derivative and plug in our values of @expr{x}:
5024 5084
5025@smallexample 5085@smallexample
5026@group 5086@group
@@ -5050,14 +5110,14 @@ to delete the @samp{x}.)
5050 5110
5051@noindent 5111@noindent
5052The first of these second derivatives is negative, so we know the function 5112The first of these second derivatives is negative, so we know the function
5053has a maximum value at @cite{x = 1.19023}. (The function also has a 5113has a maximum value at @expr{x = 1.19023}. (The function also has a
5054local @emph{minimum} at @cite{x = 0}.) 5114local @emph{minimum} at @expr{x = 0}.)
5055 5115
5056When we solved for @cite{x}, we got only one value even though 5116When we solved for @expr{x}, we got only one value even though
5057@cite{34 - 24 x^2 = 0} is a quadratic equation that ought to have 5117@expr{34 - 24 x^2 = 0} is a quadratic equation that ought to have
5058two solutions. The reason is that @w{@kbd{a S}} normally returns a 5118two solutions. The reason is that @w{@kbd{a S}} normally returns a
5059single ``principal'' solution. If it needs to come up with an 5119single ``principal'' solution. If it needs to come up with an
5060arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}. 5120arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}.
5061If it needs an arbitrary integer, it picks zero. We can get a full 5121If it needs an arbitrary integer, it picks zero. We can get a full
5062solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}. 5122solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.
5063 5123
@@ -5075,9 +5135,9 @@ Calc has invented the variable @samp{s1} to represent an unknown sign;
5075it is supposed to be either @i{+1} or @i{-1}. Here we have used 5135it is supposed to be either @i{+1} or @i{-1}. Here we have used
5076the ``let'' command to evaluate the expression when the sign is negative. 5136the ``let'' command to evaluate the expression when the sign is negative.
5077If we plugged this into our second derivative we would get the same, 5137If we plugged this into our second derivative we would get the same,
5078negative, answer, so @cite{x = -1.19023} is also a maximum. 5138negative, answer, so @expr{x = -1.19023} is also a maximum.
5079 5139
5080To find the actual maximum value, we must plug our two values of @cite{x} 5140To find the actual maximum value, we must plug our two values of @expr{x}
5081into the original formula. 5141into the original formula.
5082 5142
5083@smallexample 5143@smallexample
@@ -5127,7 +5187,7 @@ Calc has a built-in @kbd{a P} command that solves an equation using
5127@w{@kbd{H a S}} and returns a vector of all the solutions. It simply 5187@w{@kbd{H a S}} and returns a vector of all the solutions. It simply
5128automates the job we just did by hand. Applied to our original 5188automates the job we just did by hand. Applied to our original
5129cubic polynomial, it would produce the vector of solutions 5189cubic polynomial, it would produce the vector of solutions
5130@cite{[1.19023, -1.19023, 0]}. (There is also an @kbd{a X} command 5190@expr{[1.19023, -1.19023, 0]}. (There is also an @kbd{a X} command
5131which finds a local maximum of a function. It uses a numerical search 5191which finds a local maximum of a function. It uses a numerical search
5132method rather than examining the derivatives, and thus requires you 5192method rather than examining the derivatives, and thus requires you
5133to provide some kind of initial guess to show it where to look.) 5193to provide some kind of initial guess to show it where to look.)
@@ -5215,7 +5275,7 @@ may prefer to remain in Big mode, but all the examples in the tutorial
5215are shown in normal mode.) 5275are shown in normal mode.)
5216 5276
5217@cindex Area under a curve 5277@cindex Area under a curve
5218What is the area under the portion of this curve from @cite{x = 1} to @cite{2}? 5278What is the area under the portion of this curve from @expr{x = 1} to @expr{2}?
5219This is simply the integral of the function: 5279This is simply the integral of the function:
5220 5280
5221@smallexample 5281@smallexample
@@ -5228,7 +5288,7 @@ This is simply the integral of the function:
5228@end smallexample 5288@end smallexample
5229 5289
5230@noindent 5290@noindent
5231We want to evaluate this at our two values for @cite{x} and subtract. 5291We want to evaluate this at our two values for @expr{x} and subtract.
5232One way to do it is again with vector mapping and reduction: 5292One way to do it is again with vector mapping and reduction:
5233 5293
5234@smallexample 5294@smallexample
@@ -5240,20 +5300,23 @@ One way to do it is again with vector mapping and reduction:
5240@end group 5300@end group
5241@end smallexample 5301@end smallexample
5242 5302
5243(@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @cite{y} 5303(@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @expr{y}
5244of @c{$x \sin \pi x$} 5304of
5245@w{@cite{x sin(pi x)}} (where the sine is calculated in radians). 5305@texline @tmath{x \sin \pi x}
5246Find the values of the integral for integers @cite{y} from 1 to 5. 5306@infoline @w{@expr{x sin(pi x)}}
5247@xref{Algebra Answer 3, 3}. (@bullet{}) 5307(where the sine is calculated in radians). Find the values of the
5308integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3,
53093}. (@bullet{})
5248 5310
5249Calc's integrator can do many simple integrals symbolically, but many 5311Calc's integrator can do many simple integrals symbolically, but many
5250others are beyond its capabilities. Suppose we wish to find the area 5312others are beyond its capabilities. Suppose we wish to find the area
5251under the curve @c{$\sin x \ln x$} 5313under the curve
5252@cite{sin(x) ln(x)} over the same range of @cite{x}. If 5314@texline @tmath{\sin x \ln x}
5253you entered this formula and typed @kbd{a i x @key{RET}} (don't bother to try 5315@infoline @expr{sin(x) ln(x)}
5254this), Calc would work for a long time but would be unable to find a 5316over the same range of @expr{x}. If you entered this formula and typed
5255solution. In fact, there is no closed-form solution to this integral. 5317@kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a
5256Now what do we do? 5318long time but would be unable to find a solution. In fact, there is no
5319closed-form solution to this integral. Now what do we do?
5257 5320
5258@cindex Integration, numerical 5321@cindex Integration, numerical
5259@cindex Numerical integration 5322@cindex Numerical integration
@@ -5322,7 +5385,7 @@ we're not doing too well. Let's try another approach.
5322 5385
5323@noindent 5386@noindent
5324Here we have computed the Taylor series expansion of the function 5387Here we have computed the Taylor series expansion of the function
5325about the point @cite{x=1}. We can now integrate this polynomial 5388about the point @expr{x=1}. We can now integrate this polynomial
5326approximation, since polynomials are easy to integrate. 5389approximation, since polynomials are easy to integrate.
5327 5390
5328@smallexample 5391@smallexample
@@ -5339,8 +5402,8 @@ Better! By increasing the precision and/or asking for more terms
5339in the Taylor series, we can get a result as accurate as we like. 5402in the Taylor series, we can get a result as accurate as we like.
5340(Taylor series converge better away from singularities in the 5403(Taylor series converge better away from singularities in the
5341function such as the one at @code{ln(0)}, so it would also help to 5404function such as the one at @code{ln(0)}, so it would also help to
5342expand the series about the points @cite{x=2} or @cite{x=1.5} instead 5405expand the series about the points @expr{x=2} or @expr{x=1.5} instead
5343of @cite{x=1}.) 5406of @expr{x=1}.)
5344 5407
5345@cindex Simpson's rule 5408@cindex Simpson's rule
5346@cindex Integration by Simpson's rule 5409@cindex Integration by Simpson's rule
@@ -5370,7 +5433,7 @@ $$ \displaylines{
5370@end tex 5433@end tex
5371 5434
5372@noindent 5435@noindent
5373where @cite{n} (which must be even) is the number of slices and @cite{h} 5436where @expr{n} (which must be even) is the number of slices and @expr{h}
5374is the width of each slice. These are 10 and 0.1 in our example. 5437is the width of each slice. These are 10 and 0.1 in our example.
5375For reference, here is the corresponding formula for the stairstep 5438For reference, here is the corresponding formula for the stairstep
5376method: 5439method:
@@ -5389,9 +5452,11 @@ $$ h (f(a) + f(a+h) + f(a+2h) + f(a+3h) + \cdots
5389\afterdisplay 5452\afterdisplay
5390@end tex 5453@end tex
5391 5454
5392Compute the integral from 1 to 2 of @c{$\sin x \ln x$} 5455Compute the integral from 1 to 2 of
5393@cite{sin(x) ln(x)} using 5456@texline @tmath{\sin x \ln x}
5394Simpson's rule with 10 slices. @xref{Algebra Answer 4, 4}. (@bullet{}) 5457@infoline @expr{sin(x) ln(x)}
5458using Simpson's rule with 10 slices.
5459@xref{Algebra Answer 4, 4}. (@bullet{})
5395 5460
5396Calc has a built-in @kbd{a I} command for doing numerical integration. 5461Calc has a built-in @kbd{a I} command for doing numerical integration.
5397It uses @dfn{Romberg's method}, which is a more sophisticated cousin 5462It uses @dfn{Romberg's method}, which is a more sophisticated cousin
@@ -5639,7 +5704,7 @@ constants @samp{e}, @samp{phi}, and so on also match literally.
5639A common error with rewrite 5704A common error with rewrite
5640rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting 5705rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
5641to match any @samp{f} with five arguments but in fact matching 5706to match any @samp{f} with five arguments but in fact matching
5642only when the fifth argument is literally @samp{e}!@refill 5707only when the fifth argument is literally @samp{e}!
5643 5708
5644@cindex Fibonacci numbers 5709@cindex Fibonacci numbers
5645@ignore 5710@ignore
@@ -5789,10 +5854,10 @@ on the stack and tried to use the rule
5789@samp{opt(a) + opt(b) x := f(a, b, x)}. What happened? 5854@samp{opt(a) + opt(b) x := f(a, b, x)}. What happened?
5790@xref{Rewrites Answer 3, 3}. (@bullet{}) 5855@xref{Rewrites Answer 3, 3}. (@bullet{})
5791 5856
5792(@bullet{}) @strong{Exercise 4.} Starting with a positive integer @cite{a}, 5857(@bullet{}) @strong{Exercise 4.} Starting with a positive integer @expr{a},
5793divide @cite{a} by two if it is even, otherwise compute @cite{3 a + 1}. 5858divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}.
5794Now repeat this step over and over. A famous unproved conjecture 5859Now repeat this step over and over. A famous unproved conjecture
5795is that for any starting @cite{a}, the sequence always eventually 5860is that for any starting @expr{a}, the sequence always eventually
5796reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of 5861reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of
5797rules that convert this into @samp{seq(1, @var{n})} where @var{n} 5862rules that convert this into @samp{seq(1, @var{n})} where @var{n}
5798is the number of steps it took the sequence to reach the value 1. 5863is the number of steps it took the sequence to reach the value 1.
@@ -5801,27 +5866,27 @@ configuration, and to stop with just the number @var{n} by itself.
5801Now make the result be a vector of values in the sequence, from @var{a} 5866Now make the result be a vector of values in the sequence, from @var{a}
5802to 1. (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x} 5867to 1. (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x}
5803and @var{y}.) For example, rewriting @samp{seq(6)} should yield the 5868and @var{y}.) For example, rewriting @samp{seq(6)} should yield the
5804vector @cite{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. 5869vector @expr{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
5805@xref{Rewrites Answer 4, 4}. (@bullet{}) 5870@xref{Rewrites Answer 4, 4}. (@bullet{})
5806 5871
5807(@bullet{}) @strong{Exercise 5.} Define, using rewrite rules, a function 5872(@bullet{}) @strong{Exercise 5.} Define, using rewrite rules, a function
5808@samp{nterms(@var{x})} that returns the number of terms in the sum 5873@samp{nterms(@var{x})} that returns the number of terms in the sum
5809@var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes 5874@var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes
5810is one or more non-sum terms separated by @samp{+} or @samp{-} signs, 5875is one or more non-sum terms separated by @samp{+} or @samp{-} signs,
5811so that @cite{2 - 3 (x + y) + x y} is a sum of three terms.) 5876so that @expr{2 - 3 (x + y) + x y} is a sum of three terms.)
5812@xref{Rewrites Answer 5, 5}. (@bullet{}) 5877@xref{Rewrites Answer 5, 5}. (@bullet{})
5813 5878
5814(@bullet{}) @strong{Exercise 6.} Calc considers the form @cite{0^0} 5879(@bullet{}) @strong{Exercise 6.} Calc considers the form @expr{0^0}
5815to be ``indeterminate,'' and leaves it unevaluated (assuming infinite 5880to be ``indeterminate,'' and leaves it unevaluated (assuming infinite
5816mode is not enabled). Some people prefer to define @cite{0^0 = 1}, 5881mode is not enabled). Some people prefer to define @expr{0^0 = 1},
5817so that the identity @cite{x^0 = 1} can safely be used for all @cite{x}. 5882so that the identity @expr{x^0 = 1} can safely be used for all @expr{x}.
5818Find a way to make Calc follow this convention. What happens if you 5883Find a way to make Calc follow this convention. What happens if you
5819now type @kbd{m i} to turn on infinite mode? 5884now type @kbd{m i} to turn on infinite mode?
5820@xref{Rewrites Answer 6, 6}. (@bullet{}) 5885@xref{Rewrites Answer 6, 6}. (@bullet{})
5821 5886
5822(@bullet{}) @strong{Exercise 7.} A Taylor series for a function is an 5887(@bullet{}) @strong{Exercise 7.} A Taylor series for a function is an
5823infinite series that exactly equals the value of that function at 5888infinite series that exactly equals the value of that function at
5824values of @cite{x} near zero. 5889values of @expr{x} near zero.
5825 5890
5826@ifinfo 5891@ifinfo
5827@example 5892@example
@@ -5829,15 +5894,15 @@ cos(x) = 1 - x^2 / 2! + x^4 / 4! - x^6 / 6! + ...
5829@end example 5894@end example
5830@end ifinfo 5895@end ifinfo
5831@tex 5896@tex
5832\turnoffactive \let\rm\goodrm 5897\turnoffactive
5833\beforedisplay 5898\beforedisplay
5834$$ \cos x = 1 - {x^2 \over 2!} + {x^4 \over 4!} - {x^6 \over 6!} + \cdots $$ 5899$$ \cos x = 1 - {x^2 \over 2!} + {x^4 \over 4!} - {x^6 \over 6!} + \cdots $$
5835\afterdisplay 5900\afterdisplay
5836@end tex 5901@end tex
5837 5902
5838The @kbd{a t} command produces a @dfn{truncated Taylor series} which 5903The @kbd{a t} command produces a @dfn{truncated Taylor series} which
5839is obtained by dropping all the terms higher than, say, @cite{x^2}. 5904is obtained by dropping all the terms higher than, say, @expr{x^2}.
5840Calc represents the truncated Taylor series as a polynomial in @cite{x}. 5905Calc represents the truncated Taylor series as a polynomial in @expr{x}.
5841Mathematicians often write a truncated series using a ``big-O'' notation 5906Mathematicians often write a truncated series using a ``big-O'' notation
5842that records what was the lowest term that was truncated. 5907that records what was the lowest term that was truncated.
5843 5908
@@ -5847,15 +5912,15 @@ cos(x) = 1 - x^2 / 2! + O(x^3)
5847@end example 5912@end example
5848@end ifinfo 5913@end ifinfo
5849@tex 5914@tex
5850\turnoffactive \let\rm\goodrm 5915\turnoffactive
5851\beforedisplay 5916\beforedisplay
5852$$ \cos x = 1 - {x^2 \over 2!} + O(x^3) $$ 5917$$ \cos x = 1 - {x^2 \over 2!} + O(x^3) $$
5853\afterdisplay 5918\afterdisplay
5854@end tex 5919@end tex
5855 5920
5856@noindent 5921@noindent
5857The meaning of @cite{O(x^3)} is ``a quantity which is negligibly small 5922The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small
5858if @cite{x^3} is considered negligibly small as @cite{x} goes to zero.'' 5923if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.''
5859 5924
5860The exercise is to create rewrite rules that simplify sums and products of 5925The exercise is to create rewrite rules that simplify sums and products of
5861power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}. 5926power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}.
@@ -5934,9 +5999,10 @@ in @samp{a + 1} for @samp{x} in the defining formula.
5934@end ignore 5999@end ignore
5935@tindex Si 6000@tindex Si
5936(@bullet{}) @strong{Exercise 1.} The ``sine integral'' function 6001(@bullet{}) @strong{Exercise 1.} The ``sine integral'' function
5937@c{${\rm Si}(x)$} 6002@texline @tmath{{\rm Si}(x)}
5938@cite{Si(x)} is defined as the integral of @samp{sin(t)/t} for 6003@infoline @expr{Si(x)}
5939@cite{t = 0} to @cite{x} in radians. (It was invented because this 6004is defined as the integral of @samp{sin(t)/t} for
6005@expr{t = 0} to @expr{x} in radians. (It was invented because this
5940integral has no solution in terms of basic functions; if you give it 6006integral has no solution in terms of basic functions; if you give it
5941to Calc's @kbd{a i} command, it will ponder it for a long time and then 6007to Calc's @kbd{a i} command, it will ponder it for a long time and then
5942give up.) We can use the numerical integration command, however, 6008give up.) We can use the numerical integration command, however,
@@ -6010,12 +6076,13 @@ the following functions:
6010 6076
6011@enumerate 6077@enumerate
6012@item 6078@item
6013Compute @c{$\displaystyle{\sin x \over x}$} 6079Compute
6014@cite{sin(x) / x}, where @cite{x} is the number on the 6080@texline @tmath{\displaystyle{\sin x \over x}},
6015top of the stack. 6081@infoline @expr{sin(x) / x},
6082where @expr{x} is the number on the top of the stack.
6016 6083
6017@item 6084@item
6018Compute the base-@cite{b} logarithm, just like the @kbd{B} key except 6085Compute the base-@expr{b} logarithm, just like the @kbd{B} key except
6019the arguments are taken in the opposite order. 6086the arguments are taken in the opposite order.
6020 6087
6021@item 6088@item
@@ -6044,7 +6111,7 @@ inside keyboard macros, but actually work at any time.
6044@end smallexample 6111@end smallexample
6045 6112
6046@noindent 6113@noindent
6047Here we have computed the fourth derivative of @cite{x^6} by 6114Here we have computed the fourth derivative of @expr{x^6} by
6048enclosing a derivative command in a ``repeat loop'' structure. 6115enclosing a derivative command in a ``repeat loop'' structure.
6049This structure pops a repeat count from the stack, then 6116This structure pops a repeat count from the stack, then
6050executes the body of the loop that many times. 6117executes the body of the loop that many times.
@@ -6074,14 +6141,18 @@ key if you have one, makes a copy of the number in level 2.)
6074 6141
6075@cindex Golden ratio 6142@cindex Golden ratio
6076@cindex Phi, golden ratio 6143@cindex Phi, golden ratio
6077A fascinating property of the Fibonacci numbers is that the @cite{n}th 6144A fascinating property of the Fibonacci numbers is that the @expr{n}th
6078Fibonacci number can be found directly by computing @c{$\phi^n / \sqrt{5}$} 6145Fibonacci number can be found directly by computing
6079@cite{phi^n / sqrt(5)} 6146@texline @tmath{\phi^n / \sqrt{5}}
6080and then rounding to the nearest integer, where @c{$\phi$ (``phi'')} 6147@infoline @expr{phi^n / sqrt(5)}
6081@cite{phi}, the 6148and then rounding to the nearest integer, where
6082``golden ratio,'' is @c{$(1 + \sqrt{5}) / 2$} 6149@texline @tmath{\phi} (``phi''),
6083@cite{(1 + sqrt(5)) / 2}. (For convenience, this constant is available 6150@infoline @expr{phi},
6084from the @code{phi} variable, or the @kbd{I H P} command.) 6151the ``golden ratio,'' is
6152@texline @tmath{(1 + \sqrt{5}) / 2}.
6153@infoline @expr{(1 + sqrt(5)) / 2}.
6154(For convenience, this constant is available from the @code{phi}
6155variable, or the @kbd{I H P} command.)
6085 6156
6086@smallexample 6157@smallexample
6087@group 6158@group
@@ -6094,22 +6165,28 @@ from the @code{phi} variable, or the @kbd{I H P} command.)
6094 6165
6095@cindex Continued fractions 6166@cindex Continued fractions
6096(@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} 6167(@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction}
6097representation of @c{$\phi$} 6168representation of
6098@cite{phi} is @c{$1 + 1/(1 + 1/(1 + 1/( \ldots )))$} 6169@texline @tmath{\phi}
6099@cite{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. 6170@infoline @expr{phi}
6171is
6172@texline @tmath{1 + 1/(1 + 1/(1 + 1/( \ldots )))}.
6173@infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}.
6100We can compute an approximate value by carrying this however far 6174We can compute an approximate value by carrying this however far
6101and then replacing the innermost @c{$1/( \ldots )$} 6175and then replacing the innermost
6102@cite{1/( ...@: )} by 1. Approximate 6176@texline @tmath{1/( \ldots )}
6103@c{$\phi$} 6177@infoline @expr{1/( ...@: )}
6104@cite{phi} using a twenty-term continued fraction. 6178by 1. Approximate
6179@texline @tmath{\phi}
6180@infoline @expr{phi}
6181using a twenty-term continued fraction.
6105@xref{Programming Answer 5, 5}. (@bullet{}) 6182@xref{Programming Answer 5, 5}. (@bullet{})
6106 6183
6107(@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for 6184(@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for
6108Fibonacci numbers can be expressed in terms of matrices. Given a 6185Fibonacci numbers can be expressed in terms of matrices. Given a
6109vector @w{@cite{[a, b]}} determine a matrix which, when multiplied by this 6186vector @w{@expr{[a, b]}} determine a matrix which, when multiplied by this
6110vector, produces the vector @cite{[b, c]}, where @cite{a}, @cite{b} and 6187vector, produces the vector @expr{[b, c]}, where @expr{a}, @expr{b} and
6111@cite{c} are three successive Fibonacci numbers. Now write a program 6188@expr{c} are three successive Fibonacci numbers. Now write a program
6112that, given an integer @cite{n}, computes the @cite{n}th Fibonacci number 6189that, given an integer @expr{n}, computes the @expr{n}th Fibonacci number
6113using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{}) 6190using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{})
6114 6191
6115@cindex Harmonic numbers 6192@cindex Harmonic numbers
@@ -6198,12 +6275,13 @@ survive past the @kbd{Z '} command.
6198The @dfn{Bernoulli numbers} are a sequence with the interesting 6275The @dfn{Bernoulli numbers} are a sequence with the interesting
6199property that all of the odd Bernoulli numbers are zero, and the 6276property that all of the odd Bernoulli numbers are zero, and the
6200even ones, while difficult to compute, can be roughly approximated 6277even ones, while difficult to compute, can be roughly approximated
6201by the formula @c{$\displaystyle{2 n! \over (2 \pi)^n}$} 6278by the formula
6202@cite{2 n!@: / (2 pi)^n}. Let's write a keyboard 6279@texline @tmath{\displaystyle{2 n! \over (2 \pi)^n}}.
6203macro to compute (approximate) Bernoulli numbers. (Calc has a 6280@infoline @expr{2 n!@: / (2 pi)^n}.
6204command, @kbd{k b}, to compute exact Bernoulli numbers, but 6281Let's write a keyboard macro to compute (approximate) Bernoulli numbers.
6205this command is very slow for large @cite{n} since the higher 6282(Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but
6206Bernoulli numbers are very large fractions.) 6283this command is very slow for large @expr{n} since the higher Bernoulli
6284numbers are very large fractions.)
6207 6285
6208@smallexample 6286@smallexample
6209@group 6287@group
@@ -6223,7 +6301,7 @@ if it pops zero or something that is not a number (like a formula).
6223Here we take our integer argument modulo 2; this will be nonzero 6301Here we take our integer argument modulo 2; this will be nonzero
6224if we're asking for an odd Bernoulli number. 6302if we're asking for an odd Bernoulli number.
6225 6303
6226The actual tenth Bernoulli number is @cite{5/66}. 6304The actual tenth Bernoulli number is @expr{5/66}.
6227 6305
6228@smallexample 6306@smallexample
6229@group 6307@group
@@ -6354,8 +6432,8 @@ Z '
6354 6432
6355(@bullet{}) @strong{Exercise 8.} A general algorithm for solving 6433(@bullet{}) @strong{Exercise 8.} A general algorithm for solving
6356equations numerically is @dfn{Newton's Method}. Given the equation 6434equations numerically is @dfn{Newton's Method}. Given the equation
6357@cite{f(x) = 0} for any function @cite{f}, and an initial guess 6435@expr{f(x) = 0} for any function @expr{f}, and an initial guess
6358@cite{x_0} which is reasonably close to the desired solution, apply 6436@expr{x_0} which is reasonably close to the desired solution, apply
6359this formula over and over: 6437this formula over and over:
6360 6438
6361@ifinfo 6439@ifinfo
@@ -6365,32 +6443,36 @@ new_x = x - f(x)/f'(x)
6365@end ifinfo 6443@end ifinfo
6366@tex 6444@tex
6367\beforedisplay 6445\beforedisplay
6368$$ x_{\goodrm new} = x - {f(x) \over f'(x)} $$ 6446$$ x_{\rm new} = x - {f(x) \over f'(x)} $$
6369\afterdisplay 6447\afterdisplay
6370@end tex 6448@end tex
6371 6449
6372@noindent 6450@noindent
6373where @cite{f'(x)} is the derivative of @cite{f}. The @cite{x} 6451where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x}
6374values will quickly converge to a solution, i.e., eventually 6452values will quickly converge to a solution, i.e., eventually
6375@c{$x_{\rm new}$} 6453@texline @tmath{x_{\rm new}}
6376@cite{new_x} and @cite{x} will be equal to within the limits 6454@infoline @expr{new_x}
6455and @expr{x} will be equal to within the limits
6377of the current precision. Write a program which takes a formula 6456of the current precision. Write a program which takes a formula
6378involving the variable @cite{x}, and an initial guess @cite{x_0}, 6457involving the variable @expr{x}, and an initial guess @expr{x_0},
6379on the stack, and produces a value of @cite{x} for which the formula 6458on the stack, and produces a value of @expr{x} for which the formula
6380is zero. Use it to find a solution of @c{$\sin(\cos x) = 0.5$} 6459is zero. Use it to find a solution of
6381@cite{sin(cos(x)) = 0.5} 6460@texline @tmath{\sin(\cos x) = 0.5}
6382near @cite{x = 4.5}. (Use angles measured in radians.) Note that 6461@infoline @expr{sin(cos(x)) = 0.5}
6462near @expr{x = 4.5}. (Use angles measured in radians.) Note that
6383the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's 6463the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's
6384method when it is able. @xref{Programming Answer 8, 8}. (@bullet{}) 6464method when it is able. @xref{Programming Answer 8, 8}. (@bullet{})
6385 6465
6386@cindex Digamma function 6466@cindex Digamma function
6387@cindex Gamma constant, Euler's 6467@cindex Gamma constant, Euler's
6388@cindex Euler's gamma constant 6468@cindex Euler's gamma constant
6389(@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function @c{$\psi(z)$ (``psi'')} 6469(@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function
6390@cite{psi(z)} 6470@texline @tmath{\psi(z) (``psi'')}
6391is defined as the derivative of @c{$\ln \Gamma(z)$} 6471@infoline @expr{psi(z)}
6392@cite{ln(gamma(z))}. For large 6472is defined as the derivative of
6393values of @cite{z}, it can be approximated by the infinite sum 6473@texline @tmath{\ln \Gamma(z)}.
6474@infoline @expr{ln(gamma(z))}.
6475For large values of @expr{z}, it can be approximated by the infinite sum
6394 6476
6395@ifinfo 6477@ifinfo
6396@example 6478@example
@@ -6398,7 +6480,6 @@ psi(z) ~= ln(z) - 1/2z - sum(bern(2 n) / 2 n z^(2 n), n, 1, inf)
6398@end example 6480@end example
6399@end ifinfo 6481@end ifinfo
6400@tex 6482@tex
6401\let\rm\goodrm
6402\beforedisplay 6483\beforedisplay
6403$$ \psi(z) \approx \ln z - {1\over2z} - 6484$$ \psi(z) \approx \ln z - {1\over2z} -
6404 \sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}} 6485 \sum_{n=1}^\infty {\code{bern}(2 n) \over 2 n z^{2n}}
@@ -6407,37 +6488,48 @@ $$
6407@end tex 6488@end tex
6408 6489
6409@noindent 6490@noindent
6410where @c{$\sum$} 6491where
6411@cite{sum} represents the sum over @cite{n} from 1 to infinity 6492@texline @tmath{\sum}
6493@infoline @expr{sum}
6494represents the sum over @expr{n} from 1 to infinity
6412(or to some limit high enough to give the desired accuracy), and 6495(or to some limit high enough to give the desired accuracy), and
6413the @code{bern} function produces (exact) Bernoulli numbers. 6496the @code{bern} function produces (exact) Bernoulli numbers.
6414While this sum is not guaranteed to converge, in practice it is safe. 6497While this sum is not guaranteed to converge, in practice it is safe.
6415An interesting mathematical constant is Euler's gamma, which is equal 6498An interesting mathematical constant is Euler's gamma, which is equal
6416to about 0.5772. One way to compute it is by the formula, 6499to about 0.5772. One way to compute it is by the formula,
6417@c{$\gamma = -\psi(1)$} 6500@texline @tmath{\gamma = -\psi(1)}.
6418@cite{gamma = -psi(1)}. Unfortunately, 1 isn't a large enough argument 6501@infoline @expr{gamma = -psi(1)}.
6419for the above formula to work (5 is a much safer value for @cite{z}). 6502Unfortunately, 1 isn't a large enough argument
6420Fortunately, we can compute @c{$\psi(1)$} 6503for the above formula to work (5 is a much safer value for @expr{z}).
6421@cite{psi(1)} from @c{$\psi(5)$} 6504Fortunately, we can compute
6422@cite{psi(5)} using 6505@texline @tmath{\psi(1)}
6423the recurrence @c{$\psi(z+1) = \psi(z) + {1 \over z}$} 6506@infoline @expr{psi(1)}
6424@cite{psi(z+1) = psi(z) + 1/z}. Your task: Develop 6507from
6425a program to compute @c{$\psi(z)$} 6508@texline @tmath{\psi(5)}
6426@cite{psi(z)}; it should ``pump up'' @cite{z} 6509@infoline @expr{psi(5)}
6510using the recurrence
6511@texline @tmath{\psi(z+1) = \psi(z) + {1 \over z}}.
6512@infoline @expr{psi(z+1) = psi(z) + 1/z}.
6513Your task: Develop a program to compute
6514@texline @tmath{\psi(z)};
6515@infoline @expr{psi(z)};
6516it should ``pump up'' @expr{z}
6427if necessary to be greater than 5, then use the above summation 6517if necessary to be greater than 5, then use the above summation
6428formula. Use looping commands to compute the sum. Use your function 6518formula. Use looping commands to compute the sum. Use your function
6429to compute @c{$\gamma$} 6519to compute
6430@cite{gamma} to twelve decimal places. (Calc has a built-in command 6520@texline @tmath{\gamma}
6521@infoline @expr{gamma}
6522to twelve decimal places. (Calc has a built-in command
6431for Euler's constant, @kbd{I P}, which you can use to check your answer.) 6523for Euler's constant, @kbd{I P}, which you can use to check your answer.)
6432@xref{Programming Answer 9, 9}. (@bullet{}) 6524@xref{Programming Answer 9, 9}. (@bullet{})
6433 6525
6434@cindex Polynomial, list of coefficients 6526@cindex Polynomial, list of coefficients
6435(@bullet{}) @strong{Exercise 10.} Given a polynomial in @cite{x} and 6527(@bullet{}) @strong{Exercise 10.} Given a polynomial in @expr{x} and
6436a number @cite{m} on the stack, where the polynomial is of degree 6528a number @expr{m} on the stack, where the polynomial is of degree
6437@cite{m} or less (i.e., does not have any terms higher than @cite{x^m}), 6529@expr{m} or less (i.e., does not have any terms higher than @expr{x^m}),
6438write a program to convert the polynomial into a list-of-coefficients 6530write a program to convert the polynomial into a list-of-coefficients
6439notation. For example, @cite{5 x^4 + (x + 1)^2} with @cite{m = 6} 6531notation. For example, @expr{5 x^4 + (x + 1)^2} with @expr{m = 6}
6440should produce the list @cite{[1, 2, 1, 0, 5, 0, 0]}. Also develop 6532should produce the list @expr{[1, 2, 1, 0, 5, 0, 0]}. Also develop
6441a way to convert from this form back to the standard algebraic form. 6533a way to convert from this form back to the standard algebraic form.
6442@xref{Programming Answer 10, 10}. (@bullet{}) 6534@xref{Programming Answer 10, 10}. (@bullet{})
6443 6535
@@ -6478,9 +6570,9 @@ to the same key with @kbd{Z K s}. Now the @kbd{z s} command will run
6478the complete recursive program. (Another way is to use @w{@kbd{Z E}} 6570the complete recursive program. (Another way is to use @w{@kbd{Z E}}
6479or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once, 6571or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once,
6480thus avoiding the ``training'' phase.) The task: Write a program 6572thus avoiding the ``training'' phase.) The task: Write a program
6481that computes Stirling numbers of the first kind, given @cite{n} and 6573that computes Stirling numbers of the first kind, given @expr{n} and
6482@cite{m} on the stack. Test it with @emph{small} inputs like 6574@expr{m} on the stack. Test it with @emph{small} inputs like
6483@cite{s(4,2)}. (There is a built-in command for Stirling numbers, 6575@expr{s(4,2)}. (There is a built-in command for Stirling numbers,
6484@kbd{k s}, which you can use to check your answers.) 6576@kbd{k s}, which you can use to check your answers.)
6485@xref{Programming Answer 11, 11}. (@bullet{}) 6577@xref{Programming Answer 11, 11}. (@bullet{})
6486 6578
@@ -6492,7 +6584,7 @@ program can:
6492 6584
6493(@bullet{}) @strong{Exercise 12.} Write another program for 6585(@bullet{}) @strong{Exercise 12.} Write another program for
6494computing Stirling numbers of the first kind, this time using 6586computing Stirling numbers of the first kind, this time using
6495rewrite rules. Once again, @cite{n} and @cite{m} should be taken 6587rewrite rules. Once again, @expr{n} and @expr{m} should be taken
6496from the stack. @xref{Programming Answer 12, 12}. (@bullet{}) 6588from the stack. @xref{Programming Answer 12, 12}. (@bullet{})
6497 6589
6498@example 6590@example
@@ -6601,21 +6693,23 @@ This section includes answers to all the exercises in the Calc tutorial.
6601@noindent 6693@noindent
6602@kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -} 6694@kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -}
6603 6695
6604The result is @c{$1 - (2 \times (3 + 4)) = -13$} 6696The result is
6605@cite{1 - (2 * (3 + 4)) = -13}. 6697@texline @tmath{1 - (2 \times (3 + 4)) = -13}.
6698@infoline @expr{1 - (2 * (3 + 4)) = -13}.
6606 6699
6607@node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises 6700@node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises
6608@subsection RPN Tutorial Exercise 2 6701@subsection RPN Tutorial Exercise 2
6609 6702
6610@noindent 6703@noindent
6611@c{$2\times4 + 7\times9.5 + {5\over4} = 75.75$} 6704@texline @tmath{2\times4 + 7\times9.5 + {5\over4} = 75.75}
6612@cite{2*4 + 7*9.5 + 5/4 = 75.75} 6705@infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75}
6613 6706
6614After computing the intermediate term @c{$2\times4 = 8$} 6707After computing the intermediate term
6615@cite{2*4 = 8}, you can leave 6708@texline @tmath{2\times4 = 8},
6616that result on the stack while you compute the second term. With 6709@infoline @expr{2*4 = 8},
6617both of these results waiting on the stack you can then compute the 6710you can leave that result on the stack while you compute the second
6618final term, then press @kbd{+ +} to add everything up. 6711term. With both of these results waiting on the stack you can then
6712compute the final term, then press @kbd{+ +} to add everything up.
6619 6713
6620@smallexample 6714@smallexample
6621@group 6715@group
@@ -6739,8 +6833,8 @@ If the @kbd{Q} key is broken, you could use @kbd{' $^0.5 @key{RET}}.
6739Or, RPN style, @kbd{0.5 ^}. 6833Or, RPN style, @kbd{0.5 ^}.
6740 6834
6741(Actually, @samp{$^1:2}, using the fraction one-half as the power, is 6835(Actually, @samp{$^1:2}, using the fraction one-half as the power, is
6742a closer equivalent, since @samp{9^0.5} yields @cite{3.0} whereas 6836a closer equivalent, since @samp{9^0.5} yields @expr{3.0} whereas
6743@samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @cite{3}.) 6837@samp{sqrt(9)} and @samp{9^1:2} yield the exact integer @expr{3}.)
6744 6838
6745@node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to Exercises 6839@node Algebraic Answer 2, Algebraic Answer 3, Algebraic Answer 1, Answers to Exercises
6746@subsection Algebraic Entry Tutorial Exercise 2 6840@subsection Algebraic Entry Tutorial Exercise 2
@@ -6755,14 +6849,14 @@ explicit @samp{*} symbol here: @samp{2 x*(1+y)}.
6755@subsection Algebraic Entry Tutorial Exercise 3 6849@subsection Algebraic Entry Tutorial Exercise 3
6756 6850
6757@noindent 6851@noindent
6758The result from @kbd{1 @key{RET} 0 /} will be the formula @cite{1 / 0}. 6852The result from @kbd{1 @key{RET} 0 /} will be the formula @expr{1 / 0}.
6759The ``function'' @samp{/} cannot be evaluated when its second argument 6853The ``function'' @samp{/} cannot be evaluated when its second argument
6760is zero, so it is left in symbolic form. When you now type @kbd{0 *}, 6854is zero, so it is left in symbolic form. When you now type @kbd{0 *},
6761the result will be zero because Calc uses the general rule that ``zero 6855the result will be zero because Calc uses the general rule that ``zero
6762times anything is zero.'' 6856times anything is zero.''
6763 6857
6764@c [fix-ref Infinities] 6858@c [fix-ref Infinities]
6765The @kbd{m i} command enables an @dfn{infinite mode} in which @cite{1 / 0} 6859The @kbd{m i} command enables an @dfn{infinite mode} in which @expr{1 / 0}
6766results in a special symbol that represents ``infinity.'' If you 6860results in a special symbol that represents ``infinity.'' If you
6767multiply infinity by zero, Calc uses another special new symbol to 6861multiply infinity by zero, Calc uses another special new symbol to
6768show that the answer is ``indeterminate.'' @xref{Infinities}, for 6862show that the answer is ``indeterminate.'' @xref{Infinities}, for
@@ -6852,7 +6946,7 @@ copied that number into a file and later moved it back into Calc.
6852@subsection Modes Tutorial Exercise 3 6946@subsection Modes Tutorial Exercise 3
6853 6947
6854@noindent 6948@noindent
6855The answer he got was @cite{0.5000000000006399}. 6949The answer he got was @expr{0.5000000000006399}.
6856 6950
6857The problem is not that the square operation is inexact, but that the 6951The problem is not that the square operation is inexact, but that the
6858sine of 45 that was already on the stack was accurate to only 12 places. 6952sine of 45 that was already on the stack was accurate to only 12 places.
@@ -6917,16 +7011,17 @@ There is no fractional form for the square root of two, so if you type
6917@noindent 7011@noindent
6918Dividing two integers that are larger than the current precision may 7012Dividing two integers that are larger than the current precision may
6919give a floating-point result that is inaccurate even when rounded 7013give a floating-point result that is inaccurate even when rounded
6920down to an integer. Consider @cite{123456789 / 2} when the current 7014down to an integer. Consider @expr{123456789 / 2} when the current
6921precision is 6 digits. The true answer is @cite{61728394.5}, but 7015precision is 6 digits. The true answer is @expr{61728394.5}, but
6922with a precision of 6 this will be rounded to @c{$12345700.0/2.0 = 61728500.0$} 7016with a precision of 6 this will be rounded to
6923@cite{12345700.@: / 2.@: = 61728500.}. 7017@texline @tmath{12345700.0/2.0 = 61728500.0}.
7018@infoline @expr{12345700.@: / 2.@: = 61728500.}.
6924The result, when converted to an integer, will be off by 106. 7019The result, when converted to an integer, will be off by 106.
6925 7020
6926Here are two solutions: Raise the precision enough that the 7021Here are two solutions: Raise the precision enough that the
6927floating-point round-off error is strictly to the right of the 7022floating-point round-off error is strictly to the right of the
6928decimal point. Or, convert to fraction mode so that @cite{123456789 / 2} 7023decimal point. Or, convert to fraction mode so that @expr{123456789 / 2}
6929produces the exact fraction @cite{123456789:2}, which can be rounded 7024produces the exact fraction @expr{123456789:2}, which can be rounded
6930down by the @kbd{F} command without ever switching to floating-point 7025down by the @kbd{F} command without ever switching to floating-point
6931format. 7026format.
6932 7027
@@ -6934,8 +7029,8 @@ format.
6934@subsection Arithmetic Tutorial Exercise 2 7029@subsection Arithmetic Tutorial Exercise 2
6935 7030
6936@noindent 7031@noindent
6937@kbd{27 @key{RET} 9 B} could give the exact result @cite{3:2}, but it 7032@kbd{27 @key{RET} 9 B} could give the exact result @expr{3:2}, but it
6938does a floating-point calculation instead and produces @cite{1.5}. 7033does a floating-point calculation instead and produces @expr{1.5}.
6939 7034
6940Calc will find an exact result for a logarithm if the result is an integer 7035Calc will find an exact result for a logarithm if the result is an integer
6941or the reciprocal of an integer. But there is no efficient way to search 7036or the reciprocal of an integer. But there is no efficient way to search
@@ -7029,14 +7124,19 @@ Type @kbd{d N} to return to ``normal'' display mode afterwards.
7029@subsection Matrix Tutorial Exercise 3 7124@subsection Matrix Tutorial Exercise 3
7030 7125
7031@noindent 7126@noindent
7032To solve @c{$A^T A \, X = A^T B$} 7127To solve
7033@cite{trn(A) * A * X = trn(A) * B}, first we compute 7128@texline @tmath{A^T A \, X = A^T B},
7034@c{$A' = A^T A$} 7129@infoline @expr{trn(A) * A * X = trn(A) * B},
7035@cite{A2 = trn(A) * A} and @c{$B' = A^T B$} 7130first we compute
7036@cite{B2 = trn(A) * B}; now, we have a 7131@texline @tmath{A' = A^T A}
7037system @c{$A' X = B'$} 7132@infoline @expr{A2 = trn(A) * A}
7038@cite{A2 * X = B2} which we can solve using Calc's @samp{/} 7133and
7039command. 7134@texline @tmath{B' = A^T B};
7135@infoline @expr{B2 = trn(A) * B};
7136now, we have a system
7137@texline @tmath{A' X = B'}
7138@infoline @expr{A2 * X = B2}
7139which we can solve using Calc's @samp{/} command.
7040 7140
7041@ifinfo 7141@ifinfo
7042@example 7142@example
@@ -7066,8 +7166,9 @@ $$
7066 7166
7067The first step is to enter the coefficient matrix. We'll store it in 7167The first step is to enter the coefficient matrix. We'll store it in
7068quick variable number 7 for later reference. Next, we compute the 7168quick variable number 7 for later reference. Next, we compute the
7069@c{$B'$} 7169@texline @tmath{B'}
7070@cite{B2} vector. 7170@infoline @expr{B2}
7171vector.
7071 7172
7072@smallexample 7173@smallexample
7073@group 7174@group
@@ -7082,8 +7183,10 @@ quick variable number 7 for later reference. Next, we compute the
7082@end smallexample 7183@end smallexample
7083 7184
7084@noindent 7185@noindent
7085Now we compute the matrix @c{$A'$} 7186Now we compute the matrix
7086@cite{A2} and divide. 7187@texline @tmath{A'}
7188@infoline @expr{A2}
7189and divide.
7087 7190
7088@smallexample 7191@smallexample
7089@group 7192@group
@@ -7101,14 +7204,18 @@ Now we compute the matrix @c{$A'$}
7101(The actual computed answer will be slightly inexact due to 7204(The actual computed answer will be slightly inexact due to
7102round-off error.) 7205round-off error.)
7103 7206
7104Notice that the answers are similar to those for the @c{$3\times3$} 7207Notice that the answers are similar to those for the
7105@asis{3x3} system 7208@texline @tmath{3\times3}
7106solved in the text. That's because the fourth equation that was 7209@infoline 3x3
7210system solved in the text. That's because the fourth equation that was
7107added to the system is almost identical to the first one multiplied 7211added to the system is almost identical to the first one multiplied
7108by two. (If it were identical, we would have gotten the exact same 7212by two. (If it were identical, we would have gotten the exact same
7109answer since the @c{$4\times3$} 7213answer since the
7110@asis{4x3} system would be equivalent to the original @c{$3\times3$} 7214@texline @tmath{4\times3}
7111@asis{3x3} 7215@infoline 4x3
7216system would be equivalent to the original
7217@texline @tmath{3\times3}
7218@infoline 3x3
7112system.) 7219system.)
7113 7220
7114Since the first and fourth equations aren't quite equivalent, they 7221Since the first and fourth equations aren't quite equivalent, they
@@ -7129,8 +7236,8 @@ the original system of equations to see how well they match.
7129@end smallexample 7236@end smallexample
7130 7237
7131@noindent 7238@noindent
7132This is reasonably close to our original @cite{B} vector, 7239This is reasonably close to our original @expr{B} vector,
7133@cite{[6, 2, 3, 11]}. 7240@expr{[6, 2, 3, 11]}.
7134 7241
7135@node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises 7242@node List Answer 1, List Answer 2, Matrix Answer 3, Answers to Exercises
7136@subsection List Tutorial Exercise 1 7243@subsection List Tutorial Exercise 1
@@ -7168,7 +7275,7 @@ vector.
7168@subsection List Tutorial Exercise 2 7275@subsection List Tutorial Exercise 2
7169 7276
7170@noindent 7277@noindent
7171Given @cite{x} and @cite{y} vectors in quick variables 1 and 2 as before, 7278Given @expr{x} and @expr{y} vectors in quick variables 1 and 2 as before,
7172the first job is to form the matrix that describes the problem. 7279the first job is to form the matrix that describes the problem.
7173 7280
7174@ifinfo 7281@ifinfo
@@ -7183,10 +7290,12 @@ $$ m \times x + b \times 1 = y $$
7183\afterdisplay 7290\afterdisplay
7184@end tex 7291@end tex
7185 7292
7186Thus we want a @c{$19\times2$} 7293Thus we want a
7187@asis{19x2} matrix with our @cite{x} vector as one column and 7294@texline @tmath{19\times2}
7295@infoline 19x2
7296matrix with our @expr{x} vector as one column and
7188ones as the other column. So, first we build the column of ones, then 7297ones as the other column. So, first we build the column of ones, then
7189we combine the two columns to form our @cite{A} matrix. 7298we combine the two columns to form our @expr{A} matrix.
7190 7299
7191@smallexample 7300@smallexample
7192@group 7301@group
@@ -7200,9 +7309,13 @@ we combine the two columns to form our @cite{A} matrix.
7200@end smallexample 7309@end smallexample
7201 7310
7202@noindent 7311@noindent
7203Now we compute @c{$A^T y$} 7312Now we compute
7204@cite{trn(A) * y} and @c{$A^T A$} 7313@texline @tmath{A^T y}
7205@cite{trn(A) * A} and divide. 7314@infoline @expr{trn(A) * y}
7315and
7316@texline @tmath{A^T A}
7317@infoline @expr{trn(A) * A}
7318and divide.
7206 7319
7207@smallexample 7320@smallexample
7208@group 7321@group
@@ -7227,10 +7340,12 @@ Now we compute @c{$A^T y$}
7227@end group 7340@end group
7228@end smallexample 7341@end smallexample
7229 7342
7230Since we were solving equations of the form @c{$m \times x + b \times 1 = y$} 7343Since we were solving equations of the form
7231@cite{m*x + b*1 = y}, these 7344@texline @tmath{m \times x + b \times 1 = y},
7232numbers should be @cite{m} and @cite{b}, respectively. Sure enough, they 7345@infoline @expr{m*x + b*1 = y},
7233agree exactly with the result computed using @kbd{V M} and @kbd{V R}! 7346these numbers should be @expr{m} and @expr{b}, respectively. Sure
7347enough, they agree exactly with the result computed using @kbd{V M} and
7348@kbd{V R}!
7234 7349
7235The moral of this story: @kbd{V M} and @kbd{V R} will probably solve 7350The moral of this story: @kbd{V M} and @kbd{V R} will probably solve
7236your problem, but there is often an easier way using the higher-level 7351your problem, but there is often an easier way using the higher-level
@@ -7288,9 +7403,10 @@ then raise the number to that power.)
7288@subsection List Tutorial Exercise 4 7403@subsection List Tutorial Exercise 4
7289 7404
7290@noindent 7405@noindent
7291A number @cite{j} is a divisor of @cite{n} if @c{$n \mathbin{\hbox{\code{\%}}} j = 0$} 7406A number @expr{j} is a divisor of @expr{n} if
7292@samp{n % j = 0}. The first 7407@texline @tmath{n \mathbin{\hbox{\code{\%}}} j = 0}.
7293step is to get a vector that identifies the divisors. 7408@infoline @samp{n % j = 0}.
7409The first step is to get a vector that identifies the divisors.
7294 7410
7295@smallexample 7411@smallexample
7296@group 7412@group
@@ -7358,10 +7474,11 @@ so that the mapping operation works; no prime factor will ever be
7358zero, so adding zeros on the left and right is safe. From then on 7474zero, so adding zeros on the left and right is safe. From then on
7359the job is pretty straightforward. 7475the job is pretty straightforward.
7360 7476
7361Incidentally, Calc provides the @c{\dfn{M\"obius} $\mu$} 7477Incidentally, Calc provides the
7362@dfn{Moebius mu} function which is 7478@texline @dfn{M@"obius} @tmath{\mu}
7363zero if and only if its argument is square-free. It would be a much 7479@infoline @dfn{Moebius mu}
7364more convenient way to do the above test in practice. 7480function which is zero if and only if its argument is square-free. It
7481would be a much more convenient way to do the above test in practice.
7365 7482
7366@node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises 7483@node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises
7367@subsection List Tutorial Exercise 6 7484@subsection List Tutorial Exercise 6
@@ -7389,10 +7506,11 @@ exercise and type @kbd{1 -} to subtract one from all the elements.
7389@end smallexample 7506@end smallexample
7390 7507
7391The numbers down the lefthand edge of the list we desire are called 7508The numbers down the lefthand edge of the list we desire are called
7392the ``triangular numbers'' (now you know why!). The @cite{n}th 7509the ``triangular numbers'' (now you know why!). The @expr{n}th
7393triangular number is the sum of the integers from 1 to @cite{n}, and 7510triangular number is the sum of the integers from 1 to @expr{n}, and
7394can be computed directly by the formula @c{$n (n+1) \over 2$} 7511can be computed directly by the formula
7395@cite{n * (n+1) / 2}. 7512@texline @tmath{n (n+1) \over 2}.
7513@infoline @expr{n * (n+1) / 2}.
7396 7514
7397@smallexample 7515@smallexample
7398@group 7516@group
@@ -7446,7 +7564,7 @@ since each element of the main vector is itself a small vector,
7446@subsection List Tutorial Exercise 8 7564@subsection List Tutorial Exercise 8
7447 7565
7448@noindent 7566@noindent
7449The first step is to build a list of values of @cite{x}. 7567The first step is to build a list of values of @expr{x}.
7450 7568
7451@smallexample 7569@smallexample
7452@group 7570@group
@@ -7486,12 +7604,13 @@ A way to isolate the maximum value is to compute the maximum using
7486 7604
7487@noindent 7605@noindent
7488It's a good idea to verify, as in the last step above, that only 7606It's a good idea to verify, as in the last step above, that only
7489one value is equal to the maximum. (After all, a plot of @c{$\sin x$} 7607one value is equal to the maximum. (After all, a plot of
7490@cite{sin(x)} 7608@texline @tmath{\sin x}
7609@infoline @expr{sin(x)}
7491might have many points all equal to the maximum value, 1.) 7610might have many points all equal to the maximum value, 1.)
7492 7611
7493The vector we have now has a single 1 in the position that indicates 7612The vector we have now has a single 1 in the position that indicates
7494the maximum value of @cite{x}. Now it is a simple matter to convert 7613the maximum value of @expr{x}. Now it is a simple matter to convert
7495this back into the corresponding value itself. 7614this back into the corresponding value itself.
7496 7615
7497@smallexample 7616@smallexample
@@ -7504,12 +7623,12 @@ this back into the corresponding value itself.
7504@end group 7623@end group
7505@end smallexample 7624@end smallexample
7506 7625
7507If @kbd{a =} had produced more than one @cite{1} value, this method 7626If @kbd{a =} had produced more than one @expr{1} value, this method
7508would have given the sum of all maximum @cite{x} values; not very 7627would have given the sum of all maximum @expr{x} values; not very
7509useful! In this case we could have used @kbd{v m} (@code{calc-mask-vector}) 7628useful! In this case we could have used @kbd{v m} (@code{calc-mask-vector})
7510instead. This command deletes all elements of a ``data'' vector that 7629instead. This command deletes all elements of a ``data'' vector that
7511correspond to zeros in a ``mask'' vector, leaving us with, in this 7630correspond to zeros in a ``mask'' vector, leaving us with, in this
7512example, a vector of maximum @cite{x} values. 7631example, a vector of maximum @expr{x} values.
7513 7632
7514The built-in @kbd{a X} command maximizes a function using more 7633The built-in @kbd{a X} command maximizes a function using more
7515efficient methods. Just for illustration, let's use @kbd{a X} 7634efficient methods. Just for illustration, let's use @kbd{a X}
@@ -7526,7 +7645,7 @@ to maximize @samp{besJ(1,x)} over this same interval.
7526@end smallexample 7645@end smallexample
7527 7646
7528@noindent 7647@noindent
7529The output from @kbd{a X} is a vector containing the value of @cite{x} 7648The output from @kbd{a X} is a vector containing the value of @expr{x}
7530that maximizes the function, and the function's value at that maximum. 7649that maximizes the function, and the function's value at that maximum.
7531As you can see, our simple search got quite close to the right answer. 7650As you can see, our simple search got quite close to the right answer.
7532 7651
@@ -7656,10 +7775,10 @@ Another way to do this final step would be to reduce the formula
7656@subsection List Tutorial Exercise 10 7775@subsection List Tutorial Exercise 10
7657 7776
7658@noindent 7777@noindent
7659For the list @cite{[a, b, c, d]}, the result is @cite{((a = b) = c) = d}, 7778For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d},
7660which will compare @cite{a} and @cite{b} to produce a 1 or 0, which is 7779which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is
7661then compared with @cite{c} to produce another 1 or 0, which is then 7780then compared with @expr{c} to produce another 1 or 0, which is then
7662compared with @cite{d}. This is not at all what Joe wanted. 7781compared with @expr{d}. This is not at all what Joe wanted.
7663 7782
7664Here's a more correct method: 7783Here's a more correct method:
7665 7784
@@ -7687,9 +7806,9 @@ Here's a more correct method:
7687@subsection List Tutorial Exercise 11 7806@subsection List Tutorial Exercise 11
7688 7807
7689@noindent 7808@noindent
7690The circle of unit radius consists of those points @cite{(x,y)} for which 7809The circle of unit radius consists of those points @expr{(x,y)} for which
7691@cite{x^2 + y^2 < 1}. We start by generating a vector of @cite{x^2} 7810@expr{x^2 + y^2 < 1}. We start by generating a vector of @expr{x^2}
7692and a vector of @cite{y^2}. 7811and a vector of @expr{y^2}.
7693 7812
7694We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} 7813We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
7695commands. 7814commands.
@@ -7715,7 +7834,7 @@ commands.
7715@end group 7834@end group
7716@end smallexample 7835@end smallexample
7717 7836
7718Now we sum the @cite{x^2} and @cite{y^2} values, compare with 1 to 7837Now we sum the @expr{x^2} and @expr{y^2} values, compare with 1 to
7719get a vector of 1/0 truth values, then sum the truth values. 7838get a vector of 1/0 truth values, then sum the truth values.
7720 7839
7721@smallexample 7840@smallexample
@@ -7728,8 +7847,7 @@ get a vector of 1/0 truth values, then sum the truth values.
7728@end smallexample 7847@end smallexample
7729 7848
7730@noindent 7849@noindent
7731The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$} 7850The ratio @expr{84/100} should approximate the ratio @cpiover{4}.
7732@cite{pi/4}.
7733 7851
7734@smallexample 7852@smallexample
7735@group 7853@group
@@ -7757,30 +7875,33 @@ return to full-sized display of vectors.
7757@noindent 7875@noindent
7758This problem can be made a lot easier by taking advantage of some 7876This problem can be made a lot easier by taking advantage of some
7759symmetries. First of all, after some thought it's clear that the 7877symmetries. First of all, after some thought it's clear that the
7760@cite{y} axis can be ignored altogether. Just pick a random @cite{x} 7878@expr{y} axis can be ignored altogether. Just pick a random @expr{x}
7761component for one end of the match, pick a random direction @c{$\theta$} 7879component for one end of the match, pick a random direction
7762@cite{theta}, 7880@texline @tmath{\theta},
7763and see if @cite{x} and @c{$x + \cos \theta$} 7881@infoline @expr{theta},
7764@cite{x + cos(theta)} (which is the @cite{x} 7882and see if @expr{x} and
7765coordinate of the other endpoint) cross a line. The lines are at 7883@texline @tmath{x + \cos \theta}
7766integer coordinates, so this happens when the two numbers surround 7884@infoline @expr{x + cos(theta)}
7767an integer. 7885(which is the @expr{x} coordinate of the other endpoint) cross a line.
7886The lines are at integer coordinates, so this happens when the two
7887numbers surround an integer.
7768 7888
7769Since the two endpoints are equivalent, we may as well choose the leftmost 7889Since the two endpoints are equivalent, we may as well choose the leftmost
7770of the two endpoints as @cite{x}. Then @cite{theta} is an angle pointing 7890of the two endpoints as @expr{x}. Then @expr{theta} is an angle pointing
7771to the right, in the range -90 to 90 degrees. (We could use radians, but 7891to the right, in the range -90 to 90 degrees. (We could use radians, but
7772it would feel like cheating to refer to @c{$\pi/2$} 7892it would feel like cheating to refer to @cpiover{2} radians while trying
7773@cite{pi/2} radians while trying 7893to estimate @cpi{}!)
7774to estimate @c{$\pi$}
7775@cite{pi}!)
7776 7894
7777In fact, since the field of lines is infinite we can choose the 7895In fact, since the field of lines is infinite we can choose the
7778coordinates 0 and 1 for the lines on either side of the leftmost 7896coordinates 0 and 1 for the lines on either side of the leftmost
7779endpoint. The rightmost endpoint will be between 0 and 1 if the 7897endpoint. The rightmost endpoint will be between 0 and 1 if the
7780match does not cross a line, or between 1 and 2 if it does. So: 7898match does not cross a line, or between 1 and 2 if it does. So:
7781Pick random @cite{x} and @c{$\theta$} 7899Pick random @expr{x} and
7782@cite{theta}, compute @c{$x + \cos \theta$} 7900@texline @tmath{\theta},
7783@cite{x + cos(theta)}, 7901@infoline @expr{theta},
7902compute
7903@texline @tmath{x + \cos \theta},
7904@infoline @expr{x + cos(theta)},
7784and count how many of the results are greater than one. Simple! 7905and count how many of the results are greater than one. Simple!
7785 7906
7786We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} 7907We can make this go a bit faster by using the @kbd{v .} and @kbd{t .}
@@ -7881,8 +8002,8 @@ we omitted the closing @kbd{"}. (The same goes for all closing delimiters
7881like @kbd{)} and @kbd{]} at the end of a formula. 8002like @kbd{)} and @kbd{]} at the end of a formula.
7882 8003
7883We'll show two different approaches here. In the first, we note that 8004We'll show two different approaches here. In the first, we note that
7884if the input vector is @cite{[a, b, c, d]}, then the hash code is 8005if the input vector is @expr{[a, b, c, d]}, then the hash code is
7885@cite{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}. In other words, 8006@expr{3 (3 (3a + b) + c) + d = 27a + 9b + 3c + d}. In other words,
7886it's a sum of descending powers of three times the ASCII codes. 8007it's a sum of descending powers of three times the ASCII codes.
7887 8008
7888@smallexample 8009@smallexample
@@ -7944,7 +8065,7 @@ the operations are faster.
7944@end smallexample 8065@end smallexample
7945 8066
7946Why does this work? Think about a two-step computation: 8067Why does this work? Think about a two-step computation:
7947@w{@cite{3 (3a + b) + c}}. Taking a result modulo 511 basically means 8068@w{@expr{3 (3a + b) + c}}. Taking a result modulo 511 basically means
7948subtracting off enough 511's to put the result in the desired range. 8069subtracting off enough 511's to put the result in the desired range.
7949So the result when we take the modulo after every step is, 8070So the result when we take the modulo after every step is,
7950 8071
@@ -7961,7 +8082,7 @@ $$ 3 (3 a + b - 511 m) + c - 511 n $$
7961@end tex 8082@end tex
7962 8083
7963@noindent 8084@noindent
7964for some suitable integers @cite{m} and @cite{n}. Expanding out by 8085for some suitable integers @expr{m} and @expr{n}. Expanding out by
7965the distributive law yields 8086the distributive law yields
7966 8087
7967@ifinfo 8088@ifinfo
@@ -7977,10 +8098,10 @@ $$ 9 a + 3 b + c - 511\times3 m - 511 n $$
7977@end tex 8098@end tex
7978 8099
7979@noindent 8100@noindent
7980The @cite{m} term in the latter formula is redundant because any 8101The @expr{m} term in the latter formula is redundant because any
7981contribution it makes could just as easily be made by the @cite{n} 8102contribution it makes could just as easily be made by the @expr{n}
7982term. So we can take it out to get an equivalent formula with 8103term. So we can take it out to get an equivalent formula with
7983@cite{n' = 3m + n}, 8104@expr{n' = 3m + n},
7984 8105
7985@ifinfo 8106@ifinfo
7986@example 8107@example
@@ -8006,7 +8127,7 @@ modulo some value @var{m}.
8006@subsection List Tutorial Exercise 14 8127@subsection List Tutorial Exercise 14
8007 8128
8008We want to use @kbd{H V U} to nest a function which adds a random 8129We want to use @kbd{H V U} to nest a function which adds a random
8009step to an @cite{(x,y)} coordinate. The function is a bit long, but 8130step to an @expr{(x,y)} coordinate. The function is a bit long, but
8010otherwise the problem is quite straightforward. 8131otherwise the problem is quite straightforward.
8011 8132
8012@smallexample 8133@smallexample
@@ -8024,9 +8145,9 @@ Just as the text recommended, we used @samp{< >} nameless function
8024notation to keep the two @code{random} calls from being evaluated 8145notation to keep the two @code{random} calls from being evaluated
8025before nesting even begins. 8146before nesting even begins.
8026 8147
8027We now have a vector of @cite{[x, y]} sub-vectors, which by Calc's 8148We now have a vector of @expr{[x, y]} sub-vectors, which by Calc's
8028rules acts like a matrix. We can transpose this matrix and unpack 8149rules acts like a matrix. We can transpose this matrix and unpack
8029to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing. 8150to get a pair of vectors, @expr{x} and @expr{y}, suitable for graphing.
8030 8151
8031@smallexample 8152@smallexample
8032@group 8153@group
@@ -8038,12 +8159,12 @@ to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing.
8038@end group 8159@end group
8039@end smallexample 8160@end smallexample
8040 8161
8041Incidentally, because the @cite{x} and @cite{y} are completely 8162Incidentally, because the @expr{x} and @expr{y} are completely
8042independent in this case, we could have done two separate commands 8163independent in this case, we could have done two separate commands
8043to create our @cite{x} and @cite{y} vectors of numbers directly. 8164to create our @expr{x} and @expr{y} vectors of numbers directly.
8044 8165
8045To make a random walk of unit steps, we note that @code{sincos} of 8166To make a random walk of unit steps, we note that @code{sincos} of
8046a random direction exactly gives us an @cite{[x, y]} step of unit 8167a random direction exactly gives us an @expr{[x, y]} step of unit
8047length; in fact, the new nesting function is even briefer, though 8168length; in fact, the new nesting function is even briefer, though
8048we might want to lower the precision a bit for it. 8169we might want to lower the precision a bit for it.
8049 8170
@@ -8071,10 +8192,8 @@ Schwartz.)
8071@subsection Types Tutorial Exercise 1 8192@subsection Types Tutorial Exercise 1
8072 8193
8073@noindent 8194@noindent
8074If the number is the square root of @c{$\pi$} 8195If the number is the square root of @cpi{} times a rational number,
8075@cite{pi} times a rational number, 8196then its square, divided by @cpi{}, should be a rational number.
8076then its square, divided by @c{$\pi$}
8077@cite{pi}, should be a rational number.
8078 8197
8079@smallexample 8198@smallexample
8080@group 8199@group
@@ -8106,8 +8225,8 @@ precision slightly and try again:
8106@noindent 8225@noindent
8107Aha! It's unlikely that an irrational number would equal a fraction 8226Aha! It's unlikely that an irrational number would equal a fraction
8108this simple to within ten digits, so our original number was probably 8227this simple to within ten digits, so our original number was probably
8109@c{$\sqrt{27 \pi / 53}$} 8228@texline @tmath{\sqrt{27 \pi / 53}}.
8110@cite{sqrt(27 pi / 53)}. 8229@infoline @expr{sqrt(27 pi / 53)}.
8111 8230
8112Notice that we didn't need to re-round the number when we reduced the 8231Notice that we didn't need to re-round the number when we reduced the
8113precision. Remember, arithmetic operations always round their inputs 8232precision. Remember, arithmetic operations always round their inputs
@@ -8123,17 +8242,17 @@ But if @w{@samp{17 inf = inf}}, then @samp{17 inf / inf = inf / inf = 17}, too.
8123@samp{exp(inf) = inf}. It's tempting to say that the exponential 8242@samp{exp(inf) = inf}. It's tempting to say that the exponential
8124of infinity must be ``bigger'' than ``regular'' infinity, but as 8243of infinity must be ``bigger'' than ``regular'' infinity, but as
8125far as Calc is concerned all infinities are as just as big. 8244far as Calc is concerned all infinities are as just as big.
8126In other words, as @cite{x} goes to infinity, @cite{e^x} also goes 8245In other words, as @expr{x} goes to infinity, @expr{e^x} also goes
8127to infinity, but the fact the @cite{e^x} grows much faster than 8246to infinity, but the fact the @expr{e^x} grows much faster than
8128@cite{x} is not relevant here. 8247@expr{x} is not relevant here.
8129 8248
8130@samp{exp(-inf) = 0}. Here we have a finite answer even though 8249@samp{exp(-inf) = 0}. Here we have a finite answer even though
8131the input is infinite. 8250the input is infinite.
8132 8251
8133@samp{sqrt(-inf) = (0, 1) inf}. Remember that @cite{(0, 1)} 8252@samp{sqrt(-inf) = (0, 1) inf}. Remember that @expr{(0, 1)}
8134represents the imaginary number @cite{i}. Here's a derivation: 8253represents the imaginary number @expr{i}. Here's a derivation:
8135@samp{sqrt(-inf) = @w{sqrt((-1) * inf)} = sqrt(-1) * sqrt(inf)}. 8254@samp{sqrt(-inf) = @w{sqrt((-1) * inf)} = sqrt(-1) * sqrt(inf)}.
8136The first part is, by definition, @cite{i}; the second is @code{inf} 8255The first part is, by definition, @expr{i}; the second is @code{inf}
8137because, once again, all infinities are the same size. 8256because, once again, all infinities are the same size.
8138 8257
8139@samp{sqrt(uinf) = uinf}. In fact, we do know something about the 8258@samp{sqrt(uinf) = uinf}. In fact, we do know something about the
@@ -8141,11 +8260,11 @@ direction because @code{sqrt} is defined to return a value in the
8141right half of the complex plane. But Calc has no notation for this, 8260right half of the complex plane. But Calc has no notation for this,
8142so it settles for the conservative answer @code{uinf}. 8261so it settles for the conservative answer @code{uinf}.
8143 8262
8144@samp{abs(uinf) = inf}. No matter which direction @cite{x} points, 8263@samp{abs(uinf) = inf}. No matter which direction @expr{x} points,
8145@samp{abs(x)} always points along the positive real axis. 8264@samp{abs(x)} always points along the positive real axis.
8146 8265
8147@samp{ln(0) = -inf}. Here we have an infinite answer to a finite 8266@samp{ln(0) = -inf}. Here we have an infinite answer to a finite
8148input. As in the @cite{1 / 0} case, Calc will only use infinities 8267input. As in the @expr{1 / 0} case, Calc will only use infinities
8149here if you have turned on ``infinite'' mode. Otherwise, it will 8268here if you have turned on ``infinite'' mode. Otherwise, it will
8150treat @samp{ln(0)} as an error. 8269treat @samp{ln(0)} as an error.
8151 8270
@@ -8154,9 +8273,9 @@ treat @samp{ln(0)} as an error.
8154 8273
8155@noindent 8274@noindent
8156We can make @samp{inf - inf} be any real number we like, say, 8275We can make @samp{inf - inf} be any real number we like, say,
8157@cite{a}, just by claiming that we added @cite{a} to the first 8276@expr{a}, just by claiming that we added @expr{a} to the first
8158infinity but not to the second. This is just as true for complex 8277infinity but not to the second. This is just as true for complex
8159values of @cite{a}, so @code{nan} can stand for a complex number. 8278values of @expr{a}, so @code{nan} can stand for a complex number.
8160(And, similarly, @code{uinf} can stand for an infinity that points 8279(And, similarly, @code{uinf} can stand for an infinity that points
8161in any direction in the complex plane, such as @samp{(0, 1) inf}). 8280in any direction in the complex plane, such as @samp{(0, 1) inf}).
8162 8281
@@ -8403,7 +8522,7 @@ The same issue arises when you try to square an error form.
8403@subsection Types Tutorial Exercise 10 8522@subsection Types Tutorial Exercise 10
8404 8523
8405@noindent 8524@noindent
8406Testing the first number, we might arbitrarily choose 17 for @cite{x}. 8525Testing the first number, we might arbitrarily choose 17 for @expr{x}.
8407 8526
8408@smallexample 8527@smallexample
8409@group 8528@group
@@ -8435,7 +8554,7 @@ use this method to test the second number.
8435@end smallexample 8554@end smallexample
8436 8555
8437@noindent 8556@noindent
8438The result is three ones (modulo @cite{n}), so it's very probable that 8557The result is three ones (modulo @expr{n}), so it's very probable that
843915485863 is prime. (In fact, this number is the millionth prime.) 855815485863 is prime. (In fact, this number is the millionth prime.)
8440 8559
8441Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $} 8560Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $}
@@ -8604,20 +8723,20 @@ Thus Sam can take up to 14 pills without a worry.
8604 8723
8605@noindent 8724@noindent
8606@c [fix-ref Declarations] 8725@c [fix-ref Declarations]
8607The result @samp{sqrt(x)^2} is simplified back to @cite{x} by the 8726The result @samp{sqrt(x)^2} is simplified back to @expr{x} by the
8608Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens 8727Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens
8609if @w{@cite{x = -4}}.) If @cite{x} is real, this formula could be 8728if @w{@expr{x = -4}}.) If @expr{x} is real, this formula could be
8610simplified to @samp{abs(x)}, but for general complex arguments even 8729simplified to @samp{abs(x)}, but for general complex arguments even
8611that is not safe. (@xref{Declarations}, for a way to tell Calc 8730that is not safe. (@xref{Declarations}, for a way to tell Calc
8612that @cite{x} is known to be real.) 8731that @expr{x} is known to be real.)
8613 8732
8614@node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to Exercises 8733@node Algebra Answer 2, Algebra Answer 3, Algebra Answer 1, Answers to Exercises
8615@subsection Algebra Tutorial Exercise 2 8734@subsection Algebra Tutorial Exercise 2
8616 8735
8617@noindent 8736@noindent
8618Suppose our roots are @cite{[a, b, c]}. We want a polynomial which 8737Suppose our roots are @expr{[a, b, c]}. We want a polynomial which
8619is zero when @cite{x} is any of these values. The trivial polynomial 8738is zero when @expr{x} is any of these values. The trivial polynomial
8620@cite{x-a} is zero when @cite{x=a}, so the product @cite{(x-a)(x-b)(x-c)} 8739@expr{x-a} is zero when @expr{x=a}, so the product @expr{(x-a)(x-b)(x-c)}
8621will do the job. We can use @kbd{a c x} to write this in a more 8740will do the job. We can use @kbd{a c x} to write this in a more
8622familiar form. 8741familiar form.
8623 8742
@@ -8808,7 +8927,7 @@ We'll use Big mode to make the formulas more readable.
8808@end smallexample 8927@end smallexample
8809 8928
8810@noindent 8929@noindent
8811Multiplying by the conjugate helps because @cite{(a+b) (a-b) = a^2 - b^2}. 8930Multiplying by the conjugate helps because @expr{(a+b) (a-b) = a^2 - b^2}.
8812 8931
8813@smallexample 8932@smallexample
8814@group 8933@group
@@ -8858,11 +8977,11 @@ The first rule turns a one-argument @code{fib} that people like to write
8858into a three-argument @code{fib} that makes computation easier. The 8977into a three-argument @code{fib} that makes computation easier. The
8859second rule converts back from three-argument form once the computation 8978second rule converts back from three-argument form once the computation
8860is done. The third rule does the computation itself. It basically 8979is done. The third rule does the computation itself. It basically
8861says that if @cite{x} and @cite{y} are two consecutive Fibonacci numbers, 8980says that if @expr{x} and @expr{y} are two consecutive Fibonacci numbers,
8862then @cite{y} and @cite{x+y} are the next (overlapping) pair of Fibonacci 8981then @expr{y} and @expr{x+y} are the next (overlapping) pair of Fibonacci
8863numbers. 8982numbers.
8864 8983
8865Notice that because the number @cite{n} was ``validated'' by the 8984Notice that because the number @expr{n} was ``validated'' by the
8866conditions on the first rule, there is no need to put conditions on 8985conditions on the first rule, there is no need to put conditions on
8867the other rules because the rule set would never get that far unless 8986the other rules because the rule set would never get that far unless
8868the input were valid. That further speeds computation, since no 8987the input were valid. That further speeds computation, since no
@@ -8959,8 +9078,8 @@ The change to return a vector is quite simple:
8959@noindent 9078@noindent
8960Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. 9079Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
8961 9080
8962Notice that the @cite{n > 1} guard is no longer necessary on the last 9081Notice that the @expr{n > 1} guard is no longer necessary on the last
8963rule since the @cite{n = 1} case is now detected by another rule. 9082rule since the @expr{n = 1} case is now detected by another rule.
8964But a guard has been added to the initial rule to make sure the 9083But a guard has been added to the initial rule to make sure the
8965initial value is suitable before the computation begins. 9084initial value is suitable before the computation begins.
8966 9085
@@ -8978,8 +9097,8 @@ apply and the rewrites will stop right away.
8978@starindex 9097@starindex
8979@end ignore 9098@end ignore
8980@tindex nterms 9099@tindex nterms
8981If @cite{x} is the sum @cite{a + b}, then `@t{nterms(}@var{x}@t{)}' must 9100If @expr{x} is the sum @expr{a + b}, then `@t{nterms(}@var{x}@t{)}' must
8982be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @cite{x} 9101be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @expr{x}
8983is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1. 9102is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1.
8984 9103
8985@smallexample 9104@smallexample
@@ -9026,7 +9145,7 @@ But then:
9026Perhaps more surprisingly, this rule still works with infinite mode 9145Perhaps more surprisingly, this rule still works with infinite mode
9027turned on. Calc tries @code{EvalRules} before any built-in rules for 9146turned on. Calc tries @code{EvalRules} before any built-in rules for
9028a function. This allows you to override the default behavior of any 9147a function. This allows you to override the default behavior of any
9029Calc feature: Even though Calc now wants to evaluate @cite{0^0} to 9148Calc feature: Even though Calc now wants to evaluate @expr{0^0} to
9030@code{nan}, your rule gets there first and evaluates it to 1 instead. 9149@code{nan}, your rule gets there first and evaluates it to 1 instead.
9031 9150
9032Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}. 9151Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.
@@ -9085,7 +9204,7 @@ The sixth rule is the corresponding rule for products of two O's.
9085Another way to solve this problem would be to create a new ``data type'' 9204Another way to solve this problem would be to create a new ``data type''
9086that represents truncated power series. We might represent these as 9205that represents truncated power series. We might represent these as
9087function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is 9206function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is
9088a vector of coefficients for @cite{x^0}, @cite{x^1}, @cite{x^2}, and so 9207a vector of coefficients for @expr{x^0}, @expr{x^1}, @expr{x^2}, and so
9089on. Rules would exist for sums and products of such @code{series} 9208on. Rules would exist for sums and products of such @code{series}
9090objects, and as an optional convenience could also know how to combine a 9209objects, and as an optional convenience could also know how to combine a
9091@code{series} object with a normal polynomial. (With this, and with a 9210@code{series} object with a normal polynomial. (With this, and with a
@@ -9115,7 +9234,7 @@ in Lisp.)
9115Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type 9234Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type
9116@kbd{Z F}, and answer the questions. Since this formula contains two 9235@kbd{Z F}, and answer the questions. Since this formula contains two
9117variables, the default argument list will be @samp{(t x)}. We want to 9236variables, the default argument list will be @samp{(t x)}. We want to
9118change this to @samp{(x)} since @cite{t} is really a dummy variable 9237change this to @samp{(x)} since @expr{t} is really a dummy variable
9119to be used within @code{ninteg}. 9238to be used within @code{ninteg}.
9120 9239
9121The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}. 9240The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}.
@@ -9146,8 +9265,9 @@ Each of these functions can be computed using the stack, or using
9146algebraic entry, whichever way you prefer: 9265algebraic entry, whichever way you prefer:
9147 9266
9148@noindent 9267@noindent
9149Computing @c{$\displaystyle{\sin x \over x}$} 9268Computing
9150@cite{sin(x) / x}: 9269@texline @tmath{\displaystyle{\sin x \over x}}:
9270@infoline @expr{sin(x) / x}:
9151 9271
9152Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. 9272Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}.
9153 9273
@@ -9207,8 +9327,8 @@ Here is the matrix:
9207@end example 9327@end example
9208 9328
9209@noindent 9329@noindent
9210Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @cite{n+1} 9330Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @expr{n+1}
9211and @cite{n+2}. Here's one program that does the job: 9331and @expr{n+2}. Here's one program that does the job:
9212 9332
9213@example 9333@example
9214C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x ) 9334C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x )
@@ -9216,8 +9336,9 @@ C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x )
9216 9336
9217@noindent 9337@noindent
9218This program is quite efficient because Calc knows how to raise a 9338This program is quite efficient because Calc knows how to raise a
9219matrix (or other value) to the power @cite{n} in only @c{$\log_2 n$} 9339matrix (or other value) to the power @expr{n} in only
9220@cite{log(n,2)} 9340@texline @tmath{\log_2 n}
9341@infoline @expr{log(n,2)}
9221steps. For example, this program can compute the 1000th Fibonacci 9342steps. For example, this program can compute the 1000th Fibonacci
9222number (a 209-digit integer!) in about 10 steps; even though the 9343number (a 209-digit integer!) in about 10 steps; even though the
9223@kbd{Z < ... Z >} solution had much simpler steps, it would have 9344@kbd{Z < ... Z >} solution had much simpler steps, it would have
@@ -9268,9 +9389,10 @@ harmonic number is 4.02.
9268@subsection Programming Tutorial Exercise 8 9389@subsection Programming Tutorial Exercise 8
9269 9390
9270@noindent 9391@noindent
9271The first step is to compute the derivative @cite{f'(x)} and thus 9392The first step is to compute the derivative @expr{f'(x)} and thus
9272the formula @c{$\displaystyle{x - {f(x) \over f'(x)}}$} 9393the formula
9273@cite{x - f(x)/f'(x)}. 9394@texline @tmath{\displaystyle{x - {f(x) \over f'(x)}}}.
9395@infoline @expr{x - f(x)/f'(x)}.
9274 9396
9275(Because this definition is long, it will be repeated in concise form 9397(Because this definition is long, it will be repeated in concise form
9276below. You can use @w{@kbd{M-# m}} to load it from there. While you are 9398below. You can use @w{@kbd{M-# m}} to load it from there. While you are
@@ -9317,7 +9439,7 @@ repetitions are done.)
9317@end group 9439@end group
9318@end smallexample 9440@end smallexample
9319 9441
9320This is the new guess for @cite{x}. Now we compare it with the 9442This is the new guess for @expr{x}. Now we compare it with the
9321old one to see if we've converged. 9443old one to see if we've converged.
9322 9444
9323@smallexample 9445@smallexample
@@ -9383,13 +9505,16 @@ method (among others) to look for numerical solutions to any equation.
9383@subsection Programming Tutorial Exercise 9 9505@subsection Programming Tutorial Exercise 9
9384 9506
9385@noindent 9507@noindent
9386The first step is to adjust @cite{z} to be greater than 5. A simple 9508The first step is to adjust @expr{z} to be greater than 5. A simple
9387``for'' loop will do the job here. If @cite{z} is less than 5, we 9509``for'' loop will do the job here. If @expr{z} is less than 5, we
9388reduce the problem using @c{$\psi(z) = \psi(z+1) - 1/z$} 9510reduce the problem using
9389@cite{psi(z) = psi(z+1) - 1/z}. We go 9511@texline @tmath{\psi(z) = \psi(z+1) - 1/z}.
9390on to compute @c{$\psi(z+1)$} 9512@infoline @expr{psi(z) = psi(z+1) - 1/z}. We go
9391@cite{psi(z+1)}, and remember to add back a factor of 9513on to compute
9392@cite{-1/z} when we're done. This step is repeated until @cite{z > 5}. 9514@texline @tmath{\psi(z+1)},
9515@infoline @expr{psi(z+1)},
9516and remember to add back a factor of @expr{-1/z} when we're done. This
9517step is repeated until @expr{z > 5}.
9393 9518
9394(Because this definition is long, it will be repeated in concise form 9519(Because this definition is long, it will be repeated in concise form
9395below. You can use @w{@kbd{M-# m}} to load it from there. While you are 9520below. You can use @w{@kbd{M-# m}} to load it from there. While you are
@@ -9407,8 +9532,8 @@ just for purposes of illustration.)
9407@end group 9532@end group
9408@end smallexample 9533@end smallexample
9409 9534
9410Here, variable 1 holds @cite{z} and variable 2 holds the adjustment 9535Here, variable 1 holds @expr{z} and variable 2 holds the adjustment
9411factor. If @cite{z < 5}, we use a loop to increase it. 9536factor. If @expr{z < 5}, we use a loop to increase it.
9412 9537
9413(By the way, we started with @samp{1.0} instead of the integer 1 because 9538(By the way, we started with @samp{1.0} instead of the integer 1 because
9414otherwise the calculation below will try to do exact fractional arithmetic, 9539otherwise the calculation below will try to do exact fractional arithmetic,
@@ -9426,8 +9551,9 @@ are exactly equal, not just equal to within the current precision.)
9426@end group 9551@end group
9427@end smallexample 9552@end smallexample
9428 9553
9429Now we compute the initial part of the sum: @c{$\ln z - {1 \over 2z}$} 9554Now we compute the initial part of the sum:
9430@cite{ln(z) - 1/2z} 9555@texline @tmath{\ln z - {1 \over 2z}}
9556@infoline @expr{ln(z) - 1/2z}
9431minus the adjustment factor. 9557minus the adjustment factor.
9432 9558
9433@smallexample 9559@smallexample
@@ -9441,7 +9567,7 @@ minus the adjustment factor.
9441@end smallexample 9567@end smallexample
9442 9568
9443Now we evaluate the series. We'll use another ``for'' loop counting 9569Now we evaluate the series. We'll use another ``for'' loop counting
9444up the value of @cite{2 n}. (Calc does have a summation command, 9570up the value of @expr{2 n}. (Calc does have a summation command,
9445@kbd{a +}, but we'll use loops just to get more practice with them.) 9571@kbd{a +}, but we'll use loops just to get more practice with them.)
9446 9572
9447@smallexample 9573@smallexample
@@ -9468,9 +9594,11 @@ up the value of @cite{2 n}. (Calc does have a summation command,
9468@end group 9594@end group
9469@end smallexample 9595@end smallexample
9470 9596
9471This is the value of @c{$-\gamma$} 9597This is the value of
9472@cite{- gamma}, with a slight bit of roundoff error. 9598@texline @tmath{-\gamma},
9473To get a full 12 digits, let's use a higher precision: 9599@infoline @expr{- gamma},
9600with a slight bit of roundoff error. To get a full 12 digits, let's use
9601a higher precision:
9474 9602
9475@smallexample 9603@smallexample
9476@group 9604@group
@@ -9500,12 +9628,14 @@ C-x )
9500@subsection Programming Tutorial Exercise 10 9628@subsection Programming Tutorial Exercise 10
9501 9629
9502@noindent 9630@noindent
9503Taking the derivative of a term of the form @cite{x^n} will produce 9631Taking the derivative of a term of the form @expr{x^n} will produce
9504a term like @c{$n x^{n-1}$} 9632a term like
9505@cite{n x^(n-1)}. Taking the derivative of a constant 9633@texline @tmath{n x^{n-1}}.
9506produces zero. From this it is easy to see that the @cite{n}th 9634@infoline @expr{n x^(n-1)}.
9507derivative of a polynomial, evaluated at @cite{x = 0}, will equal the 9635Taking the derivative of a constant
9508coefficient on the @cite{x^n} term times @cite{n!}. 9636produces zero. From this it is easy to see that the @expr{n}th
9637derivative of a polynomial, evaluated at @expr{x = 0}, will equal the
9638coefficient on the @expr{x^n} term times @expr{n!}.
9509 9639
9510(Because this definition is long, it will be repeated in concise form 9640(Because this definition is long, it will be repeated in concise form
9511below. You can use @w{@kbd{M-# m}} to load it from there. While you are 9641below. You can use @w{@kbd{M-# m}} to load it from there. While you are
@@ -9554,7 +9684,7 @@ have written instead, @kbd{r 1 @key{TAB} | t 1}.
9554@end smallexample 9684@end smallexample
9555 9685
9556To convert back, a simple method is just to map the coefficients 9686To convert back, a simple method is just to map the coefficients
9557against a table of powers of @cite{x}. 9687against a table of powers of @expr{x}.
9558 9688
9559@smallexample 9689@smallexample
9560@group 9690@group
@@ -9614,7 +9744,7 @@ sure the stack comes out right.
9614The last step replaces the 2 that was eaten during the creation 9744The last step replaces the 2 that was eaten during the creation
9615of the dummy @kbd{z s} command. Now we move on to the real 9745of the dummy @kbd{z s} command. Now we move on to the real
9616definition. The recurrence needs to be rewritten slightly, 9746definition. The recurrence needs to be rewritten slightly,
9617to the form @cite{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}. 9747to the form @expr{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}.
9618 9748
9619(Because this definition is long, it will be repeated in concise form 9749(Because this definition is long, it will be repeated in concise form
9620below. You can use @kbd{M-# m} to load it from there.) 9750below. You can use @kbd{M-# m} to load it from there.)
@@ -9783,7 +9913,7 @@ list of the results of all calculations that have been done. The
9783Calc Trail buffer uses a variant of Calc Mode, so Calculator commands 9913Calc Trail buffer uses a variant of Calc Mode, so Calculator commands
9784still work when the trail buffer's window is selected. It is possible 9914still work when the trail buffer's window is selected. It is possible
9785to turn the trail window off, but the @samp{*Calc Trail*} buffer itself 9915to turn the trail window off, but the @samp{*Calc Trail*} buffer itself
9786still exists and is updated silently. @xref{Trail Commands}.@refill 9916still exists and is updated silently. @xref{Trail Commands}.
9787 9917
9788@kindex M-# c 9918@kindex M-# c
9789@kindex M-# M-# 9919@kindex M-# M-#
@@ -9805,7 +9935,7 @@ for some commands this is the only form. As a convenience, the @kbd{x}
9805key (@code{calc-execute-extended-command}) 9935key (@code{calc-execute-extended-command})
9806is like @kbd{M-x} except that it enters the initial string @samp{calc-} 9936is like @kbd{M-x} except that it enters the initial string @samp{calc-}
9807for you. For example, the following key sequences are equivalent: 9937for you. For example, the following key sequences are equivalent:
9808@kbd{S}, @kbd{M-x calc-sin @key{RET}}, @kbd{x sin @key{RET}}.@refill 9938@kbd{S}, @kbd{M-x calc-sin @key{RET}}, @kbd{x sin @key{RET}}.
9809 9939
9810@cindex Extensions module 9940@cindex Extensions module
9811@cindex @file{calc-ext} module 9941@cindex @file{calc-ext} module
@@ -9818,14 +9948,14 @@ of the Calculator in the common case when all you need to do is a
9818little arithmetic. If for some reason the Calculator fails to load an 9948little arithmetic. If for some reason the Calculator fails to load an
9819extension module automatically, you can force it to load all the 9949extension module automatically, you can force it to load all the
9820extensions by using the @kbd{M-# L} (@code{calc-load-everything}) 9950extensions by using the @kbd{M-# L} (@code{calc-load-everything})
9821command. @xref{Mode Settings}.@refill 9951command. @xref{Mode Settings}.
9822 9952
9823If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument, 9953If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument,
9824the Calculator is loaded if necessary, but it is not actually started. 9954the Calculator is loaded if necessary, but it is not actually started.
9825If the argument is positive, the @file{calc-ext} extensions are also 9955If the argument is positive, the @file{calc-ext} extensions are also
9826loaded if necessary. User-written Lisp code that wishes to make use 9956loaded if necessary. User-written Lisp code that wishes to make use
9827of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)} 9957of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)}
9828to auto-load the Calculator.@refill 9958to auto-load the Calculator.
9829 9959
9830@kindex M-# b 9960@kindex M-# b
9831@pindex full-calc 9961@pindex full-calc
@@ -9872,7 +10002,7 @@ If you type @kbd{M-x calc} again, the Calculator will reappear with the
9872contents of the stack intact. Typing @kbd{M-# c} or @kbd{M-# M-#} 10002contents of the stack intact. Typing @kbd{M-# c} or @kbd{M-# M-#}
9873again from inside the Calculator buffer is equivalent to executing 10003again from inside the Calculator buffer is equivalent to executing
9874@code{calc-quit}; you can think of @kbd{M-# M-#} as toggling the 10004@code{calc-quit}; you can think of @kbd{M-# M-#} as toggling the
9875Calculator on and off.@refill 10005Calculator on and off.
9876 10006
9877@kindex M-# x 10007@kindex M-# x
9878The @kbd{M-# x} command also turns the Calculator off, no matter which 10008The @kbd{M-# x} command also turns the Calculator off, no matter which
@@ -9904,7 +10034,7 @@ The @kbd{<} and @kbd{>} keys are bound to @code{calc-scroll-left} and
9904@code{calc-scroll-right}. These are just like the normal horizontal 10034@code{calc-scroll-right}. These are just like the normal horizontal
9905scrolling commands except that they scroll one half-screen at a time by 10035scrolling commands except that they scroll one half-screen at a time by
9906default. (Calc formats its output to fit within the bounds of the 10036default. (Calc formats its output to fit within the bounds of the
9907window whenever it can.)@refill 10037window whenever it can.)
9908 10038
9909@kindex @{ 10039@kindex @{
9910@kindex @} 10040@kindex @}
@@ -9913,7 +10043,7 @@ window whenever it can.)@refill
9913@cindex Vertical scrolling 10043@cindex Vertical scrolling
9914The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down} 10044The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down}
9915and @code{calc-scroll-up}. They scroll up or down by one-half the 10045and @code{calc-scroll-up}. They scroll up or down by one-half the
9916height of the Calc window.@refill 10046height of the Calc window.
9917 10047
9918@kindex M-# 0 10048@kindex M-# 0
9919@pindex calc-reset 10049@pindex calc-reset
@@ -10017,7 +10147,7 @@ H a S runs calc-solve-for: a `H a S' v => fsolve(a,v) (?=notes)
10017 10147
10018@noindent 10148@noindent
10019which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for} 10149which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for}
10020takes a value @cite{a} from the stack, prompts for a value @cite{v}, 10150takes a value @expr{a} from the stack, prompts for a value @expr{v},
10021then applies the algebraic function @code{fsolve} to these values. 10151then applies the algebraic function @code{fsolve} to these values.
10022The @samp{?=notes} message means you can now type @kbd{?} to see 10152The @samp{?=notes} message means you can now type @kbd{?} to see
10023additional notes from the summary that apply to this command. 10153additional notes from the summary that apply to this command.
@@ -10074,7 +10204,7 @@ The first three keystrokes ``push'' the numbers 1 and 2 onto the stack. The
10074@kbd{+} key always ``pops'' the top two numbers from the stack, adds them, 10204@kbd{+} key always ``pops'' the top two numbers from the stack, adds them,
10075and pushes the result (3) back onto the stack. This number is ready for 10205and pushes the result (3) back onto the stack. This number is ready for
10076further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the 10206further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the
100773 and 5, subtracts them, and pushes the result (@i{-2}).@refill 102073 and 5, subtracts them, and pushes the result (@i{-2}).
10078 10208
10079Note that the ``top'' of the stack actually appears at the @emph{bottom} 10209Note that the ``top'' of the stack actually appears at the @emph{bottom}
10080of the buffer. A line containing a single @samp{.} character signifies 10210of the buffer. A line containing a single @samp{.} character signifies
@@ -10103,12 +10233,12 @@ two consecutive numbers.
10103(After all, if you typed @kbd{1 2} by themselves the Calculator 10233(After all, if you typed @kbd{1 2} by themselves the Calculator
10104would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not} 10234would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not}
10105right after typing a number, the key duplicates the number on the top of 10235right after typing a number, the key duplicates the number on the top of
10106the stack. @kbd{@key{RET} *} is thus a handy way to square a number.@refill 10236the stack. @kbd{@key{RET} *} is thus a handy way to square a number.
10107 10237
10108The @key{DEL} key pops and throws away the top number on the stack. 10238The @key{DEL} key pops and throws away the top number on the stack.
10109The @key{TAB} key swaps the top two objects on the stack. 10239The @key{TAB} key swaps the top two objects on the stack.
10110@xref{Stack and Trail}, for descriptions of these and other stack-related 10240@xref{Stack and Trail}, for descriptions of these and other stack-related
10111commands.@refill 10241commands.
10112 10242
10113@node Numeric Entry, Algebraic Entry, Stack Basics, Introduction 10243@node Numeric Entry, Algebraic Entry, Stack Basics, Introduction
10114@section Numeric Entry 10244@section Numeric Entry
@@ -10129,8 +10259,8 @@ you press a numeric key which is not valid, the key is ignored.
10129@cindex Negative numbers, entering 10259@cindex Negative numbers, entering
10130@kindex _ 10260@kindex _
10131There are three different concepts corresponding to the word ``minus,'' 10261There are three different concepts corresponding to the word ``minus,''
10132typified by @cite{a-b} (subtraction), @cite{-x} 10262typified by @expr{a-b} (subtraction), @expr{-x}
10133(change-sign), and @cite{-5} (negative number). Calc uses three 10263(change-sign), and @expr{-5} (negative number). Calc uses three
10134different keys for these operations, respectively: 10264different keys for these operations, respectively:
10135@kbd{-}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{-} key subtracts 10265@kbd{-}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{-} key subtracts
10136the two numbers on the top of the stack. The @kbd{n} key changes the sign 10266the two numbers on the top of the stack. The @kbd{n} key changes the sign
@@ -10138,7 +10268,7 @@ of the number on the top of the stack or the number currently being entered.
10138The @kbd{_} key begins entry of a negative number or changes the sign of 10268The @kbd{_} key begins entry of a negative number or changes the sign of
10139the number currently being entered. The following sequences all enter the 10269the number currently being entered. The following sequences all enter the
10140number @i{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, 10270number @i{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}},
10141@kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.@refill 10271@kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}.
10142 10272
10143Some other keys are active during numeric entry, such as @kbd{#} for 10273Some other keys are active during numeric entry, such as @kbd{#} for
10144non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. 10274non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms.
@@ -10158,11 +10288,12 @@ During numeric entry, the only editing key available is @key{DEL}.
10158Calculations can also be entered in algebraic form. This is accomplished 10288Calculations can also be entered in algebraic form. This is accomplished
10159by typing the apostrophe key, @kbd{'}, followed by the expression in 10289by typing the apostrophe key, @kbd{'}, followed by the expression in
10160standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes 10290standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes
10161@c{$2+(3\times4) = 14$} 10291@texline @tmath{2+(3\times4) = 14}
10162@cite{2+(3*4) = 14} and pushes that on the stack. If you wish you can 10292@infoline @expr{2+(3*4) = 14}
10293and pushes that on the stack. If you wish you can
10163ignore the RPN aspect of Calc altogether and simply enter algebraic 10294ignore the RPN aspect of Calc altogether and simply enter algebraic
10164expressions in this way. You may want to use @key{DEL} every so often to 10295expressions in this way. You may want to use @key{DEL} every so often to
10165clear previous results off the stack.@refill 10296clear previous results off the stack.
10166 10297
10167You can press the apostrophe key during normal numeric entry to switch 10298You can press the apostrophe key during normal numeric entry to switch
10168the half-entered number into algebraic entry mode. One reason to do this 10299the half-entered number into algebraic entry mode. One reason to do this
@@ -10185,7 +10316,7 @@ you can omit the apostrophe. Open parentheses and square brackets also
10185begin algebraic entry. You can still do RPN calculations in this mode, 10316begin algebraic entry. You can still do RPN calculations in this mode,
10186but you will have to press @key{RET} to terminate every number: 10317but you will have to press @key{RET} to terminate every number:
10187@kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same 10318@kbd{2 @key{RET} 3 @key{RET} * 4 @key{RET} +} would accomplish the same
10188thing as @kbd{2*3+4 @key{RET}}.@refill 10319thing as @kbd{2*3+4 @key{RET}}.
10189 10320
10190@cindex Incomplete algebraic mode 10321@cindex Incomplete algebraic mode
10191If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a} 10322If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a}
@@ -10221,7 +10352,7 @@ stack with that formula rather than simply pushing the formula onto the
10221stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2 10352stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2
10222@key{RET}} replaces it with 6. Note that the @kbd{$} key always 10353@key{RET}} replaces it with 6. Note that the @kbd{$} key always
10223initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the 10354initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
10224first character in the new formula.@refill 10355first character in the new formula.
10225 10356
10226Higher stack elements can be accessed from an entered formula with the 10357Higher stack elements can be accessed from an entered formula with the
10227symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements 10358symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements
@@ -10229,7 +10360,7 @@ removed (to be replaced by the entered values) equals the number of dollar
10229signs in the longest such symbol in the formula. For example, @samp{$$+$$$} 10360signs in the longest such symbol in the formula. For example, @samp{$$+$$$}
10230adds the second and third stack elements, replacing the top three elements 10361adds the second and third stack elements, replacing the top three elements
10231with the answer. (All information about the top stack element is thus lost 10362with the answer. (All information about the top stack element is thus lost
10232since no single @samp{$} appears in this formula.)@refill 10363since no single @samp{$} appears in this formula.)
10233 10364
10234A slightly different way to refer to stack elements is with a dollar 10365A slightly different way to refer to stack elements is with a dollar
10235sign followed by a number: @samp{$1}, @samp{$2}, and so on are much 10366sign followed by a number: @samp{$1}, @samp{$2}, and so on are much
@@ -10254,7 +10385,7 @@ If you finish your algebraic entry by pressing @key{LFD} (or @kbd{C-j})
10254instead of @key{RET}, Calc disables the default simplifications 10385instead of @key{RET}, Calc disables the default simplifications
10255(as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry 10386(as if by @kbd{m O}; @pxref{Simplification Modes}) while the entry
10256is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3 10387is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3
10257on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @cite{1+2}; 10388on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @expr{1+2};
10258you might then press @kbd{=} when it is time to evaluate this formula. 10389you might then press @kbd{=} when it is time to evaluate this formula.
10259 10390
10260@node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction 10391@node Quick Calculator, Prefix Arguments, Algebraic Entry, Introduction
@@ -10333,7 +10464,7 @@ Many Calculator commands use numeric prefix arguments. Some, such as
10333@kbd{d s} (@code{calc-sci-notation}), set a parameter to the value of 10464@kbd{d s} (@code{calc-sci-notation}), set a parameter to the value of
10334the prefix argument or use a default if you don't use a prefix. 10465the prefix argument or use a default if you don't use a prefix.
10335Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument 10466Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument
10336and prompt for a number if you don't give one as a prefix.@refill 10467and prompt for a number if you don't give one as a prefix.
10337 10468
10338As a rule, stack-manipulation commands accept a numeric prefix argument 10469As a rule, stack-manipulation commands accept a numeric prefix argument
10339which is interpreted as an index into the stack. A positive argument 10470which is interpreted as an index into the stack. A positive argument
@@ -10360,7 +10491,7 @@ argument for some other purpose.
10360Numeric prefixes are specified the same way as always in Emacs: Press 10491Numeric prefixes are specified the same way as always in Emacs: Press
10361a sequence of @key{META}-digits, or press @key{ESC} followed by digits, 10492a sequence of @key{META}-digits, or press @key{ESC} followed by digits,
10362or press @kbd{C-u} followed by digits. Some commands treat plain 10493or press @kbd{C-u} followed by digits. Some commands treat plain
10363@kbd{C-u} (without any actual digits) specially.@refill 10494@kbd{C-u} (without any actual digits) specially.
10364 10495
10365@kindex ~ 10496@kindex ~
10366@pindex calc-num-prefix 10497@pindex calc-num-prefix
@@ -10368,7 +10499,7 @@ You can type @kbd{~} (@code{calc-num-prefix}) to pop an integer from the
10368top of the stack and enter it as the numeric prefix for the next command. 10499top of the stack and enter it as the numeric prefix for the next command.
10369For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate 10500For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate
10370(silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2 10501(silly) way to do this would be @kbd{2 @key{RET} 4 ^ ~ p}, i.e., compute 2
10371to the fourth power and set the precision to that value.@refill 10502to the fourth power and set the precision to that value.
10372 10503
10373Conversely, if you have typed a numeric prefix argument the @kbd{~} key 10504Conversely, if you have typed a numeric prefix argument the @kbd{~} key
10374pushes it onto the stack in the form of an integer. 10505pushes it onto the stack in the form of an integer.
@@ -10416,7 +10547,7 @@ any other change, then it will be too late to redo.
10416The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that 10547The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that
10417it restores the arguments of the most recent command onto the stack; 10548it restores the arguments of the most recent command onto the stack;
10418however, it does not remove the result of that command. Given a numeric 10549however, it does not remove the result of that command. Given a numeric
10419prefix argument, this command applies to the @cite{n}th most recent 10550prefix argument, this command applies to the @expr{n}th most recent
10420command which removed items from the stack; it pushes those items back 10551command which removed items from the stack; it pushes those items back
10421onto the stack. 10552onto the stack.
10422 10553
@@ -10438,7 +10569,7 @@ The standard Emacs @kbd{C-_} undo key is recognized as a synonym for @kbd{U}.
10438@cindex Why did an error occur? 10569@cindex Why did an error occur?
10439Many situations that would produce an error message in other calculators 10570Many situations that would produce an error message in other calculators
10440simply create unsimplified formulas in the Emacs Calculator. For example, 10571simply create unsimplified formulas in the Emacs Calculator. For example,
10441@kbd{1 @key{RET} 0 /} pushes the formula @cite{1 / 0}; @w{@kbd{0 L}} pushes 10572@kbd{1 @key{RET} 0 /} pushes the formula @expr{1 / 0}; @w{@kbd{0 L}} pushes
10442the formula @samp{ln(0)}. Floating-point overflow and underflow are also 10573the formula @samp{ln(0)}. Floating-point overflow and underflow are also
10443reasons for this to happen. 10574reasons for this to happen.
10444 10575
@@ -10543,7 +10674,7 @@ possible in an attempt to recover from program bugs. If a calculation
10543ever halts incorrectly with the message ``Computation got stuck or 10674ever halts incorrectly with the message ``Computation got stuck or
10544ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth}) 10675ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth})
10545to increase this limit. (Of course, this will not help if the 10676to increase this limit. (Of course, this will not help if the
10546calculation really did get stuck due to some problem inside Calc.)@refill 10677calculation really did get stuck due to some problem inside Calc.)
10547 10678
10548The limit is always increased (multiplied) by a factor of two. There 10679The limit is always increased (multiplied) by a factor of two. There
10549is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which 10680is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which
@@ -10561,16 +10692,15 @@ internal Lisp recursion limit. The minimum value for this limit is 600.
10561@cindex Flushing caches 10692@cindex Flushing caches
10562Calc saves certain values after they have been computed once. For 10693Calc saves certain values after they have been computed once. For
10563example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the 10694example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the
10564constant @c{$\pi$} 10695constant @cpi{} to about 20 decimal places; if the current precision
10565@cite{pi} to about 20 decimal places; if the current precision 10696is greater than this, it will recompute @cpi{} using a series
10566is greater than this, it will recompute @c{$\pi$}
10567@cite{pi} using a series
10568approximation. This value will not need to be recomputed ever again 10697approximation. This value will not need to be recomputed ever again
10569unless you raise the precision still further. Many operations such as 10698unless you raise the precision still further. Many operations such as
10570logarithms and sines make use of similarly cached values such as 10699logarithms and sines make use of similarly cached values such as
10571@c{$\pi \over 4$} 10700@cpiover{4} and
10572@cite{pi/4} and @c{$\ln 2$} 10701@texline @tmath{\ln 2}.
10573@cite{ln(2)}. The visible effect of caching is that 10702@infoline @expr{ln(2)}.
10703The visible effect of caching is that
10574high-precision computations may seem to do extra work the first time. 10704high-precision computations may seem to do extra work the first time.
10575Other things cached include powers of two (for the binary arithmetic 10705Other things cached include powers of two (for the binary arithmetic
10576functions), matrix inverses and determinants, symbolic integrals, and 10706functions), matrix inverses and determinants, symbolic integrals, and
@@ -10643,7 +10773,7 @@ will be lost.
10643This chapter discusses the various types of objects that can be placed 10773This chapter discusses the various types of objects that can be placed
10644on the Calculator stack, how they are displayed, and how they are 10774on the Calculator stack, how they are displayed, and how they are
10645entered. (@xref{Data Type Formats}, for information on how these data 10775entered. (@xref{Data Type Formats}, for information on how these data
10646types are represented as underlying Lisp objects.)@refill 10776types are represented as underlying Lisp objects.)
10647 10777
10648Integers, fractions, and floats are various ways of describing real 10778Integers, fractions, and floats are various ways of describing real
10649numbers. HMS forms also for many purposes act as real numbers. These 10779numbers. HMS forms also for many purposes act as real numbers. These
@@ -10686,7 +10816,7 @@ floating-point form according to the current Fraction Mode.
10686A decimal integer is represented as an optional sign followed by a 10816A decimal integer is represented as an optional sign followed by a
10687sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to 10817sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to
10688insert a comma at every third digit for display purposes, but you 10818insert a comma at every third digit for display purposes, but you
10689must not type commas during the entry of numbers.@refill 10819must not type commas during the entry of numbers.
10690 10820
10691@kindex # 10821@kindex #
10692A non-decimal integer is represented as an optional sign, a radix 10822A non-decimal integer is represented as an optional sign, a radix
@@ -10695,7 +10825,7 @@ and above, the letters A through Z (upper- or lower-case) count as
10695digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how 10825digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how
10696to set the default radix for display of integers. Numbers of any radix 10826to set the default radix for display of integers. Numbers of any radix
10697may be entered at any time. If you press @kbd{#} at the beginning of a 10827may be entered at any time. If you press @kbd{#} at the beginning of a
10698number, the current display radix is used.@refill 10828number, the current display radix is used.
10699 10829
10700@node Fractions, Floats, Integers, Data Types 10830@node Fractions, Floats, Integers, Data Types
10701@section Fractions 10831@section Fractions
@@ -10708,15 +10838,15 @@ performs RPN division; the following two sequences push the number
10708@samp{2:3} on the stack: @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /} 10838@samp{2:3} on the stack: @kbd{2 :@: 3 @key{RET}}, or @kbd{2 @key{RET} 3 /}
10709assuming Fraction Mode has been enabled.) 10839assuming Fraction Mode has been enabled.)
10710When the Calculator produces a fractional result it always reduces it to 10840When the Calculator produces a fractional result it always reduces it to
10711simplest form, which may in fact be an integer.@refill 10841simplest form, which may in fact be an integer.
10712 10842
10713Fractions may also be entered in a three-part form, where @samp{2:3:4} 10843Fractions may also be entered in a three-part form, where @samp{2:3:4}
10714represents two-and-three-quarters. @xref{Fraction Formats}, for fraction 10844represents two-and-three-quarters. @xref{Fraction Formats}, for fraction
10715display formats.@refill 10845display formats.
10716 10846
10717Non-decimal fractions are entered and displayed as 10847Non-decimal fractions are entered and displayed as
10718@samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part 10848@samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part
10719form). The numerator and denominator always use the same radix.@refill 10849form). The numerator and denominator always use the same radix.
10720 10850
10721@node Floats, Complex Numbers, Fractions, Data Types 10851@node Floats, Complex Numbers, Fractions, Data Types
10722@section Floats 10852@section Floats
@@ -10726,12 +10856,13 @@ form). The numerator and denominator always use the same radix.@refill
10726A floating-point number or @dfn{float} is a number stored in scientific 10856A floating-point number or @dfn{float} is a number stored in scientific
10727notation. The number of significant digits in the fractional part is 10857notation. The number of significant digits in the fractional part is
10728governed by the current floating precision (@pxref{Precision}). The 10858governed by the current floating precision (@pxref{Precision}). The
10729range of acceptable values is from @c{$10^{-3999999}$} 10859range of acceptable values is from
10730@cite{10^-3999999} (inclusive) 10860@texline @tmath{10^{-3999999}}
10731to @c{$10^{4000000}$} 10861@infoline @expr{10^-3999999}
10732@cite{10^4000000} 10862(inclusive) to
10733(exclusive), plus the corresponding negative 10863@texline @tmath{10^{4000000}}
10734values and zero. 10864@infoline @expr{10^4000000}
10865(exclusive), plus the corresponding negative values and zero.
10735 10866
10736Calculations that would exceed the allowable range of values (such 10867Calculations that would exceed the allowable range of values (such
10737as @samp{exp(exp(20))}) are left in symbolic form by Calc. The 10868as @samp{exp(exp(20))}) are left in symbolic form by Calc. The
@@ -10772,7 +10903,7 @@ final result accurate to the full requested precision. However,
10772accuracy is not rigorously guaranteed. If you suspect the validity of a 10903accuracy is not rigorously guaranteed. If you suspect the validity of a
10773result, try doing the same calculation in a higher precision. The 10904result, try doing the same calculation in a higher precision. The
10774Calculator's arithmetic is not intended to be IEEE-conformant in any 10905Calculator's arithmetic is not intended to be IEEE-conformant in any
10775way.@refill 10906way.
10776 10907
10777While floats are always @emph{stored} in decimal, they can be entered 10908While floats are always @emph{stored} in decimal, they can be entered
10778and displayed in any radix just like integers and fractions. The 10909and displayed in any radix just like integers and fractions. The
@@ -10798,16 +10929,20 @@ polar. The default format is rectangular, displayed in the form
10798@samp{(@var{real},@var{imag})} where @var{real} is the real part and 10929@samp{(@var{real},@var{imag})} where @var{real} is the real part and
10799@var{imag} is the imaginary part, each of which may be any real number. 10930@var{imag} is the imaginary part, each of which may be any real number.
10800Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} 10931Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i}
10801notation; @pxref{Complex Formats}.@refill 10932notation; @pxref{Complex Formats}.
10802 10933
10803Polar complex numbers are displayed in the form `@t{(}@var{r}@t{;}@c{$\theta$} 10934Polar complex numbers are displayed in the form
10804@var{theta}@t{)}' 10935@texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}'
10805where @var{r} is the nonnegative magnitude and @c{$\theta$} 10936@infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'
10806@var{theta} is the argument 10937where @var{r} is the nonnegative magnitude and
10807or phase angle. The range of @c{$\theta$} 10938@texline @tmath{\theta}
10808@var{theta} depends on the current angular 10939@infoline @var{theta}
10809mode (@pxref{Angular Modes}); it is generally between @i{-180} and 10940is the argument or phase angle. The range of
10810@i{+180} degrees or the equivalent range in radians.@refill 10941@texline @tmath{\theta}
10942@infoline @var{theta}
10943depends on the current angular mode (@pxref{Angular Modes}); it is
10944generally between @i{-180} and @i{+180} degrees or the equivalent range
10945in radians.
10811 10946
10812Complex numbers are entered in stages using incomplete objects. 10947Complex numbers are entered in stages using incomplete objects.
10813@xref{Incomplete Objects}. 10948@xref{Incomplete Objects}.
@@ -10819,8 +10954,7 @@ a negative real), the current @dfn{Polar Mode} is used to determine the
10819type. @xref{Polar Mode}. 10954type. @xref{Polar Mode}.
10820 10955
10821A complex result in which the imaginary part is zero (or the phase angle 10956A complex result in which the imaginary part is zero (or the phase angle
10822is 0 or 180 degrees or @c{$\pi$} 10957is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real
10823@cite{pi} radians) is automatically converted to a real
10824number. 10958number.
10825 10959
10826@node Infinities, Vectors and Matrices, Complex Numbers, Data Types 10960@node Infinities, Vectors and Matrices, Complex Numbers, Data Types
@@ -10845,24 +10979,25 @@ entered using algebraic entry.
10845Mathematically speaking, it is not rigorously correct to treat 10979Mathematically speaking, it is not rigorously correct to treat
10846``infinity'' as if it were a number, but mathematicians often do 10980``infinity'' as if it were a number, but mathematicians often do
10847so informally. When they say that @samp{1 / inf = 0}, what they 10981so informally. When they say that @samp{1 / inf = 0}, what they
10848really mean is that @cite{1 / x}, as @cite{x} becomes larger and 10982really mean is that @expr{1 / x}, as @expr{x} becomes larger and
10849larger, becomes arbitrarily close to zero. So you can imagine 10983larger, becomes arbitrarily close to zero. So you can imagine
10850that if @cite{x} got ``all the way to infinity,'' then @cite{1 / x} 10984that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x}
10851would go all the way to zero. Similarly, when they say that 10985would go all the way to zero. Similarly, when they say that
10852@samp{exp(inf) = inf}, they mean that @c{$e^x$} 10986@samp{exp(inf) = inf}, they mean that
10853@cite{exp(x)} grows without 10987@texline @tmath{e^x}
10854bound as @cite{x} grows. The symbol @samp{-inf} likewise stands 10988@infoline @expr{exp(x)}
10855for an infinitely negative real value; for example, we say that 10989grows without bound as @expr{x} grows. The symbol @samp{-inf} likewise
10990stands for an infinitely negative real value; for example, we say that
10856@samp{exp(-inf) = 0}. You can have an infinity pointing in any 10991@samp{exp(-inf) = 0}. You can have an infinity pointing in any
10857direction on the complex plane: @samp{sqrt(-inf) = i inf}. 10992direction on the complex plane: @samp{sqrt(-inf) = i inf}.
10858 10993
10859The same concept of limits can be used to define @cite{1 / 0}. We 10994The same concept of limits can be used to define @expr{1 / 0}. We
10860really want the value that @cite{1 / x} approaches as @cite{x} 10995really want the value that @expr{1 / x} approaches as @expr{x}
10861approaches zero. But if all we have is @cite{1 / 0}, we can't 10996approaches zero. But if all we have is @expr{1 / 0}, we can't
10862tell which direction @cite{x} was coming from. If @cite{x} was 10997tell which direction @expr{x} was coming from. If @expr{x} was
10863positive and decreasing toward zero, then we should say that 10998positive and decreasing toward zero, then we should say that
10864@samp{1 / 0 = inf}. But if @cite{x} was negative and increasing 10999@samp{1 / 0 = inf}. But if @expr{x} was negative and increasing
10865toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @cite{x} 11000toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @expr{x}
10866could be an imaginary number, giving the answer @samp{i inf} or 11001could be an imaginary number, giving the answer @samp{i inf} or
10867@samp{-i inf}. Calc uses the special symbol @samp{uinf} to mean 11002@samp{-i inf}. Calc uses the special symbol @samp{uinf} to mean
10868@dfn{undirected infinity}, i.e., a value which is infinitely 11003@dfn{undirected infinity}, i.e., a value which is infinitely
@@ -10870,10 +11005,10 @@ large but with an unknown sign (or direction on the complex plane).
10870 11005
10871Calc actually has three modes that say how infinities are handled. 11006Calc actually has three modes that say how infinities are handled.
10872Normally, infinities never arise from calculations that didn't 11007Normally, infinities never arise from calculations that didn't
10873already have them. Thus, @cite{1 / 0} is treated simply as an 11008already have them. Thus, @expr{1 / 0} is treated simply as an
10874error and left unevaluated. The @kbd{m i} (@code{calc-infinite-mode}) 11009error and left unevaluated. The @kbd{m i} (@code{calc-infinite-mode})
10875command (@pxref{Infinite Mode}) enables a mode in which 11010command (@pxref{Infinite Mode}) enables a mode in which
10876@cite{1 / 0} evaluates to @code{uinf} instead. There is also 11011@expr{1 / 0} evaluates to @code{uinf} instead. There is also
10877an alternative type of infinite mode which says to treat zeros 11012an alternative type of infinite mode which says to treat zeros
10878as if they were positive, so that @samp{1 / 0 = inf}. While this 11013as if they were positive, so that @samp{1 / 0 = inf}. While this
10879is less mathematically correct, it may be the answer you want in 11014is less mathematically correct, it may be the answer you want in
@@ -10892,9 +11027,9 @@ notation.
10892It's not so easy to define certain formulas like @samp{0 * inf} and 11027It's not so easy to define certain formulas like @samp{0 * inf} and
10893@samp{inf / inf}. Depending on where these zeros and infinities 11028@samp{inf / inf}. Depending on where these zeros and infinities
10894came from, the answer could be literally anything. The latter 11029came from, the answer could be literally anything. The latter
10895formula could be the limit of @cite{x / x} (giving a result of one), 11030formula could be the limit of @expr{x / x} (giving a result of one),
10896or @cite{2 x / x} (giving two), or @cite{x^2 / x} (giving @code{inf}), 11031or @expr{2 x / x} (giving two), or @expr{x^2 / x} (giving @code{inf}),
10897or @cite{x / x^2} (giving zero). Calc uses the symbol @code{nan} 11032or @expr{x / x^2} (giving zero). Calc uses the symbol @code{nan}
10898to represent such an @dfn{indeterminate} value. (The name ``nan'' 11033to represent such an @dfn{indeterminate} value. (The name ``nan''
10899comes from analogy with the ``NAN'' concept of IEEE standard 11034comes from analogy with the ``NAN'' concept of IEEE standard
10900arithmetic; it stands for ``Not A Number.'' This is somewhat of a 11035arithmetic; it stands for ``Not A Number.'' This is somewhat of a
@@ -10938,15 +11073,16 @@ Traditional vector and matrix arithmetic is also supported;
10938@pxref{Basic Arithmetic} and @pxref{Matrix Functions}. 11073@pxref{Basic Arithmetic} and @pxref{Matrix Functions}.
10939Many other operations are applied to vectors element-wise. For example, 11074Many other operations are applied to vectors element-wise. For example,
10940the complex conjugate of a vector is a vector of the complex conjugates 11075the complex conjugate of a vector is a vector of the complex conjugates
10941of its elements.@refill 11076of its elements.
10942 11077
10943@ignore 11078@ignore
10944@starindex 11079@starindex
10945@end ignore 11080@end ignore
10946@tindex vec 11081@tindex vec
10947Algebraic functions for building vectors include @samp{vec(a, b, c)} 11082Algebraic functions for building vectors include @samp{vec(a, b, c)}
10948to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an @c{$n\times m$} 11083to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an
10949@asis{@var{n}x@var{m}} 11084@texline @tmath{n\times m}
11085@infoline @var{n}x@var{m}
10950matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers 11086matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers
10951from 1 to @samp{n}. 11087from 1 to @samp{n}.
10952 11088
@@ -11077,7 +11213,7 @@ The @var{secs} value is a real number between 0 (inclusive) and 60
11077(exclusive). A positive HMS form is interpreted as @var{hours} + 11213(exclusive). A positive HMS form is interpreted as @var{hours} +
11078@var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted 11214@var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted
11079as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600. 11215as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600.
11080Display format for HMS forms is quite flexible. @xref{HMS Formats}.@refill 11216Display format for HMS forms is quite flexible. @xref{HMS Formats}.
11081 11217
11082HMS forms can be added and subtracted. When they are added to numbers, 11218HMS forms can be added and subtracted. When they are added to numbers,
11083the numbers are interpreted according to the current angular mode. HMS 11219the numbers are interpreted according to the current angular mode. HMS
@@ -11216,10 +11352,10 @@ an integer multiple of) some value @var{M}. Arithmetic modulo @var{M}
11216often arises in number theory. Modulo forms are written 11352often arises in number theory. Modulo forms are written
11217`@var{a} @t{mod} @var{M}', 11353`@var{a} @t{mod} @var{M}',
11218where @var{a} and @var{M} are real numbers or HMS forms, and 11354where @var{a} and @var{M} are real numbers or HMS forms, and
11219@c{$0 \le a < M$} 11355@texline @tmath{0 \le a < M}.
11220@cite{0 <= a < @var{M}}. 11356@infoline @expr{0 <= a < @var{M}}.
11221In many applications @cite{a} and @cite{M} will be 11357In many applications @expr{a} and @expr{M} will be
11222integers but this is not required.@refill 11358integers but this is not required.
11223 11359
11224Modulo forms are not to be confused with the modulo operator @samp{%}. 11360Modulo forms are not to be confused with the modulo operator @samp{%}.
11225The expression @samp{27 % 10} means to compute 27 modulo 10 to produce 11361The expression @samp{27 % 10} means to compute 27 modulo 10 to produce
@@ -11228,28 +11364,30 @@ The expression @samp{27 mod 10} produces the result @samp{7 mod 10};
11228further computations with this value are again reduced modulo 10 so that 11364further computations with this value are again reduced modulo 10 so that
11229the result always lies in the desired range. 11365the result always lies in the desired range.
11230 11366
11231When two modulo forms with identical @cite{M}'s are added or multiplied, 11367When two modulo forms with identical @expr{M}'s are added or multiplied,
11232the Calculator simply adds or multiplies the values, then reduces modulo 11368the Calculator simply adds or multiplies the values, then reduces modulo
11233@cite{M}. If one argument is a modulo form and the other a plain number, 11369@expr{M}. If one argument is a modulo form and the other a plain number,
11234the plain number is treated like a compatible modulo form. It is also 11370the plain number is treated like a compatible modulo form. It is also
11235possible to raise modulo forms to powers; the result is the value raised 11371possible to raise modulo forms to powers; the result is the value raised
11236to the power, then reduced modulo @cite{M}. (When all values involved 11372to the power, then reduced modulo @expr{M}. (When all values involved
11237are integers, this calculation is done much more efficiently than 11373are integers, this calculation is done much more efficiently than
11238actually computing the power and then reducing.) 11374actually computing the power and then reducing.)
11239 11375
11240@cindex Modulo division 11376@cindex Modulo division
11241Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}' 11377Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}'
11242can be divided if @cite{a}, @cite{b}, and @cite{M} are all 11378can be divided if @expr{a}, @expr{b}, and @expr{M} are all
11243integers. The result is the modulo form which, when multiplied by 11379integers. The result is the modulo form which, when multiplied by
11244`@var{b} @t{mod} @var{M}', produces `@var{a} @t{mod} @var{M}'. If 11380`@var{b} @t{mod} @var{M}', produces `@var{a} @t{mod} @var{M}'. If
11245there is no solution to this equation (which can happen only when 11381there is no solution to this equation (which can happen only when
11246@cite{M} is non-prime), or if any of the arguments are non-integers, the 11382@expr{M} is non-prime), or if any of the arguments are non-integers, the
11247division is left in symbolic form. Other operations, such as square 11383division is left in symbolic form. Other operations, such as square
11248roots, are not yet supported for modulo forms. (Note that, although 11384roots, are not yet supported for modulo forms. (Note that, although
11249@w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root'' 11385@w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root''
11250in the sense of reducing @c{$\sqrt a$} 11386in the sense of reducing
11251@cite{sqrt(a)} modulo @cite{M}, this is not a 11387@texline @tmath{\sqrt a}
11252useful definition from the number-theoretical point of view.)@refill 11388@infoline @expr{sqrt(a)}
11389modulo @expr{M}, this is not a useful definition from the
11390number-theoretical point of view.)
11253 11391
11254@ignore 11392@ignore
11255@mindex M 11393@mindex M
@@ -11261,17 +11399,17 @@ useful definition from the number-theoretical point of view.)@refill
11261@tindex mod (operator) 11399@tindex mod (operator)
11262To create a modulo form during numeric entry, press the shift-@kbd{M} 11400To create a modulo form during numeric entry, press the shift-@kbd{M}
11263key to enter the word @samp{mod}. As a special convenience, pressing 11401key to enter the word @samp{mod}. As a special convenience, pressing
11264shift-@kbd{M} a second time automatically enters the value of @cite{M} 11402shift-@kbd{M} a second time automatically enters the value of @expr{M}
11265that was most recently used before. During algebraic entry, either 11403that was most recently used before. During algebraic entry, either
11266type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}). 11404type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
11267Once again, pressing this a second time enters the current modulo.@refill 11405Once again, pressing this a second time enters the current modulo.
11268 11406
11269You can also use @kbd{v p} and @kbd{%} to modify modulo forms. 11407You can also use @kbd{v p} and @kbd{%} to modify modulo forms.
11270@xref{Building Vectors}. @xref{Basic Arithmetic}. 11408@xref{Building Vectors}. @xref{Basic Arithmetic}.
11271 11409
11272It is possible to mix HMS forms and modulo forms. For example, an 11410It is possible to mix HMS forms and modulo forms. For example, an
11273HMS form modulo 24 could be used to manipulate clock times; an HMS 11411HMS form modulo 24 could be used to manipulate clock times; an HMS
11274form modulo 360 would be suitable for angles. Making the modulo @cite{M} 11412form modulo 360 would be suitable for angles. Making the modulo @expr{M}
11275also be an HMS form eliminates troubles that would arise if the angular 11413also be an HMS form eliminates troubles that would arise if the angular
11276mode were inadvertently set to Radians, in which case 11414mode were inadvertently set to Radians, in which case
11277@w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo 11415@w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
@@ -11296,24 +11434,28 @@ The algebraic function @samp{makemod(a, m)} builds the modulo form
11296@cindex Standard deviations 11434@cindex Standard deviations
11297An @dfn{error form} is a number with an associated standard 11435An @dfn{error form} is a number with an associated standard
11298deviation, as in @samp{2.3 +/- 0.12}. The notation 11436deviation, as in @samp{2.3 +/- 0.12}. The notation
11299`@var{x} @t{+/-} @c{$\sigma$} 11437@texline `@var{x} @t{+/-} @tmath{\sigma}'
11300@asis{sigma}' stands for an uncertain value which follows a normal or 11438@infoline `@var{x} @t{+/-} sigma'
11301Gaussian distribution of mean @cite{x} and standard deviation or 11439stands for an uncertain value which follows
11302``error'' @c{$\sigma$} 11440a normal or Gaussian distribution of mean @expr{x} and standard
11303@cite{sigma}. Both the mean and the error can be either numbers or 11441deviation or ``error''
11442@texline @tmath{\sigma}.
11443@infoline @expr{sigma}.
11444Both the mean and the error can be either numbers or
11304formulas. Generally these are real numbers but the mean may also be 11445formulas. Generally these are real numbers but the mean may also be
11305complex. If the error is negative or complex, it is changed to its 11446complex. If the error is negative or complex, it is changed to its
11306absolute value. An error form with zero error is converted to a 11447absolute value. An error form with zero error is converted to a
11307regular number by the Calculator.@refill 11448regular number by the Calculator.
11308 11449
11309All arithmetic and transcendental functions accept error forms as input. 11450All arithmetic and transcendental functions accept error forms as input.
11310Operations on the mean-value part work just like operations on regular 11451Operations on the mean-value part work just like operations on regular
11311numbers. The error part for any function @cite{f(x)} (such as @c{$\sin x$} 11452numbers. The error part for any function @expr{f(x)} (such as
11312@cite{sin(x)}) 11453@texline @tmath{\sin x}
11313is defined by the error of @cite{x} times the derivative of @cite{f} 11454@infoline @expr{sin(x)})
11314evaluated at the mean value of @cite{x}. For a two-argument function 11455is defined by the error of @expr{x} times the derivative of @expr{f}
11315@cite{f(x,y)} (such as addition) the error is the square root of the sum 11456evaluated at the mean value of @expr{x}. For a two-argument function
11316of the squares of the errors due to @cite{x} and @cite{y}. 11457@expr{f(x,y)} (such as addition) the error is the square root of the sum
11458of the squares of the errors due to @expr{x} and @expr{y}.
11317@tex 11459@tex
11318$$ \eqalign{ 11460$$ \eqalign{
11319 f(x \hbox{\code{ +/- }} \sigma) 11461 f(x \hbox{\code{ +/- }} \sigma)
@@ -11327,38 +11469,48 @@ $$ \eqalign{
11327} $$ 11469} $$
11328@end tex 11470@end tex
11329Note that this 11471Note that this
11330definition assumes the errors in @cite{x} and @cite{y} are uncorrelated. 11472definition assumes the errors in @expr{x} and @expr{y} are uncorrelated.
11331A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)} 11473A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
11332is not the same as @samp{(2 +/- 1)^2}; the former represents the product 11474is not the same as @samp{(2 +/- 1)^2}; the former represents the product
11333of two independent values which happen to have the same probability 11475of two independent values which happen to have the same probability
11334distributions, and the latter is the product of one random value with itself. 11476distributions, and the latter is the product of one random value with itself.
11335The former will produce an answer with less error, since on the average 11477The former will produce an answer with less error, since on the average
11336the two independent errors can be expected to cancel out.@refill 11478the two independent errors can be expected to cancel out.
11337 11479
11338Consult a good text on error analysis for a discussion of the proper use 11480Consult a good text on error analysis for a discussion of the proper use
11339of standard deviations. Actual errors often are neither Gaussian-distributed 11481of standard deviations. Actual errors often are neither Gaussian-distributed
11340nor uncorrelated, and the above formulas are valid only when errors 11482nor uncorrelated, and the above formulas are valid only when errors
11341are small. As an example, the error arising from 11483are small. As an example, the error arising from
11342`@t{sin(}@var{x} @t{+/-} @c{$\sigma$} 11484@texline `@t{sin(}@var{x} @t{+/-} @tmath{\sigma}@t{)}'
11343@var{sigma}@t{)}' is 11485@infoline `@t{sin(}@var{x} @t{+/-} @var{sigma}@t{)}'
11344`@c{$\sigma$\nobreak} 11486is
11345@var{sigma} @t{abs(cos(}@var{x}@t{))}'. When @cite{x} is close to zero, 11487@texline `@tmath{\sigma} @t{abs(cos(}@var{x}@t{))}'.
11346@c{$\cos x$} 11488@infoline `@var{sigma} @t{abs(cos(}@var{x}@t{))}'.
11347@cite{cos(x)} is 11489When @expr{x} is close to zero,
11348close to one so the error in the sine is close to @c{$\sigma$} 11490@texline @tmath{\cos x}
11349@cite{sigma}; this makes sense, since @c{$\sin x$} 11491@infoline @expr{cos(x)}
11350@cite{sin(x)} is approximately @cite{x} near zero, so a given 11492is close to one so the error in the sine is close to
11351error in @cite{x} will produce about the same error in the sine. Likewise, 11493@texline @tmath{\sigma};
11352near 90 degrees @c{$\cos x$} 11494@infoline @expr{sigma};
11353@cite{cos(x)} is nearly zero and so the computed error is 11495this makes sense, since
11354small: The sine curve is nearly flat in that region, so an error in @cite{x} 11496@texline @tmath{\sin x}
11355has relatively little effect on the value of @c{$\sin x$} 11497@infoline @expr{sin(x)}
11356@cite{sin(x)}. However, consider 11498is approximately @expr{x} near zero, so a given error in @expr{x} will
11357@samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so Calc will report 11499produce about the same error in the sine. Likewise, near 90 degrees
11358zero error! We get an obviously wrong result because we have violated 11500@texline @tmath{\cos x}
11359the small-error approximation underlying the error analysis. If the error 11501@infoline @expr{cos(x)}
11360in @cite{x} had been small, the error in @c{$\sin x$} 11502is nearly zero and so the computed error is
11361@cite{sin(x)} would indeed have been negligible.@refill 11503small: The sine curve is nearly flat in that region, so an error in @expr{x}
11504has relatively little effect on the value of
11505@texline @tmath{\sin x}.
11506@infoline @expr{sin(x)}.
11507However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so
11508Calc will report zero error! We get an obviously wrong result because
11509we have violated the small-error approximation underlying the error
11510analysis. If the error in @expr{x} had been small, the error in
11511@texline @tmath{\sin x}
11512@infoline @expr{sin(x)}
11513would indeed have been negligible.
11362 11514
11363@ignore 11515@ignore
11364@mindex p 11516@mindex p
@@ -11411,10 +11563,10 @@ intervals of the type shown above, @dfn{open} intervals such as
11411@emph{exclusive}, and @dfn{semi-open} intervals in which one end 11563@emph{exclusive}, and @dfn{semi-open} intervals in which one end
11412uses a round parenthesis and the other a square bracket. In mathematical 11564uses a round parenthesis and the other a square bracket. In mathematical
11413terms, 11565terms,
11414@samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas 11566@samp{[2 ..@: 4]} means @expr{2 <= x <= 4}, whereas
11415@samp{[2 ..@: 4)} represents @cite{2 <= x < 4}, 11567@samp{[2 ..@: 4)} represents @expr{2 <= x < 4},
11416@samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and 11568@samp{(2 ..@: 4]} represents @expr{2 < x <= 4}, and
11417@samp{(2 ..@: 4)} represents @cite{2 < x < 4}.@refill 11569@samp{(2 ..@: 4)} represents @expr{2 < x < 4}.
11418@end ifinfo 11570@end ifinfo
11419@tex 11571@tex
11420Calc supports several varieties of intervals, including \dfn{closed} 11572Calc supports several varieties of intervals, including \dfn{closed}
@@ -11464,14 +11616,19 @@ contain zero inside them Calc is forced to give the result,
11464 11616
11465While it may seem that intervals and error forms are similar, they are 11617While it may seem that intervals and error forms are similar, they are
11466based on entirely different concepts of inexact quantities. An error 11618based on entirely different concepts of inexact quantities. An error
11467form `@var{x} @t{+/-} @c{$\sigma$} 11619form
11468@var{sigma}' means a variable is random, and its value could 11620@texline `@var{x} @t{+/-} @tmath{\sigma}'
11469be anything but is ``probably'' within one @c{$\sigma$} 11621@infoline `@var{x} @t{+/-} @var{sigma}'
11470@var{sigma} of the mean value @cite{x}. 11622means a variable is random, and its value could
11471An interval `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a variable's value 11623be anything but is ``probably'' within one
11472is unknown, but guaranteed to lie in the specified range. Error forms 11624@texline @tmath{\sigma}
11473are statistical or ``average case'' approximations; interval arithmetic 11625@infoline @var{sigma}
11474tends to produce ``worst case'' bounds on an answer.@refill 11626of the mean value @expr{x}. An interval
11627`@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a
11628variable's value is unknown, but guaranteed to lie in the specified
11629range. Error forms are statistical or ``average case'' approximations;
11630interval arithmetic tends to produce ``worst case'' bounds on an
11631answer.
11475 11632
11476Intervals may not contain complex numbers, but they may contain 11633Intervals may not contain complex numbers, but they may contain
11477HMS forms or date forms. 11634HMS forms or date forms.
@@ -11537,7 +11694,7 @@ pushes the complex number @samp{(1, 1.414)} (approximately).
11537If several values lie on the stack in front of the incomplete object, 11694If several values lie on the stack in front of the incomplete object,
11538all are collected and appended to the object. Thus the @kbd{,} key 11695all are collected and appended to the object. Thus the @kbd{,} key
11539is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people 11696is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people
11540prefer the equivalent @key{SPC} key to @key{RET}.@refill 11697prefer the equivalent @key{SPC} key to @key{RET}.
11541 11698
11542As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or 11699As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
11543@kbd{,} adds a zero or duplicates the preceding value in the list being 11700@kbd{,} adds a zero or duplicates the preceding value in the list being
@@ -11575,14 +11732,14 @@ Calc also allows apostrophes and @code{#} signs in variable names.
11575The Calc variable @code{foo} corresponds to the Emacs Lisp variable 11732The Calc variable @code{foo} corresponds to the Emacs Lisp variable
11576@code{var-foo}. Commands like @kbd{s s} (@code{calc-store}) that operate 11733@code{var-foo}. Commands like @kbd{s s} (@code{calc-store}) that operate
11577on variables can be made to use any arbitrary Lisp variable simply by 11734on variables can be made to use any arbitrary Lisp variable simply by
11578backspacing over the @samp{var-} prefix in the minibuffer.@refill 11735backspacing over the @samp{var-} prefix in the minibuffer.
11579 11736
11580In a command that takes a variable name, you can either type the full 11737In a command that takes a variable name, you can either type the full
11581name of a variable, or type a single digit to use one of the special 11738name of a variable, or type a single digit to use one of the special
11582convenience variables @code{var-q0} through @code{var-q9}. For example, 11739convenience variables @code{var-q0} through @code{var-q9}. For example,
11583@kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and 11740@kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and
11584@w{@kbd{3 s s foo @key{RET}}} stores that number in variable 11741@w{@kbd{3 s s foo @key{RET}}} stores that number in variable
11585@code{var-foo}.@refill 11742@code{var-foo}.
11586 11743
11587To push a variable itself (as opposed to the variable's value) on the 11744To push a variable itself (as opposed to the variable's value) on the
11588stack, enter its name as an algebraic expression using the apostrophe 11745stack, enter its name as an algebraic expression using the apostrophe
@@ -11623,7 +11780,7 @@ A few variables are called @dfn{special constants}. Their names are
11623(@xref{Scientific Functions}.) When they are evaluated with @kbd{=}, 11780(@xref{Scientific Functions}.) When they are evaluated with @kbd{=},
11624their values are calculated if necessary according to the current precision 11781their values are calculated if necessary according to the current precision
11625or complex polar mode. If you wish to use these symbols for other purposes, 11782or complex polar mode. If you wish to use these symbols for other purposes,
11626simply undefine or redefine them using @code{calc-store}.@refill 11783simply undefine or redefine them using @code{calc-store}.
11627 11784
11628The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for 11785The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
11629infinite or indeterminate values. It's best not to use them as 11786infinite or indeterminate values. It's best not to use them as
@@ -11697,8 +11854,9 @@ the C-style ``if'' operator @samp{a?b:c} [@code{if}];
11697@samp{=>} [@code{evalto}]. 11854@samp{=>} [@code{evalto}].
11698 11855
11699Note that, unlike in usual computer notation, multiplication binds more 11856Note that, unlike in usual computer notation, multiplication binds more
11700strongly than division: @samp{a*b/c*d} is equivalent to @c{$a b \over c d$} 11857strongly than division: @samp{a*b/c*d} is equivalent to
11701@cite{(a*b)/(c*d)}. 11858@texline @tmath{a b \over c d}.
11859@infoline @expr{(a*b)/(c*d)}.
11702 11860
11703@cindex Multiplication, implicit 11861@cindex Multiplication, implicit
11704@cindex Implicit multiplication 11862@cindex Implicit multiplication
@@ -11712,7 +11870,7 @@ is interpreted as a function call, not an implicit @samp{*}. In many
11712cases you must use a space if you omit the @samp{*}: @samp{2a} is the 11870cases you must use a space if you omit the @samp{*}: @samp{2a} is the
11713same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab} 11871same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
11714is a variable called @code{ab}, @emph{not} the product of @samp{a} and 11872is a variable called @code{ab}, @emph{not} the product of @samp{a} and
11715@samp{b}! Also note that @samp{f (x)} is still a function call.@refill 11873@samp{b}! Also note that @samp{f (x)} is still a function call.
11716 11874
11717@cindex Implicit comma in vectors 11875@cindex Implicit comma in vectors
11718The rules are slightly different for vectors written with square brackets. 11876The rules are slightly different for vectors written with square brackets.
@@ -11724,7 +11882,7 @@ Note that spaces around the brackets, and around explicit commas, are
11724ignored. To force spaces to be interpreted as multiplication you can 11882ignored. To force spaces to be interpreted as multiplication you can
11725enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is 11883enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
11726interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted 11884interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted
11727between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill 11885between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.
11728 11886
11729Vectors that contain commas (not embedded within nested parentheses or 11887Vectors that contain commas (not embedded within nested parentheses or
11730brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector 11888brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector
@@ -11753,12 +11911,12 @@ call is left as it is during algebraic manipulation: @samp{f(x+y)} is
11753left alone. Beware that many innocent-looking short names like @code{in} 11911left alone. Beware that many innocent-looking short names like @code{in}
11754and @code{re} have predefined meanings which could surprise you; however, 11912and @code{re} have predefined meanings which could surprise you; however,
11755single letters or single letters followed by digits are always safe to 11913single letters or single letters followed by digits are always safe to
11756use for your own function names. @xref{Function Index}.@refill 11914use for your own function names. @xref{Function Index}.
11757 11915
11758In the documentation for particular commands, the notation @kbd{H S} 11916In the documentation for particular commands, the notation @kbd{H S}
11759(@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the 11917(@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the
11760command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all 11918command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all
11761represent the same operation.@refill 11919represent the same operation.
11762 11920
11763Commands that interpret (``parse'') text as algebraic formulas include 11921Commands that interpret (``parse'') text as algebraic formulas include
11764algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse 11922algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
@@ -11823,7 +11981,7 @@ For example, with @samp{10 20 30} on the stack,
11823@key{RET} creates @samp{10 20 30 30}, 11981@key{RET} creates @samp{10 20 30 30},
11824@kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30}, 11982@kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30},
11825@kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and 11983@kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and
11826@kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.@refill 11984@kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.
11827 11985
11828@kindex @key{LFD} 11986@kindex @key{LFD}
11829@pindex calc-over 11987@pindex calc-over
@@ -11833,7 +11991,7 @@ except that the sign of the numeric prefix argument is interpreted
11833oppositely. Also, with no prefix argument the default argument is 2. 11991oppositely. Also, with no prefix argument the default argument is 2.
11834Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}} 11992Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}
11835are both equivalent to @kbd{C-u - 2 @key{RET}}, producing 11993are both equivalent to @kbd{C-u - 2 @key{RET}}, producing
11836@samp{10 20 30 20}.@refill 11994@samp{10 20 30 20}.
11837 11995
11838@kindex @key{DEL} 11996@kindex @key{DEL}
11839@kindex C-d 11997@kindex C-d
@@ -11851,7 +12009,7 @@ For example, with @samp{10 20 30} on the stack,
11851@key{DEL} leaves @samp{10 20}, 12009@key{DEL} leaves @samp{10 20},
11852@kbd{C-u 2 @key{DEL}} leaves @samp{10}, 12010@kbd{C-u 2 @key{DEL}} leaves @samp{10},
11853@kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and 12011@kbd{C-u - 2 @key{DEL}} leaves @samp{10 30}, and
11854@kbd{C-u 0 @key{DEL}} leaves an empty stack.@refill 12012@kbd{C-u 0 @key{DEL}} leaves an empty stack.
11855 12013
11856@kindex M-@key{DEL} 12014@kindex M-@key{DEL}
11857@pindex calc-pop-above 12015@pindex calc-pop-above
@@ -11874,7 +12032,7 @@ For example, with @samp{10 20 30 40 50} on the stack,
11874@key{TAB} creates @samp{10 20 30 50 40}, 12032@key{TAB} creates @samp{10 20 30 50 40},
11875@kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40}, 12033@kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},
11876@kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and 12034@kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and
11877@kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.@refill 12035@kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.
11878 12036
11879@kindex M-@key{TAB} 12037@kindex M-@key{TAB}
11880@pindex calc-roll-up 12038@pindex calc-roll-up
@@ -11885,7 +12043,7 @@ For example, with @samp{10 20 30 40 50} on the stack,
11885@kbd{M-@key{TAB}} creates @samp{10 20 40 50 30}, 12043@kbd{M-@key{TAB}} creates @samp{10 20 40 50 30},
11886@kbd{C-u 4 M-@key{TAB}} creates @samp{10 30 40 50 20}, 12044@kbd{C-u 4 M-@key{TAB}} creates @samp{10 30 40 50 20},
11887@kbd{C-u - 2 M-@key{TAB}} creates @samp{30 40 50 10 20}, and 12045@kbd{C-u - 2 M-@key{TAB}} creates @samp{30 40 50 10 20}, and
11888@kbd{C-u 0 M-@key{TAB}} creates @samp{50 40 30 20 10}.@refill 12046@kbd{C-u 0 M-@key{TAB}} creates @samp{50 40 30 20 10}.
11889 12047
11890A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in 12048A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in
11891terms of moving a particular element to a new position in the stack. 12049terms of moving a particular element to a new position in the stack.
@@ -11988,7 +12146,7 @@ The @kbd{t i} (@code{calc-trail-in}) and @kbd{t o}
11988Calc Trail window. In practice they are rarely used, since the commands 12146Calc Trail window. In practice they are rarely used, since the commands
11989shown below are a more convenient way to move around in the 12147shown below are a more convenient way to move around in the
11990trail, and they work ``by remote control'' when the cursor is still 12148trail, and they work ``by remote control'' when the cursor is still
11991in the Calculator window.@refill 12149in the Calculator window.
11992 12150
11993@cindex Trail pointer 12151@cindex Trail pointer
11994There is a @dfn{trail pointer} which selects some entry of the trail at 12152There is a @dfn{trail pointer} which selects some entry of the trail at
@@ -12011,7 +12169,7 @@ trail pointer.
12011@pindex calc-trail-scroll-right 12169@pindex calc-trail-scroll-right
12012The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >} 12170The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >}
12013(@code{calc-trail-scroll-right}) commands horizontally scroll the trail 12171(@code{calc-trail-scroll-right}) commands horizontally scroll the trail
12014window left or right by one half of its width.@refill 12172window left or right by one half of its width.
12015 12173
12016@kindex t n 12174@kindex t n
12017@pindex calc-trail-next 12175@pindex calc-trail-next
@@ -12026,7 +12184,7 @@ The @kbd{t n} (@code{calc-trail-next}) and @kbd{t p}
12026one line. The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b} 12184one line. The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}
12027(@code{calc-trail-backward}) commands move the trail pointer down or up 12185(@code{calc-trail-backward}) commands move the trail pointer down or up
12028one screenful at a time. All of these commands accept numeric prefix 12186one screenful at a time. All of these commands accept numeric prefix
12029arguments to move several lines or screenfuls at a time.@refill 12187arguments to move several lines or screenfuls at a time.
12030 12188
12031@kindex t [ 12189@kindex t [
12032@pindex calc-trail-first 12190@pindex calc-trail-first
@@ -12038,7 +12196,7 @@ The @kbd{t [} (@code{calc-trail-first}) and @kbd{t ]}
12038(@code{calc-trail-last}) commands move the trail pointer to the first or 12196(@code{calc-trail-last}) commands move the trail pointer to the first or
12039last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command 12197last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command
12040moves the trail pointer to the cursor position; unlike the other trail 12198moves the trail pointer to the cursor position; unlike the other trail
12041commands, @kbd{t h} works only when Calc Trail is the selected window.@refill 12199commands, @kbd{t h} works only when Calc Trail is the selected window.
12042 12200
12043@kindex t s 12201@kindex t s
12044@pindex calc-trail-isearch-forward 12202@pindex calc-trail-isearch-forward
@@ -12050,7 +12208,7 @@ The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
12050search forward or backward through the trail. You can press @key{RET} 12208search forward or backward through the trail. You can press @key{RET}
12051to terminate the search; the trail pointer moves to the current line. 12209to terminate the search; the trail pointer moves to the current line.
12052If you cancel the search with @kbd{C-g}, the trail pointer stays where 12210If you cancel the search with @kbd{C-g}, the trail pointer stays where
12053it was when the search began.@refill 12211it was when the search began.
12054@end ifinfo 12212@end ifinfo
12055@tex 12213@tex
12056The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r} 12214The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
@@ -12248,7 +12406,7 @@ what you see is what you get. Reducing the current precision does not
12248round values already on the stack, but those values will be rounded 12406round values already on the stack, but those values will be rounded
12249down before being used in any calculation. The @kbd{c 0} through 12407down before being used in any calculation. The @kbd{c 0} through
12250@kbd{c 9} commands (@pxref{Conversions}) can be used to round an 12408@kbd{c 9} commands (@pxref{Conversions}) can be used to round an
12251existing value to a new precision.@refill 12409existing value to a new precision.
12252 12410
12253@cindex Accuracy of calculations 12411@cindex Accuracy of calculations
12254It is important to distinguish the concepts of @dfn{precision} and 12412It is important to distinguish the concepts of @dfn{precision} and
@@ -12291,7 +12449,7 @@ There is no single-key equivalent to the @code{calc-arcsin} function.
12291Instead, you must first press @kbd{I} (@code{calc-inverse}) to set 12449Instead, you must first press @kbd{I} (@code{calc-inverse}) to set
12292the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}). 12450the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).
12293The @kbd{I} key actually toggles the Inverse Flag. When this flag 12451The @kbd{I} key actually toggles the Inverse Flag. When this flag
12294is set, the word @samp{Inv} appears in the mode line.@refill 12452is set, the word @samp{Inv} appears in the mode line.
12295 12453
12296@kindex H 12454@kindex H
12297@pindex calc-hyperbolic 12455@pindex calc-hyperbolic
@@ -12300,7 +12458,7 @@ Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}.
12300If both of these flags are set at once, the effect will be 12458If both of these flags are set at once, the effect will be
12301@code{calc-arcsinh}. (The Hyperbolic flag is also used by some 12459@code{calc-arcsinh}. (The Hyperbolic flag is also used by some
12302non-trigonometric commands; for example @kbd{H L} computes a base-10, 12460non-trigonometric commands; for example @kbd{H L} computes a base-10,
12303instead of base-@i{e}, logarithm.)@refill 12461instead of base-@i{e}, logarithm.)
12304 12462
12305Command names like @code{calc-arcsin} are provided for completeness, and 12463Command names like @code{calc-arcsin} are provided for completeness, and
12306may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to 12464may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to
@@ -12356,8 +12514,7 @@ result is a complex number and the current mode is HMS, the number is
12356instead expressed in degrees. (Complex-number calculations would 12514instead expressed in degrees. (Complex-number calculations would
12357normally be done in radians mode, though. Complex numbers are converted 12515normally be done in radians mode, though. Complex numbers are converted
12358to degrees by calculating the complex result in radians and then 12516to degrees by calculating the complex result in radians and then
12359multiplying by 180 over @c{$\pi$} 12517multiplying by 180 over @cpi{}.)
12360@cite{pi}.)
12361 12518
12362@kindex m r 12519@kindex m r
12363@pindex calc-radians-mode 12520@pindex calc-radians-mode
@@ -12368,7 +12525,7 @@ multiplying by 180 over @c{$\pi$}
12368The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}), 12525The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),
12369and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode. 12526and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.
12370The current angular mode is displayed on the Emacs mode line. 12527The current angular mode is displayed on the Emacs mode line.
12371The default angular mode is degrees.@refill 12528The default angular mode is degrees.
12372 12529
12373@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes 12530@node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
12374@subsection Polar Mode 12531@subsection Polar Mode
@@ -12396,16 +12553,16 @@ of the above example situations would produce polar complex numbers.
12396Division of two integers normally yields a floating-point number if the 12553Division of two integers normally yields a floating-point number if the
12397result cannot be expressed as an integer. In some cases you would 12554result cannot be expressed as an integer. In some cases you would
12398rather get an exact fractional answer. One way to accomplish this is 12555rather get an exact fractional answer. One way to accomplish this is
12399to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @cite{3:2} 12556to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @expr{3:2}
12400even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}. 12557even though @kbd{6 @key{RET} 4 /} produces @expr{1.5}.
12401 12558
12402@kindex m f 12559@kindex m f
12403@pindex calc-frac-mode 12560@pindex calc-frac-mode
12404To set the Calculator to produce fractional results for normal integer 12561To set the Calculator to produce fractional results for normal integer
12405divisions, use the @kbd{m f} (@code{calc-frac-mode}) command. 12562divisions, use the @kbd{m f} (@code{calc-frac-mode}) command.
12406For example, @cite{8/4} produces @cite{2} in either mode, 12563For example, @expr{8/4} produces @expr{2} in either mode,
12407but @cite{6/4} produces @cite{3:2} in Fraction Mode, @cite{1.5} in 12564but @expr{6/4} produces @expr{3:2} in Fraction Mode, @expr{1.5} in
12408Float Mode.@refill 12565Float Mode.
12409 12566
12410At any time you can use @kbd{c f} (@code{calc-float}) to convert a 12567At any time you can use @kbd{c f} (@code{calc-float}) to convert a
12411fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a 12568fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a
@@ -12416,7 +12573,7 @@ float to a fraction. @xref{Conversions}.
12416 12573
12417@noindent 12574@noindent
12418@cindex Infinite mode 12575@cindex Infinite mode
12419The Calculator normally treats results like @cite{1 / 0} as errors; 12576The Calculator normally treats results like @expr{1 / 0} as errors;
12420formulas like this are left in unsimplified form. But Calc can be 12577formulas like this are left in unsimplified form. But Calc can be
12421put into a mode where such calculations instead produce ``infinite'' 12578put into a mode where such calculations instead produce ``infinite''
12422results. 12579results.
@@ -12432,7 +12589,7 @@ will not be generated when infinite mode is off.)
12432 12589
12433With infinite mode turned on, @samp{1 / 0} will generate @code{uinf}, 12590With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
12434an undirected infinity. @xref{Infinities}, for a discussion of the 12591an undirected infinity. @xref{Infinities}, for a discussion of the
12435difference between @code{inf} and @code{uinf}. Also, @cite{0 / 0} 12592difference between @code{inf} and @code{uinf}. Also, @expr{0 / 0}
12436evaluates to @code{nan}, the ``indeterminate'' symbol. Various other 12593evaluates to @code{nan}, the ``indeterminate'' symbol. Various other
12437functions can also return infinities in this mode; for example, 12594functions can also return infinities in this mode; for example,
12438@samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}. Once again, 12595@samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}. Once again,
@@ -12477,7 +12634,7 @@ the expression at the top of the stack, by temporarily disabling
12477@code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}). 12634@code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).
12478Given a numeric prefix argument, it also 12635Given a numeric prefix argument, it also
12479sets the floating-point precision to the specified value for the duration 12636sets the floating-point precision to the specified value for the duration
12480of the command.@refill 12637of the command.
12481 12638
12482To evaluate a formula numerically without expanding the variables it 12639To evaluate a formula numerically without expanding the variables it
12483contains, you can use the key sequence @kbd{m s a v m s} (this uses 12640contains, you can use the key sequence @kbd{m s a v m s} (this uses
@@ -12504,7 +12661,7 @@ multiplication to be commutative. (Recall that in matrix arithmetic,
12504@samp{A*B} is not the same as @samp{B*A}.) This assumption affects 12661@samp{A*B} is not the same as @samp{B*A}.) This assumption affects
12505rewrite rules and algebraic simplification. Another effect of this 12662rewrite rules and algebraic simplification. Another effect of this
12506mode is that calculations that would normally produce constants like 12663mode is that calculations that would normally produce constants like
125070 and 1 (e.g., @cite{a - a} and @cite{a / a}, respectively) will now 126640 and 1 (e.g., @expr{a - a} and @expr{a / a}, respectively) will now
12508produce function calls that represent ``generic'' zero or identity 12665produce function calls that represent ``generic'' zero or identity
12509matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function 12666matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function
12510@samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n} 12667@samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n}
@@ -12598,7 +12755,7 @@ Type @kbd{m w} (@code{calc-working}) with a numeric prefix of 0 to
12598disable all ``working'' messages. Use a numeric prefix of 1 to enable 12755disable all ``working'' messages. Use a numeric prefix of 1 to enable
12599only the plain @samp{Working...} message. Use a numeric prefix of 2 to 12756only the plain @samp{Working...} message. Use a numeric prefix of 2 to
12600see intermediate results as well. With no numeric prefix this displays 12757see intermediate results as well. With no numeric prefix this displays
12601the current mode.@refill 12758the current mode.
12602 12759
12603While it may seem that the ``working'' messages will slow Calc down 12760While it may seem that the ``working'' messages will slow Calc down
12604considerably, experiments have shown that their impact is actually 12761considerably, experiments have shown that their impact is actually
@@ -12613,13 +12770,13 @@ The current @dfn{simplification mode} controls how numbers and formulas
12613are ``normalized'' when being taken from or pushed onto the stack. 12770are ``normalized'' when being taken from or pushed onto the stack.
12614Some normalizations are unavoidable, such as rounding floating-point 12771Some normalizations are unavoidable, such as rounding floating-point
12615results to the current precision, and reducing fractions to simplest 12772results to the current precision, and reducing fractions to simplest
12616form. Others, such as simplifying a formula like @cite{a+a} (or @cite{2+3}), 12773form. Others, such as simplifying a formula like @expr{a+a} (or @expr{2+3}),
12617are done by default but can be turned off when necessary. 12774are done by default but can be turned off when necessary.
12618 12775
12619When you press a key like @kbd{+} when @cite{2} and @cite{3} are on the 12776When you press a key like @kbd{+} when @expr{2} and @expr{3} are on the
12620stack, Calc pops these numbers, normalizes them, creates the formula 12777stack, Calc pops these numbers, normalizes them, creates the formula
12621@cite{2+3}, normalizes it, and pushes the result. Of course the standard 12778@expr{2+3}, normalizes it, and pushes the result. Of course the standard
12622rules for normalizing @cite{2+3} will produce the result @cite{5}. 12779rules for normalizing @expr{2+3} will produce the result @expr{5}.
12623 12780
12624Simplification mode commands consist of the lower-case @kbd{m} prefix key 12781Simplification mode commands consist of the lower-case @kbd{m} prefix key
12625followed by a shifted letter. 12782followed by a shifted letter.
@@ -12627,7 +12784,7 @@ followed by a shifted letter.
12627@kindex m O 12784@kindex m O
12628@pindex calc-no-simplify-mode 12785@pindex calc-no-simplify-mode
12629The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional 12786The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional
12630simplifications. These would leave a formula like @cite{2+3} alone. In 12787simplifications. These would leave a formula like @expr{2+3} alone. In
12631fact, nothing except simple numbers are ever affected by normalization 12788fact, nothing except simple numbers are ever affected by normalization
12632in this mode. 12789in this mode.
12633 12790
@@ -12635,22 +12792,24 @@ in this mode.
12635@pindex calc-num-simplify-mode 12792@pindex calc-num-simplify-mode
12636The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification 12793The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification
12637of any formulas except those for which all arguments are constants. For 12794of any formulas except those for which all arguments are constants. For
12638example, @cite{1+2} is simplified to @cite{3}, and @cite{a+(2-2)} is 12795example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(2-2)} is
12639simplified to @cite{a+0} but no further, since one argument of the sum 12796simplified to @expr{a+0} but no further, since one argument of the sum
12640is not a constant. Unfortunately, @cite{(a+2)-2} is @emph{not} simplified 12797is not a constant. Unfortunately, @expr{(a+2)-2} is @emph{not} simplified
12641because the top-level @samp{-} operator's arguments are not both 12798because the top-level @samp{-} operator's arguments are not both
12642constant numbers (one of them is the formula @cite{a+2}). 12799constant numbers (one of them is the formula @expr{a+2}).
12643A constant is a number or other numeric object (such as a constant 12800A constant is a number or other numeric object (such as a constant
12644error form or modulo form), or a vector all of whose 12801error form or modulo form), or a vector all of whose
12645elements are constant.@refill 12802elements are constant.
12646 12803
12647@kindex m D 12804@kindex m D
12648@pindex calc-default-simplify-mode 12805@pindex calc-default-simplify-mode
12649The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the 12806The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the
12650default simplifications for all formulas. This includes many easy and 12807default simplifications for all formulas. This includes many easy and
12651fast algebraic simplifications such as @cite{a+0} to @cite{a}, and 12808fast algebraic simplifications such as @expr{a+0} to @expr{a}, and
12652@cite{a + 2 a} to @cite{3 a}, as well as evaluating functions like 12809@expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like
12653@cite{@t{deriv}(x^2, x)} to @cite{2 x}. 12810@texline @t{deriv}@expr{(x^2,x)}
12811@infoline @expr{@t{deriv}(x^2, x)}
12812to @expr{2 x}.
12654 12813
12655@kindex m B 12814@kindex m B
12656@pindex calc-bin-simplify-mode 12815@pindex calc-bin-simplify-mode
@@ -12681,13 +12840,13 @@ simplification; it applies the command @kbd{u s}
12681(@code{calc-simplify-units}), which in turn 12840(@code{calc-simplify-units}), which in turn
12682is a superset of @kbd{a s}. In this mode, variable names which 12841is a superset of @kbd{a s}. In this mode, variable names which
12683are identifiable as unit names (like @samp{mm} for ``millimeters'') 12842are identifiable as unit names (like @samp{mm} for ``millimeters'')
12684are simplified with their unit definitions in mind.@refill 12843are simplified with their unit definitions in mind.
12685 12844
12686A common technique is to set the simplification mode down to the lowest 12845A common technique is to set the simplification mode down to the lowest
12687amount of simplification you will allow to be applied automatically, then 12846amount of simplification you will allow to be applied automatically, then
12688use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to 12847use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to
12689perform higher types of simplifications on demand. @xref{Algebraic 12848perform higher types of simplifications on demand. @xref{Algebraic
12690Definitions}, for another sample use of no-simplification mode.@refill 12849Definitions}, for another sample use of no-simplification mode.
12691 12850
12692@node Declarations, Display Modes, Simplification Modes, Mode Settings 12851@node Declarations, Display Modes, Simplification Modes, Mode Settings
12693@section Declarations 12852@section Declarations
@@ -12949,8 +13108,8 @@ The value is a constant with respect to other variables.
12949Calc does not check the declarations for a variable when you store 13108Calc does not check the declarations for a variable when you store
12950a value in it. However, storing @i{-3.5} in a variable that has 13109a value in it. However, storing @i{-3.5} in a variable that has
12951been declared @code{pos}, @code{int}, or @code{matrix} may have 13110been declared @code{pos}, @code{int}, or @code{matrix} may have
12952unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @cite{3.5} 13111unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5}
12953if it substitutes the value first, or to @cite{-3.5} if @code{x} 13112if it substitutes the value first, or to @expr{-3.5} if @code{x}
12954was declared @code{pos} and the formula @samp{sqrt(x^2)} is 13113was declared @code{pos} and the formula @samp{sqrt(x^2)} is
12955simplified to @samp{x} before the value is substituted. Before 13114simplified to @samp{x} before the value is substituted. Before
12956using a variable for a new purpose, it is best to use @kbd{s d} 13115using a variable for a new purpose, it is best to use @kbd{s d}
@@ -13018,7 +13177,7 @@ includes integers, fractions, floats, real error forms, and intervals.
13018@end ignore 13177@end ignore
13019@tindex dimag 13178@tindex dimag
13020The @code{dimag} function checks if its argument is imaginary, 13179The @code{dimag} function checks if its argument is imaginary,
13021i.e., is mathematically equal to a real number times @cite{i}. 13180i.e., is mathematically equal to a real number times @expr{i}.
13022 13181
13023@ignore 13182@ignore
13024@starindex 13183@starindex
@@ -13036,7 +13195,7 @@ The @code{dpos} function checks for positive (but nonzero) reals.
13036The @code{dneg} function checks for negative reals. The @code{dnonneg} 13195The @code{dneg} function checks for negative reals. The @code{dnonneg}
13037function checks for nonnegative reals, i.e., reals greater than or 13196function checks for nonnegative reals, i.e., reals greater than or
13038equal to zero. Note that the @kbd{a s} command can simplify an 13197equal to zero. Note that the @kbd{a s} command can simplify an
13039expression like @cite{x > 0} to 1 or 0 using @code{dpos}, and that 13198expression like @expr{x > 0} to 1 or 0 using @code{dpos}, and that
13040@kbd{a s} is effectively applied to all conditions in rewrite rules, 13199@kbd{a s} is effectively applied to all conditions in rewrite rules,
13041so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg} 13200so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg}
13042are rarely necessary. 13201are rarely necessary.
@@ -13105,7 +13264,7 @@ The commands in this section are two-key sequences beginning with the
13105(@code{calc-line-breaking}) commands are described elsewhere; 13264(@code{calc-line-breaking}) commands are described elsewhere;
13106@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively. 13265@pxref{Stack Basics} and @pxref{Normal Language Modes}, respectively.
13107Display formats for vectors and matrices are also covered elsewhere; 13266Display formats for vectors and matrices are also covered elsewhere;
13108@pxref{Vector and Matrix Formats}.@refill 13267@pxref{Vector and Matrix Formats}.
13109 13268
13110One thing all display modes have in common is their treatment of the 13269One thing all display modes have in common is their treatment of the
13111@kbd{H} prefix. This prefix causes any mode command that would normally 13270@kbd{H} prefix. This prefix causes any mode command that would normally
@@ -13165,7 +13324,7 @@ binary, octal, hexadecimal, and decimal as the current display radix,
13165respectively. Numbers can always be entered in any radix, though the 13324respectively. Numbers can always be entered in any radix, though the
13166current radix is used as a default if you press @kbd{#} without any initial 13325current radix is used as a default if you press @kbd{#} without any initial
13167digits. A number entered without a @kbd{#} is @emph{always} interpreted 13326digits. A number entered without a @kbd{#} is @emph{always} interpreted
13168as decimal.@refill 13327as decimal.
13169 13328
13170@kindex d r 13329@kindex d r
13171@pindex calc-radix 13330@pindex calc-radix
@@ -13180,10 +13339,12 @@ Integers normally are displayed with however many digits are necessary to
13180represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) 13339represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros})
13181command causes integers to be padded out with leading zeros according to the 13340command causes integers to be padded out with leading zeros according to the
13182current binary word size. (@xref{Binary Functions}, for a discussion of 13341current binary word size. (@xref{Binary Functions}, for a discussion of
13183word size.) If the absolute value of the word size is @cite{w}, all integers 13342word size.) If the absolute value of the word size is @expr{w}, all integers
13184are displayed with at least enough digits to represent @c{$2^w-1$} 13343are displayed with at least enough digits to represent
13185@cite{(2^w)-1} in the 13344@texline @tmath{2^w-1}
13186current radix. (Larger integers will still be displayed in their entirety.) 13345@infoline @expr{(2^w)-1}
13346in the current radix. (Larger integers will still be displayed in their
13347entirety.)
13187 13348
13188@node Grouping Digits, Float Formats, Radix Modes, Display Modes 13349@node Grouping Digits, Float Formats, Radix Modes, Display Modes
13189@subsection Grouping Digits 13350@subsection Grouping Digits
@@ -13202,10 +13363,10 @@ separated by commas.
13202The @kbd{d g} command toggles grouping on and off. 13363The @kbd{d g} command toggles grouping on and off.
13203With a numerix prefix of 0, this command displays the current state of 13364With a numerix prefix of 0, this command displays the current state of
13204the grouping flag; with an argument of minus one it disables grouping; 13365the grouping flag; with an argument of minus one it disables grouping;
13205with a positive argument @cite{N} it enables grouping on every @cite{N} 13366with a positive argument @expr{N} it enables grouping on every @expr{N}
13206digits. For floating-point numbers, grouping normally occurs only 13367digits. For floating-point numbers, grouping normally occurs only
13207before the decimal point. A negative prefix argument @cite{-N} enables 13368before the decimal point. A negative prefix argument @expr{-N} enables
13208grouping every @cite{N} digits both before and after the decimal point.@refill 13369grouping every @expr{N} digits both before and after the decimal point.
13209 13370
13210@kindex d , 13371@kindex d ,
13211@pindex calc-group-char 13372@pindex calc-group-char
@@ -13298,7 +13459,7 @@ numbers, and commas to separate elements in a list.
13298There are three supported notations for complex numbers in rectangular 13459There are three supported notations for complex numbers in rectangular
13299form. The default is as a pair of real numbers enclosed in parentheses 13460form. The default is as a pair of real numbers enclosed in parentheses
13300and separated by a comma: @samp{(a,b)}. The @kbd{d c} 13461and separated by a comma: @samp{(a,b)}. The @kbd{d c}
13301(@code{calc-complex-notation}) command selects this style.@refill 13462(@code{calc-complex-notation}) command selects this style.
13302 13463
13303@kindex d i 13464@kindex d i
13304@pindex calc-i-notation 13465@pindex calc-i-notation
@@ -13307,7 +13468,7 @@ and separated by a comma: @samp{(a,b)}. The @kbd{d c}
13307The other notations are @kbd{d i} (@code{calc-i-notation}), in which 13468The other notations are @kbd{d i} (@code{calc-i-notation}), in which
13308numbers are displayed in @samp{a+bi} form, and @kbd{d j} 13469numbers are displayed in @samp{a+bi} form, and @kbd{d j}
13309(@code{calc-j-notation}) which displays the form @samp{a+bj} preferred 13470(@code{calc-j-notation}) which displays the form @samp{a+bj} preferred
13310in some disciplines.@refill 13471in some disciplines.
13311 13472
13312@cindex @code{i} variable 13473@cindex @code{i} variable
13313@vindex i 13474@vindex i
@@ -13318,7 +13479,7 @@ this formula and you have not changed the variable @samp{i}, the @samp{i}
13318will be interpreted as @samp{(0,1)} and the formula will be simplified 13479will be interpreted as @samp{(0,1)} and the formula will be simplified
13319to @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not} 13480to @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not}
13320interpret the formula @samp{2 + 3 * i} as a complex number. 13481interpret the formula @samp{2 + 3 * i} as a complex number.
13321@xref{Variables}, under ``special constants.''@refill 13482@xref{Variables}, under ``special constants.''
13322 13483
13323@node Fraction Formats, HMS Formats, Complex Formats, Display Modes 13484@node Fraction Formats, HMS Formats, Complex Formats, Display Modes
13324@subsection Fraction Formats 13485@subsection Fraction Formats
@@ -13346,12 +13507,12 @@ a number. For example: @samp{:10} or @samp{+/3}. In this case,
13346Calc adjusts all fractions that are displayed to have the specified 13507Calc adjusts all fractions that are displayed to have the specified
13347denominator, if possible. Otherwise it adjusts the denominator to 13508denominator, if possible. Otherwise it adjusts the denominator to
13348be a multiple of the specified value. For example, in @samp{:6} mode 13509be a multiple of the specified value. For example, in @samp{:6} mode
13349the fraction @cite{1:6} will be unaffected, but @cite{2:3} will be 13510the fraction @expr{1:6} will be unaffected, but @expr{2:3} will be
13350displayed as @cite{4:6}, @cite{1:2} will be displayed as @cite{3:6}, 13511displayed as @expr{4:6}, @expr{1:2} will be displayed as @expr{3:6},
13351and @cite{1:8} will be displayed as @cite{3:24}. Integers are also 13512and @expr{1:8} will be displayed as @expr{3:24}. Integers are also
13352affected by this mode: 3 is displayed as @cite{18:6}. Note that the 13513affected by this mode: 3 is displayed as @expr{18:6}. Note that the
13353format @samp{:1} writes fractions the same as @samp{:}, but it writes 13514format @samp{:1} writes fractions the same as @samp{:}, but it writes
13354integers as @cite{n:1}. 13515integers as @expr{n:1}.
13355 13516
13356The fraction format does not affect the way fractions or integers are 13517The fraction format does not affect the way fractions or integers are
13357stored, only the way they appear on the screen. The fraction format 13518stored, only the way they appear on the screen. The fraction format
@@ -13710,15 +13871,15 @@ operations. This is similar to the Emacs ``narrowing'' feature, except
13710that the values below the @samp{.} are @emph{visible}, just temporarily 13871that the values below the @samp{.} are @emph{visible}, just temporarily
13711frozen. This feature allows you to keep several independent calculations 13872frozen. This feature allows you to keep several independent calculations
13712running at once in different parts of the stack, or to apply a certain 13873running at once in different parts of the stack, or to apply a certain
13713command to an element buried deep in the stack.@refill 13874command to an element buried deep in the stack.
13714 13875
13715Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor 13876Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor
13716is on. Thus, this line and all those below it become hidden. To un-hide 13877is on. Thus, this line and all those below it become hidden. To un-hide
13717these lines, move down to the end of the buffer and press @w{@kbd{d t}}. 13878these lines, move down to the end of the buffer and press @w{@kbd{d t}}.
13718With a positive numeric prefix argument @cite{n}, @kbd{d t} hides the 13879With a positive numeric prefix argument @expr{n}, @kbd{d t} hides the
13719bottom @cite{n} values in the buffer. With a negative argument, it hides 13880bottom @expr{n} values in the buffer. With a negative argument, it hides
13720all but the top @cite{n} values. With an argument of zero, it hides zero 13881all but the top @expr{n} values. With an argument of zero, it hides zero
13721values, i.e., moves the @samp{.} all the way down to the bottom.@refill 13882values, i.e., moves the @samp{.} all the way down to the bottom.
13722 13883
13723@kindex d [ 13884@kindex d [
13724@pindex calc-truncate-up 13885@pindex calc-truncate-up
@@ -13726,7 +13887,7 @@ values, i.e., moves the @samp{.} all the way down to the bottom.@refill
13726@pindex calc-truncate-down 13887@pindex calc-truncate-down
13727The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]} 13888The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]}
13728(@code{calc-truncate-down}) commands move the @samp{.} up or down one 13889(@code{calc-truncate-down}) commands move the @samp{.} up or down one
13729line at a time (or several lines with a prefix argument).@refill 13890line at a time (or several lines with a prefix argument).
13730 13891
13731@node Justification, Labels, Truncating the Stack, Display Modes 13892@node Justification, Labels, Truncating the Stack, Display Modes
13732@subsection Justification 13893@subsection Justification
@@ -13743,7 +13904,7 @@ control this arrangement by typing @kbd{d <} (@code{calc-left-justify}),
13743@kbd{d >} (@code{calc-right-justify}), or @kbd{d =} 13904@kbd{d >} (@code{calc-right-justify}), or @kbd{d =}
13744(@code{calc-center-justify}). For example, in right-justification mode, 13905(@code{calc-center-justify}). For example, in right-justification mode,
13745stack entries are displayed flush-right against the right edge of the 13906stack entries are displayed flush-right against the right edge of the
13746window.@refill 13907window.
13747 13908
13748If you change the width of the Calculator window you may have to type 13909If you change the width of the Calculator window you may have to type
13749@kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered 13910@kbd{d @key{SPC}} (@code{calc-refresh}) to re-align right-justified or centered
@@ -13933,10 +14094,10 @@ One slight ambiguity of Big notation is that
13933@end example 14094@end example
13934 14095
13935@noindent 14096@noindent
13936can represent either the negative rational number @cite{-3:4}, or the 14097can represent either the negative rational number @expr{-3:4}, or the
13937actual expression @samp{-(3/4)}; but the latter formula would normally 14098actual expression @samp{-(3/4)}; but the latter formula would normally
13938never be displayed because it would immediately be evaluated to 14099never be displayed because it would immediately be evaluated to
13939@cite{-3:4} or @cite{-0.75}, so this ambiguity is not a problem in 14100@expr{-3:4} or @expr{-0.75}, so this ambiguity is not a problem in
13940typical use. 14101typical use.
13941 14102
13942Non-decimal numbers are displayed with subscripts. Thus there is no 14103Non-decimal numbers are displayed with subscripts. Thus there is no
@@ -14061,7 +14222,7 @@ and displayed in @TeX{} notation, as in @samp{\sin\left( a \over b \right)}.
14061Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these 14222Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these
14062should be omitted when interfacing with Calc. To Calc, the @samp{$} sign 14223should be omitted when interfacing with Calc. To Calc, the @samp{$} sign
14063has the same meaning it always does in algebraic formulas (a reference to 14224has the same meaning it always does in algebraic formulas (a reference to
14064an existing entry on the stack).@refill 14225an existing entry on the stack).
14065 14226
14066Complex numbers are displayed as in @samp{3 + 4i}. Fractions and 14227Complex numbers are displayed as in @samp{3 + 4i}. Fractions and
14067quotients are written using @code{\over}; 14228quotients are written using @code{\over};
@@ -14073,7 +14234,7 @@ ceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc.
14073The words @code{\left} and @code{\right} are ignored when reading 14234The words @code{\left} and @code{\right} are ignored when reading
14074formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written 14235formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written
14075as @code{\infty}; when read, @code{\infty} always translates to 14236as @code{\infty}; when read, @code{\infty} always translates to
14076@code{inf}.@refill 14237@code{inf}.
14077 14238
14078Function calls are written the usual way, with the function name followed 14239Function calls are written the usual way, with the function name followed
14079by the arguments in parentheses. However, functions for which @TeX{} has 14240by the arguments in parentheses. However, functions for which @TeX{} has
@@ -14081,9 +14242,11 @@ special names (like @code{\sin}) will use curly braces instead of
14081parentheses for very simple arguments. During input, curly braces and 14242parentheses for very simple arguments. During input, curly braces and
14082parentheses work equally well for grouping, but when the document is 14243parentheses work equally well for grouping, but when the document is
14083formatted the curly braces will be invisible. Thus the printed result is 14244formatted the curly braces will be invisible. Thus the printed result is
14084@c{$\sin{2 x}$} 14245@texline @tmath{\sin{2 x}}
14085@cite{sin 2x} but @c{$\sin(2 + x)$} 14246@infoline @expr{sin 2x}
14086@cite{sin(2 + x)}. 14247but
14248@texline @tmath{\sin(2 + x)}.
14249@infoline @expr{sin(2 + x)}.
14087 14250
14088Function and variable names not treated specially by @TeX{} are simply 14251Function and variable names not treated specially by @TeX{} are simply
14089written out as-is, which will cause them to come out in italic letters 14252written out as-is, which will cause them to come out in italic letters
@@ -14244,7 +14407,6 @@ sin(a^2 / b_i)
14244@end group 14407@end group
14245@end example 14408@end example
14246@tex 14409@tex
14247\let\rm\goodrm
14248$$ \sin\left( a^2 \over b_i \right) $$ 14410$$ \sin\left( a^2 \over b_i \right) $$
14249@end tex 14411@end tex
14250@sp 1 14412@sp 1
@@ -14282,7 +14444,7 @@ $$ [|a|, \left| a \over b \right|,
14282@end group 14444@end group
14283@end example 14445@end example
14284@tex 14446@tex
14285\turnoffactive\let\rm\goodrm 14447\turnoffactive
14286$$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$ 14448$$ [\sin{a}, \sin{2 a}, \sin(2 + a), \sin\left( {a \over b} \right)] $$
14287@end tex 14449@end tex
14288@sp 2 14450@sp 2
@@ -14300,7 +14462,6 @@ First with plain @kbd{d T}, then with @kbd{C-u d T}, then finally with
14300@end group 14462@end group
14301@end example 14463@end example
14302@tex 14464@tex
14303\let\rm\goodrm
14304$$ [f(a), foo(bar), \sin{\pi}] $$ 14465$$ [f(a), foo(bar), \sin{\pi}] $$
14305$$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$ 14466$$ [f(a), \hbox{foo}(\hbox{bar}), \sin{\pi}] $$
14306$$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$ 14467$$ [f(a), \tilde F(\hbox{bar}), \sin{\pi}] $$
@@ -14453,7 +14614,7 @@ written @code{Pi}, @code{E}, @code{I}, @code{GoldenRatio}, @code{EulerGamma},
14453Mathematica mode. 14614Mathematica mode.
14454Non-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point 14615Non-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point
14455numbers in scientific notation are written @samp{1.23*10.^3}. 14616numbers in scientific notation are written @samp{1.23*10.^3}.
14456Subscripts use double square brackets: @samp{a[[i]]}.@refill 14617Subscripts use double square brackets: @samp{a[[i]]}.
14457 14618
14458@node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes 14619@node Maple Language Mode, Compositions, Mathematica Language Mode, Language Modes
14459@subsection Maple Language Mode 14620@subsection Maple Language Mode
@@ -14594,9 +14755,9 @@ mod 400
14594=> 40 14755=> 40
14595@end example 14756@end example
14596 14757
14597The general rule is that if an operator with precedence @cite{n} 14758The general rule is that if an operator with precedence @expr{n}
14598occurs as an argument to an operator with precedence @cite{m}, then 14759occurs as an argument to an operator with precedence @expr{m}, then
14599the argument is enclosed in parentheses if @cite{n < m}. Top-level 14760the argument is enclosed in parentheses if @expr{n < m}. Top-level
14600expressions and expressions which are function arguments, vector 14761expressions and expressions which are function arguments, vector
14601components, etc., are formatted with precedence zero (so that they 14762components, etc., are formatted with precedence zero (so that they
14602normally never get additional parentheses). 14763normally never get additional parentheses).
@@ -15579,8 +15740,10 @@ Command is @kbd{m p}.
15579 15740
15580@item 15741@item
15581Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar 15742Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar
15582mode, @i{-2} for matrix mode, or @var{N} for @c{$N\times N$} 15743mode, @i{-2} for matrix mode, or @var{N} for
15583@var{N}x@var{N} matrix mode. Command is @kbd{m v}. 15744@texline @tmath{N\times N}
15745@infoline @var{N}x@var{N}
15746matrix mode. Command is @kbd{m v}.
15584 15747
15585@item 15748@item
15586Simplification mode. Default is 1. Value is @i{-1} for off (@kbd{m O}), 15749Simplification mode. Default is 1. Value is @i{-1} for off (@kbd{m O}),
@@ -15906,9 +16069,9 @@ error form to a plain symbolic formula (as in @samp{(a +/- b) + c}) will not
15906work, for the same reasons just mentioned for vectors. Instead you must 16069work, for the same reasons just mentioned for vectors. Instead you must
15907write @samp{(a +/- b) + (c +/- 0)}. 16070write @samp{(a +/- b) + (c +/- 0)}.
15908 16071
15909If both arguments of @kbd{+} are modulo forms with equal values of @cite{M}, 16072If both arguments of @kbd{+} are modulo forms with equal values of @expr{M},
15910or if one argument is a modulo form and the other a plain number, the 16073or if one argument is a modulo form and the other a plain number, the
15911result is a modulo form which represents the sum, modulo @cite{M}, of 16074result is a modulo form which represents the sum, modulo @expr{M}, of
15912the two values. 16075the two values.
15913 16076
15914If both arguments of @kbd{+} are intervals, the result is an interval 16077If both arguments of @kbd{+} are intervals, the result is an interval
@@ -15964,19 +16127,19 @@ whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @samp{[0 ..@: 9]}.
15964@end ignore 16127@end ignore
15965@tindex / 16128@tindex /
15966The @kbd{/} (@code{calc-divide}) command divides two numbers. When 16129The @kbd{/} (@code{calc-divide}) command divides two numbers. When
15967dividing a scalar @cite{B} by a square matrix @cite{A}, the computation 16130dividing a scalar @expr{B} by a square matrix @expr{A}, the computation
15968performed is @cite{B} times the inverse of @cite{A}. This also occurs 16131performed is @expr{B} times the inverse of @expr{A}. This also occurs
15969if @cite{B} is itself a vector or matrix, in which case the effect is 16132if @expr{B} is itself a vector or matrix, in which case the effect is
15970to solve the set of linear equations represented by @cite{B}. If @cite{B} 16133to solve the set of linear equations represented by @expr{B}. If @expr{B}
15971is a matrix with the same number of rows as @cite{A}, or a plain vector 16134is a matrix with the same number of rows as @expr{A}, or a plain vector
15972(which is interpreted here as a column vector), then the equation 16135(which is interpreted here as a column vector), then the equation
15973@cite{A X = B} is solved for the vector or matrix @cite{X}. Otherwise, 16136@expr{A X = B} is solved for the vector or matrix @expr{X}. Otherwise,
15974if @cite{B} is a non-square matrix with the same number of @emph{columns} 16137if @expr{B} is a non-square matrix with the same number of @emph{columns}
15975as @cite{A}, the equation @cite{X A = B} is solved. If you wish a vector 16138as @expr{A}, the equation @expr{X A = B} is solved. If you wish a vector
15976@cite{B} to be interpreted as a row vector to be solved as @cite{X A = B}, 16139@expr{B} to be interpreted as a row vector to be solved as @expr{X A = B},
15977make it into a one-row matrix with @kbd{C-u 1 v p} first. To force a 16140make it into a one-row matrix with @kbd{C-u 1 v p} first. To force a
15978left-handed solution with a square matrix @cite{B}, transpose @cite{A} and 16141left-handed solution with a square matrix @expr{B}, transpose @expr{A} and
15979@cite{B} before dividing, then transpose the result. 16142@expr{B} before dividing, then transpose the result.
15980 16143
15981HMS forms can be divided by real numbers or by other HMS forms. Error 16144HMS forms can be divided by real numbers or by other HMS forms. Error
15982forms can be divided in any combination of ways. Modulo forms where both 16145forms can be divided in any combination of ways. Modulo forms where both
@@ -16026,10 +16189,10 @@ operation when the arguments are integers, it avoids problems that
16026@tindex % 16189@tindex %
16027The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') 16190The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'')
16028operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined 16191operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined
16029for all real numbers @cite{a} and @cite{b} (except @cite{b=0}). For 16192for all real numbers @expr{a} and @expr{b} (except @expr{b=0}). For
16030positive @cite{b}, the result will always be between 0 (inclusive) and 16193positive @expr{b}, the result will always be between 0 (inclusive) and
16031@cite{b} (exclusive). Modulo does not work for HMS forms and error forms. 16194@expr{b} (exclusive). Modulo does not work for HMS forms and error forms.
16032If @cite{a} is a modulo form, its modulo is changed to @cite{b}, which 16195If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which
16033must be positive real number. 16196must be positive real number.
16034 16197
16035@kindex : 16198@kindex :
@@ -16083,7 +16246,7 @@ zero depending on the sign of @samp{a}.
16083@tindex inv 16246@tindex inv
16084@cindex Reciprocal 16247@cindex Reciprocal
16085The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the 16248The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the
16086reciprocal of a number, i.e., @cite{1 / x}. Operating on a square 16249reciprocal of a number, i.e., @expr{1 / x}. Operating on a square
16087matrix, it computes the inverse of that matrix. 16250matrix, it computes the inverse of that matrix.
16088 16251
16089@kindex Q 16252@kindex Q
@@ -16098,8 +16261,8 @@ complex number whose form is determined by the current Polar Mode.
16098@tindex hypot 16261@tindex hypot
16099The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square 16262The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square
16100root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)} 16263root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)}
16101is the length of the hypotenuse of a right triangle with sides @cite{a} 16264is the length of the hypotenuse of a right triangle with sides @expr{a}
16102and @cite{b}. If the arguments are complex numbers, their squared 16265and @expr{b}. If the arguments are complex numbers, their squared
16103magnitudes are used. 16266magnitudes are used.
16104 16267
16105@kindex f Q 16268@kindex f Q
@@ -16124,7 +16287,7 @@ The @kbd{f n} (@code{calc-min}) [@code{min}] and @kbd{f x} (@code{calc-max})
16124respectively. These commands also work on HMS forms, date forms, 16287respectively. These commands also work on HMS forms, date forms,
16125intervals, and infinities. (In algebraic expressions, these functions 16288intervals, and infinities. (In algebraic expressions, these functions
16126take any number of arguments and return the maximum or minimum among 16289take any number of arguments and return the maximum or minimum among
16127all the arguments.)@refill 16290all the arguments.)
16128 16291
16129@kindex f M 16292@kindex f M
16130@kindex f X 16293@kindex f X
@@ -16133,17 +16296,18 @@ all the arguments.)@refill
16133@pindex calc-xpon-part 16296@pindex calc-xpon-part
16134@tindex xpon 16297@tindex xpon
16135The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts 16298The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts
16136the ``mantissa'' part @cite{m} of its floating-point argument; @kbd{f X} 16299the ``mantissa'' part @expr{m} of its floating-point argument; @kbd{f X}
16137(@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part 16300(@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part
16138@cite{e}. The original number is equal to @c{$m \times 10^e$} 16301@expr{e}. The original number is equal to
16139@cite{m * 10^e}, 16302@texline @tmath{m \times 10^e},
16140where @cite{m} is in the interval @samp{[1.0 ..@: 10.0)} except that 16303@infoline @expr{m * 10^e},
16141@cite{m=e=0} if the original number is zero. For integers 16304where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that
16305@expr{m=e=0} if the original number is zero. For integers
16142and fractions, @code{mant} returns the number unchanged and @code{xpon} 16306and fractions, @code{mant} returns the number unchanged and @code{xpon}
16143returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be 16307returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be
16144used to ``unpack'' a floating-point number; this produces an integer 16308used to ``unpack'' a floating-point number; this produces an integer
16145mantissa and exponent, with the constraint that the mantissa is not 16309mantissa and exponent, with the constraint that the mantissa is not
16146a multiple of ten (again except for the @cite{m=e=0} case).@refill 16310a multiple of ten (again except for the @expr{m=e=0} case).
16147 16311
16148@kindex f S 16312@kindex f S
16149@pindex calc-scale-float 16313@pindex calc-scale-float
@@ -16152,7 +16316,7 @@ The @kbd{f S} (@code{calc-scale-float}) [@code{scf}] function scales a number
16152by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any 16316by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any
16153real @samp{x}. The second argument must be an integer, but the first 16317real @samp{x}. The second argument must be an integer, but the first
16154may actually be any numeric value. For example, @samp{scf(5,-2) = 0.05} 16318may actually be any numeric value. For example, @samp{scf(5,-2) = 0.05}
16155or @samp{1:20} depending on the current Fraction Mode.@refill 16319or @samp{1:20} depending on the current Fraction Mode.
16156 16320
16157@kindex f [ 16321@kindex f [
16158@kindex f ] 16322@kindex f ]
@@ -16167,10 +16331,12 @@ floating-point numbers, the change is by one unit in the last place.
16167For example, incrementing @samp{12.3456} when the current precision 16331For example, incrementing @samp{12.3456} when the current precision
16168is 6 digits yields @samp{12.3457}. If the current precision had been 16332is 6 digits yields @samp{12.3457}. If the current precision had been
161698 digits, the result would have been @samp{12.345601}. Incrementing 163338 digits, the result would have been @samp{12.345601}. Incrementing
16170@samp{0.0} produces @c{$10^{-p}$} 16334@samp{0.0} produces
16171@cite{10^-p}, where @cite{p} is the current 16335@texline @tmath{10^{-p}},
16336@infoline @expr{10^-p},
16337where @expr{p} is the current
16172precision. These operations are defined only on integers and floats. 16338precision. These operations are defined only on integers and floats.
16173With numeric prefix arguments, they change the number by @cite{n} units. 16339With numeric prefix arguments, they change the number by @expr{n} units.
16174 16340
16175Note that incrementing followed by decrementing, or vice-versa, will 16341Note that incrementing followed by decrementing, or vice-versa, will
16176almost but not quite always cancel out. Suppose the precision is 16342almost but not quite always cancel out. Suppose the precision is
@@ -16207,7 +16373,7 @@ expressed as an integer-valued floating-point number.
16207The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command 16373The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command
16208truncates a real number to the next lower integer, i.e., toward minus 16374truncates a real number to the next lower integer, i.e., toward minus
16209infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces 16375infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
16210@i{-4}.@refill 16376@i{-4}.
16211 16377
16212@kindex I F 16378@kindex I F
16213@pindex calc-ceiling 16379@pindex calc-ceiling
@@ -16219,7 +16385,7 @@ infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces
16219@kindex H I F 16385@kindex H I F
16220The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] 16386The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}]
16221command truncates toward positive infinity. Thus @kbd{3.6 I F} produces 16387command truncates toward positive infinity. Thus @kbd{3.6 I F} produces
162224, and @kbd{_3.6 I F} produces @i{-3}.@refill 163884, and @kbd{_3.6 I F} produces @i{-3}.
16223 16389
16224@kindex R 16390@kindex R
16225@pindex calc-round 16391@pindex calc-round
@@ -16233,7 +16399,7 @@ The @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command
16233rounds to the nearest integer. When the fractional part is .5 exactly, 16399rounds to the nearest integer. When the fractional part is .5 exactly,
16234this command rounds away from zero. (All other rounding in the 16400this command rounds away from zero. (All other rounding in the
16235Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 16401Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4
16236but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill 16402but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.
16237 16403
16238@kindex I R 16404@kindex I R
16239@pindex calc-trunc 16405@pindex calc-trunc
@@ -16246,7 +16412,7 @@ but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill
16246The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] 16412The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}]
16247command truncates toward zero. In other words, it ``chops off'' 16413command truncates toward zero. In other words, it ``chops off''
16248everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and 16414everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and
16249@kbd{_3.6 I R} produces @i{-3}.@refill 16415@kbd{_3.6 I R} produces @i{-3}.
16250 16416
16251These functions may not be applied meaningfully to error forms, but they 16417These functions may not be applied meaningfully to error forms, but they
16252do work for intervals. As a convenience, applying @code{floor} to a 16418do work for intervals. As a convenience, applying @code{floor} to a
@@ -16284,7 +16450,7 @@ subtle point here is that the number being fed to @code{rounde} will
16284already have been rounded to the current precision before @code{rounde} 16450already have been rounded to the current precision before @code{rounde}
16285begins. For example, @samp{rounde(2.500001)} with a current precision 16451begins. For example, @samp{rounde(2.500001)} with a current precision
16286of 6 will incorrectly, or at least surprisingly, yield 2 because the 16452of 6 will incorrectly, or at least surprisingly, yield 2 because the
16287argument will first have been rounded down to @cite{2.5} (which 16453argument will first have been rounded down to @expr{2.5} (which
16288@code{rounde} sees as an exact tie between 2 and 3). 16454@code{rounde} sees as an exact tie between 2 and 3).
16289 16455
16290Each of these functions, when written in algebraic formulas, allows 16456Each of these functions, when written in algebraic formulas, allows
@@ -16298,7 +16464,7 @@ no second argument at all.
16298@cindex Fractional part of a number 16464@cindex Fractional part of a number
16299To compute the fractional part of a number (i.e., the amount which, when 16465To compute the fractional part of a number (i.e., the amount which, when
16300added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n} 16466added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n}
16301modulo 1 using the @code{%} command.@refill 16467modulo 1 using the @code{%} command.
16302 16468
16303Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm), 16469Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm),
16304and @kbd{f Q} (integer square root) commands, which are analogous to 16470and @kbd{f Q} (integer square root) commands, which are analogous to
@@ -16313,8 +16479,8 @@ arguments and return the result rounded down to an integer.
16313@pindex calc-conj 16479@pindex calc-conj
16314@tindex conj 16480@tindex conj
16315The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the 16481The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the
16316complex conjugate of a number. For complex number @cite{a+bi}, the 16482complex conjugate of a number. For complex number @expr{a+bi}, the
16317complex conjugate is @cite{a-bi}. If the argument is a real number, 16483complex conjugate is @expr{a-bi}. If the argument is a real number,
16318this command leaves it the same. If the argument is a vector or matrix, 16484this command leaves it the same. If the argument is a vector or matrix,
16319this command replaces each element by its complex conjugate. 16485this command replaces each element by its complex conjugate.
16320 16486
@@ -16324,15 +16490,15 @@ this command replaces each element by its complex conjugate.
16324The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the 16490The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the
16325``argument'' or polar angle of a complex number. For a number in polar 16491``argument'' or polar angle of a complex number. For a number in polar
16326notation, this is simply the second component of the pair 16492notation, this is simply the second component of the pair
16327`@t{(}@var{r}@t{;}@c{$\theta$} 16493@texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}'.
16328@var{theta}@t{)}'. 16494@infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'.
16329The result is expressed according to the current angular mode and will 16495The result is expressed according to the current angular mode and will
16330be in the range @i{-180} degrees (exclusive) to @i{+180} degrees 16496be in the range @i{-180} degrees (exclusive) to @i{+180} degrees
16331(inclusive), or the equivalent range in radians.@refill 16497(inclusive), or the equivalent range in radians.
16332 16498
16333@pindex calc-imaginary 16499@pindex calc-imaginary
16334The @code{calc-imaginary} command multiplies the number on the 16500The @code{calc-imaginary} command multiplies the number on the
16335top of the stack by the imaginary number @cite{i = (0,1)}. This 16501top of the stack by the imaginary number @expr{i = (0,1)}. This
16336command is not normally bound to a key in Calc, but it is available 16502command is not normally bound to a key in Calc, but it is available
16337on the @key{IMAG} button in Keypad Mode. 16503on the @key{IMAG} button in Keypad Mode.
16338 16504
@@ -16342,14 +16508,14 @@ on the @key{IMAG} button in Keypad Mode.
16342The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number 16508The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number
16343by its real part. This command has no effect on real numbers. (As an 16509by its real part. This command has no effect on real numbers. (As an
16344added convenience, @code{re} applied to a modulo form extracts 16510added convenience, @code{re} applied to a modulo form extracts
16345the value part.)@refill 16511the value part.)
16346 16512
16347@kindex f i 16513@kindex f i
16348@pindex calc-im 16514@pindex calc-im
16349@tindex im 16515@tindex im
16350The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number 16516The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number
16351by its imaginary part; real numbers are converted to zero. With a vector 16517by its imaginary part; real numbers are converted to zero. With a vector
16352or matrix argument, these functions operate element-wise.@refill 16518or matrix argument, these functions operate element-wise.
16353 16519
16354@ignore 16520@ignore
16355@mindex v p 16521@mindex v p
@@ -16383,13 +16549,13 @@ to another; they are two-key sequences beginning with the letter @kbd{c}.
16383@tindex pfloat 16549@tindex pfloat
16384The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the 16550The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the
16385number on the top of the stack to floating-point form. For example, 16551number on the top of the stack to floating-point form. For example,
16386@cite{23} is converted to @cite{23.0}, @cite{3:2} is converted to 16552@expr{23} is converted to @expr{23.0}, @expr{3:2} is converted to
16387@cite{1.5}, and @cite{2.3} is left the same. If the value is a composite 16553@expr{1.5}, and @expr{2.3} is left the same. If the value is a composite
16388object such as a complex number or vector, each of the components is 16554object such as a complex number or vector, each of the components is
16389converted to floating-point. If the value is a formula, all numbers 16555converted to floating-point. If the value is a formula, all numbers
16390in the formula are converted to floating-point. Note that depending 16556in the formula are converted to floating-point. Note that depending
16391on the current floating-point precision, conversion to floating-point 16557on the current floating-point precision, conversion to floating-point
16392format may lose information.@refill 16558format may lose information.
16393 16559
16394As a special exception, integers which appear as powers or subscripts 16560As a special exception, integers which appear as powers or subscripts
16395are not floated by @kbd{c f}. If you really want to float a power, 16561are not floated by @kbd{c f}. If you really want to float a power,
@@ -16442,7 +16608,7 @@ which is analogous to @kbd{H c f} discussed above.
16442The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a 16608The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a
16443number into degrees form. The value on the top of the stack may be an 16609number into degrees form. The value on the top of the stack may be an
16444HMS form (interpreted as degrees-minutes-seconds), or a real number which 16610HMS form (interpreted as degrees-minutes-seconds), or a real number which
16445will be interpreted in radians regardless of the current angular mode.@refill 16611will be interpreted in radians regardless of the current angular mode.
16446 16612
16447@kindex c r 16613@kindex c r
16448@pindex calc-to-radians 16614@pindex calc-to-radians
@@ -16475,7 +16641,7 @@ This command is equivalent to the @code{rect} or @code{polar}
16475functions in algebraic formulas, depending on the direction of 16641functions in algebraic formulas, depending on the direction of
16476conversion. (It uses @code{polar}, except that if the argument is 16642conversion. (It uses @code{polar}, except that if the argument is
16477already a polar complex number, it uses @code{rect} instead. The 16643already a polar complex number, it uses @code{rect} instead. The
16478@kbd{I c p} command always uses @code{rect}.)@refill 16644@kbd{I c p} command always uses @code{rect}.)
16479 16645
16480@kindex c c 16646@kindex c c
16481@pindex calc-clean 16647@pindex calc-clean
@@ -16488,7 +16654,7 @@ are normalized. (Note that results will be undesirable if the current
16488angular mode is different from the one under which the number was 16654angular mode is different from the one under which the number was
16489produced!) Integers and fractions are generally unaffected by this 16655produced!) Integers and fractions are generally unaffected by this
16490operation. Vectors and formulas are cleaned by cleaning each component 16656operation. Vectors and formulas are cleaned by cleaning each component
16491number (i.e., pervasively).@refill 16657number (i.e., pervasively).
16492 16658
16493If the simplification mode is set below the default level, it is raised 16659If the simplification mode is set below the default level, it is raised
16494to the default level for the purposes of this command. Thus, @kbd{c c} 16660to the default level for the purposes of this command. Thus, @kbd{c c}
@@ -16809,7 +16975,7 @@ command for this function; use @kbd{C-u 12 t I} instead.
16809 16975
16810There is no @code{newday} function at all because @kbd{F} [@code{floor}] 16976There is no @code{newday} function at all because @kbd{F} [@code{floor}]
16811serves this purpose. Similarly, instead of @code{incday} and 16977serves this purpose. Similarly, instead of @code{incday} and
16812@code{incweek} simply use @cite{d + n} or @cite{d + 7 n}. 16978@code{incweek} simply use @expr{d + n} or @expr{d + 7 n}.
16813 16979
16814@xref{Basic Arithmetic}, for the @kbd{f ]} [@code{incr}] command 16980@xref{Basic Arithmetic}, for the @kbd{f ]} [@code{incr}] command
16815which can adjust a date/time form by a certain number of seconds. 16981which can adjust a date/time form by a certain number of seconds.
@@ -16870,12 +17036,12 @@ considered to be a holiday.
16870 17036
16871@item 17037@item
16872Any Calc formula which evaluates to one of the above three things. 17038Any Calc formula which evaluates to one of the above three things.
16873If the formula involves the variable @cite{y}, it stands for a 17039If the formula involves the variable @expr{y}, it stands for a
16874yearly repeating holiday; @cite{y} will take on various year 17040yearly repeating holiday; @expr{y} will take on various year
16875numbers like 1992. For example, @samp{date(y, 12, 25)} specifies 17041numbers like 1992. For example, @samp{date(y, 12, 25)} specifies
16876Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies 17042Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies
16877Thanksgiving (which is held on the fourth Thursday of November). 17043Thanksgiving (which is held on the fourth Thursday of November).
16878If the formula involves the variable @cite{m}, that variable 17044If the formula involves the variable @expr{m}, that variable
16879takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is 17045takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is
16880a holiday that takes place on the 15th of every month. 17046a holiday that takes place on the 15th of every month.
16881 17047
@@ -17290,7 +17456,7 @@ decrease: @kbd{50 @key{RET} 40 b %} produces @samp{-20%}, since 40 is
1729020% smaller than 50. (The answers are different in magnitude 1745620% smaller than 50. (The answers are different in magnitude
17291because, in the first case, we're increasing by 25% of 40, but 17457because, in the first case, we're increasing by 25% of 40, but
17292in the second case, we're decreasing by 20% of 50.) The effect 17458in the second case, we're decreasing by 20% of 50.) The effect
17293of @kbd{40 @key{RET} 50 b %} is to compute @cite{(50-40)/40}, converting 17459of @kbd{40 @key{RET} 50 b %} is to compute @expr{(50-40)/40}, converting
17294the answer to percentage form as if by @kbd{c %}. 17460the answer to percentage form as if by @kbd{c %}.
17295 17461
17296@node Future Value, Present Value, Percentages, Financial Functions 17462@node Future Value, Present Value, Percentages, Financial Functions
@@ -17334,7 +17500,7 @@ The algebraic functions @code{fv} and @code{fvb} accept an optional
17334fourth argument, which is used as an initial lump sum in the sense 17500fourth argument, which is used as an initial lump sum in the sense
17335of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n}, 17501of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n},
17336@var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment}) 17502@var{payment}, @var{initial}) = fv(@var{rate}, @var{n}, @var{payment})
17337+ fvl(@var{rate}, @var{n}, @var{initial})}.@refill 17503+ fvl(@var{rate}, @var{n}, @var{initial})}.
17338 17504
17339To illustrate the relationships between these functions, we could 17505To illustrate the relationships between these functions, we could
17340do the @code{fvb} calculation ``by hand'' using @code{fvl}. The 17506do the @code{fvb} calculation ``by hand'' using @code{fvl}. The
@@ -17352,7 +17518,7 @@ are now at the ends of the periods. The end of one year is the same
17352as the beginning of the next, so what this really means is that we've 17518as the beginning of the next, so what this really means is that we've
17353lost the payment at year zero (which contributed $1300.78), but we're 17519lost the payment at year zero (which contributed $1300.78), but we're
17354now counting the payment at year five (which, since it didn't have 17520now counting the payment at year five (which, since it didn't have
17355a chance to earn interest, counts as $1000). Indeed, @cite{5569.96 = 17521a chance to earn interest, counts as $1000). Indeed, @expr{5569.96 =
173565870.73 - 1300.78 + 1000} (give or take a bit of roundoff error). 175225870.73 - 1300.78 + 1000} (give or take a bit of roundoff error).
17357 17523
17358@node Present Value, Related Financial Functions, Future Value, Financial Functions 17524@node Present Value, Related Financial Functions, Future Value, Financial Functions
@@ -17382,7 +17548,7 @@ considering, which is @code{fv(9%, 4, 2000) = 9146.26}, with
17382the return from leaving the money in the bank, which is 17548the return from leaving the money in the bank, which is
17383@code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money 17549@code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money
17384you would have to put up in advance. The @code{pv} function 17550you would have to put up in advance. The @code{pv} function
17385finds the break-even point, @cite{x = 6479.44}, at which 17551finds the break-even point, @expr{x = 6479.44}, at which
17386@code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is 17552@code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is
17387the largest amount you should be willing to invest. 17553the largest amount you should be willing to invest.
17388 17554
@@ -17431,7 +17597,7 @@ vector statistical functions like @code{vsum}.
17431payment arguments, each either a vector or a plain number, all these 17597payment arguments, each either a vector or a plain number, all these
17432values are collected left-to-right into the complete list of payments. 17598values are collected left-to-right into the complete list of payments.
17433A numeric prefix argument on the @kbd{b N} command says how many 17599A numeric prefix argument on the @kbd{b N} command says how many
17434payment values or vectors to take from the stack.@refill 17600payment values or vectors to take from the stack.
17435 17601
17436@kindex I b N 17602@kindex I b N
17437@tindex npvb 17603@tindex npvb
@@ -17453,7 +17619,7 @@ The @kbd{b M} (@code{calc-fin-pmt}) [@code{pmt}] command computes
17453the amount of periodic payment necessary to amortize a loan. 17619the amount of periodic payment necessary to amortize a loan.
17454Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the 17620Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the
17455value of @var{payment} such that @code{pv(@var{rate}, @var{n}, 17621value of @var{payment} such that @code{pv(@var{rate}, @var{n},
17456@var{payment}) = @var{amount}}.@refill 17622@var{payment}) = @var{amount}}.
17457 17623
17458@kindex I b M 17624@kindex I b M
17459@tindex pmtb 17625@tindex pmtb
@@ -17475,14 +17641,14 @@ Thus @code{nper(@var{rate}, @var{payment}, @var{amount})} equals
17475the value of @var{n} such that @code{pv(@var{rate}, @var{n}, 17641the value of @var{n} such that @code{pv(@var{rate}, @var{n},
17476@var{payment}) = @var{amount}}. If @var{payment} is too small 17642@var{payment}) = @var{amount}}. If @var{payment} is too small
17477ever to amortize a loan for @var{amount} at interest rate @var{rate}, 17643ever to amortize a loan for @var{amount} at interest rate @var{rate},
17478the @code{nper} function is left in symbolic form.@refill 17644the @code{nper} function is left in symbolic form.
17479 17645
17480@kindex I b # 17646@kindex I b #
17481@tindex nperb 17647@tindex nperb
17482The @kbd{I b #} [@code{nperb}] command does the same computation 17648The @kbd{I b #} [@code{nperb}] command does the same computation
17483but using @code{pvb} instead of @code{pv}. You can give a fourth 17649but using @code{pvb} instead of @code{pv}. You can give a fourth
17484lump-sum argument to these functions, but the computation will be 17650lump-sum argument to these functions, but the computation will be
17485rather slow in the four-argument case.@refill 17651rather slow in the four-argument case.
17486 17652
17487@kindex H b # 17653@kindex H b #
17488@tindex nperl 17654@tindex nperl
@@ -17490,7 +17656,7 @@ The @kbd{H b #} [@code{nperl}] command does the same computation
17490using @code{pvl}. By exchanging @var{payment} and @var{amount} you 17656using @code{pvl}. By exchanging @var{payment} and @var{amount} you
17491can also get the solution for @code{fvl}. For example, 17657can also get the solution for @code{fvl}. For example,
17492@code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a 17658@code{nperl(8%, 2000, 1000) = 9.006}, so if you place $1000 in a
17493bank account earning 8%, it will take nine years to grow to $2000.@refill 17659bank account earning 8%, it will take nine years to grow to $2000.
17494 17660
17495@kindex b T 17661@kindex b T
17496@pindex calc-fin-rate 17662@pindex calc-fin-rate
@@ -17499,7 +17665,7 @@ The @kbd{b T} (@code{calc-fin-rate}) [@code{rate}] command computes
17499the rate of return on an investment. This is also an inverse of @code{pv}: 17665the rate of return on an investment. This is also an inverse of @code{pv}:
17500@code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of 17666@code{rate(@var{n}, @var{payment}, @var{amount})} computes the value of
17501@var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) = 17667@var{rate} such that @code{pv(@var{rate}, @var{n}, @var{payment}) =
17502@var{amount}}. The result is expressed as a formula like @samp{6.3%}.@refill 17668@var{amount}}. The result is expressed as a formula like @samp{6.3%}.
17503 17669
17504@kindex I b T 17670@kindex I b T
17505@kindex H b T 17671@kindex H b T
@@ -17511,7 +17677,7 @@ in place of @code{pv}. Also, @code{rate} and @code{rateb} can
17511accept an optional fourth argument just like @code{pv} and @code{pvb}. 17677accept an optional fourth argument just like @code{pv} and @code{pvb}.
17512To redo the above example from a different perspective, 17678To redo the above example from a different perspective,
17513@code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an 17679@code{ratel(9, 2000, 1000) = 8.00597%}, which says you will need an
17514interest rate of 8% in order to double your account in nine years.@refill 17680interest rate of 8% in order to double your account in nine years.
17515 17681
17516@kindex b I 17682@kindex b I
17517@pindex calc-fin-irr 17683@pindex calc-fin-irr
@@ -17573,7 +17739,7 @@ For symmetry, the @code{sln} function will accept a @var{period}
17573parameter as well, although it will ignore its value except that the 17739parameter as well, although it will ignore its value except that the
17574return value will as usual be zero if @var{period} is out of range. 17740return value will as usual be zero if @var{period} is out of range.
17575 17741
17576For example, pushing the vector @cite{[1,2,3,4,5]} (perhaps with @kbd{v x 5}) 17742For example, pushing the vector @expr{[1,2,3,4,5]} (perhaps with @kbd{v x 5})
17577and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$), 17743and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$),
17578ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare 17744ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare
17579the three depreciation methods: 17745the three depreciation methods:
@@ -17594,7 +17760,7 @@ We see that @code{sln} depreciates by the same amount each year,
17594@kbd{syd} depreciates more at the beginning and less at the end, 17760@kbd{syd} depreciates more at the beginning and less at the end,
17595and @kbd{ddb} weights the depreciation even more toward the beginning. 17761and @kbd{ddb} weights the depreciation even more toward the beginning.
17596 17762
17597Summing columns with @kbd{V R : +} yields @cite{[10000, 10000, 10000]}; 17763Summing columns with @kbd{V R : +} yields @expr{[10000, 10000, 10000]};
17598the total depreciation in any method is (by definition) the 17764the total depreciation in any method is (by definition) the
17599difference between the cost and the salvage value. 17765difference between the cost and the salvage value.
17600 17766
@@ -17716,7 +17882,7 @@ $$ \code{ddb}(c, s, l, p) = { 2 (c - \hbox{depreciation so far}) \over l } $$
17716@end tex 17882@end tex
17717 17883
17718@noindent 17884@noindent
17719In @code{pmt} and @code{pmtb}, @cite{x=0} if omitted. 17885In @code{pmt} and @code{pmtb}, @expr{x=0} if omitted.
17720 17886
17721These functions accept any numeric objects, including error forms, 17887These functions accept any numeric objects, including error forms,
17722intervals, and even (though not very usefully) complex numbers. The 17888intervals, and even (though not very usefully) complex numbers. The
@@ -17776,31 +17942,34 @@ commands, respectively). You may also wish to enable display of leading
17776zeros with @kbd{d z}. @xref{Radix Modes}. 17942zeros with @kbd{d z}. @xref{Radix Modes}.
17777 17943
17778@cindex Word size for binary operations 17944@cindex Word size for binary operations
17779The Calculator maintains a current @dfn{word size} @cite{w}, an 17945The Calculator maintains a current @dfn{word size} @expr{w}, an
17780arbitrary positive or negative integer. For a positive word size, all 17946arbitrary positive or negative integer. For a positive word size, all
17781of the binary operations described here operate modulo @cite{2^w}. In 17947of the binary operations described here operate modulo @expr{2^w}. In
17782particular, negative arguments are converted to positive integers modulo 17948particular, negative arguments are converted to positive integers modulo
17783@cite{2^w} by all binary functions.@refill 17949@expr{2^w} by all binary functions.
17784 17950
17785If the word size is negative, binary operations produce 2's complement 17951If the word size is negative, binary operations produce 2's complement
17786integers from @c{$-2^{-w-1}$} 17952integers from
17787@cite{-(2^(-w-1))} to @c{$2^{-w-1}-1$} 17953@texline @tmath{-2^{-w-1}}
17788@cite{2^(-w-1)-1} inclusive. Either 17954@infoline @expr{-(2^(-w-1))}
17789mode accepts inputs in any range; the sign of @cite{w} affects only 17955to
17790the results produced. 17956@texline @tmath{2^{-w-1}-1}
17957@infoline @expr{2^(-w-1)-1}
17958inclusive. Either mode accepts inputs in any range; the sign of
17959@expr{w} affects only the results produced.
17791 17960
17792@kindex b c 17961@kindex b c
17793@pindex calc-clip 17962@pindex calc-clip
17794@tindex clip 17963@tindex clip
17795The @kbd{b c} (@code{calc-clip}) 17964The @kbd{b c} (@code{calc-clip})
17796[@code{clip}] command can be used to clip a number by reducing it modulo 17965[@code{clip}] command can be used to clip a number by reducing it modulo
17797@cite{2^w}. The commands described in this chapter automatically clip 17966@expr{2^w}. The commands described in this chapter automatically clip
17798their results to the current word size. Note that other operations like 17967their results to the current word size. Note that other operations like
17799addition do not use the current word size, since integer addition 17968addition do not use the current word size, since integer addition
17800generally is not ``binary.'' (However, @pxref{Simplification Modes}, 17969generally is not ``binary.'' (However, @pxref{Simplification Modes},
17801@code{calc-bin-simplify-mode}.) For example, with a word size of 8 17970@code{calc-bin-simplify-mode}.) For example, with a word size of 8
17802bits @kbd{b c} converts a number to the range 0 to 255; with a word 17971bits @kbd{b c} converts a number to the range 0 to 255; with a word
17803size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.@refill 17972size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.
17804 17973
17805@kindex b w 17974@kindex b w
17806@pindex calc-word-size 17975@pindex calc-word-size
@@ -17820,7 +17989,7 @@ will be used, but when @samp{and(a,b,-8)} is evaluated, a word size of
17820in symbolic form unless the all of its argument(s) are integers or 17989in symbolic form unless the all of its argument(s) are integers or
17821integer-valued floats. 17990integer-valued floats.
17822 17991
17823If either or both arguments are modulo forms for which @cite{M} is a 17992If either or both arguments are modulo forms for which @expr{M} is a
17824power of two, that power of two is taken as the word size unless a 17993power of two, that power of two is taken as the word size unless a
17825numeric prefix argument overrides it. The current word size is never 17994numeric prefix argument overrides it. The current word size is never
17826consulted when modulo-power-of-two forms are involved. 17995consulted when modulo-power-of-two forms are involved.
@@ -17830,7 +17999,7 @@ consulted when modulo-power-of-two forms are involved.
17830@tindex and 17999@tindex and
17831The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise 18000The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise
17832AND of the two numbers on the top of the stack. In other words, for each 18001AND of the two numbers on the top of the stack. In other words, for each
17833of the @cite{w} binary digits of the two numbers (pairwise), the corresponding 18002of the @expr{w} binary digits of the two numbers (pairwise), the corresponding
17834bit of the result is 1 if and only if both input bits are 1: 18003bit of the result is 1 if and only if both input bits are 1:
17835@samp{and(2#1100, 2#1010) = 2#1000}. 18004@samp{and(2#1100, 2#1010) = 2#1000}.
17836 18005
@@ -17965,17 +18134,20 @@ flag keys must be used to get some of these functions from the keyboard.
17965@cindex Phi, golden ratio 18134@cindex Phi, golden ratio
17966@cindex Golden ratio 18135@cindex Golden ratio
17967One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes 18136One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes
17968the value of @c{$\pi$} 18137the value of @cpi{} (at the current precision) onto the stack. With the
17969@cite{pi} (at the current precision) onto the stack. With the 18138Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms.
17970Hyperbolic flag, it pushes the value @cite{e}, the base of natural logarithms. 18139With the Inverse flag, it pushes Euler's constant
17971With the Inverse flag, it pushes Euler's constant @c{$\gamma$} 18140@texline @tmath{\gamma}
17972@cite{gamma} (about 0.5772). With both Inverse and Hyperbolic, it 18141@infoline @expr{gamma}
17973pushes the ``golden ratio'' @c{$\phi$} 18142(about 0.5772). With both Inverse and Hyperbolic, it
17974@cite{phi} (about 1.618). (At present, Euler's constant is not available 18143pushes the ``golden ratio''
18144@texline @tmath{\phi}
18145@infoline @expr{phi}
18146(about 1.618). (At present, Euler's constant is not available
17975to unlimited precision; Calc knows only the first 100 digits.) 18147to unlimited precision; Calc knows only the first 100 digits.)
17976In Symbolic mode, these commands push the 18148In Symbolic mode, these commands push the
17977actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, 18149actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi},
17978respectively, instead of their values; @pxref{Symbolic Mode}.@refill 18150respectively, instead of their values; @pxref{Symbolic Mode}.
17979 18151
17980@ignore 18152@ignore
17981@mindex Q 18153@mindex Q
@@ -18027,7 +18199,7 @@ this is redundant with the @kbd{E} command.
18027@end ignore 18199@end ignore
18028@kindex I L 18200@kindex I L
18029The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the 18201The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the
18030exponential, i.e., @cite{e} raised to the power of the number on the stack. 18202exponential, i.e., @expr{e} raised to the power of the number on the stack.
18031The meanings of the Inverse and Hyperbolic flags follow from those for 18203The meanings of the Inverse and Hyperbolic flags follow from those for
18032the @code{calc-ln} command. 18204the @code{calc-ln} command.
18033 18205
@@ -18048,8 +18220,9 @@ The @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common
18048(base-10) logarithm of a number. (With the Inverse flag [@code{exp10}], 18220(base-10) logarithm of a number. (With the Inverse flag [@code{exp10}],
18049it raises ten to a given power.) Note that the common logarithm of a 18221it raises ten to a given power.) Note that the common logarithm of a
18050complex number is computed by taking the natural logarithm and dividing 18222complex number is computed by taking the natural logarithm and dividing
18051by @c{$\ln10$} 18223by
18052@cite{ln(10)}. 18224@texline @tmath{\ln10}.
18225@infoline @expr{ln(10)}.
18053 18226
18054@kindex B 18227@kindex B
18055@kindex I B 18228@kindex I B
@@ -18058,9 +18231,10 @@ by @c{$\ln10$}
18058@tindex alog 18231@tindex alog
18059The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm 18232The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm
18060to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since 18233to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since
18061@c{$2^{10} = 1024$} 18234@texline @tmath{2^{10} = 1024}.
18062@cite{2^10 = 1024}. In certain cases like @samp{log(3,9)}, the result 18235@infoline @expr{2^10 = 1024}.
18063will be either @cite{1:2} or @cite{0.5} depending on the current Fraction 18236In certain cases like @samp{log(3,9)}, the result
18237will be either @expr{1:2} or @expr{0.5} depending on the current Fraction
18064Mode setting. With the Inverse flag [@code{alog}], this command is 18238Mode setting. With the Inverse flag [@code{alog}], this command is
18065similar to @kbd{^} except that the order of the arguments is reversed. 18239similar to @kbd{^} except that the order of the arguments is reversed.
18066 18240
@@ -18070,7 +18244,7 @@ similar to @kbd{^} except that the order of the arguments is reversed.
18070The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the 18244The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the
18071integer logarithm of a number to any base. The number and the base must 18245integer logarithm of a number to any base. The number and the base must
18072themselves be positive integers. This is the true logarithm, rounded 18246themselves be positive integers. This is the true logarithm, rounded
18073down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @cite{x} in the 18247down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @expr{x} in the
18074range from 1000 to 9999. If both arguments are positive integers, exact 18248range from 1000 to 9999. If both arguments are positive integers, exact
18075integer arithmetic is used; otherwise, this is equivalent to 18249integer arithmetic is used; otherwise, this is equivalent to
18076@samp{floor(log(x,b))}. 18250@samp{floor(log(x,b))}.
@@ -18079,19 +18253,21 @@ integer arithmetic is used; otherwise, this is equivalent to
18079@pindex calc-expm1 18253@pindex calc-expm1
18080@tindex expm1 18254@tindex expm1
18081The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes 18255The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes
18082@c{$e^x - 1$} 18256@texline @tmath{e^x - 1},
18083@cite{exp(x)-1}, but using an algorithm that produces a more accurate 18257@infoline @expr{exp(x)-1},
18084answer when the result is close to zero, i.e., when @c{$e^x$} 18258but using an algorithm that produces a more accurate
18085@cite{exp(x)} is close 18259answer when the result is close to zero, i.e., when
18086to one. 18260@texline @tmath{e^x}
18261@infoline @expr{exp(x)}
18262is close to one.
18087 18263
18088@kindex f L 18264@kindex f L
18089@pindex calc-lnp1 18265@pindex calc-lnp1
18090@tindex lnp1 18266@tindex lnp1
18091The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes 18267The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes
18092@c{$\ln(x+1)$} 18268@texline @tmath{\ln(x+1)},
18093@cite{ln(x+1)}, producing a more accurate answer when @cite{x} is close 18269@infoline @expr{ln(x+1)},
18094to zero. 18270producing a more accurate answer when @expr{x} is close to zero.
18095 18271
18096@node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions 18272@node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions
18097@section Trigonometric/Hyperbolic Functions 18273@section Trigonometric/Hyperbolic Functions
@@ -18104,7 +18280,7 @@ The shift-@kbd{S} (@code{calc-sin}) [@code{sin}] command computes the sine
18104of an angle or complex number. If the input is an HMS form, it is interpreted 18280of an angle or complex number. If the input is an HMS form, it is interpreted
18105as degrees-minutes-seconds; otherwise, the input is interpreted according 18281as degrees-minutes-seconds; otherwise, the input is interpreted according
18106to the current angular mode. It is best to use Radians mode when operating 18282to the current angular mode. It is best to use Radians mode when operating
18107on complex numbers.@refill 18283on complex numbers.
18108 18284
18109Calc's ``units'' mechanism includes angular units like @code{deg}, 18285Calc's ``units'' mechanism includes angular units like @code{deg},
18110@code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated 18286@code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated
@@ -18120,15 +18296,11 @@ mode is enabled; this example would be replaced by @samp{sqrt(2) / 2}.
18120@xref{Symbolic Mode}. Beware, this simplification occurs even if you 18296@xref{Symbolic Mode}. Beware, this simplification occurs even if you
18121have stored a different value in the variable @samp{pi}; this is one 18297have stored a different value in the variable @samp{pi}; this is one
18122reason why changing built-in variables is a bad idea. Arguments of 18298reason why changing built-in variables is a bad idea. Arguments of
18123the form @cite{x} plus a multiple of @c{$\pi/2$} 18299the form @expr{x} plus a multiple of @cpiover{2} are also simplified.
18124@cite{pi/2} are also simplified. 18300Calc includes similar formulas for @code{cos} and @code{tan}.
18125Calc includes similar formulas for @code{cos} and @code{tan}.@refill
18126 18301
18127The @kbd{a s} command knows all angles which are integer multiples of 18302The @kbd{a s} command knows all angles which are integer multiples of
18128@c{$\pi/12$} 18303@cpiover{12}, @cpiover{10}, or @cpiover{8} radians. In degrees mode,
18129@cite{pi/12}, @c{$\pi/10$}
18130@cite{pi/10}, or @c{$\pi/8$}
18131@cite{pi/8} radians. In degrees mode,
18132analogous simplifications occur for integer multiples of 15 or 18 18304analogous simplifications occur for integer multiples of 15 or 18
18133degrees, and for arguments plus multiples of 90 degrees. 18305degrees, and for arguments plus multiples of 90 degrees.
18134 18306
@@ -18253,7 +18425,7 @@ cosine of a number, returning them as a vector of the form
18253@samp{[@var{cos}, @var{sin}]}. 18425@samp{[@var{cos}, @var{sin}]}.
18254With the Inverse flag [@code{arcsincos}], this command takes a two-element 18426With the Inverse flag [@code{arcsincos}], this command takes a two-element
18255vector as an argument and computes @code{arctan2} of the elements. 18427vector as an argument and computes @code{arctan2} of the elements.
18256(This command does not accept the Hyperbolic flag.)@refill 18428(This command does not accept the Hyperbolic flag.)
18257 18429
18258@node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions 18430@node Advanced Math Functions, Branch Cuts, Trigonometric and Hyperbolic Functions, Scientific Functions
18259@section Advanced Mathematical Functions 18431@section Advanced Mathematical Functions
@@ -18278,8 +18450,9 @@ The @kbd{f g} (@code{calc-gamma}) [@code{gamma}] command computes the Euler
18278gamma function. For positive integer arguments, this is related to the 18450gamma function. For positive integer arguments, this is related to the
18279factorial function: @samp{gamma(n+1) = fact(n)}. For general complex 18451factorial function: @samp{gamma(n+1) = fact(n)}. For general complex
18280arguments the gamma function can be defined by the following definite 18452arguments the gamma function can be defined by the following definite
18281integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$} 18453integral:
18282@cite{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}. 18454@texline @tmath{\Gamma(a) = \int_0^\infty t^{a-1} e^t dt}.
18455@infoline @expr{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}.
18283(The actual implementation uses far more efficient computational methods.) 18456(The actual implementation uses far more efficient computational methods.)
18284 18457
18285@kindex f G 18458@kindex f G
@@ -18311,22 +18484,23 @@ integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$}
18311@tindex gammaG 18484@tindex gammaG
18312The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes 18485The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes
18313the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by 18486the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by
18314the integral, @c{$P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)$} 18487the integral,
18315@cite{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}. 18488@texline @tmath{P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)}.
18316This implies that @samp{gammaP(a,inf) = 1} for any @cite{a} (see the 18489@infoline @expr{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}.
18490This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the
18317definition of the normal gamma function). 18491definition of the normal gamma function).
18318 18492
18319Several other varieties of incomplete gamma function are defined. 18493Several other varieties of incomplete gamma function are defined.
18320The complement of @cite{P(a,x)}, called @cite{Q(a,x) = 1-P(a,x)} by 18494The complement of @expr{P(a,x)}, called @expr{Q(a,x) = 1-P(a,x)} by
18321some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command. 18495some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command.
18322You can think of this as taking the other half of the integral, from 18496You can think of this as taking the other half of the integral, from
18323@cite{x} to infinity. 18497@expr{x} to infinity.
18324 18498
18325@ifinfo 18499@ifinfo
18326The functions corresponding to the integrals that define @cite{P(a,x)} 18500The functions corresponding to the integrals that define @expr{P(a,x)}
18327and @cite{Q(a,x)} but without the normalizing @cite{1/gamma(a)} 18501and @expr{Q(a,x)} but without the normalizing @expr{1/gamma(a)}
18328factor are called @cite{g(a,x)} and @cite{G(a,x)}, respectively 18502factor are called @expr{g(a,x)} and @expr{G(a,x)}, respectively
18329(where @cite{g} and @cite{G} represent the lower- and upper-case Greek 18503(where @expr{g} and @expr{G} represent the lower- and upper-case Greek
18330letter gamma). You can obtain these using the @kbd{H f G} [@code{gammag}] 18504letter gamma). You can obtain these using the @kbd{H f G} [@code{gammag}]
18331and @kbd{H I f G} [@code{gammaG}] commands. 18505and @kbd{H I f G} [@code{gammaG}] commands.
18332@end ifinfo 18506@end ifinfo
@@ -18344,10 +18518,11 @@ You can obtain these using the \kbd{H f G} [\code{gammag}] and
18344@tindex beta 18518@tindex beta
18345The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the 18519The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the
18346Euler beta function, which is defined in terms of the gamma function as 18520Euler beta function, which is defined in terms of the gamma function as
18347@c{$B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)$} 18521@texline @tmath{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)},
18348@cite{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, or by 18522@infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)},
18349@c{$B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt$} 18523or by
18350@cite{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}. 18524@texline @tmath{B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt}.
18525@infoline @expr{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}.
18351 18526
18352@kindex f B 18527@kindex f B
18353@kindex H f B 18528@kindex H f B
@@ -18355,9 +18530,9 @@ Euler beta function, which is defined in terms of the gamma function as
18355@tindex betaI 18530@tindex betaI
18356@tindex betaB 18531@tindex betaB
18357The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes 18532The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes
18358the incomplete beta function @cite{I(x,a,b)}. It is defined by 18533the incomplete beta function @expr{I(x,a,b)}. It is defined by
18359@c{$I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)$} 18534@texline @tmath{I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)}.
18360@cite{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}. 18535@infoline @expr{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}.
18361Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding 18536Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding
18362un-normalized version [@code{betaB}]. 18537un-normalized version [@code{betaB}].
18363 18538
@@ -18367,12 +18542,13 @@ un-normalized version [@code{betaB}].
18367@tindex erf 18542@tindex erf
18368@tindex erfc 18543@tindex erfc
18369The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the 18544The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the
18370error function @c{$\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt$} 18545error function
18371@cite{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}. 18546@texline @tmath{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt}.
18547@infoline @expr{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}.
18372The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] 18548The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}]
18373is the corresponding integral from @samp{x} to infinity; the sum 18549is the corresponding integral from @samp{x} to infinity; the sum
18374@c{$\hbox{erf}(x) + \hbox{erfc}(x) = 1$} 18550@texline @tmath{\hbox{erf}(x) + \hbox{erfc}(x) = 1}.
18375@cite{erf(x) + erfc(x) = 1}. 18551@infoline @expr{erf(x) + erfc(x) = 1}.
18376 18552
18377@kindex f j 18553@kindex f j
18378@kindex f y 18554@kindex f y
@@ -18384,10 +18560,10 @@ The @kbd{f j} (@code{calc-bessel-J}) [@code{besJ}] and @kbd{f y}
18384(@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel 18560(@code{calc-bessel-Y}) [@code{besY}] commands compute the Bessel
18385functions of the first and second kinds, respectively. 18561functions of the first and second kinds, respectively.
18386In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter 18562In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter
18387@cite{n} is often an integer, but is not required to be one. 18563@expr{n} is often an integer, but is not required to be one.
18388Calc's implementation of the Bessel functions currently limits the 18564Calc's implementation of the Bessel functions currently limits the
18389precision to 8 digits, and may not be exact even to that precision. 18565precision to 8 digits, and may not be exact even to that precision.
18390Use with care!@refill 18566Use with care!
18391 18567
18392@node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions 18568@node Branch Cuts, Random Numbers, Advanced Math Functions, Scientific Functions
18393@section Branch Cuts and Principal Values 18569@section Branch Cuts and Principal Values
@@ -18420,9 +18596,9 @@ are designed with proper behavior around the branch cuts in mind, @emph{not}
18420efficiency or accuracy. You may need to increase the floating precision 18596efficiency or accuracy. You may need to increase the floating precision
18421and wait a while to get suitable answers from them. 18597and wait a while to get suitable answers from them.
18422 18598
18423For @samp{sqrt(a+bi)}: When @cite{a<0} and @cite{b} is small but positive 18599For @samp{sqrt(a+bi)}: When @expr{a<0} and @expr{b} is small but positive
18424or zero, the result is close to the @cite{+i} axis. For @cite{b} small and 18600or zero, the result is close to the @expr{+i} axis. For @expr{b} small and
18425negative, the result is close to the @cite{-i} axis. The result always lies 18601negative, the result is close to the @expr{-i} axis. The result always lies
18426in the right half of the complex plane. 18602in the right half of the complex plane.
18427 18603
18428For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}. 18604For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}.
@@ -18431,8 +18607,8 @@ Thus the branch cuts for @code{sqrt} and @code{ln} both lie on the
18431negative real axis. 18607negative real axis.
18432 18608
18433The following table describes these branch cuts in another way. 18609The following table describes these branch cuts in another way.
18434If the real and imaginary parts of @cite{z} are as shown, then 18610If the real and imaginary parts of @expr{z} are as shown, then
18435the real and imaginary parts of @cite{f(z)} will be as shown. 18611the real and imaginary parts of @expr{f(z)} will be as shown.
18436Here @code{eps} stands for a small positive value; each 18612Here @code{eps} stands for a small positive value; each
18437occurrence of @code{eps} may stand for a different small value. 18613occurrence of @code{eps} may stand for a different small value.
18438 18614
@@ -18448,8 +18624,8 @@ occurrence of @code{eps} may stand for a different small value.
18448For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. 18624For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}.
18449One interesting consequence of this is that @samp{(-8)^1:3} does 18625One interesting consequence of this is that @samp{(-8)^1:3} does
18450not evaluate to @i{-2} as you might expect, but to the complex 18626not evaluate to @i{-2} as you might expect, but to the complex
18451number @cite{(1., 1.732)}. Both of these are valid cube roots 18627number @expr{(1., 1.732)}. Both of these are valid cube roots
18452of @i{-8} (as is @cite{(1., -1.732)}); Calc chooses a perhaps 18628of @i{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps
18453less-obvious root for the sake of mathematical consistency. 18629less-obvious root for the sake of mathematical consistency.
18454 18630
18455For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}. 18631For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}.
@@ -18461,11 +18637,11 @@ the real axis, less than @i{-1} and greater than 1.
18461 18637
18462For @samp{arctan(z)}: This is defined by 18638For @samp{arctan(z)}: This is defined by
18463@samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}. The branch cuts are on the 18639@samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}. The branch cuts are on the
18464imaginary axis, below @cite{-i} and above @cite{i}. 18640imaginary axis, below @expr{-i} and above @expr{i}.
18465 18641
18466For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}. 18642For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}.
18467The branch cuts are on the imaginary axis, below @cite{-i} and 18643The branch cuts are on the imaginary axis, below @expr{-i} and
18468above @cite{i}. 18644above @expr{i}.
18469 18645
18470For @samp{arccosh(z)}: This is defined by 18646For @samp{arccosh(z)}: This is defined by
18471@samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the 18647@samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the
@@ -18543,38 +18719,47 @@ are not rigorously specified at present.
18543The @kbd{k r} (@code{calc-random}) [@code{random}] command produces 18719The @kbd{k r} (@code{calc-random}) [@code{random}] command produces
18544random numbers of various sorts. 18720random numbers of various sorts.
18545 18721
18546Given a positive numeric prefix argument @cite{M}, it produces a random 18722Given a positive numeric prefix argument @expr{M}, it produces a random
18547integer @cite{N} in the range @c{$0 \le N < M$} 18723integer @expr{N} in the range
18548@cite{0 <= N < M}. Each of the @cite{M} 18724@texline @tmath{0 \le N < M}.
18549values appears with equal probability.@refill 18725@infoline @expr{0 <= N < M}.
18726Each of the @expr{M} values appears with equal probability.
18550 18727
18551With no numeric prefix argument, the @kbd{k r} command takes its argument 18728With no numeric prefix argument, the @kbd{k r} command takes its argument
18552from the stack instead. Once again, if this is a positive integer @cite{M} 18729from the stack instead. Once again, if this is a positive integer @expr{M}
18553the result is a random integer less than @cite{M}. However, note that 18730the result is a random integer less than @expr{M}. However, note that
18554while numeric prefix arguments are limited to six digits or so, an @cite{M} 18731while numeric prefix arguments are limited to six digits or so, an @expr{M}
18555taken from the stack can be arbitrarily large. If @cite{M} is negative, 18732taken from the stack can be arbitrarily large. If @expr{M} is negative,
18556the result is a random integer in the range @c{$M < N \le 0$} 18733the result is a random integer in the range
18557@cite{M < N <= 0}. 18734@texline @tmath{M < N \le 0}.
18558 18735@infoline @expr{M < N <= 0}.
18559If the value on the stack is a floating-point number @cite{M}, the result 18736
18560is a random floating-point number @cite{N} in the range @c{$0 \le N < M$} 18737If the value on the stack is a floating-point number @expr{M}, the result
18561@cite{0 <= N < M} 18738is a random floating-point number @expr{N} in the range
18562or @c{$M < N \le 0$} 18739@texline @tmath{0 \le N < M}
18563@cite{M < N <= 0}, according to the sign of @cite{M}. 18740@infoline @expr{0 <= N < M}
18564 18741or
18565If @cite{M} is zero, the result is a Gaussian-distributed random real 18742@texline @tmath{M < N \le 0},
18743@infoline @expr{M < N <= 0},
18744according to the sign of @expr{M}.
18745
18746If @expr{M} is zero, the result is a Gaussian-distributed random real
18566number; the distribution has a mean of zero and a standard deviation 18747number; the distribution has a mean of zero and a standard deviation
18567of one. The algorithm used generates random numbers in pairs; thus, 18748of one. The algorithm used generates random numbers in pairs; thus,
18568every other call to this function will be especially fast. 18749every other call to this function will be especially fast.
18569 18750
18570If @cite{M} is an error form @c{$m$ @code{+/-} $\sigma$} 18751If @expr{M} is an error form
18571@samp{m +/- s} where @var{m} 18752@texline @tmath{m} @code{+/-} @tmath{\sigma}
18572and @c{$\sigma$} 18753@infoline @samp{m +/- s}
18573@var{s} are both real numbers, the result uses a Gaussian 18754where @var{m} and
18574distribution with mean @var{m} and standard deviation @c{$\sigma$} 18755@texline @tmath{\sigma}
18756@infoline @var{s}
18757are both real numbers, the result uses a Gaussian distribution with mean
18758@var{m} and standard deviation
18759@texline @tmath{\sigma}.
18575@var{s}. 18760@var{s}.
18576 18761
18577If @cite{M} is an interval form, the lower and upper bounds specify the 18762If @expr{M} is an interval form, the lower and upper bounds specify the
18578acceptable limits of the random numbers. If both bounds are integers, 18763acceptable limits of the random numbers. If both bounds are integers,
18579the result is a random integer in the specified range. If either bound 18764the result is a random integer in the specified range. If either bound
18580is floating-point, the result is a random real number in the specified 18765is floating-point, the result is a random real number in the specified
@@ -18586,7 +18771,7 @@ million numbers from 1.00000 to 1.99999; @samp{random([1.0..2.0])} may
18586additionally return 2.00000, but the probability of this happening is 18771additionally return 2.00000, but the probability of this happening is
18587extremely small.) 18772extremely small.)
18588 18773
18589If @cite{M} is a vector, the result is one element taken at random from 18774If @expr{M} is a vector, the result is one element taken at random from
18590the vector. All elements of the vector are given equal probabilities. 18775the vector. All elements of the vector are given equal probabilities.
18591 18776
18592@vindex RandSeed 18777@vindex RandSeed
@@ -18609,9 +18794,9 @@ number between zero and one. It is equivalent to @samp{random(1.0)}.
18609@kindex k a 18794@kindex k a
18610@pindex calc-random-again 18795@pindex calc-random-again
18611The @kbd{k a} (@code{calc-random-again}) command produces another random 18796The @kbd{k a} (@code{calc-random-again}) command produces another random
18612number, re-using the most recent value of @cite{M}. With a numeric 18797number, re-using the most recent value of @expr{M}. With a numeric
18613prefix argument @var{n}, it produces @var{n} more random numbers using 18798prefix argument @var{n}, it produces @var{n} more random numbers using
18614that value of @cite{M}. 18799that value of @expr{M}.
18615 18800
18616@kindex k h 18801@kindex k h
18617@pindex calc-shuffle 18802@pindex calc-shuffle
@@ -18619,12 +18804,12 @@ that value of @cite{M}.
18619The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several 18804The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several
18620random values with no duplicates. The value on the top of the stack 18805random values with no duplicates. The value on the top of the stack
18621specifies the set from which the random values are drawn, and may be any 18806specifies the set from which the random values are drawn, and may be any
18622of the @cite{M} formats described above. The numeric prefix argument 18807of the @expr{M} formats described above. The numeric prefix argument
18623gives the length of the desired list. (If you do not provide a numeric 18808gives the length of the desired list. (If you do not provide a numeric
18624prefix argument, the length of the list is taken from the top of the 18809prefix argument, the length of the list is taken from the top of the
18625stack, and @cite{M} from second-to-top.) 18810stack, and @expr{M} from second-to-top.)
18626 18811
18627If @cite{M} is a floating-point number, zero, or an error form (so 18812If @expr{M} is a floating-point number, zero, or an error form (so
18628that the random values are being drawn from the set of real numbers) 18813that the random values are being drawn from the set of real numbers)
18629there is little practical difference between using @kbd{k h} and using 18814there is little practical difference between using @kbd{k h} and using
18630@kbd{k r} several times. But if the set of possible values consists 18815@kbd{k r} several times. But if the set of possible values consists
@@ -18632,8 +18817,8 @@ of just a few integers, or the elements of a vector, then there is
18632a very real chance that multiple @kbd{k r}'s will produce the same 18817a very real chance that multiple @kbd{k r}'s will produce the same
18633number more than once. The @kbd{k h} command produces a vector whose 18818number more than once. The @kbd{k h} command produces a vector whose
18634elements are always distinct. (Actually, there is a slight exception: 18819elements are always distinct. (Actually, there is a slight exception:
18635If @cite{M} is a vector, no given vector element will be drawn more 18820If @expr{M} is a vector, no given vector element will be drawn more
18636than once, but if several elements of @cite{M} are equal, they may 18821than once, but if several elements of @expr{M} are equal, they may
18637each make it into the result vector.) 18822each make it into the result vector.)
18638 18823
18639One use of @kbd{k h} is to rearrange a list at random. This happens 18824One use of @kbd{k h} is to rearrange a list at random. This happens
@@ -18641,12 +18826,12 @@ if the prefix argument is equal to the number of values in the list:
18641@kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list 18826@kbd{[1, 1.5, 2, 2.5, 3] 5 k h} might produce the permuted list
18642@samp{[2.5, 1, 1.5, 3, 2]}. As a convenient feature, if the argument 18827@samp{[2.5, 1, 1.5, 3, 2]}. As a convenient feature, if the argument
18643@var{n} is negative it is replaced by the size of the set represented 18828@var{n} is negative it is replaced by the size of the set represented
18644by @cite{M}. Naturally, this is allowed only when @cite{M} specifies 18829by @expr{M}. Naturally, this is allowed only when @expr{M} specifies
18645a small discrete set of possibilities. 18830a small discrete set of possibilities.
18646 18831
18647To do the equivalent of @kbd{k h} but with duplications allowed, 18832To do the equivalent of @kbd{k h} but with duplications allowed,
18648given @cite{M} on the stack and with @var{n} just entered as a numeric 18833given @expr{M} on the stack and with @var{n} just entered as a numeric
18649prefix, use @kbd{v b} to build a vector of copies of @cite{M}, then use 18834prefix, use @kbd{v b} to build a vector of copies of @expr{M}, then use
18650@kbd{V M k r} to ``map'' the normal @kbd{k r} function over the 18835@kbd{V M k r} to ``map'' the normal @kbd{k r} function over the
18651elements of this vector. @xref{Matrix Functions}. 18836elements of this vector. @xref{Matrix Functions}.
18652 18837
@@ -18683,10 +18868,12 @@ generators that are typically used to implement @code{random}.
18683 18868
18684If @code{RandSeed} contains an integer, Calc uses this integer to 18869If @code{RandSeed} contains an integer, Calc uses this integer to
18685seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, 18870seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A,
18686computing @c{$X_{n-55} - X_{n-24}$} 18871computing
18687@cite{X_n-55 - X_n-24}). This method expands the seed 18872@texline @tmath{X_{n-55} - X_{n-24}}.
18873@infoline @expr{X_n-55 - X_n-24}).
18874This method expands the seed
18688value into a large table which is maintained internally; the variable 18875value into a large table which is maintained internally; the variable
18689@code{RandSeed} is changed from, e.g., 42 to the vector @cite{[42]} 18876@code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]}
18690to indicate that the seed has been absorbed into this table. When 18877to indicate that the seed has been absorbed into this table. When
18691@code{RandSeed} contains a vector, @kbd{k r} and related commands 18878@code{RandSeed} contains a vector, @kbd{k r} and related commands
18692continue to use the same internal table as last time. There is no 18879continue to use the same internal table as last time. There is no
@@ -18718,16 +18905,21 @@ value.
18718 18905
18719To create a random floating-point number with precision @var{p}, Calc 18906To create a random floating-point number with precision @var{p}, Calc
18720simply creates a random @var{p}-digit integer and multiplies by 18907simply creates a random @var{p}-digit integer and multiplies by
18721@c{$10^{-p}$} 18908@texline @tmath{10^{-p}}.
18722@cite{10^-p}. The resulting random numbers should be very clean, but note 18909@infoline @expr{10^-p}.
18910The resulting random numbers should be very clean, but note
18723that relatively small numbers will have few significant random digits. 18911that relatively small numbers will have few significant random digits.
18724In other words, with a precision of 12, you will occasionally get 18912In other words, with a precision of 12, you will occasionally get
18725numbers on the order of @c{$10^{-9}$} 18913numbers on the order of
18726@cite{10^-9} or @c{$10^{-10}$} 18914@texline @tmath{10^{-9}}
18727@cite{10^-10}, but those numbers 18915@infoline @expr{10^-9}
18728will only have two or three random digits since they correspond to small 18916or
18729integers times @c{$10^{-12}$} 18917@texline @tmath{10^{-10}},
18730@cite{10^-12}. 18918@infoline @expr{10^-10},
18919but those numbers will only have two or three random digits since they
18920correspond to small integers times
18921@texline @tmath{10^{-12}}.
18922@infoline @expr{10^-12}.
18731 18923
18732To create a random integer in the interval @samp{[0 .. @var{m})}, Calc 18924To create a random integer in the interval @samp{[0 .. @var{m})}, Calc
18733counts the digits in @var{m}, creates a random integer with three 18925counts the digits in @var{m}, creates a random integer with three
@@ -18761,7 +18953,7 @@ the GCD of two fractions is defined by taking the GCD of the
18761numerators, and the LCM of the denominators. This definition is 18953numerators, and the LCM of the denominators. This definition is
18762consistent with the idea that @samp{a / gcd(a,x)} should yield an 18954consistent with the idea that @samp{a / gcd(a,x)} should yield an
18763integer for any @samp{a} and @samp{x}. For other types of arguments, 18955integer for any @samp{a} and @samp{x}. For other types of arguments,
18764the operation is left in symbolic form.@refill 18956the operation is left in symbolic form.
18765 18957
18766@kindex k l 18958@kindex k l
18767@pindex calc-lcm 18959@pindex calc-lcm
@@ -18769,15 +18961,16 @@ the operation is left in symbolic form.@refill
18769The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the 18961The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the
18770Least Common Multiple of two integers or fractions. The product of 18962Least Common Multiple of two integers or fractions. The product of
18771the LCM and GCD of two numbers is equal to the product of the 18963the LCM and GCD of two numbers is equal to the product of the
18772numbers.@refill 18964numbers.
18773 18965
18774@kindex k E 18966@kindex k E
18775@pindex calc-extended-gcd 18967@pindex calc-extended-gcd
18776@tindex egcd 18968@tindex egcd
18777The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes 18969The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes
18778the GCD of two integers @cite{x} and @cite{y} and returns a vector 18970the GCD of two integers @expr{x} and @expr{y} and returns a vector
18779@cite{[g, a, b]} where @c{$g = \gcd(x,y) = a x + b y$} 18971@expr{[g, a, b]} where
18780@cite{g = gcd(x,y) = a x + b y}. 18972@texline @tmath{g = \gcd(x,y) = a x + b y}.
18973@infoline @expr{g = gcd(x,y) = a x + b y}.
18781 18974
18782@kindex ! 18975@kindex !
18783@pindex calc-factorial 18976@pindex calc-factorial
@@ -18794,7 +18987,7 @@ the number is a non-integral real number, the generalized factorial is used,
18794as defined by the Euler Gamma function. Please note that computation of 18987as defined by the Euler Gamma function. Please note that computation of
18795large factorials can be slow; using floating-point format will help 18988large factorials can be slow; using floating-point format will help
18796since fewer digits must be maintained. The same is true of many of 18989since fewer digits must be maintained. The same is true of many of
18797the commands in this section.@refill 18990the commands in this section.
18798 18991
18799@kindex k d 18992@kindex k d
18800@pindex calc-double-factorial 18993@pindex calc-double-factorial
@@ -18805,29 +18998,30 @@ the commands in this section.@refill
18805@tindex !! 18998@tindex !!
18806The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command 18999The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command
18807computes the ``double factorial'' of an integer. For an even integer, 19000computes the ``double factorial'' of an integer. For an even integer,
18808this is the product of even integers from 2 to @cite{N}. For an odd 19001this is the product of even integers from 2 to @expr{N}. For an odd
18809integer, this is the product of odd integers from 3 to @cite{N}. If 19002integer, this is the product of odd integers from 3 to @expr{N}. If
18810the argument is an integer-valued float, the result is a floating-point 19003the argument is an integer-valued float, the result is a floating-point
18811approximation. This function is undefined for negative even integers. 19004approximation. This function is undefined for negative even integers.
18812The notation @cite{N!!} is also recognized for double factorials.@refill 19005The notation @expr{N!!} is also recognized for double factorials.
18813 19006
18814@kindex k c 19007@kindex k c
18815@pindex calc-choose 19008@pindex calc-choose
18816@tindex choose 19009@tindex choose
18817The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the 19010The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the
18818binomial coefficient @cite{N}-choose-@cite{M}, where @cite{M} is the number 19011binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number
18819on the top of the stack and @cite{N} is second-to-top. If both arguments 19012on the top of the stack and @expr{N} is second-to-top. If both arguments
18820are integers, the result is an exact integer. Otherwise, the result is a 19013are integers, the result is an exact integer. Otherwise, the result is a
18821floating-point approximation. The binomial coefficient is defined for all 19014floating-point approximation. The binomial coefficient is defined for all
18822real numbers by @c{$N! \over M! (N-M)!\,$} 19015real numbers by
18823@cite{N! / M! (N-M)!}. 19016@texline @tmath{N! \over M! (N-M)!\,}.
19017@infoline @expr{N! / M! (N-M)!}.
18824 19018
18825@kindex H k c 19019@kindex H k c
18826@pindex calc-perm 19020@pindex calc-perm
18827@tindex perm 19021@tindex perm
18828@ifinfo 19022@ifinfo
18829The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the 19023The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the
18830number-of-permutations function @cite{N! / (N-M)!}. 19024number-of-permutations function @expr{N! / (N-M)!}.
18831@end ifinfo 19025@end ifinfo
18832@tex 19026@tex
18833The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the 19027The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the
@@ -18840,11 +19034,11 @@ number-of-perm\-utations function $N! \over (N-M)!\,$.
18840@tindex bern 19034@tindex bern
18841The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command 19035The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command
18842computes a given Bernoulli number. The value at the top of the stack 19036computes a given Bernoulli number. The value at the top of the stack
18843is a nonnegative integer @cite{n} that specifies which Bernoulli number 19037is a nonnegative integer @expr{n} that specifies which Bernoulli number
18844is desired. The @kbd{H k b} command computes a Bernoulli polynomial, 19038is desired. The @kbd{H k b} command computes a Bernoulli polynomial,
18845taking @cite{n} from the second-to-top position and @cite{x} from the 19039taking @expr{n} from the second-to-top position and @expr{x} from the
18846top of the stack. If @cite{x} is a variable or formula the result is 19040top of the stack. If @expr{x} is a variable or formula the result is
18847a polynomial in @cite{x}; if @cite{x} is a number the result is a number. 19041a polynomial in @expr{x}; if @expr{x} is a number the result is a number.
18848 19042
18849@kindex k e 19043@kindex k e
18850@kindex H k e 19044@kindex H k e
@@ -18861,13 +19055,15 @@ functions.
18861@tindex stir1 19055@tindex stir1
18862@tindex stir2 19056@tindex stir2
18863The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command 19057The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command
18864computes a Stirling number of the first kind@c{ $n \brack m$} 19058computes a Stirling number of the first
18865@asis{}, given two integers 19059@texline kind@tie{}@tmath{n \brack m},
18866@cite{n} and @cite{m} on the stack. The @kbd{H k s} [@code{stir2}] 19060@infoline kind,
18867command computes a Stirling number of the second kind@c{ $n \brace m$} 19061given two integers @expr{n} and @expr{m} on the stack. The @kbd{H k s}
18868@asis{}. These are 19062[@code{stir2}] command computes a Stirling number of the second
18869the number of @cite{m}-cycle permutations of @cite{n} objects, and 19063@texline kind@tie{}@tmath{n \brace m}.
18870the number of ways to partition @cite{n} objects into @cite{m} 19064@infoline kind.
19065These are the number of @expr{m}-cycle permutations of @expr{n} objects,
19066and the number of ways to partition @expr{n} objects into @expr{m}
18871non-empty sets, respectively. 19067non-empty sets, respectively.
18872 19068
18873@kindex k p 19069@kindex k p
@@ -18895,7 +19091,7 @@ The normal @kbd{k p} command performs one iteration of the primality
18895test. Pressing @kbd{k p} repeatedly for the same integer will perform 19091test. Pressing @kbd{k p} repeatedly for the same integer will perform
18896additional iterations. Also, @kbd{k p} with a numeric prefix performs 19092additional iterations. Also, @kbd{k p} with a numeric prefix performs
18897the specified number of iterations. There is also an algebraic function 19093the specified number of iterations. There is also an algebraic function
18898@samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @cite{n} 19094@samp{prime(n)} or @samp{prime(n,iters)} which returns 1 if @expr{n}
18899is (probably) prime and 0 if not. 19095is (probably) prime and 0 if not.
18900 19096
18901@kindex k f 19097@kindex k f
@@ -18942,17 +19138,20 @@ analogously finds the next prime less than a given number.
18942@pindex calc-totient 19138@pindex calc-totient
18943@tindex totient 19139@tindex totient
18944The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the 19140The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the
18945Euler ``totient'' function@c{ $\phi(n)$} 19141Euler ``totient''
18946@asis{}, the number of integers less than @cite{n} which 19142@texline function@tie{}@tmath{\phi(n)},
18947are relatively prime to @cite{n}. 19143@infoline function,
19144the number of integers less than @expr{n} which
19145are relatively prime to @expr{n}.
18948 19146
18949@kindex k m 19147@kindex k m
18950@pindex calc-moebius 19148@pindex calc-moebius
18951@tindex moebius 19149@tindex moebius
18952The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the 19150The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the
18953@c{M\"obius $\mu$} 19151@texline M@"obius @tmath{\mu}
18954@asis{Moebius ``mu''} function. If the input number is a product of @cite{k} 19152@infoline Moebius ``mu''
18955distinct factors, this is @cite{(-1)^k}. If the input number has any 19153function. If the input number is a product of @expr{k}
19154distinct factors, this is @expr{(-1)^k}. If the input number has any
18956duplicate factors (i.e., can be divided by the same prime more than once), 19155duplicate factors (i.e., can be divided by the same prime more than once),
18957the result is zero. 19156the result is zero.
18958 19157
@@ -18962,14 +19161,14 @@ the result is zero.
18962@noindent 19161@noindent
18963The functions in this section compute various probability distributions. 19162The functions in this section compute various probability distributions.
18964For continuous distributions, this is the integral of the probability 19163For continuous distributions, this is the integral of the probability
18965density function from @cite{x} to infinity. (These are the ``upper 19164density function from @expr{x} to infinity. (These are the ``upper
18966tail'' distribution functions; there are also corresponding ``lower 19165tail'' distribution functions; there are also corresponding ``lower
18967tail'' functions which integrate from minus infinity to @cite{x}.) 19166tail'' functions which integrate from minus infinity to @expr{x}.)
18968For discrete distributions, the upper tail function gives the sum 19167For discrete distributions, the upper tail function gives the sum
18969from @cite{x} to infinity; the lower tail function gives the sum 19168from @expr{x} to infinity; the lower tail function gives the sum
18970from minus infinity up to, but not including,@w{ }@cite{x}. 19169from minus infinity up to, but not including,@w{ }@expr{x}.
18971 19170
18972To integrate from @cite{x} to @cite{y}, just use the distribution 19171To integrate from @expr{x} to @expr{y}, just use the distribution
18973function twice and subtract. For example, the probability that a 19172function twice and subtract. For example, the probability that a
18974Gaussian random variable with mean 2 and standard deviation 1 will 19173Gaussian random variable with mean 2 and standard deviation 1 will
18975lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)} 19174lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)}
@@ -18999,7 +19198,7 @@ order of the arguments in algebraic form differs from the order of
18999arguments as found on the stack. (The random variable comes last on 19198arguments as found on the stack. (The random variable comes last on
19000the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5 19199the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5
19001k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to 19200k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to
19002recover the original arguments but substitute a new value for @cite{x}.) 19201recover the original arguments but substitute a new value for @expr{x}.)
19003 19202
19004@kindex k C 19203@kindex k C
19005@pindex calc-utpc 19204@pindex calc-utpc
@@ -19013,9 +19212,10 @@ recover the original arguments but substitute a new value for @cite{x}.)
19013@end ignore 19212@end ignore
19014@tindex ltpc 19213@tindex ltpc
19015The @samp{utpc(x,v)} function uses the chi-square distribution with 19214The @samp{utpc(x,v)} function uses the chi-square distribution with
19016@c{$\nu$} 19215@texline @tmath{\nu}
19017@cite{v} degrees of freedom. It is the probability that a model is 19216@infoline @expr{v}
19018correct if its chi-square statistic is @cite{x}. 19217degrees of freedom. It is the probability that a model is
19218correct if its chi-square statistic is @expr{x}.
19019 19219
19020@kindex k F 19220@kindex k F
19021@pindex calc-utpf 19221@pindex calc-utpf
@@ -19029,11 +19229,14 @@ correct if its chi-square statistic is @cite{x}.
19029@end ignore 19229@end ignore
19030@tindex ltpf 19230@tindex ltpf
19031The @samp{utpf(F,v1,v2)} function uses the F distribution, used in 19231The @samp{utpf(F,v1,v2)} function uses the F distribution, used in
19032various statistical tests. The parameters @c{$\nu_1$} 19232various statistical tests. The parameters
19033@cite{v1} and @c{$\nu_2$} 19233@texline @tmath{\nu_1}
19034@cite{v2} 19234@infoline @expr{v1}
19235and
19236@texline @tmath{\nu_2}
19237@infoline @expr{v2}
19035are the degrees of freedom in the numerator and denominator, 19238are the degrees of freedom in the numerator and denominator,
19036respectively, used in computing the statistic @cite{F}. 19239respectively, used in computing the statistic @expr{F}.
19037 19240
19038@kindex k N 19241@kindex k N
19039@pindex calc-utpn 19242@pindex calc-utpn
@@ -19047,10 +19250,11 @@ respectively, used in computing the statistic @cite{F}.
19047@end ignore 19250@end ignore
19048@tindex ltpn 19251@tindex ltpn
19049The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution 19252The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution
19050with mean @cite{m} and standard deviation @c{$\sigma$} 19253with mean @expr{m} and standard deviation
19051@cite{s}. It is the 19254@texline @tmath{\sigma}.
19052probability that such a normal-distributed random variable would 19255@infoline @expr{s}.
19053exceed @cite{x}. 19256It is the probability that such a normal-distributed random variable
19257would exceed @expr{x}.
19054 19258
19055@kindex k P 19259@kindex k P
19056@pindex calc-utpp 19260@pindex calc-utpp
@@ -19064,7 +19268,7 @@ exceed @cite{x}.
19064@end ignore 19268@end ignore
19065@tindex ltpp 19269@tindex ltpp
19066The @samp{utpp(n,x)} function uses a Poisson distribution with 19270The @samp{utpp(n,x)} function uses a Poisson distribution with
19067mean @cite{x}. It is the probability that @cite{n} or more such 19271mean @expr{x}. It is the probability that @expr{n} or more such
19068Poisson random events will occur. 19272Poisson random events will occur.
19069 19273
19070@kindex k T 19274@kindex k T
@@ -19079,16 +19283,22 @@ Poisson random events will occur.
19079@end ignore 19283@end ignore
19080@tindex ltpt 19284@tindex ltpt
19081The @samp{utpt(t,v)} function uses the Student's ``t'' distribution 19285The @samp{utpt(t,v)} function uses the Student's ``t'' distribution
19082with @c{$\nu$} 19286with
19083@cite{v} degrees of freedom. It is the probability that a 19287@texline @tmath{\nu}
19084t-distributed random variable will be greater than @cite{t}. 19288@infoline @expr{v}
19085(Note: This computes the distribution function @c{$A(t|\nu)$} 19289degrees of freedom. It is the probability that a
19086@cite{A(t|v)} 19290t-distributed random variable will be greater than @expr{t}.
19087where @c{$A(0|\nu) = 1$} 19291(Note: This computes the distribution function
19088@cite{A(0|v) = 1} and @c{$A(\infty|\nu) \to 0$} 19292@texline @tmath{A(t|\nu)}
19089@cite{A(inf|v) -> 0}. The 19293@infoline @expr{A(t|v)}
19090@code{UTPT} operation on the HP-48 uses a different definition 19294where
19091which returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) 19295@texline @tmath{A(0|\nu) = 1}
19296@infoline @expr{A(0|v) = 1}
19297and
19298@texline @tmath{A(\infty|\nu) \to 0}.
19299@infoline @expr{A(inf|v) -> 0}.
19300The @code{UTPT} operation on the HP-48 uses a different definition which
19301returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.)
19092 19302
19093While Calc does not provide inverses of the probability distribution 19303While Calc does not provide inverses of the probability distribution
19094functions, the @kbd{a R} command can be used to solve for the inverse. 19304functions, the @kbd{a R} command can be used to solve for the inverse.
@@ -19155,7 +19365,7 @@ Negative packing modes create other kinds of composite objects:
19155@item -1 19365@item -1
19156Two values are collected to build a complex number. For example, 19366Two values are collected to build a complex number. For example,
19157@kbd{5 @key{RET} 7 C-u -1 v p} creates the complex number 19367@kbd{5 @key{RET} 7 C-u -1 v p} creates the complex number
19158@cite{(5, 7)}. The result is always a rectangular complex 19368@expr{(5, 7)}. The result is always a rectangular complex
19159number. The two input values must both be real numbers, 19369number. The two input values must both be real numbers,
19160i.e., integers, fractions, or floats. If they are not, Calc 19370i.e., integers, fractions, or floats. If they are not, Calc
19161will instead build a formula like @samp{a + (0, 1) b}. (The 19371will instead build a formula like @samp{a + (0, 1) b}. (The
@@ -19245,8 +19455,9 @@ returned in the form @samp{[@w{[a, b, c]}, [d, e, f]]}.
19245If any elements of the vector are negative, other kinds of 19455If any elements of the vector are negative, other kinds of
19246packing are done at that level as described above. For 19456packing are done at that level as described above. For
19247example, @samp{[2, 3, -4]} takes 12 objects and creates a 19457example, @samp{[2, 3, -4]} takes 12 objects and creates a
19248@c{$2\times3$} 19458@texline @tmath{2\times3}
19249@asis{2x3} matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. 19459@infoline 2x3
19460matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}.
19250Also, @samp{[-4, -10]} will convert four integers into an 19461Also, @samp{[-4, -10]} will convert four integers into an
19251error form consisting of two fractions: @samp{a:b +/- c:d}. 19462error form consisting of two fractions: @samp{a:b +/- c:d}.
19252 19463
@@ -19346,7 +19557,7 @@ number, you can use @samp{unpack(-10, @var{x})_1}.
19346 19557
19347@noindent 19558@noindent
19348Vectors and matrices can be added, 19559Vectors and matrices can be added,
19349subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.@refill 19560subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.
19350 19561
19351@kindex | 19562@kindex |
19352@pindex calc-concat 19563@pindex calc-concat
@@ -19392,11 +19603,12 @@ prefix, if specified, must match the size of the vector. If the value on
19392the stack is a scalar, it is used for each element on the diagonal, and 19603the stack is a scalar, it is used for each element on the diagonal, and
19393the prefix argument is required. 19604the prefix argument is required.
19394 19605
19395To build a constant square matrix, e.g., a @c{$3\times3$} 19606To build a constant square matrix, e.g., a
19396@asis{3x3} matrix filled with ones, 19607@texline @tmath{3\times3}
19397use @kbd{0 M-3 v d 1 +}, i.e., build a zero matrix first and then add a 19608@infoline 3x3
19398constant value to that matrix. (Another alternative would be to use 19609matrix filled with ones, use @kbd{0 M-3 v d 1 +}, i.e., build a zero
19399@kbd{v b} and @kbd{v a}; see below.) 19610matrix first and then add a constant value to that matrix. (Another
19611alternative would be to use @kbd{v b} and @kbd{v a}; see below.)
19400 19612
19401@kindex v i 19613@kindex v i
19402@pindex calc-ident 19614@pindex calc-ident
@@ -19407,8 +19619,8 @@ where the diagonal element is always one. If no prefix argument is given,
19407this command prompts for one. 19619this command prompts for one.
19408 19620
19409In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)}, 19621In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)},
19410except that @cite{a} is required to be a scalar (non-vector) quantity. 19622except that @expr{a} is required to be a scalar (non-vector) quantity.
19411If @cite{n} is omitted, @samp{idn(a)} represents @cite{a} times an 19623If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an
19412identity matrix of unknown size. Calc can operate algebraically on 19624identity matrix of unknown size. Calc can operate algebraically on
19413such generic identity matrices, and if one is combined with a matrix 19625such generic identity matrices, and if one is combined with a matrix
19414whose size is known, it is converted automatically to an identity 19626whose size is known, it is converted automatically to an identity
@@ -19531,10 +19743,10 @@ submatrix is returned.
19531@tindex _ 19743@tindex _
19532Subscript notation in algebraic formulas (@samp{a_b}) stands for the 19744Subscript notation in algebraic formulas (@samp{a_b}) stands for the
19533Calc function @code{subscr}, which is synonymous with @code{mrow}. 19745Calc function @code{subscr}, which is synonymous with @code{mrow}.
19534Thus, @samp{[x, y, z]_k} produces @cite{x}, @cite{y}, or @cite{z} if 19746Thus, @samp{[x, y, z]_k} produces @expr{x}, @expr{y}, or @expr{z} if
19535@cite{k} is one, two, or three, respectively. A double subscript 19747@expr{k} is one, two, or three, respectively. A double subscript
19536(@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will 19748(@samp{M_i_j}, equivalent to @samp{subscr(subscr(M, i), j)}) will
19537access the element at row @cite{i}, column @cite{j} of a matrix. 19749access the element at row @expr{i}, column @expr{j} of a matrix.
19538The @kbd{a _} (@code{calc-subscript}) command creates a subscript 19750The @kbd{a _} (@code{calc-subscript}) command creates a subscript
19539formula @samp{a_b} out of two stack entries. (It is on the @kbd{a} 19751formula @samp{a_b} out of two stack entries. (It is on the @kbd{a}
19540``algebra'' prefix because subscripted variables are often used 19752``algebra'' prefix because subscripted variables are often used
@@ -19561,13 +19773,13 @@ the analogous operation on columns of a matrix. Given a plain vector
19561it extracts (or removes) one element, just like @kbd{v r}. If the 19773it extracts (or removes) one element, just like @kbd{v r}. If the
19562index in @kbd{C-u v c} is an interval or vector and the argument is a 19774index in @kbd{C-u v c} is an interval or vector and the argument is a
19563matrix, the result is a submatrix with only the specified columns 19775matrix, the result is a submatrix with only the specified columns
19564retained (and possibly permuted in the case of a vector index).@refill 19776retained (and possibly permuted in the case of a vector index).
19565 19777
19566To extract a matrix element at a given row and column, use @kbd{v r} to 19778To extract a matrix element at a given row and column, use @kbd{v r} to
19567extract the row as a vector, then @kbd{v c} to extract the column element 19779extract the row as a vector, then @kbd{v c} to extract the column element
19568from that vector. In algebraic formulas, it is often more convenient to 19780from that vector. In algebraic formulas, it is often more convenient to
19569use subscript notation: @samp{m_i_j} gives row @cite{i}, column @cite{j} 19781use subscript notation: @samp{m_i_j} gives row @expr{i}, column @expr{j}
19570of matrix @cite{m}. 19782of matrix @expr{m}.
19571 19783
19572@kindex v s 19784@kindex v s
19573@pindex calc-subvector 19785@pindex calc-subvector
@@ -19610,15 +19822,17 @@ vectors one element at a time.
19610The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the 19822The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the
19611length of a vector. The length of a non-vector is considered to be zero. 19823length of a vector. The length of a non-vector is considered to be zero.
19612Note that matrices are just vectors of vectors for the purposes of this 19824Note that matrices are just vectors of vectors for the purposes of this
19613command.@refill 19825command.
19614 19826
19615@kindex H v l 19827@kindex H v l
19616@tindex mdims 19828@tindex mdims
19617With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector 19829With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector
19618of the dimensions of a vector, matrix, or higher-order object. For 19830of the dimensions of a vector, matrix, or higher-order object. For
19619example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since 19831example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since
19620its argument is a @c{$2\times3$} 19832its argument is a
19621@asis{2x3} matrix. 19833@texline @tmath{2\times3}
19834@infoline 2x3
19835matrix.
19622 19836
19623@kindex v f 19837@kindex v f
19624@pindex calc-vector-find 19838@pindex calc-vector-find
@@ -19647,14 +19861,18 @@ If the number of columns does not evenly divide the number of elements
19647in the vector, the last row will be short and the result will not be 19861in the vector, the last row will be short and the result will not be
19648suitable for use as a matrix. For example, with the matrix 19862suitable for use as a matrix. For example, with the matrix
19649@samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces 19863@samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces
19650@samp{[[1, 2, 3, 4]]} (a @c{$1\times4$} 19864@samp{[[1, 2, 3, 4]]} (a
19651@asis{1x4} matrix), @kbd{v a 1} produces 19865@texline @tmath{1\times4}
19652@samp{[[1], [2], [3], [4]]} (a @c{$4\times1$} 19866@infoline 1x4
19653@asis{4x1} matrix), @kbd{v a 2} produces 19867matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a
19654@samp{[[1, 2], [3, 4]]} (the original @c{$2\times2$} 19868@texline @tmath{4\times1}
19655@asis{2x2} matrix), @w{@kbd{v a 3}} produces 19869@infoline 4x1
19656@samp{[[1, 2, 3], [4]]} (not a matrix), and @kbd{v a 0} produces 19870matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original
19657the flattened list @samp{[1, 2, @w{3, 4}]}. 19871@texline @tmath{2\times2}
19872@infoline 2x2
19873matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a
19874matrix), and @kbd{v a 0} produces the flattened list
19875@samp{[1, 2, @w{3, 4}]}.
19658 19876
19659@cindex Sorting data 19877@cindex Sorting data
19660@kindex V S 19878@kindex V S
@@ -19810,7 +20028,7 @@ matrix actually uses LU-decomposition for greater accuracy and speed.)
19810The following functions are applied element-wise if their arguments are 20028The following functions are applied element-wise if their arguments are
19811vectors or matrices: @code{change-sign}, @code{conj}, @code{arg}, 20029vectors or matrices: @code{change-sign}, @code{conj}, @code{arg},
19812@code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean}, 20030@code{re}, @code{im}, @code{polar}, @code{rect}, @code{clean},
19813@code{float}, @code{frac}. @xref{Function Index}.@refill 20031@code{float}, @code{frac}. @xref{Function Index}.
19814 20032
19815@kindex V J 20033@kindex V J
19816@pindex calc-conj-transpose 20034@pindex calc-conj-transpose
@@ -19832,7 +20050,7 @@ Frobenius norm of a vector or matrix argument. This is the square
19832root of the sum of the squares of the absolute values of the 20050root of the sum of the squares of the absolute values of the
19833elements of the vector or matrix. If the vector is interpreted as 20051elements of the vector or matrix. If the vector is interpreted as
19834a point in two- or three-dimensional space, this is the distance 20052a point in two- or three-dimensional space, this is the distance
19835from that point to the origin.@refill 20053from that point to the origin.
19836 20054
19837@kindex v n 20055@kindex v n
19838@pindex calc-rnorm 20056@pindex calc-rnorm
@@ -19851,7 +20069,7 @@ The @kbd{V N} (@code{calc-cnorm}) [@code{cnorm}] command computes
19851the column norm, or one-norm, of a vector or matrix. For a plain 20069the column norm, or one-norm, of a vector or matrix. For a plain
19852vector, this is the sum of the absolute values of the elements. 20070vector, this is the sum of the absolute values of the elements.
19853For a matrix, this is the maximum of the column-absolute-value-sums. 20071For a matrix, this is the maximum of the column-absolute-value-sums.
19854General @cite{k}-norms for @cite{k} other than one or infinity are 20072General @expr{k}-norms for @expr{k} other than one or infinity are
19855not provided. 20073not provided.
19856 20074
19857@kindex V C 20075@kindex V C
@@ -19877,8 +20095,8 @@ that once an inverse (or determinant) of a particular matrix has been
19877computed, the inverse and determinant of the matrix can be recomputed 20095computed, the inverse and determinant of the matrix can be recomputed
19878quickly in the future. 20096quickly in the future.
19879 20097
19880If the argument to @kbd{&} is a plain number @cite{x}, this 20098If the argument to @kbd{&} is a plain number @expr{x}, this
19881command simply computes @cite{1/x}. This is okay, because the 20099command simply computes @expr{1/x}. This is okay, because the
19882@samp{/} operator also does a matrix inversion when dividing one 20100@samp{/} operator also does a matrix inversion when dividing one
19883by a matrix. 20101by a matrix.
19884 20102
@@ -19936,8 +20154,8 @@ The result is always a vector, except that if the set consists of a
19936single interval, the interval itself is returned instead. 20154single interval, the interval itself is returned instead.
19937 20155
19938@xref{Logical Operations}, for the @code{in} function which tests if 20156@xref{Logical Operations}, for the @code{in} function which tests if
19939a certain value is a member of a given set. To test if the set @cite{A} 20157a certain value is a member of a given set. To test if the set @expr{A}
19940is a subset of the set @cite{B}, use @samp{vdiff(A, B) = []}. 20158is a subset of the set @expr{B}, use @samp{vdiff(A, B) = []}.
19941 20159
19942@kindex V + 20160@kindex V +
19943@pindex calc-remove-duplicates 20161@pindex calc-remove-duplicates
@@ -19969,20 +20187,23 @@ and only if it is in both of the input sets. Thus if the input
19969sets are disjoint, i.e., if they share no common elements, the result 20187sets are disjoint, i.e., if they share no common elements, the result
19970will be the empty vector @samp{[]}. Note that the characters @kbd{V} 20188will be the empty vector @samp{[]}. Note that the characters @kbd{V}
19971and @kbd{^} were chosen to be close to the conventional mathematical 20189and @kbd{^} were chosen to be close to the conventional mathematical
19972notation for set union@c{ ($A \cup B$)} 20190notation for set
19973@asis{} and intersection@c{ ($A \cap B$)} 20191@texline union@tie{}(@tmath{A \cup B})
19974@asis{}. 20192@infoline union
20193and
20194@texline intersection@tie{}(@tmath{A \cap B}).
20195@infoline intersection.
19975 20196
19976@kindex V - 20197@kindex V -
19977@pindex calc-set-difference 20198@pindex calc-set-difference
19978@tindex vdiff 20199@tindex vdiff
19979The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes 20200The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes
19980the difference between two sets. An object is in the difference 20201the difference between two sets. An object is in the difference
19981@cite{A - B} if and only if it is in @cite{A} but not in @cite{B}. 20202@expr{A - B} if and only if it is in @expr{A} but not in @expr{B}.
19982Thus subtracting @samp{[y,z]} from a set will remove the elements 20203Thus subtracting @samp{[y,z]} from a set will remove the elements
19983@samp{y} and @samp{z} if they are present. You can also think of this 20204@samp{y} and @samp{z} if they are present. You can also think of this
19984as a general @dfn{set complement} operator; if @cite{A} is the set of 20205as a general @dfn{set complement} operator; if @expr{A} is the set of
19985all possible values, then @cite{A - B} is the ``complement'' of @cite{B}. 20206all possible values, then @expr{A - B} is the ``complement'' of @expr{B}.
19986Obviously this is only practical if the set of all possible values in 20207Obviously this is only practical if the set of all possible values in
19987your problem is small enough to list in a Calc vector (or simple 20208your problem is small enough to list in a Calc vector (or simple
19988enough to express in a few intervals). 20209enough to express in a few intervals).
@@ -20078,8 +20299,9 @@ the same set. The set may include positive infinity, but must
20078not include any negative numbers. The input is interpreted as a 20299not include any negative numbers. The input is interpreted as a
20079set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware 20300set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware
20080that a simple input like @samp{[100]} can result in a huge integer 20301that a simple input like @samp{[100]} can result in a huge integer
20081representation (@c{$2^{100}$} 20302representation
20082@cite{2^100}, a 31-digit integer, in this case). 20303@texline (@tmath{2^{100}}, a 31-digit integer, in this case).
20304@infoline (@expr{2^100}, a 31-digit integer, in this case).
20083 20305
20084@node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions 20306@node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions
20085@section Statistical Operations on Vectors 20307@section Statistical Operations on Vectors
@@ -20167,7 +20389,7 @@ computes the sum of the data values. The @kbd{u *}
20167(@code{calc-vector-prod}) [@code{vprod}] command computes the 20389(@code{calc-vector-prod}) [@code{vprod}] command computes the
20168product of the data values. If the input is a single flat vector, 20390product of the data values. If the input is a single flat vector,
20169these are the same as @kbd{V R +} and @kbd{V R *} 20391these are the same as @kbd{V R +} and @kbd{V R *}
20170(@pxref{Reducing and Mapping}).@refill 20392(@pxref{Reducing and Mapping}).
20171 20393
20172@kindex u X 20394@kindex u X
20173@kindex u N 20395@kindex u N
@@ -20189,21 +20411,25 @@ plus or minus infinity.
20189@cindex Mean of data values 20411@cindex Mean of data values
20190The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command 20412The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command
20191computes the average (arithmetic mean) of the data values. 20413computes the average (arithmetic mean) of the data values.
20192If the inputs are error forms @c{$x$ @code{+/-} $\sigma$} 20414If the inputs are error forms
20193@samp{x +/- s}, this is the weighted 20415@texline @tmath{x \pm \sigma},
20194mean of the @cite{x} values with weights @c{$1 / \sigma^2$} 20416@infoline @samp{x +/- s},
20195@cite{1 / s^2}. 20417this is the weighted mean of the @expr{x} values with weights
20418@texline @tmath{1 /\sigma^2}.
20419@infoline @expr{1 / s^2}.
20196@tex 20420@tex
20197\turnoffactive 20421\turnoffactive
20198$$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over 20422$$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over
20199 \displaystyle \sum { 1 \over \sigma_i^2 } } $$ 20423 \displaystyle \sum { 1 \over \sigma_i^2 } } $$
20200@end tex 20424@end tex
20201If the inputs are not error forms, this is simply the sum of the 20425If the inputs are not error forms, this is simply the sum of the
20202values divided by the count of the values.@refill 20426values divided by the count of the values.
20203 20427
20204Note that a plain number can be considered an error form with 20428Note that a plain number can be considered an error form with
20205error @c{$\sigma = 0$} 20429error
20206@cite{s = 0}. If the input to @kbd{u M} is a mixture of 20430@texline @tmath{\sigma = 0}.
20431@infoline @expr{s = 0}.
20432If the input to @kbd{u M} is a mixture of
20207plain numbers and error forms, the result is the mean of the 20433plain numbers and error forms, the result is the mean of the
20208plain numbers, ignoring all values with non-zero errors. (By the 20434plain numbers, ignoring all values with non-zero errors. (By the
20209above definitions it's clear that a plain number effectively 20435above definitions it's clear that a plain number effectively
@@ -20212,7 +20438,7 @@ weight is completely negligible.)
20212 20438
20213This function also works for distributions (error forms or 20439This function also works for distributions (error forms or
20214intervals). The mean of an error form `@var{a} @t{+/-} @var{b}' is simply 20440intervals). The mean of an error form `@var{a} @t{+/-} @var{b}' is simply
20215@cite{a}. The mean of an interval is the mean of the minimum 20441@expr{a}. The mean of an interval is the mean of the minimum
20216and maximum values of the interval. 20442and maximum values of the interval.
20217 20443
20218@kindex I u M 20444@kindex I u M
@@ -20234,7 +20460,7 @@ numbers, the error is equal to the standard deviation of the values
20234divided by the square root of the number of values. (This works 20460divided by the square root of the number of values. (This works
20235out to be equivalent to calculating the standard deviation and 20461out to be equivalent to calculating the standard deviation and
20236then assuming each value's error is equal to this standard 20462then assuming each value's error is equal to this standard
20237deviation.)@refill 20463deviation.)
20238@tex 20464@tex
20239\turnoffactive 20465\turnoffactive
20240$$ \sigma_\mu^2 = {\sigma^2 \over N} $$ 20466$$ \sigma_\mu^2 = {\sigma^2 \over N} $$
@@ -20309,13 +20535,14 @@ for a vector of numbers simply by using the @kbd{A} command.
20309@cindex Standard deviation 20535@cindex Standard deviation
20310@cindex Sample statistics 20536@cindex Sample statistics
20311The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command 20537The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command
20312computes the standard deviation@c{ $\sigma$} 20538computes the standard
20313@asis{} of the data values. If the 20539@texline deviation@tie{}@tmath{\sigma}
20314values are error forms, the errors are used as weights just 20540@infoline deviation
20315as for @kbd{u M}. This is the @emph{sample} standard deviation, 20541of the data values. If the values are error forms, the errors are used
20316whose value is the square root of the sum of the squares of the 20542as weights just as for @kbd{u M}. This is the @emph{sample} standard
20317differences between the values and the mean of the @cite{N} values, 20543deviation, whose value is the square root of the sum of the squares of
20318divided by @cite{N-1}. 20544the differences between the values and the mean of the @expr{N} values,
20545divided by @expr{N-1}.
20319@tex 20546@tex
20320\turnoffactive 20547\turnoffactive
20321$$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$ 20548$$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$
@@ -20324,10 +20551,11 @@ $$ \sigma^2 = {1 \over N - 1} \sum (x_i - \mu)^2 $$
20324This function also applies to distributions. The standard deviation 20551This function also applies to distributions. The standard deviation
20325of a single error form is simply the error part. The standard deviation 20552of a single error form is simply the error part. The standard deviation
20326of a continuous interval happens to equal the difference between the 20553of a continuous interval happens to equal the difference between the
20327limits, divided by @c{$\sqrt{12}$} 20554limits, divided by
20328@cite{sqrt(12)}. The standard deviation of an 20555@texline @tmath{\sqrt{12}}.
20329integer interval is the same as the standard deviation of a vector 20556@infoline @expr{sqrt(12)}.
20330of those integers. 20557The standard deviation of an integer interval is the same as the
20558standard deviation of a vector of those integers.
20331 20559
20332@kindex I u S 20560@kindex I u S
20333@pindex calc-vector-pop-sdev 20561@pindex calc-vector-pop-sdev
@@ -20336,7 +20564,7 @@ of those integers.
20336The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}] 20564The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}]
20337command computes the @emph{population} standard deviation. 20565command computes the @emph{population} standard deviation.
20338It is defined by the same formula as above but dividing 20566It is defined by the same formula as above but dividing
20339by @cite{N} instead of by @cite{N-1}. The population standard 20567by @expr{N} instead of by @expr{N-1}. The population standard
20340deviation is used when the input represents the entire set of 20568deviation is used when the input represents the entire set of
20341data values in the distribution; the sample standard deviation 20569data values in the distribution; the sample standard deviation
20342is used when the input represents a sample of the set of all 20570is used when the input represents a sample of the set of all
@@ -20361,8 +20589,10 @@ population standard deviation of the equivalent vector of integers.
20361The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and 20589The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and
20362@kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}] 20590@kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}]
20363commands compute the variance of the data values. The variance 20591commands compute the variance of the data values. The variance
20364is the square@c{ $\sigma^2$} 20592is the
20365@asis{} of the standard deviation, i.e., the sum of the 20593@texline square@tie{}@tmath{\sigma^2}
20594@infoline square
20595of the standard deviation, i.e., the sum of the
20366squares of the deviations of the data values from the mean. 20596squares of the deviations of the data values from the mean.
20367(This definition also applies when the argument is a distribution.) 20597(This definition also applies when the argument is a distribution.)
20368 20598
@@ -20383,10 +20613,11 @@ The functions in this section take two arguments, which must be
20383vectors of equal size. The vectors are each flattened in the same 20613vectors of equal size. The vectors are each flattened in the same
20384way as by the single-variable statistical functions. Given a numeric 20614way as by the single-variable statistical functions. Given a numeric
20385prefix argument of 1, these functions instead take one object from 20615prefix argument of 1, these functions instead take one object from
20386the stack, which must be an @c{$N\times2$} 20616the stack, which must be an
20387@asis{Nx2} matrix of data values. Once 20617@texline @tmath{N\times2}
20388again, variable names can be used in place of actual vectors and 20618@infoline Nx2
20389matrices. 20619matrix of data values. Once again, variable names can be used in place
20620of actual vectors and matrices.
20390 20621
20391@kindex u C 20622@kindex u C
20392@pindex calc-vector-covariance 20623@pindex calc-vector-covariance
@@ -20397,7 +20628,7 @@ computes the sample covariance of two vectors. The covariance
20397of vectors @var{x} and @var{y} is the sum of the products of the 20628of vectors @var{x} and @var{y} is the sum of the products of the
20398differences between the elements of @var{x} and the mean of @var{x} 20629differences between the elements of @var{x} and the mean of @var{x}
20399times the differences between the corresponding elements of @var{y} 20630times the differences between the corresponding elements of @var{y}
20400and the mean of @var{y}, all divided by @cite{N-1}. Note that 20631and the mean of @var{y}, all divided by @expr{N-1}. Note that
20401the variance of a vector is just the covariance of the vector 20632the variance of a vector is just the covariance of the vector
20402with itself. Once again, if the inputs are error forms the 20633with itself. Once again, if the inputs are error forms the
20403errors are used as weight factors. If both @var{x} and @var{y} 20634errors are used as weight factors. If both @var{x} and @var{y}
@@ -20419,8 +20650,8 @@ $$
20419@tindex vpcov 20650@tindex vpcov
20420The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}] 20651The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}]
20421command computes the population covariance, which is the same as the 20652command computes the population covariance, which is the same as the
20422sample covariance computed by @kbd{u C} except dividing by @cite{N} 20653sample covariance computed by @kbd{u C} except dividing by @expr{N}
20423instead of @cite{N-1}. 20654instead of @expr{N-1}.
20424 20655
20425@kindex H u C 20656@kindex H u C
20426@pindex calc-vector-correlation 20657@pindex calc-vector-correlation
@@ -20598,7 +20829,7 @@ and is either a variable whose name is the same as the function name,
20598or a nameless function like @samp{<#^3+1>}. Operators that are normally 20829or a nameless function like @samp{<#^3+1>}. Operators that are normally
20599written as algebraic symbols have the names @code{add}, @code{sub}, 20830written as algebraic symbols have the names @code{add}, @code{sub},
20600@code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and 20831@code{mul}, @code{div}, @code{pow}, @code{neg}, @code{mod}, and
20601@code{vconcat}.@refill 20832@code{vconcat}.
20602 20833
20603@ignore 20834@ignore
20604@starindex 20835@starindex
@@ -20635,24 +20866,26 @@ is duplicated for each element of the other vector. For example,
20635With the 2 listed first, it would have computed a vector of powers of 20866With the 2 listed first, it would have computed a vector of powers of
20636two. Mapping a user-defined function pops as many arguments from the 20867two. Mapping a user-defined function pops as many arguments from the
20637stack as the function requires. If you give an undefined name, you will 20868stack as the function requires. If you give an undefined name, you will
20638be prompted for the number of arguments to use.@refill 20869be prompted for the number of arguments to use.
20639 20870
20640If any argument to @kbd{V M} is a matrix, the operator is normally mapped 20871If any argument to @kbd{V M} is a matrix, the operator is normally mapped
20641across all elements of the matrix. For example, given the matrix 20872across all elements of the matrix. For example, given the matrix
20642@cite{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to 20873@expr{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to
20643produce another @c{$3\times2$} 20874produce another
20644@asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}. 20875@texline @tmath{3\times2}
20876@infoline 3x2
20877matrix, @expr{[[1, 2, 3], [4, 5, 6]]}.
20645 20878
20646@tindex mapr 20879@tindex mapr
20647The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the 20880The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the
20648operator prompt) maps by rows instead. For example, @kbd{V M _ A} views 20881operator prompt) maps by rows instead. For example, @kbd{V M _ A} views
20649the above matrix as a vector of two 3-element row vectors. It produces 20882the above matrix as a vector of two 3-element row vectors. It produces
20650a new vector which contains the absolute values of those row vectors, 20883a new vector which contains the absolute values of those row vectors,
20651namely @cite{[3.74, 8.77]}. (Recall, the absolute value of a vector is 20884namely @expr{[3.74, 8.77]}. (Recall, the absolute value of a vector is
20652defined as the square root of the sum of the squares of the elements.) 20885defined as the square root of the sum of the squares of the elements.)
20653Some operators accept vectors and return new vectors; for example, 20886Some operators accept vectors and return new vectors; for example,
20654@kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row 20887@kbd{v v} reverses a vector, so @kbd{V M _ v v} would reverse each row
20655of the matrix to get a new matrix, @cite{[[3, -2, 1], [-6, 5, -4]]}. 20888of the matrix to get a new matrix, @expr{[[3, -2, 1], [-6, 5, -4]]}.
20656 20889
20657Sometimes a vector of vectors (representing, say, strings, sets, or lists) 20890Sometimes a vector of vectors (representing, say, strings, sets, or lists)
20658happens to look like a matrix. If so, remember to use @kbd{V M _} if you 20891happens to look like a matrix. If so, remember to use @kbd{V M _} if you
@@ -20665,7 +20898,7 @@ transposes the input matrix, maps by rows, and then, if the result is a
20665matrix, transposes again. For example, @kbd{V M : A} takes the absolute 20898matrix, transposes again. For example, @kbd{V M : A} takes the absolute
20666values of the three columns of the matrix, treating each as a 2-vector, 20899values of the three columns of the matrix, treating each as a 2-vector,
20667and @kbd{V M : v v} reverses the columns to get the matrix 20900and @kbd{V M : v v} reverses the columns to get the matrix
20668@cite{[[-4, 5, -6], [1, -2, 3]]}. 20901@expr{[[-4, 5, -6], [1, -2, 3]]}.
20669 20902
20670(The symbols @kbd{_} and @kbd{:} were chosen because they had row-like 20903(The symbols @kbd{_} and @kbd{:} were chosen because they had row-like
20671and column-like appearances, and were not already taken by useful 20904and column-like appearances, and were not already taken by useful
@@ -20756,13 +20989,13 @@ vector @samp{[a - b + c - d, b - c + d, c - d, d]}.
20756@tindex reduced 20989@tindex reduced
20757@tindex rreduced 20990@tindex rreduced
20758As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For 20991As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For
20759example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will 20992example, given the matrix @expr{[[a, b, c], [d, e, f]]}, @kbd{V R +} will
20760compute @cite{a + b + c + d + e + f}. You can type @kbd{V R _} or 20993compute @expr{a + b + c + d + e + f}. You can type @kbd{V R _} or
20761@kbd{V R :} to modify this behavior. The @kbd{V R _} [@code{reducea}] 20994@kbd{V R :} to modify this behavior. The @kbd{V R _} [@code{reducea}]
20762command reduces ``across'' the matrix; it reduces each row of the matrix 20995command reduces ``across'' the matrix; it reduces each row of the matrix
20763as a vector, then collects the results. Thus @kbd{V R _ +} of this 20996as a vector, then collects the results. Thus @kbd{V R _ +} of this
20764matrix would produce @cite{[a + b + c, d + e + f]}. Similarly, @kbd{V R :} 20997matrix would produce @expr{[a + b + c, d + e + f]}. Similarly, @kbd{V R :}
20765[@code{reduced}] reduces down; @kbd{V R : +} would produce @cite{[a + d, 20998[@code{reduced}] reduces down; @kbd{V R : +} would produce @expr{[a + d,
20766b + e, c + f]}. 20999b + e, c + f]}.
20767 21000
20768@tindex reducer 21001@tindex reducer
@@ -20919,7 +21152,7 @@ influenced by the @kbd{d O} (@code{calc-flat-language}) mode;
20919The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >} 21152The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >}
20920(@code{calc-matrix-right-justify}), and @w{@kbd{v =}} 21153(@code{calc-matrix-right-justify}), and @w{@kbd{v =}}
20921(@code{calc-matrix-center-justify}) control whether matrix elements 21154(@code{calc-matrix-center-justify}) control whether matrix elements
20922are justified to the left, right, or center of their columns.@refill 21155are justified to the left, right, or center of their columns.
20923 21156
20924@kindex V [ 21157@kindex V [
20925@pindex calc-vector-brackets 21158@pindex calc-vector-brackets
@@ -20936,7 +21169,7 @@ be used in preparation for yanking a matrix into a buffer running
20936Mathematica. (In fact, the Mathematica language mode uses this mode; 21169Mathematica. (In fact, the Mathematica language mode uses this mode;
20937@pxref{Mathematica Language Mode}.) Note that, regardless of the 21170@pxref{Mathematica Language Mode}.) Note that, regardless of the
20938display mode, either brackets or braces may be used to enter vectors, 21171display mode, either brackets or braces may be used to enter vectors,
20939and parentheses may never be used for this purpose.@refill 21172and parentheses may never be used for this purpose.
20940 21173
20941@kindex V ] 21174@kindex V ]
20942@pindex calc-matrix-brackets 21175@pindex calc-matrix-brackets
@@ -20989,7 +21222,7 @@ the others are useful for display only.
20989@kindex V , 21222@kindex V ,
20990@pindex calc-vector-commas 21223@pindex calc-vector-commas
20991The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and 21224The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and
20992off in vector and matrix display.@refill 21225off in vector and matrix display.
20993 21226
20994In vectors of length one, and in all vectors when commas have been 21227In vectors of length one, and in all vectors when commas have been
20995turned off, Calc adds extra parentheses around formulas that might 21228turned off, Calc adds extra parentheses around formulas that might
@@ -21047,7 +21280,7 @@ commands use the @kbd{j} (for ``just a letter that wasn't used
21047for anything else'') prefix. 21280for anything else'') prefix.
21048 21281
21049@xref{Editing Stack Entries}, to see how to manipulate formulas 21282@xref{Editing Stack Entries}, to see how to manipulate formulas
21050using regular Emacs editing commands.@refill 21283using regular Emacs editing commands.
21051 21284
21052When doing algebraic work, you may find several of the Calculator's 21285When doing algebraic work, you may find several of the Calculator's
21053modes to be helpful, including algebraic-simplification mode (@kbd{m A}) 21286modes to be helpful, including algebraic-simplification mode (@kbd{m A})
@@ -21055,7 +21288,7 @@ or no-simplification mode (@kbd{m O}),
21055algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and 21288algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
21056symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions 21289symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions
21057of these modes. You may also wish to select ``big'' display mode (@kbd{d B}). 21290of these modes. You may also wish to select ``big'' display mode (@kbd{d B}).
21058@xref{Normal Language Modes}.@refill 21291@xref{Normal Language Modes}.
21059 21292
21060@menu 21293@menu
21061* Selecting Subformulas:: 21294* Selecting Subformulas::
@@ -21213,7 +21446,7 @@ has a selection they have no effect. This is analogous to the
21213behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection}; 21446behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection};
21214@pxref{Selections with Rewrite Rules}) and is mainly intended to be 21447@pxref{Selections with Rewrite Rules}) and is mainly intended to be
21215used in keyboard macros that implement your own selection-oriented 21448used in keyboard macros that implement your own selection-oriented
21216commands.@refill 21449commands.
21217 21450
21218Selection of sub-formulas normally treats associative terms like 21451Selection of sub-formulas normally treats associative terms like
21219@samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula. 21452@samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula.
@@ -21311,7 +21544,7 @@ If there is no current selection, @kbd{j 1} through @kbd{j 9} select
21311the @var{n}th top-level sub-formula. (In other words, they act as if 21544the @var{n}th top-level sub-formula. (In other words, they act as if
21312the entire stack entry were selected first.) To select the @var{n}th 21545the entire stack entry were selected first.) To select the @var{n}th
21313sub-formula where @var{n} is greater than nine, you must instead invoke 21546sub-formula where @var{n} is greater than nine, you must instead invoke
21314@w{@kbd{j 1}} with @var{n} as a numeric prefix argument.@refill 21547@w{@kbd{j 1}} with @var{n} as a numeric prefix argument.
21315 21548
21316@kindex j n 21549@kindex j n
21317@kindex j p 21550@kindex j p
@@ -21493,7 +21726,7 @@ the command will abort with an error message.
21493Operations on sub-formulas sometimes leave the formula as a whole 21726Operations on sub-formulas sometimes leave the formula as a whole
21494in an ``un-natural'' state. Consider negating the @samp{2 x} term 21727in an ``un-natural'' state. Consider negating the @samp{2 x} term
21495of our sample formula by selecting it and pressing @kbd{n} 21728of our sample formula by selecting it and pressing @kbd{n}
21496(@code{calc-change-sign}).@refill 21729(@code{calc-change-sign}).
21497 21730
21498@smallexample 21731@smallexample
21499@group 21732@group
@@ -21850,7 +22083,7 @@ a given function or operator to one or more equations. It is analogous
21850to @kbd{V M}, which operates on vectors instead of equations. 22083to @kbd{V M}, which operates on vectors instead of equations.
21851@pxref{Reducing and Mapping}. For example, @kbd{a M S} changes 22084@pxref{Reducing and Mapping}. For example, @kbd{a M S} changes
21852@samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with 22085@samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with
21853@samp{x = y+1} and @cite{6} on the stack produces @samp{x+6 = y+7}. 22086@samp{x = y+1} and @expr{6} on the stack produces @samp{x+6 = y+7}.
21854With two equations on the stack, @kbd{a M +} would add the lefthand 22087With two equations on the stack, @kbd{a M +} would add the lefthand
21855sides together and the righthand sides together to get the two 22088sides together and the righthand sides together to get the two
21856respective sides of a new equation. 22089respective sides of a new equation.
@@ -21899,7 +22132,7 @@ in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces
21899Note that this is a purely structural substitution; the lone @samp{x} and 22132Note that this is a purely structural substitution; the lone @samp{x} and
21900the @samp{sin(2 x)} stayed the same because they did not look like 22133the @samp{sin(2 x)} stayed the same because they did not look like
21901@samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for 22134@samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for
21902doing substitutions.@refill 22135doing substitutions.
21903 22136
21904The @kbd{a b} command normally prompts for two formulas, the old 22137The @kbd{a b} command normally prompts for two formulas, the old
21905one and the new one. If you enter a blank line for the first 22138one and the new one. If you enter a blank line for the first
@@ -21966,26 +22199,27 @@ simplifications'' occur.
21966@cindex Default simplifications 22199@cindex Default simplifications
21967This section describes the ``default simplifications,'' those which are 22200This section describes the ``default simplifications,'' those which are
21968normally applied to all results. For example, if you enter the variable 22201normally applied to all results. For example, if you enter the variable
21969@cite{x} on the stack twice and push @kbd{+}, Calc's default 22202@expr{x} on the stack twice and push @kbd{+}, Calc's default
21970simplifications automatically change @cite{x + x} to @cite{2 x}. 22203simplifications automatically change @expr{x + x} to @expr{2 x}.
21971 22204
21972The @kbd{m O} command turns off the default simplifications, so that 22205The @kbd{m O} command turns off the default simplifications, so that
21973@cite{x + x} will remain in this form unless you give an explicit 22206@expr{x + x} will remain in this form unless you give an explicit
21974``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic 22207``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic
21975Manipulation}. The @kbd{m D} command turns the default simplifications 22208Manipulation}. The @kbd{m D} command turns the default simplifications
21976back on. 22209back on.
21977 22210
21978The most basic default simplification is the evaluation of functions. 22211The most basic default simplification is the evaluation of functions.
21979For example, @cite{2 + 3} is evaluated to @cite{5}, and @cite{@t{sqrt}(9)} 22212For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@t{sqrt}(9)}
21980is evaluated to @cite{3}. Evaluation does not occur if the arguments 22213is evaluated to @expr{3}. Evaluation does not occur if the arguments
21981to a function are somehow of the wrong type (@cite{@t{tan}([2,3,4])}), 22214to a function are somehow of the wrong type @expr{@t{tan}([2,3,4])}),
21982range (@cite{@t{tan}(90)}), or number (@cite{@t{tan}(3,5)}), or if the 22215range (@expr{@t{tan}(90)}), or number (@expr{@t{tan}(3,5)}),
21983function name is not recognized (@cite{@t{f}(5)}), or if ``symbolic'' 22216or if the function name is not recognized (@expr{@t{f}(5)}), or if
21984mode (@pxref{Symbolic Mode}) prevents evaluation (@cite{@t{sqrt}(2)}). 22217``symbolic'' mode (@pxref{Symbolic Mode}) prevents evaluation
22218(@expr{@t{sqrt}(2)}).
21985 22219
21986Calc simplifies (evaluates) the arguments to a function before it 22220Calc simplifies (evaluates) the arguments to a function before it
21987simplifies the function itself. Thus @cite{@t{sqrt}(5+4)} is 22221simplifies the function itself. Thus @expr{@t{sqrt}(5+4)} is
21988simplified to @cite{@t{sqrt}(9)} before the @code{sqrt} function 22222simplified to @expr{@t{sqrt}(9)} before the @code{sqrt} function
21989itself is applied. There are very few exceptions to this rule: 22223itself is applied. There are very few exceptions to this rule:
21990@code{quote}, @code{lambda}, and @code{condition} (the @code{::} 22224@code{quote}, @code{lambda}, and @code{condition} (the @code{::}
21991operator) do not evaluate their arguments, @code{if} (the @code{? :} 22225operator) do not evaluate their arguments, @code{if} (the @code{? :}
@@ -22024,9 +22258,9 @@ And now, on with the default simplifications:
22024Arithmetic operators like @kbd{+} and @kbd{*} always take two 22258Arithmetic operators like @kbd{+} and @kbd{*} always take two
22025arguments in Calc's internal form. Sums and products of three or 22259arguments in Calc's internal form. Sums and products of three or
22026more terms are arranged by the associative law of algebra into 22260more terms are arranged by the associative law of algebra into
22027a left-associative form for sums, @cite{((a + b) + c) + d}, and 22261a left-associative form for sums, @expr{((a + b) + c) + d}, and
22028a right-associative form for products, @cite{a * (b * (c * d))}. 22262a right-associative form for products, @expr{a * (b * (c * d))}.
22029Formulas like @cite{(a + b) + (c + d)} are rearranged to 22263Formulas like @expr{(a + b) + (c + d)} are rearranged to
22030left-associative form, though this rarely matters since Calc's 22264left-associative form, though this rarely matters since Calc's
22031algebra commands are designed to hide the inner structure of 22265algebra commands are designed to hide the inner structure of
22032sums and products as much as possible. Sums and products in 22266sums and products as much as possible. Sums and products in
@@ -22034,199 +22268,213 @@ their proper associative form will be written without parentheses
22034in the examples below. 22268in the examples below.
22035 22269
22036Sums and products are @emph{not} rearranged according to the 22270Sums and products are @emph{not} rearranged according to the
22037commutative law (@cite{a + b} to @cite{b + a}) except in a few 22271commutative law (@expr{a + b} to @expr{b + a}) except in a few
22038special cases described below. Some algebra programs always 22272special cases described below. Some algebra programs always
22039rearrange terms into a canonical order, which enables them to 22273rearrange terms into a canonical order, which enables them to
22040see that @cite{a b + b a} can be simplified to @cite{2 a b}. 22274see that @expr{a b + b a} can be simplified to @expr{2 a b}.
22041Calc assumes you have put the terms into the order you want 22275Calc assumes you have put the terms into the order you want
22042and generally leaves that order alone, with the consequence 22276and generally leaves that order alone, with the consequence
22043that formulas like the above will only be simplified if you 22277that formulas like the above will only be simplified if you
22044explicitly give the @kbd{a s} command. @xref{Algebraic 22278explicitly give the @kbd{a s} command. @xref{Algebraic
22045Simplifications}. 22279Simplifications}.
22046 22280
22047Differences @cite{a - b} are treated like sums @cite{a + (-b)} 22281Differences @expr{a - b} are treated like sums @expr{a + (-b)}
22048for purposes of simplification; one of the default simplifications 22282for purposes of simplification; one of the default simplifications
22049is to rewrite @cite{a + (-b)} or @cite{(-b) + a}, where @cite{-b} 22283is to rewrite @expr{a + (-b)} or @expr{(-b) + a}, where @expr{-b}
22050represents a ``negative-looking'' term, into @cite{a - b} form. 22284represents a ``negative-looking'' term, into @expr{a - b} form.
22051``Negative-looking'' means negative numbers, negated formulas like 22285``Negative-looking'' means negative numbers, negated formulas like
22052@cite{-x}, and products or quotients in which either term is 22286@expr{-x}, and products or quotients in which either term is
22053negative-looking. 22287negative-looking.
22054 22288
22055Other simplifications involving negation are @cite{-(-x)} to @cite{x}; 22289Other simplifications involving negation are @expr{-(-x)} to @expr{x};
22056@cite{-(a b)} or @cite{-(a/b)} where either @cite{a} or @cite{b} is 22290@expr{-(a b)} or @expr{-(a/b)} where either @expr{a} or @expr{b} is
22057negative-looking, simplified by negating that term, or else where 22291negative-looking, simplified by negating that term, or else where
22058@cite{a} or @cite{b} is any number, by negating that number; 22292@expr{a} or @expr{b} is any number, by negating that number;
22059@cite{-(a + b)} to @cite{-a - b}, and @cite{-(b - a)} to @cite{a - b}. 22293@expr{-(a + b)} to @expr{-a - b}, and @expr{-(b - a)} to @expr{a - b}.
22060(This, and rewriting @cite{(-b) + a} to @cite{a - b}, are the only 22294(This, and rewriting @expr{(-b) + a} to @expr{a - b}, are the only
22061cases where the order of terms in a sum is changed by the default 22295cases where the order of terms in a sum is changed by the default
22062simplifications.) 22296simplifications.)
22063 22297
22064The distributive law is used to simplify sums in some cases: 22298The distributive law is used to simplify sums in some cases:
22065@cite{a x + b x} to @cite{(a + b) x}, where @cite{a} represents 22299@expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents
22066a number or an implicit 1 or @i{-1} (as in @cite{x} or @cite{-x}) 22300a number or an implicit 1 or @i{-1} (as in @expr{x} or @expr{-x})
22067and similarly for @cite{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or 22301and similarly for @expr{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or
22068@kbd{j M} commands to merge sums with non-numeric coefficients 22302@kbd{j M} commands to merge sums with non-numeric coefficients
22069using the distributive law. 22303using the distributive law.
22070 22304
22071The distributive law is only used for sums of two terms, or 22305The distributive law is only used for sums of two terms, or
22072for adjacent terms in a larger sum. Thus @cite{a + b + b + c} 22306for adjacent terms in a larger sum. Thus @expr{a + b + b + c}
22073is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b} 22307is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b}
22074is not simplified. The reason is that comparing all terms of a 22308is not simplified. The reason is that comparing all terms of a
22075sum with one another would require time proportional to the 22309sum with one another would require time proportional to the
22076square of the number of terms; Calc relegates potentially slow 22310square of the number of terms; Calc relegates potentially slow
22077operations like this to commands that have to be invoked 22311operations like this to commands that have to be invoked
22078explicitly, like @kbd{a s}. 22312explicitly, like @kbd{a s}.
22079 22313
22080Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}. 22314Finally, @expr{a + 0} and @expr{0 + a} are simplified to @expr{a}.
22081A consequence of the above rules is that @cite{0 - a} is simplified 22315A consequence of the above rules is that @expr{0 - a} is simplified
22082to @cite{-a}. 22316to @expr{-a}.
22083 22317
22084@tex 22318@tex
22085\bigskip 22319\bigskip
22086@end tex 22320@end tex
22087 22321
22088The products @cite{1 a} and @cite{a 1} are simplified to @cite{a}; 22322The products @expr{1 a} and @expr{a 1} are simplified to @expr{a};
22089@cite{(-1) a} and @cite{a (-1)} are simplified to @cite{-a}; 22323@expr{(-1) a} and @expr{a (-1)} are simplified to @expr{-a};
22090@cite{0 a} and @cite{a 0} are simplified to @cite{0}, except that 22324@expr{0 a} and @expr{a 0} are simplified to @expr{0}, except that
22091in matrix mode where @cite{a} is not provably scalar the result 22325in matrix mode where @expr{a} is not provably scalar the result
22092is the generic zero matrix @samp{idn(0)}, and that if @cite{a} is 22326is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is
22093infinite the result is @samp{nan}. 22327infinite the result is @samp{nan}.
22094 22328
22095Also, @cite{(-a) b} and @cite{a (-b)} are simplified to @cite{-(a b)}, 22329Also, @expr{(-a) b} and @expr{a (-b)} are simplified to @expr{-(a b)},
22096where this occurs for negated formulas but not for regular negative 22330where this occurs for negated formulas but not for regular negative
22097numbers. 22331numbers.
22098 22332
22099Products are commuted only to move numbers to the front: 22333Products are commuted only to move numbers to the front:
22100@cite{a b 2} is commuted to @cite{2 a b}. 22334@expr{a b 2} is commuted to @expr{2 a b}.
22101 22335
22102The product @cite{a (b + c)} is distributed over the sum only if 22336The product @expr{a (b + c)} is distributed over the sum only if
22103@cite{a} and at least one of @cite{b} and @cite{c} are numbers: 22337@expr{a} and at least one of @expr{b} and @expr{c} are numbers:
22104@cite{2 (x + 3)} goes to @cite{2 x + 6}. The formula 22338@expr{2 (x + 3)} goes to @expr{2 x + 6}. The formula
22105@cite{(-a) (b - c)}, where @cite{-a} is a negative number, is 22339@expr{(-a) (b - c)}, where @expr{-a} is a negative number, is
22106rewritten to @cite{a (c - b)}. 22340rewritten to @expr{a (c - b)}.
22107 22341
22108The distributive law of products and powers is used for adjacent 22342The distributive law of products and powers is used for adjacent
22109terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$} 22343terms of the product: @expr{x^a x^b} goes to
22110@cite{x^(a+b)} 22344@texline @tmath{x^{a+b}}
22111where @cite{a} is a number, or an implicit 1 (as in @cite{x}), 22345@infoline @expr{x^(a+b)}
22112or the implicit one-half of @cite{@t{sqrt}(x)}, and similarly for 22346where @expr{a} is a number, or an implicit 1 (as in @expr{x}),
22113@cite{b}. The result is written using @samp{sqrt} or @samp{1/sqrt} 22347or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for
22114if the sum of the powers is @cite{1/2} or @cite{-1/2}, respectively. 22348@expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt}
22349if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively.
22115If the sum of the powers is zero, the product is simplified to 22350If the sum of the powers is zero, the product is simplified to
22116@cite{1} or to @samp{idn(1)} if matrix mode is enabled. 22351@expr{1} or to @samp{idn(1)} if matrix mode is enabled.
22117 22352
22118The product of a negative power times anything but another negative 22353The product of a negative power times anything but another negative
22119power is changed to use division: @c{$x^{-2} y$} 22354power is changed to use division:
22120@cite{x^(-2) y} goes to @cite{y / x^2} unless matrix mode is 22355@texline @tmath{x^{-2} y}
22121in effect and neither @cite{x} nor @cite{y} are scalar (in which 22356@infoline @expr{x^(-2) y}
22357goes to @expr{y / x^2} unless matrix mode is
22358in effect and neither @expr{x} nor @expr{y} are scalar (in which
22122case it is considered unsafe to rearrange the order of the terms). 22359case it is considered unsafe to rearrange the order of the terms).
22123 22360
22124Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also 22361Finally, @expr{a (b/c)} is rewritten to @expr{(a b)/c}, and also
22125@cite{(a/b) c} is changed to @cite{(a c)/b} unless in matrix mode. 22362@expr{(a/b) c} is changed to @expr{(a c)/b} unless in matrix mode.
22126 22363
22127@tex 22364@tex
22128\bigskip 22365\bigskip
22129@end tex 22366@end tex
22130 22367
22131Simplifications for quotients are analogous to those for products. 22368Simplifications for quotients are analogous to those for products.
22132The quotient @cite{0 / x} is simplified to @cite{0}, with the same 22369The quotient @expr{0 / x} is simplified to @expr{0}, with the same
22133exceptions that were noted for @cite{0 x}. Likewise, @cite{x / 1} 22370exceptions that were noted for @expr{0 x}. Likewise, @expr{x / 1}
22134and @cite{x / (-1)} are simplified to @cite{x} and @cite{-x}, 22371and @expr{x / (-1)} are simplified to @expr{x} and @expr{-x},
22135respectively. 22372respectively.
22136 22373
22137The quotient @cite{x / 0} is left unsimplified or changed to an 22374The quotient @expr{x / 0} is left unsimplified or changed to an
22138infinite quantity, as directed by the current infinite mode. 22375infinite quantity, as directed by the current infinite mode.
22139@xref{Infinite Mode}. 22376@xref{Infinite Mode}.
22140 22377
22141The expression @c{$a / b^{-c}$} 22378The expression
22142@cite{a / b^(-c)} is changed to @cite{a b^c}, 22379@texline @tmath{a / b^{-c}}
22143where @cite{-c} is any negative-looking power. Also, @cite{1 / b^c} 22380@infoline @expr{a / b^(-c)}
22144is changed to @c{$b^{-c}$} 22381is changed to @expr{a b^c}, where @expr{-c} is any negative-looking
22145@cite{b^(-c)} for any power @cite{c}. 22382power. Also, @expr{1 / b^c} is changed to
22146 22383@texline @tmath{b^{-c}}
22147Also, @cite{(-a) / b} and @cite{a / (-b)} go to @cite{-(a/b)}; 22384@infoline @expr{b^(-c)}
22148@cite{(a/b) / c} goes to @cite{a / (b c)}; and @cite{a / (b/c)} 22385for any power @expr{c}.
22149goes to @cite{(a c) / b} unless matrix mode prevents this 22386
22150rearrangement. Similarly, @cite{a / (b:c)} is simplified to 22387Also, @expr{(-a) / b} and @expr{a / (-b)} go to @expr{-(a/b)};
22151@cite{(c:b) a} for any fraction @cite{b:c}. 22388@expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)}
22152 22389goes to @expr{(a c) / b} unless matrix mode prevents this
22153The distributive law is applied to @cite{(a + b) / c} only if 22390rearrangement. Similarly, @expr{a / (b:c)} is simplified to
22154@cite{c} and at least one of @cite{a} and @cite{b} are numbers. 22391@expr{(c:b) a} for any fraction @expr{b:c}.
22392
22393The distributive law is applied to @expr{(a + b) / c} only if
22394@expr{c} and at least one of @expr{a} and @expr{b} are numbers.
22155Quotients of powers and square roots are distributed just as 22395Quotients of powers and square roots are distributed just as
22156described for multiplication. 22396described for multiplication.
22157 22397
22158Quotients of products cancel only in the leading terms of the 22398Quotients of products cancel only in the leading terms of the
22159numerator and denominator. In other words, @cite{a x b / a y b} 22399numerator and denominator. In other words, @expr{a x b / a y b}
22160is cancelled to @cite{x b / y b} but not to @cite{x / y}. Once 22400is cancelled to @expr{x b / y b} but not to @expr{x / y}. Once
22161again this is because full cancellation can be slow; use @kbd{a s} 22401again this is because full cancellation can be slow; use @kbd{a s}
22162to cancel all terms of the quotient. 22402to cancel all terms of the quotient.
22163 22403
22164Quotients of negative-looking values are simplified according 22404Quotients of negative-looking values are simplified according
22165to @cite{(-a) / (-b)} to @cite{a / b}, @cite{(-a) / (b - c)} 22405to @expr{(-a) / (-b)} to @expr{a / b}, @expr{(-a) / (b - c)}
22166to @cite{a / (c - b)}, and @cite{(a - b) / (-c)} to @cite{(b - a) / c}. 22406to @expr{a / (c - b)}, and @expr{(a - b) / (-c)} to @expr{(b - a) / c}.
22167 22407
22168@tex 22408@tex
22169\bigskip 22409\bigskip
22170@end tex 22410@end tex
22171 22411
22172The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)} 22412The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)}
22173in matrix mode. The formula @cite{0^x} is simplified to @cite{0} 22413in matrix mode. The formula @expr{0^x} is simplified to @expr{0}
22174unless @cite{x} is a negative number or complex number, in which 22414unless @expr{x} is a negative number or complex number, in which
22175case the result is an infinity or an unsimplified formula according 22415case the result is an infinity or an unsimplified formula according
22176to the current infinite mode. Note that @cite{0^0} is an 22416to the current infinite mode. Note that @expr{0^0} is an
22177indeterminate form, as evidenced by the fact that the simplifications 22417indeterminate form, as evidenced by the fact that the simplifications
22178for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}. 22418for @expr{x^0} and @expr{0^x} conflict when @expr{x=0}.
22179 22419
22180Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c} 22420Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c}
22181are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c} 22421are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c}
22182is an integer, or if either @cite{a} or @cite{b} are nonnegative 22422is an integer, or if either @expr{a} or @expr{b} are nonnegative
22183real numbers. Powers of powers @cite{(a^b)^c} are simplified to 22423real numbers. Powers of powers @expr{(a^b)^c} are simplified to
22184@c{$a^{b c}$} 22424@texline @tmath{a^{b c}}
22185@cite{a^(b c)} only when @cite{c} is an integer and @cite{b c} also 22425@infoline @expr{a^(b c)}
22426only when @expr{c} is an integer and @expr{b c} also
22186evaluates to an integer. Without these restrictions these simplifications 22427evaluates to an integer. Without these restrictions these simplifications
22187would not be safe because of problems with principal values. 22428would not be safe because of problems with principal values.
22188(In other words, @c{$((-3)^{1/2})^2$} 22429(In other words,
22189@cite{((-3)^1:2)^2} is safe to simplify, but 22430@texline @tmath{((-3)^{1/2})^2}
22190@c{$((-3)^2)^{1/2}$} 22431@infoline @expr{((-3)^1:2)^2}
22191@cite{((-3)^2)^1:2} is not.) @xref{Declarations}, for ways to inform 22432is safe to simplify, but
22192Calc that your variables satisfy these requirements. 22433@texline @tmath{((-3)^2)^{1/2}}
22193 22434@infoline @expr{((-3)^2)^1:2}
22194As a special case of this rule, @cite{@t{sqrt}(x)^n} is simplified to 22435is not.) @xref{Declarations}, for ways to inform Calc that your
22195@c{$x^{n/2}$} 22436variables satisfy these requirements.
22196@cite{x^(n/2)} only for even integers @cite{n}. 22437
22197 22438As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to
22198If @cite{a} is known to be real, @cite{b} is an even integer, and 22439@texline @tmath{x^{n/2}}
22199@cite{c} is a half- or quarter-integer, then @cite{(a^b)^c} is 22440@infoline @expr{x^(n/2)}
22200simplified to @c{$@t{abs}(a^{b c})$} 22441only for even integers @expr{n}.
22201@cite{@t{abs}(a^(b c))}. 22442
22202 22443If @expr{a} is known to be real, @expr{b} is an even integer, and
22203Also, @cite{(-a)^b} is simplified to @cite{a^b} if @cite{b} is an 22444@expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is
22204even integer, or to @cite{-(a^b)} if @cite{b} is an odd integer, 22445simplified to @expr{@t{abs}(a^(b c))}.
22205for any negative-looking expression @cite{-a}. 22446
22206 22447Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an
22207Square roots @cite{@t{sqrt}(x)} generally act like one-half powers 22448even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer,
22208@c{$x^{1:2}$} 22449for any negative-looking expression @expr{-a}.
22209@cite{x^1:2} for the purposes of the above-listed simplifications. 22450
22210 22451Square roots @expr{@t{sqrt}(x)} generally act like one-half powers
22211Also, note that @c{$1 / x^{1:2}$} 22452@texline @tmath{x^{1:2}}
22212@cite{1 / x^1:2} is changed to @c{$x^{-1:2}$} 22453@infoline @expr{x^1:2}
22213@cite{x^(-1:2)}, 22454for the purposes of the above-listed simplifications.
22214but @cite{1 / @t{sqrt}(x)} is left alone. 22455
22456Also, note that
22457@texline @tmath{1 / x^{1:2}}
22458@infoline @expr{1 / x^1:2}
22459is changed to
22460@texline @tmath{x^{-1:2}},
22461@infoline @expr{x^(-1:2)},
22462but @expr{1 / @t{sqrt}(x)} is left alone.
22215 22463
22216@tex 22464@tex
22217\bigskip 22465\bigskip
22218@end tex 22466@end tex
22219 22467
22220Generic identity matrices (@pxref{Matrix Mode}) are simplified by the 22468Generic identity matrices (@pxref{Matrix Mode}) are simplified by the
22221following rules: @cite{@t{idn}(a) + b} to @cite{a + b} if @cite{b} 22469following rules: @expr{@t{idn}(a) + b} to @expr{a + b} if @expr{b}
22222is provably scalar, or expanded out if @cite{b} is a matrix; 22470is provably scalar, or expanded out if @expr{b} is a matrix;
22223@cite{@t{idn}(a) + @t{idn}(b)} to @cite{@t{idn}(a + b)}; 22471@expr{@t{idn}(a) + @t{idn}(b)} to @expr{@t{idn}(a + b)};
22224@cite{-@t{idn}(a)} to @cite{@t{idn}(-a)}; @cite{a @t{idn}(b)} to 22472@expr{-@t{idn}(a)} to @expr{@t{idn}(-a)}; @expr{a @t{idn}(b)} to
22225@cite{@t{idn}(a b)} if @cite{a} is provably scalar, or to @cite{a b} 22473@expr{@t{idn}(a b)} if @expr{a} is provably scalar, or to @expr{a b}
22226if @cite{a} is provably non-scalar; @cite{@t{idn}(a) @t{idn}(b)} 22474if @expr{a} is provably non-scalar; @expr{@t{idn}(a) @t{idn}(b)} to
22227to @cite{@t{idn}(a b)}; analogous simplifications for quotients 22475@expr{@t{idn}(a b)}; analogous simplifications for quotients involving
22228involving @code{idn}; and @cite{@t{idn}(a)^n} to @cite{@t{idn}(a^n)} 22476@code{idn}; and @expr{@t{idn}(a)^n} to @expr{@t{idn}(a^n)} where
22229where @cite{n} is an integer. 22477@expr{n} is an integer.
22230 22478
22231@tex 22479@tex
22232\bigskip 22480\bigskip
@@ -22234,26 +22482,28 @@ where @cite{n} is an integer.
22234 22482
22235The @code{floor} function and other integer truncation functions 22483The @code{floor} function and other integer truncation functions
22236vanish if the argument is provably integer-valued, so that 22484vanish if the argument is provably integer-valued, so that
22237@cite{@t{floor}(@t{round}(x))} simplifies to @cite{@t{round}(x)}. 22485@expr{@t{floor}(@t{round}(x))} simplifies to @expr{@t{round}(x)}.
22238Also, combinations of @code{float}, @code{floor} and its friends, 22486Also, combinations of @code{float}, @code{floor} and its friends,
22239and @code{ffloor} and its friends, are simplified in appropriate 22487and @code{ffloor} and its friends, are simplified in appropriate
22240ways. @xref{Integer Truncation}. 22488ways. @xref{Integer Truncation}.
22241 22489
22242The expression @cite{@t{abs}(-x)} changes to @cite{@t{abs}(x)}. 22490The expression @expr{@t{abs}(-x)} changes to @expr{@t{abs}(x)}.
22243The expression @cite{@t{abs}(@t{abs}(x))} changes to @cite{@t{abs}(x)}; 22491The expression @expr{@t{abs}(@t{abs}(x))} changes to
22244in fact, @cite{@t{abs}(x)} changes to @cite{x} or @cite{-x} if @cite{x} 22492@expr{@t{abs}(x)}; in fact, @expr{@t{abs}(x)} changes to @expr{x} or
22245is provably nonnegative or nonpositive (@pxref{Declarations}). 22493@expr{-x} if @expr{x} is provably nonnegative or nonpositive
22494(@pxref{Declarations}).
22246 22495
22247While most functions do not recognize the variable @code{i} as an 22496While most functions do not recognize the variable @code{i} as an
22248imaginary number, the @code{arg} function does handle the two cases 22497imaginary number, the @code{arg} function does handle the two cases
22249@cite{@t{arg}(@t{i})} and @cite{@t{arg}(-@t{i})} just for convenience. 22498@expr{@t{arg}(@t{i})} and @expr{@t{arg}(-@t{i})} just for convenience.
22250 22499
22251The expression @cite{@t{conj}(@t{conj}(x))} simplifies to @cite{x}. 22500The expression @expr{@t{conj}(@t{conj}(x))} simplifies to @expr{x}.
22252Various other expressions involving @code{conj}, @code{re}, and 22501Various other expressions involving @code{conj}, @code{re}, and
22253@code{im} are simplified, especially if some of the arguments are 22502@code{im} are simplified, especially if some of the arguments are
22254provably real or involve the constant @code{i}. For example, 22503provably real or involve the constant @code{i}. For example,
22255@cite{@t{conj}(a + b i)} is changed to @cite{@t{conj}(a) - @t{conj}(b) i}, 22504@expr{@t{conj}(a + b i)} is changed to
22256or to @cite{a - b i} if @cite{a} and @cite{b} are known to be real. 22505@expr{@t{conj}(a) - @t{conj}(b) i}, or to @expr{a - b i} if @expr{a}
22506and @expr{b} are known to be real.
22257 22507
22258Functions like @code{sin} and @code{arctan} generally don't have 22508Functions like @code{sin} and @code{arctan} generally don't have
22259any default simplifications beyond simply evaluating the functions 22509any default simplifications beyond simply evaluating the functions
@@ -22261,18 +22511,18 @@ for suitable numeric arguments and infinity. The @kbd{a s} command
22261described in the next section does provide some simplifications for 22511described in the next section does provide some simplifications for
22262these functions, though. 22512these functions, though.
22263 22513
22264One important simplification that does occur is that @cite{@t{ln}(@t{e})} 22514One important simplification that does occur is that
22265is simplified to 1, and @cite{@t{ln}(@t{e}^x)} is simplified to @cite{x} 22515@expr{@t{ln}(@t{e})} is simplified to 1, and @expr{@t{ln}(@t{e}^x)} is
22266for any @cite{x}. This occurs even if you have stored a different 22516simplified to @expr{x} for any @expr{x}. This occurs even if you have
22267value in the Calc variable @samp{e}; but this would be a bad idea 22517stored a different value in the Calc variable @samp{e}; but this would
22268in any case if you were also using natural logarithms! 22518be a bad idea in any case if you were also using natural logarithms!
22269 22519
22270Among the logical functions, @t{(@var{a} <= @var{b})} changes to 22520Among the logical functions, @t{(@var{a} <= @var{b})} changes to
22271@t{@var{a} > @var{b}} and so on. Equations and inequalities where both sides 22521@t{@var{a} > @var{b}} and so on. Equations and inequalities where both sides
22272are either negative-looking or zero are simplified by negating both sides 22522are either negative-looking or zero are simplified by negating both sides
22273and reversing the inequality. While it might seem reasonable to simplify 22523and reversing the inequality. While it might seem reasonable to simplify
22274@cite{!!x} to @cite{x}, this would not be valid in general because 22524@expr{!!x} to @expr{x}, this would not be valid in general because
22275@cite{!!2} is 1, not 2. 22525@expr{!!2} is 1, not 2.
22276 22526
22277Most other Calc functions have few if any default simplifications 22527Most other Calc functions have few if any default simplifications
22278defined, aside of course from evaluation when the arguments are 22528defined, aside of course from evaluation when the arguments are
@@ -22309,13 +22559,13 @@ then the built-in simplifications, and so on.
22309@end tex 22559@end tex
22310 22560
22311Sums are simplified in two ways. Constant terms are commuted to the 22561Sums are simplified in two ways. Constant terms are commuted to the
22312end of the sum, so that @cite{a + 2 + b} changes to @cite{a + b + 2}. 22562end of the sum, so that @expr{a + 2 + b} changes to @expr{a + b + 2}.
22313The only exception is that a constant will not be commuted away 22563The only exception is that a constant will not be commuted away
22314from the first position of a difference, i.e., @cite{2 - x} is not 22564from the first position of a difference, i.e., @expr{2 - x} is not
22315commuted to @cite{-x + 2}. 22565commuted to @expr{-x + 2}.
22316 22566
22317Also, terms of sums are combined by the distributive law, as in 22567Also, terms of sums are combined by the distributive law, as in
22318@cite{x + y + 2 x} to @cite{y + 3 x}. This always occurs for 22568@expr{x + y + 2 x} to @expr{y + 3 x}. This always occurs for
22319adjacent terms, but @kbd{a s} compares all pairs of terms including 22569adjacent terms, but @kbd{a s} compares all pairs of terms including
22320non-adjacent ones. 22570non-adjacent ones.
22321 22571
@@ -22324,10 +22574,10 @@ non-adjacent ones.
22324@end tex 22574@end tex
22325 22575
22326Products are sorted into a canonical order using the commutative 22576Products are sorted into a canonical order using the commutative
22327law. For example, @cite{b c a} is commuted to @cite{a b c}. 22577law. For example, @expr{b c a} is commuted to @expr{a b c}.
22328This allows easier comparison of products; for example, the default 22578This allows easier comparison of products; for example, the default
22329simplifications will not change @cite{x y + y x} to @cite{2 x y}, 22579simplifications will not change @expr{x y + y x} to @expr{2 x y},
22330but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y}, 22580but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y},
22331and then the default simplifications are able to recognize a sum 22581and then the default simplifications are able to recognize a sum
22332of identical terms. 22582of identical terms.
22333 22583
@@ -22346,15 +22596,15 @@ use for adjacent terms of products.
22346 22596
22347Even though sums are not sorted, the commutative law is still 22597Even though sums are not sorted, the commutative law is still
22348taken into account when terms of a product are being compared. 22598taken into account when terms of a product are being compared.
22349Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}. 22599Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}.
22350A subtle point is that @cite{(x - y) (y - x)} will @emph{not} 22600A subtle point is that @expr{(x - y) (y - x)} will @emph{not}
22351be simplified to @cite{-(x - y)^2}; Calc does not notice that 22601be simplified to @expr{-(x - y)^2}; Calc does not notice that
22352one term can be written as a constant times the other, even if 22602one term can be written as a constant times the other, even if
22353that constant is @i{-1}. 22603that constant is @i{-1}.
22354 22604
22355A fraction times any expression, @cite{(a:b) x}, is changed to 22605A fraction times any expression, @expr{(a:b) x}, is changed to
22356a quotient involving integers: @cite{a x / b}. This is not 22606a quotient involving integers: @expr{a x / b}. This is not
22357done for floating-point numbers like @cite{0.5}, however. This 22607done for floating-point numbers like @expr{0.5}, however. This
22358is one reason why you may find it convenient to turn Fraction mode 22608is one reason why you may find it convenient to turn Fraction mode
22359on while doing algebra; @pxref{Fraction Mode}. 22609on while doing algebra; @pxref{Fraction Mode}.
22360 22610
@@ -22364,25 +22614,25 @@ on while doing algebra; @pxref{Fraction Mode}.
22364 22614
22365Quotients are simplified by comparing all terms in the numerator 22615Quotients are simplified by comparing all terms in the numerator
22366with all terms in the denominator for possible cancellation using 22616with all terms in the denominator for possible cancellation using
22367the distributive law. For example, @cite{a x^2 b / c x^3 d} will 22617the distributive law. For example, @expr{a x^2 b / c x^3 d} will
22368cancel @cite{x^2} from both sides to get @cite{a b / c x d}. 22618cancel @expr{x^2} from both sides to get @expr{a b / c x d}.
22369(The terms in the denominator will then be rearranged to @cite{c d x} 22619(The terms in the denominator will then be rearranged to @expr{c d x}
22370as described above.) If there is any common integer or fractional 22620as described above.) If there is any common integer or fractional
22371factor in the numerator and denominator, it is cancelled out; 22621factor in the numerator and denominator, it is cancelled out;
22372for example, @cite{(4 x + 6) / 8 x} simplifies to @cite{(2 x + 3) / 4 x}. 22622for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}.
22373 22623
22374Non-constant common factors are not found even by @kbd{a s}. To 22624Non-constant common factors are not found even by @kbd{a s}. To
22375cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first 22625cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first
22376use @kbd{j M} on the product @cite{a x} to Merge the numerator to 22626use @kbd{j M} on the product @expr{a x} to Merge the numerator to
22377@cite{a (1+x)}, which can then be simplified successfully. 22627@expr{a (1+x)}, which can then be simplified successfully.
22378 22628
22379@tex 22629@tex
22380\bigskip 22630\bigskip
22381@end tex 22631@end tex
22382 22632
22383Integer powers of the variable @code{i} are simplified according 22633Integer powers of the variable @code{i} are simplified according
22384to the identity @cite{i^2 = -1}. If you store a new value other 22634to the identity @expr{i^2 = -1}. If you store a new value other
22385than the complex number @cite{(0,1)} in @code{i}, this simplification 22635than the complex number @expr{(0,1)} in @code{i}, this simplification
22386will no longer occur. This is done by @kbd{a s} instead of by default 22636will no longer occur. This is done by @kbd{a s} instead of by default
22387in case someone (unwisely) uses the name @code{i} for a variable 22637in case someone (unwisely) uses the name @code{i} for a variable
22388unrelated to complex numbers; it would be unfortunate if Calc 22638unrelated to complex numbers; it would be unfortunate if Calc
@@ -22392,26 +22642,26 @@ user might not have been thinking of.
22392Square roots of integer or rational arguments are simplified in 22642Square roots of integer or rational arguments are simplified in
22393several ways. (Note that these will be left unevaluated only in 22643several ways. (Note that these will be left unevaluated only in
22394Symbolic mode.) First, square integer or rational factors are 22644Symbolic mode.) First, square integer or rational factors are
22395pulled out so that @cite{@t{sqrt}(8)} is rewritten as 22645pulled out so that @expr{@t{sqrt}(8)} is rewritten as
22396@c{$2\,\t{sqrt}(2)$} 22646@texline @tmath{$2\,\t{sqrt}(2)$}.
22397@cite{2 sqrt(2)}. Conceptually speaking this implies factoring 22647@infoline @expr{2 sqrt(2)}.
22398the argument into primes and moving pairs of primes out of the 22648Conceptually speaking this implies factoring the argument into primes
22399square root, but for reasons of efficiency Calc only looks for 22649and moving pairs of primes out of the square root, but for reasons of
22400primes up to 29. 22650efficiency Calc only looks for primes up to 29.
22401 22651
22402Square roots in the denominator of a quotient are moved to the 22652Square roots in the denominator of a quotient are moved to the
22403numerator: @cite{1 / @t{sqrt}(3)} changes to @cite{@t{sqrt}(3) / 3}. 22653numerator: @expr{1 / @t{sqrt}(3)} changes to @expr{@t{sqrt}(3) / 3}.
22404The same effect occurs for the square root of a fraction: 22654The same effect occurs for the square root of a fraction:
22405@cite{@t{sqrt}(2:3)} changes to @cite{@t{sqrt}(6) / 3}. 22655@expr{@t{sqrt}(2:3)} changes to @expr{@t{sqrt}(6) / 3}.
22406 22656
22407@tex 22657@tex
22408\bigskip 22658\bigskip
22409@end tex 22659@end tex
22410 22660
22411The @code{%} (modulo) operator is simplified in several ways 22661The @code{%} (modulo) operator is simplified in several ways
22412when the modulus @cite{M} is a positive real number. First, if 22662when the modulus @expr{M} is a positive real number. First, if
22413the argument is of the form @cite{x + n} for some real number 22663the argument is of the form @expr{x + n} for some real number
22414@cite{n}, then @cite{n} is itself reduced modulo @cite{M}. For 22664@expr{n}, then @expr{n} is itself reduced modulo @expr{M}. For
22415example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}. 22665example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}.
22416 22666
22417If the argument is multiplied by a constant, and this constant 22667If the argument is multiplied by a constant, and this constant
@@ -22435,16 +22685,16 @@ declared to be an integer.
22435@end tex 22685@end tex
22436 22686
22437Trigonometric functions are simplified in several ways. First, 22687Trigonometric functions are simplified in several ways. First,
22438@cite{@t{sin}(@t{arcsin}(x))} is simplified to @cite{x}, and 22688@expr{@t{sin}(@t{arcsin}(x))} is simplified to @expr{x}, and
22439similarly for @code{cos} and @code{tan}. If the argument to 22689similarly for @code{cos} and @code{tan}. If the argument to
22440@code{sin} is negative-looking, it is simplified to @cite{-@t{sin}(x)}, 22690@code{sin} is negative-looking, it is simplified to
22441and similarly for @code{cos} and @code{tan}. Finally, certain 22691@expr{-@t{sin}(x),}, and similarly for @code{cos} and @code{tan}.
22442special values of the argument are recognized; 22692Finally, certain special values of the argument are recognized;
22443@pxref{Trigonometric and Hyperbolic Functions}. 22693@pxref{Trigonometric and Hyperbolic Functions}.
22444 22694
22445Trigonometric functions of inverses of different trigonometric 22695Trigonometric functions of inverses of different trigonometric
22446functions can also be simplified, as in @cite{@t{sin}(@t{arccos}(x))} 22696functions can also be simplified, as in @expr{@t{sin}(@t{arccos}(x))}
22447to @cite{@t{sqrt}(1 - x^2)}. 22697to @expr{@t{sqrt}(1 - x^2)}.
22448 22698
22449Hyperbolic functions of their inverses and of negative-looking 22699Hyperbolic functions of their inverses and of negative-looking
22450arguments are also handled, as are exponentials of inverse 22700arguments are also handled, as are exponentials of inverse
@@ -22453,26 +22703,31 @@ hyperbolic functions.
22453No simplifications for inverse trigonometric and hyperbolic 22703No simplifications for inverse trigonometric and hyperbolic
22454functions are known, except for negative arguments of @code{arcsin}, 22704functions are known, except for negative arguments of @code{arcsin},
22455@code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that 22705@code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that
22456@cite{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to 22706@expr{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to
22457@cite{x}, since this only correct within an integer multiple 22707@expr{x}, since this only correct within an integer multiple of
22458of @c{$2 \pi$} 22708@texline @tmath{2 \pi}
22459@cite{2 pi} radians or 360 degrees. However, 22709@infoline @expr{2 pi}
22460@cite{@t{arcsinh}(@t{sinh}(x))} is simplified to @cite{x} if 22710radians or 360 degrees. However, @expr{@t{arcsinh}(@t{sinh}(x))} is
22461@cite{x} is known to be real. 22711simplified to @expr{x} if @expr{x} is known to be real.
22462 22712
22463Several simplifications that apply to logarithms and exponentials 22713Several simplifications that apply to logarithms and exponentials
22464are that @cite{@t{exp}(@t{ln}(x))}, @c{$@t{e}^{\ln(x)}$} 22714are that @expr{@t{exp}(@t{ln}(x))},
22465@cite{e^@t{ln}(x)}, and 22715@texline @t{e}@tmath{^{\ln(x)}},
22466@c{$10^{{\rm log10}(x)}$} 22716@infoline @expr{e^@t{ln}(x)},
22467@cite{10^@t{log10}(x)} all reduce to @cite{x}. 22717and
22468Also, @cite{@t{ln}(@t{exp}(x))}, etc., can reduce to @cite{x} if 22718@texline @tmath{10^{{\rm log10}(x)}}
22469@cite{x} is provably real. The form @cite{@t{exp}(x)^y} is simplified 22719@infoline @expr{10^@t{log10}(x)}
22470to @cite{@t{exp}(x y)}. If @cite{x} is a suitable multiple of @c{$\pi i$} 22720all reduce to @expr{x}. Also, @expr{@t{ln}(@t{exp}(x))}, etc., can
22471@cite{pi i} 22721reduce to @expr{x} if @expr{x} is provably real. The form
22472(as described above for the trigonometric functions), then @cite{@t{exp}(x)} 22722@expr{@t{exp}(x)^y} is simplified to @expr{@t{exp}(x y)}. If @expr{x}
22473or @cite{e^x} will be expanded. Finally, @cite{@t{ln}(x)} is simplified 22723is a suitable multiple of
22474to a form involving @code{pi} and @code{i} where @cite{x} is provably 22724@texline @tmath{\pi i}
22475negative, positive imaginary, or negative imaginary. 22725@infoline @expr{pi i}
22726(as described above for the trigonometric functions), then
22727@expr{@t{exp}(x)} or @expr{e^x} will be expanded. Finally,
22728@expr{@t{ln}(x)} is simplified to a form involving @code{pi} and
22729@code{i} where @expr{x} is provably negative, positive imaginary, or
22730negative imaginary.
22476 22731
22477The error functions @code{erf} and @code{erfc} are simplified when 22732The error functions @code{erf} and @code{erfc} are simplified when
22478their arguments are negative-looking or are calls to the @code{conj} 22733their arguments are negative-looking or are calls to the @code{conj}
@@ -22485,7 +22740,7 @@ function.
22485Equations and inequalities are simplified by cancelling factors 22740Equations and inequalities are simplified by cancelling factors
22486of products, quotients, or sums on both sides. Inequalities 22741of products, quotients, or sums on both sides. Inequalities
22487change sign if a negative multiplicative factor is cancelled. 22742change sign if a negative multiplicative factor is cancelled.
22488Non-constant multiplicative factors as in @cite{a b = a c} are 22743Non-constant multiplicative factors as in @expr{a b = a c} are
22489cancelled from equations only if they are provably nonzero (generally 22744cancelled from equations only if they are provably nonzero (generally
22490because they were declared so; @pxref{Declarations}). Factors 22745because they were declared so; @pxref{Declarations}). Factors
22491are cancelled from inequalities only if they are nonzero and their 22746are cancelled from inequalities only if they are nonzero and their
@@ -22493,11 +22748,11 @@ sign is known.
22493 22748
22494Simplification also replaces an equation or inequality with 22749Simplification also replaces an equation or inequality with
224951 or 0 (``true'' or ``false'') if it can through the use of 227501 or 0 (``true'' or ``false'') if it can through the use of
22496declarations. If @cite{x} is declared to be an integer greater 22751declarations. If @expr{x} is declared to be an integer greater
22497than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are 22752than 5, then @expr{x < 3}, @expr{x = 3}, and @expr{x = 7.5} are
22498all simplified to 0, but @cite{x > 3} is simplified to 1. 22753all simplified to 0, but @expr{x > 3} is simplified to 1.
22499By a similar analysis, @cite{abs(x) >= 0} is simplified to 1, 22754By a similar analysis, @expr{abs(x) >= 0} is simplified to 1,
22500as is @cite{x^2 >= 0} if @cite{x} is known to be real. 22755as is @expr{x^2 >= 0} if @expr{x} is known to be real.
22501 22756
22502@node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas 22757@node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas
22503@subsection ``Unsafe'' Simplifications 22758@subsection ``Unsafe'' Simplifications
@@ -22519,8 +22774,8 @@ formula lie in the restricted ranges for which these simplifications
22519are valid. The symbolic integrator uses @kbd{a e}; 22774are valid. The symbolic integrator uses @kbd{a e};
22520one effect of this is that the integrator's results must be used with 22775one effect of this is that the integrator's results must be used with
22521caution. Where an integral table will often attach conditions like 22776caution. Where an integral table will often attach conditions like
22522``for positive @cite{a} only,'' Calc (like most other symbolic 22777``for positive @expr{a} only,'' Calc (like most other symbolic
22523integration programs) will simply produce an unqualified result.@refill 22778integration programs) will simply produce an unqualified result.
22524 22779
22525Because @kbd{a e}'s simplifications are unsafe, it is sometimes better 22780Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
22526to type @kbd{C-u -3 a v}, which does extended simplification only 22781to type @kbd{C-u -3 a v}, which does extended simplification only
@@ -22542,45 +22797,49 @@ by @kbd{a e}.
22542 22797
22543Inverse trigonometric or hyperbolic functions, called with their 22798Inverse trigonometric or hyperbolic functions, called with their
22544corresponding non-inverse functions as arguments, are simplified 22799corresponding non-inverse functions as arguments, are simplified
22545by @kbd{a e}. For example, @cite{@t{arcsin}(@t{sin}(x))} changes 22800by @kbd{a e}. For example, @expr{@t{arcsin}(@t{sin}(x))} changes
22546to @cite{x}. Also, @cite{@t{arcsin}(@t{cos}(x))} and 22801to @expr{x}. Also, @expr{@t{arcsin}(@t{cos}(x))} and
22547@cite{@t{arccos}(@t{sin}(x))} both change to @cite{@t{pi}/2 - x}. 22802@expr{@t{arccos}(@t{sin}(x))} both change to @expr{@t{pi}/2 - x}.
22548These simplifications are unsafe because they are valid only for 22803These simplifications are unsafe because they are valid only for
22549values of @cite{x} in a certain range; outside that range, values 22804values of @expr{x} in a certain range; outside that range, values
22550are folded down to the 360-degree range that the inverse trigonometric 22805are folded down to the 360-degree range that the inverse trigonometric
22551functions always produce. 22806functions always produce.
22552 22807
22553Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$} 22808Powers of powers @expr{(x^a)^b} are simplified to
22554@cite{x^(a b)} 22809@texline @tmath{x^{a b}}
22555for all @cite{a} and @cite{b}. These results will be valid only 22810@infoline @expr{x^(a b)}
22556in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$} 22811for all @expr{a} and @expr{b}. These results will be valid only
22557@cite{(x^2)^1:2} 22812in a restricted range of @expr{x}; for example, in
22558the powers cancel to get @cite{x}, which is valid for positive values 22813@texline @tmath{(x^2)^{1:2}}
22559of @cite{x} but not for negative or complex values. 22814@infoline @expr{(x^2)^1:2}
22560 22815the powers cancel to get @expr{x}, which is valid for positive values
22561Similarly, @cite{@t{sqrt}(x^a)} and @cite{@t{sqrt}(x)^a} are both 22816of @expr{x} but not for negative or complex values.
22562simplified (possibly unsafely) to @c{$x^{a/2}$} 22817
22563@cite{x^(a/2)}. 22818Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both
22564 22819simplified (possibly unsafely) to
22565Forms like @cite{@t{sqrt}(1 - @t{sin}(x)^2)} are simplified to, e.g., 22820@texline @tmath{x^{a/2}}.
22566@cite{@t{cos}(x)}. Calc has identities of this sort for @code{sin}, 22821@infoline @expr{x^(a/2)}.
22822
22823Forms like @expr{@t{sqrt}(1 - sin(x)^2)} are simplified to, e.g.,
22824@expr{@t{cos}(x)}. Calc has identities of this sort for @code{sin},
22567@code{cos}, @code{tan}, @code{sinh}, and @code{cosh}. 22825@code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.
22568 22826
22569Arguments of square roots are partially factored to look for 22827Arguments of square roots are partially factored to look for
22570squared terms that can be extracted. For example, 22828squared terms that can be extracted. For example,
22571@cite{@t{sqrt}(a^2 b^3 + a^3 b^2)} simplifies to @cite{a b @t{sqrt}(a+b)}. 22829@expr{@t{sqrt}(a^2 b^3 + a^3 b^2)} simplifies to
22830@expr{a b @t{sqrt}(a+b)}.
22572 22831
22573The simplifications of @cite{@t{ln}(@t{exp}(x))}, @cite{@t{ln}(@t{e}^x)}, 22832The simplifications of @expr{@t{ln}(@t{exp}(x))},
22574and @cite{@t{log10}(10^x)} to @cite{x} are also unsafe because 22833@expr{@t{ln}(@t{e}^x)}, and @expr{@t{log10}(10^x)} to @expr{x} are also
22575of problems with principal values (although these simplifications 22834unsafe because of problems with principal values (although these
22576are safe if @cite{x} is known to be real). 22835simplifications are safe if @expr{x} is known to be real).
22577 22836
22578Common factors are cancelled from products on both sides of an 22837Common factors are cancelled from products on both sides of an
22579equation, even if those factors may be zero: @cite{a x / b x} 22838equation, even if those factors may be zero: @expr{a x / b x}
22580to @cite{a / b}. Such factors are never cancelled from 22839to @expr{a / b}. Such factors are never cancelled from
22581inequalities: Even @kbd{a e} is not bold enough to reduce 22840inequalities: Even @kbd{a e} is not bold enough to reduce
22582@cite{a x < b x} to @cite{a < b} (or @cite{a > b}, depending 22841@expr{a x < b x} to @expr{a < b} (or @expr{a > b}, depending
22583on whether you believe @cite{x} is positive or negative). 22842on whether you believe @expr{x} is positive or negative).
22584The @kbd{a M /} command can be used to divide a factor out of 22843The @kbd{a M /} command can be used to divide a factor out of
22585both sides of an inequality. 22844both sides of an inequality.
22586 22845
@@ -22600,12 +22859,12 @@ and @code{AlgSimpRules}.
22600Scalar mode is automatically put into effect when simplifying units. 22859Scalar mode is automatically put into effect when simplifying units.
22601@xref{Matrix Mode}. 22860@xref{Matrix Mode}.
22602 22861
22603Sums @cite{a + b} involving units are simplified by extracting the 22862Sums @expr{a + b} involving units are simplified by extracting the
22604units of @cite{a} as if by the @kbd{u x} command (call the result 22863units of @expr{a} as if by the @kbd{u x} command (call the result
22605@cite{u_a}), then simplifying the expression @cite{b / u_a} 22864@expr{u_a}), then simplifying the expression @expr{b / u_a}
22606using @kbd{u b} and @kbd{u s}. If the result has units then the sum 22865using @kbd{u b} and @kbd{u s}. If the result has units then the sum
22607is inconsistent and is left alone. Otherwise, it is rewritten 22866is inconsistent and is left alone. Otherwise, it is rewritten
22608in terms of the units @cite{u_a}. 22867in terms of the units @expr{u_a}.
22609 22868
22610If units auto-ranging mode is enabled, products or quotients in 22869If units auto-ranging mode is enabled, products or quotients in
22611which the first argument is a number which is out of range for the 22870which the first argument is a number which is out of range for the
@@ -22617,39 +22876,44 @@ For example, @samp{2 km m} is simplified to @samp{2000 m^2}.
22617However, compatible but different units like @code{ft} and @code{in} 22876However, compatible but different units like @code{ft} and @code{in}
22618are not combined in this way. 22877are not combined in this way.
22619 22878
22620Quotients @cite{a / b} are simplified in three additional ways. First, 22879Quotients @expr{a / b} are simplified in three additional ways. First,
22621if @cite{b} is a number or a product beginning with a number, Calc 22880if @expr{b} is a number or a product beginning with a number, Calc
22622computes the reciprocal of this number and moves it to the numerator. 22881computes the reciprocal of this number and moves it to the numerator.
22623 22882
22624Second, for each pair of unit names from the numerator and denominator 22883Second, for each pair of unit names from the numerator and denominator
22625of a quotient, if the units are compatible (e.g., they are both 22884of a quotient, if the units are compatible (e.g., they are both
22626units of area) then they are replaced by the ratio between those 22885units of area) then they are replaced by the ratio between those
22627units. For example, in @samp{3 s in N / kg cm} the units 22886units. For example, in @samp{3 s in N / kg cm} the units
22628@samp{in / cm} will be replaced by @cite{2.54}. 22887@samp{in / cm} will be replaced by @expr{2.54}.
22629 22888
22630Third, if the units in the quotient exactly cancel out, so that 22889Third, if the units in the quotient exactly cancel out, so that
22631a @kbd{u b} command on the quotient would produce a dimensionless 22890a @kbd{u b} command on the quotient would produce a dimensionless
22632number for an answer, then the quotient simplifies to that number. 22891number for an answer, then the quotient simplifies to that number.
22633 22892
22634For powers and square roots, the ``unsafe'' simplifications 22893For powers and square roots, the ``unsafe'' simplifications
22635@cite{(a b)^c} to @cite{a^c b^c}, @cite{(a/b)^c} to @cite{a^c / b^c}, 22894@expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c},
22636and @cite{(a^b)^c} to @c{$a^{b c}$} 22895and @expr{(a^b)^c} to
22637@cite{a^(b c)} are done if the powers are 22896@texline @tmath{a^{b c}}
22638real numbers. (These are safe in the context of units because 22897@infoline @expr{a^(b c)}
22639all numbers involved can reasonably be assumed to be real.) 22898are done if the powers are real numbers. (These are safe in the context
22899of units because all numbers involved can reasonably be assumed to be
22900real.)
22640 22901
22641Also, if a unit name is raised to a fractional power, and the 22902Also, if a unit name is raised to a fractional power, and the
22642base units in that unit name all occur to powers which are a 22903base units in that unit name all occur to powers which are a
22643multiple of the denominator of the power, then the unit name 22904multiple of the denominator of the power, then the unit name
22644is expanded out into its base units, which can then be simplified 22905is expanded out into its base units, which can then be simplified
22645according to the previous paragraph. For example, @samp{acre^1.5} 22906according to the previous paragraph. For example, @samp{acre^1.5}
22646is simplified by noting that @cite{1.5 = 3:2}, that @samp{acre} 22907is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre}
22647is defined in terms of @samp{m^2}, and that the 2 in the power of 22908is defined in terms of @samp{m^2}, and that the 2 in the power of
22648@code{m} is a multiple of 2 in @cite{3:2}. Thus, @code{acre^1.5} is 22909@code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is
22649replaced by approximately @c{$(4046 m^2)^{1.5}$} 22910replaced by approximately
22650@cite{(4046 m^2)^1.5}, which is then 22911@texline @tmath{(4046 m^2)^{1.5}}
22651changed to @c{$4046^{1.5} \, (m^2)^{1.5}$} 22912@infoline @expr{(4046 m^2)^1.5},
22652@cite{4046^1.5 (m^2)^1.5}, then to @cite{257440 m^3}. 22913which is then changed to
22914@texline @tmath{4046^{1.5} \, (m^2)^{1.5}},
22915@infoline @expr{4046^1.5 (m^2)^1.5},
22916then to @expr{257440 m^3}.
22653 22917
22654The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, 22918The functions @code{float}, @code{frac}, @code{clean}, @code{abs},
22655as well as @code{floor} and the other integer truncation functions, 22919as well as @code{floor} and the other integer truncation functions,
@@ -22667,10 +22931,10 @@ with the angular mode temporarily set to radians.
22667@section Polynomials 22931@section Polynomials
22668 22932
22669A @dfn{polynomial} is a sum of terms which are coefficients times 22933A @dfn{polynomial} is a sum of terms which are coefficients times
22670various powers of a ``base'' variable. For example, @cite{2 x^2 + 3 x - 4} 22934various powers of a ``base'' variable. For example, @expr{2 x^2 + 3 x - 4}
22671is a polynomial in @cite{x}. Some formulas can be considered 22935is a polynomial in @expr{x}. Some formulas can be considered
22672polynomials in several different variables: @cite{1 + 2 x + 3 y + 4 x y^2} 22936polynomials in several different variables: @expr{1 + 2 x + 3 y + 4 x y^2}
22673is a polynomial in both @cite{x} and @cite{y}. Polynomial coefficients 22937is a polynomial in both @expr{x} and @expr{y}. Polynomial coefficients
22674are often numbers, but they may in general be any formulas not 22938are often numbers, but they may in general be any formulas not
22675involving the base variable. 22939involving the base variable.
22676 22940
@@ -22679,9 +22943,9 @@ involving the base variable.
22679@tindex factor 22943@tindex factor
22680The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a 22944The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a
22681polynomial into a product of terms. For example, the polynomial 22945polynomial into a product of terms. For example, the polynomial
22682@cite{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another 22946@expr{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another
22683example, @cite{a c + b d + b c + a d} is factored into the product 22947example, @expr{a c + b d + b c + a d} is factored into the product
22684@cite{(a + b) (c + d)}. 22948@expr{(a + b) (c + d)}.
22685 22949
22686Calc currently has three algorithms for factoring. Formulas which are 22950Calc currently has three algorithms for factoring. Formulas which are
22687linear in several variables, such as the second example above, are 22951linear in several variables, such as the second example above, are
@@ -22689,7 +22953,7 @@ merged according to the distributive law. Formulas which are
22689polynomials in a single variable, with constant integer or fractional 22953polynomials in a single variable, with constant integer or fractional
22690coefficients, are factored into irreducible linear and/or quadratic 22954coefficients, are factored into irreducible linear and/or quadratic
22691terms. The first example above factors into three linear terms 22955terms. The first example above factors into three linear terms
22692(@cite{x}, @cite{x+1}, and @cite{x+1} again). Finally, formulas 22956(@expr{x}, @expr{x+1}, and @expr{x+1} again). Finally, formulas
22693which do not fit the above criteria are handled by the algebraic 22957which do not fit the above criteria are handled by the algebraic
22694rewrite mechanism. 22958rewrite mechanism.
22695 22959
@@ -22721,7 +22985,7 @@ The rewrite-based factorization method uses rules stored in the variable
22721@code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the 22985@code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the
22722operation of rewrite rules. The default @code{FactorRules} are able 22986operation of rewrite rules. The default @code{FactorRules} are able
22723to factor quadratic forms symbolically into two linear terms, 22987to factor quadratic forms symbolically into two linear terms,
22724@cite{(a x + b) (c x + d)}. You can edit these rules to include other 22988@expr{(a x + b) (c x + d)}. You can edit these rules to include other
22725cases if you wish. To use the rules, Calc builds the formula 22989cases if you wish. To use the rules, Calc builds the formula
22726@samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial 22990@samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
22727base variable and @code{a}, @code{b}, etc., are polynomial coefficients 22991base variable and @code{a}, @code{b}, etc., are polynomial coefficients
@@ -22742,13 +23006,13 @@ The @kbd{H a f} [@code{factors}] command also factors a polynomial,
22742but it returns a list of factors instead of an expression which is the 23006but it returns a list of factors instead of an expression which is the
22743product of the factors. Each factor is represented by a sub-vector 23007product of the factors. Each factor is represented by a sub-vector
22744of the factor, and the power with which it appears. For example, 23008of the factor, and the power with which it appears. For example,
22745@cite{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @cite{(x + 7) x^2 (x - 3)^2} 23009@expr{x^5 + x^4 - 33 x^3 + 63 x^2} factors to @expr{(x + 7) x^2 (x - 3)^2}
22746in @kbd{a f}, or to @cite{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}. 23010in @kbd{a f}, or to @expr{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}.
22747If there is an overall numeric factor, it always comes first in the list. 23011If there is an overall numeric factor, it always comes first in the list.
22748The functions @code{factor} and @code{factors} allow a second argument 23012The functions @code{factor} and @code{factors} allow a second argument
22749when written in algebraic form; @samp{factor(x,v)} factors @cite{x} with 23013when written in algebraic form; @samp{factor(x,v)} factors @expr{x} with
22750respect to the specific variable @cite{v}. The default is to factor with 23014respect to the specific variable @expr{v}. The default is to factor with
22751respect to all the variables that appear in @cite{x}. 23015respect to all the variables that appear in @expr{x}.
22752 23016
22753@kindex a c 23017@kindex a c
22754@pindex calc-collect 23018@pindex calc-collect
@@ -22756,12 +23020,12 @@ respect to all the variables that appear in @cite{x}.
22756The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a 23020The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a
22757formula as a 23021formula as a
22758polynomial in a given variable, ordered in decreasing powers of that 23022polynomial in a given variable, ordered in decreasing powers of that
22759variable. For example, given @cite{1 + 2 x + 3 y + 4 x y^2} on 23023variable. For example, given @expr{1 + 2 x + 3 y + 4 x y^2} on
22760the stack, @kbd{a c x} would produce @cite{(2 + 4 y^2) x + (1 + 3 y)}, 23024the stack, @kbd{a c x} would produce @expr{(2 + 4 y^2) x + (1 + 3 y)},
22761and @kbd{a c y} would produce @cite{(4 x) y^2 + 3 y + (1 + 2 x)}. 23025and @kbd{a c y} would produce @expr{(4 x) y^2 + 3 y + (1 + 2 x)}.
22762The polynomial will be expanded out using the distributive law as 23026The polynomial will be expanded out using the distributive law as
22763necessary: Collecting @cite{x} in @cite{(x - 1)^3} produces 23027necessary: Collecting @expr{x} in @expr{(x - 1)^3} produces
22764@cite{x^3 - 3 x^2 + 3 x - 1}. Terms not involving @cite{x} will 23028@expr{x^3 - 3 x^2 + 3 x - 1}. Terms not involving @expr{x} will
22765not be expanded. 23029not be expanded.
22766 23030
22767The ``variable'' you specify at the prompt can actually be any 23031The ``variable'' you specify at the prompt can actually be any
@@ -22790,10 +23054,10 @@ also know many other kinds of expansions, such as
22790do not do.) 23054do not do.)
22791 23055
22792Calc's automatic simplifications will sometimes reverse a partial 23056Calc's automatic simplifications will sometimes reverse a partial
22793expansion. For example, the first step in expanding @cite{(x+1)^3} is 23057expansion. For example, the first step in expanding @expr{(x+1)^3} is
22794to write @cite{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries 23058to write @expr{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries
22795to put this formula onto the stack, though, Calc will automatically 23059to put this formula onto the stack, though, Calc will automatically
22796simplify it back to @cite{(x+1)^3} form. The solution is to turn 23060simplify it back to @expr{(x+1)^3} form. The solution is to turn
22797simplification off first (@pxref{Simplification Modes}), or to run 23061simplification off first (@pxref{Simplification Modes}), or to run
22798@kbd{a x} without a numeric prefix argument so that it expands all 23062@kbd{a x} without a numeric prefix argument so that it expands all
22799the way in one step. 23063the way in one step.
@@ -22814,21 +23078,21 @@ chooses the base variable automatically.
22814@tindex nrat 23078@tindex nrat
22815The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command 23079The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command
22816attempts to arrange a formula into a quotient of two polynomials. 23080attempts to arrange a formula into a quotient of two polynomials.
22817For example, given @cite{1 + (a + b/c) / d}, the result would be 23081For example, given @expr{1 + (a + b/c) / d}, the result would be
22818@cite{(b + a c + c d) / c d}. The quotient is reduced, so that 23082@expr{(b + a c + c d) / c d}. The quotient is reduced, so that
22819@kbd{a n} will simplify @cite{(x^2 + 2x + 1) / (x^2 - 1)} by dividing 23083@kbd{a n} will simplify @expr{(x^2 + 2x + 1) / (x^2 - 1)} by dividing
22820out the common factor @cite{x + 1}, yielding @cite{(x + 1) / (x - 1)}. 23084out the common factor @expr{x + 1}, yielding @expr{(x + 1) / (x - 1)}.
22821 23085
22822@kindex a \ 23086@kindex a \
22823@pindex calc-poly-div 23087@pindex calc-poly-div
22824@tindex pdiv 23088@tindex pdiv
22825The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides 23089The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides
22826two polynomials @cite{u} and @cite{v}, yielding a new polynomial 23090two polynomials @expr{u} and @expr{v}, yielding a new polynomial
22827@cite{q}. If several variables occur in the inputs, the inputs are 23091@expr{q}. If several variables occur in the inputs, the inputs are
22828considered multivariate polynomials. (Calc divides by the variable 23092considered multivariate polynomials. (Calc divides by the variable
22829with the largest power in @cite{u} first, or, in the case of equal 23093with the largest power in @expr{u} first, or, in the case of equal
22830powers, chooses the variables in alphabetical order.) For example, 23094powers, chooses the variables in alphabetical order.) For example,
22831dividing @cite{x^2 + 3 x + 2} by @cite{x + 2} yields @cite{x + 1}. 23095dividing @expr{x^2 + 3 x + 2} by @expr{x + 2} yields @expr{x + 1}.
22832The remainder from the division, if any, is reported at the bottom 23096The remainder from the division, if any, is reported at the bottom
22833of the screen and is also placed in the Trail along with the quotient. 23097of the screen and is also placed in the Trail along with the quotient.
22834 23098
@@ -22842,9 +23106,9 @@ above.
22842@pindex calc-poly-rem 23106@pindex calc-poly-rem
22843@tindex prem 23107@tindex prem
22844The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides 23108The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides
22845two polynomials and keeps the remainder @cite{r}. The quotient 23109two polynomials and keeps the remainder @expr{r}. The quotient
22846@cite{q} is discarded. For any formulas @cite{a} and @cite{b}, the 23110@expr{q} is discarded. For any formulas @expr{a} and @expr{b}, the
22847results of @kbd{a \} and @kbd{a %} satisfy @cite{a = q b + r}. 23111results of @kbd{a \} and @kbd{a %} satisfy @expr{a = q b + r}.
22848(This is analogous to plain @kbd{\} and @kbd{%}, which compute the 23112(This is analogous to plain @kbd{\} and @kbd{%}, which compute the
22849integer quotient and remainder from dividing two numbers.) 23113integer quotient and remainder from dividing two numbers.)
22850 23114
@@ -22855,10 +23119,10 @@ integer quotient and remainder from dividing two numbers.)
22855@tindex pdivide 23119@tindex pdivide
22856The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command 23120The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command
22857divides two polynomials and reports both the quotient and the 23121divides two polynomials and reports both the quotient and the
22858remainder as a vector @cite{[q, r]}. The @kbd{H a /} [@code{pdivide}] 23122remainder as a vector @expr{[q, r]}. The @kbd{H a /} [@code{pdivide}]
22859command divides two polynomials and constructs the formula 23123command divides two polynomials and constructs the formula
22860@cite{q + r/b} on the stack. (Naturally if the remainder is zero, 23124@expr{q + r/b} on the stack. (Naturally if the remainder is zero,
22861this will immediately simplify to @cite{q}.) 23125this will immediately simplify to @expr{q}.)
22862 23126
22863@kindex a g 23127@kindex a g
22864@pindex calc-poly-gcd 23128@pindex calc-poly-gcd
@@ -22936,8 +23200,9 @@ answer!
22936 23200
22937If you use the @code{deriv} function directly in an algebraic formula, 23201If you use the @code{deriv} function directly in an algebraic formula,
22938you can write @samp{deriv(f,x,x0)} which represents the derivative 23202you can write @samp{deriv(f,x,x0)} which represents the derivative
22939of @cite{f} with respect to @cite{x}, evaluated at the point @c{$x=x_0$} 23203of @expr{f} with respect to @expr{x}, evaluated at the point
22940@cite{x=x0}. 23204@texline @tmath{x=x_0}.
23205@infoline @expr{x=x0}.
22941 23206
22942If the formula being differentiated contains functions which Calc does 23207If the formula being differentiated contains functions which Calc does
22943not know, the derivatives of those functions are produced by adding 23208not know, the derivatives of those functions are produced by adding
@@ -22960,7 +23225,7 @@ respect to the other arguments are @samp{f'2(x,y,z)} and @samp{f'3(x,y,z)}.
22960Various higher-order derivatives can be formed in the obvious way, e.g., 23225Various higher-order derivatives can be formed in the obvious way, e.g.,
22961@samp{f'@var{}'(x)} (the second derivative of @code{f}) or 23226@samp{f'@var{}'(x)} (the second derivative of @code{f}) or
22962@samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each 23227@samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each
22963argument once).@refill 23228argument once).
22964 23229
22965@node Integration, Customizing the Integrator, Differentiation, Calculus 23230@node Integration, Customizing the Integrator, Differentiation, Calculus
22966@subsection Integration 23231@subsection Integration
@@ -22975,11 +23240,12 @@ respect to a variable. The integrator is not guaranteed to work for
22975all integrable functions, but it is able to integrate several large 23240all integrable functions, but it is able to integrate several large
22976classes of formulas. In particular, any polynomial or rational function 23241classes of formulas. In particular, any polynomial or rational function
22977(a polynomial divided by a polynomial) is acceptable. (Rational functions 23242(a polynomial divided by a polynomial) is acceptable. (Rational functions
22978don't have to be in explicit quotient form, however; @c{$x/(1+x^{-2})$} 23243don't have to be in explicit quotient form, however;
22979@cite{x/(1+x^-2)} 23244@texline @tmath{x/(1+x^{-2})}
23245@infoline @expr{x/(1+x^-2)}
22980is not strictly a quotient of polynomials, but it is equivalent to 23246is not strictly a quotient of polynomials, but it is equivalent to
22981@cite{x^3/(x^2+1)}, which is.) Also, square roots of terms involving 23247@expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving
22982@cite{x} and @cite{x^2} may appear in rational functions being 23248@expr{x} and @expr{x^2} may appear in rational functions being
22983integrated. Finally, rational functions involving trigonometric or 23249integrated. Finally, rational functions involving trigonometric or
22984hyperbolic functions can be integrated. 23250hyperbolic functions can be integrated.
22985 23251
@@ -23000,17 +23266,21 @@ integral $\int_a^b f(x) \, dx$.
23000 23266
23001Please note that the current implementation of Calc's integrator sometimes 23267Please note that the current implementation of Calc's integrator sometimes
23002produces results that are significantly more complex than they need to 23268produces results that are significantly more complex than they need to
23003be. For example, the integral Calc finds for @c{$1/(x+\sqrt{x^2+1})$} 23269be. For example, the integral Calc finds for
23004@cite{1/(x+sqrt(x^2+1))} 23270@texline @tmath{1/(x+\sqrt{x^2+1})}
23271@infoline @expr{1/(x+sqrt(x^2+1))}
23005is several times more complicated than the answer Mathematica 23272is several times more complicated than the answer Mathematica
23006returns for the same input, although the two forms are numerically 23273returns for the same input, although the two forms are numerically
23007equivalent. Also, any indefinite integral should be considered to have 23274equivalent. Also, any indefinite integral should be considered to have
23008an arbitrary constant of integration added to it, although Calc does not 23275an arbitrary constant of integration added to it, although Calc does not
23009write an explicit constant of integration in its result. For example, 23276write an explicit constant of integration in its result. For example,
23010Calc's solution for @c{$1/(1+\tan x)$} 23277Calc's solution for
23011@cite{1/(1+tan(x))} differs from the solution given 23278@texline @tmath{1/(1+\tan x)}
23012in the @emph{CRC Math Tables} by a constant factor of @c{$\pi i / 2$} 23279@infoline @expr{1/(1+tan(x))}
23013@cite{pi i / 2}, 23280differs from the solution given in the @emph{CRC Math Tables} by a
23281constant factor of
23282@texline @tmath{\pi i / 2}
23283@infoline @expr{pi i / 2},
23014due to a different choice of constant of integration. 23284due to a different choice of constant of integration.
23015 23285
23016The Calculator remembers all the integrals it has done. If conditions 23286The Calculator remembers all the integrals it has done. If conditions
@@ -23068,8 +23338,10 @@ in your @code{IntegRules}.
23068@tindex Ei 23338@tindex Ei
23069As a more serious example, the expression @samp{exp(x)/x} cannot be 23339As a more serious example, the expression @samp{exp(x)/x} cannot be
23070integrated in terms of the standard functions, so the ``exponential 23340integrated in terms of the standard functions, so the ``exponential
23071integral'' function @c{${\rm Ei}(x)$} 23341integral'' function
23072@cite{Ei(x)} was invented to describe it. 23342@texline @tmath{{\rm Ei}(x)}
23343@infoline @expr{Ei(x)}
23344was invented to describe it.
23073We can get Calc to do this integral in terms of a made-up @code{Ei} 23345We can get Calc to do this integral in terms of a made-up @code{Ei}
23074function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} 23346function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]}
23075to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack 23347to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack
@@ -23215,7 +23487,7 @@ of just a variable to produce a Taylor expansion about the point @var{a}.
23215You may specify the number of terms with a numeric prefix argument; 23487You may specify the number of terms with a numeric prefix argument;
23216otherwise the command will prompt you for the number of terms. Note that 23488otherwise the command will prompt you for the number of terms. Note that
23217many series expansions have coefficients of zero for some terms, so you 23489many series expansions have coefficients of zero for some terms, so you
23218may appear to get fewer terms than you asked for.@refill 23490may appear to get fewer terms than you asked for.
23219 23491
23220If the @kbd{a i} command is unable to find a symbolic integral for a 23492If the @kbd{a i} command is unable to find a symbolic integral for a
23221function, you can get an approximation by integrating the function's 23493function, you can get an approximation by integrating the function's
@@ -23232,28 +23504,32 @@ Taylor series.
23232@cindex Solving equations 23504@cindex Solving equations
23233The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges 23505The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges
23234an equation to solve for a specific variable. An equation is an 23506an equation to solve for a specific variable. An equation is an
23235expression of the form @cite{L = R}. For example, the command @kbd{a S x} 23507expression of the form @expr{L = R}. For example, the command @kbd{a S x}
23236will rearrange @cite{y = 3x + 6} to the form, @cite{x = y/3 - 2}. If the 23508will rearrange @expr{y = 3x + 6} to the form, @expr{x = y/3 - 2}. If the
23237input is not an equation, it is treated like an equation of the 23509input is not an equation, it is treated like an equation of the
23238form @cite{X = 0}. 23510form @expr{X = 0}.
23239 23511
23240This command also works for inequalities, as in @cite{y < 3x + 6}. 23512This command also works for inequalities, as in @expr{y < 3x + 6}.
23241Some inequalities cannot be solved where the analogous equation could 23513Some inequalities cannot be solved where the analogous equation could
23242be; for example, solving @c{$a < b \, c$} 23514be; for example, solving
23243@cite{a < b c} for @cite{b} is impossible 23515@texline @tmath{a < b \, c}
23244without knowing the sign of @cite{c}. In this case, @kbd{a S} will 23516@infoline @expr{a < b c}
23245produce the result @c{$b \mathbin{\hbox{\code{!=}}} a/c$} 23517for @expr{b} is impossible
23246@cite{b != a/c} (using the not-equal-to operator) 23518without knowing the sign of @expr{c}. In this case, @kbd{a S} will
23247to signify that the direction of the inequality is now unknown. The 23519produce the result
23248inequality @c{$a \le b \, c$} 23520@texline @tmath{b \mathbin{\hbox{\code{!=}}} a/c}
23249@cite{a <= b c} is not even partially solved. 23521@infoline @expr{b != a/c}
23250@xref{Declarations}, for a way to tell Calc that the signs of the 23522(using the not-equal-to operator) to signify that the direction of the
23251variables in a formula are in fact known. 23523inequality is now unknown. The inequality
23524@texline @tmath{a \le b \, c}
23525@infoline @expr{a <= b c}
23526is not even partially solved. @xref{Declarations}, for a way to tell
23527Calc that the signs of the variables in a formula are in fact known.
23252 23528
23253Two useful commands for working with the result of @kbd{a S} are 23529Two useful commands for working with the result of @kbd{a S} are
23254@kbd{a .} (@pxref{Logical Operations}), which converts @cite{x = y/3 - 2} 23530@kbd{a .} (@pxref{Logical Operations}), which converts @expr{x = y/3 - 2}
23255to @cite{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates 23531to @expr{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates
23256another formula with @cite{x} set equal to @cite{y/3 - 2}. 23532another formula with @expr{x} set equal to @expr{y/3 - 2}.
23257 23533
23258@menu 23534@menu
23259* Multiple Solutions:: 23535* Multiple Solutions::
@@ -23293,7 +23569,7 @@ There is a similar phenomenon going the other direction: Suppose
23293we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides 23569we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides
23294to get @samp{y = x^2}. This is correct, except that it introduces 23570to get @samp{y = x^2}. This is correct, except that it introduces
23295some dubious solutions. Consider solving @samp{sqrt(y) = -3}: 23571some dubious solutions. Consider solving @samp{sqrt(y) = -3}:
23296Calc will report @cite{y = 9} as a valid solution, which is true 23572Calc will report @expr{y = 9} as a valid solution, which is true
23297in the mathematical sense of square-root, but false (there is no 23573in the mathematical sense of square-root, but false (there is no
23298solution) for the actual Calc positive-valued @code{sqrt}. This 23574solution) for the actual Calc positive-valued @code{sqrt}. This
23299happens for both @kbd{a S} and @kbd{H a S}. 23575happens for both @kbd{a S} and @kbd{H a S}.
@@ -23337,7 +23613,7 @@ in that variable is not a positive integer, the regular
23337With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression 23613With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression
23338on top of the stack as a function of the specified variable and solves 23614on top of the stack as a function of the specified variable and solves
23339to find the inverse function, written in terms of the same variable. 23615to find the inverse function, written in terms of the same variable.
23340For example, @kbd{I a S x} inverts @cite{2x + 6} to @cite{x/2 - 3}. 23616For example, @kbd{I a S x} inverts @expr{2x + 6} to @expr{x/2 - 3}.
23341You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a 23617You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a
23342fully general inverse, as described above. 23618fully general inverse, as described above.
23343 23619
@@ -23361,12 +23637,12 @@ reported; @pxref{Declarations}.)
23361Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver 23637Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver
23362symbolic solutions if the polynomial has symbolic coefficients. Also 23638symbolic solutions if the polynomial has symbolic coefficients. Also
23363note that Calc's solver is not able to get exact symbolic solutions 23639note that Calc's solver is not able to get exact symbolic solutions
23364to all polynomials. Polynomials containing powers up to @cite{x^4} 23640to all polynomials. Polynomials containing powers up to @expr{x^4}
23365can always be solved exactly; polynomials of higher degree sometimes 23641can always be solved exactly; polynomials of higher degree sometimes
23366can be: @cite{x^6 + x^3 + 1} is converted to @cite{(x^3)^2 + (x^3) + 1}, 23642can be: @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1},
23367which can be solved for @cite{x^3} using the quadratic equation, and then 23643which can be solved for @expr{x^3} using the quadratic equation, and then
23368for @cite{x} by taking cube roots. But in many cases, like 23644for @expr{x} by taking cube roots. But in many cases, like
23369@cite{x^6 + x + 1}, Calc does not know how to rewrite the polynomial 23645@expr{x^6 + x + 1}, Calc does not know how to rewrite the polynomial
23370into a form it can solve. The @kbd{a P} command can still deliver a 23646into a form it can solve. The @kbd{a P} command can still deliver a
23371list of numerical roots, however, provided that symbolic mode (@kbd{m s}) 23647list of numerical roots, however, provided that symbolic mode (@kbd{m s})
23372is not turned on. (If you work with symbolic mode on, recall that the 23648is not turned on. (If you work with symbolic mode on, recall that the
@@ -23392,7 +23668,7 @@ and typing @kbd{a S x,y @key{RET}} produces the vector of solutions
23392have the same length as the variables vector, and the variables 23668have the same length as the variables vector, and the variables
23393will be listed in the same order there. Note that the solutions 23669will be listed in the same order there. Note that the solutions
23394are not always simplified as far as possible; the solution for 23670are not always simplified as far as possible; the solution for
23395@cite{x} here could be improved by an application of the @kbd{a n} 23671@expr{x} here could be improved by an application of the @kbd{a n}
23396command. 23672command.
23397 23673
23398Calc's algorithm works by trying to eliminate one variable at a 23674Calc's algorithm works by trying to eliminate one variable at a
@@ -23453,23 +23729,23 @@ to satisfy the equations. @xref{Curve Fitting}.
23453The @code{poly} function takes a polynomial and a variable as 23729The @code{poly} function takes a polynomial and a variable as
23454arguments, and returns a vector of polynomial coefficients (constant 23730arguments, and returns a vector of polynomial coefficients (constant
23455coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns 23731coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns
23456@cite{[0, 2, 0, 1]}. If the input is not a polynomial in @cite{x}, 23732@expr{[0, 2, 0, 1]}. If the input is not a polynomial in @expr{x},
23457the call to @code{poly} is left in symbolic form. If the input does 23733the call to @code{poly} is left in symbolic form. If the input does
23458not involve the variable @cite{x}, the input is returned in a list 23734not involve the variable @expr{x}, the input is returned in a list
23459of length one, representing a polynomial with only a constant 23735of length one, representing a polynomial with only a constant
23460coefficient. The call @samp{poly(x, x)} returns the vector @cite{[0, 1]}. 23736coefficient. The call @samp{poly(x, x)} returns the vector @expr{[0, 1]}.
23461The last element of the returned vector is guaranteed to be nonzero; 23737The last element of the returned vector is guaranteed to be nonzero;
23462note that @samp{poly(0, x)} returns the empty vector @cite{[]}. 23738note that @samp{poly(0, x)} returns the empty vector @expr{[]}.
23463Note also that @cite{x} may actually be any formula; for example, 23739Note also that @expr{x} may actually be any formula; for example,
23464@samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @cite{[3, -1, 1]}. 23740@samp{poly(sin(x)^2 - sin(x) + 3, sin(x))} returns @expr{[3, -1, 1]}.
23465 23741
23466@cindex Coefficients of polynomial 23742@cindex Coefficients of polynomial
23467@cindex Degree of polynomial 23743@cindex Degree of polynomial
23468To get the @cite{x^k} coefficient of polynomial @cite{p}, use 23744To get the @expr{x^k} coefficient of polynomial @expr{p}, use
23469@samp{poly(p, x)_(k+1)}. To get the degree of polynomial @cite{p}, 23745@samp{poly(p, x)_(k+1)}. To get the degree of polynomial @expr{p},
23470use @samp{vlen(poly(p, x)) - 1}. For example, @samp{poly((x+1)^4, x)} 23746use @samp{vlen(poly(p, x)) - 1}. For example, @samp{poly((x+1)^4, x)}
23471returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)} 23747returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)}
23472gives the @cite{x^2} coefficient of this polynomial, 6. 23748gives the @expr{x^2} coefficient of this polynomial, 6.
23473 23749
23474@ignore 23750@ignore
23475@starindex 23751@starindex
@@ -23494,13 +23770,13 @@ their arguments as polynomials, will not because the decomposition
23494is considered trivial. 23770is considered trivial.
23495 23771
23496For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]}, 23772For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]},
23497since the expanded form of this polynomial is @cite{4 - 4 x + x^2}. 23773since the expanded form of this polynomial is @expr{4 - 4 x + x^2}.
23498 23774
23499The term @var{x} may itself be a polynomial in @var{var}. This is 23775The term @var{x} may itself be a polynomial in @var{var}. This is
23500done to reduce the size of the @var{c} vector. For example, 23776done to reduce the size of the @var{c} vector. For example,
23501@samp{gpoly(x^4 + x^2 - 1, x)} returns @samp{[x^2, [-1, 1, 1], 1]}, 23777@samp{gpoly(x^4 + x^2 - 1, x)} returns @samp{[x^2, [-1, 1, 1], 1]},
23502since a quadratic polynomial in @cite{x^2} is easier to solve than 23778since a quadratic polynomial in @expr{x^2} is easier to solve than
23503a quartic polynomial in @cite{x}. 23779a quartic polynomial in @expr{x}.
23504 23780
23505A few more examples of the kinds of polynomials @code{gpoly} can 23781A few more examples of the kinds of polynomials @code{gpoly} can
23506discover: 23782discover:
@@ -23517,7 +23793,7 @@ x^(2a) + 2 x^a + 5 [x^a, [5, 2, 1], 1]
23517 23793
23518The @code{poly} and @code{gpoly} functions accept a third integer argument 23794The @code{poly} and @code{gpoly} functions accept a third integer argument
23519which specifies the largest degree of polynomial that is acceptable. 23795which specifies the largest degree of polynomial that is acceptable.
23520If this is @cite{n}, then only @var{c} vectors of length @cite{n+1} 23796If this is @expr{n}, then only @var{c} vectors of length @expr{n+1}
23521or less will be returned. Otherwise, the @code{poly} or @code{gpoly} 23797or less will be returned. Otherwise, the @code{poly} or @code{gpoly}
23522call will remain in symbolic form. For example, the equation solver 23798call will remain in symbolic form. For example, the equation solver
23523can handle quartics and smaller polynomials, so it calls 23799can handle quartics and smaller polynomials, so it calls
@@ -23549,7 +23825,7 @@ The @code{plead} function finds the leading term of a polynomial.
23549Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))}, 23825Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},
23550though again more efficient. In particular, @samp{plead((2x+1)^10, x)} 23826though again more efficient. In particular, @samp{plead((2x+1)^10, x)}
23551returns 1024 without expanding out the list of coefficients. The 23827returns 1024 without expanding out the list of coefficients. The
23552value of @code{plead(p,x)} will be zero only if @cite{p = 0}. 23828value of @code{plead(p,x)} will be zero only if @expr{p = 0}.
23553 23829
23554@ignore 23830@ignore
23555@starindex 23831@starindex
@@ -23618,7 +23894,7 @@ on numerical data.)
23618The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a 23894The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a
23619numerical solution (or @dfn{root}) of an equation. (This command treats 23895numerical solution (or @dfn{root}) of an equation. (This command treats
23620inequalities the same as equations. If the input is any other kind 23896inequalities the same as equations. If the input is any other kind
23621of formula, it is interpreted as an equation of the form @cite{X = 0}.) 23897of formula, it is interpreted as an equation of the form @expr{X = 0}.)
23622 23898
23623The @kbd{a R} command requires an initial guess on the top of the 23899The @kbd{a R} command requires an initial guess on the top of the
23624stack, and a formula in the second-to-top position. It prompts for a 23900stack, and a formula in the second-to-top position. It prompts for a
@@ -23704,22 +23980,25 @@ value of the variable which minimizes the formula's value, along
23704with the minimum value itself. 23980with the minimum value itself.
23705 23981
23706Note that this command looks for a @emph{local} minimum. Many functions 23982Note that this command looks for a @emph{local} minimum. Many functions
23707have more than one minimum; some, like @c{$x \sin x$} 23983have more than one minimum; some, like
23708@cite{x sin(x)}, have infinitely 23984@texline @tmath{x \sin x},
23709many. In fact, there is no easy way to define the ``global'' minimum 23985@infoline @expr{x sin(x)},
23710of @c{$x \sin x$} 23986have infinitely many. In fact, there is no easy way to define the
23711@cite{x sin(x)} but Calc can still locate any particular local minimum 23987``global'' minimum of
23988@texline @tmath{x \sin x}
23989@infoline @expr{x sin(x)}
23990but Calc can still locate any particular local minimum
23712for you. Calc basically goes downhill from the initial guess until it 23991for you. Calc basically goes downhill from the initial guess until it
23713finds a point at which the function's value is greater both to the left 23992finds a point at which the function's value is greater both to the left
23714and to the right. Calc does not use derivatives when minimizing a function. 23993and to the right. Calc does not use derivatives when minimizing a function.
23715 23994
23716If your initial guess is an interval and it looks like the minimum 23995If your initial guess is an interval and it looks like the minimum
23717occurs at one or the other endpoint of the interval, Calc will return 23996occurs at one or the other endpoint of the interval, Calc will return
23718that endpoint only if that endpoint is closed; thus, minimizing @cite{17 x} 23997that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x}
23719over @cite{[2..3]} will return @cite{[2, 38]}, but minimizing over 23998over @expr{[2..3]} will return @expr{[2, 38]}, but minimizing over
23720@cite{(2..3]} would report no minimum found. In general, you should 23999@expr{(2..3]} would report no minimum found. In general, you should
23721use closed intervals to find literally the minimum value in that 24000use closed intervals to find literally the minimum value in that
23722range of @cite{x}, or open intervals to find the local minimum, if 24001range of @expr{x}, or open intervals to find the local minimum, if
23723any, that happens to lie in that range. 24002any, that happens to lie in that range.
23724 24003
23725Most functions are smooth and flat near their minimum values. Because 24004Most functions are smooth and flat near their minimum values. Because
@@ -23781,9 +24060,9 @@ multidimensional minimization is currently @emph{very} slow.
23781 24060
23782@noindent 24061@noindent
23783The @kbd{a F} command fits a set of data to a @dfn{model formula}, 24062The @kbd{a F} command fits a set of data to a @dfn{model formula},
23784such as @cite{y = m x + b} where @cite{m} and @cite{b} are parameters 24063such as @expr{y = m x + b} where @expr{m} and @expr{b} are parameters
23785to be determined. For a typical set of measured data there will be 24064to be determined. For a typical set of measured data there will be
23786no single @cite{m} and @cite{b} that exactly fit the data; in this 24065no single @expr{m} and @expr{b} that exactly fit the data; in this
23787case, Calc chooses values of the parameters that provide the closest 24066case, Calc chooses values of the parameters that provide the closest
23788possible fit. 24067possible fit.
23789 24068
@@ -23806,46 +24085,50 @@ possible fit.
23806@cindex Linear regression 24085@cindex Linear regression
23807@cindex Least-squares fits 24086@cindex Least-squares fits
23808The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts 24087The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts
23809to fit a set of data (@cite{x} and @cite{y} vectors of numbers) to a 24088to fit a set of data (@expr{x} and @expr{y} vectors of numbers) to a
23810straight line, polynomial, or other function of @cite{x}. For the 24089straight line, polynomial, or other function of @expr{x}. For the
23811moment we will consider only the case of fitting to a line, and we 24090moment we will consider only the case of fitting to a line, and we
23812will ignore the issue of whether or not the model was in fact a good 24091will ignore the issue of whether or not the model was in fact a good
23813fit for the data. 24092fit for the data.
23814 24093
23815In a standard linear least-squares fit, we have a set of @cite{(x,y)} 24094In a standard linear least-squares fit, we have a set of @expr{(x,y)}
23816data points that we wish to fit to the model @cite{y = m x + b} 24095data points that we wish to fit to the model @expr{y = m x + b}
23817by adjusting the parameters @cite{m} and @cite{b} to make the @cite{y} 24096by adjusting the parameters @expr{m} and @expr{b} to make the @expr{y}
23818values calculated from the formula be as close as possible to the actual 24097values calculated from the formula be as close as possible to the actual
23819@cite{y} values in the data set. (In a polynomial fit, the model is 24098@expr{y} values in the data set. (In a polynomial fit, the model is
23820instead, say, @cite{y = a x^3 + b x^2 + c x + d}. In a multilinear fit, 24099instead, say, @expr{y = a x^3 + b x^2 + c x + d}. In a multilinear fit,
23821we have data points of the form @cite{(x_1,x_2,x_3,y)} and our model is 24100we have data points of the form @expr{(x_1,x_2,x_3,y)} and our model is
23822@cite{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.) 24101@expr{y = a x_1 + b x_2 + c x_3 + d}. These will be discussed later.)
23823 24102
23824In the model formula, variables like @cite{x} and @cite{x_2} are called 24103In the model formula, variables like @expr{x} and @expr{x_2} are called
23825the @dfn{independent variables}, and @cite{y} is the @dfn{dependent 24104the @dfn{independent variables}, and @expr{y} is the @dfn{dependent
23826variable}. Variables like @cite{m}, @cite{a}, and @cite{b} are called 24105variable}. Variables like @expr{m}, @expr{a}, and @expr{b} are called
23827the @dfn{parameters} of the model. 24106the @dfn{parameters} of the model.
23828 24107
23829The @kbd{a F} command takes the data set to be fitted from the stack. 24108The @kbd{a F} command takes the data set to be fitted from the stack.
23830By default, it expects the data in the form of a matrix. For example, 24109By default, it expects the data in the form of a matrix. For example,
23831for a linear or polynomial fit, this would be a @c{$2\times N$} 24110for a linear or polynomial fit, this would be a
23832@asis{2xN} matrix where 24111@texline @tmath{2\times N}
23833the first row is a list of @cite{x} values and the second row has the 24112@infoline 2xN
23834corresponding @cite{y} values. For the multilinear fit shown above, 24113matrix where the first row is a list of @expr{x} values and the second
23835the matrix would have four rows (@cite{x_1}, @cite{x_2}, @cite{x_3}, and 24114row has the corresponding @expr{y} values. For the multilinear fit
23836@cite{y}, respectively). 24115shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2},
23837 24116@expr{x_3}, and @expr{y}, respectively).
23838If you happen to have an @c{$N\times2$} 24117
23839@asis{Nx2} matrix instead of a @c{$2\times N$} 24118If you happen to have an
23840@asis{2xN} matrix, 24119@texline @tmath{N\times2}
23841just press @kbd{v t} first to transpose the matrix. 24120@infoline Nx2
24121matrix instead of a
24122@texline @tmath{2\times N}
24123@infoline 2xN
24124matrix, just press @kbd{v t} first to transpose the matrix.
23842 24125
23843After you type @kbd{a F}, Calc prompts you to select a model. For a 24126After you type @kbd{a F}, Calc prompts you to select a model. For a
23844linear fit, press the digit @kbd{1}. 24127linear fit, press the digit @kbd{1}.
23845 24128
23846Calc then prompts for you to name the variables. By default it chooses 24129Calc then prompts for you to name the variables. By default it chooses
23847high letters like @cite{x} and @cite{y} for independent variables and 24130high letters like @expr{x} and @expr{y} for independent variables and
23848low letters like @cite{a} and @cite{b} for parameters. (The dependent 24131low letters like @expr{a} and @expr{b} for parameters. (The dependent
23849variable doesn't need a name.) The two kinds of variables are separated 24132variable doesn't need a name.) The two kinds of variables are separated
23850by a semicolon. Since you generally care more about the names of the 24133by a semicolon. Since you generally care more about the names of the
23851independent variables than of the parameters, Calc also allows you to 24134independent variables than of the parameters, Calc also allows you to
@@ -23874,17 +24157,17 @@ $$
23874@noindent 24157@noindent
23875is on the stack and we wish to do a simple linear fit. Type 24158is on the stack and we wish to do a simple linear fit. Type
23876@kbd{a F}, then @kbd{1} for the model, then @key{RET} to use 24159@kbd{a F}, then @kbd{1} for the model, then @key{RET} to use
23877the default names. The result will be the formula @cite{3 + 2 x} 24160the default names. The result will be the formula @expr{3 + 2 x}
23878on the stack. Calc has created the model expression @kbd{a + b x}, 24161on the stack. Calc has created the model expression @kbd{a + b x},
23879then found the optimal values of @cite{a} and @cite{b} to fit the 24162then found the optimal values of @expr{a} and @expr{b} to fit the
23880data. (In this case, it was able to find an exact fit.) Calc then 24163data. (In this case, it was able to find an exact fit.) Calc then
23881substituted those values for @cite{a} and @cite{b} in the model 24164substituted those values for @expr{a} and @expr{b} in the model
23882formula. 24165formula.
23883 24166
23884The @kbd{a F} command puts two entries in the trail. One is, as 24167The @kbd{a F} command puts two entries in the trail. One is, as
23885always, a copy of the result that went to the stack; the other is 24168always, a copy of the result that went to the stack; the other is
23886a vector of the actual parameter values, written as equations: 24169a vector of the actual parameter values, written as equations:
23887@cite{[a = 3, b = 2]}, in case you'd rather read them in a list 24170@expr{[a = 3, b = 2]}, in case you'd rather read them in a list
23888than pick them out of the formula. (You can type @kbd{t y} 24171than pick them out of the formula. (You can type @kbd{t y}
23889to move this vector to the stack; see @ref{Trail Commands}. 24172to move this vector to the stack; see @ref{Trail Commands}.
23890 24173
@@ -23930,17 +24213,20 @@ $$ \chi^2 = \sum_{i=1}^N (y_i - (a + b x_i))^2 $$
23930@end tex 24213@end tex
23931 24214
23932@noindent 24215@noindent
23933which is clearly zero if @cite{a + b x} exactly fits all data points, 24216which is clearly zero if @expr{a + b x} exactly fits all data points,
23934and increases as various @cite{a + b x_i} values fail to match the 24217and increases as various @expr{a + b x_i} values fail to match the
23935corresponding @cite{y_i} values. There are several reasons why the 24218corresponding @expr{y_i} values. There are several reasons why the
23936summand is squared, one of them being to ensure that @c{$\chi^2 \ge 0$} 24219summand is squared, one of them being to ensure that
23937@cite{chi^2 >= 0}. 24220@texline @tmath{\chi^2 \ge 0}.
23938Least-squares fitting simply chooses the values of @cite{a} and @cite{b} 24221@infoline @expr{chi^2 >= 0}.
23939for which the error @c{$\chi^2$} 24222Least-squares fitting simply chooses the values of @expr{a} and @expr{b}
23940@cite{chi^2} is as small as possible. 24223for which the error
24224@texline @tmath{\chi^2}
24225@infoline @expr{chi^2}
24226is as small as possible.
23941 24227
23942Other kinds of models do the same thing but with a different model 24228Other kinds of models do the same thing but with a different model
23943formula in place of @cite{a + b x_i}. 24229formula in place of @expr{a + b x_i}.
23944 24230
23945@tex 24231@tex
23946\bigskip 24232\bigskip
@@ -23953,9 +24239,9 @@ of a data matrix. In the linear case, @var{n} must be 2 since there
23953is always one independent variable and one dependent variable. 24239is always one independent variable and one dependent variable.
23954 24240
23955A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two 24241A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two
23956items from the stack, an @var{n}-row matrix of @cite{x} values, and a 24242items from the stack, an @var{n}-row matrix of @expr{x} values, and a
23957vector of @cite{y} values. If there is only one independent variable, 24243vector of @expr{y} values. If there is only one independent variable,
23958the @cite{x} values can be either a one-row matrix or a plain vector, 24244the @expr{x} values can be either a one-row matrix or a plain vector,
23959in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix. 24245in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix.
23960 24246
23961@node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits, Curve Fitting 24247@node Polynomial and Multilinear Fits, Error Estimates for Fits, Linear Fits, Curve Fitting
@@ -23974,15 +24260,15 @@ we could fit the original data matrix from the previous section
23974 24260
23975Note that since the constant and linear terms are enough to fit the 24261Note that since the constant and linear terms are enough to fit the
23976data exactly, it's no surprise that Calc chose a tiny contribution 24262data exactly, it's no surprise that Calc chose a tiny contribution
23977for @cite{x^2}. (The fact that it's not exactly zero is due only 24263for @expr{x^2}. (The fact that it's not exactly zero is due only
23978to roundoff error. Since our data are exact integers, we could get 24264to roundoff error. Since our data are exact integers, we could get
23979an exact answer by typing @kbd{m f} first to get fraction mode. 24265an exact answer by typing @kbd{m f} first to get fraction mode.
23980Then the @cite{x^2} term would vanish altogether. Usually, though, 24266Then the @expr{x^2} term would vanish altogether. Usually, though,
23981the data being fitted will be approximate floats so fraction mode 24267the data being fitted will be approximate floats so fraction mode
23982won't help.) 24268won't help.)
23983 24269
23984Doing the @kbd{a F 2} fit on the data set with 14 instead of 13 24270Doing the @kbd{a F 2} fit on the data set with 14 instead of 13
23985gives a much larger @cite{x^2} contribution, as Calc bends the 24271gives a much larger @expr{x^2} contribution, as Calc bends the
23986line slightly to improve the fit. 24272line slightly to improve the fit.
23987 24273
23988@example 24274@example
@@ -24000,7 +24286,7 @@ a polynomial that exactly matches all five data points:
24000@end example 24286@end example
24001 24287
24002The actual coefficients we get with a precision of 12, like 24288The actual coefficients we get with a precision of 12, like
24003@cite{0.0416666663588}, clearly suffer from loss of precision. 24289@expr{0.0416666663588}, clearly suffer from loss of precision.
24004It is a good idea to increase the working precision to several 24290It is a good idea to increase the working precision to several
24005digits beyond what you need when you do a fitting operation. 24291digits beyond what you need when you do a fitting operation.
24006Or, if your data are exact, use fraction mode to get exact 24292Or, if your data are exact, use fraction mode to get exact
@@ -24023,8 +24309,8 @@ command described below. @xref{Interpolation}.
24023@end tex 24309@end tex
24024 24310
24025Another generalization of the linear model is to assume the 24311Another generalization of the linear model is to assume the
24026@cite{y} values are a sum of linear contributions from several 24312@expr{y} values are a sum of linear contributions from several
24027@cite{x} values. This is a @dfn{multilinear} fit, and it is also 24313@expr{x} values. This is a @dfn{multilinear} fit, and it is also
24028selected by the @kbd{1} digit key. (Calc decides whether the fit 24314selected by the @kbd{1} digit key. (Calc decides whether the fit
24029is linear or multilinear by counting the rows in the data matrix.) 24315is linear or multilinear by counting the rows in the data matrix.)
24030 24316
@@ -24039,9 +24325,9 @@ Given the data matrix,
24039@end example 24325@end example
24040 24326
24041@noindent 24327@noindent
24042the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the 24328the command @kbd{a F 1 @key{RET}} will call the first row @expr{x} and the
24043second row @cite{y}, and will fit the values in the third row to the 24329second row @expr{y}, and will fit the values in the third row to the
24044model @cite{a + b x + c y}. 24330model @expr{a + b x + c y}.
24045 24331
24046@example 24332@example
240478. + 3. x + 0.5 y 243338. + 3. x + 0.5 y
@@ -24056,20 +24342,20 @@ Calc can do multilinear fits with any number of independent variables
24056 24342
24057Yet another variation is @dfn{homogeneous} linear models, in which 24343Yet another variation is @dfn{homogeneous} linear models, in which
24058the constant term is known to be zero. In the linear case, this 24344the constant term is known to be zero. In the linear case, this
24059means the model formula is simply @cite{a x}; in the multilinear 24345means the model formula is simply @expr{a x}; in the multilinear
24060case, the model might be @cite{a x + b y + c z}; and in the polynomial 24346case, the model might be @expr{a x + b y + c z}; and in the polynomial
24061case, the model could be @cite{a x + b x^2 + c x^3}. You can get 24347case, the model could be @expr{a x + b x^2 + c x^3}. You can get
24062a homogeneous linear or multilinear model by pressing the letter 24348a homogeneous linear or multilinear model by pressing the letter
24063@kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}. 24349@kbd{h} followed by a regular model key, like @kbd{1} or @kbd{2}.
24064 24350
24065It is certainly possible to have other constrained linear models, 24351It is certainly possible to have other constrained linear models,
24066like @cite{2.3 + a x} or @cite{a - 4 x}. While there is no single 24352like @expr{2.3 + a x} or @expr{a - 4 x}. While there is no single
24067key to select models like these, a later section shows how to enter 24353key to select models like these, a later section shows how to enter
24068any desired model by hand. In the first case, for example, you 24354any desired model by hand. In the first case, for example, you
24069would enter @kbd{a F ' 2.3 + a x}. 24355would enter @kbd{a F ' 2.3 + a x}.
24070 24356
24071Another class of models that will work but must be entered by hand 24357Another class of models that will work but must be entered by hand
24072are multinomial fits, e.g., @cite{a + b x + c y + d x^2 + e y^2 + f x y}. 24358are multinomial fits, e.g., @expr{a + b x + c y + d x^2 + e y^2 + f x y}.
24073 24359
24074@node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and Multilinear Fits, Curve Fitting 24360@node Error Estimates for Fits, Standard Nonlinear Models, Polynomial and Multilinear Fits, Curve Fitting
24075@subsection Error Estimates for Fits 24361@subsection Error Estimates for Fits
@@ -24096,9 +24382,11 @@ contain error forms. The data values must either all include errors
24096or all be plain numbers. Error forms can go anywhere but generally 24382or all be plain numbers. Error forms can go anywhere but generally
24097go on the numbers in the last row of the data matrix. If the last 24383go on the numbers in the last row of the data matrix. If the last
24098row contains error forms 24384row contains error forms
24099`@var{y_i}@w{ @t{+/-} }@c{$\sigma_i$} 24385@texline `@var{y_i}@w{ @t{+/-} }@tmath{\sigma_i}',
24100@var{sigma_i}', then the @c{$\chi^2$} 24386@infoline `@var{y_i}@w{ @t{+/-} }@var{sigma_i}',
24101@cite{chi^2} 24387then the
24388@texline @tmath{\chi^2}
24389@infoline @expr{chi^2}
24102statistic is now, 24390statistic is now,
24103 24391
24104@ifinfo 24392@ifinfo
@@ -24119,24 +24407,29 @@ the fitting operation.
24119 24407
24120If there are error forms on other rows of the data matrix, all the 24408If there are error forms on other rows of the data matrix, all the
24121errors for a given data point are combined; the square root of the 24409errors for a given data point are combined; the square root of the
24122sum of the squares of the errors forms the @c{$\sigma_i$} 24410sum of the squares of the errors forms the
24123@cite{sigma_i} used for 24411@texline @tmath{\sigma_i}
24124the data point. 24412@infoline @expr{sigma_i}
24413used for the data point.
24125 24414
24126Both @kbd{a F} and @kbd{H a F} can accept error forms in the input 24415Both @kbd{a F} and @kbd{H a F} can accept error forms in the input
24127matrix, although if you are concerned about error analysis you will 24416matrix, although if you are concerned about error analysis you will
24128probably use @kbd{H a F} so that the output also contains error 24417probably use @kbd{H a F} so that the output also contains error
24129estimates. 24418estimates.
24130 24419
24131If the input contains error forms but all the @c{$\sigma_i$} 24420If the input contains error forms but all the
24132@cite{sigma_i} values are 24421@texline @tmath{\sigma_i}
24133the same, it is easy to see that the resulting fitted model will be 24422@infoline @expr{sigma_i}
24134the same as if the input did not have error forms at all (@c{$\chi^2$} 24423values are the same, it is easy to see that the resulting fitted model
24135@cite{chi^2} 24424will be the same as if the input did not have error forms at all
24136is simply scaled uniformly by @c{$1 / \sigma^2$} 24425@texline (@tmath{\chi^2}
24137@cite{1 / sigma^2}, which doesn't affect 24426@infoline (@expr{chi^2}
24138where it has a minimum). But there @emph{will} be a difference 24427is simply scaled uniformly by
24139in the estimated errors of the coefficients reported by @kbd{H a F}. 24428@texline @tmath{1 / \sigma^2},
24429@infoline @expr{1 / sigma^2},
24430which doesn't affect where it has a minimum). But there @emph{will} be
24431a difference in the estimated errors of the coefficients reported by
24432@kbd{H a F}.
24140 24433
24141Consult any text on statistical modeling of data for a discussion 24434Consult any text on statistical modeling of data for a discussion
24142of where these error estimates come from and how they should be 24435of where these error estimates come from and how they should be
@@ -24161,54 +24454,66 @@ produced.
24161A vector of ``raw'' parameter values for the model. These are the 24454A vector of ``raw'' parameter values for the model. These are the
24162polynomial coefficients or other parameters as plain numbers, in the 24455polynomial coefficients or other parameters as plain numbers, in the
24163same order as the parameters appeared in the final prompt of the 24456same order as the parameters appeared in the final prompt of the
24164@kbd{I a F} command. For polynomials of degree @cite{d}, this vector 24457@kbd{I a F} command. For polynomials of degree @expr{d}, this vector
24165will have length @cite{M = d+1} with the constant term first. 24458will have length @expr{M = d+1} with the constant term first.
24166 24459
24167@item 24460@item
24168The covariance matrix @cite{C} computed from the fit. This is 24461The covariance matrix @expr{C} computed from the fit. This is
24169an @var{m}x@var{m} symmetric matrix; the diagonal elements 24462an @var{m}x@var{m} symmetric matrix; the diagonal elements
24170@c{$C_{jj}$} 24463@texline @tmath{C_{jj}}
24171@cite{C_j_j} are the variances @c{$\sigma_j^2$} 24464@infoline @expr{C_j_j}
24172@cite{sigma_j^2} of the parameters. 24465are the variances
24173The other elements are covariances @c{$\sigma_{ij}^2$} 24466@texline @tmath{\sigma_j^2}
24174@cite{sigma_i_j^2} that describe the 24467@infoline @expr{sigma_j^2}
24175correlation between pairs of parameters. (A related set of 24468of the parameters. The other elements are covariances
24176numbers, the @dfn{linear correlation coefficients} @c{$r_{ij}$} 24469@texline @tmath{\sigma_{ij}^2}
24177@cite{r_i_j}, 24470@infoline @expr{sigma_i_j^2}
24178are defined as @c{$\sigma_{ij}^2 / \sigma_i \, \sigma_j$} 24471that describe the correlation between pairs of parameters. (A related
24179@cite{sigma_i_j^2 / sigma_i sigma_j}.) 24472set of numbers, the @dfn{linear correlation coefficients}
24473@texline @tmath{r_{ij}},
24474@infoline @expr{r_i_j},
24475are defined as
24476@texline @tmath{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.)
24477@infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.)
24180 24478
24181@item 24479@item
24182A vector of @cite{M} ``parameter filter'' functions whose 24480A vector of @expr{M} ``parameter filter'' functions whose
24183meanings are described below. If no filters are necessary this 24481meanings are described below. If no filters are necessary this
24184will instead be an empty vector; this is always the case for the 24482will instead be an empty vector; this is always the case for the
24185polynomial and multilinear fits described so far. 24483polynomial and multilinear fits described so far.
24186 24484
24187@item 24485@item
24188The value of @c{$\chi^2$} 24486The value of
24189@cite{chi^2} for the fit, calculated by the formulas 24487@texline @tmath{\chi^2}
24190shown above. This gives a measure of the quality of the fit; 24488@infoline @expr{chi^2}
24191statisticians consider @c{$\chi^2 \approx N - M$} 24489for the fit, calculated by the formulas shown above. This gives a
24192@cite{chi^2 = N - M} to indicate a moderately good fit 24490measure of the quality of the fit; statisticians consider
24193(where again @cite{N} is the number of data points and @cite{M} 24491@texline @tmath{\chi^2 \approx N - M}
24194is the number of parameters). 24492@infoline @expr{chi^2 = N - M}
24493to indicate a moderately good fit (where again @expr{N} is the number of
24494data points and @expr{M} is the number of parameters).
24195 24495
24196@item 24496@item
24197A measure of goodness of fit expressed as a probability @cite{Q}. 24497A measure of goodness of fit expressed as a probability @expr{Q}.
24198This is computed from the @code{utpc} probability distribution 24498This is computed from the @code{utpc} probability distribution
24199function using @c{$\chi^2$} 24499function using
24200@cite{chi^2} with @cite{N - M} degrees of freedom. A 24500@texline @tmath{\chi^2}
24501@infoline @expr{chi^2}
24502with @expr{N - M} degrees of freedom. A
24201value of 0.5 implies a good fit; some texts recommend that often 24503value of 0.5 implies a good fit; some texts recommend that often
24202@cite{Q = 0.1} or even 0.001 can signify an acceptable fit. In 24504@expr{Q = 0.1} or even 0.001 can signify an acceptable fit. In
24203particular, @c{$\chi^2$} 24505particular,
24204@cite{chi^2} statistics assume the errors in your inputs 24506@texline @tmath{\chi^2}
24507@infoline @expr{chi^2}
24508statistics assume the errors in your inputs
24205follow a normal (Gaussian) distribution; if they don't, you may 24509follow a normal (Gaussian) distribution; if they don't, you may
24206have to accept smaller values of @cite{Q}. 24510have to accept smaller values of @expr{Q}.
24207 24511
24208The @cite{Q} value is computed only if the input included error 24512The @expr{Q} value is computed only if the input included error
24209estimates. Otherwise, Calc will report the symbol @code{nan} 24513estimates. Otherwise, Calc will report the symbol @code{nan}
24210for @cite{Q}. The reason is that in this case the @c{$\chi^2$} 24514for @expr{Q}. The reason is that in this case the
24211@cite{chi^2} 24515@texline @tmath{\chi^2}
24516@infoline @expr{chi^2}
24212value has effectively been used to estimate the original errors 24517value has effectively been used to estimate the original errors
24213in the input, and thus there is no redundant information left 24518in the input, and thus there is no redundant information left
24214over to use for a confidence test. 24519over to use for a confidence test.
@@ -24248,8 +24553,9 @@ Power law. @i{a x^b y^c}.
24248@item q 24553@item q
24249Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}. 24554Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}.
24250@item g 24555@item g
24251Gaussian. @c{${a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)$} 24556Gaussian.
24252@i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}. 24557@texline @tmath{{a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)}.
24558@infoline @i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}.
24253@end table 24559@end table
24254 24560
24255All of these models are used in the usual way; just press the appropriate 24561All of these models are used in the usual way; just press the appropriate
@@ -24260,12 +24566,12 @@ the parameter values from the vector that is placed in the trail.)
24260 24566
24261All models except Gaussian and polynomials can generalize as shown to any 24567All models except Gaussian and polynomials can generalize as shown to any
24262number of independent variables. Also, all the built-in models have an 24568number of independent variables. Also, all the built-in models have an
24263additive or multiplicative parameter shown as @cite{a} in the above table 24569additive or multiplicative parameter shown as @expr{a} in the above table
24264which can be replaced by zero or one, as appropriate, by typing @kbd{h} 24570which can be replaced by zero or one, as appropriate, by typing @kbd{h}
24265before the model key. 24571before the model key.
24266 24572
24267Note that many of these models are essentially equivalent, but express 24573Note that many of these models are essentially equivalent, but express
24268the parameters slightly differently. For example, @cite{a b^x} and 24574the parameters slightly differently. For example, @expr{a b^x} and
24269the other two exponential models are all algebraic rearrangements of 24575the other two exponential models are all algebraic rearrangements of
24270each other. Also, the ``quadratic'' model is just a degree-2 polynomial 24576each other. Also, the ``quadratic'' model is just a degree-2 polynomial
24271with the parameters expressed differently. Use whichever form best 24577with the parameters expressed differently. Use whichever form best
@@ -24275,8 +24581,8 @@ The HP-28/48 calculators support four different models for curve
24275fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}. 24581fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}.
24276These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)}, 24582These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)},
24277@samp{a exp(b x)}, and @samp{a x^b}, respectively. In each case, 24583@samp{a exp(b x)}, and @samp{a x^b}, respectively. In each case,
24278@cite{a} is what the HP-48 identifies as the ``intercept,'' and 24584@expr{a} is what the HP-48 identifies as the ``intercept,'' and
24279@cite{b} is what it calls the ``slope.'' 24585@expr{b} is what it calls the ``slope.''
24280 24586
24281@tex 24587@tex
24282\bigskip 24588\bigskip
@@ -24287,13 +24593,13 @@ If the model you want doesn't appear on this list, press @kbd{'}
24287formula, such as @kbd{m x - b}, as the model. (Not all models 24593formula, such as @kbd{m x - b}, as the model. (Not all models
24288will work, though---see the next section for details.) 24594will work, though---see the next section for details.)
24289 24595
24290The model can also be an equation like @cite{y = m x + b}. 24596The model can also be an equation like @expr{y = m x + b}.
24291In this case, Calc thinks of all the rows of the data matrix on 24597In this case, Calc thinks of all the rows of the data matrix on
24292equal terms; this model effectively has two parameters 24598equal terms; this model effectively has two parameters
24293(@cite{m} and @cite{b}) and two independent variables (@cite{x} 24599(@expr{m} and @expr{b}) and two independent variables (@expr{x}
24294and @cite{y}), with no ``dependent'' variables. Model equations 24600and @expr{y}), with no ``dependent'' variables. Model equations
24295do not need to take this @cite{y =} form. For example, the 24601do not need to take this @expr{y =} form. For example, the
24296implicit line equation @cite{a x + b y = 1} works fine as a 24602implicit line equation @expr{a x + b y = 1} works fine as a
24297model. 24603model.
24298 24604
24299When you enter a model, Calc makes an alphabetical list of all 24605When you enter a model, Calc makes an alphabetical list of all
@@ -24303,12 +24609,12 @@ default parameters, independent variables, and dependent variable
24303Calc assumes the dependent variable does not appear in the formula 24609Calc assumes the dependent variable does not appear in the formula
24304and thus does not need a name. 24610and thus does not need a name.
24305 24611
24306For example, if the model formula has the variables @cite{a,mu,sigma,t,x}, 24612For example, if the model formula has the variables @expr{a,mu,sigma,t,x},
24307and the data matrix has three rows (meaning two independent variables), 24613and the data matrix has three rows (meaning two independent variables),
24308Calc will use @cite{a,mu,sigma} as the default parameters, and the 24614Calc will use @expr{a,mu,sigma} as the default parameters, and the
24309data rows will be named @cite{t} and @cite{x}, respectively. If you 24615data rows will be named @expr{t} and @expr{x}, respectively. If you
24310enter an equation instead of a plain formula, Calc will use @cite{a,mu} 24616enter an equation instead of a plain formula, Calc will use @expr{a,mu}
24311as the parameters, and @cite{sigma,t,x} as the three independent 24617as the parameters, and @expr{sigma,t,x} as the three independent
24312variables. 24618variables.
24313 24619
24314You can, of course, override these choices by entering something 24620You can, of course, override these choices by entering something
@@ -24332,11 +24638,11 @@ choose which variables in the formula are independent by default and
24332which are parameters. 24638which are parameters.
24333 24639
24334Models taken from the stack can also be expressed as vectors of 24640Models taken from the stack can also be expressed as vectors of
24335two or three elements, @cite{[@var{model}, @var{vars}]} or 24641two or three elements, @expr{[@var{model}, @var{vars}]} or
24336@cite{[@var{model}, @var{vars}, @var{params}]}. Each of @var{vars} 24642@expr{[@var{model}, @var{vars}, @var{params}]}. Each of @var{vars}
24337and @var{params} may be either a variable or a vector of variables. 24643and @var{params} may be either a variable or a vector of variables.
24338(If @var{params} is omitted, all variables in @var{model} except 24644(If @var{params} is omitted, all variables in @var{model} except
24339those listed as @var{vars} are parameters.)@refill 24645those listed as @var{vars} are parameters.)
24340 24646
24341When you enter a model manually with @kbd{'}, Calc puts a 3-vector 24647When you enter a model manually with @kbd{'}, Calc puts a 3-vector
24342describing the model in the trail so you can get it back if you wish. 24648describing the model in the trail so you can get it back if you wish.
@@ -24364,14 +24670,16 @@ form @samp{arcsin(y) = a t + b}. The @code{arcsin} function always
24364returns results in the range from @i{-90} to 90 degrees (or the 24670returns results in the range from @i{-90} to 90 degrees (or the
24365equivalent range in radians). Suppose you had data that you 24671equivalent range in radians). Suppose you had data that you
24366believed to represent roughly three oscillations of a sine wave, 24672believed to represent roughly three oscillations of a sine wave,
24367so that the argument of the sine might go from zero to @c{$3\times360$} 24673so that the argument of the sine might go from zero to
24368@i{3*360} degrees. 24674@texline @tmath{3\times360}
24675@infoline @i{3*360}
24676degrees.
24369The above model would appear to be a good way to determine the 24677The above model would appear to be a good way to determine the
24370true frequency and phase of the sine wave, but in practice it 24678true frequency and phase of the sine wave, but in practice it
24371would fail utterly. The righthand side of the actual model 24679would fail utterly. The righthand side of the actual model
24372@samp{arcsin(y) = a t + b} will grow smoothly with @cite{t}, but 24680@samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but
24373the lefthand side will bounce back and forth between @i{-90} and 90. 24681the lefthand side will bounce back and forth between @i{-90} and 90.
24374No values of @cite{a} and @cite{b} can make the two sides match, 24682No values of @expr{a} and @expr{b} can make the two sides match,
24375even approximately. 24683even approximately.
24376 24684
24377There is no good solution to this problem at present. You could 24685There is no good solution to this problem at present. You could
@@ -24388,14 +24696,14 @@ taking Fourier and related transforms.)
24388@noindent 24696@noindent
24389Calc's internal least-squares fitter can only handle multilinear 24697Calc's internal least-squares fitter can only handle multilinear
24390models. More precisely, it can handle any model of the form 24698models. More precisely, it can handle any model of the form
24391@cite{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @cite{a,b,c} 24699@expr{a f(x,y,z) + b g(x,y,z) + c h(x,y,z)}, where @expr{a,b,c}
24392are the parameters and @cite{x,y,z} are the independent variables 24700are the parameters and @expr{x,y,z} are the independent variables
24393(of course there can be any number of each, not just three). 24701(of course there can be any number of each, not just three).
24394 24702
24395In a simple multilinear or polynomial fit, it is easy to see how 24703In a simple multilinear or polynomial fit, it is easy to see how
24396to convert the model into this form. For example, if the model 24704to convert the model into this form. For example, if the model
24397is @cite{a + b x + c x^2}, then @cite{f(x) = 1}, @cite{g(x) = x}, 24705is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x},
24398and @cite{h(x) = x^2} are suitable functions. 24706and @expr{h(x) = x^2} are suitable functions.
24399 24707
24400For other models, Calc uses a variety of algebraic manipulations 24708For other models, Calc uses a variety of algebraic manipulations
24401to try to put the problem into the form 24709to try to put the problem into the form
@@ -24405,15 +24713,15 @@ Y(x,y,z) = A(a,b,c) F(x,y,z) + B(a,b,c) G(x,y,z) + C(a,b,c) H(x,y,z)
24405@end smallexample 24713@end smallexample
24406 24714
24407@noindent 24715@noindent
24408where @cite{Y,A,B,C,F,G,H} are arbitrary functions. It computes 24716where @expr{Y,A,B,C,F,G,H} are arbitrary functions. It computes
24409@cite{Y}, @cite{F}, @cite{G}, and @cite{H} for all the data points, 24717@expr{Y}, @expr{F}, @expr{G}, and @expr{H} for all the data points,
24410does a standard linear fit to find the values of @cite{A}, @cite{B}, 24718does a standard linear fit to find the values of @expr{A}, @expr{B},
24411and @cite{C}, then uses the equation solver to solve for @cite{a,b,c} 24719and @expr{C}, then uses the equation solver to solve for @expr{a,b,c}
24412in terms of @cite{A,B,C}. 24720in terms of @expr{A,B,C}.
24413 24721
24414A remarkable number of models can be cast into this general form. 24722A remarkable number of models can be cast into this general form.
24415We'll look at two examples here to see how it works. The power-law 24723We'll look at two examples here to see how it works. The power-law
24416model @cite{y = a x^b} with two independent variables and two parameters 24724model @expr{y = a x^b} with two independent variables and two parameters
24417can be rewritten as follows: 24725can be rewritten as follows:
24418 24726
24419@example 24727@example
@@ -24424,15 +24732,19 @@ ln(y) = ln(a) + b ln(x)
24424@end example 24732@end example
24425 24733
24426@noindent 24734@noindent
24427which matches the desired form with @c{$Y = \ln(y)$} 24735which matches the desired form with
24428@cite{Y = ln(y)}, @c{$A = \ln(a)$} 24736@texline @tmath{Y = \ln(y)},
24429@cite{A = ln(a)}, 24737@infoline @expr{Y = ln(y)},
24430@cite{F = 1}, @cite{B = b}, and @c{$G = \ln(x)$} 24738@texline @tmath{A = \ln(a)},
24431@cite{G = ln(x)}. Calc thus computes 24739@infoline @expr{A = ln(a)},
24432the logarithms of your @cite{y} and @cite{x} values, does a linear fit 24740@expr{F = 1}, @expr{B = b}, and
24433for @cite{A} and @cite{B}, then solves to get @c{$a = \exp(A)$} 24741@texline @tmath{G = \ln(x)}.
24434@cite{a = exp(A)} and 24742@infoline @expr{G = ln(x)}.
24435@cite{b = B}. 24743Calc thus computes the logarithms of your @expr{y} and @expr{x} values,
24744does a linear fit for @expr{A} and @expr{B}, then solves to get
24745@texline @tmath{a = \exp(A)}
24746@infoline @expr{a = exp(A)}
24747and @expr{b = B}.
24436 24748
24437Another interesting example is the ``quadratic'' model, which can 24749Another interesting example is the ``quadratic'' model, which can
24438be handled by expanding according to the distributive law. 24750be handled by expanding according to the distributive law.
@@ -24443,27 +24755,27 @@ y = a + b c^2 - 2 b c x + b x^2
24443@end example 24755@end example
24444 24756
24445@noindent 24757@noindent
24446which matches with @cite{Y = y}, @cite{A = a + b c^2}, @cite{F = 1}, 24758which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1},
24447@cite{B = -2 b c}, @cite{G = x} (the @i{-2} factor could just as easily 24759@expr{B = -2 b c}, @expr{G = x} (the @i{-2} factor could just as easily
24448have been put into @cite{G} instead of @cite{B}), @cite{C = b}, and 24760have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and
24449@cite{H = x^2}. 24761@expr{H = x^2}.
24450 24762
24451The Gaussian model looks quite complicated, but a closer examination 24763The Gaussian model looks quite complicated, but a closer examination
24452shows that it's actually similar to the quadratic model but with an 24764shows that it's actually similar to the quadratic model but with an
24453exponential that can be brought to the top and moved into @cite{Y}. 24765exponential that can be brought to the top and moved into @expr{Y}.
24454 24766
24455An example of a model that cannot be put into general linear 24767An example of a model that cannot be put into general linear
24456form is a Gaussian with a constant background added on, i.e., 24768form is a Gaussian with a constant background added on, i.e.,
24457@cite{d} + the regular Gaussian formula. If you have a model like 24769@expr{d} + the regular Gaussian formula. If you have a model like
24458this, your best bet is to replace enough of your parameters with 24770this, your best bet is to replace enough of your parameters with
24459constants to make the model linearizable, then adjust the constants 24771constants to make the model linearizable, then adjust the constants
24460manually by doing a series of fits. You can compare the fits by 24772manually by doing a series of fits. You can compare the fits by
24461graphing them, by examining the goodness-of-fit measures returned by 24773graphing them, by examining the goodness-of-fit measures returned by
24462@kbd{I a F}, or by some other method suitable to your application. 24774@kbd{I a F}, or by some other method suitable to your application.
24463Note that some models can be linearized in several ways. The 24775Note that some models can be linearized in several ways. The
24464Gaussian-plus-@var{d} model can be linearized by setting @cite{d} 24776Gaussian-plus-@var{d} model can be linearized by setting @expr{d}
24465(the background) to a constant, or by setting @cite{b} (the standard 24777(the background) to a constant, or by setting @expr{b} (the standard
24466deviation) and @cite{c} (the mean) to constants. 24778deviation) and @expr{c} (the mean) to constants.
24467 24779
24468To fit a model with constants substituted for some parameters, just 24780To fit a model with constants substituted for some parameters, just
24469store suitable values in those parameter variables, then omit them 24781store suitable values in those parameter variables, then omit them
@@ -24475,8 +24787,9 @@ from the list of parameters when you answer the variables prompt.
24475 24787
24476A last desperate step would be to use the general-purpose 24788A last desperate step would be to use the general-purpose
24477@code{minimize} function rather than @code{fit}. After all, both 24789@code{minimize} function rather than @code{fit}. After all, both
24478functions solve the problem of minimizing an expression (the @c{$\chi^2$} 24790functions solve the problem of minimizing an expression (the
24479@cite{chi^2} 24791@texline @tmath{\chi^2}
24792@infoline @expr{chi^2}
24480sum) by adjusting certain parameters in the expression. The @kbd{a F} 24793sum) by adjusting certain parameters in the expression. The @kbd{a F}
24481command is able to use a vastly more efficient algorithm due to its 24794command is able to use a vastly more efficient algorithm due to its
24482special knowledge about linear chi-square sums, but the @kbd{a N} 24795special knowledge about linear chi-square sums, but the @kbd{a N}
@@ -24485,9 +24798,10 @@ command can do the same thing by brute force.
24485A compromise would be to pick out a few parameters without which the 24798A compromise would be to pick out a few parameters without which the
24486fit is linearizable, and use @code{minimize} on a call to @code{fit} 24799fit is linearizable, and use @code{minimize} on a call to @code{fit}
24487which efficiently takes care of the rest of the parameters. The thing 24800which efficiently takes care of the rest of the parameters. The thing
24488to be minimized would be the value of @c{$\chi^2$} 24801to be minimized would be the value of
24489@cite{chi^2} returned as 24802@texline @tmath{\chi^2}
24490the fifth result of the @code{xfit} function: 24803@infoline @expr{chi^2}
24804returned as the fifth result of the @code{xfit} function:
24491 24805
24492@smallexample 24806@smallexample
24493minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) 24807minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)
@@ -24496,7 +24810,7 @@ minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess)
24496@noindent 24810@noindent
24497where @code{gaus} represents the Gaussian model with background, 24811where @code{gaus} represents the Gaussian model with background,
24498@code{data} represents the data matrix, and @code{guess} represents 24812@code{data} represents the data matrix, and @code{guess} represents
24499the initial guess for @cite{d} that @code{minimize} requires. 24813the initial guess for @expr{d} that @code{minimize} requires.
24500This operation will only be, shall we say, extraordinarily slow 24814This operation will only be, shall we say, extraordinarily slow
24501rather than astronomically slow (as would be the case if @code{minimize} 24815rather than astronomically slow (as would be the case if @code{minimize}
24502were used by itself to solve the problem). 24816were used by itself to solve the problem).
@@ -24507,17 +24821,17 @@ were used by itself to solve the problem).
24507 24821
24508The @kbd{I a F} [@code{xfit}] command is somewhat trickier when 24822The @kbd{I a F} [@code{xfit}] command is somewhat trickier when
24509nonlinear models are used. The second item in the result is the 24823nonlinear models are used. The second item in the result is the
24510vector of ``raw'' parameters @cite{A}, @cite{B}, @cite{C}. The 24824vector of ``raw'' parameters @expr{A}, @expr{B}, @expr{C}. The
24511covariance matrix is written in terms of those raw parameters. 24825covariance matrix is written in terms of those raw parameters.
24512The fifth item is a vector of @dfn{filter} expressions. This 24826The fifth item is a vector of @dfn{filter} expressions. This
24513is the empty vector @samp{[]} if the raw parameters were the same 24827is the empty vector @samp{[]} if the raw parameters were the same
24514as the requested parameters, i.e., if @cite{A = a}, @cite{B = b}, 24828as the requested parameters, i.e., if @expr{A = a}, @expr{B = b},
24515and so on (which is always true if the model is already linear 24829and so on (which is always true if the model is already linear
24516in the parameters as written, e.g., for polynomial fits). If the 24830in the parameters as written, e.g., for polynomial fits). If the
24517parameters had to be rearranged, the fifth item is instead a vector 24831parameters had to be rearranged, the fifth item is instead a vector
24518of one formula per parameter in the original model. The raw 24832of one formula per parameter in the original model. The raw
24519parameters are expressed in these ``filter'' formulas as 24833parameters are expressed in these ``filter'' formulas as
24520@samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} for @cite{B}, 24834@samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} for @expr{B},
24521and so on. 24835and so on.
24522 24836
24523When Calc needs to modify the model to return the result, it replaces 24837When Calc needs to modify the model to return the result, it replaces
@@ -24537,30 +24851,33 @@ figure out how to interpret the covariances in the presence of
24537nontrivial filter functions. 24851nontrivial filter functions.
24538 24852
24539Things are also complicated when the input contains error forms. 24853Things are also complicated when the input contains error forms.
24540Suppose there are three independent and dependent variables, @cite{x}, 24854Suppose there are three independent and dependent variables, @expr{x},
24541@cite{y}, and @cite{z}, one or more of which are error forms in the 24855@expr{y}, and @expr{z}, one or more of which are error forms in the
24542data. Calc combines all the error values by taking the square root 24856data. Calc combines all the error values by taking the square root
24543of the sum of the squares of the errors. It then changes @cite{x} 24857of the sum of the squares of the errors. It then changes @expr{x}
24544and @cite{y} to be plain numbers, and makes @cite{z} into an error 24858and @expr{y} to be plain numbers, and makes @expr{z} into an error
24545form with this combined error. The @cite{Y(x,y,z)} part of the 24859form with this combined error. The @expr{Y(x,y,z)} part of the
24546linearized model is evaluated, and the result should be an error 24860linearized model is evaluated, and the result should be an error
24547form. The error part of that result is used for @c{$\sigma_i$} 24861form. The error part of that result is used for
24548@cite{sigma_i} for 24862@texline @tmath{\sigma_i}
24549the data point. If for some reason @cite{Y(x,y,z)} does not return 24863@infoline @expr{sigma_i}
24550an error form, the combined error from @cite{z} is used directly 24864for the data point. If for some reason @expr{Y(x,y,z)} does not return
24551for @c{$\sigma_i$} 24865an error form, the combined error from @expr{z} is used directly for
24552@cite{sigma_i}. Finally, @cite{z} is also stripped of its error 24866@texline @tmath{\sigma_i}.
24553for use in computing @cite{F(x,y,z)}, @cite{G(x,y,z)} and so on; 24867@infoline @expr{sigma_i}.
24868Finally, @expr{z} is also stripped of its error
24869for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on;
24554the righthand side of the linearized model is computed in regular 24870the righthand side of the linearized model is computed in regular
24555arithmetic with no error forms. 24871arithmetic with no error forms.
24556 24872
24557(While these rules may seem complicated, they are designed to do 24873(While these rules may seem complicated, they are designed to do
24558the most reasonable thing in the typical case that @cite{Y(x,y,z)} 24874the most reasonable thing in the typical case that @expr{Y(x,y,z)}
24559depends only on the dependent variable @cite{z}, and in fact is 24875depends only on the dependent variable @expr{z}, and in fact is
24560often simply equal to @cite{z}. For common cases like polynomials 24876often simply equal to @expr{z}. For common cases like polynomials
24561and multilinear models, the combined error is simply used as the 24877and multilinear models, the combined error is simply used as the
24562@c{$\sigma$} 24878@texline @tmath{\sigma}
24563@cite{sigma} for the data point with no further ado.) 24879@infoline @expr{sigma}
24880for the data point with no further ado.)
24564 24881
24565@tex 24882@tex
24566\bigskip 24883\bigskip
@@ -24617,7 +24934,7 @@ Parameter variables are renamed to function calls @samp{fitparam(1)},
24617@samp{fitparam(2)}, and so on, and independent variables are renamed 24934@samp{fitparam(2)}, and so on, and independent variables are renamed
24618to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable 24935to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable
24619is the highest-numbered @code{fitvar}. For example, the power law 24936is the highest-numbered @code{fitvar}. For example, the power law
24620model @cite{a x^b} is converted to @cite{y = a x^b}, then to 24937model @expr{a x^b} is converted to @expr{y = a x^b}, then to
24621 24938
24622@smallexample 24939@smallexample
24623@group 24940@group
@@ -24637,11 +24954,11 @@ fitsystem(@var{Y}, @var{FGH}, @var{abc})
24637@end example 24954@end example
24638 24955
24639@noindent 24956@noindent
24640where @var{Y} is a formula that describes the function @cite{Y(x,y,z)}, 24957where @var{Y} is a formula that describes the function @expr{Y(x,y,z)},
24641@var{FGH} is the vector of formulas @cite{[F(x,y,z), G(x,y,z), H(x,y,z)]}, 24958@var{FGH} is the vector of formulas @expr{[F(x,y,z), G(x,y,z), H(x,y,z)]},
24642and @var{abc} is the vector of parameter filters which refer to the 24959and @var{abc} is the vector of parameter filters which refer to the
24643raw parameters as @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} 24960raw parameters as @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)}
24644for @cite{B}, etc. While the number of raw parameters (the length of 24961for @expr{B}, etc. While the number of raw parameters (the length of
24645the @var{FGH} vector) is usually the same as the number of original 24962the @var{FGH} vector) is usually the same as the number of original
24646parameters (the length of the @var{abc} vector), this is not required. 24963parameters (the length of the @var{abc} vector), this is not required.
24647 24964
@@ -24664,7 +24981,7 @@ be put into @var{abc} or @var{FGH}). In particular, all
24664non-constant powers are converted to logs-and-exponentials form, 24981non-constant powers are converted to logs-and-exponentials form,
24665and the distributive law is used to expand products of sums. 24982and the distributive law is used to expand products of sums.
24666Quotients are rewritten to use the @samp{fitinv} function, where 24983Quotients are rewritten to use the @samp{fitinv} function, where
24667@samp{fitinv(x)} represents @cite{1/x} while the @code{FitRules} 24984@samp{fitinv(x)} represents @expr{1/x} while the @code{FitRules}
24668are operating. (The use of @code{fitinv} makes recognition of 24985are operating. (The use of @code{fitinv} makes recognition of
24669linear-looking forms easier.) If you modify @code{FitRules}, you 24986linear-looking forms easier.) If you modify @code{FitRules}, you
24670will probably only need to modify the rules for this phase. 24987will probably only need to modify the rules for this phase.
@@ -24672,8 +24989,8 @@ will probably only need to modify the rules for this phase.
24672Phase two, whose rules can actually also apply during phases one 24989Phase two, whose rules can actually also apply during phases one
24673and three, first rewrites @code{fitmodel} to a two-argument 24990and three, first rewrites @code{fitmodel} to a two-argument
24674form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is 24991form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is
24675initially zero and @var{model} has been changed from @cite{a=b} 24992initially zero and @var{model} has been changed from @expr{a=b}
24676to @cite{a-b} form. It then tries to peel off invertible functions 24993to @expr{a-b} form. It then tries to peel off invertible functions
24677from the outside of @var{model} and put them into @var{Y} instead, 24994from the outside of @var{model} and put them into @var{Y} instead,
24678calling the equation solver to invert the functions. Finally, when 24995calling the equation solver to invert the functions. Finally, when
24679this is no longer possible, the @code{fitmodel} is changed to a 24996this is no longer possible, the @code{fitmodel} is changed to a
@@ -24719,7 +25036,7 @@ least-squares solver wants to see.
24719@tindex hasfitvars 25036@tindex hasfitvars
24720Two functions which are useful in connection with @code{FitRules} 25037Two functions which are useful in connection with @code{FitRules}
24721are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check 25038are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check
24722whether @cite{x} refers to any parameters or independent variables, 25039whether @expr{x} refers to any parameters or independent variables,
24723respectively. Specifically, these functions return ``true'' if the 25040respectively. Specifically, these functions return ``true'' if the
24724argument contains any @code{fitparam} (or @code{fitvar}) function 25041argument contains any @code{fitparam} (or @code{fitvar}) function
24725calls, and ``false'' otherwise. (Recall that ``true'' means a 25042calls, and ``false'' otherwise. (Recall that ``true'' means a
@@ -24767,48 +25084,48 @@ The @code{efit} (corresponding to @kbd{H a F}) and @code{xfit}
24767@pindex calc-poly-interp 25084@pindex calc-poly-interp
24768@tindex polint 25085@tindex polint
24769The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does 25086The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does
24770a polynomial interpolation at a particular @cite{x} value. It takes 25087a polynomial interpolation at a particular @expr{x} value. It takes
24771two arguments from the stack: A data matrix of the sort used by 25088two arguments from the stack: A data matrix of the sort used by
24772@kbd{a F}, and a single number which represents the desired @cite{x} 25089@kbd{a F}, and a single number which represents the desired @expr{x}
24773value. Calc effectively does an exact polynomial fit as if by @kbd{a F i}, 25090value. Calc effectively does an exact polynomial fit as if by @kbd{a F i},
24774then substitutes the @cite{x} value into the result in order to get an 25091then substitutes the @expr{x} value into the result in order to get an
24775approximate @cite{y} value based on the fit. (Calc does not actually 25092approximate @expr{y} value based on the fit. (Calc does not actually
24776use @kbd{a F i}, however; it uses a direct method which is both more 25093use @kbd{a F i}, however; it uses a direct method which is both more
24777efficient and more numerically stable.) 25094efficient and more numerically stable.)
24778 25095
24779The result of @kbd{a p} is actually a vector of two values: The @cite{y} 25096The result of @kbd{a p} is actually a vector of two values: The @expr{y}
24780value approximation, and an error measure @cite{dy} that reflects Calc's 25097value approximation, and an error measure @expr{dy} that reflects Calc's
24781estimation of the probable error of the approximation at that value of 25098estimation of the probable error of the approximation at that value of
24782@cite{x}. If the input @cite{x} is equal to any of the @cite{x} values 25099@expr{x}. If the input @expr{x} is equal to any of the @expr{x} values
24783in the data matrix, the output @cite{y} will be the corresponding @cite{y} 25100in the data matrix, the output @expr{y} will be the corresponding @expr{y}
24784value from the matrix, and the output @cite{dy} will be exactly zero. 25101value from the matrix, and the output @expr{dy} will be exactly zero.
24785 25102
24786A prefix argument of 2 causes @kbd{a p} to take separate x- and 25103A prefix argument of 2 causes @kbd{a p} to take separate x- and
24787y-vectors from the stack instead of one data matrix. 25104y-vectors from the stack instead of one data matrix.
24788 25105
24789If @cite{x} is a vector of numbers, @kbd{a p} will return a matrix of 25106If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of
24790interpolated results for each of those @cite{x} values. (The matrix will 25107interpolated results for each of those @expr{x} values. (The matrix will
24791have two columns, the @cite{y} values and the @cite{dy} values.) 25108have two columns, the @expr{y} values and the @expr{dy} values.)
24792If @cite{x} is a formula instead of a number, the @code{polint} function 25109If @expr{x} is a formula instead of a number, the @code{polint} function
24793remains in symbolic form; use the @kbd{a "} command to expand it out to 25110remains in symbolic form; use the @kbd{a "} command to expand it out to
24794a formula that describes the fit in symbolic terms. 25111a formula that describes the fit in symbolic terms.
24795 25112
24796In all cases, the @kbd{a p} command leaves the data vectors or matrix 25113In all cases, the @kbd{a p} command leaves the data vectors or matrix
24797on the stack. Only the @cite{x} value is replaced by the result. 25114on the stack. Only the @expr{x} value is replaced by the result.
24798 25115
24799@kindex H a p 25116@kindex H a p
24800@tindex ratint 25117@tindex ratint
24801The @kbd{H a p} [@code{ratint}] command does a rational function 25118The @kbd{H a p} [@code{ratint}] command does a rational function
24802interpolation. It is used exactly like @kbd{a p}, except that it 25119interpolation. It is used exactly like @kbd{a p}, except that it
24803uses as its model the quotient of two polynomials. If there are 25120uses as its model the quotient of two polynomials. If there are
24804@cite{N} data points, the numerator and denominator polynomials will 25121@expr{N} data points, the numerator and denominator polynomials will
24805each have degree @cite{N/2} (if @cite{N} is odd, the denominator will 25122each have degree @expr{N/2} (if @expr{N} is odd, the denominator will
24806have degree one higher than the numerator). 25123have degree one higher than the numerator).
24807 25124
24808Rational approximations have the advantage that they can accurately 25125Rational approximations have the advantage that they can accurately
24809describe functions that have poles (points at which the function's value 25126describe functions that have poles (points at which the function's value
24810goes to infinity, so that the denominator polynomial of the approximation 25127goes to infinity, so that the denominator polynomial of the approximation
24811goes to zero). If @cite{x} corresponds to a pole of the fitted rational 25128goes to zero). If @expr{x} corresponds to a pole of the fitted rational
24812function, then the result will be a division by zero. If Infinite mode 25129function, then the result will be a division by zero. If Infinite mode
24813is enabled, the result will be @samp{[uinf, uinf]}. 25130is enabled, the result will be @samp{[uinf, uinf]}.
24814 25131
@@ -24842,9 +25159,9 @@ $$ \sum_{k=1}^5 k^2 = 55 $$
24842The choice of index variable is arbitrary, but it's best not to 25159The choice of index variable is arbitrary, but it's best not to
24843use a variable with a stored value. In particular, while 25160use a variable with a stored value. In particular, while
24844@code{i} is often a favorite index variable, it should be avoided 25161@code{i} is often a favorite index variable, it should be avoided
24845in Calc because @code{i} has the imaginary constant @cite{(0, 1)} 25162in Calc because @code{i} has the imaginary constant @expr{(0, 1)}
24846as a value. If you pressed @kbd{=} on a sum over @code{i}, it would 25163as a value. If you pressed @kbd{=} on a sum over @code{i}, it would
24847be changed to a nonsensical sum over the ``variable'' @cite{(0, 1)}! 25164be changed to a nonsensical sum over the ``variable'' @expr{(0, 1)}!
24848If you really want to use @code{i} as an index variable, use 25165If you really want to use @code{i} as an index variable, use
24849@w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable. 25166@w{@kbd{s u i @key{RET}}} first to ``unstore'' this variable.
24850(@xref{Storing Variables}.) 25167(@xref{Storing Variables}.)
@@ -24878,7 +25195,7 @@ is one. If @var{low} is also omitted, the limits are @samp{-inf}
24878and @samp{inf}, respectively. 25195and @samp{inf}, respectively.
24879 25196
24880Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)} 25197Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)}
24881returns @cite{1}. This is done by evaluating the sum in closed 25198returns @expr{1}. This is done by evaluating the sum in closed
24882form (to @samp{1. - 0.5^n} in this case), then evaluating this 25199form (to @samp{1. - 0.5^n} in this case), then evaluating this
24883formula with @code{n} set to @code{inf}. Calc's usual rules 25200formula with @code{n} set to @code{inf}. Calc's usual rules
24884for ``infinite'' arithmetic can find the answer from there. If 25201for ``infinite'' arithmetic can find the answer from there. If
@@ -24916,31 +25233,32 @@ of iterations is @i{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero
24916but the sum from @samp{n} to @samp{n-2} may report a nonzero value 25233but the sum from @samp{n} to @samp{n-2} may report a nonzero value
24917if Calc used a closed form solution. 25234if Calc used a closed form solution.
24918 25235
24919Calc's logical predicates like @cite{a < b} return 1 for ``true'' 25236Calc's logical predicates like @expr{a < b} return 1 for ``true''
24920and 0 for ``false.'' @xref{Logical Operations}. This can be 25237and 0 for ``false.'' @xref{Logical Operations}. This can be
24921used to advantage for building conditional sums. For example, 25238used to advantage for building conditional sums. For example,
24922@samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all 25239@samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all
24923prime numbers from 1 to 20; the @code{prime} predicate returns 1 if 25240prime numbers from 1 to 20; the @code{prime} predicate returns 1 if
24924its argument is prime and 0 otherwise. You can read this expression 25241its argument is prime and 0 otherwise. You can read this expression
24925as ``the sum of @cite{k^2}, where @cite{k} is prime.'' Indeed, 25242as ``the sum of @expr{k^2}, where @expr{k} is prime.'' Indeed,
24926@samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes 25243@samp{sum(prime(k)*k^2, k)} would represent the sum of @emph{all} primes
24927squared, since the limits default to plus and minus infinity, but 25244squared, since the limits default to plus and minus infinity, but
24928there are no such sums that Calc's built-in rules can do in 25245there are no such sums that Calc's built-in rules can do in
24929closed form. 25246closed form.
24930 25247
24931As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the 25248As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the
24932sum of @cite{f(k)} for all @cite{k} from 1 to @cite{n}, excluding 25249sum of @expr{f(k)} for all @expr{k} from 1 to @expr{n}, excluding
24933one value @cite{k_0}. Slightly more tricky is the summand 25250one value @expr{k_0}. Slightly more tricky is the summand
24934@samp{(k != k_0) / (k - k_0)}, which is an attempt to describe 25251@samp{(k != k_0) / (k - k_0)}, which is an attempt to describe
24935the sum of all @cite{1/(k-k_0)} except at @cite{k = k_0}, where 25252the sum of all @expr{1/(k-k_0)} except at @expr{k = k_0}, where
24936this would be a division by zero. But at @cite{k = k_0}, this 25253this would be a division by zero. But at @expr{k = k_0}, this
24937formula works out to the indeterminate form @cite{0 / 0}, which 25254formula works out to the indeterminate form @expr{0 / 0}, which
24938Calc will not assume is zero. Better would be to use 25255Calc will not assume is zero. Better would be to use
24939@samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does 25256@samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does
24940an ``if-then-else'' test: This expression says, ``if @c{$k \ne k_0$} 25257an ``if-then-else'' test: This expression says, ``if
24941@cite{k != k_0}, 25258@texline @tmath{k \ne k_0},
24942then @cite{1/(k-k_0)}, else zero.'' Now the formula @cite{1/(k-k_0)} 25259@infoline @expr{k != k_0},
24943will not even be evaluated by Calc when @cite{k = k_0}. 25260then @expr{1/(k-k_0)}, else zero.'' Now the formula @expr{1/(k-k_0)}
25261will not even be evaluated by Calc when @expr{k = k_0}.
24944 25262
24945@cindex Alternating sums 25263@cindex Alternating sums
24946@kindex a - 25264@kindex a -
@@ -24991,7 +25309,7 @@ for which @code{dnonzero} returns 1 is ``true,'' and anything for
24991which @code{dnonzero} returns 0 or cannot decide is assumed ``false.'' 25309which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''
24992Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then'' 25310Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then''
24993portion if its condition is provably true, but it will execute the 25311portion if its condition is provably true, but it will execute the
24994``else'' portion for any condition like @cite{a = b} that is not 25312``else'' portion for any condition like @expr{a = b} that is not
24995provably true, even if it might be true. Algebraic functions that 25313provably true, even if it might be true. Algebraic functions that
24996have conditions as arguments, like @code{? :} and @code{&&}, remain 25314have conditions as arguments, like @code{? :} and @code{&&}, remain
24997unevaluated if the condition is neither provably true nor provably 25315unevaluated if the condition is neither provably true nor provably
@@ -25004,10 +25322,10 @@ false. @xref{Declarations}.)
25004@tindex == 25322@tindex ==
25005The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function 25323The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function
25006(which can also be written @samp{a = b} or @samp{a == b} in an algebraic 25324(which can also be written @samp{a = b} or @samp{a == b} in an algebraic
25007formula) is true if @cite{a} and @cite{b} are equal, either because they 25325formula) is true if @expr{a} and @expr{b} are equal, either because they
25008are identical expressions, or because they are numbers which are 25326are identical expressions, or because they are numbers which are
25009numerically equal. (Thus the integer 1 is considered equal to the float 25327numerically equal. (Thus the integer 1 is considered equal to the float
250101.0.) If the equality of @cite{a} and @cite{b} cannot be determined, 253281.0.) If the equality of @expr{a} and @expr{b} cannot be determined,
25011the comparison is left in symbolic form. Note that as a command, this 25329the comparison is left in symbolic form. Note that as a command, this
25012operation pops two values from the stack and pushes back either a 1 or 25330operation pops two values from the stack and pushes back either a 1 or
25013a 0, or a formula @samp{a = b} if the values' equality cannot be determined. 25331a 0, or a formula @samp{a = b} if the values' equality cannot be determined.
@@ -25035,9 +25353,9 @@ variables).
25035@tindex neq 25353@tindex neq
25036@tindex != 25354@tindex !=
25037The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or 25355The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or
25038@samp{a != b} function, is true if @cite{a} and @cite{b} are not equal. 25356@samp{a != b} function, is true if @expr{a} and @expr{b} are not equal.
25039This also works with more than two arguments; @samp{a != b != c != d} 25357This also works with more than two arguments; @samp{a != b != c != d}
25040tests that all four of @cite{a}, @cite{b}, @cite{c}, and @cite{d} are 25358tests that all four of @expr{a}, @expr{b}, @expr{c}, and @expr{d} are
25041distinct numbers. 25359distinct numbers.
25042 25360
25043@kindex a < 25361@kindex a <
@@ -25087,7 +25405,7 @@ distinct numbers.
25087@end ignore 25405@end ignore
25088@tindex >= 25406@tindex >=
25089The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}] 25407The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}]
25090operation is true if @cite{a} is less than @cite{b}. Similar functions 25408operation is true if @expr{a} is less than @expr{b}. Similar functions
25091are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}], 25409are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}],
25092@kbd{a [} (@code{calc-less-equal}) [@samp{leq(a,b)} or @samp{a <= b}], and 25410@kbd{a [} (@code{calc-less-equal}) [@samp{leq(a,b)} or @samp{a <= b}], and
25093@kbd{a ]} (@code{calc-greater-equal}) [@samp{geq(a,b)} or @samp{a >= b}]. 25411@kbd{a ]} (@code{calc-greater-equal}) [@samp{geq(a,b)} or @samp{a >= b}].
@@ -25121,8 +25439,8 @@ taking the lefthand side.
25121@tindex && 25439@tindex &&
25122The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}] 25440The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}]
25123function is true if both of its arguments are true, i.e., are 25441function is true if both of its arguments are true, i.e., are
25124non-zero numbers. In this case, the result will be either @cite{a} or 25442non-zero numbers. In this case, the result will be either @expr{a} or
25125@cite{b}, chosen arbitrarily. If either argument is zero, the result is 25443@expr{b}, chosen arbitrarily. If either argument is zero, the result is
25126zero. Otherwise, the formula is left in symbolic form. 25444zero. Otherwise, the formula is left in symbolic form.
25127 25445
25128@kindex a | 25446@kindex a |
@@ -25132,7 +25450,7 @@ zero. Otherwise, the formula is left in symbolic form.
25132The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}] 25450The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}]
25133function is true if either or both of its arguments are true (nonzero). 25451function is true if either or both of its arguments are true (nonzero).
25134The result is whichever argument was nonzero, choosing arbitrarily if both 25452The result is whichever argument was nonzero, choosing arbitrarily if both
25135are nonzero. If both @cite{a} and @cite{b} are zero, the result is 25453are nonzero. If both @expr{a} and @expr{b} are zero, the result is
25136zero. 25454zero.
25137 25455
25138@kindex a ! 25456@kindex a !
@@ -25140,8 +25458,8 @@ zero.
25140@tindex lnot 25458@tindex lnot
25141@tindex ! 25459@tindex !
25142The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}] 25460The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}]
25143function is true if @cite{a} is false (zero), or false if @cite{a} is 25461function is true if @expr{a} is false (zero), or false if @expr{a} is
25144true (nonzero). It is left in symbolic form if @cite{a} is not a 25462true (nonzero). It is left in symbolic form if @expr{a} is not a
25145number. 25463number.
25146 25464
25147@kindex a : 25465@kindex a :
@@ -25157,9 +25475,9 @@ number.
25157@tindex : 25475@tindex :
25158@cindex Arguments, not evaluated 25476@cindex Arguments, not evaluated
25159The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}] 25477The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}]
25160function is equal to either @cite{b} or @cite{c} if @cite{a} is a nonzero 25478function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero
25161number or zero, respectively. If @cite{a} is not a number, the test is 25479number or zero, respectively. If @expr{a} is not a number, the test is
25162left in symbolic form and neither @cite{b} nor @cite{c} is evaluated in 25480left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in
25163any way. In algebraic formulas, this is one of the few Calc functions 25481any way. In algebraic formulas, this is one of the few Calc functions
25164whose arguments are not automatically evaluated when the function itself 25482whose arguments are not automatically evaluated when the function itself
25165is evaluated. The others are @code{lambda}, @code{quote}, and 25483is evaluated. The others are @code{lambda}, @code{quote}, and
@@ -25170,24 +25488,24 @@ will not work because the @samp{3:4} is parsed as a fraction instead of
25170as three separate symbols. Type something like @samp{a ? 3 : 4} or 25488as three separate symbols. Type something like @samp{a ? 3 : 4} or
25171@samp{a?(3):4} instead. 25489@samp{a?(3):4} instead.
25172 25490
25173As a special case, if @cite{a} evaluates to a vector, then both @cite{b} 25491As a special case, if @expr{a} evaluates to a vector, then both @expr{b}
25174and @cite{c} are evaluated; the result is a vector of the same length 25492and @expr{c} are evaluated; the result is a vector of the same length
25175as @cite{a} whose elements are chosen from corresponding elements of 25493as @expr{a} whose elements are chosen from corresponding elements of
25176@cite{b} and @cite{c} according to whether each element of @cite{a} 25494@expr{b} and @expr{c} according to whether each element of @expr{a}
25177is zero or nonzero. Each of @cite{b} and @cite{c} must be either a 25495is zero or nonzero. Each of @expr{b} and @expr{c} must be either a
25178vector of the same length as @cite{a}, or a non-vector which is matched 25496vector of the same length as @expr{a}, or a non-vector which is matched
25179with all elements of @cite{a}. 25497with all elements of @expr{a}.
25180 25498
25181@kindex a @{ 25499@kindex a @{
25182@pindex calc-in-set 25500@pindex calc-in-set
25183@tindex in 25501@tindex in
25184The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if 25502The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if
25185the number @cite{a} is in the set of numbers represented by @cite{b}. 25503the number @expr{a} is in the set of numbers represented by @expr{b}.
25186If @cite{b} is an interval form, @cite{a} must be one of the values 25504If @expr{b} is an interval form, @expr{a} must be one of the values
25187encompassed by the interval. If @cite{b} is a vector, @cite{a} must be 25505encompassed by the interval. If @expr{b} is a vector, @expr{a} must be
25188equal to one of the elements of the vector. (If any vector elements are 25506equal to one of the elements of the vector. (If any vector elements are
25189intervals, @cite{a} must be in any of the intervals.) If @cite{b} is a 25507intervals, @expr{a} must be in any of the intervals.) If @expr{b} is a
25190plain number, @cite{a} must be numerically equal to @cite{b}. 25508plain number, @expr{a} must be numerically equal to @expr{b}.
25191@xref{Set Operations}, for a group of commands that manipulate sets 25509@xref{Set Operations}, for a group of commands that manipulate sets
25192of this sort. 25510of this sort.
25193 25511
@@ -25196,7 +25514,7 @@ of this sort.
25196@end ignore 25514@end ignore
25197@tindex typeof 25515@tindex typeof
25198The @samp{typeof(a)} function produces an integer or variable which 25516The @samp{typeof(a)} function produces an integer or variable which
25199characterizes @cite{a}. If @cite{a} is a number, vector, or variable, 25517characterizes @expr{a}. If @expr{a} is a number, vector, or variable,
25200the result will be one of the following numbers: 25518the result will be one of the following numbers:
25201 25519
25202@example 25520@example
@@ -25217,7 +25535,7 @@ the result will be one of the following numbers:
25217102 Matrix 25535102 Matrix
25218@end example 25536@end example
25219 25537
25220Otherwise, @cite{a} is a formula, and the result is a variable which 25538Otherwise, @expr{a} is a formula, and the result is a variable which
25221represents the name of the top-level function call. 25539represents the name of the top-level function call.
25222 25540
25223@ignore 25541@ignore
@@ -25232,15 +25550,15 @@ represents the name of the top-level function call.
25232@starindex 25550@starindex
25233@end ignore 25551@end ignore
25234@tindex constant 25552@tindex constant
25235The @samp{integer(a)} function returns true if @cite{a} is an integer. 25553The @samp{integer(a)} function returns true if @expr{a} is an integer.
25236The @samp{real(a)} function 25554The @samp{real(a)} function
25237is true if @cite{a} is a real number, either integer, fraction, or 25555is true if @expr{a} is a real number, either integer, fraction, or
25238float. The @samp{constant(a)} function returns true if @cite{a} is 25556float. The @samp{constant(a)} function returns true if @expr{a} is
25239any of the objects for which @code{typeof} would produce an integer 25557any of the objects for which @code{typeof} would produce an integer
25240code result except for variables, and provided that the components of 25558code result except for variables, and provided that the components of
25241an object like a vector or error form are themselves constant. 25559an object like a vector or error form are themselves constant.
25242Note that infinities do not satisfy any of these tests, nor do 25560Note that infinities do not satisfy any of these tests, nor do
25243special constants like @code{pi} and @code{e}.@refill 25561special constants like @code{pi} and @code{e}.
25244 25562
25245@xref{Declarations}, for a set of similar functions that recognize 25563@xref{Declarations}, for a set of similar functions that recognize
25246formulas as well as actual numbers. For example, @samp{dint(floor(x))} 25564formulas as well as actual numbers. For example, @samp{dint(floor(x))}
@@ -25253,21 +25571,21 @@ literally an integer constant.
25253@end ignore 25571@end ignore
25254@tindex refers 25572@tindex refers
25255The @samp{refers(a,b)} function is true if the variable (or sub-expression) 25573The @samp{refers(a,b)} function is true if the variable (or sub-expression)
25256@cite{b} appears in @cite{a}, or false otherwise. Unlike the other 25574@expr{b} appears in @expr{a}, or false otherwise. Unlike the other
25257tests described here, this function returns a definite ``no'' answer 25575tests described here, this function returns a definite ``no'' answer
25258even if its arguments are still in symbolic form. The only case where 25576even if its arguments are still in symbolic form. The only case where
25259@code{refers} will be left unevaluated is if @cite{a} is a plain 25577@code{refers} will be left unevaluated is if @expr{a} is a plain
25260variable (different from @cite{b}). 25578variable (different from @expr{b}).
25261 25579
25262@ignore 25580@ignore
25263@starindex 25581@starindex
25264@end ignore 25582@end ignore
25265@tindex negative 25583@tindex negative
25266The @samp{negative(a)} function returns true if @cite{a} ``looks'' negative, 25584The @samp{negative(a)} function returns true if @expr{a} ``looks'' negative,
25267because it is a negative number, because it is of the form @cite{-x}, 25585because it is a negative number, because it is of the form @expr{-x},
25268or because it is a product or quotient with a term that looks negative. 25586or because it is a product or quotient with a term that looks negative.
25269This is most useful in rewrite rules. Beware that @samp{negative(a)} 25587This is most useful in rewrite rules. Beware that @samp{negative(a)}
25270evaluates to 1 or 0 for @emph{any} argument @cite{a}, so it can only 25588evaluates to 1 or 0 for @emph{any} argument @expr{a}, so it can only
25271be stored in a formula if the default simplifications are turned off 25589be stored in a formula if the default simplifications are turned off
25272first with @kbd{m O} (or if it appears in an unevaluated context such 25590first with @kbd{m O} (or if it appears in an unevaluated context such
25273as a rewrite rule condition). 25591as a rewrite rule condition).
@@ -25276,8 +25594,8 @@ as a rewrite rule condition).
25276@starindex 25594@starindex
25277@end ignore 25595@end ignore
25278@tindex variable 25596@tindex variable
25279The @samp{variable(a)} function is true if @cite{a} is a variable, 25597The @samp{variable(a)} function is true if @expr{a} is a variable,
25280or false if not. If @cite{a} is a function call, this test is left 25598or false if not. If @expr{a} is a function call, this test is left
25281in symbolic form. Built-in variables like @code{pi} and @code{inf} 25599in symbolic form. Built-in variables like @code{pi} and @code{inf}
25282are considered variables like any others by this test. 25600are considered variables like any others by this test.
25283 25601
@@ -25285,7 +25603,7 @@ are considered variables like any others by this test.
25285@starindex 25603@starindex
25286@end ignore 25604@end ignore
25287@tindex nonvar 25605@tindex nonvar
25288The @samp{nonvar(a)} function is true if @cite{a} is a non-variable. 25606The @samp{nonvar(a)} function is true if @expr{a} is a non-variable.
25289If its argument is a variable it is left unsimplified; it never 25607If its argument is a variable it is left unsimplified; it never
25290actually returns zero. However, since Calc's condition-testing 25608actually returns zero. However, since Calc's condition-testing
25291commands consider ``false'' anything not provably true, this is 25609commands consider ``false'' anything not provably true, this is
@@ -25310,15 +25628,15 @@ often good enough.
25310@cindex Linearity testing 25628@cindex Linearity testing
25311The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt} 25629The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt}
25312check if an expression is ``linear,'' i.e., can be written in the form 25630check if an expression is ``linear,'' i.e., can be written in the form
25313@cite{a + b x} for some constants @cite{a} and @cite{b}, and some 25631@expr{a + b x} for some constants @expr{a} and @expr{b}, and some
25314variable or subformula @cite{x}. The function @samp{islin(f,x)} checks 25632variable or subformula @expr{x}. The function @samp{islin(f,x)} checks
25315if formula @cite{f} is linear in @cite{x}, returning 1 if so. For 25633if formula @expr{f} is linear in @expr{x}, returning 1 if so. For
25316example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and 25634example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and
25317@samp{islin(x y / 3 - 2, x)} all return 1. The @samp{lin(f,x)} function 25635@samp{islin(x y / 3 - 2, x)} all return 1. The @samp{lin(f,x)} function
25318is similar, except that instead of returning 1 it returns the vector 25636is similar, except that instead of returning 1 it returns the vector
25319@cite{[a, b, x]}. For the above examples, this vector would be 25637@expr{[a, b, x]}. For the above examples, this vector would be
25320@cite{[0, 1, x]}, @cite{[0, -1, x]}, @cite{[3, 0, x]}, and 25638@expr{[0, 1, x]}, @expr{[0, -1, x]}, @expr{[3, 0, x]}, and
25321@cite{[-2, y/3, x]}, respectively. Both @code{lin} and @code{islin} 25639@expr{[-2, y/3, x]}, respectively. Both @code{lin} and @code{islin}
25322generally remain unevaluated for expressions which are not linear, 25640generally remain unevaluated for expressions which are not linear,
25323e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second 25641e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second
25324argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))} 25642argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))}
@@ -25326,19 +25644,19 @@ returns true.
25326 25644
25327The @code{linnt} and @code{islinnt} functions perform a similar check, 25645The @code{linnt} and @code{islinnt} functions perform a similar check,
25328but require a ``non-trivial'' linear form, which means that the 25646but require a ``non-trivial'' linear form, which means that the
25329@cite{b} coefficient must be non-zero. For example, @samp{lin(2,x)} 25647@expr{b} coefficient must be non-zero. For example, @samp{lin(2,x)}
25330returns @cite{[2, 0, x]} and @samp{lin(y,x)} returns @cite{[y, 0, x]}, 25648returns @expr{[2, 0, x]} and @samp{lin(y,x)} returns @expr{[y, 0, x]},
25331but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated 25649but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated
25332(in other words, these formulas are considered to be only ``trivially'' 25650(in other words, these formulas are considered to be only ``trivially''
25333linear in @cite{x}). 25651linear in @expr{x}).
25334 25652
25335All four linearity-testing functions allow you to omit the second 25653All four linearity-testing functions allow you to omit the second
25336argument, in which case the input may be linear in any non-constant 25654argument, in which case the input may be linear in any non-constant
25337formula. Here, the @cite{a=0}, @cite{b=1} case is also considered 25655formula. Here, the @expr{a=0}, @expr{b=1} case is also considered
25338trivial, and only constant values for @cite{a} and @cite{b} are 25656trivial, and only constant values for @expr{a} and @expr{b} are
25339recognized. Thus, @samp{lin(2 x y)} returns @cite{[0, 2, x y]}, 25657recognized. Thus, @samp{lin(2 x y)} returns @expr{[0, 2, x y]},
25340@samp{lin(2 - x y)} returns @cite{[2, -1, x y]}, and @samp{lin(x y)} 25658@samp{lin(2 - x y)} returns @expr{[2, -1, x y]}, and @samp{lin(x y)}
25341returns @cite{[0, 1, x y]}. The @code{linnt} function would allow the 25659returns @expr{[0, 1, x y]}. The @code{linnt} function would allow the
25342first two cases but not the third. Also, neither @code{lin} nor 25660first two cases but not the third. Also, neither @code{lin} nor
25343@code{linnt} accept plain constants as linear in the one-argument 25661@code{linnt} accept plain constants as linear in the one-argument
25344case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false. 25662case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
@@ -25347,8 +25665,8 @@ case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
25347@starindex 25665@starindex
25348@end ignore 25666@end ignore
25349@tindex istrue 25667@tindex istrue
25350The @samp{istrue(a)} function returns 1 if @cite{a} is a nonzero 25668The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero
25351number or provably nonzero formula, or 0 if @cite{a} is anything else. 25669number or provably nonzero formula, or 0 if @expr{a} is anything else.
25352Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is 25670Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is
25353used to make sure they are not evaluated prematurely. (Note that 25671used to make sure they are not evaluated prematurely. (Note that
25354declarations are used when deciding whether a formula is true; 25672declarations are used when deciding whether a formula is true;
@@ -25408,7 +25726,7 @@ This operator is equivalent to the function call @samp{assign(old, new)}.
25408The @code{assign} function is undefined by itself in Calc, so an 25726The @code{assign} function is undefined by itself in Calc, so an
25409assignment formula such as a rewrite rule will be left alone by ordinary 25727assignment formula such as a rewrite rule will be left alone by ordinary
25410Calc commands. But certain commands, like the rewrite system, interpret 25728Calc commands. But certain commands, like the rewrite system, interpret
25411assignments in special ways.@refill 25729assignments in special ways.
25412 25730
25413For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace 25731For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace
25414every occurrence of the sine of something, squared, with one minus the 25732every occurrence of the sine of something, squared, with one minus the
@@ -25451,7 +25769,7 @@ invoke them by giving the variable name. The @kbd{s e}
25451(@code{calc-edit-variable}) command is an easy way to create or edit a 25769(@code{calc-edit-variable}) command is an easy way to create or edit a
25452rule set stored in a variable. You may also wish to use @kbd{s p} 25770rule set stored in a variable. You may also wish to use @kbd{s p}
25453(@code{calc-permanent-variable}) to save your rules permanently; 25771(@code{calc-permanent-variable}) to save your rules permanently;
25454@pxref{Operations on Variables}.@refill 25772@pxref{Operations on Variables}.
25455 25773
25456Rewrite rules are compiled into a special internal form for faster 25774Rewrite rules are compiled into a special internal form for faster
25457matching. If you enter a rule set directly it must be recompiled 25775matching. If you enter a rule set directly it must be recompiled
@@ -25468,10 +25786,10 @@ vector of two rules, the use of this notation is no longer recommended.
25468@subsection Basic Rewrite Rules 25786@subsection Basic Rewrite Rules
25469 25787
25470@noindent 25788@noindent
25471To match a particular formula @cite{x} with a particular rewrite rule 25789To match a particular formula @expr{x} with a particular rewrite rule
25472@samp{@var{old} := @var{new}}, Calc compares the structure of @cite{x} with 25790@samp{@var{old} := @var{new}}, Calc compares the structure of @expr{x} with
25473the structure of @var{old}. Variables that appear in @var{old} are 25791the structure of @var{old}. Variables that appear in @var{old} are
25474treated as @dfn{meta-variables}; the corresponding positions in @cite{x} 25792treated as @dfn{meta-variables}; the corresponding positions in @expr{x}
25475may contain any sub-formulas. For example, the pattern @samp{f(x,y)} 25793may contain any sub-formulas. For example, the pattern @samp{f(x,y)}
25476would match the expression @samp{f(12, a+1)} with the meta-variable 25794would match the expression @samp{f(12, a+1)} with the meta-variable
25477@samp{x} corresponding to 12 and with @samp{y} corresponding to 25795@samp{x} corresponding to 12 and with @samp{y} corresponding to
@@ -25481,7 +25799,7 @@ that will make the pattern match these expressions. Notice that if
25481the pattern is a single meta-variable, it will match any expression. 25799the pattern is a single meta-variable, it will match any expression.
25482 25800
25483If a given meta-variable appears more than once in @var{old}, the 25801If a given meta-variable appears more than once in @var{old}, the
25484corresponding sub-formulas of @cite{x} must be identical. Thus 25802corresponding sub-formulas of @expr{x} must be identical. Thus
25485the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and 25803the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and
25486@samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}. 25804@samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(a+b, b+a)}.
25487(@xref{Conditional Rewrite Rules}, for a way to match the latter.) 25805(@xref{Conditional Rewrite Rules}, for a way to match the latter.)
@@ -25525,14 +25843,14 @@ number or any other object known to be nonzero (@pxref{Declarations}),
25525the rule is accepted. If the result is zero or if it is a symbolic 25843the rule is accepted. If the result is zero or if it is a symbolic
25526formula that is not known to be nonzero, the rule is rejected. 25844formula that is not known to be nonzero, the rule is rejected.
25527@xref{Logical Operations}, for a number of functions that return 25845@xref{Logical Operations}, for a number of functions that return
255281 or 0 according to the results of various tests.@refill 258461 or 0 according to the results of various tests.
25529 25847
25530For example, the formula @samp{n > 0} simplifies to 1 or 0 if @cite{n} 25848For example, the formula @samp{n > 0} simplifies to 1 or 0 if @expr{n}
25531is replaced by a positive or nonpositive number, respectively (or if 25849is replaced by a positive or nonpositive number, respectively (or if
25532@cite{n} has been declared to be positive or nonpositive). Thus, 25850@expr{n} has been declared to be positive or nonpositive). Thus,
25533the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to 25851the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to
25534@samp{f(0, 4)} but not to @samp{f(-3, 2)} or @samp{f(12, a+1)} 25852@samp{f(0, 4)} but not to @samp{f(-3, 2)} or @samp{f(12, a+1)}
25535(assuming no outstanding declarations for @cite{a}). In the case of 25853(assuming no outstanding declarations for @expr{a}). In the case of
25536@samp{f(-3, 2)}, the condition can be shown not to be satisfied; in 25854@samp{f(-3, 2)}, the condition can be shown not to be satisfied; in
25537the case of @samp{f(12, a+1)}, the condition merely cannot be shown 25855the case of @samp{f(12, a+1)}, the condition merely cannot be shown
25538to be satisfied, but that is enough to reject the rule. 25856to be satisfied, but that is enough to reject the rule.
@@ -25562,12 +25880,12 @@ decides when it is best to test each condition while a rule is being
25562matched. 25880matched.
25563 25881
25564Certain conditions are handled as special cases by the rewrite rule 25882Certain conditions are handled as special cases by the rewrite rule
25565system and are tested very efficiently: Where @cite{x} is any 25883system and are tested very efficiently: Where @expr{x} is any
25566meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)}, 25884meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)},
25567@samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @cite{y} 25885@samp{constant(x)}, @samp{negative(x)}, @samp{x >= y} where @expr{y}
25568is either a constant or another meta-variable and @samp{>=} may be 25886is either a constant or another meta-variable and @samp{>=} may be
25569replaced by any of the six relational operators, and @samp{x % a = b} 25887replaced by any of the six relational operators, and @samp{x % a = b}
25570where @cite{a} and @cite{b} are constants. Other conditions, like 25888where @expr{a} and @expr{b} are constants. Other conditions, like
25571@samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check 25889@samp{x >= y+1} or @samp{dreal(x)}, will be less efficient to check
25572since Calc must bring the whole evaluator and simplifier into play. 25890since Calc must bring the whole evaluator and simplifier into play.
25573 25891
@@ -25776,7 +26094,7 @@ are linear in @samp{x}. You can also use the @code{lin} and @code{islin}
25776functions with rewrite conditions to test for this; @pxref{Logical 26094functions with rewrite conditions to test for this; @pxref{Logical
25777Operations}. These functions are not as convenient to use in rewrite 26095Operations}. These functions are not as convenient to use in rewrite
25778rules, but they recognize more kinds of formulas as linear: 26096rules, but they recognize more kinds of formulas as linear:
25779@samp{x/z} is considered linear with @cite{b = 1/z} by @code{lin}, 26097@samp{x/z} is considered linear with @expr{b = 1/z} by @code{lin},
25780but it will not match the above pattern because that pattern calls 26098but it will not match the above pattern because that pattern calls
25781for a multiplication, not a division. 26099for a multiplication, not a division.
25782 26100
@@ -25796,7 +26114,7 @@ opt(a) sin(x)^2 + opt(a) cos(x)^2 := a
25796@end example 26114@end example
25797 26115
25798Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2} 26116Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2}
25799because one @cite{a} would have ``matched'' 1 while the other matched 6. 26117because one @expr{a} would have ``matched'' 1 while the other matched 6.
25800 26118
25801Calc automatically converts a rule like 26119Calc automatically converts a rule like
25802 26120
@@ -25944,20 +26262,25 @@ work in the righthand side of a rule.
25944@end ignore 26262@end ignore
25945@tindex import 26263@tindex import
25946One kind of marker, @samp{import(x)}, takes the place of a whole 26264One kind of marker, @samp{import(x)}, takes the place of a whole
25947rule. Here @cite{x} is the name of a variable containing another 26265rule. Here @expr{x} is the name of a variable containing another
25948rule set; those rules are ``spliced into'' the rule set that 26266rule set; those rules are ``spliced into'' the rule set that
25949imports them. For example, if @samp{[f(a+b) := f(a) + f(b), 26267imports them. For example, if @samp{[f(a+b) := f(a) + f(b),
25950f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, 26268f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},
25951then the rule set @samp{[f(0) := 0, import(linearF)]} will apply 26269then the rule set @samp{[f(0) := 0, import(linearF)]} will apply
25952all three rules. It is possible to modify the imported rules 26270all three rules. It is possible to modify the imported rules
25953slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports 26271slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports
25954the rule set @cite{x} with all occurrences of @c{$v_1$} 26272the rule set @expr{x} with all occurrences of
25955@cite{v1}, as either 26273@texline @tmath{v_1},
25956a variable name or a function name, replaced with @c{$x_1$} 26274@infoline @expr{v1},
25957@cite{x1} and 26275as either a variable name or a function name, replaced with
25958so on. (If @c{$v_1$} 26276@texline @tmath{x_1}
25959@cite{v1} is used as a function name, then @c{$x_1$} 26277@infoline @expr{x1}
25960@cite{x1} 26278and so on. (If
26279@texline @tmath{v_1}
26280@infoline @expr{v1}
26281is used as a function name, then
26282@texline @tmath{x_1}
26283@infoline @expr{x1}
25961must be either a function name itself or a @w{@samp{< >}} nameless 26284must be either a function name itself or a @w{@samp{< >}} nameless
25962function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, 26285function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0,
25963import(linearF, f, g)]} applies the linearity rules to the function 26286import(linearF, f, g)]} applies the linearity rules to the function
@@ -25972,7 +26295,7 @@ The special functions allowed in patterns are:
25972@starindex 26295@starindex
25973@end ignore 26296@end ignore
25974@tindex quote 26297@tindex quote
25975This pattern matches exactly @cite{x}; variable names in @cite{x} are 26298This pattern matches exactly @expr{x}; variable names in @expr{x} are
25976not interpreted as meta-variables. The only flexibility is that 26299not interpreted as meta-variables. The only flexibility is that
25977numbers are compared for numeric equality, so that the pattern 26300numbers are compared for numeric equality, so that the pattern
25978@samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}. 26301@samp{f(quote(12))} will match both @samp{f(12)} and @samp{f(12.0)}.
@@ -25986,10 +26309,10 @@ as a result in this case.)
25986@starindex 26309@starindex
25987@end ignore 26310@end ignore
25988@tindex plain 26311@tindex plain
25989Here @cite{x} must be a function call @samp{f(x1,x2,@dots{})}. This 26312Here @expr{x} must be a function call @samp{f(x1,x2,@dots{})}. This
25990pattern matches a call to function @cite{f} with the specified 26313pattern matches a call to function @expr{f} with the specified
25991argument patterns. No special knowledge of the properties of the 26314argument patterns. No special knowledge of the properties of the
25992function @cite{f} is used in this case; @samp{+} is not commutative or 26315function @expr{f} is used in this case; @samp{+} is not commutative or
25993associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}} 26316associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}}
25994are treated as patterns. If you wish them to be treated ``plainly'' 26317are treated as patterns. If you wish them to be treated ``plainly''
25995as well, you must enclose them with more @code{plain} markers: 26318as well, you must enclose them with more @code{plain} markers:
@@ -26000,24 +26323,24 @@ as well, you must enclose them with more @code{plain} markers:
26000@starindex 26323@starindex
26001@end ignore 26324@end ignore
26002@tindex opt 26325@tindex opt
26003Here @cite{x} must be a variable name. This must appear as an 26326Here @expr{x} must be a variable name. This must appear as an
26004argument to a function or an element of a vector; it specifies that 26327argument to a function or an element of a vector; it specifies that
26005the argument or element is optional. 26328the argument or element is optional.
26006As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||}, 26329As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||},
26007or as the second argument to @samp{/} or @samp{^}, the value @var{def} 26330or as the second argument to @samp{/} or @samp{^}, the value @var{def}
26008may be omitted. The pattern @samp{x + opt(y)} matches a sum by 26331may be omitted. The pattern @samp{x + opt(y)} matches a sum by
26009binding one summand to @cite{x} and the other to @cite{y}, and it 26332binding one summand to @expr{x} and the other to @expr{y}, and it
26010matches anything else by binding the whole expression to @cite{x} and 26333matches anything else by binding the whole expression to @expr{x} and
26011zero to @cite{y}. The other operators above work similarly.@refill 26334zero to @expr{y}. The other operators above work similarly.
26012 26335
26013For general miscellaneous functions, the default value @code{def} 26336For general miscellaneous functions, the default value @code{def}
26014must be specified. Optional arguments are dropped starting with 26337must be specified. Optional arguments are dropped starting with
26015the rightmost one during matching. For example, the pattern 26338the rightmost one during matching. For example, the pattern
26016@samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)}, 26339@samp{f(opt(a,0), b, opt(c,b))} will match @samp{f(b)}, @samp{f(a,b)},
26017or @samp{f(a,b,c)}. Default values of zero and @cite{b} are 26340or @samp{f(a,b,c)}. Default values of zero and @expr{b} are
26018supplied in this example for the omitted arguments. Note that 26341supplied in this example for the omitted arguments. Note that
26019the literal variable @cite{b} will be the default in the latter 26342the literal variable @expr{b} will be the default in the latter
26020case, @emph{not} the value that matched the meta-variable @cite{b}. 26343case, @emph{not} the value that matched the meta-variable @expr{b}.
26021In other words, the default @var{def} is effectively quoted. 26344In other words, the default @var{def} is effectively quoted.
26022 26345
26023@item condition(x,c) 26346@item condition(x,c)
@@ -26026,8 +26349,8 @@ In other words, the default @var{def} is effectively quoted.
26026@end ignore 26349@end ignore
26027@tindex condition 26350@tindex condition
26028@tindex :: 26351@tindex ::
26029This matches the pattern @cite{x}, with the attached condition 26352This matches the pattern @expr{x}, with the attached condition
26030@cite{c}. It is the same as @samp{x :: c}. 26353@expr{c}. It is the same as @samp{x :: c}.
26031 26354
26032@item pand(x,y) 26355@item pand(x,y)
26033@ignore 26356@ignore
@@ -26035,8 +26358,8 @@ This matches the pattern @cite{x}, with the attached condition
26035@end ignore 26358@end ignore
26036@tindex pand 26359@tindex pand
26037@tindex &&& 26360@tindex &&&
26038This matches anything that matches both pattern @cite{x} and 26361This matches anything that matches both pattern @expr{x} and
26039pattern @cite{y}. It is the same as @samp{x &&& y}. 26362pattern @expr{y}. It is the same as @samp{x &&& y}.
26040@pxref{Composing Patterns in Rewrite Rules}. 26363@pxref{Composing Patterns in Rewrite Rules}.
26041 26364
26042@item por(x,y) 26365@item por(x,y)
@@ -26045,8 +26368,8 @@ pattern @cite{y}. It is the same as @samp{x &&& y}.
26045@end ignore 26368@end ignore
26046@tindex por 26369@tindex por
26047@tindex ||| 26370@tindex |||
26048This matches anything that matches either pattern @cite{x} or 26371This matches anything that matches either pattern @expr{x} or
26049pattern @cite{y}. It is the same as @w{@samp{x ||| y}}. 26372pattern @expr{y}. It is the same as @w{@samp{x ||| y}}.
26050 26373
26051@item pnot(x) 26374@item pnot(x)
26052@ignore 26375@ignore
@@ -26054,7 +26377,7 @@ pattern @cite{y}. It is the same as @w{@samp{x ||| y}}.
26054@end ignore 26377@end ignore
26055@tindex pnot 26378@tindex pnot
26056@tindex !!! 26379@tindex !!!
26057This matches anything that does not match pattern @cite{x}. 26380This matches anything that does not match pattern @expr{x}.
26058It is the same as @samp{!!! x}. 26381It is the same as @samp{!!! x}.
26059 26382
26060@item cons(h,t) 26383@item cons(h,t)
@@ -26063,8 +26386,8 @@ It is the same as @samp{!!! x}.
26063@end ignore 26386@end ignore
26064@tindex cons (rewrites) 26387@tindex cons (rewrites)
26065This matches any vector of one or more elements. The first 26388This matches any vector of one or more elements. The first
26066element is matched to @cite{h}; a vector of the remaining 26389element is matched to @expr{h}; a vector of the remaining
26067elements is matched to @cite{t}. Note that vectors of fixed 26390elements is matched to @expr{t}. Note that vectors of fixed
26068length can also be matched as actual vectors: The rule 26391length can also be matched as actual vectors: The rule
26069@samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent 26392@samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent
26070to the rule @samp{[a,b] := [a+b]}. 26393to the rule @samp{[a,b] := [a+b]}.
@@ -26075,8 +26398,8 @@ to the rule @samp{[a,b] := [a+b]}.
26075@end ignore 26398@end ignore
26076@tindex rcons (rewrites) 26399@tindex rcons (rewrites)
26077This is like @code{cons}, except that the @emph{last} element 26400This is like @code{cons}, except that the @emph{last} element
26078is matched to @cite{h}, with the remaining elements matched 26401is matched to @expr{h}, with the remaining elements matched
26079to @cite{t}. 26402to @expr{t}.
26080 26403
26081@item apply(f,args) 26404@item apply(f,args)
26082@ignore 26405@ignore
@@ -26084,7 +26407,7 @@ to @cite{t}.
26084@end ignore 26407@end ignore
26085@tindex apply (rewrites) 26408@tindex apply (rewrites)
26086This matches any function call. The name of the function, in 26409This matches any function call. The name of the function, in
26087the form of a variable, is matched to @cite{f}. The arguments 26410the form of a variable, is matched to @expr{f}. The arguments
26088of the function, as a vector of zero or more objects, are 26411of the function, as a vector of zero or more objects, are
26089matched to @samp{args}. Constants, variables, and vectors 26412matched to @samp{args}. Constants, variables, and vectors
26090do @emph{not} match an @code{apply} pattern. For example, 26413do @emph{not} match an @code{apply} pattern. For example,
@@ -26152,7 +26475,7 @@ protecting rules from evaluation.)
26152 26475
26153@item plain(x) 26476@item plain(x)
26154Special properties of and simplifications for the function call 26477Special properties of and simplifications for the function call
26155@cite{x} are not used. One interesting case where @code{plain} 26478@expr{x} are not used. One interesting case where @code{plain}
26156is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a 26479is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a
26157shorthand notation for the @code{quote} function. This rule will 26480shorthand notation for the @code{quote} function. This rule will
26158not work as shown; instead of replacing @samp{q(foo)} with 26481not work as shown; instead of replacing @samp{q(foo)} with
@@ -26160,7 +26483,7 @@ not work as shown; instead of replacing @samp{q(foo)} with
26160rule would be @samp{q(x) := plain(quote(x))}. 26483rule would be @samp{q(x) := plain(quote(x))}.
26161 26484
26162@item cons(h,t) 26485@item cons(h,t)
26163Where @cite{t} is a vector, this is converted into an expanded 26486Where @expr{t} is a vector, this is converted into an expanded
26164vector during rewrite processing. Note that @code{cons} is a regular 26487vector during rewrite processing. Note that @code{cons} is a regular
26165Calc function which normally does this anyway; the only way @code{cons} 26488Calc function which normally does this anyway; the only way @code{cons}
26166is treated specially by rewrites is that @code{cons} on the righthand 26489is treated specially by rewrites is that @code{cons} on the righthand
@@ -26168,11 +26491,11 @@ side of a rule will be evaluated even if default simplifications
26168have been turned off. 26491have been turned off.
26169 26492
26170@item rcons(t,h) 26493@item rcons(t,h)
26171Analogous to @code{cons} except putting @cite{h} at the @emph{end} of 26494Analogous to @code{cons} except putting @expr{h} at the @emph{end} of
26172the vector @cite{t}. 26495the vector @expr{t}.
26173 26496
26174@item apply(f,args) 26497@item apply(f,args)
26175Where @cite{f} is a variable and @var{args} is a vector, this 26498Where @expr{f} is a variable and @var{args} is a vector, this
26176is converted to a function call. Once again, note that @code{apply} 26499is converted to a function call. Once again, note that @code{apply}
26177is also a regular Calc function. 26500is also a regular Calc function.
26178 26501
@@ -26181,7 +26504,7 @@ is also a regular Calc function.
26181@starindex 26504@starindex
26182@end ignore 26505@end ignore
26183@tindex eval 26506@tindex eval
26184The formula @cite{x} is handled in the usual way, then the 26507The formula @expr{x} is handled in the usual way, then the
26185default simplifications are applied to it even if they have 26508default simplifications are applied to it even if they have
26186been turned off normally. This allows you to treat any function 26509been turned off normally. This allows you to treat any function
26187similarly to the way @code{cons} and @code{apply} are always 26510similarly to the way @code{cons} and @code{apply} are always
@@ -26194,7 +26517,7 @@ whereas @samp{eval(cons(2+3, []))} will be converted to @samp{[5]}.
26194@starindex 26517@starindex
26195@end ignore 26518@end ignore
26196@tindex evalsimp 26519@tindex evalsimp
26197The formula @cite{x} has meta-variables substituted in the usual 26520The formula @expr{x} has meta-variables substituted in the usual
26198way, then algebraically simplified as if by the @kbd{a s} command. 26521way, then algebraically simplified as if by the @kbd{a s} command.
26199 26522
26200@item evalextsimp(x) 26523@item evalextsimp(x)
@@ -26202,7 +26525,7 @@ way, then algebraically simplified as if by the @kbd{a s} command.
26202@starindex 26525@starindex
26203@end ignore 26526@end ignore
26204@tindex evalextsimp 26527@tindex evalextsimp
26205The formula @cite{x} has meta-variables substituted in the normal 26528The formula @expr{x} has meta-variables substituted in the normal
26206way, then ``extendedly'' simplified as if by the @kbd{a e} command. 26529way, then ``extendedly'' simplified as if by the @kbd{a e} command.
26207 26530
26208@item select(x) 26531@item select(x)
@@ -26217,22 +26540,22 @@ There are also some special functions you can use in conditions.
26217@starindex 26540@starindex
26218@end ignore 26541@end ignore
26219@tindex let 26542@tindex let
26220The expression @cite{x} is evaluated with meta-variables substituted. 26543The expression @expr{x} is evaluated with meta-variables substituted.
26221The @kbd{a s} command's simplifications are @emph{not} applied by 26544The @kbd{a s} command's simplifications are @emph{not} applied by
26222default, but @cite{x} can include calls to @code{evalsimp} or 26545default, but @expr{x} can include calls to @code{evalsimp} or
26223@code{evalextsimp} as described above to invoke higher levels 26546@code{evalextsimp} as described above to invoke higher levels
26224of simplification. The 26547of simplification. The
26225result of @cite{x} is then bound to the meta-variable @cite{v}. As 26548result of @expr{x} is then bound to the meta-variable @expr{v}. As
26226usual, if this meta-variable has already been matched to something 26549usual, if this meta-variable has already been matched to something
26227else the two values must be equal; if the meta-variable is new then 26550else the two values must be equal; if the meta-variable is new then
26228it is bound to the result of the expression. This variable can then 26551it is bound to the result of the expression. This variable can then
26229appear in later conditions, and on the righthand side of the rule. 26552appear in later conditions, and on the righthand side of the rule.
26230In fact, @cite{v} may be any pattern in which case the result of 26553In fact, @expr{v} may be any pattern in which case the result of
26231evaluating @cite{x} is matched to that pattern, binding any 26554evaluating @expr{x} is matched to that pattern, binding any
26232meta-variables that appear in that pattern. Note that @code{let} 26555meta-variables that appear in that pattern. Note that @code{let}
26233can only appear by itself as a condition, or as one term of an 26556can only appear by itself as a condition, or as one term of an
26234@samp{&&} which is a whole condition: It cannot be inside 26557@samp{&&} which is a whole condition: It cannot be inside
26235an @samp{||} term or otherwise buried.@refill 26558an @samp{||} term or otherwise buried.
26236 26559
26237The alternate, equivalent form @samp{let(v, x)} is also recognized. 26560The alternate, equivalent form @samp{let(v, x)} is also recognized.
26238Note that the use of @samp{:=} by @code{let}, while still being 26561Note that the use of @samp{:=} by @code{let}, while still being
@@ -26249,7 +26572,7 @@ to express this rule that didn't have to invert the matrix twice.
26249Note that, because the meta-variable @samp{ia} is otherwise unbound 26572Note that, because the meta-variable @samp{ia} is otherwise unbound
26250in this rule, the @code{let} condition itself always ``succeeds'' 26573in this rule, the @code{let} condition itself always ``succeeds''
26251because no matter what @samp{1/a} evaluates to, it can successfully 26574because no matter what @samp{1/a} evaluates to, it can successfully
26252be bound to @code{ia}.@refill 26575be bound to @code{ia}.
26253 26576
26254Here's another example, for integrating cosines of linear 26577Here's another example, for integrating cosines of linear
26255terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}. 26578terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}.
@@ -26260,7 +26583,7 @@ so this @code{let} both verifies that @code{y} is linear, and binds
26260the coefficients @code{a} and @code{b} for use elsewhere in the rule. 26583the coefficients @code{a} and @code{b} for use elsewhere in the rule.
26261(It would have been possible to use @samp{sin(a x + b)/b} for the 26584(It would have been possible to use @samp{sin(a x + b)/b} for the
26262righthand side instead, but using @samp{sin(y)/b} avoids gratuitous 26585righthand side instead, but using @samp{sin(y)/b} avoids gratuitous
26263rearrangement of the argument of the sine.)@refill 26586rearrangement of the argument of the sine.)
26264 26587
26265@ignore 26588@ignore
26266@starindex 26589@starindex
@@ -26321,7 +26644,7 @@ be added to the rule set and will continue to operate even if
26321@starindex 26644@starindex
26322@end ignore 26645@end ignore
26323@tindex remember 26646@tindex remember
26324Remember the match as described above, but only if condition @cite{c} 26647Remember the match as described above, but only if condition @expr{c}
26325is true. For example, @samp{remember(n % 4 = 0)} in the above factorial 26648is true. For example, @samp{remember(n % 4 = 0)} in the above factorial
26326rule remembers only every fourth result. Note that @samp{remember(1)} 26649rule remembers only every fourth result. Note that @samp{remember(1)}
26327is equivalent to @samp{remember}, and @samp{remember(0)} has no effect. 26650is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.
@@ -26883,7 +27206,7 @@ or ran too long'' message.
26883 27206
26884Another subtle difference between @code{EvalRules} and regular rewrites 27207Another subtle difference between @code{EvalRules} and regular rewrites
26885concerns rules that rewrite a formula into an identical formula. For 27208concerns rules that rewrite a formula into an identical formula. For
26886example, @samp{f(n) := f(floor(n))} ``fails to match'' when @cite{n} is 27209example, @samp{f(n) := f(floor(n))} ``fails to match'' when @expr{n} is
26887already an integer. But in @code{EvalRules} this case is detected only 27210already an integer. But in @code{EvalRules} this case is detected only
26888if the righthand side literally becomes the original formula before any 27211if the righthand side literally becomes the original formula before any
26889further simplification. This means that @samp{f(n) := f(floor(n))} will 27212further simplification. This means that @samp{f(n) := f(floor(n))} will
@@ -26927,14 +27250,14 @@ Finally, another limitation is that Calc sometimes calls its built-in
26927functions directly rather than going through the default simplifications. 27250functions directly rather than going through the default simplifications.
26928When it does this, @code{EvalRules} will not be able to override those 27251When it does this, @code{EvalRules} will not be able to override those
26929functions. For example, when you take the absolute value of the complex 27252functions. For example, when you take the absolute value of the complex
26930number @cite{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling 27253number @expr{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling
26931the multiplication, addition, and square root functions directly rather 27254the multiplication, addition, and square root functions directly rather
26932than applying the default simplifications to this formula. So an 27255than applying the default simplifications to this formula. So an
26933@code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6} 27256@code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}
26934would not apply. (However, if you put Calc into symbolic mode so that 27257would not apply. (However, if you put Calc into symbolic mode so that
26935@samp{sqrt(13)} will be left in symbolic form by the built-in square 27258@samp{sqrt(13)} will be left in symbolic form by the built-in square
26936root function, your rule will be able to apply. But if the complex 27259root function, your rule will be able to apply. But if the complex
26937number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated, 27260number were @expr{(3,4)}, so that @samp{sqrt(25)} must be calculated,
26938then symbolic mode will not help because @samp{sqrt(25)} can be 27261then symbolic mode will not help because @samp{sqrt(25)} can be
26939evaluated exactly to 5.) 27262evaluated exactly to 5.)
26940 27263
@@ -27028,7 +27351,7 @@ Returning to the example of substituting the pattern
27028finding suitable cases. Another solution would be to use the rule 27351finding suitable cases. Another solution would be to use the rule
27029@samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification 27352@samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification
27030if necessary. This rule will be the most effective way to do the job, 27353if necessary. This rule will be the most effective way to do the job,
27031but at the expense of making some changes that you might not desire.@refill 27354but at the expense of making some changes that you might not desire.
27032 27355
27033Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}. 27356Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
27034To make this work with the @w{@kbd{j r}} command so that it can be 27357To make this work with the @w{@kbd{j r}} command so that it can be
@@ -27036,10 +27359,10 @@ easily targeted to a particular exponential in a large formula,
27036you might wish to write the rule as @samp{select(exp(x+y)) := 27359you might wish to write the rule as @samp{select(exp(x+y)) :=
27037select(exp(x) exp(y))}. The @samp{select} markers will be 27360select(exp(x) exp(y))}. The @samp{select} markers will be
27038ignored by the regular @kbd{a r} command 27361ignored by the regular @kbd{a r} command
27039(@pxref{Selections with Rewrite Rules}).@refill 27362(@pxref{Selections with Rewrite Rules}).
27040 27363
27041A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}. 27364A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}.
27042This will simplify the formula whenever @cite{b} and/or @cite{c} can 27365This will simplify the formula whenever @expr{b} and/or @expr{c} can
27043be made simpler by squaring. For example, applying this rule to 27366be made simpler by squaring. For example, applying this rule to
27044@samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming 27367@samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming
27045Symbolic Mode has been enabled to keep the square root from being 27368Symbolic Mode has been enabled to keep the square root from being
@@ -27059,17 +27382,19 @@ the keyboard macro @kbd{' tri($) @key{RET}} to make a command that applies
27059@code{tri} to the value on the top of the stack. @xref{Programming}. 27382@code{tri} to the value on the top of the stack. @xref{Programming}.
27060 27383
27061@cindex Quaternions 27384@cindex Quaternions
27062The following rule set, contributed by @c{Fran\c cois} 27385The following rule set, contributed by
27063@asis{Francois} Pinard, implements 27386@texline Fran\c cois
27064@dfn{quaternions}, a generalization of the concept of complex numbers. 27387@infoline Francois
27065Quaternions have four components, and are here represented by function 27388Pinard, implements @dfn{quaternions}, a generalization of the concept of
27066calls @samp{quat(@var{w}, [@var{x}, @var{y}, @var{z}])} with ``real 27389complex numbers. Quaternions have four components, and are here
27067part'' @var{w} and the three ``imaginary'' parts collected into a 27390represented by function calls @samp{quat(@var{w}, [@var{x}, @var{y},
27068vector. Various arithmetical operations on quaternions are supported. 27391@var{z}])} with ``real part'' @var{w} and the three ``imaginary'' parts
27069To use these rules, either add them to @code{EvalRules}, or create a 27392collected into a vector. Various arithmetical operations on quaternions
27070command based on @kbd{a r} for simplifying quaternion formulas. 27393are supported. To use these rules, either add them to @code{EvalRules},
27071A convenient way to enter quaternions would be a command defined by 27394or create a command based on @kbd{a r} for simplifying quaternion
27072a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}. 27395formulas. A convenient way to enter quaternions would be a command
27396defined by a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $])
27397@key{RET}}.
27073 27398
27074@smallexample 27399@smallexample
27075[ quat(w, x, y, z) := quat(w, [x, y, z]), 27400[ quat(w, x, y, z) := quat(w, [x, y, z]),
@@ -27094,8 +27419,8 @@ a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}.
27094@end smallexample 27419@end smallexample
27095 27420
27096Quaternions, like matrices, have non-commutative multiplication. 27421Quaternions, like matrices, have non-commutative multiplication.
27097In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if 27422In other words, @expr{q1 * q2 = q2 * q1} is not necessarily true if
27098@cite{q1} and @cite{q2} are @code{quat} forms. The @samp{quat*quat} 27423@expr{q1} and @expr{q2} are @code{quat} forms. The @samp{quat*quat}
27099rule above uses @code{plain} to prevent Calc from rearranging the 27424rule above uses @code{plain} to prevent Calc from rearranging the
27100product. It may also be wise to add the line @samp{[quat(), matrix]} 27425product. It may also be wise to add the line @samp{[quat(), matrix]}
27101to the @code{Decls} matrix, to ensure that Calc's other algebraic 27426to the @code{Decls} matrix, to ensure that Calc's other algebraic
@@ -27142,13 +27467,13 @@ or a variable whose name is a prefix character like @samp{k} (for ``kilo'')
27142or @samp{u} (for ``micro'') followed by a name in the unit table. 27467or @samp{u} (for ``micro'') followed by a name in the unit table.
27143A substantial table of built-in units is provided with Calc; 27468A substantial table of built-in units is provided with Calc;
27144@pxref{Predefined Units}. You can also define your own unit names; 27469@pxref{Predefined Units}. You can also define your own unit names;
27145@pxref{User-Defined Units}.@refill 27470@pxref{User-Defined Units}.
27146 27471
27147Note that if the value part of a units expression is exactly @samp{1}, 27472Note that if the value part of a units expression is exactly @samp{1},
27148it will be removed by the Calculator's automatic algebra routines: The 27473it will be removed by the Calculator's automatic algebra routines: The
27149formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a 27474formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a
27150display anomaly, however; @samp{mm} will work just fine as a 27475display anomaly, however; @samp{mm} will work just fine as a
27151representation of one millimeter.@refill 27476representation of one millimeter.
27152 27477
27153You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working 27478You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working
27154with units expressions easier. Otherwise, you will have to remember 27479with units expressions easier. Otherwise, you will have to remember
@@ -27169,7 +27494,7 @@ to be compatible with another's. For example, @samp{5 m + 23 mm} will
27169simplify to @samp{5.023 m}. When different but compatible units are 27494simplify to @samp{5.023 m}. When different but compatible units are
27170added, the righthand term's units are converted to match those of the 27495added, the righthand term's units are converted to match those of the
27171lefthand term. @xref{Simplification Modes}, for a way to have this done 27496lefthand term. @xref{Simplification Modes}, for a way to have this done
27172automatically at all times.@refill 27497automatically at all times.
27173 27498
27174Units simplification also handles quotients of two units with the same 27499Units simplification also handles quotients of two units with the same
27175dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional 27500dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional
@@ -27180,7 +27505,7 @@ powers of unit expressions, as in @samp{sqrt(9 mm^2)} to @samp{3 mm} and
27180applied to units expressions, in which case 27505applied to units expressions, in which case
27181the operation in question is applied only to the numeric part of the 27506the operation in question is applied only to the numeric part of the
27182expression. Finally, trigonometric functions of quantities with units 27507expression. Finally, trigonometric functions of quantities with units
27183of angle are evaluated, regardless of the current angular mode.@refill 27508of angle are evaluated, regardless of the current angular mode.
27184 27509
27185@kindex u c 27510@kindex u c
27186@pindex calc-convert-units 27511@pindex calc-convert-units
@@ -27261,7 +27586,7 @@ The @kbd{u t} (@code{calc-convert-temperature}) command converts
27261absolute temperatures. The value on the stack must be a simple units 27586absolute temperatures. The value on the stack must be a simple units
27262expression with units of temperature only. This command would convert 27587expression with units of temperature only. This command would convert
27263@samp{10 degC} to @samp{50 degF}, the equivalent temperature on the 27588@samp{10 degC} to @samp{50 degF}, the equivalent temperature on the
27264Fahrenheit scale.@refill 27589Fahrenheit scale.
27265 27590
27266@kindex u r 27591@kindex u r
27267@pindex calc-remove-units 27592@pindex calc-remove-units
@@ -27272,7 +27597,7 @@ formula at the top of the stack. The @kbd{u x}
27272(@code{calc-extract-units}) command extracts only the units portion of a 27597(@code{calc-extract-units}) command extracts only the units portion of a
27273formula. These commands essentially replace every term of the formula 27598formula. These commands essentially replace every term of the formula
27274that does or doesn't (respectively) look like a unit name by the 27599that does or doesn't (respectively) look like a unit name by the
27275constant 1, then resimplify the formula.@refill 27600constant 1, then resimplify the formula.
27276 27601
27277@kindex u a 27602@kindex u a
27278@pindex calc-autorange-units 27603@pindex calc-autorange-units
@@ -27397,12 +27722,12 @@ also @code{tpt}, which stands for a printer's point as defined by the
27397 27722
27398The unit @code{e} stands for the elementary (electron) unit of charge; 27723The unit @code{e} stands for the elementary (electron) unit of charge;
27399because algebra command could mistake this for the special constant 27724because algebra command could mistake this for the special constant
27400@cite{e}, Calc provides the alternate unit name @code{ech} which is 27725@expr{e}, Calc provides the alternate unit name @code{ech} which is
27401preferable to @code{e}. 27726preferable to @code{e}.
27402 27727
27403The name @code{g} stands for one gram of mass; there is also @code{gf}, 27728The name @code{g} stands for one gram of mass; there is also @code{gf},
27404one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.) 27729one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.)
27405Meanwhile, one ``@cite{g}'' of acceleration is denoted @code{ga}. 27730Meanwhile, one ``@expr{g}'' of acceleration is denoted @code{ga}.
27406 27731
27407The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is 27732The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
27408a metric ton of @samp{1000 kg}. 27733a metric ton of @samp{1000 kg}.
@@ -27634,12 +27959,15 @@ variable. The other arithmetic stores are @kbd{s -}, @kbd{s *}, @kbd{s /},
27634and @kbd{s ]} which decrease or increase a variable by one. 27959and @kbd{s ]} which decrease or increase a variable by one.
27635 27960
27636All the arithmetic stores accept the Inverse prefix to reverse the 27961All the arithmetic stores accept the Inverse prefix to reverse the
27637order of the operands. If @cite{v} represents the contents of the 27962order of the operands. If @expr{v} represents the contents of the
27638variable, and @cite{a} is the value drawn from the stack, then regular 27963variable, and @expr{a} is the value drawn from the stack, then regular
27639@w{@kbd{s -}} assigns @c{$v \coloneq v - a$} 27964@w{@kbd{s -}} assigns
27640@cite{v := v - a}, but @kbd{I s -} assigns 27965@texline @tmath{v \coloneq v - a},
27641@c{$v \coloneq a - v$} 27966@infoline @expr{v := v - a},
27642@cite{v := a - v}. While @kbd{I s *} might seem pointless, it is 27967but @kbd{I s -} assigns
27968@texline @tmath{v \coloneq a - v}.
27969@infoline @expr{v := a - v}.
27970While @kbd{I s *} might seem pointless, it is
27643useful if matrix multiplication is involved. Actually, all the 27971useful if matrix multiplication is involved. Actually, all the
27644arithmetic stores use formulas designed to behave usefully both 27972arithmetic stores use formulas designed to behave usefully both
27645forwards and backwards: 27973forwards and backwards:
@@ -27666,7 +27994,7 @@ minus-two minus the variable.
27666 27994
27667The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -}, 27995The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -},
27668etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous 27996etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous
27669arithmetic stores that don't remove the value @cite{a} from the stack. 27997arithmetic stores that don't remove the value @expr{a} from the stack.
27670 27998
27671All arithmetic stores report the new value of the variable in the 27999All arithmetic stores report the new value of the variable in the
27672Trail for your information. They signal an error if the variable 28000Trail for your information. They signal an error if the variable
@@ -27692,8 +28020,8 @@ takes the hyperbolic arcsine of the variable contents.
27692 28020
27693If the mapping function takes two or more arguments, the additional 28021If the mapping function takes two or more arguments, the additional
27694arguments are taken from the stack; the old value of the variable 28022arguments are taken from the stack; the old value of the variable
27695is provided as the first argument. Thus @kbd{s m -} with @cite{a} 28023is provided as the first argument. Thus @kbd{s m -} with @expr{a}
27696on the stack computes @cite{v - a}, just like @kbd{s -}. With the 28024on the stack computes @expr{v - a}, just like @kbd{s -}. With the
27697Inverse prefix, the variable's original value becomes the @emph{last} 28025Inverse prefix, the variable's original value becomes the @emph{last}
27698argument instead of the first. Thus @kbd{I s m -} is also 28026argument instead of the first. Thus @kbd{I s m -} is also
27699equivalent to @kbd{I s -}. 28027equivalent to @kbd{I s -}.
@@ -27716,7 +28044,7 @@ Until you store something in them, variables are ``void,'' that is, they
27716contain no value at all. If they appear in an algebraic formula they 28044contain no value at all. If they appear in an algebraic formula they
27717will be left alone even if you press @kbd{=} (@code{calc-evaluate}). 28045will be left alone even if you press @kbd{=} (@code{calc-evaluate}).
27718The @kbd{s u} (@code{calc-unstore}) command returns a variable to the 28046The @kbd{s u} (@code{calc-unstore}) command returns a variable to the
27719void state.@refill 28047void state.
27720 28048
27721The only variables with predefined values are the ``special constants'' 28049The only variables with predefined values are the ``special constants''
27722@code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}. You are free 28050@code{pi}, @code{e}, @code{i}, @code{phi}, and @code{gamma}. You are free
@@ -27728,8 +28056,7 @@ special variables @code{inf}, @code{uinf}, and @code{nan} (which are
27728normally void). 28056normally void).
27729 28057
27730Note that @code{var-pi} doesn't actually have 3.14159265359 stored 28058Note that @code{var-pi} doesn't actually have 3.14159265359 stored
27731in it, but rather a special magic value that evaluates to @c{$\pi$} 28059in it, but rather a special magic value that evaluates to @cpi{}
27732@cite{pi}
27733at the current precision. Likewise @code{var-e}, @code{var-i}, and 28060at the current precision. Likewise @code{var-e}, @code{var-i}, and
27734@code{var-phi} evaluate according to the current precision or polar mode. 28061@code{var-phi} evaluate according to the current precision or polar mode.
27735If you recall a value from @code{pi} and store it back, this magic 28062If you recall a value from @code{pi} and store it back, this magic
@@ -27913,7 +28240,7 @@ and @code{PlotRejects};
27913@code{FitRules}, @code{DistribRules}, and other built-in rewrite 28240@code{FitRules}, @code{DistribRules}, and other built-in rewrite
27914rules; and @code{PlotData@var{n}} variables generated 28241rules; and @code{PlotData@var{n}} variables generated
27915by the graphics commands. (You can still save these variables by 28242by the graphics commands. (You can still save these variables by
27916explicitly naming them in an @kbd{s p} command.)@refill 28243explicitly naming them in an @kbd{s p} command.)
27917 28244
27918@kindex s i 28245@kindex s i
27919@pindex calc-insert-variables 28246@pindex calc-insert-variables
@@ -27936,9 +28263,9 @@ stores in a more human-readable format.)
27936@cindex Variables, temporary assignment 28263@cindex Variables, temporary assignment
27937@cindex Temporary assignment to variables 28264@cindex Temporary assignment to variables
27938If you have an expression like @samp{a+b^2} on the stack and you wish to 28265If you have an expression like @samp{a+b^2} on the stack and you wish to
27939compute its value where @cite{b=3}, you can simply store 3 in @cite{b} and 28266compute its value where @expr{b=3}, you can simply store 3 in @expr{b} and
27940then press @kbd{=} to reevaluate the formula. This has the side-effect 28267then press @kbd{=} to reevaluate the formula. This has the side-effect
27941of leaving the stored value of 3 in @cite{b} for future operations. 28268of leaving the stored value of 3 in @expr{b} for future operations.
27942 28269
27943The @kbd{s l} (@code{calc-let}) command evaluates a formula under a 28270The @kbd{s l} (@code{calc-let}) command evaluates a formula under a
27944@emph{temporary} assignment of a variable. It stores the value on the 28271@emph{temporary} assignment of a variable. It stores the value on the
@@ -27961,7 +28288,7 @@ and typing @kbd{s l b @key{RET}}.
27961The @kbd{a b} (@code{calc-substitute}) command is another way to substitute 28288The @kbd{a b} (@code{calc-substitute}) command is another way to substitute
27962a variable with a value in a formula. It does an actual substitution 28289a variable with a value in a formula. It does an actual substitution
27963rather than temporarily assigning the variable and evaluating. For 28290rather than temporarily assigning the variable and evaluating. For
27964example, letting @cite{n=2} in @samp{f(n pi)} with @kbd{a b} will 28291example, letting @expr{n=2} in @samp{f(n pi)} with @kbd{a b} will
27965produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)} 28292produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}
27966since the evaluation step will also evaluate @code{pi}. 28293since the evaluation step will also evaluate @code{pi}.
27967 28294
@@ -28145,8 +28472,8 @@ The ``x'' entry may instead be an interval form, in which case suitable
28145the interval (whether the interval is open or closed is ignored). 28472the interval (whether the interval is open or closed is ignored).
28146 28473
28147The ``x'' entry may also be a number, in which case Calc uses the 28474The ``x'' entry may also be a number, in which case Calc uses the
28148sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc. 28475sequence of ``x'' values @expr{x}, @expr{x+1}, @expr{x+2}, etc.
28149(Generally the number 0 or 1 would be used for @cite{x} in this case.) 28476(Generally the number 0 or 1 would be used for @expr{x} in this case.)
28150 28477
28151The ``y'' entry may be any formula instead of a vector. Calc effectively 28478The ``y'' entry may be any formula instead of a vector. Calc effectively
28152uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula; 28479uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula;
@@ -28169,7 +28496,7 @@ are used as the ``x'' and ``y'' coordinates of the curve, respectively.
28169In this case the ``x'' vector or interval you specified is not directly 28496In this case the ``x'' vector or interval you specified is not directly
28170visible in the graph. For example, if ``x'' is the interval @samp{[0..360]} 28497visible in the graph. For example, if ``x'' is the interval @samp{[0..360]}
28171and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph 28498and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
28172will be a circle.@refill 28499will be a circle.
28173 28500
28174Also, ``x'' and ``y'' may each be variable names, in which case Calc 28501Also, ``x'' and ``y'' may each be variable names, in which case Calc
28175looks for suitable vectors, intervals, or formulas stored in those 28502looks for suitable vectors, intervals, or formulas stored in those
@@ -28224,9 +28551,11 @@ In the first case, ``x'' and ``y'' are each vectors (not necessarily of
28224the same length); either or both may instead be interval forms. The 28551the same length); either or both may instead be interval forms. The
28225``z'' value must be a matrix with the same number of rows as elements 28552``z'' value must be a matrix with the same number of rows as elements
28226in ``x'', and the same number of columns as elements in ``y''. The 28553in ``x'', and the same number of columns as elements in ``y''. The
28227result is a surface plot where @c{$z_{ij}$} 28554result is a surface plot where
28228@cite{z_ij} is the height of the point 28555@texline @tmath{z_{ij}}
28229at coordinate @cite{(x_i, y_j)} on the surface. The 3D graph will 28556@infoline @expr{z_ij}
28557is the height of the point
28558at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will
28230be displayed from a certain default viewpoint; you can change this 28559be displayed from a certain default viewpoint; you can change this
28231viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} 28560viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}
28232buffer as described later. See the GNUPLOT 3.0 documentation for a 28561buffer as described later. See the GNUPLOT 3.0 documentation for a
@@ -28317,26 +28646,28 @@ itself, is what was added by @kbd{g a}.
28317 28646
28318A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way 28647A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way
28319stack entries are interpreted as curves. With a positive prefix 28648stack entries are interpreted as curves. With a positive prefix
28320argument @cite{n}, the top @cite{n} stack entries are ``y'' values 28649argument @expr{n}, the top @expr{n} stack entries are ``y'' values
28321for @cite{n} different curves which share a common ``x'' value in 28650for @expr{n} different curves which share a common ``x'' value in
28322the @cite{n+1}st stack entry. (Thus @kbd{g a} with no prefix 28651the @expr{n+1}st stack entry. (Thus @kbd{g a} with no prefix
28323argument is equivalent to @kbd{C-u 1 g a}.) 28652argument is equivalent to @kbd{C-u 1 g a}.)
28324 28653
28325A prefix of zero or plain @kbd{C-u} means to take two stack entries, 28654A prefix of zero or plain @kbd{C-u} means to take two stack entries,
28326``x'' and ``y'' as usual, but to interpret ``y'' as a vector of 28655``x'' and ``y'' as usual, but to interpret ``y'' as a vector of
28327``y'' values for several curves that share a common ``x''. 28656``y'' values for several curves that share a common ``x''.
28328 28657
28329A negative prefix argument tells Calc to read @cite{n} vectors from 28658A negative prefix argument tells Calc to read @expr{n} vectors from
28330the stack; each vector @cite{[x, y]} describes an independent curve. 28659the stack; each vector @expr{[x, y]} describes an independent curve.
28331This is the only form of @kbd{g a} that creates several curves at once 28660This is the only form of @kbd{g a} that creates several curves at once
28332that don't have common ``x'' values. (Of course, the range of ``x'' 28661that don't have common ``x'' values. (Of course, the range of ``x''
28333values covered by all the curves ought to be roughly the same if 28662values covered by all the curves ought to be roughly the same if
28334they are to look nice on the same graph.) 28663they are to look nice on the same graph.)
28335 28664
28336For example, to plot @c{$\sin n x$} 28665For example, to plot
28337@cite{sin(n x)} for integers @cite{n} 28666@texline @tmath{\sin n x}
28667@infoline @expr{sin(n x)}
28668for integers @expr{n}
28338from 1 to 5, you could use @kbd{v x} to create a vector of integers 28669from 1 to 5, you could use @kbd{v x} to create a vector of integers
28339(@cite{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)} 28670(@expr{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)}
28340across this vector. The resulting vector of formulas is suitable 28671across this vector. The resulting vector of formulas is suitable
28341for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f} 28672for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f}
28342command. 28673command.
@@ -28346,11 +28677,11 @@ command.
28346The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve 28677The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve
28347to the graph. It is not legal to intermix 2D and 3D curves in a 28678to the graph. It is not legal to intermix 2D and 3D curves in a
28348single graph. This command takes three arguments, ``x'', ``y'', 28679single graph. This command takes three arguments, ``x'', ``y'',
28349and ``z'', from the stack. With a positive prefix @cite{n}, it 28680and ``z'', from the stack. With a positive prefix @expr{n}, it
28350takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n} 28681takes @expr{n+2} arguments (common ``x'' and ``y'', plus @expr{n}
28351separate ``z''s). With a zero prefix, it takes three stack entries 28682separate ``z''s). With a zero prefix, it takes three stack entries
28352but the ``z'' entry is a vector of curve values. With a negative 28683but the ``z'' entry is a vector of curve values. With a negative
28353prefix @cite{-n}, it takes @cite{n} vectors of the form @cite{[x, y, z]}. 28684prefix @expr{-n}, it takes @expr{n} vectors of the form @expr{[x, y, z]}.
28354The @kbd{g A} command works by adding a @code{splot} (surface-plot) 28685The @kbd{g A} command works by adding a @code{splot} (surface-plot)
28355command to the @samp{*Gnuplot Commands*} buffer. 28686command to the @samp{*Gnuplot Commands*} buffer.
28356 28687
@@ -28469,13 +28800,13 @@ a blank line, displays the default number of points used for all
28469graphs created by @kbd{g a} that don't specify the resolution explicitly. 28800graphs created by @kbd{g a} that don't specify the resolution explicitly.
28470With a negative prefix argument, this command changes or displays 28801With a negative prefix argument, this command changes or displays
28471the default value (initially 5) used for 3D graphs created by @kbd{g A}. 28802the default value (initially 5) used for 3D graphs created by @kbd{g A}.
28472Note that a 3D setting of 5 means that a total of @cite{5^2 = 25} points 28803Note that a 3D setting of 5 means that a total of @expr{5^2 = 25} points
28473will be computed for the surface. 28804will be computed for the surface.
28474 28805
28475Data values in the graph of a function are normally computed to a 28806Data values in the graph of a function are normally computed to a
28476precision of five digits, regardless of the current precision at the 28807precision of five digits, regardless of the current precision at the
28477time. This is usually more than adequate, but there are cases where 28808time. This is usually more than adequate, but there are cases where
28478it will not be. For example, plotting @cite{1 + x} with @cite{x} in the 28809it will not be. For example, plotting @expr{1 + x} with @expr{x} in the
28479interval @samp{[0 ..@: 1e-6]} will round all the data points down 28810interval @samp{[0 ..@: 1e-6]} will round all the data points down
28480to 1.0! Putting the command @samp{set precision @var{n}} in the 28811to 1.0! Putting the command @samp{set precision @var{n}} in the
28481@samp{*Gnuplot Commands*} buffer will cause the data to be computed 28812@samp{*Gnuplot Commands*} buffer will cause the data to be computed
@@ -28621,8 +28952,10 @@ terminals with no special graphics facilities. It writes a crude
28621picture of the graph composed of characters like @code{-} and @code{|} 28952picture of the graph composed of characters like @code{-} and @code{|}
28622to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. 28953to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.
28623The graph is made the same size as the Emacs screen, which on most 28954The graph is made the same size as the Emacs screen, which on most
28624dumb terminals will be @c{$80\times24$} 28955dumb terminals will be
28625@asis{80x24} characters. The graph is displayed in 28956@texline @tmath{80\times24}
28957@infoline 80x24
28958characters. The graph is displayed in
28626an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit 28959an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit
28627the recursive edit and return to Calc. Note that the @code{dumb} 28960the recursive edit and return to Calc. Note that the @code{dumb}
28628device is present only in GNUPLOT 3.0 and later versions. 28961device is present only in GNUPLOT 3.0 and later versions.
@@ -28824,8 +29157,8 @@ encompass full lines.) The text is copied into the kill ring exactly as
28824it appears on the screen, including line numbers if they are enabled. 29157it appears on the screen, including line numbers if they are enabled.
28825 29158
28826A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number 29159A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number
28827of lines killed. A positive argument kills the current line and @cite{n-1} 29160of lines killed. A positive argument kills the current line and @expr{n-1}
28828lines below it. A negative argument kills the @cite{-n} lines above the 29161lines below it. A negative argument kills the @expr{-n} lines above the
28829current line. Again this mirrors the behavior of the standard Emacs 29162current line. Again this mirrors the behavior of the standard Emacs
28830@kbd{C-k} command. Although a whole line is always deleted, @kbd{C-k} 29163@kbd{C-k} command. Although a whole line is always deleted, @kbd{C-k}
28831with no argument copies only the number itself into the kill ring, whereas 29164with no argument copies only the number itself into the kill ring, whereas
@@ -28868,9 +29201,9 @@ If the @kbd{M-# g} command works successfully, it does an automatic
28868 29201
28869A numeric prefix argument grabs the specified number of lines around 29202A numeric prefix argument grabs the specified number of lines around
28870point, ignoring the mark. A positive prefix grabs from point to the 29203point, ignoring the mark. A positive prefix grabs from point to the
28871@cite{n}th following newline (so that @kbd{M-1 M-# g} grabs from point 29204@expr{n}th following newline (so that @kbd{M-1 M-# g} grabs from point
28872to the end of the current line); a negative prefix grabs from point 29205to the end of the current line); a negative prefix grabs from point
28873back to the @cite{n+1}st preceding newline. In these cases the text 29206back to the @expr{n+1}st preceding newline. In these cases the text
28874that is grabbed is exactly the same as the text that @kbd{C-k} would 29207that is grabbed is exactly the same as the text that @kbd{C-k} would
28875delete given that prefix argument. 29208delete given that prefix argument.
28876 29209
@@ -28926,12 +29259,13 @@ If you give a positive numeric prefix argument @var{n}, then each line
28926will be split up into columns of width @var{n}; each column is parsed 29259will be split up into columns of width @var{n}; each column is parsed
28927separately as a matrix element. If a line contained 29260separately as a matrix element. If a line contained
28928@w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8 29261@w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8
28929would correctly split the line into two error forms.@refill 29262would correctly split the line into two error forms.
28930 29263
28931@xref{Matrix Functions}, to see how to pull the matrix apart into its 29264@xref{Matrix Functions}, to see how to pull the matrix apart into its
28932constituent rows and columns. (If it is a @c{$1\times1$} 29265constituent rows and columns. (If it is a
28933@asis{1x1} matrix, just hit @kbd{v u} 29266@texline @tmath{1\times1}
28934(@code{calc-unpack}) twice.) 29267@infoline 1x1
29268matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.)
28935 29269
28936@kindex M-# : 29270@kindex M-# :
28937@kindex M-# _ 29271@kindex M-# _
@@ -28984,7 +29318,7 @@ normally not included.) The number is @emph{not} removed from the stack.
28984 29318
28985With a prefix argument, @kbd{y} inserts several numbers, one per line. 29319With a prefix argument, @kbd{y} inserts several numbers, one per line.
28986A positive argument inserts the specified number of values from the top 29320A positive argument inserts the specified number of values from the top
28987of the stack. A negative argument inserts the @cite{n}th value from the 29321of the stack. A negative argument inserts the @expr{n}th value from the
28988top of the stack. An argument of zero inserts the entire stack. Note 29322top of the stack. An argument of zero inserts the entire stack. Note
28989that @kbd{y} with an argument of 1 is slightly different from @kbd{y} 29323that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
28990with no argument; the former always copies full lines, whereas the 29324with no argument; the former always copies full lines, whereas the
@@ -28999,7 +29333,7 @@ original data with the new data. One might wish to alter the matrix
28999display style (@pxref{Vector and Matrix Formats}) or change the current 29333display style (@pxref{Vector and Matrix Formats}) or change the current
29000display language (@pxref{Language Modes}) before doing this. Also, note 29334display language (@pxref{Language Modes}) before doing this. Also, note
29001that this command replaces a linear region of text (as grabbed by 29335that this command replaces a linear region of text (as grabbed by
29002@kbd{M-# g}), not a rectangle (as grabbed by @kbd{M-# r}).@refill 29336@kbd{M-# g}), not a rectangle (as grabbed by @kbd{M-# r}).
29003 29337
29004If the editing buffer is in overwrite (as opposed to insert) mode, 29338If the editing buffer is in overwrite (as opposed to insert) mode,
29005and the @kbd{C-u} prefix was not used, then the yanked number will 29339and the @kbd{C-u} prefix was not used, then the yanked number will
@@ -29187,7 +29521,7 @@ is the same as @key{CONJ}.
29187@item INV * 29521@item INV *
29188is the same as @key{y^x}. 29522is the same as @key{y^x}.
29189@item INV / 29523@item INV /
29190is the same as @key{INV y^x} (the @cite{x}th root of @cite{y}). 29524is the same as @key{INV y^x} (the @expr{x}th root of @expr{y}).
29191@item HYP/INV 1 29525@item HYP/INV 1
29192are the same as @key{SIN} / @kbd{INV SIN}. 29526are the same as @key{SIN} / @kbd{INV SIN}.
29193@item HYP/INV 2 29527@item HYP/INV 2
@@ -29253,7 +29587,7 @@ This menu provides various operations from the @kbd{f} and @kbd{k}
29253prefix keys. 29587prefix keys.
29254 29588
29255@key{IMAG} multiplies the number on the stack by the imaginary 29589@key{IMAG} multiplies the number on the stack by the imaginary
29256number @cite{i = (0, 1)}. 29590number @expr{i = (0, 1)}.
29257 29591
29258@key{RE} extracts the real part a complex number. @kbd{INV RE} 29592@key{RE} extracts the real part a complex number. @kbd{INV RE}
29259extracts the imaginary part. 29593extracts the imaginary part.
@@ -29266,8 +29600,9 @@ same limit as last time.
29266 29600
29267@key{INV GCD} computes the LCM (least common multiple) function. 29601@key{INV GCD} computes the LCM (least common multiple) function.
29268 29602
29269@key{INV FACT} is the gamma function. @c{$\Gamma(x) = (x-1)!$} 29603@key{INV FACT} is the gamma function.
29270@cite{gamma(x) = (x-1)!}. 29604@texline @tmath{\Gamma(x) = (x-1)!}.
29605@infoline @expr{gamma(x) = (x-1)!}.
29271 29606
29272@key{PERM} is the number-of-permutations function, which is on the 29607@key{PERM} is the number-of-permutations function, which is on the
29273@kbd{H k c} key in normal Calc. 29608@kbd{H k c} key in normal Calc.
@@ -29382,13 +29717,13 @@ the variables set to the various sets of numbers in those vectors.
29382For example, you could simulate @key{MAP^} using @key{MAP$} with 29717For example, you could simulate @key{MAP^} using @key{MAP$} with
29383the formula @samp{x^y}. 29718the formula @samp{x^y}.
29384 29719
29385The @kbd{"x"} key pushes the variable name @cite{x} onto the 29720The @kbd{"x"} key pushes the variable name @expr{x} onto the
29386stack. To build the formula @cite{x^2 + 6}, you would use the 29721stack. To build the formula @expr{x^2 + 6}, you would use the
29387key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be 29722key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be
29388suitable for use with the @key{MAP$} key described above. 29723suitable for use with the @key{MAP$} key described above.
29389With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the 29724With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the
29390@kbd{"x"} key pushes the variable names @cite{y}, @cite{z}, and 29725@kbd{"x"} key pushes the variable names @expr{y}, @expr{z}, and
29391@cite{t}, respectively. 29726@expr{t}, respectively.
29392 29727
29393@node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode 29728@node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode
29394@section Modes Menu 29729@section Modes Menu
@@ -29553,7 +29888,7 @@ We define $F_n = F_(n-1)+F_(n-2)$ for all $n>2$.
29553@end example 29888@end example
29554 29889
29555@noindent 29890@noindent
29556The formula @cite{n>2} will be pushed onto the Calc stack, and 29891The formula @expr{n>2} will be pushed onto the Calc stack, and
29557the top of stack will be copied back into the editing buffer. 29892the top of stack will be copied back into the editing buffer.
29558This means that spaces will appear around the @samp{>} symbol 29893This means that spaces will appear around the @samp{>} symbol
29559to match Calc's usual display style: 29894to match Calc's usual display style:
@@ -29681,8 +30016,7 @@ in the file as well as the rounded-down number.
29681 30016
29682Embedded buffers remember active formulas for as long as they 30017Embedded buffers remember active formulas for as long as they
29683exist in Emacs memory. Suppose you have an embedded formula 30018exist in Emacs memory. Suppose you have an embedded formula
29684which is @c{$\pi$} 30019which is @cpi{} to the normal 12 decimal places, and then
29685@cite{pi} to the normal 12 decimal places, and then
29686type @w{@kbd{C-u 5 d n}} to display only five decimal places. 30020type @w{@kbd{C-u 5 d n}} to display only five decimal places.
29687If you then type @kbd{d n}, all 12 places reappear because the 30021If you then type @kbd{d n}, all 12 places reappear because the
29688full number is still there on the Calc stack. More surprisingly, 30022full number is still there on the Calc stack. More surprisingly,
@@ -29820,9 +30154,9 @@ foo := 5
29820@end example 30154@end example
29821 30155
29822@noindent 30156@noindent
29823records @cite{5} as the stored value of @code{foo} for the 30157records @expr{5} as the stored value of @code{foo} for the
29824purposes of Embedded mode operations in the current buffer. It 30158purposes of Embedded mode operations in the current buffer. It
29825does @emph{not} actually store @cite{5} as the ``global'' value 30159does @emph{not} actually store @expr{5} as the ``global'' value
29826of @code{foo}, however. Regular Calc operations, and Embedded 30160of @code{foo}, however. Regular Calc operations, and Embedded
29827formulas in other buffers, will not see this assignment. 30161formulas in other buffers, will not see this assignment.
29828 30162
@@ -29891,7 +30225,7 @@ to edit the number using regular Emacs editing rather than Embedded
29891mode. Then, we have to find a way to get Embedded mode to notice 30225mode. Then, we have to find a way to get Embedded mode to notice
29892the change. The @kbd{M-# u} or @kbd{M-# =} 30226the change. The @kbd{M-# u} or @kbd{M-# =}
29893(@code{calc-embedded-update-formula}) command is a convenient way 30227(@code{calc-embedded-update-formula}) command is a convenient way
29894to do this.@refill 30228to do this.
29895 30229
29896@example 30230@example
29897foo := 6 30231foo := 6
@@ -30458,7 +30792,7 @@ performing their usual functions. Press @kbd{C-x )} to end recording.
30458Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to 30792Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to
30459execute your keyboard macro by replaying the recorded keystrokes. 30793execute your keyboard macro by replaying the recorded keystrokes.
30460@xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further 30794@xref{Keyboard Macros, , , emacs, the Emacs Manual}, for further
30461information.@refill 30795information.
30462 30796
30463When you use @kbd{X} to invoke a keyboard macro, the entire macro is 30797When you use @kbd{X} to invoke a keyboard macro, the entire macro is
30464treated as a single command by the undo and trail features. The stack 30798treated as a single command by the undo and trail features. The stack
@@ -30504,7 +30838,7 @@ sequence. The default command name (if you answer the second prompt with
30504just the @key{RET} key as in this example) will be something like 30838just the @key{RET} key as in this example) will be something like
30505@samp{calc-User-n}. The keyboard macro will now be available as both 30839@samp{calc-User-n}. The keyboard macro will now be available as both
30506@kbd{z n} and @kbd{M-x calc-User-n}. You can backspace and enter a more 30840@kbd{z n} and @kbd{M-x calc-User-n}. You can backspace and enter a more
30507descriptive command name if you wish.@refill 30841descriptive command name if you wish.
30508 30842
30509Macros defined by @kbd{Z K} act like single commands; they are executed 30843Macros defined by @kbd{Z K} act like single commands; they are executed
30510in the same way as by the @kbd{X} key. If you wish to define the macro 30844in the same way as by the @kbd{X} key. If you wish to define the macro
@@ -30522,7 +30856,7 @@ command to edit the macro. This command may be found in the
30522the macro definition into full Emacs command names, like @code{calc-pop} 30856the macro definition into full Emacs command names, like @code{calc-pop}
30523and @code{calc-add}. Type @kbd{M-# M-#} to finish editing and update 30857and @code{calc-add}. Type @kbd{M-# M-#} to finish editing and update
30524the definition stored on the key, or, to cancel the edit, type 30858the definition stored on the key, or, to cancel the edit, type
30525@kbd{M-# x}.@refill 30859@kbd{M-# x}.
30526 30860
30527If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard 30861If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard
30528macro is edited in spelled-out keystroke form. For example, the editing 30862macro is edited in spelled-out keystroke form. For example, the editing
@@ -30536,13 +30870,13 @@ copied verbatim into the keyboard macro. Basically, the notation is the
30536same as is used in all of this manual's examples, except that the manual 30870same as is used in all of this manual's examples, except that the manual
30537takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take 30871takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take
30538it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}, 30872it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}},
30539which is what @code{read-kbd-macro} wants to see.@refill 30873which is what @code{read-kbd-macro} wants to see.
30540 30874
30541If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro 30875If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro
30542in ``raw'' form; the editing buffer simply contains characters like 30876in ``raw'' form; the editing buffer simply contains characters like
30543@samp{1^M2+} (here @samp{^M} represents the carriage-return character). 30877@samp{1^M2+} (here @samp{^M} represents the carriage-return character).
30544Editing in this mode, you will have to use @kbd{C-q} to enter new 30878Editing in this mode, you will have to use @kbd{C-q} to enter new
30545control characters into the buffer.@refill 30879control characters into the buffer.
30546 30880
30547@kindex M-# m 30881@kindex M-# m
30548@pindex read-kbd-macro 30882@pindex read-kbd-macro
@@ -30646,7 +30980,7 @@ body is skipped altogether. For example, @kbd{1 @key{TAB} Z < 2 * Z >}
30646computes two to a nonnegative integer power. First, we push 1 on the 30980computes two to a nonnegative integer power. First, we push 1 on the
30647stack and then swap the integer argument back to the top. The @kbd{Z <} 30981stack and then swap the integer argument back to the top. The @kbd{Z <}
30648pops that argument leaving the 1 back on top of the stack. Then, we 30982pops that argument leaving the 1 back on top of the stack. Then, we
30649repeat a multiply-by-two step however many times.@refill 30983repeat a multiply-by-two step however many times.
30650 30984
30651Once again, the keyboard macro is executed as it is being entered. 30985Once again, the keyboard macro is executed as it is being entered.
30652In this case it is especially important to set up reasonable initial 30986In this case it is especially important to set up reasonable initial
@@ -30666,7 +31000,7 @@ if that object is true (a non-zero number), control jumps out of the
30666innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues 31000innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues
30667after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no 31001after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no
30668effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;} 31002effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;}
30669in the C language.@refill 31003in the C language.
30670 31004
30671@kindex Z ( 31005@kindex Z (
30672@kindex Z ) 31006@kindex Z )
@@ -30680,7 +31014,7 @@ command pops initial and final values from the stack. It then creates
30680a temporary internal counter and initializes it with the value @var{init}. 31014a temporary internal counter and initializes it with the value @var{init}.
30681The @kbd{Z (} command then repeatedly pushes the counter value onto the 31015The @kbd{Z (} command then repeatedly pushes the counter value onto the
30682stack and executes @var{body} and @var{step}, adding @var{step} to the 31016stack and executes @var{body} and @var{step}, adding @var{step} to the
30683counter each time until the loop finishes.@refill 31017counter each time until the loop finishes.
30684 31018
30685@cindex Summations (by keyboard macros) 31019@cindex Summations (by keyboard macros)
30686By default, the loop finishes when the counter becomes greater than (or 31020By default, the loop finishes when the counter becomes greater than (or
@@ -30880,7 +31214,7 @@ name as the command name but with @samp{calcFunc-} in place of
30880new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}. 31214new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}.
30881Then the new function can be invoked by pushing two numbers on the 31215Then the new function can be invoked by pushing two numbers on the
30882stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic 31216stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic
30883formula @samp{yow(x,y)}.@refill 31217formula @samp{yow(x,y)}.
30884 31218
30885The fourth prompt is for the function's argument list. This is used to 31219The fourth prompt is for the function's argument list. This is used to
30886associate values on the stack with the variables that appear in the formula. 31220associate values on the stack with the variables that appear in the formula.
@@ -30891,9 +31225,9 @@ two numbers from the stack, substitute these numbers for @samp{a} and
30891@samp{b} (respectively) in the formula, then simplify the formula and 31225@samp{b} (respectively) in the formula, then simplify the formula and
30892push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m} 31226push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m}
30893would replace the 10 and 100 on the stack with the number 210, which is 31227would replace the 10 and 100 on the stack with the number 210, which is
30894@cite{a + 2 b} with @cite{a=10} and @cite{b=100}. Likewise, the formula 31228@expr{a + 2 b} with @expr{a=10} and @expr{b=100}. Likewise, the formula
30895@samp{yow(10, 100)} will be evaluated by substituting @cite{a=10} and 31229@samp{yow(10, 100)} will be evaluated by substituting @expr{a=10} and
30896@cite{b=100} in the definition. 31230@expr{b=100} in the definition.
30897 31231
30898You can rearrange the order of the names before pressing @key{RET} to 31232You can rearrange the order of the names before pressing @key{RET} to
30899control which stack positions go to which variables in the formula. If 31233control which stack positions go to which variables in the formula. If
@@ -30911,12 +31245,12 @@ using the argument list @samp{(a b)}.
30911The final prompt is a y-or-n question concerning what to do if symbolic 31245The final prompt is a y-or-n question concerning what to do if symbolic
30912arguments are given to your function. If you answer @kbd{y}, then 31246arguments are given to your function. If you answer @kbd{y}, then
30913executing @kbd{z m} (using the original argument list @samp{(a b)}) with 31247executing @kbd{z m} (using the original argument list @samp{(a b)}) with
30914arguments @cite{10} and @cite{x} will leave the function in symbolic 31248arguments @expr{10} and @expr{x} will leave the function in symbolic
30915form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n}, 31249form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n},
30916then the formula will always be expanded, even for non-constant 31250then the formula will always be expanded, even for non-constant
30917arguments: @samp{10 + 2 x}. If you never plan to feed algebraic 31251arguments: @samp{10 + 2 x}. If you never plan to feed algebraic
30918formulas to your new function, it doesn't matter how you answer this 31252formulas to your new function, it doesn't matter how you answer this
30919question.@refill 31253question.
30920 31254
30921If you answered @kbd{y} to this question you can still cause a function 31255If you answered @kbd{y} to this question you can still cause a function
30922call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}). 31256call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}).
@@ -30931,7 +31265,7 @@ key, and this command pushes the formula that was used to define that
30931key onto the stack. Actually, it pushes a nameless function that 31265key onto the stack. Actually, it pushes a nameless function that
30932specifies both the argument list and the defining formula. You will get 31266specifies both the argument list and the defining formula. You will get
30933an error message if the key is undefined, or if the key was not defined 31267an error message if the key is undefined, or if the key was not defined
30934by a @kbd{Z F} command.@refill 31268by a @kbd{Z F} command.
30935 31269
30936The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has 31270The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has
30937been defined by a formula uses a variant of the @code{calc-edit} command 31271been defined by a formula uses a variant of the @code{calc-edit} command
@@ -30951,7 +31285,7 @@ You may find it useful to turn off the default simplifications with
30951used as a function definition. For example, the formula @samp{deriv(a^2,v)} 31285used as a function definition. For example, the formula @samp{deriv(a^2,v)}
30952which might be used to define a new function @samp{dsqr(a,v)} will be 31286which might be used to define a new function @samp{dsqr(a,v)} will be
30953``simplified'' to 0 immediately upon entry since @code{deriv} considers 31287``simplified'' to 0 immediately upon entry since @code{deriv} considers
30954@cite{a} to be constant with respect to @cite{v}. Turning off 31288@expr{a} to be constant with respect to @expr{v}. Turning off
30955default simplifications cures this problem: The definition will be stored 31289default simplifications cures this problem: The definition will be stored
30956in symbolic form without ever activating the @code{deriv} function. Press 31290in symbolic form without ever activating the @code{deriv} function. Press
30957@kbd{m D} to turn the default simplifications back on afterwards. 31291@kbd{m D} to turn the default simplifications back on afterwards.
@@ -31049,7 +31383,7 @@ The following standard Lisp functions are treated by @code{defmath}:
31049@code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=}, 31383@code{expt}, @code{=}, @code{<}, @code{>}, @code{<=}, @code{>=},
31050@code{/=}, @code{1+}, @code{1-}, @code{logand}, @code{logior}, @code{logxor}, 31384@code{/=}, @code{1+}, @code{1-}, @code{logand}, @code{logior}, @code{logxor},
31051@code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for 31385@code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for
31052@code{math-nearly-equal}, which is useful in implementing Taylor series.@refill 31386@code{math-nearly-equal}, which is useful in implementing Taylor series.
31053 31387
31054For other functions @var{func}, if a function by the name 31388For other functions @var{func}, if a function by the name
31055@samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the 31389@samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the
@@ -31057,13 +31391,13 @@ name @samp{math-@var{func}} exists it is used, otherwise if @var{func} itself
31057is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is 31391is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is
31058used on the assumption that this is a to-be-defined math function. Also, if 31392used on the assumption that this is a to-be-defined math function. Also, if
31059the function name is quoted as in @samp{('integerp a)} the function name is 31393the function name is quoted as in @samp{('integerp a)} the function name is
31060always used exactly as written (but not quoted).@refill 31394always used exactly as written (but not quoted).
31061 31395
31062Variable names have @samp{var-} prepended to them unless they appear in 31396Variable names have @samp{var-} prepended to them unless they appear in
31063the function's argument list or in an enclosing @code{let}, @code{let*}, 31397the function's argument list or in an enclosing @code{let}, @code{let*},
31064@code{for}, or @code{foreach} form, 31398@code{for}, or @code{foreach} form,
31065or their names already contain a @samp{-} character. Thus a reference to 31399or their names already contain a @samp{-} character. Thus a reference to
31066@samp{foo} is the same as a reference to @samp{var-foo}.@refill 31400@samp{foo} is the same as a reference to @samp{var-foo}.
31067 31401
31068A few other Lisp extensions are available in @code{defmath} definitions: 31402A few other Lisp extensions are available in @code{defmath} definitions:
31069 31403
@@ -31081,18 +31415,18 @@ Lisp @code{setf} function. (The name @code{setf} is recognized as
31081a synonym of @code{setq}.) Specifically, the first argument of 31415a synonym of @code{setq}.) Specifically, the first argument of
31082@code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form, 31416@code{setq} can be an @code{nth}, @code{elt}, @code{car}, or @code{cdr} form,
31083in which case the effect is to store into the specified 31417in which case the effect is to store into the specified
31084element of a list. Thus, @samp{(setq (elt m i j) x)} stores @cite{x} 31418element of a list. Thus, @samp{(setq (elt m i j) x)} stores @expr{x}
31085into one element of a matrix. 31419into one element of a matrix.
31086 31420
31087@item 31421@item
31088A @code{for} looping construct is available. For example, 31422A @code{for} looping construct is available. For example,
31089@samp{(for ((i 0 10)) body)} executes @code{body} once for each 31423@samp{(for ((i 0 10)) body)} executes @code{body} once for each
31090binding of @cite{i} from zero to 10. This is like a @code{let} 31424binding of @expr{i} from zero to 10. This is like a @code{let}
31091form in that @cite{i} is temporarily bound to the loop count 31425form in that @expr{i} is temporarily bound to the loop count
31092without disturbing its value outside the @code{for} construct. 31426without disturbing its value outside the @code{for} construct.
31093Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)}, 31427Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)},
31094are also available. For each value of @cite{i} from zero to 10, 31428are also available. For each value of @expr{i} from zero to 10,
31095@cite{j} counts from 0 to @cite{i-1} in steps of two. Note that 31429@expr{j} counts from 0 to @expr{i-1} in steps of two. Note that
31096@code{for} has the same general outline as @code{let*}, except 31430@code{for} has the same general outline as @code{let*}, except
31097that each element of the header is a list of three or four 31431that each element of the header is a list of three or four
31098things, not just two. 31432things, not just two.
@@ -31100,8 +31434,8 @@ things, not just two.
31100@item 31434@item
31101The @code{foreach} construct loops over elements of a list. 31435The @code{foreach} construct loops over elements of a list.
31102For example, @samp{(foreach ((x (cdr v))) body)} executes 31436For example, @samp{(foreach ((x (cdr v))) body)} executes
31103@code{body} with @cite{x} bound to each element of Calc vector 31437@code{body} with @expr{x} bound to each element of Calc vector
31104@cite{v} in turn. The purpose of @code{cdr} here is to skip over 31438@expr{v} in turn. The purpose of @code{cdr} here is to skip over
31105the initial @code{vec} symbol in the vector. 31439the initial @code{vec} symbol in the vector.
31106 31440
31107@item 31441@item
@@ -31112,7 +31446,7 @@ loop. (Lisp loops otherwise always return @code{nil}.)
31112 31446
31113@item 31447@item
31114The @code{return} function prematurely returns from the enclosing 31448The @code{return} function prematurely returns from the enclosing
31115function. For example, @samp{(return (+ x y))} returns @cite{x+y} 31449function. For example, @samp{(return (+ x y))} returns @expr{x+y}
31116as the value of a function. You can use @code{return} anywhere 31450as the value of a function. You can use @code{return} anywhere
31117inside the body of the function. 31451inside the body of the function.
31118@end itemize 31452@end itemize
@@ -31464,7 +31798,7 @@ Emacs-style code string as well which comes just before @var{num} and
31464 31798
31465In this example, the command @code{calc-foo} will evaluate the expression 31799In this example, the command @code{calc-foo} will evaluate the expression
31466@samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if 31800@samp{foo(a,b)} if executed with no argument, or @samp{foo(a,b,n)} if
31467executed with a numeric prefix argument of @cite{n}. 31801executed with a numeric prefix argument of @expr{n}.
31468 31802
31469The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"} 31803The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}
31470code as used with @code{defun}). It uses the numeric prefix argument as the 31804code as used with @code{defun}). It uses the numeric prefix argument as the
@@ -31501,7 +31835,7 @@ The following qualifiers are recognized:
31501The argument must not be an incomplete vector, interval, or complex number. 31835The argument must not be an incomplete vector, interval, or complex number.
31502(This is rarely needed since the Calculator itself will never call your 31836(This is rarely needed since the Calculator itself will never call your
31503function with an incomplete argument. But there is nothing stopping your 31837function with an incomplete argument. But there is nothing stopping your
31504own Lisp code from calling your function with an incomplete argument.)@refill 31838own Lisp code from calling your function with an incomplete argument.)
31505 31839
31506@item integer 31840@item integer
31507@findex integer 31841@findex integer
@@ -31665,8 +31999,9 @@ same thing with a single division by 512.
31665@end ignore 31999@end ignore
31666@tindex mysin 32000@tindex mysin
31667A somewhat limited sine function could be defined as follows, using the 32001A somewhat limited sine function could be defined as follows, using the
31668well-known Taylor series expansion for @c{$\sin x$} 32002well-known Taylor series expansion for
31669@samp{sin(x)}: 32003@texline @tmath{\sin x}:
32004@infoline @samp{sin(x)}:
31670 32005
31671@smallexample 32006@smallexample
31672(defmath mysin ((float (anglep x))) 32007(defmath mysin ((float (anglep x)))
@@ -31688,8 +32023,7 @@ well-known Taylor series expansion for @c{$\sin x$}
31688@end smallexample 32023@end smallexample
31689 32024
31690The actual @code{sin} function in Calc works by first reducing the problem 32025The actual @code{sin} function in Calc works by first reducing the problem
31691to a sine or cosine of a nonnegative number less than @c{$\pi \over 4$} 32026to a sine or cosine of a nonnegative number less than @cpiover{4}. This
31692@cite{pi/4}. This
31693ensures that the Taylor series will converge quickly. Also, the calculation 32027ensures that the Taylor series will converge quickly. Also, the calculation
31694is carried out with two extra digits of precision to guard against cumulative 32028is carried out with two extra digits of precision to guard against cumulative
31695round-off in @samp{sum}. Finally, complex arguments are allowed and handled 32029round-off in @samp{sum}. Finally, complex arguments are allowed and handled
@@ -31724,10 +32058,9 @@ numbers, @code{mysin-series} is the routine to compute the sine Taylor
31724series as before, and @code{mycos-raw} is a function analogous to 32058series as before, and @code{mycos-raw} is a function analogous to
31725@code{mysin-raw} for cosines. 32059@code{mysin-raw} for cosines.
31726 32060
31727The strategy is to ensure that @cite{x} is nonnegative before calling 32061The strategy is to ensure that @expr{x} is nonnegative before calling
31728@code{mysin-raw}. This function then recursively reduces its argument 32062@code{mysin-raw}. This function then recursively reduces its argument
31729to a suitable range, namely, plus-or-minus @c{$\pi \over 4$} 32063to a suitable range, namely, plus-or-minus @cpiover{4}. Note that each
31730@cite{pi/4}. Note that each
31731test, and particularly the first comparison against 7, is designed so 32064test, and particularly the first comparison against 7, is designed so
31732that small roundoff errors cannot produce an infinite loop. (Suppose 32065that small roundoff errors cannot produce an infinite loop. (Suppose
31733we compared with @samp{(two-pi)} instead; if due to roundoff problems 32066we compared with @samp{(two-pi)} instead; if due to roundoff problems
@@ -31877,8 +32210,8 @@ consider what happens with @samp{(calc-eval "sqrt(2)" 'num)}
31877when the user has left Calc in symbolic mode or no-simplify mode. 32210when the user has left Calc in symbolic mode or no-simplify mode.
31878 32211
31879As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")} 32212As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")}
31880checks if the number in string @cite{a} is less than the one in 32213checks if the number in string @expr{a} is less than the one in
31881string @cite{b}. Without using a list, the integer 1 might 32214string @expr{b}. Without using a list, the integer 1 might
31882come out in a variety of formats which would be hard to test for 32215come out in a variety of formats which would be hard to test for
31883conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But 32216conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But
31884see ``Predicates'' mode, below.) 32217see ``Predicates'' mode, below.)
@@ -32218,13 +32551,13 @@ the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number
32218are that the number 0.0 is always stored as @samp{(float 0 0)}, and, 32551are that the number 0.0 is always stored as @samp{(float 0 0)}, and,
32219except for the 0.0 case, the rightmost base-10 digit of @var{mant} is 32552except for the 0.0 case, the rightmost base-10 digit of @var{mant} is
32220always nonzero. (If the rightmost digit is zero, the number is 32553always nonzero. (If the rightmost digit is zero, the number is
32221rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)@refill 32554rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)
32222 32555
32223Rectangular complex numbers are stored in the form @samp{(cplx @var{re} 32556Rectangular complex numbers are stored in the form @samp{(cplx @var{re}
32224@var{im})}, where @var{re} and @var{im} are each real numbers, either 32557@var{im})}, where @var{re} and @var{im} are each real numbers, either
32225integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}. 32558integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}.
32226The @var{im} part is nonzero; complex numbers with zero imaginary 32559The @var{im} part is nonzero; complex numbers with zero imaginary
32227components are converted to real numbers automatically.@refill 32560components are converted to real numbers automatically.
32228 32561
32229Polar complex numbers are stored in the form @samp{(polar @var{r} 32562Polar complex numbers are stored in the form @samp{(polar @var{r}
32230@var{theta})}, where @var{r} is a positive real value and @var{theta} 32563@var{theta})}, where @var{r} is a positive real value and @var{theta}
@@ -32233,13 +32566,13 @@ usually normalized to lie in the interval @samp{(-180 ..@: 180)} degrees,
32233or @samp{(-pi ..@: pi)} radians, according to the current angular mode. 32566or @samp{(-pi ..@: pi)} radians, according to the current angular mode.
32234If the angle is 0 the value is converted to a real number automatically. 32567If the angle is 0 the value is converted to a real number automatically.
32235(If the angle is 180 degrees, the value is usually also converted to a 32568(If the angle is 180 degrees, the value is usually also converted to a
32236negative real number.)@refill 32569negative real number.)
32237 32570
32238Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m} 32571Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m}
32239@var{s})}, where @var{h} is an integer or an integer-valued float (i.e., 32572@var{s})}, where @var{h} is an integer or an integer-valued float (i.e.,
32240a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued 32573a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued
32241float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number 32574float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number
32242in the range @samp{[0 ..@: 60)}.@refill 32575in the range @samp{[0 ..@: 60)}.
32243 32576
32244Date forms are stored as @samp{(date @var{n})}, where @var{n} is 32577Date forms are stored as @samp{(date @var{n})}, where @var{n} is
32245a real number that counts days since midnight on the morning of 32578a real number that counts days since midnight on the morning of
@@ -32293,7 +32626,7 @@ which is evaluated when the constant's value is requested. Variables
32293which represent units are not stored in any special way; they are units 32626which represent units are not stored in any special way; they are units
32294only because their names appear in the units table. If the value 32627only because their names appear in the units table. If the value
32295cell contains a string, it is parsed to get the variable's value when 32628cell contains a string, it is parsed to get the variable's value when
32296the variable is used.@refill 32629the variable is used.
32297 32630
32298A Lisp list with any other symbol as the first element is a function call. 32631A Lisp list with any other symbol as the first element is a function call.
32299The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^}, 32632The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^},
@@ -32313,7 +32646,7 @@ object which represents their value, or a list of such objects if they
32313wish to return multiple values. (The latter case is allowed only for 32646wish to return multiple values. (The latter case is allowed only for
32314functions which are the outer-level call in an expression whose value is 32647functions which are the outer-level call in an expression whose value is
32315about to be pushed on the stack; this feature is considered obsolete 32648about to be pushed on the stack; this feature is considered obsolete
32316and is not used by any built-in Calc functions.)@refill 32649and is not used by any built-in Calc functions.)
32317 32650
32318@node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats, Internals 32651@node Interactive Lisp Functions, Stack Lisp Functions, Data Type Formats, Internals
32319@subsubsection Interactive Functions 32652@subsubsection Interactive Functions
@@ -32349,7 +32682,7 @@ contains the variable's value) was stored and its previous value was
32349previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})}, 32682previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})},
32350which means that to undo requires calling the function @samp{(@var{undo} 32683which means that to undo requires calling the function @samp{(@var{undo}
32351@var{args} @dots{})} and, if the undo is later redone, calling 32684@var{args} @dots{})} and, if the undo is later redone, calling
32352@samp{(@var{redo} @var{args} @dots{})}.@refill 32685@samp{(@var{redo} @var{args} @dots{})}.
32353@end defun 32686@end defun
32354 32687
32355@defun calc-record-why msg args 32688@defun calc-record-why msg args
@@ -32364,7 +32697,7 @@ some sort. If @var{msg} is a symbol, it is the name of a Calc predicate
32364(such as @code{integerp} or @code{numvecp}) which the arguments did not 32697(such as @code{integerp} or @code{numvecp}) which the arguments did not
32365satisfy; it is expanded to a suitable string such as ``Expected an 32698satisfy; it is expanded to a suitable string such as ``Expected an
32366integer.'' The @code{reject-arg} function calls @code{calc-record-why} 32699integer.'' The @code{reject-arg} function calls @code{calc-record-why}
32367automatically; @pxref{Predicates}.@refill 32700automatically; @pxref{Predicates}.
32368@end defun 32701@end defun
32369 32702
32370@defun calc-is-inverse 32703@defun calc-is-inverse
@@ -32391,7 +32724,7 @@ elements will be inserted into the stack so that the last element will
32391end up at level @var{n}, the next-to-last at level @var{n}+1, etc. 32724end up at level @var{n}, the next-to-last at level @var{n}+1, etc.
32392The elements of @var{vals} are assumed to be valid Calc objects, and 32725The elements of @var{vals} are assumed to be valid Calc objects, and
32393are not evaluated, rounded, or renormalized in any way. If @var{vals} 32726are not evaluated, rounded, or renormalized in any way. If @var{vals}
32394is an empty list, nothing happens.@refill 32727is an empty list, nothing happens.
32395 32728
32396The stack elements are pushed without any sub-formula selections. 32729The stack elements are pushed without any sub-formula selections.
32397You can give an optional third argument to this function, which must 32730You can give an optional third argument to this function, which must
@@ -32410,7 +32743,7 @@ one-element list) is returned. If @var{m} is greater than 1, the
32410element will be next-to-last, etc. If @var{n} or @var{m} are out of 32743element will be next-to-last, etc. If @var{n} or @var{m} are out of
32411range, the command is aborted with a suitable error message. If @var{n} 32744range, the command is aborted with a suitable error message. If @var{n}
32412is zero, the function returns an empty list. The stack elements are not 32745is zero, the function returns an empty list. The stack elements are not
32413evaluated, rounded, or renormalized.@refill 32746evaluated, rounded, or renormalized.
32414 32747
32415If any stack elements contain selections, and selections have not 32748If any stack elements contain selections, and selections have not
32416been disabled by the @kbd{j e} (@code{calc-enable-selections}) command, 32749been disabled by the @kbd{j e} (@code{calc-enable-selections}) command,
@@ -32506,7 +32839,7 @@ This function implements a unary operator that allows a numeric prefix
32506argument to apply the operator over many stack entries. If the prefix 32839argument to apply the operator over many stack entries. If the prefix
32507argument @var{arg} is @code{nil}, this uses @code{calc-enter-result} 32840argument @var{arg} is @code{nil}, this uses @code{calc-enter-result}
32508as outlined above. Otherwise, it maps the function over several stack 32841as outlined above. Otherwise, it maps the function over several stack
32509elements; @pxref{Prefix Arguments}. For example,@refill 32842elements; @pxref{Prefix Arguments}. For example,
32510 32843
32511@smallexample 32844@smallexample
32512(defun calc-zeta (arg) 32845(defun calc-zeta (arg)
@@ -32527,7 +32860,7 @@ specified, nothing happens. When the argument is two or more,
32527the binary function @var{func} is reduced across the top @var{arg} 32860the binary function @var{func} is reduced across the top @var{arg}
32528stack elements; when the argument is negative, the function is 32861stack elements; when the argument is negative, the function is
32529mapped between the next-to-top @i{-@var{arg}} stack elements and the 32862mapped between the next-to-top @i{-@var{arg}} stack elements and the
32530top element.@refill 32863top element.
32531@end defun 32864@end defun
32532 32865
32533@defun calc-stack-size 32866@defun calc-stack-size
@@ -32541,7 +32874,7 @@ Move the point to the @var{n}th stack entry. If @var{n} is zero, this
32541will be the @samp{.} line. If @var{n} is from 1 to the current stack size, 32874will be the @samp{.} line. If @var{n} is from 1 to the current stack size,
32542this will be the beginning of the first line of that stack entry's display. 32875this will be the beginning of the first line of that stack entry's display.
32543If line numbers are enabled, this will move to the first character of the 32876If line numbers are enabled, this will move to the first character of the
32544line number, not the stack entry itself.@refill 32877line number, not the stack entry itself.
32545@end defun 32878@end defun
32546 32879
32547@defun calc-substack-height n 32880@defun calc-substack-height n
@@ -32551,7 +32884,7 @@ will be one (assuming no stack truncation). If all stack entries are
32551one line long (i.e., no matrices are displayed), the return value will 32884one line long (i.e., no matrices are displayed), the return value will
32552be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big 32885be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big
32553mode, the return value includes the blank lines that separate stack 32886mode, the return value includes the blank lines that separate stack
32554entries.)@refill 32887entries.)
32555@end defun 32888@end defun
32556 32889
32557@defun calc-refresh 32890@defun calc-refresh
@@ -32560,7 +32893,7 @@ This must be called after changing any parameter, such as the current
32560display radix, which might change the appearance of existing stack 32893display radix, which might change the appearance of existing stack
32561entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing 32894entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing
32562is suppressed, but a flag is set so that the entire stack will be refreshed 32895is suppressed, but a flag is set so that the entire stack will be refreshed
32563rather than just the top few elements when the macro finishes.)@refill 32896rather than just the top few elements when the macro finishes.)
32564@end defun 32897@end defun
32565 32898
32566@node Predicates, Computational Lisp Functions, Stack Lisp Functions, Internals 32899@node Predicates, Computational Lisp Functions, Stack Lisp Functions, Internals
@@ -32739,7 +33072,7 @@ undefined or cannot be determined. Generally speaking, this works
32739by checking whether @samp{@var{x} - @var{y}} is @code{negp}. In 33072by checking whether @samp{@var{x} - @var{y}} is @code{negp}. In
32740@code{defmath}, the expression @samp{(< x y)} will automatically be 33073@code{defmath}, the expression @samp{(< x y)} will automatically be
32741converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=}, 33074converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=},
32742and @code{>=} are similarly converted in terms of @code{lessp}.@refill 33075and @code{>=} are similarly converted in terms of @code{lessp}.
32743@end defun 33076@end defun
32744 33077
32745@defun beforep x y 33078@defun beforep x y
@@ -32771,7 +33104,7 @@ converted to @samp{(math-equal x y)}.
32771Returns true if @var{x} and @var{n} are numerically equal, where @var{n} 33104Returns true if @var{x} and @var{n} are numerically equal, where @var{n}
32772is a fixnum which is not a multiple of 10. This will automatically be 33105is a fixnum which is not a multiple of 10. This will automatically be
32773used by @code{defmath} in place of the more general @code{math-equal} 33106used by @code{defmath} in place of the more general @code{math-equal}
32774whenever possible.@refill 33107whenever possible.
32775@end defun 33108@end defun
32776 33109
32777@defun nearly-equal x y 33110@defun nearly-equal x y
@@ -32808,7 +33141,7 @@ or a provably non-zero formula.
32808Abort the current function evaluation due to unacceptable argument values. 33141Abort the current function evaluation due to unacceptable argument values.
32809This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a 33142This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a
32810Lisp error which @code{normalize} will trap. The net effect is that the 33143Lisp error which @code{normalize} will trap. The net effect is that the
32811function call which led here will be left in symbolic form.@refill 33144function call which led here will be left in symbolic form.
32812@end defun 33145@end defun
32813 33146
32814@defun inexact-value 33147@defun inexact-value
@@ -32819,7 +33152,7 @@ Note that if your function calls @samp{(sin 5)} in Symbolic Mode, the
32819@code{sin} function will call @code{inexact-value}, which will cause your 33152@code{sin} function will call @code{inexact-value}, which will cause your
32820function to be left unsimplified. You may instead wish to call 33153function to be left unsimplified. You may instead wish to call
32821@samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic Mode will 33154@samp{(normalize (list 'calcFunc-sin 5))}, which in Symbolic Mode will
32822return the formula @samp{sin(5)} to your function.@refill 33155return the formula @samp{sin(5)} to your function.
32823@end defun 33156@end defun
32824 33157
32825@defun overflow 33158@defun overflow
@@ -32840,13 +33173,13 @@ the main body of this manual may be called from Lisp; for example, if
32840the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command, 33173the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command,
32841this means @code{calc-sqrt} is an interactive stack-based square-root 33174this means @code{calc-sqrt} is an interactive stack-based square-root
32842command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt}) 33175command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt})
32843is the actual Lisp function for taking square roots.@refill 33176is the actual Lisp function for taking square roots.
32844 33177
32845The functions @code{math-add}, @code{math-sub}, @code{math-mul}, 33178The functions @code{math-add}, @code{math-sub}, @code{math-mul},
32846@code{math-div}, @code{math-mod}, and @code{math-neg} are not included 33179@code{math-div}, @code{math-mod}, and @code{math-neg} are not included
32847in this list, since @code{defmath} allows you to write native Lisp 33180in this list, since @code{defmath} allows you to write native Lisp
32848@code{+}, @code{-}, @code{*}, @code{/}, @code{%}, and unary @code{-}, 33181@code{+}, @code{-}, @code{*}, @code{/}, @code{%}, and unary @code{-},
32849respectively, instead.@refill 33182respectively, instead.
32850 33183
32851@defun normalize val 33184@defun normalize val
32852(Full form: @code{math-normalize}.) 33185(Full form: @code{math-normalize}.)
@@ -32857,12 +33190,12 @@ if @var{val} is a bignum it will be normalized by clipping off trailing
32857small. All the various data types are similarly converted to their standard 33190small. All the various data types are similarly converted to their standard
32858forms. Variables are left alone, but function calls are actually evaluated 33191forms. Variables are left alone, but function calls are actually evaluated
32859in formulas. For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will 33192in formulas. For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will
32860return 6.@refill 33193return 6.
32861 33194
32862If a function call fails, because the function is void or has the wrong 33195If a function call fails, because the function is void or has the wrong
32863number of parameters, or because it returns @code{nil} or calls 33196number of parameters, or because it returns @code{nil} or calls
32864@code{reject-arg} or @code{inexact-result}, @code{normalize} returns 33197@code{reject-arg} or @code{inexact-result}, @code{normalize} returns
32865the formula still in symbolic form.@refill 33198the formula still in symbolic form.
32866 33199
32867If the current Simplification Mode is ``none'' or ``numeric arguments 33200If the current Simplification Mode is ``none'' or ``numeric arguments
32868only,'' @code{normalize} will act appropriately. However, the more 33201only,'' @code{normalize} will act appropriately. However, the more
@@ -32871,13 +33204,13 @@ not handled by @code{normalize}. They are handled by @code{calc-normalize},
32871which calls @code{normalize} and possibly some other routines, such 33204which calls @code{normalize} and possibly some other routines, such
32872as @code{simplify} or @code{simplify-units}. Programs generally will 33205as @code{simplify} or @code{simplify-units}. Programs generally will
32873never call @code{calc-normalize} except when popping or pushing values 33206never call @code{calc-normalize} except when popping or pushing values
32874on the stack.@refill 33207on the stack.
32875@end defun 33208@end defun
32876 33209
32877@defun evaluate-expr expr 33210@defun evaluate-expr expr
32878Replace all variables in @var{expr} that have values with their values, 33211Replace all variables in @var{expr} that have values with their values,
32879then use @code{normalize} to simplify the result. This is what happens 33212then use @code{normalize} to simplify the result. This is what happens
32880when you press the @kbd{=} key interactively.@refill 33213when you press the @kbd{=} key interactively.
32881@end defun 33214@end defun
32882 33215
32883@defmac with-extra-prec n body 33216@defmac with-extra-prec n body
@@ -32948,7 +33281,7 @@ or formula, this calls @code{reject-arg}.
32948Compare the numbers @var{x} and @var{y}, and return @i{-1} if 33281Compare the numbers @var{x} and @var{y}, and return @i{-1} if
32949@samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})}, 33282@samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})},
329500 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is 332830 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is
32951undefined or cannot be determined.@refill 33284undefined or cannot be determined.
32952@end defun 33285@end defun
32953 33286
32954@defun numdigs n 33287@defun numdigs n
@@ -33000,13 +33333,13 @@ For a more well-defined result, use @samp{(% @var{x} @var{y})}.
33000@defun idivmod x y 33333@defun idivmod x y
33001Divide integer @var{x} by integer @var{y}; return a cons cell whose 33334Divide integer @var{x} by integer @var{y}; return a cons cell whose
33002@code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr} 33335@code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}
33003is @samp{(imod @var{x} @var{y})}.@refill 33336is @samp{(imod @var{x} @var{y})}.
33004@end defun 33337@end defun
33005 33338
33006@defun pow x y 33339@defun pow x y
33007Compute @var{x} to the power @var{y}. In @code{defmath} code, this can 33340Compute @var{x} to the power @var{y}. In @code{defmath} code, this can
33008also be written @samp{(^ @var{x} @var{y})} or 33341also be written @samp{(^ @var{x} @var{y})} or
33009@w{@samp{(expt @var{x} @var{y})}}.@refill 33342@w{@samp{(expt @var{x} @var{y})}}.
33010@end defun 33343@end defun
33011 33344
33012@defun abs-approx x 33345@defun abs-approx x
@@ -33030,7 +33363,7 @@ Other related constant-generating functions are @code{two-pi},
33030@code{pi-over-2}, @code{pi-over-4}, @code{pi-over-180}, @code{sqrt-two-pi}, 33363@code{pi-over-2}, @code{pi-over-4}, @code{pi-over-180}, @code{sqrt-two-pi},
33031@code{e}, @code{sqrt-e}, @code{ln-2}, and @code{ln-10}. Each function 33364@code{e}, @code{sqrt-e}, @code{ln-2}, and @code{ln-10}. Each function
33032returns a floating-point value in the current precision, and each uses 33365returns a floating-point value in the current precision, and each uses
33033caching so that all calls after the first are essentially free.@refill 33366caching so that all calls after the first are essentially free.
33034@end defun 33367@end defun
33035 33368
33036@defmac math-defcache @var{func} @var{initial} @var{form} 33369@defmac math-defcache @var{func} @var{initial} @var{form}
@@ -33045,7 +33378,7 @@ with the current precision increased by four, and the result minus its
33045two least significant digits is stored in the cache. For example, 33378two least significant digits is stored in the cache. For example,
33046calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34 33379calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34
33047digits, rounds it down to 32 digits for future use, then rounds it 33380digits, rounds it down to 32 digits for future use, then rounds it
33048again to 30 digits for use in the present request.@refill 33381again to 30 digits for use in the present request.
33049@end defmac 33382@end defmac
33050 33383
33051@findex half-circle 33384@findex half-circle
@@ -33072,7 +33405,7 @@ return @code{nil}.
33072 33405
33073@defun div-mod a b m 33406@defun div-mod a b m
33074Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if 33407Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if
33075there is no solution, or if any of the arguments are not integers.@refill 33408there is no solution, or if any of the arguments are not integers.
33076@end defun 33409@end defun
33077 33410
33078@defun pow-mod a b m 33411@defun pow-mod a b m
@@ -33147,7 +33480,7 @@ iterations, is @var{p} percent sure that the number is prime. The
33147@var{iters} parameter is the number of Fermat iterations to use, in the 33480@var{iters} parameter is the number of Fermat iterations to use, in the
33148case that this is necessary. If @code{prime-test} returns ``maybe,'' 33481case that this is necessary. If @code{prime-test} returns ``maybe,''
33149you can call it again with the same @var{n} to get a greater certainty; 33482you can call it again with the same @var{n} to get a greater certainty;
33150@code{prime-test} remembers where it left off.@refill 33483@code{prime-test} remembers where it left off.
33151@end defun 33484@end defun
33152 33485
33153@defun to-simple-fraction f 33486@defun to-simple-fraction f
@@ -33198,7 +33531,7 @@ the result is the list @samp{(@var{r} @var{c})}. Higher-order tensors
33198produce lists of more than two dimensions. Note that the object 33531produce lists of more than two dimensions. Note that the object
33199@samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size, 33532@samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,
33200and is treated by this and other Calc routines as a plain vector of two 33533and is treated by this and other Calc routines as a plain vector of two
33201elements.@refill 33534elements.
33202@end defun 33535@end defun
33203 33536
33204@defun dimension-error 33537@defun dimension-error
@@ -33246,7 +33579,7 @@ for each pair of elements @var{ai} and @var{bi}. If either @var{a} or
33246For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v} 33579For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v}
33247with each element increased by one. Note that using @samp{'+} would not 33580with each element increased by one. Note that using @samp{'+} would not
33248work here, since @code{defmath} does not expand function names everywhere, 33581work here, since @code{defmath} does not expand function names everywhere,
33249just where they are in the function position of a Lisp expression.@refill 33582just where they are in the function position of a Lisp expression.
33250@end defun 33583@end defun
33251 33584
33252@defun reduce-vec f v 33585@defun reduce-vec f v
@@ -33296,7 +33629,7 @@ If @var{m} is a matrix, return a copy of @var{m}. This maps
33296element of the result matrix will be @code{eq} to the corresponding 33629element of the result matrix will be @code{eq} to the corresponding
33297element of @var{m}, but none of the @code{cons} cells that make up 33630element of @var{m}, but none of the @code{cons} cells that make up
33298the structure of the matrix will be @code{eq}. If @var{m} is a plain 33631the structure of the matrix will be @code{eq}. If @var{m} is a plain
33299vector, this is the same as @code{copy-sequence}.@refill 33632vector, this is the same as @code{copy-sequence}.
33300@end defun 33633@end defun
33301 33634
33302@defun swap-rows m r1 r2 33635@defun swap-rows m r1 r2
@@ -33305,7 +33638,7 @@ other words, unlike most of the other functions described here, this
33305function changes @var{m} itself rather than building up a new result 33638function changes @var{m} itself rather than building up a new result
33306matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)} 33639matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)}
33307is true, with the side effect of exchanging the first two rows of 33640is true, with the side effect of exchanging the first two rows of
33308@var{m}.@refill 33641@var{m}.
33309@end defun 33642@end defun
33310 33643
33311@node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp Functions, Internals 33644@node Symbolic Lisp Functions, Formatting Lisp Functions, Vector Lisp Functions, Internals
@@ -33443,7 +33776,7 @@ to @samp{x}, which is only valid when @var{x} is positive.) This is
33443implemented by temporarily binding the variable @code{math-living-dangerously} 33776implemented by temporarily binding the variable @code{math-living-dangerously}
33444to @code{t} (using a @code{let} form) and calling @code{simplify}. 33777to @code{t} (using a @code{let} form) and calling @code{simplify}.
33445Dangerous simplification rules are written to check this variable 33778Dangerous simplification rules are written to check this variable
33446before taking any action.@refill 33779before taking any action.
33447@end defun 33780@end defun
33448 33781
33449@defun simplify-units expr 33782@defun simplify-units expr
@@ -33465,7 +33798,7 @@ the functions @var{funcs}. If the function body returns @code{nil}, or
33465if it returns a result @code{equal} to the original @code{expr}, it is 33798if it returns a result @code{equal} to the original @code{expr}, it is
33466ignored and Calc goes on to try the next simplification rule that applies. 33799ignored and Calc goes on to try the next simplification rule that applies.
33467If the function body returns something different, that new formula is 33800If the function body returns something different, that new formula is
33468substituted for @var{expr} in the original formula.@refill 33801substituted for @var{expr} in the original formula.
33469 33802
33470At each point in the formula, rules are tried in the order of the 33803At each point in the formula, rules are tried in the order of the
33471original calls to @code{math-defsimplify}; the search stops after the 33804original calls to @code{math-defsimplify}; the search stops after the
@@ -33498,7 +33831,7 @@ convenient. Here is a typical example of a simplification rule:
33498This is really a pair of rules written with one @code{math-defsimplify} 33831This is really a pair of rules written with one @code{math-defsimplify}
33499for convenience; the first replaces @samp{arcsinh(-x)} with 33832for convenience; the first replaces @samp{arcsinh(-x)} with
33500@samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x}, 33833@samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x},
33501replaces @samp{arcsinh(sinh(x))} with @samp{x}.@refill 33834replaces @samp{arcsinh(sinh(x))} with @samp{x}.
33502@end defmac 33835@end defmac
33503 33836
33504@defun common-constant-factor expr 33837@defun common-constant-factor expr
@@ -33533,7 +33866,7 @@ Compute a ``rational GCD'' of @var{a} and @var{b}, which must both be
33533rational numbers. This is the fraction composed of the GCD of the 33866rational numbers. This is the fraction composed of the GCD of the
33534numerators of @var{a} and @var{b}, over the GCD of the denominators. 33867numerators of @var{a} and @var{b}, over the GCD of the denominators.
33535It is used by @code{common-constant-factor}. Note that the standard 33868It is used by @code{common-constant-factor}. Note that the standard
33536@code{gcd} function uses the LCM to combine the denominators.@refill 33869@code{gcd} function uses the LCM to combine the denominators.
33537@end defun 33870@end defun
33538 33871
33539@defun map-tree func expr many 33872@defun map-tree func expr many
@@ -33548,7 +33881,7 @@ is returned by @code{map-tree}. Note that, unlike simplification rules,
33548@var{func} functions may @emph{not} make destructive changes to 33881@var{func} functions may @emph{not} make destructive changes to
33549@var{expr}. If a third argument @var{many} is provided, it is an 33882@var{expr}. If a third argument @var{many} is provided, it is an
33550integer which says how many times @var{func} may be applied; the 33883integer which says how many times @var{func} may be applied; the
33551default, as described above, is infinitely many times.@refill 33884default, as described above, is infinitely many times.
33552@end defun 33885@end defun
33553 33886
33554@defun compile-rewrites rules 33887@defun compile-rewrites rules
@@ -33665,14 +33998,14 @@ relying on the general integration-by-substitution facility to handle
33665cosines of more complicated arguments. An integration rule should return 33998cosines of more complicated arguments. An integration rule should return
33666@code{nil} if it can't do the integral; if several rules are defined for 33999@code{nil} if it can't do the integral; if several rules are defined for
33667the same function, they are tried in order until one returns a non-@code{nil} 34000the same function, they are tried in order until one returns a non-@code{nil}
33668result.@refill 34001result.
33669@end defmac 34002@end defmac
33670 34003
33671@defmac math-defintegral-2 funcs body 34004@defmac math-defintegral-2 funcs body
33672Define a rule for integrating a function or functions of two arguments. 34005Define a rule for integrating a function or functions of two arguments.
33673This is exactly analogous to @code{math-defintegral}, except that @var{body} 34006This is exactly analogous to @code{math-defintegral}, except that @var{body}
33674is written as the body of a function with two arguments, @var{u} and 34007is written as the body of a function with two arguments, @var{u} and
33675@var{v}.@refill 34008@var{v}.
33676@end defmac 34009@end defmac
33677 34010
33678@defun solve-for lhs rhs var full 34011@defun solve-for lhs rhs var full
@@ -33685,7 +34018,7 @@ different from the user-level @code{solve} and @code{finv} functions,
33685which return a rearranged equation or a functional inverse, respectively. 34018which return a rearranged equation or a functional inverse, respectively.
33686If @var{full} is non-@code{nil}, a full solution including dummy signs 34019If @var{full} is non-@code{nil}, a full solution including dummy signs
33687and dummy integers will be produced. User-defined inverses are provided 34020and dummy integers will be produced. User-defined inverses are provided
33688as properties in a manner similar to derivatives:@refill 34021as properties in a manner similar to derivatives:
33689 34022
33690@smallexample 34023@smallexample
33691(put 'calcFunc-ln 'math-inverse 34024(put 'calcFunc-ln 'math-inverse
@@ -33721,12 +34054,12 @@ This function might seem at first to be identical to
33721@code{expr-contains} uses @code{equal} to test for matches, whereas 34054@code{expr-contains} uses @code{equal} to test for matches, whereas
33722@code{calc-find-sub-formula} uses @code{eq}. In the formula 34055@code{calc-find-sub-formula} uses @code{eq}. In the formula
33723@samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not 34056@samp{f(a, a)}, the two @samp{a}s will be @code{equal} but not
33724@code{eq} to each other.@refill 34057@code{eq} to each other.
33725@end defun 34058@end defun
33726 34059
33727@defun expr-contains-count expr var 34060@defun expr-contains-count expr var
33728Returns the number of occurrences of @var{var} as a subexpression 34061Returns the number of occurrences of @var{var} as a subexpression
33729of @var{expr}, or @code{nil} if there are no occurrences.@refill 34062of @var{expr}, or @code{nil} if there are no occurrences.
33730@end defun 34063@end defun
33731 34064
33732@defun expr-depends expr var 34065@defun expr-depends expr var
@@ -33744,7 +34077,7 @@ contains only constants and functions with constant arguments.
33744Returns a copy of @var{expr}, with all occurrences of @var{old} replaced 34077Returns a copy of @var{expr}, with all occurrences of @var{old} replaced
33745by @var{new}. This treats @code{lambda} forms specially with respect 34078by @var{new}. This treats @code{lambda} forms specially with respect
33746to the dummy argument variables, so that the effect is always to return 34079to the dummy argument variables, so that the effect is always to return
33747@var{expr} evaluated at @var{old} = @var{new}.@refill 34080@var{expr} evaluated at @var{old} = @var{new}.
33748@end defun 34081@end defun
33749 34082
33750@defun multi-subst expr old new 34083@defun multi-subst expr old new
@@ -33763,7 +34096,7 @@ number of objects and function calls that appear in @var{expr}. For
33763@defun expr-height expr 34096@defun expr-height expr
33764Returns the ``height'' of @var{expr}, which is the deepest level to 34097Returns the ``height'' of @var{expr}, which is the deepest level to
33765which function calls are nested. (Note that @samp{@var{a} + @var{b}} 34098which function calls are nested. (Note that @samp{@var{a} + @var{b}}
33766counts as a function call.) For primitive objects, this returns zero.@refill 34099counts as a function call.) For primitive objects, this returns zero.
33767@end defun 34100@end defun
33768 34101
33769@defun polynomial-p expr var 34102@defun polynomial-p expr var
@@ -33775,7 +34108,7 @@ for @samp{(x^2 + 3)^3 + 4} this would return 6. This function returns
33775(@code{calc-expand}), would consist of a sum of terms in which @var{var} 34108(@code{calc-expand}), would consist of a sum of terms in which @var{var}
33776appears only raised to nonnegative integer powers. Note that if 34109appears only raised to nonnegative integer powers. Note that if
33777@var{var} does not occur in @var{expr}, then @var{expr} is considered 34110@var{var} does not occur in @var{expr}, then @var{expr} is considered
33778a polynomial of degree 0.@refill 34111a polynomial of degree 0.
33779@end defun 34112@end defun
33780 34113
33781@defun is-polynomial expr var degree loose 34114@defun is-polynomial expr var degree loose
@@ -33797,7 +34130,7 @@ is used in which coefficients are no longer required not to depend on
33797themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose 34130themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose
33798polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin 34131polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin
33799x))}. The result will never be @code{nil} in loose mode, since any 34132x))}. The result will never be @code{nil} in loose mode, since any
33800expression can be interpreted as a ``constant'' loose polynomial.@refill 34133expression can be interpreted as a ``constant'' loose polynomial.
33801@end defun 34134@end defun
33802 34135
33803@defun polynomial-base expr pred 34136@defun polynomial-base expr pred
@@ -33810,7 +34143,7 @@ the original @var{expr}) is a suitable polynomial in @var{subexpr}.
33810The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})}; 34143The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})};
33811you can use @var{pred} to specify additional conditions. Or, you could 34144you can use @var{pred} to specify additional conditions. Or, you could
33812have @var{pred} build up a list of every suitable @var{subexpr} that 34145have @var{pred} build up a list of every suitable @var{subexpr} that
33813is found.@refill 34146is found.
33814@end defun 34147@end defun
33815 34148
33816@defun poly-simplify poly 34149@defun poly-simplify poly
@@ -33822,7 +34155,7 @@ clipping off trailing zeros.
33822Mix two polynomial lists @var{a} and @var{b} (in the form returned by 34155Mix two polynomial lists @var{a} and @var{b} (in the form returned by
33823@code{is-polynomial}) in a linear combination with coefficient expressions 34156@code{is-polynomial}) in a linear combination with coefficient expressions
33824@var{ac} and @var{bc}. The result is a (not necessarily simplified) 34157@var{ac} and @var{bc}. The result is a (not necessarily simplified)
33825polynomial list representing @samp{@var{ac} @var{a} + @var{bc} @var{b}}.@refill 34158polynomial list representing @samp{@var{ac} @var{a} + @var{bc} @var{b}}.
33826@end defun 34159@end defun
33827 34160
33828@defun poly-mul a b 34161@defun poly-mul a b
@@ -33835,7 +34168,7 @@ Construct a Calc formula which represents the polynomial coefficient
33835list @var{poly} applied to variable @var{var}. The @kbd{a c} 34168list @var{poly} applied to variable @var{var}. The @kbd{a c}
33836(@code{calc-collect}) command uses @code{is-polynomial} to turn an 34169(@code{calc-collect}) command uses @code{is-polynomial} to turn an
33837expression into a coefficient list, then @code{build-polynomial-expr} 34170expression into a coefficient list, then @code{build-polynomial-expr}
33838to turn the list back into an expression in regular form.@refill 34171to turn the list back into an expression in regular form.
33839@end defun 34172@end defun
33840 34173
33841@defun check-unit-name var 34174@defun check-unit-name var
@@ -33852,7 +34185,7 @@ is not a variable or is not a unit name, return @code{nil}.
33852Return true if @var{expr} contains any variables which can be 34185Return true if @var{expr} contains any variables which can be
33853interpreted as units. If @var{sub-exprs} is @code{t}, the entire 34186interpreted as units. If @var{sub-exprs} is @code{t}, the entire
33854expression is searched. If @var{sub-exprs} is @code{nil}, this 34187expression is searched. If @var{sub-exprs} is @code{nil}, this
33855checks whether @var{expr} is directly a units expression.@refill 34188checks whether @var{expr} is directly a units expression.
33856@end defun 34189@end defun
33857 34190
33858@defun single-units-in-expr-p expr 34191@defun single-units-in-expr-p expr
@@ -33867,7 +34200,7 @@ Convert units expression @var{expr} to base units. If @var{which}
33867is @code{nil}, use Calc's native base units. Otherwise, @var{which} 34200is @code{nil}, use Calc's native base units. Otherwise, @var{which}
33868can specify a units system, which is a list of two-element lists, 34201can specify a units system, which is a list of two-element lists,
33869where the first element is a Calc base symbol name and the second 34202where the first element is a Calc base symbol name and the second
33870is an expression to substitute for it.@refill 34203is an expression to substitute for it.
33871@end defun 34204@end defun
33872 34205
33873@defun remove-units expr 34206@defun remove-units expr
@@ -33903,7 +34236,7 @@ Read an algebraic expression from string @var{str}. If @var{str} does
33903not have the form of a valid expression, return a list of the form 34236not have the form of a valid expression, return a list of the form
33904@samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index 34237@samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index
33905into @var{str} of the general location of the error, and @var{msg} is 34238into @var{str} of the general location of the error, and @var{msg} is
33906a string describing the problem.@refill 34239a string describing the problem.
33907@end defun 34240@end defun
33908 34241
33909@defun read-exprs str 34242@defun read-exprs str
@@ -33922,14 +34255,14 @@ given, it is a string which the minibuffer will initially contain.
33922If @var{prompt} is given, it is the prompt string to use; the default 34255If @var{prompt} is given, it is the prompt string to use; the default
33923is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will 34256is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will
33924be returned exactly as parsed; otherwise, they will be passed through 34257be returned exactly as parsed; otherwise, they will be passed through
33925@code{calc-normalize} first.@refill 34258@code{calc-normalize} first.
33926 34259
33927To support the use of @kbd{$} characters in the algebraic entry, use 34260To support the use of @kbd{$} characters in the algebraic entry, use
33928@code{let} to bind @code{calc-dollar-values} to a list of the values 34261@code{let} to bind @code{calc-dollar-values} to a list of the values
33929to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind 34262to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind
33930@code{calc-dollar-used} to 0. Upon return, @code{calc-dollar-used} 34263@code{calc-dollar-used} to 0. Upon return, @code{calc-dollar-used}
33931will have been changed to the highest number of consecutive @kbd{$}s 34264will have been changed to the highest number of consecutive @kbd{$}s
33932that actually appeared in the input.@refill 34265that actually appeared in the input.
33933@end defun 34266@end defun
33934 34267
33935@defun format-number a 34268@defun format-number a
@@ -33945,7 +34278,7 @@ mostly to guarantee the string is of a form that can be re-parsed by
33945complex number format, and point character, are ignored to ensure the 34278complex number format, and point character, are ignored to ensure the
33946result will be re-readable. The @var{prec} parameter is normally 0; if 34279result will be re-readable. The @var{prec} parameter is normally 0; if
33947you pass a large integer like 1000 instead, the expression will be 34280you pass a large integer like 1000 instead, the expression will be
33948surrounded by parentheses unless it is a plain number or variable name.@refill 34281surrounded by parentheses unless it is a plain number or variable name.
33949@end defun 34282@end defun
33950 34283
33951@defun format-nice-expr a width 34284@defun format-nice-expr a width
@@ -33964,7 +34297,7 @@ grouping. Multi-line objects like matrices produce strings that
33964contain newline characters to separate the lines. The @var{w} 34297contain newline characters to separate the lines. The @var{w}
33965parameter, if given, is the target window size for which to format 34298parameter, if given, is the target window size for which to format
33966the expressions. If @var{w} is omitted, the width of the Calculator 34299the expressions. If @var{w} is omitted, the width of the Calculator
33967window is used.@refill 34300window is used.
33968@end defun 34301@end defun
33969 34302
33970@defun compose-expr a prec 34303@defun compose-expr a prec
@@ -34012,7 +34345,7 @@ the baseline. For a one-line composition, this will be zero.
34012@defun comp-first-char c 34345@defun comp-first-char c
34013If composition @var{c} is a ``flat'' composition, return the first 34346If composition @var{c} is a ``flat'' composition, return the first
34014(leftmost) character of the composition as an integer. Otherwise, 34347(leftmost) character of the composition as an integer. Otherwise,
34015return @code{nil}.@refill 34348return @code{nil}.
34016@end defun 34349@end defun
34017 34350
34018@defun comp-last-char c 34351@defun comp-last-char c
@@ -34192,7 +34525,7 @@ you should add a command to set the Lisp variable @code{calc-gnuplot-name}
34192to the appropriate file name. You may also need to change the variables 34525to the appropriate file name. You may also need to change the variables
34193@code{calc-gnuplot-plot-command} and @code{calc-gnuplot-print-command} in 34526@code{calc-gnuplot-plot-command} and @code{calc-gnuplot-print-command} in
34194order to get correct displays and hardcopies, respectively, of your 34527order to get correct displays and hardcopies, respectively, of your
34195plots.@refill 34528plots.
34196 34529
34197@ifinfo 34530@ifinfo
34198@example 34531@example
@@ -34207,7 +34540,7 @@ copy if you really need it. To print the manual, you will need the
34207@TeX{} typesetting program (this is a free program by Donald Knuth 34540@TeX{} typesetting program (this is a free program by Donald Knuth
34208at Stanford University) as well as the @file{texindex} program and 34541at Stanford University) as well as the @file{texindex} program and
34209@file{texinfo.tex} file, both of which can be obtained from the FSF 34542@file{texinfo.tex} file, both of which can be obtained from the FSF
34210as part of the @code{texinfo} package.@refill 34543as part of the @code{texinfo} package.
34211 34544
34212To print the Calc manual in one huge 470 page tome, you will need the 34545To print the Calc manual in one huge 470 page tome, you will need the
34213source code to this manual, @file{calc.texi}, available as part of the 34546source code to this manual, @file{calc.texi}, available as part of the
@@ -34253,7 +34586,7 @@ is @code{"~/.emacs"}. If @code{calc-settings-file} does not contain
34253@code{".emacs"} as a substring, and if the variable 34586@code{".emacs"} as a substring, and if the variable
34254@code{calc-loaded-settings-file} is @code{nil}, then Calc will 34587@code{calc-loaded-settings-file} is @code{nil}, then Calc will
34255automatically load your settings file (if it exists) the first time 34588automatically load your settings file (if it exists) the first time
34256Calc is invoked.@refill 34589Calc is invoked.
34257 34590
34258@ifinfo 34591@ifinfo
34259@example 34592@example
@@ -35194,21 +35527,21 @@ NOTES
35194@enumerate 35527@enumerate
35195@c 1 35528@c 1
35196@item 35529@item
35197Positive prefix arguments apply to @cite{n} stack entries. 35530Positive prefix arguments apply to @expr{n} stack entries.
35198Negative prefix arguments apply to the @cite{-n}th stack entry. 35531Negative prefix arguments apply to the @expr{-n}th stack entry.
35199A prefix of zero applies to the entire stack. (For @key{LFD} and 35532A prefix of zero applies to the entire stack. (For @key{LFD} and
35200@kbd{M-@key{DEL}}, the meaning of the sign is reversed.) 35533@kbd{M-@key{DEL}}, the meaning of the sign is reversed.)
35201 35534
35202@c 2 35535@c 2
35203@item 35536@item
35204Positive prefix arguments apply to @cite{n} stack entries. 35537Positive prefix arguments apply to @expr{n} stack entries.
35205Negative prefix arguments apply to the top stack entry 35538Negative prefix arguments apply to the top stack entry
35206and the next @cite{-n} stack entries. 35539and the next @expr{-n} stack entries.
35207 35540
35208@c 3 35541@c 3
35209@item 35542@item
35210Positive prefix arguments rotate top @cite{n} stack entries by one. 35543Positive prefix arguments rotate top @expr{n} stack entries by one.
35211Negative prefix arguments rotate the entire stack by @cite{-n}. 35544Negative prefix arguments rotate the entire stack by @expr{-n}.
35212A prefix of zero reverses the entire stack. 35545A prefix of zero reverses the entire stack.
35213 35546
35214@c 4 35547@c 4
@@ -35217,8 +35550,8 @@ Prefix argument specifies a repeat count or distance.
35217 35550
35218@c 5 35551@c 5
35219@item 35552@item
35220Positive prefix arguments specify a precision @cite{p}. 35553Positive prefix arguments specify a precision @expr{p}.
35221Negative prefix arguments reduce the current precision by @cite{-p}. 35554Negative prefix arguments reduce the current precision by @expr{-p}.
35222 35555
35223@c 6 35556@c 6
35224@item 35557@item
@@ -35236,17 +35569,17 @@ A negative prefix operates only on the top level of the input formula.
35236 35569
35237@c 9 35570@c 9
35238@item 35571@item
35239Positive prefix arguments specify a word size of @cite{w} bits, unsigned. 35572Positive prefix arguments specify a word size of @expr{w} bits, unsigned.
35240Negative prefix arguments specify a word size of @cite{w} bits, signed. 35573Negative prefix arguments specify a word size of @expr{w} bits, signed.
35241 35574
35242@c 10 35575@c 10
35243@item 35576@item
35244Prefix arguments specify the shift amount @cite{n}. The @cite{w} argument 35577Prefix arguments specify the shift amount @expr{n}. The @expr{w} argument
35245cannot be specified in the keyboard version of this command. 35578cannot be specified in the keyboard version of this command.
35246 35579
35247@c 11 35580@c 11
35248@item 35581@item
35249From the keyboard, @cite{d} is omitted and defaults to zero. 35582From the keyboard, @expr{d} is omitted and defaults to zero.
35250 35583
35251@c 12 35584@c 12
35252@item 35585@item
@@ -35259,16 +35592,16 @@ Some prefix argument values provide special variations of the mode.
35259 35592
35260@c 14 35593@c 14
35261@item 35594@item
35262A prefix argument, if any, is used for @cite{m} instead of taking 35595A prefix argument, if any, is used for @expr{m} instead of taking
35263@cite{m} from the stack. @cite{M} may take any of these values: 35596@expr{m} from the stack. @expr{M} may take any of these values:
35264@iftex 35597@iftex
35265{@advance@tableindent10pt 35598{@advance@tableindent10pt
35266@end iftex 35599@end iftex
35267@table @asis 35600@table @asis
35268@item Integer 35601@item Integer
35269Random integer in the interval @cite{[0 .. m)}. 35602Random integer in the interval @expr{[0 .. m)}.
35270@item Float 35603@item Float
35271Random floating-point number in the interval @cite{[0 .. m)}. 35604Random floating-point number in the interval @expr{[0 .. m)}.
35272@item 0.0 35605@item 0.0
35273Gaussian with mean 1 and standard deviation 0. 35606Gaussian with mean 1 and standard deviation 0.
35274@item Error form 35607@item Error form
@@ -35308,20 +35641,21 @@ input data set. Each entry may be a single value or a vector of values.
35308 35641
35309@c 20 35642@c 20
35310@item 35643@item
35311With a prefix argument of 1, take a single @c{$@var{n}\times2$} 35644With a prefix argument of 1, take a single
35312@i{@var{N}x2} matrix from the 35645@texline @tmath{@var{n}\times2}
35313stack instead of two separate data vectors. 35646@infoline @i{@var{N}x2}
35647matrix from the stack instead of two separate data vectors.
35314 35648
35315@c 21 35649@c 21
35316@item 35650@item
35317The row or column number @cite{n} may be given as a numeric prefix 35651The row or column number @expr{n} may be given as a numeric prefix
35318argument instead. A plain @kbd{C-u} prefix says to take @cite{n} 35652argument instead. A plain @kbd{C-u} prefix says to take @expr{n}
35319from the top of the stack. If @cite{n} is a vector or interval, 35653from the top of the stack. If @expr{n} is a vector or interval,
35320a subvector/submatrix of the input is created. 35654a subvector/submatrix of the input is created.
35321 35655
35322@c 22 35656@c 22
35323@item 35657@item
35324The @cite{op} prompt can be answered with the key sequence for the 35658The @expr{op} prompt can be answered with the key sequence for the
35325desired function, or with @kbd{x} or @kbd{z} followed by a function name, 35659desired function, or with @kbd{x} or @kbd{z} followed by a function name,
35326or with @kbd{$} to take a formula from the top of the stack, or with 35660or with @kbd{$} to take a formula from the top of the stack, or with
35327@kbd{'} and a typed formula. In the last two cases, the formula may 35661@kbd{'} and a typed formula. In the last two cases, the formula may
@@ -35336,7 +35670,7 @@ stack by @kbd{V M} depends on the number of arguments of the function.
35336One of the mapping direction keys @kbd{_} (horizontal, i.e., map 35670One of the mapping direction keys @kbd{_} (horizontal, i.e., map
35337by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or 35671by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or
35338reduce down), or @kbd{=} (map or reduce by rows) may be used before 35672reduce down), or @kbd{=} (map or reduce by rows) may be used before
35339entering @cite{op}; these modify the function name by adding the letter 35673entering @expr{op}; these modify the function name by adding the letter
35340@code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,'' 35674@code{r} for ``rows,'' @code{c} for ``columns,'' @code{a} for ``across,''
35341or @code{d} for ``down.'' 35675or @code{d} for ``down.''
35342 35676
@@ -35374,7 +35708,7 @@ may be an integer or a vector of integers.
35374@item -11 35708@item -11
35375(@var{2}) Float with integer mantissa. 35709(@var{2}) Float with integer mantissa.
35376@item -12 35710@item -12
35377(@var{2}) Float with mantissa in @cite{[1 .. 10)}. 35711(@var{2}) Float with mantissa in @expr{[1 .. 10)}.
35378@item -13 35712@item -13
35379(@var{1}) Date form (using date numbers). 35713(@var{1}) Date form (using date numbers).
35380@item -14 35714@item -14
@@ -35388,13 +35722,13 @@ may be an integer or a vector of integers.
35388 35722
35389@c 25 35723@c 25
35390@item 35724@item
35391A prefix argument specifies the size @cite{n} of the matrix. With no 35725A prefix argument specifies the size @expr{n} of the matrix. With no
35392prefix argument, @cite{n} is omitted and the size is inferred from 35726prefix argument, @expr{n} is omitted and the size is inferred from
35393the input vector. 35727the input vector.
35394 35728
35395@c 26 35729@c 26
35396@item 35730@item
35397The prefix argument specifies the starting position @cite{n} (default 1). 35731The prefix argument specifies the starting position @expr{n} (default 1).
35398 35732
35399@c 27 35733@c 27
35400@item 35734@item
@@ -35460,16 +35794,16 @@ later prompts by popping additional stack entries.
35460 35794
35461@c 39 35795@c 39
35462@item 35796@item
35463Answer for @cite{v} may also be of the form @cite{v = v_0} or 35797Answer for @expr{v} may also be of the form @expr{v = v_0} or
35464@cite{v - v_0}. 35798@expr{v - v_0}.
35465 35799
35466@c 40 35800@c 40
35467@item 35801@item
35468With a positive prefix argument, stack contains many @cite{y}'s and one 35802With a positive prefix argument, stack contains many @expr{y}'s and one
35469common @cite{x}. With a zero prefix, stack contains a vector of 35803common @expr{x}. With a zero prefix, stack contains a vector of
35470@cite{y}s and a common @cite{x}. With a negative prefix, stack 35804@expr{y}s and a common @expr{x}. With a negative prefix, stack
35471contains many @cite{[x,y]} vectors. (For 3D plots, substitute 35805contains many @expr{[x,y]} vectors. (For 3D plots, substitute
35472@cite{z} for @cite{y} and @cite{x,y} for @cite{x}.) 35806@expr{z} for @expr{y} and @expr{x,y} for @expr{x}.)
35473 35807
35474@c 41 35808@c 41
35475@item 35809@item
@@ -35504,19 +35838,20 @@ in stack level three, and causes the formula to replace the top three
35504stack levels. The notation @kbd{$3} refers to stack level three without 35838stack levels. The notation @kbd{$3} refers to stack level three without
35505causing that value to be removed from the stack. Use @key{LFD} in place 35839causing that value to be removed from the stack. Use @key{LFD} in place
35506of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET} 35840of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET}
35507to evaluate variables.@refill 35841to evaluate variables.
35508 35842
35509@c 47 35843@c 47
35510@item 35844@item
35511The variable is replaced by the formula shown on the right. The 35845The variable is replaced by the formula shown on the right. The
35512Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} 35846Inverse flag reverses the order of the operands, e.g., @kbd{I s - x}
35513assigns @c{$x \coloneq a-x$} 35847assigns
35514@cite{x := a-x}. 35848@texline @tmath{x \coloneq a-x}.
35849@infoline @expr{x := a-x}.
35515 35850
35516@c 48 35851@c 48
35517@item 35852@item
35518Press @kbd{?} repeatedly to see how to choose a model. Answer the 35853Press @kbd{?} repeatedly to see how to choose a model. Answer the
35519variables prompt with @cite{iv} or @cite{iv;pv} to specify 35854variables prompt with @expr{iv} or @expr{iv;pv} to specify
35520independent and parameter variables. A positive prefix argument 35855independent and parameter variables. A positive prefix argument
35521takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix 35856takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix
35522and a vector from the stack. 35857and a vector from the stack.