home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-28
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
39KB
|
660 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: Symbolic Lisp Functions, Next: Formatting Lisp Functions, Prev: Vector Lisp Functions, Up: Internals
Symbolic Functions
..................
The functions described here operate on symbolic formulas in the
Calculator.
- Function: calc-prepare-selection NUM
Prepare a stack entry for selection operations. If NUM is
omitted, the stack entry containing the cursor is used; otherwise,
it is the number of the stack entry to use. This function stores
useful information about the current stack entry into a set of
variables. `calc-selection-cache-num' contains the number of the
stack entry involved (equal to NUM if you specified it);
`calc-selection-cache-entry' contains the stack entry as a list
(such as `calc-top-list' would return with `entry' as the
selection mode); and `calc-selection-cache-comp' contains a
special "tagged" composition (*note Formatting Lisp Functions::.)
which allows Calc to relate cursor positions in the buffer with
their corresponding sub-formulas.
A slight complication arises in the selection mechanism because
formulas may contain small integers. For example, in the vector
`[1, 2, 1]' the first and last elements are `eq' to each other;
selections are recorded as the actual Lisp object that appears
somewhere in the tree of the whole formula, but storing `1' would
falsely select both `1''s in the vector. So
`calc-prepare-selection' also checks the stack entry and replaces
any plain integers with "complex number" lists of the form `(cplx
N 0)'. This list will be displayed the same as a plain N and the
change will be completely invisible to the user, but it will
guarantee that no two sub-formulas of the stack entry will be `eq'
to each other. Next time the stack entry is involved in a
computation, `calc-normalize' will replace these lists with plain
numbers again, again invisibly to the user.
- Function: calc-encase-atoms X
This modifies the formula X to ensure that each part of the
formula is a unique atom, using the `(cplx N 0)' trick described
above. This function may use `setcar' to modify the formula
in-place.
- Function: calc-find-selected-part
Find the smallest sub-formula of the current formula that contains
the cursor. This assumes `calc-prepare-selection' has been called
already. If the cursor is not actually on any part of the
formula, this returns `nil'.
- Function: calc-change-current-selection SELECTION
Change the currently prepared stack element's selection to
SELECTION, which should be `eq' to some sub-formula of the stack
element, or `nil' to unselect the formula. The stack element's
appearance in the Calc buffer is adjusted to reflect the new
selection.
- Function: calc-find-nth-part EXPR N
Return the Nth sub-formula of EXPR. This function is used by the
selection commands, and (unless `j b' has been used) treats sums
and products as flat many-element formulas. Thus if EXPR is `((a
+ b) - c) + d', calling `calc-find-nth-part' with N equal to four
will return `d'.
- Function: calc-find-parent-formula EXPR PART
Return the sub-formula of EXPR which immediately contains PART.
If EXPR is `a*b + (c+1)*d' and PART is `eq' to the `c+1' term of
EXPR, then this function will return `(c+1)*d'. If PART turns out
not to be a sub-formula of EXPR, the function returns `nil'. If
PART is `eq' to EXPR, the function returns `t'. This function
does not take associativity into account.
- Function: calc-find-assoc-parent-formula EXPR PART
This is the same as `calc-find-parent-formula', except that
(unless `j b' has been used) it continues widening the selection
to contain a complete level of the formula. Given `a' from `((a +
b) - c) + d', `calc-find-parent-formula' will return `a + b' but
`calc-find-assoc-parent-formula' will return the whole expression.
- Function: calc-grow-assoc-formula EXPR PART
This expands sub-formula PART of EXPR to encompass a complete
level of the formula. If PART and its immediate parent are not
compatible associative operators, or if `j b' has been used, this
simply returns PART.
- Function: calc-find-sub-formula EXPR PART
This finds the immediate sub-formula of EXPR which contains PART.
It returns an index N such that `(calc-find-nth-part EXPR N)'
would return PART. If PART is not a sub-formula of EXPR, it
returns `nil'. If PART is `eq' to EXPR, it returns `t'. This
function does not take associativity into account.
- Function: calc-replace-sub-formula EXPR OLD NEW
This function returns a copy of formula EXPR, with the sub-formula
that is `eq' to OLD replaced by NEW.
- Function: simplify EXPR
Simplify the expression EXPR by applying various algebraic rules.
This is what the `a s' (`calc-simplify') command uses. This
always returns a copy of the expression; the structure EXPR points
to remains unchanged in memory.
More precisely, here is what `simplify' does: The expression is
first normalized and evaluated by calling `normalize'. If any
`AlgSimpRules' have been defined, they are then applied. Then the
expression is traversed in a depth-first, bottom-up fashion; at
each level, any simplifications that can be made are made until no
further changes are possible. Once the entire formula has been
traversed in this way, it is compared with the original formula
(from before the call to `normalize') and, if it has changed, the
entire procedure is repeated (starting with `normalize') until no
further changes occur. Usually only two iterations are needed:
one to simplify the formula, and another to verify that no further
simplifications were possible.
- Function: simplify-extended EXPR
Simplify the expression EXPR, with additional rules enabled that
help do a more thorough job, while not being entirely "safe" in all
circumstances. (For example, this mode will simplify `sqrt(x^2)'
to `x', which is only valid when X is positive.) This is
implemented by temporarily binding the variable
`math-living-dangerously' to `t' (using a `let' form) and calling
`simplify'. Dangerous simplification rules are written to check
this variable before taking any action.
- Function: simplify-units EXPR
Simplify the expression EXPR, treating variable names as units
whenever possible. This works by binding the variable
`math-simplifying-units' to `t' while calling `simplify'.
- Macro: math-defsimplify FUNCS BODY
Register a new simplification rule; this is normally called as a
top-level form, like `defun' or `defmath'. If FUNCS is a symbol
(like `+' or `calcFunc-sqrt'), this simplification rule is applied
to the formulas which are calls to the specified function. Or,
FUNCS can be a list of such symbols; the rule applies to all
functions on the list. The BODY is wr