[comp.sources.misc] v15i044: Patch for GNU Emacs Calc, version 1.04 -> 1.05, part 17/20

daveg@csvax.cs.caltech.edu (David Gillespie) (10/15/90)

Posting-number: Volume 15, Issue 44
Submitted-by: daveg@csvax.cs.caltech.edu (David Gillespie)
Archive-name: calc-1.05/part17

#!/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