diff options
| author | Jay Belanger | 2004-12-06 05:01:20 +0000 |
|---|---|---|
| committer | Jay Belanger | 2004-12-06 05:01:20 +0000 |
| commit | a4231b040c816e810514d1fa045daaff3d1229f8 (patch) | |
| tree | 80d375272e71d627fa95e1db7ac46432343b1cb6 /man | |
| parent | cc60c723223998a93a059d669ccfdc7e9aa3e050 (diff) | |
| download | emacs-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.texi | 4441 |
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 |
| 514 | Every Calc keyboard command is listed in the Calc Summary, and also | 541 | Every Calc keyboard command is listed in the Calc Summary, and also |
| 515 | in the Key Index. Algebraic functions, @kbd{M-x} commands, and | 542 | in the Key Index. Algebraic functions, @kbd{M-x} commands, and |
| 516 | variables also have their own indices. @c{Each} | 543 | variables also have their own indices. |
| 517 | @asis{In the printed manual, each} | 544 | @texline Each |
| 545 | @infoline In the printed manual, each | ||
| 518 | paragraph that is referenced in the Key or Function Index is marked | 546 | paragraph that is referenced in the Key or Function Index is marked |
| 519 | in the margin with its index entry. | 547 | in the margin with its index entry. |
| 520 | 548 | ||
| @@ -570,7 +598,7 @@ the corresponding function in an algebraic-style formula would | |||
| 570 | be @samp{cos(@var{x})}. | 598 | be @samp{cos(@var{x})}. |
| 571 | 599 | ||
| 572 | A few commands don't have key equivalents: @code{calc-sincos} | 600 | A 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. | |||
| 595 | then the command to operate on the numbers. | 623 | then the command to operate on the numbers. |
| 596 | 624 | ||
| 597 | @noindent | 625 | @noindent |
| 598 | Type @kbd{2 @key{RET} 3 + Q} to compute @c{$\sqrt{2+3} = 2.2360679775$} | 626 | Type @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 |
| 602 | Type @kbd{P 2 ^} to compute @c{$\pi^2 = 9.86960440109$} | 631 | Type @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 |
| 606 | Type @key{TAB} to exchange the order of these two results. | 636 | Type @key{TAB} to exchange the order of these two results. |
| @@ -617,13 +647,15 @@ conventional ``algebraic'' notation. To enter an algebraic formula, | |||
| 617 | use the apostrophe key. | 647 | use the apostrophe key. |
| 618 | 648 | ||
| 619 | @noindent | 649 | @noindent |
| 620 | Type @kbd{' sqrt(2+3) @key{RET}} to compute @c{$\sqrt{2+3}$} | 650 | Type @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 |
| 624 | Type @kbd{' pi^2 @key{RET}} to enter @c{$\pi^2$} | 655 | Type @kbd{' pi^2 @key{RET}} to enter |
| 625 | @asis{`pi' squared}. To evaluate this symbolic | 656 | @texline @tmath{\pi^2}. |
| 626 | formula as a number, type @kbd{=}. | 657 | @infoline `pi' squared. |
| 658 | To evaluate this symbolic formula as a number, type @kbd{=}. | ||
| 627 | 659 | ||
| 628 | @noindent | 660 | @noindent |
| 629 | Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent | 661 | Type @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 | |||
| 680 | the lower-right @samp{8} and press @kbd{M-# r}. | 712 | the lower-right @samp{8} and press @kbd{M-# r}. |
| 681 | 713 | ||
| 682 | @noindent | 714 | @noindent |
| 683 | Type @kbd{v t} to transpose this @c{$3\times2$} | 715 | Type @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 | 718 | matrix 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 |
| 721 | matrix. Type @w{@kbd{v u}} to unpack the rows into two separate | ||
| 722 | vectors. Now type @w{@kbd{V R + @key{TAB} V R +}} to compute the sums | ||
| 723 | of the two original columns. (There is also a special | ||
| 724 | grab-and-sum-columns command, @kbd{M-# :}.) | ||
| 689 | 725 | ||
| 690 | @strong{Units conversion.} Units are entered algebraically. | 726 | @strong{Units conversion.} Units are entered algebraically. |
| 691 | Type @w{@kbd{' 43 mi/hr @key{RET}}} to enter the quantity 43 miles-per-hour. | 727 | Type @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 | |||
| 701 | to enter a pair of equations involving three variables. | 737 | to 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 |
| 703 | between @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve | 739 | between @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve |
| 704 | these equations for the variables @cite{x} and @cite{y}.@refill | 740 | these equations for the variables @expr{x} and @expr{y}. |
| 705 | 741 | ||
| 706 | @noindent | 742 | @noindent |
| 707 | Type @kbd{d B} to view the solutions in more readable notation. | 743 | Type @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. | |||
| 710 | Type @kbd{d N} to return to normal notation. | 746 | Type @kbd{d N} to return to normal notation. |
| 711 | 747 | ||
| 712 | @noindent | 748 | @noindent |
| 713 | Type @kbd{7.5}, then @kbd{s l a @key{RET}} to let @cite{a = 7.5} in these formulas. | 749 | Type @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 |
| 770 | don't even have an @key{ESC} key, you can fake it by holding down | 806 | don't even have an @key{ESC} key, you can fake it by holding down |
| 771 | Control or @key{CTRL} while typing a left square bracket | 807 | Control 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 |
| 775 | you to press a second key to complete the command. In this case, | 811 | you 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. | |||
| 853 | Shifted (i.e., upper-case) letters are different from lowercase | 889 | Shifted (i.e., upper-case) letters are different from lowercase |
| 854 | letters. Some letters are @dfn{prefix} keys that begin two-letter | 890 | letters. Some letters are @dfn{prefix} keys that begin two-letter |
| 855 | commands. For example, @kbd{e} means ``enter exponent'' and shifted | 891 | commands. 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 |
| 857 | the letter ``e'' takes on very different meanings: @kbd{d e} means | 893 | the 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 |
| 1318 | Calc was originally started as a two-week project to occupy a lull | 1354 | Calc was originally started as a two-week project to occupy a lull |
| 1319 | in the author's schedule. Basically, a friend asked if I remembered | 1355 | in the author's schedule. Basically, a friend asked if I remembered |
| 1320 | the value of @c{$2^{32}$} | 1356 | the value of |
| 1321 | @cite{2^32}. I didn't offhand, but I said, ``that's | 1357 | @texline @tmath{2^{32}}. |
| 1322 | easy, just call up an @code{xcalc}.'' @code{Xcalc} duly reported | 1358 | @infoline @expr{2^32}. |
| 1323 | that the answer to our question was @samp{4.294967e+09}---with no way to | 1359 | I didn't offhand, but I said, ``that's easy, just call up an |
| 1324 | see 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 |
| 1325 | program's memory! I was so annoyed, I vowed to write a calculator | 1361 | question was @samp{4.294967e+09}---with no way to see the full ten |
| 1326 | of my own, once and for all. | 1362 | digits even though we knew they were there in the program's memory! I |
| 1363 | was so annoyed, I vowed to write a calculator of my own, once and for | ||
| 1364 | all. | ||
| 1327 | 1365 | ||
| 1328 | I chose Emacs Lisp, a) because I had always been curious about it | 1366 | I chose Emacs Lisp, a) because I had always been curious about it |
| 1329 | and b) because, being only a text editor extension language after | 1367 | and b) because, being only a text editor extension language after |
| @@ -1373,18 +1411,19 @@ algebra system for microcomputers. | |||
| 1373 | Many people have contributed to Calc by reporting bugs and suggesting | 1411 | Many people have contributed to Calc by reporting bugs and suggesting |
| 1374 | features, large and small. A few deserve special mention: Tim Peters, | 1412 | features, large and small. A few deserve special mention: Tim Peters, |
| 1375 | who helped develop the ideas that led to the selection commands, rewrite | 1413 | who helped develop the ideas that led to the selection commands, rewrite |
| 1376 | rules, and many other algebra features; @c{Fran\c cois} | 1414 | rules, and many other algebra features; |
| 1377 | @asis{Francois} Pinard, who contributed | 1415 | @texline Fran\c cois |
| 1378 | an early prototype of the Calc Summary appendix as well as providing | 1416 | @infoline Francois |
| 1379 | valuable suggestions in many other areas of Calc; Carl Witty, whose eagle | 1417 | Pinard, who contributed an early prototype of the Calc Summary appendix |
| 1380 | eyes discovered many typographical and factual errors in the Calc manual; | 1418 | as well as providing valuable suggestions in many other areas of Calc; |
| 1381 | Tim Kay, who drove the development of Embedded mode; Ove Ewerlid, who | 1419 | Carl Witty, whose eagle eyes discovered many typographical and factual |
| 1382 | made many suggestions relating to the algebra commands and contributed | 1420 | errors in the Calc manual; Tim Kay, who drove the development of |
| 1383 | some code for polynomial operations; Randal Schwartz, who suggested the | 1421 | Embedded mode; Ove Ewerlid, who made many suggestions relating to the |
| 1384 | @code{calc-eval} function; Robert J. Chassell, who suggested the Calc | 1422 | algebra commands and contributed some code for polynomial operations; |
| 1385 | Tutorial and exercises; and Juha Sarlin, who first worked out how to split | 1423 | Randal Schwartz, who suggested the @code{calc-eval} function; Robert |
| 1386 | Calc into quickly-loading parts. Bob Weiner helped immensely with the | 1424 | J. Chassell, who suggested the Calc Tutorial and exercises; and Juha |
| 1387 | Lucid Emacs port. | 1425 | Sarlin, who first worked out how to split Calc into quickly-loading |
| 1426 | parts. 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 |
| 1548 | In an operation like @cite{2+3}, the 2 and 3 are called the @dfn{operands} | 1587 | In an operation like @expr{2+3}, the 2 and 3 are called the @dfn{operands} |
| 1549 | and the @cite{+} is the @dfn{operator}. In an RPN calculator you always | 1588 | and the @expr{+} is the @dfn{operator}. In an RPN calculator you always |
| 1550 | enter the operands first, then the operator. Each time you type a | 1589 | enter the operands first, then the operator. Each time you type a |
| 1551 | number, Calc adds or @dfn{pushes} it onto the top of the Stack. | 1590 | number, Calc adds or @dfn{pushes} it onto the top of the Stack. |
| 1552 | When you press an operator key like @kbd{+}, Calc @dfn{pops} the appropriate | 1591 | When 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 | |||
| 1560 | The first four keystrokes ``push'' the numbers 2 and 3 onto the stack. | 1599 | The first four keystrokes ``push'' the numbers 2 and 3 onto the stack. |
| 1561 | The @kbd{+} key ``pops'' the top two numbers from the stack, adds them, | 1600 | The @kbd{+} key ``pops'' the top two numbers from the stack, adds them, |
| 1562 | and pushes the result (5) back onto the stack. Here's how the stack | 1601 | and pushes the result (5) back onto the stack. Here's how the stack |
| 1563 | will look at various points throughout the calculation:@refill | 1602 | will 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 |
| 1582 | The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level | 1621 | The numbers @samp{1:} and @samp{2:} on the left are @dfn{stack level |
| 1583 | numbers}. Old RPN calculators always had four stack levels called | 1622 | numbers}. 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 |
| 1585 | as large as you like, so it uses numbers instead of letters. Some | 1624 | as large as you like, so it uses numbers instead of letters. Some |
| 1586 | stack-manipulation commands accept a numeric argument that says | 1625 | stack-manipulation commands accept a numeric argument that says |
| 1587 | which stack level to work on. Normal commands like @kbd{+} always | 1626 | which stack level to work on. Normal commands like @kbd{+} always |
| 1588 | work on the top few levels of the stack.@refill | 1627 | work on the top few levels of the stack. |
| 1589 | 1628 | ||
| 1590 | @c [fix-ref Truncating the Stack] | 1629 | @c [fix-ref Truncating the Stack] |
| 1591 | The Stack buffer is just an Emacs buffer, and you can move around in | 1630 | The 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 |
| 1603 | other non-numeric key when you are entering a number, the Calculator | 1642 | other non-numeric key when you are entering a number, the Calculator |
| 1604 | automatically enters that number and then does the requested command. | 1643 | automatically enters that number and then does the requested command. |
| 1605 | Thus @kbd{2 @key{RET} 3 +} will work just as well.@refill | 1644 | Thus @kbd{2 @key{RET} 3 +} will work just as well. |
| 1606 | 1645 | ||
| 1607 | Examples in this tutorial will often omit @key{RET} even when the | 1646 | Examples in this tutorial will often omit @key{RET} even when the |
| 1608 | stack displays shown would only happen if you did press @key{RET}: | 1647 | stack 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 | |||
| 1636 | multiplication.) Figure it out by hand, then try it with Calc to see | 1675 | multiplication.) Figure it out by hand, then try it with Calc to see |
| 1637 | if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) | 1676 | if 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}} |
| 1641 | stack. @xref{RPN Answer 2, 2}. (@bullet{}) | 1680 | @infoline @expr{2*4 + 7*9.5 + 5/4} |
| 1681 | using the stack. @xref{RPN Answer 2, 2}. (@bullet{}) | ||
| 1642 | 1682 | ||
| 1643 | The @key{DEL} key is called Backspace on some keyboards. It is | 1683 | The @key{DEL} key is called Backspace on some keyboards. It is |
| 1644 | whatever key you would use to correct a simple typing error when | 1684 | whatever 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. | |||
| 1690 | Another stack manipulation key is @key{TAB}. This exchanges the top | 1730 | Another stack manipulation key is @key{TAB}. This exchanges the top |
| 1691 | two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +} | 1731 | two stack entries. Suppose you have computed @kbd{2 @key{RET} 3 +} |
| 1692 | to get 5, and then you realize what you really wanted to compute | 1732 | to get 5, and then you realize what you really wanted to compute |
| 1693 | was @cite{20 / (2+3)}. | 1733 | was @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 |
| 1801 | The notation @cite{(a, b)} represents a complex number. | 1841 | The notation @expr{(a, b)} represents a complex number. |
| 1802 | Complex numbers are more traditionally written @c{$a + b i$} | 1842 | Complex numbers are more traditionally written @expr{a + b i}; |
| 1803 | @cite{a + b i}; | ||
| 1804 | Calc can display in this format, too, but for now we'll stick to the | 1843 | Calc 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 | ||
| 1807 | If you don't know how complex numbers work, you can safely ignore this | 1846 | If you don't know how complex numbers work, you can safely ignore this |
| 1808 | feature. Complex numbers only arise from operations that would be | 1847 | feature. Complex numbers only arise from operations that would be |
| @@ -1861,7 +1900,7 @@ When you press @kbd{)} all the stack entries between the incomplete | |||
| 1861 | entry and the top are collected, so there's never really a reason | 1900 | entry and the top are collected, so there's never really a reason |
| 1862 | to use the comma. It's up to you. | 1901 | to 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)}, |
| 1865 | your friend Joe typed @kbd{( 2 , @key{SPC} 3 )}. What happened? | 1904 | your 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 |
| 1867 | keystrokes, but it didn't quite work. Try it to find out why.) | 1906 | keystrokes, but it didn't quite work. Try it to find out why.) |
| @@ -1921,7 +1960,7 @@ entire stack.) | |||
| 1921 | If you are not used to RPN notation, you may prefer to operate the | 1960 | If you are not used to RPN notation, you may prefer to operate the |
| 1922 | Calculator in ``algebraic mode,'' which is closer to the way | 1961 | Calculator in ``algebraic mode,'' which is closer to the way |
| 1923 | non-RPN calculators work. In algebraic mode, you enter formulas | 1962 | non-RPN calculators work. In algebraic mode, you enter formulas |
| 1924 | in traditional @cite{2+3} notation. | 1963 | in traditional @expr{2+3} notation. |
| 1925 | 1964 | ||
| 1926 | You don't really need any special ``mode'' to enter algebraic formulas. | 1965 | You don't really need any special ``mode'' to enter algebraic formulas. |
| 1927 | You can enter a formula at any time by pressing the apostrophe (@kbd{'}) | 1966 | You 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 | |||
| 2004 | the notation @samp{sqrt(@var{x})}. | 2043 | the notation @samp{sqrt(@var{x})}. |
| 2005 | 2044 | ||
| 2006 | Press the apostrophe, then type @kbd{sqrt(5*2) - 3}. The result should | 2045 | Press the apostrophe, then type @kbd{sqrt(5*2) - 3}. The result should |
| 2007 | be @cite{0.16227766017}. | 2046 | be @expr{0.16227766017}. |
| 2008 | 2047 | ||
| 2009 | Note that if the formula begins with a function name, you need to use | 2048 | Note that if the formula begins with a function name, you need to use |
| 2010 | the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin} | 2049 | the apostrophe even if you are in algebraic mode. If you type @kbd{arcsin} |
| @@ -2030,7 +2069,7 @@ Still in algebraic mode, type: | |||
| 2030 | 2069 | ||
| 2031 | Algebraic mode allows us to enter complex numbers without pressing | 2070 | Algebraic mode allows us to enter complex numbers without pressing |
| 2032 | an apostrophe first, but it also means we need to press @key{RET} | 2071 | an apostrophe first, but it also means we need to press @key{RET} |
| 2033 | after every entry, even for a simple number like @cite{1}. | 2072 | after 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 |
| 2036 | mode'' in which the @kbd{(} and @kbd{[} keys use algebraic entry even | 2075 | mode'' 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 | |||
| 2050 | accomplish this in Calc by performing your calculation as a series | 2089 | accomplish this in Calc by performing your calculation as a series |
| 2051 | of algebraic entries, using the @kbd{$} sign to tie them together. | 2090 | of algebraic entries, using the @kbd{$} sign to tie them together. |
| 2052 | In an algebraic formula, @kbd{$} represents the number on the top | 2091 | In an algebraic formula, @kbd{$} represents the number on the top |
| 2053 | of the stack. Here, we perform the calculation @c{$\sqrt{2\times4+1}$} | 2092 | of 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)}, | ||
| 2055 | which on a traditional calculator would be done by pressing | 2095 | which 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 |
| 2192 | Notice that the instant we stored a new value in @code{a}, all | 2232 | Notice 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} |
| 2194 | were updated to use the new value. With @samp{=>}, you can push a | 2234 | were updated to use the new value. With @samp{=>}, you can push a |
| 2195 | set of formulas on the stack, then change the variables experimentally | 2235 | set of formulas on the stack, then change the variables experimentally |
| 2196 | to see the effects on the formulas' values. | 2236 | to see the effects on the formulas' values. |
| @@ -2257,7 +2297,7 @@ mistakenly. | |||
| 2257 | @end smallexample | 2297 | @end smallexample |
| 2258 | 2298 | ||
| 2259 | @noindent | 2299 | @noindent |
| 2260 | It was not possible to redo past the @cite{6}, since that was placed there | 2300 | It was not possible to redo past the @expr{6}, since that was placed there |
| 2261 | by something other than an undo command. | 2301 | by 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 |
| 2266 | backward and do something (like @kbd{*}) then, as any science fiction | 2306 | backward and do something (like @kbd{*}) then, as any science fiction |
| 2267 | reader knows, you have changed your future and you cannot go forward | 2307 | reader knows, you have changed your future and you cannot go forward |
| 2268 | again. Thus, the inability to redo past the @cite{6} even though there | 2308 | again. Thus, the inability to redo past the @expr{6} even though there |
| 2269 | was an earlier undo command. | 2309 | was an earlier undo command. |
| 2270 | 2310 | ||
| 2271 | You can always recall an earlier result using the Trail. We've ignored | 2311 | You 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 | |||
| 2273 | did since we loaded the Calculator. If the Trail is not displayed, | 2313 | did since we loaded the Calculator. If the Trail is not displayed, |
| 2274 | press @kbd{t d} now to turn it on. | 2314 | press @kbd{t d} now to turn it on. |
| 2275 | 2315 | ||
| 2276 | Let's try grabbing an earlier result. The @cite{8} we computed was | 2316 | Let's try grabbing an earlier result. The @expr{8} we computed was |
| 2277 | undone by a @kbd{U} command, and was lost even to Redo when we pressed | 2317 | undone 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 |
| 2280 | entry. If there isn't, press @kbd{t ]} to reset the trail pointer. | 2320 | entry. If there isn't, press @kbd{t ]} to reset the trail pointer. |
| 2281 | Now, press @w{@kbd{t p}} to move the arrow onto the line containing | 2321 | Now, 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 |
| 2283 | stack. | 2323 | stack. |
| 2284 | 2324 | ||
| 2285 | If you press @kbd{t ]} again, you will see that even our Yank command | 2325 | If 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) | |||
| 2340 | to edit a stack entry. | 2380 | to edit a stack entry. |
| 2341 | 2381 | ||
| 2342 | Try entering @samp{3.141439} now. If this is supposed to represent | 2382 | Try 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. | ||
| 2345 | Now use the normal Emacs cursor motion and editing keys to change | 2384 | Now use the normal Emacs cursor motion and editing keys to change |
| 2346 | the second 4 to a 5, and to transpose the 3 and the 9. When you | 2385 | the second 4 to a 5, and to transpose the 3 and the 9. When you |
| 2347 | press @key{RET}, the number on the stack will be replaced by your | 2386 | press @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 | |||
| 2370 | about, but the @samp{12} and the @samp{Deg} are mode indicators. | 2409 | about, but the @samp{12} and the @samp{Deg} are mode indicators. |
| 2371 | The @samp{12} means that calculations should always be carried to | 2410 | The @samp{12} means that calculations should always be carried to |
| 2372 | 12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /}, | 2411 | 12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /}, |
| 2373 | we get @cite{0.142857142857} with exactly 12 digits, not counting | 2412 | we get @expr{0.142857142857} with exactly 12 digits, not counting |
| 2374 | leading and trailing zeros. | 2413 | leading and trailing zeros. |
| 2375 | 2414 | ||
| 2376 | You can set the precision to anything you like by pressing @kbd{p}, | 2415 | You 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 | ||
| 2388 | Although the precision can be set arbitrarily high, Calc always | 2427 | Although the precision can be set arbitrarily high, Calc always |
| 2389 | has to have @emph{some} value for the current precision. After | 2428 | has to have @emph{some} value for the current precision. After |
| 2390 | all, the true value @cite{1/7} is an infinitely repeating decimal; | 2429 | all, the true value @expr{1/7} is an infinitely repeating decimal; |
| 2391 | Calc has to stop somewhere. | 2430 | Calc has to stop somewhere. |
| 2392 | 2431 | ||
| 2393 | Of course, calculations are slower the more digits you request. | 2432 | Of course, calculations are slower the more digits you request. |
| 2394 | Press @w{@kbd{p 12}} now to set the precision back down to the default. | 2433 | Press @w{@kbd{p 12}} now to set the precision back down to the default. |
| 2395 | 2434 | ||
| 2396 | Calculations always use the current precision. For example, even | 2435 | Calculations always use the current precision. For example, even |
| 2397 | though we have a 30-digit value for @cite{1/7} on the stack, if | 2436 | though we have a 30-digit value for @expr{1/7} on the stack, if |
| 2398 | we use it in a calculation in 12-digit mode it will be rounded | 2437 | we use it in a calculation in 12-digit mode it will be rounded |
| 2399 | down to 12 digits before it is used. Try it; press @key{RET} to | 2438 | down to 12 digits before it is used. Try it; press @key{RET} to |
| 2400 | duplicate the number, then @w{@kbd{1 +}}. Notice that the @key{RET} | 2439 | duplicate 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 |
| 2414 | In fact, since we added a digit on the left, we had to lose one | 2453 | In fact, since we added a digit on the left, we had to lose one |
| 2415 | digit on the right from even the 12-digit value of @cite{1/7}. | 2454 | digit on the right from even the 12-digit value of @expr{1/7}. |
| 2416 | 2455 | ||
| 2417 | How did we get more than 12 digits when we computed @samp{2^3^4}? The | 2456 | How did we get more than 12 digits when we computed @samp{2^3^4}? The |
| 2418 | answer is that Calc makes a distinction between @dfn{integers} and | 2457 | answer 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 |
| 2464 | Hey, the answer is different! Look closely at the middle columns | 2503 | Hey, the answer is different! Look closely at the middle columns |
| 2465 | of the two examples. In the first, the stack contained the | 2504 | of the two examples. In the first, the stack contained the |
| 2466 | exact integer @cite{10000}, but in the second it contained | 2505 | exact integer @expr{10000}, but in the second it contained |
| 2467 | a floating-point value with a decimal point. When you raise a | 2506 | a floating-point value with a decimal point. When you raise a |
| 2468 | number to an integer power, Calc uses repeated squaring and | 2507 | number to an integer power, Calc uses repeated squaring and |
| 2469 | multiplication to get the answer. When you use a floating-point | 2508 | multiplication 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 | |||
| 2564 | format; since it doesn't have an @kbd{H} prefix, it also updates all | 2603 | format; since it doesn't have an @kbd{H} prefix, it also updates all |
| 2565 | the stack entries to be in @kbd{d n} format. | 2604 | the stack entries to be in @kbd{d n} format. |
| 2566 | 2605 | ||
| 2567 | Notice that the integer @cite{12345} was not affected by any | 2606 | Notice that the integer @expr{12345} was not affected by any |
| 2568 | of the float formats. Integers are integers, and are always | 2607 | of the float formats. Integers are integers, and are always |
| 2569 | displayed exactly. | 2608 | displayed exactly. |
| 2570 | 2609 | ||
| @@ -2712,13 +2751,15 @@ angle is measured in degrees. For example, | |||
| 2712 | 2751 | ||
| 2713 | @noindent | 2752 | @noindent |
| 2714 | The shift-@kbd{S} command computes the sine of an angle. The sine | 2753 | The shift-@kbd{S} command computes the sine of an angle. The sine |
| 2715 | of 45 degrees is @c{$\sqrt{2}/2$} | 2754 | of 45 degrees is |
| 2716 | @cite{sqrt(2)/2}; squaring this yields @cite{2/4 = 0.5}. | 2755 | @texline @tmath{\sqrt{2}/2}; |
| 2717 | However, there has been a slight roundoff error because the | 2756 | @infoline @expr{sqrt(2)/2}; |
| 2718 | representation of @c{$\sqrt{2}/2$} | 2757 | squaring 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} | 2758 | roundoff error because the representation of |
| 2720 | command is a handy way to clean up numbers in this case; it | 2759 | @texline @tmath{\sqrt{2}/2} |
| 2721 | temporarily reduces the precision by one digit while it | 2760 | @infoline @expr{sqrt(2)/2} |
| 2761 | wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers | ||
| 2762 | in this case; it temporarily reduces the precision by one digit while it | ||
| 2722 | re-rounds the number on the top of the stack. | 2763 | re-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 | ||
| 2730 | To do this calculation in radians, we would type @kbd{m r} first. | 2771 | To 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 | ||
| 2735 | again, this is a shifted capital @kbd{P}. Remember, unshifted | 2774 | again, 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 |
| 2760 | Here we compute the Inverse Sine of @c{$\sqrt{0.5}$} | 2799 | Here we compute the Inverse Sine of |
| 2761 | @cite{sqrt(0.5)}, first in | 2800 | @texline @tmath{\sqrt{0.5}}, |
| 2762 | radians, then in degrees. | 2801 | @infoline @expr{sqrt(0.5)}, |
| 2802 | first in radians, then in degrees. | ||
| 2763 | 2803 | ||
| 2764 | Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees | 2804 | Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees |
| 2765 | and vice-versa. | 2805 | and vice-versa. |
| @@ -2939,15 +2979,16 @@ provide a @kbd{\} command. @xref{Arithmetic Answer 1, 1}. (@bullet{}) | |||
| 2939 | 2979 | ||
| 2940 | We've already seen the @kbd{Q} (square root) and @kbd{S} (sine) | 2980 | We've already seen the @kbd{Q} (square root) and @kbd{S} (sine) |
| 2941 | commands. Other commands along those lines are @kbd{C} (cosine), | 2981 | commands. 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 |
| 2943 | logarithm). These can be modified by the @kbd{I} (inverse) and | 2983 | logarithm). These can be modified by the @kbd{I} (inverse) and |
| 2944 | @kbd{H} (hyperbolic) prefix keys. | 2984 | @kbd{H} (hyperbolic) prefix keys. |
| 2945 | 2985 | ||
| 2946 | Let's compute the sine and cosine of an angle, and verify the | 2986 | Let's compute the sine and cosine of an angle, and verify the |
| 2947 | identity @c{$\sin^2x + \cos^2x = 1$} | 2987 | identity |
| 2948 | @cite{sin(x)^2 + cos(x)^2 = 1}. We'll | 2988 | @texline @tmath{\sin^2x + \cos^2x = 1}. |
| 2949 | arbitrarily pick @i{-64} degrees as a good value for @cite{x}. With | 2989 | @infoline @expr{sin(x)^2 + cos(x)^2 = 1}. |
| 2950 | the angular mode set to degrees (type @w{@kbd{m d}}), do: | 2990 | We'll arbitrarily pick @i{-64} degrees as a good value for @expr{x}. |
| 2991 | With the angular mode set to degrees (type @w{@kbd{m d}}), do: | ||
| 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.) | |||
| 2966 | Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum | 3007 | Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum |
| 2967 | of squares, command. | 3008 | of squares, command. |
| 2968 | 3009 | ||
| 2969 | Another identity is @c{$\displaystyle\tan x = {\sin x \over \cos x}$} | 3010 | Another 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 | ||
| 2982 | A physical interpretation of this calculation is that if you move | 3024 | A 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, |
| 2984 | your direction of motion is @i{-64} degrees from horizontal. Suppose | 3026 | your direction of motion is @i{-64} degrees from horizontal. Suppose |
| 2985 | we move in the opposite direction, up and to the left: | 3027 | we 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 | ||
| 3030 | A similar identity is supposed to hold for hyperbolic sines and cosines, | 3072 | A similar identity is supposed to hold for hyperbolic sines and cosines, |
| 3031 | except that it is the @emph{difference} | 3073 | except 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} |
| 3034 | Let's try to verify this identity.@refill | 3076 | that 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 | |||
| 3057 | 0.99999, reasonably close to 1. | 3099 | 0.99999, reasonably close to 1. |
| 3058 | 3100 | ||
| 3059 | Of course, a more reasonable way to verify the identity is to use | 3101 | Of course, a more reasonable way to verify the identity is to use |
| 3060 | a more reasonable value for @cite{x}! | 3102 | a more reasonable value for @expr{x}! |
| 3061 | 3103 | ||
| 3062 | @cindex Common logarithm | 3104 | @cindex Common logarithm |
| 3063 | Some Calculator commands use the Hyperbolic prefix for other purposes. | 3105 | Some Calculator commands use the Hyperbolic prefix for other purposes. |
| 3064 | The logarithm and exponential functions, for example, work to the base | 3106 | The 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 |
| 3066 | prefix. | 3108 | prefix. |
| 3067 | 3109 | ||
| 3068 | @smallexample | 3110 | @smallexample |
| @@ -3095,7 +3137,7 @@ value of @var{b}. | |||
| 3095 | Here we first use @kbd{B} to compute the base-10 logarithm, then use | 3137 | Here we first use @kbd{B} to compute the base-10 logarithm, then use |
| 3096 | the ``hyperbolic'' exponential as a cheap hack to recover the number | 3138 | the ``hyperbolic'' exponential as a cheap hack to recover the number |
| 3097 | 1000, then use @kbd{B} again to compute the natural logarithm. Note | 3139 | 1000, then use @kbd{B} again to compute the natural logarithm. Note |
| 3098 | that @kbd{P} with the hyperbolic prefix pushes the constant @cite{e} | 3140 | that @kbd{P} with the hyperbolic prefix pushes the constant @expr{e} |
| 3099 | onto the stack. | 3141 | onto the stack. |
| 3100 | 3142 | ||
| 3101 | You may have noticed that both times we took the base-10 logarithm | 3143 | You may have noticed that both times we took the base-10 logarithm |
| @@ -3136,8 +3178,8 @@ in this case). | |||
| 3136 | 3178 | ||
| 3137 | If you take the factorial of a non-integer, Calc uses a generalized | 3179 | If you take the factorial of a non-integer, Calc uses a generalized |
| 3138 | factorial function defined in terms of Euler's Gamma function | 3180 | factorial 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 |
| 3155 | Here we verify the identity @c{$n! = \Gamma(n+1)$} | 3197 | Here 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 | ||
| 3158 | The binomial coefficient @var{n}-choose-@var{m}@c{ or $\displaystyle {n \choose m}$} | 3201 | The 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)!}$} | 3203 | is 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)!} |
| 3163 | large even if the final result is small; the @kbd{k c} command computes | 3206 | for all reals @expr{n} and @expr{m}. The intermediate results in this |
| 3164 | a binomial coefficient in a way that avoids large intermediate | 3207 | formula can become quite large even if the final result is small; the |
| 3165 | values. | 3208 | @kbd{k c} command computes a binomial coefficient in a way that avoids |
| 3209 | large intermediate values. | ||
| 3166 | 3210 | ||
| 3167 | The @kbd{k} prefix key defines several common functions out of | 3211 | The @kbd{k} prefix key defines several common functions out of |
| 3168 | combinatorics and number theory. Here we compute the binomial | 3212 | combinatorics and number theory. Here we compute the binomial |
| @@ -3266,7 +3310,7 @@ of the vectors. | |||
| 3266 | @cindex Dot product | 3310 | @cindex Dot product |
| 3267 | The dot product of two vectors is equal to the product of their | 3311 | The dot product of two vectors is equal to the product of their |
| 3268 | lengths times the cosine of the angle between them. (Here the vector | 3312 | lengths times the cosine of the angle between them. (Here the vector |
| 3269 | is interpreted as a line from the origin @cite{(0,0,0)} to the | 3313 | is interpreted as a line from the origin @expr{(0,0,0)} to the |
| 3270 | specified point in three-dimensional space.) The @kbd{A} | 3314 | specified 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 |
| 3272 | vector. | 3316 | vector. |
| @@ -3379,8 +3423,8 @@ the second example. | |||
| 3379 | 3423 | ||
| 3380 | When two matrices are multiplied, the lefthand matrix must have | 3424 | When two matrices are multiplied, the lefthand matrix must have |
| 3381 | the same number of columns as the righthand matrix has rows. | 3425 | the same number of columns as the righthand matrix has rows. |
| 3382 | Row @cite{i}, column @cite{j} of the result is effectively the | 3426 | Row @expr{i}, column @expr{j} of the result is effectively the |
| 3383 | dot product of row @cite{i} of the left matrix by column @cite{j} | 3427 | dot product of row @expr{i} of the left matrix by column @expr{j} |
| 3384 | of the right matrix. | 3428 | of the right matrix. |
| 3385 | 3429 | ||
| 3386 | If we try to duplicate this matrix and multiply it by itself, | 3430 | If 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 | |||
| 3441 | vector. | 3485 | vector. |
| 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 |
| 3444 | of the above @c{$2\times3$} | 3488 | of the above |
| 3445 | @asis{2x3} matrix to get @cite{[6, 15]}. Now use @samp{*} to | 3489 | @texline @tmath{2\times3} |
| 3446 | sum along the columns to get @cite{[5, 7, 9]}. | 3490 | @infoline 2x3 |
| 3491 | matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns | ||
| 3492 | to 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 |
| 3569 | The result is the @cite{[a, b, c]} vector that solves the equations. | 3615 | The 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 |
| 3571 | inverse.) | 3617 | inverse.) |
| 3572 | 3618 | ||
| @@ -3590,16 +3636,19 @@ the matrix and vector. If we multiplied in the other order, Calc would | |||
| 3590 | assume the vector was a row vector in order to make the dimensions | 3636 | assume the vector was a row vector in order to make the dimensions |
| 3591 | come out right, and the answer would be incorrect. If you | 3637 | come out right, and the answer would be incorrect. If you |
| 3592 | don't feel safe letting Calc take either interpretation of your | 3638 | don't feel safe letting Calc take either interpretation of your |
| 3593 | vectors, use explicit @c{$N\times1$} | 3639 | vectors, use explicit |
| 3594 | @asis{Nx1} or @c{$1\times N$} | 3640 | @texline @tmath{N\times1} |
| 3595 | @asis{1xN} matrices instead. | 3641 | @infoline Nx1 |
| 3596 | In this case, you would enter the original column vector as | 3642 | or |
| 3597 | @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. | 3643 | @texline @tmath{1\times N} |
| 3644 | @infoline 1xN | ||
| 3645 | matrices instead. In this case, you would enter the original column | ||
| 3646 | vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. | ||
| 3598 | 3647 | ||
| 3599 | (@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make | 3648 | (@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make |
| 3600 | vectors and matrices that include variables. Solve the following | 3649 | vectors and matrices that include variables. Solve the following |
| 3601 | system of equations to get expressions for @cite{x} and @cite{y} | 3650 | system of equations to get expressions for @expr{x} and @expr{y} |
| 3602 | in terms of @cite{a} and @cite{b}. | 3651 | in 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 | |||
| 3628 | there are no values for the variables that will satisfy all the | 3677 | there are no values for the variables that will satisfy all the |
| 3629 | equations at once, but it is still useful to find a set of values | 3678 | equations at once, but it is still useful to find a set of values |
| 3630 | which ``nearly'' satisfy all the equations. In terms of matrix equations, | 3679 | which ``nearly'' satisfy all the equations. In terms of matrix equations, |
| 3631 | you can't solve @cite{A X = B} directly because the matrix @cite{A} | 3680 | you can't solve @expr{A X = B} directly because the matrix @expr{A} |
| 3632 | is not square for an over-determined system. Matrix inversion works | 3681 | is not square for an over-determined system. Matrix inversion works |
| 3633 | only for square matrices. One common trick is to multiply both sides | 3682 | only for square matrices. One common trick is to multiply both sides |
| 3634 | on the left by the transpose of @cite{A}: | 3683 | on 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 |
| 3642 | Now @c{$A^T A$} | 3691 | Now |
| 3643 | @cite{trn(A)*A} is a square matrix so a solution is possible. It | 3692 | @texline @tmath{A^T A} |
| 3644 | turns 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'' | 3694 | is a square matrix so a solution is possible. It turns out that the |
| 3646 | solution 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'' |
| 3647 | over-determined system:@refill | 3696 | solution, which can be regarded as the ``closest'' solution to the set |
| 3697 | of equations. Use Calc to solve the following over-determined | ||
| 3698 | system: | ||
| 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 | |||
| 3733 | of each element. | 3784 | of 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 |
| 3736 | from @c{$2^{-4}$} | 3787 | from |
| 3737 | @cite{2^-4} to @cite{2^4}. @xref{List Answer 1, 1}. (@bullet{}) | 3788 | @texline @tmath{2^{-4}} |
| 3789 | @infoline @expr{2^-4} | ||
| 3790 | to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{}) | ||
| 3738 | 3791 | ||
| 3739 | You can also @dfn{reduce} a binary operator across a vector. | 3792 | You can also @dfn{reduce} a binary operator across a vector. |
| 3740 | For example, reducing @samp{*} computes the product of all the | 3793 | For 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 | ||
| 3870 | Position the cursor at the upper-left corner of this table, just | 3923 | Position the cursor at the upper-left corner of this table, just |
| 3871 | to the left of the @cite{1.34}. Press @kbd{C-@@} to set the mark. | 3924 | to 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}.) |
| 3873 | Now position the cursor to the lower-right, just after the @cite{1.354}. | 3926 | Now position the cursor to the lower-right, just after the @expr{1.354}. |
| 3874 | You have now defined this region as an Emacs ``rectangle.'' Still | 3927 | You have now defined this region as an Emacs ``rectangle.'' Still |
| 3875 | in the Info buffer, type @kbd{M-# r}. This command | 3928 | in 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 |
| 3877 | the contents of the rectangle you specified in the form of a matrix.@refill | 3930 | the 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 |
| 3920 | stored value from the stack.) | 3973 | stored value from the stack.) |
| 3921 | 3974 | ||
| 3922 | In a least squares fit, the slope @cite{m} is given by the formula | 3975 | In 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 |
| 3938 | where @c{$\sum x$} | 3991 | where |
| 3939 | @cite{sum(x)} represents the sum of all the values of @cite{x}. | 3992 | @texline @tmath{\sum x} |
| 3940 | While there is an actual @code{sum} function in Calc, it's easier to | 3993 | @infoline @expr{sum(x)} |
| 3941 | sum a vector using a simple reduction. First, let's compute the four | 3994 | represents the sum of all the values of @expr{x}. While there is an |
| 3942 | different sums that this formula uses. | 3995 | actual @code{sum} function in Calc, it's easier to sum a vector using a |
| 3996 | simple reduction. First, let's compute the four different sums that | ||
| 3997 | this formula uses. | ||
| 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 | ||
| 3976 | Finally, we also need @cite{N}, the number of data points. This is just | 4031 | Finally, we also need @expr{N}, the number of data points. This is just |
| 3977 | the length of either of our lists. | 4032 | the 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 | ||
| 4015 | That gives us the slope @cite{m}. The y-intercept @cite{b} can now | 4070 | That gives us the slope @expr{m}. The y-intercept @expr{b} can now |
| 4016 | be found with the simple formula, | 4071 | be 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 | ||
| 4041 | Let's ``plot'' this straight line approximation, @c{$y \approx m x + b$} | 4096 | Let'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}, | ||
| 4099 | and 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 | |||
| 4056 | common operations from vector algebra. As far as Calc is concerned, | 4113 | common operations from vector algebra. As far as Calc is concerned, |
| 4057 | we've just been doing geometry in 19-dimensional space! | 4114 | we've just been doing geometry in 19-dimensional space! |
| 4058 | 4115 | ||
| 4059 | We can subtract this vector from our original @cite{y} vector to get | 4116 | We can subtract this vector from our original @expr{y} vector to get |
| 4060 | a feel for the error of our fit. Let's find the maximum error: | 4117 | a 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 |
| 4133 | least squares fitting to a general system of equations. Our 19 data | 4190 | least squares fitting to a general system of equations. Our 19 data |
| 4134 | points are really 19 equations of the form @cite{y_i = m x_i + b} for | 4191 | points are really 19 equations of the form @expr{y_i = m x_i + b} for |
| 4135 | different pairs of @cite{(x_i,y_i)}. Use the matrix-transpose method | 4192 | different pairs of @expr{(x_i,y_i)}. Use the matrix-transpose method |
| 4136 | to solve for @cite{m} and @cite{b}, duplicating the above result. | 4193 | to 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 |
| 4162 | on up to @var{n}-choose-@var{n}, | 4219 | on up to @var{n}-choose-@var{n}, |
| 4163 | always comes out to zero. Let's verify this | 4220 | always comes out to zero. Let's verify this |
| 4164 | for @cite{n=6}.@refill | 4221 | for @expr{n=6}. |
| 4165 | @end ifinfo | 4222 | @end ifinfo |
| 4166 | @tex | 4223 | @tex |
| 4167 | As another example, a theorem about binomial coefficients tells | 4224 | As another example, a theorem about binomial coefficients tells |
| @@ -4232,13 +4289,13 @@ element of a plain vector. With a negative argument, @kbd{v r} | |||
| 4232 | and @kbd{v c} instead delete one row, column, or vector element. | 4289 | and @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 |
| 4239 | is the sum of the @cite{k}th powers of all the divisors of an | 4296 | is the sum of the @expr{k}th powers of all the divisors of an |
| 4240 | integer @cite{n}. Figure out a method for computing the divisor | 4297 | integer @expr{n}. Figure out a method for computing the divisor |
| 4241 | function for reasonably small values of @cite{n}. As a test, | 4298 | function for reasonably small values of @expr{n}. As a test, |
| 4242 | the 0th and 1st divisor functions of 30 are 8 and 72, respectively. | 4299 | the 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} |
| 4295 | in steps of 0.25. | 4352 | function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25. |
| 4296 | Find the value of @cite{x} (from among the above set of values) for | 4353 | Find the value of @expr{x} (from among the above set of values) for |
| 4297 | which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, | 4354 | which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, |
| 4298 | i.e., just reading along the list by hand to find the largest value | 4355 | i.e., just reading along the list by hand to find the largest value |
| 4299 | is not allowed! (There is an @kbd{a X} command which does this kind | 4356 | is not allowed! (There is an @kbd{a X} command which does this kind |
| 4300 | of thing automatically; @pxref{Numerical Solutions}.) | 4357 | of 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} |
| 4307 | twelve digits). Convert this integer into a vector of @cite{m} | 4364 | for @expr{m=12} (i.e., an integer of less than |
| 4365 | twelve digits). Convert this integer into a vector of @expr{m} | ||
| 4308 | digits, each in the range from 0 to 9. In vector-of-digits notation, | 4366 | digits, each in the range from 0 to 9. In vector-of-digits notation, |
| 4309 | add one to this integer to produce a vector of @cite{m+1} digits | 4367 | add 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). |
| 4311 | Convert this vector back into a regular integer. A good integer | 4369 | Convert this vector back into a regular integer. A good integer |
| 4312 | to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) | 4370 | to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) |
| @@ -4316,40 +4374,39 @@ to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{}) | |||
| 4316 | happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) | 4374 | happened? 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 |
| 4319 | is @c{$\pi$} | 4377 | is @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 |
| 4322 | circle is 4. So if we throw @var{n} darts at random points in the square, | 4380 | square that encloses that circle is 4. So if we throw @var{n} darts at |
| 4323 | about @c{$\pi/4$} | 4381 | random 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 | 4382 | the circle. This gives us an entertaining way to estimate the value of |
| 4325 | an entertaining way to estimate the value of @c{$\pi$} | 4383 | @cpi{}. The @w{@kbd{k r}} |
| 4326 | @cite{pi}. The @w{@kbd{k r}} | ||
| 4327 | command picks a random number between zero and the value on the stack. | 4384 | command picks a random number between zero and the value on the stack. |
| 4328 | We could get a random floating-point number between @i{-1} and 1 by typing | 4385 | We 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 |
| 4330 | this square, then use vector mapping and reduction to count how many | 4387 | this square, then use vector mapping and reduction to count how many |
| 4331 | points lie inside the unit circle. Hint: Use the @kbd{v b} command. | 4388 | points 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 |
| 4336 | another way to calculate @c{$\pi$} | 4393 | another way to calculate @cpi{}. Say you have an infinite field |
| 4337 | @cite{pi}. Say you have an infinite field | ||
| 4338 | of vertical lines with a spacing of one inch. Toss a one-inch matchstick | 4394 | of vertical lines with a spacing of one inch. Toss a one-inch matchstick |
| 4339 | onto the field. The probability that the matchstick will land crossing | 4395 | onto the field. The probability that the matchstick will land crossing |
| 4340 | a line turns out to be @c{$2/\pi$} | 4396 | a 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 | 4399 | Toss 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$} | 4400 | the probability that the GCD (@w{@kbd{k g}}) of two large integers is |
| 4345 | @cite{6/pi^2}. | 4401 | one turns out to be |
| 4346 | That provides yet another way to estimate @c{$\pi$} | 4402 | @texline @tmath{6/\pi^2}. |
| 4347 | @cite{pi}.) | 4403 | @infoline @expr{6/pi^2}. |
| 4404 | That 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 |
| 4351 | double-quote marks, @samp{"hello"}, creates a vector of the numerical | 4408 | double-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]}). |
| 4353 | Sometimes it is convenient to compute a @dfn{hash code} of a string, | 4410 | Sometimes it is convenient to compute a @dfn{hash code} of a string, |
| 4354 | which is just an integer that represents the value of that string. | 4411 | which is just an integer that represents the value of that string. |
| 4355 | Two equal strings have the same hash code; two different strings | 4412 | Two 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 | |||
| 4358 | any given name because it has sorted the functions into ``buckets'' by | 4415 | any given name because it has sorted the functions into ``buckets'' by |
| 4359 | their hash codes. Sometimes a few names will hash into the same bucket, | 4416 | their hash codes. Sometimes a few names will hash into the same bucket, |
| 4360 | but it is easier to search among a few names than among all the names.) | 4417 | but it is easier to search among a few names than among all the names.) |
| 4361 | One popular hash function is computed as follows: First set @cite{h = 0}. | 4418 | One popular hash function is computed as follows: First set @expr{h = 0}. |
| 4362 | Then, for each character from the string in turn, set @cite{h = 3h + c_i} | 4419 | Then, for each character from the string in turn, set @expr{h = 3h + c_i} |
| 4363 | where @cite{c_i} is the character's ASCII code. If we have 511 buckets, | 4420 | where @expr{c_i} is the character's ASCII code. If we have 511 buckets, |
| 4364 | we then take the hash code modulo 511 to get the bucket number. Develop a | 4421 | we then take the hash code modulo 511 to get the bucket number. Develop a |
| 4365 | simple command or commands for converting string vectors into hash codes. | 4422 | simple command or commands for converting string vectors into hash codes. |
| 4366 | The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo | 4423 | The 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 | |||
| 4372 | function you give to the starting value 0, 1, 2, up to @var{n} times | 4429 | function you give to the starting value 0, 1, 2, up to @var{n} times |
| 4373 | and returns a vector of the results. Use this command to create a | 4430 | and 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 |
| 4376 | in both @cite{x} and @cite{y}; then take another step, and so on. Use the | 4433 | in 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 |
| 4378 | walk to walk a unit distance, but in a random direction, at each step. | 4435 | walk 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 |
| 4438 | result 1.26508260337. You suspect it is the square root of the | 4495 | result 1.26508260337. You suspect it is the square root of the |
| 4439 | product of @c{$\pi$} | 4496 | product of @cpi{} and some rational number. Is it? (Be sure |
| 4440 | @cite{pi} and some rational number. Is it? (Be sure | ||
| 4441 | to allow for roundoff error!) @xref{Types Answer 1, 1}. (@bullet{}) | 4497 | to 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 |
| 4455 | The square root of @i{-9} is by default rendered in rectangular form | 4511 | The 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 |
| 4457 | phase angle of 90 degrees). All the usual arithmetic and scientific | 4513 | phase angle of 90 degrees). All the usual arithmetic and scientific |
| 4458 | operations are defined on both types of complex numbers. | 4514 | operations are defined on both types of complex numbers. |
| 4459 | 4515 | ||
| @@ -4509,9 +4565,9 @@ to turn on ``infinite mode.'' | |||
| 4509 | Dividing by zero normally is left unevaluated, but after @kbd{m i} | 4565 | Dividing by zero normally is left unevaluated, but after @kbd{m i} |
| 4510 | it instead gives an infinite result. The answer is actually | 4566 | it 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 |
| 4513 | plus infinity as you approach zero from above, but toward minus | 4569 | plus infinity as you approach zero from above, but toward minus |
| 4514 | infinity as you approach from below. Since we said only @cite{1 / 0}, | 4570 | infinity as you approach from below. Since we said only @expr{1 / 0}, |
| 4515 | Calc knows that the answer is infinite but not in which direction. | 4571 | Calc knows that the answer is infinite but not in which direction. |
| 4516 | That's what @code{uinf} means. Notice that multiplying @code{uinf} | 4572 | That's what @code{uinf} means. Notice that multiplying @code{uinf} |
| 4517 | by a negative number still leaves plain @code{uinf}; there's no | 4573 | by 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}} |
| 4646 | defines the center of the tube and @cite{r} is the radius of the tube | 4702 | where @expr{R} is the radius of the circle that |
| 4647 | itself. Suppose @cite{R} is 20 cm and @cite{r} is 4 cm, each known to | 4703 | defines the center of the tube and @expr{r} is the radius of the tube |
| 4704 | itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to | ||
| 4648 | within 5 percent. What is the volume and the relative uncertainty of | 4705 | within 5 percent. What is the volume and the relative uncertainty of |
| 4649 | the volume? @xref{Types Answer 7, 7}. (@bullet{}) | 4706 | the 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 |
| 4742 | says that @c{\w{$x^{n-1} \bmod n = 1$}} | 4799 | says 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}} |
| 4744 | and @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 | 4802 | if @expr{n} is a prime number and @expr{x} is an integer less than |
| 4746 | values 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 |
| 4747 | prime 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 |
| 4748 | Use this test to tell whether the following numbers are prime: | 4805 | informally if a number is prime by trying this formula for several |
| 4749 | 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{}) | 4806 | values of @expr{x}. Use this test to tell whether the following numbers |
| 4807 | are prime: 811749613, 15485863. @xref{Types Answer 10, 10}. (@bullet{}) | ||
| 4750 | 4808 | ||
| 4751 | It is possible to use HMS forms as parts of error forms, intervals, | 4809 | It is possible to use HMS forms as parts of error forms, intervals, |
| 4752 | modulo forms, or as the phase part of a polar complex number. | 4810 | modulo 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. | |||
| 4766 | This calculation tells me it is six hours and 22 minutes until midnight. | 4824 | This 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 |
| 4769 | is about @c{$\pi \times 10^7$} | 4827 | is about |
| 4770 | @w{@cite{pi * 10^7}} seconds. What time will it be that | 4828 | @texline @tmath{\pi \times 10^7} |
| 4771 | many seconds from right now? @xref{Types Answer 11, 11}. (@bullet{}) | 4829 | @infoline @w{@expr{pi * 10^7}} |
| 4830 | seconds. What time will it be that many seconds from right now? | ||
| 4831 | @xref{Types Answer 11, 11}. (@bullet{}) | ||
| 4772 | 4832 | ||
| 4773 | (@bullet{}) @strong{Exercise 12.} You are preparing to order packaging | 4833 | (@bullet{}) @strong{Exercise 12.} You are preparing to order packaging |
| 4774 | for the CD release of the Extended Disco Version of @emph{Abbey Road}. | 4834 | for 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 |
| 4951 | First we ``expand'' using the distributive law, then we ``collect'' | 5011 | First we ``expand'' using the distributive law, then we ``collect'' |
| 4952 | terms involving like powers of @cite{x}. | 5012 | terms involving like powers of @expr{x}. |
| 4953 | 5013 | ||
| 4954 | Let's find the value of this expression when @cite{x} is 2 and @cite{y} | 5014 | Let's find the value of this expression when @expr{x} is 2 and @expr{y} |
| 4955 | is one-half. | 5015 | is 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 | |||
| 4976 | properly.) | 5036 | properly.) |
| 4977 | 5037 | ||
| 4978 | @cindex Maximum of a function using Calculus | 5038 | @cindex Maximum of a function using Calculus |
| 4979 | Let's find the maximum value of our original expression when @cite{y} | 5039 | Let's find the maximum value of our original expression when @expr{y} |
| 4980 | is one-half and @cite{x} ranges over all possible values. We can | 5040 | is one-half and @expr{x} ranges over all possible values. We can |
| 4981 | do this by taking the derivative with respect to @cite{x} and examining | 5041 | do this by taking the derivative with respect to @expr{x} and examining |
| 4982 | values of @cite{x} for which the derivative is zero. If the second | 5042 | values of @expr{x} for which the derivative is zero. If the second |
| 4983 | derivative of the function at that value of @cite{x} is negative, | 5043 | derivative of the function at that value of @expr{x} is negative, |
| 4984 | the function has a local maximum there. | 5044 | the 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 |
| 4996 | Well, the derivative is clearly zero when @cite{x} is zero. To find | 5056 | Well, the derivative is clearly zero when @expr{x} is zero. To find |
| 4997 | the other root(s), let's divide through by @cite{x} and then solve: | 5057 | the 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 | |||
| 5020 | default algebraic simplifications don't do enough, you can use | 5080 | default 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 | ||
| 5023 | Now we compute the second derivative and plug in our values of @cite{x}: | 5083 | Now 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 |
| 5052 | The first of these second derivatives is negative, so we know the function | 5112 | The first of these second derivatives is negative, so we know the function |
| 5053 | has a maximum value at @cite{x = 1.19023}. (The function also has a | 5113 | has a maximum value at @expr{x = 1.19023}. (The function also has a |
| 5054 | local @emph{minimum} at @cite{x = 0}.) | 5114 | local @emph{minimum} at @expr{x = 0}.) |
| 5055 | 5115 | ||
| 5056 | When we solved for @cite{x}, we got only one value even though | 5116 | When 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 |
| 5058 | two solutions. The reason is that @w{@kbd{a S}} normally returns a | 5118 | two solutions. The reason is that @w{@kbd{a S}} normally returns a |
| 5059 | single ``principal'' solution. If it needs to come up with an | 5119 | single ``principal'' solution. If it needs to come up with an |
| 5060 | arbitrary sign (as occurs in the quadratic formula) it picks @cite{+}. | 5120 | arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}. |
| 5061 | If it needs an arbitrary integer, it picks zero. We can get a full | 5121 | If it needs an arbitrary integer, it picks zero. We can get a full |
| 5062 | solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}. | 5122 | solution 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; | |||
| 5075 | it is supposed to be either @i{+1} or @i{-1}. Here we have used | 5135 | it is supposed to be either @i{+1} or @i{-1}. Here we have used |
| 5076 | the ``let'' command to evaluate the expression when the sign is negative. | 5136 | the ``let'' command to evaluate the expression when the sign is negative. |
| 5077 | If we plugged this into our second derivative we would get the same, | 5137 | If we plugged this into our second derivative we would get the same, |
| 5078 | negative, answer, so @cite{x = -1.19023} is also a maximum. | 5138 | negative, answer, so @expr{x = -1.19023} is also a maximum. |
| 5079 | 5139 | ||
| 5080 | To find the actual maximum value, we must plug our two values of @cite{x} | 5140 | To find the actual maximum value, we must plug our two values of @expr{x} |
| 5081 | into the original formula. | 5141 | into 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 |
| 5128 | automates the job we just did by hand. Applied to our original | 5188 | automates the job we just did by hand. Applied to our original |
| 5129 | cubic polynomial, it would produce the vector of solutions | 5189 | cubic 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 |
| 5131 | which finds a local maximum of a function. It uses a numerical search | 5191 | which finds a local maximum of a function. It uses a numerical search |
| 5132 | method rather than examining the derivatives, and thus requires you | 5192 | method rather than examining the derivatives, and thus requires you |
| 5133 | to provide some kind of initial guess to show it where to look.) | 5193 | to 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 | |||
| 5215 | are shown in normal mode.) | 5275 | are shown in normal mode.) |
| 5216 | 5276 | ||
| 5217 | @cindex Area under a curve | 5277 | @cindex Area under a curve |
| 5218 | What is the area under the portion of this curve from @cite{x = 1} to @cite{2}? | 5278 | What is the area under the portion of this curve from @expr{x = 1} to @expr{2}? |
| 5219 | This is simply the integral of the function: | 5279 | This 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 |
| 5231 | We want to evaluate this at our two values for @cite{x} and subtract. | 5291 | We want to evaluate this at our two values for @expr{x} and subtract. |
| 5232 | One way to do it is again with vector mapping and reduction: | 5292 | One 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} |
| 5244 | of @c{$x \sin \pi x$} | 5304 | of |
| 5245 | @w{@cite{x sin(pi x)}} (where the sine is calculated in radians). | 5305 | @texline @tmath{x \sin \pi x} |
| 5246 | Find 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 |
| 5308 | integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3, | ||
| 5309 | 3}. (@bullet{}) | ||
| 5248 | 5310 | ||
| 5249 | Calc's integrator can do many simple integrals symbolically, but many | 5311 | Calc's integrator can do many simple integrals symbolically, but many |
| 5250 | others are beyond its capabilities. Suppose we wish to find the area | 5312 | others are beyond its capabilities. Suppose we wish to find the area |
| 5251 | under the curve @c{$\sin x \ln x$} | 5313 | under the curve |
| 5252 | @cite{sin(x) ln(x)} over the same range of @cite{x}. If | 5314 | @texline @tmath{\sin x \ln x} |
| 5253 | you entered this formula and typed @kbd{a i x @key{RET}} (don't bother to try | 5315 | @infoline @expr{sin(x) ln(x)} |
| 5254 | this), Calc would work for a long time but would be unable to find a | 5316 | over the same range of @expr{x}. If you entered this formula and typed |
| 5255 | solution. 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 |
| 5256 | Now what do we do? | 5318 | long time but would be unable to find a solution. In fact, there is no |
| 5319 | closed-form solution to this integral. Now what do we do? | ||
| 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 |
| 5324 | Here we have computed the Taylor series expansion of the function | 5387 | Here we have computed the Taylor series expansion of the function |
| 5325 | about the point @cite{x=1}. We can now integrate this polynomial | 5388 | about the point @expr{x=1}. We can now integrate this polynomial |
| 5326 | approximation, since polynomials are easy to integrate. | 5389 | approximation, 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 | |||
| 5339 | in the Taylor series, we can get a result as accurate as we like. | 5402 | in 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 |
| 5341 | function such as the one at @code{ln(0)}, so it would also help to | 5404 | function such as the one at @code{ln(0)}, so it would also help to |
| 5342 | expand the series about the points @cite{x=2} or @cite{x=1.5} instead | 5405 | expand the series about the points @expr{x=2} or @expr{x=1.5} instead |
| 5343 | of @cite{x=1}.) | 5406 | of @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 |
| 5373 | where @cite{n} (which must be even) is the number of slices and @cite{h} | 5436 | where @expr{n} (which must be even) is the number of slices and @expr{h} |
| 5374 | is the width of each slice. These are 10 and 0.1 in our example. | 5437 | is the width of each slice. These are 10 and 0.1 in our example. |
| 5375 | For reference, here is the corresponding formula for the stairstep | 5438 | For reference, here is the corresponding formula for the stairstep |
| 5376 | method: | 5439 | method: |
| @@ -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 | ||
| 5392 | Compute the integral from 1 to 2 of @c{$\sin x \ln x$} | 5455 | Compute the integral from 1 to 2 of |
| 5393 | @cite{sin(x) ln(x)} using | 5456 | @texline @tmath{\sin x \ln x} |
| 5394 | Simpson's rule with 10 slices. @xref{Algebra Answer 4, 4}. (@bullet{}) | 5457 | @infoline @expr{sin(x) ln(x)} |
| 5458 | using Simpson's rule with 10 slices. | ||
| 5459 | @xref{Algebra Answer 4, 4}. (@bullet{}) | ||
| 5395 | 5460 | ||
| 5396 | Calc has a built-in @kbd{a I} command for doing numerical integration. | 5461 | Calc has a built-in @kbd{a I} command for doing numerical integration. |
| 5397 | It uses @dfn{Romberg's method}, which is a more sophisticated cousin | 5462 | It 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. | |||
| 5639 | A common error with rewrite | 5704 | A common error with rewrite |
| 5640 | rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting | 5705 | rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting |
| 5641 | to match any @samp{f} with five arguments but in fact matching | 5706 | to match any @samp{f} with five arguments but in fact matching |
| 5642 | only when the fifth argument is literally @samp{e}!@refill | 5707 | only 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}, |
| 5793 | divide @cite{a} by two if it is even, otherwise compute @cite{3 a + 1}. | 5858 | divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}. |
| 5794 | Now repeat this step over and over. A famous unproved conjecture | 5859 | Now repeat this step over and over. A famous unproved conjecture |
| 5795 | is that for any starting @cite{a}, the sequence always eventually | 5860 | is that for any starting @expr{a}, the sequence always eventually |
| 5796 | reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of | 5861 | reaches 1. Given the formula @samp{seq(@var{a}, 0)}, write a set of |
| 5797 | rules that convert this into @samp{seq(1, @var{n})} where @var{n} | 5862 | rules that convert this into @samp{seq(1, @var{n})} where @var{n} |
| 5798 | is the number of steps it took the sequence to reach the value 1. | 5863 | is 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. | |||
| 5801 | Now make the result be a vector of values in the sequence, from @var{a} | 5866 | Now make the result be a vector of values in the sequence, from @var{a} |
| 5802 | to 1. (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x} | 5867 | to 1. (The formula @samp{@var{x}|@var{y}} appends the vectors @var{x} |
| 5803 | and @var{y}.) For example, rewriting @samp{seq(6)} should yield the | 5868 | and @var{y}.) For example, rewriting @samp{seq(6)} should yield the |
| 5804 | vector @cite{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. | 5869 | vector @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 |
| 5810 | is one or more non-sum terms separated by @samp{+} or @samp{-} signs, | 5875 | is one or more non-sum terms separated by @samp{+} or @samp{-} signs, |
| 5811 | so that @cite{2 - 3 (x + y) + x y} is a sum of three terms.) | 5876 | so 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} |
| 5815 | to be ``indeterminate,'' and leaves it unevaluated (assuming infinite | 5880 | to be ``indeterminate,'' and leaves it unevaluated (assuming infinite |
| 5816 | mode is not enabled). Some people prefer to define @cite{0^0 = 1}, | 5881 | mode is not enabled). Some people prefer to define @expr{0^0 = 1}, |
| 5817 | so that the identity @cite{x^0 = 1} can safely be used for all @cite{x}. | 5882 | so that the identity @expr{x^0 = 1} can safely be used for all @expr{x}. |
| 5818 | Find a way to make Calc follow this convention. What happens if you | 5883 | Find a way to make Calc follow this convention. What happens if you |
| 5819 | now type @kbd{m i} to turn on infinite mode? | 5884 | now 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 |
| 5823 | infinite series that exactly equals the value of that function at | 5888 | infinite series that exactly equals the value of that function at |
| 5824 | values of @cite{x} near zero. | 5889 | values 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 | ||
| 5838 | The @kbd{a t} command produces a @dfn{truncated Taylor series} which | 5903 | The @kbd{a t} command produces a @dfn{truncated Taylor series} which |
| 5839 | is obtained by dropping all the terms higher than, say, @cite{x^2}. | 5904 | is obtained by dropping all the terms higher than, say, @expr{x^2}. |
| 5840 | Calc represents the truncated Taylor series as a polynomial in @cite{x}. | 5905 | Calc represents the truncated Taylor series as a polynomial in @expr{x}. |
| 5841 | Mathematicians often write a truncated series using a ``big-O'' notation | 5906 | Mathematicians often write a truncated series using a ``big-O'' notation |
| 5842 | that records what was the lowest term that was truncated. | 5907 | that 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 |
| 5857 | The meaning of @cite{O(x^3)} is ``a quantity which is negligibly small | 5922 | The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small |
| 5858 | if @cite{x^3} is considered negligibly small as @cite{x} goes to zero.'' | 5923 | if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.'' |
| 5859 | 5924 | ||
| 5860 | The exercise is to create rewrite rules that simplify sums and products of | 5925 | The exercise is to create rewrite rules that simplify sums and products of |
| 5861 | power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}. | 5926 | power 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 | 6004 | is defined as the integral of @samp{sin(t)/t} for |
| 6005 | @expr{t = 0} to @expr{x} in radians. (It was invented because this | ||
| 5940 | integral has no solution in terms of basic functions; if you give it | 6006 | integral has no solution in terms of basic functions; if you give it |
| 5941 | to Calc's @kbd{a i} command, it will ponder it for a long time and then | 6007 | to Calc's @kbd{a i} command, it will ponder it for a long time and then |
| 5942 | give up.) We can use the numerical integration command, however, | 6008 | give 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 |
| 6013 | Compute @c{$\displaystyle{\sin x \over x}$} | 6079 | Compute |
| 6014 | @cite{sin(x) / x}, where @cite{x} is the number on the | 6080 | @texline @tmath{\displaystyle{\sin x \over x}}, |
| 6015 | top of the stack. | 6081 | @infoline @expr{sin(x) / x}, |
| 6082 | where @expr{x} is the number on the top of the stack. | ||
| 6016 | 6083 | ||
| 6017 | @item | 6084 | @item |
| 6018 | Compute the base-@cite{b} logarithm, just like the @kbd{B} key except | 6085 | Compute the base-@expr{b} logarithm, just like the @kbd{B} key except |
| 6019 | the arguments are taken in the opposite order. | 6086 | the 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 |
| 6047 | Here we have computed the fourth derivative of @cite{x^6} by | 6114 | Here we have computed the fourth derivative of @expr{x^6} by |
| 6048 | enclosing a derivative command in a ``repeat loop'' structure. | 6115 | enclosing a derivative command in a ``repeat loop'' structure. |
| 6049 | This structure pops a repeat count from the stack, then | 6116 | This structure pops a repeat count from the stack, then |
| 6050 | executes the body of the loop that many times. | 6117 | executes 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 |
| 6077 | A fascinating property of the Fibonacci numbers is that the @cite{n}th | 6144 | A fascinating property of the Fibonacci numbers is that the @expr{n}th |
| 6078 | Fibonacci number can be found directly by computing @c{$\phi^n / \sqrt{5}$} | 6145 | Fibonacci number can be found directly by computing |
| 6079 | @cite{phi^n / sqrt(5)} | 6146 | @texline @tmath{\phi^n / \sqrt{5}} |
| 6080 | and then rounding to the nearest integer, where @c{$\phi$ (``phi'')} | 6147 | @infoline @expr{phi^n / sqrt(5)} |
| 6081 | @cite{phi}, the | 6148 | and 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}, |
| 6084 | from the @code{phi} variable, or the @kbd{I H P} command.) | 6151 | the ``golden ratio,'' is |
| 6152 | @texline @tmath{(1 + \sqrt{5}) / 2}. | ||
| 6153 | @infoline @expr{(1 + sqrt(5)) / 2}. | ||
| 6154 | (For convenience, this constant is available from the @code{phi} | ||
| 6155 | variable, or the @kbd{I H P} command.) | ||
| 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} |
| 6097 | representation of @c{$\phi$} | 6168 | representation 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} |
| 6171 | is | ||
| 6172 | @texline @tmath{1 + 1/(1 + 1/(1 + 1/( \ldots )))}. | ||
| 6173 | @infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. | ||
| 6100 | We can compute an approximate value by carrying this however far | 6174 | We can compute an approximate value by carrying this however far |
| 6101 | and then replacing the innermost @c{$1/( \ldots )$} | 6175 | and 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. | 6178 | by 1. Approximate |
| 6179 | @texline @tmath{\phi} | ||
| 6180 | @infoline @expr{phi} | ||
| 6181 | using 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 |
| 6108 | Fibonacci numbers can be expressed in terms of matrices. Given a | 6185 | Fibonacci numbers can be expressed in terms of matrices. Given a |
| 6109 | vector @w{@cite{[a, b]}} determine a matrix which, when multiplied by this | 6186 | vector @w{@expr{[a, b]}} determine a matrix which, when multiplied by this |
| 6110 | vector, produces the vector @cite{[b, c]}, where @cite{a}, @cite{b} and | 6187 | vector, 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 |
| 6112 | that, given an integer @cite{n}, computes the @cite{n}th Fibonacci number | 6189 | that, given an integer @expr{n}, computes the @expr{n}th Fibonacci number |
| 6113 | using matrix arithmetic. @xref{Programming Answer 6, 6}. (@bullet{}) | 6190 | using 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. | |||
| 6198 | The @dfn{Bernoulli numbers} are a sequence with the interesting | 6275 | The @dfn{Bernoulli numbers} are a sequence with the interesting |
| 6199 | property that all of the odd Bernoulli numbers are zero, and the | 6276 | property that all of the odd Bernoulli numbers are zero, and the |
| 6200 | even ones, while difficult to compute, can be roughly approximated | 6277 | even ones, while difficult to compute, can be roughly approximated |
| 6201 | by the formula @c{$\displaystyle{2 n! \over (2 \pi)^n}$} | 6278 | by the formula |
| 6202 | @cite{2 n!@: / (2 pi)^n}. Let's write a keyboard | 6279 | @texline @tmath{\displaystyle{2 n! \over (2 \pi)^n}}. |
| 6203 | macro to compute (approximate) Bernoulli numbers. (Calc has a | 6280 | @infoline @expr{2 n!@: / (2 pi)^n}. |
| 6204 | command, @kbd{k b}, to compute exact Bernoulli numbers, but | 6281 | Let's write a keyboard macro to compute (approximate) Bernoulli numbers. |
| 6205 | this 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 |
| 6206 | Bernoulli numbers are very large fractions.) | 6283 | this command is very slow for large @expr{n} since the higher Bernoulli |
| 6284 | numbers 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). | |||
| 6223 | Here we take our integer argument modulo 2; this will be nonzero | 6301 | Here we take our integer argument modulo 2; this will be nonzero |
| 6224 | if we're asking for an odd Bernoulli number. | 6302 | if we're asking for an odd Bernoulli number. |
| 6225 | 6303 | ||
| 6226 | The actual tenth Bernoulli number is @cite{5/66}. | 6304 | The 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 |
| 6356 | equations numerically is @dfn{Newton's Method}. Given the equation | 6434 | equations 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 |
| 6359 | this formula over and over: | 6437 | this 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 |
| 6373 | where @cite{f'(x)} is the derivative of @cite{f}. The @cite{x} | 6451 | where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x} |
| 6374 | values will quickly converge to a solution, i.e., eventually | 6452 | values 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} |
| 6455 | and @expr{x} will be equal to within the limits | ||
| 6377 | of the current precision. Write a program which takes a formula | 6456 | of the current precision. Write a program which takes a formula |
| 6378 | involving the variable @cite{x}, and an initial guess @cite{x_0}, | 6457 | involving the variable @expr{x}, and an initial guess @expr{x_0}, |
| 6379 | on the stack, and produces a value of @cite{x} for which the formula | 6458 | on the stack, and produces a value of @expr{x} for which the formula |
| 6380 | is zero. Use it to find a solution of @c{$\sin(\cos x) = 0.5$} | 6459 | is zero. Use it to find a solution of |
| 6381 | @cite{sin(cos(x)) = 0.5} | 6460 | @texline @tmath{\sin(\cos x) = 0.5} |
| 6382 | near @cite{x = 4.5}. (Use angles measured in radians.) Note that | 6461 | @infoline @expr{sin(cos(x)) = 0.5} |
| 6462 | near @expr{x = 4.5}. (Use angles measured in radians.) Note that | ||
| 6383 | the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's | 6463 | the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's |
| 6384 | method when it is able. @xref{Programming Answer 8, 8}. (@bullet{}) | 6464 | method 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'')} |
| 6391 | is defined as the derivative of @c{$\ln \Gamma(z)$} | 6471 | @infoline @expr{psi(z)} |
| 6392 | @cite{ln(gamma(z))}. For large | 6472 | is defined as the derivative of |
| 6393 | values of @cite{z}, it can be approximated by the infinite sum | 6473 | @texline @tmath{\ln \Gamma(z)}. |
| 6474 | @infoline @expr{ln(gamma(z))}. | ||
| 6475 | For large values of @expr{z}, it can be approximated by the infinite sum | ||
| 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 |
| 6410 | where @c{$\sum$} | 6491 | where |
| 6411 | @cite{sum} represents the sum over @cite{n} from 1 to infinity | 6492 | @texline @tmath{\sum} |
| 6493 | @infoline @expr{sum} | ||
| 6494 | represents 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 |
| 6413 | the @code{bern} function produces (exact) Bernoulli numbers. | 6496 | the @code{bern} function produces (exact) Bernoulli numbers. |
| 6414 | While this sum is not guaranteed to converge, in practice it is safe. | 6497 | While this sum is not guaranteed to converge, in practice it is safe. |
| 6415 | An interesting mathematical constant is Euler's gamma, which is equal | 6498 | An interesting mathematical constant is Euler's gamma, which is equal |
| 6416 | to about 0.5772. One way to compute it is by the formula, | 6499 | to 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)}. |
| 6419 | for the above formula to work (5 is a much safer value for @cite{z}). | 6502 | Unfortunately, 1 isn't a large enough argument |
| 6420 | Fortunately, we can compute @c{$\psi(1)$} | 6503 | for the above formula to work (5 is a much safer value for @expr{z}). |
| 6421 | @cite{psi(1)} from @c{$\psi(5)$} | 6504 | Fortunately, we can compute |
| 6422 | @cite{psi(5)} using | 6505 | @texline @tmath{\psi(1)} |
| 6423 | the 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 | 6507 | from |
| 6425 | a 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)} |
| 6510 | using the recurrence | ||
| 6511 | @texline @tmath{\psi(z+1) = \psi(z) + {1 \over z}}. | ||
| 6512 | @infoline @expr{psi(z+1) = psi(z) + 1/z}. | ||
| 6513 | Your task: Develop a program to compute | ||
| 6514 | @texline @tmath{\psi(z)}; | ||
| 6515 | @infoline @expr{psi(z)}; | ||
| 6516 | it should ``pump up'' @expr{z} | ||
| 6427 | if necessary to be greater than 5, then use the above summation | 6517 | if necessary to be greater than 5, then use the above summation |
| 6428 | formula. Use looping commands to compute the sum. Use your function | 6518 | formula. Use looping commands to compute the sum. Use your function |
| 6429 | to compute @c{$\gamma$} | 6519 | to compute |
| 6430 | @cite{gamma} to twelve decimal places. (Calc has a built-in command | 6520 | @texline @tmath{\gamma} |
| 6521 | @infoline @expr{gamma} | ||
| 6522 | to twelve decimal places. (Calc has a built-in command | ||
| 6431 | for Euler's constant, @kbd{I P}, which you can use to check your answer.) | 6523 | for 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 |
| 6436 | a number @cite{m} on the stack, where the polynomial is of degree | 6528 | a 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}), |
| 6438 | write a program to convert the polynomial into a list-of-coefficients | 6530 | write a program to convert the polynomial into a list-of-coefficients |
| 6439 | notation. For example, @cite{5 x^4 + (x + 1)^2} with @cite{m = 6} | 6531 | notation. For example, @expr{5 x^4 + (x + 1)^2} with @expr{m = 6} |
| 6440 | should produce the list @cite{[1, 2, 1, 0, 5, 0, 0]}. Also develop | 6532 | should produce the list @expr{[1, 2, 1, 0, 5, 0, 0]}. Also develop |
| 6441 | a way to convert from this form back to the standard algebraic form. | 6533 | a 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 | |||
| 6478 | the complete recursive program. (Another way is to use @w{@kbd{Z E}} | 6570 | the complete recursive program. (Another way is to use @w{@kbd{Z E}} |
| 6479 | or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once, | 6571 | or @kbd{M-# m} (@code{read-kbd-macro}) to read the whole macro at once, |
| 6480 | thus avoiding the ``training'' phase.) The task: Write a program | 6572 | thus avoiding the ``training'' phase.) The task: Write a program |
| 6481 | that computes Stirling numbers of the first kind, given @cite{n} and | 6573 | that 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 |
| 6494 | computing Stirling numbers of the first kind, this time using | 6586 | computing Stirling numbers of the first kind, this time using |
| 6495 | rewrite rules. Once again, @cite{n} and @cite{m} should be taken | 6587 | rewrite rules. Once again, @expr{n} and @expr{m} should be taken |
| 6496 | from the stack. @xref{Programming Answer 12, 12}. (@bullet{}) | 6588 | from 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 | ||
| 6604 | The result is @c{$1 - (2 \times (3 + 4)) = -13$} | 6696 | The 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 | ||
| 6614 | After computing the intermediate term @c{$2\times4 = 8$} | 6707 | After computing the intermediate term |
| 6615 | @cite{2*4 = 8}, you can leave | 6708 | @texline @tmath{2\times4 = 8}, |
| 6616 | that result on the stack while you compute the second term. With | 6709 | @infoline @expr{2*4 = 8}, |
| 6617 | both of these results waiting on the stack you can then compute the | 6710 | you can leave that result on the stack while you compute the second |
| 6618 | final term, then press @kbd{+ +} to add everything up. | 6711 | term. With both of these results waiting on the stack you can then |
| 6712 | compute the final term, then press @kbd{+ +} to add everything up. | ||
| 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}}. | |||
| 6739 | Or, RPN style, @kbd{0.5 ^}. | 6833 | Or, 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 |
| 6742 | a closer equivalent, since @samp{9^0.5} yields @cite{3.0} whereas | 6836 | a 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 |
| 6758 | The result from @kbd{1 @key{RET} 0 /} will be the formula @cite{1 / 0}. | 6852 | The result from @kbd{1 @key{RET} 0 /} will be the formula @expr{1 / 0}. |
| 6759 | The ``function'' @samp{/} cannot be evaluated when its second argument | 6853 | The ``function'' @samp{/} cannot be evaluated when its second argument |
| 6760 | is zero, so it is left in symbolic form. When you now type @kbd{0 *}, | 6854 | is zero, so it is left in symbolic form. When you now type @kbd{0 *}, |
| 6761 | the result will be zero because Calc uses the general rule that ``zero | 6855 | the result will be zero because Calc uses the general rule that ``zero |
| 6762 | times anything is zero.'' | 6856 | times anything is zero.'' |
| 6763 | 6857 | ||
| 6764 | @c [fix-ref Infinities] | 6858 | @c [fix-ref Infinities] |
| 6765 | The @kbd{m i} command enables an @dfn{infinite mode} in which @cite{1 / 0} | 6859 | The @kbd{m i} command enables an @dfn{infinite mode} in which @expr{1 / 0} |
| 6766 | results in a special symbol that represents ``infinity.'' If you | 6860 | results in a special symbol that represents ``infinity.'' If you |
| 6767 | multiply infinity by zero, Calc uses another special new symbol to | 6861 | multiply infinity by zero, Calc uses another special new symbol to |
| 6768 | show that the answer is ``indeterminate.'' @xref{Infinities}, for | 6862 | show 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 |
| 6855 | The answer he got was @cite{0.5000000000006399}. | 6949 | The answer he got was @expr{0.5000000000006399}. |
| 6856 | 6950 | ||
| 6857 | The problem is not that the square operation is inexact, but that the | 6951 | The problem is not that the square operation is inexact, but that the |
| 6858 | sine of 45 that was already on the stack was accurate to only 12 places. | 6952 | sine 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 |
| 6918 | Dividing two integers that are larger than the current precision may | 7012 | Dividing two integers that are larger than the current precision may |
| 6919 | give a floating-point result that is inaccurate even when rounded | 7013 | give a floating-point result that is inaccurate even when rounded |
| 6920 | down to an integer. Consider @cite{123456789 / 2} when the current | 7014 | down to an integer. Consider @expr{123456789 / 2} when the current |
| 6921 | precision is 6 digits. The true answer is @cite{61728394.5}, but | 7015 | precision is 6 digits. The true answer is @expr{61728394.5}, but |
| 6922 | with a precision of 6 this will be rounded to @c{$12345700.0/2.0 = 61728500.0$} | 7016 | with 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.}. | ||
| 6924 | The result, when converted to an integer, will be off by 106. | 7019 | The result, when converted to an integer, will be off by 106. |
| 6925 | 7020 | ||
| 6926 | Here are two solutions: Raise the precision enough that the | 7021 | Here are two solutions: Raise the precision enough that the |
| 6927 | floating-point round-off error is strictly to the right of the | 7022 | floating-point round-off error is strictly to the right of the |
| 6928 | decimal point. Or, convert to fraction mode so that @cite{123456789 / 2} | 7023 | decimal point. Or, convert to fraction mode so that @expr{123456789 / 2} |
| 6929 | produces the exact fraction @cite{123456789:2}, which can be rounded | 7024 | produces the exact fraction @expr{123456789:2}, which can be rounded |
| 6930 | down by the @kbd{F} command without ever switching to floating-point | 7025 | down by the @kbd{F} command without ever switching to floating-point |
| 6931 | format. | 7026 | format. |
| 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 |
| 6938 | does a floating-point calculation instead and produces @cite{1.5}. | 7033 | does a floating-point calculation instead and produces @expr{1.5}. |
| 6939 | 7034 | ||
| 6940 | Calc will find an exact result for a logarithm if the result is an integer | 7035 | Calc will find an exact result for a logarithm if the result is an integer |
| 6941 | or the reciprocal of an integer. But there is no efficient way to search | 7036 | or 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 |
| 7032 | To solve @c{$A^T A \, X = A^T B$} | 7127 | To 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$} | 7130 | first we compute |
| 7036 | @cite{B2 = trn(A) * B}; now, we have a | 7131 | @texline @tmath{A' = A^T A} |
| 7037 | system @c{$A' X = B'$} | 7132 | @infoline @expr{A2 = trn(A) * A} |
| 7038 | @cite{A2 * X = B2} which we can solve using Calc's @samp{/} | 7133 | and |
| 7039 | command. | 7134 | @texline @tmath{B' = A^T B}; |
| 7135 | @infoline @expr{B2 = trn(A) * B}; | ||
| 7136 | now, we have a system | ||
| 7137 | @texline @tmath{A' X = B'} | ||
| 7138 | @infoline @expr{A2 * X = B2} | ||
| 7139 | which we can solve using Calc's @samp{/} command. | ||
| 7040 | 7140 | ||
| 7041 | @ifinfo | 7141 | @ifinfo |
| 7042 | @example | 7142 | @example |
| @@ -7066,8 +7166,9 @@ $$ | |||
| 7066 | 7166 | ||
| 7067 | The first step is to enter the coefficient matrix. We'll store it in | 7167 | The first step is to enter the coefficient matrix. We'll store it in |
| 7068 | quick variable number 7 for later reference. Next, we compute the | 7168 | quick 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} |
| 7171 | vector. | ||
| 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 |
| 7085 | Now we compute the matrix @c{$A'$} | 7186 | Now we compute the matrix |
| 7086 | @cite{A2} and divide. | 7187 | @texline @tmath{A'} |
| 7188 | @infoline @expr{A2} | ||
| 7189 | and 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 |
| 7102 | round-off error.) | 7205 | round-off error.) |
| 7103 | 7206 | ||
| 7104 | Notice that the answers are similar to those for the @c{$3\times3$} | 7207 | Notice that the answers are similar to those for the |
| 7105 | @asis{3x3} system | 7208 | @texline @tmath{3\times3} |
| 7106 | solved in the text. That's because the fourth equation that was | 7209 | @infoline 3x3 |
| 7210 | system solved in the text. That's because the fourth equation that was | ||
| 7107 | added to the system is almost identical to the first one multiplied | 7211 | added to the system is almost identical to the first one multiplied |
| 7108 | by two. (If it were identical, we would have gotten the exact same | 7212 | by two. (If it were identical, we would have gotten the exact same |
| 7109 | answer since the @c{$4\times3$} | 7213 | answer 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 |
| 7216 | system would be equivalent to the original | ||
| 7217 | @texline @tmath{3\times3} | ||
| 7218 | @infoline 3x3 | ||
| 7112 | system.) | 7219 | system.) |
| 7113 | 7220 | ||
| 7114 | Since the first and fourth equations aren't quite equivalent, they | 7221 | Since 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 |
| 7132 | This is reasonably close to our original @cite{B} vector, | 7239 | This 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 |
| 7171 | Given @cite{x} and @cite{y} vectors in quick variables 1 and 2 as before, | 7278 | Given @expr{x} and @expr{y} vectors in quick variables 1 and 2 as before, |
| 7172 | the first job is to form the matrix that describes the problem. | 7279 | the 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 | ||
| 7186 | Thus we want a @c{$19\times2$} | 7293 | Thus we want a |
| 7187 | @asis{19x2} matrix with our @cite{x} vector as one column and | 7294 | @texline @tmath{19\times2} |
| 7295 | @infoline 19x2 | ||
| 7296 | matrix with our @expr{x} vector as one column and | ||
| 7188 | ones as the other column. So, first we build the column of ones, then | 7297 | ones as the other column. So, first we build the column of ones, then |
| 7189 | we combine the two columns to form our @cite{A} matrix. | 7298 | we 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 |
| 7203 | Now we compute @c{$A^T y$} | 7312 | Now 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} |
| 7315 | and | ||
| 7316 | @texline @tmath{A^T A} | ||
| 7317 | @infoline @expr{trn(A) * A} | ||
| 7318 | and 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 | ||
| 7230 | Since we were solving equations of the form @c{$m \times x + b \times 1 = y$} | 7343 | Since 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}, |
| 7232 | numbers should be @cite{m} and @cite{b}, respectively. Sure enough, they | 7345 | @infoline @expr{m*x + b*1 = y}, |
| 7233 | agree exactly with the result computed using @kbd{V M} and @kbd{V R}! | 7346 | these numbers should be @expr{m} and @expr{b}, respectively. Sure |
| 7347 | enough, they agree exactly with the result computed using @kbd{V M} and | ||
| 7348 | @kbd{V R}! | ||
| 7234 | 7349 | ||
| 7235 | The moral of this story: @kbd{V M} and @kbd{V R} will probably solve | 7350 | The moral of this story: @kbd{V M} and @kbd{V R} will probably solve |
| 7236 | your problem, but there is often an easier way using the higher-level | 7351 | your 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 |
| 7291 | A number @cite{j} is a divisor of @cite{n} if @c{$n \mathbin{\hbox{\code{\%}}} j = 0$} | 7406 | A 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}. |
| 7293 | step is to get a vector that identifies the divisors. | 7408 | @infoline @samp{n % j = 0}. |
| 7409 | The 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 | |||
| 7358 | zero, so adding zeros on the left and right is safe. From then on | 7474 | zero, so adding zeros on the left and right is safe. From then on |
| 7359 | the job is pretty straightforward. | 7475 | the job is pretty straightforward. |
| 7360 | 7476 | ||
| 7361 | Incidentally, Calc provides the @c{\dfn{M\"obius} $\mu$} | 7477 | Incidentally, Calc provides the |
| 7362 | @dfn{Moebius mu} function which is | 7478 | @texline @dfn{M@"obius} @tmath{\mu} |
| 7363 | zero if and only if its argument is square-free. It would be a much | 7479 | @infoline @dfn{Moebius mu} |
| 7364 | more convenient way to do the above test in practice. | 7480 | function which is zero if and only if its argument is square-free. It |
| 7481 | would be a much more convenient way to do the above test in practice. | ||
| 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 | ||
| 7391 | The numbers down the lefthand edge of the list we desire are called | 7508 | The numbers down the lefthand edge of the list we desire are called |
| 7392 | the ``triangular numbers'' (now you know why!). The @cite{n}th | 7509 | the ``triangular numbers'' (now you know why!). The @expr{n}th |
| 7393 | triangular number is the sum of the integers from 1 to @cite{n}, and | 7510 | triangular number is the sum of the integers from 1 to @expr{n}, and |
| 7394 | can be computed directly by the formula @c{$n (n+1) \over 2$} | 7511 | can 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 |
| 7449 | The first step is to build a list of values of @cite{x}. | 7567 | The 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 |
| 7488 | It's a good idea to verify, as in the last step above, that only | 7606 | It's a good idea to verify, as in the last step above, that only |
| 7489 | one value is equal to the maximum. (After all, a plot of @c{$\sin x$} | 7607 | one 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)} | ||
| 7491 | might have many points all equal to the maximum value, 1.) | 7610 | might have many points all equal to the maximum value, 1.) |
| 7492 | 7611 | ||
| 7493 | The vector we have now has a single 1 in the position that indicates | 7612 | The vector we have now has a single 1 in the position that indicates |
| 7494 | the maximum value of @cite{x}. Now it is a simple matter to convert | 7613 | the maximum value of @expr{x}. Now it is a simple matter to convert |
| 7495 | this back into the corresponding value itself. | 7614 | this 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 | ||
| 7507 | If @kbd{a =} had produced more than one @cite{1} value, this method | 7626 | If @kbd{a =} had produced more than one @expr{1} value, this method |
| 7508 | would have given the sum of all maximum @cite{x} values; not very | 7627 | would have given the sum of all maximum @expr{x} values; not very |
| 7509 | useful! In this case we could have used @kbd{v m} (@code{calc-mask-vector}) | 7628 | useful! In this case we could have used @kbd{v m} (@code{calc-mask-vector}) |
| 7510 | instead. This command deletes all elements of a ``data'' vector that | 7629 | instead. This command deletes all elements of a ``data'' vector that |
| 7511 | correspond to zeros in a ``mask'' vector, leaving us with, in this | 7630 | correspond to zeros in a ``mask'' vector, leaving us with, in this |
| 7512 | example, a vector of maximum @cite{x} values. | 7631 | example, a vector of maximum @expr{x} values. |
| 7513 | 7632 | ||
| 7514 | The built-in @kbd{a X} command maximizes a function using more | 7633 | The built-in @kbd{a X} command maximizes a function using more |
| 7515 | efficient methods. Just for illustration, let's use @kbd{a X} | 7634 | efficient 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 |
| 7529 | The output from @kbd{a X} is a vector containing the value of @cite{x} | 7648 | The output from @kbd{a X} is a vector containing the value of @expr{x} |
| 7530 | that maximizes the function, and the function's value at that maximum. | 7649 | that maximizes the function, and the function's value at that maximum. |
| 7531 | As you can see, our simple search got quite close to the right answer. | 7650 | As 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 |
| 7659 | For the list @cite{[a, b, c, d]}, the result is @cite{((a = b) = c) = d}, | 7778 | For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d}, |
| 7660 | which will compare @cite{a} and @cite{b} to produce a 1 or 0, which is | 7779 | which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is |
| 7661 | then compared with @cite{c} to produce another 1 or 0, which is then | 7780 | then compared with @expr{c} to produce another 1 or 0, which is then |
| 7662 | compared with @cite{d}. This is not at all what Joe wanted. | 7781 | compared with @expr{d}. This is not at all what Joe wanted. |
| 7663 | 7782 | ||
| 7664 | Here's a more correct method: | 7783 | Here'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 |
| 7690 | The circle of unit radius consists of those points @cite{(x,y)} for which | 7809 | The 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} |
| 7692 | and a vector of @cite{y^2}. | 7811 | and a vector of @expr{y^2}. |
| 7693 | 7812 | ||
| 7694 | We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} | 7813 | We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} |
| 7695 | commands. | 7814 | commands. |
| @@ -7715,7 +7834,7 @@ commands. | |||
| 7715 | @end group | 7834 | @end group |
| 7716 | @end smallexample | 7835 | @end smallexample |
| 7717 | 7836 | ||
| 7718 | Now we sum the @cite{x^2} and @cite{y^2} values, compare with 1 to | 7837 | Now we sum the @expr{x^2} and @expr{y^2} values, compare with 1 to |
| 7719 | get a vector of 1/0 truth values, then sum the truth values. | 7838 | get 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 |
| 7731 | The ratio @cite{84/100} should approximate the ratio @c{$\pi/4$} | 7850 | The 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 |
| 7758 | This problem can be made a lot easier by taking advantage of some | 7876 | This problem can be made a lot easier by taking advantage of some |
| 7759 | symmetries. First of all, after some thought it's clear that the | 7877 | symmetries. 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} |
| 7761 | component for one end of the match, pick a random direction @c{$\theta$} | 7879 | component for one end of the match, pick a random direction |
| 7762 | @cite{theta}, | 7880 | @texline @tmath{\theta}, |
| 7763 | and see if @cite{x} and @c{$x + \cos \theta$} | 7881 | @infoline @expr{theta}, |
| 7764 | @cite{x + cos(theta)} (which is the @cite{x} | 7882 | and see if @expr{x} and |
| 7765 | coordinate of the other endpoint) cross a line. The lines are at | 7883 | @texline @tmath{x + \cos \theta} |
| 7766 | integer coordinates, so this happens when the two numbers surround | 7884 | @infoline @expr{x + cos(theta)} |
| 7767 | an integer. | 7885 | (which is the @expr{x} coordinate of the other endpoint) cross a line. |
| 7886 | The lines are at integer coordinates, so this happens when the two | ||
| 7887 | numbers surround an integer. | ||
| 7768 | 7888 | ||
| 7769 | Since the two endpoints are equivalent, we may as well choose the leftmost | 7889 | Since the two endpoints are equivalent, we may as well choose the leftmost |
| 7770 | of the two endpoints as @cite{x}. Then @cite{theta} is an angle pointing | 7890 | of the two endpoints as @expr{x}. Then @expr{theta} is an angle pointing |
| 7771 | to the right, in the range -90 to 90 degrees. (We could use radians, but | 7891 | to the right, in the range -90 to 90 degrees. (We could use radians, but |
| 7772 | it would feel like cheating to refer to @c{$\pi/2$} | 7892 | it would feel like cheating to refer to @cpiover{2} radians while trying |
| 7773 | @cite{pi/2} radians while trying | 7893 | to estimate @cpi{}!) |
| 7774 | to estimate @c{$\pi$} | ||
| 7775 | @cite{pi}!) | ||
| 7776 | 7894 | ||
| 7777 | In fact, since the field of lines is infinite we can choose the | 7895 | In fact, since the field of lines is infinite we can choose the |
| 7778 | coordinates 0 and 1 for the lines on either side of the leftmost | 7896 | coordinates 0 and 1 for the lines on either side of the leftmost |
| 7779 | endpoint. The rightmost endpoint will be between 0 and 1 if the | 7897 | endpoint. The rightmost endpoint will be between 0 and 1 if the |
| 7780 | match does not cross a line, or between 1 and 2 if it does. So: | 7898 | match does not cross a line, or between 1 and 2 if it does. So: |
| 7781 | Pick random @cite{x} and @c{$\theta$} | 7899 | Pick 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}, |
| 7902 | compute | ||
| 7903 | @texline @tmath{x + \cos \theta}, | ||
| 7904 | @infoline @expr{x + cos(theta)}, | ||
| 7784 | and count how many of the results are greater than one. Simple! | 7905 | and count how many of the results are greater than one. Simple! |
| 7785 | 7906 | ||
| 7786 | We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} | 7907 | We 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 | |||
| 7881 | like @kbd{)} and @kbd{]} at the end of a formula. | 8002 | like @kbd{)} and @kbd{]} at the end of a formula. |
| 7882 | 8003 | ||
| 7883 | We'll show two different approaches here. In the first, we note that | 8004 | We'll show two different approaches here. In the first, we note that |
| 7884 | if the input vector is @cite{[a, b, c, d]}, then the hash code is | 8005 | if 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, |
| 7886 | it's a sum of descending powers of three times the ASCII codes. | 8007 | it'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 | ||
| 7946 | Why does this work? Think about a two-step computation: | 8067 | Why 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 |
| 7948 | subtracting off enough 511's to put the result in the desired range. | 8069 | subtracting off enough 511's to put the result in the desired range. |
| 7949 | So the result when we take the modulo after every step is, | 8070 | So 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 |
| 7964 | for some suitable integers @cite{m} and @cite{n}. Expanding out by | 8085 | for some suitable integers @expr{m} and @expr{n}. Expanding out by |
| 7965 | the distributive law yields | 8086 | the 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 |
| 7980 | The @cite{m} term in the latter formula is redundant because any | 8101 | The @expr{m} term in the latter formula is redundant because any |
| 7981 | contribution it makes could just as easily be made by the @cite{n} | 8102 | contribution it makes could just as easily be made by the @expr{n} |
| 7982 | term. So we can take it out to get an equivalent formula with | 8103 | term. 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 | ||
| 8008 | We want to use @kbd{H V U} to nest a function which adds a random | 8129 | We want to use @kbd{H V U} to nest a function which adds a random |
| 8009 | step to an @cite{(x,y)} coordinate. The function is a bit long, but | 8130 | step to an @expr{(x,y)} coordinate. The function is a bit long, but |
| 8010 | otherwise the problem is quite straightforward. | 8131 | otherwise 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 | |||
| 8024 | notation to keep the two @code{random} calls from being evaluated | 8145 | notation to keep the two @code{random} calls from being evaluated |
| 8025 | before nesting even begins. | 8146 | before nesting even begins. |
| 8026 | 8147 | ||
| 8027 | We now have a vector of @cite{[x, y]} sub-vectors, which by Calc's | 8148 | We now have a vector of @expr{[x, y]} sub-vectors, which by Calc's |
| 8028 | rules acts like a matrix. We can transpose this matrix and unpack | 8149 | rules acts like a matrix. We can transpose this matrix and unpack |
| 8029 | to get a pair of vectors, @cite{x} and @cite{y}, suitable for graphing. | 8150 | to 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 | ||
| 8041 | Incidentally, because the @cite{x} and @cite{y} are completely | 8162 | Incidentally, because the @expr{x} and @expr{y} are completely |
| 8042 | independent in this case, we could have done two separate commands | 8163 | independent in this case, we could have done two separate commands |
| 8043 | to create our @cite{x} and @cite{y} vectors of numbers directly. | 8164 | to create our @expr{x} and @expr{y} vectors of numbers directly. |
| 8044 | 8165 | ||
| 8045 | To make a random walk of unit steps, we note that @code{sincos} of | 8166 | To make a random walk of unit steps, we note that @code{sincos} of |
| 8046 | a random direction exactly gives us an @cite{[x, y]} step of unit | 8167 | a random direction exactly gives us an @expr{[x, y]} step of unit |
| 8047 | length; in fact, the new nesting function is even briefer, though | 8168 | length; in fact, the new nesting function is even briefer, though |
| 8048 | we might want to lower the precision a bit for it. | 8169 | we 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 |
| 8074 | If the number is the square root of @c{$\pi$} | 8195 | If the number is the square root of @cpi{} times a rational number, |
| 8075 | @cite{pi} times a rational number, | 8196 | then its square, divided by @cpi{}, should be a rational number. |
| 8076 | then 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 |
| 8107 | Aha! It's unlikely that an irrational number would equal a fraction | 8226 | Aha! It's unlikely that an irrational number would equal a fraction |
| 8108 | this simple to within ten digits, so our original number was probably | 8227 | this 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 | ||
| 8112 | Notice that we didn't need to re-round the number when we reduced the | 8231 | Notice that we didn't need to re-round the number when we reduced the |
| 8113 | precision. Remember, arithmetic operations always round their inputs | 8232 | precision. 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 |
| 8124 | of infinity must be ``bigger'' than ``regular'' infinity, but as | 8243 | of infinity must be ``bigger'' than ``regular'' infinity, but as |
| 8125 | far as Calc is concerned all infinities are as just as big. | 8244 | far as Calc is concerned all infinities are as just as big. |
| 8126 | In other words, as @cite{x} goes to infinity, @cite{e^x} also goes | 8245 | In other words, as @expr{x} goes to infinity, @expr{e^x} also goes |
| 8127 | to infinity, but the fact the @cite{e^x} grows much faster than | 8246 | to 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 |
| 8131 | the input is infinite. | 8250 | the 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)} |
| 8134 | represents the imaginary number @cite{i}. Here's a derivation: | 8253 | represents 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)}. |
| 8136 | The first part is, by definition, @cite{i}; the second is @code{inf} | 8255 | The first part is, by definition, @expr{i}; the second is @code{inf} |
| 8137 | because, once again, all infinities are the same size. | 8256 | because, 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 | |||
| 8141 | right half of the complex plane. But Calc has no notation for this, | 8260 | right half of the complex plane. But Calc has no notation for this, |
| 8142 | so it settles for the conservative answer @code{uinf}. | 8261 | so 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 |
| 8148 | input. As in the @cite{1 / 0} case, Calc will only use infinities | 8267 | input. As in the @expr{1 / 0} case, Calc will only use infinities |
| 8149 | here if you have turned on ``infinite'' mode. Otherwise, it will | 8268 | here if you have turned on ``infinite'' mode. Otherwise, it will |
| 8150 | treat @samp{ln(0)} as an error. | 8269 | treat @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 |
| 8156 | We can make @samp{inf - inf} be any real number we like, say, | 8275 | We 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 |
| 8158 | infinity but not to the second. This is just as true for complex | 8277 | infinity but not to the second. This is just as true for complex |
| 8159 | values of @cite{a}, so @code{nan} can stand for a complex number. | 8278 | values 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 |
| 8161 | in any direction in the complex plane, such as @samp{(0, 1) inf}). | 8280 | in 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 |
| 8406 | Testing the first number, we might arbitrarily choose 17 for @cite{x}. | 8525 | Testing 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 |
| 8438 | The result is three ones (modulo @cite{n}), so it's very probable that | 8557 | The result is three ones (modulo @expr{n}), so it's very probable that |
| 8439 | 15485863 is prime. (In fact, this number is the millionth prime.) | 8558 | 15485863 is prime. (In fact, this number is the millionth prime.) |
| 8440 | 8559 | ||
| 8441 | Note that the functions @samp{($$^($-1)) mod $} or @samp{$$^($-1) % $} | 8560 | Note 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] |
| 8607 | The result @samp{sqrt(x)^2} is simplified back to @cite{x} by the | 8726 | The result @samp{sqrt(x)^2} is simplified back to @expr{x} by the |
| 8608 | Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens | 8727 | Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens |
| 8609 | if @w{@cite{x = -4}}.) If @cite{x} is real, this formula could be | 8728 | if @w{@expr{x = -4}}.) If @expr{x} is real, this formula could be |
| 8610 | simplified to @samp{abs(x)}, but for general complex arguments even | 8729 | simplified to @samp{abs(x)}, but for general complex arguments even |
| 8611 | that is not safe. (@xref{Declarations}, for a way to tell Calc | 8730 | that is not safe. (@xref{Declarations}, for a way to tell Calc |
| 8612 | that @cite{x} is known to be real.) | 8731 | that @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 |
| 8618 | Suppose our roots are @cite{[a, b, c]}. We want a polynomial which | 8737 | Suppose our roots are @expr{[a, b, c]}. We want a polynomial which |
| 8619 | is zero when @cite{x} is any of these values. The trivial polynomial | 8738 | is 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)} |
| 8621 | will do the job. We can use @kbd{a c x} to write this in a more | 8740 | will do the job. We can use @kbd{a c x} to write this in a more |
| 8622 | familiar form. | 8741 | familiar 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 |
| 8811 | Multiplying by the conjugate helps because @cite{(a+b) (a-b) = a^2 - b^2}. | 8930 | Multiplying 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 | |||
| 8858 | into a three-argument @code{fib} that makes computation easier. The | 8977 | into a three-argument @code{fib} that makes computation easier. The |
| 8859 | second rule converts back from three-argument form once the computation | 8978 | second rule converts back from three-argument form once the computation |
| 8860 | is done. The third rule does the computation itself. It basically | 8979 | is done. The third rule does the computation itself. It basically |
| 8861 | says that if @cite{x} and @cite{y} are two consecutive Fibonacci numbers, | 8980 | says that if @expr{x} and @expr{y} are two consecutive Fibonacci numbers, |
| 8862 | then @cite{y} and @cite{x+y} are the next (overlapping) pair of Fibonacci | 8981 | then @expr{y} and @expr{x+y} are the next (overlapping) pair of Fibonacci |
| 8863 | numbers. | 8982 | numbers. |
| 8864 | 8983 | ||
| 8865 | Notice that because the number @cite{n} was ``validated'' by the | 8984 | Notice that because the number @expr{n} was ``validated'' by the |
| 8866 | conditions on the first rule, there is no need to put conditions on | 8985 | conditions on the first rule, there is no need to put conditions on |
| 8867 | the other rules because the rule set would never get that far unless | 8986 | the other rules because the rule set would never get that far unless |
| 8868 | the input were valid. That further speeds computation, since no | 8987 | the 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 |
| 8960 | Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. | 9079 | Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}. |
| 8961 | 9080 | ||
| 8962 | Notice that the @cite{n > 1} guard is no longer necessary on the last | 9081 | Notice that the @expr{n > 1} guard is no longer necessary on the last |
| 8963 | rule since the @cite{n = 1} case is now detected by another rule. | 9082 | rule since the @expr{n = 1} case is now detected by another rule. |
| 8964 | But a guard has been added to the initial rule to make sure the | 9083 | But a guard has been added to the initial rule to make sure the |
| 8965 | initial value is suitable before the computation begins. | 9084 | initial 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 |
| 8981 | If @cite{x} is the sum @cite{a + b}, then `@t{nterms(}@var{x}@t{)}' must | 9100 | If @expr{x} is the sum @expr{a + b}, then `@t{nterms(}@var{x}@t{)}' must |
| 8982 | be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @cite{x} | 9101 | be `@t{nterms(}@var{a}@t{)}' plus `@t{nterms(}@var{b}@t{)}'. If @expr{x} |
| 8983 | is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1. | 9102 | is not a sum, then `@t{nterms(}@var{x}@t{)}' = 1. |
| 8984 | 9103 | ||
| 8985 | @smallexample | 9104 | @smallexample |
| @@ -9026,7 +9145,7 @@ But then: | |||
| 9026 | Perhaps more surprisingly, this rule still works with infinite mode | 9145 | Perhaps more surprisingly, this rule still works with infinite mode |
| 9027 | turned on. Calc tries @code{EvalRules} before any built-in rules for | 9146 | turned on. Calc tries @code{EvalRules} before any built-in rules for |
| 9028 | a function. This allows you to override the default behavior of any | 9147 | a function. This allows you to override the default behavior of any |
| 9029 | Calc feature: Even though Calc now wants to evaluate @cite{0^0} to | 9148 | Calc 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 | ||
| 9032 | Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}. | 9151 | Just 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. | |||
| 9085 | Another way to solve this problem would be to create a new ``data type'' | 9204 | Another way to solve this problem would be to create a new ``data type'' |
| 9086 | that represents truncated power series. We might represent these as | 9205 | that represents truncated power series. We might represent these as |
| 9087 | function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is | 9206 | function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is |
| 9088 | a vector of coefficients for @cite{x^0}, @cite{x^1}, @cite{x^2}, and so | 9207 | a vector of coefficients for @expr{x^0}, @expr{x^1}, @expr{x^2}, and so |
| 9089 | on. Rules would exist for sums and products of such @code{series} | 9208 | on. Rules would exist for sums and products of such @code{series} |
| 9090 | objects, and as an optional convenience could also know how to combine a | 9209 | objects, 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.) | |||
| 9115 | Just enter the formula @samp{ninteg(sin(t)/t, t, 0, x)}, type | 9234 | Just 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 |
| 9117 | variables, the default argument list will be @samp{(t x)}. We want to | 9236 | variables, the default argument list will be @samp{(t x)}. We want to |
| 9118 | change this to @samp{(x)} since @cite{t} is really a dummy variable | 9237 | change this to @samp{(x)} since @expr{t} is really a dummy variable |
| 9119 | to be used within @code{ninteg}. | 9238 | to be used within @code{ninteg}. |
| 9120 | 9239 | ||
| 9121 | The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}. | 9240 | The exact keystrokes are @kbd{Z F s Si @key{RET} @key{RET} C-b C-b @key{DEL} @key{DEL} @key{RET} y}. |
| @@ -9146,8 +9265,9 @@ Each of these functions can be computed using the stack, or using | |||
| 9146 | algebraic entry, whichever way you prefer: | 9265 | algebraic entry, whichever way you prefer: |
| 9147 | 9266 | ||
| 9148 | @noindent | 9267 | @noindent |
| 9149 | Computing @c{$\displaystyle{\sin x \over x}$} | 9268 | Computing |
| 9150 | @cite{sin(x) / x}: | 9269 | @texline @tmath{\displaystyle{\sin x \over x}}: |
| 9270 | @infoline @expr{sin(x) / x}: | ||
| 9151 | 9271 | ||
| 9152 | Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. | 9272 | Using 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 |
| 9210 | Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @cite{n+1} | 9330 | Thus @samp{[0, 1; 1, 1]^n * [1, 1]} computes Fibonacci numbers @expr{n+1} |
| 9211 | and @cite{n+2}. Here's one program that does the job: | 9331 | and @expr{n+2}. Here's one program that does the job: |
| 9212 | 9332 | ||
| 9213 | @example | 9333 | @example |
| 9214 | C-x ( ' [0, 1; 1, 1] ^ ($-1) * [1, 1] @key{RET} v u @key{DEL} C-x ) | 9334 | C-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 |
| 9218 | This program is quite efficient because Calc knows how to raise a | 9338 | This program is quite efficient because Calc knows how to raise a |
| 9219 | matrix (or other value) to the power @cite{n} in only @c{$\log_2 n$} | 9339 | matrix (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)} | ||
| 9221 | steps. For example, this program can compute the 1000th Fibonacci | 9342 | steps. For example, this program can compute the 1000th Fibonacci |
| 9222 | number (a 209-digit integer!) in about 10 steps; even though the | 9343 | number (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 |
| 9271 | The first step is to compute the derivative @cite{f'(x)} and thus | 9392 | The first step is to compute the derivative @expr{f'(x)} and thus |
| 9272 | the formula @c{$\displaystyle{x - {f(x) \over f'(x)}}$} | 9393 | the 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 |
| 9276 | below. You can use @w{@kbd{M-# m}} to load it from there. While you are | 9398 | below. 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 | ||
| 9320 | This is the new guess for @cite{x}. Now we compare it with the | 9442 | This is the new guess for @expr{x}. Now we compare it with the |
| 9321 | old one to see if we've converged. | 9443 | old 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 |
| 9386 | The first step is to adjust @cite{z} to be greater than 5. A simple | 9508 | The 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 |
| 9388 | reduce the problem using @c{$\psi(z) = \psi(z+1) - 1/z$} | 9510 | reduce the problem using |
| 9389 | @cite{psi(z) = psi(z+1) - 1/z}. We go | 9511 | @texline @tmath{\psi(z) = \psi(z+1) - 1/z}. |
| 9390 | on 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 | 9513 | on 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)}, | ||
| 9516 | and remember to add back a factor of @expr{-1/z} when we're done. This | ||
| 9517 | step is repeated until @expr{z > 5}. | ||
| 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 |
| 9395 | below. You can use @w{@kbd{M-# m}} to load it from there. While you are | 9520 | below. 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 | ||
| 9410 | Here, variable 1 holds @cite{z} and variable 2 holds the adjustment | 9535 | Here, variable 1 holds @expr{z} and variable 2 holds the adjustment |
| 9411 | factor. If @cite{z < 5}, we use a loop to increase it. | 9536 | factor. 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 |
| 9414 | otherwise the calculation below will try to do exact fractional arithmetic, | 9539 | otherwise 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 | ||
| 9429 | Now we compute the initial part of the sum: @c{$\ln z - {1 \over 2z}$} | 9554 | Now 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} | ||
| 9431 | minus the adjustment factor. | 9557 | minus 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 | ||
| 9443 | Now we evaluate the series. We'll use another ``for'' loop counting | 9569 | Now we evaluate the series. We'll use another ``for'' loop counting |
| 9444 | up the value of @cite{2 n}. (Calc does have a summation command, | 9570 | up 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 | ||
| 9471 | This is the value of @c{$-\gamma$} | 9597 | This is the value of |
| 9472 | @cite{- gamma}, with a slight bit of roundoff error. | 9598 | @texline @tmath{-\gamma}, |
| 9473 | To get a full 12 digits, let's use a higher precision: | 9599 | @infoline @expr{- gamma}, |
| 9600 | with a slight bit of roundoff error. To get a full 12 digits, let's use | ||
| 9601 | a 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 |
| 9503 | Taking the derivative of a term of the form @cite{x^n} will produce | 9631 | Taking the derivative of a term of the form @expr{x^n} will produce |
| 9504 | a term like @c{$n x^{n-1}$} | 9632 | a term like |
| 9505 | @cite{n x^(n-1)}. Taking the derivative of a constant | 9633 | @texline @tmath{n x^{n-1}}. |
| 9506 | produces zero. From this it is easy to see that the @cite{n}th | 9634 | @infoline @expr{n x^(n-1)}. |
| 9507 | derivative of a polynomial, evaluated at @cite{x = 0}, will equal the | 9635 | Taking the derivative of a constant |
| 9508 | coefficient on the @cite{x^n} term times @cite{n!}. | 9636 | produces zero. From this it is easy to see that the @expr{n}th |
| 9637 | derivative of a polynomial, evaluated at @expr{x = 0}, will equal the | ||
| 9638 | coefficient on the @expr{x^n} term times @expr{n!}. | ||
| 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 |
| 9511 | below. You can use @w{@kbd{M-# m}} to load it from there. While you are | 9641 | below. 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 | ||
| 9556 | To convert back, a simple method is just to map the coefficients | 9686 | To convert back, a simple method is just to map the coefficients |
| 9557 | against a table of powers of @cite{x}. | 9687 | against 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. | |||
| 9614 | The last step replaces the 2 that was eaten during the creation | 9744 | The last step replaces the 2 that was eaten during the creation |
| 9615 | of the dummy @kbd{z s} command. Now we move on to the real | 9745 | of the dummy @kbd{z s} command. Now we move on to the real |
| 9616 | definition. The recurrence needs to be rewritten slightly, | 9746 | definition. The recurrence needs to be rewritten slightly, |
| 9617 | to the form @cite{s(n,m) = s(n-1,m-1) - (n-1) s(n-1,m)}. | 9747 | to 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 |
| 9620 | below. You can use @kbd{M-# m} to load it from there.) | 9750 | below. 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 | |||
| 9783 | Calc Trail buffer uses a variant of Calc Mode, so Calculator commands | 9913 | Calc Trail buffer uses a variant of Calc Mode, so Calculator commands |
| 9784 | still work when the trail buffer's window is selected. It is possible | 9914 | still work when the trail buffer's window is selected. It is possible |
| 9785 | to turn the trail window off, but the @samp{*Calc Trail*} buffer itself | 9915 | to turn the trail window off, but the @samp{*Calc Trail*} buffer itself |
| 9786 | still exists and is updated silently. @xref{Trail Commands}.@refill | 9916 | still 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} | |||
| 9805 | key (@code{calc-execute-extended-command}) | 9935 | key (@code{calc-execute-extended-command}) |
| 9806 | is like @kbd{M-x} except that it enters the initial string @samp{calc-} | 9936 | is like @kbd{M-x} except that it enters the initial string @samp{calc-} |
| 9807 | for you. For example, the following key sequences are equivalent: | 9937 | for 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 | |||
| 9818 | little arithmetic. If for some reason the Calculator fails to load an | 9948 | little arithmetic. If for some reason the Calculator fails to load an |
| 9819 | extension module automatically, you can force it to load all the | 9949 | extension module automatically, you can force it to load all the |
| 9820 | extensions by using the @kbd{M-# L} (@code{calc-load-everything}) | 9950 | extensions by using the @kbd{M-# L} (@code{calc-load-everything}) |
| 9821 | command. @xref{Mode Settings}.@refill | 9951 | command. @xref{Mode Settings}. |
| 9822 | 9952 | ||
| 9823 | If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument, | 9953 | If you type @kbd{M-x calc} or @kbd{M-# c} with any numeric prefix argument, |
| 9824 | the Calculator is loaded if necessary, but it is not actually started. | 9954 | the Calculator is loaded if necessary, but it is not actually started. |
| 9825 | If the argument is positive, the @file{calc-ext} extensions are also | 9955 | If the argument is positive, the @file{calc-ext} extensions are also |
| 9826 | loaded if necessary. User-written Lisp code that wishes to make use | 9956 | loaded if necessary. User-written Lisp code that wishes to make use |
| 9827 | of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)} | 9957 | of Calc's arithmetic routines can use @samp{(calc 0)} or @samp{(calc 1)} |
| 9828 | to auto-load the Calculator.@refill | 9958 | to 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 | |||
| 9872 | contents of the stack intact. Typing @kbd{M-# c} or @kbd{M-# M-#} | 10002 | contents of the stack intact. Typing @kbd{M-# c} or @kbd{M-# M-#} |
| 9873 | again from inside the Calculator buffer is equivalent to executing | 10003 | again 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 |
| 9875 | Calculator on and off.@refill | 10005 | Calculator on and off. |
| 9876 | 10006 | ||
| 9877 | @kindex M-# x | 10007 | @kindex M-# x |
| 9878 | The @kbd{M-# x} command also turns the Calculator off, no matter which | 10008 | The @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 |
| 9905 | scrolling commands except that they scroll one half-screen at a time by | 10035 | scrolling commands except that they scroll one half-screen at a time by |
| 9906 | default. (Calc formats its output to fit within the bounds of the | 10036 | default. (Calc formats its output to fit within the bounds of the |
| 9907 | window whenever it can.)@refill | 10037 | window 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 |
| 9914 | The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down} | 10044 | The @kbd{@{} and @kbd{@}} keys are bound to @code{calc-scroll-down} |
| 9915 | and @code{calc-scroll-up}. They scroll up or down by one-half the | 10045 | and @code{calc-scroll-up}. They scroll up or down by one-half the |
| 9916 | height of the Calc window.@refill | 10046 | height 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 |
| 10019 | which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for} | 10149 | which means the command @kbd{H a S} or @kbd{H M-x calc-solve-for} |
| 10020 | takes a value @cite{a} from the stack, prompts for a value @cite{v}, | 10150 | takes a value @expr{a} from the stack, prompts for a value @expr{v}, |
| 10021 | then applies the algebraic function @code{fsolve} to these values. | 10151 | then applies the algebraic function @code{fsolve} to these values. |
| 10022 | The @samp{?=notes} message means you can now type @kbd{?} to see | 10152 | The @samp{?=notes} message means you can now type @kbd{?} to see |
| 10023 | additional notes from the summary that apply to this command. | 10153 | additional 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, |
| 10075 | and pushes the result (3) back onto the stack. This number is ready for | 10205 | and pushes the result (3) back onto the stack. This number is ready for |
| 10076 | further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the | 10206 | further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the |
| 10077 | 3 and 5, subtracts them, and pushes the result (@i{-2}).@refill | 10207 | 3 and 5, subtracts them, and pushes the result (@i{-2}). |
| 10078 | 10208 | ||
| 10079 | Note that the ``top'' of the stack actually appears at the @emph{bottom} | 10209 | Note that the ``top'' of the stack actually appears at the @emph{bottom} |
| 10080 | of the buffer. A line containing a single @samp{.} character signifies | 10210 | of 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 |
| 10104 | would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not} | 10234 | would enter the number 12.) If you press @key{RET} or @key{SPC} @emph{not} |
| 10105 | right after typing a number, the key duplicates the number on the top of | 10235 | right after typing a number, the key duplicates the number on the top of |
| 10106 | the stack. @kbd{@key{RET} *} is thus a handy way to square a number.@refill | 10236 | the stack. @kbd{@key{RET} *} is thus a handy way to square a number. |
| 10107 | 10237 | ||
| 10108 | The @key{DEL} key pops and throws away the top number on the stack. | 10238 | The @key{DEL} key pops and throws away the top number on the stack. |
| 10109 | The @key{TAB} key swaps the top two objects on the stack. | 10239 | The @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 |
| 10111 | commands.@refill | 10241 | commands. |
| 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 _ |
| 10131 | There are three different concepts corresponding to the word ``minus,'' | 10261 | There are three different concepts corresponding to the word ``minus,'' |
| 10132 | typified by @cite{a-b} (subtraction), @cite{-x} | 10262 | typified 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 |
| 10134 | different keys for these operations, respectively: | 10264 | different 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 |
| 10136 | the two numbers on the top of the stack. The @kbd{n} key changes the sign | 10266 | the 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. | |||
| 10138 | The @kbd{_} key begins entry of a negative number or changes the sign of | 10268 | The @kbd{_} key begins entry of a negative number or changes the sign of |
| 10139 | the number currently being entered. The following sequences all enter the | 10269 | the number currently being entered. The following sequences all enter the |
| 10140 | number @i{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, | 10270 | number @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 | ||
| 10143 | Some other keys are active during numeric entry, such as @kbd{#} for | 10273 | Some other keys are active during numeric entry, such as @kbd{#} for |
| 10144 | non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. | 10274 | non-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}. | |||
| 10158 | Calculations can also be entered in algebraic form. This is accomplished | 10288 | Calculations can also be entered in algebraic form. This is accomplished |
| 10159 | by typing the apostrophe key, @kbd{'}, followed by the expression in | 10289 | by typing the apostrophe key, @kbd{'}, followed by the expression in |
| 10160 | standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes | 10290 | standard 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} |
| 10293 | and pushes that on the stack. If you wish you can | ||
| 10163 | ignore the RPN aspect of Calc altogether and simply enter algebraic | 10294 | ignore the RPN aspect of Calc altogether and simply enter algebraic |
| 10164 | expressions in this way. You may want to use @key{DEL} every so often to | 10295 | expressions in this way. You may want to use @key{DEL} every so often to |
| 10165 | clear previous results off the stack.@refill | 10296 | clear previous results off the stack. |
| 10166 | 10297 | ||
| 10167 | You can press the apostrophe key during normal numeric entry to switch | 10298 | You can press the apostrophe key during normal numeric entry to switch |
| 10168 | the half-entered number into algebraic entry mode. One reason to do this | 10299 | the 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 | |||
| 10185 | begin algebraic entry. You can still do RPN calculations in this mode, | 10316 | begin algebraic entry. You can still do RPN calculations in this mode, |
| 10186 | but you will have to press @key{RET} to terminate every number: | 10317 | but 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 |
| 10188 | thing as @kbd{2*3+4 @key{RET}}.@refill | 10319 | thing as @kbd{2*3+4 @key{RET}}. |
| 10189 | 10320 | ||
| 10190 | @cindex Incomplete algebraic mode | 10321 | @cindex Incomplete algebraic mode |
| 10191 | If you give a numeric prefix argument like @kbd{C-u} to the @kbd{m a} | 10322 | If 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 | |||
| 10221 | stack. Thus, @kbd{' 1+2 @key{RET}} pushes 3 on the stack, and @kbd{$*2 | 10352 | stack. 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 |
| 10223 | initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the | 10354 | initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the |
| 10224 | first character in the new formula.@refill | 10355 | first character in the new formula. |
| 10225 | 10356 | ||
| 10226 | Higher stack elements can be accessed from an entered formula with the | 10357 | Higher stack elements can be accessed from an entered formula with the |
| 10227 | symbols @kbd{$$}, @kbd{$$$}, and so on. The number of stack elements | 10358 | symbols @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 | |||
| 10229 | signs in the longest such symbol in the formula. For example, @samp{$$+$$$} | 10360 | signs in the longest such symbol in the formula. For example, @samp{$$+$$$} |
| 10230 | adds the second and third stack elements, replacing the top three elements | 10361 | adds the second and third stack elements, replacing the top three elements |
| 10231 | with the answer. (All information about the top stack element is thus lost | 10362 | with the answer. (All information about the top stack element is thus lost |
| 10232 | since no single @samp{$} appears in this formula.)@refill | 10363 | since no single @samp{$} appears in this formula.) |
| 10233 | 10364 | ||
| 10234 | A slightly different way to refer to stack elements is with a dollar | 10365 | A slightly different way to refer to stack elements is with a dollar |
| 10235 | sign followed by a number: @samp{$1}, @samp{$2}, and so on are much | 10366 | sign 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}) | |||
| 10254 | instead of @key{RET}, Calc disables the default simplifications | 10385 | instead 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 |
| 10256 | is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3 | 10387 | is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3 |
| 10257 | on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @cite{1+2}; | 10388 | on the stack, but @kbd{' 1+2 @key{LFD}} pushes the formula @expr{1+2}; |
| 10258 | you might then press @kbd{=} when it is time to evaluate this formula. | 10389 | you 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 |
| 10334 | the prefix argument or use a default if you don't use a prefix. | 10465 | the prefix argument or use a default if you don't use a prefix. |
| 10335 | Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument | 10466 | Others (like @kbd{d f} (@code{calc-fix-notation})) require an argument |
| 10336 | and prompt for a number if you don't give one as a prefix.@refill | 10467 | and prompt for a number if you don't give one as a prefix. |
| 10337 | 10468 | ||
| 10338 | As a rule, stack-manipulation commands accept a numeric prefix argument | 10469 | As a rule, stack-manipulation commands accept a numeric prefix argument |
| 10339 | which is interpreted as an index into the stack. A positive argument | 10470 | which is interpreted as an index into the stack. A positive argument |
| @@ -10360,7 +10491,7 @@ argument for some other purpose. | |||
| 10360 | Numeric prefixes are specified the same way as always in Emacs: Press | 10491 | Numeric prefixes are specified the same way as always in Emacs: Press |
| 10361 | a sequence of @key{META}-digits, or press @key{ESC} followed by digits, | 10492 | a sequence of @key{META}-digits, or press @key{ESC} followed by digits, |
| 10362 | or press @kbd{C-u} followed by digits. Some commands treat plain | 10493 | or 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 | |||
| 10368 | top of the stack and enter it as the numeric prefix for the next command. | 10499 | top of the stack and enter it as the numeric prefix for the next command. |
| 10369 | For example, @kbd{C-u 16 p} sets the precision to 16 digits; an alternate | 10500 | For 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 |
| 10371 | to the fourth power and set the precision to that value.@refill | 10502 | to the fourth power and set the precision to that value. |
| 10372 | 10503 | ||
| 10373 | Conversely, if you have typed a numeric prefix argument the @kbd{~} key | 10504 | Conversely, if you have typed a numeric prefix argument the @kbd{~} key |
| 10374 | pushes it onto the stack in the form of an integer. | 10505 | pushes 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. | |||
| 10416 | The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that | 10547 | The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that |
| 10417 | it restores the arguments of the most recent command onto the stack; | 10548 | it restores the arguments of the most recent command onto the stack; |
| 10418 | however, it does not remove the result of that command. Given a numeric | 10549 | however, it does not remove the result of that command. Given a numeric |
| 10419 | prefix argument, this command applies to the @cite{n}th most recent | 10550 | prefix argument, this command applies to the @expr{n}th most recent |
| 10420 | command which removed items from the stack; it pushes those items back | 10551 | command which removed items from the stack; it pushes those items back |
| 10421 | onto the stack. | 10552 | onto 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? |
| 10439 | Many situations that would produce an error message in other calculators | 10570 | Many situations that would produce an error message in other calculators |
| 10440 | simply create unsimplified formulas in the Emacs Calculator. For example, | 10571 | simply 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 |
| 10442 | the formula @samp{ln(0)}. Floating-point overflow and underflow are also | 10573 | the formula @samp{ln(0)}. Floating-point overflow and underflow are also |
| 10443 | reasons for this to happen. | 10574 | reasons for this to happen. |
| 10444 | 10575 | ||
| @@ -10543,7 +10674,7 @@ possible in an attempt to recover from program bugs. If a calculation | |||
| 10543 | ever halts incorrectly with the message ``Computation got stuck or | 10674 | ever halts incorrectly with the message ``Computation got stuck or |
| 10544 | ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth}) | 10675 | ran too long,'' use the @kbd{M} command (@code{calc-more-recursion-depth}) |
| 10545 | to increase this limit. (Of course, this will not help if the | 10676 | to increase this limit. (Of course, this will not help if the |
| 10546 | calculation really did get stuck due to some problem inside Calc.)@refill | 10677 | calculation really did get stuck due to some problem inside Calc.) |
| 10547 | 10678 | ||
| 10548 | The limit is always increased (multiplied) by a factor of two. There | 10679 | The limit is always increased (multiplied) by a factor of two. There |
| 10549 | is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which | 10680 | is 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 |
| 10562 | Calc saves certain values after they have been computed once. For | 10693 | Calc saves certain values after they have been computed once. For |
| 10563 | example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the | 10694 | example, the @kbd{P} (@code{calc-pi}) command initially ``knows'' the |
| 10564 | constant @c{$\pi$} | 10695 | constant @cpi{} to about 20 decimal places; if the current precision |
| 10565 | @cite{pi} to about 20 decimal places; if the current precision | 10696 | is greater than this, it will recompute @cpi{} using a series |
| 10566 | is greater than this, it will recompute @c{$\pi$} | ||
| 10567 | @cite{pi} using a series | ||
| 10568 | approximation. This value will not need to be recomputed ever again | 10697 | approximation. This value will not need to be recomputed ever again |
| 10569 | unless you raise the precision still further. Many operations such as | 10698 | unless you raise the precision still further. Many operations such as |
| 10570 | logarithms and sines make use of similarly cached values such as | 10699 | logarithms 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)}. |
| 10703 | The visible effect of caching is that | ||
| 10574 | high-precision computations may seem to do extra work the first time. | 10704 | high-precision computations may seem to do extra work the first time. |
| 10575 | Other things cached include powers of two (for the binary arithmetic | 10705 | Other things cached include powers of two (for the binary arithmetic |
| 10576 | functions), matrix inverses and determinants, symbolic integrals, and | 10706 | functions), matrix inverses and determinants, symbolic integrals, and |
| @@ -10643,7 +10773,7 @@ will be lost. | |||
| 10643 | This chapter discusses the various types of objects that can be placed | 10773 | This chapter discusses the various types of objects that can be placed |
| 10644 | on the Calculator stack, how they are displayed, and how they are | 10774 | on the Calculator stack, how they are displayed, and how they are |
| 10645 | entered. (@xref{Data Type Formats}, for information on how these data | 10775 | entered. (@xref{Data Type Formats}, for information on how these data |
| 10646 | types are represented as underlying Lisp objects.)@refill | 10776 | types are represented as underlying Lisp objects.) |
| 10647 | 10777 | ||
| 10648 | Integers, fractions, and floats are various ways of describing real | 10778 | Integers, fractions, and floats are various ways of describing real |
| 10649 | numbers. HMS forms also for many purposes act as real numbers. These | 10779 | numbers. HMS forms also for many purposes act as real numbers. These |
| @@ -10686,7 +10816,7 @@ floating-point form according to the current Fraction Mode. | |||
| 10686 | A decimal integer is represented as an optional sign followed by a | 10816 | A decimal integer is represented as an optional sign followed by a |
| 10687 | sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to | 10817 | sequence of digits. Grouping (@pxref{Grouping Digits}) can be used to |
| 10688 | insert a comma at every third digit for display purposes, but you | 10818 | insert a comma at every third digit for display purposes, but you |
| 10689 | must not type commas during the entry of numbers.@refill | 10819 | must not type commas during the entry of numbers. |
| 10690 | 10820 | ||
| 10691 | @kindex # | 10821 | @kindex # |
| 10692 | A non-decimal integer is represented as an optional sign, a radix | 10822 | A 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 | |||
| 10695 | digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how | 10825 | digits and do not terminate numeric entry mode. @xref{Radix Modes}, for how |
| 10696 | to set the default radix for display of integers. Numbers of any radix | 10826 | to set the default radix for display of integers. Numbers of any radix |
| 10697 | may be entered at any time. If you press @kbd{#} at the beginning of a | 10827 | may be entered at any time. If you press @kbd{#} at the beginning of a |
| 10698 | number, the current display radix is used.@refill | 10828 | number, 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 /} |
| 10709 | assuming Fraction Mode has been enabled.) | 10839 | assuming Fraction Mode has been enabled.) |
| 10710 | When the Calculator produces a fractional result it always reduces it to | 10840 | When the Calculator produces a fractional result it always reduces it to |
| 10711 | simplest form, which may in fact be an integer.@refill | 10841 | simplest form, which may in fact be an integer. |
| 10712 | 10842 | ||
| 10713 | Fractions may also be entered in a three-part form, where @samp{2:3:4} | 10843 | Fractions may also be entered in a three-part form, where @samp{2:3:4} |
| 10714 | represents two-and-three-quarters. @xref{Fraction Formats}, for fraction | 10844 | represents two-and-three-quarters. @xref{Fraction Formats}, for fraction |
| 10715 | display formats.@refill | 10845 | display formats. |
| 10716 | 10846 | ||
| 10717 | Non-decimal fractions are entered and displayed as | 10847 | Non-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 |
| 10719 | form). The numerator and denominator always use the same radix.@refill | 10849 | form). 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 | |||
| 10726 | A floating-point number or @dfn{float} is a number stored in scientific | 10856 | A floating-point number or @dfn{float} is a number stored in scientific |
| 10727 | notation. The number of significant digits in the fractional part is | 10857 | notation. The number of significant digits in the fractional part is |
| 10728 | governed by the current floating precision (@pxref{Precision}). The | 10858 | governed by the current floating precision (@pxref{Precision}). The |
| 10729 | range of acceptable values is from @c{$10^{-3999999}$} | 10859 | range of acceptable values is from |
| 10730 | @cite{10^-3999999} (inclusive) | 10860 | @texline @tmath{10^{-3999999}} |
| 10731 | to @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}} |
| 10734 | values and zero. | 10864 | @infoline @expr{10^4000000} |
| 10865 | (exclusive), plus the corresponding negative values and zero. | ||
| 10735 | 10866 | ||
| 10736 | Calculations that would exceed the allowable range of values (such | 10867 | Calculations that would exceed the allowable range of values (such |
| 10737 | as @samp{exp(exp(20))}) are left in symbolic form by Calc. The | 10868 | as @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, | |||
| 10772 | accuracy is not rigorously guaranteed. If you suspect the validity of a | 10903 | accuracy is not rigorously guaranteed. If you suspect the validity of a |
| 10773 | result, try doing the same calculation in a higher precision. The | 10904 | result, try doing the same calculation in a higher precision. The |
| 10774 | Calculator's arithmetic is not intended to be IEEE-conformant in any | 10905 | Calculator's arithmetic is not intended to be IEEE-conformant in any |
| 10775 | way.@refill | 10906 | way. |
| 10776 | 10907 | ||
| 10777 | While floats are always @emph{stored} in decimal, they can be entered | 10908 | While floats are always @emph{stored} in decimal, they can be entered |
| 10778 | and displayed in any radix just like integers and fractions. The | 10909 | and 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. |
| 10800 | Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} | 10931 | Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} |
| 10801 | notation; @pxref{Complex Formats}.@refill | 10932 | notation; @pxref{Complex Formats}. |
| 10802 | 10933 | ||
| 10803 | Polar complex numbers are displayed in the form `@t{(}@var{r}@t{;}@c{$\theta$} | 10934 | Polar complex numbers are displayed in the form |
| 10804 | @var{theta}@t{)}' | 10935 | @texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}' |
| 10805 | where @var{r} is the nonnegative magnitude and @c{$\theta$} | 10936 | @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}' |
| 10806 | @var{theta} is the argument | 10937 | where @var{r} is the nonnegative magnitude and |
| 10807 | or phase angle. The range of @c{$\theta$} | 10938 | @texline @tmath{\theta} |
| 10808 | @var{theta} depends on the current angular | 10939 | @infoline @var{theta} |
| 10809 | mode (@pxref{Angular Modes}); it is generally between @i{-180} and | 10940 | is 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} | ||
| 10943 | depends on the current angular mode (@pxref{Angular Modes}); it is | ||
| 10944 | generally between @i{-180} and @i{+180} degrees or the equivalent range | ||
| 10945 | in radians. | ||
| 10811 | 10946 | ||
| 10812 | Complex numbers are entered in stages using incomplete objects. | 10947 | Complex 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 | |||
| 10819 | type. @xref{Polar Mode}. | 10954 | type. @xref{Polar Mode}. |
| 10820 | 10955 | ||
| 10821 | A complex result in which the imaginary part is zero (or the phase angle | 10956 | A complex result in which the imaginary part is zero (or the phase angle |
| 10822 | is 0 or 180 degrees or @c{$\pi$} | 10957 | is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real |
| 10823 | @cite{pi} radians) is automatically converted to a real | ||
| 10824 | number. | 10958 | number. |
| 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. | |||
| 10845 | Mathematically speaking, it is not rigorously correct to treat | 10979 | Mathematically 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 |
| 10847 | so informally. When they say that @samp{1 / inf = 0}, what they | 10981 | so informally. When they say that @samp{1 / inf = 0}, what they |
| 10848 | really mean is that @cite{1 / x}, as @cite{x} becomes larger and | 10982 | really mean is that @expr{1 / x}, as @expr{x} becomes larger and |
| 10849 | larger, becomes arbitrarily close to zero. So you can imagine | 10983 | larger, becomes arbitrarily close to zero. So you can imagine |
| 10850 | that if @cite{x} got ``all the way to infinity,'' then @cite{1 / x} | 10984 | that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x} |
| 10851 | would go all the way to zero. Similarly, when they say that | 10985 | would 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} |
| 10854 | bound as @cite{x} grows. The symbol @samp{-inf} likewise stands | 10988 | @infoline @expr{exp(x)} |
| 10855 | for an infinitely negative real value; for example, we say that | 10989 | grows without bound as @expr{x} grows. The symbol @samp{-inf} likewise |
| 10990 | stands for an infinitely negative real value; for example, we say that | ||
| 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 |
| 10857 | direction on the complex plane: @samp{sqrt(-inf) = i inf}. | 10992 | direction on the complex plane: @samp{sqrt(-inf) = i inf}. |
| 10858 | 10993 | ||
| 10859 | The same concept of limits can be used to define @cite{1 / 0}. We | 10994 | The same concept of limits can be used to define @expr{1 / 0}. We |
| 10860 | really want the value that @cite{1 / x} approaches as @cite{x} | 10995 | really want the value that @expr{1 / x} approaches as @expr{x} |
| 10861 | approaches zero. But if all we have is @cite{1 / 0}, we can't | 10996 | approaches zero. But if all we have is @expr{1 / 0}, we can't |
| 10862 | tell which direction @cite{x} was coming from. If @cite{x} was | 10997 | tell which direction @expr{x} was coming from. If @expr{x} was |
| 10863 | positive and decreasing toward zero, then we should say that | 10998 | positive 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 |
| 10865 | toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @cite{x} | 11000 | toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @expr{x} |
| 10866 | could be an imaginary number, giving the answer @samp{i inf} or | 11001 | could 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 | ||
| 10871 | Calc actually has three modes that say how infinities are handled. | 11006 | Calc actually has three modes that say how infinities are handled. |
| 10872 | Normally, infinities never arise from calculations that didn't | 11007 | Normally, infinities never arise from calculations that didn't |
| 10873 | already have them. Thus, @cite{1 / 0} is treated simply as an | 11008 | already have them. Thus, @expr{1 / 0} is treated simply as an |
| 10874 | error and left unevaluated. The @kbd{m i} (@code{calc-infinite-mode}) | 11009 | error and left unevaluated. The @kbd{m i} (@code{calc-infinite-mode}) |
| 10875 | command (@pxref{Infinite Mode}) enables a mode in which | 11010 | command (@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 |
| 10877 | an alternative type of infinite mode which says to treat zeros | 11012 | an alternative type of infinite mode which says to treat zeros |
| 10878 | as if they were positive, so that @samp{1 / 0 = inf}. While this | 11013 | as if they were positive, so that @samp{1 / 0 = inf}. While this |
| 10879 | is less mathematically correct, it may be the answer you want in | 11014 | is less mathematically correct, it may be the answer you want in |
| @@ -10892,9 +11027,9 @@ notation. | |||
| 10892 | It's not so easy to define certain formulas like @samp{0 * inf} and | 11027 | It'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 |
| 10894 | came from, the answer could be literally anything. The latter | 11029 | came from, the answer could be literally anything. The latter |
| 10895 | formula could be the limit of @cite{x / x} (giving a result of one), | 11030 | formula could be the limit of @expr{x / x} (giving a result of one), |
| 10896 | or @cite{2 x / x} (giving two), or @cite{x^2 / x} (giving @code{inf}), | 11031 | or @expr{2 x / x} (giving two), or @expr{x^2 / x} (giving @code{inf}), |
| 10897 | or @cite{x / x^2} (giving zero). Calc uses the symbol @code{nan} | 11032 | or @expr{x / x^2} (giving zero). Calc uses the symbol @code{nan} |
| 10898 | to represent such an @dfn{indeterminate} value. (The name ``nan'' | 11033 | to represent such an @dfn{indeterminate} value. (The name ``nan'' |
| 10899 | comes from analogy with the ``NAN'' concept of IEEE standard | 11034 | comes from analogy with the ``NAN'' concept of IEEE standard |
| 10900 | arithmetic; it stands for ``Not A Number.'' This is somewhat of a | 11035 | arithmetic; 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}. |
| 10939 | Many other operations are applied to vectors element-wise. For example, | 11074 | Many other operations are applied to vectors element-wise. For example, |
| 10940 | the complex conjugate of a vector is a vector of the complex conjugates | 11075 | the complex conjugate of a vector is a vector of the complex conjugates |
| 10941 | of its elements.@refill | 11076 | of its elements. |
| 10942 | 11077 | ||
| 10943 | @ignore | 11078 | @ignore |
| 10944 | @starindex | 11079 | @starindex |
| 10945 | @end ignore | 11080 | @end ignore |
| 10946 | @tindex vec | 11081 | @tindex vec |
| 10947 | Algebraic functions for building vectors include @samp{vec(a, b, c)} | 11082 | Algebraic functions for building vectors include @samp{vec(a, b, c)} |
| 10948 | to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an @c{$n\times m$} | 11083 | to 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} | ||
| 10950 | matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers | 11086 | matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers |
| 10951 | from 1 to @samp{n}. | 11087 | from 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 |
| 11079 | as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600. | 11215 | as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600. |
| 11080 | Display format for HMS forms is quite flexible. @xref{HMS Formats}.@refill | 11216 | Display format for HMS forms is quite flexible. @xref{HMS Formats}. |
| 11081 | 11217 | ||
| 11082 | HMS forms can be added and subtracted. When they are added to numbers, | 11218 | HMS forms can be added and subtracted. When they are added to numbers, |
| 11083 | the numbers are interpreted according to the current angular mode. HMS | 11219 | the 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} | |||
| 11216 | often arises in number theory. Modulo forms are written | 11352 | often arises in number theory. Modulo forms are written |
| 11217 | `@var{a} @t{mod} @var{M}', | 11353 | `@var{a} @t{mod} @var{M}', |
| 11218 | where @var{a} and @var{M} are real numbers or HMS forms, and | 11354 | where @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}}. |
| 11221 | In many applications @cite{a} and @cite{M} will be | 11357 | In many applications @expr{a} and @expr{M} will be |
| 11222 | integers but this is not required.@refill | 11358 | integers but this is not required. |
| 11223 | 11359 | ||
| 11224 | Modulo forms are not to be confused with the modulo operator @samp{%}. | 11360 | Modulo forms are not to be confused with the modulo operator @samp{%}. |
| 11225 | The expression @samp{27 % 10} means to compute 27 modulo 10 to produce | 11361 | The 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}; | |||
| 11228 | further computations with this value are again reduced modulo 10 so that | 11364 | further computations with this value are again reduced modulo 10 so that |
| 11229 | the result always lies in the desired range. | 11365 | the result always lies in the desired range. |
| 11230 | 11366 | ||
| 11231 | When two modulo forms with identical @cite{M}'s are added or multiplied, | 11367 | When two modulo forms with identical @expr{M}'s are added or multiplied, |
| 11232 | the Calculator simply adds or multiplies the values, then reduces modulo | 11368 | the 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, |
| 11234 | the plain number is treated like a compatible modulo form. It is also | 11370 | the plain number is treated like a compatible modulo form. It is also |
| 11235 | possible to raise modulo forms to powers; the result is the value raised | 11371 | possible to raise modulo forms to powers; the result is the value raised |
| 11236 | to the power, then reduced modulo @cite{M}. (When all values involved | 11372 | to the power, then reduced modulo @expr{M}. (When all values involved |
| 11237 | are integers, this calculation is done much more efficiently than | 11373 | are integers, this calculation is done much more efficiently than |
| 11238 | actually computing the power and then reducing.) | 11374 | actually computing the power and then reducing.) |
| 11239 | 11375 | ||
| 11240 | @cindex Modulo division | 11376 | @cindex Modulo division |
| 11241 | Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}' | 11377 | Two modulo forms `@var{a} @t{mod} @var{M}' and `@var{b} @t{mod} @var{M}' |
| 11242 | can be divided if @cite{a}, @cite{b}, and @cite{M} are all | 11378 | can be divided if @expr{a}, @expr{b}, and @expr{M} are all |
| 11243 | integers. The result is the modulo form which, when multiplied by | 11379 | integers. 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 |
| 11245 | there is no solution to this equation (which can happen only when | 11381 | there 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 |
| 11247 | division is left in symbolic form. Other operations, such as square | 11383 | division is left in symbolic form. Other operations, such as square |
| 11248 | roots, are not yet supported for modulo forms. (Note that, although | 11384 | roots, 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'' |
| 11250 | in the sense of reducing @c{$\sqrt a$} | 11386 | in the sense of reducing |
| 11251 | @cite{sqrt(a)} modulo @cite{M}, this is not a | 11387 | @texline @tmath{\sqrt a} |
| 11252 | useful definition from the number-theoretical point of view.)@refill | 11388 | @infoline @expr{sqrt(a)} |
| 11389 | modulo @expr{M}, this is not a useful definition from the | ||
| 11390 | number-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) |
| 11262 | To create a modulo form during numeric entry, press the shift-@kbd{M} | 11400 | To create a modulo form during numeric entry, press the shift-@kbd{M} |
| 11263 | key to enter the word @samp{mod}. As a special convenience, pressing | 11401 | key to enter the word @samp{mod}. As a special convenience, pressing |
| 11264 | shift-@kbd{M} a second time automatically enters the value of @cite{M} | 11402 | shift-@kbd{M} a second time automatically enters the value of @expr{M} |
| 11265 | that was most recently used before. During algebraic entry, either | 11403 | that was most recently used before. During algebraic entry, either |
| 11266 | type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}). | 11404 | type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}). |
| 11267 | Once again, pressing this a second time enters the current modulo.@refill | 11405 | Once again, pressing this a second time enters the current modulo. |
| 11268 | 11406 | ||
| 11269 | You can also use @kbd{v p} and @kbd{%} to modify modulo forms. | 11407 | You 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 | ||
| 11272 | It is possible to mix HMS forms and modulo forms. For example, an | 11410 | It is possible to mix HMS forms and modulo forms. For example, an |
| 11273 | HMS form modulo 24 could be used to manipulate clock times; an HMS | 11411 | HMS form modulo 24 could be used to manipulate clock times; an HMS |
| 11274 | form modulo 360 would be suitable for angles. Making the modulo @cite{M} | 11412 | form modulo 360 would be suitable for angles. Making the modulo @expr{M} |
| 11275 | also be an HMS form eliminates troubles that would arise if the angular | 11413 | also be an HMS form eliminates troubles that would arise if the angular |
| 11276 | mode were inadvertently set to Radians, in which case | 11414 | mode 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 |
| 11297 | An @dfn{error form} is a number with an associated standard | 11435 | An @dfn{error form} is a number with an associated standard |
| 11298 | deviation, as in @samp{2.3 +/- 0.12}. The notation | 11436 | deviation, 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' |
| 11301 | Gaussian distribution of mean @cite{x} and standard deviation or | 11439 | stands for an uncertain value which follows |
| 11302 | ``error'' @c{$\sigma$} | 11440 | a normal or Gaussian distribution of mean @expr{x} and standard |
| 11303 | @cite{sigma}. Both the mean and the error can be either numbers or | 11441 | deviation or ``error'' |
| 11442 | @texline @tmath{\sigma}. | ||
| 11443 | @infoline @expr{sigma}. | ||
| 11444 | Both the mean and the error can be either numbers or | ||
| 11304 | formulas. Generally these are real numbers but the mean may also be | 11445 | formulas. Generally these are real numbers but the mean may also be |
| 11305 | complex. If the error is negative or complex, it is changed to its | 11446 | complex. If the error is negative or complex, it is changed to its |
| 11306 | absolute value. An error form with zero error is converted to a | 11447 | absolute value. An error form with zero error is converted to a |
| 11307 | regular number by the Calculator.@refill | 11448 | regular number by the Calculator. |
| 11308 | 11449 | ||
| 11309 | All arithmetic and transcendental functions accept error forms as input. | 11450 | All arithmetic and transcendental functions accept error forms as input. |
| 11310 | Operations on the mean-value part work just like operations on regular | 11451 | Operations on the mean-value part work just like operations on regular |
| 11311 | numbers. The error part for any function @cite{f(x)} (such as @c{$\sin x$} | 11452 | numbers. The error part for any function @expr{f(x)} (such as |
| 11312 | @cite{sin(x)}) | 11453 | @texline @tmath{\sin x} |
| 11313 | is defined by the error of @cite{x} times the derivative of @cite{f} | 11454 | @infoline @expr{sin(x)}) |
| 11314 | evaluated at the mean value of @cite{x}. For a two-argument function | 11455 | is 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 | 11456 | evaluated at the mean value of @expr{x}. For a two-argument function |
| 11316 | of 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 |
| 11458 | of 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 |
| 11329 | Note that this | 11471 | Note that this |
| 11330 | definition assumes the errors in @cite{x} and @cite{y} are uncorrelated. | 11472 | definition assumes the errors in @expr{x} and @expr{y} are uncorrelated. |
| 11331 | A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)} | 11473 | A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)} |
| 11332 | is not the same as @samp{(2 +/- 1)^2}; the former represents the product | 11474 | is not the same as @samp{(2 +/- 1)^2}; the former represents the product |
| 11333 | of two independent values which happen to have the same probability | 11475 | of two independent values which happen to have the same probability |
| 11334 | distributions, and the latter is the product of one random value with itself. | 11476 | distributions, and the latter is the product of one random value with itself. |
| 11335 | The former will produce an answer with less error, since on the average | 11477 | The former will produce an answer with less error, since on the average |
| 11336 | the two independent errors can be expected to cancel out.@refill | 11478 | the two independent errors can be expected to cancel out. |
| 11337 | 11479 | ||
| 11338 | Consult a good text on error analysis for a discussion of the proper use | 11480 | Consult a good text on error analysis for a discussion of the proper use |
| 11339 | of standard deviations. Actual errors often are neither Gaussian-distributed | 11481 | of standard deviations. Actual errors often are neither Gaussian-distributed |
| 11340 | nor uncorrelated, and the above formulas are valid only when errors | 11482 | nor uncorrelated, and the above formulas are valid only when errors |
| 11341 | are small. As an example, the error arising from | 11483 | are 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} | 11486 | is |
| 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 | 11489 | When @expr{x} is close to zero, |
| 11348 | close 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 | 11492 | is close to one so the error in the sine is close to |
| 11351 | error in @cite{x} will produce about the same error in the sine. Likewise, | 11493 | @texline @tmath{\sigma}; |
| 11352 | near 90 degrees @c{$\cos x$} | 11494 | @infoline @expr{sigma}; |
| 11353 | @cite{cos(x)} is nearly zero and so the computed error is | 11495 | this makes sense, since |
| 11354 | small: The sine curve is nearly flat in that region, so an error in @cite{x} | 11496 | @texline @tmath{\sin x} |
| 11355 | has relatively little effect on the value of @c{$\sin x$} | 11497 | @infoline @expr{sin(x)} |
| 11356 | @cite{sin(x)}. However, consider | 11498 | is 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 | 11499 | produce about the same error in the sine. Likewise, near 90 degrees |
| 11358 | zero error! We get an obviously wrong result because we have violated | 11500 | @texline @tmath{\cos x} |
| 11359 | the small-error approximation underlying the error analysis. If the error | 11501 | @infoline @expr{cos(x)} |
| 11360 | in @cite{x} had been small, the error in @c{$\sin x$} | 11502 | is nearly zero and so the computed error is |
| 11361 | @cite{sin(x)} would indeed have been negligible.@refill | 11503 | small: The sine curve is nearly flat in that region, so an error in @expr{x} |
| 11504 | has relatively little effect on the value of | ||
| 11505 | @texline @tmath{\sin x}. | ||
| 11506 | @infoline @expr{sin(x)}. | ||
| 11507 | However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so | ||
| 11508 | Calc will report zero error! We get an obviously wrong result because | ||
| 11509 | we have violated the small-error approximation underlying the error | ||
| 11510 | analysis. If the error in @expr{x} had been small, the error in | ||
| 11511 | @texline @tmath{\sin x} | ||
| 11512 | @infoline @expr{sin(x)} | ||
| 11513 | would indeed have been negligible. | ||
| 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 |
| 11412 | uses a round parenthesis and the other a square bracket. In mathematical | 11564 | uses a round parenthesis and the other a square bracket. In mathematical |
| 11413 | terms, | 11565 | terms, |
| 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 |
| 11420 | Calc supports several varieties of intervals, including \dfn{closed} | 11572 | Calc 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 | ||
| 11465 | While it may seem that intervals and error forms are similar, they are | 11617 | While it may seem that intervals and error forms are similar, they are |
| 11466 | based on entirely different concepts of inexact quantities. An error | 11618 | based on entirely different concepts of inexact quantities. An error |
| 11467 | form `@var{x} @t{+/-} @c{$\sigma$} | 11619 | form |
| 11468 | @var{sigma}' means a variable is random, and its value could | 11620 | @texline `@var{x} @t{+/-} @tmath{\sigma}' |
| 11469 | be anything but is ``probably'' within one @c{$\sigma$} | 11621 | @infoline `@var{x} @t{+/-} @var{sigma}' |
| 11470 | @var{sigma} of the mean value @cite{x}. | 11622 | means a variable is random, and its value could |
| 11471 | An interval `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a variable's value | 11623 | be anything but is ``probably'' within one |
| 11472 | is unknown, but guaranteed to lie in the specified range. Error forms | 11624 | @texline @tmath{\sigma} |
| 11473 | are statistical or ``average case'' approximations; interval arithmetic | 11625 | @infoline @var{sigma} |
| 11474 | tends to produce ``worst case'' bounds on an answer.@refill | 11626 | of the mean value @expr{x}. An interval |
| 11627 | `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a | ||
| 11628 | variable's value is unknown, but guaranteed to lie in the specified | ||
| 11629 | range. Error forms are statistical or ``average case'' approximations; | ||
| 11630 | interval arithmetic tends to produce ``worst case'' bounds on an | ||
| 11631 | answer. | ||
| 11475 | 11632 | ||
| 11476 | Intervals may not contain complex numbers, but they may contain | 11633 | Intervals may not contain complex numbers, but they may contain |
| 11477 | HMS forms or date forms. | 11634 | HMS forms or date forms. |
| @@ -11537,7 +11694,7 @@ pushes the complex number @samp{(1, 1.414)} (approximately). | |||
| 11537 | If several values lie on the stack in front of the incomplete object, | 11694 | If several values lie on the stack in front of the incomplete object, |
| 11538 | all are collected and appended to the object. Thus the @kbd{,} key | 11695 | all are collected and appended to the object. Thus the @kbd{,} key |
| 11539 | is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people | 11696 | is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people |
| 11540 | prefer the equivalent @key{SPC} key to @key{RET}.@refill | 11697 | prefer the equivalent @key{SPC} key to @key{RET}. |
| 11541 | 11698 | ||
| 11542 | As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or | 11699 | As 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. | |||
| 11575 | The Calc variable @code{foo} corresponds to the Emacs Lisp variable | 11732 | The 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 |
| 11577 | on variables can be made to use any arbitrary Lisp variable simply by | 11734 | on variables can be made to use any arbitrary Lisp variable simply by |
| 11578 | backspacing over the @samp{var-} prefix in the minibuffer.@refill | 11735 | backspacing over the @samp{var-} prefix in the minibuffer. |
| 11579 | 11736 | ||
| 11580 | In a command that takes a variable name, you can either type the full | 11737 | In a command that takes a variable name, you can either type the full |
| 11581 | name of a variable, or type a single digit to use one of the special | 11738 | name of a variable, or type a single digit to use one of the special |
| 11582 | convenience variables @code{var-q0} through @code{var-q9}. For example, | 11739 | convenience 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 | ||
| 11587 | To push a variable itself (as opposed to the variable's value) on the | 11744 | To push a variable itself (as opposed to the variable's value) on the |
| 11588 | stack, enter its name as an algebraic expression using the apostrophe | 11745 | stack, 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{=}, |
| 11624 | their values are calculated if necessary according to the current precision | 11781 | their values are calculated if necessary according to the current precision |
| 11625 | or complex polar mode. If you wish to use these symbols for other purposes, | 11782 | or complex polar mode. If you wish to use these symbols for other purposes, |
| 11626 | simply undefine or redefine them using @code{calc-store}.@refill | 11783 | simply undefine or redefine them using @code{calc-store}. |
| 11627 | 11784 | ||
| 11628 | The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for | 11785 | The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for |
| 11629 | infinite or indeterminate values. It's best not to use them as | 11786 | infinite 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 | ||
| 11699 | Note that, unlike in usual computer notation, multiplication binds more | 11856 | Note that, unlike in usual computer notation, multiplication binds more |
| 11700 | strongly than division: @samp{a*b/c*d} is equivalent to @c{$a b \over c d$} | 11857 | strongly 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 | |||
| 11712 | cases you must use a space if you omit the @samp{*}: @samp{2a} is the | 11870 | cases you must use a space if you omit the @samp{*}: @samp{2a} is the |
| 11713 | same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab} | 11871 | same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab} |
| 11714 | is a variable called @code{ab}, @emph{not} the product of @samp{a} and | 11872 | is 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 |
| 11718 | The rules are slightly different for vectors written with square brackets. | 11876 | The 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 | |||
| 11724 | ignored. To force spaces to be interpreted as multiplication you can | 11882 | ignored. To force spaces to be interpreted as multiplication you can |
| 11725 | enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is | 11883 | enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is |
| 11726 | interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted | 11884 | interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted |
| 11727 | between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill | 11885 | between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}. |
| 11728 | 11886 | ||
| 11729 | Vectors that contain commas (not embedded within nested parentheses or | 11887 | Vectors that contain commas (not embedded within nested parentheses or |
| 11730 | brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector | 11888 | brackets) 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 | |||
| 11753 | left alone. Beware that many innocent-looking short names like @code{in} | 11911 | left alone. Beware that many innocent-looking short names like @code{in} |
| 11754 | and @code{re} have predefined meanings which could surprise you; however, | 11912 | and @code{re} have predefined meanings which could surprise you; however, |
| 11755 | single letters or single letters followed by digits are always safe to | 11913 | single letters or single letters followed by digits are always safe to |
| 11756 | use for your own function names. @xref{Function Index}.@refill | 11914 | use for your own function names. @xref{Function Index}. |
| 11757 | 11915 | ||
| 11758 | In the documentation for particular commands, the notation @kbd{H S} | 11916 | In 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 |
| 11760 | command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all | 11918 | command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all |
| 11761 | represent the same operation.@refill | 11919 | represent the same operation. |
| 11762 | 11920 | ||
| 11763 | Commands that interpret (``parse'') text as algebraic formulas include | 11921 | Commands that interpret (``parse'') text as algebraic formulas include |
| 11764 | algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse | 11922 | algebraic 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 | |||
| 11833 | oppositely. Also, with no prefix argument the default argument is 2. | 11991 | oppositely. Also, with no prefix argument the default argument is 2. |
| 11834 | Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}} | 11992 | Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}} |
| 11835 | are both equivalent to @kbd{C-u - 2 @key{RET}}, producing | 11993 | are 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 | ||
| 11890 | A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in | 12048 | A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in |
| 11891 | terms of moving a particular element to a new position in the stack. | 12049 | terms 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} | |||
| 11988 | Calc Trail window. In practice they are rarely used, since the commands | 12146 | Calc Trail window. In practice they are rarely used, since the commands |
| 11989 | shown below are a more convenient way to move around in the | 12147 | shown below are a more convenient way to move around in the |
| 11990 | trail, and they work ``by remote control'' when the cursor is still | 12148 | trail, and they work ``by remote control'' when the cursor is still |
| 11991 | in the Calculator window.@refill | 12149 | in the Calculator window. |
| 11992 | 12150 | ||
| 11993 | @cindex Trail pointer | 12151 | @cindex Trail pointer |
| 11994 | There is a @dfn{trail pointer} which selects some entry of the trail at | 12152 | There 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 |
| 12012 | The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >} | 12170 | The @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 |
| 12014 | window left or right by one half of its width.@refill | 12172 | window 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} | |||
| 12026 | one line. The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b} | 12184 | one 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 |
| 12028 | one screenful at a time. All of these commands accept numeric prefix | 12186 | one screenful at a time. All of these commands accept numeric prefix |
| 12029 | arguments to move several lines or screenfuls at a time.@refill | 12187 | arguments 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 |
| 12039 | last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command | 12197 | last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command |
| 12040 | moves the trail pointer to the cursor position; unlike the other trail | 12198 | moves the trail pointer to the cursor position; unlike the other trail |
| 12041 | commands, @kbd{t h} works only when Calc Trail is the selected window.@refill | 12199 | commands, @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} | |||
| 12050 | search forward or backward through the trail. You can press @key{RET} | 12208 | search forward or backward through the trail. You can press @key{RET} |
| 12051 | to terminate the search; the trail pointer moves to the current line. | 12209 | to terminate the search; the trail pointer moves to the current line. |
| 12052 | If you cancel the search with @kbd{C-g}, the trail pointer stays where | 12210 | If you cancel the search with @kbd{C-g}, the trail pointer stays where |
| 12053 | it was when the search began.@refill | 12211 | it was when the search began. |
| 12054 | @end ifinfo | 12212 | @end ifinfo |
| 12055 | @tex | 12213 | @tex |
| 12056 | The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r} | 12214 | The @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 | |||
| 12248 | round values already on the stack, but those values will be rounded | 12406 | round values already on the stack, but those values will be rounded |
| 12249 | down before being used in any calculation. The @kbd{c 0} through | 12407 | down 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 |
| 12251 | existing value to a new precision.@refill | 12409 | existing value to a new precision. |
| 12252 | 12410 | ||
| 12253 | @cindex Accuracy of calculations | 12411 | @cindex Accuracy of calculations |
| 12254 | It is important to distinguish the concepts of @dfn{precision} and | 12412 | It 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. | |||
| 12291 | Instead, you must first press @kbd{I} (@code{calc-inverse}) to set | 12449 | Instead, you must first press @kbd{I} (@code{calc-inverse}) to set |
| 12292 | the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}). | 12450 | the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}). |
| 12293 | The @kbd{I} key actually toggles the Inverse Flag. When this flag | 12451 | The @kbd{I} key actually toggles the Inverse Flag. When this flag |
| 12294 | is set, the word @samp{Inv} appears in the mode line.@refill | 12452 | is 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}. | |||
| 12300 | If both of these flags are set at once, the effect will be | 12458 | If 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 |
| 12302 | non-trigonometric commands; for example @kbd{H L} computes a base-10, | 12460 | non-trigonometric commands; for example @kbd{H L} computes a base-10, |
| 12303 | instead of base-@i{e}, logarithm.)@refill | 12461 | instead of base-@i{e}, logarithm.) |
| 12304 | 12462 | ||
| 12305 | Command names like @code{calc-arcsin} are provided for completeness, and | 12463 | Command names like @code{calc-arcsin} are provided for completeness, and |
| 12306 | may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to | 12464 | may 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 | |||
| 12356 | instead expressed in degrees. (Complex-number calculations would | 12514 | instead expressed in degrees. (Complex-number calculations would |
| 12357 | normally be done in radians mode, though. Complex numbers are converted | 12515 | normally be done in radians mode, though. Complex numbers are converted |
| 12358 | to degrees by calculating the complex result in radians and then | 12516 | to degrees by calculating the complex result in radians and then |
| 12359 | multiplying by 180 over @c{$\pi$} | 12517 | multiplying 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$} | |||
| 12368 | The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}), | 12525 | The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}), |
| 12369 | and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode. | 12526 | and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode. |
| 12370 | The current angular mode is displayed on the Emacs mode line. | 12527 | The current angular mode is displayed on the Emacs mode line. |
| 12371 | The default angular mode is degrees.@refill | 12528 | The 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. | |||
| 12396 | Division of two integers normally yields a floating-point number if the | 12553 | Division of two integers normally yields a floating-point number if the |
| 12397 | result cannot be expressed as an integer. In some cases you would | 12554 | result cannot be expressed as an integer. In some cases you would |
| 12398 | rather get an exact fractional answer. One way to accomplish this is | 12555 | rather get an exact fractional answer. One way to accomplish this is |
| 12399 | to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @cite{3:2} | 12556 | to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @expr{3:2} |
| 12400 | even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}. | 12557 | even 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 |
| 12404 | To set the Calculator to produce fractional results for normal integer | 12561 | To set the Calculator to produce fractional results for normal integer |
| 12405 | divisions, use the @kbd{m f} (@code{calc-frac-mode}) command. | 12562 | divisions, use the @kbd{m f} (@code{calc-frac-mode}) command. |
| 12406 | For example, @cite{8/4} produces @cite{2} in either mode, | 12563 | For example, @expr{8/4} produces @expr{2} in either mode, |
| 12407 | but @cite{6/4} produces @cite{3:2} in Fraction Mode, @cite{1.5} in | 12564 | but @expr{6/4} produces @expr{3:2} in Fraction Mode, @expr{1.5} in |
| 12408 | Float Mode.@refill | 12565 | Float Mode. |
| 12409 | 12566 | ||
| 12410 | At any time you can use @kbd{c f} (@code{calc-float}) to convert a | 12567 | At any time you can use @kbd{c f} (@code{calc-float}) to convert a |
| 12411 | fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a | 12568 | fraction 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 |
| 12419 | The Calculator normally treats results like @cite{1 / 0} as errors; | 12576 | The Calculator normally treats results like @expr{1 / 0} as errors; |
| 12420 | formulas like this are left in unsimplified form. But Calc can be | 12577 | formulas like this are left in unsimplified form. But Calc can be |
| 12421 | put into a mode where such calculations instead produce ``infinite'' | 12578 | put into a mode where such calculations instead produce ``infinite'' |
| 12422 | results. | 12579 | results. |
| @@ -12432,7 +12589,7 @@ will not be generated when infinite mode is off.) | |||
| 12432 | 12589 | ||
| 12433 | With infinite mode turned on, @samp{1 / 0} will generate @code{uinf}, | 12590 | With infinite mode turned on, @samp{1 / 0} will generate @code{uinf}, |
| 12434 | an undirected infinity. @xref{Infinities}, for a discussion of the | 12591 | an undirected infinity. @xref{Infinities}, for a discussion of the |
| 12435 | difference between @code{inf} and @code{uinf}. Also, @cite{0 / 0} | 12592 | difference between @code{inf} and @code{uinf}. Also, @expr{0 / 0} |
| 12436 | evaluates to @code{nan}, the ``indeterminate'' symbol. Various other | 12593 | evaluates to @code{nan}, the ``indeterminate'' symbol. Various other |
| 12437 | functions can also return infinities in this mode; for example, | 12594 | functions 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}). |
| 12478 | Given a numeric prefix argument, it also | 12635 | Given a numeric prefix argument, it also |
| 12479 | sets the floating-point precision to the specified value for the duration | 12636 | sets the floating-point precision to the specified value for the duration |
| 12480 | of the command.@refill | 12637 | of the command. |
| 12481 | 12638 | ||
| 12482 | To evaluate a formula numerically without expanding the variables it | 12639 | To evaluate a formula numerically without expanding the variables it |
| 12483 | contains, you can use the key sequence @kbd{m s a v m s} (this uses | 12640 | contains, 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 |
| 12505 | rewrite rules and algebraic simplification. Another effect of this | 12662 | rewrite rules and algebraic simplification. Another effect of this |
| 12506 | mode is that calculations that would normally produce constants like | 12663 | mode is that calculations that would normally produce constants like |
| 12507 | 0 and 1 (e.g., @cite{a - a} and @cite{a / a}, respectively) will now | 12664 | 0 and 1 (e.g., @expr{a - a} and @expr{a / a}, respectively) will now |
| 12508 | produce function calls that represent ``generic'' zero or identity | 12665 | produce function calls that represent ``generic'' zero or identity |
| 12509 | matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function | 12666 | matrices: @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 | |||
| 12598 | disable all ``working'' messages. Use a numeric prefix of 1 to enable | 12755 | disable all ``working'' messages. Use a numeric prefix of 1 to enable |
| 12599 | only the plain @samp{Working...} message. Use a numeric prefix of 2 to | 12756 | only the plain @samp{Working...} message. Use a numeric prefix of 2 to |
| 12600 | see intermediate results as well. With no numeric prefix this displays | 12757 | see intermediate results as well. With no numeric prefix this displays |
| 12601 | the current mode.@refill | 12758 | the current mode. |
| 12602 | 12759 | ||
| 12603 | While it may seem that the ``working'' messages will slow Calc down | 12760 | While it may seem that the ``working'' messages will slow Calc down |
| 12604 | considerably, experiments have shown that their impact is actually | 12761 | considerably, experiments have shown that their impact is actually |
| @@ -12613,13 +12770,13 @@ The current @dfn{simplification mode} controls how numbers and formulas | |||
| 12613 | are ``normalized'' when being taken from or pushed onto the stack. | 12770 | are ``normalized'' when being taken from or pushed onto the stack. |
| 12614 | Some normalizations are unavoidable, such as rounding floating-point | 12771 | Some normalizations are unavoidable, such as rounding floating-point |
| 12615 | results to the current precision, and reducing fractions to simplest | 12772 | results to the current precision, and reducing fractions to simplest |
| 12616 | form. Others, such as simplifying a formula like @cite{a+a} (or @cite{2+3}), | 12773 | form. Others, such as simplifying a formula like @expr{a+a} (or @expr{2+3}), |
| 12617 | are done by default but can be turned off when necessary. | 12774 | are done by default but can be turned off when necessary. |
| 12618 | 12775 | ||
| 12619 | When you press a key like @kbd{+} when @cite{2} and @cite{3} are on the | 12776 | When you press a key like @kbd{+} when @expr{2} and @expr{3} are on the |
| 12620 | stack, Calc pops these numbers, normalizes them, creates the formula | 12777 | stack, 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 |
| 12622 | rules for normalizing @cite{2+3} will produce the result @cite{5}. | 12779 | rules for normalizing @expr{2+3} will produce the result @expr{5}. |
| 12623 | 12780 | ||
| 12624 | Simplification mode commands consist of the lower-case @kbd{m} prefix key | 12781 | Simplification mode commands consist of the lower-case @kbd{m} prefix key |
| 12625 | followed by a shifted letter. | 12782 | followed 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 |
| 12629 | The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional | 12786 | The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional |
| 12630 | simplifications. These would leave a formula like @cite{2+3} alone. In | 12787 | simplifications. These would leave a formula like @expr{2+3} alone. In |
| 12631 | fact, nothing except simple numbers are ever affected by normalization | 12788 | fact, nothing except simple numbers are ever affected by normalization |
| 12632 | in this mode. | 12789 | in this mode. |
| 12633 | 12790 | ||
| @@ -12635,22 +12792,24 @@ in this mode. | |||
| 12635 | @pindex calc-num-simplify-mode | 12792 | @pindex calc-num-simplify-mode |
| 12636 | The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification | 12793 | The @kbd{m N} (@code{calc-num-simplify-mode}) command turns off simplification |
| 12637 | of any formulas except those for which all arguments are constants. For | 12794 | of any formulas except those for which all arguments are constants. For |
| 12638 | example, @cite{1+2} is simplified to @cite{3}, and @cite{a+(2-2)} is | 12795 | example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(2-2)} is |
| 12639 | simplified to @cite{a+0} but no further, since one argument of the sum | 12796 | simplified to @expr{a+0} but no further, since one argument of the sum |
| 12640 | is not a constant. Unfortunately, @cite{(a+2)-2} is @emph{not} simplified | 12797 | is not a constant. Unfortunately, @expr{(a+2)-2} is @emph{not} simplified |
| 12641 | because the top-level @samp{-} operator's arguments are not both | 12798 | because the top-level @samp{-} operator's arguments are not both |
| 12642 | constant numbers (one of them is the formula @cite{a+2}). | 12799 | constant numbers (one of them is the formula @expr{a+2}). |
| 12643 | A constant is a number or other numeric object (such as a constant | 12800 | A constant is a number or other numeric object (such as a constant |
| 12644 | error form or modulo form), or a vector all of whose | 12801 | error form or modulo form), or a vector all of whose |
| 12645 | elements are constant.@refill | 12802 | elements are constant. |
| 12646 | 12803 | ||
| 12647 | @kindex m D | 12804 | @kindex m D |
| 12648 | @pindex calc-default-simplify-mode | 12805 | @pindex calc-default-simplify-mode |
| 12649 | The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the | 12806 | The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the |
| 12650 | default simplifications for all formulas. This includes many easy and | 12807 | default simplifications for all formulas. This includes many easy and |
| 12651 | fast algebraic simplifications such as @cite{a+0} to @cite{a}, and | 12808 | fast 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)} | ||
| 12812 | to @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 |
| 12682 | is a superset of @kbd{a s}. In this mode, variable names which | 12841 | is a superset of @kbd{a s}. In this mode, variable names which |
| 12683 | are identifiable as unit names (like @samp{mm} for ``millimeters'') | 12842 | are identifiable as unit names (like @samp{mm} for ``millimeters'') |
| 12684 | are simplified with their unit definitions in mind.@refill | 12843 | are simplified with their unit definitions in mind. |
| 12685 | 12844 | ||
| 12686 | A common technique is to set the simplification mode down to the lowest | 12845 | A common technique is to set the simplification mode down to the lowest |
| 12687 | amount of simplification you will allow to be applied automatically, then | 12846 | amount of simplification you will allow to be applied automatically, then |
| 12688 | use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to | 12847 | use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to |
| 12689 | perform higher types of simplifications on demand. @xref{Algebraic | 12848 | perform higher types of simplifications on demand. @xref{Algebraic |
| 12690 | Definitions}, for another sample use of no-simplification mode.@refill | 12849 | Definitions}, 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. | |||
| 12949 | Calc does not check the declarations for a variable when you store | 13108 | Calc does not check the declarations for a variable when you store |
| 12950 | a value in it. However, storing @i{-3.5} in a variable that has | 13109 | a value in it. However, storing @i{-3.5} in a variable that has |
| 12951 | been declared @code{pos}, @code{int}, or @code{matrix} may have | 13110 | been declared @code{pos}, @code{int}, or @code{matrix} may have |
| 12952 | unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @cite{3.5} | 13111 | unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5} |
| 12953 | if it substitutes the value first, or to @cite{-3.5} if @code{x} | 13112 | if it substitutes the value first, or to @expr{-3.5} if @code{x} |
| 12954 | was declared @code{pos} and the formula @samp{sqrt(x^2)} is | 13113 | was declared @code{pos} and the formula @samp{sqrt(x^2)} is |
| 12955 | simplified to @samp{x} before the value is substituted. Before | 13114 | simplified to @samp{x} before the value is substituted. Before |
| 12956 | using a variable for a new purpose, it is best to use @kbd{s d} | 13115 | using 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 |
| 13020 | The @code{dimag} function checks if its argument is imaginary, | 13179 | The @code{dimag} function checks if its argument is imaginary, |
| 13021 | i.e., is mathematically equal to a real number times @cite{i}. | 13180 | i.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. | |||
| 13036 | The @code{dneg} function checks for negative reals. The @code{dnonneg} | 13195 | The @code{dneg} function checks for negative reals. The @code{dnonneg} |
| 13037 | function checks for nonnegative reals, i.e., reals greater than or | 13196 | function checks for nonnegative reals, i.e., reals greater than or |
| 13038 | equal to zero. Note that the @kbd{a s} command can simplify an | 13197 | equal to zero. Note that the @kbd{a s} command can simplify an |
| 13039 | expression like @cite{x > 0} to 1 or 0 using @code{dpos}, and that | 13198 | expression 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, |
| 13041 | so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg} | 13200 | so the actual functions @code{dpos}, @code{dneg}, and @code{dnonneg} |
| 13042 | are rarely necessary. | 13201 | are 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. |
| 13107 | Display formats for vectors and matrices are also covered elsewhere; | 13266 | Display formats for vectors and matrices are also covered elsewhere; |
| 13108 | @pxref{Vector and Matrix Formats}.@refill | 13267 | @pxref{Vector and Matrix Formats}. |
| 13109 | 13268 | ||
| 13110 | One thing all display modes have in common is their treatment of the | 13269 | One 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, | |||
| 13165 | respectively. Numbers can always be entered in any radix, though the | 13324 | respectively. Numbers can always be entered in any radix, though the |
| 13166 | current radix is used as a default if you press @kbd{#} without any initial | 13325 | current radix is used as a default if you press @kbd{#} without any initial |
| 13167 | digits. A number entered without a @kbd{#} is @emph{always} interpreted | 13326 | digits. A number entered without a @kbd{#} is @emph{always} interpreted |
| 13168 | as decimal.@refill | 13327 | as 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 | |||
| 13180 | represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) | 13339 | represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) |
| 13181 | command causes integers to be padded out with leading zeros according to the | 13340 | command causes integers to be padded out with leading zeros according to the |
| 13182 | current binary word size. (@xref{Binary Functions}, for a discussion of | 13341 | current binary word size. (@xref{Binary Functions}, for a discussion of |
| 13183 | word size.) If the absolute value of the word size is @cite{w}, all integers | 13342 | word size.) If the absolute value of the word size is @expr{w}, all integers |
| 13184 | are displayed with at least enough digits to represent @c{$2^w-1$} | 13343 | are displayed with at least enough digits to represent |
| 13185 | @cite{(2^w)-1} in the | 13344 | @texline @tmath{2^w-1} |
| 13186 | current radix. (Larger integers will still be displayed in their entirety.) | 13345 | @infoline @expr{(2^w)-1} |
| 13346 | in the current radix. (Larger integers will still be displayed in their | ||
| 13347 | entirety.) | ||
| 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. | |||
| 13202 | The @kbd{d g} command toggles grouping on and off. | 13363 | The @kbd{d g} command toggles grouping on and off. |
| 13203 | With a numerix prefix of 0, this command displays the current state of | 13364 | With a numerix prefix of 0, this command displays the current state of |
| 13204 | the grouping flag; with an argument of minus one it disables grouping; | 13365 | the grouping flag; with an argument of minus one it disables grouping; |
| 13205 | with a positive argument @cite{N} it enables grouping on every @cite{N} | 13366 | with a positive argument @expr{N} it enables grouping on every @expr{N} |
| 13206 | digits. For floating-point numbers, grouping normally occurs only | 13367 | digits. For floating-point numbers, grouping normally occurs only |
| 13207 | before the decimal point. A negative prefix argument @cite{-N} enables | 13368 | before the decimal point. A negative prefix argument @expr{-N} enables |
| 13208 | grouping every @cite{N} digits both before and after the decimal point.@refill | 13369 | grouping 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. | |||
| 13298 | There are three supported notations for complex numbers in rectangular | 13459 | There are three supported notations for complex numbers in rectangular |
| 13299 | form. The default is as a pair of real numbers enclosed in parentheses | 13460 | form. The default is as a pair of real numbers enclosed in parentheses |
| 13300 | and separated by a comma: @samp{(a,b)}. The @kbd{d c} | 13461 | and 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} | |||
| 13307 | The other notations are @kbd{d i} (@code{calc-i-notation}), in which | 13468 | The other notations are @kbd{d i} (@code{calc-i-notation}), in which |
| 13308 | numbers are displayed in @samp{a+bi} form, and @kbd{d j} | 13469 | numbers 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 |
| 13310 | in some disciplines.@refill | 13471 | in 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} | |||
| 13318 | will be interpreted as @samp{(0,1)} and the formula will be simplified | 13479 | will be interpreted as @samp{(0,1)} and the formula will be simplified |
| 13319 | to @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not} | 13480 | to @samp{(2,3)}. Other commands (like @code{calc-sin}) will @emph{not} |
| 13320 | interpret the formula @samp{2 + 3 * i} as a complex number. | 13481 | interpret 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, | |||
| 13346 | Calc adjusts all fractions that are displayed to have the specified | 13507 | Calc adjusts all fractions that are displayed to have the specified |
| 13347 | denominator, if possible. Otherwise it adjusts the denominator to | 13508 | denominator, if possible. Otherwise it adjusts the denominator to |
| 13348 | be a multiple of the specified value. For example, in @samp{:6} mode | 13509 | be a multiple of the specified value. For example, in @samp{:6} mode |
| 13349 | the fraction @cite{1:6} will be unaffected, but @cite{2:3} will be | 13510 | the fraction @expr{1:6} will be unaffected, but @expr{2:3} will be |
| 13350 | displayed as @cite{4:6}, @cite{1:2} will be displayed as @cite{3:6}, | 13511 | displayed as @expr{4:6}, @expr{1:2} will be displayed as @expr{3:6}, |
| 13351 | and @cite{1:8} will be displayed as @cite{3:24}. Integers are also | 13512 | and @expr{1:8} will be displayed as @expr{3:24}. Integers are also |
| 13352 | affected by this mode: 3 is displayed as @cite{18:6}. Note that the | 13513 | affected by this mode: 3 is displayed as @expr{18:6}. Note that the |
| 13353 | format @samp{:1} writes fractions the same as @samp{:}, but it writes | 13514 | format @samp{:1} writes fractions the same as @samp{:}, but it writes |
| 13354 | integers as @cite{n:1}. | 13515 | integers as @expr{n:1}. |
| 13355 | 13516 | ||
| 13356 | The fraction format does not affect the way fractions or integers are | 13517 | The fraction format does not affect the way fractions or integers are |
| 13357 | stored, only the way they appear on the screen. The fraction format | 13518 | stored, 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 | |||
| 13710 | that the values below the @samp{.} are @emph{visible}, just temporarily | 13871 | that the values below the @samp{.} are @emph{visible}, just temporarily |
| 13711 | frozen. This feature allows you to keep several independent calculations | 13872 | frozen. This feature allows you to keep several independent calculations |
| 13712 | running at once in different parts of the stack, or to apply a certain | 13873 | running at once in different parts of the stack, or to apply a certain |
| 13713 | command to an element buried deep in the stack.@refill | 13874 | command to an element buried deep in the stack. |
| 13714 | 13875 | ||
| 13715 | Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor | 13876 | Pressing @kbd{d t} by itself moves the @samp{.} to the line the cursor |
| 13716 | is on. Thus, this line and all those below it become hidden. To un-hide | 13877 | is on. Thus, this line and all those below it become hidden. To un-hide |
| 13717 | these lines, move down to the end of the buffer and press @w{@kbd{d t}}. | 13878 | these lines, move down to the end of the buffer and press @w{@kbd{d t}}. |
| 13718 | With a positive numeric prefix argument @cite{n}, @kbd{d t} hides the | 13879 | With a positive numeric prefix argument @expr{n}, @kbd{d t} hides the |
| 13719 | bottom @cite{n} values in the buffer. With a negative argument, it hides | 13880 | bottom @expr{n} values in the buffer. With a negative argument, it hides |
| 13720 | all but the top @cite{n} values. With an argument of zero, it hides zero | 13881 | all but the top @expr{n} values. With an argument of zero, it hides zero |
| 13721 | values, i.e., moves the @samp{.} all the way down to the bottom.@refill | 13882 | values, 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 |
| 13727 | The @kbd{d [} (@code{calc-truncate-up}) and @kbd{d ]} | 13888 | The @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 |
| 13729 | line at a time (or several lines with a prefix argument).@refill | 13890 | line 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, |
| 13745 | stack entries are displayed flush-right against the right edge of the | 13906 | stack entries are displayed flush-right against the right edge of the |
| 13746 | window.@refill | 13907 | window. |
| 13747 | 13908 | ||
| 13748 | If you change the width of the Calculator window you may have to type | 13909 | If 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 |
| 13936 | can represent either the negative rational number @cite{-3:4}, or the | 14097 | can represent either the negative rational number @expr{-3:4}, or the |
| 13937 | actual expression @samp{-(3/4)}; but the latter formula would normally | 14098 | actual expression @samp{-(3/4)}; but the latter formula would normally |
| 13938 | never be displayed because it would immediately be evaluated to | 14099 | never 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 |
| 13940 | typical use. | 14101 | typical use. |
| 13941 | 14102 | ||
| 13942 | Non-decimal numbers are displayed with subscripts. Thus there is no | 14103 | Non-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)}. | |||
| 14061 | Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these | 14222 | Math formulas are usually enclosed by @samp{$ $} signs in @TeX{}; these |
| 14062 | should be omitted when interfacing with Calc. To Calc, the @samp{$} sign | 14223 | should be omitted when interfacing with Calc. To Calc, the @samp{$} sign |
| 14063 | has the same meaning it always does in algebraic formulas (a reference to | 14224 | has the same meaning it always does in algebraic formulas (a reference to |
| 14064 | an existing entry on the stack).@refill | 14225 | an existing entry on the stack). |
| 14065 | 14226 | ||
| 14066 | Complex numbers are displayed as in @samp{3 + 4i}. Fractions and | 14227 | Complex numbers are displayed as in @samp{3 + 4i}. Fractions and |
| 14067 | quotients are written using @code{\over}; | 14228 | quotients are written using @code{\over}; |
| @@ -14073,7 +14234,7 @@ ceiling functions are written with @code{\lfloor}, @code{\rfloor}, etc. | |||
| 14073 | The words @code{\left} and @code{\right} are ignored when reading | 14234 | The words @code{\left} and @code{\right} are ignored when reading |
| 14074 | formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written | 14235 | formulas in @TeX{} mode. Both @code{inf} and @code{uinf} are written |
| 14075 | as @code{\infty}; when read, @code{\infty} always translates to | 14236 | as @code{\infty}; when read, @code{\infty} always translates to |
| 14076 | @code{inf}.@refill | 14237 | @code{inf}. |
| 14077 | 14238 | ||
| 14078 | Function calls are written the usual way, with the function name followed | 14239 | Function calls are written the usual way, with the function name followed |
| 14079 | by the arguments in parentheses. However, functions for which @TeX{} has | 14240 | by 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 | |||
| 14081 | parentheses for very simple arguments. During input, curly braces and | 14242 | parentheses for very simple arguments. During input, curly braces and |
| 14082 | parentheses work equally well for grouping, but when the document is | 14243 | parentheses work equally well for grouping, but when the document is |
| 14083 | formatted the curly braces will be invisible. Thus the printed result is | 14244 | formatted 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)}. | 14247 | but |
| 14248 | @texline @tmath{\sin(2 + x)}. | ||
| 14249 | @infoline @expr{sin(2 + x)}. | ||
| 14087 | 14250 | ||
| 14088 | Function and variable names not treated specially by @TeX{} are simply | 14251 | Function and variable names not treated specially by @TeX{} are simply |
| 14089 | written out as-is, which will cause them to come out in italic letters | 14252 | written 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}, | |||
| 14453 | Mathematica mode. | 14614 | Mathematica mode. |
| 14454 | Non-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point | 14615 | Non-decimal numbers are written, e.g., @samp{16^^7fff}. Floating-point |
| 14455 | numbers in scientific notation are written @samp{1.23*10.^3}. | 14616 | numbers in scientific notation are written @samp{1.23*10.^3}. |
| 14456 | Subscripts use double square brackets: @samp{a[[i]]}.@refill | 14617 | Subscripts 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 | ||
| 14597 | The general rule is that if an operator with precedence @cite{n} | 14758 | The general rule is that if an operator with precedence @expr{n} |
| 14598 | occurs as an argument to an operator with precedence @cite{m}, then | 14759 | occurs as an argument to an operator with precedence @expr{m}, then |
| 14599 | the argument is enclosed in parentheses if @cite{n < m}. Top-level | 14760 | the argument is enclosed in parentheses if @expr{n < m}. Top-level |
| 14600 | expressions and expressions which are function arguments, vector | 14761 | expressions and expressions which are function arguments, vector |
| 14601 | components, etc., are formatted with precedence zero (so that they | 14762 | components, etc., are formatted with precedence zero (so that they |
| 14602 | normally never get additional parentheses). | 14763 | normally never get additional parentheses). |
| @@ -15579,8 +15740,10 @@ Command is @kbd{m p}. | |||
| 15579 | 15740 | ||
| 15580 | @item | 15741 | @item |
| 15581 | Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar | 15742 | Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar |
| 15582 | mode, @i{-2} for matrix mode, or @var{N} for @c{$N\times N$} | 15743 | mode, @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} | ||
| 15746 | matrix mode. Command is @kbd{m v}. | ||
| 15584 | 15747 | ||
| 15585 | @item | 15748 | @item |
| 15586 | Simplification mode. Default is 1. Value is @i{-1} for off (@kbd{m O}), | 15749 | Simplification 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 | |||
| 15906 | work, for the same reasons just mentioned for vectors. Instead you must | 16069 | work, for the same reasons just mentioned for vectors. Instead you must |
| 15907 | write @samp{(a +/- b) + (c +/- 0)}. | 16070 | write @samp{(a +/- b) + (c +/- 0)}. |
| 15908 | 16071 | ||
| 15909 | If both arguments of @kbd{+} are modulo forms with equal values of @cite{M}, | 16072 | If both arguments of @kbd{+} are modulo forms with equal values of @expr{M}, |
| 15910 | or if one argument is a modulo form and the other a plain number, the | 16073 | or if one argument is a modulo form and the other a plain number, the |
| 15911 | result is a modulo form which represents the sum, modulo @cite{M}, of | 16074 | result is a modulo form which represents the sum, modulo @expr{M}, of |
| 15912 | the two values. | 16075 | the two values. |
| 15913 | 16076 | ||
| 15914 | If both arguments of @kbd{+} are intervals, the result is an interval | 16077 | If 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 / |
| 15966 | The @kbd{/} (@code{calc-divide}) command divides two numbers. When | 16129 | The @kbd{/} (@code{calc-divide}) command divides two numbers. When |
| 15967 | dividing a scalar @cite{B} by a square matrix @cite{A}, the computation | 16130 | dividing a scalar @expr{B} by a square matrix @expr{A}, the computation |
| 15968 | performed is @cite{B} times the inverse of @cite{A}. This also occurs | 16131 | performed is @expr{B} times the inverse of @expr{A}. This also occurs |
| 15969 | if @cite{B} is itself a vector or matrix, in which case the effect is | 16132 | if @expr{B} is itself a vector or matrix, in which case the effect is |
| 15970 | to solve the set of linear equations represented by @cite{B}. If @cite{B} | 16133 | to solve the set of linear equations represented by @expr{B}. If @expr{B} |
| 15971 | is a matrix with the same number of rows as @cite{A}, or a plain vector | 16134 | is 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, |
| 15974 | if @cite{B} is a non-square matrix with the same number of @emph{columns} | 16137 | if @expr{B} is a non-square matrix with the same number of @emph{columns} |
| 15975 | as @cite{A}, the equation @cite{X A = B} is solved. If you wish a vector | 16138 | as @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}, |
| 15977 | make it into a one-row matrix with @kbd{C-u 1 v p} first. To force a | 16140 | make it into a one-row matrix with @kbd{C-u 1 v p} first. To force a |
| 15978 | left-handed solution with a square matrix @cite{B}, transpose @cite{A} and | 16141 | left-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 | ||
| 15981 | HMS forms can be divided by real numbers or by other HMS forms. Error | 16144 | HMS forms can be divided by real numbers or by other HMS forms. Error |
| 15982 | forms can be divided in any combination of ways. Modulo forms where both | 16145 | forms 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 % |
| 16027 | The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') | 16190 | The @kbd{%} (@code{calc-mod}) command performs a ``modulo'' (or ``remainder'') |
| 16028 | operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined | 16191 | operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined |
| 16029 | for all real numbers @cite{a} and @cite{b} (except @cite{b=0}). For | 16192 | for all real numbers @expr{a} and @expr{b} (except @expr{b=0}). For |
| 16030 | positive @cite{b}, the result will always be between 0 (inclusive) and | 16193 | positive @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. |
| 16032 | If @cite{a} is a modulo form, its modulo is changed to @cite{b}, which | 16195 | If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which |
| 16033 | must be positive real number. | 16196 | must 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 |
| 16085 | The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the | 16248 | The @kbd{&} (@code{calc-inv}) [@code{inv}] command computes the |
| 16086 | reciprocal of a number, i.e., @cite{1 / x}. Operating on a square | 16249 | reciprocal of a number, i.e., @expr{1 / x}. Operating on a square |
| 16087 | matrix, it computes the inverse of that matrix. | 16250 | matrix, 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 |
| 16099 | The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square | 16262 | The @kbd{f h} (@code{calc-hypot}) [@code{hypot}] command computes the square |
| 16100 | root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)} | 16263 | root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)} |
| 16101 | is the length of the hypotenuse of a right triangle with sides @cite{a} | 16264 | is the length of the hypotenuse of a right triangle with sides @expr{a} |
| 16102 | and @cite{b}. If the arguments are complex numbers, their squared | 16265 | and @expr{b}. If the arguments are complex numbers, their squared |
| 16103 | magnitudes are used. | 16266 | magnitudes 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}) | |||
| 16124 | respectively. These commands also work on HMS forms, date forms, | 16287 | respectively. These commands also work on HMS forms, date forms, |
| 16125 | intervals, and infinities. (In algebraic expressions, these functions | 16288 | intervals, and infinities. (In algebraic expressions, these functions |
| 16126 | take any number of arguments and return the maximum or minimum among | 16289 | take any number of arguments and return the maximum or minimum among |
| 16127 | all the arguments.)@refill | 16290 | all 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 |
| 16135 | The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts | 16298 | The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts |
| 16136 | the ``mantissa'' part @cite{m} of its floating-point argument; @kbd{f X} | 16299 | the ``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}, |
| 16140 | where @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 | 16304 | where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that |
| 16305 | @expr{m=e=0} if the original number is zero. For integers | ||
| 16142 | and fractions, @code{mant} returns the number unchanged and @code{xpon} | 16306 | and fractions, @code{mant} returns the number unchanged and @code{xpon} |
| 16143 | returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be | 16307 | returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be |
| 16144 | used to ``unpack'' a floating-point number; this produces an integer | 16308 | used to ``unpack'' a floating-point number; this produces an integer |
| 16145 | mantissa and exponent, with the constraint that the mantissa is not | 16309 | mantissa and exponent, with the constraint that the mantissa is not |
| 16146 | a multiple of ten (again except for the @cite{m=e=0} case).@refill | 16310 | a 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 | |||
| 16152 | by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any | 16316 | by a given power of ten. Thus, @samp{scf(mant(x), xpon(x)) = x} for any |
| 16153 | real @samp{x}. The second argument must be an integer, but the first | 16317 | real @samp{x}. The second argument must be an integer, but the first |
| 16154 | may actually be any numeric value. For example, @samp{scf(5,-2) = 0.05} | 16318 | may actually be any numeric value. For example, @samp{scf(5,-2) = 0.05} |
| 16155 | or @samp{1:20} depending on the current Fraction Mode.@refill | 16319 | or @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. | |||
| 16167 | For example, incrementing @samp{12.3456} when the current precision | 16331 | For example, incrementing @samp{12.3456} when the current precision |
| 16168 | is 6 digits yields @samp{12.3457}. If the current precision had been | 16332 | is 6 digits yields @samp{12.3457}. If the current precision had been |
| 16169 | 8 digits, the result would have been @samp{12.345601}. Incrementing | 16333 | 8 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}, | ||
| 16337 | where @expr{p} is the current | ||
| 16172 | precision. These operations are defined only on integers and floats. | 16338 | precision. These operations are defined only on integers and floats. |
| 16173 | With numeric prefix arguments, they change the number by @cite{n} units. | 16339 | With numeric prefix arguments, they change the number by @expr{n} units. |
| 16174 | 16340 | ||
| 16175 | Note that incrementing followed by decrementing, or vice-versa, will | 16341 | Note that incrementing followed by decrementing, or vice-versa, will |
| 16176 | almost but not quite always cancel out. Suppose the precision is | 16342 | almost but not quite always cancel out. Suppose the precision is |
| @@ -16207,7 +16373,7 @@ expressed as an integer-valued floating-point number. | |||
| 16207 | The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command | 16373 | The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command |
| 16208 | truncates a real number to the next lower integer, i.e., toward minus | 16374 | truncates a real number to the next lower integer, i.e., toward minus |
| 16209 | infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces | 16375 | infinity. 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 |
| 16220 | The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] | 16386 | The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] |
| 16221 | command truncates toward positive infinity. Thus @kbd{3.6 I F} produces | 16387 | command truncates toward positive infinity. Thus @kbd{3.6 I F} produces |
| 16222 | 4, and @kbd{_3.6 I F} produces @i{-3}.@refill | 16388 | 4, 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 | |||
| 16233 | rounds to the nearest integer. When the fractional part is .5 exactly, | 16399 | rounds to the nearest integer. When the fractional part is .5 exactly, |
| 16234 | this command rounds away from zero. (All other rounding in the | 16400 | this command rounds away from zero. (All other rounding in the |
| 16235 | Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 | 16401 | Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 |
| 16236 | but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}.@refill | 16402 | but @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 | |||
| 16246 | The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] | 16412 | The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] |
| 16247 | command truncates toward zero. In other words, it ``chops off'' | 16413 | command truncates toward zero. In other words, it ``chops off'' |
| 16248 | everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and | 16414 | everything 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 | ||
| 16251 | These functions may not be applied meaningfully to error forms, but they | 16417 | These functions may not be applied meaningfully to error forms, but they |
| 16252 | do work for intervals. As a convenience, applying @code{floor} to a | 16418 | do 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 | |||
| 16284 | already have been rounded to the current precision before @code{rounde} | 16450 | already have been rounded to the current precision before @code{rounde} |
| 16285 | begins. For example, @samp{rounde(2.500001)} with a current precision | 16451 | begins. For example, @samp{rounde(2.500001)} with a current precision |
| 16286 | of 6 will incorrectly, or at least surprisingly, yield 2 because the | 16452 | of 6 will incorrectly, or at least surprisingly, yield 2 because the |
| 16287 | argument will first have been rounded down to @cite{2.5} (which | 16453 | argument 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 | ||
| 16290 | Each of these functions, when written in algebraic formulas, allows | 16456 | Each 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 |
| 16299 | To compute the fractional part of a number (i.e., the amount which, when | 16465 | To compute the fractional part of a number (i.e., the amount which, when |
| 16300 | added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n} | 16466 | added to `@t{floor(}@var{n}@t{)}', will produce @var{n}) just take @var{n} |
| 16301 | modulo 1 using the @code{%} command.@refill | 16467 | modulo 1 using the @code{%} command. |
| 16302 | 16468 | ||
| 16303 | Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm), | 16469 | Note also the @kbd{\} (integer quotient), @kbd{f I} (integer logarithm), |
| 16304 | and @kbd{f Q} (integer square root) commands, which are analogous to | 16470 | and @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 |
| 16315 | The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the | 16481 | The @kbd{J} (@code{calc-conj}) [@code{conj}] command computes the |
| 16316 | complex conjugate of a number. For complex number @cite{a+bi}, the | 16482 | complex conjugate of a number. For complex number @expr{a+bi}, the |
| 16317 | complex conjugate is @cite{a-bi}. If the argument is a real number, | 16483 | complex conjugate is @expr{a-bi}. If the argument is a real number, |
| 16318 | this command leaves it the same. If the argument is a vector or matrix, | 16484 | this command leaves it the same. If the argument is a vector or matrix, |
| 16319 | this command replaces each element by its complex conjugate. | 16485 | this command replaces each element by its complex conjugate. |
| 16320 | 16486 | ||
| @@ -16324,15 +16490,15 @@ this command replaces each element by its complex conjugate. | |||
| 16324 | The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the | 16490 | The @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 |
| 16326 | notation, this is simply the second component of the pair | 16492 | notation, 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{)}'. |
| 16329 | The result is expressed according to the current angular mode and will | 16495 | The result is expressed according to the current angular mode and will |
| 16330 | be in the range @i{-180} degrees (exclusive) to @i{+180} degrees | 16496 | be 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 |
| 16334 | The @code{calc-imaginary} command multiplies the number on the | 16500 | The @code{calc-imaginary} command multiplies the number on the |
| 16335 | top of the stack by the imaginary number @cite{i = (0,1)}. This | 16501 | top of the stack by the imaginary number @expr{i = (0,1)}. This |
| 16336 | command is not normally bound to a key in Calc, but it is available | 16502 | command is not normally bound to a key in Calc, but it is available |
| 16337 | on the @key{IMAG} button in Keypad Mode. | 16503 | on the @key{IMAG} button in Keypad Mode. |
| 16338 | 16504 | ||
| @@ -16342,14 +16508,14 @@ on the @key{IMAG} button in Keypad Mode. | |||
| 16342 | The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number | 16508 | The @kbd{f r} (@code{calc-re}) [@code{re}] command replaces a complex number |
| 16343 | by its real part. This command has no effect on real numbers. (As an | 16509 | by its real part. This command has no effect on real numbers. (As an |
| 16344 | added convenience, @code{re} applied to a modulo form extracts | 16510 | added convenience, @code{re} applied to a modulo form extracts |
| 16345 | the value part.)@refill | 16511 | the 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 |
| 16350 | The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number | 16516 | The @kbd{f i} (@code{calc-im}) [@code{im}] command replaces a complex number |
| 16351 | by its imaginary part; real numbers are converted to zero. With a vector | 16517 | by its imaginary part; real numbers are converted to zero. With a vector |
| 16352 | or matrix argument, these functions operate element-wise.@refill | 16518 | or 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 |
| 16384 | The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the | 16550 | The @kbd{c f} (@code{calc-float}) [@code{pfloat}] command converts the |
| 16385 | number on the top of the stack to floating-point form. For example, | 16551 | number 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 |
| 16388 | object such as a complex number or vector, each of the components is | 16554 | object such as a complex number or vector, each of the components is |
| 16389 | converted to floating-point. If the value is a formula, all numbers | 16555 | converted to floating-point. If the value is a formula, all numbers |
| 16390 | in the formula are converted to floating-point. Note that depending | 16556 | in the formula are converted to floating-point. Note that depending |
| 16391 | on the current floating-point precision, conversion to floating-point | 16557 | on the current floating-point precision, conversion to floating-point |
| 16392 | format may lose information.@refill | 16558 | format may lose information. |
| 16393 | 16559 | ||
| 16394 | As a special exception, integers which appear as powers or subscripts | 16560 | As a special exception, integers which appear as powers or subscripts |
| 16395 | are not floated by @kbd{c f}. If you really want to float a power, | 16561 | are 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. | |||
| 16442 | The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a | 16608 | The @kbd{c d} (@code{calc-to-degrees}) [@code{deg}] command converts a |
| 16443 | number into degrees form. The value on the top of the stack may be an | 16609 | number into degrees form. The value on the top of the stack may be an |
| 16444 | HMS form (interpreted as degrees-minutes-seconds), or a real number which | 16610 | HMS form (interpreted as degrees-minutes-seconds), or a real number which |
| 16445 | will be interpreted in radians regardless of the current angular mode.@refill | 16611 | will 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} | |||
| 16475 | functions in algebraic formulas, depending on the direction of | 16641 | functions in algebraic formulas, depending on the direction of |
| 16476 | conversion. (It uses @code{polar}, except that if the argument is | 16642 | conversion. (It uses @code{polar}, except that if the argument is |
| 16477 | already a polar complex number, it uses @code{rect} instead. The | 16643 | already 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 | |||
| 16488 | angular mode is different from the one under which the number was | 16654 | angular mode is different from the one under which the number was |
| 16489 | produced!) Integers and fractions are generally unaffected by this | 16655 | produced!) Integers and fractions are generally unaffected by this |
| 16490 | operation. Vectors and formulas are cleaned by cleaning each component | 16656 | operation. Vectors and formulas are cleaned by cleaning each component |
| 16491 | number (i.e., pervasively).@refill | 16657 | number (i.e., pervasively). |
| 16492 | 16658 | ||
| 16493 | If the simplification mode is set below the default level, it is raised | 16659 | If the simplification mode is set below the default level, it is raised |
| 16494 | to the default level for the purposes of this command. Thus, @kbd{c c} | 16660 | to 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 | ||
| 16810 | There is no @code{newday} function at all because @kbd{F} [@code{floor}] | 16976 | There is no @code{newday} function at all because @kbd{F} [@code{floor}] |
| 16811 | serves this purpose. Similarly, instead of @code{incday} and | 16977 | serves 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 |
| 16815 | which can adjust a date/time form by a certain number of seconds. | 16981 | which 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 |
| 16872 | Any Calc formula which evaluates to one of the above three things. | 17038 | Any Calc formula which evaluates to one of the above three things. |
| 16873 | If the formula involves the variable @cite{y}, it stands for a | 17039 | If the formula involves the variable @expr{y}, it stands for a |
| 16874 | yearly repeating holiday; @cite{y} will take on various year | 17040 | yearly repeating holiday; @expr{y} will take on various year |
| 16875 | numbers like 1992. For example, @samp{date(y, 12, 25)} specifies | 17041 | numbers like 1992. For example, @samp{date(y, 12, 25)} specifies |
| 16876 | Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies | 17042 | Christmas day, and @samp{newweek(date(y, 11, 7), 4) + 21} specifies |
| 16877 | Thanksgiving (which is held on the fourth Thursday of November). | 17043 | Thanksgiving (which is held on the fourth Thursday of November). |
| 16878 | If the formula involves the variable @cite{m}, that variable | 17044 | If the formula involves the variable @expr{m}, that variable |
| 16879 | takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is | 17045 | takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is |
| 16880 | a holiday that takes place on the 15th of every month. | 17046 | a 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 | |||
| 17290 | 20% smaller than 50. (The answers are different in magnitude | 17456 | 20% smaller than 50. (The answers are different in magnitude |
| 17291 | because, in the first case, we're increasing by 25% of 40, but | 17457 | because, in the first case, we're increasing by 25% of 40, but |
| 17292 | in the second case, we're decreasing by 20% of 50.) The effect | 17458 | in the second case, we're decreasing by 20% of 50.) The effect |
| 17293 | of @kbd{40 @key{RET} 50 b %} is to compute @cite{(50-40)/40}, converting | 17459 | of @kbd{40 @key{RET} 50 b %} is to compute @expr{(50-40)/40}, converting |
| 17294 | the answer to percentage form as if by @kbd{c %}. | 17460 | the 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 | |||
| 17334 | fourth argument, which is used as an initial lump sum in the sense | 17500 | fourth argument, which is used as an initial lump sum in the sense |
| 17335 | of @code{fvl}. In other words, @code{fv(@var{rate}, @var{n}, | 17501 | of @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 | ||
| 17339 | To illustrate the relationships between these functions, we could | 17505 | To illustrate the relationships between these functions, we could |
| 17340 | do the @code{fvb} calculation ``by hand'' using @code{fvl}. The | 17506 | do 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 | |||
| 17352 | as the beginning of the next, so what this really means is that we've | 17518 | as the beginning of the next, so what this really means is that we've |
| 17353 | lost the payment at year zero (which contributed $1300.78), but we're | 17519 | lost the payment at year zero (which contributed $1300.78), but we're |
| 17354 | now counting the payment at year five (which, since it didn't have | 17520 | now counting the payment at year five (which, since it didn't have |
| 17355 | a chance to earn interest, counts as $1000). Indeed, @cite{5569.96 = | 17521 | a chance to earn interest, counts as $1000). Indeed, @expr{5569.96 = |
| 17356 | 5870.73 - 1300.78 + 1000} (give or take a bit of roundoff error). | 17522 | 5870.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 | |||
| 17382 | the return from leaving the money in the bank, which is | 17548 | the 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 |
| 17384 | you would have to put up in advance. The @code{pv} function | 17550 | you would have to put up in advance. The @code{pv} function |
| 17385 | finds the break-even point, @cite{x = 6479.44}, at which | 17551 | finds 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 |
| 17387 | the largest amount you should be willing to invest. | 17553 | the largest amount you should be willing to invest. |
| 17388 | 17554 | ||
| @@ -17431,7 +17597,7 @@ vector statistical functions like @code{vsum}. | |||
| 17431 | payment arguments, each either a vector or a plain number, all these | 17597 | payment arguments, each either a vector or a plain number, all these |
| 17432 | values are collected left-to-right into the complete list of payments. | 17598 | values are collected left-to-right into the complete list of payments. |
| 17433 | A numeric prefix argument on the @kbd{b N} command says how many | 17599 | A numeric prefix argument on the @kbd{b N} command says how many |
| 17434 | payment values or vectors to take from the stack.@refill | 17600 | payment 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 | |||
| 17453 | the amount of periodic payment necessary to amortize a loan. | 17619 | the amount of periodic payment necessary to amortize a loan. |
| 17454 | Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the | 17620 | Thus @code{pmt(@var{rate}, @var{n}, @var{amount})} equals the |
| 17455 | value of @var{payment} such that @code{pv(@var{rate}, @var{n}, | 17621 | value 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 | |||
| 17475 | the value of @var{n} such that @code{pv(@var{rate}, @var{n}, | 17641 | the 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 |
| 17477 | ever to amortize a loan for @var{amount} at interest rate @var{rate}, | 17643 | ever to amortize a loan for @var{amount} at interest rate @var{rate}, |
| 17478 | the @code{nper} function is left in symbolic form.@refill | 17644 | the @code{nper} function is left in symbolic form. |
| 17479 | 17645 | ||
| 17480 | @kindex I b # | 17646 | @kindex I b # |
| 17481 | @tindex nperb | 17647 | @tindex nperb |
| 17482 | The @kbd{I b #} [@code{nperb}] command does the same computation | 17648 | The @kbd{I b #} [@code{nperb}] command does the same computation |
| 17483 | but using @code{pvb} instead of @code{pv}. You can give a fourth | 17649 | but using @code{pvb} instead of @code{pv}. You can give a fourth |
| 17484 | lump-sum argument to these functions, but the computation will be | 17650 | lump-sum argument to these functions, but the computation will be |
| 17485 | rather slow in the four-argument case.@refill | 17651 | rather 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 | |||
| 17490 | using @code{pvl}. By exchanging @var{payment} and @var{amount} you | 17656 | using @code{pvl}. By exchanging @var{payment} and @var{amount} you |
| 17491 | can also get the solution for @code{fvl}. For example, | 17657 | can 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 |
| 17493 | bank account earning 8%, it will take nine years to grow to $2000.@refill | 17659 | bank 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 | |||
| 17499 | the rate of return on an investment. This is also an inverse of @code{pv}: | 17665 | the 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 | |||
| 17511 | accept an optional fourth argument just like @code{pv} and @code{pvb}. | 17677 | accept an optional fourth argument just like @code{pv} and @code{pvb}. |
| 17512 | To redo the above example from a different perspective, | 17678 | To 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 |
| 17514 | interest rate of 8% in order to double your account in nine years.@refill | 17680 | interest 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} | |||
| 17573 | parameter as well, although it will ignore its value except that the | 17739 | parameter as well, although it will ignore its value except that the |
| 17574 | return value will as usual be zero if @var{period} is out of range. | 17740 | return value will as usual be zero if @var{period} is out of range. |
| 17575 | 17741 | ||
| 17576 | For example, pushing the vector @cite{[1,2,3,4,5]} (perhaps with @kbd{v x 5}) | 17742 | For example, pushing the vector @expr{[1,2,3,4,5]} (perhaps with @kbd{v x 5}) |
| 17577 | and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$), | 17743 | and then mapping @kbd{V M ' [sln(12000,2000,5,$), syd(12000,2000,5,$), |
| 17578 | ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare | 17744 | ddb(12000,2000,5,$)] @key{RET}} produces a matrix that allows us to compare |
| 17579 | the three depreciation methods: | 17745 | the 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, |
| 17595 | and @kbd{ddb} weights the depreciation even more toward the beginning. | 17761 | and @kbd{ddb} weights the depreciation even more toward the beginning. |
| 17596 | 17762 | ||
| 17597 | Summing columns with @kbd{V R : +} yields @cite{[10000, 10000, 10000]}; | 17763 | Summing columns with @kbd{V R : +} yields @expr{[10000, 10000, 10000]}; |
| 17598 | the total depreciation in any method is (by definition) the | 17764 | the total depreciation in any method is (by definition) the |
| 17599 | difference between the cost and the salvage value. | 17765 | difference 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 |
| 17719 | In @code{pmt} and @code{pmtb}, @cite{x=0} if omitted. | 17885 | In @code{pmt} and @code{pmtb}, @expr{x=0} if omitted. |
| 17720 | 17886 | ||
| 17721 | These functions accept any numeric objects, including error forms, | 17887 | These functions accept any numeric objects, including error forms, |
| 17722 | intervals, and even (though not very usefully) complex numbers. The | 17888 | intervals, and even (though not very usefully) complex numbers. The |
| @@ -17776,31 +17942,34 @@ commands, respectively). You may also wish to enable display of leading | |||
| 17776 | zeros with @kbd{d z}. @xref{Radix Modes}. | 17942 | zeros with @kbd{d z}. @xref{Radix Modes}. |
| 17777 | 17943 | ||
| 17778 | @cindex Word size for binary operations | 17944 | @cindex Word size for binary operations |
| 17779 | The Calculator maintains a current @dfn{word size} @cite{w}, an | 17945 | The Calculator maintains a current @dfn{word size} @expr{w}, an |
| 17780 | arbitrary positive or negative integer. For a positive word size, all | 17946 | arbitrary positive or negative integer. For a positive word size, all |
| 17781 | of the binary operations described here operate modulo @cite{2^w}. In | 17947 | of the binary operations described here operate modulo @expr{2^w}. In |
| 17782 | particular, negative arguments are converted to positive integers modulo | 17948 | particular, 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 | ||
| 17785 | If the word size is negative, binary operations produce 2's complement | 17951 | If the word size is negative, binary operations produce 2's complement |
| 17786 | integers from @c{$-2^{-w-1}$} | 17952 | integers 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))} |
| 17789 | mode accepts inputs in any range; the sign of @cite{w} affects only | 17955 | to |
| 17790 | the results produced. | 17956 | @texline @tmath{2^{-w-1}-1} |
| 17957 | @infoline @expr{2^(-w-1)-1} | ||
| 17958 | inclusive. Either mode accepts inputs in any range; the sign of | ||
| 17959 | @expr{w} affects only the results produced. | ||
| 17791 | 17960 | ||
| 17792 | @kindex b c | 17961 | @kindex b c |
| 17793 | @pindex calc-clip | 17962 | @pindex calc-clip |
| 17794 | @tindex clip | 17963 | @tindex clip |
| 17795 | The @kbd{b c} (@code{calc-clip}) | 17964 | The @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 |
| 17798 | their results to the current word size. Note that other operations like | 17967 | their results to the current word size. Note that other operations like |
| 17799 | addition do not use the current word size, since integer addition | 17968 | addition do not use the current word size, since integer addition |
| 17800 | generally is not ``binary.'' (However, @pxref{Simplification Modes}, | 17969 | generally 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 |
| 17802 | bits @kbd{b c} converts a number to the range 0 to 255; with a word | 17971 | bits @kbd{b c} converts a number to the range 0 to 255; with a word |
| 17803 | size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127.@refill | 17972 | size 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 | |||
| 17820 | in symbolic form unless the all of its argument(s) are integers or | 17989 | in symbolic form unless the all of its argument(s) are integers or |
| 17821 | integer-valued floats. | 17990 | integer-valued floats. |
| 17822 | 17991 | ||
| 17823 | If either or both arguments are modulo forms for which @cite{M} is a | 17992 | If either or both arguments are modulo forms for which @expr{M} is a |
| 17824 | power of two, that power of two is taken as the word size unless a | 17993 | power of two, that power of two is taken as the word size unless a |
| 17825 | numeric prefix argument overrides it. The current word size is never | 17994 | numeric prefix argument overrides it. The current word size is never |
| 17826 | consulted when modulo-power-of-two forms are involved. | 17995 | consulted 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 |
| 17831 | The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise | 18000 | The @kbd{b a} (@code{calc-and}) [@code{and}] command computes the bitwise |
| 17832 | AND of the two numbers on the top of the stack. In other words, for each | 18001 | AND of the two numbers on the top of the stack. In other words, for each |
| 17833 | of the @cite{w} binary digits of the two numbers (pairwise), the corresponding | 18002 | of the @expr{w} binary digits of the two numbers (pairwise), the corresponding |
| 17834 | bit of the result is 1 if and only if both input bits are 1: | 18003 | bit 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 |
| 17967 | One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes | 18136 | One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes |
| 17968 | the value of @c{$\pi$} | 18137 | the value of @cpi{} (at the current precision) onto the stack. With the |
| 17969 | @cite{pi} (at the current precision) onto the stack. With the | 18138 | Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms. |
| 17970 | Hyperbolic flag, it pushes the value @cite{e}, the base of natural logarithms. | 18139 | With the Inverse flag, it pushes Euler's constant |
| 17971 | With 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} |
| 17973 | pushes 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 | 18143 | pushes the ``golden ratio'' |
| 18144 | @texline @tmath{\phi} | ||
| 18145 | @infoline @expr{phi} | ||
| 18146 | (about 1.618). (At present, Euler's constant is not available | ||
| 17975 | to unlimited precision; Calc knows only the first 100 digits.) | 18147 | to unlimited precision; Calc knows only the first 100 digits.) |
| 17976 | In Symbolic mode, these commands push the | 18148 | In Symbolic mode, these commands push the |
| 17977 | actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, | 18149 | actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, |
| 17978 | respectively, instead of their values; @pxref{Symbolic Mode}.@refill | 18150 | respectively, 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 |
| 18029 | The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the | 18201 | The shift-@kbd{E} (@code{calc-exp}) [@code{exp}] command computes the |
| 18030 | exponential, i.e., @cite{e} raised to the power of the number on the stack. | 18202 | exponential, i.e., @expr{e} raised to the power of the number on the stack. |
| 18031 | The meanings of the Inverse and Hyperbolic flags follow from those for | 18203 | The meanings of the Inverse and Hyperbolic flags follow from those for |
| 18032 | the @code{calc-ln} command. | 18204 | the @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}], |
| 18049 | it raises ten to a given power.) Note that the common logarithm of a | 18221 | it raises ten to a given power.) Note that the common logarithm of a |
| 18050 | complex number is computed by taking the natural logarithm and dividing | 18222 | complex number is computed by taking the natural logarithm and dividing |
| 18051 | by @c{$\ln10$} | 18223 | by |
| 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 |
| 18059 | The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm | 18232 | The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm |
| 18060 | to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since | 18233 | to 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}. |
| 18063 | will be either @cite{1:2} or @cite{0.5} depending on the current Fraction | 18236 | In certain cases like @samp{log(3,9)}, the result |
| 18237 | will be either @expr{1:2} or @expr{0.5} depending on the current Fraction | ||
| 18064 | Mode setting. With the Inverse flag [@code{alog}], this command is | 18238 | Mode setting. With the Inverse flag [@code{alog}], this command is |
| 18065 | similar to @kbd{^} except that the order of the arguments is reversed. | 18239 | similar 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. | |||
| 18070 | The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the | 18244 | The @kbd{f I} (@code{calc-ilog}) [@code{ilog}] command computes the |
| 18071 | integer logarithm of a number to any base. The number and the base must | 18245 | integer logarithm of a number to any base. The number and the base must |
| 18072 | themselves be positive integers. This is the true logarithm, rounded | 18246 | themselves be positive integers. This is the true logarithm, rounded |
| 18073 | down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @cite{x} in the | 18247 | down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @expr{x} in the |
| 18074 | range from 1000 to 9999. If both arguments are positive integers, exact | 18248 | range from 1000 to 9999. If both arguments are positive integers, exact |
| 18075 | integer arithmetic is used; otherwise, this is equivalent to | 18249 | integer 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 |
| 18081 | The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes | 18255 | The @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}, |
| 18084 | answer when the result is close to zero, i.e., when @c{$e^x$} | 18258 | but using an algorithm that produces a more accurate |
| 18085 | @cite{exp(x)} is close | 18259 | answer when the result is close to zero, i.e., when |
| 18086 | to one. | 18260 | @texline @tmath{e^x} |
| 18261 | @infoline @expr{exp(x)} | ||
| 18262 | is 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 |
| 18091 | The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes | 18267 | The @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)}, |
| 18094 | to zero. | 18270 | producing 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 | |||
| 18104 | of an angle or complex number. If the input is an HMS form, it is interpreted | 18280 | of an angle or complex number. If the input is an HMS form, it is interpreted |
| 18105 | as degrees-minutes-seconds; otherwise, the input is interpreted according | 18281 | as degrees-minutes-seconds; otherwise, the input is interpreted according |
| 18106 | to the current angular mode. It is best to use Radians mode when operating | 18282 | to the current angular mode. It is best to use Radians mode when operating |
| 18107 | on complex numbers.@refill | 18283 | on complex numbers. |
| 18108 | 18284 | ||
| 18109 | Calc's ``units'' mechanism includes angular units like @code{deg}, | 18285 | Calc'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 |
| 18121 | have stored a different value in the variable @samp{pi}; this is one | 18297 | have stored a different value in the variable @samp{pi}; this is one |
| 18122 | reason why changing built-in variables is a bad idea. Arguments of | 18298 | reason why changing built-in variables is a bad idea. Arguments of |
| 18123 | the form @cite{x} plus a multiple of @c{$\pi/2$} | 18299 | the form @expr{x} plus a multiple of @cpiover{2} are also simplified. |
| 18124 | @cite{pi/2} are also simplified. | 18300 | Calc includes similar formulas for @code{cos} and @code{tan}. |
| 18125 | Calc includes similar formulas for @code{cos} and @code{tan}.@refill | ||
| 18126 | 18301 | ||
| 18127 | The @kbd{a s} command knows all angles which are integer multiples of | 18302 | The @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, | ||
| 18132 | analogous simplifications occur for integer multiples of 15 or 18 | 18304 | analogous simplifications occur for integer multiples of 15 or 18 |
| 18133 | degrees, and for arguments plus multiples of 90 degrees. | 18305 | degrees, 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}]}. |
| 18254 | With the Inverse flag [@code{arcsincos}], this command takes a two-element | 18426 | With the Inverse flag [@code{arcsincos}], this command takes a two-element |
| 18255 | vector as an argument and computes @code{arctan2} of the elements. | 18427 | vector 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 | |||
| 18278 | gamma function. For positive integer arguments, this is related to the | 18450 | gamma function. For positive integer arguments, this is related to the |
| 18279 | factorial function: @samp{gamma(n+1) = fact(n)}. For general complex | 18451 | factorial function: @samp{gamma(n+1) = fact(n)}. For general complex |
| 18280 | arguments the gamma function can be defined by the following definite | 18452 | arguments the gamma function can be defined by the following definite |
| 18281 | integral: @c{$\Gamma(a) = \int_0^\infty t^{a-1} e^t dt$} | 18453 | integral: |
| 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 |
| 18312 | The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes | 18485 | The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes |
| 18313 | the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by | 18486 | the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by |
| 18314 | the integral, @c{$P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)$} | 18487 | the 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)}. |
| 18316 | This 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)}. |
| 18490 | This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the | ||
| 18317 | definition of the normal gamma function). | 18491 | definition of the normal gamma function). |
| 18318 | 18492 | ||
| 18319 | Several other varieties of incomplete gamma function are defined. | 18493 | Several other varieties of incomplete gamma function are defined. |
| 18320 | The complement of @cite{P(a,x)}, called @cite{Q(a,x) = 1-P(a,x)} by | 18494 | The complement of @expr{P(a,x)}, called @expr{Q(a,x) = 1-P(a,x)} by |
| 18321 | some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command. | 18495 | some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command. |
| 18322 | You can think of this as taking the other half of the integral, from | 18496 | You 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 |
| 18326 | The functions corresponding to the integrals that define @cite{P(a,x)} | 18500 | The functions corresponding to the integrals that define @expr{P(a,x)} |
| 18327 | and @cite{Q(a,x)} but without the normalizing @cite{1/gamma(a)} | 18501 | and @expr{Q(a,x)} but without the normalizing @expr{1/gamma(a)} |
| 18328 | factor are called @cite{g(a,x)} and @cite{G(a,x)}, respectively | 18502 | factor 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 |
| 18330 | letter gamma). You can obtain these using the @kbd{H f G} [@code{gammag}] | 18504 | letter gamma). You can obtain these using the @kbd{H f G} [@code{gammag}] |
| 18331 | and @kbd{H I f G} [@code{gammaG}] commands. | 18505 | and @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 |
| 18345 | The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the | 18519 | The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the |
| 18346 | Euler beta function, which is defined in terms of the gamma function as | 18520 | Euler 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$} | 18523 | or 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 |
| 18357 | The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes | 18532 | The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes |
| 18358 | the incomplete beta function @cite{I(x,a,b)}. It is defined by | 18533 | the 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)}. |
| 18361 | Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding | 18536 | Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding |
| 18362 | un-normalized version [@code{betaB}]. | 18537 | un-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 |
| 18369 | The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the | 18544 | The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the |
| 18370 | error function @c{$\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt$} | 18545 | error 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)}. | ||
| 18372 | The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] | 18548 | The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] |
| 18373 | is the corresponding integral from @samp{x} to infinity; the sum | 18549 | is 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 |
| 18385 | functions of the first and second kinds, respectively. | 18561 | functions of the first and second kinds, respectively. |
| 18386 | In @samp{besJ(n,x)} and @samp{besY(n,x)} the ``order'' parameter | 18562 | In @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. |
| 18388 | Calc's implementation of the Bessel functions currently limits the | 18564 | Calc's implementation of the Bessel functions currently limits the |
| 18389 | precision to 8 digits, and may not be exact even to that precision. | 18565 | precision to 8 digits, and may not be exact even to that precision. |
| 18390 | Use with care!@refill | 18566 | Use 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} | |||
| 18420 | efficiency or accuracy. You may need to increase the floating precision | 18596 | efficiency or accuracy. You may need to increase the floating precision |
| 18421 | and wait a while to get suitable answers from them. | 18597 | and wait a while to get suitable answers from them. |
| 18422 | 18598 | ||
| 18423 | For @samp{sqrt(a+bi)}: When @cite{a<0} and @cite{b} is small but positive | 18599 | For @samp{sqrt(a+bi)}: When @expr{a<0} and @expr{b} is small but positive |
| 18424 | or zero, the result is close to the @cite{+i} axis. For @cite{b} small and | 18600 | or zero, the result is close to the @expr{+i} axis. For @expr{b} small and |
| 18425 | negative, the result is close to the @cite{-i} axis. The result always lies | 18601 | negative, the result is close to the @expr{-i} axis. The result always lies |
| 18426 | in the right half of the complex plane. | 18602 | in the right half of the complex plane. |
| 18427 | 18603 | ||
| 18428 | For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}. | 18604 | For @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 | |||
| 18431 | negative real axis. | 18607 | negative real axis. |
| 18432 | 18608 | ||
| 18433 | The following table describes these branch cuts in another way. | 18609 | The following table describes these branch cuts in another way. |
| 18434 | If the real and imaginary parts of @cite{z} are as shown, then | 18610 | If the real and imaginary parts of @expr{z} are as shown, then |
| 18435 | the real and imaginary parts of @cite{f(z)} will be as shown. | 18611 | the real and imaginary parts of @expr{f(z)} will be as shown. |
| 18436 | Here @code{eps} stands for a small positive value; each | 18612 | Here @code{eps} stands for a small positive value; each |
| 18437 | occurrence of @code{eps} may stand for a different small value. | 18613 | occurrence 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. | |||
| 18448 | For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. | 18624 | For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. |
| 18449 | One interesting consequence of this is that @samp{(-8)^1:3} does | 18625 | One interesting consequence of this is that @samp{(-8)^1:3} does |
| 18450 | not evaluate to @i{-2} as you might expect, but to the complex | 18626 | not evaluate to @i{-2} as you might expect, but to the complex |
| 18451 | number @cite{(1., 1.732)}. Both of these are valid cube roots | 18627 | number @expr{(1., 1.732)}. Both of these are valid cube roots |
| 18452 | of @i{-8} (as is @cite{(1., -1.732)}); Calc chooses a perhaps | 18628 | of @i{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps |
| 18453 | less-obvious root for the sake of mathematical consistency. | 18629 | less-obvious root for the sake of mathematical consistency. |
| 18454 | 18630 | ||
| 18455 | For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}. | 18631 | For @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 | ||
| 18462 | For @samp{arctan(z)}: This is defined by | 18638 | For @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 |
| 18464 | imaginary axis, below @cite{-i} and above @cite{i}. | 18640 | imaginary axis, below @expr{-i} and above @expr{i}. |
| 18465 | 18641 | ||
| 18466 | For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}. | 18642 | For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}. |
| 18467 | The branch cuts are on the imaginary axis, below @cite{-i} and | 18643 | The branch cuts are on the imaginary axis, below @expr{-i} and |
| 18468 | above @cite{i}. | 18644 | above @expr{i}. |
| 18469 | 18645 | ||
| 18470 | For @samp{arccosh(z)}: This is defined by | 18646 | For @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. | |||
| 18543 | The @kbd{k r} (@code{calc-random}) [@code{random}] command produces | 18719 | The @kbd{k r} (@code{calc-random}) [@code{random}] command produces |
| 18544 | random numbers of various sorts. | 18720 | random numbers of various sorts. |
| 18545 | 18721 | ||
| 18546 | Given a positive numeric prefix argument @cite{M}, it produces a random | 18722 | Given a positive numeric prefix argument @expr{M}, it produces a random |
| 18547 | integer @cite{N} in the range @c{$0 \le N < M$} | 18723 | integer @expr{N} in the range |
| 18548 | @cite{0 <= N < M}. Each of the @cite{M} | 18724 | @texline @tmath{0 \le N < M}. |
| 18549 | values appears with equal probability.@refill | 18725 | @infoline @expr{0 <= N < M}. |
| 18726 | Each of the @expr{M} values appears with equal probability. | ||
| 18550 | 18727 | ||
| 18551 | With no numeric prefix argument, the @kbd{k r} command takes its argument | 18728 | With no numeric prefix argument, the @kbd{k r} command takes its argument |
| 18552 | from the stack instead. Once again, if this is a positive integer @cite{M} | 18729 | from the stack instead. Once again, if this is a positive integer @expr{M} |
| 18553 | the result is a random integer less than @cite{M}. However, note that | 18730 | the result is a random integer less than @expr{M}. However, note that |
| 18554 | while numeric prefix arguments are limited to six digits or so, an @cite{M} | 18731 | while numeric prefix arguments are limited to six digits or so, an @expr{M} |
| 18555 | taken from the stack can be arbitrarily large. If @cite{M} is negative, | 18732 | taken from the stack can be arbitrarily large. If @expr{M} is negative, |
| 18556 | the result is a random integer in the range @c{$M < N \le 0$} | 18733 | the 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}. | |
| 18559 | If the value on the stack is a floating-point number @cite{M}, the result | 18736 | |
| 18560 | is a random floating-point number @cite{N} in the range @c{$0 \le N < M$} | 18737 | If the value on the stack is a floating-point number @expr{M}, the result |
| 18561 | @cite{0 <= N < M} | 18738 | is a random floating-point number @expr{N} in the range |
| 18562 | or @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 | 18741 | or | |
| 18565 | If @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}, | ||
| 18744 | according to the sign of @expr{M}. | ||
| 18745 | |||
| 18746 | If @expr{M} is zero, the result is a Gaussian-distributed random real | ||
| 18566 | number; the distribution has a mean of zero and a standard deviation | 18747 | number; the distribution has a mean of zero and a standard deviation |
| 18567 | of one. The algorithm used generates random numbers in pairs; thus, | 18748 | of one. The algorithm used generates random numbers in pairs; thus, |
| 18568 | every other call to this function will be especially fast. | 18749 | every other call to this function will be especially fast. |
| 18569 | 18750 | ||
| 18570 | If @cite{M} is an error form @c{$m$ @code{+/-} $\sigma$} | 18751 | If @expr{M} is an error form |
| 18571 | @samp{m +/- s} where @var{m} | 18752 | @texline @tmath{m} @code{+/-} @tmath{\sigma} |
| 18572 | and @c{$\sigma$} | 18753 | @infoline @samp{m +/- s} |
| 18573 | @var{s} are both real numbers, the result uses a Gaussian | 18754 | where @var{m} and |
| 18574 | distribution with mean @var{m} and standard deviation @c{$\sigma$} | 18755 | @texline @tmath{\sigma} |
| 18756 | @infoline @var{s} | ||
| 18757 | are both real numbers, the result uses a Gaussian distribution with mean | ||
| 18758 | @var{m} and standard deviation | ||
| 18759 | @texline @tmath{\sigma}. | ||
| 18575 | @var{s}. | 18760 | @var{s}. |
| 18576 | 18761 | ||
| 18577 | If @cite{M} is an interval form, the lower and upper bounds specify the | 18762 | If @expr{M} is an interval form, the lower and upper bounds specify the |
| 18578 | acceptable limits of the random numbers. If both bounds are integers, | 18763 | acceptable limits of the random numbers. If both bounds are integers, |
| 18579 | the result is a random integer in the specified range. If either bound | 18764 | the result is a random integer in the specified range. If either bound |
| 18580 | is floating-point, the result is a random real number in the specified | 18765 | is 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 | |||
| 18586 | additionally return 2.00000, but the probability of this happening is | 18771 | additionally return 2.00000, but the probability of this happening is |
| 18587 | extremely small.) | 18772 | extremely small.) |
| 18588 | 18773 | ||
| 18589 | If @cite{M} is a vector, the result is one element taken at random from | 18774 | If @expr{M} is a vector, the result is one element taken at random from |
| 18590 | the vector. All elements of the vector are given equal probabilities. | 18775 | the 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 |
| 18611 | The @kbd{k a} (@code{calc-random-again}) command produces another random | 18796 | The @kbd{k a} (@code{calc-random-again}) command produces another random |
| 18612 | number, re-using the most recent value of @cite{M}. With a numeric | 18797 | number, re-using the most recent value of @expr{M}. With a numeric |
| 18613 | prefix argument @var{n}, it produces @var{n} more random numbers using | 18798 | prefix argument @var{n}, it produces @var{n} more random numbers using |
| 18614 | that value of @cite{M}. | 18799 | that 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}. | |||
| 18619 | The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several | 18804 | The @kbd{k h} (@code{calc-shuffle}) command produces a vector of several |
| 18620 | random values with no duplicates. The value on the top of the stack | 18805 | random values with no duplicates. The value on the top of the stack |
| 18621 | specifies the set from which the random values are drawn, and may be any | 18806 | specifies the set from which the random values are drawn, and may be any |
| 18622 | of the @cite{M} formats described above. The numeric prefix argument | 18807 | of the @expr{M} formats described above. The numeric prefix argument |
| 18623 | gives the length of the desired list. (If you do not provide a numeric | 18808 | gives the length of the desired list. (If you do not provide a numeric |
| 18624 | prefix argument, the length of the list is taken from the top of the | 18809 | prefix argument, the length of the list is taken from the top of the |
| 18625 | stack, and @cite{M} from second-to-top.) | 18810 | stack, and @expr{M} from second-to-top.) |
| 18626 | 18811 | ||
| 18627 | If @cite{M} is a floating-point number, zero, or an error form (so | 18812 | If @expr{M} is a floating-point number, zero, or an error form (so |
| 18628 | that the random values are being drawn from the set of real numbers) | 18813 | that the random values are being drawn from the set of real numbers) |
| 18629 | there is little practical difference between using @kbd{k h} and using | 18814 | there 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 | |||
| 18632 | a very real chance that multiple @kbd{k r}'s will produce the same | 18817 | a very real chance that multiple @kbd{k r}'s will produce the same |
| 18633 | number more than once. The @kbd{k h} command produces a vector whose | 18818 | number more than once. The @kbd{k h} command produces a vector whose |
| 18634 | elements are always distinct. (Actually, there is a slight exception: | 18819 | elements are always distinct. (Actually, there is a slight exception: |
| 18635 | If @cite{M} is a vector, no given vector element will be drawn more | 18820 | If @expr{M} is a vector, no given vector element will be drawn more |
| 18636 | than once, but if several elements of @cite{M} are equal, they may | 18821 | than once, but if several elements of @expr{M} are equal, they may |
| 18637 | each make it into the result vector.) | 18822 | each make it into the result vector.) |
| 18638 | 18823 | ||
| 18639 | One use of @kbd{k h} is to rearrange a list at random. This happens | 18824 | One 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 |
| 18644 | by @cite{M}. Naturally, this is allowed only when @cite{M} specifies | 18829 | by @expr{M}. Naturally, this is allowed only when @expr{M} specifies |
| 18645 | a small discrete set of possibilities. | 18830 | a small discrete set of possibilities. |
| 18646 | 18831 | ||
| 18647 | To do the equivalent of @kbd{k h} but with duplications allowed, | 18832 | To do the equivalent of @kbd{k h} but with duplications allowed, |
| 18648 | given @cite{M} on the stack and with @var{n} just entered as a numeric | 18833 | given @expr{M} on the stack and with @var{n} just entered as a numeric |
| 18649 | prefix, use @kbd{v b} to build a vector of copies of @cite{M}, then use | 18834 | prefix, 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 |
| 18651 | elements of this vector. @xref{Matrix Functions}. | 18836 | elements of this vector. @xref{Matrix Functions}. |
| 18652 | 18837 | ||
| @@ -18683,10 +18868,12 @@ generators that are typically used to implement @code{random}. | |||
| 18683 | 18868 | ||
| 18684 | If @code{RandSeed} contains an integer, Calc uses this integer to | 18869 | If @code{RandSeed} contains an integer, Calc uses this integer to |
| 18685 | seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, | 18870 | seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, |
| 18686 | computing @c{$X_{n-55} - X_{n-24}$} | 18871 | computing |
| 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}). | ||
| 18874 | This method expands the seed | ||
| 18688 | value into a large table which is maintained internally; the variable | 18875 | value 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]} |
| 18690 | to indicate that the seed has been absorbed into this table. When | 18877 | to 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 |
| 18692 | continue to use the same internal table as last time. There is no | 18879 | continue to use the same internal table as last time. There is no |
| @@ -18718,16 +18905,21 @@ value. | |||
| 18718 | 18905 | ||
| 18719 | To create a random floating-point number with precision @var{p}, Calc | 18906 | To create a random floating-point number with precision @var{p}, Calc |
| 18720 | simply creates a random @var{p}-digit integer and multiplies by | 18907 | simply 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}. |
| 18910 | The resulting random numbers should be very clean, but note | ||
| 18723 | that relatively small numbers will have few significant random digits. | 18911 | that relatively small numbers will have few significant random digits. |
| 18724 | In other words, with a precision of 12, you will occasionally get | 18912 | In other words, with a precision of 12, you will occasionally get |
| 18725 | numbers on the order of @c{$10^{-9}$} | 18913 | numbers 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} |
| 18728 | will only have two or three random digits since they correspond to small | 18916 | or |
| 18729 | integers times @c{$10^{-12}$} | 18917 | @texline @tmath{10^{-10}}, |
| 18730 | @cite{10^-12}. | 18918 | @infoline @expr{10^-10}, |
| 18919 | but those numbers will only have two or three random digits since they | ||
| 18920 | correspond to small integers times | ||
| 18921 | @texline @tmath{10^{-12}}. | ||
| 18922 | @infoline @expr{10^-12}. | ||
| 18731 | 18923 | ||
| 18732 | To create a random integer in the interval @samp{[0 .. @var{m})}, Calc | 18924 | To create a random integer in the interval @samp{[0 .. @var{m})}, Calc |
| 18733 | counts the digits in @var{m}, creates a random integer with three | 18925 | counts 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 | |||
| 18761 | numerators, and the LCM of the denominators. This definition is | 18953 | numerators, and the LCM of the denominators. This definition is |
| 18762 | consistent with the idea that @samp{a / gcd(a,x)} should yield an | 18954 | consistent with the idea that @samp{a / gcd(a,x)} should yield an |
| 18763 | integer for any @samp{a} and @samp{x}. For other types of arguments, | 18955 | integer for any @samp{a} and @samp{x}. For other types of arguments, |
| 18764 | the operation is left in symbolic form.@refill | 18956 | the 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 | |||
| 18769 | The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the | 18961 | The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the |
| 18770 | Least Common Multiple of two integers or fractions. The product of | 18962 | Least Common Multiple of two integers or fractions. The product of |
| 18771 | the LCM and GCD of two numbers is equal to the product of the | 18963 | the LCM and GCD of two numbers is equal to the product of the |
| 18772 | numbers.@refill | 18964 | numbers. |
| 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 |
| 18777 | The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes | 18969 | The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes |
| 18778 | the GCD of two integers @cite{x} and @cite{y} and returns a vector | 18970 | the 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, | |||
| 18794 | as defined by the Euler Gamma function. Please note that computation of | 18987 | as defined by the Euler Gamma function. Please note that computation of |
| 18795 | large factorials can be slow; using floating-point format will help | 18988 | large factorials can be slow; using floating-point format will help |
| 18796 | since fewer digits must be maintained. The same is true of many of | 18989 | since fewer digits must be maintained. The same is true of many of |
| 18797 | the commands in this section.@refill | 18990 | the 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 !! |
| 18806 | The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command | 18999 | The @kbd{k d} (@code{calc-double-factorial}) [@code{dfact}] command |
| 18807 | computes the ``double factorial'' of an integer. For an even integer, | 19000 | computes the ``double factorial'' of an integer. For an even integer, |
| 18808 | this is the product of even integers from 2 to @cite{N}. For an odd | 19001 | this is the product of even integers from 2 to @expr{N}. For an odd |
| 18809 | integer, this is the product of odd integers from 3 to @cite{N}. If | 19002 | integer, this is the product of odd integers from 3 to @expr{N}. If |
| 18810 | the argument is an integer-valued float, the result is a floating-point | 19003 | the argument is an integer-valued float, the result is a floating-point |
| 18811 | approximation. This function is undefined for negative even integers. | 19004 | approximation. This function is undefined for negative even integers. |
| 18812 | The notation @cite{N!!} is also recognized for double factorials.@refill | 19005 | The 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 |
| 18817 | The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the | 19010 | The @kbd{k c} (@code{calc-choose}) [@code{choose}] command computes the |
| 18818 | binomial coefficient @cite{N}-choose-@cite{M}, where @cite{M} is the number | 19011 | binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number |
| 18819 | on the top of the stack and @cite{N} is second-to-top. If both arguments | 19012 | on the top of the stack and @expr{N} is second-to-top. If both arguments |
| 18820 | are integers, the result is an exact integer. Otherwise, the result is a | 19013 | are integers, the result is an exact integer. Otherwise, the result is a |
| 18821 | floating-point approximation. The binomial coefficient is defined for all | 19014 | floating-point approximation. The binomial coefficient is defined for all |
| 18822 | real numbers by @c{$N! \over M! (N-M)!\,$} | 19015 | real 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 |
| 18829 | The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the | 19023 | The @kbd{H k c} (@code{calc-perm}) [@code{perm}] command computes the |
| 18830 | number-of-permutations function @cite{N! / (N-M)!}. | 19024 | number-of-permutations function @expr{N! / (N-M)!}. |
| 18831 | @end ifinfo | 19025 | @end ifinfo |
| 18832 | @tex | 19026 | @tex |
| 18833 | The \kbd{H k c} (\code{calc-perm}) [\code{perm}] command computes the | 19027 | The \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 |
| 18841 | The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command | 19035 | The @kbd{k b} (@code{calc-bernoulli-number}) [@code{bern}] command |
| 18842 | computes a given Bernoulli number. The value at the top of the stack | 19036 | computes a given Bernoulli number. The value at the top of the stack |
| 18843 | is a nonnegative integer @cite{n} that specifies which Bernoulli number | 19037 | is a nonnegative integer @expr{n} that specifies which Bernoulli number |
| 18844 | is desired. The @kbd{H k b} command computes a Bernoulli polynomial, | 19038 | is desired. The @kbd{H k b} command computes a Bernoulli polynomial, |
| 18845 | taking @cite{n} from the second-to-top position and @cite{x} from the | 19039 | taking @expr{n} from the second-to-top position and @expr{x} from the |
| 18846 | top of the stack. If @cite{x} is a variable or formula the result is | 19040 | top of the stack. If @expr{x} is a variable or formula the result is |
| 18847 | a polynomial in @cite{x}; if @cite{x} is a number the result is a number. | 19041 | a 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 |
| 18863 | The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command | 19057 | The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command |
| 18864 | computes a Stirling number of the first kind@c{ $n \brack m$} | 19058 | computes 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, |
| 18867 | command computes a Stirling number of the second kind@c{ $n \brace m$} | 19061 | given 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 |
| 18869 | the number of @cite{m}-cycle permutations of @cite{n} objects, and | 19063 | @texline kind@tie{}@tmath{n \brace m}. |
| 18870 | the number of ways to partition @cite{n} objects into @cite{m} | 19064 | @infoline kind. |
| 19065 | These are the number of @expr{m}-cycle permutations of @expr{n} objects, | ||
| 19066 | and the number of ways to partition @expr{n} objects into @expr{m} | ||
| 18871 | non-empty sets, respectively. | 19067 | non-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 | |||
| 18895 | test. Pressing @kbd{k p} repeatedly for the same integer will perform | 19091 | test. Pressing @kbd{k p} repeatedly for the same integer will perform |
| 18896 | additional iterations. Also, @kbd{k p} with a numeric prefix performs | 19092 | additional iterations. Also, @kbd{k p} with a numeric prefix performs |
| 18897 | the specified number of iterations. There is also an algebraic function | 19093 | the 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} |
| 18899 | is (probably) prime and 0 if not. | 19095 | is (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 |
| 18944 | The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the | 19140 | The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the |
| 18945 | Euler ``totient'' function@c{ $\phi(n)$} | 19141 | Euler ``totient'' |
| 18946 | @asis{}, the number of integers less than @cite{n} which | 19142 | @texline function@tie{}@tmath{\phi(n)}, |
| 18947 | are relatively prime to @cite{n}. | 19143 | @infoline function, |
| 19144 | the number of integers less than @expr{n} which | ||
| 19145 | are 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 |
| 18952 | The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the | 19150 | The @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'' |
| 18955 | distinct factors, this is @cite{(-1)^k}. If the input number has any | 19153 | function. If the input number is a product of @expr{k} |
| 19154 | distinct factors, this is @expr{(-1)^k}. If the input number has any | ||
| 18956 | duplicate factors (i.e., can be divided by the same prime more than once), | 19155 | duplicate factors (i.e., can be divided by the same prime more than once), |
| 18957 | the result is zero. | 19156 | the result is zero. |
| 18958 | 19157 | ||
| @@ -18962,14 +19161,14 @@ the result is zero. | |||
| 18962 | @noindent | 19161 | @noindent |
| 18963 | The functions in this section compute various probability distributions. | 19162 | The functions in this section compute various probability distributions. |
| 18964 | For continuous distributions, this is the integral of the probability | 19163 | For continuous distributions, this is the integral of the probability |
| 18965 | density function from @cite{x} to infinity. (These are the ``upper | 19164 | density function from @expr{x} to infinity. (These are the ``upper |
| 18966 | tail'' distribution functions; there are also corresponding ``lower | 19165 | tail'' distribution functions; there are also corresponding ``lower |
| 18967 | tail'' functions which integrate from minus infinity to @cite{x}.) | 19166 | tail'' functions which integrate from minus infinity to @expr{x}.) |
| 18968 | For discrete distributions, the upper tail function gives the sum | 19167 | For discrete distributions, the upper tail function gives the sum |
| 18969 | from @cite{x} to infinity; the lower tail function gives the sum | 19168 | from @expr{x} to infinity; the lower tail function gives the sum |
| 18970 | from minus infinity up to, but not including,@w{ }@cite{x}. | 19169 | from minus infinity up to, but not including,@w{ }@expr{x}. |
| 18971 | 19170 | ||
| 18972 | To integrate from @cite{x} to @cite{y}, just use the distribution | 19171 | To integrate from @expr{x} to @expr{y}, just use the distribution |
| 18973 | function twice and subtract. For example, the probability that a | 19172 | function twice and subtract. For example, the probability that a |
| 18974 | Gaussian random variable with mean 2 and standard deviation 1 will | 19173 | Gaussian random variable with mean 2 and standard deviation 1 will |
| 18975 | lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)} | 19174 | lie 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 | |||
| 18999 | arguments as found on the stack. (The random variable comes last on | 19198 | arguments as found on the stack. (The random variable comes last on |
| 19000 | the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5 | 19199 | the stack, so that you can type, e.g., @kbd{2 @key{RET} 1 @key{RET} 2.5 |
| 19001 | k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to | 19200 | k N M-@key{RET} @key{DEL} 2.8 k N -}, using @kbd{M-@key{RET} @key{DEL}} to |
| 19002 | recover the original arguments but substitute a new value for @cite{x}.) | 19201 | recover 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 |
| 19015 | The @samp{utpc(x,v)} function uses the chi-square distribution with | 19214 | The @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} |
| 19018 | correct if its chi-square statistic is @cite{x}. | 19217 | degrees of freedom. It is the probability that a model is |
| 19218 | correct 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 |
| 19031 | The @samp{utpf(F,v1,v2)} function uses the F distribution, used in | 19231 | The @samp{utpf(F,v1,v2)} function uses the F distribution, used in |
| 19032 | various statistical tests. The parameters @c{$\nu_1$} | 19232 | various statistical tests. The parameters |
| 19033 | @cite{v1} and @c{$\nu_2$} | 19233 | @texline @tmath{\nu_1} |
| 19034 | @cite{v2} | 19234 | @infoline @expr{v1} |
| 19235 | and | ||
| 19236 | @texline @tmath{\nu_2} | ||
| 19237 | @infoline @expr{v2} | ||
| 19035 | are the degrees of freedom in the numerator and denominator, | 19238 | are the degrees of freedom in the numerator and denominator, |
| 19036 | respectively, used in computing the statistic @cite{F}. | 19239 | respectively, 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 |
| 19049 | The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution | 19252 | The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution |
| 19050 | with mean @cite{m} and standard deviation @c{$\sigma$} | 19253 | with mean @expr{m} and standard deviation |
| 19051 | @cite{s}. It is the | 19254 | @texline @tmath{\sigma}. |
| 19052 | probability that such a normal-distributed random variable would | 19255 | @infoline @expr{s}. |
| 19053 | exceed @cite{x}. | 19256 | It is the probability that such a normal-distributed random variable |
| 19257 | would 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 |
| 19066 | The @samp{utpp(n,x)} function uses a Poisson distribution with | 19270 | The @samp{utpp(n,x)} function uses a Poisson distribution with |
| 19067 | mean @cite{x}. It is the probability that @cite{n} or more such | 19271 | mean @expr{x}. It is the probability that @expr{n} or more such |
| 19068 | Poisson random events will occur. | 19272 | Poisson 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 |
| 19081 | The @samp{utpt(t,v)} function uses the Student's ``t'' distribution | 19285 | The @samp{utpt(t,v)} function uses the Student's ``t'' distribution |
| 19082 | with @c{$\nu$} | 19286 | with |
| 19083 | @cite{v} degrees of freedom. It is the probability that a | 19287 | @texline @tmath{\nu} |
| 19084 | t-distributed random variable will be greater than @cite{t}. | 19288 | @infoline @expr{v} |
| 19085 | (Note: This computes the distribution function @c{$A(t|\nu)$} | 19289 | degrees of freedom. It is the probability that a |
| 19086 | @cite{A(t|v)} | 19290 | t-distributed random variable will be greater than @expr{t}. |
| 19087 | where @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 | 19294 | where |
| 19091 | which 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} | ||
| 19297 | and | ||
| 19298 | @texline @tmath{A(\infty|\nu) \to 0}. | ||
| 19299 | @infoline @expr{A(inf|v) -> 0}. | ||
| 19300 | The @code{UTPT} operation on the HP-48 uses a different definition which | ||
| 19301 | returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) | ||
| 19092 | 19302 | ||
| 19093 | While Calc does not provide inverses of the probability distribution | 19303 | While Calc does not provide inverses of the probability distribution |
| 19094 | functions, the @kbd{a R} command can be used to solve for the inverse. | 19304 | functions, 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 |
| 19156 | Two values are collected to build a complex number. For example, | 19366 | Two 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 |
| 19159 | number. The two input values must both be real numbers, | 19369 | number. The two input values must both be real numbers, |
| 19160 | i.e., integers, fractions, or floats. If they are not, Calc | 19370 | i.e., integers, fractions, or floats. If they are not, Calc |
| 19161 | will instead build a formula like @samp{a + (0, 1) b}. (The | 19371 | will 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]]}. | |||
| 19245 | If any elements of the vector are negative, other kinds of | 19455 | If any elements of the vector are negative, other kinds of |
| 19246 | packing are done at that level as described above. For | 19456 | packing are done at that level as described above. For |
| 19247 | example, @samp{[2, 3, -4]} takes 12 objects and creates a | 19457 | example, @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 |
| 19460 | matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. | ||
| 19250 | Also, @samp{[-4, -10]} will convert four integers into an | 19461 | Also, @samp{[-4, -10]} will convert four integers into an |
| 19251 | error form consisting of two fractions: @samp{a:b +/- c:d}. | 19462 | error 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 |
| 19348 | Vectors and matrices can be added, | 19559 | Vectors and matrices can be added, |
| 19349 | subtracted, multiplied, and divided; @pxref{Basic Arithmetic}.@refill | 19560 | subtracted, 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 | |||
| 19392 | the stack is a scalar, it is used for each element on the diagonal, and | 19603 | the stack is a scalar, it is used for each element on the diagonal, and |
| 19393 | the prefix argument is required. | 19604 | the prefix argument is required. |
| 19394 | 19605 | ||
| 19395 | To build a constant square matrix, e.g., a @c{$3\times3$} | 19606 | To build a constant square matrix, e.g., a |
| 19396 | @asis{3x3} matrix filled with ones, | 19607 | @texline @tmath{3\times3} |
| 19397 | use @kbd{0 M-3 v d 1 +}, i.e., build a zero matrix first and then add a | 19608 | @infoline 3x3 |
| 19398 | constant value to that matrix. (Another alternative would be to use | 19609 | matrix 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.) | 19610 | matrix first and then add a constant value to that matrix. (Another |
| 19611 | alternative would be to use @kbd{v b} and @kbd{v a}; see below.) | ||
| 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, | |||
| 19407 | this command prompts for one. | 19619 | this command prompts for one. |
| 19408 | 19620 | ||
| 19409 | In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)}, | 19621 | In algebraic notation, @samp{idn(a,n)} acts much like @samp{diag(a,n)}, |
| 19410 | except that @cite{a} is required to be a scalar (non-vector) quantity. | 19622 | except that @expr{a} is required to be a scalar (non-vector) quantity. |
| 19411 | If @cite{n} is omitted, @samp{idn(a)} represents @cite{a} times an | 19623 | If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an |
| 19412 | identity matrix of unknown size. Calc can operate algebraically on | 19624 | identity matrix of unknown size. Calc can operate algebraically on |
| 19413 | such generic identity matrices, and if one is combined with a matrix | 19625 | such generic identity matrices, and if one is combined with a matrix |
| 19414 | whose size is known, it is converted automatically to an identity | 19626 | whose size is known, it is converted automatically to an identity |
| @@ -19531,10 +19743,10 @@ submatrix is returned. | |||
| 19531 | @tindex _ | 19743 | @tindex _ |
| 19532 | Subscript notation in algebraic formulas (@samp{a_b}) stands for the | 19744 | Subscript notation in algebraic formulas (@samp{a_b}) stands for the |
| 19533 | Calc function @code{subscr}, which is synonymous with @code{mrow}. | 19745 | Calc function @code{subscr}, which is synonymous with @code{mrow}. |
| 19534 | Thus, @samp{[x, y, z]_k} produces @cite{x}, @cite{y}, or @cite{z} if | 19746 | Thus, @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 |
| 19537 | access the element at row @cite{i}, column @cite{j} of a matrix. | 19749 | access the element at row @expr{i}, column @expr{j} of a matrix. |
| 19538 | The @kbd{a _} (@code{calc-subscript}) command creates a subscript | 19750 | The @kbd{a _} (@code{calc-subscript}) command creates a subscript |
| 19539 | formula @samp{a_b} out of two stack entries. (It is on the @kbd{a} | 19751 | formula @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 | |||
| 19561 | it extracts (or removes) one element, just like @kbd{v r}. If the | 19773 | it extracts (or removes) one element, just like @kbd{v r}. If the |
| 19562 | index in @kbd{C-u v c} is an interval or vector and the argument is a | 19774 | index in @kbd{C-u v c} is an interval or vector and the argument is a |
| 19563 | matrix, the result is a submatrix with only the specified columns | 19775 | matrix, the result is a submatrix with only the specified columns |
| 19564 | retained (and possibly permuted in the case of a vector index).@refill | 19776 | retained (and possibly permuted in the case of a vector index). |
| 19565 | 19777 | ||
| 19566 | To extract a matrix element at a given row and column, use @kbd{v r} to | 19778 | To extract a matrix element at a given row and column, use @kbd{v r} to |
| 19567 | extract the row as a vector, then @kbd{v c} to extract the column element | 19779 | extract the row as a vector, then @kbd{v c} to extract the column element |
| 19568 | from that vector. In algebraic formulas, it is often more convenient to | 19780 | from that vector. In algebraic formulas, it is often more convenient to |
| 19569 | use subscript notation: @samp{m_i_j} gives row @cite{i}, column @cite{j} | 19781 | use subscript notation: @samp{m_i_j} gives row @expr{i}, column @expr{j} |
| 19570 | of matrix @cite{m}. | 19782 | of 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. | |||
| 19610 | The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the | 19822 | The @kbd{v l} (@code{calc-vlength}) [@code{vlen}] command computes the |
| 19611 | length of a vector. The length of a non-vector is considered to be zero. | 19823 | length of a vector. The length of a non-vector is considered to be zero. |
| 19612 | Note that matrices are just vectors of vectors for the purposes of this | 19824 | Note that matrices are just vectors of vectors for the purposes of this |
| 19613 | command.@refill | 19825 | command. |
| 19614 | 19826 | ||
| 19615 | @kindex H v l | 19827 | @kindex H v l |
| 19616 | @tindex mdims | 19828 | @tindex mdims |
| 19617 | With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector | 19829 | With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector |
| 19618 | of the dimensions of a vector, matrix, or higher-order object. For | 19830 | of the dimensions of a vector, matrix, or higher-order object. For |
| 19619 | example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since | 19831 | example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since |
| 19620 | its argument is a @c{$2\times3$} | 19832 | its argument is a |
| 19621 | @asis{2x3} matrix. | 19833 | @texline @tmath{2\times3} |
| 19834 | @infoline 2x3 | ||
| 19835 | matrix. | ||
| 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 | |||
| 19647 | in the vector, the last row will be short and the result will not be | 19861 | in the vector, the last row will be short and the result will not be |
| 19648 | suitable for use as a matrix. For example, with the matrix | 19862 | suitable 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 | 19867 | matrix), @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 | 19870 | matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original |
| 19657 | the flattened list @samp{[1, 2, @w{3, 4}]}. | 19871 | @texline @tmath{2\times2} |
| 19872 | @infoline 2x2 | ||
| 19873 | matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a | ||
| 19874 | matrix), and @kbd{v a 0} produces the flattened list | ||
| 19875 | @samp{[1, 2, @w{3, 4}]}. | ||
| 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.) | |||
| 19810 | The following functions are applied element-wise if their arguments are | 20028 | The following functions are applied element-wise if their arguments are |
| 19811 | vectors or matrices: @code{change-sign}, @code{conj}, @code{arg}, | 20029 | vectors 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 | |||
| 19832 | root of the sum of the squares of the absolute values of the | 20050 | root of the sum of the squares of the absolute values of the |
| 19833 | elements of the vector or matrix. If the vector is interpreted as | 20051 | elements of the vector or matrix. If the vector is interpreted as |
| 19834 | a point in two- or three-dimensional space, this is the distance | 20052 | a point in two- or three-dimensional space, this is the distance |
| 19835 | from that point to the origin.@refill | 20053 | from 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 | |||
| 19851 | the column norm, or one-norm, of a vector or matrix. For a plain | 20069 | the column norm, or one-norm, of a vector or matrix. For a plain |
| 19852 | vector, this is the sum of the absolute values of the elements. | 20070 | vector, this is the sum of the absolute values of the elements. |
| 19853 | For a matrix, this is the maximum of the column-absolute-value-sums. | 20071 | For a matrix, this is the maximum of the column-absolute-value-sums. |
| 19854 | General @cite{k}-norms for @cite{k} other than one or infinity are | 20072 | General @expr{k}-norms for @expr{k} other than one or infinity are |
| 19855 | not provided. | 20073 | not 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 | |||
| 19877 | computed, the inverse and determinant of the matrix can be recomputed | 20095 | computed, the inverse and determinant of the matrix can be recomputed |
| 19878 | quickly in the future. | 20096 | quickly in the future. |
| 19879 | 20097 | ||
| 19880 | If the argument to @kbd{&} is a plain number @cite{x}, this | 20098 | If the argument to @kbd{&} is a plain number @expr{x}, this |
| 19881 | command simply computes @cite{1/x}. This is okay, because the | 20099 | command 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 |
| 19883 | by a matrix. | 20101 | by a matrix. |
| 19884 | 20102 | ||
| @@ -19936,8 +20154,8 @@ The result is always a vector, except that if the set consists of a | |||
| 19936 | single interval, the interval itself is returned instead. | 20154 | single 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 |
| 19939 | a certain value is a member of a given set. To test if the set @cite{A} | 20157 | a certain value is a member of a given set. To test if the set @expr{A} |
| 19940 | is a subset of the set @cite{B}, use @samp{vdiff(A, B) = []}. | 20158 | is 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 | |||
| 19969 | sets are disjoint, i.e., if they share no common elements, the result | 20187 | sets are disjoint, i.e., if they share no common elements, the result |
| 19970 | will be the empty vector @samp{[]}. Note that the characters @kbd{V} | 20188 | will be the empty vector @samp{[]}. Note that the characters @kbd{V} |
| 19971 | and @kbd{^} were chosen to be close to the conventional mathematical | 20189 | and @kbd{^} were chosen to be close to the conventional mathematical |
| 19972 | notation for set union@c{ ($A \cup B$)} | 20190 | notation for set |
| 19973 | @asis{} and intersection@c{ ($A \cap B$)} | 20191 | @texline union@tie{}(@tmath{A \cup B}) |
| 19974 | @asis{}. | 20192 | @infoline union |
| 20193 | and | ||
| 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 |
| 19979 | The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes | 20200 | The @kbd{V -} (@code{calc-set-difference}) [@code{vdiff}] command computes |
| 19980 | the difference between two sets. An object is in the difference | 20201 | the 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}. |
| 19982 | Thus subtracting @samp{[y,z]} from a set will remove the elements | 20203 | Thus 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 |
| 19984 | as a general @dfn{set complement} operator; if @cite{A} is the set of | 20205 | as a general @dfn{set complement} operator; if @expr{A} is the set of |
| 19985 | all possible values, then @cite{A - B} is the ``complement'' of @cite{B}. | 20206 | all possible values, then @expr{A - B} is the ``complement'' of @expr{B}. |
| 19986 | Obviously this is only practical if the set of all possible values in | 20207 | Obviously this is only practical if the set of all possible values in |
| 19987 | your problem is small enough to list in a Calc vector (or simple | 20208 | your problem is small enough to list in a Calc vector (or simple |
| 19988 | enough to express in a few intervals). | 20209 | enough to express in a few intervals). |
| @@ -20078,8 +20299,9 @@ the same set. The set may include positive infinity, but must | |||
| 20078 | not include any negative numbers. The input is interpreted as a | 20299 | not include any negative numbers. The input is interpreted as a |
| 20079 | set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware | 20300 | set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware |
| 20080 | that a simple input like @samp{[100]} can result in a huge integer | 20301 | that a simple input like @samp{[100]} can result in a huge integer |
| 20081 | representation (@c{$2^{100}$} | 20302 | representation |
| 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 |
| 20168 | product of the data values. If the input is a single flat vector, | 20390 | product of the data values. If the input is a single flat vector, |
| 20169 | these are the same as @kbd{V R +} and @kbd{V R *} | 20391 | these 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 |
| 20190 | The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command | 20412 | The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command |
| 20191 | computes the average (arithmetic mean) of the data values. | 20413 | computes the average (arithmetic mean) of the data values. |
| 20192 | If the inputs are error forms @c{$x$ @code{+/-} $\sigma$} | 20414 | If the inputs are error forms |
| 20193 | @samp{x +/- s}, this is the weighted | 20415 | @texline @tmath{x \pm \sigma}, |
| 20194 | mean of the @cite{x} values with weights @c{$1 / \sigma^2$} | 20416 | @infoline @samp{x +/- s}, |
| 20195 | @cite{1 / s^2}. | 20417 | this 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 |
| 20201 | If the inputs are not error forms, this is simply the sum of the | 20425 | If the inputs are not error forms, this is simply the sum of the |
| 20202 | values divided by the count of the values.@refill | 20426 | values divided by the count of the values. |
| 20203 | 20427 | ||
| 20204 | Note that a plain number can be considered an error form with | 20428 | Note that a plain number can be considered an error form with |
| 20205 | error @c{$\sigma = 0$} | 20429 | error |
| 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}. | ||
| 20432 | If the input to @kbd{u M} is a mixture of | ||
| 20207 | plain numbers and error forms, the result is the mean of the | 20433 | plain numbers and error forms, the result is the mean of the |
| 20208 | plain numbers, ignoring all values with non-zero errors. (By the | 20434 | plain numbers, ignoring all values with non-zero errors. (By the |
| 20209 | above definitions it's clear that a plain number effectively | 20435 | above definitions it's clear that a plain number effectively |
| @@ -20212,7 +20438,7 @@ weight is completely negligible.) | |||
| 20212 | 20438 | ||
| 20213 | This function also works for distributions (error forms or | 20439 | This function also works for distributions (error forms or |
| 20214 | intervals). The mean of an error form `@var{a} @t{+/-} @var{b}' is simply | 20440 | intervals). 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 |
| 20216 | and maximum values of the interval. | 20442 | and 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 | |||
| 20234 | divided by the square root of the number of values. (This works | 20460 | divided by the square root of the number of values. (This works |
| 20235 | out to be equivalent to calculating the standard deviation and | 20461 | out to be equivalent to calculating the standard deviation and |
| 20236 | then assuming each value's error is equal to this standard | 20462 | then assuming each value's error is equal to this standard |
| 20237 | deviation.)@refill | 20463 | deviation.) |
| 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 |
| 20311 | The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command | 20537 | The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command |
| 20312 | computes the standard deviation@c{ $\sigma$} | 20538 | computes the standard |
| 20313 | @asis{} of the data values. If the | 20539 | @texline deviation@tie{}@tmath{\sigma} |
| 20314 | values are error forms, the errors are used as weights just | 20540 | @infoline deviation |
| 20315 | as for @kbd{u M}. This is the @emph{sample} standard deviation, | 20541 | of the data values. If the values are error forms, the errors are used |
| 20316 | whose value is the square root of the sum of the squares of the | 20542 | as weights just as for @kbd{u M}. This is the @emph{sample} standard |
| 20317 | differences between the values and the mean of the @cite{N} values, | 20543 | deviation, whose value is the square root of the sum of the squares of |
| 20318 | divided by @cite{N-1}. | 20544 | the differences between the values and the mean of the @expr{N} values, |
| 20545 | divided 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 $$ | |||
| 20324 | This function also applies to distributions. The standard deviation | 20551 | This function also applies to distributions. The standard deviation |
| 20325 | of a single error form is simply the error part. The standard deviation | 20552 | of a single error form is simply the error part. The standard deviation |
| 20326 | of a continuous interval happens to equal the difference between the | 20553 | of a continuous interval happens to equal the difference between the |
| 20327 | limits, divided by @c{$\sqrt{12}$} | 20554 | limits, divided by |
| 20328 | @cite{sqrt(12)}. The standard deviation of an | 20555 | @texline @tmath{\sqrt{12}}. |
| 20329 | integer interval is the same as the standard deviation of a vector | 20556 | @infoline @expr{sqrt(12)}. |
| 20330 | of those integers. | 20557 | The standard deviation of an integer interval is the same as the |
| 20558 | standard 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. | |||
| 20336 | The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}] | 20564 | The @kbd{I u S} (@code{calc-vector-pop-sdev}) [@code{vpsdev}] |
| 20337 | command computes the @emph{population} standard deviation. | 20565 | command computes the @emph{population} standard deviation. |
| 20338 | It is defined by the same formula as above but dividing | 20566 | It is defined by the same formula as above but dividing |
| 20339 | by @cite{N} instead of by @cite{N-1}. The population standard | 20567 | by @expr{N} instead of by @expr{N-1}. The population standard |
| 20340 | deviation is used when the input represents the entire set of | 20568 | deviation is used when the input represents the entire set of |
| 20341 | data values in the distribution; the sample standard deviation | 20569 | data values in the distribution; the sample standard deviation |
| 20342 | is used when the input represents a sample of the set of all | 20570 | is 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. | |||
| 20361 | The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and | 20589 | The @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}] |
| 20363 | commands compute the variance of the data values. The variance | 20591 | commands compute the variance of the data values. The variance |
| 20364 | is the square@c{ $\sigma^2$} | 20592 | is the |
| 20365 | @asis{} of the standard deviation, i.e., the sum of the | 20593 | @texline square@tie{}@tmath{\sigma^2} |
| 20594 | @infoline square | ||
| 20595 | of the standard deviation, i.e., the sum of the | ||
| 20366 | squares of the deviations of the data values from the mean. | 20596 | squares 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 | |||
| 20383 | vectors of equal size. The vectors are each flattened in the same | 20613 | vectors of equal size. The vectors are each flattened in the same |
| 20384 | way as by the single-variable statistical functions. Given a numeric | 20614 | way as by the single-variable statistical functions. Given a numeric |
| 20385 | prefix argument of 1, these functions instead take one object from | 20615 | prefix argument of 1, these functions instead take one object from |
| 20386 | the stack, which must be an @c{$N\times2$} | 20616 | the stack, which must be an |
| 20387 | @asis{Nx2} matrix of data values. Once | 20617 | @texline @tmath{N\times2} |
| 20388 | again, variable names can be used in place of actual vectors and | 20618 | @infoline Nx2 |
| 20389 | matrices. | 20619 | matrix of data values. Once again, variable names can be used in place |
| 20620 | of 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 | |||
| 20397 | of vectors @var{x} and @var{y} is the sum of the products of the | 20628 | of vectors @var{x} and @var{y} is the sum of the products of the |
| 20398 | differences between the elements of @var{x} and the mean of @var{x} | 20629 | differences between the elements of @var{x} and the mean of @var{x} |
| 20399 | times the differences between the corresponding elements of @var{y} | 20630 | times the differences between the corresponding elements of @var{y} |
| 20400 | and the mean of @var{y}, all divided by @cite{N-1}. Note that | 20631 | and the mean of @var{y}, all divided by @expr{N-1}. Note that |
| 20401 | the variance of a vector is just the covariance of the vector | 20632 | the variance of a vector is just the covariance of the vector |
| 20402 | with itself. Once again, if the inputs are error forms the | 20633 | with itself. Once again, if the inputs are error forms the |
| 20403 | errors are used as weight factors. If both @var{x} and @var{y} | 20634 | errors are used as weight factors. If both @var{x} and @var{y} |
| @@ -20419,8 +20650,8 @@ $$ | |||
| 20419 | @tindex vpcov | 20650 | @tindex vpcov |
| 20420 | The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}] | 20651 | The @kbd{I u C} (@code{calc-vector-pop-covariance}) [@code{vpcov}] |
| 20421 | command computes the population covariance, which is the same as the | 20652 | command computes the population covariance, which is the same as the |
| 20422 | sample covariance computed by @kbd{u C} except dividing by @cite{N} | 20653 | sample covariance computed by @kbd{u C} except dividing by @expr{N} |
| 20423 | instead of @cite{N-1}. | 20654 | instead 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, | |||
| 20598 | or a nameless function like @samp{<#^3+1>}. Operators that are normally | 20829 | or a nameless function like @samp{<#^3+1>}. Operators that are normally |
| 20599 | written as algebraic symbols have the names @code{add}, @code{sub}, | 20830 | written 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, | |||
| 20635 | With the 2 listed first, it would have computed a vector of powers of | 20866 | With the 2 listed first, it would have computed a vector of powers of |
| 20636 | two. Mapping a user-defined function pops as many arguments from the | 20867 | two. Mapping a user-defined function pops as many arguments from the |
| 20637 | stack as the function requires. If you give an undefined name, you will | 20868 | stack as the function requires. If you give an undefined name, you will |
| 20638 | be prompted for the number of arguments to use.@refill | 20869 | be prompted for the number of arguments to use. |
| 20639 | 20870 | ||
| 20640 | If any argument to @kbd{V M} is a matrix, the operator is normally mapped | 20871 | If any argument to @kbd{V M} is a matrix, the operator is normally mapped |
| 20641 | across all elements of the matrix. For example, given the matrix | 20872 | across 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 |
| 20643 | produce another @c{$3\times2$} | 20874 | produce another |
| 20644 | @asis{3x2} matrix, @cite{[[1, 2, 3], [4, 5, 6]]}. | 20875 | @texline @tmath{3\times2} |
| 20876 | @infoline 3x2 | ||
| 20877 | matrix, @expr{[[1, 2, 3], [4, 5, 6]]}. | ||
| 20645 | 20878 | ||
| 20646 | @tindex mapr | 20879 | @tindex mapr |
| 20647 | The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the | 20880 | The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the |
| 20648 | operator prompt) maps by rows instead. For example, @kbd{V M _ A} views | 20881 | operator prompt) maps by rows instead. For example, @kbd{V M _ A} views |
| 20649 | the above matrix as a vector of two 3-element row vectors. It produces | 20882 | the above matrix as a vector of two 3-element row vectors. It produces |
| 20650 | a new vector which contains the absolute values of those row vectors, | 20883 | a new vector which contains the absolute values of those row vectors, |
| 20651 | namely @cite{[3.74, 8.77]}. (Recall, the absolute value of a vector is | 20884 | namely @expr{[3.74, 8.77]}. (Recall, the absolute value of a vector is |
| 20652 | defined as the square root of the sum of the squares of the elements.) | 20885 | defined as the square root of the sum of the squares of the elements.) |
| 20653 | Some operators accept vectors and return new vectors; for example, | 20886 | Some 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 |
| 20655 | of the matrix to get a new matrix, @cite{[[3, -2, 1], [-6, 5, -4]]}. | 20888 | of the matrix to get a new matrix, @expr{[[3, -2, 1], [-6, 5, -4]]}. |
| 20656 | 20889 | ||
| 20657 | Sometimes a vector of vectors (representing, say, strings, sets, or lists) | 20890 | Sometimes a vector of vectors (representing, say, strings, sets, or lists) |
| 20658 | happens to look like a matrix. If so, remember to use @kbd{V M _} if you | 20891 | happens 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 | |||
| 20665 | matrix, transposes again. For example, @kbd{V M : A} takes the absolute | 20898 | matrix, transposes again. For example, @kbd{V M : A} takes the absolute |
| 20666 | values of the three columns of the matrix, treating each as a 2-vector, | 20899 | values of the three columns of the matrix, treating each as a 2-vector, |
| 20667 | and @kbd{V M : v v} reverses the columns to get the matrix | 20900 | and @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 |
| 20671 | and column-like appearances, and were not already taken by useful | 20904 | and 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 |
| 20758 | As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For | 20991 | As for @kbd{V M}, @kbd{V R} normally reduces a matrix elementwise. For |
| 20759 | example, given the matrix @cite{[[a, b, c], [d, e, f]]}, @kbd{V R +} will | 20992 | example, given the matrix @expr{[[a, b, c], [d, e, f]]}, @kbd{V R +} will |
| 20760 | compute @cite{a + b + c + d + e + f}. You can type @kbd{V R _} or | 20993 | compute @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}] |
| 20762 | command reduces ``across'' the matrix; it reduces each row of the matrix | 20995 | command reduces ``across'' the matrix; it reduces each row of the matrix |
| 20763 | as a vector, then collects the results. Thus @kbd{V R _ +} of this | 20996 | as a vector, then collects the results. Thus @kbd{V R _ +} of this |
| 20764 | matrix would produce @cite{[a + b + c, d + e + f]}. Similarly, @kbd{V R :} | 20997 | matrix 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, |
| 20766 | b + e, c + f]}. | 20999 | b + 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; | |||
| 20919 | The commands @kbd{v <} (@code{calc-matrix-left-justify}), @kbd{v >} | 21152 | The 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 |
| 20922 | are justified to the left, right, or center of their columns.@refill | 21155 | are 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 | |||
| 20936 | Mathematica. (In fact, the Mathematica language mode uses this mode; | 21169 | Mathematica. (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 |
| 20938 | display mode, either brackets or braces may be used to enter vectors, | 21171 | display mode, either brackets or braces may be used to enter vectors, |
| 20939 | and parentheses may never be used for this purpose.@refill | 21172 | and 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 |
| 20991 | The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and | 21224 | The @kbd{v ,} (@code{calc-vector-commas}) command turns commas on and |
| 20992 | off in vector and matrix display.@refill | 21225 | off in vector and matrix display. |
| 20993 | 21226 | ||
| 20994 | In vectors of length one, and in all vectors when commas have been | 21227 | In vectors of length one, and in all vectors when commas have been |
| 20995 | turned off, Calc adds extra parentheses around formulas that might | 21228 | turned 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 | |||
| 21047 | for anything else'') prefix. | 21280 | for 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 |
| 21050 | using regular Emacs editing commands.@refill | 21283 | using regular Emacs editing commands. |
| 21051 | 21284 | ||
| 21052 | When doing algebraic work, you may find several of the Calculator's | 21285 | When doing algebraic work, you may find several of the Calculator's |
| 21053 | modes to be helpful, including algebraic-simplification mode (@kbd{m A}) | 21286 | modes to be helpful, including algebraic-simplification mode (@kbd{m A}) |
| @@ -21055,7 +21288,7 @@ or no-simplification mode (@kbd{m O}), | |||
| 21055 | algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and | 21288 | algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and |
| 21056 | symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions | 21289 | symbolic mode (@kbd{m s}). @xref{Mode Settings}, for discussions |
| 21057 | of these modes. You may also wish to select ``big'' display mode (@kbd{d B}). | 21290 | of 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 | |||
| 21213 | behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection}; | 21446 | behavior 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 |
| 21215 | used in keyboard macros that implement your own selection-oriented | 21448 | used in keyboard macros that implement your own selection-oriented |
| 21216 | commands.@refill | 21449 | commands. |
| 21217 | 21450 | ||
| 21218 | Selection of sub-formulas normally treats associative terms like | 21451 | Selection 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 | |||
| 21311 | the @var{n}th top-level sub-formula. (In other words, they act as if | 21544 | the @var{n}th top-level sub-formula. (In other words, they act as if |
| 21312 | the entire stack entry were selected first.) To select the @var{n}th | 21545 | the entire stack entry were selected first.) To select the @var{n}th |
| 21313 | sub-formula where @var{n} is greater than nine, you must instead invoke | 21546 | sub-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. | |||
| 21493 | Operations on sub-formulas sometimes leave the formula as a whole | 21726 | Operations on sub-formulas sometimes leave the formula as a whole |
| 21494 | in an ``un-natural'' state. Consider negating the @samp{2 x} term | 21727 | in an ``un-natural'' state. Consider negating the @samp{2 x} term |
| 21495 | of our sample formula by selecting it and pressing @kbd{n} | 21728 | of 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 | |||
| 21850 | to @kbd{V M}, which operates on vectors instead of equations. | 22083 | to @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}. |
| 21854 | With two equations on the stack, @kbd{a M +} would add the lefthand | 22087 | With two equations on the stack, @kbd{a M +} would add the lefthand |
| 21855 | sides together and the righthand sides together to get the two | 22088 | sides together and the righthand sides together to get the two |
| 21856 | respective sides of a new equation. | 22089 | respective sides of a new equation. |
| @@ -21899,7 +22132,7 @@ in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces | |||
| 21899 | Note that this is a purely structural substitution; the lone @samp{x} and | 22132 | Note that this is a purely structural substitution; the lone @samp{x} and |
| 21900 | the @samp{sin(2 x)} stayed the same because they did not look like | 22133 | the @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 |
| 21902 | doing substitutions.@refill | 22135 | doing substitutions. |
| 21903 | 22136 | ||
| 21904 | The @kbd{a b} command normally prompts for two formulas, the old | 22137 | The @kbd{a b} command normally prompts for two formulas, the old |
| 21905 | one and the new one. If you enter a blank line for the first | 22138 | one 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 |
| 21967 | This section describes the ``default simplifications,'' those which are | 22200 | This section describes the ``default simplifications,'' those which are |
| 21968 | normally applied to all results. For example, if you enter the variable | 22201 | normally 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 |
| 21970 | simplifications automatically change @cite{x + x} to @cite{2 x}. | 22203 | simplifications automatically change @expr{x + x} to @expr{2 x}. |
| 21971 | 22204 | ||
| 21972 | The @kbd{m O} command turns off the default simplifications, so that | 22205 | The @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 |
| 21975 | Manipulation}. The @kbd{m D} command turns the default simplifications | 22208 | Manipulation}. The @kbd{m D} command turns the default simplifications |
| 21976 | back on. | 22209 | back on. |
| 21977 | 22210 | ||
| 21978 | The most basic default simplification is the evaluation of functions. | 22211 | The most basic default simplification is the evaluation of functions. |
| 21979 | For example, @cite{2 + 3} is evaluated to @cite{5}, and @cite{@t{sqrt}(9)} | 22212 | For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@t{sqrt}(9)} |
| 21980 | is evaluated to @cite{3}. Evaluation does not occur if the arguments | 22213 | is evaluated to @expr{3}. Evaluation does not occur if the arguments |
| 21981 | to a function are somehow of the wrong type (@cite{@t{tan}([2,3,4])}), | 22214 | to a function are somehow of the wrong type @expr{@t{tan}([2,3,4])}), |
| 21982 | range (@cite{@t{tan}(90)}), or number (@cite{@t{tan}(3,5)}), or if the | 22215 | range (@expr{@t{tan}(90)}), or number (@expr{@t{tan}(3,5)}), |
| 21983 | function name is not recognized (@cite{@t{f}(5)}), or if ``symbolic'' | 22216 | or if the function name is not recognized (@expr{@t{f}(5)}), or if |
| 21984 | mode (@pxref{Symbolic Mode}) prevents evaluation (@cite{@t{sqrt}(2)}). | 22217 | ``symbolic'' mode (@pxref{Symbolic Mode}) prevents evaluation |
| 22218 | (@expr{@t{sqrt}(2)}). | ||
| 21985 | 22219 | ||
| 21986 | Calc simplifies (evaluates) the arguments to a function before it | 22220 | Calc simplifies (evaluates) the arguments to a function before it |
| 21987 | simplifies the function itself. Thus @cite{@t{sqrt}(5+4)} is | 22221 | simplifies the function itself. Thus @expr{@t{sqrt}(5+4)} is |
| 21988 | simplified to @cite{@t{sqrt}(9)} before the @code{sqrt} function | 22222 | simplified to @expr{@t{sqrt}(9)} before the @code{sqrt} function |
| 21989 | itself is applied. There are very few exceptions to this rule: | 22223 | itself 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{::} |
| 21991 | operator) do not evaluate their arguments, @code{if} (the @code{? :} | 22225 | operator) do not evaluate their arguments, @code{if} (the @code{? :} |
| @@ -22024,9 +22258,9 @@ And now, on with the default simplifications: | |||
| 22024 | Arithmetic operators like @kbd{+} and @kbd{*} always take two | 22258 | Arithmetic operators like @kbd{+} and @kbd{*} always take two |
| 22025 | arguments in Calc's internal form. Sums and products of three or | 22259 | arguments in Calc's internal form. Sums and products of three or |
| 22026 | more terms are arranged by the associative law of algebra into | 22260 | more terms are arranged by the associative law of algebra into |
| 22027 | a left-associative form for sums, @cite{((a + b) + c) + d}, and | 22261 | a left-associative form for sums, @expr{((a + b) + c) + d}, and |
| 22028 | a right-associative form for products, @cite{a * (b * (c * d))}. | 22262 | a right-associative form for products, @expr{a * (b * (c * d))}. |
| 22029 | Formulas like @cite{(a + b) + (c + d)} are rearranged to | 22263 | Formulas like @expr{(a + b) + (c + d)} are rearranged to |
| 22030 | left-associative form, though this rarely matters since Calc's | 22264 | left-associative form, though this rarely matters since Calc's |
| 22031 | algebra commands are designed to hide the inner structure of | 22265 | algebra commands are designed to hide the inner structure of |
| 22032 | sums and products as much as possible. Sums and products in | 22266 | sums and products as much as possible. Sums and products in |
| @@ -22034,199 +22268,213 @@ their proper associative form will be written without parentheses | |||
| 22034 | in the examples below. | 22268 | in the examples below. |
| 22035 | 22269 | ||
| 22036 | Sums and products are @emph{not} rearranged according to the | 22270 | Sums and products are @emph{not} rearranged according to the |
| 22037 | commutative law (@cite{a + b} to @cite{b + a}) except in a few | 22271 | commutative law (@expr{a + b} to @expr{b + a}) except in a few |
| 22038 | special cases described below. Some algebra programs always | 22272 | special cases described below. Some algebra programs always |
| 22039 | rearrange terms into a canonical order, which enables them to | 22273 | rearrange terms into a canonical order, which enables them to |
| 22040 | see that @cite{a b + b a} can be simplified to @cite{2 a b}. | 22274 | see that @expr{a b + b a} can be simplified to @expr{2 a b}. |
| 22041 | Calc assumes you have put the terms into the order you want | 22275 | Calc assumes you have put the terms into the order you want |
| 22042 | and generally leaves that order alone, with the consequence | 22276 | and generally leaves that order alone, with the consequence |
| 22043 | that formulas like the above will only be simplified if you | 22277 | that formulas like the above will only be simplified if you |
| 22044 | explicitly give the @kbd{a s} command. @xref{Algebraic | 22278 | explicitly give the @kbd{a s} command. @xref{Algebraic |
| 22045 | Simplifications}. | 22279 | Simplifications}. |
| 22046 | 22280 | ||
| 22047 | Differences @cite{a - b} are treated like sums @cite{a + (-b)} | 22281 | Differences @expr{a - b} are treated like sums @expr{a + (-b)} |
| 22048 | for purposes of simplification; one of the default simplifications | 22282 | for purposes of simplification; one of the default simplifications |
| 22049 | is to rewrite @cite{a + (-b)} or @cite{(-b) + a}, where @cite{-b} | 22283 | is to rewrite @expr{a + (-b)} or @expr{(-b) + a}, where @expr{-b} |
| 22050 | represents a ``negative-looking'' term, into @cite{a - b} form. | 22284 | represents 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 |
| 22053 | negative-looking. | 22287 | negative-looking. |
| 22054 | 22288 | ||
| 22055 | Other simplifications involving negation are @cite{-(-x)} to @cite{x}; | 22289 | Other 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 |
| 22057 | negative-looking, simplified by negating that term, or else where | 22291 | negative-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 |
| 22061 | cases where the order of terms in a sum is changed by the default | 22295 | cases where the order of terms in a sum is changed by the default |
| 22062 | simplifications.) | 22296 | simplifications.) |
| 22063 | 22297 | ||
| 22064 | The distributive law is used to simplify sums in some cases: | 22298 | The 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 |
| 22066 | a number or an implicit 1 or @i{-1} (as in @cite{x} or @cite{-x}) | 22300 | a number or an implicit 1 or @i{-1} (as in @expr{x} or @expr{-x}) |
| 22067 | and similarly for @cite{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or | 22301 | and 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 |
| 22069 | using the distributive law. | 22303 | using the distributive law. |
| 22070 | 22304 | ||
| 22071 | The distributive law is only used for sums of two terms, or | 22305 | The distributive law is only used for sums of two terms, or |
| 22072 | for adjacent terms in a larger sum. Thus @cite{a + b + b + c} | 22306 | for adjacent terms in a larger sum. Thus @expr{a + b + b + c} |
| 22073 | is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b} | 22307 | is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b} |
| 22074 | is not simplified. The reason is that comparing all terms of a | 22308 | is not simplified. The reason is that comparing all terms of a |
| 22075 | sum with one another would require time proportional to the | 22309 | sum with one another would require time proportional to the |
| 22076 | square of the number of terms; Calc relegates potentially slow | 22310 | square of the number of terms; Calc relegates potentially slow |
| 22077 | operations like this to commands that have to be invoked | 22311 | operations like this to commands that have to be invoked |
| 22078 | explicitly, like @kbd{a s}. | 22312 | explicitly, like @kbd{a s}. |
| 22079 | 22313 | ||
| 22080 | Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}. | 22314 | Finally, @expr{a + 0} and @expr{0 + a} are simplified to @expr{a}. |
| 22081 | A consequence of the above rules is that @cite{0 - a} is simplified | 22315 | A consequence of the above rules is that @expr{0 - a} is simplified |
| 22082 | to @cite{-a}. | 22316 | to @expr{-a}. |
| 22083 | 22317 | ||
| 22084 | @tex | 22318 | @tex |
| 22085 | \bigskip | 22319 | \bigskip |
| 22086 | @end tex | 22320 | @end tex |
| 22087 | 22321 | ||
| 22088 | The products @cite{1 a} and @cite{a 1} are simplified to @cite{a}; | 22322 | The 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 |
| 22091 | in matrix mode where @cite{a} is not provably scalar the result | 22325 | in matrix mode where @expr{a} is not provably scalar the result |
| 22092 | is the generic zero matrix @samp{idn(0)}, and that if @cite{a} is | 22326 | is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is |
| 22093 | infinite the result is @samp{nan}. | 22327 | infinite the result is @samp{nan}. |
| 22094 | 22328 | ||
| 22095 | Also, @cite{(-a) b} and @cite{a (-b)} are simplified to @cite{-(a b)}, | 22329 | Also, @expr{(-a) b} and @expr{a (-b)} are simplified to @expr{-(a b)}, |
| 22096 | where this occurs for negated formulas but not for regular negative | 22330 | where this occurs for negated formulas but not for regular negative |
| 22097 | numbers. | 22331 | numbers. |
| 22098 | 22332 | ||
| 22099 | Products are commuted only to move numbers to the front: | 22333 | Products 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 | ||
| 22102 | The product @cite{a (b + c)} is distributed over the sum only if | 22336 | The 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 |
| 22106 | rewritten to @cite{a (c - b)}. | 22340 | rewritten to @expr{a (c - b)}. |
| 22107 | 22341 | ||
| 22108 | The distributive law of products and powers is used for adjacent | 22342 | The distributive law of products and powers is used for adjacent |
| 22109 | terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$} | 22343 | terms of the product: @expr{x^a x^b} goes to |
| 22110 | @cite{x^(a+b)} | 22344 | @texline @tmath{x^{a+b}} |
| 22111 | where @cite{a} is a number, or an implicit 1 (as in @cite{x}), | 22345 | @infoline @expr{x^(a+b)} |
| 22112 | or the implicit one-half of @cite{@t{sqrt}(x)}, and similarly for | 22346 | where @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} | 22347 | or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for |
| 22114 | if 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} |
| 22349 | if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively. | ||
| 22115 | If the sum of the powers is zero, the product is simplified to | 22350 | If 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 | ||
| 22118 | The product of a negative power times anything but another negative | 22353 | The product of a negative power times anything but another negative |
| 22119 | power is changed to use division: @c{$x^{-2} y$} | 22354 | power 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} |
| 22121 | in effect and neither @cite{x} nor @cite{y} are scalar (in which | 22356 | @infoline @expr{x^(-2) y} |
| 22357 | goes to @expr{y / x^2} unless matrix mode is | ||
| 22358 | in effect and neither @expr{x} nor @expr{y} are scalar (in which | ||
| 22122 | case it is considered unsafe to rearrange the order of the terms). | 22359 | case it is considered unsafe to rearrange the order of the terms). |
| 22123 | 22360 | ||
| 22124 | Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also | 22361 | Finally, @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 | ||
| 22131 | Simplifications for quotients are analogous to those for products. | 22368 | Simplifications for quotients are analogous to those for products. |
| 22132 | The quotient @cite{0 / x} is simplified to @cite{0}, with the same | 22369 | The quotient @expr{0 / x} is simplified to @expr{0}, with the same |
| 22133 | exceptions that were noted for @cite{0 x}. Likewise, @cite{x / 1} | 22370 | exceptions that were noted for @expr{0 x}. Likewise, @expr{x / 1} |
| 22134 | and @cite{x / (-1)} are simplified to @cite{x} and @cite{-x}, | 22371 | and @expr{x / (-1)} are simplified to @expr{x} and @expr{-x}, |
| 22135 | respectively. | 22372 | respectively. |
| 22136 | 22373 | ||
| 22137 | The quotient @cite{x / 0} is left unsimplified or changed to an | 22374 | The quotient @expr{x / 0} is left unsimplified or changed to an |
| 22138 | infinite quantity, as directed by the current infinite mode. | 22375 | infinite quantity, as directed by the current infinite mode. |
| 22139 | @xref{Infinite Mode}. | 22376 | @xref{Infinite Mode}. |
| 22140 | 22377 | ||
| 22141 | The expression @c{$a / b^{-c}$} | 22378 | The expression |
| 22142 | @cite{a / b^(-c)} is changed to @cite{a b^c}, | 22379 | @texline @tmath{a / b^{-c}} |
| 22143 | where @cite{-c} is any negative-looking power. Also, @cite{1 / b^c} | 22380 | @infoline @expr{a / b^(-c)} |
| 22144 | is changed to @c{$b^{-c}$} | 22381 | is changed to @expr{a b^c}, where @expr{-c} is any negative-looking |
| 22145 | @cite{b^(-c)} for any power @cite{c}. | 22382 | power. Also, @expr{1 / b^c} is changed to |
| 22146 | 22383 | @texline @tmath{b^{-c}} | |
| 22147 | Also, @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)} | 22385 | for any power @expr{c}. |
| 22149 | goes to @cite{(a c) / b} unless matrix mode prevents this | 22386 | |
| 22150 | rearrangement. Similarly, @cite{a / (b:c)} is simplified to | 22387 | Also, @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 | 22389 | goes to @expr{(a c) / b} unless matrix mode prevents this | |
| 22153 | The distributive law is applied to @cite{(a + b) / c} only if | 22390 | rearrangement. 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 | |||
| 22393 | The 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. | ||
| 22155 | Quotients of powers and square roots are distributed just as | 22395 | Quotients of powers and square roots are distributed just as |
| 22156 | described for multiplication. | 22396 | described for multiplication. |
| 22157 | 22397 | ||
| 22158 | Quotients of products cancel only in the leading terms of the | 22398 | Quotients of products cancel only in the leading terms of the |
| 22159 | numerator and denominator. In other words, @cite{a x b / a y b} | 22399 | numerator and denominator. In other words, @expr{a x b / a y b} |
| 22160 | is cancelled to @cite{x b / y b} but not to @cite{x / y}. Once | 22400 | is cancelled to @expr{x b / y b} but not to @expr{x / y}. Once |
| 22161 | again this is because full cancellation can be slow; use @kbd{a s} | 22401 | again this is because full cancellation can be slow; use @kbd{a s} |
| 22162 | to cancel all terms of the quotient. | 22402 | to cancel all terms of the quotient. |
| 22163 | 22403 | ||
| 22164 | Quotients of negative-looking values are simplified according | 22404 | Quotients of negative-looking values are simplified according |
| 22165 | to @cite{(-a) / (-b)} to @cite{a / b}, @cite{(-a) / (b - c)} | 22405 | to @expr{(-a) / (-b)} to @expr{a / b}, @expr{(-a) / (b - c)} |
| 22166 | to @cite{a / (c - b)}, and @cite{(a - b) / (-c)} to @cite{(b - a) / c}. | 22406 | to @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 | ||
| 22172 | The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)} | 22412 | The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)} |
| 22173 | in matrix mode. The formula @cite{0^x} is simplified to @cite{0} | 22413 | in matrix mode. The formula @expr{0^x} is simplified to @expr{0} |
| 22174 | unless @cite{x} is a negative number or complex number, in which | 22414 | unless @expr{x} is a negative number or complex number, in which |
| 22175 | case the result is an infinity or an unsimplified formula according | 22415 | case the result is an infinity or an unsimplified formula according |
| 22176 | to the current infinite mode. Note that @cite{0^0} is an | 22416 | to the current infinite mode. Note that @expr{0^0} is an |
| 22177 | indeterminate form, as evidenced by the fact that the simplifications | 22417 | indeterminate form, as evidenced by the fact that the simplifications |
| 22178 | for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}. | 22418 | for @expr{x^0} and @expr{0^x} conflict when @expr{x=0}. |
| 22179 | 22419 | ||
| 22180 | Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c} | 22420 | Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c} |
| 22181 | are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c} | 22421 | are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c} |
| 22182 | is an integer, or if either @cite{a} or @cite{b} are nonnegative | 22422 | is an integer, or if either @expr{a} or @expr{b} are nonnegative |
| 22183 | real numbers. Powers of powers @cite{(a^b)^c} are simplified to | 22423 | real 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)} |
| 22426 | only when @expr{c} is an integer and @expr{b c} also | ||
| 22186 | evaluates to an integer. Without these restrictions these simplifications | 22427 | evaluates to an integer. Without these restrictions these simplifications |
| 22187 | would not be safe because of problems with principal values. | 22428 | would 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 | 22432 | is safe to simplify, but |
| 22192 | Calc that your variables satisfy these requirements. | 22433 | @texline @tmath{((-3)^2)^{1/2}} |
| 22193 | 22434 | @infoline @expr{((-3)^2)^1:2} | |
| 22194 | As a special case of this rule, @cite{@t{sqrt}(x)^n} is simplified to | 22435 | is not.) @xref{Declarations}, for ways to inform Calc that your |
| 22195 | @c{$x^{n/2}$} | 22436 | variables satisfy these requirements. |
| 22196 | @cite{x^(n/2)} only for even integers @cite{n}. | 22437 | |
| 22197 | 22438 | As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to | |
| 22198 | If @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)} |
| 22200 | simplified to @c{$@t{abs}(a^{b c})$} | 22441 | only for even integers @expr{n}. |
| 22201 | @cite{@t{abs}(a^(b c))}. | 22442 | |
| 22202 | 22443 | If @expr{a} is known to be real, @expr{b} is an even integer, and | |
| 22203 | Also, @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 |
| 22204 | even integer, or to @cite{-(a^b)} if @cite{b} is an odd integer, | 22445 | simplified to @expr{@t{abs}(a^(b c))}. |
| 22205 | for any negative-looking expression @cite{-a}. | 22446 | |
| 22206 | 22447 | Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an | |
| 22207 | Square roots @cite{@t{sqrt}(x)} generally act like one-half powers | 22448 | even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer, |
| 22208 | @c{$x^{1:2}$} | 22449 | for any negative-looking expression @expr{-a}. |
| 22209 | @cite{x^1:2} for the purposes of the above-listed simplifications. | 22450 | |
| 22210 | 22451 | Square roots @expr{@t{sqrt}(x)} generally act like one-half powers | |
| 22211 | Also, 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)}, | 22454 | for the purposes of the above-listed simplifications. |
| 22214 | but @cite{1 / @t{sqrt}(x)} is left alone. | 22455 | |
| 22456 | Also, note that | ||
| 22457 | @texline @tmath{1 / x^{1:2}} | ||
| 22458 | @infoline @expr{1 / x^1:2} | ||
| 22459 | is changed to | ||
| 22460 | @texline @tmath{x^{-1:2}}, | ||
| 22461 | @infoline @expr{x^(-1:2)}, | ||
| 22462 | but @expr{1 / @t{sqrt}(x)} is left alone. | ||
| 22215 | 22463 | ||
| 22216 | @tex | 22464 | @tex |
| 22217 | \bigskip | 22465 | \bigskip |
| 22218 | @end tex | 22466 | @end tex |
| 22219 | 22467 | ||
| 22220 | Generic identity matrices (@pxref{Matrix Mode}) are simplified by the | 22468 | Generic identity matrices (@pxref{Matrix Mode}) are simplified by the |
| 22221 | following rules: @cite{@t{idn}(a) + b} to @cite{a + b} if @cite{b} | 22469 | following rules: @expr{@t{idn}(a) + b} to @expr{a + b} if @expr{b} |
| 22222 | is provably scalar, or expanded out if @cite{b} is a matrix; | 22470 | is 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} |
| 22226 | if @cite{a} is provably non-scalar; @cite{@t{idn}(a) @t{idn}(b)} | 22474 | if @expr{a} is provably non-scalar; @expr{@t{idn}(a) @t{idn}(b)} to |
| 22227 | to @cite{@t{idn}(a b)}; analogous simplifications for quotients | 22475 | @expr{@t{idn}(a b)}; analogous simplifications for quotients involving |
| 22228 | involving @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 |
| 22229 | where @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 | ||
| 22235 | The @code{floor} function and other integer truncation functions | 22483 | The @code{floor} function and other integer truncation functions |
| 22236 | vanish if the argument is provably integer-valued, so that | 22484 | vanish 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)}. |
| 22238 | Also, combinations of @code{float}, @code{floor} and its friends, | 22486 | Also, combinations of @code{float}, @code{floor} and its friends, |
| 22239 | and @code{ffloor} and its friends, are simplified in appropriate | 22487 | and @code{ffloor} and its friends, are simplified in appropriate |
| 22240 | ways. @xref{Integer Truncation}. | 22488 | ways. @xref{Integer Truncation}. |
| 22241 | 22489 | ||
| 22242 | The expression @cite{@t{abs}(-x)} changes to @cite{@t{abs}(x)}. | 22490 | The expression @expr{@t{abs}(-x)} changes to @expr{@t{abs}(x)}. |
| 22243 | The expression @cite{@t{abs}(@t{abs}(x))} changes to @cite{@t{abs}(x)}; | 22491 | The expression @expr{@t{abs}(@t{abs}(x))} changes to |
| 22244 | in 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 |
| 22245 | is provably nonnegative or nonpositive (@pxref{Declarations}). | 22493 | @expr{-x} if @expr{x} is provably nonnegative or nonpositive |
| 22494 | (@pxref{Declarations}). | ||
| 22246 | 22495 | ||
| 22247 | While most functions do not recognize the variable @code{i} as an | 22496 | While most functions do not recognize the variable @code{i} as an |
| 22248 | imaginary number, the @code{arg} function does handle the two cases | 22497 | imaginary 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 | ||
| 22251 | The expression @cite{@t{conj}(@t{conj}(x))} simplifies to @cite{x}. | 22500 | The expression @expr{@t{conj}(@t{conj}(x))} simplifies to @expr{x}. |
| 22252 | Various other expressions involving @code{conj}, @code{re}, and | 22501 | Various 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 |
| 22254 | provably real or involve the constant @code{i}. For example, | 22503 | provably 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 |
| 22256 | or 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} |
| 22506 | and @expr{b} are known to be real. | ||
| 22257 | 22507 | ||
| 22258 | Functions like @code{sin} and @code{arctan} generally don't have | 22508 | Functions like @code{sin} and @code{arctan} generally don't have |
| 22259 | any default simplifications beyond simply evaluating the functions | 22509 | any default simplifications beyond simply evaluating the functions |
| @@ -22261,18 +22511,18 @@ for suitable numeric arguments and infinity. The @kbd{a s} command | |||
| 22261 | described in the next section does provide some simplifications for | 22511 | described in the next section does provide some simplifications for |
| 22262 | these functions, though. | 22512 | these functions, though. |
| 22263 | 22513 | ||
| 22264 | One important simplification that does occur is that @cite{@t{ln}(@t{e})} | 22514 | One important simplification that does occur is that |
| 22265 | is 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 |
| 22266 | for any @cite{x}. This occurs even if you have stored a different | 22516 | simplified to @expr{x} for any @expr{x}. This occurs even if you have |
| 22267 | value in the Calc variable @samp{e}; but this would be a bad idea | 22517 | stored a different value in the Calc variable @samp{e}; but this would |
| 22268 | in any case if you were also using natural logarithms! | 22518 | be a bad idea in any case if you were also using natural logarithms! |
| 22269 | 22519 | ||
| 22270 | Among the logical functions, @t{(@var{a} <= @var{b})} changes to | 22520 | Among 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 |
| 22272 | are either negative-looking or zero are simplified by negating both sides | 22522 | are either negative-looking or zero are simplified by negating both sides |
| 22273 | and reversing the inequality. While it might seem reasonable to simplify | 22523 | and 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 | ||
| 22277 | Most other Calc functions have few if any default simplifications | 22527 | Most other Calc functions have few if any default simplifications |
| 22278 | defined, aside of course from evaluation when the arguments are | 22528 | defined, 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 | ||
| 22311 | Sums are simplified in two ways. Constant terms are commuted to the | 22561 | Sums are simplified in two ways. Constant terms are commuted to the |
| 22312 | end of the sum, so that @cite{a + 2 + b} changes to @cite{a + b + 2}. | 22562 | end of the sum, so that @expr{a + 2 + b} changes to @expr{a + b + 2}. |
| 22313 | The only exception is that a constant will not be commuted away | 22563 | The only exception is that a constant will not be commuted away |
| 22314 | from the first position of a difference, i.e., @cite{2 - x} is not | 22564 | from the first position of a difference, i.e., @expr{2 - x} is not |
| 22315 | commuted to @cite{-x + 2}. | 22565 | commuted to @expr{-x + 2}. |
| 22316 | 22566 | ||
| 22317 | Also, terms of sums are combined by the distributive law, as in | 22567 | Also, 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 |
| 22319 | adjacent terms, but @kbd{a s} compares all pairs of terms including | 22569 | adjacent terms, but @kbd{a s} compares all pairs of terms including |
| 22320 | non-adjacent ones. | 22570 | non-adjacent ones. |
| 22321 | 22571 | ||
| @@ -22324,10 +22574,10 @@ non-adjacent ones. | |||
| 22324 | @end tex | 22574 | @end tex |
| 22325 | 22575 | ||
| 22326 | Products are sorted into a canonical order using the commutative | 22576 | Products are sorted into a canonical order using the commutative |
| 22327 | law. For example, @cite{b c a} is commuted to @cite{a b c}. | 22577 | law. For example, @expr{b c a} is commuted to @expr{a b c}. |
| 22328 | This allows easier comparison of products; for example, the default | 22578 | This allows easier comparison of products; for example, the default |
| 22329 | simplifications will not change @cite{x y + y x} to @cite{2 x y}, | 22579 | simplifications will not change @expr{x y + y x} to @expr{2 x y}, |
| 22330 | but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y}, | 22580 | but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y}, |
| 22331 | and then the default simplifications are able to recognize a sum | 22581 | and then the default simplifications are able to recognize a sum |
| 22332 | of identical terms. | 22582 | of identical terms. |
| 22333 | 22583 | ||
| @@ -22346,15 +22596,15 @@ use for adjacent terms of products. | |||
| 22346 | 22596 | ||
| 22347 | Even though sums are not sorted, the commutative law is still | 22597 | Even though sums are not sorted, the commutative law is still |
| 22348 | taken into account when terms of a product are being compared. | 22598 | taken into account when terms of a product are being compared. |
| 22349 | Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}. | 22599 | Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}. |
| 22350 | A subtle point is that @cite{(x - y) (y - x)} will @emph{not} | 22600 | A subtle point is that @expr{(x - y) (y - x)} will @emph{not} |
| 22351 | be simplified to @cite{-(x - y)^2}; Calc does not notice that | 22601 | be simplified to @expr{-(x - y)^2}; Calc does not notice that |
| 22352 | one term can be written as a constant times the other, even if | 22602 | one term can be written as a constant times the other, even if |
| 22353 | that constant is @i{-1}. | 22603 | that constant is @i{-1}. |
| 22354 | 22604 | ||
| 22355 | A fraction times any expression, @cite{(a:b) x}, is changed to | 22605 | A fraction times any expression, @expr{(a:b) x}, is changed to |
| 22356 | a quotient involving integers: @cite{a x / b}. This is not | 22606 | a quotient involving integers: @expr{a x / b}. This is not |
| 22357 | done for floating-point numbers like @cite{0.5}, however. This | 22607 | done for floating-point numbers like @expr{0.5}, however. This |
| 22358 | is one reason why you may find it convenient to turn Fraction mode | 22608 | is one reason why you may find it convenient to turn Fraction mode |
| 22359 | on while doing algebra; @pxref{Fraction Mode}. | 22609 | on while doing algebra; @pxref{Fraction Mode}. |
| 22360 | 22610 | ||
| @@ -22364,25 +22614,25 @@ on while doing algebra; @pxref{Fraction Mode}. | |||
| 22364 | 22614 | ||
| 22365 | Quotients are simplified by comparing all terms in the numerator | 22615 | Quotients are simplified by comparing all terms in the numerator |
| 22366 | with all terms in the denominator for possible cancellation using | 22616 | with all terms in the denominator for possible cancellation using |
| 22367 | the distributive law. For example, @cite{a x^2 b / c x^3 d} will | 22617 | the distributive law. For example, @expr{a x^2 b / c x^3 d} will |
| 22368 | cancel @cite{x^2} from both sides to get @cite{a b / c x d}. | 22618 | cancel @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} |
| 22370 | as described above.) If there is any common integer or fractional | 22620 | as described above.) If there is any common integer or fractional |
| 22371 | factor in the numerator and denominator, it is cancelled out; | 22621 | factor in the numerator and denominator, it is cancelled out; |
| 22372 | for example, @cite{(4 x + 6) / 8 x} simplifies to @cite{(2 x + 3) / 4 x}. | 22622 | for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}. |
| 22373 | 22623 | ||
| 22374 | Non-constant common factors are not found even by @kbd{a s}. To | 22624 | Non-constant common factors are not found even by @kbd{a s}. To |
| 22375 | cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first | 22625 | cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first |
| 22376 | use @kbd{j M} on the product @cite{a x} to Merge the numerator to | 22626 | use @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 | ||
| 22383 | Integer powers of the variable @code{i} are simplified according | 22633 | Integer powers of the variable @code{i} are simplified according |
| 22384 | to the identity @cite{i^2 = -1}. If you store a new value other | 22634 | to the identity @expr{i^2 = -1}. If you store a new value other |
| 22385 | than the complex number @cite{(0,1)} in @code{i}, this simplification | 22635 | than the complex number @expr{(0,1)} in @code{i}, this simplification |
| 22386 | will no longer occur. This is done by @kbd{a s} instead of by default | 22636 | will no longer occur. This is done by @kbd{a s} instead of by default |
| 22387 | in case someone (unwisely) uses the name @code{i} for a variable | 22637 | in case someone (unwisely) uses the name @code{i} for a variable |
| 22388 | unrelated to complex numbers; it would be unfortunate if Calc | 22638 | unrelated to complex numbers; it would be unfortunate if Calc |
| @@ -22392,26 +22642,26 @@ user might not have been thinking of. | |||
| 22392 | Square roots of integer or rational arguments are simplified in | 22642 | Square roots of integer or rational arguments are simplified in |
| 22393 | several ways. (Note that these will be left unevaluated only in | 22643 | several ways. (Note that these will be left unevaluated only in |
| 22394 | Symbolic mode.) First, square integer or rational factors are | 22644 | Symbolic mode.) First, square integer or rational factors are |
| 22395 | pulled out so that @cite{@t{sqrt}(8)} is rewritten as | 22645 | pulled 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)}. |
| 22398 | the argument into primes and moving pairs of primes out of the | 22648 | Conceptually speaking this implies factoring the argument into primes |
| 22399 | square root, but for reasons of efficiency Calc only looks for | 22649 | and moving pairs of primes out of the square root, but for reasons of |
| 22400 | primes up to 29. | 22650 | efficiency Calc only looks for primes up to 29. |
| 22401 | 22651 | ||
| 22402 | Square roots in the denominator of a quotient are moved to the | 22652 | Square roots in the denominator of a quotient are moved to the |
| 22403 | numerator: @cite{1 / @t{sqrt}(3)} changes to @cite{@t{sqrt}(3) / 3}. | 22653 | numerator: @expr{1 / @t{sqrt}(3)} changes to @expr{@t{sqrt}(3) / 3}. |
| 22404 | The same effect occurs for the square root of a fraction: | 22654 | The 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 | ||
| 22411 | The @code{%} (modulo) operator is simplified in several ways | 22661 | The @code{%} (modulo) operator is simplified in several ways |
| 22412 | when the modulus @cite{M} is a positive real number. First, if | 22662 | when the modulus @expr{M} is a positive real number. First, if |
| 22413 | the argument is of the form @cite{x + n} for some real number | 22663 | the 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 |
| 22415 | example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}. | 22665 | example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}. |
| 22416 | 22666 | ||
| 22417 | If the argument is multiplied by a constant, and this constant | 22667 | If 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 | ||
| 22437 | Trigonometric functions are simplified in several ways. First, | 22687 | Trigonometric 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 |
| 22439 | similarly for @code{cos} and @code{tan}. If the argument to | 22689 | similarly 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 |
| 22441 | and similarly for @code{cos} and @code{tan}. Finally, certain | 22691 | @expr{-@t{sin}(x),}, and similarly for @code{cos} and @code{tan}. |
| 22442 | special values of the argument are recognized; | 22692 | Finally, certain special values of the argument are recognized; |
| 22443 | @pxref{Trigonometric and Hyperbolic Functions}. | 22693 | @pxref{Trigonometric and Hyperbolic Functions}. |
| 22444 | 22694 | ||
| 22445 | Trigonometric functions of inverses of different trigonometric | 22695 | Trigonometric functions of inverses of different trigonometric |
| 22446 | functions can also be simplified, as in @cite{@t{sin}(@t{arccos}(x))} | 22696 | functions can also be simplified, as in @expr{@t{sin}(@t{arccos}(x))} |
| 22447 | to @cite{@t{sqrt}(1 - x^2)}. | 22697 | to @expr{@t{sqrt}(1 - x^2)}. |
| 22448 | 22698 | ||
| 22449 | Hyperbolic functions of their inverses and of negative-looking | 22699 | Hyperbolic functions of their inverses and of negative-looking |
| 22450 | arguments are also handled, as are exponentials of inverse | 22700 | arguments are also handled, as are exponentials of inverse |
| @@ -22453,26 +22703,31 @@ hyperbolic functions. | |||
| 22453 | No simplifications for inverse trigonometric and hyperbolic | 22703 | No simplifications for inverse trigonometric and hyperbolic |
| 22454 | functions are known, except for negative arguments of @code{arcsin}, | 22704 | functions 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 |
| 22458 | of @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 | 22710 | radians or 360 degrees. However, @expr{@t{arcsinh}(@t{sinh}(x))} is |
| 22461 | @cite{x} is known to be real. | 22711 | simplified to @expr{x} if @expr{x} is known to be real. |
| 22462 | 22712 | ||
| 22463 | Several simplifications that apply to logarithms and exponentials | 22713 | Several simplifications that apply to logarithms and exponentials |
| 22464 | are that @cite{@t{exp}(@t{ln}(x))}, @c{$@t{e}^{\ln(x)}$} | 22714 | are 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}. | 22717 | and |
| 22468 | Also, @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)} |
| 22470 | to @cite{@t{exp}(x y)}. If @cite{x} is a suitable multiple of @c{$\pi i$} | 22720 | all reduce to @expr{x}. Also, @expr{@t{ln}(@t{exp}(x))}, etc., can |
| 22471 | @cite{pi i} | 22721 | reduce 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} |
| 22473 | or @cite{e^x} will be expanded. Finally, @cite{@t{ln}(x)} is simplified | 22723 | is a suitable multiple of |
| 22474 | to a form involving @code{pi} and @code{i} where @cite{x} is provably | 22724 | @texline @tmath{\pi i} |
| 22475 | negative, 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 | ||
| 22730 | negative imaginary. | ||
| 22476 | 22731 | ||
| 22477 | The error functions @code{erf} and @code{erfc} are simplified when | 22732 | The error functions @code{erf} and @code{erfc} are simplified when |
| 22478 | their arguments are negative-looking or are calls to the @code{conj} | 22733 | their arguments are negative-looking or are calls to the @code{conj} |
| @@ -22485,7 +22740,7 @@ function. | |||
| 22485 | Equations and inequalities are simplified by cancelling factors | 22740 | Equations and inequalities are simplified by cancelling factors |
| 22486 | of products, quotients, or sums on both sides. Inequalities | 22741 | of products, quotients, or sums on both sides. Inequalities |
| 22487 | change sign if a negative multiplicative factor is cancelled. | 22742 | change sign if a negative multiplicative factor is cancelled. |
| 22488 | Non-constant multiplicative factors as in @cite{a b = a c} are | 22743 | Non-constant multiplicative factors as in @expr{a b = a c} are |
| 22489 | cancelled from equations only if they are provably nonzero (generally | 22744 | cancelled from equations only if they are provably nonzero (generally |
| 22490 | because they were declared so; @pxref{Declarations}). Factors | 22745 | because they were declared so; @pxref{Declarations}). Factors |
| 22491 | are cancelled from inequalities only if they are nonzero and their | 22746 | are cancelled from inequalities only if they are nonzero and their |
| @@ -22493,11 +22748,11 @@ sign is known. | |||
| 22493 | 22748 | ||
| 22494 | Simplification also replaces an equation or inequality with | 22749 | Simplification also replaces an equation or inequality with |
| 22495 | 1 or 0 (``true'' or ``false'') if it can through the use of | 22750 | 1 or 0 (``true'' or ``false'') if it can through the use of |
| 22496 | declarations. If @cite{x} is declared to be an integer greater | 22751 | declarations. If @expr{x} is declared to be an integer greater |
| 22497 | than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are | 22752 | than 5, then @expr{x < 3}, @expr{x = 3}, and @expr{x = 7.5} are |
| 22498 | all simplified to 0, but @cite{x > 3} is simplified to 1. | 22753 | all simplified to 0, but @expr{x > 3} is simplified to 1. |
| 22499 | By a similar analysis, @cite{abs(x) >= 0} is simplified to 1, | 22754 | By a similar analysis, @expr{abs(x) >= 0} is simplified to 1, |
| 22500 | as is @cite{x^2 >= 0} if @cite{x} is known to be real. | 22755 | as 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 | |||
| 22519 | are valid. The symbolic integrator uses @kbd{a e}; | 22774 | are valid. The symbolic integrator uses @kbd{a e}; |
| 22520 | one effect of this is that the integrator's results must be used with | 22775 | one effect of this is that the integrator's results must be used with |
| 22521 | caution. Where an integral table will often attach conditions like | 22776 | caution. 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 |
| 22523 | integration programs) will simply produce an unqualified result.@refill | 22778 | integration programs) will simply produce an unqualified result. |
| 22524 | 22779 | ||
| 22525 | Because @kbd{a e}'s simplifications are unsafe, it is sometimes better | 22780 | Because @kbd{a e}'s simplifications are unsafe, it is sometimes better |
| 22526 | to type @kbd{C-u -3 a v}, which does extended simplification only | 22781 | to type @kbd{C-u -3 a v}, which does extended simplification only |
| @@ -22542,45 +22797,49 @@ by @kbd{a e}. | |||
| 22542 | 22797 | ||
| 22543 | Inverse trigonometric or hyperbolic functions, called with their | 22798 | Inverse trigonometric or hyperbolic functions, called with their |
| 22544 | corresponding non-inverse functions as arguments, are simplified | 22799 | corresponding non-inverse functions as arguments, are simplified |
| 22545 | by @kbd{a e}. For example, @cite{@t{arcsin}(@t{sin}(x))} changes | 22800 | by @kbd{a e}. For example, @expr{@t{arcsin}(@t{sin}(x))} changes |
| 22546 | to @cite{x}. Also, @cite{@t{arcsin}(@t{cos}(x))} and | 22801 | to @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}. |
| 22548 | These simplifications are unsafe because they are valid only for | 22803 | These simplifications are unsafe because they are valid only for |
| 22549 | values of @cite{x} in a certain range; outside that range, values | 22804 | values of @expr{x} in a certain range; outside that range, values |
| 22550 | are folded down to the 360-degree range that the inverse trigonometric | 22805 | are folded down to the 360-degree range that the inverse trigonometric |
| 22551 | functions always produce. | 22806 | functions always produce. |
| 22552 | 22807 | ||
| 22553 | Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$} | 22808 | Powers of powers @expr{(x^a)^b} are simplified to |
| 22554 | @cite{x^(a b)} | 22809 | @texline @tmath{x^{a b}} |
| 22555 | for all @cite{a} and @cite{b}. These results will be valid only | 22810 | @infoline @expr{x^(a b)} |
| 22556 | in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$} | 22811 | for all @expr{a} and @expr{b}. These results will be valid only |
| 22557 | @cite{(x^2)^1:2} | 22812 | in a restricted range of @expr{x}; for example, in |
| 22558 | the powers cancel to get @cite{x}, which is valid for positive values | 22813 | @texline @tmath{(x^2)^{1:2}} |
| 22559 | of @cite{x} but not for negative or complex values. | 22814 | @infoline @expr{(x^2)^1:2} |
| 22560 | 22815 | the powers cancel to get @expr{x}, which is valid for positive values | |
| 22561 | Similarly, @cite{@t{sqrt}(x^a)} and @cite{@t{sqrt}(x)^a} are both | 22816 | of @expr{x} but not for negative or complex values. |
| 22562 | simplified (possibly unsafely) to @c{$x^{a/2}$} | 22817 | |
| 22563 | @cite{x^(a/2)}. | 22818 | Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both |
| 22564 | 22819 | simplified (possibly unsafely) to | |
| 22565 | Forms 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 | |||
| 22823 | Forms 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 | ||
| 22569 | Arguments of square roots are partially factored to look for | 22827 | Arguments of square roots are partially factored to look for |
| 22570 | squared terms that can be extracted. For example, | 22828 | squared 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 | ||
| 22573 | The simplifications of @cite{@t{ln}(@t{exp}(x))}, @cite{@t{ln}(@t{e}^x)}, | 22832 | The simplifications of @expr{@t{ln}(@t{exp}(x))}, |
| 22574 | and @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 |
| 22575 | of problems with principal values (although these simplifications | 22834 | unsafe because of problems with principal values (although these |
| 22576 | are safe if @cite{x} is known to be real). | 22835 | simplifications are safe if @expr{x} is known to be real). |
| 22577 | 22836 | ||
| 22578 | Common factors are cancelled from products on both sides of an | 22837 | Common factors are cancelled from products on both sides of an |
| 22579 | equation, even if those factors may be zero: @cite{a x / b x} | 22838 | equation, even if those factors may be zero: @expr{a x / b x} |
| 22580 | to @cite{a / b}. Such factors are never cancelled from | 22839 | to @expr{a / b}. Such factors are never cancelled from |
| 22581 | inequalities: Even @kbd{a e} is not bold enough to reduce | 22840 | inequalities: 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 |
| 22583 | on whether you believe @cite{x} is positive or negative). | 22842 | on whether you believe @expr{x} is positive or negative). |
| 22584 | The @kbd{a M /} command can be used to divide a factor out of | 22843 | The @kbd{a M /} command can be used to divide a factor out of |
| 22585 | both sides of an inequality. | 22844 | both sides of an inequality. |
| 22586 | 22845 | ||
| @@ -22600,12 +22859,12 @@ and @code{AlgSimpRules}. | |||
| 22600 | Scalar mode is automatically put into effect when simplifying units. | 22859 | Scalar mode is automatically put into effect when simplifying units. |
| 22601 | @xref{Matrix Mode}. | 22860 | @xref{Matrix Mode}. |
| 22602 | 22861 | ||
| 22603 | Sums @cite{a + b} involving units are simplified by extracting the | 22862 | Sums @expr{a + b} involving units are simplified by extracting the |
| 22604 | units of @cite{a} as if by the @kbd{u x} command (call the result | 22863 | units 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} |
| 22606 | using @kbd{u b} and @kbd{u s}. If the result has units then the sum | 22865 | using @kbd{u b} and @kbd{u s}. If the result has units then the sum |
| 22607 | is inconsistent and is left alone. Otherwise, it is rewritten | 22866 | is inconsistent and is left alone. Otherwise, it is rewritten |
| 22608 | in terms of the units @cite{u_a}. | 22867 | in terms of the units @expr{u_a}. |
| 22609 | 22868 | ||
| 22610 | If units auto-ranging mode is enabled, products or quotients in | 22869 | If units auto-ranging mode is enabled, products or quotients in |
| 22611 | which the first argument is a number which is out of range for the | 22870 | which 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}. | |||
| 22617 | However, compatible but different units like @code{ft} and @code{in} | 22876 | However, compatible but different units like @code{ft} and @code{in} |
| 22618 | are not combined in this way. | 22877 | are not combined in this way. |
| 22619 | 22878 | ||
| 22620 | Quotients @cite{a / b} are simplified in three additional ways. First, | 22879 | Quotients @expr{a / b} are simplified in three additional ways. First, |
| 22621 | if @cite{b} is a number or a product beginning with a number, Calc | 22880 | if @expr{b} is a number or a product beginning with a number, Calc |
| 22622 | computes the reciprocal of this number and moves it to the numerator. | 22881 | computes the reciprocal of this number and moves it to the numerator. |
| 22623 | 22882 | ||
| 22624 | Second, for each pair of unit names from the numerator and denominator | 22883 | Second, for each pair of unit names from the numerator and denominator |
| 22625 | of a quotient, if the units are compatible (e.g., they are both | 22884 | of a quotient, if the units are compatible (e.g., they are both |
| 22626 | units of area) then they are replaced by the ratio between those | 22885 | units of area) then they are replaced by the ratio between those |
| 22627 | units. For example, in @samp{3 s in N / kg cm} the units | 22886 | units. 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 | ||
| 22630 | Third, if the units in the quotient exactly cancel out, so that | 22889 | Third, if the units in the quotient exactly cancel out, so that |
| 22631 | a @kbd{u b} command on the quotient would produce a dimensionless | 22890 | a @kbd{u b} command on the quotient would produce a dimensionless |
| 22632 | number for an answer, then the quotient simplifies to that number. | 22891 | number for an answer, then the quotient simplifies to that number. |
| 22633 | 22892 | ||
| 22634 | For powers and square roots, the ``unsafe'' simplifications | 22893 | For 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}, |
| 22636 | and @cite{(a^b)^c} to @c{$a^{b c}$} | 22895 | and @expr{(a^b)^c} to |
| 22637 | @cite{a^(b c)} are done if the powers are | 22896 | @texline @tmath{a^{b c}} |
| 22638 | real numbers. (These are safe in the context of units because | 22897 | @infoline @expr{a^(b c)} |
| 22639 | all numbers involved can reasonably be assumed to be real.) | 22898 | are done if the powers are real numbers. (These are safe in the context |
| 22899 | of units because all numbers involved can reasonably be assumed to be | ||
| 22900 | real.) | ||
| 22640 | 22901 | ||
| 22641 | Also, if a unit name is raised to a fractional power, and the | 22902 | Also, if a unit name is raised to a fractional power, and the |
| 22642 | base units in that unit name all occur to powers which are a | 22903 | base units in that unit name all occur to powers which are a |
| 22643 | multiple of the denominator of the power, then the unit name | 22904 | multiple of the denominator of the power, then the unit name |
| 22644 | is expanded out into its base units, which can then be simplified | 22905 | is expanded out into its base units, which can then be simplified |
| 22645 | according to the previous paragraph. For example, @samp{acre^1.5} | 22906 | according to the previous paragraph. For example, @samp{acre^1.5} |
| 22646 | is simplified by noting that @cite{1.5 = 3:2}, that @samp{acre} | 22907 | is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre} |
| 22647 | is defined in terms of @samp{m^2}, and that the 2 in the power of | 22908 | is 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 |
| 22649 | replaced by approximately @c{$(4046 m^2)^{1.5}$} | 22910 | replaced by approximately |
| 22650 | @cite{(4046 m^2)^1.5}, which is then | 22911 | @texline @tmath{(4046 m^2)^{1.5}} |
| 22651 | changed 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}. | 22913 | which is then changed to |
| 22914 | @texline @tmath{4046^{1.5} \, (m^2)^{1.5}}, | ||
| 22915 | @infoline @expr{4046^1.5 (m^2)^1.5}, | ||
| 22916 | then to @expr{257440 m^3}. | ||
| 22653 | 22917 | ||
| 22654 | The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, | 22918 | The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, |
| 22655 | as well as @code{floor} and the other integer truncation functions, | 22919 | as 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 | ||
| 22669 | A @dfn{polynomial} is a sum of terms which are coefficients times | 22933 | A @dfn{polynomial} is a sum of terms which are coefficients times |
| 22670 | various powers of a ``base'' variable. For example, @cite{2 x^2 + 3 x - 4} | 22934 | various powers of a ``base'' variable. For example, @expr{2 x^2 + 3 x - 4} |
| 22671 | is a polynomial in @cite{x}. Some formulas can be considered | 22935 | is a polynomial in @expr{x}. Some formulas can be considered |
| 22672 | polynomials in several different variables: @cite{1 + 2 x + 3 y + 4 x y^2} | 22936 | polynomials in several different variables: @expr{1 + 2 x + 3 y + 4 x y^2} |
| 22673 | is a polynomial in both @cite{x} and @cite{y}. Polynomial coefficients | 22937 | is a polynomial in both @expr{x} and @expr{y}. Polynomial coefficients |
| 22674 | are often numbers, but they may in general be any formulas not | 22938 | are often numbers, but they may in general be any formulas not |
| 22675 | involving the base variable. | 22939 | involving the base variable. |
| 22676 | 22940 | ||
| @@ -22679,9 +22943,9 @@ involving the base variable. | |||
| 22679 | @tindex factor | 22943 | @tindex factor |
| 22680 | The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a | 22944 | The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a |
| 22681 | polynomial into a product of terms. For example, the polynomial | 22945 | polynomial 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 |
| 22683 | example, @cite{a c + b d + b c + a d} is factored into the product | 22947 | example, @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 | ||
| 22686 | Calc currently has three algorithms for factoring. Formulas which are | 22950 | Calc currently has three algorithms for factoring. Formulas which are |
| 22687 | linear in several variables, such as the second example above, are | 22951 | linear in several variables, such as the second example above, are |
| @@ -22689,7 +22953,7 @@ merged according to the distributive law. Formulas which are | |||
| 22689 | polynomials in a single variable, with constant integer or fractional | 22953 | polynomials in a single variable, with constant integer or fractional |
| 22690 | coefficients, are factored into irreducible linear and/or quadratic | 22954 | coefficients, are factored into irreducible linear and/or quadratic |
| 22691 | terms. The first example above factors into three linear terms | 22955 | terms. 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 |
| 22693 | which do not fit the above criteria are handled by the algebraic | 22957 | which do not fit the above criteria are handled by the algebraic |
| 22694 | rewrite mechanism. | 22958 | rewrite 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 |
| 22722 | operation of rewrite rules. The default @code{FactorRules} are able | 22986 | operation of rewrite rules. The default @code{FactorRules} are able |
| 22723 | to factor quadratic forms symbolically into two linear terms, | 22987 | to 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 |
| 22725 | cases if you wish. To use the rules, Calc builds the formula | 22989 | cases 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 |
| 22727 | base variable and @code{a}, @code{b}, etc., are polynomial coefficients | 22991 | base 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, | |||
| 22742 | but it returns a list of factors instead of an expression which is the | 23006 | but it returns a list of factors instead of an expression which is the |
| 22743 | product of the factors. Each factor is represented by a sub-vector | 23007 | product of the factors. Each factor is represented by a sub-vector |
| 22744 | of the factor, and the power with which it appears. For example, | 23008 | of 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} |
| 22746 | in @kbd{a f}, or to @cite{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}. | 23010 | in @kbd{a f}, or to @expr{[ [x, 2], [x+7, 1], [x-3, 2] ]} in @kbd{H a f}. |
| 22747 | If there is an overall numeric factor, it always comes first in the list. | 23011 | If there is an overall numeric factor, it always comes first in the list. |
| 22748 | The functions @code{factor} and @code{factors} allow a second argument | 23012 | The functions @code{factor} and @code{factors} allow a second argument |
| 22749 | when written in algebraic form; @samp{factor(x,v)} factors @cite{x} with | 23013 | when written in algebraic form; @samp{factor(x,v)} factors @expr{x} with |
| 22750 | respect to the specific variable @cite{v}. The default is to factor with | 23014 | respect to the specific variable @expr{v}. The default is to factor with |
| 22751 | respect to all the variables that appear in @cite{x}. | 23015 | respect 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}. | |||
| 22756 | The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a | 23020 | The @kbd{a c} (@code{calc-collect}) [@code{collect}] command rearranges a |
| 22757 | formula as a | 23021 | formula as a |
| 22758 | polynomial in a given variable, ordered in decreasing powers of that | 23022 | polynomial in a given variable, ordered in decreasing powers of that |
| 22759 | variable. For example, given @cite{1 + 2 x + 3 y + 4 x y^2} on | 23023 | variable. For example, given @expr{1 + 2 x + 3 y + 4 x y^2} on |
| 22760 | the stack, @kbd{a c x} would produce @cite{(2 + 4 y^2) x + (1 + 3 y)}, | 23024 | the stack, @kbd{a c x} would produce @expr{(2 + 4 y^2) x + (1 + 3 y)}, |
| 22761 | and @kbd{a c y} would produce @cite{(4 x) y^2 + 3 y + (1 + 2 x)}. | 23025 | and @kbd{a c y} would produce @expr{(4 x) y^2 + 3 y + (1 + 2 x)}. |
| 22762 | The polynomial will be expanded out using the distributive law as | 23026 | The polynomial will be expanded out using the distributive law as |
| 22763 | necessary: Collecting @cite{x} in @cite{(x - 1)^3} produces | 23027 | necessary: 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 |
| 22765 | not be expanded. | 23029 | not be expanded. |
| 22766 | 23030 | ||
| 22767 | The ``variable'' you specify at the prompt can actually be any | 23031 | The ``variable'' you specify at the prompt can actually be any |
| @@ -22790,10 +23054,10 @@ also know many other kinds of expansions, such as | |||
| 22790 | do not do.) | 23054 | do not do.) |
| 22791 | 23055 | ||
| 22792 | Calc's automatic simplifications will sometimes reverse a partial | 23056 | Calc's automatic simplifications will sometimes reverse a partial |
| 22793 | expansion. For example, the first step in expanding @cite{(x+1)^3} is | 23057 | expansion. For example, the first step in expanding @expr{(x+1)^3} is |
| 22794 | to write @cite{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries | 23058 | to write @expr{(x+1) (x+1)^2}. If @kbd{a x} stops there and tries |
| 22795 | to put this formula onto the stack, though, Calc will automatically | 23059 | to put this formula onto the stack, though, Calc will automatically |
| 22796 | simplify it back to @cite{(x+1)^3} form. The solution is to turn | 23060 | simplify it back to @expr{(x+1)^3} form. The solution is to turn |
| 22797 | simplification off first (@pxref{Simplification Modes}), or to run | 23061 | simplification 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 |
| 22799 | the way in one step. | 23063 | the way in one step. |
| @@ -22814,21 +23078,21 @@ chooses the base variable automatically. | |||
| 22814 | @tindex nrat | 23078 | @tindex nrat |
| 22815 | The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command | 23079 | The @kbd{a n} (@code{calc-normalize-rat}) [@code{nrat}] command |
| 22816 | attempts to arrange a formula into a quotient of two polynomials. | 23080 | attempts to arrange a formula into a quotient of two polynomials. |
| 22817 | For example, given @cite{1 + (a + b/c) / d}, the result would be | 23081 | For 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 |
| 22820 | out the common factor @cite{x + 1}, yielding @cite{(x + 1) / (x - 1)}. | 23084 | out 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 |
| 22825 | The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides | 23089 | The @kbd{a \} (@code{calc-poly-div}) [@code{pdiv}] command divides |
| 22826 | two polynomials @cite{u} and @cite{v}, yielding a new polynomial | 23090 | two 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 |
| 22828 | considered multivariate polynomials. (Calc divides by the variable | 23092 | considered multivariate polynomials. (Calc divides by the variable |
| 22829 | with the largest power in @cite{u} first, or, in the case of equal | 23093 | with the largest power in @expr{u} first, or, in the case of equal |
| 22830 | powers, chooses the variables in alphabetical order.) For example, | 23094 | powers, chooses the variables in alphabetical order.) For example, |
| 22831 | dividing @cite{x^2 + 3 x + 2} by @cite{x + 2} yields @cite{x + 1}. | 23095 | dividing @expr{x^2 + 3 x + 2} by @expr{x + 2} yields @expr{x + 1}. |
| 22832 | The remainder from the division, if any, is reported at the bottom | 23096 | The remainder from the division, if any, is reported at the bottom |
| 22833 | of the screen and is also placed in the Trail along with the quotient. | 23097 | of 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 |
| 22844 | The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides | 23108 | The @kbd{a %} (@code{calc-poly-rem}) [@code{prem}] command divides |
| 22845 | two polynomials and keeps the remainder @cite{r}. The quotient | 23109 | two 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 |
| 22847 | results of @kbd{a \} and @kbd{a %} satisfy @cite{a = q b + r}. | 23111 | results 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 |
| 22849 | integer quotient and remainder from dividing two numbers.) | 23113 | integer 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 |
| 22856 | The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command | 23120 | The @kbd{a /} (@code{calc-poly-div-rem}) [@code{pdivrem}] command |
| 22857 | divides two polynomials and reports both the quotient and the | 23121 | divides two polynomials and reports both the quotient and the |
| 22858 | remainder as a vector @cite{[q, r]}. The @kbd{H a /} [@code{pdivide}] | 23122 | remainder as a vector @expr{[q, r]}. The @kbd{H a /} [@code{pdivide}] |
| 22859 | command divides two polynomials and constructs the formula | 23123 | command 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, |
| 22861 | this will immediately simplify to @cite{q}.) | 23125 | this 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 | ||
| 22937 | If you use the @code{deriv} function directly in an algebraic formula, | 23201 | If you use the @code{deriv} function directly in an algebraic formula, |
| 22938 | you can write @samp{deriv(f,x,x0)} which represents the derivative | 23202 | you can write @samp{deriv(f,x,x0)} which represents the derivative |
| 22939 | of @cite{f} with respect to @cite{x}, evaluated at the point @c{$x=x_0$} | 23203 | of @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 | ||
| 22942 | If the formula being differentiated contains functions which Calc does | 23207 | If the formula being differentiated contains functions which Calc does |
| 22943 | not know, the derivatives of those functions are produced by adding | 23208 | not 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)}. | |||
| 22960 | Various higher-order derivatives can be formed in the obvious way, e.g., | 23225 | Various 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 |
| 22963 | argument once).@refill | 23228 | argument 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 | |||
| 22975 | all integrable functions, but it is able to integrate several large | 23240 | all integrable functions, but it is able to integrate several large |
| 22976 | classes of formulas. In particular, any polynomial or rational function | 23241 | classes 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 |
| 22978 | don't have to be in explicit quotient form, however; @c{$x/(1+x^{-2})$} | 23243 | don'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)} | ||
| 22980 | is not strictly a quotient of polynomials, but it is equivalent to | 23246 | is 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 |
| 22983 | integrated. Finally, rational functions involving trigonometric or | 23249 | integrated. Finally, rational functions involving trigonometric or |
| 22984 | hyperbolic functions can be integrated. | 23250 | hyperbolic functions can be integrated. |
| 22985 | 23251 | ||
| @@ -23000,17 +23266,21 @@ integral $\int_a^b f(x) \, dx$. | |||
| 23000 | 23266 | ||
| 23001 | Please note that the current implementation of Calc's integrator sometimes | 23267 | Please note that the current implementation of Calc's integrator sometimes |
| 23002 | produces results that are significantly more complex than they need to | 23268 | produces results that are significantly more complex than they need to |
| 23003 | be. For example, the integral Calc finds for @c{$1/(x+\sqrt{x^2+1})$} | 23269 | be. 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))} | ||
| 23005 | is several times more complicated than the answer Mathematica | 23272 | is several times more complicated than the answer Mathematica |
| 23006 | returns for the same input, although the two forms are numerically | 23273 | returns for the same input, although the two forms are numerically |
| 23007 | equivalent. Also, any indefinite integral should be considered to have | 23274 | equivalent. Also, any indefinite integral should be considered to have |
| 23008 | an arbitrary constant of integration added to it, although Calc does not | 23275 | an arbitrary constant of integration added to it, although Calc does not |
| 23009 | write an explicit constant of integration in its result. For example, | 23276 | write an explicit constant of integration in its result. For example, |
| 23010 | Calc's solution for @c{$1/(1+\tan x)$} | 23277 | Calc's solution for |
| 23011 | @cite{1/(1+tan(x))} differs from the solution given | 23278 | @texline @tmath{1/(1+\tan x)} |
| 23012 | in 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}, | 23280 | differs from the solution given in the @emph{CRC Math Tables} by a |
| 23281 | constant factor of | ||
| 23282 | @texline @tmath{\pi i / 2} | ||
| 23283 | @infoline @expr{pi i / 2}, | ||
| 23014 | due to a different choice of constant of integration. | 23284 | due to a different choice of constant of integration. |
| 23015 | 23285 | ||
| 23016 | The Calculator remembers all the integrals it has done. If conditions | 23286 | The Calculator remembers all the integrals it has done. If conditions |
| @@ -23068,8 +23338,10 @@ in your @code{IntegRules}. | |||
| 23068 | @tindex Ei | 23338 | @tindex Ei |
| 23069 | As a more serious example, the expression @samp{exp(x)/x} cannot be | 23339 | As a more serious example, the expression @samp{exp(x)/x} cannot be |
| 23070 | integrated in terms of the standard functions, so the ``exponential | 23340 | integrated in terms of the standard functions, so the ``exponential |
| 23071 | integral'' function @c{${\rm Ei}(x)$} | 23341 | integral'' function |
| 23072 | @cite{Ei(x)} was invented to describe it. | 23342 | @texline @tmath{{\rm Ei}(x)} |
| 23343 | @infoline @expr{Ei(x)} | ||
| 23344 | was invented to describe it. | ||
| 23073 | We can get Calc to do this integral in terms of a made-up @code{Ei} | 23345 | We can get Calc to do this integral in terms of a made-up @code{Ei} |
| 23074 | function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} | 23346 | function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} |
| 23075 | to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack | 23347 | to @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}. | |||
| 23215 | You may specify the number of terms with a numeric prefix argument; | 23487 | You may specify the number of terms with a numeric prefix argument; |
| 23216 | otherwise the command will prompt you for the number of terms. Note that | 23488 | otherwise the command will prompt you for the number of terms. Note that |
| 23217 | many series expansions have coefficients of zero for some terms, so you | 23489 | many series expansions have coefficients of zero for some terms, so you |
| 23218 | may appear to get fewer terms than you asked for.@refill | 23490 | may appear to get fewer terms than you asked for. |
| 23219 | 23491 | ||
| 23220 | If the @kbd{a i} command is unable to find a symbolic integral for a | 23492 | If the @kbd{a i} command is unable to find a symbolic integral for a |
| 23221 | function, you can get an approximation by integrating the function's | 23493 | function, you can get an approximation by integrating the function's |
| @@ -23232,28 +23504,32 @@ Taylor series. | |||
| 23232 | @cindex Solving equations | 23504 | @cindex Solving equations |
| 23233 | The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges | 23505 | The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges |
| 23234 | an equation to solve for a specific variable. An equation is an | 23506 | an equation to solve for a specific variable. An equation is an |
| 23235 | expression of the form @cite{L = R}. For example, the command @kbd{a S x} | 23507 | expression of the form @expr{L = R}. For example, the command @kbd{a S x} |
| 23236 | will rearrange @cite{y = 3x + 6} to the form, @cite{x = y/3 - 2}. If the | 23508 | will rearrange @expr{y = 3x + 6} to the form, @expr{x = y/3 - 2}. If the |
| 23237 | input is not an equation, it is treated like an equation of the | 23509 | input is not an equation, it is treated like an equation of the |
| 23238 | form @cite{X = 0}. | 23510 | form @expr{X = 0}. |
| 23239 | 23511 | ||
| 23240 | This command also works for inequalities, as in @cite{y < 3x + 6}. | 23512 | This command also works for inequalities, as in @expr{y < 3x + 6}. |
| 23241 | Some inequalities cannot be solved where the analogous equation could | 23513 | Some inequalities cannot be solved where the analogous equation could |
| 23242 | be; for example, solving @c{$a < b \, c$} | 23514 | be; for example, solving |
| 23243 | @cite{a < b c} for @cite{b} is impossible | 23515 | @texline @tmath{a < b \, c} |
| 23244 | without knowing the sign of @cite{c}. In this case, @kbd{a S} will | 23516 | @infoline @expr{a < b c} |
| 23245 | produce the result @c{$b \mathbin{\hbox{\code{!=}}} a/c$} | 23517 | for @expr{b} is impossible |
| 23246 | @cite{b != a/c} (using the not-equal-to operator) | 23518 | without knowing the sign of @expr{c}. In this case, @kbd{a S} will |
| 23247 | to signify that the direction of the inequality is now unknown. The | 23519 | produce the result |
| 23248 | inequality @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 |
| 23251 | variables in a formula are in fact known. | 23523 | inequality is now unknown. The inequality |
| 23524 | @texline @tmath{a \le b \, c} | ||
| 23525 | @infoline @expr{a <= b c} | ||
| 23526 | is not even partially solved. @xref{Declarations}, for a way to tell | ||
| 23527 | Calc that the signs of the variables in a formula are in fact known. | ||
| 23252 | 23528 | ||
| 23253 | Two useful commands for working with the result of @kbd{a S} are | 23529 | Two 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} |
| 23255 | to @cite{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates | 23531 | to @expr{y/3 - 2}, and @kbd{s l} (@pxref{Let Command}) which evaluates |
| 23256 | another formula with @cite{x} set equal to @cite{y/3 - 2}. | 23532 | another 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 | |||
| 23293 | we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides | 23569 | we solve @samp{sqrt(y) = x} for @code{y}. Calc squares both sides |
| 23294 | to get @samp{y = x^2}. This is correct, except that it introduces | 23570 | to get @samp{y = x^2}. This is correct, except that it introduces |
| 23295 | some dubious solutions. Consider solving @samp{sqrt(y) = -3}: | 23571 | some dubious solutions. Consider solving @samp{sqrt(y) = -3}: |
| 23296 | Calc will report @cite{y = 9} as a valid solution, which is true | 23572 | Calc will report @expr{y = 9} as a valid solution, which is true |
| 23297 | in the mathematical sense of square-root, but false (there is no | 23573 | in the mathematical sense of square-root, but false (there is no |
| 23298 | solution) for the actual Calc positive-valued @code{sqrt}. This | 23574 | solution) for the actual Calc positive-valued @code{sqrt}. This |
| 23299 | happens for both @kbd{a S} and @kbd{H a S}. | 23575 | happens for both @kbd{a S} and @kbd{H a S}. |
| @@ -23337,7 +23613,7 @@ in that variable is not a positive integer, the regular | |||
| 23337 | With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression | 23613 | With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression |
| 23338 | on top of the stack as a function of the specified variable and solves | 23614 | on top of the stack as a function of the specified variable and solves |
| 23339 | to find the inverse function, written in terms of the same variable. | 23615 | to find the inverse function, written in terms of the same variable. |
| 23340 | For example, @kbd{I a S x} inverts @cite{2x + 6} to @cite{x/2 - 3}. | 23616 | For example, @kbd{I a S x} inverts @expr{2x + 6} to @expr{x/2 - 3}. |
| 23341 | You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a | 23617 | You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a |
| 23342 | fully general inverse, as described above. | 23618 | fully general inverse, as described above. |
| 23343 | 23619 | ||
| @@ -23361,12 +23637,12 @@ reported; @pxref{Declarations}.) | |||
| 23361 | Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver | 23637 | Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver |
| 23362 | symbolic solutions if the polynomial has symbolic coefficients. Also | 23638 | symbolic solutions if the polynomial has symbolic coefficients. Also |
| 23363 | note that Calc's solver is not able to get exact symbolic solutions | 23639 | note that Calc's solver is not able to get exact symbolic solutions |
| 23364 | to all polynomials. Polynomials containing powers up to @cite{x^4} | 23640 | to all polynomials. Polynomials containing powers up to @expr{x^4} |
| 23365 | can always be solved exactly; polynomials of higher degree sometimes | 23641 | can always be solved exactly; polynomials of higher degree sometimes |
| 23366 | can be: @cite{x^6 + x^3 + 1} is converted to @cite{(x^3)^2 + (x^3) + 1}, | 23642 | can be: @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1}, |
| 23367 | which can be solved for @cite{x^3} using the quadratic equation, and then | 23643 | which can be solved for @expr{x^3} using the quadratic equation, and then |
| 23368 | for @cite{x} by taking cube roots. But in many cases, like | 23644 | for @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 |
| 23370 | into a form it can solve. The @kbd{a P} command can still deliver a | 23646 | into a form it can solve. The @kbd{a P} command can still deliver a |
| 23371 | list of numerical roots, however, provided that symbolic mode (@kbd{m s}) | 23647 | list of numerical roots, however, provided that symbolic mode (@kbd{m s}) |
| 23372 | is not turned on. (If you work with symbolic mode on, recall that the | 23648 | is 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 | |||
| 23392 | have the same length as the variables vector, and the variables | 23668 | have the same length as the variables vector, and the variables |
| 23393 | will be listed in the same order there. Note that the solutions | 23669 | will be listed in the same order there. Note that the solutions |
| 23394 | are not always simplified as far as possible; the solution for | 23670 | are 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} |
| 23396 | command. | 23672 | command. |
| 23397 | 23673 | ||
| 23398 | Calc's algorithm works by trying to eliminate one variable at a | 23674 | Calc's algorithm works by trying to eliminate one variable at a |
| @@ -23453,23 +23729,23 @@ to satisfy the equations. @xref{Curve Fitting}. | |||
| 23453 | The @code{poly} function takes a polynomial and a variable as | 23729 | The @code{poly} function takes a polynomial and a variable as |
| 23454 | arguments, and returns a vector of polynomial coefficients (constant | 23730 | arguments, and returns a vector of polynomial coefficients (constant |
| 23455 | coefficient first). For example, @samp{poly(x^3 + 2 x, x)} returns | 23731 | coefficient 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}, |
| 23457 | the call to @code{poly} is left in symbolic form. If the input does | 23733 | the call to @code{poly} is left in symbolic form. If the input does |
| 23458 | not involve the variable @cite{x}, the input is returned in a list | 23734 | not involve the variable @expr{x}, the input is returned in a list |
| 23459 | of length one, representing a polynomial with only a constant | 23735 | of length one, representing a polynomial with only a constant |
| 23460 | coefficient. The call @samp{poly(x, x)} returns the vector @cite{[0, 1]}. | 23736 | coefficient. The call @samp{poly(x, x)} returns the vector @expr{[0, 1]}. |
| 23461 | The last element of the returned vector is guaranteed to be nonzero; | 23737 | The last element of the returned vector is guaranteed to be nonzero; |
| 23462 | note that @samp{poly(0, x)} returns the empty vector @cite{[]}. | 23738 | note that @samp{poly(0, x)} returns the empty vector @expr{[]}. |
| 23463 | Note also that @cite{x} may actually be any formula; for example, | 23739 | Note 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 |
| 23468 | To get the @cite{x^k} coefficient of polynomial @cite{p}, use | 23744 | To 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}, |
| 23470 | use @samp{vlen(poly(p, x)) - 1}. For example, @samp{poly((x+1)^4, x)} | 23746 | use @samp{vlen(poly(p, x)) - 1}. For example, @samp{poly((x+1)^4, x)} |
| 23471 | returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)} | 23747 | returns @samp{[1, 4, 6, 4, 1]}, so @samp{poly((x+1)^4, x)_(2+1)} |
| 23472 | gives the @cite{x^2} coefficient of this polynomial, 6. | 23748 | gives 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 | |||
| 23494 | is considered trivial. | 23770 | is considered trivial. |
| 23495 | 23771 | ||
| 23496 | For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]}, | 23772 | For example, @samp{gpoly((x-2)^2, x)} returns @samp{[x, [4, -4, 1], 1]}, |
| 23497 | since the expanded form of this polynomial is @cite{4 - 4 x + x^2}. | 23773 | since the expanded form of this polynomial is @expr{4 - 4 x + x^2}. |
| 23498 | 23774 | ||
| 23499 | The term @var{x} may itself be a polynomial in @var{var}. This is | 23775 | The term @var{x} may itself be a polynomial in @var{var}. This is |
| 23500 | done to reduce the size of the @var{c} vector. For example, | 23776 | done 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]}, |
| 23502 | since a quadratic polynomial in @cite{x^2} is easier to solve than | 23778 | since a quadratic polynomial in @expr{x^2} is easier to solve than |
| 23503 | a quartic polynomial in @cite{x}. | 23779 | a quartic polynomial in @expr{x}. |
| 23504 | 23780 | ||
| 23505 | A few more examples of the kinds of polynomials @code{gpoly} can | 23781 | A few more examples of the kinds of polynomials @code{gpoly} can |
| 23506 | discover: | 23782 | discover: |
| @@ -23517,7 +23793,7 @@ x^(2a) + 2 x^a + 5 [x^a, [5, 2, 1], 1] | |||
| 23517 | 23793 | ||
| 23518 | The @code{poly} and @code{gpoly} functions accept a third integer argument | 23794 | The @code{poly} and @code{gpoly} functions accept a third integer argument |
| 23519 | which specifies the largest degree of polynomial that is acceptable. | 23795 | which specifies the largest degree of polynomial that is acceptable. |
| 23520 | If this is @cite{n}, then only @var{c} vectors of length @cite{n+1} | 23796 | If this is @expr{n}, then only @var{c} vectors of length @expr{n+1} |
| 23521 | or less will be returned. Otherwise, the @code{poly} or @code{gpoly} | 23797 | or less will be returned. Otherwise, the @code{poly} or @code{gpoly} |
| 23522 | call will remain in symbolic form. For example, the equation solver | 23798 | call will remain in symbolic form. For example, the equation solver |
| 23523 | can handle quartics and smaller polynomials, so it calls | 23799 | can handle quartics and smaller polynomials, so it calls |
| @@ -23549,7 +23825,7 @@ The @code{plead} function finds the leading term of a polynomial. | |||
| 23549 | Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))}, | 23825 | Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))}, |
| 23550 | though again more efficient. In particular, @samp{plead((2x+1)^10, x)} | 23826 | though again more efficient. In particular, @samp{plead((2x+1)^10, x)} |
| 23551 | returns 1024 without expanding out the list of coefficients. The | 23827 | returns 1024 without expanding out the list of coefficients. The |
| 23552 | value of @code{plead(p,x)} will be zero only if @cite{p = 0}. | 23828 | value 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.) | |||
| 23618 | The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a | 23894 | The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a |
| 23619 | numerical solution (or @dfn{root}) of an equation. (This command treats | 23895 | numerical solution (or @dfn{root}) of an equation. (This command treats |
| 23620 | inequalities the same as equations. If the input is any other kind | 23896 | inequalities the same as equations. If the input is any other kind |
| 23621 | of formula, it is interpreted as an equation of the form @cite{X = 0}.) | 23897 | of formula, it is interpreted as an equation of the form @expr{X = 0}.) |
| 23622 | 23898 | ||
| 23623 | The @kbd{a R} command requires an initial guess on the top of the | 23899 | The @kbd{a R} command requires an initial guess on the top of the |
| 23624 | stack, and a formula in the second-to-top position. It prompts for a | 23900 | stack, 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 | |||
| 23704 | with the minimum value itself. | 23980 | with the minimum value itself. |
| 23705 | 23981 | ||
| 23706 | Note that this command looks for a @emph{local} minimum. Many functions | 23982 | Note that this command looks for a @emph{local} minimum. Many functions |
| 23707 | have more than one minimum; some, like @c{$x \sin x$} | 23983 | have more than one minimum; some, like |
| 23708 | @cite{x sin(x)}, have infinitely | 23984 | @texline @tmath{x \sin x}, |
| 23709 | many. In fact, there is no easy way to define the ``global'' minimum | 23985 | @infoline @expr{x sin(x)}, |
| 23710 | of @c{$x \sin x$} | 23986 | have 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)} | ||
| 23990 | but Calc can still locate any particular local minimum | ||
| 23712 | for you. Calc basically goes downhill from the initial guess until it | 23991 | for you. Calc basically goes downhill from the initial guess until it |
| 23713 | finds a point at which the function's value is greater both to the left | 23992 | finds a point at which the function's value is greater both to the left |
| 23714 | and to the right. Calc does not use derivatives when minimizing a function. | 23993 | and to the right. Calc does not use derivatives when minimizing a function. |
| 23715 | 23994 | ||
| 23716 | If your initial guess is an interval and it looks like the minimum | 23995 | If your initial guess is an interval and it looks like the minimum |
| 23717 | occurs at one or the other endpoint of the interval, Calc will return | 23996 | occurs at one or the other endpoint of the interval, Calc will return |
| 23718 | that endpoint only if that endpoint is closed; thus, minimizing @cite{17 x} | 23997 | that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x} |
| 23719 | over @cite{[2..3]} will return @cite{[2, 38]}, but minimizing over | 23998 | over @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 |
| 23721 | use closed intervals to find literally the minimum value in that | 24000 | use closed intervals to find literally the minimum value in that |
| 23722 | range of @cite{x}, or open intervals to find the local minimum, if | 24001 | range of @expr{x}, or open intervals to find the local minimum, if |
| 23723 | any, that happens to lie in that range. | 24002 | any, that happens to lie in that range. |
| 23724 | 24003 | ||
| 23725 | Most functions are smooth and flat near their minimum values. Because | 24004 | Most 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 |
| 23783 | The @kbd{a F} command fits a set of data to a @dfn{model formula}, | 24062 | The @kbd{a F} command fits a set of data to a @dfn{model formula}, |
| 23784 | such as @cite{y = m x + b} where @cite{m} and @cite{b} are parameters | 24063 | such as @expr{y = m x + b} where @expr{m} and @expr{b} are parameters |
| 23785 | to be determined. For a typical set of measured data there will be | 24064 | to be determined. For a typical set of measured data there will be |
| 23786 | no single @cite{m} and @cite{b} that exactly fit the data; in this | 24065 | no single @expr{m} and @expr{b} that exactly fit the data; in this |
| 23787 | case, Calc chooses values of the parameters that provide the closest | 24066 | case, Calc chooses values of the parameters that provide the closest |
| 23788 | possible fit. | 24067 | possible 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 |
| 23808 | The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts | 24087 | The @kbd{a F} (@code{calc-curve-fit}) [@code{fit}] command attempts |
| 23809 | to fit a set of data (@cite{x} and @cite{y} vectors of numbers) to a | 24088 | to fit a set of data (@expr{x} and @expr{y} vectors of numbers) to a |
| 23810 | straight line, polynomial, or other function of @cite{x}. For the | 24089 | straight line, polynomial, or other function of @expr{x}. For the |
| 23811 | moment we will consider only the case of fitting to a line, and we | 24090 | moment we will consider only the case of fitting to a line, and we |
| 23812 | will ignore the issue of whether or not the model was in fact a good | 24091 | will ignore the issue of whether or not the model was in fact a good |
| 23813 | fit for the data. | 24092 | fit for the data. |
| 23814 | 24093 | ||
| 23815 | In a standard linear least-squares fit, we have a set of @cite{(x,y)} | 24094 | In a standard linear least-squares fit, we have a set of @expr{(x,y)} |
| 23816 | data points that we wish to fit to the model @cite{y = m x + b} | 24095 | data points that we wish to fit to the model @expr{y = m x + b} |
| 23817 | by adjusting the parameters @cite{m} and @cite{b} to make the @cite{y} | 24096 | by adjusting the parameters @expr{m} and @expr{b} to make the @expr{y} |
| 23818 | values calculated from the formula be as close as possible to the actual | 24097 | values 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 |
| 23820 | instead, say, @cite{y = a x^3 + b x^2 + c x + d}. In a multilinear fit, | 24099 | instead, say, @expr{y = a x^3 + b x^2 + c x + d}. In a multilinear fit, |
| 23821 | we have data points of the form @cite{(x_1,x_2,x_3,y)} and our model is | 24100 | we 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 | ||
| 23824 | In the model formula, variables like @cite{x} and @cite{x_2} are called | 24103 | In the model formula, variables like @expr{x} and @expr{x_2} are called |
| 23825 | the @dfn{independent variables}, and @cite{y} is the @dfn{dependent | 24104 | the @dfn{independent variables}, and @expr{y} is the @dfn{dependent |
| 23826 | variable}. Variables like @cite{m}, @cite{a}, and @cite{b} are called | 24105 | variable}. Variables like @expr{m}, @expr{a}, and @expr{b} are called |
| 23827 | the @dfn{parameters} of the model. | 24106 | the @dfn{parameters} of the model. |
| 23828 | 24107 | ||
| 23829 | The @kbd{a F} command takes the data set to be fitted from the stack. | 24108 | The @kbd{a F} command takes the data set to be fitted from the stack. |
| 23830 | By default, it expects the data in the form of a matrix. For example, | 24109 | By default, it expects the data in the form of a matrix. For example, |
| 23831 | for a linear or polynomial fit, this would be a @c{$2\times N$} | 24110 | for a linear or polynomial fit, this would be a |
| 23832 | @asis{2xN} matrix where | 24111 | @texline @tmath{2\times N} |
| 23833 | the first row is a list of @cite{x} values and the second row has the | 24112 | @infoline 2xN |
| 23834 | corresponding @cite{y} values. For the multilinear fit shown above, | 24113 | matrix where the first row is a list of @expr{x} values and the second |
| 23835 | the matrix would have four rows (@cite{x_1}, @cite{x_2}, @cite{x_3}, and | 24114 | row has the corresponding @expr{y} values. For the multilinear fit |
| 23836 | @cite{y}, respectively). | 24115 | shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2}, |
| 23837 | 24116 | @expr{x_3}, and @expr{y}, respectively). | |
| 23838 | If you happen to have an @c{$N\times2$} | 24117 | |
| 23839 | @asis{Nx2} matrix instead of a @c{$2\times N$} | 24118 | If you happen to have an |
| 23840 | @asis{2xN} matrix, | 24119 | @texline @tmath{N\times2} |
| 23841 | just press @kbd{v t} first to transpose the matrix. | 24120 | @infoline Nx2 |
| 24121 | matrix instead of a | ||
| 24122 | @texline @tmath{2\times N} | ||
| 24123 | @infoline 2xN | ||
| 24124 | matrix, just press @kbd{v t} first to transpose the matrix. | ||
| 23842 | 24125 | ||
| 23843 | After you type @kbd{a F}, Calc prompts you to select a model. For a | 24126 | After you type @kbd{a F}, Calc prompts you to select a model. For a |
| 23844 | linear fit, press the digit @kbd{1}. | 24127 | linear fit, press the digit @kbd{1}. |
| 23845 | 24128 | ||
| 23846 | Calc then prompts for you to name the variables. By default it chooses | 24129 | Calc then prompts for you to name the variables. By default it chooses |
| 23847 | high letters like @cite{x} and @cite{y} for independent variables and | 24130 | high letters like @expr{x} and @expr{y} for independent variables and |
| 23848 | low letters like @cite{a} and @cite{b} for parameters. (The dependent | 24131 | low letters like @expr{a} and @expr{b} for parameters. (The dependent |
| 23849 | variable doesn't need a name.) The two kinds of variables are separated | 24132 | variable doesn't need a name.) The two kinds of variables are separated |
| 23850 | by a semicolon. Since you generally care more about the names of the | 24133 | by a semicolon. Since you generally care more about the names of the |
| 23851 | independent variables than of the parameters, Calc also allows you to | 24134 | independent variables than of the parameters, Calc also allows you to |
| @@ -23874,17 +24157,17 @@ $$ | |||
| 23874 | @noindent | 24157 | @noindent |
| 23875 | is on the stack and we wish to do a simple linear fit. Type | 24158 | is 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 |
| 23877 | the default names. The result will be the formula @cite{3 + 2 x} | 24160 | the default names. The result will be the formula @expr{3 + 2 x} |
| 23878 | on the stack. Calc has created the model expression @kbd{a + b x}, | 24161 | on the stack. Calc has created the model expression @kbd{a + b x}, |
| 23879 | then found the optimal values of @cite{a} and @cite{b} to fit the | 24162 | then found the optimal values of @expr{a} and @expr{b} to fit the |
| 23880 | data. (In this case, it was able to find an exact fit.) Calc then | 24163 | data. (In this case, it was able to find an exact fit.) Calc then |
| 23881 | substituted those values for @cite{a} and @cite{b} in the model | 24164 | substituted those values for @expr{a} and @expr{b} in the model |
| 23882 | formula. | 24165 | formula. |
| 23883 | 24166 | ||
| 23884 | The @kbd{a F} command puts two entries in the trail. One is, as | 24167 | The @kbd{a F} command puts two entries in the trail. One is, as |
| 23885 | always, a copy of the result that went to the stack; the other is | 24168 | always, a copy of the result that went to the stack; the other is |
| 23886 | a vector of the actual parameter values, written as equations: | 24169 | a 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 |
| 23888 | than pick them out of the formula. (You can type @kbd{t y} | 24171 | than pick them out of the formula. (You can type @kbd{t y} |
| 23889 | to move this vector to the stack; see @ref{Trail Commands}. | 24172 | to 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 |
| 23933 | which is clearly zero if @cite{a + b x} exactly fits all data points, | 24216 | which is clearly zero if @expr{a + b x} exactly fits all data points, |
| 23934 | and increases as various @cite{a + b x_i} values fail to match the | 24217 | and increases as various @expr{a + b x_i} values fail to match the |
| 23935 | corresponding @cite{y_i} values. There are several reasons why the | 24218 | corresponding @expr{y_i} values. There are several reasons why the |
| 23936 | summand is squared, one of them being to ensure that @c{$\chi^2 \ge 0$} | 24219 | summand is squared, one of them being to ensure that |
| 23937 | @cite{chi^2 >= 0}. | 24220 | @texline @tmath{\chi^2 \ge 0}. |
| 23938 | Least-squares fitting simply chooses the values of @cite{a} and @cite{b} | 24221 | @infoline @expr{chi^2 >= 0}. |
| 23939 | for which the error @c{$\chi^2$} | 24222 | Least-squares fitting simply chooses the values of @expr{a} and @expr{b} |
| 23940 | @cite{chi^2} is as small as possible. | 24223 | for which the error |
| 24224 | @texline @tmath{\chi^2} | ||
| 24225 | @infoline @expr{chi^2} | ||
| 24226 | is as small as possible. | ||
| 23941 | 24227 | ||
| 23942 | Other kinds of models do the same thing but with a different model | 24228 | Other kinds of models do the same thing but with a different model |
| 23943 | formula in place of @cite{a + b x_i}. | 24229 | formula 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 | |||
| 23953 | is always one independent variable and one dependent variable. | 24239 | is always one independent variable and one dependent variable. |
| 23954 | 24240 | ||
| 23955 | A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two | 24241 | A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two |
| 23956 | items from the stack, an @var{n}-row matrix of @cite{x} values, and a | 24242 | items from the stack, an @var{n}-row matrix of @expr{x} values, and a |
| 23957 | vector of @cite{y} values. If there is only one independent variable, | 24243 | vector of @expr{y} values. If there is only one independent variable, |
| 23958 | the @cite{x} values can be either a one-row matrix or a plain vector, | 24244 | the @expr{x} values can be either a one-row matrix or a plain vector, |
| 23959 | in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix. | 24245 | in 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 | ||
| 23975 | Note that since the constant and linear terms are enough to fit the | 24261 | Note that since the constant and linear terms are enough to fit the |
| 23976 | data exactly, it's no surprise that Calc chose a tiny contribution | 24262 | data exactly, it's no surprise that Calc chose a tiny contribution |
| 23977 | for @cite{x^2}. (The fact that it's not exactly zero is due only | 24263 | for @expr{x^2}. (The fact that it's not exactly zero is due only |
| 23978 | to roundoff error. Since our data are exact integers, we could get | 24264 | to roundoff error. Since our data are exact integers, we could get |
| 23979 | an exact answer by typing @kbd{m f} first to get fraction mode. | 24265 | an exact answer by typing @kbd{m f} first to get fraction mode. |
| 23980 | Then the @cite{x^2} term would vanish altogether. Usually, though, | 24266 | Then the @expr{x^2} term would vanish altogether. Usually, though, |
| 23981 | the data being fitted will be approximate floats so fraction mode | 24267 | the data being fitted will be approximate floats so fraction mode |
| 23982 | won't help.) | 24268 | won't help.) |
| 23983 | 24269 | ||
| 23984 | Doing the @kbd{a F 2} fit on the data set with 14 instead of 13 | 24270 | Doing the @kbd{a F 2} fit on the data set with 14 instead of 13 |
| 23985 | gives a much larger @cite{x^2} contribution, as Calc bends the | 24271 | gives a much larger @expr{x^2} contribution, as Calc bends the |
| 23986 | line slightly to improve the fit. | 24272 | line 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 | ||
| 24002 | The actual coefficients we get with a precision of 12, like | 24288 | The 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. |
| 24004 | It is a good idea to increase the working precision to several | 24290 | It is a good idea to increase the working precision to several |
| 24005 | digits beyond what you need when you do a fitting operation. | 24291 | digits beyond what you need when you do a fitting operation. |
| 24006 | Or, if your data are exact, use fraction mode to get exact | 24292 | Or, 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 | ||
| 24025 | Another generalization of the linear model is to assume the | 24311 | Another 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 |
| 24028 | selected by the @kbd{1} digit key. (Calc decides whether the fit | 24314 | selected by the @kbd{1} digit key. (Calc decides whether the fit |
| 24029 | is linear or multilinear by counting the rows in the data matrix.) | 24315 | is 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 |
| 24042 | the command @kbd{a F 1 @key{RET}} will call the first row @cite{x} and the | 24328 | the command @kbd{a F 1 @key{RET}} will call the first row @expr{x} and the |
| 24043 | second row @cite{y}, and will fit the values in the third row to the | 24329 | second row @expr{y}, and will fit the values in the third row to the |
| 24044 | model @cite{a + b x + c y}. | 24330 | model @expr{a + b x + c y}. |
| 24045 | 24331 | ||
| 24046 | @example | 24332 | @example |
| 24047 | 8. + 3. x + 0.5 y | 24333 | 8. + 3. x + 0.5 y |
| @@ -24056,20 +24342,20 @@ Calc can do multilinear fits with any number of independent variables | |||
| 24056 | 24342 | ||
| 24057 | Yet another variation is @dfn{homogeneous} linear models, in which | 24343 | Yet another variation is @dfn{homogeneous} linear models, in which |
| 24058 | the constant term is known to be zero. In the linear case, this | 24344 | the constant term is known to be zero. In the linear case, this |
| 24059 | means the model formula is simply @cite{a x}; in the multilinear | 24345 | means the model formula is simply @expr{a x}; in the multilinear |
| 24060 | case, the model might be @cite{a x + b y + c z}; and in the polynomial | 24346 | case, the model might be @expr{a x + b y + c z}; and in the polynomial |
| 24061 | case, the model could be @cite{a x + b x^2 + c x^3}. You can get | 24347 | case, the model could be @expr{a x + b x^2 + c x^3}. You can get |
| 24062 | a homogeneous linear or multilinear model by pressing the letter | 24348 | a 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 | ||
| 24065 | It is certainly possible to have other constrained linear models, | 24351 | It is certainly possible to have other constrained linear models, |
| 24066 | like @cite{2.3 + a x} or @cite{a - 4 x}. While there is no single | 24352 | like @expr{2.3 + a x} or @expr{a - 4 x}. While there is no single |
| 24067 | key to select models like these, a later section shows how to enter | 24353 | key to select models like these, a later section shows how to enter |
| 24068 | any desired model by hand. In the first case, for example, you | 24354 | any desired model by hand. In the first case, for example, you |
| 24069 | would enter @kbd{a F ' 2.3 + a x}. | 24355 | would enter @kbd{a F ' 2.3 + a x}. |
| 24070 | 24356 | ||
| 24071 | Another class of models that will work but must be entered by hand | 24357 | Another class of models that will work but must be entered by hand |
| 24072 | are multinomial fits, e.g., @cite{a + b x + c y + d x^2 + e y^2 + f x y}. | 24358 | are 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 | |||
| 24096 | or all be plain numbers. Error forms can go anywhere but generally | 24382 | or all be plain numbers. Error forms can go anywhere but generally |
| 24097 | go on the numbers in the last row of the data matrix. If the last | 24383 | go on the numbers in the last row of the data matrix. If the last |
| 24098 | row contains error forms | 24384 | row 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} | 24387 | then the |
| 24388 | @texline @tmath{\chi^2} | ||
| 24389 | @infoline @expr{chi^2} | ||
| 24102 | statistic is now, | 24390 | statistic is now, |
| 24103 | 24391 | ||
| 24104 | @ifinfo | 24392 | @ifinfo |
| @@ -24119,24 +24407,29 @@ the fitting operation. | |||
| 24119 | 24407 | ||
| 24120 | If there are error forms on other rows of the data matrix, all the | 24408 | If there are error forms on other rows of the data matrix, all the |
| 24121 | errors for a given data point are combined; the square root of the | 24409 | errors for a given data point are combined; the square root of the |
| 24122 | sum of the squares of the errors forms the @c{$\sigma_i$} | 24410 | sum of the squares of the errors forms the |
| 24123 | @cite{sigma_i} used for | 24411 | @texline @tmath{\sigma_i} |
| 24124 | the data point. | 24412 | @infoline @expr{sigma_i} |
| 24413 | used for the data point. | ||
| 24125 | 24414 | ||
| 24126 | Both @kbd{a F} and @kbd{H a F} can accept error forms in the input | 24415 | Both @kbd{a F} and @kbd{H a F} can accept error forms in the input |
| 24127 | matrix, although if you are concerned about error analysis you will | 24416 | matrix, although if you are concerned about error analysis you will |
| 24128 | probably use @kbd{H a F} so that the output also contains error | 24417 | probably use @kbd{H a F} so that the output also contains error |
| 24129 | estimates. | 24418 | estimates. |
| 24130 | 24419 | ||
| 24131 | If the input contains error forms but all the @c{$\sigma_i$} | 24420 | If the input contains error forms but all the |
| 24132 | @cite{sigma_i} values are | 24421 | @texline @tmath{\sigma_i} |
| 24133 | the same, it is easy to see that the resulting fitted model will be | 24422 | @infoline @expr{sigma_i} |
| 24134 | the same as if the input did not have error forms at all (@c{$\chi^2$} | 24423 | values are the same, it is easy to see that the resulting fitted model |
| 24135 | @cite{chi^2} | 24424 | will be the same as if the input did not have error forms at all |
| 24136 | is 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} |
| 24138 | where it has a minimum). But there @emph{will} be a difference | 24427 | is simply scaled uniformly by |
| 24139 | in the estimated errors of the coefficients reported by @kbd{H a F}. | 24428 | @texline @tmath{1 / \sigma^2}, |
| 24429 | @infoline @expr{1 / sigma^2}, | ||
| 24430 | which doesn't affect where it has a minimum). But there @emph{will} be | ||
| 24431 | a difference in the estimated errors of the coefficients reported by | ||
| 24432 | @kbd{H a F}. | ||
| 24140 | 24433 | ||
| 24141 | Consult any text on statistical modeling of data for a discussion | 24434 | Consult any text on statistical modeling of data for a discussion |
| 24142 | of where these error estimates come from and how they should be | 24435 | of where these error estimates come from and how they should be |
| @@ -24161,54 +24454,66 @@ produced. | |||
| 24161 | A vector of ``raw'' parameter values for the model. These are the | 24454 | A vector of ``raw'' parameter values for the model. These are the |
| 24162 | polynomial coefficients or other parameters as plain numbers, in the | 24455 | polynomial coefficients or other parameters as plain numbers, in the |
| 24163 | same order as the parameters appeared in the final prompt of the | 24456 | same 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 |
| 24165 | will have length @cite{M = d+1} with the constant term first. | 24458 | will have length @expr{M = d+1} with the constant term first. |
| 24166 | 24459 | ||
| 24167 | @item | 24460 | @item |
| 24168 | The covariance matrix @cite{C} computed from the fit. This is | 24461 | The covariance matrix @expr{C} computed from the fit. This is |
| 24169 | an @var{m}x@var{m} symmetric matrix; the diagonal elements | 24462 | an @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. | 24465 | are the variances |
| 24173 | The 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} |
| 24175 | correlation between pairs of parameters. (A related set of | 24468 | of the parameters. The other elements are covariances |
| 24176 | numbers, 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} |
| 24178 | are defined as @c{$\sigma_{ij}^2 / \sigma_i \, \sigma_j$} | 24471 | that describe the correlation between pairs of parameters. (A related |
| 24179 | @cite{sigma_i_j^2 / sigma_i sigma_j}.) | 24472 | set of numbers, the @dfn{linear correlation coefficients} |
| 24473 | @texline @tmath{r_{ij}}, | ||
| 24474 | @infoline @expr{r_i_j}, | ||
| 24475 | are defined as | ||
| 24476 | @texline @tmath{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.) | ||
| 24477 | @infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.) | ||
| 24180 | 24478 | ||
| 24181 | @item | 24479 | @item |
| 24182 | A vector of @cite{M} ``parameter filter'' functions whose | 24480 | A vector of @expr{M} ``parameter filter'' functions whose |
| 24183 | meanings are described below. If no filters are necessary this | 24481 | meanings are described below. If no filters are necessary this |
| 24184 | will instead be an empty vector; this is always the case for the | 24482 | will instead be an empty vector; this is always the case for the |
| 24185 | polynomial and multilinear fits described so far. | 24483 | polynomial and multilinear fits described so far. |
| 24186 | 24484 | ||
| 24187 | @item | 24485 | @item |
| 24188 | The value of @c{$\chi^2$} | 24486 | The value of |
| 24189 | @cite{chi^2} for the fit, calculated by the formulas | 24487 | @texline @tmath{\chi^2} |
| 24190 | shown above. This gives a measure of the quality of the fit; | 24488 | @infoline @expr{chi^2} |
| 24191 | statisticians consider @c{$\chi^2 \approx N - M$} | 24489 | for the fit, calculated by the formulas shown above. This gives a |
| 24192 | @cite{chi^2 = N - M} to indicate a moderately good fit | 24490 | measure 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} |
| 24194 | is the number of parameters). | 24492 | @infoline @expr{chi^2 = N - M} |
| 24493 | to indicate a moderately good fit (where again @expr{N} is the number of | ||
| 24494 | data points and @expr{M} is the number of parameters). | ||
| 24195 | 24495 | ||
| 24196 | @item | 24496 | @item |
| 24197 | A measure of goodness of fit expressed as a probability @cite{Q}. | 24497 | A measure of goodness of fit expressed as a probability @expr{Q}. |
| 24198 | This is computed from the @code{utpc} probability distribution | 24498 | This is computed from the @code{utpc} probability distribution |
| 24199 | function using @c{$\chi^2$} | 24499 | function using |
| 24200 | @cite{chi^2} with @cite{N - M} degrees of freedom. A | 24500 | @texline @tmath{\chi^2} |
| 24501 | @infoline @expr{chi^2} | ||
| 24502 | with @expr{N - M} degrees of freedom. A | ||
| 24201 | value of 0.5 implies a good fit; some texts recommend that often | 24503 | value 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 |
| 24203 | particular, @c{$\chi^2$} | 24505 | particular, |
| 24204 | @cite{chi^2} statistics assume the errors in your inputs | 24506 | @texline @tmath{\chi^2} |
| 24507 | @infoline @expr{chi^2} | ||
| 24508 | statistics assume the errors in your inputs | ||
| 24205 | follow a normal (Gaussian) distribution; if they don't, you may | 24509 | follow a normal (Gaussian) distribution; if they don't, you may |
| 24206 | have to accept smaller values of @cite{Q}. | 24510 | have to accept smaller values of @expr{Q}. |
| 24207 | 24511 | ||
| 24208 | The @cite{Q} value is computed only if the input included error | 24512 | The @expr{Q} value is computed only if the input included error |
| 24209 | estimates. Otherwise, Calc will report the symbol @code{nan} | 24513 | estimates. Otherwise, Calc will report the symbol @code{nan} |
| 24210 | for @cite{Q}. The reason is that in this case the @c{$\chi^2$} | 24514 | for @expr{Q}. The reason is that in this case the |
| 24211 | @cite{chi^2} | 24515 | @texline @tmath{\chi^2} |
| 24516 | @infoline @expr{chi^2} | ||
| 24212 | value has effectively been used to estimate the original errors | 24517 | value has effectively been used to estimate the original errors |
| 24213 | in the input, and thus there is no redundant information left | 24518 | in the input, and thus there is no redundant information left |
| 24214 | over to use for a confidence test. | 24519 | over to use for a confidence test. |
| @@ -24248,8 +24553,9 @@ Power law. @i{a x^b y^c}. | |||
| 24248 | @item q | 24553 | @item q |
| 24249 | Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}. | 24554 | Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}. |
| 24250 | @item g | 24555 | @item g |
| 24251 | Gaussian. @c{${a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)$} | 24556 | Gaussian. |
| 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 | ||
| 24255 | All of these models are used in the usual way; just press the appropriate | 24561 | All 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 | ||
| 24261 | All models except Gaussian and polynomials can generalize as shown to any | 24567 | All models except Gaussian and polynomials can generalize as shown to any |
| 24262 | number of independent variables. Also, all the built-in models have an | 24568 | number of independent variables. Also, all the built-in models have an |
| 24263 | additive or multiplicative parameter shown as @cite{a} in the above table | 24569 | additive or multiplicative parameter shown as @expr{a} in the above table |
| 24264 | which can be replaced by zero or one, as appropriate, by typing @kbd{h} | 24570 | which can be replaced by zero or one, as appropriate, by typing @kbd{h} |
| 24265 | before the model key. | 24571 | before the model key. |
| 24266 | 24572 | ||
| 24267 | Note that many of these models are essentially equivalent, but express | 24573 | Note that many of these models are essentially equivalent, but express |
| 24268 | the parameters slightly differently. For example, @cite{a b^x} and | 24574 | the parameters slightly differently. For example, @expr{a b^x} and |
| 24269 | the other two exponential models are all algebraic rearrangements of | 24575 | the other two exponential models are all algebraic rearrangements of |
| 24270 | each other. Also, the ``quadratic'' model is just a degree-2 polynomial | 24576 | each other. Also, the ``quadratic'' model is just a degree-2 polynomial |
| 24271 | with the parameters expressed differently. Use whichever form best | 24577 | with the parameters expressed differently. Use whichever form best |
| @@ -24275,8 +24581,8 @@ The HP-28/48 calculators support four different models for curve | |||
| 24275 | fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}. | 24581 | fitting, called @code{LIN}, @code{LOG}, @code{EXP}, and @code{PWR}. |
| 24276 | These correspond to Calc models @samp{a + b x}, @samp{a + b ln(x)}, | 24582 | These 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{'} | |||
| 24287 | formula, such as @kbd{m x - b}, as the model. (Not all models | 24593 | formula, such as @kbd{m x - b}, as the model. (Not all models |
| 24288 | will work, though---see the next section for details.) | 24594 | will work, though---see the next section for details.) |
| 24289 | 24595 | ||
| 24290 | The model can also be an equation like @cite{y = m x + b}. | 24596 | The model can also be an equation like @expr{y = m x + b}. |
| 24291 | In this case, Calc thinks of all the rows of the data matrix on | 24597 | In this case, Calc thinks of all the rows of the data matrix on |
| 24292 | equal terms; this model effectively has two parameters | 24598 | equal 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} |
| 24294 | and @cite{y}), with no ``dependent'' variables. Model equations | 24600 | and @expr{y}), with no ``dependent'' variables. Model equations |
| 24295 | do not need to take this @cite{y =} form. For example, the | 24601 | do not need to take this @expr{y =} form. For example, the |
| 24296 | implicit line equation @cite{a x + b y = 1} works fine as a | 24602 | implicit line equation @expr{a x + b y = 1} works fine as a |
| 24297 | model. | 24603 | model. |
| 24298 | 24604 | ||
| 24299 | When you enter a model, Calc makes an alphabetical list of all | 24605 | When you enter a model, Calc makes an alphabetical list of all |
| @@ -24303,12 +24609,12 @@ default parameters, independent variables, and dependent variable | |||
| 24303 | Calc assumes the dependent variable does not appear in the formula | 24609 | Calc assumes the dependent variable does not appear in the formula |
| 24304 | and thus does not need a name. | 24610 | and thus does not need a name. |
| 24305 | 24611 | ||
| 24306 | For example, if the model formula has the variables @cite{a,mu,sigma,t,x}, | 24612 | For example, if the model formula has the variables @expr{a,mu,sigma,t,x}, |
| 24307 | and the data matrix has three rows (meaning two independent variables), | 24613 | and the data matrix has three rows (meaning two independent variables), |
| 24308 | Calc will use @cite{a,mu,sigma} as the default parameters, and the | 24614 | Calc will use @expr{a,mu,sigma} as the default parameters, and the |
| 24309 | data rows will be named @cite{t} and @cite{x}, respectively. If you | 24615 | data rows will be named @expr{t} and @expr{x}, respectively. If you |
| 24310 | enter an equation instead of a plain formula, Calc will use @cite{a,mu} | 24616 | enter an equation instead of a plain formula, Calc will use @expr{a,mu} |
| 24311 | as the parameters, and @cite{sigma,t,x} as the three independent | 24617 | as the parameters, and @expr{sigma,t,x} as the three independent |
| 24312 | variables. | 24618 | variables. |
| 24313 | 24619 | ||
| 24314 | You can, of course, override these choices by entering something | 24620 | You can, of course, override these choices by entering something |
| @@ -24332,11 +24638,11 @@ choose which variables in the formula are independent by default and | |||
| 24332 | which are parameters. | 24638 | which are parameters. |
| 24333 | 24639 | ||
| 24334 | Models taken from the stack can also be expressed as vectors of | 24640 | Models taken from the stack can also be expressed as vectors of |
| 24335 | two or three elements, @cite{[@var{model}, @var{vars}]} or | 24641 | two 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} |
| 24337 | and @var{params} may be either a variable or a vector of variables. | 24643 | and @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 |
| 24339 | those listed as @var{vars} are parameters.)@refill | 24645 | those listed as @var{vars} are parameters.) |
| 24340 | 24646 | ||
| 24341 | When you enter a model manually with @kbd{'}, Calc puts a 3-vector | 24647 | When you enter a model manually with @kbd{'}, Calc puts a 3-vector |
| 24342 | describing the model in the trail so you can get it back if you wish. | 24648 | describing 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 | |||
| 24364 | returns results in the range from @i{-90} to 90 degrees (or the | 24670 | returns results in the range from @i{-90} to 90 degrees (or the |
| 24365 | equivalent range in radians). Suppose you had data that you | 24671 | equivalent range in radians). Suppose you had data that you |
| 24366 | believed to represent roughly three oscillations of a sine wave, | 24672 | believed to represent roughly three oscillations of a sine wave, |
| 24367 | so that the argument of the sine might go from zero to @c{$3\times360$} | 24673 | so 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} | ||
| 24676 | degrees. | ||
| 24369 | The above model would appear to be a good way to determine the | 24677 | The above model would appear to be a good way to determine the |
| 24370 | true frequency and phase of the sine wave, but in practice it | 24678 | true frequency and phase of the sine wave, but in practice it |
| 24371 | would fail utterly. The righthand side of the actual model | 24679 | would 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 |
| 24373 | the lefthand side will bounce back and forth between @i{-90} and 90. | 24681 | the lefthand side will bounce back and forth between @i{-90} and 90. |
| 24374 | No values of @cite{a} and @cite{b} can make the two sides match, | 24682 | No values of @expr{a} and @expr{b} can make the two sides match, |
| 24375 | even approximately. | 24683 | even approximately. |
| 24376 | 24684 | ||
| 24377 | There is no good solution to this problem at present. You could | 24685 | There is no good solution to this problem at present. You could |
| @@ -24388,14 +24696,14 @@ taking Fourier and related transforms.) | |||
| 24388 | @noindent | 24696 | @noindent |
| 24389 | Calc's internal least-squares fitter can only handle multilinear | 24697 | Calc's internal least-squares fitter can only handle multilinear |
| 24390 | models. More precisely, it can handle any model of the form | 24698 | models. 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} |
| 24392 | are the parameters and @cite{x,y,z} are the independent variables | 24700 | are 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 | ||
| 24395 | In a simple multilinear or polynomial fit, it is easy to see how | 24703 | In a simple multilinear or polynomial fit, it is easy to see how |
| 24396 | to convert the model into this form. For example, if the model | 24704 | to convert the model into this form. For example, if the model |
| 24397 | is @cite{a + b x + c x^2}, then @cite{f(x) = 1}, @cite{g(x) = x}, | 24705 | is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x}, |
| 24398 | and @cite{h(x) = x^2} are suitable functions. | 24706 | and @expr{h(x) = x^2} are suitable functions. |
| 24399 | 24707 | ||
| 24400 | For other models, Calc uses a variety of algebraic manipulations | 24708 | For other models, Calc uses a variety of algebraic manipulations |
| 24401 | to try to put the problem into the form | 24709 | to 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 |
| 24408 | where @cite{Y,A,B,C,F,G,H} are arbitrary functions. It computes | 24716 | where @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, |
| 24410 | does a standard linear fit to find the values of @cite{A}, @cite{B}, | 24718 | does a standard linear fit to find the values of @expr{A}, @expr{B}, |
| 24411 | and @cite{C}, then uses the equation solver to solve for @cite{a,b,c} | 24719 | and @expr{C}, then uses the equation solver to solve for @expr{a,b,c} |
| 24412 | in terms of @cite{A,B,C}. | 24720 | in terms of @expr{A,B,C}. |
| 24413 | 24721 | ||
| 24414 | A remarkable number of models can be cast into this general form. | 24722 | A remarkable number of models can be cast into this general form. |
| 24415 | We'll look at two examples here to see how it works. The power-law | 24723 | We'll look at two examples here to see how it works. The power-law |
| 24416 | model @cite{y = a x^b} with two independent variables and two parameters | 24724 | model @expr{y = a x^b} with two independent variables and two parameters |
| 24417 | can be rewritten as follows: | 24725 | can 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 |
| 24427 | which matches the desired form with @c{$Y = \ln(y)$} | 24735 | which 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)}, |
| 24432 | the logarithms of your @cite{y} and @cite{x} values, does a linear fit | 24740 | @expr{F = 1}, @expr{B = b}, and |
| 24433 | for @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}. | 24743 | Calc thus computes the logarithms of your @expr{y} and @expr{x} values, |
| 24744 | does a linear fit for @expr{A} and @expr{B}, then solves to get | ||
| 24745 | @texline @tmath{a = \exp(A)} | ||
| 24746 | @infoline @expr{a = exp(A)} | ||
| 24747 | and @expr{b = B}. | ||
| 24436 | 24748 | ||
| 24437 | Another interesting example is the ``quadratic'' model, which can | 24749 | Another interesting example is the ``quadratic'' model, which can |
| 24438 | be handled by expanding according to the distributive law. | 24750 | be 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 |
| 24446 | which matches with @cite{Y = y}, @cite{A = a + b c^2}, @cite{F = 1}, | 24758 | which 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 |
| 24448 | have been put into @cite{G} instead of @cite{B}), @cite{C = b}, and | 24760 | have 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 | ||
| 24451 | The Gaussian model looks quite complicated, but a closer examination | 24763 | The Gaussian model looks quite complicated, but a closer examination |
| 24452 | shows that it's actually similar to the quadratic model but with an | 24764 | shows that it's actually similar to the quadratic model but with an |
| 24453 | exponential that can be brought to the top and moved into @cite{Y}. | 24765 | exponential that can be brought to the top and moved into @expr{Y}. |
| 24454 | 24766 | ||
| 24455 | An example of a model that cannot be put into general linear | 24767 | An example of a model that cannot be put into general linear |
| 24456 | form is a Gaussian with a constant background added on, i.e., | 24768 | form 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 |
| 24458 | this, your best bet is to replace enough of your parameters with | 24770 | this, your best bet is to replace enough of your parameters with |
| 24459 | constants to make the model linearizable, then adjust the constants | 24771 | constants to make the model linearizable, then adjust the constants |
| 24460 | manually by doing a series of fits. You can compare the fits by | 24772 | manually by doing a series of fits. You can compare the fits by |
| 24461 | graphing them, by examining the goodness-of-fit measures returned by | 24773 | graphing 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. |
| 24463 | Note that some models can be linearized in several ways. The | 24775 | Note that some models can be linearized in several ways. The |
| 24464 | Gaussian-plus-@var{d} model can be linearized by setting @cite{d} | 24776 | Gaussian-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 |
| 24466 | deviation) and @cite{c} (the mean) to constants. | 24778 | deviation) and @expr{c} (the mean) to constants. |
| 24467 | 24779 | ||
| 24468 | To fit a model with constants substituted for some parameters, just | 24780 | To fit a model with constants substituted for some parameters, just |
| 24469 | store suitable values in those parameter variables, then omit them | 24781 | store 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 | ||
| 24476 | A last desperate step would be to use the general-purpose | 24788 | A 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 |
| 24478 | functions solve the problem of minimizing an expression (the @c{$\chi^2$} | 24790 | functions solve the problem of minimizing an expression (the |
| 24479 | @cite{chi^2} | 24791 | @texline @tmath{\chi^2} |
| 24792 | @infoline @expr{chi^2} | ||
| 24480 | sum) by adjusting certain parameters in the expression. The @kbd{a F} | 24793 | sum) by adjusting certain parameters in the expression. The @kbd{a F} |
| 24481 | command is able to use a vastly more efficient algorithm due to its | 24794 | command is able to use a vastly more efficient algorithm due to its |
| 24482 | special knowledge about linear chi-square sums, but the @kbd{a N} | 24795 | special knowledge about linear chi-square sums, but the @kbd{a N} |
| @@ -24485,9 +24798,10 @@ command can do the same thing by brute force. | |||
| 24485 | A compromise would be to pick out a few parameters without which the | 24798 | A compromise would be to pick out a few parameters without which the |
| 24486 | fit is linearizable, and use @code{minimize} on a call to @code{fit} | 24799 | fit is linearizable, and use @code{minimize} on a call to @code{fit} |
| 24487 | which efficiently takes care of the rest of the parameters. The thing | 24800 | which efficiently takes care of the rest of the parameters. The thing |
| 24488 | to be minimized would be the value of @c{$\chi^2$} | 24801 | to be minimized would be the value of |
| 24489 | @cite{chi^2} returned as | 24802 | @texline @tmath{\chi^2} |
| 24490 | the fifth result of the @code{xfit} function: | 24803 | @infoline @expr{chi^2} |
| 24804 | returned as the fifth result of the @code{xfit} function: | ||
| 24491 | 24805 | ||
| 24492 | @smallexample | 24806 | @smallexample |
| 24493 | minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) | 24807 | minimize(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 |
| 24497 | where @code{gaus} represents the Gaussian model with background, | 24811 | where @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 |
| 24499 | the initial guess for @cite{d} that @code{minimize} requires. | 24813 | the initial guess for @expr{d} that @code{minimize} requires. |
| 24500 | This operation will only be, shall we say, extraordinarily slow | 24814 | This operation will only be, shall we say, extraordinarily slow |
| 24501 | rather than astronomically slow (as would be the case if @code{minimize} | 24815 | rather than astronomically slow (as would be the case if @code{minimize} |
| 24502 | were used by itself to solve the problem). | 24816 | were used by itself to solve the problem). |
| @@ -24507,17 +24821,17 @@ were used by itself to solve the problem). | |||
| 24507 | 24821 | ||
| 24508 | The @kbd{I a F} [@code{xfit}] command is somewhat trickier when | 24822 | The @kbd{I a F} [@code{xfit}] command is somewhat trickier when |
| 24509 | nonlinear models are used. The second item in the result is the | 24823 | nonlinear models are used. The second item in the result is the |
| 24510 | vector of ``raw'' parameters @cite{A}, @cite{B}, @cite{C}. The | 24824 | vector of ``raw'' parameters @expr{A}, @expr{B}, @expr{C}. The |
| 24511 | covariance matrix is written in terms of those raw parameters. | 24825 | covariance matrix is written in terms of those raw parameters. |
| 24512 | The fifth item is a vector of @dfn{filter} expressions. This | 24826 | The fifth item is a vector of @dfn{filter} expressions. This |
| 24513 | is the empty vector @samp{[]} if the raw parameters were the same | 24827 | is the empty vector @samp{[]} if the raw parameters were the same |
| 24514 | as the requested parameters, i.e., if @cite{A = a}, @cite{B = b}, | 24828 | as the requested parameters, i.e., if @expr{A = a}, @expr{B = b}, |
| 24515 | and so on (which is always true if the model is already linear | 24829 | and so on (which is always true if the model is already linear |
| 24516 | in the parameters as written, e.g., for polynomial fits). If the | 24830 | in the parameters as written, e.g., for polynomial fits). If the |
| 24517 | parameters had to be rearranged, the fifth item is instead a vector | 24831 | parameters had to be rearranged, the fifth item is instead a vector |
| 24518 | of one formula per parameter in the original model. The raw | 24832 | of one formula per parameter in the original model. The raw |
| 24519 | parameters are expressed in these ``filter'' formulas as | 24833 | parameters 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}, |
| 24521 | and so on. | 24835 | and so on. |
| 24522 | 24836 | ||
| 24523 | When Calc needs to modify the model to return the result, it replaces | 24837 | When 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 | |||
| 24537 | nontrivial filter functions. | 24851 | nontrivial filter functions. |
| 24538 | 24852 | ||
| 24539 | Things are also complicated when the input contains error forms. | 24853 | Things are also complicated when the input contains error forms. |
| 24540 | Suppose there are three independent and dependent variables, @cite{x}, | 24854 | Suppose 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 |
| 24542 | data. Calc combines all the error values by taking the square root | 24856 | data. Calc combines all the error values by taking the square root |
| 24543 | of the sum of the squares of the errors. It then changes @cite{x} | 24857 | of the sum of the squares of the errors. It then changes @expr{x} |
| 24544 | and @cite{y} to be plain numbers, and makes @cite{z} into an error | 24858 | and @expr{y} to be plain numbers, and makes @expr{z} into an error |
| 24545 | form with this combined error. The @cite{Y(x,y,z)} part of the | 24859 | form with this combined error. The @expr{Y(x,y,z)} part of the |
| 24546 | linearized model is evaluated, and the result should be an error | 24860 | linearized model is evaluated, and the result should be an error |
| 24547 | form. The error part of that result is used for @c{$\sigma_i$} | 24861 | form. The error part of that result is used for |
| 24548 | @cite{sigma_i} for | 24862 | @texline @tmath{\sigma_i} |
| 24549 | the data point. If for some reason @cite{Y(x,y,z)} does not return | 24863 | @infoline @expr{sigma_i} |
| 24550 | an error form, the combined error from @cite{z} is used directly | 24864 | for the data point. If for some reason @expr{Y(x,y,z)} does not return |
| 24551 | for @c{$\sigma_i$} | 24865 | an 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}. |
| 24553 | for use in computing @cite{F(x,y,z)}, @cite{G(x,y,z)} and so on; | 24867 | @infoline @expr{sigma_i}. |
| 24868 | Finally, @expr{z} is also stripped of its error | ||
| 24869 | for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on; | ||
| 24554 | the righthand side of the linearized model is computed in regular | 24870 | the righthand side of the linearized model is computed in regular |
| 24555 | arithmetic with no error forms. | 24871 | arithmetic 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 |
| 24558 | the most reasonable thing in the typical case that @cite{Y(x,y,z)} | 24874 | the most reasonable thing in the typical case that @expr{Y(x,y,z)} |
| 24559 | depends only on the dependent variable @cite{z}, and in fact is | 24875 | depends only on the dependent variable @expr{z}, and in fact is |
| 24560 | often simply equal to @cite{z}. For common cases like polynomials | 24876 | often simply equal to @expr{z}. For common cases like polynomials |
| 24561 | and multilinear models, the combined error is simply used as the | 24877 | and 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} |
| 24880 | for 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 |
| 24618 | to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable | 24935 | to @samp{fitvar(1)}, @samp{fitvar(2)}, etc. The dependent variable |
| 24619 | is the highest-numbered @code{fitvar}. For example, the power law | 24936 | is the highest-numbered @code{fitvar}. For example, the power law |
| 24620 | model @cite{a x^b} is converted to @cite{y = a x^b}, then to | 24937 | model @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 |
| 24640 | where @var{Y} is a formula that describes the function @cite{Y(x,y,z)}, | 24957 | where @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)]}, |
| 24642 | and @var{abc} is the vector of parameter filters which refer to the | 24959 | and @var{abc} is the vector of parameter filters which refer to the |
| 24643 | raw parameters as @samp{fitdummy(1)} for @cite{A}, @samp{fitdummy(2)} | 24960 | raw parameters as @samp{fitdummy(1)} for @expr{A}, @samp{fitdummy(2)} |
| 24644 | for @cite{B}, etc. While the number of raw parameters (the length of | 24961 | for @expr{B}, etc. While the number of raw parameters (the length of |
| 24645 | the @var{FGH} vector) is usually the same as the number of original | 24962 | the @var{FGH} vector) is usually the same as the number of original |
| 24646 | parameters (the length of the @var{abc} vector), this is not required. | 24963 | parameters (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 | |||
| 24664 | non-constant powers are converted to logs-and-exponentials form, | 24981 | non-constant powers are converted to logs-and-exponentials form, |
| 24665 | and the distributive law is used to expand products of sums. | 24982 | and the distributive law is used to expand products of sums. |
| 24666 | Quotients are rewritten to use the @samp{fitinv} function, where | 24983 | Quotients 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} |
| 24668 | are operating. (The use of @code{fitinv} makes recognition of | 24985 | are operating. (The use of @code{fitinv} makes recognition of |
| 24669 | linear-looking forms easier.) If you modify @code{FitRules}, you | 24986 | linear-looking forms easier.) If you modify @code{FitRules}, you |
| 24670 | will probably only need to modify the rules for this phase. | 24987 | will 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. | |||
| 24672 | Phase two, whose rules can actually also apply during phases one | 24989 | Phase two, whose rules can actually also apply during phases one |
| 24673 | and three, first rewrites @code{fitmodel} to a two-argument | 24990 | and three, first rewrites @code{fitmodel} to a two-argument |
| 24674 | form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is | 24991 | form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is |
| 24675 | initially zero and @var{model} has been changed from @cite{a=b} | 24992 | initially zero and @var{model} has been changed from @expr{a=b} |
| 24676 | to @cite{a-b} form. It then tries to peel off invertible functions | 24993 | to @expr{a-b} form. It then tries to peel off invertible functions |
| 24677 | from the outside of @var{model} and put them into @var{Y} instead, | 24994 | from the outside of @var{model} and put them into @var{Y} instead, |
| 24678 | calling the equation solver to invert the functions. Finally, when | 24995 | calling the equation solver to invert the functions. Finally, when |
| 24679 | this is no longer possible, the @code{fitmodel} is changed to a | 24996 | this 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 |
| 24720 | Two functions which are useful in connection with @code{FitRules} | 25037 | Two functions which are useful in connection with @code{FitRules} |
| 24721 | are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check | 25038 | are @samp{hasfitparams(x)} and @samp{hasfitvars(x)}, which check |
| 24722 | whether @cite{x} refers to any parameters or independent variables, | 25039 | whether @expr{x} refers to any parameters or independent variables, |
| 24723 | respectively. Specifically, these functions return ``true'' if the | 25040 | respectively. Specifically, these functions return ``true'' if the |
| 24724 | argument contains any @code{fitparam} (or @code{fitvar}) function | 25041 | argument contains any @code{fitparam} (or @code{fitvar}) function |
| 24725 | calls, and ``false'' otherwise. (Recall that ``true'' means a | 25042 | calls, 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 |
| 24769 | The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does | 25086 | The @kbd{a p} (@code{calc-poly-interp}) [@code{polint}] command does |
| 24770 | a polynomial interpolation at a particular @cite{x} value. It takes | 25087 | a polynomial interpolation at a particular @expr{x} value. It takes |
| 24771 | two arguments from the stack: A data matrix of the sort used by | 25088 | two 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} |
| 24773 | value. Calc effectively does an exact polynomial fit as if by @kbd{a F i}, | 25090 | value. Calc effectively does an exact polynomial fit as if by @kbd{a F i}, |
| 24774 | then substitutes the @cite{x} value into the result in order to get an | 25091 | then substitutes the @expr{x} value into the result in order to get an |
| 24775 | approximate @cite{y} value based on the fit. (Calc does not actually | 25092 | approximate @expr{y} value based on the fit. (Calc does not actually |
| 24776 | use @kbd{a F i}, however; it uses a direct method which is both more | 25093 | use @kbd{a F i}, however; it uses a direct method which is both more |
| 24777 | efficient and more numerically stable.) | 25094 | efficient and more numerically stable.) |
| 24778 | 25095 | ||
| 24779 | The result of @kbd{a p} is actually a vector of two values: The @cite{y} | 25096 | The result of @kbd{a p} is actually a vector of two values: The @expr{y} |
| 24780 | value approximation, and an error measure @cite{dy} that reflects Calc's | 25097 | value approximation, and an error measure @expr{dy} that reflects Calc's |
| 24781 | estimation of the probable error of the approximation at that value of | 25098 | estimation 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 |
| 24783 | in the data matrix, the output @cite{y} will be the corresponding @cite{y} | 25100 | in the data matrix, the output @expr{y} will be the corresponding @expr{y} |
| 24784 | value from the matrix, and the output @cite{dy} will be exactly zero. | 25101 | value from the matrix, and the output @expr{dy} will be exactly zero. |
| 24785 | 25102 | ||
| 24786 | A prefix argument of 2 causes @kbd{a p} to take separate x- and | 25103 | A prefix argument of 2 causes @kbd{a p} to take separate x- and |
| 24787 | y-vectors from the stack instead of one data matrix. | 25104 | y-vectors from the stack instead of one data matrix. |
| 24788 | 25105 | ||
| 24789 | If @cite{x} is a vector of numbers, @kbd{a p} will return a matrix of | 25106 | If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of |
| 24790 | interpolated results for each of those @cite{x} values. (The matrix will | 25107 | interpolated results for each of those @expr{x} values. (The matrix will |
| 24791 | have two columns, the @cite{y} values and the @cite{dy} values.) | 25108 | have two columns, the @expr{y} values and the @expr{dy} values.) |
| 24792 | If @cite{x} is a formula instead of a number, the @code{polint} function | 25109 | If @expr{x} is a formula instead of a number, the @code{polint} function |
| 24793 | remains in symbolic form; use the @kbd{a "} command to expand it out to | 25110 | remains in symbolic form; use the @kbd{a "} command to expand it out to |
| 24794 | a formula that describes the fit in symbolic terms. | 25111 | a formula that describes the fit in symbolic terms. |
| 24795 | 25112 | ||
| 24796 | In all cases, the @kbd{a p} command leaves the data vectors or matrix | 25113 | In all cases, the @kbd{a p} command leaves the data vectors or matrix |
| 24797 | on the stack. Only the @cite{x} value is replaced by the result. | 25114 | on 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 |
| 24801 | The @kbd{H a p} [@code{ratint}] command does a rational function | 25118 | The @kbd{H a p} [@code{ratint}] command does a rational function |
| 24802 | interpolation. It is used exactly like @kbd{a p}, except that it | 25119 | interpolation. It is used exactly like @kbd{a p}, except that it |
| 24803 | uses as its model the quotient of two polynomials. If there are | 25120 | uses 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 |
| 24805 | each have degree @cite{N/2} (if @cite{N} is odd, the denominator will | 25122 | each have degree @expr{N/2} (if @expr{N} is odd, the denominator will |
| 24806 | have degree one higher than the numerator). | 25123 | have degree one higher than the numerator). |
| 24807 | 25124 | ||
| 24808 | Rational approximations have the advantage that they can accurately | 25125 | Rational approximations have the advantage that they can accurately |
| 24809 | describe functions that have poles (points at which the function's value | 25126 | describe functions that have poles (points at which the function's value |
| 24810 | goes to infinity, so that the denominator polynomial of the approximation | 25127 | goes to infinity, so that the denominator polynomial of the approximation |
| 24811 | goes to zero). If @cite{x} corresponds to a pole of the fitted rational | 25128 | goes to zero). If @expr{x} corresponds to a pole of the fitted rational |
| 24812 | function, then the result will be a division by zero. If Infinite mode | 25129 | function, then the result will be a division by zero. If Infinite mode |
| 24813 | is enabled, the result will be @samp{[uinf, uinf]}. | 25130 | is enabled, the result will be @samp{[uinf, uinf]}. |
| 24814 | 25131 | ||
| @@ -24842,9 +25159,9 @@ $$ \sum_{k=1}^5 k^2 = 55 $$ | |||
| 24842 | The choice of index variable is arbitrary, but it's best not to | 25159 | The choice of index variable is arbitrary, but it's best not to |
| 24843 | use a variable with a stored value. In particular, while | 25160 | use 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 |
| 24845 | in Calc because @code{i} has the imaginary constant @cite{(0, 1)} | 25162 | in Calc because @code{i} has the imaginary constant @expr{(0, 1)} |
| 24846 | as a value. If you pressed @kbd{=} on a sum over @code{i}, it would | 25163 | as a value. If you pressed @kbd{=} on a sum over @code{i}, it would |
| 24847 | be changed to a nonsensical sum over the ``variable'' @cite{(0, 1)}! | 25164 | be changed to a nonsensical sum over the ``variable'' @expr{(0, 1)}! |
| 24848 | If you really want to use @code{i} as an index variable, use | 25165 | If 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} | |||
| 24878 | and @samp{inf}, respectively. | 25195 | and @samp{inf}, respectively. |
| 24879 | 25196 | ||
| 24880 | Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)} | 25197 | Infinite sums can sometimes be evaluated: @samp{sum(.5^k, k, 1, inf)} |
| 24881 | returns @cite{1}. This is done by evaluating the sum in closed | 25198 | returns @expr{1}. This is done by evaluating the sum in closed |
| 24882 | form (to @samp{1. - 0.5^n} in this case), then evaluating this | 25199 | form (to @samp{1. - 0.5^n} in this case), then evaluating this |
| 24883 | formula with @code{n} set to @code{inf}. Calc's usual rules | 25200 | formula with @code{n} set to @code{inf}. Calc's usual rules |
| 24884 | for ``infinite'' arithmetic can find the answer from there. If | 25201 | for ``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 | |||
| 24916 | but the sum from @samp{n} to @samp{n-2} may report a nonzero value | 25233 | but the sum from @samp{n} to @samp{n-2} may report a nonzero value |
| 24917 | if Calc used a closed form solution. | 25234 | if Calc used a closed form solution. |
| 24918 | 25235 | ||
| 24919 | Calc's logical predicates like @cite{a < b} return 1 for ``true'' | 25236 | Calc's logical predicates like @expr{a < b} return 1 for ``true'' |
| 24920 | and 0 for ``false.'' @xref{Logical Operations}. This can be | 25237 | and 0 for ``false.'' @xref{Logical Operations}. This can be |
| 24921 | used to advantage for building conditional sums. For example, | 25238 | used 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 |
| 24923 | prime numbers from 1 to 20; the @code{prime} predicate returns 1 if | 25240 | prime numbers from 1 to 20; the @code{prime} predicate returns 1 if |
| 24924 | its argument is prime and 0 otherwise. You can read this expression | 25241 | its argument is prime and 0 otherwise. You can read this expression |
| 24925 | as ``the sum of @cite{k^2}, where @cite{k} is prime.'' Indeed, | 25242 | as ``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 |
| 24927 | squared, since the limits default to plus and minus infinity, but | 25244 | squared, since the limits default to plus and minus infinity, but |
| 24928 | there are no such sums that Calc's built-in rules can do in | 25245 | there are no such sums that Calc's built-in rules can do in |
| 24929 | closed form. | 25246 | closed form. |
| 24930 | 25247 | ||
| 24931 | As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the | 25248 | As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the |
| 24932 | sum of @cite{f(k)} for all @cite{k} from 1 to @cite{n}, excluding | 25249 | sum of @expr{f(k)} for all @expr{k} from 1 to @expr{n}, excluding |
| 24933 | one value @cite{k_0}. Slightly more tricky is the summand | 25250 | one 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 |
| 24935 | the sum of all @cite{1/(k-k_0)} except at @cite{k = k_0}, where | 25252 | the sum of all @expr{1/(k-k_0)} except at @expr{k = k_0}, where |
| 24936 | this would be a division by zero. But at @cite{k = k_0}, this | 25253 | this would be a division by zero. But at @expr{k = k_0}, this |
| 24937 | formula works out to the indeterminate form @cite{0 / 0}, which | 25254 | formula works out to the indeterminate form @expr{0 / 0}, which |
| 24938 | Calc will not assume is zero. Better would be to use | 25255 | Calc 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 |
| 24940 | an ``if-then-else'' test: This expression says, ``if @c{$k \ne k_0$} | 25257 | an ``if-then-else'' test: This expression says, ``if |
| 24941 | @cite{k != k_0}, | 25258 | @texline @tmath{k \ne k_0}, |
| 24942 | then @cite{1/(k-k_0)}, else zero.'' Now the formula @cite{1/(k-k_0)} | 25259 | @infoline @expr{k != k_0}, |
| 24943 | will not even be evaluated by Calc when @cite{k = k_0}. | 25260 | then @expr{1/(k-k_0)}, else zero.'' Now the formula @expr{1/(k-k_0)} |
| 25261 | will not even be evaluated by Calc when @expr{k = k_0}. | ||
| 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 | |||
| 24991 | which @code{dnonzero} returns 0 or cannot decide is assumed ``false.'' | 25309 | which @code{dnonzero} returns 0 or cannot decide is assumed ``false.'' |
| 24992 | Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then'' | 25310 | Note that this means that @w{@kbd{Z [ Z ]}} will execute the ``then'' |
| 24993 | portion if its condition is provably true, but it will execute the | 25311 | portion 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 |
| 24995 | provably true, even if it might be true. Algebraic functions that | 25313 | provably true, even if it might be true. Algebraic functions that |
| 24996 | have conditions as arguments, like @code{? :} and @code{&&}, remain | 25314 | have conditions as arguments, like @code{? :} and @code{&&}, remain |
| 24997 | unevaluated if the condition is neither provably true nor provably | 25315 | unevaluated if the condition is neither provably true nor provably |
| @@ -25004,10 +25322,10 @@ false. @xref{Declarations}.) | |||
| 25004 | @tindex == | 25322 | @tindex == |
| 25005 | The @kbd{a =} (@code{calc-equal-to}) command, or @samp{eq(a,b)} function | 25323 | The @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 |
| 25007 | formula) is true if @cite{a} and @cite{b} are equal, either because they | 25325 | formula) is true if @expr{a} and @expr{b} are equal, either because they |
| 25008 | are identical expressions, or because they are numbers which are | 25326 | are identical expressions, or because they are numbers which are |
| 25009 | numerically equal. (Thus the integer 1 is considered equal to the float | 25327 | numerically equal. (Thus the integer 1 is considered equal to the float |
| 25010 | 1.0.) If the equality of @cite{a} and @cite{b} cannot be determined, | 25328 | 1.0.) If the equality of @expr{a} and @expr{b} cannot be determined, |
| 25011 | the comparison is left in symbolic form. Note that as a command, this | 25329 | the comparison is left in symbolic form. Note that as a command, this |
| 25012 | operation pops two values from the stack and pushes back either a 1 or | 25330 | operation pops two values from the stack and pushes back either a 1 or |
| 25013 | a 0, or a formula @samp{a = b} if the values' equality cannot be determined. | 25331 | a 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 != |
| 25037 | The @kbd{a #} (@code{calc-not-equal-to}) command, or @samp{neq(a,b)} or | 25355 | The @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. |
| 25039 | This also works with more than two arguments; @samp{a != b != c != d} | 25357 | This also works with more than two arguments; @samp{a != b != c != d} |
| 25040 | tests that all four of @cite{a}, @cite{b}, @cite{c}, and @cite{d} are | 25358 | tests that all four of @expr{a}, @expr{b}, @expr{c}, and @expr{d} are |
| 25041 | distinct numbers. | 25359 | distinct 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 >= |
| 25089 | The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}] | 25407 | The @kbd{a <} (@code{calc-less-than}) [@samp{lt(a,b)} or @samp{a < b}] |
| 25090 | operation is true if @cite{a} is less than @cite{b}. Similar functions | 25408 | operation is true if @expr{a} is less than @expr{b}. Similar functions |
| 25091 | are @kbd{a >} (@code{calc-greater-than}) [@samp{gt(a,b)} or @samp{a > b}], | 25409 | are @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 && |
| 25122 | The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}] | 25440 | The @kbd{a &} (@code{calc-logical-and}) [@samp{land(a,b)} or @samp{a && b}] |
| 25123 | function is true if both of its arguments are true, i.e., are | 25441 | function is true if both of its arguments are true, i.e., are |
| 25124 | non-zero numbers. In this case, the result will be either @cite{a} or | 25442 | non-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 |
| 25126 | zero. Otherwise, the formula is left in symbolic form. | 25444 | zero. 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. | |||
| 25132 | The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}] | 25450 | The @kbd{a |} (@code{calc-logical-or}) [@samp{lor(a,b)} or @samp{a || b}] |
| 25133 | function is true if either or both of its arguments are true (nonzero). | 25451 | function is true if either or both of its arguments are true (nonzero). |
| 25134 | The result is whichever argument was nonzero, choosing arbitrarily if both | 25452 | The result is whichever argument was nonzero, choosing arbitrarily if both |
| 25135 | are nonzero. If both @cite{a} and @cite{b} are zero, the result is | 25453 | are nonzero. If both @expr{a} and @expr{b} are zero, the result is |
| 25136 | zero. | 25454 | zero. |
| 25137 | 25455 | ||
| 25138 | @kindex a ! | 25456 | @kindex a ! |
| @@ -25140,8 +25458,8 @@ zero. | |||
| 25140 | @tindex lnot | 25458 | @tindex lnot |
| 25141 | @tindex ! | 25459 | @tindex ! |
| 25142 | The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}] | 25460 | The @kbd{a !} (@code{calc-logical-not}) [@samp{lnot(a)} or @samp{!@: a}] |
| 25143 | function is true if @cite{a} is false (zero), or false if @cite{a} is | 25461 | function is true if @expr{a} is false (zero), or false if @expr{a} is |
| 25144 | true (nonzero). It is left in symbolic form if @cite{a} is not a | 25462 | true (nonzero). It is left in symbolic form if @expr{a} is not a |
| 25145 | number. | 25463 | number. |
| 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 |
| 25159 | The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}] | 25477 | The @kbd{a :} (@code{calc-logical-if}) [@samp{if(a,b,c)} or @samp{a ? b :@: c}] |
| 25160 | function is equal to either @cite{b} or @cite{c} if @cite{a} is a nonzero | 25478 | function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero |
| 25161 | number or zero, respectively. If @cite{a} is not a number, the test is | 25479 | number or zero, respectively. If @expr{a} is not a number, the test is |
| 25162 | left in symbolic form and neither @cite{b} nor @cite{c} is evaluated in | 25480 | left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in |
| 25163 | any way. In algebraic formulas, this is one of the few Calc functions | 25481 | any way. In algebraic formulas, this is one of the few Calc functions |
| 25164 | whose arguments are not automatically evaluated when the function itself | 25482 | whose arguments are not automatically evaluated when the function itself |
| 25165 | is evaluated. The others are @code{lambda}, @code{quote}, and | 25483 | is 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 | |||
| 25170 | as three separate symbols. Type something like @samp{a ? 3 : 4} or | 25488 | as 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 | ||
| 25173 | As a special case, if @cite{a} evaluates to a vector, then both @cite{b} | 25491 | As a special case, if @expr{a} evaluates to a vector, then both @expr{b} |
| 25174 | and @cite{c} are evaluated; the result is a vector of the same length | 25492 | and @expr{c} are evaluated; the result is a vector of the same length |
| 25175 | as @cite{a} whose elements are chosen from corresponding elements of | 25493 | as @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} |
| 25177 | is zero or nonzero. Each of @cite{b} and @cite{c} must be either a | 25495 | is zero or nonzero. Each of @expr{b} and @expr{c} must be either a |
| 25178 | vector of the same length as @cite{a}, or a non-vector which is matched | 25496 | vector of the same length as @expr{a}, or a non-vector which is matched |
| 25179 | with all elements of @cite{a}. | 25497 | with 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 |
| 25184 | The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if | 25502 | The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if |
| 25185 | the number @cite{a} is in the set of numbers represented by @cite{b}. | 25503 | the number @expr{a} is in the set of numbers represented by @expr{b}. |
| 25186 | If @cite{b} is an interval form, @cite{a} must be one of the values | 25504 | If @expr{b} is an interval form, @expr{a} must be one of the values |
| 25187 | encompassed by the interval. If @cite{b} is a vector, @cite{a} must be | 25505 | encompassed by the interval. If @expr{b} is a vector, @expr{a} must be |
| 25188 | equal to one of the elements of the vector. (If any vector elements are | 25506 | equal to one of the elements of the vector. (If any vector elements are |
| 25189 | intervals, @cite{a} must be in any of the intervals.) If @cite{b} is a | 25507 | intervals, @expr{a} must be in any of the intervals.) If @expr{b} is a |
| 25190 | plain number, @cite{a} must be numerically equal to @cite{b}. | 25508 | plain 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 |
| 25192 | of this sort. | 25510 | of this sort. |
| 25193 | 25511 | ||
| @@ -25196,7 +25514,7 @@ of this sort. | |||
| 25196 | @end ignore | 25514 | @end ignore |
| 25197 | @tindex typeof | 25515 | @tindex typeof |
| 25198 | The @samp{typeof(a)} function produces an integer or variable which | 25516 | The @samp{typeof(a)} function produces an integer or variable which |
| 25199 | characterizes @cite{a}. If @cite{a} is a number, vector, or variable, | 25517 | characterizes @expr{a}. If @expr{a} is a number, vector, or variable, |
| 25200 | the result will be one of the following numbers: | 25518 | the 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: | |||
| 25217 | 102 Matrix | 25535 | 102 Matrix |
| 25218 | @end example | 25536 | @end example |
| 25219 | 25537 | ||
| 25220 | Otherwise, @cite{a} is a formula, and the result is a variable which | 25538 | Otherwise, @expr{a} is a formula, and the result is a variable which |
| 25221 | represents the name of the top-level function call. | 25539 | represents 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 |
| 25235 | The @samp{integer(a)} function returns true if @cite{a} is an integer. | 25553 | The @samp{integer(a)} function returns true if @expr{a} is an integer. |
| 25236 | The @samp{real(a)} function | 25554 | The @samp{real(a)} function |
| 25237 | is true if @cite{a} is a real number, either integer, fraction, or | 25555 | is true if @expr{a} is a real number, either integer, fraction, or |
| 25238 | float. The @samp{constant(a)} function returns true if @cite{a} is | 25556 | float. The @samp{constant(a)} function returns true if @expr{a} is |
| 25239 | any of the objects for which @code{typeof} would produce an integer | 25557 | any of the objects for which @code{typeof} would produce an integer |
| 25240 | code result except for variables, and provided that the components of | 25558 | code result except for variables, and provided that the components of |
| 25241 | an object like a vector or error form are themselves constant. | 25559 | an object like a vector or error form are themselves constant. |
| 25242 | Note that infinities do not satisfy any of these tests, nor do | 25560 | Note that infinities do not satisfy any of these tests, nor do |
| 25243 | special constants like @code{pi} and @code{e}.@refill | 25561 | special 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 |
| 25246 | formulas as well as actual numbers. For example, @samp{dint(floor(x))} | 25564 | formulas 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 |
| 25255 | The @samp{refers(a,b)} function is true if the variable (or sub-expression) | 25573 | The @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 |
| 25257 | tests described here, this function returns a definite ``no'' answer | 25575 | tests described here, this function returns a definite ``no'' answer |
| 25258 | even if its arguments are still in symbolic form. The only case where | 25576 | even 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 |
| 25260 | variable (different from @cite{b}). | 25578 | variable (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 |
| 25266 | The @samp{negative(a)} function returns true if @cite{a} ``looks'' negative, | 25584 | The @samp{negative(a)} function returns true if @expr{a} ``looks'' negative, |
| 25267 | because it is a negative number, because it is of the form @cite{-x}, | 25585 | because it is a negative number, because it is of the form @expr{-x}, |
| 25268 | or because it is a product or quotient with a term that looks negative. | 25586 | or because it is a product or quotient with a term that looks negative. |
| 25269 | This is most useful in rewrite rules. Beware that @samp{negative(a)} | 25587 | This is most useful in rewrite rules. Beware that @samp{negative(a)} |
| 25270 | evaluates to 1 or 0 for @emph{any} argument @cite{a}, so it can only | 25588 | evaluates to 1 or 0 for @emph{any} argument @expr{a}, so it can only |
| 25271 | be stored in a formula if the default simplifications are turned off | 25589 | be stored in a formula if the default simplifications are turned off |
| 25272 | first with @kbd{m O} (or if it appears in an unevaluated context such | 25590 | first with @kbd{m O} (or if it appears in an unevaluated context such |
| 25273 | as a rewrite rule condition). | 25591 | as 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 |
| 25279 | The @samp{variable(a)} function is true if @cite{a} is a variable, | 25597 | The @samp{variable(a)} function is true if @expr{a} is a variable, |
| 25280 | or false if not. If @cite{a} is a function call, this test is left | 25598 | or false if not. If @expr{a} is a function call, this test is left |
| 25281 | in symbolic form. Built-in variables like @code{pi} and @code{inf} | 25599 | in symbolic form. Built-in variables like @code{pi} and @code{inf} |
| 25282 | are considered variables like any others by this test. | 25600 | are 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 |
| 25288 | The @samp{nonvar(a)} function is true if @cite{a} is a non-variable. | 25606 | The @samp{nonvar(a)} function is true if @expr{a} is a non-variable. |
| 25289 | If its argument is a variable it is left unsimplified; it never | 25607 | If its argument is a variable it is left unsimplified; it never |
| 25290 | actually returns zero. However, since Calc's condition-testing | 25608 | actually returns zero. However, since Calc's condition-testing |
| 25291 | commands consider ``false'' anything not provably true, this is | 25609 | commands consider ``false'' anything not provably true, this is |
| @@ -25310,15 +25628,15 @@ often good enough. | |||
| 25310 | @cindex Linearity testing | 25628 | @cindex Linearity testing |
| 25311 | The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt} | 25629 | The functions @code{lin}, @code{linnt}, @code{islin}, and @code{islinnt} |
| 25312 | check if an expression is ``linear,'' i.e., can be written in the form | 25630 | check 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 |
| 25314 | variable or subformula @cite{x}. The function @samp{islin(f,x)} checks | 25632 | variable or subformula @expr{x}. The function @samp{islin(f,x)} checks |
| 25315 | if formula @cite{f} is linear in @cite{x}, returning 1 if so. For | 25633 | if formula @expr{f} is linear in @expr{x}, returning 1 if so. For |
| 25316 | example, @samp{islin(x,x)}, @samp{islin(-x,x)}, @samp{islin(3,x)}, and | 25634 | example, @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 |
| 25318 | is similar, except that instead of returning 1 it returns the vector | 25636 | is 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} |
| 25322 | generally remain unevaluated for expressions which are not linear, | 25640 | generally remain unevaluated for expressions which are not linear, |
| 25323 | e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second | 25641 | e.g., @samp{lin(2 x^2, x)} and @samp{lin(sin(x), x)}. The second |
| 25324 | argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))} | 25642 | argument can also be a formula; @samp{islin(2 + 3 sin(x), sin(x))} |
| @@ -25326,19 +25644,19 @@ returns true. | |||
| 25326 | 25644 | ||
| 25327 | The @code{linnt} and @code{islinnt} functions perform a similar check, | 25645 | The @code{linnt} and @code{islinnt} functions perform a similar check, |
| 25328 | but require a ``non-trivial'' linear form, which means that the | 25646 | but 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)} |
| 25330 | returns @cite{[2, 0, x]} and @samp{lin(y,x)} returns @cite{[y, 0, x]}, | 25648 | returns @expr{[2, 0, x]} and @samp{lin(y,x)} returns @expr{[y, 0, x]}, |
| 25331 | but @samp{linnt(2,x)} and @samp{linnt(y,x)} are left unevaluated | 25649 | but @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'' |
| 25333 | linear in @cite{x}). | 25651 | linear in @expr{x}). |
| 25334 | 25652 | ||
| 25335 | All four linearity-testing functions allow you to omit the second | 25653 | All four linearity-testing functions allow you to omit the second |
| 25336 | argument, in which case the input may be linear in any non-constant | 25654 | argument, in which case the input may be linear in any non-constant |
| 25337 | formula. Here, the @cite{a=0}, @cite{b=1} case is also considered | 25655 | formula. Here, the @expr{a=0}, @expr{b=1} case is also considered |
| 25338 | trivial, and only constant values for @cite{a} and @cite{b} are | 25656 | trivial, and only constant values for @expr{a} and @expr{b} are |
| 25339 | recognized. Thus, @samp{lin(2 x y)} returns @cite{[0, 2, x y]}, | 25657 | recognized. 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)} |
| 25341 | returns @cite{[0, 1, x y]}. The @code{linnt} function would allow the | 25659 | returns @expr{[0, 1, x y]}. The @code{linnt} function would allow the |
| 25342 | first two cases but not the third. Also, neither @code{lin} nor | 25660 | first 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 |
| 25344 | case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false. | 25662 | case: @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 |
| 25350 | The @samp{istrue(a)} function returns 1 if @cite{a} is a nonzero | 25668 | The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero |
| 25351 | number or provably nonzero formula, or 0 if @cite{a} is anything else. | 25669 | number or provably nonzero formula, or 0 if @expr{a} is anything else. |
| 25352 | Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is | 25670 | Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is |
| 25353 | used to make sure they are not evaluated prematurely. (Note that | 25671 | used to make sure they are not evaluated prematurely. (Note that |
| 25354 | declarations are used when deciding whether a formula is true; | 25672 | declarations 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)}. | |||
| 25408 | The @code{assign} function is undefined by itself in Calc, so an | 25726 | The @code{assign} function is undefined by itself in Calc, so an |
| 25409 | assignment formula such as a rewrite rule will be left alone by ordinary | 25727 | assignment formula such as a rewrite rule will be left alone by ordinary |
| 25410 | Calc commands. But certain commands, like the rewrite system, interpret | 25728 | Calc commands. But certain commands, like the rewrite system, interpret |
| 25411 | assignments in special ways.@refill | 25729 | assignments in special ways. |
| 25412 | 25730 | ||
| 25413 | For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace | 25731 | For example, the rule @samp{sin(x)^2 := 1-cos(x)^2} says to replace |
| 25414 | every occurrence of the sine of something, squared, with one minus the | 25732 | every 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 |
| 25452 | rule set stored in a variable. You may also wish to use @kbd{s p} | 25770 | rule 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 | ||
| 25456 | Rewrite rules are compiled into a special internal form for faster | 25774 | Rewrite rules are compiled into a special internal form for faster |
| 25457 | matching. If you enter a rule set directly it must be recompiled | 25775 | matching. 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 |
| 25471 | To match a particular formula @cite{x} with a particular rewrite rule | 25789 | To 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 |
| 25473 | the structure of @var{old}. Variables that appear in @var{old} are | 25791 | the structure of @var{old}. Variables that appear in @var{old} are |
| 25474 | treated as @dfn{meta-variables}; the corresponding positions in @cite{x} | 25792 | treated as @dfn{meta-variables}; the corresponding positions in @expr{x} |
| 25475 | may contain any sub-formulas. For example, the pattern @samp{f(x,y)} | 25793 | may contain any sub-formulas. For example, the pattern @samp{f(x,y)} |
| 25476 | would match the expression @samp{f(12, a+1)} with the meta-variable | 25794 | would 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 | |||
| 25481 | the pattern is a single meta-variable, it will match any expression. | 25799 | the pattern is a single meta-variable, it will match any expression. |
| 25482 | 25800 | ||
| 25483 | If a given meta-variable appears more than once in @var{old}, the | 25801 | If a given meta-variable appears more than once in @var{old}, the |
| 25484 | corresponding sub-formulas of @cite{x} must be identical. Thus | 25802 | corresponding sub-formulas of @expr{x} must be identical. Thus |
| 25485 | the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and | 25803 | the 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}), | |||
| 25525 | the rule is accepted. If the result is zero or if it is a symbolic | 25843 | the rule is accepted. If the result is zero or if it is a symbolic |
| 25526 | formula that is not known to be nonzero, the rule is rejected. | 25844 | formula 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 |
| 25528 | 1 or 0 according to the results of various tests.@refill | 25846 | 1 or 0 according to the results of various tests. |
| 25529 | 25847 | ||
| 25530 | For example, the formula @samp{n > 0} simplifies to 1 or 0 if @cite{n} | 25848 | For example, the formula @samp{n > 0} simplifies to 1 or 0 if @expr{n} |
| 25531 | is replaced by a positive or nonpositive number, respectively (or if | 25849 | is 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, |
| 25533 | the rule @samp{f(x,y) := g(y+x,x) :: x+y > 0} would apply to | 25851 | the 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 |
| 25537 | the case of @samp{f(12, a+1)}, the condition merely cannot be shown | 25855 | the case of @samp{f(12, a+1)}, the condition merely cannot be shown |
| 25538 | to be satisfied, but that is enough to reject the rule. | 25856 | to 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 | |||
| 25562 | matched. | 25880 | matched. |
| 25563 | 25881 | ||
| 25564 | Certain conditions are handled as special cases by the rewrite rule | 25882 | Certain conditions are handled as special cases by the rewrite rule |
| 25565 | system and are tested very efficiently: Where @cite{x} is any | 25883 | system and are tested very efficiently: Where @expr{x} is any |
| 25566 | meta-variable, these conditions are @samp{integer(x)}, @samp{real(x)}, | 25884 | meta-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} |
| 25568 | is either a constant or another meta-variable and @samp{>=} may be | 25886 | is either a constant or another meta-variable and @samp{>=} may be |
| 25569 | replaced by any of the six relational operators, and @samp{x % a = b} | 25887 | replaced by any of the six relational operators, and @samp{x % a = b} |
| 25570 | where @cite{a} and @cite{b} are constants. Other conditions, like | 25888 | where @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 |
| 25572 | since Calc must bring the whole evaluator and simplifier into play. | 25890 | since 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} | |||
| 25776 | functions with rewrite conditions to test for this; @pxref{Logical | 26094 | functions with rewrite conditions to test for this; @pxref{Logical |
| 25777 | Operations}. These functions are not as convenient to use in rewrite | 26095 | Operations}. These functions are not as convenient to use in rewrite |
| 25778 | rules, but they recognize more kinds of formulas as linear: | 26096 | rules, 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}, |
| 25780 | but it will not match the above pattern because that pattern calls | 26098 | but it will not match the above pattern because that pattern calls |
| 25781 | for a multiplication, not a division. | 26099 | for 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 | ||
| 25798 | Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2} | 26116 | Note that this rule will @emph{not} match @samp{sin(x)^2 + 6 cos(x)^2} |
| 25799 | because one @cite{a} would have ``matched'' 1 while the other matched 6. | 26117 | because one @expr{a} would have ``matched'' 1 while the other matched 6. |
| 25800 | 26118 | ||
| 25801 | Calc automatically converts a rule like | 26119 | Calc 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 |
| 25946 | One kind of marker, @samp{import(x)}, takes the place of a whole | 26264 | One kind of marker, @samp{import(x)}, takes the place of a whole |
| 25947 | rule. Here @cite{x} is the name of a variable containing another | 26265 | rule. Here @expr{x} is the name of a variable containing another |
| 25948 | rule set; those rules are ``spliced into'' the rule set that | 26266 | rule set; those rules are ``spliced into'' the rule set that |
| 25949 | imports them. For example, if @samp{[f(a+b) := f(a) + f(b), | 26267 | imports them. For example, if @samp{[f(a+b) := f(a) + f(b), |
| 25950 | f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, | 26268 | f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, |
| 25951 | then the rule set @samp{[f(0) := 0, import(linearF)]} will apply | 26269 | then the rule set @samp{[f(0) := 0, import(linearF)]} will apply |
| 25952 | all three rules. It is possible to modify the imported rules | 26270 | all three rules. It is possible to modify the imported rules |
| 25953 | slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports | 26271 | slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports |
| 25954 | the rule set @cite{x} with all occurrences of @c{$v_1$} | 26272 | the rule set @expr{x} with all occurrences of |
| 25955 | @cite{v1}, as either | 26273 | @texline @tmath{v_1}, |
| 25956 | a variable name or a function name, replaced with @c{$x_1$} | 26274 | @infoline @expr{v1}, |
| 25957 | @cite{x1} and | 26275 | as either a variable name or a function name, replaced with |
| 25958 | so 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} | 26278 | and so on. (If |
| 26279 | @texline @tmath{v_1} | ||
| 26280 | @infoline @expr{v1} | ||
| 26281 | is used as a function name, then | ||
| 26282 | @texline @tmath{x_1} | ||
| 26283 | @infoline @expr{x1} | ||
| 25961 | must be either a function name itself or a @w{@samp{< >}} nameless | 26284 | must be either a function name itself or a @w{@samp{< >}} nameless |
| 25962 | function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, | 26285 | function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, |
| 25963 | import(linearF, f, g)]} applies the linearity rules to the function | 26286 | import(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 |
| 25975 | This pattern matches exactly @cite{x}; variable names in @cite{x} are | 26298 | This pattern matches exactly @expr{x}; variable names in @expr{x} are |
| 25976 | not interpreted as meta-variables. The only flexibility is that | 26299 | not interpreted as meta-variables. The only flexibility is that |
| 25977 | numbers are compared for numeric equality, so that the pattern | 26300 | numbers 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 |
| 25989 | Here @cite{x} must be a function call @samp{f(x1,x2,@dots{})}. This | 26312 | Here @expr{x} must be a function call @samp{f(x1,x2,@dots{})}. This |
| 25990 | pattern matches a call to function @cite{f} with the specified | 26313 | pattern matches a call to function @expr{f} with the specified |
| 25991 | argument patterns. No special knowledge of the properties of the | 26314 | argument patterns. No special knowledge of the properties of the |
| 25992 | function @cite{f} is used in this case; @samp{+} is not commutative or | 26315 | function @expr{f} is used in this case; @samp{+} is not commutative or |
| 25993 | associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}} | 26316 | associative. Unlike @code{quote}, the arguments @samp{x1,x2,@dots{}} |
| 25994 | are treated as patterns. If you wish them to be treated ``plainly'' | 26317 | are treated as patterns. If you wish them to be treated ``plainly'' |
| 25995 | as well, you must enclose them with more @code{plain} markers: | 26318 | as 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 |
| 26003 | Here @cite{x} must be a variable name. This must appear as an | 26326 | Here @expr{x} must be a variable name. This must appear as an |
| 26004 | argument to a function or an element of a vector; it specifies that | 26327 | argument to a function or an element of a vector; it specifies that |
| 26005 | the argument or element is optional. | 26328 | the argument or element is optional. |
| 26006 | As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||}, | 26329 | As an argument to @samp{+}, @samp{-}, @samp{*}, @samp{&&}, or @samp{||}, |
| 26007 | or as the second argument to @samp{/} or @samp{^}, the value @var{def} | 26330 | or as the second argument to @samp{/} or @samp{^}, the value @var{def} |
| 26008 | may be omitted. The pattern @samp{x + opt(y)} matches a sum by | 26331 | may be omitted. The pattern @samp{x + opt(y)} matches a sum by |
| 26009 | binding one summand to @cite{x} and the other to @cite{y}, and it | 26332 | binding one summand to @expr{x} and the other to @expr{y}, and it |
| 26010 | matches anything else by binding the whole expression to @cite{x} and | 26333 | matches anything else by binding the whole expression to @expr{x} and |
| 26011 | zero to @cite{y}. The other operators above work similarly.@refill | 26334 | zero to @expr{y}. The other operators above work similarly. |
| 26012 | 26335 | ||
| 26013 | For general miscellaneous functions, the default value @code{def} | 26336 | For general miscellaneous functions, the default value @code{def} |
| 26014 | must be specified. Optional arguments are dropped starting with | 26337 | must be specified. Optional arguments are dropped starting with |
| 26015 | the rightmost one during matching. For example, the pattern | 26338 | the 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)}, |
| 26017 | or @samp{f(a,b,c)}. Default values of zero and @cite{b} are | 26340 | or @samp{f(a,b,c)}. Default values of zero and @expr{b} are |
| 26018 | supplied in this example for the omitted arguments. Note that | 26341 | supplied in this example for the omitted arguments. Note that |
| 26019 | the literal variable @cite{b} will be the default in the latter | 26342 | the literal variable @expr{b} will be the default in the latter |
| 26020 | case, @emph{not} the value that matched the meta-variable @cite{b}. | 26343 | case, @emph{not} the value that matched the meta-variable @expr{b}. |
| 26021 | In other words, the default @var{def} is effectively quoted. | 26344 | In 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 :: |
| 26029 | This matches the pattern @cite{x}, with the attached condition | 26352 | This 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 &&& |
| 26038 | This matches anything that matches both pattern @cite{x} and | 26361 | This matches anything that matches both pattern @expr{x} and |
| 26039 | pattern @cite{y}. It is the same as @samp{x &&& y}. | 26362 | pattern @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 ||| |
| 26048 | This matches anything that matches either pattern @cite{x} or | 26371 | This matches anything that matches either pattern @expr{x} or |
| 26049 | pattern @cite{y}. It is the same as @w{@samp{x ||| y}}. | 26372 | pattern @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 !!! |
| 26057 | This matches anything that does not match pattern @cite{x}. | 26380 | This matches anything that does not match pattern @expr{x}. |
| 26058 | It is the same as @samp{!!! x}. | 26381 | It 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) |
| 26065 | This matches any vector of one or more elements. The first | 26388 | This matches any vector of one or more elements. The first |
| 26066 | element is matched to @cite{h}; a vector of the remaining | 26389 | element is matched to @expr{h}; a vector of the remaining |
| 26067 | elements is matched to @cite{t}. Note that vectors of fixed | 26390 | elements is matched to @expr{t}. Note that vectors of fixed |
| 26068 | length can also be matched as actual vectors: The rule | 26391 | length 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 |
| 26070 | to the rule @samp{[a,b] := [a+b]}. | 26393 | to 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) |
| 26077 | This is like @code{cons}, except that the @emph{last} element | 26400 | This is like @code{cons}, except that the @emph{last} element |
| 26078 | is matched to @cite{h}, with the remaining elements matched | 26401 | is matched to @expr{h}, with the remaining elements matched |
| 26079 | to @cite{t}. | 26402 | to @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) |
| 26086 | This matches any function call. The name of the function, in | 26409 | This matches any function call. The name of the function, in |
| 26087 | the form of a variable, is matched to @cite{f}. The arguments | 26410 | the form of a variable, is matched to @expr{f}. The arguments |
| 26088 | of the function, as a vector of zero or more objects, are | 26411 | of the function, as a vector of zero or more objects, are |
| 26089 | matched to @samp{args}. Constants, variables, and vectors | 26412 | matched to @samp{args}. Constants, variables, and vectors |
| 26090 | do @emph{not} match an @code{apply} pattern. For example, | 26413 | do @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) |
| 26154 | Special properties of and simplifications for the function call | 26477 | Special 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} |
| 26156 | is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a | 26479 | is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a |
| 26157 | shorthand notation for the @code{quote} function. This rule will | 26480 | shorthand notation for the @code{quote} function. This rule will |
| 26158 | not work as shown; instead of replacing @samp{q(foo)} with | 26481 | not 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 | |||
| 26160 | rule would be @samp{q(x) := plain(quote(x))}. | 26483 | rule would be @samp{q(x) := plain(quote(x))}. |
| 26161 | 26484 | ||
| 26162 | @item cons(h,t) | 26485 | @item cons(h,t) |
| 26163 | Where @cite{t} is a vector, this is converted into an expanded | 26486 | Where @expr{t} is a vector, this is converted into an expanded |
| 26164 | vector during rewrite processing. Note that @code{cons} is a regular | 26487 | vector during rewrite processing. Note that @code{cons} is a regular |
| 26165 | Calc function which normally does this anyway; the only way @code{cons} | 26488 | Calc function which normally does this anyway; the only way @code{cons} |
| 26166 | is treated specially by rewrites is that @code{cons} on the righthand | 26489 | is 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 | |||
| 26168 | have been turned off. | 26491 | have been turned off. |
| 26169 | 26492 | ||
| 26170 | @item rcons(t,h) | 26493 | @item rcons(t,h) |
| 26171 | Analogous to @code{cons} except putting @cite{h} at the @emph{end} of | 26494 | Analogous to @code{cons} except putting @expr{h} at the @emph{end} of |
| 26172 | the vector @cite{t}. | 26495 | the vector @expr{t}. |
| 26173 | 26496 | ||
| 26174 | @item apply(f,args) | 26497 | @item apply(f,args) |
| 26175 | Where @cite{f} is a variable and @var{args} is a vector, this | 26498 | Where @expr{f} is a variable and @var{args} is a vector, this |
| 26176 | is converted to a function call. Once again, note that @code{apply} | 26499 | is converted to a function call. Once again, note that @code{apply} |
| 26177 | is also a regular Calc function. | 26500 | is 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 |
| 26184 | The formula @cite{x} is handled in the usual way, then the | 26507 | The formula @expr{x} is handled in the usual way, then the |
| 26185 | default simplifications are applied to it even if they have | 26508 | default simplifications are applied to it even if they have |
| 26186 | been turned off normally. This allows you to treat any function | 26509 | been turned off normally. This allows you to treat any function |
| 26187 | similarly to the way @code{cons} and @code{apply} are always | 26510 | similarly 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 |
| 26197 | The formula @cite{x} has meta-variables substituted in the usual | 26520 | The formula @expr{x} has meta-variables substituted in the usual |
| 26198 | way, then algebraically simplified as if by the @kbd{a s} command. | 26521 | way, 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 |
| 26205 | The formula @cite{x} has meta-variables substituted in the normal | 26528 | The formula @expr{x} has meta-variables substituted in the normal |
| 26206 | way, then ``extendedly'' simplified as if by the @kbd{a e} command. | 26529 | way, 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 |
| 26220 | The expression @cite{x} is evaluated with meta-variables substituted. | 26543 | The expression @expr{x} is evaluated with meta-variables substituted. |
| 26221 | The @kbd{a s} command's simplifications are @emph{not} applied by | 26544 | The @kbd{a s} command's simplifications are @emph{not} applied by |
| 26222 | default, but @cite{x} can include calls to @code{evalsimp} or | 26545 | default, 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 |
| 26224 | of simplification. The | 26547 | of simplification. The |
| 26225 | result of @cite{x} is then bound to the meta-variable @cite{v}. As | 26548 | result of @expr{x} is then bound to the meta-variable @expr{v}. As |
| 26226 | usual, if this meta-variable has already been matched to something | 26549 | usual, if this meta-variable has already been matched to something |
| 26227 | else the two values must be equal; if the meta-variable is new then | 26550 | else the two values must be equal; if the meta-variable is new then |
| 26228 | it is bound to the result of the expression. This variable can then | 26551 | it is bound to the result of the expression. This variable can then |
| 26229 | appear in later conditions, and on the righthand side of the rule. | 26552 | appear in later conditions, and on the righthand side of the rule. |
| 26230 | In fact, @cite{v} may be any pattern in which case the result of | 26553 | In fact, @expr{v} may be any pattern in which case the result of |
| 26231 | evaluating @cite{x} is matched to that pattern, binding any | 26554 | evaluating @expr{x} is matched to that pattern, binding any |
| 26232 | meta-variables that appear in that pattern. Note that @code{let} | 26555 | meta-variables that appear in that pattern. Note that @code{let} |
| 26233 | can only appear by itself as a condition, or as one term of an | 26556 | can 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 |
| 26235 | an @samp{||} term or otherwise buried.@refill | 26558 | an @samp{||} term or otherwise buried. |
| 26236 | 26559 | ||
| 26237 | The alternate, equivalent form @samp{let(v, x)} is also recognized. | 26560 | The alternate, equivalent form @samp{let(v, x)} is also recognized. |
| 26238 | Note that the use of @samp{:=} by @code{let}, while still being | 26561 | Note 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. | |||
| 26249 | Note that, because the meta-variable @samp{ia} is otherwise unbound | 26572 | Note that, because the meta-variable @samp{ia} is otherwise unbound |
| 26250 | in this rule, the @code{let} condition itself always ``succeeds'' | 26573 | in this rule, the @code{let} condition itself always ``succeeds'' |
| 26251 | because no matter what @samp{1/a} evaluates to, it can successfully | 26574 | because no matter what @samp{1/a} evaluates to, it can successfully |
| 26252 | be bound to @code{ia}.@refill | 26575 | be bound to @code{ia}. |
| 26253 | 26576 | ||
| 26254 | Here's another example, for integrating cosines of linear | 26577 | Here's another example, for integrating cosines of linear |
| 26255 | terms: @samp{myint(cos(y),x) := sin(y)/b :: let([a,b,x] := lin(y,x))}. | 26578 | terms: @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 | |||
| 26260 | the coefficients @code{a} and @code{b} for use elsewhere in the rule. | 26583 | the 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 |
| 26262 | righthand side instead, but using @samp{sin(y)/b} avoids gratuitous | 26585 | righthand side instead, but using @samp{sin(y)/b} avoids gratuitous |
| 26263 | rearrangement of the argument of the sine.)@refill | 26586 | rearrangement 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 |
| 26324 | Remember the match as described above, but only if condition @cite{c} | 26647 | Remember the match as described above, but only if condition @expr{c} |
| 26325 | is true. For example, @samp{remember(n % 4 = 0)} in the above factorial | 26648 | is true. For example, @samp{remember(n % 4 = 0)} in the above factorial |
| 26326 | rule remembers only every fourth result. Note that @samp{remember(1)} | 26649 | rule remembers only every fourth result. Note that @samp{remember(1)} |
| 26327 | is equivalent to @samp{remember}, and @samp{remember(0)} has no effect. | 26650 | is equivalent to @samp{remember}, and @samp{remember(0)} has no effect. |
| @@ -26883,7 +27206,7 @@ or ran too long'' message. | |||
| 26883 | 27206 | ||
| 26884 | Another subtle difference between @code{EvalRules} and regular rewrites | 27207 | Another subtle difference between @code{EvalRules} and regular rewrites |
| 26885 | concerns rules that rewrite a formula into an identical formula. For | 27208 | concerns rules that rewrite a formula into an identical formula. For |
| 26886 | example, @samp{f(n) := f(floor(n))} ``fails to match'' when @cite{n} is | 27209 | example, @samp{f(n) := f(floor(n))} ``fails to match'' when @expr{n} is |
| 26887 | already an integer. But in @code{EvalRules} this case is detected only | 27210 | already an integer. But in @code{EvalRules} this case is detected only |
| 26888 | if the righthand side literally becomes the original formula before any | 27211 | if the righthand side literally becomes the original formula before any |
| 26889 | further simplification. This means that @samp{f(n) := f(floor(n))} will | 27212 | further 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 | |||
| 26927 | functions directly rather than going through the default simplifications. | 27250 | functions directly rather than going through the default simplifications. |
| 26928 | When it does this, @code{EvalRules} will not be able to override those | 27251 | When it does this, @code{EvalRules} will not be able to override those |
| 26929 | functions. For example, when you take the absolute value of the complex | 27252 | functions. For example, when you take the absolute value of the complex |
| 26930 | number @cite{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling | 27253 | number @expr{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling |
| 26931 | the multiplication, addition, and square root functions directly rather | 27254 | the multiplication, addition, and square root functions directly rather |
| 26932 | than applying the default simplifications to this formula. So an | 27255 | than 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} |
| 26934 | would not apply. (However, if you put Calc into symbolic mode so that | 27257 | would 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 |
| 26936 | root function, your rule will be able to apply. But if the complex | 27259 | root function, your rule will be able to apply. But if the complex |
| 26937 | number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated, | 27260 | number were @expr{(3,4)}, so that @samp{sqrt(25)} must be calculated, |
| 26938 | then symbolic mode will not help because @samp{sqrt(25)} can be | 27261 | then symbolic mode will not help because @samp{sqrt(25)} can be |
| 26939 | evaluated exactly to 5.) | 27262 | evaluated exactly to 5.) |
| 26940 | 27263 | ||
| @@ -27028,7 +27351,7 @@ Returning to the example of substituting the pattern | |||
| 27028 | finding suitable cases. Another solution would be to use the rule | 27351 | finding 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 |
| 27030 | if necessary. This rule will be the most effective way to do the job, | 27353 | if necessary. This rule will be the most effective way to do the job, |
| 27031 | but at the expense of making some changes that you might not desire.@refill | 27354 | but at the expense of making some changes that you might not desire. |
| 27032 | 27355 | ||
| 27033 | Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}. | 27356 | Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}. |
| 27034 | To make this work with the @w{@kbd{j r}} command so that it can be | 27357 | To 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, | |||
| 27036 | you might wish to write the rule as @samp{select(exp(x+y)) := | 27359 | you might wish to write the rule as @samp{select(exp(x+y)) := |
| 27037 | select(exp(x) exp(y))}. The @samp{select} markers will be | 27360 | select(exp(x) exp(y))}. The @samp{select} markers will be |
| 27038 | ignored by the regular @kbd{a r} command | 27361 | ignored by the regular @kbd{a r} command |
| 27039 | (@pxref{Selections with Rewrite Rules}).@refill | 27362 | (@pxref{Selections with Rewrite Rules}). |
| 27040 | 27363 | ||
| 27041 | A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}. | 27364 | A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}. |
| 27042 | This will simplify the formula whenever @cite{b} and/or @cite{c} can | 27365 | This will simplify the formula whenever @expr{b} and/or @expr{c} can |
| 27043 | be made simpler by squaring. For example, applying this rule to | 27366 | be 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 |
| 27045 | Symbolic Mode has been enabled to keep the square root from being | 27368 | Symbolic 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 |
| 27062 | The following rule set, contributed by @c{Fran\c cois} | 27385 | The 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 |
| 27065 | Quaternions have four components, and are here represented by function | 27388 | Pinard, implements @dfn{quaternions}, a generalization of the concept of |
| 27066 | calls @samp{quat(@var{w}, [@var{x}, @var{y}, @var{z}])} with ``real | 27389 | complex numbers. Quaternions have four components, and are here |
| 27067 | part'' @var{w} and the three ``imaginary'' parts collected into a | 27390 | represented by function calls @samp{quat(@var{w}, [@var{x}, @var{y}, |
| 27068 | vector. Various arithmetical operations on quaternions are supported. | 27391 | @var{z}])} with ``real part'' @var{w} and the three ``imaginary'' parts |
| 27069 | To use these rules, either add them to @code{EvalRules}, or create a | 27392 | collected into a vector. Various arithmetical operations on quaternions |
| 27070 | command based on @kbd{a r} for simplifying quaternion formulas. | 27393 | are supported. To use these rules, either add them to @code{EvalRules}, |
| 27071 | A convenient way to enter quaternions would be a command defined by | 27394 | or create a command based on @kbd{a r} for simplifying quaternion |
| 27072 | a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}. | 27395 | formulas. A convenient way to enter quaternions would be a command |
| 27396 | defined 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 | ||
| 27096 | Quaternions, like matrices, have non-commutative multiplication. | 27421 | Quaternions, like matrices, have non-commutative multiplication. |
| 27097 | In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if | 27422 | In 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} |
| 27099 | rule above uses @code{plain} to prevent Calc from rearranging the | 27424 | rule above uses @code{plain} to prevent Calc from rearranging the |
| 27100 | product. It may also be wise to add the line @samp{[quat(), matrix]} | 27425 | product. It may also be wise to add the line @samp{[quat(), matrix]} |
| 27101 | to the @code{Decls} matrix, to ensure that Calc's other algebraic | 27426 | to 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'') | |||
| 27142 | or @samp{u} (for ``micro'') followed by a name in the unit table. | 27467 | or @samp{u} (for ``micro'') followed by a name in the unit table. |
| 27143 | A substantial table of built-in units is provided with Calc; | 27468 | A 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 | ||
| 27147 | Note that if the value part of a units expression is exactly @samp{1}, | 27472 | Note that if the value part of a units expression is exactly @samp{1}, |
| 27148 | it will be removed by the Calculator's automatic algebra routines: The | 27473 | it will be removed by the Calculator's automatic algebra routines: The |
| 27149 | formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a | 27474 | formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a |
| 27150 | display anomaly, however; @samp{mm} will work just fine as a | 27475 | display anomaly, however; @samp{mm} will work just fine as a |
| 27151 | representation of one millimeter.@refill | 27476 | representation of one millimeter. |
| 27152 | 27477 | ||
| 27153 | You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working | 27478 | You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working |
| 27154 | with units expressions easier. Otherwise, you will have to remember | 27479 | with 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 | |||
| 27169 | simplify to @samp{5.023 m}. When different but compatible units are | 27494 | simplify to @samp{5.023 m}. When different but compatible units are |
| 27170 | added, the righthand term's units are converted to match those of the | 27495 | added, the righthand term's units are converted to match those of the |
| 27171 | lefthand term. @xref{Simplification Modes}, for a way to have this done | 27496 | lefthand term. @xref{Simplification Modes}, for a way to have this done |
| 27172 | automatically at all times.@refill | 27497 | automatically at all times. |
| 27173 | 27498 | ||
| 27174 | Units simplification also handles quotients of two units with the same | 27499 | Units simplification also handles quotients of two units with the same |
| 27175 | dimensionality, as in @w{@samp{2 in s/L cm}} to @samp{5.08 s/L}; fractional | 27500 | dimensionality, 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 | |||
| 27180 | applied to units expressions, in which case | 27505 | applied to units expressions, in which case |
| 27181 | the operation in question is applied only to the numeric part of the | 27506 | the operation in question is applied only to the numeric part of the |
| 27182 | expression. Finally, trigonometric functions of quantities with units | 27507 | expression. Finally, trigonometric functions of quantities with units |
| 27183 | of angle are evaluated, regardless of the current angular mode.@refill | 27508 | of 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 | |||
| 27261 | absolute temperatures. The value on the stack must be a simple units | 27586 | absolute temperatures. The value on the stack must be a simple units |
| 27262 | expression with units of temperature only. This command would convert | 27587 | expression 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 |
| 27264 | Fahrenheit scale.@refill | 27589 | Fahrenheit 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 |
| 27273 | formula. These commands essentially replace every term of the formula | 27598 | formula. These commands essentially replace every term of the formula |
| 27274 | that does or doesn't (respectively) look like a unit name by the | 27599 | that does or doesn't (respectively) look like a unit name by the |
| 27275 | constant 1, then resimplify the formula.@refill | 27600 | constant 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 | ||
| 27398 | The unit @code{e} stands for the elementary (electron) unit of charge; | 27723 | The unit @code{e} stands for the elementary (electron) unit of charge; |
| 27399 | because algebra command could mistake this for the special constant | 27724 | because 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 |
| 27401 | preferable to @code{e}. | 27726 | preferable to @code{e}. |
| 27402 | 27727 | ||
| 27403 | The name @code{g} stands for one gram of mass; there is also @code{gf}, | 27728 | The name @code{g} stands for one gram of mass; there is also @code{gf}, |
| 27404 | one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.) | 27729 | one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}.) |
| 27405 | Meanwhile, one ``@cite{g}'' of acceleration is denoted @code{ga}. | 27730 | Meanwhile, one ``@expr{g}'' of acceleration is denoted @code{ga}. |
| 27406 | 27731 | ||
| 27407 | The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is | 27732 | The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is |
| 27408 | a metric ton of @samp{1000 kg}. | 27733 | a metric ton of @samp{1000 kg}. |
| @@ -27634,12 +27959,15 @@ variable. The other arithmetic stores are @kbd{s -}, @kbd{s *}, @kbd{s /}, | |||
| 27634 | and @kbd{s ]} which decrease or increase a variable by one. | 27959 | and @kbd{s ]} which decrease or increase a variable by one. |
| 27635 | 27960 | ||
| 27636 | All the arithmetic stores accept the Inverse prefix to reverse the | 27961 | All the arithmetic stores accept the Inverse prefix to reverse the |
| 27637 | order of the operands. If @cite{v} represents the contents of the | 27962 | order of the operands. If @expr{v} represents the contents of the |
| 27638 | variable, and @cite{a} is the value drawn from the stack, then regular | 27963 | variable, 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 | 27967 | but @kbd{I s -} assigns |
| 27968 | @texline @tmath{v \coloneq a - v}. | ||
| 27969 | @infoline @expr{v := a - v}. | ||
| 27970 | While @kbd{I s *} might seem pointless, it is | ||
| 27643 | useful if matrix multiplication is involved. Actually, all the | 27971 | useful if matrix multiplication is involved. Actually, all the |
| 27644 | arithmetic stores use formulas designed to behave usefully both | 27972 | arithmetic stores use formulas designed to behave usefully both |
| 27645 | forwards and backwards: | 27973 | forwards and backwards: |
| @@ -27666,7 +27994,7 @@ minus-two minus the variable. | |||
| 27666 | 27994 | ||
| 27667 | The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -}, | 27995 | The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -}, |
| 27668 | etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous | 27996 | etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous |
| 27669 | arithmetic stores that don't remove the value @cite{a} from the stack. | 27997 | arithmetic stores that don't remove the value @expr{a} from the stack. |
| 27670 | 27998 | ||
| 27671 | All arithmetic stores report the new value of the variable in the | 27999 | All arithmetic stores report the new value of the variable in the |
| 27672 | Trail for your information. They signal an error if the variable | 28000 | Trail for your information. They signal an error if the variable |
| @@ -27692,8 +28020,8 @@ takes the hyperbolic arcsine of the variable contents. | |||
| 27692 | 28020 | ||
| 27693 | If the mapping function takes two or more arguments, the additional | 28021 | If the mapping function takes two or more arguments, the additional |
| 27694 | arguments are taken from the stack; the old value of the variable | 28022 | arguments are taken from the stack; the old value of the variable |
| 27695 | is provided as the first argument. Thus @kbd{s m -} with @cite{a} | 28023 | is provided as the first argument. Thus @kbd{s m -} with @expr{a} |
| 27696 | on the stack computes @cite{v - a}, just like @kbd{s -}. With the | 28024 | on the stack computes @expr{v - a}, just like @kbd{s -}. With the |
| 27697 | Inverse prefix, the variable's original value becomes the @emph{last} | 28025 | Inverse prefix, the variable's original value becomes the @emph{last} |
| 27698 | argument instead of the first. Thus @kbd{I s m -} is also | 28026 | argument instead of the first. Thus @kbd{I s m -} is also |
| 27699 | equivalent to @kbd{I s -}. | 28027 | equivalent to @kbd{I s -}. |
| @@ -27716,7 +28044,7 @@ Until you store something in them, variables are ``void,'' that is, they | |||
| 27716 | contain no value at all. If they appear in an algebraic formula they | 28044 | contain no value at all. If they appear in an algebraic formula they |
| 27717 | will be left alone even if you press @kbd{=} (@code{calc-evaluate}). | 28045 | will be left alone even if you press @kbd{=} (@code{calc-evaluate}). |
| 27718 | The @kbd{s u} (@code{calc-unstore}) command returns a variable to the | 28046 | The @kbd{s u} (@code{calc-unstore}) command returns a variable to the |
| 27719 | void state.@refill | 28047 | void state. |
| 27720 | 28048 | ||
| 27721 | The only variables with predefined values are the ``special constants'' | 28049 | The 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 | |||
| 27728 | normally void). | 28056 | normally void). |
| 27729 | 28057 | ||
| 27730 | Note that @code{var-pi} doesn't actually have 3.14159265359 stored | 28058 | Note that @code{var-pi} doesn't actually have 3.14159265359 stored |
| 27731 | in it, but rather a special magic value that evaluates to @c{$\pi$} | 28059 | in it, but rather a special magic value that evaluates to @cpi{} |
| 27732 | @cite{pi} | ||
| 27733 | at the current precision. Likewise @code{var-e}, @code{var-i}, and | 28060 | at 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. |
| 27735 | If you recall a value from @code{pi} and store it back, this magic | 28062 | If 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 |
| 27914 | rules; and @code{PlotData@var{n}} variables generated | 28241 | rules; and @code{PlotData@var{n}} variables generated |
| 27915 | by the graphics commands. (You can still save these variables by | 28242 | by the graphics commands. (You can still save these variables by |
| 27916 | explicitly naming them in an @kbd{s p} command.)@refill | 28243 | explicitly 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 |
| 27938 | If you have an expression like @samp{a+b^2} on the stack and you wish to | 28265 | If you have an expression like @samp{a+b^2} on the stack and you wish to |
| 27939 | compute its value where @cite{b=3}, you can simply store 3 in @cite{b} and | 28266 | compute its value where @expr{b=3}, you can simply store 3 in @expr{b} and |
| 27940 | then press @kbd{=} to reevaluate the formula. This has the side-effect | 28267 | then press @kbd{=} to reevaluate the formula. This has the side-effect |
| 27941 | of leaving the stored value of 3 in @cite{b} for future operations. | 28268 | of leaving the stored value of 3 in @expr{b} for future operations. |
| 27942 | 28269 | ||
| 27943 | The @kbd{s l} (@code{calc-let}) command evaluates a formula under a | 28270 | The @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}}. | |||
| 27961 | The @kbd{a b} (@code{calc-substitute}) command is another way to substitute | 28288 | The @kbd{a b} (@code{calc-substitute}) command is another way to substitute |
| 27962 | a variable with a value in a formula. It does an actual substitution | 28289 | a variable with a value in a formula. It does an actual substitution |
| 27963 | rather than temporarily assigning the variable and evaluating. For | 28290 | rather than temporarily assigning the variable and evaluating. For |
| 27964 | example, letting @cite{n=2} in @samp{f(n pi)} with @kbd{a b} will | 28291 | example, letting @expr{n=2} in @samp{f(n pi)} with @kbd{a b} will |
| 27965 | produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)} | 28292 | produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)} |
| 27966 | since the evaluation step will also evaluate @code{pi}. | 28293 | since 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 | |||
| 28145 | the interval (whether the interval is open or closed is ignored). | 28472 | the interval (whether the interval is open or closed is ignored). |
| 28146 | 28473 | ||
| 28147 | The ``x'' entry may also be a number, in which case Calc uses the | 28474 | The ``x'' entry may also be a number, in which case Calc uses the |
| 28148 | sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc. | 28475 | sequence 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 | ||
| 28151 | The ``y'' entry may be any formula instead of a vector. Calc effectively | 28478 | The ``y'' entry may be any formula instead of a vector. Calc effectively |
| 28152 | uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula; | 28479 | uses @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. | |||
| 28169 | In this case the ``x'' vector or interval you specified is not directly | 28496 | In this case the ``x'' vector or interval you specified is not directly |
| 28170 | visible in the graph. For example, if ``x'' is the interval @samp{[0..360]} | 28497 | visible in the graph. For example, if ``x'' is the interval @samp{[0..360]} |
| 28171 | and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph | 28498 | and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph |
| 28172 | will be a circle.@refill | 28499 | will be a circle. |
| 28173 | 28500 | ||
| 28174 | Also, ``x'' and ``y'' may each be variable names, in which case Calc | 28501 | Also, ``x'' and ``y'' may each be variable names, in which case Calc |
| 28175 | looks for suitable vectors, intervals, or formulas stored in those | 28502 | looks 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 | |||
| 28224 | the same length); either or both may instead be interval forms. The | 28551 | the 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 |
| 28226 | in ``x'', and the same number of columns as elements in ``y''. The | 28553 | in ``x'', and the same number of columns as elements in ``y''. The |
| 28227 | result is a surface plot where @c{$z_{ij}$} | 28554 | result is a surface plot where |
| 28228 | @cite{z_ij} is the height of the point | 28555 | @texline @tmath{z_{ij}} |
| 28229 | at coordinate @cite{(x_i, y_j)} on the surface. The 3D graph will | 28556 | @infoline @expr{z_ij} |
| 28557 | is the height of the point | ||
| 28558 | at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will | ||
| 28230 | be displayed from a certain default viewpoint; you can change this | 28559 | be displayed from a certain default viewpoint; you can change this |
| 28231 | viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} | 28560 | viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} |
| 28232 | buffer as described later. See the GNUPLOT 3.0 documentation for a | 28561 | buffer 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 | ||
| 28318 | A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way | 28647 | A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way |
| 28319 | stack entries are interpreted as curves. With a positive prefix | 28648 | stack entries are interpreted as curves. With a positive prefix |
| 28320 | argument @cite{n}, the top @cite{n} stack entries are ``y'' values | 28649 | argument @expr{n}, the top @expr{n} stack entries are ``y'' values |
| 28321 | for @cite{n} different curves which share a common ``x'' value in | 28650 | for @expr{n} different curves which share a common ``x'' value in |
| 28322 | the @cite{n+1}st stack entry. (Thus @kbd{g a} with no prefix | 28651 | the @expr{n+1}st stack entry. (Thus @kbd{g a} with no prefix |
| 28323 | argument is equivalent to @kbd{C-u 1 g a}.) | 28652 | argument is equivalent to @kbd{C-u 1 g a}.) |
| 28324 | 28653 | ||
| 28325 | A prefix of zero or plain @kbd{C-u} means to take two stack entries, | 28654 | A 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 | ||
| 28329 | A negative prefix argument tells Calc to read @cite{n} vectors from | 28658 | A negative prefix argument tells Calc to read @expr{n} vectors from |
| 28330 | the stack; each vector @cite{[x, y]} describes an independent curve. | 28659 | the stack; each vector @expr{[x, y]} describes an independent curve. |
| 28331 | This is the only form of @kbd{g a} that creates several curves at once | 28660 | This is the only form of @kbd{g a} that creates several curves at once |
| 28332 | that don't have common ``x'' values. (Of course, the range of ``x'' | 28661 | that don't have common ``x'' values. (Of course, the range of ``x'' |
| 28333 | values covered by all the curves ought to be roughly the same if | 28662 | values covered by all the curves ought to be roughly the same if |
| 28334 | they are to look nice on the same graph.) | 28663 | they are to look nice on the same graph.) |
| 28335 | 28664 | ||
| 28336 | For example, to plot @c{$\sin n x$} | 28665 | For example, to plot |
| 28337 | @cite{sin(n x)} for integers @cite{n} | 28666 | @texline @tmath{\sin n x} |
| 28667 | @infoline @expr{sin(n x)} | ||
| 28668 | for integers @expr{n} | ||
| 28338 | from 1 to 5, you could use @kbd{v x} to create a vector of integers | 28669 | from 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)} |
| 28340 | across this vector. The resulting vector of formulas is suitable | 28671 | across this vector. The resulting vector of formulas is suitable |
| 28341 | for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f} | 28672 | for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f} |
| 28342 | command. | 28673 | command. |
| @@ -28346,11 +28677,11 @@ command. | |||
| 28346 | The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve | 28677 | The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve |
| 28347 | to the graph. It is not legal to intermix 2D and 3D curves in a | 28678 | to the graph. It is not legal to intermix 2D and 3D curves in a |
| 28348 | single graph. This command takes three arguments, ``x'', ``y'', | 28679 | single graph. This command takes three arguments, ``x'', ``y'', |
| 28349 | and ``z'', from the stack. With a positive prefix @cite{n}, it | 28680 | and ``z'', from the stack. With a positive prefix @expr{n}, it |
| 28350 | takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n} | 28681 | takes @expr{n+2} arguments (common ``x'' and ``y'', plus @expr{n} |
| 28351 | separate ``z''s). With a zero prefix, it takes three stack entries | 28682 | separate ``z''s). With a zero prefix, it takes three stack entries |
| 28352 | but the ``z'' entry is a vector of curve values. With a negative | 28683 | but the ``z'' entry is a vector of curve values. With a negative |
| 28353 | prefix @cite{-n}, it takes @cite{n} vectors of the form @cite{[x, y, z]}. | 28684 | prefix @expr{-n}, it takes @expr{n} vectors of the form @expr{[x, y, z]}. |
| 28354 | The @kbd{g A} command works by adding a @code{splot} (surface-plot) | 28685 | The @kbd{g A} command works by adding a @code{splot} (surface-plot) |
| 28355 | command to the @samp{*Gnuplot Commands*} buffer. | 28686 | command to the @samp{*Gnuplot Commands*} buffer. |
| 28356 | 28687 | ||
| @@ -28469,13 +28800,13 @@ a blank line, displays the default number of points used for all | |||
| 28469 | graphs created by @kbd{g a} that don't specify the resolution explicitly. | 28800 | graphs created by @kbd{g a} that don't specify the resolution explicitly. |
| 28470 | With a negative prefix argument, this command changes or displays | 28801 | With a negative prefix argument, this command changes or displays |
| 28471 | the default value (initially 5) used for 3D graphs created by @kbd{g A}. | 28802 | the default value (initially 5) used for 3D graphs created by @kbd{g A}. |
| 28472 | Note that a 3D setting of 5 means that a total of @cite{5^2 = 25} points | 28803 | Note that a 3D setting of 5 means that a total of @expr{5^2 = 25} points |
| 28473 | will be computed for the surface. | 28804 | will be computed for the surface. |
| 28474 | 28805 | ||
| 28475 | Data values in the graph of a function are normally computed to a | 28806 | Data values in the graph of a function are normally computed to a |
| 28476 | precision of five digits, regardless of the current precision at the | 28807 | precision of five digits, regardless of the current precision at the |
| 28477 | time. This is usually more than adequate, but there are cases where | 28808 | time. This is usually more than adequate, but there are cases where |
| 28478 | it will not be. For example, plotting @cite{1 + x} with @cite{x} in the | 28809 | it will not be. For example, plotting @expr{1 + x} with @expr{x} in the |
| 28479 | interval @samp{[0 ..@: 1e-6]} will round all the data points down | 28810 | interval @samp{[0 ..@: 1e-6]} will round all the data points down |
| 28480 | to 1.0! Putting the command @samp{set precision @var{n}} in the | 28811 | to 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 | |||
| 28621 | picture of the graph composed of characters like @code{-} and @code{|} | 28952 | picture of the graph composed of characters like @code{-} and @code{|} |
| 28622 | to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. | 28953 | to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. |
| 28623 | The graph is made the same size as the Emacs screen, which on most | 28954 | The graph is made the same size as the Emacs screen, which on most |
| 28624 | dumb terminals will be @c{$80\times24$} | 28955 | dumb terminals will be |
| 28625 | @asis{80x24} characters. The graph is displayed in | 28956 | @texline @tmath{80\times24} |
| 28957 | @infoline 80x24 | ||
| 28958 | characters. The graph is displayed in | ||
| 28626 | an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit | 28959 | an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit |
| 28627 | the recursive edit and return to Calc. Note that the @code{dumb} | 28960 | the recursive edit and return to Calc. Note that the @code{dumb} |
| 28628 | device is present only in GNUPLOT 3.0 and later versions. | 28961 | device 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 | |||
| 28824 | it appears on the screen, including line numbers if they are enabled. | 29157 | it appears on the screen, including line numbers if they are enabled. |
| 28825 | 29158 | ||
| 28826 | A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number | 29159 | A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number |
| 28827 | of lines killed. A positive argument kills the current line and @cite{n-1} | 29160 | of lines killed. A positive argument kills the current line and @expr{n-1} |
| 28828 | lines below it. A negative argument kills the @cite{-n} lines above the | 29161 | lines below it. A negative argument kills the @expr{-n} lines above the |
| 28829 | current line. Again this mirrors the behavior of the standard Emacs | 29162 | current 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} |
| 28831 | with no argument copies only the number itself into the kill ring, whereas | 29164 | with 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 | ||
| 28869 | A numeric prefix argument grabs the specified number of lines around | 29202 | A numeric prefix argument grabs the specified number of lines around |
| 28870 | point, ignoring the mark. A positive prefix grabs from point to the | 29203 | point, 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 |
| 28872 | to the end of the current line); a negative prefix grabs from point | 29205 | to the end of the current line); a negative prefix grabs from point |
| 28873 | back to the @cite{n+1}st preceding newline. In these cases the text | 29206 | back to the @expr{n+1}st preceding newline. In these cases the text |
| 28874 | that is grabbed is exactly the same as the text that @kbd{C-k} would | 29207 | that is grabbed is exactly the same as the text that @kbd{C-k} would |
| 28875 | delete given that prefix argument. | 29208 | delete given that prefix argument. |
| 28876 | 29209 | ||
| @@ -28926,12 +29259,13 @@ If you give a positive numeric prefix argument @var{n}, then each line | |||
| 28926 | will be split up into columns of width @var{n}; each column is parsed | 29259 | will be split up into columns of width @var{n}; each column is parsed |
| 28927 | separately as a matrix element. If a line contained | 29260 | separately 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 |
| 28929 | would correctly split the line into two error forms.@refill | 29262 | would 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 |
| 28932 | constituent rows and columns. (If it is a @c{$1\times1$} | 29265 | constituent 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 |
| 29268 | matrix, 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 | ||
| 28985 | With a prefix argument, @kbd{y} inserts several numbers, one per line. | 29319 | With a prefix argument, @kbd{y} inserts several numbers, one per line. |
| 28986 | A positive argument inserts the specified number of values from the top | 29320 | A positive argument inserts the specified number of values from the top |
| 28987 | of the stack. A negative argument inserts the @cite{n}th value from the | 29321 | of the stack. A negative argument inserts the @expr{n}th value from the |
| 28988 | top of the stack. An argument of zero inserts the entire stack. Note | 29322 | top of the stack. An argument of zero inserts the entire stack. Note |
| 28989 | that @kbd{y} with an argument of 1 is slightly different from @kbd{y} | 29323 | that @kbd{y} with an argument of 1 is slightly different from @kbd{y} |
| 28990 | with no argument; the former always copies full lines, whereas the | 29324 | with 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 | |||
| 28999 | display style (@pxref{Vector and Matrix Formats}) or change the current | 29333 | display style (@pxref{Vector and Matrix Formats}) or change the current |
| 29000 | display language (@pxref{Language Modes}) before doing this. Also, note | 29334 | display language (@pxref{Language Modes}) before doing this. Also, note |
| 29001 | that this command replaces a linear region of text (as grabbed by | 29335 | that 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 | ||
| 29004 | If the editing buffer is in overwrite (as opposed to insert) mode, | 29338 | If the editing buffer is in overwrite (as opposed to insert) mode, |
| 29005 | and the @kbd{C-u} prefix was not used, then the yanked number will | 29339 | and 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 * |
| 29188 | is the same as @key{y^x}. | 29522 | is the same as @key{y^x}. |
| 29189 | @item INV / | 29523 | @item INV / |
| 29190 | is the same as @key{INV y^x} (the @cite{x}th root of @cite{y}). | 29524 | is 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 |
| 29192 | are the same as @key{SIN} / @kbd{INV SIN}. | 29526 | are 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} | |||
| 29253 | prefix keys. | 29587 | prefix 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 |
| 29256 | number @cite{i = (0, 1)}. | 29590 | number @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} |
| 29259 | extracts the imaginary part. | 29593 | extracts 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. | |||
| 29382 | For example, you could simulate @key{MAP^} using @key{MAP$} with | 29717 | For example, you could simulate @key{MAP^} using @key{MAP$} with |
| 29383 | the formula @samp{x^y}. | 29718 | the formula @samp{x^y}. |
| 29384 | 29719 | ||
| 29385 | The @kbd{"x"} key pushes the variable name @cite{x} onto the | 29720 | The @kbd{"x"} key pushes the variable name @expr{x} onto the |
| 29386 | stack. To build the formula @cite{x^2 + 6}, you would use the | 29721 | stack. To build the formula @expr{x^2 + 6}, you would use the |
| 29387 | key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be | 29722 | key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be |
| 29388 | suitable for use with the @key{MAP$} key described above. | 29723 | suitable for use with the @key{MAP$} key described above. |
| 29389 | With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the | 29724 | With @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 |
| 29556 | The formula @cite{n>2} will be pushed onto the Calc stack, and | 29891 | The formula @expr{n>2} will be pushed onto the Calc stack, and |
| 29557 | the top of stack will be copied back into the editing buffer. | 29892 | the top of stack will be copied back into the editing buffer. |
| 29558 | This means that spaces will appear around the @samp{>} symbol | 29893 | This means that spaces will appear around the @samp{>} symbol |
| 29559 | to match Calc's usual display style: | 29894 | to match Calc's usual display style: |
| @@ -29681,8 +30016,7 @@ in the file as well as the rounded-down number. | |||
| 29681 | 30016 | ||
| 29682 | Embedded buffers remember active formulas for as long as they | 30017 | Embedded buffers remember active formulas for as long as they |
| 29683 | exist in Emacs memory. Suppose you have an embedded formula | 30018 | exist in Emacs memory. Suppose you have an embedded formula |
| 29684 | which is @c{$\pi$} | 30019 | which is @cpi{} to the normal 12 decimal places, and then |
| 29685 | @cite{pi} to the normal 12 decimal places, and then | ||
| 29686 | type @w{@kbd{C-u 5 d n}} to display only five decimal places. | 30020 | type @w{@kbd{C-u 5 d n}} to display only five decimal places. |
| 29687 | If you then type @kbd{d n}, all 12 places reappear because the | 30021 | If you then type @kbd{d n}, all 12 places reappear because the |
| 29688 | full number is still there on the Calc stack. More surprisingly, | 30022 | full 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 |
| 29823 | records @cite{5} as the stored value of @code{foo} for the | 30157 | records @expr{5} as the stored value of @code{foo} for the |
| 29824 | purposes of Embedded mode operations in the current buffer. It | 30158 | purposes of Embedded mode operations in the current buffer. It |
| 29825 | does @emph{not} actually store @cite{5} as the ``global'' value | 30159 | does @emph{not} actually store @expr{5} as the ``global'' value |
| 29826 | of @code{foo}, however. Regular Calc operations, and Embedded | 30160 | of @code{foo}, however. Regular Calc operations, and Embedded |
| 29827 | formulas in other buffers, will not see this assignment. | 30161 | formulas 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 | |||
| 29891 | mode. Then, we have to find a way to get Embedded mode to notice | 30225 | mode. Then, we have to find a way to get Embedded mode to notice |
| 29892 | the change. The @kbd{M-# u} or @kbd{M-# =} | 30226 | the 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 |
| 29894 | to do this.@refill | 30228 | to do this. |
| 29895 | 30229 | ||
| 29896 | @example | 30230 | @example |
| 29897 | foo := 6 | 30231 | foo := 6 |
| @@ -30458,7 +30792,7 @@ performing their usual functions. Press @kbd{C-x )} to end recording. | |||
| 30458 | Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to | 30792 | Press shift-@kbd{X} (or the standard Emacs key sequence @kbd{C-x e}) to |
| 30459 | execute your keyboard macro by replaying the recorded keystrokes. | 30793 | execute 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 |
| 30461 | information.@refill | 30795 | information. |
| 30462 | 30796 | ||
| 30463 | When you use @kbd{X} to invoke a keyboard macro, the entire macro is | 30797 | When you use @kbd{X} to invoke a keyboard macro, the entire macro is |
| 30464 | treated as a single command by the undo and trail features. The stack | 30798 | treated 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 | |||
| 30504 | just the @key{RET} key as in this example) will be something like | 30838 | just 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 |
| 30507 | descriptive command name if you wish.@refill | 30841 | descriptive command name if you wish. |
| 30508 | 30842 | ||
| 30509 | Macros defined by @kbd{Z K} act like single commands; they are executed | 30843 | Macros defined by @kbd{Z K} act like single commands; they are executed |
| 30510 | in the same way as by the @kbd{X} key. If you wish to define the macro | 30844 | in 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 | |||
| 30522 | the macro definition into full Emacs command names, like @code{calc-pop} | 30856 | the macro definition into full Emacs command names, like @code{calc-pop} |
| 30523 | and @code{calc-add}. Type @kbd{M-# M-#} to finish editing and update | 30857 | and @code{calc-add}. Type @kbd{M-# M-#} to finish editing and update |
| 30524 | the definition stored on the key, or, to cancel the edit, type | 30858 | the definition stored on the key, or, to cancel the edit, type |
| 30525 | @kbd{M-# x}.@refill | 30859 | @kbd{M-# x}. |
| 30526 | 30860 | ||
| 30527 | If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard | 30861 | If you give a negative numeric prefix argument to @kbd{Z E}, the keyboard |
| 30528 | macro is edited in spelled-out keystroke form. For example, the editing | 30862 | macro 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 | |||
| 30536 | same as is used in all of this manual's examples, except that the manual | 30870 | same as is used in all of this manual's examples, except that the manual |
| 30537 | takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take | 30871 | takes some liberties with spaces: When we say @kbd{' [1 2 3] @key{RET}}, we take |
| 30538 | it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}, | 30872 | it for granted that it is clear we really mean @kbd{' [1 @key{SPC} 2 @key{SPC} 3] @key{RET}}, |
| 30539 | which is what @code{read-kbd-macro} wants to see.@refill | 30873 | which is what @code{read-kbd-macro} wants to see. |
| 30540 | 30874 | ||
| 30541 | If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro | 30875 | If @file{macedit} is not available, @kbd{Z E} edits the keyboard macro |
| 30542 | in ``raw'' form; the editing buffer simply contains characters like | 30876 | in ``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). |
| 30544 | Editing in this mode, you will have to use @kbd{C-q} to enter new | 30878 | Editing in this mode, you will have to use @kbd{C-q} to enter new |
| 30545 | control characters into the buffer.@refill | 30879 | control 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 >} | |||
| 30646 | computes two to a nonnegative integer power. First, we push 1 on the | 30980 | computes two to a nonnegative integer power. First, we push 1 on the |
| 30647 | stack and then swap the integer argument back to the top. The @kbd{Z <} | 30981 | stack and then swap the integer argument back to the top. The @kbd{Z <} |
| 30648 | pops that argument leaving the 1 back on top of the stack. Then, we | 30982 | pops that argument leaving the 1 back on top of the stack. Then, we |
| 30649 | repeat a multiply-by-two step however many times.@refill | 30983 | repeat a multiply-by-two step however many times. |
| 30650 | 30984 | ||
| 30651 | Once again, the keyboard macro is executed as it is being entered. | 30985 | Once again, the keyboard macro is executed as it is being entered. |
| 30652 | In this case it is especially important to set up reasonable initial | 30986 | In 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 | |||
| 30666 | innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues | 31000 | innermost enclosing @kbd{Z <} @dots{} @kbd{Z >} loop and continues |
| 30667 | after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no | 31001 | after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no |
| 30668 | effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;} | 31002 | effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;} |
| 30669 | in the C language.@refill | 31003 | in 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 | |||
| 30680 | a temporary internal counter and initializes it with the value @var{init}. | 31014 | a temporary internal counter and initializes it with the value @var{init}. |
| 30681 | The @kbd{Z (} command then repeatedly pushes the counter value onto the | 31015 | The @kbd{Z (} command then repeatedly pushes the counter value onto the |
| 30682 | stack and executes @var{body} and @var{step}, adding @var{step} to the | 31016 | stack and executes @var{body} and @var{step}, adding @var{step} to the |
| 30683 | counter each time until the loop finishes.@refill | 31017 | counter each time until the loop finishes. |
| 30684 | 31018 | ||
| 30685 | @cindex Summations (by keyboard macros) | 31019 | @cindex Summations (by keyboard macros) |
| 30686 | By default, the loop finishes when the counter becomes greater than (or | 31020 | By 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 | |||
| 30880 | new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}. | 31214 | new function in an algebraic formula. Suppose we enter @kbd{yow @key{RET}}. |
| 30881 | Then the new function can be invoked by pushing two numbers on the | 31215 | Then the new function can be invoked by pushing two numbers on the |
| 30882 | stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic | 31216 | stack and typing @kbd{z m} or @kbd{x spam}, or by entering the algebraic |
| 30883 | formula @samp{yow(x,y)}.@refill | 31217 | formula @samp{yow(x,y)}. |
| 30884 | 31218 | ||
| 30885 | The fourth prompt is for the function's argument list. This is used to | 31219 | The fourth prompt is for the function's argument list. This is used to |
| 30886 | associate values on the stack with the variables that appear in the formula. | 31220 | associate 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 |
| 30892 | push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m} | 31226 | push the result on the stack. In other words, @kbd{10 @key{RET} 100 z m} |
| 30893 | would replace the 10 and 100 on the stack with the number 210, which is | 31227 | would 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 | ||
| 30898 | You can rearrange the order of the names before pressing @key{RET} to | 31232 | You can rearrange the order of the names before pressing @key{RET} to |
| 30899 | control which stack positions go to which variables in the formula. If | 31233 | control which stack positions go to which variables in the formula. If |
| @@ -30911,12 +31245,12 @@ using the argument list @samp{(a b)}. | |||
| 30911 | The final prompt is a y-or-n question concerning what to do if symbolic | 31245 | The final prompt is a y-or-n question concerning what to do if symbolic |
| 30912 | arguments are given to your function. If you answer @kbd{y}, then | 31246 | arguments are given to your function. If you answer @kbd{y}, then |
| 30913 | executing @kbd{z m} (using the original argument list @samp{(a b)}) with | 31247 | executing @kbd{z m} (using the original argument list @samp{(a b)}) with |
| 30914 | arguments @cite{10} and @cite{x} will leave the function in symbolic | 31248 | arguments @expr{10} and @expr{x} will leave the function in symbolic |
| 30915 | form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n}, | 31249 | form, i.e., @samp{yow(10,x)}. On the other hand, if you answer @kbd{n}, |
| 30916 | then the formula will always be expanded, even for non-constant | 31250 | then the formula will always be expanded, even for non-constant |
| 30917 | arguments: @samp{10 + 2 x}. If you never plan to feed algebraic | 31251 | arguments: @samp{10 + 2 x}. If you never plan to feed algebraic |
| 30918 | formulas to your new function, it doesn't matter how you answer this | 31252 | formulas to your new function, it doesn't matter how you answer this |
| 30919 | question.@refill | 31253 | question. |
| 30920 | 31254 | ||
| 30921 | If you answered @kbd{y} to this question you can still cause a function | 31255 | If you answered @kbd{y} to this question you can still cause a function |
| 30922 | call to be expanded by typing @kbd{a "} (@code{calc-expand-formula}). | 31256 | call 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 | |||
| 30931 | key onto the stack. Actually, it pushes a nameless function that | 31265 | key onto the stack. Actually, it pushes a nameless function that |
| 30932 | specifies both the argument list and the defining formula. You will get | 31266 | specifies both the argument list and the defining formula. You will get |
| 30933 | an error message if the key is undefined, or if the key was not defined | 31267 | an error message if the key is undefined, or if the key was not defined |
| 30934 | by a @kbd{Z F} command.@refill | 31268 | by a @kbd{Z F} command. |
| 30935 | 31269 | ||
| 30936 | The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has | 31270 | The @kbd{Z E} (@code{calc-user-define-edit}) command on a key that has |
| 30937 | been defined by a formula uses a variant of the @code{calc-edit} command | 31271 | been 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 | |||
| 30951 | used as a function definition. For example, the formula @samp{deriv(a^2,v)} | 31285 | used as a function definition. For example, the formula @samp{deriv(a^2,v)} |
| 30952 | which might be used to define a new function @samp{dsqr(a,v)} will be | 31286 | which 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 |
| 30955 | default simplifications cures this problem: The definition will be stored | 31289 | default simplifications cures this problem: The definition will be stored |
| 30956 | in symbolic form without ever activating the @code{deriv} function. Press | 31290 | in 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 | ||
| 31054 | For other functions @var{func}, if a function by the name | 31388 | For 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 | |||
| 31057 | is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is | 31391 | is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is |
| 31058 | used on the assumption that this is a to-be-defined math function. Also, if | 31392 | used on the assumption that this is a to-be-defined math function. Also, if |
| 31059 | the function name is quoted as in @samp{('integerp a)} the function name is | 31393 | the function name is quoted as in @samp{('integerp a)} the function name is |
| 31060 | always used exactly as written (but not quoted).@refill | 31394 | always used exactly as written (but not quoted). |
| 31061 | 31395 | ||
| 31062 | Variable names have @samp{var-} prepended to them unless they appear in | 31396 | Variable names have @samp{var-} prepended to them unless they appear in |
| 31063 | the function's argument list or in an enclosing @code{let}, @code{let*}, | 31397 | the 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, |
| 31065 | or their names already contain a @samp{-} character. Thus a reference to | 31399 | or 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 | ||
| 31068 | A few other Lisp extensions are available in @code{defmath} definitions: | 31402 | A 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 | |||
| 31081 | a synonym of @code{setq}.) Specifically, the first argument of | 31415 | a 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, |
| 31083 | in which case the effect is to store into the specified | 31417 | in which case the effect is to store into the specified |
| 31084 | element of a list. Thus, @samp{(setq (elt m i j) x)} stores @cite{x} | 31418 | element of a list. Thus, @samp{(setq (elt m i j) x)} stores @expr{x} |
| 31085 | into one element of a matrix. | 31419 | into one element of a matrix. |
| 31086 | 31420 | ||
| 31087 | @item | 31421 | @item |
| 31088 | A @code{for} looping construct is available. For example, | 31422 | A @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 |
| 31090 | binding of @cite{i} from zero to 10. This is like a @code{let} | 31424 | binding of @expr{i} from zero to 10. This is like a @code{let} |
| 31091 | form in that @cite{i} is temporarily bound to the loop count | 31425 | form in that @expr{i} is temporarily bound to the loop count |
| 31092 | without disturbing its value outside the @code{for} construct. | 31426 | without disturbing its value outside the @code{for} construct. |
| 31093 | Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)}, | 31427 | Nested loops, as in @samp{(for ((i 0 10) (j 0 (1- i) 2)) body)}, |
| 31094 | are also available. For each value of @cite{i} from zero to 10, | 31428 | are 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 |
| 31097 | that each element of the header is a list of three or four | 31431 | that each element of the header is a list of three or four |
| 31098 | things, not just two. | 31432 | things, not just two. |
| @@ -31100,8 +31434,8 @@ things, not just two. | |||
| 31100 | @item | 31434 | @item |
| 31101 | The @code{foreach} construct loops over elements of a list. | 31435 | The @code{foreach} construct loops over elements of a list. |
| 31102 | For example, @samp{(foreach ((x (cdr v))) body)} executes | 31436 | For 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 |
| 31105 | the initial @code{vec} symbol in the vector. | 31439 | the 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 |
| 31114 | The @code{return} function prematurely returns from the enclosing | 31448 | The @code{return} function prematurely returns from the enclosing |
| 31115 | function. For example, @samp{(return (+ x y))} returns @cite{x+y} | 31449 | function. For example, @samp{(return (+ x y))} returns @expr{x+y} |
| 31116 | as the value of a function. You can use @code{return} anywhere | 31450 | as the value of a function. You can use @code{return} anywhere |
| 31117 | inside the body of the function. | 31451 | inside 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 | ||
| 31465 | In this example, the command @code{calc-foo} will evaluate the expression | 31799 | In 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 |
| 31467 | executed with a numeric prefix argument of @cite{n}. | 31801 | executed with a numeric prefix argument of @expr{n}. |
| 31468 | 31802 | ||
| 31469 | The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"} | 31803 | The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"} |
| 31470 | code as used with @code{defun}). It uses the numeric prefix argument as the | 31804 | code as used with @code{defun}). It uses the numeric prefix argument as the |
| @@ -31501,7 +31835,7 @@ The following qualifiers are recognized: | |||
| 31501 | The argument must not be an incomplete vector, interval, or complex number. | 31835 | The 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 |
| 31503 | function with an incomplete argument. But there is nothing stopping your | 31837 | function with an incomplete argument. But there is nothing stopping your |
| 31504 | own Lisp code from calling your function with an incomplete argument.)@refill | 31838 | own 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 |
| 31667 | A somewhat limited sine function could be defined as follows, using the | 32001 | A somewhat limited sine function could be defined as follows, using the |
| 31668 | well-known Taylor series expansion for @c{$\sin x$} | 32002 | well-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 | ||
| 31690 | The actual @code{sin} function in Calc works by first reducing the problem | 32025 | The actual @code{sin} function in Calc works by first reducing the problem |
| 31691 | to a sine or cosine of a nonnegative number less than @c{$\pi \over 4$} | 32026 | to a sine or cosine of a nonnegative number less than @cpiover{4}. This |
| 31692 | @cite{pi/4}. This | ||
| 31693 | ensures that the Taylor series will converge quickly. Also, the calculation | 32027 | ensures that the Taylor series will converge quickly. Also, the calculation |
| 31694 | is carried out with two extra digits of precision to guard against cumulative | 32028 | is carried out with two extra digits of precision to guard against cumulative |
| 31695 | round-off in @samp{sum}. Finally, complex arguments are allowed and handled | 32029 | round-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 | |||
| 31724 | series as before, and @code{mycos-raw} is a function analogous to | 32058 | series 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 | ||
| 31727 | The strategy is to ensure that @cite{x} is nonnegative before calling | 32061 | The 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 |
| 31729 | to a suitable range, namely, plus-or-minus @c{$\pi \over 4$} | 32063 | to a suitable range, namely, plus-or-minus @cpiover{4}. Note that each |
| 31730 | @cite{pi/4}. Note that each | ||
| 31731 | test, and particularly the first comparison against 7, is designed so | 32064 | test, and particularly the first comparison against 7, is designed so |
| 31732 | that small roundoff errors cannot produce an infinite loop. (Suppose | 32065 | that small roundoff errors cannot produce an infinite loop. (Suppose |
| 31733 | we compared with @samp{(two-pi)} instead; if due to roundoff problems | 32066 | we 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)} | |||
| 31877 | when the user has left Calc in symbolic mode or no-simplify mode. | 32210 | when the user has left Calc in symbolic mode or no-simplify mode. |
| 31878 | 32211 | ||
| 31879 | As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")} | 32212 | As another example, @samp{(equal (calc-eval '("$<$$") nil a b) "1")} |
| 31880 | checks if the number in string @cite{a} is less than the one in | 32213 | checks if the number in string @expr{a} is less than the one in |
| 31881 | string @cite{b}. Without using a list, the integer 1 might | 32214 | string @expr{b}. Without using a list, the integer 1 might |
| 31882 | come out in a variety of formats which would be hard to test for | 32215 | come out in a variety of formats which would be hard to test for |
| 31883 | conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But | 32216 | conveniently: @code{"1"}, @code{"8#1"}, @code{"00001"}. (But |
| 31884 | see ``Predicates'' mode, below.) | 32217 | see ``Predicates'' mode, below.) |
| @@ -32218,13 +32551,13 @@ the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number | |||
| 32218 | are that the number 0.0 is always stored as @samp{(float 0 0)}, and, | 32551 | are that the number 0.0 is always stored as @samp{(float 0 0)}, and, |
| 32219 | except for the 0.0 case, the rightmost base-10 digit of @var{mant} is | 32552 | except for the 0.0 case, the rightmost base-10 digit of @var{mant} is |
| 32220 | always nonzero. (If the rightmost digit is zero, the number is | 32553 | always nonzero. (If the rightmost digit is zero, the number is |
| 32221 | rearranged by dividing @var{mant} by ten and incrementing @var{exp}.)@refill | 32554 | rearranged by dividing @var{mant} by ten and incrementing @var{exp}.) |
| 32222 | 32555 | ||
| 32223 | Rectangular complex numbers are stored in the form @samp{(cplx @var{re} | 32556 | Rectangular 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 |
| 32225 | integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}. | 32558 | integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}. |
| 32226 | The @var{im} part is nonzero; complex numbers with zero imaginary | 32559 | The @var{im} part is nonzero; complex numbers with zero imaginary |
| 32227 | components are converted to real numbers automatically.@refill | 32560 | components are converted to real numbers automatically. |
| 32228 | 32561 | ||
| 32229 | Polar complex numbers are stored in the form @samp{(polar @var{r} | 32562 | Polar 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, | |||
| 32233 | or @samp{(-pi ..@: pi)} radians, according to the current angular mode. | 32566 | or @samp{(-pi ..@: pi)} radians, according to the current angular mode. |
| 32234 | If the angle is 0 the value is converted to a real number automatically. | 32567 | If 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 |
| 32236 | negative real number.)@refill | 32569 | negative real number.) |
| 32237 | 32570 | ||
| 32238 | Hours-minutes-seconds forms are stored as @samp{(hms @var{h} @var{m} | 32571 | Hours-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., |
| 32240 | a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued | 32573 | a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued |
| 32241 | float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number | 32574 | float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number |
| 32242 | in the range @samp{[0 ..@: 60)}.@refill | 32575 | in the range @samp{[0 ..@: 60)}. |
| 32243 | 32576 | ||
| 32244 | Date forms are stored as @samp{(date @var{n})}, where @var{n} is | 32577 | Date forms are stored as @samp{(date @var{n})}, where @var{n} is |
| 32245 | a real number that counts days since midnight on the morning of | 32578 | a 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 | |||
| 32293 | which represent units are not stored in any special way; they are units | 32626 | which represent units are not stored in any special way; they are units |
| 32294 | only because their names appear in the units table. If the value | 32627 | only because their names appear in the units table. If the value |
| 32295 | cell contains a string, it is parsed to get the variable's value when | 32628 | cell contains a string, it is parsed to get the variable's value when |
| 32296 | the variable is used.@refill | 32629 | the variable is used. |
| 32297 | 32630 | ||
| 32298 | A Lisp list with any other symbol as the first element is a function call. | 32631 | A Lisp list with any other symbol as the first element is a function call. |
| 32299 | The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^}, | 32632 | The symbols @code{+}, @code{-}, @code{*}, @code{/}, @code{%}, @code{^}, |
| @@ -32313,7 +32646,7 @@ object which represents their value, or a list of such objects if they | |||
| 32313 | wish to return multiple values. (The latter case is allowed only for | 32646 | wish to return multiple values. (The latter case is allowed only for |
| 32314 | functions which are the outer-level call in an expression whose value is | 32647 | functions which are the outer-level call in an expression whose value is |
| 32315 | about to be pushed on the stack; this feature is considered obsolete | 32648 | about to be pushed on the stack; this feature is considered obsolete |
| 32316 | and is not used by any built-in Calc functions.)@refill | 32649 | and 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 | |||
| 32349 | previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})}, | 32682 | previously void); or @samp{(eval @var{undo} @var{redo} @var{args} @dots{})}, |
| 32350 | which means that to undo requires calling the function @samp{(@var{undo} | 32683 | which 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 |
| 32365 | satisfy; it is expanded to a suitable string such as ``Expected an | 32698 | satisfy; it is expanded to a suitable string such as ``Expected an |
| 32366 | integer.'' The @code{reject-arg} function calls @code{calc-record-why} | 32699 | integer.'' The @code{reject-arg} function calls @code{calc-record-why} |
| 32367 | automatically; @pxref{Predicates}.@refill | 32700 | automatically; @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 | |||
| 32391 | end up at level @var{n}, the next-to-last at level @var{n}+1, etc. | 32724 | end up at level @var{n}, the next-to-last at level @var{n}+1, etc. |
| 32392 | The elements of @var{vals} are assumed to be valid Calc objects, and | 32725 | The elements of @var{vals} are assumed to be valid Calc objects, and |
| 32393 | are not evaluated, rounded, or renormalized in any way. If @var{vals} | 32726 | are not evaluated, rounded, or renormalized in any way. If @var{vals} |
| 32394 | is an empty list, nothing happens.@refill | 32727 | is an empty list, nothing happens. |
| 32395 | 32728 | ||
| 32396 | The stack elements are pushed without any sub-formula selections. | 32729 | The stack elements are pushed without any sub-formula selections. |
| 32397 | You can give an optional third argument to this function, which must | 32730 | You 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 | |||
| 32410 | element will be next-to-last, etc. If @var{n} or @var{m} are out of | 32743 | element will be next-to-last, etc. If @var{n} or @var{m} are out of |
| 32411 | range, the command is aborted with a suitable error message. If @var{n} | 32744 | range, the command is aborted with a suitable error message. If @var{n} |
| 32412 | is zero, the function returns an empty list. The stack elements are not | 32745 | is zero, the function returns an empty list. The stack elements are not |
| 32413 | evaluated, rounded, or renormalized.@refill | 32746 | evaluated, rounded, or renormalized. |
| 32414 | 32747 | ||
| 32415 | If any stack elements contain selections, and selections have not | 32748 | If any stack elements contain selections, and selections have not |
| 32416 | been disabled by the @kbd{j e} (@code{calc-enable-selections}) command, | 32749 | been 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 | |||
| 32506 | argument to apply the operator over many stack entries. If the prefix | 32839 | argument to apply the operator over many stack entries. If the prefix |
| 32507 | argument @var{arg} is @code{nil}, this uses @code{calc-enter-result} | 32840 | argument @var{arg} is @code{nil}, this uses @code{calc-enter-result} |
| 32508 | as outlined above. Otherwise, it maps the function over several stack | 32841 | as outlined above. Otherwise, it maps the function over several stack |
| 32509 | elements; @pxref{Prefix Arguments}. For example,@refill | 32842 | elements; @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, | |||
| 32527 | the binary function @var{func} is reduced across the top @var{arg} | 32860 | the binary function @var{func} is reduced across the top @var{arg} |
| 32528 | stack elements; when the argument is negative, the function is | 32861 | stack elements; when the argument is negative, the function is |
| 32529 | mapped between the next-to-top @i{-@var{arg}} stack elements and the | 32862 | mapped between the next-to-top @i{-@var{arg}} stack elements and the |
| 32530 | top element.@refill | 32863 | top 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 | |||
| 32541 | will be the @samp{.} line. If @var{n} is from 1 to the current stack size, | 32874 | will be the @samp{.} line. If @var{n} is from 1 to the current stack size, |
| 32542 | this will be the beginning of the first line of that stack entry's display. | 32875 | this will be the beginning of the first line of that stack entry's display. |
| 32543 | If line numbers are enabled, this will move to the first character of the | 32876 | If line numbers are enabled, this will move to the first character of the |
| 32544 | line number, not the stack entry itself.@refill | 32877 | line 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 | |||
| 32551 | one line long (i.e., no matrices are displayed), the return value will | 32884 | one line long (i.e., no matrices are displayed), the return value will |
| 32552 | be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big | 32885 | be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big |
| 32553 | mode, the return value includes the blank lines that separate stack | 32886 | mode, the return value includes the blank lines that separate stack |
| 32554 | entries.)@refill | 32887 | entries.) |
| 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 | |||
| 32560 | display radix, which might change the appearance of existing stack | 32893 | display radix, which might change the appearance of existing stack |
| 32561 | entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing | 32894 | entries. (During a keyboard macro invoked by the @kbd{X} key, refreshing |
| 32562 | is suppressed, but a flag is set so that the entire stack will be refreshed | 32895 | is suppressed, but a flag is set so that the entire stack will be refreshed |
| 32563 | rather than just the top few elements when the macro finishes.)@refill | 32896 | rather 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 | |||
| 32739 | by checking whether @samp{@var{x} - @var{y}} is @code{negp}. In | 33072 | by 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 |
| 32741 | converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=}, | 33074 | converted to @samp{(lessp x y)}; expressions involving @code{>}, @code{<=}, |
| 32742 | and @code{>=} are similarly converted in terms of @code{lessp}.@refill | 33075 | and @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)}. | |||
| 32771 | Returns true if @var{x} and @var{n} are numerically equal, where @var{n} | 33104 | Returns true if @var{x} and @var{n} are numerically equal, where @var{n} |
| 32772 | is a fixnum which is not a multiple of 10. This will automatically be | 33105 | is a fixnum which is not a multiple of 10. This will automatically be |
| 32773 | used by @code{defmath} in place of the more general @code{math-equal} | 33106 | used by @code{defmath} in place of the more general @code{math-equal} |
| 32774 | whenever possible.@refill | 33107 | whenever 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. | |||
| 32808 | Abort the current function evaluation due to unacceptable argument values. | 33141 | Abort the current function evaluation due to unacceptable argument values. |
| 32809 | This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a | 33142 | This calls @samp{(calc-record-why @var{pred} @var{val})}, then signals a |
| 32810 | Lisp error which @code{normalize} will trap. The net effect is that the | 33143 | Lisp error which @code{normalize} will trap. The net effect is that the |
| 32811 | function call which led here will be left in symbolic form.@refill | 33144 | function 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 |
| 32820 | function to be left unsimplified. You may instead wish to call | 33153 | function 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 |
| 32822 | return the formula @samp{sin(5)} to your function.@refill | 33155 | return 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 | |||
| 32840 | the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command, | 33173 | the documentation refers to the @code{calc-sqrt} [@code{sqrt}] command, |
| 32841 | this means @code{calc-sqrt} is an interactive stack-based square-root | 33174 | this means @code{calc-sqrt} is an interactive stack-based square-root |
| 32842 | command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt}) | 33175 | command and @code{sqrt} (which @code{defmath} expands to @code{calcFunc-sqrt}) |
| 32843 | is the actual Lisp function for taking square roots.@refill | 33176 | is the actual Lisp function for taking square roots. |
| 32844 | 33177 | ||
| 32845 | The functions @code{math-add}, @code{math-sub}, @code{math-mul}, | 33178 | The 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 |
| 32847 | in this list, since @code{defmath} allows you to write native Lisp | 33180 | in 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{-}, |
| 32849 | respectively, instead.@refill | 33182 | respectively, 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 | |||
| 32857 | small. All the various data types are similarly converted to their standard | 33190 | small. All the various data types are similarly converted to their standard |
| 32858 | forms. Variables are left alone, but function calls are actually evaluated | 33191 | forms. Variables are left alone, but function calls are actually evaluated |
| 32859 | in formulas. For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will | 33192 | in formulas. For example, normalizing @samp{(+ 2 (calcFunc-abs -4))} will |
| 32860 | return 6.@refill | 33193 | return 6. |
| 32861 | 33194 | ||
| 32862 | If a function call fails, because the function is void or has the wrong | 33195 | If a function call fails, because the function is void or has the wrong |
| 32863 | number of parameters, or because it returns @code{nil} or calls | 33196 | number 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 |
| 32865 | the formula still in symbolic form.@refill | 33198 | the formula still in symbolic form. |
| 32866 | 33199 | ||
| 32867 | If the current Simplification Mode is ``none'' or ``numeric arguments | 33200 | If the current Simplification Mode is ``none'' or ``numeric arguments |
| 32868 | only,'' @code{normalize} will act appropriately. However, the more | 33201 | only,'' @code{normalize} will act appropriately. However, the more |
| @@ -32871,13 +33204,13 @@ not handled by @code{normalize}. They are handled by @code{calc-normalize}, | |||
| 32871 | which calls @code{normalize} and possibly some other routines, such | 33204 | which calls @code{normalize} and possibly some other routines, such |
| 32872 | as @code{simplify} or @code{simplify-units}. Programs generally will | 33205 | as @code{simplify} or @code{simplify-units}. Programs generally will |
| 32873 | never call @code{calc-normalize} except when popping or pushing values | 33206 | never call @code{calc-normalize} except when popping or pushing values |
| 32874 | on the stack.@refill | 33207 | on the stack. |
| 32875 | @end defun | 33208 | @end defun |
| 32876 | 33209 | ||
| 32877 | @defun evaluate-expr expr | 33210 | @defun evaluate-expr expr |
| 32878 | Replace all variables in @var{expr} that have values with their values, | 33211 | Replace all variables in @var{expr} that have values with their values, |
| 32879 | then use @code{normalize} to simplify the result. This is what happens | 33212 | then use @code{normalize} to simplify the result. This is what happens |
| 32880 | when you press the @kbd{=} key interactively.@refill | 33213 | when 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}. | |||
| 32948 | Compare the numbers @var{x} and @var{y}, and return @i{-1} if | 33281 | Compare 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})}, |
| 32950 | 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is | 33283 | 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is |
| 32951 | undefined or cannot be determined.@refill | 33284 | undefined 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 |
| 33001 | Divide integer @var{x} by integer @var{y}; return a cons cell whose | 33334 | Divide 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} |
| 33003 | is @samp{(imod @var{x} @var{y})}.@refill | 33336 | is @samp{(imod @var{x} @var{y})}. |
| 33004 | @end defun | 33337 | @end defun |
| 33005 | 33338 | ||
| 33006 | @defun pow x y | 33339 | @defun pow x y |
| 33007 | Compute @var{x} to the power @var{y}. In @code{defmath} code, this can | 33340 | Compute @var{x} to the power @var{y}. In @code{defmath} code, this can |
| 33008 | also be written @samp{(^ @var{x} @var{y})} or | 33341 | also 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 |
| 33032 | returns a floating-point value in the current precision, and each uses | 33365 | returns a floating-point value in the current precision, and each uses |
| 33033 | caching so that all calls after the first are essentially free.@refill | 33366 | caching 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 | |||
| 33045 | two least significant digits is stored in the cache. For example, | 33378 | two least significant digits is stored in the cache. For example, |
| 33046 | calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34 | 33379 | calling @samp{(pi)} with a precision of 30 computes @samp{pi} to 34 |
| 33047 | digits, rounds it down to 32 digits for future use, then rounds it | 33380 | digits, rounds it down to 32 digits for future use, then rounds it |
| 33048 | again to 30 digits for use in the present request.@refill | 33381 | again 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 |
| 33074 | Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if | 33407 | Divide @var{a} by @var{b}, modulo @var{m}. This returns @code{nil} if |
| 33075 | there is no solution, or if any of the arguments are not integers.@refill | 33408 | there 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 |
| 33148 | case that this is necessary. If @code{prime-test} returns ``maybe,'' | 33481 | case that this is necessary. If @code{prime-test} returns ``maybe,'' |
| 33149 | you can call it again with the same @var{n} to get a greater certainty; | 33482 | you 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 | |||
| 33198 | produce lists of more than two dimensions. Note that the object | 33531 | produce 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, |
| 33200 | and is treated by this and other Calc routines as a plain vector of two | 33533 | and is treated by this and other Calc routines as a plain vector of two |
| 33201 | elements.@refill | 33534 | elements. |
| 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 | |||
| 33246 | For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v} | 33579 | For example, @samp{(map-vec-2 'math-add v 1)} returns the vector @var{v} |
| 33247 | with each element increased by one. Note that using @samp{'+} would not | 33580 | with each element increased by one. Note that using @samp{'+} would not |
| 33248 | work here, since @code{defmath} does not expand function names everywhere, | 33581 | work here, since @code{defmath} does not expand function names everywhere, |
| 33249 | just where they are in the function position of a Lisp expression.@refill | 33582 | just 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 | |||
| 33296 | element of the result matrix will be @code{eq} to the corresponding | 33629 | element of the result matrix will be @code{eq} to the corresponding |
| 33297 | element of @var{m}, but none of the @code{cons} cells that make up | 33630 | element of @var{m}, but none of the @code{cons} cells that make up |
| 33298 | the structure of the matrix will be @code{eq}. If @var{m} is a plain | 33631 | the structure of the matrix will be @code{eq}. If @var{m} is a plain |
| 33299 | vector, this is the same as @code{copy-sequence}.@refill | 33632 | vector, 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 | |||
| 33305 | function changes @var{m} itself rather than building up a new result | 33638 | function changes @var{m} itself rather than building up a new result |
| 33306 | matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)} | 33639 | matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)} |
| 33307 | is true, with the side effect of exchanging the first two rows of | 33640 | is 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 | |||
| 33443 | implemented by temporarily binding the variable @code{math-living-dangerously} | 33776 | implemented by temporarily binding the variable @code{math-living-dangerously} |
| 33444 | to @code{t} (using a @code{let} form) and calling @code{simplify}. | 33777 | to @code{t} (using a @code{let} form) and calling @code{simplify}. |
| 33445 | Dangerous simplification rules are written to check this variable | 33778 | Dangerous simplification rules are written to check this variable |
| 33446 | before taking any action.@refill | 33779 | before 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 | |||
| 33465 | if it returns a result @code{equal} to the original @code{expr}, it is | 33798 | if it returns a result @code{equal} to the original @code{expr}, it is |
| 33466 | ignored and Calc goes on to try the next simplification rule that applies. | 33799 | ignored and Calc goes on to try the next simplification rule that applies. |
| 33467 | If the function body returns something different, that new formula is | 33800 | If the function body returns something different, that new formula is |
| 33468 | substituted for @var{expr} in the original formula.@refill | 33801 | substituted for @var{expr} in the original formula. |
| 33469 | 33802 | ||
| 33470 | At each point in the formula, rules are tried in the order of the | 33803 | At each point in the formula, rules are tried in the order of the |
| 33471 | original calls to @code{math-defsimplify}; the search stops after the | 33804 | original calls to @code{math-defsimplify}; the search stops after the |
| @@ -33498,7 +33831,7 @@ convenient. Here is a typical example of a simplification rule: | |||
| 33498 | This is really a pair of rules written with one @code{math-defsimplify} | 33831 | This is really a pair of rules written with one @code{math-defsimplify} |
| 33499 | for convenience; the first replaces @samp{arcsinh(-x)} with | 33832 | for 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}, |
| 33501 | replaces @samp{arcsinh(sinh(x))} with @samp{x}.@refill | 33834 | replaces @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 | |||
| 33533 | rational numbers. This is the fraction composed of the GCD of the | 33866 | rational numbers. This is the fraction composed of the GCD of the |
| 33534 | numerators of @var{a} and @var{b}, over the GCD of the denominators. | 33867 | numerators of @var{a} and @var{b}, over the GCD of the denominators. |
| 33535 | It is used by @code{common-constant-factor}. Note that the standard | 33868 | It 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 |
| 33550 | integer which says how many times @var{func} may be applied; the | 33883 | integer which says how many times @var{func} may be applied; the |
| 33551 | default, as described above, is infinitely many times.@refill | 33884 | default, 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 | |||
| 33665 | cosines of more complicated arguments. An integration rule should return | 33998 | cosines 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 |
| 33667 | the same function, they are tried in order until one returns a non-@code{nil} | 34000 | the same function, they are tried in order until one returns a non-@code{nil} |
| 33668 | result.@refill | 34001 | result. |
| 33669 | @end defmac | 34002 | @end defmac |
| 33670 | 34003 | ||
| 33671 | @defmac math-defintegral-2 funcs body | 34004 | @defmac math-defintegral-2 funcs body |
| 33672 | Define a rule for integrating a function or functions of two arguments. | 34005 | Define a rule for integrating a function or functions of two arguments. |
| 33673 | This is exactly analogous to @code{math-defintegral}, except that @var{body} | 34006 | This is exactly analogous to @code{math-defintegral}, except that @var{body} |
| 33674 | is written as the body of a function with two arguments, @var{u} and | 34007 | is 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, | |||
| 33685 | which return a rearranged equation or a functional inverse, respectively. | 34018 | which return a rearranged equation or a functional inverse, respectively. |
| 33686 | If @var{full} is non-@code{nil}, a full solution including dummy signs | 34019 | If @var{full} is non-@code{nil}, a full solution including dummy signs |
| 33687 | and dummy integers will be produced. User-defined inverses are provided | 34020 | and dummy integers will be produced. User-defined inverses are provided |
| 33688 | as properties in a manner similar to derivatives:@refill | 34021 | as 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 |
| 33728 | Returns the number of occurrences of @var{var} as a subexpression | 34061 | Returns the number of occurrences of @var{var} as a subexpression |
| 33729 | of @var{expr}, or @code{nil} if there are no occurrences.@refill | 34062 | of @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. | |||
| 33744 | Returns a copy of @var{expr}, with all occurrences of @var{old} replaced | 34077 | Returns a copy of @var{expr}, with all occurrences of @var{old} replaced |
| 33745 | by @var{new}. This treats @code{lambda} forms specially with respect | 34078 | by @var{new}. This treats @code{lambda} forms specially with respect |
| 33746 | to the dummy argument variables, so that the effect is always to return | 34079 | to 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 |
| 33764 | Returns the ``height'' of @var{expr}, which is the deepest level to | 34097 | Returns the ``height'' of @var{expr}, which is the deepest level to |
| 33765 | which function calls are nested. (Note that @samp{@var{a} + @var{b}} | 34098 | which function calls are nested. (Note that @samp{@var{a} + @var{b}} |
| 33766 | counts as a function call.) For primitive objects, this returns zero.@refill | 34099 | counts 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} |
| 33776 | appears only raised to nonnegative integer powers. Note that if | 34109 | appears 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 |
| 33778 | a polynomial of degree 0.@refill | 34111 | a 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 | |||
| 33797 | themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose | 34130 | themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose |
| 33798 | polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin | 34131 | polynomial with coefficients @samp{((calcFunc-cos x) 0 (calcFunc-sin |
| 33799 | x))}. The result will never be @code{nil} in loose mode, since any | 34132 | x))}. The result will never be @code{nil} in loose mode, since any |
| 33800 | expression can be interpreted as a ``constant'' loose polynomial.@refill | 34133 | expression 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}. | |||
| 33810 | The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})}; | 34143 | The default predicate uses @samp{(polynomial-p mpb-top-expr @var{subexpr})}; |
| 33811 | you can use @var{pred} to specify additional conditions. Or, you could | 34144 | you can use @var{pred} to specify additional conditions. Or, you could |
| 33812 | have @var{pred} build up a list of every suitable @var{subexpr} that | 34145 | have @var{pred} build up a list of every suitable @var{subexpr} that |
| 33813 | is found.@refill | 34146 | is 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. | |||
| 33822 | Mix two polynomial lists @var{a} and @var{b} (in the form returned by | 34155 | Mix 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) |
| 33825 | polynomial list representing @samp{@var{ac} @var{a} + @var{bc} @var{b}}.@refill | 34158 | polynomial 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 | |||
| 33835 | list @var{poly} applied to variable @var{var}. The @kbd{a c} | 34168 | list @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 |
| 33837 | expression into a coefficient list, then @code{build-polynomial-expr} | 34170 | expression into a coefficient list, then @code{build-polynomial-expr} |
| 33838 | to turn the list back into an expression in regular form.@refill | 34171 | to 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}. | |||
| 33852 | Return true if @var{expr} contains any variables which can be | 34185 | Return true if @var{expr} contains any variables which can be |
| 33853 | interpreted as units. If @var{sub-exprs} is @code{t}, the entire | 34186 | interpreted as units. If @var{sub-exprs} is @code{t}, the entire |
| 33854 | expression is searched. If @var{sub-exprs} is @code{nil}, this | 34187 | expression is searched. If @var{sub-exprs} is @code{nil}, this |
| 33855 | checks whether @var{expr} is directly a units expression.@refill | 34188 | checks 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} | |||
| 33867 | is @code{nil}, use Calc's native base units. Otherwise, @var{which} | 34200 | is @code{nil}, use Calc's native base units. Otherwise, @var{which} |
| 33868 | can specify a units system, which is a list of two-element lists, | 34201 | can specify a units system, which is a list of two-element lists, |
| 33869 | where the first element is a Calc base symbol name and the second | 34202 | where the first element is a Calc base symbol name and the second |
| 33870 | is an expression to substitute for it.@refill | 34203 | is 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 | |||
| 33903 | not have the form of a valid expression, return a list of the form | 34236 | not 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 |
| 33905 | into @var{str} of the general location of the error, and @var{msg} is | 34238 | into @var{str} of the general location of the error, and @var{msg} is |
| 33906 | a string describing the problem.@refill | 34239 | a 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. | |||
| 33922 | If @var{prompt} is given, it is the prompt string to use; the default | 34255 | If @var{prompt} is given, it is the prompt string to use; the default |
| 33923 | is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will | 34256 | is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will |
| 33924 | be returned exactly as parsed; otherwise, they will be passed through | 34257 | be returned exactly as parsed; otherwise, they will be passed through |
| 33925 | @code{calc-normalize} first.@refill | 34258 | @code{calc-normalize} first. |
| 33926 | 34259 | ||
| 33927 | To support the use of @kbd{$} characters in the algebraic entry, use | 34260 | To 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 |
| 33929 | to be substituted for @kbd{$}, @kbd{$$}, and so on, and bind | 34262 | to 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} |
| 33931 | will have been changed to the highest number of consecutive @kbd{$}s | 34264 | will have been changed to the highest number of consecutive @kbd{$}s |
| 33932 | that actually appeared in the input.@refill | 34265 | that 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 | |||
| 33945 | complex number format, and point character, are ignored to ensure the | 34278 | complex number format, and point character, are ignored to ensure the |
| 33946 | result will be re-readable. The @var{prec} parameter is normally 0; if | 34279 | result will be re-readable. The @var{prec} parameter is normally 0; if |
| 33947 | you pass a large integer like 1000 instead, the expression will be | 34280 | you pass a large integer like 1000 instead, the expression will be |
| 33948 | surrounded by parentheses unless it is a plain number or variable name.@refill | 34281 | surrounded 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 | |||
| 33964 | contain newline characters to separate the lines. The @var{w} | 34297 | contain newline characters to separate the lines. The @var{w} |
| 33965 | parameter, if given, is the target window size for which to format | 34298 | parameter, if given, is the target window size for which to format |
| 33966 | the expressions. If @var{w} is omitted, the width of the Calculator | 34299 | the expressions. If @var{w} is omitted, the width of the Calculator |
| 33967 | window is used.@refill | 34300 | window 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 |
| 34013 | If composition @var{c} is a ``flat'' composition, return the first | 34346 | If 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, |
| 34015 | return @code{nil}.@refill | 34348 | return @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} | |||
| 34192 | to the appropriate file name. You may also need to change the variables | 34525 | to 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 |
| 34194 | order to get correct displays and hardcopies, respectively, of your | 34527 | order to get correct displays and hardcopies, respectively, of your |
| 34195 | plots.@refill | 34528 | plots. |
| 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 |
| 34208 | at Stanford University) as well as the @file{texindex} program and | 34541 | at 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 |
| 34210 | as part of the @code{texinfo} package.@refill | 34543 | as part of the @code{texinfo} package. |
| 34211 | 34544 | ||
| 34212 | To print the Calc manual in one huge 470 page tome, you will need the | 34545 | To print the Calc manual in one huge 470 page tome, you will need the |
| 34213 | source code to this manual, @file{calc.texi}, available as part of the | 34546 | source 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 |
| 34255 | automatically load your settings file (if it exists) the first time | 34588 | automatically load your settings file (if it exists) the first time |
| 34256 | Calc is invoked.@refill | 34589 | Calc 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 |
| 35197 | Positive prefix arguments apply to @cite{n} stack entries. | 35530 | Positive prefix arguments apply to @expr{n} stack entries. |
| 35198 | Negative prefix arguments apply to the @cite{-n}th stack entry. | 35531 | Negative prefix arguments apply to the @expr{-n}th stack entry. |
| 35199 | A prefix of zero applies to the entire stack. (For @key{LFD} and | 35532 | A 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 |
| 35204 | Positive prefix arguments apply to @cite{n} stack entries. | 35537 | Positive prefix arguments apply to @expr{n} stack entries. |
| 35205 | Negative prefix arguments apply to the top stack entry | 35538 | Negative prefix arguments apply to the top stack entry |
| 35206 | and the next @cite{-n} stack entries. | 35539 | and the next @expr{-n} stack entries. |
| 35207 | 35540 | ||
| 35208 | @c 3 | 35541 | @c 3 |
| 35209 | @item | 35542 | @item |
| 35210 | Positive prefix arguments rotate top @cite{n} stack entries by one. | 35543 | Positive prefix arguments rotate top @expr{n} stack entries by one. |
| 35211 | Negative prefix arguments rotate the entire stack by @cite{-n}. | 35544 | Negative prefix arguments rotate the entire stack by @expr{-n}. |
| 35212 | A prefix of zero reverses the entire stack. | 35545 | A 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 |
| 35220 | Positive prefix arguments specify a precision @cite{p}. | 35553 | Positive prefix arguments specify a precision @expr{p}. |
| 35221 | Negative prefix arguments reduce the current precision by @cite{-p}. | 35554 | Negative 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 |
| 35239 | Positive prefix arguments specify a word size of @cite{w} bits, unsigned. | 35572 | Positive prefix arguments specify a word size of @expr{w} bits, unsigned. |
| 35240 | Negative prefix arguments specify a word size of @cite{w} bits, signed. | 35573 | Negative prefix arguments specify a word size of @expr{w} bits, signed. |
| 35241 | 35574 | ||
| 35242 | @c 10 | 35575 | @c 10 |
| 35243 | @item | 35576 | @item |
| 35244 | Prefix arguments specify the shift amount @cite{n}. The @cite{w} argument | 35577 | Prefix arguments specify the shift amount @expr{n}. The @expr{w} argument |
| 35245 | cannot be specified in the keyboard version of this command. | 35578 | cannot be specified in the keyboard version of this command. |
| 35246 | 35579 | ||
| 35247 | @c 11 | 35580 | @c 11 |
| 35248 | @item | 35581 | @item |
| 35249 | From the keyboard, @cite{d} is omitted and defaults to zero. | 35582 | From 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 |
| 35262 | A prefix argument, if any, is used for @cite{m} instead of taking | 35595 | A 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 |
| 35269 | Random integer in the interval @cite{[0 .. m)}. | 35602 | Random integer in the interval @expr{[0 .. m)}. |
| 35270 | @item Float | 35603 | @item Float |
| 35271 | Random floating-point number in the interval @cite{[0 .. m)}. | 35604 | Random floating-point number in the interval @expr{[0 .. m)}. |
| 35272 | @item 0.0 | 35605 | @item 0.0 |
| 35273 | Gaussian with mean 1 and standard deviation 0. | 35606 | Gaussian 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 |
| 35311 | With a prefix argument of 1, take a single @c{$@var{n}\times2$} | 35644 | With a prefix argument of 1, take a single |
| 35312 | @i{@var{N}x2} matrix from the | 35645 | @texline @tmath{@var{n}\times2} |
| 35313 | stack instead of two separate data vectors. | 35646 | @infoline @i{@var{N}x2} |
| 35647 | matrix from the stack instead of two separate data vectors. | ||
| 35314 | 35648 | ||
| 35315 | @c 21 | 35649 | @c 21 |
| 35316 | @item | 35650 | @item |
| 35317 | The row or column number @cite{n} may be given as a numeric prefix | 35651 | The row or column number @expr{n} may be given as a numeric prefix |
| 35318 | argument instead. A plain @kbd{C-u} prefix says to take @cite{n} | 35652 | argument instead. A plain @kbd{C-u} prefix says to take @expr{n} |
| 35319 | from the top of the stack. If @cite{n} is a vector or interval, | 35653 | from the top of the stack. If @expr{n} is a vector or interval, |
| 35320 | a subvector/submatrix of the input is created. | 35654 | a subvector/submatrix of the input is created. |
| 35321 | 35655 | ||
| 35322 | @c 22 | 35656 | @c 22 |
| 35323 | @item | 35657 | @item |
| 35324 | The @cite{op} prompt can be answered with the key sequence for the | 35658 | The @expr{op} prompt can be answered with the key sequence for the |
| 35325 | desired function, or with @kbd{x} or @kbd{z} followed by a function name, | 35659 | desired function, or with @kbd{x} or @kbd{z} followed by a function name, |
| 35326 | or with @kbd{$} to take a formula from the top of the stack, or with | 35660 | or 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. | |||
| 35336 | One of the mapping direction keys @kbd{_} (horizontal, i.e., map | 35670 | One of the mapping direction keys @kbd{_} (horizontal, i.e., map |
| 35337 | by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or | 35671 | by rows or reduce across), @kbd{:} (vertical, i.e., map by columns or |
| 35338 | reduce down), or @kbd{=} (map or reduce by rows) may be used before | 35672 | reduce down), or @kbd{=} (map or reduce by rows) may be used before |
| 35339 | entering @cite{op}; these modify the function name by adding the letter | 35673 | entering @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,'' |
| 35341 | or @code{d} for ``down.'' | 35675 | or @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 |
| 35391 | A prefix argument specifies the size @cite{n} of the matrix. With no | 35725 | A prefix argument specifies the size @expr{n} of the matrix. With no |
| 35392 | prefix argument, @cite{n} is omitted and the size is inferred from | 35726 | prefix argument, @expr{n} is omitted and the size is inferred from |
| 35393 | the input vector. | 35727 | the input vector. |
| 35394 | 35728 | ||
| 35395 | @c 26 | 35729 | @c 26 |
| 35396 | @item | 35730 | @item |
| 35397 | The prefix argument specifies the starting position @cite{n} (default 1). | 35731 | The 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 |
| 35463 | Answer for @cite{v} may also be of the form @cite{v = v_0} or | 35797 | Answer 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 |
| 35468 | With a positive prefix argument, stack contains many @cite{y}'s and one | 35802 | With a positive prefix argument, stack contains many @expr{y}'s and one |
| 35469 | common @cite{x}. With a zero prefix, stack contains a vector of | 35803 | common @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 |
| 35471 | contains many @cite{[x,y]} vectors. (For 3D plots, substitute | 35805 | contains 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 | |||
| 35504 | stack levels. The notation @kbd{$3} refers to stack level three without | 35838 | stack levels. The notation @kbd{$3} refers to stack level three without |
| 35505 | causing that value to be removed from the stack. Use @key{LFD} in place | 35839 | causing that value to be removed from the stack. Use @key{LFD} in place |
| 35506 | of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET} | 35840 | of @key{RET} to prevent evaluation; use @kbd{M-=} in place of @key{RET} |
| 35507 | to evaluate variables.@refill | 35841 | to evaluate variables. |
| 35508 | 35842 | ||
| 35509 | @c 47 | 35843 | @c 47 |
| 35510 | @item | 35844 | @item |
| 35511 | The variable is replaced by the formula shown on the right. The | 35845 | The variable is replaced by the formula shown on the right. The |
| 35512 | Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} | 35846 | Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} |
| 35513 | assigns @c{$x \coloneq a-x$} | 35847 | assigns |
| 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 |
| 35518 | Press @kbd{?} repeatedly to see how to choose a model. Answer the | 35853 | Press @kbd{?} repeatedly to see how to choose a model. Answer the |
| 35519 | variables prompt with @cite{iv} or @cite{iv;pv} to specify | 35854 | variables prompt with @expr{iv} or @expr{iv;pv} to specify |
| 35520 | independent and parameter variables. A positive prefix argument | 35855 | independent and parameter variables. A positive prefix argument |
| 35521 | takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix | 35856 | takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix |
| 35522 | and a vector from the stack. | 35857 | and a vector from the stack. |