home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-18
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
46KB
|
730 lines
This is Info file calc.info, produced by Makeinfo-1.55 from the input
file calc.texinfo.
This file documents Calc, the GNU Emacs calculator.
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the section entitled "GNU General Public License"
may be included in a translation approved by the author instead of in
the original English.
File: calc.info, Node: Default Simplifications, Next: Algebraic Simplifications, Prev: Simplifying Formulas, Up: Simplifying Formulas
Default Simplifications
-----------------------
This section describes the "default simplifications," those which are
normally applied to all results. For example, if you enter the variable
`x' on the stack twice and push `+', Calc's default simplifications
automatically change `x + x' to `2 x'.
The `m O' command turns off the default simplifications, so that `x
+ x' will remain in this form unless you give an explicit "simplify"
command like `=' or `a v'. *Note Algebraic Manipulation::. The `m D'
command turns the default simplifications back on.
The most basic default simplification is the evaluation of functions.
For example, `2 + 3' is evaluated to `5', and `sqrt(9)' is evaluated to
`3'. Evaluation does not occur if the arguments to a function are
somehow of the wrong type (`tan([2,3,4])', range (`tan(90)'), or number
(`tan(3,5)'), or if the function name is not recognized (`f(5)'), or if
"symbolic" mode (*note Symbolic Mode::.) prevents evaluation
(`sqrt(2)').
Calc simplifies (evaluates) the arguments to a function before it
simplifies the function itself. Thus `sqrt(5+4)' is simplified to
`sqrt(9)' before the `sqrt' function itself is applied. There are very
few exceptions to this rule: `quote', `lambda', and `condition' (the
`::' operator) do not evaluate their arguments, `if' (the `? :'
operator) does not evaluate all of its arguments, and `evalto' does not
evaluate its lefthand argument.
Most commands apply the default simplifications to all arguments they
take from the stack, perform a particular operation, then simplify the
result before pushing it back on the stack. In the common special case
of regular arithmetic commands like `+' and `Q' [`sqrt'], the arguments
are simply popped from the stack and collected into a suitable function
call, which is then simplified (the arguments being simplified first as
part of the process, as described above).
The default simplifications are too numerous to describe completely
here, but this section will describe the ones that apply to the major
arithmetic operators. This list will be rather technical in nature,
and will probably be interesting to you only if you are a serious user
of Calc's algebra facilities.
As well as the simplifications described here, if you have stored
any rewrite rules in the variable `EvalRules' then these rules will
also be applied before any built-in default simplifications. *Note
Automatic Rewrites::, for details.
And now, on with the default simplifications:
Arithmetic operators like `+' and `*' always take two arguments in
Calc's internal form. Sums and products of three or more terms are
arranged by the associative law of algebra into a left-associative form
for sums, `((a + b) + c) + d', and a right-associative form for
products, `a * (b * (c * d))'. Formulas like `(a + b) + (c + d)' are
rearranged to left-associative form, though this rarely matters since
Calc's algebra commands are designed to hide the inner structure of
sums and products as much as possible. Sums and products in their
proper associative form will be written without parentheses in the
examples below.
Sums and products are *not* rearranged according to the commutative
law (`a + b' to `b + a') except in a few special cases described below.
Some algebra programs always rearrange terms into a canonical order,
which enables them to see that `a b + b a' can be simplified to `2 a b'.
Calc assumes you have put the terms into the order you want and
generally leaves that order alone, with the consequence that formulas
like the above will only be simplified if you explicitly give the `a s'
command. *Note Algebraic Simplifications::.
Differences `a - b' are treated like sums `a + (-b)' for purposes of
simplification; one of the default simplifications is to rewrite `a +
(-b)' or `(-b) + a', where `-b' represents a "negative-looking" term,
into `a - b' form. "Negative-looking" means negative numbers, negated
formulas like `-x', and products or quotients in which either term is
negative-looking.
Other simplifications involving negation are `-(-x)' to `x'; `-(a
b)' or `-(a/b)' where either `a' or `b' is negative-looking, simplified
by negating that term, or else where `a' or `b' is any number, by
negating that number; `-(a + b)' to `-a - b', and `-(b - a)' to `a - b'.
(This, and rewriting `(-b) + a' to `a - b', are the only cases where
the order of terms in a sum is changed by the default simplifications.)
The distributive law is used to simplify sums in some cases: `a x +
b x' to `(a + b) x', where `a' represents a number or an implicit 1 or
-1 (as in `x' or `-x') and similarly for `b'. Use the `a c', `a f', or
`j M' commands to merge sums with non-numeric coefficients using the
distributive law.
The distributive law is only used for sums of two terms, or for
adjacent terms in a larger sum. Thus `a + b + b + c' is simplified to
`a + 2 b + c', but `a + b + c + b' is not simplified. The reason is
that comparing all terms of a sum with one another would require time
proportional to the square of the number of terms; Calc relegates
potentially slow operations like this to commands that have to be
invoked explicitly, like `a s'.
Finally, `a + 0' and `0 + a' are simplified to `a'. A consequence
of the above rules is that `0 - a' is simplified to `-a'.
The products `1 a' and `a 1' are simplified to `a'; `(-1) a' and `a
(-1)' are simplified to `-a'; `0 a' and `a 0' are simplified to `0',
except that in matrix mode where `a' is not provably scalar the result
is the generic zero matrix `idn(0)', and that if `a' is infinite the
result is `nan'.
Also, `(-a) b' and `a (-b)' are simplified to `-(a b)', where this
occurs for negated formulas but not for regular negative numbers.
Products are commuted only to move numbers to the front: `a b 2' is
commuted to `2 a b'.
The product `a (b + c)' is distributed over the sum only if `a' and
at least one of `b' and `c' are numbers: `2 (x + 3)' goes to `2 x + 6'.
The formula `(-a) (b - c)', where `-a' is a negative number, is
rewritten to `a (c - b)'.
The distributive law of products and powers is used for adjacent
terms of the product: `x^a x^b' goes to `x^(a+b)' where `a' is a
number, or an implicit 1 (as in `x'), or the implicit one-half of
`sqrt(x)', and similarly for `b'. The result is written using `sqrt'
or `1/sqrt' if the sum of the powers is `1/2' or `-1/2', respectively.
If the sum of the powers is zero, the product is simplified to `1' or
to `idn(1)' if matrix mode is enabled.
The product of a negative power times anything but another negative
power is changed to use division: `x^(-2) y' goes to `y / x^2' unless
matrix mode is in effect and neither `x' nor `y' are scalar (in which
case it is considered unsafe to rearrange the order of the terms).
Finally, `a (b/c)' is rewritten to `(a b)/c', and also `(a/b) c' is
changed to `(a c)/b' unless in matrix mode.
Simplifications for quotients are analogous to those for products.
The quotien