calc: Algebraic Entry
4.5 Algebraic Entry
===================
The ‘'’ (‘calc-algebraic-entry’) command can be used to enter
calculations in algebraic form. This is accomplished by typing the
apostrophe key, ’, followed by the expression in standard format:
' 2+3*4 <RET>.
This will compute ‘2+(3*4) = 14’ and push it on the stack. If you wish
you can ignore the RPN aspect of Calc altogether and simply enter
algebraic expressions in this way. You may want to use <DEL> every so
often to clear previous results off the stack.
You can press the apostrophe key during normal numeric entry to
switch the half-entered number into Algebraic entry mode. One reason to
do this would be to fix a typo, as the full Emacs cursor motion and
editing keys are available during algebraic entry but not during numeric
entry.
In the same vein, during either numeric or algebraic entry you can
press ‘`’ (grave accent) to switch to ‘calc-edit’ mode, where you
complete your half-finished entry in a separate buffer. Editing
Stack Entries.
If you prefer algebraic entry, you can use the command ‘m a’
(‘calc-algebraic-mode’) to set Algebraic mode. In this mode, digits and
other keys that would normally start numeric entry instead start full
algebraic entry; as long as your formula begins with a digit you can
omit the apostrophe. Open parentheses and square brackets also begin
algebraic entry. You can still do RPN calculations in this mode, but
you will have to press <RET> to terminate every number: ‘2 <RET> 3 <RET>
* 4 <RET> +’ would accomplish the same thing as ‘2*3+4 <RET>’.
If you give a numeric prefix argument like ‘C-u’ to the ‘m a’
command, it enables Incomplete Algebraic mode; this is like regular
Algebraic mode except that it applies to the ‘(’ and ‘[’ keys only.
Numeric keys still begin a numeric entry in this mode.
The ‘m t’ (‘calc-total-algebraic-mode’) gives you an even stronger
algebraic-entry mode, in which _all_ regular letter and punctuation keys
begin algebraic entry. Use this if you prefer typing ‘sqrt( )’ instead
of ‘Q’, ‘factor( )’ instead of ‘a f’, and so on. To type regular Calc
commands when you are in Total Algebraic mode, hold down the <META> key.
Thus ‘M-q’ is the command to quit Calc, ‘M-p’ sets the precision, and
‘M-m t’ (or ‘M-m M-t’, if you prefer) turns Total Algebraic mode back
off again. Meta keys also terminate algebraic entry, so that ‘2+3 M-S’
is equivalent to ‘2+3 <RET> M-S’. The symbol ‘Alg*’ will appear in the
mode line whenever you are in this mode.
Pressing ‘'’ (the apostrophe) a second time re-enters the previous
algebraic formula. You can then use the normal Emacs editing keys to
modify this formula to your liking before pressing <RET>.
Within a formula entered from the keyboard, the symbol ‘$’ represents
the number on the top of the stack. If an entered formula contains any
‘$’ characters, the Calculator replaces the top of stack with that
formula rather than simply pushing the formula onto the stack. Thus, ‘'
1+2 <RET>’ pushes 3 on the stack, and ‘$*2 <RET>’ replaces it with 6.
Note that the ‘$’ key always initiates algebraic entry; the ‘'’ is
unnecessary if ‘$’ is the first character in the new formula.
Higher stack elements can be accessed from an entered formula with
the symbols ‘$$’, ‘$$$’, and so on. The number of stack elements
removed (to be replaced by the entered values) equals the number of
dollar signs in the longest such symbol in the formula. For example,
‘$$+$$$’ adds the second and third stack elements, replacing the top
three elements with the answer. (All information about the top stack
element is thus lost since no single ‘$’ appears in this formula.)
A slightly different way to refer to stack elements is with a dollar
sign followed by a number: ‘$1’, ‘$2’, and so on are much like ‘$’,
‘$$’, etc., except that stack entries referred to numerically are not
replaced by the algebraic entry. That is, while ‘$+1’ replaces 5 on the
stack with 6, ‘$1+1’ leaves the 5 on the stack and pushes an additional
6.
If a sequence of formulas are entered separated by commas, each
formula is pushed onto the stack in turn. For example, ‘1,2,3’ pushes
those three numbers onto the stack (leaving the 3 at the top), and
‘$+1,$-1’ replaces a 5 on the stack with 4 followed by 6. Also, ‘$,$$’
exchanges the top two elements of the stack, just like the <TAB> key.
You can finish an algebraic entry with ‘M-=’ or ‘M-<RET>’ instead of
<RET>. This uses ‘=’ to evaluate the variables in each formula that
goes onto the stack. (Thus ‘' pi <RET>’ pushes the variable ‘pi’, but
‘' pi M-<RET>’ pushes 3.1415.)
If you finish your algebraic entry by pressing <LFD> (or ‘C-j’)
instead of <RET>, Calc disables simplification (as if by ‘m O’;
Simplification Modes) while the entry is being pushed on the stack.
Thus ‘' 1+2 <RET>’ pushes 3 on the stack, but ‘' 1+2 <LFD>’ pushes the
formula ‘1+2’; you might then press ‘=’ when it is time to evaluate this
formula.