www.delorie.com/gnu/docs/calc/calc_300.html | search |
Buy the book! | |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The special algebraic symbol `=>' is known as the evaluates-to
operator. (It will show up as an 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.
A formula like `a => b' is evaluated by Calc as follows: First, a is not simplified or modified in any way. The previous value of argument b is thrown away; the formula a is then copied and evaluated as if by the = command according to all current modes and stored variable values, and the result is installed as the new value of b.
For example, suppose you enter the algebraic formula `2 + 3 => 17'. The number 17 is ignored, and the lefthand argument is left in its unevaluated form; the result is the formula `2 + 3 => 5'.
You can enter an `=>' formula either directly using algebraic
entry (in which case the righthand side may be omitted since it is
going to be replaced right away anyhow), or by using the s =
(calc-evalto
) command, which takes a from the stack
and replaces it with `a => b'.
Calc keeps track of all `=>' operators on the stack, and recomputes them whenever anything changes that might affect their values, i.e., a mode setting or variable value. This occurs only if the `=>' operator is at the top level of the formula, or if it is part of a top-level vector. In other words, pushing `2 + (a => 17)' will change the 17 to the actual value of `a' when you enter the formula, but the result will not be dynamically updated when `a' is changed later because the `=>' operator is buried inside a sum. However, a vector of `=>' operators will be recomputed, since it is convenient to push a vector like `[a =>, b =>, c =>]' on the stack to make a concise display of all the variables in your problem. (Another way to do this would be to use `[a, b, c] =>', which provides a slightly different format of display. You can use whichever you find easiest to read.)
The m C (calc-auto-recompute
) command allows you to
turn this automatic recomputation on or off. If you turn
recomputation off, you must explicitly recompute an `=>'
operator on the stack in one of the usual ways, such as by
pressing =. Turning recomputation off temporarily can save
a lot of time if you will be changing several modes or variables
before you look at the `=>' entries again.
Most commands are not especially useful with `=>' operators as arguments. For example, given `x + 2 => 17', it won't work to type 1 + to get `x + 3 => 18'. If you want to operate on the lefthand side of the `=>' operator on the top of the stack, type j 1 (that's the digit "one") to select the lefthand side, execute your commands, then type j u to unselect.
All current modes apply when an `=>' operator is computed, including the current simplification mode. Recall that the formula `x + y + x' is not handled by Calc's default simplifications, but the a s command will reduce it to the simpler form `y + 2 x'. You can also type m A to enable an algebraic-simplification mode in which the equivalent of a s is used on all of Calc's results. If you enter `x + y + x =>' normally, the result will be `x + y + x => x + y + x'. If you change to algebraic-simplification mode, the result will be `x + y + x => y + 2 x'. However, just pressing a s once will have no effect on `x + y + x => x + y + x', because the righthand side depends only on the lefthand side and the current mode settings, and the lefthand side is not affected by commands like a s.
The "let" command (s l) has an interesting interaction with the `=>' operator. The s l command evaluates the second-to-top stack entry with the top stack entry supplying a temporary value for a given variable. As you might expect, if that stack entry is an `=>' operator its righthand side will temporarily show this value for the variable. In fact, all `=>'s on the stack will be updated if they refer to that variable. But this change is temporary in the sense that the next command that causes Calc to look at those stack entries will make them revert to the old variable value.
2: a => a 2: a => 17 2: a => a 1: a + 1 => a + 1 1: a + 1 => 18 1: a + 1 => a + 1 . . . 17 s l a RET p 8 RET |
Here the p 8 command changes the current precision,
thus causing the `=>' forms to be recomputed after the
influence of the "let" is gone. The d SPC command
(calc-refresh
) is a handy way to force the `=>'
operators on the stack to be recomputed without any other
side effects.
Embedded Mode also uses `=>' operators. In embedded mode,
the lefthand side of an `=>' operator can refer to variables
assigned elsewhere in the file by `:=' operators. The
assignment operator `a := 17' does not actually do anything
by itself. But Embedded Mode recognizes it and marks it as a sort
of file-local definition of the variable. You can enter `:='
operators in algebraic mode, or by using the s :
(calc-assign
) [assign
] command which takes a variable
and value from the stack and replaces them with an assignment.
See section 7.8.3 TeX Language Mode, for the way `=>' appears in TeX language output. The eqn mode gives similar treatment to `=>'.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster donations bookstore | delorie software privacy |
Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |