home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-01 | 55.5 KB | 1,207 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i097: gnucalc - GNU Emacs Calculator, v2.00, Part49/56
- Message-ID: <1991Nov1.183950.21360@sparky.imd.sterling.com>
- X-Md4-Signature: a52d97effca603a5a26f3c220a524f23
- Date: Fri, 1 Nov 1991 18:39:50 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 97
- Archive-name: gnucalc/part49
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 49; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- include references to @code{select} to tell where in the pattern
- the selected sub-formula should appear.
- X
- If there is still exactly one @samp{select( )} function call in
- the formula after rewriting is done, it indicates which part of
- the formula should be selected afterwards. Otherwise, the
- formula will be unselected.
- X
- You can make @kbd{j r} act much like @kbd{a r} by enclosing both parts
- of the rewrite rule with @samp{select()}. However, @kbd{j r}
- allows you to use the current selection in more flexible ways.
- Suppose you wished to make a rule which removed the exponent from
- the selected term; the rule @samp{select(a)^x := select(a)} would
- work. In the above example, it would rewrite @samp{2 select(a + b)^2}
- to @samp{2 select(a + b)}. This would then be returned to the
- stack as @samp{2 (a + b)} with the @samp{a + b} selected.
- X
- The @kbd{j r} command uses one iteration by default, unlike
- @kbd{a r} which defaults to 100 iterations. A numeric prefix
- argument affects @kbd{j r} in the same way as @kbd{a r}.
- @xref{Nested Formulas with Rewrite Rules}.
- X
- As with other selection commands, @kbd{j r} operates on the stack
- entry that contains the cursor. (If the cursor is on the top-of-stack
- @samp{.} marker, it works as if the cursor were on the formula
- at stack level 1.)
- X
- If you don't specify a set of rules, the rules are taken from the
- top of the stack, just as with @kbd{a r}. In this case, the
- cursor must indicate stack entry 2 or above as the formula to be
- rewritten (otherwise the same formula would be used as both the
- target and the rewrite rules).
- X
- If the indicated formula has no selection, the cursor position within
- the formula temporarily selects a sub-formula for the purposes of this
- command. If the cursor is not on any sub-formula (e.g., it is in
- the line-number area to the left of the formula), the @samp{select( )}
- markers are ignored by the rewrite mechanism and the rules are allowed
- to apply anywhere in the formula.
- X
- As a special feature, the normal @kbd{a r} command also ignores
- @samp{select( )} calls in rewrite rules. For example, if you used the
- above rule @samp{select(a)^x := select(a)} with @kbd{a r}, it would apply
- the rule as if it were @samp{a^x := a}. Thus, you can write general
- purpose rules with @samp{select( )} hints inside them so that they
- will ``do the right thing'' in both @kbd{a r} and @kbd{j r},
- both with and without selections.
- X
- @node Matching Commands, Automatic Rewrites, Selections with Rewrite Rules, Rewrite Rules
- @subsection Matching Commands
- X
- @noindent
- @kindex a m
- @pindex calc-match
- @tindex match
- The @kbd{a m} (@code{calc-match}) [@code{match}] function takes a
- vector of formulas and a rewrite-rule-style pattern, and produces
- a vector of all formulas which match the pattern. The command
- prompts you to enter the pattern; as for @kbd{a r}, you can enter
- a single pattern (i.e., a formula with meta-variables), or a
- vector of patterns, or a variable which contains patterns, or
- you can give a blank response in which case the patterns are taken
- from the top of the stack. The pattern set will be compiled once
- and saved if it is stored in a variable. If there are several
- patterns in the set, vector elements are kept if they match any
- of the patterns.
- X
- For example, @samp{match(a+b, [x, x+y, x-y, 7, x+y+z])}
- will return @samp{[x+y, x-y, x+y+z]}.
- X
- The @code{import} mechanism is not available for pattern sets.
- X
- The @kbd{a m} command does not provide you with any information about
- which meta-variables in the pattern matched which parts of the vector
- elements. To get this information you should map @code{rewrite} across
- the vector instead. For example, @samp{map(rewrite,
- [x, x+y, x-y, 7, x+y+z], a+b := b)} might produce the result
- @samp{[x, y, -y, 7, y+z]}. (This has the unfortunate effect of
- recompiling the rewrite rule five times; putting @samp{a+b := b}
- in a variable would, as usual, avoid this problem.)
- @xref{Reducing and Mapping}.
- X
- The @kbd{a m} command can also be used to extract all vector elements
- which satisfy any condition: The pattern @samp{x :: x>0} will select
- all the positive vector elements.
- X
- @kindex I a m
- @tindex matchnot
- With the Inverse flag [@code{matchnot}], this command extracts all
- vector elements which do @emph{not} match the given pattern.
- X
- @tindex matches
- There is also a function @samp{matches(@var{x}, @var{p})} which
- evaluates to 1 if expression @var{x} matches pattern @var{p}, or
- to 0 otherwise. This is sometimes useful for including into the
- conditional clauses of other rewrite rules.
- X
- @node Automatic Rewrites, Debugging Rewrites, Matching Commands, Rewrite Rules
- @subsection Automatic Rewrites
- X
- @noindent
- @cindex @code{EvalRules} variable
- @vindex EvalRules
- It is possible to get Calc to apply a set of rewrite rules on all
- results, effectively adding to the built-in set of default
- simplifications. To do this, simply store your rule set in the
- variable @code{EvalRules}. There is a convenient @kbd{s E} command
- for editing @code{EvalRules}; @pxref{Operations on Variables}.
- X
- For example, suppose you want @samp{sin(a + b)} to be expanded out
- to @samp{sin(b) cos(a) + cos(b) sin(a)} wherever it appears, and
- similarly for @samp{cos(a + b)}. The corresponding rewrite rule
- set would be,
- X
- @group
- @smallexample
- [ sin(a + b) := cos(a) sin(b) + sin(a) cos(b),
- X cos(a + b) := cos(a) cos(b) - sin(a) sin(b) ]
- @end smallexample
- @end group
- X
- To apply these manually, you could put them in a variable called
- @code{trigexp} and then use @kbd{a r trigexp} every time you wanted
- to expand trig functions. But if instead you store them in the
- variable @code{EvalRules}, they will automatically be applied to all
- sines and cosines of sums. Then, with @samp{2 x} and @samp{45} on
- the stack, typing @kbd{+ S} will (assuming degrees mode) result in
- @samp{0.7071 sin(2 x) + 0.7071 cos(2 x)} automatically.
- X
- As each level of a formula is evaluated, the rules from
- @code{EvalRules} are applied before the default simplifications.
- Rewriting continues until no further @code{EvalRules} apply.
- Note that this is different from the usual order of application of
- rewrite rules: @code{EvalRules} works from the bottom up, simplifying
- the arguments to a function before the function itself, while @kbd{a r}
- applies rules from the top down.
- X
- Because the @code{EvalRules} are tried first, you can use them to
- override the normal behavior of any built-in Calc function.
- X
- It is important not to write a rule that will get into an infinite
- loop. For example, the rule set @samp{[f(0) := 1, f(n) := n f(n-1)]}
- appears to be a good definition of a factorial function, but it is
- unsafe. Imagine what happens if @samp{f(2.5)} is simplified. Calc
- will continue to subtract 1 from this argument forever without reaching
- zero. A safer second rule would be @samp{f(n) := n f(n-1) :: n>0}.
- Another dangerous rule is @samp{g(x, y) := g(y, x)}. Rewriting
- @samp{g(2, 4)}, this would bounce back and forth between that and
- @samp{g(4, 2)} forever. If an infinite loop in @code{EvalRules}
- occurs, Emacs will eventually stop with a ``Computation got stuck
- or ran too long'' message.
- X
- Another subtle difference between @code{EvalRules} and regular rewrites
- concerns rules that rewrite a formula into an identical formula. For
- example, @samp{f(n) := f(floor(n))} ``fails to match'' when @cite{n} is
- already an integer. But in @code{EvalRules} this case is detected only
- if the righthand side literally becomes the original formula before any
- further simplification. For example, @samp{f(n) := f(floor(n))} will
- get into an infinite loop if it occurs in @code{EvalRules}. Calc will
- replace @samp{f(6)} with @samp{f(floor(6))}, which is different from
- @samp{f(6)}, so it will consider the rule to have matched and will
- continue simplifying that formula; first the argument is simplified
- to get @samp{f(6)}, then the rule matches again to get @samp{f(floor(6))}
- again, ad infinitum. A much safer rule would check its argument first,
- say, with @samp{f(n) := f(floor(n)) :: !integer(n)}.
- X
- (What really happens is that the rewrite mechanism substitutes the
- meta-variables in the righthand side of a rule, compares to see if the
- result is the same as the original formula and fails if so, then uses
- the default simplifications to simplify the result and compares again
- (and again fails if the formula has simplified back to its original
- form). The only special wrinkle for the @code{EvalRules} is that they
- will of course come back into play when the default simplifications
- are used. What Calc wants to do is build @samp{f(floor(6))}, see that
- this is different from the original formula, simplify to @samp{f(6)},
- see that this is the same as the original formula, and thus halt the
- rewriting. But while simplifying, @samp{f(6)} will again trigger
- the same @code{EvalRules} rule and Calc will get into a loop inside
- the rewrite mechanism itself.)
- X
- The @code{phase}, @code{schedule}, and @code{iterations} markers do
- not work in @code{EvalRules}. If the rule set is divided into phases,
- only the phase 1 rules are applied, and the schedule is ignored.
- The rules are always repeated as many times as possible.
- X
- The @code{EvalRules} are applied to all function calls in a formula,
- but not to numbers (and other number-like objects like error forms),
- nor to vectors or individual variable names. (Though they will apply
- to @emph{components} of vectors and error forms when appropriate.) You
- might try to make a variable @code{phihat} which automatically expands
- to its definition without the need to press @kbd{=} by writing the
- rule @samp{quote(phihat) := (1-sqrt(5))/2}, but unfortunately this rule
- will not work as part of @code{EvalRules}.
- X
- Finally, another limitation is that Calc sometimes calls its built-in
- functions directly rather than going through the default simplifications.
- When it does this, @code{EvalRules} will not be able to override those
- functions. For example, when you take the absolute value of the complex
- number @cite{(2, 3)}, Calc computes @samp{sqrt(2*2 + 3*3)} by calling
- the multiplication, addition, and square root functions directly rather
- than applying the default simplifications to this formula. So an
- @code{EvalRules} rule that (perversely) rewrites @samp{sqrt(13) := 6}
- would not apply. (However, if you put Calc into symbolic mode so that
- @samp{sqrt(13)} will be left in symbolic form by the built-in square
- root function, your rule will be able to apply. But if the complex
- number were @cite{(3,4)}, so that @samp{sqrt(25)} must be calculated,
- then symbolic mode will not help because @samp{sqrt(25)} can be
- evaluated exactly to 5.)
- X
- One subtle restriction that normally only manifests itself with
- @code{EvalRules} is that while a given rewrite rule is in the process
- of being checked, that same rule cannot be recursively applied. Calc
- effectively removes the rule from its rule set while checking the rule,
- then puts it back once the match succeeds or fails. (The technical
- reason for this is that compiled pattern programs are not reentrant.)
- For example, consider the rule @samp{foo(x) := x :: foo(x/2) > 0}
- attempting to match @samp{foo(8)}. This rule will be inactive while
- the condition @samp{foo(4) > 0} is checked, even though it might be
- an integral part of evaluating that condition. Note that this is not
- a problem for the more usual recursive type of rule, such as
- @samp{foo(x) := foo(x/2)}, because there the rule has succeeded and
- been reactivated by the time the righthand side is evaluated.
- X
- If @code{EvalRules} has no stored value (its default state), or if
- anything but a non-empty vector is stored in it, then it is ignored.
- X
- Even though Calc's rewrite mechanism is designed to compare rewrite
- rules to formulas as quickly as possible, storing rules in
- @code{EvalRules} may make Calc run substantially slower. This is
- particularly true of rules where the top-level function call is common,
- or is not fixed. The rule @samp{f(n) := n f(n-1) :: n>0} will only
- activate the rewrite mechanism for calls to the function @code{f}, but
- @samp{lg(n) + lg(m) := lg(n m)} will check every @samp{+} operator.
- And @samp{apply(f, [a*b]) := apply(f, [a]) + apply(f, [b]) ::
- in(f, [ln, log10])} may seem more ``efficient'' than two separate
- rules for @code{ln} and @code{log10}, but actually it is vastly less
- efficient because rules with @code{apply} as the top-level pattern
- must be tested against @emph{every} function call that is simplified.
- X
- @cindex @code{AlgSimpRules} variable
- @vindex AlgSimpRules
- Suppose you want @samp{sin(a + b)} to be expanded out not all the time,
- but only when @kbd{a s} is used to simplify the formula. The variable
- @code{AlgSimpRules} holds rules for this purpose. The @kbd{a s} command
- will apply @code{EvalRules} and @code{AlgSimpRules} to the formula, as
- well as all of its built-in simplifications.
- X
- Most of the special limitations for @code{EvalRules} don't apply to
- @code{AlgSimpRules}. Calc simply does an @kbd{a r AlgSimpRules}
- command with an infinite repeat count as the first step of @kbd{a s}.
- It then applies its own built-in simplifications throughout the
- formula, and then repeats these two steps (along with applying the
- default simplifications) until no further changes are possible.
- X
- @cindex @code{ExtSimpRules} variable
- @cindex @code{UnitSimpRules} variable
- @vindex ExtSimpRules
- @vindex UnitSimpRules
- There are also @code{ExtSimpRules} and @code{UnitSimpRules} variables
- that are used by @kbd{a e} and @kbd{u s}, respectively; these commands
- also apply @code{EvalRules} and @code{AlgSimpRules}. The variable
- @code{IntegSimpRules} contains simplification rules that are used
- only during integration by @kbd{a i}; there is no special command
- for editing this variable.
- X
- @node Debugging Rewrites, Examples of Rewrite Rules, Automatic Rewrites, Rewrite Rules
- @subsection Debugging Rewrites
- X
- @noindent
- If a buffer named @samp{*Trace*} exists, the rewrite mechanism will
- record some useful information there as it operates. The original
- formula is written there, as is the result of each successful rewrite,
- and the final result of the rewriting. All phase changes are also
- noted.
- X
- Calc always appends to @samp{*Trace*}. You must empty this buffer
- yourself periodically if it is in danger of growing unwieldy.
- X
- Note that the rewriting mechanism is substantially slower when the
- @samp{*Trace*} buffer exists. Once you are done, you will probably
- want to kill this buffer (with @kbd{C-x k *Trace* @key{RET}}).
- If you leave it in existence and forget about it, all your future
- rewrite commands will be needlessly slow.
- X
- @node Examples of Rewrite Rules, , Debugging Rewrites, Rewrite Rules
- @subsection Examples of Rewrite Rules
- X
- @noindent
- Returning to the example of substituting the pattern
- @samp{sin(x)^2 + cos(x)^2} with 1, we saw that the rule
- @samp{opt(a) sin(x)^2 + opt(a) cos(x)^2 := a} does a good job of
- finding suitable cases. Another solution would be to use the rule
- @samp{cos(x)^2 := 1 - sin(x)^2}, followed by algebraic simplification
- if necessary. This rule will be the most effective way to do the job,
- but at the expense of making some changes that you might not desire.@refill
- X
- Another algebraic rewrite rule is @samp{exp(x+y) := exp(x) exp(y)}.
- To make this work with the @kbd{j r} command so that it can be
- easily targeted to a particular exponential in a large formula,
- you might wish to write the rule as @samp{select(exp(x+y)) :=
- select(exp(x) exp(y))}. The @samp{select} markers will be
- ignored by the regular @kbd{a r} command
- (@pxref{Selections with Rewrite Rules}).@refill
- X
- A surprisingly useful rewrite rule is @samp{a/(b-c) := a*(b+c)/(b^2-c^2)}.
- This will simplify the formula whenever @cite{b} and/or @cite{c} can
- be made simpler by squaring. For example, applying this rule to
- @samp{2 / (sqrt(2) + 3)} yields @samp{6:7 - 2:7 sqrt(2)} (assuming
- Symbolic Mode has been enabled to keep the square root from being
- evaulated to a floating-point approximation). This rule is also
- useful when working with symbolic complex numbers, e.g.,
- @samp{(a + b i) / (c + d i)}.
- X
- As another example, we could define our own factorial function with the
- rules @samp{[f(0) := 1, f(n) := n*f(n-1) :: n>0]}. Enter this vector
- and store it in a variable: @kbd{s t factrules}. Now, given a factorial
- formula like @samp{f(5)} on the stack, type @samp{a r factrules} to apply
- these rules repeatedly. After six applications, @kbd{a r} will stop with
- 120 on the stack. Once these rules are debugged, it would probably be
- most useful to add them to @code{EvalRules} so that Calc will evaluate
- the new @code{f} function automatically. We could then use @kbd{Z K} on
- the keyboard macro @kbd{' f($) RET} to make a command analogous to @kbd{!}
- that applies @code{f} to the value on the top of the stack.
- @xref{Programming}.
- X
- @cindex Quaternions
- The following rule set, contributed by @c{Fran\c cois}
- @asis{Francois} Pinard, implements
- @dfn{Quaternions}, a generalization of the concept of complex numbers.
- Quaternions have four components, and are here represented by function
- calls @samp{quat(@var{w}, [@var{x}, @var{y}, @var{x}])} with ``real
- part'' @var{w} and the three ``imaginary'' parts collected into a
- vector. Various arithmetical operations on quaternions are supported.
- To use these rules, either add them to @code{EvalRules}, or create a
- command based on @kbd{a r} for simplifying quaternion formulas.
- A convenient way to enter quaternions would be a command defined by
- a keyboard macro containing: @kbd{' quat($$$$, [$$$, $$, $]) @key{RET}}.
- X
- @smallexample
- [ quat(w, x, y, z) := quat(w, [x, y, z]),
- X quat(w, [0, 0, 0]) := w,
- X abs(quat(w, v)) := hypot(w, v),
- X -quat(w, v) := quat(-w, -v),
- X r + quat(w, v) := quat(r + w, v) :: real(r),
- X r - quat(w, v) := quat(r - w, -v) :: real(r),
- X quat(w1, v1) + quat(w2, v2) := quat(w1 + w2, v1 + v2),
- X r * quat(w, v) := quat(r * w, r * v) :: real(r),
- X plain(quat(w1, v1) * quat(w2, v2))
- X := quat(w1 * w2 - v1 * v2, w1 * v2 + w2 * v1 + cross(v1, v2)),
- X quat(w1, v1) / r := quat(w1 / r, v1 / r) :: real(r),
- X z / quat(w, v) := z * quatinv(quat(w, v)),
- X quatinv(quat(w, v)) := quat(w, -v) / (w^2 + v^2),
- X quatsqr(quat(w, v)) := quat(w^2 - v^2, 2 * w * v),
- X quat(w, v)^k := quatsqr(quat(w, v)^(k / 2))
- X :: integer(k) :: k > 0 :: k % 2 = 0,
- X quat(w, v)^k := quatsqr(quat(w, v)^((k - 1) / 2)) * quat(w, v)
- X :: integer(k) :: k > 2,
- X quat(w, v)^-k := quatinv(quat(w, v)^k) :: integer(k) :: k > 0 ]
- @end smallexample
- X
- Quaternions, like matrices, have non-commutative multiplication.
- In other words, @cite{q1 * q2 = q2 * q1} is not necessarily true if
- @cite{q1} and @cite{q2} are @code{quat} forms. The @samp{quat*quat}
- rule above uses @code{plain} to prevent Calc from rearranging the
- product. It may also be wise to add the line @samp{[quat(), matrix]}
- to the @code{Decls} matrix, to ensure that Calc's other algebraic
- operations will not rearrange a quaternion product. @xref{Declarations}.
- X
- These rules also accept a four-argument @code{quat} form, converting
- it to the preferred form in the first rule. If you would rather see
- results in the four-argument form, just append the two items
- @samp{phase(2), quat(w, [x, y, z]) := quat(w, x, y, z)} to the end
- of the rule set. (But remember that multi-phase rule sets don't work
- in @code{EvalRules}.)
- X
- @node Units, Store and Recall, Algebra, Top
- @chapter Operating on Units
- X
- @noindent
- One special interpretation of formulas is as numbers with units.
- For example, the formula @samp{5 m / s^2} can be read ``five meters
- per second squared.'' The commands in this chapter help you
- manipulate units expressions in this form. Units-related commands
- begin with the @kbd{u} prefix key.
- X
- @menu
- * Basic Operations on Units::
- * The Units Table::
- * Predefined Units::
- * User-Defined Units::
- @end menu
- X
- @node Basic Operations on Units, The Units Table, Units, Units
- @section Basic Operations on Units
- X
- @noindent
- A @dfn{units expression} is a formula which is basically a number
- multiplied and/or divided by one or more @dfn{unit names}, which may
- optionally be raised to powers. Actually, the value part need not be
- a number; any product or quotient involving unit names is a units
- expression. Many of the units commands will also accept any formula,
- where the command applies to all units expressions which appear in the
- formula.
- X
- A unit name is a variable whose name appears in the @dfn{unit table},
- or a variable whose name is a prefix character like @samp{k} (for ``kilo'')
- or @samp{u} (for ``micro'') followed by a name from the unit table.
- A substantial table of built-in units is provided with Calc;
- @pxref{Predefined Units}. You can also define your own unit names;
- @pxref{User-Defined Units}.@refill
- X
- Note that if the value part of a units expression is exactly @samp{1},
- it will be removed by the Calculator's automatic algebra routines: The
- formula @samp{1 mm} is ``simplified'' to @samp{mm}. This is only a
- display anomaly, however; @samp{mm} will work just fine as a
- representation of one millimeter.@refill
- X
- You may find that Algebraic Mode (@pxref{Algebraic Entry}) makes working
- with units expressions easier. Otherwise, you will have to remember
- to hit the apostrophe key every time you wish to enter units.
- X
- @kindex u s
- @pindex calc-simplify-units
- @tindex usimplify
- The @kbd{u s} (@code{calc-simplify-units}) [@code{usimplify}] command
- simplifies a units
- expression. It uses @kbd{a s} (@code{calc-simplify}) to simplify the
- expression first as a regular algebraic formula; it then looks for
- features that can be further simplified by converting one object's units
- to be compatible with another's. For example, @samp{5 m + 23 mm} will
- simplify to @samp{5.023 m}. When different but compatible units are
- added, the righthand term's units are converted to match those of the
- lefthand term. @xref{Simplification Modes}, for a way to have this done
- automatically at all times.@refill
- X
- Units simplification also handles quotients of two units with the same
- dimensionality, as in @samp{2 in s/L cm} to @samp{5.08 s/L}; fractional
- powers of unit expressions, as in @samp{sqrt(9 mm^2)} to @samp{3 mm} and
- @samp{sqrt(9 acre)} to a quantity in meters; and @code{floor},
- @code{ceil}, @code{round}, @code{trunc}, @code{float}, @code{frac},
- @code{abs}, and @code{clean} applied to units expressions, in which case
- the operation in question is applied only to the numeric part of the
- expression. Finally, trigonometric functions of quantities with units
- of angle are evaluated, regardless of the current angular mode.@refill
- X
- @kindex u c
- @pindex calc-convert-units
- The @kbd{u c} (@code{calc-convert-units}) command converts a units
- expression to new, compatible units. For example, given the units
- expression @samp{55 mph}, typing @kbd{u c m/s @key{RET}} produces
- @samp{24.5872 m/s}. If the units you request are inconsistent with
- the original units, the number will be converted into your units
- times whatever ``remainder'' units are left over. For example,
- converting @samp{55 mph} into acres produces @samp{6.08e-3 acre / m s}.
- (Recall that multiplication binds more strongly than division in Calc
- formulas, so the units here are acres per meter-second.) Remainder
- units are expressed in terms of ``fundamental'' units like @samp{m} and
- @samp{s}, regardless of the input units.
- X
- One special exception is that if you specify a single unit name, and
- a compatible unit appears somewhere in the units expression, then
- that compatible unit will be converted to the new unit and the
- remaining units in the expression will be left alone. For example,
- given the input @samp{980 cm/s^2}, the command @kbd{u c ms} will
- change the @samp{s} to @samp{ms} to get @samp{9.8e-4 cm/ms^2}.
- The ``remainder unit'' @samp{cm} is left alone rather than being
- changed to the base unit @samp{m}.
- X
- You can use explicit unit conversion instead of the @kbd{u s} command
- to gain more control over the units of the result of an expression.
- For example, given @samp{5 m + 23 mm}, you can type @kbd{u c m} or
- @kbd{u c mm} to express the result in either meters or millimeters.
- (For that matter, you could type @kbd{u c fath} to express the result
- in fathoms, if you preferred!)
- X
- In place of a specific set of units, you can also enter one of the
- units system names @code{si}, @code{mks} (equivalent), or @code{cgs}.
- For example, @kbd{u c si @key{RET}} converts the expression into
- International System of Units (SI) base units. Also, @code{base}
- converts to Calc's base units, which are the same as @code{si} units
- except that @code{base} uses @samp{g} as the fundamental unit of mass
- whereas @code{si} uses @samp{kg}.
- X
- @cindex Composite units
- The @kbd{u c} command also accepts @dfn{composite units}, which
- are expressed as the sum of several compatible unit names. For
- example, converting @samp{30.5 in} to units @samp{mi+ft+in} (miles,
- feet, and inches) produces @samp{2 ft + 6.5 in}. Calc first
- sorts the unit names into order of decreasing relative size.
- It then accounts for as much of the input quantity as it can
- using an integer number times the largest unit, then moves on
- to the next smaller unit, and so on. Only the smallest unit
- may have a non-integer amount attached in the result. A few
- standard unit names exist for common combinations, such as
- @code{mfi} for @samp{mi+ft+in}, and @code{tpo} for @samp{ton+lb+oz}.
- Composite units are expanded as if by @kbd{a x}, so that
- @samp{(ft+in)/hr} is first converted to @samp{ft/hr+in/hr}.
- X
- If the value on the stack does not contain any units, @kbd{u c} will
- prompt first for the old units which this value should be considered
- to have, then for the new units. Assuming the old and new units you
- give are consistent with each other, the result also will not contain
- any units. For example, @kbd{u c cm RET in RET} converts the number
- 2 on the stack to 5.08.
- X
- @kindex u b
- @pindex calc-base-units
- The @kbd{u b} (@code{calc-base-units}) command is shorthand for
- @kbd{u c base}; it converts the units expression on the top of the
- stack into @code{base} units. If @kbd{u s} does not simplify a
- units expression as far as you would like, try @kbd{u b}.
- X
- The @kbd{u c} and @kbd{u b} commands treat temperature units (like
- @samp{degC} and @samp{K}) as relative temperatures. For example,
- @kbd{u c} converts @samp{10 degC} to @samp{18 degF}: A change of 10
- degrees Celsius corresponds to a change of 18 degrees Fahrenheit.
- X
- @kindex u t
- @pindex calc-convert-temperature
- @cindex Temperature conversion
- The @kbd{u t} (@code{calc-convert-temperature}) command converts
- absolute temperatures. The value on the stack must be a simple units
- expression with units of temperature only. This command would convert
- @samp{10 degC} to @samp{50 degF}, the equivalent temperature on the
- Fahrenheit scale.@refill
- X
- @kindex u r
- @pindex calc-remove-units
- @kindex u x
- @pindex calc-extract-units
- The @kbd{u r} (@code{calc-remove-units}) command removes units from the
- formula at the top of the stack. The @kbd{u x}
- (@code{calc-extract-units}) command extracts only the units portion of a
- formula. These commands essentially replace every term of the formula
- that does or doesn't (respectively) look like a unit name by the
- constant 1, then resimplify the formula.@refill
- X
- @kindex u a
- @pindex calc-autorange-units
- The @kbd{u a} (@code{calc-autorange-units}) command turns on and off a
- mode in which unit prefixes like @code{k} (``kilo'') are automatically
- applied to keep the numeric part of a units expression in a reasonable
- range. This mode affects @kbd{u s} and all units conversion commands
- except @kbd{u b}. For example, with autoranging on, @samp{12345 Hz}
- will be simplified to @samp{12.345 kHz}. Autoranging is useful for
- some kinds of units (like @code{Hz} and @code{m}), but is probably
- undesirable for non-metric units like @code{ft} and @code{tbsp}.
- (Composite units are more appropriate for those; see above.)
- X
- Autoranging always applies the prefix to the leftmost unit name.
- Calc chooses the largest prefix that causes the number to be greater
- than or equal to 1.0. Thus an increasing sequence of adjusted times
- would be @samp{1 ms, 10 ms, 100 ms, 1 s, 10 s, 100 s, 1 ks}.
- Generally the rule of thumb is that the number will be adjusted
- to be in the interval @samp{[1 .. 1000)}, although there are several
- exceptions to this rule. First, if the unit has a power then this
- is not possible; @samp{0.1 s^2} simplifies to @samp{100000 ms^2}.
- Second, the ``centi-'' prefix is allowed to form @code{cm} (centimeters),
- but will not apply to other units. The ``deci-,'' ``deka-,'' and
- ``hecto-'' prefixes are never used. Thus the allowable interval is
- @samp{[1 .. 10)} for millimeters and @samp{[1 .. 100)} for centimeters.
- Finally, a prefix will not be added to a unit if the resulting name
- is also the actual name of another unit; @samp{1e-15 t} would normally
- be considered a ``femto-ton,'' but it is written as @samp{1000 at}
- (1000 atto-tons) instead because @code{ft} would be confused with feet.
- X
- @node The Units Table, Predefined Units, Basic Operations on Units, Units
- @section The Units Table
- X
- @noindent
- @kindex u v
- @pindex calc-enter-units-table
- The @kbd{u v} (@code{calc-enter-units-table}) command displays the units table
- in another buffer called @code{*Units Table*}. Each entry in this table
- gives the unit name as it would appear in an expression, the definition
- of the unit in terms of simpler units, and a full name or description of
- the unit. Fundamental units are defined as themselves; these are the
- units produced by the @kbd{u b} command. The fundamental units are
- meters, seconds, grams, kelvins, amperes, candelas, moles, radians,
- and steradians.
- X
- The Units Table buffer also displays the Unit Prefix Table. Note that
- two prefixes, ``kilo'' and ``hecto,'' accept either upper- or lower-case
- prefix letters. @samp{Meg} is also accepted as a synonym for the @samp{M}
- prefix. Whenever a unit name can be interpreted as either a built-in name
- or a prefix followed by another built-in name, the former interpretation
- wins. For example, @samp{2 pt} means two pints, not two pico-tons.
- X
- The Units Table buffer, once created, is not rebuilt unless you define
- new units. To force the buffer to be rebuilt, give any numeric prefix
- argument to @kbd{u v}.
- X
- @kindex u V
- @pindex calc-view-units-table
- The @kbd{u V} (@code{calc-view-units-table}) command is like @kbd{u v} except
- that the cursor is not moved into the Units Table buffer. You can
- type @kbd{u V} again to remove the Units Table from the display. To
- return from the Units Table buffer after a @kbd{u v}, type @kbd{M-x calc}
- again or use the regular Emacs @kbd{C-x o} (@code{other-window})
- command. You can also kill the buffer with @kbd{C-x k} if you wish;
- the actual units table is safely stored inside the Calculator.
- X
- @kindex u g
- @pindex calc-get-unit-definition
- The @kbd{u g} (@code{calc-get-unit-definition}) command retrieves a unit's
- defining expression and pushes it onto the Calculator stack. For example,
- @kbd{u g in} will produce the expression @samp{2.54 cm}. This is the
- same definition for the unit that would appear in the Units Table buffer.
- Note that this command works only for actual unit names; @kbd{u g km}
- will report that no such unit exists, for example, because @code{km} is
- really the unit @code{m} with a @code{k} (``kilo'') prefix. To see a
- definition of a unit in terms of base units, it is easier to push the
- unit name on the stack and then reduce it to base units with @kbd{u b}.
- X
- @kindex u e
- @pindex calc-explain-units
- The @kbd{u e} (@code{calc-explain-units}) command displays an English
- description of the units of the expression on the stack. For example,
- for the expression @samp{62 km^2 g / s^2 mol K}, the description is
- ``Square-Kilometer Gram per (Second-squared Mole Degree-Kelvin).'' This
- command uses the English descriptions that appear in the righthand
- column of the Units Table.
- X
- @node Predefined Units, User-Defined Units, The Units Table, Units
- @section Predefined Units
- X
- @noindent
- Since the exact definitions of many kinds of units have evolved over the
- years, and since certain countries sometimes have local differences in
- their definitions, it is a good idea to examine Calc's definition of a
- unit before depending on its exact value. For example, there are three
- different units for gallons, corresponding to the US (@code{gal}),
- Canadian (@code{galC}), and British (@code{galUK}) definitions. Also,
- note that @code{oz} is a standard ounce of mass, @code{ozt} is a Troy
- ounce, and @code{ozfl} is a fluid ounce.
- X
- The temperature units corresponding to degrees Kelvin and Centigrade
- (Celsius) are the same in this table, since most units commands treat
- temperatures as being relative. The @code{calc-convert-temperature}
- command has special rules for handling the different absolute magnitudes
- of the various temperature scales.
- X
- The unit of volume ``liters'' can be referred to by either the lower-case
- @code{l} or the upper-case @code{L}.
- X
- The unit @code{A} stands for Amperes; the name @code{Ang} is used
- @iftex
- for \AA ngstroms.
- @end iftex
- @ifinfo
- for Angstroms.
- @end ifinfo
- X
- The unit @code{pt} stands for pints; the name @code{point} stands for
- a typographical point, defined by @samp{72 point = 1 in}. There is
- also @code{tpt}, which stands for a printer's point as defined by the
- @TeX{} typesetting system: @samp{72.27 tpt = 1 in}.
- X
- The unit @code{e} stands for the elementary (electron) unit of charge;
- because algebra command could mistake this for the special constant
- @cite{e}, Calc provides the alternate unit name @code{ech} which is
- preferable to @code{e}.
- X
- The name @code{g} stands for one gram of mass; there is also @code{gf},
- one gram of force. (Likewise for @kbd{lb}, pounds, and @kbd{lbf}).
- Meanwhile, one ``@cite{g}'' of acceleration is denoted @code{ga}.
- X
- The unit @code{ton} is a U.S. ton of @samp{2000 lb}, and @code{t} is
- a metric ton of @samp{1000 kg}.
- X
- The names @code{s} (or @code{sec}) and @code{min} refer to units of
- time; @code{arcsec} and @code{arcmin} are units of angle.
- X
- Some ``units'' are really physical constants; for example, @code{c}
- represents the speed of light, and @code{h} represents Planck's
- constant. You can use these just like other units: converting
- @samp{.5 c} to @samp{m/s} expresses one-half the speed of light in
- meters per second. You can also use this merely as a handy reference;
- the @kbd{u g} command gets the definition of one of these constants
- in its normal terms, and @kbd{u b} expresses the definition in base
- units.
- X
- Two units, @code{pi} and @code{fsc} (the fine structure constant) are
- dimensionless. The units simplification commands simply treat these
- names as equivalent to their corresponding values. However you can, for
- example, use @kbd{u c} to convert a pure number into multiples of the
- fine structure constant, or @kbd{u b} to convert this back into a pure
- number. (When @kbd{u c} prompts for the ``old units,'' just enter a
- blank line to signify that the value really is unitless.)
- X
- @c Describe angular units, luminosity vs. steradians problem.
- X
- @node User-Defined Units, , Predefined Units, Units
- @section User-Defined Units
- X
- @noindent
- @kindex u d
- @pindex calc-define-unit
- @cindex User-defined units
- The @kbd{u d} (@code{calc-define-unit}) command records the units
- expression on the top of the stack as the definition for a new,
- user-defined unit. For example, putting @samp{16.5 ft} on the stack and
- typing @kbd{u d rod} defines the new unit @samp{rod} to be equivalent to
- 16.5 feet. The unit conversion and simplification commands will now
- treat @code{rod} just like any other unit of length. You will also be
- prompted for an optional English description of the unit, which will
- appear in the Units Table.
- X
- @kindex u u
- @pindex calc-undefine-unit
- The @kbd{u u} (@code{calc-undefine-unit}) command removes a user-defined
- unit. It is not possible to remove one of the predefined units,
- however.
- X
- If you define a unit with an existing unit name, your new definition
- will replace the original definition of that unit. If the unit was a
- predefined unit, the old definition will not be replaced, only
- ``shadowed.'' The built-in definition will reappear if you later use
- @kbd{u u} to remove the shadowing definition.
- X
- To create a new fundamental unit, use either 1 or the unit name itself
- as the defining expression. Otherwise the expression can involve any
- other units that you like (except for composite units like @samp{mfi}).
- You can create a new composite unit with a sum of other units as the
- defining expression. The next unit operation like @kbd{u c} or @kbd{u v}
- will rebuild the internal unit table incorporating your modifications.
- Note that erroneous definitions (such as two units defined in terms of
- each other) will not be detected until the unit table is next rebuilt;
- @kbd{u v} is a convenient way to cause this to happen.
- X
- Temperature units are treated specially inside the Calculator; it is not
- possible to create user-defined temperature units.
- X
- @kindex u p
- @pindex calc-permanent-units
- @cindex @file{.emacs} file, user-defined units
- The @kbd{u p} (@code{calc-permanent-units}) command stores the user-defined
- units in your @file{.emacs} file, so that the units will still be
- available in subsequent Emacs sessions. If there was already a set of
- user-defined units in your @file{.emacs} file, it is replaced by the
- new set. (@xref{General Mode Commands}, for a way to tell Calc to use
- a different file instead of @file{.emacs}.)
- X
- @node Store and Recall, Graphics, Units, Top
- @chapter Storing and Recalling
- X
- @noindent
- Calculator variables are really just Lisp variables that contain numbers
- or formulas in a form that Calc can understand. The commands in this
- section allow you to manipulate variables conveniently. Commands related
- to variables use the @kbd{s} prefix key.
- X
- @menu
- * Storing Variables::
- * Recalling Variables::
- * Operations on Variables::
- * Let Command::
- * Evaluates-To Operator::
- @end menu
- X
- @node Storing Variables, Recalling Variables, Store and Recall, Store and Recall
- @section Storing Variables
- X
- @noindent
- @kindex s s
- @pindex calc-store
- @cindex Storing variables
- @cindex Quick variables
- @vindex q0
- @vindex q9
- The @kbd{s s} (@code{calc-store}) command stores the value at the top of
- the stack into a specified variable. It prompts you to enter the
- name of the variable. If you press a single digit, the value is stored
- immediately in one of the ``quick'' variables @code{var-q0} through
- @code{var-q9}. Or you can enter any variable name. The prefix @samp{var-}
- is supplied for you; when a name appears in a formula (as in @samp{a+q2})
- the prefix @samp{var-} is also supplied there, so normally you can simply
- forget about @samp{var-} everywhere. Its only purpose is to enable you to
- use Calc variables without fear of accidentally clobbering some variable in
- another Emacs package. If you really want to store in an arbitrary Lisp
- variable, just backspace over the @samp{var-}.
- X
- @kindex s t
- @pindex calc-store-into
- The @kbd{s s} command leaves the stored value on the stack. There is
- also an @kbd{s t} (@code{calc-store-into}) command, which removes a
- value from the stack and stores it in a variable.
- X
- If the top of stack value is an equation @samp{a = 7} or assignment
- @samp{a := 7} with a variable on the lefthand side, then Calc will
- assign that variable with that value by default, i.e., if you type
- @kbd{s s @key{RET}} or @kbd{s t @key{RET}}. In this example, the
- value 7 would be stored in the variable @samp{a}. (If you do type
- a variable name at the prompt, the top-of-stack value is stored in
- its entirety, even if it is an equation: @samp{s s b @key{RET}}
- with @samp{a := 7} on the stack stores @samp{a := 7} in @code{b}.)
- X
- In fact, the top of stack value can be a vector of equations or
- assignments with different variables on their lefthand sides; the
- default will be to store all the variables with their corresponding
- righthand sides simultaneously.
- X
- It is also possible to type an equation or assignment directly at
- the prompt for the @kbd{s s} or @kbd{s t} command: @kbd{s s foo = 7}.
- In this case the expression to the right of the @kbd{=} or @kbd{:=}
- symbol is evaluated as if by the @kbd{=} command, and that value is
- stored in the variable. No value is taken from the stack; @kbd{s s}
- and @kbd{s t} are equivalent when used in this way.
- X
- @kindex s 0-9
- @kindex t 0-9
- The prefix keys @kbd{s} and @kbd{t} may be followed immediately by a
- digit; @kbd{s 9} is equivalent to @kbd{s s 9}, and @kbd{t 9} is
- equivalent to @kbd{s t 9}. (The @kbd{t} prefix is otherwise used
- for trail and time/date commands.)
- X
- @kindex s +
- @kindex s -
- @kindex s *
- @kindex s /
- @kindex s ^
- @kindex s |
- @kindex s n
- @kindex s &
- @kindex s [
- @kindex s ]
- @pindex calc-store-plus
- @pindex calc-store-minus
- @pindex calc-store-times
- @pindex calc-store-div
- @pindex calc-store-power
- @pindex calc-store-concat
- @pindex calc-store-neg
- @pindex calc-store-inv
- @pindex calc-store-decr
- @pindex calc-store-incr
- There are also several ``arithmetic store'' commands. For example,
- @kbd{s +} removes a value from the stack and adds it to the specified
- variable. The other arithmetic stores are @kbd{s -}, @kbd{s *}, @kbd{s /},
- @kbd{s ^}, and @kbd{s |} (vector concatenation), plus @kbd{s n} and
- @kbd{s &} which negate or invert the value in a variable, and @kbd{s [}
- and @kbd{s ]} which decrease or increase a variable by one.
- X
- All the arithmetic stores accept the Inverse prefix to reverse the
- order of the operands. If @cite{v} represents the contents of the
- variable, and @cite{a} is the value drawn from the stack, then regular
- @kbd{s -} assigns @cite{v := v - a}, but @kbd{I s -} assigns
- @cite{v := a - v}. While @kbd{I s *} might seem pointless, it is
- useful if matrix multiplication is involved. Actually, all the
- arithmetic stores use formulas designed to behave usefully both
- forwards and backwards:
- X
- @group
- @example
- s + v := v + a v := a + v
- s - v := v - a v := a - v
- s * v := v * a v := a * v
- s / v := v / a v := a / v
- s ^ v := v ^ a v := a ^ v
- s | v := v | a v := a | v
- s n v := v / (-1) v := (-1) / v
- s & v := v ^ (-1) v := (-1) ^ v
- s [ v := v - 1 v := 1 - v
- s ] v := v - (-1) v := (-1) - v
- @end example
- @end group
- X
- In the last four cases, a numeric prefix argument will be used in
- place of the number one. (For example, @kbd{M-2 s ]} increases
- a variable by 2, and @kbd{M-2 I s ]} replaces a variable by
- minus-two minus the variable.
- X
- The first six arithmetic stores can also be typed @kbd{s t +}, @kbd{s t -},
- etc. The commands @kbd{s s +}, @kbd{s s -}, and so on are analogous
- arithmetic stores that don't remove the value @cite{a} from the stack.
- X
- All arithmetic stores report the new value of the variable in the
- Trail for your information. They signal an error if the variable
- previously had no stored value. If default simplifications have been
- turned off, the arithmetic stores temporarily turn them on for numeric
- arguments only (i.e., they temporarily do an @kbd{m N} command).
- @xref{Simplification Modes}.
- X
- @kindex s m
- @pindex calc-store-map
- The @kbd{s m} command is a general way to adjust a variable's value
- using any Calc function. It is a ``mapping'' command analogous to
- @kbd{V M}, @kbd{V R}, etc. @xref{Reducing and Mapping}, to see
- how to specify a function for a mapping command. Basically,
- all you do is type the Calc command key that would invoke that
- function normally. For example, @kbd{s m n} applies the @kbd{n}
- key to negate the contents of the variable, so @kbd{s m n} is
- equivalent to @kbd{s n}. Also, @kbd{s m Q} takes the square root
- of the value stored in a variable, @kbd{s m v v} uses @kbd{v v} to
- reverse the vector stored in the variable, and @kbd{s m H I S}
- takes the hyperbolic arcsine of the variable contents.
- X
- If the mapping function takes two or more arguments, the additional
- arguments are taken from the stack; the old value of the variable
- is provided as the first argument. Thus @kbd{s m -} with @cite{a}
- on the stack computes @cite{v - a}, just like @kbd{s -}. With the
- Inverse prefix, the variable's original value becomes the @emph{last}
- argument instead of the first. Thus @kbd{I s m -} is also
- equivalent to @kbd{I s -}.
- X
- @kindex s x
- @pindex calc-store-exchange
- The @kbd{s x} (@code{calc-store-exchange}) command exchanges the value
- of a variable with the value on the top of the stack. Naturally, the
- variable must already have a stored value for this to work.
- X
- You can type an equation or assignment at the @kbd{s x} prompt. The
- command @kbd{s x a=6} takes no values from the stack; instead, it
- pushes the old value of @samp{a} on the stack and stores @samp{a = 6}.
- X
- @kindex s u
- @pindex calc-unstore
- @cindex Void variables
- @cindex Un-storing variables
- Until you store something in them, variables are ``void,'' that is, they
- contain no value at all. If they appear in an algebraic formula they
- will be left alone even if you press @kbd{=} (@code{calc-evaluate}).
- The @kbd{s u} (@code{calc-unstore}) command returns a variable to the
- void state.@refill
- X
- The only variables with predefined values are the ``special constants''
- @code{var-pi}, @code{var-e}, and @code{var-i}. You are free to unstore
- these variables or to store new values into them if you like, although
- some of the algebraic-manipulation functions may assume these variables
- represent their standard values. Calc displays a warning if you change
- the value of one of these variables, or of one of the other special
- variables @code{var-inf}, @code{var-uinf}, and @code{var-nan} (which
- are normally void).
- X
- Note that @code{var-pi} doesn't actually have 3.14159265359 stored
- in it, but rather a special magic value that evaluates to @c{$\pi$}
- @cite{pi}
- at the current precision. Likewise @code{var-e}, @code{var-i}, and
- @code{var-phi} evaluate according to the current precision or polar mode.
- If you recall a value from @code{pi} and store it back, this magic
- property will be lost.
- X
- @kindex s c
- @pindex calc-copy-variable
- The @kbd{s c} (@code{calc-copy-variable}) command copies the stored
- value of one variable to another. It differs from a simple @kbd{s r}
- followed by an @kbd{s t} in two important ways. First, the value
- never goes on the stack and thus is never evaluated or simplified
- in any way; it is not even rounded down to the current precision.
- Second, the ``magic'' contents of a variable like @code{var-e} can
- be copied into another variable with this command, perhaps because
- you need to unstore @code{var-e} right now but you wish to put it
- back when you're done. The @kbd{s c} command is the only way to
- manipulate these magic values intact.
- X
- @node Recalling Variables, Operations on Variables, Storing Variables, Store and Recall
- @section Recalling Variables
- X
- @noindent
- @kindex s r
- @pindex calc-recall
- @cindex Recalling variables
- The most straightforward way to extract the stored value from a variable
- is to use the @kbd{s r} (@code{calc-recall}) command. This command prompts
- for a variable name (similarly to @code{calc-store}), looks up the value
- of the specified variable, and pushes that value onto the stack. It is
- an error to try to recall a void variable.
- X
- It is also possible to recall the value from a variable by evaluating a
- formula containing that variable. For example, @kbd{' a @key{RET} =} is
- the same as @kbd{s r a @key{RET}} except that if the variable is void, the
- former will simply leave the formula @samp{a} on the stack whereas the
- latter will produce an error message.
- X
- @kindex r 0-9
- The @kbd{r} prefix may be followed by a digit, so that @kbd{r 9} is
- equivalent to @kbd{s r 9}. (The @kbd{r} prefix is otherwise unused
- in the current version of Calc.)
- X
- @node Operations on Variables, Let Command, Recalling Variables, Store and Recall
- @section Other Operations on Variables
- X
- @noindent
- @kindex s e
- @pindex calc-edit-variable
- The @kbd{s e} (@code{calc-edit-variable}) command edits the stored
- value of a variable without ever putting that value on the stack
- or simplifying or evaluating the value. It prompts for the name of
- the variable to edit. If the variable has no stored value, the
- editing buffer will start out empty. If the editing buffer is
- empty when you press @key{M-# M-#} to finish, the variable will
- be made void. @xref{Editing Stack Entries}, for a general
- description of editing.
- X
- The @kbd{s e} command is especially useful for creating and editing
- rewrite rules which are stored in variables. Sometimes these rules
- contain formulas which must not be evaluated until the rules are
- actually used. (For example, they may refer to @samp{variable(x)},
- which tests if @code{x} is a variable; if you let Calc evaluate the
- rule while you are defining it, Calc will replace @samp{variable(x)}
- with 1 (true) because @code{x} itself is a variable, but what you
- really wanted was to test the thing that will replace @code{x} when
- the rule is invoked.) By contrast, recalling the variable, editing
- with @kbd{`}, and storing will evaluate the variable's value as a
- side effect of putting the value on the stack.
- X
- There are several special-purpose variable-editing commands that
- use the @kbd{s} prefix followed by a shifted letter:
- X
- @kindex s A
- @kindex s D
- @kindex s E
- @kindex s F
- @kindex s G
- @kindex s I
- @kindex s P
- @kindex s T
- @kindex s U
- @kindex s X
- @pindex calc-store-AlgSimpRules
- @pindex calc-store-Decls
- @pindex calc-store-EvalRules
- @pindex calc-store-FitRules
- @pindex calc-store-GenCount
- @pindex calc-store-IntegLimit
- @pindex calc-store-PlotRejects
- @pindex calc-store-TimeZone
- @pindex calc-store-UnitSimpRules
- @pindex calc-store-ExtSimpRules
- @table @kbd
- @item s A
- Edit @code{AlgSimpRules}. @xref{Algebraic Simplifications}.
- @item s D
- Edit @code{Decls}. @xref{Declarations}.
- @item s E
- Edit @code{EvalRules}. @xref{Default Simplifications}.
- @item s F
- Edit @code{FitRules}. @xref{Curve Fitting}.
- @item s G
- Edit @code{GenCount}. @xref{Solving Equations}.
- @item s I
- Edit @code{IntegLimit}. @xref{Calculus}.
- @item s P
- Edit @code{PlotRejects}. @xref{Graphics}.
- @item s T
- Edit @code{TimeZone}. @xref{Time Zones}.
- @item s U
- Edit @code{UnitSimpRules}. @xref{Simplification of Units}.
- @item s X
- Edit @code{ExtSimpRules}. @xref{Unsafe Simplifications}.
- @end table
- X
- These commands are just versions of @kbd{s e} that use fixed variable
- names rather than prompting for the variable name.
- X
- @kindex s p
- @pindex calc-permanent-variable
- @cindex Storing variables
- @cindex Permanent variables
- @cindex @file{.emacs} file, veriables
- The @kbd{s p} (@code{calc-permanent-variable}) command saves a
- variable's value permanently in your @file{.emacs} file, so that its
- value will still be available in future Emacs sessions. You can
- re-execute @kbd{s p} later on to update the saved value, but the
- only way to remove a saved variable is to edit your @file{.emacs} file
- by hand. (@xref{General Mode Commands}, for a way to tell Calc to
- use a different file instead of @file{.emacs}.)
- X
- If you do not specify the name of a variable to save (i.e.,
- @kbd{s p @key{RET}}), all @samp{var-} variables with defined values
- are saved except for the special constants @code{pi}, @code{e},
- @code{i}, @code{phi}, and @code{gamma}; the variables @code{TimeZone}
- and @code{PlotRejects};
- @code{FitRules}, @code{DistribRules}, and other built-in rewrite
- rules; and @code{PlotData@var{n}} variables generated
- by the graphics commands. (You can still save these variables by
- explicitly naming them in an @kbd{s p} command.)@refill
- X
- @kindex s i
- @pindex calc-insert-variables
- The @kbd{s i} (@code{calc-insert-variables}) command writes
- the values of all @samp{var-} variables into a specified buffer.
- The variables are written in the form of Lisp @code{setq} commands
- which store the values in string form. You can place these commands
- in your @file{.emacs} buffer if you wish, though in this case it
- would be easier to use @kbd{s p @key{RET}}. (Note that @kbd{s i}
- omits the same set of variables as @kbd{s p @key{RET}}; the difference
- is that @kbd{s i} will store the variables in any buffer, and it also
- stores in a more human-readable format.)
- X
- @node Let Command, Evaluates-To Operator, Operations on Variables, Store and Recall
- @section The Let Command
- X
- @noindent
- @kindex s l
- @pindex calc-let
- @cindex Variables, temporary assignment
- @cindex Temporary assignment to variables
- If you have an expression like @samp{a+b^2} on the stack and you wish to
- compute its value where @cite{b=3}, you can simply store 3 in @cite{b} and
- then press @kbd{=} to reevaluate the formula. This has the side-effect
- of leaving the stored value of 3 in @cite{b} for future operations.
- X
- The @kbd{s l} (@code{calc-let}) command evaluates a formula under a
- @emph{temporary} assignment of a variable. It stores the value on the
- top of the stack into the specified variable, then evaluates the
- second-to-top stack entry, then restores the original value (or lack of
- one) in the variable. Thus after @kbd{' a+b^2 @key{RET} 3 s l b @key{RET}},
- the stack will contain the formula @samp{a + 9}. The subsequent command
- @kbd{5 s l a @key{RET}} will replace this formula with the number 14. The
- variables @samp{a} and @samp{b} are not permanently affected in any way
- by these commands.
- X
- The value on the top of the stack may be an equation or assignment, or
- vector of equations or assignments, in which case the default will be
- analogous to the case of @kbd{s t @key{RET}}. @xref{Storing Variables}.
- X
- Also, you can answer the variable-name prompt with an equation or
- assignment: @kbd{s l b=3 RET} is the same as storing 3 on the stack
- and typing @kbd{s l b RET}.
- X
- The @kbd{a b} (@code{calc-substitute}) is another way to substitute
- a variable with a value in a formula. It does an actual substitution
- rather than temporarily assigning the variable and evaluating. For
- example, letting @cite{n=2} in @samp{f(n pi)} with @kbd{a b} will
- produce @samp{f(2 pi)}, whereas @kbd{s l} would give @samp{f(6.28)}
- since the evaluation step will also evaluate @code{pi}.
- X
- @node Evaluates-To Operator, , Let Command, Store and Recall
- @section The Evaluates-To Operator
- X
- @noindent
- @tindex evalto
- @tindex =>
- @cindex Evaluates-to operator
- @cindex @samp{=>} operator
- The special algebraic symbol @samp{=>} is known as the @dfn{evaluates-to
- operator}. (It will show up as an @code{evalto} function call in
- other language modes like Pascal and @TeX{}.) This is a binary
- operator, that is, it has a lefthand and a righthand argument,
- although it can be entered with the righthand argument omitted.
- X
- A formula like @samp{@var{a} => @var{b}} is evaluated by Calc as
- follows: First, @var{a} is not simplified or modified in any
- way. The previous value of argument @var{b} is thrown away; the
- formula @var{a} is then copied and evaluated as if by the @kbd{=}
- command according to all current modes and stored variable values,
- and the result is installed as the new value of @var{b}.
- X
- For example, suppose you enter the algebraic formula @samp{2 + 3 => 17}.
- The number 17 is ignored, and the lefthand argument is left in its
- unevaluated form; the result is the formula @samp{2 + 3 => 5}.
- X
- @kindex s =
- @pindex calc-evalto
- You can enter an @samp{=>} formula either directly using algebraic
- entry (in which case the righthand side may be omitted since it is
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 49'
- echo 'File calc.texinfo is continued in part 50'
- echo 50 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-