Go to the previous, next section.
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 s prefix key.
The s s (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 var-q0
through
var-q9
. Or you can enter any variable name. The prefix `var-'
is supplied for you; when a name appears in a formula (as in `a+q2')
the prefix `var-' is also supplied there, so normally you can simply
forget about `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 `var-'.
The s s command leaves the stored value on the stack. There is
also an s t (calc-store-into
) command, which removes a
value from the stack and stores it in a variable.
If the top of stack value is an equation `a = 7' or assignment
`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
s s RET or s t RET. In this example, the
value 7 would be stored in the variable `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: `s s b RET'
with `a := 7' on the stack stores `a := 7' in b
.)
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.
It is also possible to type an equation or assignment directly at the prompt for the s s or s t command: s s foo = 7. In this case the expression to the right of the = or := symbol is evaluated as if by the = command, and that value is stored in the variable. No value is taken from the stack; s s and s t are equivalent when used in this way.
The prefix keys s and t may be followed immediately by a digit; s 9 is equivalent to s s 9, and t 9 is equivalent to s t 9. (The t prefix is otherwise used for trail and time/date commands.)
There are also several "arithmetic store" commands. For example, s + removes a value from the stack and adds it to the specified variable. The other arithmetic stores are s -, s *, s /, s ^, and s | (vector concatenation), plus s n and s & which negate or invert the value in a variable, and s [ and s ] which decrease or increase a variable by one.
All the arithmetic stores accept the Inverse prefix to reverse the order of the operands. If v represents the contents of the variable, and a is the value drawn from the stack, then regular s - assigns @c{$v \coloneq v - a$} v := v - a, but I s - assigns v := a - v. While 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:
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
In the last four cases, a numeric prefix argument will be used in place of the number one. (For example, M-2 s ] increases a variable by 2, and M-2 I s ] replaces a variable by minus-two minus the variable.
The first six arithmetic stores can also be typed s t +, s t -, etc. The commands s s +, s s -, and so on are analogous arithmetic stores that don't remove the value a from the stack.
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 m N command). See section Simplification Modes. Large vectors put in the trail by these commands always use abbreviated (t .) mode.
The s m command is a general way to adjust a variable's value using any Calc function. It is a "mapping" command analogous to V M, V R, etc. See section Reducing and Mapping Vectors, 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, s m n applies the n key to negate the contents of the variable, so s m n is equivalent to s n. Also, s m Q takes the square root of the value stored in a variable, s m v v uses v v to reverse the vector stored in the variable, and s m H I S takes the hyperbolic arcsine of the variable contents.
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 s m - with a on the stack computes v - a, just like s -. With the Inverse prefix, the variable's original value becomes the last argument instead of the first. Thus I s m - is also equivalent to I s -.
The s x (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.
You can type an equation or assignment at the s x prompt. The command s x a=6 takes no values from the stack; instead, it pushes the old value of `a' on the stack and stores `a = 6'.
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 = (calc-evaluate
).
The s u (calc-unstore
) command returns a variable to the
void state.
The only variables with predefined values are the "special constants"
pi
, e
, i
, phi
, and gamma
. 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 inf
, uinf
, and nan
(which are
normally void).
Note that var-pi
doesn't actually have 3.14159265359 stored
in it, but rather a special magic value that evaluates to @c{$\pi$}
pi
at the current precision. Likewise var-e
, var-i
, and
var-phi
evaluate according to the current precision or polar mode.
If you recall a value from pi
and store it back, this magic
property will be lost.
The s c (calc-copy-variable
) command copies the stored
value of one variable to another. It differs from a simple s r
followed by an s t in two important ways. First, the value never
goes on the stack and thus is never rounded, evaluated, or simplified
in any way; it is not even rounded down to the current precision.
Second, the "magic" contents of a variable like var-e
can
be copied into another variable with this command, perhaps because
you need to unstore var-e
right now but you wish to put it
back when you're done. The s c command is the only way to
manipulate these magic values intact.
The most straightforward way to extract the stored value from a variable
is to use the s r (calc-recall
) command. This command prompts
for a variable name (similarly to 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.
It is also possible to recall the value from a variable by evaluating a formula containing that variable. For example, ' a RET = is the same as s r a RET except that if the variable is void, the former will simply leave the formula `a' on the stack whereas the latter will produce an error message.
The r prefix may be followed by a digit, so that r 9 is equivalent to s r 9. (The r prefix is otherwise unused in the current version of Calc.)
The s e (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 M-# M-# to finish, the variable will
be made void. See section Editing Stack Entries, for a general
description of editing.
The 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 `deriv(x,y)',
where x
will someday become some expression involving y
;
if you let Calc evaluate the rule while you are defining it, Calc will
replace `deriv(x,y)' with 0 because the formula x
does
not itself refer to y
.) By contrast, recalling the variable,
editing with `, and storing will evaluate the variable's value
as a side effect of putting the value on the stack.
There are several special-purpose variable-editing commands that use the s prefix followed by a shifted letter:
AlgSimpRules
. See section Algebraic Simplifications.
Decls
. See section Declarations.
EvalRules
. See section Default Simplifications.
FitRules
. See section Curve Fitting.
GenCount
. See section Solving Equations.
Holidays
. See section Business Days.
IntegLimit
. See section Calculus.
LineStyles
. See section Graphics.
PointStyles
. See section Graphics.
PlotRejects
. See section Graphics.
TimeZone
. See section Time Zones.
Units
. See section User-Defined Units.
ExtSimpRules
. See section "Unsafe" Simplifications.
These commands are just versions of s e that use fixed variable names rather than prompting for the variable name.
The s p (calc-permanent-variable
) command saves a
variable's value permanently in your `.emacs' file, so that its
value will still be available in future Emacs sessions. You can
re-execute s p later on to update the saved value, but the
only way to remove a saved variable is to edit your `.emacs' file
by hand. (See section General Mode Commands, for a way to tell Calc to
use a different file instead of `.emacs'.)
If you do not specify the name of a variable to save (i.e.,
s p RET), all `var-' variables with defined values
are saved except for the special constants pi
, e
,
i
, phi
, and gamma
; the variables TimeZone
and PlotRejects
;
FitRules
, DistribRules
, and other built-in rewrite
rules; and PlotDatan
variables generated
by the graphics commands. (You can still save these variables by
explicitly naming them in an s p command.)
The s i (calc-insert-variables
) command writes
the values of all `var-' variables into a specified buffer.
The variables are written in the form of Lisp setq
commands
which store the values in string form. You can place these commands
in your `.emacs' buffer if you wish, though in this case it
would be easier to use s p RET. (Note that s i
omits the same set of variables as s p RET; the difference
is that s i will store the variables in any buffer, and it also
stores in a more human-readable format.)
If you have an expression like `a+b^2' on the stack and you wish to compute its value where b=3, you can simply store 3 in b and then press = to reevaluate the formula. This has the side-effect of leaving the stored value of 3 in b for future operations.
The s l (calc-let
) command evaluates a formula under a
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 ' a+b^2 RET 3 s l b RET,
the stack will contain the formula `a + 9'. The subsequent command
5 s l a RET will replace this formula with the number 14.
The variables `a' and `b' are not permanently affected in any way
by these commands.
The value on the top of the stack may be an equation or assignment, ohe second-to-top stack entry, then restores the original value (or lack of one) in the variable. Thus after ' a+b^2 RET 3 s l b RET, the stack will contain the formula `a + 9'. The subsequent command 5 s l a RET will replace this formula with the number 14. The variables `a' and `b' are not permanently affected in any way by these commands.
The value on the top of the stack may be an equation or assignment, ohe second-to-top stack entry, then restores the original value (or lack of one) in the variable. Thus after ' a+b^2 RET 3 s l b RET, the stack will contain the formula `a + 9'. The subsequent command 5 s l a RET will replace this formula with the number 14. The variables `a' and `b' are not permanently affected in any way by these commands.
The value on the top of the stack may be an equation or assignment, o