aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJay Belanger2012-07-29 22:38:24 -0500
committerJay Belanger2012-07-29 22:38:24 -0500
commitd2bd74ff3e3f88027c4a7de0dcdb7dfb3e12716e (patch)
treee7ac1574fa2658e71dc12dd1878ed358945026a6 /doc
parent4514c2522dc0d5a65698b5a2d397e53102b247eb (diff)
downloademacs-d2bd74ff3e3f88027c4a7de0dcdb7dfb3e12716e.tar.gz
emacs-d2bd74ff3e3f88027c4a7de0dcdb7dfb3e12716e.zip
doc/misc/calc.texi (Getting Started, Tutorial): Change simulated
Calc output to match actual output. (Simplifying Formulas): Mention that algebraic simplification is now the default.
Diffstat (limited to 'doc')
-rw-r--r--doc/misc/ChangeLog7
-rw-r--r--doc/misc/calc.texi401
2 files changed, 194 insertions, 214 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index fe7687424ca..d0f60c60234 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,10 @@
12012-07-30 Jay Belanger <jay.p.belanger@gmail.com>
2
3 * calc.texi (Getting Started, Tutorial): Change simulated
4 Calc output to match actual output.
5 (Simplifying Formulas): Mention that algebraic simplification is now
6 the default.
7
12012-07-28 Eli Zaretskii <eliz@gnu.org> 82012-07-28 Eli Zaretskii <eliz@gnu.org>
2 9
3 * faq.texi (Right-to-left alphabets): Update for Emacs 24. 10 * faq.texi (Right-to-left alphabets): Update for Emacs 24.
diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi
index fe11cedce5d..301866ad65c 100644
--- a/doc/misc/calc.texi
+++ b/doc/misc/calc.texi
@@ -910,12 +910,12 @@ The derivative of
910 910
911is 911is
912 912
9131 / ln(x) x 9131 / x ln(x)
914@end group 914@end group
915@end smallexample 915@end smallexample
916 916
917(Note that by default, Calc gives division lower precedence than multiplication, 917(Note that by default, Calc gives division lower precedence than multiplication,
918so that @samp{1 / ln(x) x} is equivalent to @samp{1 / (ln(x) x)}.) 918so that @samp{1 / x ln(x)} is equivalent to @samp{1 / (x ln(x))}.)
919 919
920To make this look nicer, you might want to press @kbd{d =} to center 920To make this look nicer, you might want to press @kbd{d =} to center
921the formula, and even @kbd{d B} to use Big display mode. 921the formula, and even @kbd{d B} to use Big display mode.
@@ -932,7 +932,7 @@ is
932 932
933 1 933 1
934 ------- 934 -------
935 ln(x) x 935 x ln(x)
936@end group 936@end group
937@end smallexample 937@end smallexample
938 938
@@ -964,7 +964,9 @@ and keyboard will revert to the way they were before.
964The related command @kbd{C-x * w} operates on a single word, which 964The related command @kbd{C-x * w} operates on a single word, which
965generally means a single number, inside text. It searches for an 965generally means a single number, inside text. It searches for an
966expression which ``looks'' like a number containing the point. 966expression which ``looks'' like a number containing the point.
967Here's an example of its use: 967Here's an example of its use (before you try this, remove the Calc
968annotations or use a new buffer so that the extra settings in the
969annotations don't take effect):
968 970
969@smallexample 971@smallexample
970A slope of one-third corresponds to an angle of 1 degrees. 972A slope of one-third corresponds to an angle of 1 degrees.
@@ -1175,15 +1177,16 @@ turned out to be more open-ended than one might have expected.
1175 1177
1176Emacs Lisp didn't have built-in floating point math (now it does), so 1178Emacs Lisp didn't have built-in floating point math (now it does), so
1177this had to be simulated in software. In fact, Emacs integers would 1179this had to be simulated in software. In fact, Emacs integers would
1178only comfortably fit six decimal digits or so---not enough for a decent 1180only comfortably fit six decimal digits or so (at the time)---not
1179calculator. So I had to write my own high-precision integer code as 1181enough for a decent calculator. So I had to write my own
1180well, and once I had this I figured that arbitrary-size integers were 1182high-precision integer code as well, and once I had this I figured
1181just as easy as large integers. Arbitrary floating-point precision was 1183that arbitrary-size integers were just as easy as large integers.
1182the logical next step. Also, since the large integer arithmetic was 1184Arbitrary floating-point precision was the logical next step. Also,
1183there anyway it seemed only fair to give the user direct access to it, 1185since the large integer arithmetic was there anyway it seemed only
1184which in turn made it practical to support fractions as well as floats. 1186fair to give the user direct access to it, which in turn made it
1185All these features inspired me to look around for other data types that 1187practical to support fractions as well as floats. All these features
1186might be worth having. 1188inspired me to look around for other data types that might be worth
1189having.
1187 1190
1188Around this time, my friend Rick Koshi showed me his nifty new HP-28 1191Around this time, my friend Rick Koshi showed me his nifty new HP-28
1189calculator. It allowed the user to manipulate formulas as well as 1192calculator. It allowed the user to manipulate formulas as well as
@@ -1359,15 +1362,14 @@ to control various modes of the Calculator.
1359@subsection RPN Calculations and the Stack 1362@subsection RPN Calculations and the Stack
1360 1363
1361@cindex RPN notation 1364@cindex RPN notation
1362@ifnottex
1363@noindent 1365@noindent
1366@ifnottex
1364Calc normally uses RPN notation. You may be familiar with the RPN 1367Calc normally uses RPN notation. You may be familiar with the RPN
1365system from Hewlett-Packard calculators, FORTH, or PostScript. 1368system from Hewlett-Packard calculators, FORTH, or PostScript.
1366(Reverse Polish Notation, RPN, is named after the Polish mathematician 1369(Reverse Polish Notation, RPN, is named after the Polish mathematician
1367Jan Lukasiewicz.) 1370Jan Lukasiewicz.)
1368@end ifnottex 1371@end ifnottex
1369@tex 1372@tex
1370\noindent
1371Calc normally uses RPN notation. You may be familiar with the RPN 1373Calc normally uses RPN notation. You may be familiar with the RPN
1372system from Hewlett-Packard calculators, FORTH, or PostScript. 1374system from Hewlett-Packard calculators, FORTH, or PostScript.
1373(Reverse Polish Notation, RPN, is named after the Polish mathematician 1375(Reverse Polish Notation, RPN, is named after the Polish mathematician
@@ -1473,7 +1475,7 @@ multiplication.) Figure it out by hand, then try it with Calc to see
1473if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) 1475if you're right. @xref{RPN Answer 1, 1}. (@bullet{})
1474 1476
1475(@bullet{}) @strong{Exercise 2.} Compute 1477(@bullet{}) @strong{Exercise 2.} Compute
1476@texline @math{(2\times4) + (7\times9.4) + {5\over4}} 1478@texline @math{(2\times4) + (7\times9.5) + {5\over4}}
1477@infoline @expr{2*4 + 7*9.5 + 5/4} 1479@infoline @expr{2*4 + 7*9.5 + 5/4}
1478using the stack. @xref{RPN Answer 2, 2}. (@bullet{}) 1480using the stack. @xref{RPN Answer 2, 2}. (@bullet{})
1479 1481
@@ -1964,7 +1966,7 @@ values are left alone, even when you evaluate the formula.
1964 1966
1965@smallexample 1967@smallexample
1966@group 1968@group
19671: 2 a + 2 b 1: 34 + 2 b 19691: 2 a + 2 b 1: 2 b + 34
1968 . . 1970 . .
1969 1971
1970 ' 2a+2b @key{RET} = 1972 ' 2a+2b @key{RET} =
@@ -1976,7 +1978,7 @@ alone, as are calls for which the value is undefined.
1976 1978
1977@smallexample 1979@smallexample
1978@group 1980@group
19791: 2 + log10(0) + log10(x) + log10(5, 6) + foo(3) 19811: log10(0) + log10(x) + log10(5, 6) + foo(3) + 2
1980 . 1982 .
1981 1983
1982 ' log10(100) + log10(0) + log10(x) + log10(5,6) + foo(3) @key{RET} 1984 ' log10(100) + log10(0) + log10(x) + log10(5,6) + foo(3) @key{RET}
@@ -4588,7 +4590,7 @@ that arises in the second one.
4588@cindex Fermat, primality test of 4590@cindex Fermat, primality test of
4589(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat 4591(@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat
4590says that 4592says that
4591@texline @w{@math{x^{n-1} \bmod n = 1}} 4593@texline @math{x^{n-1} \bmod n = 1}
4592@infoline @expr{x^(n-1) mod n = 1} 4594@infoline @expr{x^(n-1) mod n = 1}
4593if @expr{n} is a prime number and @expr{x} is an integer less than 4595if @expr{n} is a prime number and @expr{x} is an integer less than
4594@expr{n}. If @expr{n} is @emph{not} a prime number, this will 4596@expr{n}. If @expr{n} is @emph{not} a prime number, this will
@@ -4704,19 +4706,17 @@ for them.
4704 4706
4705@smallexample 4707@smallexample
4706@group 4708@group
47071: 20 degF 1: 11.1111 degC 1: -20:3 degC 1: -6.666 degC 47091: 20 degF 1: 11.1111 degC 1: -6.666 degC
4708 . . . . 4710 . . . .
4709 4711
4710 ' 20 degF @key{RET} u c degC @key{RET} U u t degC @key{RET} c f 4712 ' 20 degF @key{RET} u c degC @key{RET} U u t degC @key{RET}
4711@end group 4713@end group
4712@end smallexample 4714@end smallexample
4713 4715
4714@noindent 4716@noindent
4715First we convert a change of 20 degrees Fahrenheit into an equivalent 4717First we convert a change of 20 degrees Fahrenheit into an equivalent
4716change in degrees Celsius (or Centigrade). Then, we convert the 4718change in degrees Celsius (or Centigrade). Then, we convert the
4717absolute temperature 20 degrees Fahrenheit into Celsius. Since 4719absolute temperature 20 degrees Fahrenheit into Celsius.
4718this comes out as an exact fraction, we then convert to floating-point
4719for easier comparison with the other result.
4720 4720
4721For simple unit conversions, you can put a plain number on the stack. 4721For simple unit conversions, you can put a plain number on the stack.
4722Then @kbd{u c} and @kbd{u t} will prompt for both old and new units. 4722Then @kbd{u c} and @kbd{u t} will prompt for both old and new units.
@@ -4775,7 +4775,7 @@ formulas as regular data objects.
4775 4775
4776@smallexample 4776@smallexample
4777@group 4777@group
47781: 2 x^2 - 6 1: 6 - 2 x^2 1: (6 - 2 x^2) (3 x^2 + y) 47781: 2 x^2 - 6 1: 6 - 2 x^2 1: (3 x^2 + y) (6 - 2 x^2)
4779 . . . 4779 . . .
4780 4780
4781 ' 2x^2-6 @key{RET} n ' 3x^2+y @key{RET} * 4781 ' 2x^2-6 @key{RET} n ' 3x^2+y @key{RET} *
@@ -4791,7 +4791,7 @@ formulas. Continuing with the formula from the last example,
4791 4791
4792@smallexample 4792@smallexample
4793@group 4793@group
47941: 18 x^2 + 6 y - 6 x^4 - 2 x^2 y 1: (18 - 2 y) x^2 - 6 x^4 + 6 y 47941: 18 x^2 - 6 x^4 + 6 y - 2 y x^2 1: (18 - 2 y) x^2 - 6 x^4 + 6 y
4795 . . 4795 . .
4796 4796
4797 a x a c x @key{RET} 4797 a x a c x @key{RET}
@@ -4849,17 +4849,17 @@ the other root(s), let's divide through by @expr{x} and then solve:
4849 4849
4850@smallexample 4850@smallexample
4851@group 4851@group
48521: (34 x - 24 x^3) / x 1: 34 x / x - 24 x^3 / x 1: 34 - 24 x^2 48521: (34 x - 24 x^3) / x 1: 34 - 24 x^2
4853 . . . 4853 . .
4854 4854
4855 ' x @key{RET} / a x a s 4855 ' x @key{RET} / a x
4856 4856
4857@end group 4857@end group
4858@end smallexample 4858@end smallexample
4859@noindent 4859@noindent
4860@smallexample 4860@smallexample
4861@group 4861@group
48621: 34 - 24 x^2 = 0 1: x = 1.19023 48621: 0.70588 x^2 = 1 1: x = 1.19023
4863 . . 4863 . .
4864 4864
4865 0 a = s 3 a S x @key{RET} 4865 0 a = s 3 a S x @key{RET}
@@ -4867,10 +4867,6 @@ the other root(s), let's divide through by @expr{x} and then solve:
4867@end smallexample 4867@end smallexample
4868 4868
4869@noindent 4869@noindent
4870Notice the use of @kbd{a s} to ``simplify'' the formula. When the
4871default algebraic simplifications don't do enough, you can use
4872@kbd{a s} to tell Calc to spend more time on the job.
4873
4874Now we compute the second derivative and plug in our values of @expr{x}: 4870Now we compute the second derivative and plug in our values of @expr{x}:
4875 4871
4876@smallexample 4872@smallexample
@@ -4905,7 +4901,7 @@ has a maximum value at @expr{x = 1.19023}. (The function also has a
4905local @emph{minimum} at @expr{x = 0}.) 4901local @emph{minimum} at @expr{x = 0}.)
4906 4902
4907When we solved for @expr{x}, we got only one value even though 4903When we solved for @expr{x}, we got only one value even though
4908@expr{34 - 24 x^2 = 0} is a quadratic equation that ought to have 4904@expr{0.70588 x^2 = 1} is a quadratic equation that ought to have
4909two solutions. The reason is that @w{@kbd{a S}} normally returns a 4905two solutions. The reason is that @w{@kbd{a S}} normally returns a
4910single ``principal'' solution. If it needs to come up with an 4906single ``principal'' solution. If it needs to come up with an
4911arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}. 4907arbitrary sign (as occurs in the quadratic formula) it picks @expr{+}.
@@ -4914,7 +4910,7 @@ solution by pressing @kbd{H} (the Hyperbolic flag) before @kbd{a S}.
4914 4910
4915@smallexample 4911@smallexample
4916@group 4912@group
49171: 34 - 24 x^2 = 0 1: x = 1.19023 s1 1: x = -1.19023 49131: 0.70588 x^2 = 1 1: x = 1.19023 s1 1: x = -1.19023
4918 . . . 4914 . . .
4919 4915
4920 r 3 H a S x @key{RET} s 5 1 n s l s1 @key{RET} 4916 r 3 H a S x @key{RET} s 5 1 n s l s1 @key{RET}
@@ -5135,7 +5131,7 @@ also have used plain @kbd{v x} as follows: @kbd{v x 10 @key{RET} 9 + .1 *}.)
5135@smallexample 5131@smallexample
5136@group 5132@group
51372: [1, 1.1, ... ] 1: [0., 0.084941, 0.16993, ... ] 51332: [1, 1.1, ... ] 1: [0., 0.084941, 0.16993, ... ]
51381: sin(x) ln(x) . 51341: ln(x) sin(x) .
5139 . 5135 .
5140 5136
5141 ' sin(x) ln(x) @key{RET} s 1 m r p 5 @key{RET} V M $ @key{RET} 5137 ' sin(x) ln(x) @key{RET} s 1 m r p 5 @key{RET} V M $ @key{RET}
@@ -5168,7 +5164,7 @@ we're not doing too well. Let's try another approach.
5168 5164
5169@smallexample 5165@smallexample
5170@group 5166@group
51711: sin(x) ln(x) 1: 0.84147 x - 0.84147 + 0.11957 (x - 1)^2 - ... 51671: ln(x) sin(x) 1: 0.84147 x + 0.11957 (x - 1)^2 - ...
5172 . . 5168 . .
5173 5169
5174 r 1 a t x=1 @key{RET} 4 @key{RET} 5170 r 1 a t x=1 @key{RET} 4 @key{RET}
@@ -5277,60 +5273,43 @@ Suppose we want to simplify this trigonometric formula:
5277 5273
5278@smallexample 5274@smallexample
5279@group 5275@group
52801: 2 / cos(x)^2 - 2 tan(x)^2 52761: 2 sec(x)^2 / tan(x)^2 - 2 / tan(x)^2
5281 . 5277 .
5282 5278
5283 ' 2/cos(x)^2 - 2tan(x)^2 @key{RET} s 1 5279 ' 2sec(x)^2/tan(x)^2 - 2/tan(x)^2 @key{RET} s 1
5284@end group 5280@end group
5285@end smallexample 5281@end smallexample
5286 5282
5287@noindent 5283@noindent
5288If we were simplifying this by hand, we'd probably replace the 5284If we were simplifying this by hand, we'd probably combine over the common
5289@samp{tan} with a @samp{sin/cos} first, then combine over a common 5285denominator. The @kbd{a n} algebra command will do this, but we'll do
5290denominator. The @kbd{I a s} command will do the former and the @kbd{a n} 5286it with a rewrite rule just for practice.
5291algebra command will do the latter, but we'll do both with rewrite
5292rules just for practice.
5293 5287
5294Rewrite rules are written with the @samp{:=} symbol. 5288Rewrite rules are written with the @samp{:=} symbol.
5295 5289
5296@smallexample 5290@smallexample
5297@group 5291@group
52981: 2 / cos(x)^2 - 2 sin(x)^2 / cos(x)^2 52921: (2 sec(x)^2 - 2) / tan(x)^2
5299 . 5293 .
5300 5294
5301 a r tan(a) := sin(a)/cos(a) @key{RET} 5295 a r a/x + b/x := (a+b)/x @key{RET}
5302@end group 5296@end group
5303@end smallexample 5297@end smallexample
5304 5298
5305@noindent 5299@noindent
5306(The ``assignment operator'' @samp{:=} has several uses in Calc. All 5300(The ``assignment operator'' @samp{:=} has several uses in Calc. All
5307by itself the formula @samp{tan(a) := sin(a)/cos(a)} doesn't do anything, 5301by itself the formula @samp{a/x + b/x := (a+b)/x} doesn't do anything,
5308but when it is given to the @kbd{a r} command, that command interprets 5302but when it is given to the @kbd{a r} command, that command interprets
5309it as a rewrite rule.) 5303it as a rewrite rule.)
5310 5304
5311The lefthand side, @samp{tan(a)}, is called the @dfn{pattern} of the 5305The lefthand side, @samp{a/x + b/x}, is called the @dfn{pattern} of the
5312rewrite rule. Calc searches the formula on the stack for parts that 5306rewrite rule. Calc searches the formula on the stack for parts that
5313match the pattern. Variables in a rewrite pattern are called 5307match the pattern. Variables in a rewrite pattern are called
5314@dfn{meta-variables}, and when matching the pattern each meta-variable 5308@dfn{meta-variables}, and when matching the pattern each meta-variable
5315can match any sub-formula. Here, the meta-variable @samp{a} matched 5309can match any sub-formula. Here, the meta-variable @samp{a} matched
5316the actual variable @samp{x}. 5310the expression @samp{2 sec(x)^2}, the meta-variable @samp{b} matched
5317 5311the constant @samp{-2} and the meta-variable @samp{x} matched
5318When the pattern part of a rewrite rule matches a part of the formula, 5312the expression @samp{tan(x)^2}.
5319that part is replaced by the righthand side with all the meta-variables
5320substituted with the things they matched. So the result is
5321@samp{sin(x) / cos(x)}. Calc's normal algebraic simplifications then
5322mix this in with the rest of the original formula.
5323
5324To merge over a common denominator, we can use another simple rule:
5325
5326@smallexample
5327@group
53281: (2 - 2 sin(x)^2) / cos(x)^2
5329 .
5330
5331 a r a/x + b/x := (a+b)/x @key{RET}
5332@end group
5333@end smallexample
5334 5313
5335This rule points out several interesting features of rewrite patterns. 5314This rule points out several interesting features of rewrite patterns.
5336First, if a meta-variable appears several times in a pattern, it must 5315First, if a meta-variable appears several times in a pattern, it must
@@ -5340,13 +5319,18 @@ denominators.
5340 5319
5341Second, meta-variable names are independent from variables in the 5320Second, meta-variable names are independent from variables in the
5342target formula. Notice that the meta-variable @samp{x} here matches 5321target formula. Notice that the meta-variable @samp{x} here matches
5343the subformula @samp{cos(x)^2}; Calc never confuses the two meanings of 5322the subformula @samp{tan(x)^2}; Calc never confuses the two meanings of
5344@samp{x}. 5323@samp{x}.
5345 5324
5346And third, rewrite patterns know a little bit about the algebraic 5325And third, rewrite patterns know a little bit about the algebraic
5347properties of formulas. The pattern called for a sum of two quotients; 5326properties of formulas. The pattern called for a sum of two quotients;
5348Calc was able to match a difference of two quotients by matching 5327Calc was able to match a difference of two quotients by matching
5349@samp{a = 2}, @samp{b = -2 sin(x)^2}, and @samp{x = cos(x)^2}. 5328@samp{a = 2 sec(x)^2}, @samp{b = -2}, and @samp{x = tan(x)^2}.
5329
5330When the pattern part of a rewrite rule matches a part of the formula,
5331that part is replaced by the righthand side with all the meta-variables
5332substituted with the things they matched. So the result is
5333@samp{(2 sec(x)^2 - 2) / tan(x)^2}.
5350 5334
5351@c [fix-ref Algebraic Properties of Rewrite Rules] 5335@c [fix-ref Algebraic Properties of Rewrite Rules]
5352We could just as easily have written @samp{a/x - b/x := (a-b)/x} for 5336We could just as easily have written @samp{a/x - b/x := (a-b)/x} for
@@ -5356,19 +5340,19 @@ we could have used the @code{plain} symbol. @xref{Algebraic Properties
5356of Rewrite Rules}, for some examples of this.) 5340of Rewrite Rules}, for some examples of this.)
5357 5341
5358One more rewrite will complete the job. We want to use the identity 5342One more rewrite will complete the job. We want to use the identity
5359@samp{sin(x)^2 + cos(x)^2 = 1}, but of course we must first rearrange 5343@samp{tan(x)^2 + 1 = sec(x)^2}, but of course we must first rearrange
5360the identity in a way that matches our formula. The obvious rule 5344the identity in a way that matches our formula. The obvious rule
5361would be @samp{@w{2 - 2 sin(x)^2} := 2 cos(x)^2}, but a little thought shows 5345would be @samp{@w{2 sec(x)^2 - 2} := 2 tan(x)^2}, but a little thought shows
5362that the rule @samp{sin(x)^2 := 1 - cos(x)^2} will also work. The 5346that the rule @samp{sec(x)^2 := 1 + tan(x)^2} will also work. The
5363latter rule has a more general pattern so it will work in many other 5347latter rule has a more general pattern so it will work in many other
5364situations, too. 5348situations, too.
5365 5349
5366@smallexample 5350@smallexample
5367@group 5351@group
53681: (2 + 2 cos(x)^2 - 2) / cos(x)^2 1: 2 53521: 2
5369 . . 5353 .
5370 5354
5371 a r sin(x)^2 := 1 - cos(x)^2 @key{RET} a s 5355 a r sec(x)^2 := 1 + tan(x)^2 @key{RET}
5372@end group 5356@end group
5373@end smallexample 5357@end smallexample
5374 5358
@@ -5383,14 +5367,13 @@ having to retype it.
5383 5367
5384@smallexample 5368@smallexample
5385@group 5369@group
5386' tan(x) := sin(x)/cos(x) @key{RET} s t tsc @key{RET} 5370' a/x + b/x := (a+b)/x @key{RET} s t merge @key{RET}
5387' a/x + b/x := (a+b)/x @key{RET} s t merge @key{RET} 5371' sec(x)^2 := 1 + tan(x)^2 @key{RET} s t secsqr @key{RET}
5388' sin(x)^2 := 1 - cos(x)^2 @key{RET} s t sinsqr @key{RET}
5389 5372
53901: 2 / cos(x)^2 - 2 tan(x)^2 1: 2 53731: 2 sec(x)^2 / tan(x)^2 - 2 / tan(x)^2 1: 2
5391 . . 5374 . .
5392 5375
5393 r 1 a r tsc @key{RET} a r merge @key{RET} a r sinsqr @key{RET} a s 5376 r 1 a r merge @key{RET} a r secsqr @key{RET}
5394@end group 5377@end group
5395@end smallexample 5378@end smallexample
5396 5379
@@ -5420,20 +5403,20 @@ a variable containing a vector of rules.
5420 5403
5421@smallexample 5404@smallexample
5422@group 5405@group
54231: [tsc, merge, sinsqr] 1: [tan(x) := sin(x) / cos(x), ... ] 54061: [merge, secsqr] 1: [a/x + b/x := (a + b)/x, ... ]
5424 . . 5407 . .
5425 5408
5426 ' [tsc,merge,sinsqr] @key{RET} = 5409 ' [merge,sinsqr] @key{RET} =
5427 5410
5428@end group 5411@end group
5429@end smallexample 5412@end smallexample
5430@noindent 5413@noindent
5431@smallexample 5414@smallexample
5432@group 5415@group
54331: 1 / cos(x) - sin(x) tan(x) 1: cos(x) 54161: 2 sec(x)^2 / tan(x)^2 - 2 / tan(x)^2 1: 2
5434 . . 5417 . .
5435 5418
5436 s t trig @key{RET} r 1 a r trig @key{RET} a s 5419 s t trig @key{RET} r 1 a r trig @key{RET}
5437@end group 5420@end group
5438@end smallexample 5421@end smallexample
5439 5422
@@ -5451,10 +5434,10 @@ only one rewrite at a time.
5451 5434
5452@smallexample 5435@smallexample
5453@group 5436@group
54541: 1 / cos(x) - sin(x)^2 / cos(x) 1: (1 - sin(x)^2) / cos(x) 54371: (2 sec(x)^2 - 2) / tan(x)^2 1: 2
5455 . . 5438 . .
5456 5439
5457 r 1 M-1 a r trig @key{RET} M-1 a r trig @key{RET} 5440 r 1 M-1 a r trig @key{RET} M-1 a r trig @key{RET}
5458@end group 5441@end group
5459@end smallexample 5442@end smallexample
5460 5443
@@ -5466,20 +5449,20 @@ with a @samp{::} symbol and the desired condition. For example,
5466 5449
5467@smallexample 5450@smallexample
5468@group 5451@group
54691: exp(2 pi i) + exp(3 pi i) + exp(4 pi i) 54521: sin(x + 2 pi) + sin(x + 3 pi) + sin(x + 4 pi)
5470 . 5453 .
5471 5454
5472 ' exp(2 pi i) + exp(3 pi i) + exp(4 pi i) @key{RET} 5455 ' sin(x+2pi) + sin(x+3pi) + sin(x+4pi) @key{RET}
5473 5456
5474@end group 5457@end group
5475@end smallexample 5458@end smallexample
5476@noindent 5459@noindent
5477@smallexample 5460@smallexample
5478@group 5461@group
54791: 1 + exp(3 pi i) + 1 54621: sin(x + 3 pi) + 2 sin(x)
5480 . 5463 .
5481 5464
5482 a r exp(k pi i) := 1 :: k % 2 = 0 @key{RET} 5465 a r sin(a + k pi) := sin(a) :: k % 2 = 0 @key{RET}
5483@end group 5466@end group
5484@end smallexample 5467@end smallexample
5485 5468
@@ -5487,10 +5470,10 @@ with a @samp{::} symbol and the desired condition. For example,
5487(Recall, @samp{k % 2} is the remainder from dividing @samp{k} by 2, 5470(Recall, @samp{k % 2} is the remainder from dividing @samp{k} by 2,
5488which will be zero only when @samp{k} is an even integer.) 5471which will be zero only when @samp{k} is an even integer.)
5489 5472
5490An interesting point is that the variables @samp{pi} and @samp{i} 5473An interesting point is that the variable @samp{pi} was matched
5491were matched literally rather than acting as meta-variables. 5474literally rather than acting as a meta-variable.
5492This is because they are special-constant variables. The special 5475This is because it is a special-constant variable. The special
5493constants @samp{e}, @samp{phi}, and so on also match literally. 5476constants @samp{e}, @samp{i}, @samp{phi}, and so on also match literally.
5494A common error with rewrite 5477A common error with rewrite
5495rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting 5478rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
5496to match any @samp{f} with five arguments but in fact matching 5479to match any @samp{f} with five arguments but in fact matching
@@ -5541,7 +5524,7 @@ Now:
5541 5524
5542@smallexample 5525@smallexample
5543@group 5526@group
55441: fib(6) + fib(x) + fib(0) 1: 8 + fib(x) + fib(0) 55271: fib(6) + fib(x) + fib(0) 1: fib(x) + fib(0) + 8
5545 . . 5528 . .
5546 5529
5547 ' fib(6)+fib(x)+fib(0) @key{RET} a r fib @key{RET} 5530 ' fib(6)+fib(x)+fib(0) @key{RET} a r fib @key{RET}
@@ -5707,10 +5690,10 @@ power series represented as @samp{@var{polynomial} + O(@var{var}^@var{n})}.
5707For example, given @samp{1 - x^2 / 2 + O(x^3)} and @samp{x - x^3 / 6 + O(x^4)} 5690For example, given @samp{1 - x^2 / 2 + O(x^3)} and @samp{x - x^3 / 6 + O(x^4)}
5708on the stack, we want to be able to type @kbd{*} and get the result 5691on the stack, we want to be able to type @kbd{*} and get the result
5709@samp{x - 2:3 x^3 + O(x^4)}. Don't worry if the terms of the sum are 5692@samp{x - 2:3 x^3 + O(x^4)}. Don't worry if the terms of the sum are
5710rearranged or if @kbd{a s} needs to be typed after rewriting. (This one 5693rearranged. (This one is rather tricky; the solution at the end of
5711is rather tricky; the solution at the end of this chapter uses 6 rewrite 5694this chapter uses 6 rewrite rules. Hint: The @samp{constant(x)}
5712rules. Hint: The @samp{constant(x)} condition tests whether @samp{x} is 5695condition tests whether @samp{x} is a number.) @xref{Rewrites Answer
5713a number.) @xref{Rewrites Answer 6, 6}. (@bullet{}) 56966, 6}. (@bullet{})
5714 5697
5715Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}. 5698Just for kicks, try adding the rule @code{2+3 := 6} to @code{EvalRules}.
5716What happens? (Be sure to remove this rule afterward, or you might get 5699What happens? (Be sure to remove this rule afterward, or you might get
@@ -5737,7 +5720,7 @@ case @kbd{z} prefix.
5737 5720
5738@smallexample 5721@smallexample
5739@group 5722@group
57401: 1 + x + x^2 / 2 + x^3 / 6 1: 1 + x + x^2 / 2 + x^3 / 6 57231: x + x^2 / 2 + x^3 / 6 + 1 1: x + x^2 / 2 + x^3 / 6 + 1
5741 . . 5724 . .
5742 5725
5743 ' 1 + x + x^2/2! + x^3/3! @key{RET} Z F e myexp @key{RET} @key{RET} @key{RET} y 5726 ' 1 + x + x^2/2! + x^3/3! @key{RET} Z F e myexp @key{RET} @key{RET} @key{RET} y
@@ -5808,7 +5791,7 @@ you may wish to program a keyboard macro to type this for you.
5808 5791
5809 ' y=sqrt(x) @key{RET} C-x ( H a S x @key{RET} C-x ) 5792 ' y=sqrt(x) @key{RET} C-x ( H a S x @key{RET} C-x )
5810 5793
58111: y = cos(x) 1: x = s1 arccos(y) + 2 pi n1 57941: y = cos(x) 1: x = s1 arccos(y) + 2 n1 pi
5812 . . 5795 . .
5813 5796
5814 ' y=cos(x) @key{RET} X 5797 ' y=cos(x) @key{RET} X
@@ -6874,7 +6857,7 @@ matrix as usual.
6874 6857
6875@smallexample 6858@smallexample
6876@group 6859@group
68771: [6, 10] 2: [6, 10] 1: [6 - 4 a / (b - a), 4 / (b - a) ] 68601: [6, 10] 2: [6, 10] 1: [4 a / (a - b) + 6, 4 / (b - a) ]
6878 . 1: [ [ 1, a ] . 6861 . 1: [ [ 1, a ] .
6879 [ 1, b ] ] 6862 [ 1, b ] ]
6880 . 6863 .
@@ -6888,9 +6871,9 @@ mode:
6888 6871
6889@smallexample 6872@smallexample
6890@group 6873@group
6891 4 a 4 6874 4 a 4
68921: [6 - -----, -----] 68751: [----- + 6, -----]
6893 b - a b - a 6876 a - b b - a
6894@end group 6877@end group
6895@end smallexample 6878@end smallexample
6896 6879
@@ -8442,11 +8425,11 @@ to the other?
8442 8425
8443@smallexample 8426@smallexample
8444@group 8427@group
84451: 3.3356 ns 1: 0.81356 ns / ns 1: 0.81356 84281: 3.3356 ns 1: 0.81356
84462: 4.1 ns . . 84292: 4.1 ns .
8447 . 8430 .
8448 8431
8449 ' 4.1 ns @key{RET} / u s 8432 ' 4.1 ns @key{RET} /
8450@end group 8433@end group
8451@end smallexample 8434@end smallexample
8452 8435
@@ -8523,7 +8506,7 @@ familiar form.
8523@noindent 8506@noindent
8524@smallexample 8507@smallexample
8525@group 8508@group
85261: [x - 1.19023, x + 1.19023, x] 1: (x - 1.19023) (x + 1.19023) x 85091: [x - 1.19023, x + 1.19023, x] 1: x*(x + 1.19023) (x - 1.19023)
8527 . . 8510 . .
8528 8511
8529 V M ' x-$ @key{RET} V R * 8512 V M ' x-$ @key{RET} V R *
@@ -8549,7 +8532,7 @@ same as the original polynomial.
8549 8532
8550@smallexample 8533@smallexample
8551@group 8534@group
85521: x sin(pi x) 1: (sin(pi x) - pi x cos(pi x)) / pi^2 85351: x sin(pi x) 1: sin(pi x) / pi^2 - x cos(pi x) / pi
8553 . . 8536 . .
8554 8537
8555 ' x sin(pi x) @key{RET} m r a i x @key{RET} 8538 ' x sin(pi x) @key{RET} m r a i x @key{RET}
@@ -8560,7 +8543,7 @@ same as the original polynomial.
8560@smallexample 8543@smallexample
8561@group 8544@group
85621: [y, 1] 85451: [y, 1]
85632: (sin(pi x) - pi x cos(pi x)) / pi^2 85462: sin(pi x) / pi^2 - x cos(pi x) / pi
8564 . 8547 .
8565 8548
8566 ' [y,1] @key{RET} @key{TAB} 8549 ' [y,1] @key{RET} @key{TAB}
@@ -8570,7 +8553,7 @@ same as the original polynomial.
8570@noindent 8553@noindent
8571@smallexample 8554@smallexample
8572@group 8555@group
85731: [(sin(pi y) - pi y cos(pi y)) / pi^2, (sin(pi) - pi cos(pi)) / pi^2] 85561: [sin(pi y) / pi^2 - y cos(pi y) / pi, 1 / pi]
8574 . 8557 .
8575 8558
8576 V M $ @key{RET} 8559 V M $ @key{RET}
@@ -8580,7 +8563,7 @@ same as the original polynomial.
8580@noindent 8563@noindent
8581@smallexample 8564@smallexample
8582@group 8565@group
85831: (sin(pi y) - pi y cos(pi y)) / pi^2 + (pi cos(pi) - sin(pi)) / pi^2 85661: sin(pi y) / pi^2 - y cos(pi y) / pi - 1 / pi
8584 . 8567 .
8585 8568
8586 V R - 8569 V R -
@@ -8590,7 +8573,7 @@ same as the original polynomial.
8590@noindent 8573@noindent
8591@smallexample 8574@smallexample
8592@group 8575@group
85931: (sin(3.14159 y) - 3.14159 y cos(3.14159 y)) / 9.8696 - 0.3183 85761: sin(3.14159 y) / 9.8696 - y cos(3.14159 y) / 3.14159 - 0.3183
8594 . 8577 .
8595 8578
8596 = 8579 =
@@ -8685,11 +8668,11 @@ We'll use Big mode to make the formulas more readable.
8685 8668
8686@smallexample 8669@smallexample
8687@group 8670@group
8688 ___ 8671 ___
8689 2 + V 2 8672 V 2 + 2
86901: (2 + sqrt(2)) / (1 + sqrt(2)) 1: -------- 86731: (2 + sqrt(2)) / (1 + sqrt(2)) 1: ---------
8691 . ___ 8674 . ___
8692 1 + V 2 8675 V 2 + 1
8693 8676
8694 . 8677 .
8695 8678
@@ -8713,11 +8696,11 @@ Multiplying by the conjugate helps because @expr{(a+b) (a-b) = a^2 - b^2}.
8713@noindent 8696@noindent
8714@smallexample 8697@smallexample
8715@group 8698@group
8716 ___ ___ 8699 ___
87171: 2 + V 2 - 2 1: V 2 87001: V 2
8718 . . 8701 .
8719 8702
8720 a r a*(b+c) := a*b + a*c a s 8703 a r a*(b+c) := a*b + a*c
8721@end group 8704@end group
8722@end smallexample 8705@end smallexample
8723 8706
@@ -12601,7 +12584,11 @@ followed by a shifted letter.
12601The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional 12584The @kbd{m O} (@code{calc-no-simplify-mode}) command turns off all optional
12602simplifications. These would leave a formula like @expr{2+3} alone. In 12585simplifications. These would leave a formula like @expr{2+3} alone. In
12603fact, nothing except simple numbers are ever affected by normalization 12586fact, nothing except simple numbers are ever affected by normalization
12604in this mode. 12587in this mode. Explicit simplification commands, such as @kbd{=} or
12588@kbd{a s}, can still be given to simplify any formulas.
12589@xref{Algebraic Definitions}, for a sample use of
12590No-Simplification mode.
12591
12605 12592
12606@kindex m N 12593@kindex m N
12607@pindex calc-num-simplify-mode 12594@pindex calc-num-simplify-mode
@@ -12616,29 +12603,27 @@ A constant is a number or other numeric object (such as a constant
12616error form or modulo form), or a vector all of whose 12603error form or modulo form), or a vector all of whose
12617elements are constant. 12604elements are constant.
12618 12605
12619@kindex m D 12606@kindex m L
12620@pindex calc-default-simplify-mode 12607@pindex calc-limited-simplify-mode
12621The @kbd{m D} (@code{calc-default-simplify-mode}) command restores the 12608The @kbd{m L} (@code{calc-limited-simplify-mode}) command does limited
12622default simplifications for all formulas. This includes many easy and 12609simplifications for all formulas. This includes many easy and
12623fast algebraic simplifications such as @expr{a+0} to @expr{a}, and 12610fast algebraic simplifications such as @expr{a+0} to @expr{a}, and
12624@expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like 12611@expr{a + 2 a} to @expr{3 a}, as well as evaluating functions like
12625@expr{@tfn{deriv}(x^2, x)} to @expr{2 x}. 12612@expr{@tfn{deriv}(x^2, x)} to @expr{2 x}.
12626 12613
12627@kindex m B 12614@kindex m B
12628@pindex calc-bin-simplify-mode 12615@pindex calc-bin-simplify-mode
12629The @kbd{m B} (@code{calc-bin-simplify-mode}) mode applies the default 12616The @kbd{m B} (@code{calc-bin-simplify-mode}) mode applies the limited
12630simplifications to a result and then, if the result is an integer, 12617simplifications to a result and then, if the result is an integer,
12631uses the @kbd{b c} (@code{calc-clip}) command to clip the integer according 12618uses the @kbd{b c} (@code{calc-clip}) command to clip the integer according
12632to the current binary word size. @xref{Binary Functions}. Real numbers 12619to the current binary word size. @xref{Binary Functions}. Real numbers
12633are rounded to the nearest integer and then clipped; other kinds of 12620are rounded to the nearest integer and then clipped; other kinds of
12634results (after the default simplifications) are left alone. 12621results (after the default simplifications) are left alone.
12635 12622
12636@kindex m A 12623@kindex m D
12637@pindex calc-alg-simplify-mode 12624@pindex calc-default-simplify-mode
12638The @kbd{m A} (@code{calc-alg-simplify-mode}) mode does algebraic 12625The @kbd{m D} (@code{calc-default-simplify-mode}) mode does standard
12639simplification; it applies all the default simplifications, and also 12626algebraic simplifications. @xref{Algebraic Simplifications}.
12640the more powerful (and slower) simplifications made by @kbd{a s}
12641(@code{calc-simplify}). @xref{Algebraic Simplifications}.
12642 12627
12643@kindex m E 12628@kindex m E
12644@pindex calc-ext-simplify-mode 12629@pindex calc-ext-simplify-mode
@@ -12658,9 +12643,7 @@ are simplified with their unit definitions in mind.
12658A common technique is to set the simplification mode down to the lowest 12643A common technique is to set the simplification mode down to the lowest
12659amount of simplification you will allow to be applied automatically, then 12644amount of simplification you will allow to be applied automatically, then
12660use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to 12645use manual commands like @kbd{a s} and @kbd{c c} (@code{calc-clean}) to
12661perform higher types of simplifications on demand. @xref{Algebraic 12646perform higher types of simplifications on demand.
12662Definitions}, for another sample use of No-Simplification mode.
12663
12664@node Declarations, Display Modes, Simplification Modes, Mode Settings 12647@node Declarations, Display Modes, Simplification Modes, Mode Settings
12665@section Declarations 12648@section Declarations
12666 12649
@@ -15893,8 +15876,8 @@ Default simplifications for numeric arguments only (@kbd{m N}).
15893@item BinSimp@var{w} 15876@item BinSimp@var{w}
15894Binary-integer simplification mode; word size @var{w} (@kbd{m B}, @kbd{b w}). 15877Binary-integer simplification mode; word size @var{w} (@kbd{m B}, @kbd{b w}).
15895 15878
15896@item AlgSimp 15879@item LimSimp
15897Algebraic simplification mode (@kbd{m A}). 15880Limited simplification mode (@kbd{m L}).
15898 15881
15899@item ExtSimp 15882@item ExtSimp
15900Extended algebraic simplification mode (@kbd{m E}). 15883Extended algebraic simplification mode (@kbd{m E}).
@@ -16733,9 +16716,9 @@ produced!) Integers and fractions are generally unaffected by this
16733operation. Vectors and formulas are cleaned by cleaning each component 16716operation. Vectors and formulas are cleaned by cleaning each component
16734number (i.e., pervasively). 16717number (i.e., pervasively).
16735 16718
16736If the simplification mode is set below the default level, it is raised 16719If the simplification mode is set below the limited level, it is raised
16737to the default level for the purposes of this command. Thus, @kbd{c c} 16720to the limited level for the purposes of this command. Thus, @kbd{c c}
16738applies the default simplifications even if their automatic application 16721applies the limited simplifications even if their automatic application
16739is disabled. @xref{Simplification Modes}. 16722is disabled. @xref{Simplification Modes}.
16740 16723
16741@cindex Roundoff errors, correcting 16724@cindex Roundoff errors, correcting
@@ -18336,7 +18319,7 @@ of the current angular mode. @xref{Basic Operations on Units}.
18336 18319
18337Also, the symbolic variable @code{pi} is not ordinarily recognized in 18320Also, the symbolic variable @code{pi} is not ordinarily recognized in
18338arguments to trigonometric functions, as in @samp{sin(3 pi / 4)}, but 18321arguments to trigonometric functions, as in @samp{sin(3 pi / 4)}, but
18339the @kbd{a s} (@code{calc-simplify}) command recognizes many such 18322the default algebraic simplifications recognize many such
18340formulas when the current angular mode is Radians @emph{and} Symbolic 18323formulas when the current angular mode is Radians @emph{and} Symbolic
18341mode is enabled; this example would be replaced by @samp{sqrt(2) / 2}. 18324mode is enabled; this example would be replaced by @samp{sqrt(2) / 2}.
18342@xref{Symbolic Mode}. Beware, this simplification occurs even if you 18325@xref{Symbolic Mode}. Beware, this simplification occurs even if you
@@ -22075,8 +22058,8 @@ as well as equations.
22075@pindex calc-sel-div-both-sides 22058@pindex calc-sel-div-both-sides
22076The @kbd{j *} (@code{calc-sel-mult-both-sides}) command prompts for a 22059The @kbd{j *} (@code{calc-sel-mult-both-sides}) command prompts for a
22077formula using algebraic entry, then multiplies both sides of the 22060formula using algebraic entry, then multiplies both sides of the
22078selected quotient or equation by that formula. It simplifies each 22061selected quotient or equation by that formula. It performs the
22079side with @kbd{a s} (@code{calc-simplify}) before re-forming the 22062default algebraic simplifications before re-forming the
22080quotient or equation. You can suppress this simplification by 22063quotient or equation. You can suppress this simplification by
22081providing a prefix argument: @kbd{C-u j *}. There is also a @kbd{j /} 22064providing a prefix argument: @kbd{C-u j *}. There is also a @kbd{j /}
22082(@code{calc-sel-div-both-sides}) which is similar to @kbd{j *} but 22065(@code{calc-sel-div-both-sides}) which is similar to @kbd{j *} but
@@ -22143,15 +22126,15 @@ now to take the cosine of the selected part.)
22143@kindex j v 22126@kindex j v
22144@pindex calc-sel-evaluate 22127@pindex calc-sel-evaluate
22145The @kbd{j v} (@code{calc-sel-evaluate}) command performs the 22128The @kbd{j v} (@code{calc-sel-evaluate}) command performs the
22146normal default simplifications on the selected sub-formula. 22129limited simplifications on the selected sub-formula.
22147These are the simplifications that are normally done automatically 22130These simplifications would normally be done automatically
22148on all results, but which may have been partially inhibited by 22131on all results, but may have been partially inhibited by
22149previous selection-related operations, or turned off altogether 22132previous selection-related operations, or turned off altogether
22150by the @kbd{m O} command. This command is just an auto-selecting 22133by the @kbd{m O} command. This command is just an auto-selecting
22151version of the @w{@kbd{a v}} command (@pxref{Algebraic Manipulation}). 22134version of the @w{@kbd{a v}} command (@pxref{Algebraic Manipulation}).
22152 22135
22153With a numeric prefix argument of 2, @kbd{C-u 2 j v} applies 22136With a numeric prefix argument of 2, @kbd{C-u 2 j v} applies
22154the @kbd{a s} (@code{calc-simplify}) command to the selected 22137the default algebraic simplifications to the selected
22155sub-formula. With a prefix argument of 3 or more, e.g., @kbd{C-u j v} 22138sub-formula. With a prefix argument of 3 or more, e.g., @kbd{C-u j v}
22156applies the @kbd{a e} (@code{calc-simplify-extended}) command. 22139applies the @kbd{a e} (@code{calc-simplify-extended}) command.
22157@xref{Simplifying Formulas}. With a negative prefix argument 22140@xref{Simplifying Formulas}. With a negative prefix argument
@@ -22340,15 +22323,8 @@ turn the default simplifications off first (with @kbd{m O}).
22340@kindex H a s 22323@kindex H a s
22341@pindex calc-simplify 22324@pindex calc-simplify
22342@tindex simplify 22325@tindex simplify
22343The @kbd{a s} (@code{calc-simplify}) [@code{simplify}] command applies 22326
22344various algebraic rules to simplify a formula. This includes rules which 22327The sections below describe all the various kinds of
22345are not part of the default simplifications because they may be too slow
22346to apply all the time, or may not be desirable all of the time. For
22347example, non-adjacent terms of sums are combined, as in @samp{a + b + 2 a}
22348to @samp{b + 3 a}, and some formulas like @samp{sin(arcsin(x))} are
22349simplified to @samp{x}.
22350
22351The sections below describe all the various kinds of algebraic
22352simplifications Calc provides in full detail. None of Calc's 22328simplifications Calc provides in full detail. None of Calc's
22353simplification commands are designed to pull rabbits out of hats; 22329simplification commands are designed to pull rabbits out of hats;
22354they simply apply certain specific rules to put formulas into 22330they simply apply certain specific rules to put formulas into
@@ -22358,8 +22334,10 @@ and rewrite rules. @xref{Rearranging with Selections}.
22358@xref{Rewrite Rules}. 22334@xref{Rewrite Rules}.
22359 22335
22360@xref{Simplification Modes}, for commands to control what level of 22336@xref{Simplification Modes}, for commands to control what level of
22361simplification occurs automatically. Normally only the ``default 22337simplification occurs automatically. Normally only the default
22362simplifications'' occur. 22338algebraic simplifications occur. If you have turned on a
22339simplification mode which does not do these default simplifications,
22340you can still perform them on a formula with the @kbd{a s} command.
22363 22341
22364There are some simplifications that, while sometimes useful, are never 22342There are some simplifications that, while sometimes useful, are never
22365done automatically. For example, the @kbd{I} prefix can be given to 22343done automatically. For example, the @kbd{I} prefix can be given to
@@ -22379,29 +22357,23 @@ combinations of @samp{sinh}s and @samp{cosh}s before simplifying.
22379 22357
22380 22358
22381@menu 22359@menu
22382* Default Simplifications:: 22360* Limited Simplifications::
22383* Algebraic Simplifications:: 22361* Algebraic Simplifications::
22384* Unsafe Simplifications:: 22362* Unsafe Simplifications::
22385* Simplification of Units:: 22363* Simplification of Units::
22386@end menu 22364@end menu
22387 22365
22388@node Default Simplifications, Algebraic Simplifications, Simplifying Formulas, Simplifying Formulas 22366@node Limited Simplifications, Algebraic Simplifications, Simplifying Formulas, Simplifying Formulas
22389@subsection Default Simplifications 22367@subsection Limited Simplifications
22390 22368
22391@noindent 22369@noindent
22392@cindex Default simplifications 22370@cindex Limited simplifications
22393This section describes the ``default simplifications,'' those which are 22371This section describes a limited set of simplifications. These, as
22394normally applied to all results. For example, if you enter the variable 22372well as those described in the next section, are normally applied to
22395@expr{x} on the stack twice and push @kbd{+}, Calc's default 22373all results. You can type @kbd{m L} to restrict the simplifications
22396simplifications automatically change @expr{x + x} to @expr{2 x}. 22374done on the stack to this limited set.
22397
22398The @kbd{m O} command turns off the default simplifications, so that
22399@expr{x + x} will remain in this form unless you give an explicit
22400``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic
22401Manipulation}. The @kbd{m D} command turns the default simplifications
22402back on.
22403 22375
22404The most basic default simplification is the evaluation of functions. 22376The most basic simplification is the evaluation of functions.
22405For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@tfn{sqrt}(9)} 22377For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@tfn{sqrt}(9)}
22406is evaluated to @expr{3}. Evaluation does not occur if the arguments 22378is evaluated to @expr{3}. Evaluation does not occur if the arguments
22407to a function are somehow of the wrong type @expr{@tfn{tan}([2,3,4])}), 22379to a function are somehow of the wrong type @expr{@tfn{tan}([2,3,4])}),
@@ -22419,16 +22391,17 @@ operator) do not evaluate their arguments, @code{if} (the @code{? :}
22419operator) does not evaluate all of its arguments, and @code{evalto} 22391operator) does not evaluate all of its arguments, and @code{evalto}
22420does not evaluate its lefthand argument. 22392does not evaluate its lefthand argument.
22421 22393
22422Most commands apply the default simplifications to all arguments they 22394Most commands apply at least these limited simplifications to all
22423take from the stack, perform a particular operation, then simplify 22395arguments they take from the stack, perform a particular operation,
22424the result before pushing it back on the stack. In the common special 22396then simplify the result before pushing it back on the stack. In the
22425case of regular arithmetic commands like @kbd{+} and @kbd{Q} [@code{sqrt}], 22397common special case of regular arithmetic commands like @kbd{+} and
22426the arguments are simply popped from the stack and collected into a 22398@kbd{Q} [@code{sqrt}], the arguments are simply popped from the stack
22427suitable function call, which is then simplified (the arguments being 22399and collected into a suitable function call, which is then simplified
22428simplified first as part of the process, as described above). 22400(the arguments being simplified first as part of the process, as
22429 22401described above).
22430The default simplifications are too numerous to describe completely 22402
22431here, but this section will describe the ones that apply to the 22403Even the limited set of simplifications are too numerous to describe
22404completely here, but this section will describe the ones that apply to the
22432major arithmetic operators. This list will be rather technical in 22405major arithmetic operators. This list will be rather technical in
22433nature, and will probably be interesting to you only if you are 22406nature, and will probably be interesting to you only if you are
22434a serious user of Calc's algebra facilities. 22407a serious user of Calc's algebra facilities.
@@ -22446,7 +22419,7 @@ will also be applied before any built-in default simplifications.
22446\bigskip 22419\bigskip
22447@end tex 22420@end tex
22448 22421
22449And now, on with the default simplifications: 22422And now, on with the limited set of simplifications:
22450 22423
22451Arithmetic operators like @kbd{+} and @kbd{*} always take two 22424Arithmetic operators like @kbd{+} and @kbd{*} always take two
22452arguments in Calc's internal form. Sums and products of three or 22425arguments in Calc's internal form. Sums and products of three or
@@ -22720,29 +22693,29 @@ Most other Calc functions have few if any default simplifications
22720defined, aside of course from evaluation when the arguments are 22693defined, aside of course from evaluation when the arguments are
22721suitable numbers. 22694suitable numbers.
22722 22695
22723@node Algebraic Simplifications, Unsafe Simplifications, Default Simplifications, Simplifying Formulas 22696@node Algebraic Simplifications, Unsafe Simplifications, Limited Simplifications, Simplifying Formulas
22724@subsection Algebraic Simplifications 22697@subsection Algebraic Simplifications
22725 22698
22726@noindent 22699@noindent
22727@cindex Algebraic simplifications 22700@cindex Algebraic simplifications
22728The @kbd{a s} command makes simplifications that may be too slow to 22701@kindex a s
22729do all the time, or that may not be desirable all of the time. 22702@kindex I a s
22730If you find these simplifications are worthwhile, you can type 22703@kindex H a s
22731@kbd{m A} to have Calc apply them automatically. 22704@pindex calc-simplify
22732 22705@tindex simplify
22733This section describes all simplifications that are performed by 22706This section describes all simplifications that are performed by
22734the @kbd{a s} command. Note that these occur in addition to the 22707the default algebraic simplification mode. If you have switched to a different
22735default simplifications; even if the default simplifications have 22708simplification mode, you can switch back with the @kbd{m D} command.
22736been turned off by an @kbd{m O} command, @kbd{a s} will turn them 22709Even in other simplification modes, the @kbd{a s} command will use
22737back on temporarily while it simplifies the formula. 22710these algebraic simplifications to simplifies the formula.
22738 22711
22739There is a variable, @code{AlgSimpRules}, in which you can put rewrites 22712There is a variable, @code{AlgSimpRules}, in which you can put rewrites
22740to be applied by @kbd{a s}. Its use is analogous to @code{EvalRules}, 22713to be applied. Its use is analogous to @code{EvalRules},
22741but without the special restrictions. Basically, the simplifier does 22714but without the special restrictions. Basically, the simplifier does
22742@samp{@w{a r} AlgSimpRules} with an infinite repeat count on the whole 22715@samp{@w{a r} AlgSimpRules} with an infinite repeat count on the whole
22743expression being simplified, then it traverses the expression applying 22716expression being simplified, then it traverses the expression applying
22744the built-in rules described below. If the result is different from 22717the built-in rules described below. If the result is different from
22745the original expression, the process repeats with the default 22718the original expression, the process repeats with the limited
22746simplifications (including @code{EvalRules}), then @code{AlgSimpRules}, 22719simplifications (including @code{EvalRules}), then @code{AlgSimpRules},
22747then the built-in simplifications, and so on. 22720then the built-in simplifications, and so on.
22748 22721
@@ -22767,11 +22740,11 @@ non-adjacent ones.
22767 22740
22768Products are sorted into a canonical order using the commutative 22741Products are sorted into a canonical order using the commutative
22769law. For example, @expr{b c a} is commuted to @expr{a b c}. 22742law. For example, @expr{b c a} is commuted to @expr{a b c}.
22770This allows easier comparison of products; for example, the default 22743This allows easier comparison of products; for example, the limited
22771simplifications will not change @expr{x y + y x} to @expr{2 x y}, 22744simplifications will not change @expr{x y + y x} to @expr{2 x y},
22772but @kbd{a s} will; it first rewrites the sum to @expr{x y + x y}, 22745but the algebraic simplifications; it first rewrites the sum to
22773and then the default simplifications are able to recognize a sum 22746@expr{x y + x y} which can then be recognized as a sum of identical
22774of identical terms. 22747terms.
22775 22748
22776The canonical ordering used to sort terms of products has the 22749The canonical ordering used to sort terms of products has the
22777property that real-valued numbers, interval forms and infinities 22750property that real-valued numbers, interval forms and infinities
@@ -22813,10 +22786,11 @@ as described above.) If there is any common integer or fractional
22813factor in the numerator and denominator, it is canceled out; 22786factor in the numerator and denominator, it is canceled out;
22814for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}. 22787for example, @expr{(4 x + 6) / 8 x} simplifies to @expr{(2 x + 3) / 4 x}.
22815 22788
22816Non-constant common factors are not found even by @kbd{a s}. To 22789Non-constant common factors are not found even by algebraic
22817cancel the factor @expr{a} in @expr{(a x + a) / a^2} you could first 22790simplifications. To cancel the factor @expr{a} in
22818use @kbd{j M} on the product @expr{a x} to Merge the numerator to 22791@expr{(a x + a) / a^2} you could first use @kbd{j M} on the product
22819@expr{a (1+x)}, which can then be simplified successfully. 22792@expr{a x} to Merge the numerator to @expr{a (1+x)}, which can then be
22793simplified successfully.
22820 22794
22821@tex 22795@tex
22822\bigskip 22796\bigskip
@@ -22825,11 +22799,10 @@ use @kbd{j M} on the product @expr{a x} to Merge the numerator to
22825Integer powers of the variable @code{i} are simplified according 22799Integer powers of the variable @code{i} are simplified according
22826to the identity @expr{i^2 = -1}. If you store a new value other 22800to the identity @expr{i^2 = -1}. If you store a new value other
22827than the complex number @expr{(0,1)} in @code{i}, this simplification 22801than the complex number @expr{(0,1)} in @code{i}, this simplification
22828will no longer occur. This is done by @kbd{a s} instead of by default 22802will no longer occur. This is not done by the limited
22829in case someone (unwisely) uses the name @code{i} for a variable 22803simplifications; in case someone (unwisely) wants to use the name
22830unrelated to complex numbers; it would be unfortunate if Calc 22804@code{i} for a variable unrelated to complex numbers, they can use
22831quietly and automatically changed this formula for reasons the 22805limited simplifications.
22832user might not have been thinking of.
22833 22806
22834Square roots of integer or rational arguments are simplified in 22807Square roots of integer or rational arguments are simplified in
22835several ways. (Note that these will be left unevaluated only in 22808several ways. (Note that these will be left unevaluated only in
@@ -28800,7 +28773,7 @@ Edit @code{AlgSimpRules}. @xref{Algebraic Simplifications}.
28800@item s D 28773@item s D
28801Edit @code{Decls}. @xref{Declarations}. 28774Edit @code{Decls}. @xref{Declarations}.
28802@item s E 28775@item s E
28803Edit @code{EvalRules}. @xref{Default Simplifications}. 28776Edit @code{EvalRules}. @xref{Limited Simplifications}.
28804@item s F 28777@item s F
28805Edit @code{FitRules}. @xref{Curve Fitting}. 28778Edit @code{FitRules}. @xref{Curve Fitting}.
28806@item s G 28779@item s G