Lines Matching +refs:simp +refs:is

2 @comment %**start of header (This is for running Texinfo on a region.)
9 @comment %**end of header (This is for running Texinfo on a region.)
102 Permission is granted to copy, distribute and/or modify this document
107 Texts as in (a) below. A copy of the license is included in the section
110 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
148 @dfn{Calc} is an advanced desk calculator and mathematical tool
151 This manual, also written (mostly) by Dave Gillespie, is divided into
154 Calculator use in an easy, hands-on way. The remainder of the manual is
213 Calculator: What it is, how to start it and how to exit from it,
217 * What is Calc::
225 @node What is Calc, About This Manual, Getting Started, Getting Started
226 @section What is Calc?
229 @dfn{Calc} is an advanced calculator and mathematical tool that runs as
277 Calc tries to include a little something for everyone; as a result it is
280 read is the ``Getting Started'' chapter of this manual and possibly the
286 @node About This Manual, Notations Used in This Manual, What is Calc, Getting Started
297 This manual is divided into three major parts: the ``Getting
305 If you are in a hurry to use Calc, there is a brief ``demonstration''
326 Every Calc keyboard command is listed in the Calc Summary, and also
331 @c paragraph that is referenced in the Key or Function Index is marked
346 The Calc manual can be printed, but because the manual is so large, you
348 manual, you will need the @TeX{} typesetting program (this is a free
376 The @key{DEL} key is called Backspace on some keyboards, it is
386 Sometimes the @key{RET} key is not shown when it is ``obvious''
388 is usually omitted in key sequences like @kbd{M-x calc-keypad @key{RET}}.
391 or @kbd{C-x * k} (@code{calc-keypad}). This means that the command is
397 the @kbd{C} key is equivalent to @kbd{M-x calc-cos}, and that
410 Calc. The focus is more on demonstration than explanation, but
430 @infoline the square root of 2+3, which is 2.2360679775.
504 The result @samp{[1.23, 1.97, 1.6, 2, 1.19, 1.08]} is a Calc ``vector.''
525 of the two original columns. (There is also a special
541 in @samp{x y} is required.) Type @w{@kbd{a S x,y @key{RET}}} to solve
596 The key sequence @kbd{C-x *} is bound to the command @code{calc-dispatch},
620 the Calculator also turn it off if it is already on.
651 actually makes two windows side-by-side. The lefthand one is
652 called the @dfn{stack window} and the righthand one is called the
663 The net result is the two numbers 17.3 and @mathit{-5} sitting on the stack.
666 there is a set of commands that allow you to search back through
677 There is nothing stopping you from switching out of the Calc
679 @w{@kbd{C-x o}} (@code{other-window}) command. When the cursor is
681 cursor is in the Calc stack or trail windows, keys are interpreted
692 a fresh stack and trail. There is a command (@kbd{m m}) that lets
694 One of the things it saves is which user interface (standard or
698 The @kbd{q} key is another equivalent way to turn the Calculator off.
708 Finally, @kbd{C-x * o} (@code{calc-other-window}) is like @kbd{C-x * c}
709 except that the Calc window is not selected. The buffer you were
712 switch you to the Calc Trail window. So @kbd{C-x * o} is a handy
720 @dfn{Quick mode} is a quick way to use Calc when you don't need the
724 Quick mode is very simple: It prompts you to type any formula in
743 @dfn{Keypad mode} is a mouse-based interface to the Calculator.
744 It is designed for use with terminals that support a mouse. If you
746 arrow keys (which is probably more trouble than it's worth).
750 instead of at the bottom. The upper window is the familiar Calc
751 Stack; the lower window is a picture of a typical calculator keypad.
786 Keypad mode is much easier for beginners to learn, because there
787 is no need to memorize lots of obscure key sequences. But not all
807 keypad. One advantage of Keypad mode is that you don't need an
823 you must start Emacs first. If all you want is to run Calc, you
848 @dfn{Embedded mode} is a way to use Calc directly from inside an
858 is
875 is
890 you get is copied from the stack back into the buffer. To take the
899 is
906 so that @samp{1 / x ln(x)} is equivalent to @samp{1 / (x ln(x))}.)
917 is
930 @LaTeX{}. (In this example @TeX{} is not being used, so you might want
981 Calculator. The region is defined in the usual Emacs way, by
986 top-to-bottom order. The result is packaged into a Calc vector
988 user interface) is then started. Type @kbd{v u} if you want
995 is a matrix of numbers on the Calculator stack.
997 Complementary to these is @kbd{C-x * y}, which ``yanks'' the
999 If you type @w{@kbd{C-x * y}} while in such a buffer, the value is
1004 is something on the Calc stack.
1006 Here, for reference, is the complete list of @kbd{C-x *} commands.
1022 interface. If Calc is already turned on but the cursor is not
1027 Calc is already turned on and the cursor is in the Calc window,
1053 (This is like @kbd{q} or @key{OFF} inside of Calc.)
1120 (This is the same as @kbd{h i} inside of Calc.)
1137 (This is the ``zero'' digit key.) Reset the Calculator to
1243 @c This node is accessed by the 'C-x * t' command.
1257 go back up from a sub-section to the menu it is part of.
1296 The easiest way to read this tutorial on-line is to have two windows on
1305 This tutorial is designed to be done in sequence. But the rest of this
1355 (Reverse Polish Notation, RPN, is named after the Polish mathematician
1361 (Reverse Polish Notation, RPN, is named after the Polish mathematician
1365 The central component of an RPN calculator is the @dfn{stack}. A
1366 calculator stack is like a stack of dishes. New dishes (numbers) are
1373 and the @expr{+} is the @dfn{operator}. In an RPN calculator you always
1399 The @samp{.} symbol is a marker that represents the top of the stack.
1400 Note that the ``top'' of the stack is really shown at the bottom of
1415 The Stack buffer is just an Emacs buffer, and you can move around in
1417 cursor is, even if you have scrolled the @samp{.} marker out of
1419 before doing anything. It is possible to move the @samp{.} marker
1421 commands like @kbd{+}. This is called @dfn{stack truncation} and
1459 @key{RET} 3 @key{RET} 4 + * -} compute? (@samp{*} is the symbol for
1468 The @key{DEL} key is called Backspace on some keyboards. It is
1475 In the few places where it is really important to use @key{DEL} to
1482 Since the @kbd{-} key is also an operator (it subtracts the top two
1494 is to duplicate the top number on the stack. Consider this calculation:
1515 Another stack manipulation key is @key{TAB}. This exchanges the top
1544 A related stack command is @kbd{M-@key{TAB}} (hold @key{META} and type
1581 typing @kbd{q}. Remember, plain unshifted @kbd{q} is the Quit command.)
1600 gets tiring to type this, Calc provides an @kbd{x} key which is just
1699 typing a series of @key{META}-digits beforehand. If @key{META} is
1737 Another common idiom is @kbd{M-0 @key{DEL}}, which clears the stack.
1746 Calculator in Algebraic mode, which is closer to the way
1751 that @samp{a/b*c} is interpreted as @samp{a/(b*c)}; this is not
1757 The formula is evaluated and the result is pushed onto the RPN stack.
1767 of evaluation clear. In the absence of parentheses, @samp{^} is
1776 is equivalent to
1804 Calc's order of evaluation is the same as for most computer languages,
1807 can often be omitted: @samp{2 a} is the same as @samp{2*a}.
1810 that @samp{^} is evaluated from right to left. Thus, @samp{2-3-4} is
1811 equivalent to @samp{(2-3)-4} or @mathit{-5}, whereas @samp{2^3^4} is equivalent
1814 If you tire of typing the apostrophe all the time, there is
1829 the function name corresponding to the square-root key @kbd{Q} is
1864 though regular numeric keys still use RPN numeric entry. There is also
1905 entries. For example, @kbd{' $$+$ @key{RET}} is just like typing @kbd{+}.
1963 alone, as are calls for which the value is undefined.
1976 calls are not evaluated. In the second call, the logarithm is
1978 is symbolic, and in the fourth, there are too many arguments. In the
1979 fifth case, there is no function called @code{foo}. You will see a
1984 automatically displays the first message only if the message is
2000 One interesting way to work with variables is to use the
2003 the formula with an @samp{=>} symbol. (There is also an @kbd{s =}
2006 between them. The lefthand formula is exactly like you typed it;
2101 did since we loaded the Calculator. If the Trail is not displayed,
2121 the string ``241'' in the trail. This is just a regular Emacs
2135 two-letter sequences where the first letter is called the @dfn{prefix}
2158 When you are in the help display for a prefix key, the prefix is
2164 One more way to correct an error is by editing the stack entries.
2165 The actual Stack buffer is marked read-only and must not be edited
2169 Try entering @samp{3.141439} now. If this is supposed to represent
2187 Perhaps the most fundamental mode in Calc is the current @dfn{precision}.
2198 12 significant figures. That is why, when we type @kbd{1 @key{RET} 7 /},
2216 all, the true value @expr{1/7} is an infinitely repeating decimal;
2225 down to 12 digits before it is used. Try it; press @key{RET} to
2244 answer is that Calc makes a distinction between @dfn{integers} and
2245 @dfn{floating-point} numbers, or @dfn{floats}. An integer is a number
2246 that does not contain a decimal point. There is no such thing as an
2250 If you ask for @samp{2.^10000}, you will quickly get an answer which is
2274 power of,'' and is used by Calc automatically whenever writing the
2290 Hey, the answer is different! Look closely at the middle columns
2316 no matter what. And the verdict is@dots{} Integer powers were more
2361 Engineering notation, not shown here, is like scientific notation
2362 except the exponent (the power-of-ten part) is always adjusted to be
2430 The integer part is grouped but the fractional part isn't. Now try
2458 The number is now displayed in @dfn{hexadecimal}, or ``base-16'' form.
2460 got this number by computing a power of two, and 16 is a power of 2.
2473 something large is to press @kbd{`} (grave accent) to edit the top of
2487 is binary or hexadecimal, but by threes if it is decimal, octal, or any
2513 modes in the natural way (the exponent is a power of the radix instead of
2514 a power of ten, although the exponent itself is always written in decimal).
2517 What is wrong with this picture? What could we write instead that would
2525 The most popular @kbd{m}-prefix mode is the @dfn{angular mode}. Notice
2528 angle is measured in degrees. For example,
2541 of 45 degrees is
2548 wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers
2561 again, this is a shifted capital @kbd{P}. Remember, unshifted
2603 Another interesting mode is @dfn{Fraction mode}. Normally,
2625 because @kbd{/} is already used to divide the top two stack
2632 (@bullet{}) @strong{Exercise 4.} If fractional arithmetic is exact,
2653 on the stack is recomputed when we change the precision, then
2715 integer. There is also @kbd{R}, which rounds to the nearest
2733 Since dividing-and-flooring (i.e., ``integer quotient'') is such a
2735 backslash @kbd{\}. Another common arithmetic operator is @kbd{%}, which
2763 of a situation where this is not true---@kbd{/ F} would be inadequate.
2794 Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum
2797 Another identity is
2811 A physical interpretation of this calculation is that if you move
2813 your direction of motion is @mathit{-64} degrees from horizontal. Suppose
2827 How can the angle be the same? The answer is that the @kbd{/} operation
2829 is negative, we know exactly one of the inputs was negative, but we
2830 can't tell which one. There is an @kbd{f T} [@code{arctan2}] function which
2850 The @key{META}-@key{RET} we used in the third step is the
2851 ``last-arguments'' command. It is sort of like Undo, except that it
2853 the command's result. It is useful in situations like this one,
2859 A similar identity is supposed to hold for hyperbolic sines and cosines,
2860 except that it is the @emph{difference}
2885 enormously so. Try it if you wish; sure enough, the answer is
2888 Of course, a more reasonable way to verify the identity is to use
2936 exact integer 1000. But the @kbd{H E} command is rigged to generate
2970 (which is itself available as the @kbd{f g} command).
2990 is defined by
2994 formula can become quite large even if the final result is small; the
3014 together the elements of this vector. The result is the original
3048 A @dfn{vector} is a list of numbers or other Calc data objects.
3063 If you add two vectors, the result is a vector of the sums of the
3078 spaces. This is true whether we are using incomplete vectors or
3082 If you multiply two vectors, the result is the sum of the products
3083 of the elements taken pairwise. This is called the @dfn{dot product}
3097 The dot product of two vectors is equal to the product of their
3099 is interpreted as a line from the origin @expr{(0,0,0)} to the
3121 is about 56 degrees.
3125 The @dfn{cross product} of two vectors is a vector whose length
3126 is the product of the lengths of the inputs times the sine of the
3127 angle between them, and whose direction is perpendicular to both
3128 input vectors. Unlike the dot product, the cross product is
3147 this vector should be the sine of the angle; sure enough, it is!
3157 to get zero, since the cosine of 90 degrees is zero. Let's check
3158 that the cross product is indeed perpendicular to both inputs:
3188 A @dfn{matrix} is just a vector of vectors, all the same length.
3212 Row @expr{i}, column @expr{j} of the result is effectively the
3230 Though rather hard to read, this is a formula which shows the product
3249 Matrix multiplication is not commutative; indeed, switching the
3253 If you multiply a plain vector by a matrix, it is treated as a
3254 single row or column depending on which side of the matrix it is
3255 on. The result is a plain vector which should also be interpreted
3270 rows in the matrix is different from the number of elements in the
3282 An @dfn{identity matrix} is a square matrix with ones along the
3300 If a matrix is square, it is often possible to find its @dfn{inverse},
3301 that is, a matrix which, when multiplied by the original matrix, yields
3399 The result is the @expr{[a, b, c]} vector that solves the equations.
3400 (Dividing by a square matrix is equivalent to multiplying by its
3458 (@bullet{}) @strong{Exercise 3.} A system of equations is ``over-determined''
3459 if it has more equations than variables. It is often the case that
3461 equations at once, but it is still useful to find a set of values
3464 is not square for an over-determined system. Matrix inversion works
3465 only for square matrices. One common trick is to multiply both sides
3471 $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}.
3476 is a square matrix so a solution is possible. It turns out that the
3518 command returns a vector which is a list of the prime factors of a
3562 the power two. (The general rule is that both operands must be
3608 A slight variant of vector reduction is the @dfn{accumulate} operation,
3623 Actually, most of the time is spent formatting these large vectors
3625 (if your computer is very fast you may need to substitute a larger
3651 (where now the @samp{...} is actually part of the Calc display).
3659 An easy way to view a full vector when @kbd{v .} mode is active is
3725 We want to treat this as a pair of lists. The first step is to
3726 transpose this matrix into a pair of rows. Remember, a matrix is
3753 (Recall that @kbd{t 2} is a variant of @kbd{s 2} that removes the
3756 In a least squares fit, the slope @expr{m} is given by the formula
3774 represents the sum of all the values of @expr{x}. While there is an
3810 Finally, we also need @expr{N}, the number of data points. This is just
3891 common operations from vector algebra. As far as Calc is concerned,
3909 across the vector. (The @code{max} function is on the two-key sequence
3910 @kbd{f x}; because it is so common to use @code{max} in a vector
3941 graphics window. For other kinds of displays, the default is to
3980 (The geometric mean is the @var{n}th root of the product of @var{n} numbers.)
4035 argument and @samp{$} for the second: @kbd{V M ' $$-$ @key{RET}} is
4036 equivalent to @kbd{V M -}. This is analogous to regular algebraic
4044 The function is enclosed in @samp{< >} brackets, and the argument is
4048 trail.) This object is a ``nameless function''; you can use nameless
4051 property that a nameless function is not actually evaluated until
4052 it is used. For example, @kbd{V M ' $+random(2.0)} evaluates
4074 is the sum of the @expr{k}th powers of all the divisors of an
4083 list of prime factors for a number. Sometimes it is important to
4084 know that a number is @dfn{square-free}, i.e., that no prime occurs
4086 keystrokes to tell if a number is square-free; your method should
4087 leave 1 on the stack if it is, or 0 if it isn't.
4132 which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method,
4134 is not allowed! (There is an @kbd{a X} command which does this kind
4148 to try is 25129925999. @xref{List Answer 9, 9}. (@bullet{})
4155 is @cpi{}. The area of the
4158 square that encloses that circle is 4. So if we throw @var{n} darts at
4178 the probability that the GCD (@w{@kbd{k g}}) of two large integers is
4188 Sometimes it is convenient to compute a @dfn{hash code} of a string,
4189 which is just an integer that represents the value of that string.
4195 but it is easier to search among a few names than among all the names.)
4196 One popular hash function is computed as follows: First set @expr{h = 0}.
4198 where @expr{c_i} is the character's ASCII code. If we have 511 buckets,
4201 The hash code for @samp{"Testing, 1, 2, 3"} is 1960915098, which modulo
4202 511 is 121. @xref{List Answer 13, 13}. (@bullet{})
4260 ``simplest'' fraction whose floating-point representation is the
4273 result 1.26508260337. You suspect it is the square root of the
4289 The square root of @mathit{-9} is by default rendered in rectangular form
4294 Another generalized kind of number is @dfn{infinity}. Infinity
4313 Since infinity is infinitely large, multiplying it by any finite
4315 is negative, it changes a plus infinity to a minus infinity.
4323 the finite difference between them, if any, is undetectable.
4324 So we say the result is @dfn{indeterminate}, which Calc writes
4327 Dividing by zero is normally treated as an error, but you can get
4343 Dividing by zero normally is left unevaluated, but after @kbd{m i}
4344 it instead gives an infinite result. The answer is actually
4349 Calc knows that the answer is infinite but not in which direction.
4352 point in saying @samp{-uinf} because the sign of @code{uinf} is
4357 @code{nan} wins out when it is combined with @code{uinf}, or, for
4402 (@bullet{}) @strong{Exercise 4.} The Beatles' @emph{Abbey Road} is
4403 47 minutes and 26 seconds long, and contains 17 songs. What is the
4424 number of days between them. It is also possible to add an
4456 a certain telephone pole is about 30 meters away, with an estimated
4458 meters. What is the slope of a line from here to the top of the
4459 pole, and what is the equivalent angle in degrees?
4472 This means that the angle is about 15 degrees, and, assuming our
4473 original error estimates were valid standard deviations, there is about
4474 a 60% chance that the result is correct within 0.59 degrees.
4477 (@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is
4480 where @expr{R} is the radius of the circle that
4481 defines the center of the tube and @expr{r} is the radius of the tube
4482 itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to
4483 within 5 percent. What is the volume and the relative uncertainty of
4487 error form is best for making statistical estimates, intervals give
4489 our telephone pole is definitely between 28 and 31 meters away,
4490 and that it is between 7.7 and 8.1 meters tall.
4504 is sure to lie in the range shown.
4508 telephone pole is between 28 and 31, @emph{inclusive}. You can also
4509 make an interval that is exclusive of its endpoints by writing
4511 which is inclusive (``closed'') on one end and exclusive (``open'') on
4542 A @dfn{modulo form} is used for performing arithmetic modulo @var{m}.
4543 For example, arithmetic involving time is generally done modulo 12
4558 number, 21. If @var{m} is prime and the divisor is not a multiple of
4559 @var{m}, it is always possible to find such a number. For non-prime
4560 @var{m} like 24, it is only sometimes possible.
4572 These two calculations get the same answer, but the first one is
4581 if @expr{n} is a prime number and @expr{x} is an integer less than
4582 @expr{n}. If @expr{n} is @emph{not} a prime number, this will
4584 informally if a number is prime by trying this formula for several
4588 It is possible to use HMS forms as parts of error forms, intervals,
4603 This calculation tells me it is six hours and 22 minutes until midnight.
4605 (@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year
4606 is about
4619 Another kind of data the Calculator can manipulate is numbers with
4661 root of @samp{acre} is undefined. After all, @code{acre} might be an
4670 There is a wide variety of units defined in the Calculator.
4689 units there is no difference, but temperature units have an offset
4730 the speed of light (and of electricity, which is nearly as fast).
4732 cabinet is one meter across. Is speed of light going to be a
4759 the formula itself is pushed onto the stack. You can manipulate
4791 Let's find the value of this expression when @expr{x} is 2 and @expr{y}
4792 is one-half.
4811 variable @code{x}; if this value is still there, you will have to
4817 is one-half and @expr{x} ranges over all possible values. We can
4819 values of @expr{x} for which the derivative is zero. If the second
4820 derivative of the function at that value of @expr{x} is negative,
4833 Well, the derivative is clearly zero when @expr{x} is zero. To find
4885 The first of these second derivatives is negative, so we know the function
4890 @expr{0.70588 x^2 = 1} is a quadratic equation that ought to have
4891 two solutions. The reason is that @w{@kbd{a S}} normally returns a
4908 it is supposed to be either @mathit{+1} or @mathit{-1}. Here we have used
4909 the ``let'' command to evaluate the expression when the sign is negative.
4911 negative, answer, so @expr{x = -1.19023} is also a maximum.
4927 (Here we see another way to use @kbd{s l}; if its input is an equation
4946 at several values of @samp{s1} at once. @kbd{V M $} is like @kbd{V M '}
4948 formula is interpreted as a function to apply across the vector at the
4953 default list. In this case the default is @samp{(s1)}, which is just
4963 @expr{[1.19023, -1.19023, 0]}. (There is also an @kbd{a X} command
4972 multiple; choose the solution where the leading coefficient is one.)
4978 Fraction mode (@kbd{m f}) is also useful when doing algebra.
4990 One more mode that makes reading formulas easier is Big mode.
5043 like @samp{sqrt(51.0)}. It is always wise to check over the formulas
5052 What is the area under the portion of this curve from @expr{x = 1} to @expr{2}?
5053 This is simply the integral of the function:
5066 One way to do it is again with vector mapping and reduction:
5081 (where the sine is calculated in radians). Find the values of the
5092 long time but would be unable to find a solution. In fact, there is no
5097 One approach would be to do the integral numerically. It is not hard
5098 to do this by hand using vector mapping and reduction. It is rather
5143 the curve is nearly flat at that resolution), we compute the areas
5144 of the boxes (height times width), then sum the areas. (It is
5146 is the same for every box.)
5188 to be a better approximation than stairsteps. A third method is
5189 @dfn{Simpson's rule}, which is like the stairstep method except
5209 where @expr{n} (which must be even) is the number of slices and @expr{h}
5210 is the width of each slice. These are 10 and 0.1 in our example.
5211 For reference, here is the corresponding formula for the stairstep
5234 It uses @dfn{Romberg's method}, which is a more sophisticated cousin
5236 result until the current precision is satisfied.
5288 but when it is given to the @kbd{a r} command, that command interprets
5291 The lefthand side, @samp{a/x + b/x}, is called the @dfn{pattern} of the
5303 because the same meta-variable @samp{x} is used in both of the
5317 that part is replaced by the righthand side with all the meta-variables
5318 substituted with the things they matched. So the result is
5346 have to type it in every time anyway? The answer is that Calc allows
5348 name in the @kbd{a r} command. In fact, this is the preferred way to
5375 efficiently. If the rule is stored in a variable, Calc compiles it
5411 repeating until no further change is possible. (The exact order in
5412 which things are tried is rather complex, but for simple rules like
5456 (Recall, @samp{k % 2} is the remainder from dividing @samp{k} by 2,
5457 which will be zero only when @samp{k} is an even integer.)
5459 An interesting point is that the variable @samp{pi} was matched
5461 This is because it is a special-constant variable. The special
5464 rules is to write, say, @samp{f(a,b,c,d,e) := g(a+b+c+d+e)}, expecting
5466 only when the fifth argument is literally @samp{e}!
5477 the sequence. This is easy to express in a set of three rules:
5490 One thing that is guaranteed about the order that rewrites are tried
5491 is that, for any given subformula, earlier rules in the rule set will
5500 fib(x-4)}, and so on, expanding forever. What we really want is to apply
5501 the third rule only when @samp{n} is an integer greater than two. Type
5537 more work than it needs to when @samp{n} is large. Consider the
5565 for technical reasons it is most effective in @code{EvalRules}.) For
5582 (@bullet{}) @strong{Exercise 2.} Sometimes it is possible to reformulate
5587 @var{n}th and @var{n+1}st Fibonacci numbers, respectively. This rule is
5617 divide @expr{a} by two if it is even, otherwise compute @expr{3 a + 1}.
5619 is that for any starting @expr{a}, the sequence always eventually
5622 is the number of steps it took the sequence to reach the value 1.
5633 @var{x}, or 1 if @var{x} is not a sum. (A @dfn{sum} for our purposes
5634 is one or more non-sum terms separated by @samp{+} or @samp{-} signs,
5635 so that @expr{2 - 3 (x + y) + x y} is a sum of three terms.)
5638 (@bullet{}) @strong{Exercise 6.} A Taylor series for a function is an
5654 is obtained by dropping all the terms higher than, say, @expr{x^2}.
5671 The meaning of @expr{O(x^3)} is ``a quantity which is negligibly small
5672 if @expr{x^3} is considered negligibly small as @expr{x} goes to zero.''
5674 The exercise is to create rewrite rules that simplify sums and products of
5679 rearranged. (This one is rather tricky; the solution at the end of
5681 condition tests whether @samp{x} is a number.) @xref{Rewrites Answer
5694 The Calculator is written entirely in Emacs Lisp, a highly extensible
5698 all you want to do is define a new function or repeat a command a few
5701 One very limited form of programming is defining your own functions.
5716 This polynomial is a Taylor series approximation to @samp{exp(x)}.
5721 default argument list @samp{(x)} is acceptable; and finally @kbd{y}
5753 is defined as the integral of @samp{sin(t)/t} for
5758 which in algebraic notation is written like @samp{ninteg(f(t), t, 0, x)}
5763 Calc is in Radians mode. Also, @code{ninteg} will run a lot faster if
5767 The simplest way to do real ``programming'' of Emacs is to define a
5768 @dfn{keyboard macro}. A keyboard macro is simply a sequence of
5788 When you type @kbd{C-x (}, Emacs begins recording. But it is also
5791 @w{@kbd{C-x )}}, the macro is recorded. You can now type @kbd{X} to
5832 where @expr{x} is the number on the top of the stack.
5894 A fascinating property of the Fibonacci numbers is that the @expr{n}th
5901 the ``golden ratio,'' is
5904 (For convenience, this constant is available from the @code{phi}
5921 is
5943 A more sophisticated kind of loop is the @dfn{for} loop. Suppose
5944 we wish to compute the 20th ``harmonic'' number, which is equal to
5994 harmonic number which is greater than 4.0.
5999 caller was keeping in those same variables. This is easy to
6033 this command is very slow for large @expr{n} since the higher Bernoulli
6047 @kbd{Z ]} as ``end-if.'' There is no need for an explicit ``if''
6048 command. For the purposes of @w{@kbd{Z [}}, the condition is ``true''
6049 if the value it pops from the stack is a nonzero number, or ``false''
6050 if it pops zero or something that is not a number (like a formula).
6054 The actual tenth Bernoulli number is @expr{5/66}.
6082 The vertical-bar @kbd{|} is the vector-concatenation command. When
6084 (initially this is an empty list), and the next Bernoulli number
6085 will be in level 1. The effect is to append the Bernoulli number
6091 in Calc. One other command that makes looping easier is @kbd{Z /},
6093 loop if the condition is true (non-zero). You can use this to make
6098 One technique is to enter a throwaway dummy definition for the macro,
6116 A keyboard macro is stored as a pure keystroke sequence. The
6120 @samp{;;}, and which are ignored when the edited macro is saved.
6121 Spaces and line breaks are also ignored when the edited macro is saved.
6144 1 ;; calc digits (The loop step is 1)
6166 (and @kbd{C-x e}) key. Because this is so useful, Calc puts this
6182 equations numerically is @dfn{Newton's Method}. Given the equation
6184 @expr{x_0} which is reasonably close to the desired solution, apply
6199 where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x}
6207 is zero. Use it to find a solution of
6212 method when it is able. @xref{Programming Answer 8, 8}. (@bullet{})
6220 is defined as the derivative of
6245 While this sum is not guaranteed to converge, in practice it is safe.
6246 An interesting mathematical constant is Euler's gamma, which is equal
6247 to about 0.5772. One way to compute it is by the formula,
6251 for the above formula to work (5 is a much safer value for @expr{z}).
6276 a number @expr{m} on the stack, where the polynomial is of degree
6311 the computation. Recursion is a little difficult with Emacs keyboard
6312 macros since the macro is executed before its definition is complete.
6317 the complete recursive program. (Another way is to use @w{@kbd{Z E}}
6322 @expr{s(4,2)}. (There is a built-in command for Stirling numbers,
6442 The result is
6501 you choose is purely a matter of taste.
6553 But a feature of Calc is that @key{DEL} on an incomplete object
6569 @kbd{M-@key{DEL}} is just like @kbd{@key{TAB} @key{DEL}}, except that it doesn't exhibit
6578 If the @kbd{Q} key is broken, you could use @kbd{' $^0.5 @key{RET}}.
6581 (Actually, @samp{$^1:2}, using the fraction one-half as the power, is
6600 is zero, so it is left in symbolic form. When you now type @kbd{0 *},
6602 times anything is zero.''
6608 show that the answer is ``indeterminate.'' @xref{Infinities}, for
6617 an exact base-3 representation (@samp{3#0.1}), it is still stored as
6619 the calculator's memory. When this inexact number is converted back
6624 to show. If the current precision is 12 (decimal) digits, that corresponds
6625 to @samp{12 / log10(3) = 25.15} base-3 digits. Because 25.15 is not an
6632 0.666667 by 2 to get 0.333334, which is why he got something a little
6641 @samp{0.022222} in base 3 is like @samp{0.099999} in base 10; rounding
6646 Incidentally, another consequence of all this is that if you type
6651 rounds off that 0.15 digit, there is the danger that two numbers could
6657 An interesting side note is that most computers store their
6668 in binary, octal, or hexadecimal is also exact in decimal, so the kinds
6675 If the radix is 15 or higher, we can't use the letter @samp{e} to mark
6676 the exponent because @samp{e} is interpreted as a digit. When Calc
6681 puts you in algebraic entry: @kbd{16#f.e8f @key{RET} e 15 @key{RET} *} is another
6684 The reason Calc puts a decimal point in the @samp{16.^} is to prevent
6685 huge integers from being generated if the exponent is large (consider
6698 The problem is not that the square operation is inexact, but that the
6703 The real problem is that there is no 12-digit number which, when
6731 before anything is done after the number 45 has been entered in order
6740 can't be measured exactly anyway, and if the data that is input to
6741 a calculation is inexact, doing exact arithmetic on it is a waste
6746 integers from 1 to 10 is 7381:2520. The sum from 1 to 30 is
6752 There is no fractional form for the square root of two, so if you type
6760 give a floating-point result that is inaccurate even when rounded
6762 precision is 6 digits. The true answer is @expr{61728394.5}, but
6769 floating-point round-off error is strictly to the right of the
6782 Calc will find an exact result for a logarithm if the result is an integer
6783 or (when in Fraction mode) the reciprocal of an integer. But there is
6811 The average position is equal to the sum of the products of the
6812 positions times their corresponding probabilities. This is the
6814 is to put the two vectors on the stack and press @kbd{*}.
6820 The trick is to multiply by a vector of ones. Use @kbd{r 4 [1 1 1] *} to
6912 The first step is to enter the coefficient matrix. We'll store it in
6956 added to the system is almost identical to the first one multiplied
6984 This is reasonably close to our original @expr{B} vector,
7024 the first job is to form the matrix that describes the problem.
7095 your problem, but there is often an easier way using the higher-level
7099 In fact, there is a built-in @kbd{a F} command that does least-squares
7150 A number @expr{j} is a divisor of @expr{n} if
7153 The first step is to get a vector that identifies the divisors.
7168 The zeroth divisor function is just the total number of divisors.
7169 The first divisor function is the sum of the divisors.
7190 The obvious first step is to obtain the list of factors with @kbd{k f}.
7192 they will be right next to each other. A suitable method is to compare
7218 zero, so adding zeros on the left and right is safe. From then on
7219 the job is pretty straightforward.
7222 function which is zero if and only if its argument is square-free. It
7252 triangular number is the sum of the integers from 1 to @expr{n}, and
7302 since each element of the main vector is itself a small vector,
7309 The first step is to build a list of values of @expr{x}.
7334 A way to isolate the maximum value is to compute the maximum using
7349 one value is equal to the maximum. (After all, a plot of
7355 the maximum value of @expr{x}. Now it is a simple matter to convert
7390 The output from @kbd{a X} is a vector containing the value of @expr{x}
7398 Step one is to convert our integer into vector notation.
7435 the last digit, plus handling carries. There is a carry to the
7436 left out of a digit if that digit is a nine and all the digits to
7520 For the list @expr{[a, b, c, d]}, the result is @expr{((a = b) = c) = d},
7521 which will compare @expr{a} and @expr{b} to produce a 1 or 0, which is
7522 then compared with @expr{c} to produce another 1 or 0, which is then
7523 compared with @expr{d}. This is not at all what Joe wanted.
7604 Our estimate, 3.36, is off by about 7%. We could get a better estimate
7605 by taking more points (say, 1000), but it's clear that this method is
7627 (which is the @expr{x} coordinate of the other endpoint) cross a line.
7632 of the two endpoints as @expr{x}. Then @expr{theta} is an angle pointing
7637 In fact, since the field of lines is infinite we can choose the
7747 if the input vector is @expr{[a, b, c, d]}, then the hash code is
7812 So the result when we take the modulo after every step is,
7841 The @expr{m} term in the latter formula is redundant because any
7858 which is just the formula for taking the modulo only at the end of
7869 step to an @expr{(x,y)} coordinate. The function is a bit long, but
7870 otherwise the problem is quite straightforward.
7907 length; in fact, the new nesting function is even briefer, though
7934 If the number is the square root of @cpi{} times a rational number,
7947 Technically speaking this is a rational number, but not one that is
7978 @samp{inf / inf = nan}. Perhaps @samp{1} is the ``obvious'' answer.
7983 far as Calc is concerned all infinities are the same size.
7986 @expr{x} is not relevant here.
7989 the input is infinite.
7994 The first part is, by definition, @expr{i}; the second is @code{inf}
7998 direction because @code{sqrt} is defined to return a value in the
8016 infinity but not to the second. This is just as true for complex
8026 The moral of this story is that ``infinity'' is a slippery fish
8029 Calc is careful to write @code{nan} any time this simple model is
8030 unable to tell what the true answer is.
8046 The average song length is two minutes and 47.4 seconds.
8065 Let's suppose it's January 14, 1991. The easiest thing to do is
8081 This is getting tedious---we can keep advancing the date by typing
8085 argument is exactly what we want to map over:
8099 Et voilà, September 13, 1991 is a Friday.
8117 The full rule for leap years is that they occur in every year divisible
8121 exceptions, but there is a much simpler way that works even if we
8124 Let's assume the present year is 1991. Years have 365 days, except
8202 Thus the volume is 6316 cubic centimeters, within about 11 percent.
8208 The first answer is pretty simple: @samp{1 / (0 .. 10) = (0.1 .. inf)}.
8211 is an interval that effectively means, ``any number greater than 0.1''
8214 The second answer, similarly, is @samp{1 / (-10 .. 0) = (-inf .. -0.1)}.
8217 @w{@samp{1 / 0}} is left unsimplified. Our third problem,
8219 is now a member of the interval. So Calc leaves this one unevaluated, too.
8226 Zero is buried inside the interval, but it's still a possible value.
8250 In the first case the result says, ``if a number is between @mathit{-3} and
8251 3, its square is between 0 and 9.'' The second case says, ``the product
8252 of two numbers each between @mathit{-3} and 3 is between @mathit{-9} and 9.''
8254 An interval form is not a number; it is a symbol that can stand for
8277 Since 533694123 is (considerably) different from 1, the number 811749613
8281 various ways to avoid this, and algebraic entry is one. In fact, using
8296 The result is three ones (modulo @expr{n}), so it's very probable that
8297 15485863 is prime. (In fact, this number is the millionth prime.)
8306 to prove that a large integer is prime with any desired probability.
8313 One way to convert a number of seconds to an HMS form is simply to
8353 The @kbd{=} key is necessary to evaluate the symbol @samp{pi} to
8384 No matter how long it is, the album will fit nicely on one CD.
8390 Type @kbd{' 1 yr @key{RET} u c s @key{RET}}. The answer is 31557600 seconds.
8409 (Recall, @samp{c} is a ``unit'' corresponding to the speed of light.)
8430 The speed limit is 55 miles per hour on most highways. We want to
8465 The result @samp{sqrt(x)^2} is simplified back to @expr{x} by the
8466 Calculator, but @samp{sqrt(x^2)} is not. (Consider what happens
8467 if @w{@expr{x = -4}}.) If @expr{x} is real, this formula could be
8469 that is not safe. (@xref{Declarations}, for a way to tell Calc
8470 that @expr{x} is known to be real.)
8477 is zero when @expr{x} is any of these values. The trivial polynomial
8478 @expr{x-a} is zero when @expr{x=a}, so the product @expr{(x-a)(x-b)(x-c)}
8512 Sure enough, our answer (multiplied by a suitable constant) is the
8582 The hard part is that @kbd{V R +} is no longer sufficient to add up all
8704 Here is the rule set:
8718 is done. The third rule does the computation itself. It basically
8724 conditions on the first rule, there is no need to put conditions on
8749 really gives for @kbd{M-1 a r} in this situation is @samp{f(3 x, 1, 2)},
8754 @samp{x} is indeed a variable, or to change @samp{x} to @samp{quote(x)}
8766 Here is a suitable set of rules to solve the first part of the problem:
8806 The change to return a vector is quite simple:
8818 Given @samp{seq(6)}, the result is @samp{[6, 3, 10, 5, 16, 8, 4, 2, 1]}.
8820 Notice that the @expr{n > 1} guard is no longer necessary on the last
8821 rule since the @expr{n = 1} case is now detected by another rule.
8823 initial value is suitable before the computation begins.
8825 While still a good idea, this guard is not as vitally important as it
8828 the symbol @samp{x} is either even or odd, so none of the rules will
8839 If @expr{x} is the sum @expr{a + b}, then `@tfn{nterms(}@var{x}@tfn{)}' must
8841 is not a sum, then `@tfn{nterms(}@var{x}@tfn{)}' = 1.
8853 already know that @samp{x} is not a sum.
8859 Here is a rule set that will do the job:
8876 testing purposes, it is better to put them in a different variable,
8885 In the second rule, the sum of two O's is changed to the smaller O@.
8893 is still negligible. (This rule will also match @samp{O(x^3) / 4},
8897 (It is easy to see that if one of these forms is negligible, the other
8898 is, too.) Notice the @samp{x^opt(m)} to pick up terms like
8902 The sixth rule is the corresponding rule for products of two O's.
8906 function calls @samp{series(@var{coefs}, @var{x})} where @var{coefs} is
8920 @var{nmax}, @var{den}]}, where @var{x0} is the point about which the
8921 power series is taken (we've been assuming this was always zero),
8937 change this to @samp{(x)} since @expr{t} is really a dummy variable
8947 One way is to move the number to the top of the stack, operate on
8950 Another way is to negate the top three stack entries, then negate
8955 which is just what we want: @kbd{C-x ( M-- 3 n C-x )}.
9016 This answer is quite accurate.
9022 Here is the matrix:
9038 This program is quite efficient because Calc knows how to raise a
9051 The trick here is to compute the harmonic numbers differently, so that
9085 Thus we find that the 30th harmonic number is 3.99, and the 31st
9086 harmonic number is 4.02.
9092 The first step is to compute the derivative @expr{f'(x)} and thus
9097 (Because this definition is long, it will be repeated in concise form
9142 This is the new guess for @expr{x}. Now we compare it with the
9200 Also, of course, @kbd{a R} is a built-in command that uses Newton's
9208 The first step is to adjust @expr{z} to be greater than 5. A simple
9209 ``for'' loop will do the job here. If @expr{z} is less than 5, we
9217 step is repeated until @expr{z > 5}.
9219 (Because this definition is long, it will be repeated in concise form
9297 This is the value of
9336 produces zero. From this it is easy to see that the @expr{n}th
9340 (Because this definition is long, it will be repeated in concise form
9374 in a variable; it is completely analogous to @kbd{s + 1}. We could
9386 To convert back, a simple method is just to map the coefficients
9430 @w{@kbd{z s}} key is supposed to take two numbers from the stack and
9449 (Because this definition is long, it will be repeated in concise form
9478 (Note that the value 3 that our dummy @kbd{z s} produces is not correct;
9479 it is merely a placeholder that will do just as well for now.)
9505 bogus, once the definition is complete the @kbd{z s} command gets
9527 definition as it reads it in. For this reason, @code{C-x * m} is often
9575 This chapter is the beginning of the Calc reference manual.
9607 Calculator stack and is manipulated exclusively through Calc commands.
9608 It is possible (though not usually necessary) to create several Calc
9610 mode settings. There is exactly one Calc Trail buffer; it records a
9613 still work when the trail buffer's window is selected. It is possible
9615 still exists and is updated silently. @xref{Trail Commands}.
9622 In most installations, the @kbd{C-x * c} key sequence is a more
9624 is a synonym for @kbd{C-x * c} unless you last used Calc
9632 for some commands this is the only form. As a convenience, the @kbd{x}
9634 is like @kbd{M-x} except that it enters the initial string @samp{calc-}
9638 Although Calc is designed to be used from the keyboard, some of
9649 functions or matrix operations. This is done to improve the response time
9650 of the Calculator in the common case when all you need to do is a
9657 the Calculator is loaded if necessary, but it is not actually started.
9658 If the argument is positive, the @file{calc-ext} extensions are also
9667 When full-screen mode is on, @kbd{C-x * c} runs the @code{full-calc}
9670 as a calculator. When Calc is started from the Emacs command line
9675 The @kbd{C-x * o} command is like @kbd{C-x * c} except that the Calc
9676 window is not actually selected. If you are already in the Calc
9686 which prompts you for a formula (like @samp{2+3/4}). The result is
9706 again from inside the Calculator buffer is equivalent to executing
9712 user interface (standard, Keypad, or Embedded) is currently active.
9811 to read this manual on-line. This is basically the same as typing
9813 is not already in the Calc manual, selecting the beginning of the
9814 manual. The @kbd{C-x * i} command is another way to read the Calc
9815 manual; it is different from @kbd{h i} in that it works any time,
9816 not just inside Calc. The plain @kbd{i} key is also equivalent to
9817 @kbd{h i}, though this key is obsolete and may be replaced with a
9824 the Tutorial section of the Calc manual. It is like @kbd{h i},
9829 The @kbd{C-x * t} key is equivalent to @kbd{h t} (but it works at
9837 key is equivalent to @kbd{h s}.
9849 strings, since the @kbd{h k} command is both more convenient and
9892 The @kbd{h b} (@code{calc-describe-bindings}) command is just like
9924 and pushes the result (3) back onto the stack. This number is ready for
9950 The @key{RET} (or equivalent @key{SPC}) key is only required to separate
9955 the stack. @kbd{@key{RET} *} is thus a handy way to square a number.
9972 minibuffer. The number is pushed on the stack when you press the @key{RET}
9973 or @key{SPC} keys. If you press any other non-numeric key, the number is
9974 pushed onto the stack and the appropriate operation is performed. If
9975 you press a numeric key which is not valid, the key is ignored.
9997 During numeric entry, the only editing key available is @key{DEL}.
10008 calculations in algebraic form. This is accomplished by typing the
10049 command, it enables Incomplete Algebraic mode; this is like regular
10062 is the command to quit Calc, @kbd{M-p} sets the precision, and
10065 that @kbd{2+3 M-S} is equivalent to @kbd{2+3 @key{RET} M-S}. The symbol
10080 initiates algebraic entry; the @kbd{'} is unnecessary if @kbd{$} is the
10088 with the answer. (All information about the top stack element is thus lost
10091 A slightly different way to refer to stack elements is with a dollar
10094 to numerically are not replaced by the algebraic entry. That is, while
10099 is pushed onto the stack in turn. For example, @samp{1,2,3} pushes
10113 is being pushed on the stack. Thus @kbd{' 1+2 @key{RET}} pushes 3
10115 you might then press @kbd{=} when it is time to evaluate this formula.
10124 There is another way to invoke the Calculator if all you need to do
10125 is make one or two quick calculations. Type @kbd{C-x * q} (or
10137 If this is the first time you have used the Calculator in this Emacs
10147 effect is the same as pressing the apostrophe key (algebraic entry).
10149 The result of a Quick calculation is placed in the Emacs ``kill ring''
10157 by typing @key{LFD} (or @kbd{C-j}) instead of @key{RET}, the result is
10163 If the formula you enter is an assignment to a variable using the
10165 then the result of the evaluation is stored in that Calc variable.
10168 If the result is an integer and the current display radix is decimal,
10170 the integer is in the range from 1 to 126, it will also be displayed as
10174 result @samp{[120]} (because 120 is the ASCII code of the lower-case
10175 ``x''; @pxref{Strings}). Since this is a vector, not an integer, it
10176 is displayed only according to the current mode settings. But
10181 Please note that the Quick Calculator is not any faster at loading
10197 which is interpreted as an index into the stack. A positive argument
10205 (that is, functions of one argument like absolute value or complex
10215 This feature is not available for operations which use the numeric prefix
10250 specified number of operations. When the Calculator is quit, as with
10254 is @expr{100}. (Recall that @kbd{C-x * c} is synonymous with
10266 mistakenly undone. Pressing @kbd{U} with a negative prefix argument is
10269 information is cleared whenever you give any command that adds new undo
10277 The @kbd{M-@key{RET}} key (@code{calc-last-args}) is like undo in that
10287 It is also possible to recall previous results or inputs using the trail.
10290 The standard Emacs @kbd{C-_} undo key is recognized as a synonym for @kbd{U}.
10328 It is possible to have any number of Calc mode buffers at once.
10329 Usually this is done by executing @kbd{M-x another-calc}, which
10330 is similar to @kbd{C-x * c} except that if a @file{*Calculator*}
10332 form @file{*Calculator*<@var{n}>} is created. You can also use the
10344 Calculator buffer is created. The @code{calc-quit} command saves
10347 There is only one trail buffer, @file{*Calc Trail*}, used by all
10371 The Calc program is split into many component files; components are
10373 Occasionally Calc may lose track of when a certain component is
10379 If this happens, the easiest workaround is to type @kbd{C-x * L}
10404 The limit is always increased (multiplied) by a factor of two. There
10405 is also an @kbd{I M} (@code{calc-less-recursion-depth}) command which
10407 The default value is 1000.
10410 internal Lisp recursion limit. The minimum value for this limit is 600.
10421 is greater than this, it will recompute @cpi{} using a series
10428 The visible effect of caching is that
10452 in which the timing of slow commands is reported in the Trail.
10454 to the Trail showing how many seconds it took. This value is
10458 taken to format the result for display in the stack and trail is
10467 Another advantage of the @kbd{X} command is that while it is
10475 Another thing @kbd{Z T} does is to increase the Emacs variable
10477 usual default in Calc is 250,000) for the duration of each command.
10480 abnormally large. (Garbage collection time is a major unpredictable
10483 Another command that is useful when debugging your own Lisp
10484 extensions to Calc is @kbd{M-x calc-pass-errors}, which disables
10537 integers is not an integer, it is expressed in fractional or
10541 A decimal integer is represented as an optional sign followed by a
10547 A non-decimal integer is represented as an optional sign, a radix
10553 number, the current display radix is used.
10560 A @dfn{fraction} is a ratio of two integers. Fractions are traditionally
10581 A floating-point number or @dfn{float} is a number stored in scientific
10582 notation. The number of significant digits in the fractional part is
10584 range of acceptable values is from
10611 For example, @samp{23.5e-2} is 23.5 times ten to the minus-second power,
10621 of each operation is rounded to the nearest value representable in the
10624 display mode) what you see is exactly what you get. Some operations such
10628 accuracy is not rigorously guaranteed. If you suspect the validity of a
10630 Calculator's arithmetic is not intended to be IEEE-conformant in any
10635 float that is entered in a radix other that 10 will be converted to
10639 is a floating-point number whose digits are in the specified radix.
10640 Note that the @samp{.} is more aptly referred to as a ``radix point''
10641 than as a decimal point in this case. The number @samp{8#123.4567} is
10642 defined as @samp{8#1234567 * 8^-4}. If the radix is 14 or less, you can
10644 notation. The exponent is written in decimal, and is considered to be a
10645 power of the radix: @samp{8#1234567e-4}. If the radix is 15 or above,
10646 the letter @samp{e} is a digit, so scientific notation must be written
10656 polar. The default format is rectangular, displayed in the form
10657 @samp{(@var{real},@var{imag})} where @var{real} is the real part and
10658 @var{imag} is the imaginary part, each of which may be any real number.
10665 where @var{r} is the nonnegative magnitude and
10668 is the argument or phase angle. The range of
10671 depends on the current angular mode (@pxref{Angular Modes}); it is
10681 a negative real), the current @dfn{Polar mode} is used to determine the
10684 A complex result in which the imaginary part is zero (or the phase angle
10685 is 0 or 180 degrees or @cpi{} radians) is automatically converted to a real
10707 Mathematically speaking, it is not rigorously correct to treat
10710 really mean is that @expr{1 / x}, as @expr{x} becomes larger and
10724 approaches zero. But if all we have is @expr{1 / 0}, we can't
10728 toward zero, the answer is @samp{1 / 0 = -inf}. In fact, @expr{x}
10731 @dfn{undirected infinity}, i.e., a value which is infinitely
10736 already have them. Thus, @expr{1 / 0} is treated simply as an
10739 @expr{1 / 0} evaluates to @code{uinf} instead. There is also
10742 is less mathematically correct, it may be the answer you want in
10746 e.g., @samp{5 inf} to @samp{inf}. Another example is
10747 @samp{5 - inf = -inf}, where the @samp{-inf} is so large that
10763 arithmetic; it stands for ``Not A Number.'' This is somewhat of a
10782 The @dfn{vector} data type is flexible and general. A vector is simply a
10784 whole is a vector in the mathematical sense. When these objects are
10785 themselves vectors of equal (nonzero) length, the whole is a @dfn{matrix}.
10786 A vector which is not a matrix is referred to here as a @dfn{plain vector}.
10788 A vector is displayed as a list of values separated by commas and enclosed
10789 in square brackets: @samp{[1, 2, 3]}. Thus the following is a 2 row by
10800 Traditional vector and matrix arithmetic is also supported;
10803 the complex conjugate of a vector is a vector of the complex conjugates
10825 Rather, a string is represented simply as a vector all of whose
10860 there is one, or otherwise uses a @samp{\^} sequence.
10862 The only Calc feature that uses strings is @dfn{compositions};
10870 There is a @code{string} function which provides a different display
10872 is a vector of integers in the proper range, is displayed as the
10877 only way to turn it off is to use @kbd{d U} (unformatted language
10889 The @code{bstring} function is just like @code{string} except that
10890 the resulting string is breakable across multiple lines if it doesn't
10901 argument, the interpretation is Degrees-Minutes-Seconds. All functions
10903 degrees regardless of the current angular mode. It is also possible to
10932 The default format for HMS values is
10936 @samp{@@}, @samp{m} is accepted in place of @samp{'}, and @samp{s} is
10938 The @var{hours} value is an integer (or integer-valued float).
10939 The @var{mins} value is an integer or integer-valued float between 0 and 59.
10940 The @var{secs} value is a real number between 0 (inclusive) and 60
10941 (exclusive). A positive HMS form is interpreted as @var{hours} +
10942 @var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted
10944 Display format for HMS forms is quite flexible. @xref{HMS Formats}.
10962 Simple date arithmetic is supported: Adding a number to a date
10970 The default format is, e.g., @samp{<Wed Jan 9, 1991>} for dates,
10972 Input is flexible; date forms can be entered in any of the usual
10977 If the internal number is an integer, the form represents a date only;
10978 if the internal number is a fraction or float, the form represents
10980 is represented by the number 726842.25. The standard precision of
10981 12 decimal digits is enough to ensure that a (reasonable) date and
10984 If the current precision is greater than 12, date forms will keep
10986 precision is 15, the seconds will keep three digits after the
10991 forms without times are stored as exact integers, so roundoff is
10999 year numbers represent years BC@. There is no ``year 0''; the day
11000 before @samp{<Mon Jan 1, +1>} is @samp{<Sun Dec 31, -1>}. These are
11002 Gregorian calendar is used for all dates, including dates before the
11055 Another day counting system in common use is, confusingly, also called
11057 is the numbers of days since 12:00 noon (GMT) on November 24, 4714 BC
11059 calendar). In Calc's scheme (in GMT) the Julian day origin is
11066 The Julian day number is based on the Julian cycle, which was invented
11070 Julian cycle is based on three other cycles: the indiction cycle, the
11071 Metonic cycle, and the solar cycle. The indiction cycle is a 15 year
11073 date medieval documents. The Metonic cycle is a 19 year cycle; 19
11074 years is close to being a common multiple of a solar year and a lunar
11076 same days of the year. The solar cycle is a 28 year cycle; the Julian
11078 which contains multiples of all three cycles is the least common
11080 pairwise relatively prime) is
11083 This is the length of a Julian cycle. Working backwards, the previous
11094 noon GMT@.) Julian day numbering is largely used in astronomy.
11108 for California time. The same is usually true of Julian day
11117 A @dfn{modulo form} is a real number which is taken modulo (i.e., within
11125 integers but this is not required.
11151 @expr{M}. If one argument is a modulo form and the other a plain number,
11152 the plain number is treated like a compatible modulo form. It is also
11153 possible to raise modulo forms to powers; the result is the value raised
11155 are integers, this calculation is done much more efficiently than
11161 integers. The result is the modulo form which, when multiplied by
11163 there is no solution to this equation (which can happen only when
11164 @expr{M} is non-prime), or if any of the arguments are non-integers, the
11165 division is left in symbolic form. Other operations, such as square
11171 modulo @expr{M}, this is not a useful definition from the
11174 It is possible to mix HMS forms and modulo forms. For example, an
11202 An @dfn{error form} is a number with an associated standard
11213 complex. If the error is negative or complex, it is changed to its
11214 absolute value. An error form with zero error is converted to a
11222 is defined by the error of @expr{x} times the derivative of @expr{f}
11224 @expr{f(x,y)} (such as addition) the error is the square root of the sum
11240 A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
11241 is not the same as @samp{(2 +/- 1)^2}; the former represents the product
11243 distributions, and the latter is the product of one random value with itself.
11253 is
11256 When @expr{x} is close to zero,
11259 is close to one so the error in the sine is close to
11265 is approximately @expr{x} near zero, so a given error in @expr{x} will
11269 is nearly zero and so the computed error is
11270 small: The sine curve is nearly flat in that region, so an error in @expr{x}
11274 However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so
11296 the squares of the absolute values of the two error contributions) is
11303 the mean and the error should be HMS forms if either one is.
11316 An @dfn{interval} is a subset of consecutive real numbers. For example,
11322 from 1 to 8. Interval arithmetic is used to get a worst-case estimate
11357 one value, @samp{[3 ..@: 3]}, is converted to a plain number (3)
11359 @samp{[3 ..@: 2]} or @samp{[2 ..@: 2)}) can be represented but is not
11369 left to right, so that @samp{1...1e2} is interpreted as @samp{1.0 ..@: 1e2}
11372 a default of @samp{-inf} or @samp{inf} (respectively) is furnished.
11379 a zero is not an issue in this case since the zero is always assumed
11381 contain zero inside them Calc is forced to give the result,
11389 means a variable is random, and its value could
11390 be anything but is ``probably'' within one
11395 variable's value is unknown, but guaranteed to lie in the specified
11411 from @samp{a} to @samp{b}; @samp{n} is an integer code which must
11450 When @kbd{(} or @kbd{[} is typed to begin entering a complex number or
11451 vector, respectively, the effect is to push an @dfn{incomplete} complex
11463 is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people
11472 The @kbd{;} key is used in the same way as @kbd{,} to create polar complex
11473 numbers: @kbd{( 1 ; 2 )}. When entering a vector, @kbd{;} is useful for
11474 creating a matrix. In particular, @kbd{[ [ 1 , 2 ; 3 , 4 ; 5 , 6 ] ]} is
11479 Incomplete entry is also used to enter intervals. For example,
11482 you type a second period immediately afterward, it is re-interpreted as
11494 A @dfn{variable} is somewhere between a storage register on a conventional
11496 variable is really just an Emacs Lisp variable that contains a Calc number
11497 or formula.) A variable's name is normally composed of letters and digits.
11505 contains any dashes, the prefix @samp{var-} is @emph{not} automatically
11570 interchangeably.) An expression is built up of numbers, variable names,
11625 strongly than division: @samp{a*b/c*d} is equivalent to
11632 if the righthand side is a number, variable name, or parenthesized
11635 the rule is that a variable name followed by a parenthesized expression,
11637 is interpreted as a function call, not an implicit @samp{*}. In many
11638 cases you must use a space if you omit the @samp{*}: @samp{2a} is the
11639 same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
11640 is a variable called @code{ab}, @emph{not} the product of @samp{a} and
11641 @samp{b}! Also note that @samp{f (x)} is still a function call.
11645 In vectors, the space character is interpreted (like the comma) as a
11646 separator of elements of the vector. Thus @w{@samp{[ 2a b+c d ]}} is
11647 equivalent to @samp{[2*a, b+c, d]}, whereas @samp{2a b+c d} is equivalent
11651 enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
11652 interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted
11656 brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector
11659 @w{@samp{[a - b]}} is a vector of one element, but @w{@samp{[a -b]}} is
11666 The expression @samp{5%-2} is ambiguous; is this five-percent minus two,
11672 A function call is, e.g., @samp{sin(1+x)}. (The Calc algebraic function
11677 If no Lisp function is defined for a function called by a formula, the
11678 call is left as it is during algebraic manipulation: @samp{f(x+y)} is
11705 %% last line is coming up:
11710 This is parsed exactly the same as @samp{[ a + b, c + d, e + f ]}.
11757 have it, else on @kbd{C-j}) is like @code{calc-enter}
11758 except that the sign of the numeric prefix argument is interpreted
11759 oppositely. Also, with no prefix argument the default argument is 2.
11770 The @kbd{C-d} key is a synonym for @key{DEL}.
11771 (If the top element is an incomplete object with at least one element, the
11772 last element is removed from it.) Given a positive numeric prefix argument,
11774 element of the stack is deleted. Given an argument of zero, the entire
11775 stack is emptied.
11784 The @kbd{M-@key{DEL}} (@code{calc-pop-above}) command is to @key{DEL} what
11785 @key{LFD} is to @key{RET}: It interprets the sign of the numeric
11786 prefix argument in the opposite way, and the default argument is 2.
11792 If the customizable variable @code{calc-context-sensitive-enter} is
11808 Given a negative argument, the entire stack is rotated downward the specified
11809 number of times. Given an argument of zero, the entire stack is reversed
11819 The command @kbd{M-@key{TAB}} (@code{calc-roll-up}) is analogous to @key{TAB}
11821 with no prefix argument is to rotate the top 3 elements.
11828 A good way to view the operation of @key{TAB} and @kbd{M-@key{TAB}} is in
11872 Emacs commands. Note that @kbd{`} is a grave accent, not an apostrophe.
11891 The formula is normally reevaluated as it is put onto the stack.
11902 rearranged the stack in the meanwhile. This is not so much of a problem
11907 each line of the @file{*Calc Edit*} buffer is interpreted as a
11908 separate formula. Otherwise, the entire buffer is interpreted as
11913 text entered so far is moved to the @file{*Calc Edit*} buffer for
11914 more extensive editing than is convenient in the minibuffer.
11927 trail on and off. Normally the trail display is toggled on if it was off,
11931 the trail on. Note that when the trail is off values are still recorded
11944 trail, and they work ``by remote control'' when the cursor is still
11948 There is a @dfn{trail pointer} which selects some entry of the trail at
11995 commands, @kbd{t h} works only when Calc Trail is the selected window.
12021 line of text of your own choosing into the trail. The text is inserted
12022 after the line containing the trail pointer; this usually means it is
12029 from the trail. The line is saved in the Emacs kill ring suitable for
12030 yanking into another buffer, but it is not easy to yank the text back
12034 The @kbd{t .} (@code{calc-full-trail-vectors}) command is described
12057 formula and then simplifying the copy. One difference is that for a very
12071 command is effectively the same as @kbd{K s t}. @xref{Storing Variables}.
12117 precision and binary word size, whether or not the trail is displayed,
12119 interface (used when you type @kbd{C-x * *}) is also saved. If there
12121 Otherwise, the new mode information is appended to the end of the
12129 ``automatic mode recording'' mode is also saved.
12132 necessary. (If Embedded mode is enabled, other options for recording
12144 file name is @file{~/.emacs.d/calc.el}. You can see the current file name by
12148 If the file name you give is your user init file (typically
12150 is because your user init file may contain other things you don't want
12156 which is useful if you intend your new file to have a variant of the
12165 has effect when Calc is first loaded, @kbd{m x} is usually followed by
12175 @kbd{A S} instead. When this mode is enabled, the commands that used to
12180 prefix is not affected by this mode. Press @kbd{m S} again to disable
12203 what you see is what you get. Reducing the current precision does not
12210 It is important to distinguish the concepts of @dfn{precision} and
12213 The precision is the total number of digits not counting leading
12215 The accuracy is simply the number of digits after the decimal point
12231 cents with two digits after the decimal point), one solution is to work
12246 There is no single-key equivalent to the @code{calc-arcsin} function.
12250 is set, the word @samp{Inv} appears in the mode line.
12257 @code{calc-arcsinh}. (The Hyperbolic flag is also used by some
12262 may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to
12274 are also cleared if the next keystroke is not a Calc command.) Digits
12277 same is true of @kbd{C-u}, but not of the minus sign (@kbd{K -} means
12280 Another Calc prefix flag, @kbd{K} (keep-arguments), is discussed
12289 The @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
12309 and degrees-minutes-seconds. When a number is presented to a function
12310 like @code{sin} that requires an angle, the current angular mode is
12312 form is presented to @code{sin}, it is always interpreted as
12317 result is a complex number and the current mode is HMS, the number is
12331 The current angular mode is displayed on the Emacs mode line.
12332 The default angular mode is Degrees.
12340 sense that rectangular form is used when the proper form can not be
12359 rather get an exact fractional answer. One way to accomplish this is
12390 on and off. When the mode is off, infinities do not arise except
12392 is that infinite open intervals like @samp{[0 .. inf)} can be
12394 will not be generated when Infinite mode is off.)
12408 which zero is treated as positive instead of being directionless.
12413 single symbol, @samp{0}. One consequence of this is that, while
12415 is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}.
12425 algebraic expression, produces a numeric answer if the argument is a
12426 number or a symbolic expression if the argument is an expression:
12465 otherwise. One major effect is that Calc will no longer consider
12467 @samp{A*B} is not the same as @samp{B*A}.) This assumption affects
12469 mode is that calculations that would normally produce constants like
12474 identity matrix; if @var{n} is omitted, it doesn't know what
12476 form. However, if this generic identity matrix is later combined
12477 with a matrix whose size is known, it will be converted into
12479 if it is combined with a scalar (as in @samp{idn(1) + 2}), Calc
12487 another 3-vector. In Scalar mode, @samp{a} is assumed to be a
12488 non-vector, and the addition is evaluated to @samp{[x+a, y+a, z+a]}.
12502 affairs, which is probably that some quantities will be matrices
12503 and others will be scalars. One solution is to ``declare''
12507 There is nothing stopping you from declaring a variable to be
12515 Another way to mix scalars and matrices is to use selections
12536 attached Embedded mode buffer, if there is one). They will not
12539 recomputation is off, you can think of @kbd{m C m C} as a command
12543 automatic recomputation is off, use @w{@kbd{C-x * u}}.
12552 Since the Calculator is written entirely in Emacs Lisp, which is not
12569 considerably, experiments have shown that their impact is actually
12570 quite small. But if your terminal is slow you may find that it helps
12606 example, @expr{1+2} is simplified to @expr{3}, and @expr{a+(2-2)} is
12608 is not a constant. Unfortunately, @expr{(a+2)-2} is @emph{not} simplified
12610 constant numbers (one of them is the formula @expr{a+2}).
12611 A constant is a number or other numeric object (such as a constant
12626 simplifications to a result and then, if the result is an integer,
12650 A common technique is to set the simplification mode down to the lowest
12658 A @dfn{declaration} is a statement you make that promises you will
12675 The @kbd{s d} (@code{calc-declare-variable}) command is the easiest
12678 at the declaration prompt is the previous declaration, if any.
12683 A declaration is in general a vector of @dfn{type symbols} and
12684 @dfn{range} values. If there is only one type symbol or range value,
12705 the call are ignored; the effect is to say that this function returns
12726 If there is a declaration for the variable @code{All}, then that
12738 The type-specifier part of a declaration (that is, the second prompt
12752 Here @code{a} is declared to contain one of the five integers shown;
12753 @code{b} is any number in the interval from 1 to 5 (any real number
12754 since we haven't specified), and @code{c} is any integer in that
12759 nothing is known about a given variable's value. This is the same
12763 The initial value of @code{Decls} is the empty vector @samp{[]}.
12765 is not valid, it is ignored and there are no declarations as far
12766 as Calc is concerned. (The @kbd{s d} command will replace such a
12799 @samp{((-3)^2)^1:2} is 3, but @samp{(-3)^(2*1:2) = (-3)^1} is @mathit{-3}.
12800 However, this simplification @emph{is} safe if @code{z} is known
12801 to be an integer, or if @code{x} is known to be a nonnegative
12811 it is able to determine that @samp{2n+1} must be an odd integer.)
12819 One instance of this simplification is @samp{sqrt(x^2)} (since the
12820 @code{sqrt} function is effectively a one-half power). Normally
12829 @code{real} is effectively the same as the range @samp{[-inf .. inf]}
12830 (note that infinity is included in the range of possible values);
12831 @code{pos} is the same as @samp{(0 .. inf]}, and @code{nonneg} is
12832 the same as @samp{[0 .. inf]}. Saying @samp{[real, [-5 .. 5]]} is
12833 redundant because the fact that the variable is real can be
12837 Note that the vector of intervals or numbers is in the same format
12840 The type specifier @samp{[1, 2, 3]} is equivalent to
12849 results are unpredictable. An example is @samp{[pos, [0 .. 5]]},
12855 is in the @kbd{a P} command which returns a list of all roots of a
12865 from both sides of @samp{a x = b x} only if it is sure @code{x}
12866 is non-zero, say, because it has a @code{pos} declaration.
12867 To declare specifically that @code{x} is real and non-zero,
12868 use @samp{[[-inf .. 0), (0 .. inf]]}. (There is no way in the
12869 current notation to say that @code{x} is nonzero but not necessarily
12871 including canceling @samp{x} from the equation when @samp{x} is
12878 The value is not a vector.
12880 The value is a vector.
12882 The value is a matrix (a rectangular vector of vectors).
12884 The value is a square matrix.
12889 is a matrix of integers.
12893 is normally not simplified to @samp{[a + x, b + x, c + x]}, but
12895 other hand, multiplication is usually assumed to be commutative,
12905 One more type symbol that is recognized is used with the @kbd{H a d}
12910 The value is a constant with respect to other variables.
12918 was declared @code{pos} and the formula @samp{sqrt(x^2)} is
12919 simplified to @samp{x} before the value is substituted. Before
12920 using a variable for a new purpose, it is best to use @kbd{s d}
12938 For example, @samp{dint(17)} returns 1 because 17 is an integer, as
12956 The @code{dint} function checks if its argument is an integer.
12957 The @code{dnatnum} function checks if its argument is a natural
12959 checks if its argument is numerically an integer, i.e., either an
12969 The @code{drat} function checks if its argument is rational, i.e.,
12977 The @code{dreal} function checks if its argument is real. This
12984 The @code{dimag} function checks if its argument is imaginary,
12985 i.e., is mathematically equal to a real number times @expr{i}.
13012 The @code{dnonzero} function checks that its argument is nonzero.
13017 represent values which could be anything including zero. (This is
13028 The @code{deven} function returns 1 if its argument is known to be
13030 is known not to be even (because it is known to be odd or a non-integer).
13032 @samp{x % 2 = 0}. There is also an analogous @code{dodd} function.
13040 the set of possible values of its argument. If the argument is
13041 a variable or a function with a declaration, the range is copied
13044 etc., and a suitable set like @samp{[0 .. inf]} is returned. If
13045 the expression is not provably real, the @code{drange} function
13052 The @code{dscalar} function returns 1 if its argument is provably
13053 scalar, or 0 if its argument is provably non-scalar. It is left
13055 mode is in effect, this function returns 1 or 0, respectively,
13058 ``false.'' Thus, @samp{dscalar(a)} is ``true'' only if @code{a} is
13059 provably scalar, and @samp{!dscalar(a)} is ``true'' only if @code{a}
13060 is provably non-scalar; both are ``false'' if there is insufficient
13074 One thing all display modes have in common is their treatment of the
13085 reformat the specified entry, and a prefix of zero is equivalent to
13091 is set only temporarily; the top stack entry is reformatted according
13092 to that mode, then the original mode setting is restored. In other
13093 words, @kbd{I d s} is equivalent to @kbd{H d s d @key{RET} H d (@var{old mode})}.
13117 When the radix is above 10, the letters @code{A} to @code{Z} are used as
13130 current radix is used as a default if you press @kbd{#} without any initial
13131 digits. A number entered without a @kbd{#} is @emph{always} interpreted
13147 word size.) If the absolute value of the word size is @expr{w}, all integers
13156 notation, although this is most useful with the binary, octal and
13157 hexadecimal display modes. This option is selected by using the
13177 to @expr{2^w-1} (the integer @expr{k} is represented by @expr{k+2^w}).
13202 example, the factorial of 30 is 33 digits long! Press @kbd{d g}
13218 character as the grouping separator. The default is the comma character.
13221 This command takes the next character you type, whatever it is, and
13227 (@xref{Kill and Yank}, for details on these commands.) One exception is
13229 is ignored by @TeX{} language mode.
13236 form, with scientific notation used if the exponent is especially high
13248 precision is used. (Thus @kbd{C-u -2 d n} displays 10 digits if the
13249 current precision is 12.)
13254 notation. The numeric argument is the number of digits after the
13257 way to zero. Specifying a negative number of digits is the same as
13268 The default is to display all significant digits.
13274 notation. This is similar to scientific notation except that the
13275 exponent is rounded down to a multiple of three, with from one to three
13279 It is important to distinguish between the current @emph{precision} and
13292 as a decimal point. Normally this is a period; users in some countries
13293 may wish to change this to a comma. Note that this is only a display
13304 form. The default is as a pair of real numbers enclosed in parentheses
13334 Display of fractional numbers is controlled by the @kbd{d o}
13336 eight thirds is displayed in the form @samp{8:3}. The @kbd{d o} command
13338 that character is used as the fraction separator. Common separators are
13340 used regardless of the display format; in particular, the @kbd{/} is used
13346 the number is interpreted in this form (so that the entries @kbd{2:2:3}
13349 It is also possible to follow the one- or two-character format with
13357 affected by this mode: 3 is displayed as @expr{18:6}. Note that the
13375 Punctuation is zero or more spaces, commas, or semicolons. The hours
13376 marker is one or more non-punctuation characters. The minutes and
13379 The default HMS format is @samp{@@ ' "}, producing HMS values of the form
13388 The @kbd{'} key is recognized as ``minutes'' only if @kbd{@@} (or @kbd{h} or
13407 The default format is: @samp{<H:mm:SSpp >Www Mmm D, YYYY}.
13408 An example string in this format is @samp{3:32pm Wed Jan 9, 1991}.
13409 If you enter a blank format string, this default format is
13437 The ISO 8601 calendar date representation is
13444 where @var{YYYY} is the four digit year, @var{MM} is the two-digit month
13445 number (01 for January to 12 for December), and @var{DD} is the
13449 least four digits, is the Gregorian year, except that the year before
13450 0001 (1 AD) is the year 0000 (1 BC). The date October 11, 2012 is
13451 written 2012-10-11 in this representation and November 10, 2012 is
13454 The ISO 8601 ordinal date representation is
13461 where @var{YYYY} is the year, as above, and @var{DDD} is the day of the year.
13462 The date December 31, 2011 is written 2011-365 in this representation
13463 and January 1, 2012 is written 2012-001.
13465 The ISO 8601 week date representation is
13472 where @var{YYYY} is the ISO week-numbering year, @var{ww} is the two
13473 digit week number (preceded by a literal ``W''), and @var{D} is the day
13475 year is based on the Gregorian year but can differ slightly. The first
13476 week of an ISO week-numbering year is the week with the Gregorian year's
13478 any day of that week (Monday through Sunday) is part of the same ISO
13479 week-numbering year, any day from the previous week is part of the
13480 previous year. For example, January 4, 2013 is on a Friday, and so
13482 Monday, December 31, 2012. The day December 31, 2012 is then part of the
13493 The ISO 8601 standard uses a 24 hour clock; a particular time is
13494 represented by @var{hh}:@var{mm}:@var{ss} where @var{hh} is the
13495 two-digit hour (from 00 to 24), @var{mm} is the two-digit minute (from
13496 00 to 59) and @var{ss} is the two-digit second. The seconds or minutes
13498 time is represented, they should be separated by a literal ``T'', so noon
13505 When displaying a date, the current date format is used. All
13508 @samp{< >} markers is omitted for pure dates, or included for
13516 the input. If this doesn't work, Calc checks if the input is a
13517 simple number; if so, the number is interpreted as a number of days
13519 flexible algorithm which is described in the next section.
13529 Here is a complete list of the formatting codes for dates:
13673 If ``SS'' or ``BS'' (optional seconds) is preceded by a colon, the
13674 colon is also omitted if the seconds part is zero.
13700 but it is described here in full detail for the curious.
13705 First, the time portion, if present, is located somewhere in the
13706 text and then removed. The remaining text is then interpreted as
13709 A time is of the form @samp{hh:mm:ss}, possibly with the seconds
13711 12-hour time. If the AM/PM is present, the minutes may also be
13721 If there is no AM/PM indicator, the time is interpreted in 24-hour
13724 When reading the date portion, Calc first checks to see if it is an
13736 are interpreted as years. If one of the other numbers is
13738 number in the input is therefore the month. Otherwise, Calc
13740 appear in the current date format. If the year is omitted, the
13741 current year is taken from the system clock.
13744 words, then the input is rejected.
13756 of a number for the month, there is no danger of ambiguity.
13811 The number right above that line is considered to the be at the top of
13813 operations (although still visible to the user). This is similar to the
13821 is on. Thus, this line and all those below it become hidden. To un-hide
13857 Right-justification is especially useful together with fixed-point
13863 horizontal ``origin'' of a display line. It is also possible to
13867 origin and line width is slightly different in each justification
13870 In Left-Justified mode, the line is indented by a number of spaces
13871 given by the origin (default zero). If the result is longer than the
13873 otherwise, then it is broken into lines which will fit; each broken
13874 line is indented to the origin.
13877 character is just before the origin, or just before the current
13878 window width if no origin was specified. If the line is too long
13879 for this, then it is broken; the current line width is used, if
13880 specified, or else the origin is used as a width if that is
13881 specified, or else the line is broken to fit in the window.
13883 In Centering mode, the origin is the column number of the center of
13884 each stack entry. If a line width is specified, lines will not be
13886 break the lines if necessary. If no origin is specified, half the
13887 line width or Calc window width is used.
13889 Note that, in each case, if line numbering is enabled the display
13890 is indented an additional four spaces to make room for the line
13891 number. The width of the line number is taken into account when
13894 case, the display is formatted as specified, and then uniformly
13919 stack entry is justified to the origin and the righthand label is
13940 trail buffer, nor does it affect numeric entry. Only algebraic entry is
14035 One slight ambiguity of Big notation is that
14047 @expr{-3:4} or @expr{-0.75}, so this ambiguity is not a problem in
14050 Non-decimal numbers are displayed with subscripts. Thus there is no
14052 though generally you will know which interpretation is correct.
14095 in C mode; a value raised to a power is written as a function call,
14100 rather than using the @samp{#} symbol. Array subscripting is
14102 mode is the same as @samp{a_i} in Normal mode. Assignments
14113 as @samp{asin(x)} as long as C mode is in effect.
14125 vectors, and so on, since there is no universally accepted standard way
14136 both in the same way; @samp{a(i)} is interpreted as a function call
14148 language modes. The underscore here is equivalent to the @samp{#} in
14205 document is formatted the curly braces will be invisible. Thus the
14206 printed result is
14218 are simply written out as-is, which will cause them to come out in
14233 During reading, text of the form @samp{\matrix@{ ...@: @}} is replaced
14240 The symbol @samp{&} is interpreted as a comma,
14269 While this wouldn't bother Calc, it is incorrect @LaTeX{}.
14274 sequence is treated as an accent. The @code{\vec} accent corresponds
14275 to the function name @code{Vec}, because @code{vec} is the name of
14421 alias for @code{\rightarrow}. However, if the @samp{=>} is the
14423 is used: @samp{\evalto @var{a} \to @var{b}}. The @code{\evalto}
14424 word is ignored by Calc's input routines, and is undefined in @TeX{}.
14436 Another definition you may wish to use is @samp{\let\to=\Rightarrow}
14441 reading is:
14457 Also, the ``discretionary multiplication sign'' @samp{\*} is read
14584 @dfn{Eqn} is another popular formatter for math formulas. It is
14589 The @dfn{eqn} language's main idiosyncrasy is that whitespace plays
14600 @samp{sin * x + 1}, because @code{sin} is not a special operator
14615 operators, respectively. Note that the caret symbol @samp{^} is
14616 treated the same as a space in @dfn{eqn} mode, as is the @samp{~}
14629 are treated the same as curly braces: @samp{sqrt "1+x"} is equivalent to
14630 @samp{sqrt @{1+x@}}; this is only an approximation to the true meaning
14631 of quotes in @dfn{eqn}, but it is good enough for most uses.
14636 functions. The @code{prime} accent is treated specially if it occurs on
14637 a variable or function name: @samp{f prime prime @w{( x prime )}} is
14665 @samp{sin(2 x)}, for example, is entered and displayed @samp{Sin(2 x)}
14666 in Yacas mode, and @samp{arcsin(x^2)} is @samp{ArcSin(x^2)} in Yacas
14701 variable names in Maxima mode. The underscore again is equivalent to
14702 the @samp{#} in Normal mode, and the percent sign is equivalent to
14745 formula @samp{sin(2 x)} is entered and displayed @w{@samp{Sin[2 x]}} in
14767 Maple's language is much like C@. Underscores are allowed in symbol
14779 The Maple interval notation @samp{2 .. 3} is like Giac's interval
14780 notation, and is handled the same by Calc.
14803 @xref{Strings}. For example, @samp{string("ABC")} is displayed as
14813 language mode). The one exception is Unformatted mode (@kbd{d U}),
14849 the second term of the sum is four lines tall and has line three as
14850 its baseline. Thus when the term is combined with 17, line three
14851 is placed on the same level as the baseline of 17.
14857 Another important composition concept is @dfn{precedence}. This is
14892 The general rule is that if an operator with precedence @expr{n}
14894 the argument is enclosed in parentheses if @expr{n < m}. Top-level
14900 argument is actually formatted with one-higher precedence than shown
14920 A final composition issue is @dfn{line breaking}. Calc uses two
14922 A non-flat composition is anything that appears on multiple lines
14932 general strategy is to fill each line as much as possible, then to
14948 But Calc prefers to break at the comma since the comma is part
14955 also generates breakable items: A break point is added after every
14960 hierarchy, so a @code{choriz} that is a component of a larger
14989 in Big language mode. This is actually one case of the general
14993 each of the components of @var{vec}. The default precedence is
14996 @var{Sep} is a string (i.e., a vector of character codes as might
14998 of the composition. Also, if @var{sep} is given, the line breaker
15000 If @var{sep} is omitted, the composition will not be breakable
15003 For example, @samp{2 choriz([a, b c, d = e], " + ", 180)} is
15009 The baseline of a horizontal composition is the same as the
15021 component of the vector is centered in a column. The baseline of
15022 the result is by default the top line of the resulting composition.
15042 will be the same as the baseline of whatever component is enclosed
15082 be written with no arguments: @samp{ctbase()} is a zero-height object
15083 which means the baseline is the top line of the following item, and
15084 @samp{cbbase()} means the baseline is the bottom line of the preceding
15095 vector of exactly one character code. It is repeated to match the
15097 with a thick line is @samp{cvert([a + 1, cbase(crule("=")), b^2])}:
15143 language mode. This is essentially a horizontal composition of
15144 @samp{a} and @samp{b}, where @samp{b} is shifted up so that its
15145 bottom line is one above the baseline.
15152 This shifts @samp{b} down so that its top line is one below the
15153 bottom line of @samp{a} (note that this is not quite analogous to
15162 as obtained by @samp{d O}, if the current language mode is normal
15164 @samp{a^(b/c)} is formatted by Big mode like @samp{csup(a, cflat(b/c))}
15172 @samp{cspace(4)} is effectively the same as @samp{string(" ")}.
15173 A second string (i.e., vector of characters) argument is repeated
15175 looks like @samp{abababab}. If the second argument is not a string,
15176 it is formatted in the normal way and then several copies of that
15187 If the number argument is zero, this is a zero-width object.
15195 baseline is the center line of the resulting stack. A numerical
15240 composition. For example, @samp{cwidth(a + b)} is 5, and
15241 @samp{cwidth(a / b)} is 5 in Normal mode, 1 in Big mode, and 11 in
15250 This is the total number of lines in the argument's printed form.
15261 of the height that is above (and including) the baseline, or below
15267 is @samp{cvspace(0)} or equivalents.
15296 for the current language mode (and number of arguments); if there is
15306 @samp{choose(n, m)} in the Big language mode is
15350 numbers of the first kind, @samp{stir1(n, m)}. This is just like
15376 evaluated at display time. For example, if the formula is
15387 It is not a good idea to use @code{eval} except as a last resort.
15393 the factorial @samp{fact(100)} which is unevaluated because you
15434 @dfn{Parsing} is the process of converting a raw string of characters,
15436 Calc's parser works in two stages. First, the input is broken down
15438 like @samp{+}, @samp{:=}, and @samp{+/-}. Space between tokens is
15445 A @dfn{syntax table} is a list of user-defined @dfn{syntax rules},
15453 resemble algebraic rewrite rules, but the notation for patterns is
15456 A syntax pattern is a list of tokens, separated by spaces.
15478 While it is possible to make a token with a mixture of letters
15479 and punctuation symbols, this is not recommended. It is better to
15499 It is important to write the first two rules in the order shown,
15503 is itself a valid expression. Thus the @w{@samp{foo ( # )}} rule would
15507 ambiguities is not to use the same symbol in more than one way at
15512 Calc is quite flexible about what sorts of patterns are allowed.
15513 The only rule is that every pattern must begin with a literal
15516 patterns). After that, any mixture is allowed, although putting
15555 again it is generally better to use two tokens than one token with
15568 it is not valid to use @samp{"#"} in a syntax rule. However, longer
15593 place of @samp{#}, where @var{p} is an integer precedence level.
15649 arguments, so the net result is the formula @samp{myfunc(1,2,3)}.
15689 empty vector is produced.
15691 Another variant is @samp{@{ ... @}?$}, which means the body is
15737 It is possible to attach a @dfn{condition} to a syntax rule. For
15749 rule to succeed. A condition is ``true'' if it evaluates to a
15753 The exact sequence of events is as follows: When Calc tries a
15758 Each result is true if it is a nonzero number, or an expression
15761 @samp{ifoo(#1)}) has its @samp{#}s substituted, and that is the
15762 result of the parse. If the result of any condition is false, Calc
15768 condition is always true, but as a side effect it defines a
15777 The @code{dnumint} function tests if a value is numerically an
15783 variable, not the arbitrary pattern that is allowed in rewrite
15786 The @code{matches} function is also treated specially in syntax
15798 This is another way to implement the Maple mode @code{sum} notation.
15822 The modes vector is also available in the special variable
15823 @code{Modes}. In other words, @kbd{m g} is like @kbd{s r Modes @key{RET}}.
15828 In general, each number in this vector is suitable as a numeric
15837 Current precision. Default is 12; associated command is @kbd{p}.
15840 Binary word size. Default is 32; associated command is @kbd{b w}.
15844 This is zero if @kbd{m g} is executed with an empty stack.
15847 Number radix. Default is 10; command is @kbd{d r}.
15850 Floating-point format. This is the number of digits, plus the
15856 identical) effects if the current precision is 12, but they both
15862 Angular mode. Default is 1 (degrees). Other values are 2 (radians)
15866 Symbolic mode. Value is 0 or 1; default is 0. Command is @kbd{m s}.
15869 Fraction mode. Value is 0 or 1; default is 0. Command is @kbd{m f}.
15872 Polar mode. Value is 0 (rectangular) or 1 (polar); default is 0.
15873 Command is @kbd{m p}.
15876 Matrix/Scalar mode. Default value is @mathit{-1}. Value is 0 for Scalar
15881 Matrix mode. Command is @kbd{m v}.
15884 Simplification mode. Default is 1. Value is @mathit{-1} for off (@kbd{m O}),
15889 Infinite mode. Default is @mathit{-1} (off). Value is 1 if the mode is on,
15890 or 0 if the mode is on with positive zeros. Command is @kbd{m i}.
15914 This section is a summary of all symbols that can appear on the
15918 The basic mode line format is:
15924 The @samp{%*} indicates that the buffer is ``read-only''; it shows that
15929 is enabled. The words after this describe the various Calc modes
15932 The first mode is always the current precision, an integer.
15933 The second mode is always the angular mode, either @code{Deg},
15936 Here is a complete list of the remaining symbols that can appear
15995 Current radix is 2 (@kbd{d 2}; @pxref{Radix Modes}).
15998 Current radix is 8 (@kbd{d 8}).
16001 Current radix is 16 (@kbd{d 6}).
16004 Current radix is @var{n} (@kbd{d r}).
16104 GNUPLOT process is alive in background (@pxref{Graphics}).
16122 Stack is truncated (@kbd{d t}; @pxref{Truncating the Stack}).
16136 stack. If the operation cannot be performed, the result pushed is a
16138 is invalid) or @samp{sqrt(x)} (because the argument @samp{x} is a formula).
16169 be any of the standard Calc data types. The resulting sum is pushed back
16173 the result is a vector or matrix sum. If one argument is a vector and the
16174 other a scalar (i.e., a non-vector), the scalar is added to each of the
16175 elements of the vector to form a new vector. If the scalar is not a
16176 number, the operation is left in symbolic form: Suppose you added @samp{x}
16183 If either argument of @kbd{+} is a complex number, the result will in general
16184 be complex. If one argument is in rectangular form and the other polar,
16186 mode is enabled, the sum may be left as a formula if the necessary
16191 is an HMS form and the other is a number, that number is converted from
16195 If one argument of @kbd{+} is a date form, the other can be either a
16199 Adding two date forms is meaningless, but Calc interprets it as the
16204 If both arguments of @kbd{+} are error forms, the result is an error form
16205 with an appropriately computed standard deviation. If one argument is an
16206 error form and the other is a number, the number is taken to have zero error.
16214 or if one argument is a modulo form and the other a plain number, the
16215 result is a modulo form which represents the sum, modulo @expr{M}, of
16218 If both arguments of @kbd{+} are intervals, the result is an interval
16220 one argument is a plain number, it is treated as the interval
16223 If one argument of @kbd{+} is an infinity and the other is not, the
16224 result is that same infinity. If both arguments are infinite and in
16225 the same direction, the result is the same infinity, but if they are
16226 infinite in different directions the result is @code{nan}.
16235 number on the stack is subtracted from the one behind it, so that the
16246 argument is a vector and the other a scalar, the scalar is multiplied by
16249 vectors: If both arguments are matrices, a matrix multiplication is
16250 done. If one argument is a matrix and the other a plain vector, the
16251 vector is interpreted as a row vector or column vector, whichever is
16253 is a single scalar number which is the dot product of the two vectors.
16255 If one argument of @kbd{*} is an HMS form and the other a number, the
16256 HMS form is multiplied by that amount. It is an error to multiply two
16261 independent; thus, @samp{[-2 ..@: 3] * [-2 ..@: 3]} is @samp{[-6 ..@: 9]},
16262 whereas @w{@samp{[-2 ..@: 3] ^ 2}} is @samp{[0 ..@: 9]}.
16273 is good style to use parentheses to distinguish between possible
16278 multiplication. (This is not standard across all computer languages, and
16294 computation performed is @expr{B} times the inverse of @expr{A}. This
16295 also occurs if @expr{B} is itself a vector or matrix, in which case the
16296 effect is to solve the set of linear equations represented by @expr{B}.
16297 If @expr{B} is a matrix with the same number of rows as @expr{A}, or a
16298 plain vector (which is interpreted here as a column vector), then the
16299 equation @expr{A X = B} is solved for the vector or matrix @expr{X}.
16300 Otherwise, if @expr{B} is a non-square matrix with the same number of
16301 @emph{columns} as @expr{A}, the equation @expr{X A = B} is solved. If
16322 the power is an integer, an exact result is computed using repeated
16325 powers. If either argument is an error (or interval or modulo) form,
16326 the result is also an error (or interval or modulo) form.
16332 (This is entirely equivalent to @kbd{125 @key{RET} 1:3 ^}.)
16342 to produce an integer result. It is equivalent to dividing with
16344 more convenient and efficient. Also, since it is an all-integer
16355 operation. Mathematically, @samp{a%b = a - (a\b)*b}, and is defined
16359 If @expr{a} is a modulo form, its modulo is changed to @expr{b}, which
16367 result. This is a convenient shorthand for enabling Fraction mode (with
16369 the @kbd{:} key is interpreted as a fraction separator, so to divide 8 by 6
16384 value of a number. The result of @code{abs} is always a nonnegative
16388 elements. The absolute value of an error form is defined by replacing
16390 The absolute value of a modulo form is undefined. The absolute value of
16391 an interval is defined in the obvious way.
16403 argument is positive, @mathit{-1} if its argument is negative, or 0 if its
16404 argument is zero. In algebraic form, you can also write @samp{sign(a,x)}
16421 complex number whose form is determined by the current Polar mode.
16427 root of the sum of the squares of two numbers. That is, @samp{hypot(a,b)}
16428 is the length of the hypotenuse of a right triangle with sides @expr{a}
16436 integer square root of an integer. This is the true square root of the
16440 is a floating-point number or other non-integer value, this is exactly
16465 @expr{e}. The original number is equal to
16468 where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that
16469 @expr{m=e=0} if the original number is zero. For integers
16473 mantissa and exponent, with the constraint that the mantissa is not
16493 a number by one unit. For integers, the effect is obvious. For
16494 floating-point numbers, the change is by one unit in the last place.
16496 is 6 digits yields @samp{12.3457}. If the current precision had been
16501 where @expr{p} is the current
16506 almost but not quite always cancel out. Suppose the precision is
16507 6 digits and the number @samp{9.99999} is on the stack. Incrementing
16509 One digit has been dropped. This is an unavoidable consequence of the
16521 commands have the property that if the argument is an integer, the result
16522 is the same integer. An integer-valued floating-point argument is converted
16563 rounds to the nearest integer. When the fractional part is .5 exactly,
16605 algebraic notation. The @code{roundu} function is like @code{round}
16607 part is .5. This distinction matters only for negative arguments.
16611 The advantage of round-to-even is that the net error due to rounding
16613 subtle point here is that the number being fed to @code{rounde} will
16624 produce 120 (i.e., the cutoff is one digit to the @emph{left} of
16625 the decimal point). A second argument of zero is equivalent to
16647 complex conjugate is @expr{a-bi}. If the argument is a real number,
16648 this command leaves it the same. If the argument is a vector or matrix,
16656 notation, this is simply the second component of the pair
16659 The result is expressed according to the current angular mode and will
16666 command is not normally bound to a key in Calc, but it is available
16718 @expr{23} is converted to @expr{23.0}, @expr{3:2} is converted to
16719 @expr{1.5}, and @expr{2.3} is left the same. If the value is a composite
16720 object such as a complex number or vector, each of the components is
16721 converted to floating-point. If the value is a formula, all numbers
16730 it does not notice that the thing being floated is a power.
16733 The normal @kbd{c f} command is ``pervasive'' in the sense that it
16736 changes to @samp{a + 1.0} as soon as it is evaluated.
16742 argument. Thus, @samp{float(1)} is 1.0, but @samp{float(a + 1)}
16743 is left unevaluated because its argument is not a number.
16746 value, once all the variables have been assigned, is a float; you
16755 produces a fraction whose decimal representation is the same as the
16758 if the prefix argument is zero, by using the number on top of the stack
16759 as the tolerance. If the tolerance is a positive integer, the fraction
16760 is correct to within that many significant figures. If the tolerance is
16762 precision to use. If the tolerance is a floating-point number, the
16763 fraction is correct to within that absolute amount.
16767 The @code{pfrac} function is pervasive, like @code{pfloat}.
16768 There is also a non-pervasive version, @kbd{H c F} [@code{frac}],
16769 which is analogous to @kbd{H c f} discussed above.
16792 (The three-argument version is independent of the current angular mode.)
16805 to polar form, whichever is appropriate. Real numbers are left the same.
16806 This command is equivalent to the @code{rect} or @code{polar}
16808 conversion. (It uses @code{polar}, except that if the argument is
16820 angular mode is different from the one under which the number was
16825 If the simplification mode is set below basic simplification, it is raised
16827 simplifications even if their automatic application is disabled.
16845 numbers to zero. If the exponent is less than or equal to the negative
16846 of the specified precision, the number is changed to 0.0. For example,
16847 if the current precision is 12, then @kbd{c 2} changes the vector
16857 a prefix argument, is that integer-valued floats are converted to
16859 produces @samp{[1, 1.5, 2, 2.5, 3]}. This is not done for huge
16860 numbers (@samp{1e100} is technically an integer-valued float, but
16879 The simplest date arithmetic is done using the regular @kbd{+} and @kbd{-}
16906 result will be an integer if @var{date} is a pure date form, or a
16907 fraction or float if @var{date} is a date/time form. Or, if its
16908 argument is a number, it converts this number into a date form.
16916 day, which must all be integers. @var{Year} is a year number,
16920 @var{day} is too large, the equivalent day in the following
16942 a date form into a Julian day count, which is the number of days
16943 since noon (GMT) on Jan 1, 4713 BC@. A pure date is converted to an
16945 is converted to an exact floating-point Julian count, adjusted to
16962 converts a date form into a Unix time value, which is the number of
16964 will be an integer if the current precision is 12 or less; for higher
16967 is interpreted in the GMT time zone and the date form is interpreted
16981 zone is used for that prompt. You can also answer the first
16993 current date and time on the stack as a date form. The time is
17008 argument, which is interpreted as a standard Calc day number.
17023 that 24-hour time is always used. This returns zero for a pure
17033 from a date form. If the current precision is 12 or less,
17034 the result is an integer in the range 0 to 59. For higher
17057 specified by the input date. The result is always a pure date
17061 is greater than the actual number of days in the month, or if
17062 @var{n} is zero, the last day of the month is used.)
17072 @var{n}th day of the year (366 is treated as 365 in non-leap
17091 of @code{newweek} shows that if the input date is itself a Wednesday,
17093 exercise for the reader is to modify this formula to yield the same day
17094 if the input is already a Wednesday. Another interesting exercise is
17108 7 to 31; if the day number is greater than the actual number of days
17109 in the month, the true number of days is used instead. Thus
17136 is equivalent to @w{@samp{incmonth(d, 12*n)}}, but these do not have
17139 argument is omitted, 1 year is assumed. There is no keyboard
17142 There is no @code{newday} function at all because @kbd{F} [@code{floor}]
17153 Often time is measured in ``business days'' or ``working days,''
17170 number (positive or negative). If the number is not an integer,
17171 then a certain amount of time is added as well as a number of
17173 evening will produce a time in Monday morning. It is also
17177 case the result is the number of business days between the two
17182 By default, Calc considers any day that is not a Saturday or
17185 (There is an @w{@kbd{s H}} convenience command for editing this
17200 Nested vectors of date forms. Each date form in the vector is
17209 Thanksgiving (which is held on the fourth Thursday of November).
17211 takes on month numbers from 1 to 12: @samp{date(y, m, 15)} is
17215 A weekday name, such as @code{sat} or @code{sun}. This is really
17216 a variable whose name is a three-letter, lower-case day name.
17220 years over which this holiday list is to be considered valid. Any
17225 where the holidays you entered are complete. If there is no
17227 @samp{[1 .. 2737]} is used. (This is the absolute range of years
17233 range is @samp{[9@@ 0' 0" .. 17@@ 0' 0"]} (i.e., 9am to 5pm), then
17234 the business day is only eight hours long, so that @kbd{1.5 t +}
17240 be treated as 4:59:59pm. If there is no HMS interval in @code{Holidays},
17241 the full 24-hour day @samp{[0@ 0' 0" .. 24@ 0' 0"]} is assumed.
17242 (Regardless of the type of bounds you specify, the interval is
17247 If the @code{Holidays} vector is empty, then @kbd{t +} and
17252 list of holidays for internal use. This is done mainly to make
17254 @samp{<Jan 1, 1989>} is both New Year's Day and a Sunday, but
17268 weekend or holiday, the date form is treated as if it were the most
17271 subtract a number of days from a weekend or holiday, the date is
17280 might come out a bit differently, since @kbd{t +} is incapable of
17287 There is a @code{holiday} function, not on any keys, that takes
17289 holiday, as defined in @code{Holidays}, or 0 if the date is a
17309 to exactly 30 days even though there is a daylight-saving
17310 transition in between. This is also true for Julian pure dates:
17332 is a number, the result is simply that value multiplied by 3600.
17334 Daylight Saving time is in effect, one hour should be subtracted from
17340 and @kbd{t U}, the normal argument is then taken from the second-to-top
17343 it can be a variable which is a time zone name in upper- or lower-case.
17348 note that for each time zone there is one name for standard time,
17350 in which the daylight saving adjustment is computed from context.
17368 is a list of lists describing the different time zone names; its
17369 structure is best explained by an example. The three entries for
17387 @code{TimeZone} (which is by default @code{nil}) to an appropriate
17388 time zone name. (The easiest way to do this is to edit the
17392 If the time zone given by @code{TimeZone} is a generalized time zone,
17395 is explicit, e.g., @code{EST} or @code{EDT}, then that adjustment is
17396 used exactly and Calc's daylight saving algorithm is not consulted.
17398 is equivalent to no argument; i.e., it uses the information obtained
17403 information from the calendar if @code{TimeZone} is @code{nil},
17409 the @code{TimeZone} variable is set), it will by default consider
17423 name of a function that is used to compute the daylight saving
17424 adjustment for a given date. The default is
17428 The daylight saving hook function is called with four arguments:
17437 The Lisp function @code{math-prev-weekday-in-month} is useful for
17438 daylight saving computations. This is an internal version of
17448 algorithm for 1987 and later. Here is a listing of the default
17472 The @code{bump} parameter is equal to zero when Calc is converting
17474 It is @mathit{-1} when Calc is converting in the other direction. The
17478 There is a ``missing'' hour between 2 a.m.@: and 3 a.m.@: at the
17487 If @code{math-daylight-savings-hook} is @code{nil}, then the
17488 daylight saving adjustment is always taken to be zero.
17492 given date. The @var{date} is ignored unless @var{zone} is a
17493 generalized time zone. If @var{date} is a date form, the
17494 daylight saving computation is applied to it as it appears.
17495 If @var{date} is a numeric date value, it is adjusted for the
17498 that the daylight-saving computation is always done in
17500 is typically represented in.
17507 daylight saving adjustment that is appropriate for @var{date} in
17508 time zone @var{zone}. If @var{zone} is explicitly in or not in
17510 @var{date} is ignored. If @var{zone} is a generalized time zone,
17511 the algorithms described above are used. If @var{zone} is omitted,
17512 the computation is done for the current time zone.
17520 a lower-case letter is used for operations on binary numbers.)
17527 It is wise to compute these functions to a higher precision than
17528 you really need, just to make sure your answer is correct to the
17557 @samp{1+8%} is interpreted as @samp{1+(8%)}, not as @samp{(1+8)%}.
17558 (The @samp{%} operator is just a postfix notation for the
17559 @code{percent} function, just like @samp{20!} is the notation for
17566 The net effect is that you get to look at @samp{5.4%} on the stack,
17567 but Calc commands see it as @samp{0.054}, which is what they expect.
17571 but the number @samp{5.4} is probably @emph{not} suitable---it
17575 For example, @kbd{68 @key{RET} 25 M-% *} computes 17, which is 25% of
17582 For example, if 0.08 is on the stack, @kbd{c %} converts it to
17583 @samp{8%}. The quantity is the same, it's just represented
17585 this number to @samp{0.08%}.) The @kbd{=} key is a convenient way
17588 To compute what percentage one quantity is of another quantity,
17598 since 50 is 25% larger than 40. A negative result represents a
17599 decrease: @kbd{50 @key{RET} 40 b %} produces @samp{-20%}, since 40 is
17603 of @kbd{40 @key{RET} 50 b %} is to compute @expr{(50-40)/40}, converting
17633 @kbd{5.4 M-% 5 @key{RET} 1000 I b F}. Note that the rate is expressed
17644 fourth argument, which is used as an initial lump sum in the sense
17657 these five values is, sure enough, $5870.73, just as was computed
17661 are now at the ends of the periods. The end of one year is the same
17662 as the beginning of the next, so what this really means is that we've
17682 You want to know whether it is better to make the investment, or
17686 say, $6000, then the investment is worthwhile. But if you had to
17689 Here is the interpretation of the result of @code{pv}: You are
17691 considering, which is @code{fv(9%, 4, 2000) = 9146.26}, with
17692 the return from leaving the money in the bank, which is
17693 @code{fvl(9%, 4, @var{x})} where @var{x} is the amount of money
17696 @code{fvl(9%, 4, 6479.44)} is also equal to 9146.26. This is
17713 four years, @code{pvl(9%, 4, 8000) = 5667.40}. This is much
17719 and @code{pvb}; this is handled in exactly the same way as the
17727 The first argument is the interest rate. The second argument is
17734 Obviously this function is more interesting when the payments are
17776 The @kbd{H b M} key just invokes the @code{fvl} function, which is
17777 the inverse of @code{pvl}. There is no explicit @code{pmtl} function.
17786 @var{payment}) = @var{amount}}. If @var{payment} is too small
17788 the @code{nper} function is left in symbolic form.
17809 the rate of return on an investment. This is also an inverse of @code{pv}:
17812 @var{amount}}. The result is expressed as a formula like @samp{6.3%}.
17829 The @kbd{b I} (@code{calc-fin-irr}) [@code{irr}] command is the
17831 Its argument is a vector of payments. Thus @code{irr(@var{payments})}
17833 this rate is known as the @dfn{internal rate of return}.
17844 The functions in this section calculate @dfn{depreciation}, which is
17869 is higher during the early years of the asset's life. Since the
17870 depreciation is different each year, @kbd{b Y} takes a fourth @var{period}
17871 parameter which specifies which year is requested, from 1 to @var{life}.
17872 If @var{period} is outside this range, the @code{syd} function will
17884 return value will as usual be zero if @var{period} is out of range.
17908 the total depreciation in any method is (by definition) the
17919 @var{n} argument is known. However, @var{payment} or @var{amount} can
17928 linearly is @samp{pmt * ((1 + rate)^n) - 1) / rate}.
18035 Note that if the first argument to the @code{log} in @code{nper} is
18042 for an initial guess. The @code{rateb} function is the same except
18044 directly; its formula is shown in the above list.
18055 The same is true of @code{fvb}, @code{pv}, and @code{pvb}.
18057 The @kbd{ddb} function is computed iteratively; the ``book'' value
18061 and the depreciation is zero for all subsequent periods. The @code{ddb}
18086 If the word size is negative, binary operations produce twos-complement
18096 If the word size is zero, binary operations work on the entire number
18107 generally is not ``binary.'' (However, @pxref{Simplification Modes},
18114 The default word size is 32 bits. All operations except the shifts and
18124 @samp{and(a,b)} is finally evaluated, the word size current at that time
18125 will be used, but when @samp{and(a,b,-8)} is evaluated, a word size of
18130 If either or both arguments are modulo forms for which @expr{M} is a
18131 power of two, that power of two is taken as the word size unless a
18132 numeric prefix argument overrides it. The current word size is never
18141 bit of the result is 1 if and only if both input bits are 1:
18148 inclusive OR of two numbers. A bit is 1 if either of the input bits, or
18155 exclusive OR of two numbers. A bit is 1 if exactly one of the input bits
18156 is 1: @samp{xor(2#1100, 2#1010) = 2#0110}.
18162 difference of two numbers; this is defined by @samp{diff(a,b) = and(a,not(b))},
18169 NOT of a number. A bit is 1 if the input bit is 0 and vice-versa.
18178 is short for @samp{lsh(a,1)}, which in turn is short for @samp{lsh(a,n,w)}.
18212 number left. It is analogous to @code{lsh}, except that if the shift
18213 is rightward (the prefix argument is negative), an arithmetic shift
18214 is performed as described below.
18221 to the current word size) is duplicated rather than shifting in zeros.
18222 This corresponds to dividing by a power of two where the input is interpreted
18224 and @samp{rash} operations is totally independent from whether the word
18225 size is positive or negative.) With a negative prefix argument, this
18228 When the word size is zero, logical and arithmetic shift operations
18230 there is an infinite supply of ones to shift in.
18237 word size) is dropped off the left and shifted in on the right. With a
18238 numeric prefix argument, the number is rotated that many bits to the left
18241 Rotation is not possible with a zero word size.
18250 is to reverse the bits in, say, a 32-bit integer. Type @kbd{b u} to
18280 One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes
18290 (about 1.618). (At present, Euler's constant is not available
18304 The @kbd{Q} (@code{calc-sqrt}) [@code{sqrt}] function is described elsewhere;
18336 this is redundant with the @kbd{E} command.
18366 complex number is computed by taking the natural logarithm and dividing
18382 mode setting. With the Inverse flag [@code{alog}], this command is
18383 similar to @kbd{^} except that the order of the arguments is reversed.
18390 themselves be positive integers. This is the true logarithm, rounded
18391 down to an integer. Thus @kbd{ilog(x,10)} is 3 for all @expr{x} in the
18393 integer arithmetic is used; otherwise, this is equivalent to
18403 answer when the result is close to zero, i.e., when
18406 is close to one.
18414 producing a more accurate answer when @expr{x} is close to zero.
18424 of an angle or complex number. If the input is an HMS form, it is interpreted
18425 as degrees-minutes-seconds; otherwise, the input is interpreted according
18426 to the current angular mode. It is best to use Radians mode when operating
18430 @code{rad}, and @code{grad}. While @samp{sin(45 deg)} is not evaluated
18435 Also, the symbolic variable @code{pi} is not ordinarily recognized in
18438 formulas when the current angular mode is Radians @emph{and} Symbolic
18439 mode is enabled; this example would be replaced by @samp{sqrt(2) / 2}.
18441 have stored a different value in the variable @samp{pi}; this is one
18442 reason why changing built-in variables is a bad idea. Arguments of
18454 With the Inverse flag, @code{calc-sin} computes an arcsine. This is also
18456 function. The returned argument is converted to degrees, radians, or HMS
18546 result is in the full range from @mathit{-180} (exclusive) to @mathit{+180}
18604 accuracy is not guaranteed in all domains. It is advisable to set the
18613 gamma function. For positive integer arguments, this is related to the
18649 the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by
18658 some authors, is computed by the @kbd{I f G} [@code{gammaQ}] command.
18682 Euler beta function, which is defined in terms of the gamma function as
18695 the incomplete beta function @expr{I(x,a,b)}. It is defined by
18711 is the corresponding integral from @samp{x} to infinity; the sum
18725 @expr{n} is often an integer, but is not required to be one.
18739 returned in cases where the general result is a family of possible values.
18751 @code{arctan} cut is always in the right half of the complex plane,
18752 and its @code{arctanh} cut is always in the top half of the plane.
18761 For @samp{sqrt(a+bi)}: When @expr{a<0} and @expr{b} is small but positive
18762 or zero, the result is close to the @expr{+i} axis. For @expr{b} small and
18763 negative, the result is close to the @expr{-i} axis. The result always lies
18766 For @samp{ln(a+bi)}: The real part is defined as @samp{ln(abs(a+bi))}.
18767 The imaginary part is defined as @samp{arg(a+bi) = arctan2(b,a)}.
18786 For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}.
18787 One interesting consequence of this is that @samp{(-8)^1:3} does
18790 of @mathit{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps
18793 For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}.
18796 For @samp{arccos(z)}: This is defined by @samp{-i*ln(z + i*sqrt(1-z^2))},
18800 For @samp{arctan(z)}: This is defined by
18804 For @samp{arcsinh(z)}: This is defined by @samp{ln(z + sqrt(1+z^2))}.
18808 For @samp{arccosh(z)}: This is defined by
18809 @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the
18812 For @samp{arctanh(z)}: This is defined by @samp{(ln(1+z) - ln(1-z)) / 2}.
18816 @code{arctan} assume the current angular mode is Radians. The
18891 from the stack instead. Once again, if this is a positive integer @expr{M}
18892 the result is a random integer less than @expr{M}. If @expr{M} is negative,
18893 the result is a random integer in the range
18897 If the value on the stack is a floating-point number @expr{M}, the result
18898 is a random floating-point number @expr{N} in the range
18906 If @expr{M} is zero, the result is a Gaussian-distributed random real
18911 If @expr{M} is an error form
18922 If @expr{M} is an interval form, the lower and upper bounds specify the
18924 the result is a random integer in the specified range. If either bound
18925 is floating-point, the result is a random real number in the specified
18926 range. If the interval is open at either end, the result will be sure
18931 additionally return 2.00000, but the probability of this happening is
18934 If @expr{M} is a vector, the result is one element taken at random from
18938 The sequence of numbers produced by @kbd{k r} is completely random by
18939 default, i.e., the sequence is seeded each time you start Calc using
18952 number between zero and one. It is equivalent to @samp{random(1.0)}.
18969 prefix argument, the length of the list is taken from the top of the
18972 If @expr{M} is a floating-point number, zero, or an error form (so
18974 there is little practical difference between using @kbd{k h} and using
18976 of just a few integers, or the elements of a vector, then there is
18979 elements are always distinct. (Actually, there is a slight exception:
18980 If @expr{M} is a vector, no given vector element will be drawn more
18984 One use of @kbd{k h} is to rearrange a list at random. This happens
18985 if the prefix argument is equal to the number of values in the list:
18988 @var{n} is negative it is replaced by the size of the set represented
18989 by @expr{M}. Naturally, this is allowed only when @expr{M} specifies
19016 When Calc's random number generator is first invoked, it ``seeds''
19035 value into a large table which is maintained internally; the variable
19036 @code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]}
19039 continue to use the same internal table as last time. There is no
19043 same seed is to type @kbd{s r RandSeed} to get the seed vector,
19062 (which returns a value from 0 to 1023); if the random value is 1000
19086 additional digits, then reduces modulo @var{m}. Unless @var{m} is a
19089 if @var{m} is 42, Calc will reduce a random integer less than 100000
19090 modulo 42 to get a result less than 42. It is easy to show that the
19092 modulo operation as numbers 39 and below.) If @var{m} is a power of
19112 the GCD of two fractions is defined by taking the GCD of the
19113 numerators, and the LCM of the denominators. This definition is
19116 the operation is left in symbolic form.
19123 the LCM and GCD of two numbers is equal to the absolute value of the
19143 factorial of the number at the top of the stack. If the number is an
19144 integer, the result is an exact integer. If the number is an
19145 integer-valued float, the result is a floating-point approximation. If
19146 the number is a non-integral real number, the generalized factorial is used,
19149 since fewer digits must be maintained. The same is true of many of
19161 this is the product of even integers from 2 to @expr{N}. For an odd
19162 integer, this is the product of odd integers from 3 to @expr{N}. If
19163 the argument is an integer-valued float, the result is a floating-point
19164 approximation. This function is undefined for negative even integers.
19165 The notation @expr{N!!} is also recognized for double factorials.
19171 binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number
19172 on the top of the stack and @expr{N} is second-to-top. If both arguments
19173 are integers, the result is an exact integer. Otherwise, the result is a
19174 floating-point approximation. The binomial coefficient is defined for all
19197 is a nonnegative integer @expr{n} that specifies which Bernoulli number
19198 is desired. The @kbd{H k b} command computes a Bernoulli polynomial,
19200 top of the stack. If @expr{x} is a variable or formula the result is
19201 a polynomial in @expr{x}; if @expr{x} is a number the result is a number.
19233 the top of the stack is prime. For integers less than eight million, the
19234 answer is always exact and reasonably fast. For larger integers, a
19235 probabilistic method is used (see Knuth vol.@: II, section 4.5.4, algorithm P).
19236 The number is first checked against small prime factors (up to 13). Then,
19238 discovers that the number is non-prime, or substantially increases the
19239 certainty that the number is prime. After a few steps, the chance that
19241 (Indeed, this is a worst-case estimate of the probability; in practice
19242 even a single iteration is quite reliable.) After the @kbd{k p} command,
19253 the specified number of iterations. There is also an algebraic function
19255 is (probably) prime and 0 if not.
19262 to 25 million, the answer is exact although it may take some time. The
19263 result is a vector of the prime factors in increasing order. For larger
19268 @mathit{1}, the result is a list of the same number.
19279 passes the test. This is quite fast for integers less than eight million,
19285 @kbd{k p} commands to increase your certainty that the number is indeed
19311 Möbius μ function. If the input number is a product of @expr{k}
19312 distinct factors, this is @expr{(-1)^k}. If the input number has any
19314 the result is zero.
19321 For continuous distributions, this is the integral of the probability
19332 lie in the range from 2.5 to 2.8 is @samp{utpn(2.5,2,1) - utpn(2.8,2,1)}
19333 (``the probability that it is greater than 2.5, but not greater than 2.8''),
19343 then @var{x} onto the stack; the result (@samp{utpb(x,n,p)}) is the
19346 trial is @var{p}. The @kbd{I k B} [@code{ltpb}] function is
19375 degrees of freedom. It is the probability that a model is
19376 correct if its chi-square statistic is @expr{x}.
19414 It is the probability that such a normal-distributed random variable
19429 mean @expr{x}. It is the probability that @expr{n} or more such
19447 degrees of freedom. It is the probability that a
19463 Since the distribution functions are monotonic, @kbd{a R} is guaranteed
19472 (For convenience, the shift-@kbd{V} prefix is equivalent to @kbd{v}.)
19475 has the wrong dimensions the operation is left in symbolic form.
19510 object to be built; this argument is referred to as the ``packing mode.''
19511 If the packing mode is a nonnegative integer, a vector of that
19512 length is created. For example, @kbd{C-u 5 v p} will pop the top
19527 @expr{(5, 7)}. The result is always a rectangular complex
19536 The first is the magnitude; the second is the phase expressed
19572 The first is the mantissa; the second, which must be an
19573 integer, is the exponent. The result is the mantissa
19577 This is treated the same as @mathit{-11} by the @kbd{v p} command.
19579 is desired.
19582 A real number is converted into a date form.
19593 length, the result is another vector made by packing corresponding
19594 elements of the input vectors. If one input is a vector and the
19595 other is a plain number, the number is packed along with each vector
19605 @kbd{1 @key{RET} 2 @key{RET} 4 n v p} is another way to
19608 If the packing mode taken from the stack is a vector, the result is a
19610 which must each be integers. For example, if the packing mode is
19627 There is an equivalent algebraic function,
19628 @samp{pack(@var{mode}, @var{items})} where @var{mode} is a
19630 is a vector of objects to be packed (re-packed, really) according
19632 yields @samp{[a +/- b, @w{c +/- d}, e +/- f]}. The function is
19633 left in symbolic form if the packing mode is invalid, or if the
19643 objects. Thus, it is the ``inverse'' of @kbd{v p}. If the value
19644 at the top of the stack is a formula, @kbd{v u} unpacks it by pushing
19648 to specify an explicit (un)packing mode. If the packing mode is
19649 negative and the input is actually a vector or matrix, the result
19655 Note that the prefix argument can have an effect even when the input is
19656 not a vector. For example, if the input is the number @mathit{-5}, then
19662 is not a composite object.
19665 an integer exponent, where the mantissa is not divisible by 10
19666 (except that 0.0 is represented by a mantissa and exponent of 0).
19669 is guaranteed to lie in the range [1 .. 10). In both cases,
19670 the mantissa is shifted left or right (and the exponent adjusted
19674 A mode of 1 is much like plain @kbd{v u} with no prefix argument,
19676 a suitable packing mode to re-pack the object is also pushed.
19700 The @code{unpackt} function is like @code{unpack} but instead
19705 The identity for re-building the original object is
19711 Subscript notation is a useful way to extract a particular part
19733 of row-vectors as far as @kbd{|} is concerned.)
19735 If either argument to @kbd{|} is a scalar (a non-vector), it is treated
19737 produces the vector @samp{[1, 2, 3]}. Likewise, if one argument is a
19738 matrix and the other is a plain vector, the vector is treated as a
19745 Whether or not they are matrices is not taken into account. If either
19746 argument is a scalar, the @code{append} function is left in symbolic form.
19752 two stack arguments in the opposite order. Thus @kbd{I |} is equivalent
19761 and columns in the matrix. If the value at the top of the stack is a
19764 the stack is a scalar, it is used for each element on the diagonal, and
19765 the prefix argument is required.
19779 matrix of the specified size. It is a convenient form of @kbd{v d}
19780 where the diagonal element is always one. If no prefix argument is given,
19784 except that @expr{a} is required to be a scalar (non-vector) quantity.
19785 If @expr{n} is omitted, @samp{idn(a)} represents @expr{a} times an
19787 such generic identity matrices, and if one is combined with a matrix
19788 whose size is known, it is converted automatically to an identity
19800 of consecutive integers from 1 to @var{n}, where @var{n} is the numeric
19802 prompted to enter a suitable number. If @var{n} is negative, the result
19803 is a vector of negative integers from @var{n} to @mathit{-1}.
19809 is in floating-point format, the resulting vector elements will also be
19818 is one for positive @var{n} or two for negative @var{n}.
19826 is the numeric prefix argument. In algebraic formulas, @samp{cvec(x,n,m)}
19849 and a vector @var{t} from the stack, and produces the vector whose head is
19850 @var{h} and whose tail is @var{t}. This is similar to @kbd{|}, except
19851 if @var{h} is itself a vector, @kbd{|} will concatenate the two vectors
19893 the top of the stack. The row or element is specified by the numeric
19894 prefix argument; the default is to prompt for the row or element number.
19895 The matrix or vector is replaced by the specified row or element in the
19901 from the second-to-top position. If the index is itself a vector of
19902 integers, the result is a vector of the corresponding elements of the
19906 With @kbd{C-u}, if the index is an interval form with integer components,
19907 it is interpreted as a range of indices and the corresponding subvector or
19908 submatrix is returned.
19916 Calc function @code{subscr}, which is synonymous with @code{mrow}.
19918 @expr{k} is one, two, or three, respectively. A double subscript
19922 formula @samp{a_b} out of two stack entries. (It is on the @kbd{a}
19931 In algebraic form this function is called @code{mrrow}.
19936 function is called @code{getdiag}.
19943 The @kbd{v c} (@code{calc-mcol}) [@code{mcol} or @code{mrcol}] command is
19946 index in @kbd{C-u v c} is an interval or vector and the argument is a
19947 matrix, the result is a submatrix with only the specified columns
19952 from that vector. In algebraic formulas, it is often more convenient to
19969 If either the start or the end index is zero or negative, it is
19973 is taken as zero, i.e., elements from the starting element to the
19983 produces @samp{[a, d, e]}. It is always true that @code{subvec} and
19998 length of a vector. The length of a non-vector is considered to be zero.
20008 its argument is a
20019 is on the top of the stack; the vector is in the second-to-top position.
20020 If a match is found, the result is the index of the matching element.
20021 Otherwise, the result is zero. The numeric prefix argument, if given,
20035 The vector or matrix on the top of the stack is @dfn{flattened} into a
20036 plain vector. If the number of columns is nonzero, this vector is
20069 one vector is less or greater than another if the first corresponding
20091 A permutation vector is just a vector of integers from 1 to @var{n}, where
20092 each integer occurs exactly once. One application of this is to sort a
20096 is that, if the input is itself a permutation vector, the result will
20097 be the inverse of the permutation. The inverse of an index table is
20099 vector element will rest when the vector is sorted. To get a rank
20105 will not be moved out of their original order. Generally there is no way
20111 by phone numbers. Because the sort is stable, any two rows with equal
20125 bins'' @var{n}, which is the numeric prefix argument given to the
20126 command. The result is a vector of @var{n} counts of how many times
20133 If no prefix is given, then you will be prompted for a vector which
20134 will be used to determine the bins. (If a positive integer is given at
20138 @expr{[a, b, c, ...]} is entered at the prompt, the bins will be
20150 The second-to-top vector is the list of numbers as before. The top
20151 vector is an equal-sized list of ``weights'' to attach to the elements
20152 of the data vector. For example, if the first data element is 4.2 and
20153 the first weight is 10, then 10 will be added to bin 4 of the result
20162 is a plain vector, it is treated as a row vector and transposed into
20181 is in the second-to-top position; the target vector is on the top of
20182 the stack. These vectors must have the same length. The result is
20193 expands a vector according to another mask vector. The result is a
20196 vector is normally the number of nonzero elements in the mask. If the
20197 target vector is longer, its last few elements are lost. If the target
20198 vector is shorter, the last few nonzero mask elements are left
20206 second elements of the stack. This filler is used where the mask is
20208 @samp{[a, z, c, z, 7]}. If the filler value is itself a vector,
20209 then successive values are taken from it, so that the effect is to
20214 Another variation on the masking idea is to combine @samp{[a, b, c, d, e]}
20227 the sense of multiplying by the inverse, is supported. (Division by a
20253 Frobenius norm of a vector or matrix argument. This is the square
20255 elements of the vector or matrix. If the vector is interpreted as
20256 a point in two- or three-dimensional space, this is the distance
20265 vector, this is the maximum of the absolute values of the elements. For
20266 a matrix, this is the maximum of the row-absolute-value-sums, i.e., of
20275 vector, this is the sum of the absolute values of the elements.
20276 For a matrix, this is the maximum of the column-absolute-value-sums.
20278 not provided. However, the 2-norm (or Frobenius norm) is provided for
20299 inverse of a square matrix. If the matrix is singular, the inverse
20300 operation is left in symbolic form. Matrix inverses are recorded so
20305 If the argument to @kbd{&} is a plain number @expr{x}, this
20306 command simply computes @expr{1/x}. This is okay, because the
20322 LU decomposition of a matrix. The result is a list of three matrices
20324 The first is a permutation matrix that arises from pivoting in the
20325 algorithm, the second is lower-triangular with ones on the diagonal,
20326 and the third is upper-triangular.
20333 trace of a square matrix. This is defined as the sum of the diagonal
20349 objects. A set is a collection of objects; any given object can appear
20361 If a set contains interval forms, then it is assumed to be a set of
20368 If the input to a set operation is a plain number or interval form
20369 @var{a}, it is treated like the one-element vector @samp{[@var{a}]}.
20370 The result is always a vector, except that if the set consists of a
20371 single interval, the interval itself is returned instead.
20374 a certain value is a member of a given set. To test if the set @expr{A}
20375 is a subset of the set @expr{B}, use @samp{vdiff(A, B) = []}.
20384 @kbd{[a, 5, 4, a, 4.0]} is sorted to @samp{[4, 4.0, 5, a, a]} and then
20395 the union of two sets. An object is in the union of two sets if and
20396 only if it is in either (or both) of the input sets. (You could
20405 the intersection of two sets. An object is in the intersection if
20406 and only if it is in both of the input sets. Thus if the input
20422 the difference between two sets. An object is in the difference
20423 @expr{A - B} if and only if it is in @expr{A} but not in @expr{B}.
20426 as a general @dfn{set complement} operator; if @expr{A} is the set of
20427 all possible values, then @expr{A - B} is the ``complement'' of @expr{B}.
20428 Obviously this is only practical if the set of all possible values in
20429 your problem is small enough to list in a Calc vector (or simple
20438 An object is in the symmetric difference of two sets if and only
20439 if it is in one, but @emph{not} both, of the sets. Objects that
20448 Thus @samp{vcompl(x)} is equivalent to @samp{vdiff([-inf .. inf], x)}.
20461 complement of the set @samp{[2, 6, 7, 8]} is messy, but if you wanted
20490 the number of integers in a set. The result is the length of the vector
20491 that would be produced by @kbd{V E}, although the computation is much
20496 cases is binary numbers. If you are dealing with sets of integers
20498 particular bit is 1 if the corresponding element is in the set.
20504 respectively. You can use whatever representation for sets is most
20516 returns @samp{[[0 .. 1], 6]}. If the input is negative, the set
20517 it represents is semi-infinite: @samp{vunpack(-4) = [2 .. inf)}.
20526 not include any negative numbers. The input is interpreted as a
20572 is popped, which (in order to be useful) is usually a vector.
20574 If an argument is a variable name, and the value stored in that
20575 variable is a vector, then the stored vector is used. This method
20576 has the advantage that if your data vector is large, you can avoid
20580 are not numbers or vectors, e.g., if an argument is a formula, or
20582 arguments are accepted; the result is a symbolic representation
20592 particular, an interval with integer limits is considered an integer
20593 distribution, so that @samp{[2 .. 6)} is the same as @samp{[2 .. 5]}.
20594 An interval with at least one floating-point limit is a continuous
20595 distribution: @samp{[2.0 .. 6.0)} is @emph{not} the same as
20604 If the argument is a single vector with no sub-vectors, this
20617 product of the data values. If the input is a single flat vector,
20630 If the argument is an interval, this finds the minimum or maximum
20632 described above.) If the argument is an error form, this returns
20644 this is the weighted mean of the @expr{x} values with weights
20651 If the inputs are not error forms, this is simply the sum of the
20658 If the input to @kbd{u M} is a mixture of
20659 plain numbers and error forms, the result is the mean of the
20663 weight is completely negligible.)
20666 intervals). The mean of an error form `@var{a} @tfn{+/-} @var{b}' is simply
20667 @expr{a}. The mean of an interval is the mean of the minimum
20676 the mean. If the inputs are error forms, the error is the square
20678 of the input errors. (I.e., the variance is the reciprocal of the
20684 numbers, the error is equal to the standard deviation of the values
20687 then assuming each value's error is equal to this standard
20699 first sorted into numerical order; the median is the middle
20700 value after sorting. (If the number of data values is even,
20701 the median is taken to be the average of the two middle values.)
20702 The median function is different from the other functions in
20705 (Otherwise it is not possible to sort the data values.) If
20710 (error form) and uniform (interval) distributions, the median is
20718 command computes the harmonic mean of the data values. This is
20731 is the @var{n}th root of the product of the values. This is also
20742 mean'' of two numbers taken from the stack. This is computed by
20754 As its name suggests, this is the square root of the mean of the
20767 as weights just as for @kbd{u M}. This is the @emph{sample} standard
20768 deviation, whose value is the square root of the sum of the squares of
20776 of a single error form is simply the error part. The standard deviation
20781 The standard deviation of an integer interval is the same as the
20790 It is defined by the same formula as above but dividing
20792 deviation is used when the input represents the entire set of
20794 is used when the input represents a sample of the set of all
20795 data values, so that the mean computed from the input is itself
20815 is the
20820 (This definition also applies when the argument is a distribution.)
20851 of vectors @var{x} and @var{y} is the sum of the products of the
20855 the variance of a vector is just the covariance of the vector
20859 is taken as the square root of the sum of the squares of the two
20874 command computes the population covariance, which is the same as the
20885 This is defined by the covariance of the vectors divided by the
20886 product of their standard deviations. (There is no difference
20903 The simplest of these operations is @kbd{V A} (@code{calc-apply})
20908 @samp{a + b}. Applying @code{+} to the vector @samp{[a, b, c]} is an
20911 While @kbd{V A} is useful in some cases, you will usually find that either
20912 @kbd{V R} or @kbd{V M}, described below, is closer to what you want.
20928 list of the available operators. Generally, an operator is any key or
20939 defined, the result is left in symbolic form, as in @samp{f(1, 2, 3)}.
20942 is currently undefined). It is also possible to type a digit key before
20951 It is also possible to apply any formula to a vector by treating that
20958 this function is applied to the arguments @samp{[3, 10]} the result will
20962 Another way to specify the arguments to the formula you enter is with
20964 has the same effect as the previous example. The argument list is
20966 may seem backwards, but it is analogous to the way normal algebraic
20969 If you press @kbd{$} at the operator prompt, the effect is similar to
20970 the apostrophe except that the relevant formula is taken from top-of-stack
20989 If there is only one argument, you can write @samp{#} in place of @samp{#1}.
20990 (Note that @samp{< >} notation is also used for date forms. Calc tells
20991 that @samp{<@var{stuff}>} is a nameless function by the presence of
21000 so that @kbd{V A ' #1+#2 @key{RET}} is the same as @kbd{V A ' <#1+#2> @key{RET}},
21001 which in turn is the same as @kbd{V A ' $$+$ @key{RET}}.
21008 The internal format for @samp{<x, y : x + y>} is @samp{lambda(x, y, x + y)}.
21010 functions.) The internal format for @samp{<#1 + #2>} is @samp{lambda(ArgA,
21011 ArgB, ArgA + ArgB)}. Note that there is no actual Calc function called
21012 @code{lambda}; the whole point is that the @code{lambda} expression is
21013 used in its symbolic form, not evaluated for an answer until it is applied
21018 will not simplify the @samp{2/3} until the nameless function is actually
21048 For example, @kbd{V A k g} with an argument of @samp{v} is equivalent to
21050 and is either a variable whose name is the same as the function name,
21061 @samp{call(gcd, x, y)} is the same as @samp{apply(gcd, [x, y])}, which
21062 in turn is the same as @samp{gcd(x, y)}. The first argument of @code{call},
21064 function, or a nameless function (@samp{call(<#1+2#2>, x, y)} is the same
21086 pairwise sums of the elements. If either argument is a non-vector, it
21087 is duplicated for each element of the other vector. For example,
21094 If any argument to @kbd{V M} is a matrix, the operator is normally mapped
21107 namely @expr{[3.74, 8.77]}. (Recall, the absolute value of a vector is
21120 transposes the input matrix, maps by rows, and then, if the result is a
21143 Sometimes it is useful to specify another mapping command as the operator
21148 otherwise; thus @kbd{V M V A +} is equivalent to @kbd{V M _ V A +}. (If
21151 @kbd{V M V A +} over the rows of the matrix; in turn, @kbd{V A +} is
21157 that are now considered obsolete; the old ``map across'' is now simply
21158 @kbd{V M V A}, and ``map down'' is now @kbd{V M : V A}. The algebraic
21165 @xref{Algebraic Manipulation}, for the @kbd{a M} command, which is like
21179 binary operator across all the elements of a vector. A binary operator is
21190 The @kbd{I V R} [@code{rreduce}] command is similar to @kbd{V R} except
21230 There is a third ``by rows'' mode for reduction that is occasionally
21234 row vectors is equivalent to adding their elements. But @kbd{V R = *}
21243 The obsolete reduce-by-columns function, @code{reducec}, is still
21244 supported but there is no way to get it through the @kbd{V R} command.
21261 function nested @samp{n} times; if the function is @samp{f} and @samp{n}
21262 is 3, the result is @samp{f(f(f(a)))}. The number @samp{n} may be
21269 The @kbd{H V U} [@code{anest}] command is an accumulating version of
21271 @samp{[a, f(a), f(f(a)), f(f(f(a)))]}. If @samp{n} is negative and
21272 @samp{F} is the inverse of @samp{f}, then the result is of the
21279 The @kbd{H I V R} [@code{fixp}] command is like @kbd{H V R}, except
21280 that it takes only an @samp{a} value from the stack; the function is
21287 The @kbd{H I V U} [@code{afixp}] command is an accumulating @code{fixp}.
21292 For example, 0.739085 is a fixed point of the cosine function (in radians):
21299 Newton's method for finding roots is a classic example of iteration
21304 2.23607. This is equivalent to using the @kbd{a R} (@code{calc-find-root})
21311 @samp{a} is a formula (say, a variable name), then the function is
21313 It is up to you to ensure that the function will eventually converge;
21317 and @samp{tol}. The first is the maximum number of steps to be allowed,
21319 default). The second is a convergence tolerance. If a tolerance is
21322 between two successive results is less than or equal to the tolerance.
21328 stopping when the result is correct within the specified tolerance, or
21329 when 20 steps have been taken, whichever is sooner.
21343 the result matrix is obtained by applying the operator to element @var{r}
21354 respectively, the result is a standard matrix multiplication. Element
21355 @var{r},@var{c} of the result matrix is obtained by mapping the
21365 first (multiplicative) operator is taken from the top of the stack
21366 and the second (additive) operator is taken from second-to-top.
21375 in the same way (@pxref{Display Modes}). Matrix display is also
21427 is @samp{RO}. (Before Calc 2.00, the format was fixed at @samp{ROC}.)
21521 mechanism is described; this works in conjunction with any Calc
21524 is discussed.
21562 When working with an algebraic formula it is often necessary to
21590 character. By default the sub-formula is highlighted by blanking out
21592 display mode but is perhaps easiest in Big mode (@kbd{d B}).
21621 @code{calc-highlight-selections-with-faces} is non-@code{nil}, then the characters
21624 The @samp{*} next to the line number is to remind you that
21626 obvious, but it might not always be. If Embedded mode is enabled,
21643 The portion selected is always large enough to be considered a complete
21648 (Strictly speaking, the Emacs cursor is really the manifestation of
21649 the Emacs ``point,'' which is a position @emph{between} two characters
21653 If you supply a numeric prefix argument @var{n}, the selection is
21659 If the cursor is not on any part of the formula, or if you give a
21660 numeric prefix that is too large, the entire formula is selected.
21662 If the cursor is on the @samp{.} line that marks the top of the stack
21674 is roughly analogous to using @kbd{C-@@} (@code{set-mark-command}) to
21682 @kbd{j o 1 +} is a handy way to add one to the sub-formula indicated
21697 has a selection they have no effect. This is analogous to the
21699 @pxref{Selections with Rewrite Rules}) and is mainly intended to be
21718 c} portion, which makes sense when the deep structure of the sum is
21719 considered. There is no way to select the @samp{b - c + d} portion;
21725 When @kbd{j b} mode has not been enabled, the deep structure is
21726 generally hidden by the selection commands---what you see is what
21732 that the cursor is on. If there was no selection in the formula,
21749 @w{@kbd{j m}} (@code{calc-select-more}) command. If @samp{a + b} is
21762 In the last example, the entire formula is selected. This is roughly
21764 differences the @samp{*} character is still there on the line number.
21767 times (or until the entire formula is selected). Note that @kbd{j s}
21768 with argument @var{n} is equivalent to plain @kbd{j s} followed by
21769 @kbd{j m} with argument @var{n}. If @w{@kbd{j m}} is used when there
21770 is no current selection, it is equivalent to @w{@kbd{j s}}.
21775 is not on any stack element operates on the top stack element.
21780 selection around the cursor position. That is, it selects the
21782 cursor, the opposite of @kbd{j m}. If the cursor is not inside the
21791 For example, if the current selection is @kbd{a + b + c} or
21796 If there is no current selection, @kbd{j 1} through @kbd{j 9} select
21799 sub-formula where @var{n} is greater than nine, you must instead invoke
21809 if @samp{b} is selected in @w{@samp{2 + a*b*c + x}}, then @kbd{j n}
21811 even though there is something to the right of @samp{c} (namely, @samp{x}),
21812 it is not at the same level; in this case, it is not a term of the
21821 It is interesting to compare Calc's selection commands with the
21823 organized documentation. Calc's @kbd{j n} command is completely
21825 @kbd{p}, @kbd{j 2} maps to @kbd{2}, and Info's @kbd{u} is like @kbd{j m}.
21827 The Info @kbd{m} command is somewhat similar to Calc's @kbd{j s} and
21841 selected sub-formulas are displayed. One of the alternatives is
21843 to the other style in which the selected portion itself is obscured
21855 @code{calc-highlight-selections-with-faces} is non-@code{nil}, then the
21866 Once a selection is made, all Calc commands that manipulate items
21913 The @kbd{j '} (@code{calc-enter-selection}) command is another way
21918 selection. If there is no selection in the formula under the cursor,
21919 the cursor is used to make a temporary selection for the purposes of
21921 do is move the Emacs cursor to that term and press @kbd{j '}.
21925 The @kbd{j `} (@code{calc-edit-selection}) command is a similar
21927 selected sub-formula in a separate buffer. If there is no
21947 since this is part of a product, Calc replaces it with @samp{1}
21951 element is deleted from the vector. If you delete one side of
21956 The @kbd{j @key{DEL}} (@code{calc-del-selection}) command is like
21964 (There is also an auto-selecting @kbd{j @key{RET}} (@code{calc-copy-selection})
21984 shows, the result of the subtraction is spliced back into the argument
22027 selection is one term of a sum or product; the sum or product is
22030 As with @kbd{j '} and @kbd{j @key{DEL}}, the term under the cursor is used
22031 if there is no selection in the current formula. All commands described
22040 Note that in the final step above, the @samp{a} is switched with
22046 of a function. The term is exchanged with the one to its right.
22058 The @kbd{j L} (@code{calc-commute-left}) command is like @kbd{j R}
22062 term several steps at a time. It is an error to try to move a
22072 selected, the result is @samp{a b - a c}. This also distributes
22075 where @samp{a + b} is the selected term, and @samp{ln(a ^ b)}
22076 to @samp{ln(a) b}, where @samp{a ^ b} is the selected term.
22083 times to expand at once; the default is one time only.
22086 The @kbd{j D} command is implemented using rewrite rules.
22089 these rules is to use @kbd{s e} (@code{calc-edit-variable}) which
22102 The @kbd{j M} (@code{calc-sel-merge}) command is the complement
22104 @samp{a c} selected, the result is @samp{a * (b - c)}. Once
22114 if @kbd{j b} mode were in effect, i.e., the sum @samp{a + b + c} is
22116 If you put the cursor on the first @samp{+}, the result is
22118 result is @samp{c + (a + b)} (which the default simplifications
22126 you don't turn them off. The same is true of some of the other
22135 @samp{exp(a - b)} where @samp{a - b} is selected, the result is
22139 of the formula as a whole. The rules variable is @code{NegateRules}.
22144 The @kbd{j &} (@code{calc-sel-invert}) command is similar to @kbd{j N}
22146 given @samp{a - ln(b)} with @samp{b} selected, the result is
22147 @samp{a + ln(1/b)}. The rules variable is @code{InvertRules}.
22154 @samp{a + b = c + d} with @samp{c} selected, the result is
22156 term is part of a @samp{*}, @samp{/}, or @samp{^} formula. The
22157 relevant rules variable is @code{JumpRules}.
22166 When it applies, @kbd{j I} is often easier to use than @kbd{j E}.
22179 providing a prefix argument: @kbd{C-u j *}. There is also a @kbd{j /}
22180 (@code{calc-sel-div-both-sides}) which is similar to @kbd{j *} but
22183 If the selection is a quotient with numerator 1, then Calc's default
22185 this, when the @kbd{j *} command is used on a selection whose numerator is
22186 1 or -1, the denominator is expanded at the top level using the
22188 formula on the stack is @samp{1 / (a + 1)} and you wish to multiplying the
22191 to the original form by cancellation; when @kbd{j *} is used, Calc
22196 example, if the formula on the stack is @samp{1 / (sqrt(a) + 1)}, you may
22203 generally, if @kbd{j *} is called with an argument of a positive
22207 If the selection is an inequality, @kbd{j *} and @kbd{j /} will
22209 is either positive or negative. (In the latter case the direction
22211 for ways to inform Calc that a given variable is positive or
22213 will be, it will assume it is positive and display a warning
22237 is @samp{a + x^2}. (The @samp{x^2} will remain selected; if you
22248 by the @kbd{m O} command. This command is just an auto-selecting
22262 The @kbd{j "} (@code{calc-sel-expand-formula}) command is to @kbd{a "}
22263 (@pxref{Algebraic Manipulation}) what @kbd{j v} is to @kbd{a v}.
22278 answer the prompt with a blank line, the variable or formula is taken
22279 from top-of-stack, and the normal argument for the command is taken
22285 default simplifications on a formula; for example, @samp{a - -b} is
22287 automatically on all Calc results, so this command is useful only if
22291 It is often more convenient to type @kbd{=}, which is like @kbd{a v}
22313 the related @kbd{N} command, which is like @kbd{=} but temporarily
22330 is then rounded down to 12); and @samp{evalvn(pi - 3.1415, [-2])}
22337 @samp{deg(x^2)} is changed to @samp{180 x^2 / pi}. Most functions,
22340 functions which @emph{can} be expanded is the user-defined functions
22354 a given function or operator to one or more equations. It is analogous
22368 are mapped, the direction of the second inequality is reversed to
22378 though this is not true for all values of the variables.
22385 (This change is mathematically incorrect, but perhaps you were
22404 Note that this is a purely structural substitution; the lone @samp{x} and
22413 blank line for the new one, the new formula is taken from top-of-stack
22415 target is taken from top-of-stack as usual.
22420 because the @samp{+} operator is left-associative, so the ``deep
22421 structure'' of that formula is @samp{(x+y) + z}. Use @kbd{d U}
22427 Target expression, old, new. Note that @code{subst} is always
22492 The most basic simplification is the evaluation of functions.
22493 For example, @expr{2 + 3} is evaluated to @expr{5}, and @expr{@tfn{sqrt}(9)}
22494 is evaluated to @expr{3}. Evaluation does not occur if the arguments
22497 or if the function name is not recognized (@expr{@tfn{f}(5)}), or if
22502 simplifies the function itself. Thus @expr{@tfn{sqrt}(5+4)} is
22504 itself is applied. There are very few exceptions to this rule:
22515 and collected into a suitable function call, which is then simplified
22565 is to rewrite @expr{a + (-b)} or @expr{(-b) + a}, where @expr{-b}
22568 @expr{-x}, and products or quotients in which either term is
22572 @expr{-(a b)} or @expr{-(a/b)} where either @expr{a} or @expr{b} is
22574 @expr{a} or @expr{b} is any number, by negating that number;
22577 cases where the order of terms in a sum is changed by the default
22580 The distributive law is used to simplify sums in some cases:
22587 The distributive law is only used for sums of two terms, or
22589 is simplified to @expr{a + 2 b + c}, but @expr{a + b + c + b}
22590 is not simplified. The reason is that comparing all terms of a
22596 A consequence of the above rules is that @expr{0 - a} is simplified
22606 in Matrix mode where @expr{a} is not provably scalar the result
22607 is the generic zero matrix @samp{idn(0)}, and that if @expr{a} is
22608 infinite the result is @samp{nan}.
22615 @expr{a b 2} is commuted to @expr{2 a b}.
22617 The product @expr{a (b + c)} is distributed over the sum only if
22620 @expr{(-a) (b - c)}, where @expr{-a} is a negative number, is
22623 The distributive law of products and powers is used for adjacent
22627 where @expr{a} is a number, or an implicit 1 (as in @expr{x}),
22629 @expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt}
22630 if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively.
22631 If the sum of the powers is zero, the product is simplified to
22632 @expr{1} or to @samp{idn(1)} if Matrix mode is enabled.
22635 power is changed to use division:
22638 goes to @expr{y / x^2} unless Matrix mode is
22640 case it is considered unsafe to rearrange the order of the terms).
22642 Finally, @expr{a (b/c)} is rewritten to @expr{(a b)/c}, and also
22643 @expr{(a/b) c} is changed to @expr{(a c)/b} unless in Matrix mode.
22650 The quotient @expr{0 / x} is simplified to @expr{0}, with the same
22655 The quotient @expr{x / 0} is left unsimplified or changed to an
22662 is changed to @expr{a b^c}, where @expr{-c} is any negative-looking
22663 power. Also, @expr{1 / b^c} is changed to
22671 rearrangement. Similarly, @expr{a / (b:c)} is simplified to
22674 The distributive law is applied to @expr{(a + b) / c} only if
22681 is canceled to @expr{x b / y b} but not to @expr{x / y}. Once
22682 again this is because full cancellation can be slow; use @kbd{a s}
22693 The formula @expr{x^0} is simplified to @expr{1}, or to @samp{idn(1)}
22694 in Matrix mode. The formula @expr{0^x} is simplified to @expr{0}
22695 unless @expr{x} is a negative number, complex number or zero.
22696 If @expr{x} is negative, complex or @expr{0.0}, @expr{0^x} is an
22698 mode. The expression @expr{0^0} is simplified to @expr{1}.
22702 is an integer, or if either @expr{a} or @expr{b} are nonnegative
22706 only when @expr{c} is an integer and @expr{b c} also
22712 is safe to simplify, but
22715 is not.) @xref{Declarations}, for ways to inform Calc that your
22718 As a special case of this rule, @expr{@tfn{sqrt}(x)^n} is simplified to
22723 If @expr{a} is known to be real, @expr{b} is an even integer, and
22724 @expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is
22727 Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an
22728 even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer,
22739 is changed to
22742 but @expr{1 / @tfn{sqrt}(x)} is left alone.
22750 is provably scalar, or expanded out if @expr{b} is a matrix;
22753 @expr{@tfn{idn}(a b)} if @expr{a} is provably scalar, or to @expr{a b}
22754 if @expr{a} is provably non-scalar; @expr{@tfn{idn}(a) @tfn{idn}(b)} to
22757 @expr{n} is an integer.
22764 vanish if the argument is provably integer-valued, so that
22773 @expr{-x} if @expr{x} is provably nonnegative or nonpositive
22784 @expr{@tfn{conj}(a + b i)} is changed to
22794 One important simplification that does occur is that
22795 @expr{@tfn{ln}(@tfn{e})} is simplified to 1, and @expr{@tfn{ln}(@tfn{e}^x)} is
22805 @expr{!!2} is 1, not 2.
22819 the algebraic simplification mode, which is the default simplification
22825 There is a variable, @code{AlgSimpRules}, in which you can put rewrites
22826 to be applied. Its use is analogous to @code{EvalRules},
22830 the built-in rules described below. If the result is different from
22841 The only exception is that a constant will not be commuted away
22842 from the first position of a difference, i.e., @expr{2 - x} is not
22855 law. For example, @expr{b c a} is commuted to @expr{a b c}.
22867 Sorting of terms of products is inhibited when Matrix mode is
22869 two terms unless it knows at least one of the terms is a scalar.
22875 Even though sums are not sorted, the commutative law is still
22878 A subtle point is that @expr{(x - y) (y - x)} will @emph{not}
22881 that constant is @mathit{-1}.
22883 A fraction times any expression, @expr{(a:b) x}, is changed to
22884 a quotient involving integers: @expr{a x / b}. This is not
22886 is one reason why you may find it convenient to turn Fraction mode
22898 as described above.) If there is any common integer or fractional
22899 factor in the numerator and denominator, it is canceled out;
22915 will no longer occur. This is not done by the basic
22923 pulled out so that @expr{@tfn{sqrt}(8)} is rewritten as
22939 The @code{%} (modulo) operator is simplified in several ways
22940 when the modulus @expr{M} is a positive real number. First, if
22941 the argument is of the form @expr{x + n} for some real number
22942 @expr{n}, then @expr{n} is itself reduced modulo @expr{M}. For
22943 example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}.
22945 If the argument is multiplied by a constant, and this constant
22946 has a common integer divisor with the modulus, then this factor is
22947 canceled out. For example, @samp{12 x % 15} is changed to
22949 is changed to @samp{3 ((4 x + 1:3) % 5)}. While these forms may
22953 If the modulus is 1, then Calc can use @code{int} declarations to
22954 evaluate the expression. For example, the idiom @samp{x % 2} is
22955 often used to check whether a number is odd or even. As described
22967 function, the replacement is made; for example,
22968 @expr{@tfn{tan}(x) @tfn{cos}(x)} is simplified to @expr{@tfn{sin}(x)}.
22970 function; for example, @expr{1/@tfn{sec}(x)} is simplified to
22975 simplified. The expression @expr{@tfn{sin}(@tfn{arcsin}(x))} is
22981 If the argument to @code{sin} is negative-looking, it is simplified to
22997 radians or 360 degrees. However, @expr{@tfn{arcsinh}(@tfn{sinh}(x))} is
22998 simplified to @expr{x} if @expr{x} is known to be real.
23008 reduce to @expr{x} if @expr{x} is provably real. The form
23009 @expr{@tfn{exp}(x)^y} is simplified to @expr{@tfn{exp}(x y)}. If @expr{x}
23010 is a suitable multiple of
23015 @expr{@tfn{ln}(x)} is simplified to a form involving @code{pi} and
23016 @code{i} where @expr{x} is provably negative, positive imaginary, or
23029 change sign if a negative multiplicative factor is canceled.
23034 sign is known.
23038 declarations. If @expr{x} is declared to be an integer greater
23040 all simplified to 0, but @expr{x > 3} is simplified to 1.
23041 By a similar analysis, @expr{abs(x) >= 0} is simplified to 1,
23042 as is @expr{x^2 >= 0} if @expr{x} is known to be real.
23057 Calc is capable of performing some simplifications which may sometimes
23067 of this is that the integrator's results must be used with caution.
23072 Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
23081 step described above is simply followed by an @kbd{a r ExtSimpRules} step.)
23083 Following is a complete list of the ``unsafe'' simplifications.
23106 the powers cancel to get @expr{x}, which is valid for positive values
23126 simplifications are safe if @expr{x} is known to be real).
23133 on whether you believe @expr{x} is positive or negative).
23151 Scalar mode is automatically put into effect when simplifying units.
23158 is inconsistent and is left alone. Otherwise, it is rewritten
23161 If units auto-ranging mode is enabled, products or quotients in
23162 which the first argument is a number which is out of range for the
23167 For example, @samp{2 km m} is simplified to @samp{2000 m^2}.
23172 if @expr{b} is a number or a product beginning with a number, Calc
23194 Also, if a unit name is raised to a fractional power, and the
23197 is expanded out into its base units, which can then be simplified
23199 is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre}
23200 is defined in terms of @samp{m^2}, and that the 2 in the power of
23201 @code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is
23205 which is then changed to
23213 simplified. For example, @samp{round(1.6 in)} is changed to
23225 A @dfn{polynomial} is a sum of terms which are coefficients times
23227 is a polynomial in @expr{x}. Some formulas can be considered
23229 is a polynomial in both @expr{x} and @expr{y}. Polynomial coefficients
23238 @expr{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another
23239 example, @expr{a c + b d + b c + a d} is factored into the product
23282 @samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
23284 (which may be numbers or formulas). The constant term is written first,
23291 polynomial alone on the assumption that it is unfactorable. (Note that
23298 but it returns a list of factors instead of an expression which is the
23299 product of the factors. Each factor is represented by a sub-vector
23303 If there is an overall numeric factor, it always comes first in the list.
23306 respect to the specific variable @expr{v}. The default is to factor with
23336 the distributive law is applied only the specified number of times, then
23337 the partially expanded expression is left on the stack.
23342 the formula. There is an exactly analogous correspondence between
23349 expansion. For example, the first step in expanding @expr{(x+1)^3} is
23352 simplify it back to @expr{(x+1)^3} form. The solution is to turn
23361 rational function by partial fractions. A rational function is the
23374 @expr{(b + a c + c d) / c d}. The quotient is reduced, so that
23388 The remainder from the division, if any, is reported at the bottom
23389 of the screen and is also placed in the Trail along with the quotient.
23393 If @code{pdiv} is given only two arguments (as is always the case with
23402 @expr{q} is discarded. For any formulas @expr{a} and @expr{b}, the
23404 (This is analogous to plain @kbd{\} and @kbd{%}, which compute the
23416 @expr{q + r/b} on the stack. (Naturally if the remainder is zero,
23424 is unique only to within a constant multiplier; Calc attempts to
23432 often have integer coefficients, this is not required. Calc can also
23477 considered constant, i.e., @samp{deriv(y,x)} is reduced to zero. With
23478 the Hyperbolic flag, the @code{tderiv} (total derivative) operation is used
23488 When working with trigonometric functions, it is best to switch to
23490 in degrees is @samp{(pi/180) cos(x)}, probably not the expected
23515 to the first argument is written @samp{f'(x,y,z)}; derivatives with
23531 respect to a prompted-for variable. The integrator is not guaranteed to
23532 work for all integrable functions, but it is able to integrate several
23534 function (a polynomial divided by a polynomial) is acceptable.
23538 is not strictly a quotient of polynomials, but it is equivalent to
23539 @expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving
23569 is several times more complicated than the answer Mathematica
23586 suspect this is not happening when it should, use the
23592 If the integrator is taking too long, you can lower this limit by storing
23594 command is a convenient way to edit @code{IntegLimit}.) If this variable
23596 of 3 is used. The lower this limit is, the greater the chance that Calc
23618 @samp{integtry(@var{expr},@var{var})}, where @var{expr} is the
23619 integrand and @var{var} is the integration variable. If your rules
23656 is allowed only within @code{IntegRules}; it means ``integrate this
23657 with respect to the same integration variable.'' If Calc is unable
23660 unevaluated integral @samp{integ(twice(f(x)), x)}. It is still valid
23662 if @code{u} is not integrable, @code{twice} itself will still be
23663 integrated: If the above rule is changed to @samp{... := twice(integ(u,x))},
23673 @samp{u = sqrt(x)}. (This particular rule is unnecessary because
23686 general form is @samp{integsubst(@var{sexpr}, @var{svar}, @var{sinv},
23687 @var{sprime})}, where @var{sinv} is the inverse of @var{sexpr} (still
23688 written as a function of @var{svar}), and @var{sprime} is the
23690 specify these things, and Calc is not able to work them out on its
23706 integration is attempted.
23708 One more way to influence the integrator is to define a function with
23717 Sometimes Calc is able to find a solution to your integral, but it
23718 expresses the result in a way that is unnecessarily complicated. If
23721 you can use @code{IntegAfterRules}. This is an extra rule set that
23747 value, if any, for the integration variable itself is ignored.)
23752 it is safe to integrate @samp{sin(x)/x} from zero, for example). Also,
23754 integrated is fairly smooth. If the function is not smooth, Calc will
23758 Integration is much faster when the current precision is small. It is
23762 to need hundreds of evaluations, check to make sure your function is
23765 It is possible for the lower integration limit to be @samp{-inf} (minus
23768 limits. However, integration to or across singularities is not supported:
23790 If the @kbd{a i} command is unable to find a symbolic integral for a
23804 an equation to solve for a specific variable. An equation is an
23807 input is not an equation, it is treated like an equation of the
23815 for @expr{b} is impossible
23821 inequality is now unknown. The inequality
23824 is not even partially solved. @xref{Declarations}, for a way to tell
23860 think about it is that the square-root operation is really a
23866 There is a similar phenomenon going the other direction: Suppose
23868 to get @samp{y = x^2}. This is correct, except that it introduces
23870 Calc will report @expr{y = 9} as a valid solution, which is true
23871 in the mathematical sense of square-root, but false (there is no
23892 arbitrary value a name that is unique throughout the entire Calc
23894 of variables, which is advantageous in some cases. For example,
23900 The @kbd{s G} (@code{calc-edit-GenCount}) command is a convenient
23904 in that variable is not a positive integer, the regular
23905 @code{s1}/@code{n1} notation is used.
23927 values. The results are collected into a vector, which is returned.
23935 Note that because @kbd{a P} uses @kbd{H a S}, it is able to deliver
23937 note that Calc's solver is not able to get exact symbolic solutions
23940 can be: @expr{x^6 + x^3 + 1} is converted to @expr{(x^3)^2 + (x^3) + 1},
23946 is not turned on. (If you work with Symbolic mode on, recall that the
23947 @kbd{N} (@code{calc-eval-num}) key is a handy way to reevaluate the
24009 to get a general family of solutions, or, if there is a finite
24016 equations is the @kbd{a F} command, which does least-squares fitting
24030 @expr{[0, 2, 0, 1]}. If the input is not a polynomial in @expr{x},
24031 the call to @code{poly} is left in symbolic form. If the input does
24032 not involve the variable @expr{x}, the input is returned in a list
24035 The last element of the returned vector is guaranteed to be nonzero;
24052 One important feature of the solver is its ability to recognize
24053 formulas which are ``essentially'' polynomials. This ability is
24055 is used just like @code{poly}: @samp{gpoly(@var{expr}, @var{var})}.
24056 If @var{expr} is a polynomial in some term which includes @var{var}, then
24058 where @var{x} is the term that depends on @var{var}, @var{c} is a
24060 and @var{a} is a multiplier which is usually 1. Basically,
24062 @var{c}_3 @var{x}^2 + ...)}. The last element of @var{c} is
24064 (i.e., the trivial decomposition @var{expr} = @var{x} is not
24065 considered a polynomial). One side effect is that @samp{gpoly(x, x)}
24068 is considered trivial.
24071 since the expanded form of this polynomial is @expr{4 - 4 x + x^2}.
24073 The term @var{x} may itself be a polynomial in @var{var}. This is
24076 since a quadratic polynomial in @expr{x^2} is easier to solve than
24093 which specifies the largest degree of polynomial that is acceptable.
24094 If this is @expr{n}, then only @var{c} vectors of length @expr{n+1}
24106 @samp{pdeg(p,x)} is the highest power of @code{x} that appears in
24107 @code{p}. This is the same as @samp{vlen(poly(p,x))-1}, but is
24108 much more efficient. If @code{p} is constant with respect to @code{x},
24109 then @samp{pdeg(p,x) = 0}. If @code{p} is not a polynomial in @code{x}
24111 It is possible to omit the second argument @code{x}, in which case
24115 the degree of the constant zero is considered to be @code{-inf}
24123 Thus @samp{plead(p,x)} is equivalent to @samp{poly(p,x)_vlen(poly(p,x))},
24133 is the greatest common divisor of all the coefficients of the polynomial.
24137 @samp{pcont(4 x y^2 + 6 x^2 y, x)} is @samp{2 y}. The content is
24139 exactly. The sign of the content is the same as the sign of the leading
24145 is defined on rational numbers as well as integers; it computes
24150 numerators. The numerical content of a polynomial is negative only
24158 polynomial, which is simply the polynomial divided (using @code{pdiv}
24170 numerical commands are slower than their algebraic cousins; it is a
24194 inequalities the same as equations. If the input is any other kind
24195 of formula, it is interpreted as an equation of the form @expr{X = 0}.)
24201 a value is assigned to the solution variable and the formula is
24203 value for the solution variable itself is ignored and unaffected by
24206 When the command completes, the initial guess is replaced on the stack
24215 The @kbd{v h} (@code{calc-head}) command is a handy way to extract
24225 If this succeeds, it uses Newton's method. If the equation is not
24229 with a slightly different initial guess.) If the initial guess is a
24233 is negative at one end of the interval you specify and positive at
24234 the other end, the root finder is guaranteed to find a root.
24236 positive and negative values to bracket the root. When your guess is
24241 The @kbd{H a R} [@code{wroot}] command is similar to @kbd{a R}, except
24242 that if the initial guess is an interval for which the function has
24247 If the function is not differentiable, and you give a simple number
24250 @emph{is} differentiable, Calc uses Newton's method which does not
24272 finds a minimum value for a formula. It is very similar in operation
24284 have infinitely many. In fact, there is no easy way to define the
24290 finds a point at which the function's value is greater both to the left
24293 If your initial guess is an interval and it looks like the minimum
24295 that endpoint only if that endpoint is closed; thus, minimizing @expr{17 x}
24303 of this flatness, if the current precision is, say, 12 digits, the
24325 interval (or near the initial guess if the guess is a number). If
24326 the initial guess is a complex number the variable will be minimized
24327 over the complex numbers; if it is real or an interval it will
24348 It is also possible to minimize over many variables with @kbd{a N}
24354 multidimensional minimization is currently @emph{very} slow.
24366 the key sequence @kbd{a F} is pressed.
24368 If the letter @kbd{P} is pressed after @kbd{a F} but before the model
24369 description is entered, the data as well as the model formula will be
24370 plotted after the formula is determined. This will be indicated by a
24402 @expr{y} values in the data set. (In a polynomial fit, the model is
24404 we have data points of the form @expr{(x_1,x_2,x_3,y)} and our model is
24408 the @dfn{independent variables}, and @expr{y} is the @dfn{dependent
24417 matrix where the first row is a list of @expr{x} values and the second
24460 is on the stack and we wish to do a simple linear fit. Type
24469 The @kbd{a F} command puts two entries in the trail. One is, as
24470 always, a copy of the result that went to the stack; the other is
24485 To see what happens when the fit is not exact, we could change
24487 The result is:
24500 Since there is no line which passes through all the @var{n} data points,
24502 the method of least squares. The idea is to define the @dfn{chi-square}
24517 which is clearly zero if @expr{a + b x} exactly fits all data points,
24520 summand is squared, one of them being to ensure that
24527 is as small as possible.
24540 is always one independent variable and one dependent variable.
24542 A prefix of zero or plain @kbd{C-u} is a compromise; Calc takes two
24544 vector of @expr{y} values. If there is only one independent variable,
24546 in which case the @kbd{C-u} prefix is the same as a @w{@kbd{C-u 2}} prefix.
24564 for @expr{x^2}. (The fact that it's not exactly zero is due only
24579 An important result from the theory of polynomial fitting is that it
24580 is always possible to fit @var{n} data points exactly using a polynomial
24591 It is a good idea to increase the working precision to several
24601 Fitting data ``exactly'' to high-degree polynomials is not always
24604 if the exact-fit polynomial is going to be used to interpolate or
24605 extrapolate the data, it is numerically better to use the @kbd{a p}
24612 Another generalization of the linear model is to assume the
24614 @expr{x} values. This is a @dfn{multilinear} fit, and it is also
24616 is linear or multilinear by counting the rows in the data matrix.)
24644 Yet another variation is @dfn{homogeneous} linear models, in which
24645 the constant term is known to be zero. In the linear case, this
24646 means the model formula is simply @expr{a x}; in the multilinear
24654 It is certainly possible to have other constrained linear models,
24655 like @expr{2.3 + a x} or @expr{a - 4 x}. While there is no single
24680 fit is perfect. In the second case, the errors are nonzero but
24683 It is also possible for the @emph{input} to a fitting operation to
24693 statistic is now,
24725 values are the same, it is easy to see that the resulting fitted model
24729 is simply scaled uniformly by
24747 information. The result is a vector of six items:
24752 parameters. This is the result that @kbd{H a F} would have
24763 The covariance matrix @expr{C} computed from the fit. This is
24784 will instead be an empty vector; this is always the case for the
24795 to indicate a moderately good fit (where again @expr{N} is the number of
24796 data points and @expr{M} is the number of parameters).
24800 This is computed from the @code{utpc} probability distribution
24814 The @expr{Q} value is computed only if the input included error
24816 for @expr{Q}. The reason is that in this case the
24820 in the input, and thus there is no redundant information left
24832 Here is a complete list of the standard models recognized by @kbd{a F}:
24879 the parameter values from the vector that is placed in the trail.)
24891 each other. Also, the ``quadratic'' model is just a degree-2 polynomial
24899 @expr{a} is what the HP-48 identifies as the ``intercept,'' and
24900 @expr{b} is what it calls the ``slope.''
24946 another, and so on. Thus @kbd{$ x + $$} is another way to describe
24959 (If @var{params} is omitted, all variables in @var{model} except
25000 There is no good solution to this problem at present. You could
25004 Fourier analysis, which is beyond the scope of the @kbd{a F} command.
25018 In a simple multilinear or polynomial fit, it is easy to see how
25020 is @expr{a + b x + c x^2}, then @expr{f(x) = 1}, @expr{g(x) = x},
25064 Another interesting example is the ``quadratic'' model, which can
25088 form is a Gaussian with a constant background added on, i.e.,
25090 this, your best bet is to replace enough of your parameters with
25114 command is able to use a vastly more efficient algorithm due to its
25119 fit is linearizable, and use @code{minimize} on a call to @code{fit}
25142 The @kbd{I a F} [@code{xfit}] command is somewhat trickier when
25143 nonlinear models are used. The second item in the result is the
25145 covariance matrix is written in terms of those raw parameters.
25146 The fifth item is a vector of @dfn{filter} expressions. This
25147 is the empty vector @samp{[]} if the raw parameters were the same
25149 and so on (which is always true if the model is already linear
25151 parameters had to be rearranged, the fifth item is instead a vector
25168 that the covariance matrix is in terms of the raw parameters,
25180 linearized model is evaluated, and the result should be an error
25181 form. The error part of that result is used for
25185 an error form, the combined error from @expr{z} is used directly for
25188 Finally, @expr{z} is also stripped of its error
25190 the righthand side of the linearized model is computed in regular
25195 depends only on the dependent variable @expr{z}, and in fact is
25197 and multilinear models, the combined error is simply used as the
25207 It may be the case that the model you wish to use is linearizable,
25211 variable using the @kbd{s e FitRules} command; in fact, there is
25251 call to the function @code{fitmodel} (which is not actually a defined
25252 function in Calc; it is only used as a placeholder by the rewrite rules).
25256 is the highest-numbered @code{fitvar}. For example, the power law
25257 model @expr{a x^b} is converted to @expr{y = a x^b}, then to
25269 When rewriting is complete, the @code{fitmodel} call should have
25277 where @var{Y} is a formula that describes the function @expr{Y(x,y,z)},
25278 @var{FGH} is the vector of formulas @expr{[F(x,y,z), G(x,y,z), H(x,y,z)]},
25279 and @var{abc} is the vector of parameter filters which refer to the
25282 the @var{FGH} vector) is usually the same as the number of original
25283 parameters (the length of the @var{abc} vector), this is not required.
25295 The actual implementation of @code{FitRules} is complicated; it
25302 and the distributive law is used to expand products of sums.
25311 form @samp{fitmodel(@var{Y}, @var{model})}, where @var{Y} is
25316 this is no longer possible, the @code{fitmodel} is changed to a
25317 four-argument @code{fitsystem}, where the fourth argument is
25319 empty. (The last vector is really @var{ABC}, corresponding to
25325 is all factors that do not involve any variables, @var{b} is all
25326 factors that involve only parameters, and @var{c} is the factors
25328 is not possible, the rule set will not complete and Calc will
25329 complain that the model is too complex.) Then @code{fitpart}s
25364 returned is the largest @var{n} from all the @samp{fitparam(@var{n})}s
25373 where @var{model} is the model formula as it would be typed after
25374 @kbd{a F '}, @var{vars} is the independent variable or a vector of
25376 and @var{data} is the data matrix. Note that the length of @var{vars}
25377 must be equal to the number of rows in @var{data} if @var{model} is
25378 an equation, or one less than the number of rows if @var{model} is
25379 a plain formula. (Actually, a name for the dependent variable is
25382 If @var{params} is omitted, the parameters are all variables in
25384 is also omitted, Calc sorts all the variables that appear in
25388 Alternatively, @samp{fit(@var{modelvec}, @var{data})} is allowed
25389 where @var{modelvec} is a 2- or 3-vector describing the model
25392 If Calc is unable to do the fit, the @code{fit} function is left
25394 message will be ``Model expression is too complex'' if the
25413 use @kbd{a F i}, however; it uses a direct method which is both more
25416 The result of @kbd{a p} is actually a vector of two values: The @expr{y}
25419 @expr{x}. If the input @expr{x} is equal to any of the @expr{x} values
25426 If @expr{x} is a vector of numbers, @kbd{a p} will return a matrix of
25429 If @expr{x} is a formula instead of a number, the @code{polint} function
25434 on the stack. Only the @expr{x} value is replaced by the result.
25439 interpolation. It is used exactly like @kbd{a p}, except that it
25442 each have degree @expr{N/2} (if @expr{N} is odd, the denominator will
25450 is enabled, the result will be @samp{[uinf, uinf]}.
25452 There is no way to get the actual coefficients of the rational function
25467 is taken from the top of the stack; the command prompts for the
25478 The choice of index variable is arbitrary, but it's best not to
25480 @code{i} is often a favorite index variable, it should be avoided
25500 this is possible if the formula being summed is polynomial or
25509 The notation for sums in algebraic formulas is
25511 If @var{step} is omitted, it defaults to one. If @var{high} is
25512 omitted, @var{low} is actually the upper limit and the lower limit
25513 is one. If @var{low} is also omitted, the limits are @samp{-inf}
25517 returns @expr{1}. This is done by evaluating the sum in closed
25539 not come out to an integer, the sum is invalid and will be left
25543 @samp{sum(k, k, 1, 10, 2)} is invalid, but Calc will go ahead and
25547 If the lower limit is greater than the upper limit (assuming a
25548 positive step size), the result is generally zero. However,
25549 Calc only guarantees a zero result when the upper limit is
25551 of iterations is @mathit{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero
25558 @samp{sum(prime(k)*k^2, k, 1, 20)} is the sum of the squares of all
25560 its argument is prime and 0 otherwise. You can read this expression
25561 as ``the sum of @expr{k^2}, where @expr{k} is prime.'' Indeed,
25567 As another example, @samp{sum((k != k_0) * f(k), k, 1, n)} is the
25569 one value @expr{k_0}. Slightly more tricky is the summand
25570 @samp{(k != k_0) / (k - k_0)}, which is an attempt to describe
25574 Calc will not assume is zero. Better would be to use
25591 @samp{(-1)^(k-@var{low})}. This formula is adjusted appropriately
25592 if the step value is other than one. For example, the Taylor
25593 series for the sine function is @samp{asum(x^k / k!, k, 1, inf, 2)}.
25603 The @kbd{a *} (@code{calc-product}) [@code{prod}] command is
25614 like @code{sum} and @code{prod}, but its result is simply a
25624 a truth value is required (such as for the condition part of a rewrite
25626 nonzero value is accepted to mean ``true.'' (Specifically, anything
25627 for which @code{dnonzero} returns 1 is ``true,'' and anything for
25628 which @code{dnonzero} returns 0 or cannot decide is assumed ``false.''
25630 portion if its condition is provably true, but it will execute the
25631 ``else'' portion for any condition like @expr{a = b} that is not
25634 unevaluated if the condition is neither provably true nor provably
25644 formula) is true if @expr{a} and @expr{b} are equal, either because they
25646 numerically equal. (Thus the integer 1 is considered equal to the float
25648 the comparison is left in symbolic form. Note that as a command, this
25659 @samp{2 (a = b)} which represents 2 if the equality is true or
25664 algebraic notation, the @samp{=} operator is unusual in that it is
25665 neither left- nor right-associative: @samp{a = b = c} is not the
25675 @samp{a != b} function, is true if @expr{a} and @expr{b} are not equal.
25727 operation is true if @expr{a} is less than @expr{b}. Similar functions
25733 than two arguments, the syntax @w{@samp{a <= b < c}} is translated to an
25747 @samp{[x = 2.34, y = z / 2]} is on the stack, then @kbd{a .} produces
25748 @samp{[2.34, z / 2]}. As a special case, if the righthand side is a
25749 variable and the lefthand side is a number (as in @samp{2.34 = x}), then
25760 function is true if both of its arguments are true, i.e., are
25762 @expr{b}, chosen arbitrarily. If either argument is zero, the result is
25763 zero. Otherwise, the formula is left in symbolic form.
25770 function is true if either or both of its arguments are true (nonzero).
25771 The result is whichever argument was nonzero, choosing arbitrarily if both
25772 are nonzero. If both @expr{a} and @expr{b} are zero, the result is
25780 function is true if @expr{a} is false (zero), or false if @expr{a} is
25781 true (nonzero). It is left in symbolic form if @expr{a} is not a
25797 function is equal to either @expr{b} or @expr{c} if @expr{a} is a nonzero
25798 number or zero, respectively. If @expr{a} is not a number, the test is
25799 left in symbolic form and neither @expr{b} nor @expr{c} is evaluated in
25800 any way. In algebraic formulas, this is one of the few Calc functions
25802 is evaluated. The others are @code{lambda}, @code{quote}, and
25805 One minor surprise to watch out for is that the formula @samp{a?3:4}
25806 will not work because the @samp{3:4} is parsed as a fraction instead of
25811 and @expr{c} are evaluated; the result is a vector of the same length
25814 is zero or nonzero. Each of @expr{b} and @expr{c} must be either a
25815 vector of the same length as @expr{a}, or a non-vector which is matched
25821 The @kbd{a @{} (@code{calc-in-set}) [@samp{in(a,b)}] function is true if
25822 the number @expr{a} is in the set of numbers represented by @expr{b}.
25823 If @expr{b} is an interval form, @expr{a} must be one of the values
25824 encompassed by the interval. If @expr{b} is a vector, @expr{a} must be
25826 intervals, @expr{a} must be in any of the intervals.) If @expr{b} is a
25836 characterizes @expr{a}. If @expr{a} is a number, vector, or variable,
25857 Otherwise, @expr{a} is a formula, and the result is a variable which
25872 The @samp{integer(a)} function returns true if @expr{a} is an integer.
25874 is true if @expr{a} is a real number, either integer, fraction, or
25875 float. The @samp{constant(a)} function returns true if @expr{a} is
25884 is true because @samp{floor(x)} is provably integer-valued, but
25885 @samp{integer(floor(x))} does not because @samp{floor(x)} is not
25892 The @samp{refers(a,b)} function is true if the variable (or sub-expression)
25896 @code{refers} will be left unevaluated is if @expr{a} is a plain
25904 because it is a negative number, because it is of the form @expr{-x},
25905 or because it is a product or quotient with a term that looks negative.
25906 This is most useful in rewrite rules. Beware that @samp{negative(a)}
25916 The @samp{variable(a)} function is true if @expr{a} is a variable,
25917 or false if not. If @expr{a} is a function call, this test is left
25925 The @samp{nonvar(a)} function is true if @expr{a} is a non-variable.
25926 If its argument is a variable it is left unsimplified; it never
25928 commands consider ``false'' anything not provably true, this is
25949 check if an expression is ``linear,'' i.e., can be written in the form
25952 if formula @expr{f} is linear in @expr{x}, returning 1 if so. For
25955 is similar, except that instead of returning 1 it returns the vector
25974 formula. Here, the @expr{a=0}, @expr{b=1} case is also considered
25981 case: @samp{islin(2,x)} is true, but @samp{islin(2)} is false.
25987 The @samp{istrue(a)} function returns 1 if @expr{a} is a nonzero
25988 number or provably nonzero formula, or 0 if @expr{a} is anything else.
25989 Calls to @code{istrue} can only be manipulated if @kbd{m O} mode is
25991 declarations are used when deciding whether a formula is true;
26014 name @code{x} is that the same name is used on both sides of the rule.
26044 This operator is equivalent to the function call @samp{assign(old, new)}.
26045 The @code{assign} function is undefined by itself in Calc, so an
26086 It is most convenient to store rules you use often in a variable and
26088 (@code{calc-edit-variable}) command is an easy way to create or edit a
26097 along with the variable for later reference. This is another good
26101 @samp{[@var{old}, @var{new}]}. But because it is easily confused with a
26102 vector of two rules, the use of this notation is no longer recommended.
26116 @samp{g(12, a+1)}, since there is no assignment of the meta-variables
26118 the pattern is a single meta-variable, it will match any expression.
26137 If the @var{old} pattern is found to match a given formula, that
26138 formula is replaced by @var{new}, where any occurrences in @var{new}
26153 @samp{@var{old} := @var{new} :: @var{cond}}. (There is also the obsolete
26155 is present in the
26156 rule, this is an additional condition that must be satisfied before
26157 the rule is accepted. Once @var{old} has been successfully matched
26158 to the target expression, @var{cond} is evaluated (with all the
26160 with Calc's algebraic simplifications. If the result is a nonzero
26162 the rule is accepted. If the result is zero or if it is a symbolic
26163 formula that is not known to be nonzero, the rule is rejected.
26168 is replaced by a positive or nonpositive number, respectively (or if
26175 to be satisfied, but that is enough to reject the rule.
26187 The @samp{::} operator is a shorthand for the @code{condition}
26188 function; @samp{@var{old} := @var{new} :: @var{cond}} is equivalent to
26194 It is also possible to embed conditions inside the pattern:
26195 @samp{f(x :: x>0, y) := g(y+x, x)}. This is purely a notational
26197 effect on when it is tested. The rewrite-rule compiler automatically
26198 decides when it is best to test each condition while a rule is being
26202 system and are tested very efficiently: Where @expr{x} is any
26205 is either a constant or another meta-variable and @samp{>=} may be
26211 An interesting property of @samp{::} is that neither of its arguments
26212 will be touched by Calc's default simplifications. This is important
26218 is safe since @samp{::} prevents the @code{typeof} from being
26219 evaluated until the condition is actually used by the rewrite system.
26226 lost. But @samp{a(f,x) := apply(f, [x]) :: 1} is safe, and of course
26227 the condition @samp{1} is always true (nonzero) so it has no effect on
26273 like @samp{x + y + z - w}. First, @samp{a} is matched against each
26276 If none of these succeed, then @samp{b} is matched against each of the
26280 Note that @samp{*} is not commutative when applied to matrices, but
26281 rewrite rules pretend that it is. If you type @kbd{m v} to enable
26284 current implementation, the associativity also vanishes---it is as
26300 condition. The @code{negative} function is true if its argument
26301 ``looks'' negative, for example, because it is a negative number or
26302 because it is a formula like @samp{-x}. The new rule using this
26303 condition is:
26314 @samp{y} is a number. Thus the rule @samp{a x + @w{b x} := (a+b) x}
26322 Nor will @samp{f(a b)} match @samp{f(x / y)} if @samp{y} is not a
26326 for addition and subtraction, often it is preferable to treat the cases
26329 Even more subtle is the rule set
26348 Another thing patterns will @emph{not} do is break up complex numbers.
26366 It is also possible to specify optional arguments in patterns. The rule
26397 The default value for a term of a sum is zero. The default value
26399 quotient, is one. Also, @samp{-x} matches the pattern @samp{opt(a) b}
26416 @samp{x/z} is considered linear with @expr{b = 1/z} by @code{lin},
26466 will not work. That is, it will match @samp{f(a - 1 + b, a + 1 + b)}
26469 then Calc is smart enough to use it for literal matching. But in this
26470 last example, Calc is forced to rewrite the rule to @samp{f(x-1, temp)
26476 @code{let} notation, which is described in the next section:
26485 elsewhere in the pattern. When matching a function call, Calc is
26498 This marker causes the function call which is its argument to be
26511 commutativity and associativity is still considered while matching
26542 A certain amount of algebra is also done when substituting the
26555 special simplification is only noticeable if you have turned the
26556 default simplifications off.) This rewriting is done only when
26558 If this simplification is not desirable, you can use a @code{plain}
26575 Here is a complete list of these markers. First are listed the
26584 rule. Here @expr{x} is the name of a variable containing another
26587 f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF},
26589 all three rules. It is possible to modify the imported rules
26600 is used as a function name, then
26618 not interpreted as meta-variables. The only flexibility is that
26634 function @expr{f} is used in this case; @samp{+} is not commutative or
26647 the argument or element is optional.
26663 In other words, the default @var{def} is effectively quoted.
26672 @expr{c}. It is the same as @samp{x :: c}.
26681 pattern @expr{y}. It is the same as @samp{x &&& y}.
26691 pattern @expr{y}. It is the same as @w{@samp{x ||| y}}.
26700 It is the same as @samp{!!! x}.
26708 element is matched to @expr{h}; a vector of the remaining
26709 elements is matched to @expr{t}. Note that vectors of fixed
26711 @samp{cons(a,cons(b,[])) := cons(a+b,[])} is equivalent
26719 This is like @code{cons}, except that the @emph{last} element
26720 is matched to @expr{h}, with the remaining elements matched
26729 the form of a variable, is matched to @expr{f}. The arguments
26749 set with four separate rules. The reason is that Calc sorts
26751 if the top-level function is @code{apply}, Calc must try the
26753 function in the pattern is, say, @code{floor}, then Calc invokes
26762 is @emph{not} correct, because it rewrites @samp{spam(6)} into
26776 This is used for applying rules to formulas with selections;
26784 The notation @samp{quote(x)} is changed to @samp{x} when the
26785 righthand side is used. As far as the rewrite rule is concerned,
26786 @code{quote} is invisible. However, @code{quote} has the special
26787 property in Calc that its argument is not evaluated. Thus,
26789 on the stack because @samp{typeof(a)} is evaluated immediately
26798 is useful is the rule, @samp{q(x) := quote(x)}, trying to expand a
26805 Where @expr{t} is a vector, this is converted into an expanded
26806 vector during rewrite processing. Note that @code{cons} is a regular
26808 is treated specially by rewrites is that @code{cons} on the righthand
26817 Where @expr{f} is a variable and @var{args} is a vector, this
26818 is converted to a function call. Once again, note that @code{apply}
26819 is also a regular Calc function.
26826 The formula @expr{x} is handled in the usual way, then the
26830 treated. However, there is a slight difference: @samp{cons(2+3, [])}
26862 The expression @expr{x} is evaluated with meta-variables substituted.
26866 of simplification. The result of @expr{x} is then bound to the
26869 meta-variable is new then it is bound to the result of the expression.
26873 evaluating @expr{x} is matched to that pattern, binding any
26876 @samp{&&} which is a whole condition: It cannot be inside
26879 The alternate, equivalent form @samp{let(v, x)} is also recognized.
26881 assignment-like in character, is unrelated to the use of @samp{:=}
26886 that inverse exists and is constant. For example, if @samp{a} is a
26887 singular matrix the operation @samp{1/a} is left unsimplified and
26888 @samp{constant(ia)} fails, but if @samp{a} is an invertible matrix
26891 Note that, because the meta-variable @samp{ia} is otherwise unbound
26898 The @code{lin} function returns a 3-vector if its argument is linear,
26901 so this @code{let} both verifies that @code{y} is linear, and binds
26911 Similarly, here is a rule that implements an inverse-@code{erf}
26914 where the first number is the desired solution. If no solution
26915 is found, @code{root} remains in symbolic form. So we use
26924 to something elsewhere in the rule, is compared against pattern
26925 @var{p}. Since @code{matches} is a standard Calc function, it
26933 @samp{matches(v, p)} is that the former evaluates @samp{v} using
26938 This is actually a variable, not a function. If @code{remember}
26942 was not stored in a variable, @code{remember} is ignored. The
26943 lefthand side is enclosed in @code{quote} in the added rule if it
26950 the result is added to the rule set, in this case as @samp{f(7) := 5040}.
26951 Thus @code{remember} is most useful inside @code{EvalRules}.
26953 It is up to you to ensure that the optimization performed by
26954 @code{remember} is safe. For example, the rule @samp{foo(n) := n
26955 :: evalv(eatfoo) > 0 :: remember} is a bad idea (@code{evalv} is
26959 @code{eatfoo} is later changed to 0.
26967 is true. For example, @samp{remember(n % 4 = 0)} in the above factorial
26969 is equivalent to @samp{remember}, and @samp{remember(0)} has no effect.
26987 matches both @var{p1} and @var{p2}. One especially useful case is
26988 when one of @var{p1} or @var{p2} is a meta-variable. For example,
26989 here is a rule that operates on error forms:
26995 This does the same thing, but is arguably simpler than, the rule
27036 A simple example of @samp{|||} is
27045 Here is a larger example:
27061 bound in the pattern to which the condition is attached (say, if
27094 converts @code{f} whose first argument is anything @emph{except} an
27095 error form, and whose second argument is not the empty vector, into
27106 where of course 7 is the @code{typeof} code for error forms.
27114 It is possible for a @samp{!!!} to refer to meta-variables bound
27125 If a function call is to be matched and one of the argument patterns
27145 When @kbd{a r} (@code{calc-rewrite}) is used, it takes an expression from
27155 The top-level formula is first matched and substituted repeatedly until
27163 It is possible for a rule set to get into an infinite loop. The
27164 most obvious case, replacing a formula with itself, is not a problem
27165 because a rule is not considered to ``succeed'' unless the righthand
27182 rewriting is not what is called for by your application).
27205 where each iteration is a successful matching of a rule pattern whose
27207 default simplifications, is different from the original sub-formula
27217 does a rewriting operation. Here @var{expr} is the expression
27218 being rewritten, @var{rules} is the rule, vector of rules, or
27219 variable containing the rules, and @var{n} is the optional
27221 integer, or @samp{inf} or @samp{-inf}. If @var{n} is omitted
27222 the @code{iterations} value from the rule set is used; if both
27223 are omitted, 100 is used.
27229 It is possible to separate a rewrite rule set into several @dfn{phases}.
27244 this is the default at the start of the rule set.
27274 When no more phase 3 rules apply, rewriting finishes. (This is
27278 100 by default, is reached.)
27294 for arguments; each phase number is invoked in turn until the
27298 no effect since this is the default schedule; and @samp{schedule(1,2,1,3)}
27312 numbers. A variable name is interpreted as the name of a function
27315 call @code{simplify} which is the function name equivalent of @kbd{a s}.
27319 Phases can be used purely to improve efficiency; if it is known that
27328 examine the set @code{FitRules}, which is used by the curve-fitting
27330 @xref{Curve Fitting Details}. This set is divided into four phases.
27344 two separate phases, this problem is neatly avoided.
27350 If a sub-formula of the current formula is selected (as by @kbd{j s};
27365 this is only a tag used by the @kbd{j r} command.)
27367 For example, suppose the formula on the stack is @samp{2 (a + b)^2}
27368 and the sub-formula @samp{a + b} is selected. This formula will
27374 If there is still exactly one @samp{select( )} function call in
27375 the formula after rewriting is done, it indicates which part of
27394 entry that contains the cursor. (If the cursor is on the top-of-stack
27406 command. If the cursor is not on any sub-formula (e.g., it is in
27434 and saved if it is stored in a variable. If there are several
27441 The @code{import} mechanism is not available for pattern sets.
27456 There is also a function @samp{matches(@var{x}, @var{p})} which
27458 to 0 otherwise. This is sometimes useful for including into the
27465 The function @code{vmatches} is just like @code{matches}, except
27477 It is possible to get Calc to apply a set of rewrite rules on all
27480 variable @code{EvalRules}. There is a convenient @kbd{s E} command
27503 As each level of a formula is evaluated, the rules from
27506 Note that this is different from the usual order of application of
27514 It is important not to write a rule that will get into an infinite
27516 appears to be a good definition of a factorial function, but it is
27517 unsafe. Imagine what happens if @samp{f(2.5)} is simplified. Calc
27520 Another dangerous rule is @samp{g(x, y) := g(y, x)}. Rewriting
27528 example, @samp{f(n) := f(floor(n))} ``fails to match'' when @expr{n} is
27529 already an integer. But in @code{EvalRules} this case is detected only
27533 replace @samp{f(6)} with @samp{f(floor(6))}, which is different from
27535 continue simplifying that formula; first the argument is simplified
27540 (What really happens is that the rewrite mechanism substitutes the
27542 result is the same as the original formula and fails if so, then uses
27545 form). The only special wrinkle for the @code{EvalRules} is that the
27547 are used. What Calc wants to do is build @samp{f(floor(6))}, see that
27548 this is different from the original formula, simplify to @samp{f(6)},
27549 see that this is the same as the original formula, and thus halt the
27555 not work in @code{EvalRules}. If the rule set is divided into phases,
27556 only the phase 1 rules are applied, and the schedule is ignored.
27568 Finally, another limitation is that Calc sometimes calls its built-in
27584 @code{EvalRules} is that while a given rewrite rule is in the process
27588 reason for this is that compiled pattern programs are not reentrant.)
27591 the condition @samp{foo(4) > 0} is checked, even though it might be
27592 an integral part of evaluating that condition. Note that this is not
27595 been reactivated by the time the righthand side is evaluated.
27598 anything but a vector is stored in it, then it is ignored.
27600 Even though Calc's rewrite mechanism is designed to compare rewrite
27602 @code{EvalRules} may make Calc run substantially slower. This is
27603 particularly true of rules where the top-level call is a commonly used
27604 function, or is not fixed. The rule @samp{f(n) := n f(n-1) :: n>0} will
27614 @code{log10}, but actually it is vastly less efficient because rules
27616 @emph{every} function call that is simplified.
27651 formula is written there, as is the result of each successful rewrite,
27656 yourself periodically if it is in danger of growing unwieldy.
27658 Note that the rewriting mechanism is substantially slower when the
27659 @file{*Trace*} buffer exists, even if the buffer is not visible on
27677 Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
27685 A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}.
27690 evaluated to a floating-point approximation). This rule is also
27741 In other words, @expr{q1 * q2 = q2 * q1} is not necessarily true if
27759 One special interpretation of algebraic formulas is as numbers with units.
27778 A @dfn{units expression} is a formula which is basically a number
27781 be a number; any product or quotient involving unit names is a units
27786 A unit name is a variable whose name appears in the @dfn{unit table},
27787 or a variable whose name is a prefix character like @samp{k} (for ``kilo'')
27789 A substantial table of built-in units is provided with Calc;
27793 Note that if the value part of a units expression is exactly @samp{1},
27795 formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a
27827 the operation in question is applied only to the numeric part of the
27857 approximate. If Calc is in fraction mode (@pxref{Fraction Mode}), then
27880 One special exception is that if you specify a single unit name, and
27886 The ``remainder unit'' @samp{cm} is left alone rather than being
27917 @samp{(ft+in)/hr} is first converted to @samp{ft/hr+in/hr}.
27931 The @kbd{u b} (@code{calc-base-units}) command is shorthand for
27957 will be simplified to @samp{12.345 kHz}. Autoranging is useful for
27958 some kinds of units (like @code{Hz} and @code{m}), but is probably
27966 Generally the rule of thumb is that the number will be adjusted
27969 is not possible; @samp{0.1 s^2} simplifies to @samp{100000 ms^2}.
27970 Second, the ``centi-'' prefix is allowed to form @code{cm} (centimeters),
27972 ``hecto-'' prefixes are never used. Thus the allowable interval is
27975 is also the actual name of another unit; @samp{1e-15 t} would normally
27976 be considered a ``femto-ton,'' but it is written as @samp{1000 at}
27996 prefix letters. @samp{Meg} is also accepted as a synonym for the @samp{M}
28001 The Units Table buffer, once created, is not rebuilt unless you define
28007 The @kbd{u V} (@code{calc-view-units-table}) command is like @kbd{u v} except
28008 that the cursor is not moved into the Units Table buffer. You can
28013 the actual units table is safely stored inside the Calculator.
28019 @kbd{u g in} will produce the expression @samp{2.54 cm}. This is the
28022 will report that no such unit exists, for example, because @code{km} is
28024 definition of a unit in terms of base units, it is easier to push the
28031 for the expression @samp{62 km^2 g / s^2 mol K}, the description is
28043 precise, the definition was adjusted several times, and now a meter is
28046 vacuum is exactly 299792458 m/s. Many other units have been
28048 example, is currently defined as 9192631770 periods of a certain
28059 their definitions, it is a good idea to examine Calc's definition of a
28063 note that @code{oz} is a standard ounce of mass, @code{ozt} is a Troy
28064 ounce, and @code{ozfl} is a fluid ounce.
28075 The unit @code{A} stands for amperes; the name @code{Ang} is used
28079 a typographical point, defined by @samp{72 point = 1 in}. This is
28083 There is also @code{texpt}, which stands for a printer's point as
28086 @code{texbp} (a ``big point'', equal to a standard point which is larger
28091 When Calc is using the @TeX{} or @LaTeX{} language mode (@pxref{TeX
28100 @expr{e}, Calc provides the alternate unit name @code{ech} which is
28103 The name @code{g} stands for one gram of mass; there is also @code{gf},
28105 Meanwhile, one ``@expr{g}'' of acceleration is denoted @code{ga}.
28107 The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
28129 really is unitless.)
28148 to these units. If the value on the top of the stack is a plain
28154 is stored in @code{Units}. Then @kbd{30 u 1} will create the
28160 variable has no stored value (the default), or if its value is not
28162 @kbd{s U} command is a convenient way to edit the @code{Units}
28184 unit. It is not possible to remove one of the predefined units,
28200 each other) will not be detected until the unit table is next rebuilt;
28201 @kbd{u v} is a convenient way to force this to happen.
28203 Temperature units are treated specially inside the Calculator; it is not
28214 is replaced by the new set. (@xref{General Mode Commands}, for a way to
28237 is defined to be
28240 (The factor of 10 is because a decibel, as its name implies, is
28243 the decibel.) If @math{F} is a field quantity with power
28267 quantity or the corresponding power quantity is used, the decibel
28274 is defined as
28283 (the threshold of human hearing) is
28286 which is about
28292 Nepers (named after John Napier, who is credited with inventing the
28300 is
28309 is
28324 as the default reference quantity; this is the value used in acoustics
28325 which is where decibels are commonly encountered. This default can be
28329 capital @kbd{O} prefix is used.
28401 acoustics, for example, the sound pressure level is a field quantity
28417 If the power corresponding to @math{D} dB is multiplied by a number @math{N},
28430 if a field quantity is multiplied by @math{N} the corresponding decibel level
28475 corresponds to the note @expr{C} in octave 4 and is denoted
28477 offset in cents (where a cent is a ratio of frequencies so that a
28516 @code{1}. For example, middle @var{C} is approximately
28517 @expr{261.625565302 Hz}; this frequency is often shortened to
28553 name of the variable. If you press a single digit, the value is stored
28559 The @kbd{s s} command leaves the stored value on the stack. There is
28563 If the top of stack value is an equation @samp{a = 7} or assignment
28568 a variable name at the prompt, the top-of-stack value is stored in
28569 its entirety, even if it is an equation: @samp{s s b @key{RET}}
28577 It is also possible to type an equation or assignment directly at
28580 symbol is evaluated as if by the @kbd{=} command, and that value is
28581 stored in the variable. No value is taken from the stack; @kbd{s s}
28587 digit; @kbd{s 9} is equivalent to @kbd{s s 9}, and @kbd{t 9} is
28588 equivalent to @kbd{s t 9}. (The @kbd{t} prefix is otherwise used
28644 variable, and @expr{a} is the value drawn from the stack, then regular
28651 While @kbd{I s *} might seem pointless, it is
28652 useful if matrix multiplication is involved. Actually, all the
28690 The @kbd{s m} command is a general way to adjust a variable's value
28691 using any Calc function. It is a ``mapping'' command analogous to
28694 all you do is type the Calc command key that would invoke that
28696 key to negate the contents of the variable, so @kbd{s m n} is
28704 is provided as the first argument. Thus @kbd{s m -} with @expr{a}
28707 argument instead of the first. Thus @kbd{I s m -} is also
28724 Until you store something in them, most variables are ``void,'' that is,
28734 @kbd{s r} followed by an @kbd{s t} (aside from saving keystrokes) is
28735 that the value never goes on the stack and thus is never rounded,
28736 evaluated, or simplified in any way; it is not even rounded down to the
28753 magic property is preserved, however, when a variable is copied with
28758 If one of the ``special constants'' is redefined (or undefined) so that
28764 @code{pi} will represent 3.14159@dots{} regardless of what is currently
28766 variables, @code{inf}, @code{uinf} or @code{nan}, is given a value, its
28777 is to use the @kbd{s r} (@code{calc-recall}) command. This command prompts
28779 of the specified variable, and pushes that value onto the stack. It is
28782 It is also possible to recall the value from a variable by evaluating a
28783 formula containing that variable. For example, @kbd{' a @key{RET} =} is
28784 the same as @kbd{s r a @key{RET}} except that if the variable is void, the
28789 The @kbd{r} prefix may be followed by a digit, so that @kbd{r 9} is
28802 editing buffer will start out empty. If the editing buffer is
28807 The @kbd{s e} command is especially useful for creating and editing
28922 only way to remove a saved variable is to edit your calc init file
28946 is that @kbd{s i} will store the variables in any buffer, and it also
28977 assignment: @kbd{s l b=3 @key{RET}} is the same as storing 3 on the stack
28980 The @kbd{a b} (@code{calc-substitute}) command is another way to substitute
28995 The special algebraic symbol @samp{=>} is known as the @dfn{evaluates-to
28997 other language modes like Pascal and @LaTeX{}.) This is a binary
28998 operator, that is, it has a lefthand and a righthand argument,
29001 A formula like @samp{@var{a} => @var{b}} is evaluated by Calc as
29002 follows: First, @var{a} is not simplified or modified in any
29003 way. The previous value of argument @var{b} is thrown away; the
29004 formula @var{a} is then copied and evaluated as if by the @kbd{=}
29006 and the result is installed as the new value of @var{b}.
29009 The number 17 is ignored, and the lefthand argument is left in its
29010 unevaluated form; the result is the formula @samp{2 + 3 => 5}.
29015 entry (in which case the righthand side may be omitted since it is
29023 if the @samp{=>} operator is at the top level of the formula, or
29024 if it is part of a top-level vector. In other words, pushing
29027 dynamically updated when @samp{a} is changed later because the
29028 @samp{=>} operator is buried inside a sum. However, a vector
29029 of @samp{=>} operators will be recomputed, since it is convenient
29054 All current modes apply when an @samp{=>} operator is computed,
29064 and the current mode settings, and the lefthand side is not
29071 if that stack entry is an @samp{=>} operator its righthand
29074 to that variable. But this change is temporary in the sense
29090 influence of the ``let'' is gone. The @kbd{d @key{SPC}} command
29091 (@code{calc-refresh}) is a handy way to force the @samp{=>}
29119 if GNUPLOT is available on your system. (While GNUPLOT sounds like
29120 a relative of GNU Emacs, it is actually completely unrelated.
29121 However, it is free software. It can be obtained from
29125 If you have GNUPLOT installed on your system but Calc is unable to
29150 The easiest graphics command is @kbd{g f} (@code{calc-graph-fast}).
29162 the interval (whether the interval is open or closed is ignored).
29171 The formula is plotted with this variable taking on the various ``x''
29173 computed data points. Note that if neither ``x'' nor ``y'' is a vector,
29176 or an interval if ``y'' is a formula.)
29182 If ``y'' is (or evaluates to) a formula of the form
29183 @samp{xy(@var{x}, @var{y})} then the result is a
29186 In this case the ``x'' vector or interval you specified is not directly
29187 visible in the graph. For example, if ``x'' is the interval @samp{[0..360]}
29188 and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
29198 is that the ``y'' entry can consist of a vector of numbers combined with
29201 value or the ``y'' value of a given data point is not a real number, that
29218 for the @kbd{s R} command which is another easy way to examine
29224 If the GNUPLOT output device is an X window, the window will go away.
29228 window if there is one.
29247 result is a surface plot where
29250 is the height of the point
29266 ``z'' is any formula involving two variables (not counting variables
29277 @samp{xyz(@var{x}, @var{y}, @var{z})}, then the result is a
29283 will draw a sphere. (Since the default resolution for 3D plots is
29289 It is also possible to have a function in a regular @kbd{g f} plot
29302 The @kbd{g f} command is really shorthand for the following commands:
29303 @kbd{C-u g d g a g p}. Likewise, @w{@kbd{g F}} is shorthand for
29317 in another window. This buffer is a template of the commands that will
29318 be sent to GNUPLOT when it is time to draw the graph. The first
29323 directly, but you can if you wish. The only constraint is that there
29338 itself, is what was added by @kbd{g a}.
29345 argument is equivalent to @kbd{C-u 1 g a}.)
29353 This is the only form of @kbd{g a} that creates several curves at once
29364 across this vector. The resulting vector of formulas is suitable
29371 to the graph. It is not valid to intermix 2D and 3D curves in a
29376 but the ``z'' entry is a vector of curve values. With a negative
29406 front of the list. The next-most-recent curve is thus exposed for
29432 This is to ensure quick response. You can ``refine'' a plot by giving
29440 numerix prefix argument, if any, to @kbd{g p} is effectively ignored if
29441 the current graph is three-dimensional.
29445 The @kbd{g P} (@code{calc-graph-print}) command is like @kbd{g p},
29453 Provided everything is set up properly, @kbd{g p} will plot to
29464 on and off. It is off by default; tick marks appear only at the
29473 (the box that surrounds the graph) on and off. It is on by default.
29479 on and off. The key is a chart in the corner of the graph that
29480 shows the correspondence between curves and line styles. It is
29481 off by default, and is only really useful if you have several
29488 curves where neither ``x'' nor ``y'' is specified as a vector.
29501 time. This is usually more than adequate, but there are cases where
29506 at precision @var{n} instead of 5. Since this is such a rare case,
29507 there is no keystroke-based command to set the precision.
29513 The default title is blank (no title).
29523 Curve titles appear in the key; if the key is turned off they are
29575 (@code{calc-graph-zero-y}) commands control whether a dotted line is
29606 Another way to specify curve styles is with the @code{LineStyles} and
29640 the X window system is in use (as indicated by the presence of a
29643 @code{postscript} under GNUPLOT 2.0. This is the initial default
29646 The @code{dumb} device is an interface to ``dumb terminals,'' i.e.,
29650 The graph is made the same size as the Emacs screen, which on most
29654 characters. The graph is displayed in
29657 device is present only in GNUPLOT 3.0 and later versions.
29661 characters. Also, the device name @code{big} is like @code{dumb}
29670 is initially @code{postscript}. If you don't have a PostScript
29678 @code{windows}, there is no output file and this information is not
29683 i.e., to @file{*Gnuplot Trail*}. This is the default setting.
29685 Another special output name is @code{tty}, which means that GNUPLOT
29686 is going to write graphics commands directly to its standard output,
29700 name is not @code{auto}, the file is not automatically deleted.
29705 (see @kbd{g X}) are also saved. Other graph information is @emph{not}
29725 @code{nil} if no command is necessary, or strings which can include
29736 effect unless the current device is @code{x11}.
29740 The @kbd{g X} (@code{calc-graph-geometry}) command is a similar
29742 The normal value is @code{default}, which generally means your
29746 effect if the current device is @code{windows}.
29757 the GNUPLOT command window that is displayed as in normal interactive
29776 This happens automatically when Calc thinks there is something you
29778 or @kbd{g V} when the relevant buffer is already displayed, the
29779 buffer is hidden again. (Note that on MS-Windows, the @file{*Gnuplot
29783 One reason to use @kbd{g v} is to add your own commands to the
29796 to delete a label all you need to do is delete the @samp{set label}
29803 process that is running. The next graphing command you give will
29805 the Calc window's mode line whenever a GNUPLOT process is currently
29806 running. The GNUPLOT process is automatically killed when you
29811 The @kbd{g K} (@code{calc-graph-kill}) command is like @kbd{g q}
29813 you can see the process being killed. This is better if you are
29823 In many cases Embedded mode is an easier and more natural way to
29865 of the cursor in the Calculator buffer. If the cursor is on or below
29867 Otherwise, they operate on whatever stack element the cursor is on. The
29868 text is copied into the kill ring exactly as it appears on the screen,
29875 @kbd{C-k} command. Although a whole line is always deleted, @kbd{C-k}
29890 the thing being yanked is something that was just killed from the Calculator
29891 itself, its full internal structure is yanked. For example, if you have
29904 if @samp{111} has just been killed and is yanked into Calc with a command
29909 the text is an algebraic expression), then the prefix will have no
29921 An alternative to killing and yanking stack entries is using
29922 registers in Calc. Saving stack entries in registers is like
29928 each register is indexed by a single character. To store the current
29937 It is possible to add additional stack entries to a register. The
29955 inserted into the Calculator, otherwise whatever text is in the
29956 register is reparsed and then inserted into the Calculator.
29967 @samp{[ ]} unless the text already is enclosed in vector brackets,
29978 that is grabbed is exactly the same as the text that @kbd{C-k} would
29988 reads a formula which is a product of three things: @samp{2 a b}.
30009 braces), that portion is interpreted as a vector which becomes a row
30011 is ignored.
30013 Otherwise, the entire line is interpreted as a row vector as if it
30021 line is instead interpreted as a single formula which is converted into
30023 one-column matrix. For example, suppose one line of the data is the
30025 @samp{[2 a]}, which in turn is read as a two-element vector that forms
30030 will be split up into columns of width @var{n}; each column is parsed
30036 constituent rows and columns. (If it is a
30046 The @kbd{C-x * :} (@code{calc-grab-sum-down}) command is a handy way to
30047 grab a rectangle of data and sum its columns. It is equivalent to
30063 is only one column, the result will be a vector of one number, the sum.
30070 the form of a column matrix. The statistics command @kbd{u *} is a
30083 (More specifically, this is the most recently used buffer which is displayed
30084 in a window and whose name does not begin with @samp{*}. If there is no
30085 such buffer, this is the most recently used buffer except for Calculator
30086 and Calc Trail buffers.) The number is inserted exactly as it appears and
30087 without a newline. (If line-numbering is enabled, the line number is
30088 normally not included.) The number is @emph{not} removed from the stack.
30094 that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
30109 If the editing buffer is in overwrite (as opposed to insert) mode,
30117 Finally, if the thing being yanked is a simple integer or floating-point
30125 The @kbd{C-x * y} key sequence is equivalent to @kbd{y} except that
30133 If you are using Emacs with the X window system, there is an easier
30147 new value is always pushed onto the top of the stack.
30149 The @code{xterm} program that is typically used for general-purpose
30152 Unix program. One nice feature of @code{xterm} is that a double
30182 is easier than using Calc normally, go right ahead.
30195 is equivalent to clicking the right mouse button there.
30198 Calc key sequence. This is equivalent to switching into the
30236 This is the menu that appears the first time you start Keypad mode.
30238 Above this menu is the traditional Calc stack display. On a 24-line
30244 number is pushed onto the stack as soon as you press @key{ENTER}
30261 @kbd{INV UNDO} is the ``redo'' command, and @kbd{HYP UNDO} is
30271 numeric prefix if you wish. It is also possible simply to
30272 switch into the Calc window and type commands in it; there is
30273 nothing ``magic'' about this window when Keypad mode is active.
30282 is not displayed. Obviously you don't need to learn these keys
30287 is the same as @key{1/x}.
30289 is the same as @key{SQRT}.
30291 is the same as @key{CONJ}.
30293 is the same as @key{y^x}.
30295 is the same as @kbd{INV y^x} (the @expr{x}th root of @expr{y}).
30307 is the same as @key{ABS}.
30309 is the same as @key{RND} (@code{calc-round}).
30311 is the same as @key{CLN2}.
30313 is the same as @key{FLT} (@code{calc-float}).
30315 is the same as @key{IMAG}.
30317 is the same as @key{PREC}.
30319 is the same as @key{SWAP}.
30321 is the same as @key{RLL3}.
30323 is the same as @key{OVER}.
30329 creates an interval form; this removes an integer which is one
30335 again has the same effect. This is analogous to typing @kbd{q} or
30336 hitting @kbd{C-x * c} again in the normal calculator. If Calc is
30338 command line that started Emacs), then @kbd{OFF} is replaced with
30368 number. (@xref{Random Numbers}.) @key{RAGN} is the ``random
30374 @kbd{INV FACT} is the gamma function.
30378 @key{PERM} is the number-of-permutations function, which is on the
30404 The ``difference'' function (normally on @kbd{b d}) is on @kbd{INV AND}.
30405 The ``clip'' function (normally on @w{@kbd{b c}}) is on @kbd{INV NOT}.
30415 The initial word size is 32 bits.
30437 which is replaced onto the stack. Thus the sequence
30462 @key{SUM} replaces a vector by the sum of its elements. It is
30475 @key{MAP*} multiplies two vectors elementwise. It is equivalent
30485 alphabetical order. The result is a vector of the same size as
30562 linked to the stack and this copying is taken care of automatically.
30580 Note that @kbd{C-x * e} is not to be used in the Calc stack buffer
30585 of the editing buffer. (@xref{Language Modes}.) If the current buffer is
30594 suitable language is available, Calc will continue with its current language.
30632 non-numeric character (i.e., the first character that is not a digit,
30639 Big-style formulas even if the language mode is wrong. If Calc
30641 Embedded mode. But if the current language is wrong, Calc can
30649 formula which is blank, say with the cursor on the space between
30660 the stack. No Calc stack window is created; however, Calc copies
30688 Now that Embedded mode is enabled, keys you type in this buffer
30691 This is a selection-based command for which we first need to
30699 The @kbd{C-x * o} command is a useful way to open a Calc window
30701 verifies that @samp{2 < n} is also on the Calc stack. Typing
30712 normally see the stack in Embedded mode, it is still there and
30718 window reveals that the formula @w{@samp{2 < n}} is automatically
30719 removed from the stack, but the @samp{17} is not. Entering
30722 that happens on the stack is entirely your business as far as
30723 Embedded mode is concerned.
30725 If you press @kbd{C-x * e} in the wrong place by accident, it is
30733 will not do you any good, because as far as Calc is concerned
30744 it is parsed (i.e., read) in @LaTeX{} mode. If the formula appears to
30745 be written in multi-line Big mode, it is parsed in Big mode. Otherwise,
30746 it is parsed according to the current language mode.
30751 whatever language mode is in effect.
30759 Calc's parser is unable to read certain kinds of formulas. For
30761 specify matrix display styles which the parser is unable to
30764 formula is placed in front of the fully-formatted version.
30771 character begins a comment in @TeX{} and @LaTeX{}, so if your formula is
30785 these cases it is important to use ``plain'' mode to make sure
30788 Another example where ``plain'' mode is important is if you have
30792 mode allows you to make sure that the complete number is present
30801 which is @cpi{} to the normal 12 decimal places, and then
30804 full number is still there on the Calc stack. More surprisingly,
30827 is
30831 whose value at x = 2 is
30835 and at x = 3 is
30842 The @kbd{C-x * d} (@code{calc-embedded-duplicate}) command is a
30845 mode enabled for it at the time) is copied immediately below and
30846 Embedded mode is then enabled for that copy.
30858 is
30891 and then does an algebraic entry to get the formula (which is
30892 then enabled for Embedded mode). This is just shorthand for
30895 @kbd{C-x * '} is equivalent to @kbd{C-x * f}.
30929 An embedded formula which is an assignment to a variable, as in
30942 One way to use this assigned value is simply to create an
30946 is to use @samp{=>} elsewhere:
30963 The obvious question then is, @emph{how} can one easily change the
30975 The right thing to do is first to use a selection command (@kbd{j 2}
30983 easy way to operate on assignments. It is just like @kbd{C-x * e},
30984 except that if the enabled formula is an assignment, it uses
30986 is an evaluates-to, it uses @kbd{j 1} to select the lefthand side.
30996 The formula is automatically deselected when you leave Embedded
31005 command is a convenient way to do this.
31013 Pressing @kbd{C-x * u} is much like pressing @kbd{C-x * e = C-x * e}, that
31014 is, temporarily enabling Embedded mode for the formula under the
31024 (This is useful only if you have used @kbd{m C}; see below.)
31029 @kbd{C-x * u} is also a handy way to activate a formula, such as an
31038 that Embedded mode is actually turned on, but only that the
31043 It is a good idea to type @kbd{C-x * a} right after loading a file
31046 automatically. The idea is to place near the end of your file
31092 a variable changed, and finds that the formula is no longer there
31104 nearest preceding assignment is used if there is one, otherwise the
31105 following assignment is used.
31127 stored value for the variable is used (@pxref{Storing Variables}),
31128 or, if no value is stored, the variable is left in symbolic form.
31129 Note that global stored values will be lost when the file is saved
31152 The mode settings can be changed while Calc is in embedded mode, but
31154 is ended. However, the modes saved when the mode-recording mode is
31156 (@code{calc-embedded-preserve-modes}) command is given
31157 will be preserved when embedded mode is ended.
31160 settings in Embedded formulas. It is possible to put annotations
31164 is the enabled Embedded mode formula.
31188 scan is getting too slow, or just to provide a barrier between one
31192 closest one before the formula is used. Annotations after the
31203 the easiest way to find the syntax for a given mode is to let
31213 of mode setting, the second is a name for the mode itself, and
31214 the third is the value in the form of a Lisp symbol, number,
31216 second parts are ignored. The third part is not checked to make
31217 sure the value is of a valid type or range; if you write an
31221 While Embedded mode is enabled, the word @code{Local} appears in
31222 the mode line. This is to show that mode setting commands generate
31237 is enabled in Embedded mode. The second kind will be used only
31238 when the formula is @emph{not} enabled. (Whether the formula
31239 is ``active'' or not, i.e., whether Calc has seen this formula
31240 yet, is not relevant here.)
31261 Another way that modes can get out of date is if you add a local
31264 first of the two embedded formulas is active. But the second
31284 mode (where there is no symbol like @code{Save} or @code{Local} in
31288 When Embedded mode is not enabled, mode-recording modes except
31309 how regular expressions work. Basically, a regular expression is a
31311 blank lines, @samp{$}, and @samp{$$} to be opening delimiters is
31313 regular expression is not completely plain, let's go through it
31320 The most obvious property of this regular expression is that it
31326 So the actual regular expression seen by Calc is
31330 to have special meanings. Sometimes the backslash is used to quote
31333 or @samp{?}, which means that the preceding item is optional. So
31349 is that the former expression actually ``consumes'' only one
31356 But just for your convenience, here is a list of all characters
31360 must use @code{"\\\\\\["}. An exercise for the reader is to
31367 @code{"\\'\\|\n$\\|\\$\\$?"}. This is almost the same as the
31370 of describing a blank line that is more appropriate for this
31379 The @code{calc-embedded-open-plain} variable is a string which
31381 formula when @kbd{d p} mode is turned on. Note that this is an
31384 The default string is @code{"%%% "} (note the trailing space), but may
31388 The @code{calc-embedded-close-plain} variable is a string which
31389 ends a ``plain'' formula. The default is @code{" %%%\n"}, but may be
31395 The @code{calc-embedded-open-new-formula} variable is a string
31396 which is inserted at the front of a new formula when you type
31397 @kbd{C-x * f}. Its default value is @code{"\n\n"}. If this
31398 string begins with a newline character and the @kbd{C-x * f} is
31404 The @code{calc-embedded-close-new-formula} variable is the corresponding
31405 string which is inserted at the end of a new formula. Its default
31406 value is also @code{"\n\n"}. The final newline is omitted by
31408 @kbd{C-x * f} is typed on a blank line, both a leading opening
31412 The @code{calc-embedded-announce-formula} variable is a regular
31413 expression which is sure to be followed by an embedded formula.
31420 The default pattern is @code{"%Embed\n\\(% .*\n\\)*"}, but may be
31423 lines beginning with @samp{%} and a space. This last is important to
31425 formula's opening delimiter really is sure to follow the pattern.
31428 The @code{calc-embedded-open-mode} variable is a string (not a
31431 annotation itself. But this is the string that is inserted before
31433 The default is @code{"% "}, but may be different for different major
31437 The @code{calc-embedded-close-mode} variable is a string which
31439 is simply a newline, @code{"\n"}, but may be different for different
31440 major modes. If you change this, it is a good idea still to end with a
31453 and play them back at a later time. This is just the standard Emacs
31466 results in just the same way as an internal ``rule'' is applied to
31470 @dfn{Lisp} is the programming language that Calc (and most of Emacs)
31471 is written in. If the above techniques aren't powerful enough, you
31473 can do. Lisp code is also somewhat faster than keyboard macros or
31482 command is described elsewhere; @pxref{Troubleshooting Commands}.
31483 The @kbd{Z C} (@code{calc-user-define-composition}) command is also
31501 (@code{calc-user-define}) command. Actually, it is bound to a two-key
31507 run. For example, the @code{calc-sincos} command is not normally
31540 your Calc init file; that is, the file given by the variable
31576 The easiest way to ``program'' the Emacs Calculator is to use standard
31585 When you use @kbd{X} to invoke a keyboard macro, the entire macro is
31587 display buffer is not updated during macro execution, but is instead
31649 copied verbatim into the keyboard macro. Basically, the notation is the
31650 same as is used in all of this manual's examples, except that the manual
31652 we take it for granted that it is clear we really mean
31659 It is a convenient way to define a keyboard macro that has been stored
31675 sees the @kbd{Z [}, it pops an object from the stack and, if the object is
31676 a non-zero value, continues executing keystrokes. But if the object is
31677 zero, or if it is not provably nonzero, Calc skips ahead to the matching
31686 command is skipped.
31692 suitable number is on the stack before defining the macro so that you
31700 two keystroke sequences. The general format is @kbd{@var{cond} Z [
31701 @var{then-part} Z : @var{else-part} Z ]}. If @var{cond} is true
31711 @var{part3} Z ]} will execute @var{part1} if @var{cond1} is true,
31712 otherwise it will execute @var{part2} if @var{cond2} is true, otherwise
31725 and @samp{Z]}. One side-effect of this is that if you use these
31729 is not likely to be a problem. Another side-effect is that it will
31751 the specified number of times. If the integer is zero or negative, the
31752 body is skipped altogether. For example, @kbd{1 @key{TAB} Z < 2 * Z >}
31758 Once again, the keyboard macro is executed as it is being entered.
31759 In this case it is especially important to set up reasonable initial
31762 Another approach is to enter a harmless dummy definition for the macro,
31764 another approach is to type the macro as written-out keystroke names
31772 if that object is true (a non-zero number), control jumps out of the
31774 after the @kbd{Z >}. If the object is false, the @kbd{Z /} has no
31775 effect. Thus @kbd{@var{cond} Z /} is similar to @samp{if (@var{cond}) break;}
31784 value of the counter available inside the loop. The general layout is
31794 less than) @var{final}, assuming @var{initial} is less than (greater
31795 than) @var{final}. If @var{initial} is equal to @var{final}, the body
31800 If you give a numeric prefix argument of 1 to @kbd{Z (}, the loop is
31802 is greater than @var{final} the body will not be executed at all.
31817 to beep, the keyboard macro will also be halted; this is a standard
31885 In fact, @kbd{C-u Z `} is like @kbd{Z `} except that it sets the modes
31905 @c is displayed unless @kbd{m w} (@code{calc-working}) has been used
31914 use of @kbd{$} characters, are supported. The prompt message itself is
31917 pressing the @kbd{"} key and will appear as a vector when it is put on
31918 the stack. The prompt message is only put on the stack to provide a
31944 (@code{calc-user-invocation}), that is intended to allow you to define
31948 There is only one invocation macro, so you don't need to type any
31961 do not apply. @kbd{C-x * z} is just like @kbd{C-x e}, except that it
31985 formula on the @kbd{z m} key sequence. The next prompt is for a command
31996 The third prompt is for an algebraic function name. The default is to
31998 prefix. (If this is of the form @samp{User-m}, the hyphen is removed so
32000 This is the name you will use if you want to enter your
32006 The fourth prompt is for the function's argument list. This is used to
32008 The default is a list of all variables which appear in the formula, sorted
32014 would replace the 10 and 100 on the stack with the number 210, which is
32032 The final prompt is a y-or-n question concerning what to do if symbolic
32054 an error message if the key is undefined, or if the key was not defined
32086 do is write a normal Lisp function definition, but with @code{defmath}
32095 Emacs Lisp is described in the GNU Emacs Lisp Reference Manual. This section
32103 Finally, there is a list of internal Calc functions and data structures
32122 The @code{defmath} function (actually a Lisp macro) is like @code{defun}
32124 range of Calculator data types. The prefix @samp{calcFunc-} is added
32148 The @samp{myfact} function as it is defined above has the bug that an
32150 formula @samp{a+b} is not considered to be @code{posp}. A robust
32162 If a function returns @code{nil}, it is left unsimplified by the Calculator
32173 @code{logandc2}, @code{lognot}. Also, @code{~=} is an abbreviation for
32174 @code{math-nearly-equal}, which is useful in implementing Taylor series.
32177 @samp{calcFunc-@var{func}} exists it is used, otherwise if a function by the
32178 name @samp{math-@var{func}} exists it is used, otherwise if @var{func} itself
32179 is defined as a function it is used, otherwise @samp{calcFunc-@var{func}} is
32180 used on the assumption that this is a to-be-defined math function. Also, if
32181 the function name is quoted as in @samp{('integerp a)} the function name is
32188 @samp{foo} is the same as a reference to @samp{var-foo}.
32196 element is the symbol @code{vec}; thus, @samp{(elt v 2)} yields
32202 Lisp @code{setf} function. (The name @code{setf} is recognized as
32205 in which case the effect is to store into the specified
32210 A @code{for} looping construct is available. For example,
32212 binding of @expr{i} from zero to 10. This is like a @code{let}
32213 form in that @expr{i} is temporarily bound to the loop count
32219 that each element of the header is a list of three or four
32226 @expr{v} in turn. The purpose of @code{cdr} here is to skip over
32232 value, as in @samp{(break x)}, this value is returned by the
32243 directly into a @code{defmath} definition. This is because the Lisp
32262 Note the use of @code{numberp} as a guard to ensure that the argument is
32272 A good place to put your @code{defmath} commands is your Calc init file
32297 the property list for the symbol @code{calc-define} is checked and the
32303 The net effect is that you can put the above code in your @file{.emacs}
32304 file and it will not be executed until Calc is loaded. Or, you can put
32306 after Calc itself is loaded.
32315 call your function, even if the file defining the property is loaded
32316 after Calc is loaded. But if the property defines commands or key
32328 at the end of your file. The @code{calc-check-defines} function is what
32330 has the advantage that it is quietly ignored if @code{calc-check-defines}
32331 is not yet defined because Calc has not yet been loaded.
32355 "Increase precision by DELTA." ; This is the "documentation string"
32378 @code{+} even when the intent is to operate on native Lisp integers.
32410 after this command completes. This is set by routines like
32433 Do not move trail pointer to end of trail when something is recorded
32444 @kbd{Y ?} is defined; it takes help messages from a list of strings
32450 others, it is best to minimize the number of @kbd{Y}-key sequences
32456 Users may wish to install several Calc enhancements, and it is possible
32460 value is initially @code{"P"}, but a user can change this variable
32463 Here is a complete file, @file{inc-prec.el}, which makes a @kbd{Y P I}
32505 on the stack, a special form of @code{interactive} clause is used.
32512 where @var{num} is an integer, and @var{tag} is a string. The effect is
32517 parameters is valid.
32524 or use @code{nil} as a tag, the result is not recorded in the trail.
32538 is a version of the factorial function shown previously which can be used
32557 The @code{calc-slow-wrapper} function is a version of @code{calc-wrapper}
32565 calling @code{calc-normalize}. If its argument is zero it returns an
32570 @var{tag} as described above, plus a third argument which is either a
32573 of values from the stack. If @var{tag} is non-@code{nil}, the values
32584 @var{tag}. Currently the only Emacs code supported is @samp{"p"}, as in
32596 The other code string allowed is @samp{"m"} (unrelated to the usual @samp{"m"}
32600 arguments to be used when no prefix is supplied.
32607 an @dfn{argument qualifier}. Thus the general form of a definition is:
32617 where each @var{param} is either a symbol or a list of the form
32629 (This is rarely needed since the Calculator itself will never call your
32630 function with an incomplete argument. But there is nothing stopping your
32635 The argument must be an integer. If it is an integer-valued float
32647 argument is converted into Lisp-integer form if necessary.
32651 The argument is converted to floating-point format if it is a number or
32652 vector. If it is a formula it is left alone. (The argument is never
32656 The argument must satisfy predicate @var{pred}, which is one of the
32728 When this is expanded by @code{defmath}, it will become the following
32763 (for ((n 3 100 2)) ; Upper limit of 100 is a good precaution.
32768 (if (~= newsum sum) ; If newsum is "nearly equal to" sum,
32777 is carried out with two extra digits of precision to guard against cumulative
32805 where @code{mysin-complex} is an appropriate function to handle complex
32806 numbers, @code{mysin-series} is the routine to compute the sine Taylor
32807 series as before, and @code{mycos-raw} is a function analogous to
32810 The strategy is to ensure that @expr{x} is nonnegative before calling
32813 test, and particularly the first comparison against 7, is designed so
32821 If a program is being written for general use, it is important to code
32824 a large argument, a simpler program like the first one shown is fine.
32845 Since @code{calc-eval} is on the list of recommended @code{autoload}
32874 (assuming Fraction mode is not in effect). Note the @code{nil}
32887 string. Note that @samp{1 / 0} is @emph{not} an error by Calc's
32888 standards; it simply returns the string @code{"1 / 0"} which is the
32898 are returned as strings instead of lists. The character position is
32913 Sometimes it is preferable to treat @samp{1 / 0} as an error
32917 reported is the first @code{calc-why} message if there is one,
32920 A result is ``constant'' if it is a number, vector, or other
32922 is a vector, the components must themselves be constants.
32932 If the first argument to @code{calc-eval} is a list whose first
32933 element is a formula string, then @code{calc-eval} sets all the
32934 various Calc modes to their default values while the formula is
32935 evaluated and formatted. For example, the precision is set to 12
32936 digits, digit grouping is turned off, and the Normal language
32937 mode is used.
32948 original values when @code{calc-eval} is done.
32952 using default mode settings except that the precision is 8 instead
32962 checks if the number in string @expr{a} is less than the one in
32976 Normally all input and output for @code{calc-eval} is done with strings.
32978 in place of @samp{(+ a b)}, but this is very inefficient since the
32982 If the separator is the symbol @code{raw}, the result will be returned
32988 There is also a @code{rawnum} symbol, which is a combination of
32990 an error if that object is not a constant).
32994 arguments. Thus @samp{(calc-eval "$+$$" 'raw a b)} is an
32999 In particular, note that a plain Lisp integer is acceptable to Calc
33005 It is an error if the input expression evaluates to a list of
33006 values. The separator symbol @code{list} is like @code{raw}
33009 Note that a Lisp string is not a valid Calc object, nor is a list
33021 If the separator symbol is @code{pred}, the result of the formula is
33023 @code{nil}, respectively. A value is considered ``true'' if it is a
33024 non-zero number, or false if it is zero or if it is not a number.
33027 one value is less than another.
33029 As usual, it is also possible for @code{calc-eval} to return one of
33046 if 4 is stored in Calc variable @code{a} (i.e., in Lisp variable
33052 corresponding Lisp variable. (This is obtained by prepending
33070 If the separator symbol is @code{push}, the formula argument is
33072 result is pushed onto the Calc stack. The return value is @code{nil}
33073 (unless there is an error from evaluating the formula, in which
33077 If the separator symbol is @code{pop}, the first argument to
33081 is the number of elements remaining in the stack after popping;
33082 @samp{(calc-eval 0 'pop)} is a good way to measure the size of
33085 If the separator symbol is @code{top}, the first argument to
33087 stack level is formatted as a string and returned. Thus
33089 integer is out of range, @code{nil} is returned.
33091 The separator symbol @code{rawtop} is just like @code{top} except
33092 that the stack entry is returned as a raw Calc object instead of
33099 instead of current display modes, except that the radix is
33102 It is, of course, polite to put the Calc stack back the way you
33103 found it when you are done, unless the user of your program is
33118 If the separator symbol is @code{macro}, the first argument must be a
33123 with the sum of those numbers. Note that @samp{\r} is the Lisp
33126 If your keyboard macro wishes to pop the stack, @samp{\C-d} is
33134 that argument as a tag string. Normally the Trail is unaffected.
33136 The return value in this case is always @code{nil}.
33146 Finally, if the separator symbol is @code{eval}, then the Lisp
33147 @code{eval} function is called on the first argument, which must
33149 quote the expression so that it is not evaluated until inside
33152 The difference from plain @code{eval} is that @code{calc-eval}
33158 This is evaluating a call to the function that is normally invoked
33162 automatically if not invoked from there, so the above call is
33165 your original buffer when it is done.
33170 The result of @code{calc-eval} in this usage is just the result
33182 Here is a sample Emacs command that uses @code{calc-eval}. Suppose
33187 command to change ``98.6 F'' to ``37 C''. Or, if the temperature is
33243 special, check carefully to make sure each function you are using is
33264 Integers are stored as standard Lisp integers. This is the only
33265 storage format for Calc data objects which is not a Lisp list.
33268 where @var{n} is an integer numerator, @var{d} is an
33270 prime. Note that fractions where @var{d} is one are automatically converted
33271 to plain integers by all math routines; fractions where @var{d} is negative
33275 @var{exp})}, where @var{mant} (the ``mantissa'') is an integer less than
33277 precision), and @var{exp} (the ``exponent'') is an integer. The value of
33278 the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number
33279 @mathit{-3.14} is stored as @samp{(float -314 -2) = -314*10^-2}. Other constraints
33280 are that the number 0.0 is always stored as @samp{(float 0 0)}, and,
33281 except for the 0.0 case, the rightmost base-10 digit of @var{mant} is
33282 always nonzero. (If the rightmost digit is zero, the number is
33287 integers, fractions, or floats. The value is @samp{@var{re} + @var{im}i}.
33288 The @var{im} part is nonzero; complex numbers with zero imaginary
33292 @var{theta})}, where @var{r} is a positive real value and @var{theta}
33293 is a real value or HMS form representing an angle. This angle is
33296 If the angle is 0 the value is converted to a real number automatically.
33297 (If the angle is 180 degrees, the value is usually also converted to a
33301 @var{s})}, where @var{h} is an integer or an integer-valued float (i.e.,
33302 a float with @samp{@var{exp} >= 0}), @var{m} is an integer or integer-valued
33303 float in the range @w{@samp{[0 ..@: 60)}}, and @var{s} is any real number
33306 Date forms are stored as @samp{(date @var{n})}, where @var{n} is
33308 January 1, 1 AD@. If @var{n} is an integer, this is a pure date
33309 form. If @var{n} is a fraction or float, this is a date/time form.
33311 Modulo forms are stored as @samp{(mod @var{n} @var{m})}, where @var{m} is a
33312 positive real number or HMS form, and @var{n} is a real number or HMS
33316 is the mean value and @var{sigma} is the standard deviation. Each
33317 component is either a number, an HMS form, or a symbolic object
33318 (a variable or function call). If @var{sigma} is zero, the value is
33319 converted to a plain real number. If @var{sigma} is negative or
33320 complex, it is automatically normalized to be a positive real.
33323 where @var{mask} is one of the integers 0, 1, 2, or 3, and @var{lo} and
33325 is a binary integer where 1 represents the fact that the interval is
33326 closed on the high end, and 2 represents the fact that it is closed on
33328 @w{@samp{(intv 3 @var{x} @var{x})}} is converted to the plain number @var{x};
33330 represent empty intervals. If @var{hi} is less than @var{lo}, the interval
33331 is converted to a standard empty interval by replacing @var{hi} with @var{lo}.
33334 is the first element of the vector, @var{v2} is the second, and so on.
33335 An empty vector is stored as @samp{(vec)}. A matrix is simply a vector
33337 Calc vectors are unrelated to the Emacs Lisp ``vector'' type, which is
33341 @var{name} is a Lisp symbol whose print name is used as the visible name
33342 of the variable, and @var{sym} is a Lisp symbol in which the variable's
33343 value is actually stored. Thus, @samp{(var pi var-pi)} represents the
33344 special constant @samp{pi}. Almost always, the form is @samp{(var
33346 signs (which are converted to hyphens internally), the form is
33347 @samp{(var @var{u} @var{v})}, where @var{u} is a symbol whose name
33348 contains @code{#} characters, and @var{v} is a symbol that contains
33349 @code{-} characters instead. The value of a variable is the Calc
33351 value cell is void or if it contains @code{nil}, the variable has no
33353 @var{value})} stored in their value cell, where @var{value} is a formula
33354 which is evaluated when the constant's value is requested. Variables
33357 cell contains a string, it is parsed to get the variable's value when
33358 the variable is used.
33360 A Lisp list with any other symbol as the first element is a function call.
33363 of the form @samp{(@var{op} @var{lhs} @var{rhs})} where @var{lhs} is the
33364 sub-formula on the lefthand side and @var{rhs} is the sub-formula on the
33365 right. The symbol @code{neg} represents unary negation; this list is always
33368 @var{func} is in general always of the form @samp{calcFunc-@var{name}}.
33370 for evaluating a call to @var{func}. This function is passed the remaining
33375 wish to return multiple values. (The latter case is allowed only for
33376 functions which are the outer-level call in an expression whose value is
33377 about to be pushed on the stack; this feature is considered obsolete
33378 and is not used by any built-in Calc functions.)
33385 commands. Note that this list is not exhaustive! If there is an
33390 Set the command flag @var{flag}. This is generally a Lisp symbol, but
33391 may in fact be anything. The effect is to add @var{flag} to the list
33392 stored in the variable @code{calc-command-flags}, unless it is already
33408 the Calc variable @var{var} (a string which is the name of the symbol that
33413 @var{args} @dots{})} and, if the undo is later redone, calling
33418 Record the error or warning message @var{msg}, which is normally a string.
33420 if the message string begins with a @samp{*}, it is considered important
33425 some sort. If @var{msg} is a symbol, it is the name of a Calc predicate
33427 satisfy; it is expanded to a suitable string such as ``Expected an
33432 @defun calc-is-inverse
33433 This predicate returns true if the current command is inverse,
33437 @defun calc-is-hyperbolic
33438 This predicate is the analogous function for the @kbd{H} key.
33450 @var{n}. If @var{n} is omitted it defaults to 1, so that the elements
33451 are pushed at the top of the stack. If @var{n} is greater than 1, the
33456 is an empty list, nothing happens.
33467 stack. If @var{m} is omitted it defaults to 1, so that the elements are
33468 taken from the top of the stack. If @var{n} is omitted, it also
33470 one-element list) is returned. If @var{m} is greater than 1, the
33473 range, the command is aborted with a suitable error message. If @var{n}
33474 is zero, the function returns an empty list. The stack elements are not
33481 which selects other behaviors. If it is the symbol @code{t}, then
33483 ``invalid operation on selections'' error. If it is the symbol @code{full},
33484 the whole stack entry is always returned regardless of selections.
33485 If it is the symbol @code{sel}, the selected portion is always returned,
33486 or @code{nil} if there is no selection. (This mode ignores the @kbd{j e}
33487 command.) If the symbol is @code{entry}, the complete stack entry in
33488 list form is returned; the first element of this list will be the whole
33495 value of @code{calc-pop-stack} is uninteresting.
33506 are a list of strings or Calc objects. The @var{tag} is the four-character
33507 tag string to identify the values. If @var{tag} is omitted, a blank tag
33521 This function is identical to @code{calc-top-list}, except that it calls
33533 This function is a convenient form of @code{calc-top-list-n} in which only
33534 a single element of the stack is taken and returned, rather than a list
33539 This function is a convenient interface to most of the above functions.
33542 stack entries are replaced by the normalized objects. If @var{tag} is
33553 this function takes one of two courses of action. If @var{n} is
33555 @var{vals} is spliced into the corresponding selection; this is what
33558 element but @var{n} is greater than one, there must be only one
33560 @var{vals} is spliced into that selection. This is what happens when
33562 combination of @var{n} and @var{vals} is an error when selections
33569 argument @var{arg} is @code{nil}, this uses @code{calc-enter-result}
33583 arguments specify the behavior when the prefix argument is zero or
33584 one, respectively. If the prefix is zero, the value @var{ident}
33585 is pushed onto the stack, if specified, otherwise an error message
33586 is displayed. If the prefix is one, the unary function @var{unary}
33587 is applied to the top stack element, or, if @var{unary} is not
33588 specified, nothing happens. When the argument is two or more,
33589 the binary function @var{func} is reduced across the top @var{arg}
33590 stack elements; when the argument is negative, the function is
33602 Move the point to the @var{n}th stack entry. If @var{n} is zero, this
33603 will be the @samp{.} line. If @var{n} is from 1 to the current stack size,
33611 entry and the bottom of the buffer. If @var{n} is zero, this
33614 be equal @var{n}+1 as long as @var{n} is in range. (Note that in Big
33624 is suppressed, but a flag is set so that the entire stack will be refreshed
33632 The functions described here are predicates, that is, they return a
33640 Returns true if @var{x} is numerically zero, in any of the Calc data
33648 Returns true if @var{x} is negative. This accepts negative real numbers
33656 Returns true if @var{x} is positive (and non-zero). For complex
33661 Returns true if @var{x} is ``negative-looking.'' This returns true if
33662 @var{x} is a negative number, or a formula with a leading minus sign
33663 such as @samp{-a/b}. In other words, this is an object which can be
33668 Returns true if @var{x} is an integer of any size.
33672 Returns true if @var{x} is a native Lisp fixnum.
33676 Returns true if @var{x} is a nonnegative integer of any size.
33680 Returns true if @var{x} is a nonnegative Lisp fixnum.
33684 Returns true if @var{x} is numerically an integer, i.e., either a
33690 Returns true if @var{x} is numerically, but not literally, an integer.
33691 A value is @code{num-integerp} if it is @code{integerp} or
33692 @code{messy-integerp} (but it is never both at once).
33696 Returns true if @var{x} is numerically a nonnegative integer.
33700 Returns true if @var{x} is an even integer.
33704 Returns true if @var{x} is an even integer, or a formula with a leading
33705 multiplicative coefficient which is an even integer.
33709 Returns true if @var{x} is an odd integer.
33713 Returns true if @var{x} is a rational number, i.e., an integer or a
33718 Returns true if @var{x} is a real number, i.e., an integer, fraction,
33723 Returns true if @var{x} is a real number or HMS form.
33727 Returns true if @var{x} is a float, or a complex number, error form,
33729 is a float.
33733 Returns true if @var{x} is a rectangular or polar complex number
33738 Returns true if @var{x} is a rectangular complex number.
33742 Returns true if @var{x} is a polar complex number.
33746 Returns true if @var{x} is a real number or a complex number.
33750 Returns true if @var{x} is a real or complex number or an HMS form.
33754 Returns true if @var{x} is a vector (this simply checks if its argument
33755 is a list whose first element is the symbol @code{vec}).
33759 Returns true if @var{x} is a number or vector.
33763 Returns true if @var{x} is a matrix, i.e., a vector of one or more vectors,
33768 Returns true if @var{x} is a square matrix.
33772 Returns true if @var{x} is any numeric Calc object, including real and
33779 Returns true if @var{x} is an object or a vector. This also accepts
33785 Returns true if @var{x} is a ``primitive'' or ``atomic'' Calc object,
33792 Returns true if @var{x} is constant, i.e., a real or complex number,
33798 Returns true if @var{x} is numerically less than @var{y}. Returns false
33799 if @var{x} is greater than or equal to @var{y}, or if the order is
33801 by checking whether @samp{@var{x} - @var{y}} is @code{negp}. In
33813 function is used by the @kbd{V S} vector-sorting command, and also
33820 This is the standard Lisp @code{equal} predicate; it returns true if
33821 @var{x} and @var{y} are structurally identical. This is the usual way
33828 they are @code{equal}, or because their difference is @code{zerop}. In
33835 is an integer which is not a multiple of 10. This will automatically be
33844 precision is 6 (since they differ by 7 units), but not if the current
33845 precision is 7 (since they differ by 70 units). Most functions which
33850 lost when the result is rounded back down to the current precision.
33856 Returns true if @var{x} is nearly zero, compared to @var{y}. This
33864 @defun is-true x
33866 Calc, not Lisp, terms. It tests if @var{x} is a non-zero number
33873 Lisp error which @code{normalize} will trap. The net effect is that the
33878 If Symbolic mode is enabled, this will signal an error that causes
33904 this means @code{calc-sqrt} is an interactive stack-based square-root
33906 is the actual Lisp function for taking square roots.
33921 If a function call fails, because the function is void or has the wrong
33926 If the current simplification mode is ``none'' or ``numeric arguments
33938 then use @code{normalize} to simplify the result. This is what happens
33944 digits. This is a macro which expands to
33954 is important because some arithmetic operations assume a number's
33959 Build a fraction @samp{@var{n}:@var{d}}. This is equivalent to calling
33967 if @var{exp} is out of range.
33972 If @var{sigma} is zero, the result is the number @var{x} directly.
33973 If @var{sigma} is negative or complex, its absolute value is used.
33974 If @var{x} or @var{sigma} is not a valid type of object for use in
33979 Build an interval form out of @var{mask} (which is assumed to be an
33981 @var{lo} is greater than @var{hi}, an empty interval form is returned.
33982 This calls @code{reject-arg} if @var{lo} or @var{hi} is unsuitable.
33987 @var{lo} is less than @var{hi} they are simply exchanged, and the
33994 is not a real number or HMS form the result will be a formula which
33995 is a call to @code{makemod}, the algebraic version of this function.
34002 modulo forms are recursively floated. If the argument is a variable
34009 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is
34015 @samp{ceil(log10(@var{n}))}, but much more efficient. Zero is
34031 If @var{n} is outside the permissible range for Lisp fixnums (usually
34032 62 binary bits) the result is undefined.
34041 and discard the remainder. If @var{x} or @var{y} is negative, the
34042 direction of rounding is undefined.
34048 @samp{floor(@var{x}/@var{y})}. Thus the result is well-defined but
34055 integer arguments and is not well-defined for negative arguments.
34061 @code{car} is @samp{(quotient @var{x} @var{y})} and whose @code{cdr}
34062 is @samp{(imod @var{x} @var{y})}.
34073 example, for a rectangular complex number the result is the sum of
34102 if @var{initial} is non-@code{nil} it must be a @samp{(float @dots{})}
34104 is called when the cache is empty or does not have enough digits to
34105 satisfy the current precision, the Lisp expression @var{form} is evaluated
34107 two least significant digits is stored in the cache. For example,
34116 If the current angular mode is Degrees or HMS, this function returns the
34126 particular @var{n} is expensive.
34131 is a power of two. If @var{n} is not a power of two, this function will
34137 there is no solution, or if any of the arguments are not integers.
34147 Compute the integer square root of @var{n}. This is the square root
34149 If @var{n} is itself an integer, the computation is especially efficient.
34153 Convert the argument @var{a} into an HMS form. If @var{ang} is specified,
34154 it is the angular mode in which to interpret @var{a}, either @code{deg}
34155 or @code{rad}. Otherwise, the current angular mode is used. If @var{a}
34156 is already an HMS form it is returned as-is.
34160 Convert the HMS form @var{a} into a real number. If @var{ang} is specified,
34161 it is the angular mode in which to express the result, otherwise the
34162 current angular mode is used. If @var{a} is already a real number, it
34163 is returned as-is.
34173 If @var{a} is a formula, this returns the formula @samp{deg(@var{a})}.
34200 Determine whether the integer @var{n} is prime. Return a list which has
34201 one of these forms: @samp{(nil @var{f})} means the number is non-prime
34204 @samp{(nil unknown)} means it is definitely non-prime but no factors
34206 test had to be used; @samp{(t)} means the number is definitely prime;
34208 iterations, is @var{p} percent sure that the number is prime. The
34209 @var{iters} parameter is the number of Fermat iterations to use, in the
34210 case that this is necessary. If @code{prime-test} returns ``maybe,''
34216 If @var{f} is a floating-point number which can be represented exactly
34218 For example, 0.75 would be converted to 3:4. This function is very
34229 If @var{n} is an integer or integer-valued float, this function
34230 returns zero. If @var{n} is a half-integer (i.e., an integer plus
34231 @mathit{1:2} or 0.5), it returns 2. If @var{n} is a quarter-integer,
34232 it returns 1 or 3. If @var{n} is anything else, this function
34244 Do a vector concatenation; this operation is written @samp{@var{x} | @var{y}}
34249 Return the length of vector @var{v}. If @var{v} is not a vector, the
34250 result is zero. If @var{v} is a matrix, this returns the number of
34255 Determine the dimensions of vector or matrix @var{m}. If @var{m} is not
34256 a vector, the result is an empty list. If @var{m} is a plain vector
34257 but not a matrix, the result is a one-element list containing the length
34258 of the vector. If @var{m} is a matrix with @var{r} rows and @var{c} columns,
34259 the result is the list @samp{(@var{r} @var{c})}. Higher-order tensors
34261 @samp{[[1, 2, 3], [4, 5]]} is a vector of vectors not all the same size,
34262 and is treated by this and other Calc routines as a plain vector of two
34269 form; this is really just a special case of @code{reject-arg}.
34285 If @var{v} is a plain vector, convert it into a row matrix, i.e.,
34286 a matrix whose single row is @var{v}. If @var{v} is already a matrix,
34291 If @var{v} is a plain vector, convert it into a column matrix, i.e., a
34292 matrix with each element of @var{v} as a separate row. If @var{v} is
34304 If @var{a} and @var{b} are vectors of equal length, the result is a
34307 @var{b} is a scalar, it is matched with each value of the other vector.
34316 @var{v} is @samp{[10, 20, 30, 40]}, this calls @samp{(f (f (f 10 20) 30) 40)}.
34317 If @var{v} is a matrix, this reduces over the rows of @var{v}.
34322 example, if @var{m} is @samp{[[1, 2], [3, 4], [5, 6]]}, the result
34323 is a vector of the two elements @samp{(f (f 1 3) 5)} and @samp{(f (f 2 4) 6)}.
34327 Return the @var{n}th row of matrix @var{m}. This is equivalent to
34352 if @var{v} is @samp{[[1, 2, 3], [4, 5]]} the result is @samp{[1, 2, 3, 4, 5]}.
34356 If @var{m} is a matrix, return a copy of @var{m}. This maps
34360 the structure of the matrix will be @code{eq}. If @var{m} is a plain
34361 vector, this is the same as @code{copy-sequence}.
34368 matrix. The return value is @var{m}, i.e., @samp{(eq (swap-rows m 1 2) m)}
34369 is true, with the side effect of exchanging the first two rows of
34381 Prepare a stack entry for selection operations. If @var{num} is
34382 omitted, the stack entry containing the cursor is used; otherwise,
34383 it is the number of the stack entry to use. This function stores
34406 is involved in a computation, @code{calc-normalize} will replace
34412 formula is a unique atom, using the @samp{(cplx @var{n} 0)} trick
34420 called already. If the cursor is not actually on any part of the
34428 The stack element's appearance in the Calc buffer is adjusted
34433 Return the @var{n}th sub-formula of @var{expr}. This function is used
34436 is @samp{((a + b) - c) + d}, calling @code{calc-find-nth-part} with
34442 @var{part}. If @var{expr} is @samp{a*b + (c+1)*d} and @var{part}
34443 is @code{eq} to the @samp{c+1} term of @var{expr}, then this function
34446 @var{part} is @code{eq} to @var{expr}, the function returns @code{t}.
34451 This is the same as @code{calc-find-parent-formula}, except that
34470 If @var{part} is not a sub-formula of @var{expr}, it returns @code{nil}.
34471 If @var{part} is @code{eq} to @var{expr}, it returns @code{t}. This
34477 sub-formula that is @code{eq} to @var{old} replaced by @var{new}.
34485 More precisely, here is what @code{simplify} does: The expression is
34488 the expression is traversed in a depth-first, bottom-up fashion; at
34491 traversed in this way, it is compared with the original formula (from
34493 the entire procedure is repeated (starting with @code{normalize})
34503 to @samp{x}, which is only valid when @var{x} is positive.) This is
34517 Register a new simplification rule; this is normally called as a top-level
34518 form, like @code{defun} or @code{defmath}. If @var{funcs} is a symbol
34519 (like @code{+} or @code{calcFunc-sqrt}), this simplification rule is
34522 functions on the list. The @var{body} is written like the body of a
34524 executed with @code{expr} bound to a formula which is a call to one of
34526 if it returns a result @code{equal} to the original @code{expr}, it is
34528 If the function body returns something different, that new formula is
34537 Note that, since @code{defmath} is not being used here, @var{body} must
34544 list is consed up when this happens, this means that the rule's body is
34545 allowed to rearrange the function's arguments destructively if that is
34546 convenient. Here is a typical example of a simplification rule:
34559 This is really a pair of rules written with one @code{math-defsimplify}
34561 @samp{-arcsinh(x)}, and the second, which is safe only for real @samp{x},
34566 Check @var{expr} to see if it is a sum of terms all multiplied by the
34569 3 is a common factor of all the terms.
34573 Assuming @var{expr} is a sum with @var{factor} as a common factor,
34574 divide each term of the sum by @var{factor}. This is done by
34576 it is being used by a simplification rule (where such things are
34594 rational numbers. This is the fraction composed of the GCD of the
34596 It is used by @code{common-constant-factor}. Note that the standard
34603 argument. If this returns an expression which is not @code{equal} to
34605 @var{expr} with no changes. Then, if @var{expr} is a function call,
34608 is returned by @code{map-tree}. Note that, unlike simplification rules,
34610 @var{expr}. If a third argument @var{many} is provided, it is an
34612 default, as described above, is infinitely many times.
34617 be a formula that is either a vector or a variable name. If the latter,
34629 the expression. The @var{heads} argument is optional; if is given,
34643 This is an all-in-one rewrite function. It compiles the rule set
34652 of all elements of @var{vec} which do (or don't, if @var{not-flag} is
34658 (which may actually be any sub-expression). If @var{value} is specified,
34659 the derivative is evaluated at the value of @var{var}; otherwise, the
34660 derivative is left in terms of @var{var}. If the expression contains
34661 functions for which no derivative formula is known, new derivative
34663 However, if @var{symb} is non-@code{nil}, the presence of nondifferentiable
34671 should be a Lisp function; it is called with the same arguments as the
34672 original function call that is being differentiated. It should return
34674 is defined by
34691 Compute the total derivative of @var{expr}. This is the same as
34703 this macro is very similar in format to @code{math-defsimplify}.
34704 The main difference is that here @var{body} is the body of a function
34705 with a single argument @code{u} which is bound to the argument to the
34707 variable of integration is available as @code{math-integ-var}. If
34734 This is exactly analogous to @code{math-defintegral}, except that @var{body}
34735 is written as the body of a function with two arguments, @var{u} and
34744 the return value is a formula which does not contain @var{var}; this is
34747 If @var{full} is non-@code{nil}, a full solution including dummy signs
34765 typically be an equation or inequality. (If it is not, it will be
34781 @code{calc-find-sub-formula}. The key difference is that
34807 to the dummy argument variables, so that the effect is always to return
34812 This is like @code{expr-subst}, except that @var{old} and @var{new}
34814 list is shorter than the other, trailing elements of the longer list
34825 Returns the ``height'' of @var{expr}, which is the deepest level to
34831 Check if @var{expr} is a polynomial in variable (or sub-expression)
34832 @var{var}. If so, return the degree of the polynomial, that is, the
34838 @var{var} does not occur in @var{expr}, then @var{expr} is considered
34842 @defun is-polynomial expr var degree loose
34843 Check if @var{expr} is a polynomial in variable or sub-expression
34849 be non-zero, with the special exception that if @var{expr} is the
34851 if @var{expr} is not a polynomial in @var{var}. If @var{degree} is
34853 value. This is a good precaution because otherwise an input of
34855 @var{loose} is non-@code{nil}, then a looser definition of a polynomial
34856 is used in which coefficients are no longer required not to depend on
34858 themselves. For example, @samp{sin(x) x^2 + cos(x)} is a loose
34865 Check if @var{expr} is a polynomial in any variable that occurs in it;
34866 if so, return that variable. (If @var{expr} is a multivariate polynomial,
34867 this chooses one variable arbitrarily.) If @var{pred} is specified, it should
34868 be a Lisp function which is called as @samp{(@var{pred} @var{subexpr})},
34870 the original @var{expr}) is a suitable polynomial in @var{subexpr}.
34874 is found.
34884 @code{is-polynomial}) in a linear combination with coefficient expressions
34885 @var{ac} and @var{bc}. The result is a (not necessarily simplified)
34897 (@code{calc-collect}) command uses @code{is-polynomial} to turn an
34903 Check if @var{var} is a variable which can be interpreted as a unit
34905 will be a list whose first element is the unit name (not counting
34906 prefix characters) as a symbol and whose second element is the
34909 is not a variable or is not a unit name, return @code{nil}.
34914 interpreted as units. If @var{sub-exprs} is @code{t}, the entire
34915 expression is searched. If @var{sub-exprs} is @code{nil}, this
34916 checks whether @var{expr} is directly a units expression.
34928 is @code{nil}, use Calc's native base units. Otherwise, @var{which}
34929 can specify a units system, which is a list of two-element lists,
34930 where the first element is a Calc base symbol name and the second
34931 is an expression to substitute for it.
34936 This expression is generally normalized before use.
34952 This is the simplest interface to the Calculator from another Lisp program.
34965 @samp{(error @var{pos} @var{msg})} where @var{pos} is an integer index
34966 into @var{str} of the general location of the error, and @var{msg} is
34973 shown above is returned instead.
34979 is a list of Calc formulas; there will be more than one if the user
34980 entered a list of values separated by commas. The result is @code{nil}
34981 if the user presses Return with a blank line. If @var{initial} is
34982 given, it is a string which the minibuffer will initially contain.
34983 If @var{prompt} is given, it is the prompt string to use; the default
34984 is ``Algebraic:''. If @var{no-norm} is @code{t}, the formulas will
35003 This is a simple format designed
35004 mostly to guarantee the string is of a form that can be re-parsed by
35007 result will be re-readable. The @var{prec} parameter is normally 0; if
35009 surrounded by parentheses unless it is a plain number or variable name.
35013 This is like @code{format-flat-expr} (with @var{prec} equal to 0),
35017 command uses this when only one stack entry is being edited.
35026 parameter, if given, is the target window size for which to format
35027 the expressions. If @var{w} is omitted, the width of the Calculator
35028 window is used.
35037 whose value is a Lisp function that takes @var{a} and @var{prec} as
35038 arguments and returns a composition. Here @var{lang} is a language
35043 or if the function returns @code{nil}, the function is written in the
35050 newline characters. The target window size is given by @var{w}.
35064 Compute the portion of the height of composition @var{c} which is on or
35069 Compute the portion of the height of composition @var{c} which is below
35074 If composition @var{c} is a ``flat'' composition, return the first
35080 If composition @var{c} is a ``flat'' composition, return the last
35088 @comment (This section is currently unfinished.)
35102 This hook is called as the last step in a @kbd{M-x calc} command.
35109 This hook is called when the Calc buffer is being created. Usually
35110 this will only happen once per Emacs session. The hook is called
35120 This hook is called when the Calc Trail buffer is being created.
35121 It is called as the very last step of setting up the Trail buffer.
35127 This hook is called by @code{calc-quit}, generally because the user
35129 be the current buffer. The hook is called as the very first
35130 step, before the Calc window is destroyed.
35134 If this hook is non-@code{nil}, it is called to create the Calc window.
35137 hook is called.) If the hook is not defined, Calc will
35143 If this hook is non-@code{nil}, it is called to create the Calc Trail
35150 This hook is called the first time that Embedded mode is entered.
35154 This hook is called each time that Embedded mode is entered in a
35159 This hook is called each time that Embedded mode is enabled for a
35164 This hook is called by @code{calc-edit} (and the other ``edit''
35165 commands) when the temporary editing buffer is being created.
35173 This hook is called by the @code{calc-save-modes} command,
35176 message is inserted.
35180 This hook is called after @kbd{C-x * 0} (@code{calc-reset}) has
35189 by a space. The variable is @code{nil} by default.
35193 This is the keymap that is used by Calc mode. The best time
35194 to adjust it is probably in a @code{calc-mode-hook}. If the
35197 which is a command that loads the extensions package and
35204 This is the keymap that is used during numeric entry. Numeric
35211 This is the keymap that is used during algebraic entry. This is
35216 This is the keymap that is used during entry of variable names for
35217 commands like @code{calc-store} and @code{calc-recall}. This is
35222 This is the (sparse) keymap used by @code{calc-edit} and other
35228 This is a list of variables which are saved by @code{calc-save-modes}.
35229 Each entry is a list of two items, the variable (as a Lisp symbol)
35231 is compared with its default value (using @code{equal}) and any
35236 This is a list of variables which should be buffer-local to the
35237 Calc buffer. Each entry is a variable name (as a Lisp symbol).
35240 Since @code{calc-mode-hook} is called after this list has been
35256 The usual prefix for Calc is the key sequence @kbd{C-x *}. If you wish
35267 A convenient way to start Calc is with @kbd{C-x * *}; to make it equally
35273 Calc is controlled by many variables, most of which can be reset from
35285 expression is basically a pattern that Calc can search for.
35293 If @code{calc-settings-file} is not your user init file (typically
35294 @file{~/.emacs}) and if the variable @code{calc-loaded-settings-file} is
35296 exists) the first time Calc is invoked.
35298 The default value for this variable is @code{"~/.emacs.d/calc.el"}
35307 system but Calc is unable to find it, you may need to set this
35310 The default value of @code{calc-gnuplot-name} is @code{"gnuplot"}.
35319 @code{nil} if no command is necessary, or strings which can include
35324 The default value of @code{calc-gnuplot-plot-command} is @code{nil},
35325 and the default value of @code{calc-gnuplot-print-command} is
35332 Calc will associate with major modes. When Calc embedded mode is
35338 @code{(latex-mode . latex)} is one such pair. If Calc embedded is
35339 activated in a buffer whose major mode is @var{MAJOR-MODE}, it will set itself
35342 The default value of @code{calc-language-alist} is
35361 what formulas @kbd{C-x * a} will activate in a buffer. It is a
35363 @kbd{C-x * a}, it will tell Calc that what follows is a formula to be
35367 The default pattern is @code{"%Embed\n\\(% .*\n\\)*"}, which checks
35371 The variable @code{calc-embedded-announce-formula-alist} is used to
35375 @var{REGEXP})}, and its default value is
35400 activate as a formula when Embedded mode is entered with @kbd{C-x * e}.
35422 The variable @code{calc-embedded-open-close-formula-alist} is used to
35428 @var{CLOSE-FORMULA-REGEXP})}, and its default value is
35436 that Calc will activate when Embedded mode is entered with @kbd{C-x *
35437 w}. It is a regular expressions.
35439 The default value of @code{calc-embedded-word-regexp} is
35442 The variable @code{calc-embedded-word-regexp-alist} is used to
35446 @code{(@var{MAJOR-MODE} @var{WORD-REGEXP})}, and its default value is
35460 The default string for @code{calc-embedded-open-plain} is
35462 @code{calc-embedded-close-plain} is @code{" %%%\n"}, without
35466 The variable @code{calc-embedded-open-close-plain-alist} is used to
35472 @var{CLOSE-PLAIN-STRING})}, and its default value is
35499 The default value of @code{calc-embedded-open-new-formula} is
35501 @kbd{C-x * f} is typed at the beginning of a line, @kbd{C-x * f} will skip
35503 file. The default value of @code{calc-embedded-close-new-formula} is
35504 also @code{"\n\n"}. The final newline is omitted by @w{@kbd{C-x * f}}
35505 if typed at the end of a line. (It follows that if @kbd{C-x * f} is
35509 The variable @code{calc-embedded-open-close-new-formula-alist} is used to
35515 @var{CLOSE-NEW-FORMULA-STRING})}, and its default value is
35526 these strings; Calc always looks for the annotation itself, so it is not
35529 The default value of @code{calc-embedded-open-mode} is @code{"% "}
35530 and the default value of @code{calc-embedded-close-mode} is
35532 If you change the value of @code{calc-embedded-close-mode}, it is a good
35536 The variable @code{calc-embedded-open-close-mode-alist} is used to
35542 @var{CLOSE-MODE-STRING})}, and its default value is
35569 The default value of @code{calc-lu-power-reference} is @code{"mW"}
35570 and the default value of @code{calc-lu-field-reference} is
35576 The variable @code{calc-note-threshold} is a number (written as a
35580 The default value of @code{calc-note-threshold} is 1.
35589 If @code{calc-highlight-selections-with-faces} is nil, then
35590 a selected sub-formula is distinguished either by changing every
35593 If @code{calc-highlight-selections-with-faces} is t,
35594 then a selected sub-formula is distinguished either by displaying the
35604 @code{calc-multiplication-has-precedence} is non-@code{nil}, then
35605 multiplication has precedence (and, for certain obscure reasons, is
35607 as @samp{a/(b*c)}. If @code{calc-multiplication-has-precedence} is
35609 (and, like division, is left associative), and so for example
35611 of @code{calc-multiplication-has-precedence} is @code{t}.
35617 @code{calc-context-sensitive-enter} is non-@code{nil}, then the
35620 cursor. The default value of @code{calc-context-sensitive-enter} is
35626 steps that Calc will keep track of when @code{calc-quit} is called.
35627 If @code{calc-undo-length} is a non-negative integer, then this is the
35630 be preserved. The default value of @code{calc-undo-length} is @expr{100}.
35635 The variable @code{calc-gregorian-switch} is either a list of integers
35637 If it is @code{nil}, then Calc's date forms always represent Gregorian dates.
35644 The default value of @code{calc-gregorian-switch} is @code{nil}.
35652 There is an automatic command @kbd{M-x report-emacs-bug} which helps
35659 them. Some have dared to suggest that Calc is already top-heavy with
35663 At the front of the source file, @file{calc.el}, is a list of ideas for
35668 The latest version of Calc is available from Savannah, in the Emacs
35680 The result is expressed using the equivalent algebraic function.
36584 @kbd{M-@key{DEL}}, the meaning of the sign is reversed.)
36609 A prefix argument is interpreted as an additional step-size parameter.
36633 From the keyboard, @expr{d} is omitted and defaults to zero.
36637 Mode is toggled; a positive prefix always sets the mode, and a negative
36646 A prefix argument, if any, is used for @expr{m} instead of taking
36704 from the top of the stack. If @expr{n} is a vector or interval,
36705 a subvector/submatrix of the input is created.
36731 is the number of items (for @kbd{v p}) or the number of levels
36732 (for @kbd{v u}). A negative mode is as described below. With no
36733 prefix argument, the mode is taken from the top of the stack and
36777 prefix argument, @expr{n} is omitted and the size is inferred from
36818 Default is to scan for nearest formula delimiter symbols. With a
36819 prefix of zero, formula is delimited by mark and point. With a
36820 non-zero prefix, formula is delimited by scanning forward or
36879 Condition is considered ``true'' if it is a nonzero real or complex
36880 number, or a formula whose value is known to be nonzero; it is ``false''
36896 The variable is replaced by the formula shown on the right. The
36930 @var{matrix}, @var{simp}, @var{inf}]. A prefix argument from 1 to 12
36935 (Space is provided below for you to keep your own written notes.)
36953 types @samp{calc-} for you. Thus, @kbd{x last-args} is short for
36961 This is a list of built-in functions and operators usable in algebraic
36993 the corresponding full Lisp name is derived by adding a prefix of