[comp.sources.bugs] Repost of Calc 1.05 patch, part 17/20

daveg@near.cs.caltech.edu (Dave Gillespie) (10/16/90)

Several sites have reported that part 17 of the Calc 1.04 -> 1.05 patch
arrived truncated in comp.sources.misc.  (In fact it was truncated when
it arrived here.)  Following is a complete re-post of part 17 of the patch.
Starting at the "#!/bin/sh" line it should be 1156 lines long.

                                                                -- Dave

#!/bin/sh
# this is part 17 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file calc.patch continued
#
CurArch=17
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> calc.patch
X! 
X! @kindex g v
X! @kindex g V
X! @pindex calc-graph-view-commands
X! @pindex calc-graph-view-trail
X! The @kbd{g v} (@code{calc-graph-view-commands}) and @kbd{g V}
X! (@code{calc-graph-view-trail}) commands display the @samp{*Gnuplot Commands*}
X! and @samp{*Gnuplot Trail*} buffers, respectively, in another window.
X! This happens automatically when Calc thinks there is something you
X! will want to see in either of these buffers.  If you type @kbd{g v}
X! or @kbd{g V} when the relevant buffer is already displayed, the
X! buffer is hidden again.
X! 
X! @kindex g K
X! @pindex calc-graph-kill
X! If something goes wrong, you can use @kbd{g K} (@code{calc-graph-kill})
X! to kill the GNUPLOT process that is running.  The next graphing
X! command you give will start a fresh GNUPLOT process.  The word
X! @samp{Graph} appears in the Calc window's mode line whenever a GNUPLOT
X! process is currently running.
X! 
X! @node Algebra, Units, Graphics, Top
X  @chapter Algebra
X  
X! This section covers the Calc features that help you work with
X! algebraic formulas.  First, the general sub-formula selection
X! mechanism is described; this works in conjunction with any Calc
X! commands.  Then, commands for specific algebraic operations are
X! described.  Finally, the flexiblr @dfn{rewrite rule} mechanism
X! is discussed.
X! 
X! The algebraic commands use the @kbd{a} key prefix; selection
X! commands use the @kbd{j} (for ``just a letter that wasn't used
X! for anything else'') prefix.
X  
X! @xref{Editing Stack Entries}, to see how to manipulate formulas
X! using regular Emacs editing commands.@refill
X  
X  When doing algebraic work, you may find several of the Calculator's
X! modes to be helpful, including algebraic-simplification mode (@kbd{m A})
X! or no-simplification mode (@kbd{m O}),
X  algebraic-entry mode (@kbd{m a}), fraction mode (@kbd{m f}), and
X  symbolic mode (@kbd{m s}).  @xref{Mode Settings}, for discussions
X  of these modes.  You may also wish to select ``big'' display mode (@kbd{d B}).
X! @xref{Normal Language Modes}.@refill
X  
X  @menu
X+ * Selecting Subformulas::
X  * Algebraic Manipulation::
X  * Calculus::
X+ * Numerical Solutions::
X+ * Logical Operations::
X+ * Rewrite Rules::
X  @end menu
X  
X! @node Selecting Subformulas, Algebraic Manipulation, Algebra, Algebra
X! @section Selecting Sub-Formulas
X! 
X! @cindex Selections
X! @cindex Sub-formulas
X! @cindex Parts of formulas
X! When working with an algebraic formula it is often necessary to
X! manipulate a portion of the formula rather than the formula as a
X! whole.  Calc allows you to ``select'' a portion of any formula on
X! the stack.  Commands which would normally operate on that stack
X! entry will now operate only on the sub-formula, leaving the
X! surrounding part of the stack entry alone.
X! 
X! One common non-algebraic use for selection involves vectors.  To work
X! on one element of a vector in-place, simply select that element as a
X! ``sub-formula'' of the vector.
X! 
X! @menu
X! * Making Selections::
X! * Changing Selections::
X! * Displaying Selections::
X! * Operating on Selections::
X! * Rearranging with Selections::
X! @end menu
X! 
X! @node Making Selections, Changing Selections, Selecting Subformulas, Selecting Subformulas
X! @subsection Making Selections
X! 
X! @kindex j s
X! @pindex calc-select-here
X! To select a sub-formula, move the Emacs cursor to any character in that
X! sub-formula, and press @kbd{j s} (@code{calc-select-here}).  Calc will
X! highlight the smallest portion of the formula that contains that
X! character.  By default the sub-formula is highlighted by blanking out
X! all of the rest of the formula with dots.  Selection works in any
X! display mode but is perhaps easiest in ``big'' (@kbd{d B}) mode.
X! Suppose you enter the following formula:
X! 
X! @example
X!            3
X!     (a + b)  + sqrt(c)
X! 1:  ------------------
X!          2 x + 1
X! @end example
X! 
X! @noindent
X! (by typing @kbd{' ((a+b)^3 + sqrt(c)) / (2x+1)}).  If you move the
X! cursor to the letter @samp{b} and press @kbd{j s}, the display changes
X! to
X! 
X! @example
X!            .
X!     .. . b.  . .......
X! 1*  ..................
X!          . . . .
X! @end example
X! 
X! Every character not part of the sub-formula @samp{b} has been changed
X! to a dot.  The @samp{*} next to the line number is to remind you that
X! the formula has a portion of it selected.  (In this case, it's very
X! obvious, but it might not always be.)
X! 
X! If you had instead placed the cursor on the parenthesis immediately to
X! the right of the @samp{b}, the selection would have been:
X! 
X! @example
X!            .
X!     (a + b)  . .......
X! 1*  ..................
X!          . . . .
X! @end example
X! 
X! The portion selected is always large enough to be considered a complete
X! formula all by itself, so selecting the parenthesis selects the whole
X! formula that it encloses.  Putting the cursor on the the @samp{+} sign
X! would have had the same effect.
X! 
X! (Strictly speaking, the Emacs cursor is really the manifestation of
X! the Emacs ``point,'' which is a position @emph{between} two characters
X! in the buffer.  So purists would say that Calc selects the smallest
X! sub-formula which contains the character to the right of ``point.'')
X! 
X! If you supply a numeric prefix argument @var{n}, the selection is
X! expanded to the @var{n}th enclosing sub-formula.  Thus, positioning
X! the cursor on the @samp{b} and typing @kbd{C-u 1 g s} will select
X! @samp{a + b}; typing @kbd{C-u 2 g s} will select @samp{(a + b)^3},
X! and so on.
X! 
X! If the cursor is not on any part of the formula, or if you give a
X! numeric prefix that is too large, the entire formula is selected.
X! 
X! If the cursor is on the @samp{.} line that marks the top of the stack
X! (i.e., its normal ``rest position''), this command selects the entire
X! formula at stack level 1.  Most selection commands similarly operate
X! on the formula at the top of the stack if you haven't positioned the
X! cursor on any stack entry.
X! 
X! @kindex j a
X! @pindex calc-select-additional
X! The @kbd{j a} (@code{calc-select-additional}) command enlarges the
X! current selection to encompass the cursor.  To select the smallest
X! sub-formula defined by two different points, move to the first and
X! press @kbd{j s}, then move to the other and press @kbd{j a}.  This
X! is roughly analogous to using @code{set-mark-command} to select the
X! two ends of a region of text during normal Emacs editing.
X! 
X! @kindex j o
X! @pindex calc-select-once
X! The @kbd{j o} (@code{calc-select-once}) command selects a formula in
X! exactly the same way as @kbd{j s}, except that the selection will
X! last only as long as the next command that uses it.  For example,
X! @kbd{j o 1 +} is a handy way to add one to the sub-formula indicated
X! by the cursor.
X! 
X! (A somewhat more precise definition: The @kbd{j o} command sets a flag
X! such that the next command involving selected stack entries will clear
X! the selections on those stack entries afterwards.  All other selection
X! commands except @kbd{j a} clear this flag.)
X! 
X! @kindex j S
X! @kindex j O
X! @pindex calc-select-here-maybe
X! @pindex calc-select-once-maybe
X! The @kbd{j S} (@code{calc-select-here-maybe}) and @kbd{j O}
X! (@code{calc-select-once-maybe}) commands are equivalent to @kbd{j s}
X! and @kbd{j o}, respectively, except that if the formula already
X! has a selection they have no effect.  This is analogous to the
X! behavior of some commands such as @kbd{j r} (@code{calc-rewrite-selection};
X! @pxref{Rewrite Rules}) and is mainly intended to be used in keyboard
X! macros that implement your own selection-oriented commands.@refill
X! 
X! Selection of sub-formulas normally treats associative terms like
X! @samp{a + b - c + d} and @samp{x * y * z} as single levels of the formula.
X! If you place the cursor anywhere inside @samp{a + b - c + d} except
X! on one of the variable names and use @kbd{j s}, you will select the
X! entire four-term sum.
X! 
X! @kindex j b
X! @pindex calc-break-selections
X! The @kbd{j b} (@code{calc-break-selections}) command controls a mode
X! in which the ``deep structure'' of these associative formulas shows
X! through.  Calc actually stores the above formulas as @samp{((a + b) - c) + d}
X! and @samp{x * (y * z)} (note that for certain obscure reasons, Calc
X! treats multiplication as right-associative).  Once you have enabled
X! @kbd{j b} mode, selecting with the cursor on the @samp{-} sign would
X! only select the @samp{a + b - c} portion, which makes sense when the
X! deep structure of the sum is considered.  There is no way to select
X! the @samp{b - c + d} portion; although this might initially look
X! like just as legitimate a sub-formula as @samp{a + b - c}, the deep
X! structure shows that it isn't.  The @kbd{d U} command can be used
X! to view the deep structure of any formula (@pxref{Normal Language Modes}).
X! 
X! When @kbd{j b} mode has not been enabled, the deep structure is
X! generally hidden by the selection commands---what you see is what
X! you get.
X! 
X! @kindex j u
X! @pindex calc-unselect
X! The @kbd{j u} (@code{calc-unselect}) command unselects the formula
X! that the cursor is on.  If there was no selection in the formula,
X! this command has no effect.  With a numeric prefix argument, it
X! unselects that stack element rather than using the cursor position.
X! 
X! @kindex j c
X! @pindex calc-clear-selections
X! The @kbd{j c} (@code{calc-clear-selections}) command unselects all
X! stack elements.
X! 
X! @node Changing Selections, Displaying Selections, Making Selections, Selecting Subformulas
X! @subsection Changing Selections
X! 
X! @kindex j m
X! @pindex calc-select-more
X! Once you have selected a sub-formula, you can expand it using the
X! @kbd{j m} (@code{calc-select-more}) command.  If @samp{a + b} is
X! selected, pressing @kbd{j m} repeatedly works as follows:
X! 
X! @example
X!            3                        3                        3
X!     (a + b)  . .......       (a + b)  + sqrt(c)       (a + b)  + sqrt(c)
X! 1*  ..................   1*  ..................   1*  ------------------
X!          . . . .                  . . . .                   2 x + 1
X! @end example
X! 
X! In the last example, the entire formula is selected.  This is roughly
X! the same as having no selection at all, but because there are subtle
X! differences the @samp{*} character is still there on the line number.
X! 
X! With a numeric prefix argument @var{n}, @kbd{j m} expands @var{n}
X! times (or until the entire formula is selected).  Note that @kbd{j s}
X! with argument @var{n} is equivalent to plain @kbd{j s} followed by
X! @kbd{j m} with argument @var{n}.  If @kbd{j m} is used when there
X! is no current selection, it is equivalent to @kbd{j s}.
X! 
X! Even though @kbd{j m} does not explicitly use the location of the
X! cursor within the formula, it nevertheless uses the cursor to determine
X! which stack element to operate on.  As usual, @kbd{j m} when the cursor
X! is not on any stack element operates on the top stack element.
X! 
X! @kindex j l
X! @pindex calc-select-less
X! The @kbd{j l} (@code{calc-select-less}) command reduces the current
X! selection around the cursor position.  That is, it selects the
X! immediate sub-formula of the current selection which contains the
X! cursor, the opposite of @kbd{j m}.  If the cursor is not inside the
X! current selection, the command de-selects the formula.
X! 
X! @kindex j 1-9
X! @pindex calc-select-part
X! The @kbd{j 1} through @kbd{j 9} (@code{calc-select-part}) commands
X! select the @var{n}th sub-formula of the current selection.  They are
X! like @kbd{j l} (@code{calc-select-less}) except they use counting
X! rather than the cursor position to decide which sub-formula to select.
X! For example, if the current selection is @kbd{a + b + c} or
X! @kbd{f(a, b, c)} or @kbd{[a, b, c]}, then @kbd{j 1} selects @samp{a},
X! @kbd{j 2} selects @samp{b}, and @kbd{j 3} selects @samp{c}; in each of
X! these cases, @kbd{j 4} through @kbd{j 9} would be errors.
X! 
X! If there is no current selection, @kbd{j 1} through @kbd{j 9} select
X! the @var{n}th top-level sub-formula.  (In other words, they act as if
X! the entire stack entry were selected first.)  To select the @var{n}th
X! sub-formula where @var{n} is greater than nine, you must instead invoke
X! @kbd{j 1} with @var{n} as a numeric prefix argument.@refill
X! 
X! @kindex j n
X! @kindex j p
X! @pindex calc-select-next
X! @pindex calc-select-previous
X! The @kbd{j n} (@code{calc-select-next}) and @kbd{j p}
X! (@code{calc-select-previous}) commands change the current selection
X! to the next or previous sub-formula at the same level.  For example,
X! if @samp{b} is selected in @samp{2 + a*b*c + x}, then @kbd{j n}
X! selects @samp{c}.  Further @kbd{j n} commands would be in error because,
X! even though there is something to the right of @samp{c} (namely, @samp{x}),
X! it is not at the same level; in this case, it is not a term of the
X! same product as @samp{b} and @samp{c}.  However, @kbd{j m} (to select
X! the whole product @samp{a*b*c} as a term of the sum) followed by
X! @kbd{j n} would successfully select the @samp{x}.
X! 
X! Similarly, @kbd{j p} moves the selection from the @samp{b} in this
X! sample formula to the @samp{a}.  Both commands accept numeric prefix
X! arguments to move several steps at a time.
X! 
X! It is interesting to compare Calc's selection commands with the
X! Emacs Info system's commands for navigating through hierarchically
X! organized documentation.  Calc's @kbd{j n} command is completely
X! analogous to Info's @kbd{n} command.  Likewise, @kbd{j p} maps to
X! @kbd{p}, @kbd{j 2} maps to @kbd{2}, and Info's @kbd{u} is like @kbd{j m}.
X! (Note that @kbd{j u} stands for @code{calc-unselect}, not ``up''.)
X! The Info @kbd{m} command is somewhat similar to Calc's @kbd{j s} and
X! @kbd{j l}; in each case, you can jump directly to a sub-component
X! of the hierarchy simply by pointing to it with the cursor.
X! 
X! @node Displaying Selections, Operating on Selections, Changing Selections, Selecting Subformulas
X! @subsection Displaying Selections
X! 
X! @kindex j d
X! @pindex calc-show-selections
X! The @kbd{j d} (@code{calc-show-selections}) command controls how
X! selected sub-formulas are displayed.  One of the alternatives is
X! illustrated in the above examples; if we press @kbd{j d} we switch
X! to the other style in which the selected portion itself is obscured
X! by @samp{#} signs:
X! 
X! @example
X!            3                          #               
X!     (a + b)  . .......         ## # ##  + sqrt(c)     
X! 1:  ..................     1:  ------------------     
X!          . . . .                    2 x + 1           
X! @end example
X! 
X! @node Operating on Selections, Rearranging with Selections, Displaying Selections, Selecting Subformulas
X! @subsection Operating on Selections
X! 
X! Once a selection is made, all Calc commands that manipulate items
X! on the stack will operate on the selected portions of the items
X! instead.  (Note that several stack elements may have selections
X! at once, though there can be only one selection at a time in any
X! given stack element.)
X! 
X! @kindex j e
X! @pindex calc-enable-selections
X! The @kbd{j e} (@code{calc-enable-selections}) command disables the
X! effect that selections have on Calc commands.  The current selections
X! still exist, but Calc commands operate on whole stack elements anyway.
X! This mode can be identified by the fact that the @samp{*} markers on
X! the line numbers are gone, even though selections are visible.  To
X! reactivate the selections, press @kbd{j e} again.
X! 
X! To extract a sub-formula as a new formula, simply press @key{RET}.
X! This normally duplicates the top stack element; here it duplicates
X! only the selected portion of that element.
X! 
X! To replace a sub-formula with something different, you can enter the
X! new value onto the stack and press @key{TAB}.  This normally exchanges
X! the top two stack elements; here it swaps the value you entered into
X! the selected portion of the formula, returning the old selected
X! portion to the top of the stack.
X! 
X! @example
X!            3
X!     (a + b)  . .......        17 x y . .......        17 x y + sqrt(c)
X! 2*  ..................    2*  ................    2:  ----------------
X!          . . . .                    . . . .               2 x + 1
X! 
X!                                      3                       3
X! 1:  17 x y                1:  (a + b)             1:  (a + b)
X! @end example
X! 
X! In this example we select a sub-formula of our original example,
X! enter a new formula, @key{TAB} it into place, then deselect to see
X! the complete, edited formula.
X! 
X! If you want to swap whole formulas around even though they contain
X! selections, just use @kbd{j e} before and after.
X! 
X! @kindex j '
X! @pindex calc-enter-selection
X! The @kbd{j '} (@code{calc-enter-selection}) command is another way
X! to replace a selected sub-formula.  This command does an algebraic
X! entry just like the regular @kbd{'} key.  When you press @key{RET},
X! the formula you type replaces the original selection.  You can use
X! the @samp{$} symbol in the formula to refer to the original
X! selection.  If there is no selection in the formula under the cursor,
X! the cursor is used to make a temporary selection for the purposes of
X! the command.  Thus, to change a term of a formula, all you have to
X! do is move the Emacs cursor to that term and press @kbd{j '}.
X! 
X! @kindex j `
X! @pindex calc-edit-selection
X! The @kbd{j `} (@code{calc-edit-selection}) command is a similar
X! analogue of the @kbd{`} (@code{calc-edit}) command.  It edits the
X! selected sub-formula in a separate buffer.  If there is no
X! selection, it edits the sub-formula indicated by the cursor.
X! 
X! To delete a sub-formula, press @key{DEL}.  This generally replaces
X! the sub-formula with the constant zero, but in a few suitable contexts
X! it uses the constant one instead.  The @key{DEL} key automatically
X! deselects and re-simplifies the entire formula afterwards.  Thus:
X! 
X! @example
X!     17 x y - #######        17 x y         17 # y          17 y
X! 1*  ----------------    1:  -------    1*  -------    1:  -------
X!         2 x + 1             2 x + 1        2 x + 1        2 x + 1
X! @end example
X! 
X! In this example, we first delete the @samp{sqrt(c)} term; Calc
X! accomplishes this by replacing @samp{sqrt(c)} with zero and
X! resimplifying.  We then delete the @kbd{x} in the numerator;
X! since this is part of a product, Calc replaces it with @samp{1}
X! and resimplifies.
X! 
X! If you select an element of a vector and press @key{DEL}, that
X! element is deleted from the vector.
X! 
X! @kindex j DEL
X! @pindex calc-del-selection
X! The @kbd{j @key{DEL}} (@code{calc-del-selection}) command is like
X! @key{DEL} but with the auto-selecting behavior of @kbd{j '} and
X! @kbd{j `}.  It deletes the selected portion of the formula
X! indicated by the cursor, or, in the absence of a selection, it
X! deletes the sub-formula indicated by the cursor position.
X! 
X! @kindex j RET
X! @pindex calc-grab-selection
X! (There is also an auto-selecting @kbd{j @key{RET}} (@code{calc-copy-selection})
X! command.)
X! 
X! Normal arithmetic operations also apply to sub-formulas.  Here we
X! select the denominator, press @kbd{5 -} to subtract five from the
X! denominator, press @kbd{n} to negate the denominator, then
X! press @kbd{Q} to take the square root.
X! 
X! @example
X!      .. .           .. .           .. .              .. .     
X! 1*  .......    1*  .......    1*  .......    1*  .............
X!     2 x + 1        2 x - 4        4 - 2 x        sqrt(4 - 2 x)
X! @end example
X! 
X! Certain types of operations on selections are not allowed.  For
X! example, for an arithmetic function like @kbd{-} no more than one of
X! the arguments may be a selected sub-formula.  (As the above example
X! shows, the result of the subtraction is spliced back into the argument
X! which had the selection; if there were more than one selection involved,
X! this would not be well-defined.)  If you try to subtract two selections,
X! the command will abort with an error message.
X! 
X! Operations on sub-formulas sometimes leave the formula as a whole
X! in an ``un-natural'' state.  Consider negating the @samp{2 x} term
X! of our sample formula by selecting it and pressing @kbd{n}
X! (@code{calc-change-sign}).@refill
X! 
X! @example
X!         .. .                   .. .
X! 1*  .............     1*  ..............
X!     ...... . 2 x.         ...... . -2 x.
X! @end example
X! 
X! Unselecting the sub-formula reveals that the minus sign, which would
X! normally have cancelled out with the subtraction automatically, has
X! not been able to do so because the subtraction was not part of the
X! selected portion.  Pressing @kbd{=} (@code{calc-evaluate}) or doing
X! any other mathematical operation on the whole formula will cause it
X! to be simplified.
X! 
X! @example
X!          17 y                  17 y
X! 1:  --------------     1:  -------------
X!     sqrt(4 - -2 x)         sqrt(4 + 2 x)
X! @end example
X! 
X! @node Rearranging with Selections, , Operating on Selections, Selecting Subformulas
X! @subsection Rearranging Formulas using Selections
X! 
X! @kindex j R
X! @pindex calc-commute-right
X! The @kbd{j R} (@code{calc-commute-right}) command moves the selected
X! sub-formula to the right in its surrounding formula.  Generally the
X! selection is one term of a sum or product; the sum or product is
X! rearranged according to the commutative laws of algebra.
X! 
X! As with @kbd{j '} and @kbd{j DEL}, the term under the cursor is used
X! if there is no selection in the current formula.  All commands described
X! in this section share this property.  In this example, we place the
X! cursor on the @samp{a} and type @kbd{j R}, then repeat.
X! 
X! @example
X! 1:  a + b - c          1:  b + a - c          1:  b - c + a
X! @end example
X! 
X! Note that in the final step above, the @samp{a} is switched with
X! the @samp{c} but the signs are adjusted accordingly.  When moving
X! terms of sums and products, @kbd{j R} will never change the
X! mathematical meaning of the formula.
X! 
X! The selected term may also be an element of a vector or an argument
X! of a function.  The term is exchanged with the one to its right.
X! In this case, the ``meaning'' of the vector or function may of
X! course be drastically changed.
X! 
X! @example
X! 1:  [a, b, c]          1:  [b, a, c]          1:  [b, c, a]
X! 
X! 1:  f(a, b, c)         1:  f(b, a, c)         1:  f(b, c, a)
X! @end example
X! 
X! @kindex j L
X! @pindex calc-commute-left
X! The @kbd{j L} (@code{calc-commute-left}) command is like @kbd{j R}
X! except that it swaps the selected term with the one to its left.
X! 
X! With numeric prefix arguments, these commands move the selected
X! term several steps at a time.  It is an error to try to move a
X! term left or right past the end of its enclosing formula.
X! 
X! With numeric prefix arguments of zero, these commands move the
X! selected term as far as possible in the given direction, with
X! no possibility of signalling an error.
X! 
X! @kindex j D
X! @pindex calc-sel-distribute
X! The @kbd{j D} (@code{calc-sel-distribute}) command mixes the selected
X! sum or product into the surrounding formula using the distributive
X! law.  For example, in @samp{a * (b - c)} with the @samp{b - c}
X! selected, the result is @samp{a b - a c}.  This also distributes
X! products or quotients into surrounding powers, and can also do
X! transformations like @samp{exp(a + b)} to @samp{exp(a) exp(b)},
X! where @samp{a + b} is the selected term, and @samp{ln(a ^ b)}
X! to @samp{ln(a) b}, where @samp{a ^ b} is the selected term.
X! 
X! For multiple-term sums or products, @kbd{j D} takes off one term
X! at a time:  @samp{a * (b + c - d)} goes to @samp{a * (c - d) + a b}
X! with the @samp{c - d} selected so that you can type @kbd{j D}
X! repeatedly to expand completely.  The @kbd{j D} command allows a
X! numeric prefix argument which specifies the maximum number of
X! times to expand at once; the default is one time only.
X! 
X! The @kbd{j D} command is implemented using rewrite rules.
X! @xref{Selections with Rewrite Rules}.  The rules are stored in
X! the Calc variable @code{DistribRules}.  A convenient way to view
X! these rules is to put the name @code{DistribRules} on the stack,
X! then type @kbd{`} (@code{calc-edit}).  Press @key{RET} to return
X! from editing mode; be careful not to make any actual changes or
X! else you will affect the behavior of future @kbd{j D} commands!
X! 
X! To extend @kbd{j D} to handle new cases, just edit @code{DistribRules}
X! as described above.  You can then use the @kbd{Z V} command to save
X! this variable's value permanently for future Calc sessions.
X! 
X! @kindex j M
X! @pindex calc-sel-merge
X! The @kbd{j M} (@code{calc-sel-merge}) command is the complement
X! of @kbd{j D}; given @samp{a b - a c} with either @samp{a b} or
X! @samp{a c} selected, the result is @samp{a * (b - c)}.  Once
X! again, @kbd{j M} can also merge calls to functions like @code{exp}
X! and @code{ln}; examine the variable @code{MergeRules} to see all
X! the relevant rules.
X! 
X! @kindex j C
X! @pindex calc-sel-commute
X! The @kbd{j C} (@code{calc-sel-commute}) command swaps the arguments
X! of the selected sum, product, or equation.  It always behaves as
X! if @kbd{j b} mode were in effect, i.e., the sum @samp{a + b + c} is
X! treated as the nested sums @samp{(a + b) + c} by this command.
X! If you put the cursor on the first @samp{+}, the result is
X! @samp{(b + a) + c}; if you put the cursor on the second @samp{+}, the
X! result is @samp{c + (a + b)} (which the default simplifications
X! will rearrange to @samp{(c + a) + b}).  The relevant rules are stored
X! in the variable @code{CommuteRules}.
X! 
X! You may need to turn default simplifications off (with the @kbd{m O}
X! command) in order to get the full benefit of @kbd{j C}.  For example,
X! commuting @samp{a - b} produces @samp{-b + a}, but the default
X! simplifications will ``simplify'' this right back to @samp{a - b} if
X! you don't turn them off.  The same is true of some of the other
X! manipulations described in this section.
X! 
X! @kindex j N
X! @pindex calc-sel-negate
X! The @kbd{j N} (@code{calc-sel-negate}) command replaces the selected
X! term with the negative of that term, then adjusts the surrounding
X! formula in order to preserve the meaning.  For example, given
X! @samp{exp(a - b)} where @samp{a - b} is selected, the result is
X! @samp{1 / exp(b - a)}.  By contrast, selecting a term and using the
X! regular @kbd{n} (@code{calc-change-sign}) command negates the
X! term without adjusting the surroundings, thus changing the meaning
X! of the formula as a whole.  The rules variable is @code{NegateRules}.
X! 
X! @kindex j &
X! @pindex calc-sel-invert
X! The @kbd{j &} (@code{calc-sel-invert}) command is similar to @kbd{j N}
X! except it takes the reciprocal of the selected term.  For example,
X! given @samp{a - ln(b)} with @samp{b} selected, the result is
X! @samp{a + ln(1/b)}.  The rules variable is @code{InvertRules}.
X! 
X! @kindex j E
X! @pindex calc-sel-jump-equals
X! The @kbd{j E} (@code{calc-sel-jump-equals}) command moves the
X! selected term from one side of an equation to the other.  Given
X! @samp{a + b = c + d} with @samp{c} selected, the result is
X! @samp{a + b - c = d}.  This command also works if the selected
X! term is part of a @samp{*}, @samp{/}, or @samp{^} formula.  If the
X! term you wish to move is neither the first nor the last term
X! of its sum or product, you may need to use @kbd{j L} or @kbd{j R}
X! first to move it to one end.  The relevant rules variable is
X! @code{JumpRules}.
X! 
X! @kindex j I
X! @pindex calc-sel-isolate
X! The @kbd{j I} (@code{calc-sel-isolate}) command isolates the
X! selected term on its side of an equation.  It uses the @kbd{a S}
X! (@code{calc-solve-for}) command to solve the equation, and the
X! Hyperbolic flag affects it in the same way.  @xref{Calculus}.
X! When it applies, @kbd{j I} is often easier to use than @kbd{j E}.
X! It understands more rules of algebra, and works for inequalities
X! as well as equations.
X! 
X! @kindex j *
X! @kindex j /
X! @pindex calc-sel-mult-both-sides
X! @pindex calc-sel-div-both-sides
X! The @kbd{j *} (@code{calc-sel-mult-both-sides}) command prompts for a
X! formula using algebraic entry, then multiplies both sides of the
X! selected quotient or equation by that formula.  It simplifies each
X! side with @kbd{a s} (@code{calc-simplify}) before re-forming the
X! quotient or equation.  You can suppress this simplification by
X! providing any numeric prefix argument.  There is also a @kbd{j /}
X! (@code{calc-sel-div-both-sides}) which is similar to @kbd{j *} but
X! dividing instead of multiplying by the factor you enter.
X! 
X! If the selection is an inequality, @kbd{j *} and @kbd{j /} work
X! only if the formula you enter evaluates to a nonzero real number.
X! (The sense of the inequality is reversed if the number is negative.)
X! For selections that are not quotients, equations, or inequalities,
X! these commands pull out a multiplicative factor:  They divide (or
X! multiply) by the entered formula, simplify, then multiply (or divide)
X! back by the formula.
X! 
X! @kindex j +
X! @kindex j -
X! @pindex calc-sel-add-both-sides
X! @pindex calc-sel-sub-both-sides
X! The @kbd{j +} (@code{calc-sel-add-both-sides}) and @kbd{j -}
X! (@code{calc-sel-sub-both-sides}) commands analogously add to or
X! subtract from both sides of an equation or inequality.  For other
X! types of selections, they extract an additive factor.  A numeric
X! prefix argument suppresses simplification of the intermediate
X! results.
X! 
X! @kindex j U
X! @pindex calc-sel-unpack
X! The @kbd{j U} (@code{calc-sel-unpack}) command replaces the
X! selected function call with its argument.  For example, given
X! @samp{a + sin(x^2)} with @samp{sin(x^2)} selected, the result
X! is @samp{a + x^2}.  (The @samp{x^2} will remain selected; if you
X! wanted to change the @code{sin} to @code{cos}, just press @kbd{C}
X! now to take the cosine of the selected part.)
X! 
X! @kindex j v
X! @pindex calc-sel-evaluate
X! The @kbd{j v} (@code{calc-sel-evaluate}) command performs the
X! normal default simplifications on the selected sub-formula.
X! These are the simplifications that are normally done automatically
X! on all results, but which may have been partially inhibited by
X! previous selection-related operations, or turned off altogether
X! by the @kbd{m O} command.
X! 
X! With a numeric prefix argument of 2, @kbd{C-u 2 g v} applies
X! the @kbd{a s} (@code{calc-simplify}) command to the selected
X! sub-formula.  With a prefix argument of 3 or more, e.g., @kbd{C-u g v}
X! applies the @kbd{a e} (@code{calc-simplify-extended}) command.
X! @xref{Algebraic Manipulation}.
X! 
X! You can use the @kbd{j r} (@code{calc-rewrite-selection}) command
X! to define other algebraic operations on sub-formulas.  @xref{Rewrite Rules}.
X! 
X! @node Algebraic Manipulation, Calculus, Selecting Subformulas, Algebra
X  @section Algebraic Manipulation
X  
X+ The commands in this section perform general-purpose algebraic
X+ manipulations.  They work on the whole formula at the top of the
X+ stack (unless, of course, you have made a selection in that
X+ formula).
X+ 
X+ Many of these commands prompt for a variable name or formula.  If you
X+ answer the prompt with a blank line, the variable or formula is taken
X+ from top-of-stack, and the normal argument for the command is taken
X+ from the second-to-top stack level.
X+ 
X+ @kindex a v
X+ @pindex calc-alg-evaluate
X+ The @kbd{a v} (@code{calc-alg-evaluate}) command performs the normal
X+ default simplifications on a formula; for example, @samp{a - -b} is
X+ changed to @samp{a + b}.  These simplifications are normally done
X+ automatically on all Calc results, so this command is useful only if
X+ you have turned default simplifications off with an @kbd{m O}
X+ command.  @xref{Simplification Modes}.
X+ 
X  @kindex a s
X  @pindex calc-simplify
X! The @kbd{a s} (@code{calc-simplify}) [@code{simplify}] command applies
X! various algebraic rules to simplify a formula.  This includes rules which
X! are not part of the default simplifications because they may be too slow
X! to apply all the time, or may not be desirable all of the time.  For
X! example, non-adjacent terms of sums are combined, as in @samp{a + b + 2 a}
X! to @samp{b + 3 a}, and some formulas like @samp{sin(arcsin(x))} are
X! simplified to @samp{x}.
X  
X  @kindex a e
X  @pindex calc-simplify-extended
X! The @kbd{a e} (@code{calc-simplify-extended}) [@code{esimplify}] command
X! is like @kbd{a s}
X  except that it applies some additional simplifications which are not
X  ``safe'' in all cases.  For example, powers are simplified according
X  to the rule @samp{(a^b)^c = a^(b c)}, even though this is not always
X! true (consider @samp{sqrt(a^2)} for negative @samp{a}).  As another
X! example, equations of the form @samp{a x = b x} are simplified to
X! @samp{a = b} even though this is not valid if @samp{x} may be zero.
X! The symbolic
X  integrator uses @code{calc-simplify-extended}; one effect of this is
X  that the integrator's results must be used with caution.  Where an
X  integral table will often attach conditions like ``for positive @samp{a}
X! only,'' Calc (like most other symbolic integration programs) will simply
X! produce an unqualified result.@refill
X  
X  @kindex a x
X  @pindex calc-expand
X***************
X*** 7195,7201 ****
X  The @kbd{a x} (@code{calc-expand}) command expands an expression by
X  applying the distributive law.  It applies to products, quotients, and
X  powers involving sums.  By default, it fully distributes all parts of
X! the expression.  With the a numeric prefix argument, the distributive
X  law is applied only the specified number of times, then the partially
X  expanded expression is left on the stack.
X  
X--- 11490,11496 ----
X  The @kbd{a x} (@code{calc-expand}) command expands an expression by
X  applying the distributive law.  It applies to products, quotients, and
X  powers involving sums.  By default, it fully distributes all parts of
X! the expression.  With a numeric prefix argument, the distributive
X  law is applied only the specified number of times, then the partially
X  expanded expression is left on the stack.
X  
X***************
X*** 7223,7229 ****
X  @pindex calc-substitute
X  The @kbd{a b} (@code{calc-substitute}) command substitutes occurrences
X  of some variable or sub-expression of an expression with a new
X! sub-expression.  For example, substituting @samp{sin(x)} to @samp{cos(y)}
X  in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces
X  @samp{2 cos(y)^2 + x cos(y) + sin(2 x)}.
X  Note that this is a purely structural substitution; the lone @code{x} and the
X--- 11518,11524 ----
X  @pindex calc-substitute
X  The @kbd{a b} (@code{calc-substitute}) command substitutes occurrences
X  of some variable or sub-expression of an expression with a new
X! sub-expression.  For example, substituting @samp{sin(x)} with @samp{cos(y)}
X  in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces
X  @samp{2 cos(y)^2 + x cos(y) + sin(2 x)}.
X  Note that this is a purely structural substitution; the lone @code{x} and the
X***************
X*** 7245,7391 ****
X  because the @samp{+} operator is left-associative, so the ``deep
X  structure'' of that formula is @samp{(x+y) + z}.  Use @kbd{d U}
X  (@code{calc-unformatted-language}) mode to see the true structure of
X! a formula.
X  
X! @node Rewrite Rules, Logical Operations, Algebraic Manipulation, Algebra
X! @section Rewrite Rules
X  
X! @cindex Rewrite rules
X! @cindex Transformations
X! @cindex Pattern matching
X! @kindex a r
X! @pindex calc-rewrite
X! The @kbd{a r} (@code{calc-rewrite}) command makes substitutions in a
X! formula according to a specified pattern or patterns.  It is like a
X! generalized version of @code{calc-substitute}.  You provide Calc with
X! one or more @dfn{rewrite rules}, which take the form of vectors of
X! two or three elements:  @samp{[old, new]} or @samp{[old, new, cond]}.
X! To specify a set of rules, make a vector of rule vectors.  (Calc will
X! interpret this structure as a matrix as long as the rules either all
X! include or all omit the @samp{cond} part.  Whether or not this is true
X! makes no difference to @code{calc-rewrite} itself.)
X  
X! When you are prompted to enter the rewrite rules, you can either type
X! the vector directly (as an algebraic entry), or type the name of a
X! Calc variable into which you have stored a rules vector, or enter
X! a blank line in which case the rules vector will be taken from the
X! top of the stack.  It is most convenient to store rules you use often
X! in a variable and invoke them by naming the variable.  You may also
X! wish to use @kbd{Z V} (@code{calc-permanent-variable}) to save the
X! rules permanently; @pxref{Storing Variables}.
X  
X! To match a particular formula @samp{x} with a particular rule vector
X! @samp{[old, new]}, Calc compares the structure of @samp{x} with the
X! structure of @samp{old}.  Variables that appear in @samp{old} are
X! treated as ``meta-variables''; the corresponding positions in @samp{x}
X! may contain any sub-formulas.  For example, the pattern @samp{f(x,y)}
X! would match the expression @samp{f(12, a+1)} with the meta-variable
X! @samp{x} corresponding to 12 and with @samp{y} corresponding to
X! @samp{a+1}.  However, this pattern would not match @samp{f(12)} or
X! @samp{g(12, a+1)}, since there is no assignment of the meta-variables
X! that will allow the pattern to match these expressions.  Notice that
X! if the pattern is a single variable, it will match any expression.
X  
X! If a given meta-variable appears more than once in @var{old}, the
X! corresponding sub-formulas of @samp{x} must be identical.  Thus
X! the pattern @samp{f(x,x)} would match @samp{f(12, 12)} and
X! @samp{f(a+1, a+1)} but not @samp{f(12, a+1)} or @samp{f(12, 12.0)}.
X  
X! Things other than variables must match exactly between the pattern
X! and the target formula.  To match a particular variable, use the
X! pseudo-function @samp{quote(v)} in the pattern.  For example, the
X! pattern @samp{x+quote(y)} matches @samp{x+y}, @samp{2+y}, or
X! @samp{sin(x)+y}.
X  
X! Pattern-matching is completely structural, not taking the algebraic
X! properties of formulas into account.  Thus @samp{f(x+1)} matches
X! the formula @samp{f(a+1)} but not @samp{f(a)}, @samp{f(a+2)}, or
X! @samp{f(1+a)}.  For other examples @pxref{Algebraic Manipulation},
X! under the discussion of @code{calc-substitute}.@refill
X  
X! If the @samp{old} pattern is found to match a given formula, that
X! formula is replaced by @samp{new}, where any occurrences in @samp{new}
X! of meta-variables from the pattern are replaced with the sub-formulas
X! that they matched.  Thus, applying the rule @samp{[f(x,y), g(y+x,x)]}
X! to @samp{f(12, a+1)} would produce @samp{g(a+13, 12)}.
X  
X! If a @samp{cond} part is also present in the rule, this is an
X! additional condition that must be satisfied before the rule is
X! accepted.  Once @samp{old} has been successfully matched to the
X! target expression, @samp{cond} is evaluated (with the meta-variables
X! substituted for the values they matched) and simplified with
X! @code{calc-simplify}.  If the result is a nonzero number, the rule
X! is accepted.  If the result is zero or if it is still a symbolic
X! formula, the rule is rejected.  @xref{Logical Operations}, for a
X! number of functions that return 1 or 0 according to the result of
X! some test.  For example, the formula @samp{n > 0} simplifies to
X! 1 or 0 if @samp{n} is a replaced by a positive or nonpositive
X! number, respectively.  Thus, the rule @samp{[f(x,y), g(y+x,x), x+y > 0]}
X! would be applied to @samp{f(0, 4)} but not to @samp{f(-3, 2)} or
X! @samp{f(12, a+1)}.  (In the former case, the condition can be shown
X! not to be satisfied; in the latter case, the condition merely cannot
X! be shown to be satisfied, but that is enough to reject the rule.)
X  
X! When @code{calc-rewrite} is used, it takes an expression from the
X! top of the stack and attempts to match any of the specified rules
X! to any part of the expression, starting with the whole expression
X! and then, if that fails, trying deeper and deeper sub-expressions.
X! For each part of the expression, the rules are tried in the
X! specified order.  The first rule to match the first sub-expression
X! wins; it replaces the matched sub-expression according to the
X! @samp{new} part of the rule.  By default, only one substitution
X! is made per @code{calc-rewrite} command.
X  
X! Given a positive numeric prefix argument, @code{calc-rewrite} will
X! perform up to that many substitutions before stopping.  First, the
X! top-level formula is matched and substituted repeatedly until it
X! no longer matches the pattern; then, sub-formulas are tried, and
X! so on.  If the limit still has not been reached, the top-level
X! formula is check again (in case a substitution of one of its
X! arguments causes it again to match).  This continues until no
X! further matches can be made, or until the limit is reached.
X  
X! Given a negative numeric prefix argument, @code{calc-rewrite} will
X! match and substitute the top-level expression up to that many times,
X! but will not attempt to match any sub-expressions.
X  
X! A prefix argument of zero is equivalent to a prefix of 25.  This is
X! meant to be a convenient limit that is usually enough to finish the
X! job, but not enough to be too slow in case the rule transformations
X! get into an infinite loop.
X  
X! As a larger example, suppose we wish to substitute the pattern
X! @samp{sin(x)^2 + cos(x)^2} with 1 in a given expression.  The rule
X! @samp{[sin(x)^2 + cos(x)^2, 1]} would work, but only for the most
X! literal matches.  This would miss the formula @samp{2 sin(a)^2 + 2
X! cos(a)^2}, for example, because our pattern does not account for both
X! terms being multiplied by an equal factor.  A more flexible solution
X! would be to use the rule @samp{[cos(x)^2, 1 - sin(x)^2]}, followed by
X! algebraic simplification if necessary.@refill
X! 
X! Similarly, the pattern @samp{[f(x, x+1), g(x)]} is not a very reliable
X! rule since it fails to match in cases like @samp{f(2, 3)}.  A better
X! rule would be @samp{[f(x,y), g(x), y=x+1]}, since the algebraic
X! simplifier is applied to conditions but not to patterns.
X  
X! As another example, we could define our own factorial function with the
X! rules @samp{[[f(0), 1], [f(n), n*f(n-1), n>0]]}.  Enter this rules
X! vector and store it in a variable: @kbd{s factrules}.  Now, given a
X! factorial formula like @samp{f(5)} on the stack, type @samp{C-u 0 a r
X! factrules} to apply these rules repeatedly.  After six applications,
X! @code{calc-rewrite} will stop with 120 on the stack.  If we expect to
X! use these rules often, we could define the above sequence of keystrokes
X! as a keyboard macro.  We could then assign this macro to a single
X! key sequence which effectively means, ``simplify all calls to the function
X! @samp{f} on top-of-stack.''  @xref{Keyboard Macros}.@refill
X  
X! @node Logical Operations, Calculus, Rewrite Rules, Algebra
X  @section Logical Operations
X  
X  The following commands and algebraic functions return true/false values,
X  where 1 represents ``true'' and 0 represents ``false.''  In cases where
X  a truth value is required (such as for the condition part of a rewrite
X! rule), any nonzero number is accepted to mean ``true.''
X  
X  @kindex a =
X  @pindex calc-equal-to
X--- 11540,11840 ----
X  because the @samp{+} operator is left-associative, so the ``deep
X  structure'' of that formula is @samp{(x+y) + z}.  Use @kbd{d U}
X  (@code{calc-unformatted-language}) mode to see the true structure of
X! a formula.  The rewrite rule mechanism, discussed next, does not have
X! these limitations.
X  
X! @node Calculus, Numerical Solutions, Algebraic Manipulation, Algebra
X! @section Calculus
X  
X! The following calculus commands do not automatically simplify their
X! inputs or outputs using @code{calc-simplify}.  You may find it helps
X! to do this by hand by typing @kbd{a s} or @kbd{a e}.  It may also help
X! to use @kbd{a x} and/or @kbd{a c} to arrange a result in the most
X! readable way.
X  
X! @kindex a d
X! @kindex H a d
X! @pindex calc-derivative
X! @tindex deriv
X! @tindex tderiv
X! The @kbd{a d} (@code{calc-derivative}) [@code{deriv}] command computes
X! the derivative of the expression on the top of the stack with respect to
X! some variable, which it will prompt you to enter.  Normally, variables
X! in the formula other than the specified differentiation variable are
X! considered constant, i.e., @samp{deriv(y,x)} is reduced to zero.  With
X! the Hyperbolic flag, the @code{tderiv} (total derivative) operation is used
X! instead, in which derivatives of variables are not reduced to zero.
X  
X! With a numeric prefix argument @var{n}, this computes the @var{n}th
X! derivative.
X  
X! If you use the @code{deriv} function directly in an algebraic formula,
X! you can also write @samp{deriv(f,x,x0)} which represents the derivative
X! of @code{f} with respect to @code{x}, evaluated at the point @samp{x=x0}.
X  
X! If the formula being differentiated contains functions which Calc does
X! not know, the derivatives of those functions are produced by adding
X! primes (apostrophe characters).  For example, @samp{deriv(f(2x), x)}
X! produces @samp{2 f'(2 x)}, where the function @code{f'} represents the
X! derivative of @code{f}.  If you enter a definition for @code{f'}, for
X! example using the @kbd{Z F} (@code{calc-user-define-formula}) command,
X! the Calculator will use it.  @xref{Algebraic Definitions}.
X  
X! For multi-argument functions @samp{f(x,y,z)}, the derivative with respect
X! to the first argument is written @samp{f'(x,y,z)}; derivatives with
X! respect to the other arguments are @samp{f'2(x,y,z)} and @samp{f'3(x,y,z)}.
X! Various higher-order derivatives can be formed in the obvious way, e.g.,
X! @samp{f'@var{}'(x)} (the second derivative of @code{f}) or
X! @samp{f'@var{}'2'3(x,y,z)} (@code{f} differentiated with respect to each
X! argument once).@refill
X  
X! @kindex a i
X! @pindex calc-integral
X! @tindex integ
X! The @kbd{a i} (@code{calc-integral}) [@code{integ}] command computes the
X! indefinite integral of the expression on the top of the stack with
X! respect to a variable.  The integrator is not guaranteed to work for
X! all integrable functions, but it will work for any polynomial and for
X! most simple functions.
X  
X! If you use the @code{integ} function directly in an algebraic formula,
X! you can also write @samp{integ(f,x,v)} which expresses the resulting
X! indefinite integral in terms of variable @code{v} instead of @code{x},
X! or @samp{integ(f,x,a,b)}, which represents a definite integral from
X! @code{a} to @code{b}.
X  
X! The Calculator remembers all the integrals it has done.  If conditions
X! change in a way that would invalidate the old integrals, they will be
X! thrown out.  If you suspect this is not happening when it should,
X! use the @code{calc-flush-caches} command; @pxref{Caches}.
X  
X! @kindex a I
X! @pindex calc-integral-limit
X! The @kbd{a I} (@code{calc-integral-limit}) command displays or, with a
X! numeric prefix argument, sets the current ``integration nesting limit.''
X! This is the depth to which Calc will pursue integration by substitution
X! or integration by parts before abandoning an approach as fruitless.
X! The default value is 3.  If the integrator is taking too long, you
X! might consider lowering this limit.  However, the lower this limit is,
X! the greater the chance that Calc will be unable to integrate a function
X! it could otherwise handle.  Raising this limit allows the Calculator to
X! solve more integrals, though the time it takes may grow exponentially.
X! You can monitor the integrator's actions by creating an Emacs buffer called
X! @code{*Trace*}.  If such a buffer exists, the @kbd{a i} command will write
X! a log of its actions there.
X  
X! @kindex a t
X! @pindex calc-taylor
X! @tindex taylor
X! The @kbd{a t} (@code{calc-taylor}) [@code{taylor}] command computes a
X! power series expansion or Taylor series of a function.  You specify the
X! variable and the desired number of terms.  You may give an expression of
X! the form @samp{@var{var} = @var{a}} or @samp{@var{var} - @var{a}} to
X! produce a Taylor expansion about the point @var{a}.  You may specify the
X! number of terms with a numeric prefix argument; otherwise the command
X! will prompt you for the number of terms.  Note that many series
X! expansions have coefficients of zero for some terms, so you may appear
X! to get fewer terms than you asked for.@refill
X  
X! If the @kbd{a i} command is unable to find a symbolic integral for a
X! function, you can get an approximation by integrating the function's
X! Taylor series.
X  
X! @kindex a S
X! @pindex calc-solve-for
X! @tindex solve
X! The @kbd{a S} (@code{calc-solve-for}) [@code{solve}] command rearranges
X! an equation to solve for a specific variable.  An equation is an
X! expression of the form @samp{L = R}.  For example, the command @kbd{a S x}
X! will rearrange @samp{y = 3x + 6} to the form, @samp{x = y/3 - 2}.  If the
X! input is not an equation, it is treated like an equation of the
X! form @samp{X = 0}.
X  
X! This command also works for inequalities, as in @samp{y < 3x + 6}.
X! Some inequalities cannot be solved where the analogous equation could
X! be; for example, solving @samp{a < b c} for @samp{b} is impossible
X! without knowing the sign of @samp{c}.  In this case, @kbd{a S} will
X! produce the result @samp{b != a/c} (using the not-equal-to operator)
X! to signify that the direction of the inequality was unknown.  The
X! inequality @samp{a <= b c} is not even partially solved.
X! 
X! @kindex H a S
X! @tindex fsolve
X! Some equations have more than one solution.  The Hyperbolic flag
X! (@code{H a S}) [@code{fsolve}] tells the solver to report the fully
X! general family of solutions.  It will invent variables @code{n1},
X! @code{n2}, @dots{}, which represent independent arbitrary integers, and
X! @code{s1}, @code{s2}, @dots{}, which represent independent arbitrary
X! signs (either @samp{+1} or @samp{-1}).  If you don't use the Hyperbolic
X! flag, Calc will use zero in place of all arbitrary integers, and plus
X! one in place of all arbitrary signs.  Note that variables like @code{n1}
X! and @code{s1} are not given any special interpretation in Calc except by
X! @code{calc-solve-for} itself.  As usual, you can use the @code{calc-let}
X! command to obtain solutions for various actual values of these
X! variables.
X! 
X! @kindex I a S
X! @kindex H I a S
X! @tindex finv
X! @tindex ffinv
X! With the Inverse flag, @kbd{I a S} [@code{finv}] treats the expression
X! on top of the stack as a function of the specified variable and solves
X! to find the inverse function, written in terms of the same variable.
X! For example, @kbd{I a S x} inverts @samp{2x + 6} to @samp{x/2 - 3}.
X! You can use both Inverse and Hyperbolic [@code{ffinv}] to obtain a
X! fully general inverse, as described above.
X! 
X! @node Numerical Solutions, Logical Operations, Calculus, Algebra
X! @section Numerical Solutions
X  
X! Not all equations can be solved symbolically.  The commands in this
X! section use numerical algorithms that can find a solution to a specific
X! instance of an equation to any desired accuracy.  Note that these
X! commands are slower than their algebraic cousins; it is a good idea
X! to try @kbd{a S} before resorting to @kbd{a R}.
X! 
X! @kindex a R
X! @pindex calc-find-root
X! @tindex root
X! @cindex Newton's method
X! @cindex Roots of equations
X! @cindex Numerical root-finding
X! The @kbd{a R} (@code{calc-find-root}) [@code{root}] command finds a
X! numerical solution (or @dfn{root}) of an equation.  (This command treats
X! inequalities the same as equations.  If the input is any other kind
X! of formula, it is interpreted as an equation of the form @samp{X = 0}.)
X! 
X! The @kbd{a R} command requires an initial guess on the top of the
X! stack, and a formula in the second-to-top position.  It prompts for a
X! solution variable, which must appear in the formula.  All other variables
X! that appear in the formula must have assigned values, i.e., when
X! a value is assigned to the solution variable and the formula is
X! evaluated with @kbd{=}, it should evaluate to a number.  Any assigned
X! value for the solution variable itself is ignored and unaffected by
X! this command.
X! 
X! When the command completes, the initial guess is replaced on the stack
X! by a vector of two numbers:  The value of the solution variable that
X! solves the equation, and the difference between the lefthand and
X! righthand sides of the equation at that value.  Ordinarily, the second
X! number will be zero or very nearly zero.  (Note that Calc uses a
X! slightly higher precision while finding the root, and thus the second
X! number may be slightly different from the value you would compute from
X! the equation yourself.)
X! 
X! The initial guess can be a real number, in which case Calc searches
X! for a real solution near that number, or a complex number, in which
X! case Calc searches the whole complex plane near that number for a
X! solution, or it can be an interval form which restricts the search
X! to values inside that interval of real numbers.
X! 
X! Calc tries to use @kbd{a d} to take the derivative of the equation.
X! If this succeeds, it uses Newton's method.  If the equation is not
X! differentiable Calc uses a bisection method.  (If Newton's method
X! appears to be going astray, Calc switches over to bisection if it
X! can, or otherwise gives up.  In this case it may help to try again
X! with a slightly different initial guess.)  If the initial guess is a
X! complex number, the function must be differentiable.
X! 
X! If the formula (or the difference between the sides of an equation)
X! is negative at one end of the interval you specify and positive at
X! the other end, the root finder is guaranteed to find a root if there
X! is one.  Otherwise, Calc subdivides the interval into small parts
X! looking for positive and negative values to bracket the root.  If your
X! guess is an interval, Calc will not look outside that interval for a root.
X! 
X! @kindex H a R
X! @tindex wroot
X! The @kbd{H a R} [@code{wroot}] command is similar to @kbd{a R}, except
X! that if the initial guess is an interval for which the function has
X! the same sign at both ends, then rather than subdividing the interval
X! Calc attempts to widen it to enclose a root.  Use this mode if
X! you are not sure if the function has a root in your interval.
X! 
X! If the function is not differentiable, and you give a simple number
X! instead of an interval as your initial guess, Calc uses this widening
X! process even if you did not type the Hyperbolic flag.  (If the function
X! @emph{is} differentiable, Calc uses Newton's method which does not
X! require a bounding interval in order to work.)
X! 
X! @cindex Systems of equations, solving numerically
X! The @kbd{a R} command can also solve systems of equations.  In this
X! case, the equation should instead be a vector of equations, the
X! guess should instead be a vector of numbers (intervals are not
X! supported), and the variable should be a vector of variables.  You
X! can omit the brackets while entering the list of variables.  Each
X! equation must be differentiable by each variable for this mode to
X! work.  The result will be a vector of two vectors:  The variable
X! values that solved the system of equations, and the differences
X! between the sides of the equations with those variable values.
SHAR_EOF
echo "End of part 17, continue with part 18"
echo "18" > s2_seq_.tmp
exit 0
--
Dave Gillespie
  256-80 Caltech Pasadena CA USA 91125
  daveg@csvax.cs.caltech.edu, ...!cit-vax!daveg