home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-31 | 55.5 KB | 1,257 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i086: gnucalc - GNU Emacs Calculator, v2.00, Part38/56
- Message-ID: <1991Oct31.214656.2773@sparky.imd.sterling.com>
- X-Md4-Signature: cc12ad4ca461f596619fbe0135426c34
- Date: Thu, 31 Oct 1991 21:46:56 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 86
- Archive-name: gnucalc/part38
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 38; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- there is no solution to this equation (which can happen only when
- @cite{M} is non-prime), or if any of the arguments are non-integers, the
- division is left in symbolic form. Other operations, such as square
- roots, are not yet supported for modulo forms. (Note that, although
- @w{`@t{(}@i{a} @t{mod} @i{M}@t{)^.5}'} will compute a ``modulo square root''
- in the sense of reducing @c{$\sqrt a$}
- @cite{sqrt(a)} modulo @cite{M}, this is not a
- useful definition from the number-theoretical point of view.)@refill
- X
- @kindex M (modulo forms)
- @tindex mod (operator)
- To create a modulo form during numeric entry, press the shift-@kbd{M}
- key to enter the word @samp{mod}. As a special convenience, pressing
- shift-@kbd{M} a second time automatically enters the value of @cite{M}
- that was most recently used before. During algebraic entry, either
- type @samp{mod} by hand or press @kbd{M-m} (that's @kbd{@key{META}-m}).
- Once again, pressing this a second time enters the current modulo.@refill
- X
- You can also use @code{calc-pack} and @kbd{%} to modify modulo forms.
- @xref{Building Vectors}. @xref{Basic Arithmetic}.
- X
- It is possible to mix HMS forms and modulo forms. For example, an
- HMS form modulo 24 could be used to manipulate clock times; an HMS
- form modulo 360 would be suitable for angles. Making the modulo @cite{M}
- also be an HMS form eliminates troubles that would arise if the angular
- mode were inadvertently set to Radians, in which case
- @w{@samp{2@@ 0' 0" mod 24}} would be interpreted as two degrees modulo
- 24 radians!
- X
- Modulo forms cannot have variables or formulas for components. If you
- enter the formula @samp{(x + 2) mod 5}, Calc propagates the modulus
- to each of the coefficients: @samp{(1 mod 5) x + (2 mod 5)}.
- X
- @tindex makemod
- The algebraic function @samp{makemod(a, m)} builds the modulo form
- @w{@samp{a mod m}}.
- X
- @node Error Forms, Interval Forms, Modulo Forms, Data Types
- @section Error Forms
- X
- @noindent
- @cindex Error forms
- @cindex Standard deviations
- An @dfn{error form} is a number with an associated standard
- deviation, as in @samp{2.3 +/- 0.12}. The notation
- `@i{x} @t{+/-} @c{$\sigma$}
- @asis{sigma}' stands for an uncertain value which follows a normal or
- Gaussian distribution of mean @cite{x} and standard deviation or
- ``error'' @c{$\sigma$}
- @cite{sigma}. Both the mean and the error can be either numbers or
- formulas. Generally these are real numbers but the mean may also be
- complex. If the error is negative or complex, it is changed to its
- absolute value. An error form with zero error is converted to a
- regular number by the Calculator.@refill
- X
- All arithmetic and transcendental functions accept error forms as input.
- Operations on the mean-value part work just like operations on regular
- numbers. The error part for any function @cite{f(x)} (such as @c{$\sin x$}
- @cite{sin(x)})
- is defined by the error of @cite{x} times the derivative of @cite{f}
- evaluated at the mean value of @cite{x}. For a two-argument function
- @cite{f(x,y)} (such as addition) the error is the square root of the sum
- of the squares of the errors due to @cite{x} and @cite{y}.
- @tex
- $$ \eqalign{
- X f(x \hbox{\code{ +/- }} \sigma)
- X &= f(x) \hbox{\code{ +/- }} \sigma \left| {df(x) \over dx} \right| \cr
- X f(x \hbox{\code{ +/- }} \sigma_x, y \hbox{\code{ +/- }} \sigma_y)
- X &= f(x,y) \hbox{\code{ +/- }}
- X \sqrt{\left(\sigma_x \left| {\partial f(x,y) \over \partial x}
- X \right| \right)^2
- X +\left(\sigma_y \left| {\partial f(x,y) \over \partial y}
- X \right| \right)^2 } \cr
- } $$
- @end tex
- Note that this
- definition assumes the errors in @cite{x} and @cite{y} are uncorrelated.
- A side effect of this definition is that @samp{(2 +/- 1) * (2 +/- 1)}
- is not the same as @samp{(2 +/- 1)^2}; the former represents the product
- of two independent values which happen to have the same probability
- distributions, and the latter is the product of one random value with itself.
- The former will produce an answer with less error, since on the average
- the two independent errors can be expected to cancel out.@refill
- X
- Consult a good text on error analysis for a discussion of the proper use
- of standard deviations. Actual errors often are neither Gaussian-distributed
- nor uncorrelated, and the above formulas are valid only when errors
- are small. As an example, the error arising from
- `@t{sin(}@i{x} @t{+/-} @c{$\sigma$}
- @i{sigma}@t{)}' is
- `@c{$\sigma$}
- @i{sigma} @t{abs(cos(}@i{x}@t{))}'. When @cite{x} is close to zero,
- @c{$\cos x$}
- @cite{cos(x)} is
- close to one so the error in the sine is close to @c{$\sigma$}
- @cite{sigma}; this makes sense, since @c{$\sin x$}
- @cite{sin(x)} is approximately @cite{x} near zero, so a given
- error in @cite{x} will produce about the same error in the sine. Likewise,
- near 90 degrees @c{$\cos x$}
- @cite{cos(x)} is nearly zero and so the computed error is
- small: The sine curve is nearly flat in that region, so an error in @cite{x}
- has relatively little effect on the value of @c{$\sin x$}
- @cite{sin(x)}. However, consider
- @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so Calc will report
- zero error! We get an obviously wrong result because we have violated
- the small-error approximation underlying the error analysis. If the error
- in @cite{x} had been small, the error in @c{$\sin x$}
- @cite{sin(x)} would indeed have been negligible.@refill
- X
- @kindex p (error forms)
- @tindex +/-
- To enter an error form during regular numeric entry, use the @kbd{p}
- (``plus-or-minus'') key to type the @samp{+/-} symbol. (If you try actually
- typing @samp{+/-} the @kbd{+} key will be interpreted as the Calculator's
- @kbd{+} command!) Within an algebraic formula, you can press @kbd{M-p} to
- type the @samp{+/-} symbol, or type it out by hand.
- X
- Error forms and complex numbers can be mixed; the formulas shown above
- are used for complex numbers, too, except that if the error part evaluates
- to a complex number its absolute value (or the square root of the sum of
- the squares of the absolute values of the two error contributions) is
- used. Mathematically, this corresponds to a radially symmetric Gaussian
- distribution of numbers on the complex plane. However, note that Calc
- considers an error form with real components to represent a real number,
- not a complex distribution around a real mean.
- X
- Error forms may also be composed of HMS forms. For best results, both
- the mean and the error should be HMS forms if either one is.
- X
- @tindex sdev
- The algebraic function @samp{sdev(a, b)} builds the error form @samp{a +/- b}.
- X
- @node Interval Forms, Incomplete Objects, Error Forms, Data Types
- @section Interval Forms
- X
- @noindent
- @cindex Interval forms
- An @dfn{interval} is a subset of consecutive real numbers. For example,
- the interval @samp{[2 ..@: 4]} represents all the numbers from 2 to 4,
- inclusive. If you multiply it by the interval @samp{[0.5 ..@: 2]} you
- obtain @samp{[1 ..@: 8]}. This calculation represents the fact that if
- you multiply some number in the range @samp{[2 ..@: 4]} by some other
- number in the range @samp{[0.5 ..@: 2]}, your result will lie in the range
- from 1 to 8. Interval arithmetic is used to get a worst-case estimate
- of the possible range of values a computation will produce, given the
- set of possible values of the input.
- X
- @ifinfo
- Calc supports several varieties of intervals, including @dfn{closed}
- intervals of the type shown above, @dfn{open} intervals such as
- @samp{(2 ..@: 4)}, which represents the range of numbers from 2 to 4
- @emph{exclusive}, and @dfn{semi-open} intervals in which one end
- uses a round parenthesis and the other a square bracket. In mathematical
- terms,
- @samp{[2 ..@: 4]} means @cite{2 <= x <= 4}, whereas
- @samp{[2 ..@: 4)} represents @cite{2 <= x < 4},
- @samp{(2 ..@: 4]} represents @cite{2 < x <= 4}, and
- @samp{(2 ..@: 4)} represents @cite{2 < x < 4}.@refill
- @end ifinfo
- @tex
- Calc supports several varieties of intervals, including \dfn{closed}
- intervals of the type shown above, \dfn{open} intervals such as
- \samp{(2 ..\: 4)}, which represents the range of numbers from 2 to 4
- \emph{exclusive}, and \dfn{semi-open} intervals in which one end
- uses a round parenthesis and the other a square bracket. In mathematical
- terms,
- $$ \eqalign{
- X [2 \hbox{\cite{..}} 4] &\quad\hbox{means}\quad 2 \le x \le 4 \cr
- X [2 \hbox{\cite{..}} 4) &\quad\hbox{means}\quad 2 \le x < 4 \cr
- X (2 \hbox{\cite{..}} 4] &\quad\hbox{means}\quad 2 < x \le 4 \cr
- X (2 \hbox{\cite{..}} 4) &\quad\hbox{means}\quad 2 < x < 4 \cr
- } $$
- @end tex
- X
- The lower and upper limits of an interval must be either real numbers
- (or HMS or date forms), or symbolic expressions which are assumed to be
- real-valued, or @samp{-inf} and @samp{inf}. In general the lower limit
- must be less than the upper limit. A closed interval containing only
- one value, @samp{[3 ..@: 3]}, is converted to a plain number (3)
- automatically. An interval containing no values at all (such as
- @samp{[3 ..@: 2]} or @samp{[2 ..@: 2)}) can be represented but is not
- guaranteed to behave well when used in arithmetic. Note that the
- interval @samp{[3 .. inf)} represents all real numbers greater than
- or equal to 3, and @samp{(-inf .. inf)} represents all real numbers.
- In fact, @samp{[-inf .. inf]} represents all real numbers including
- infinity.
- X
- Intervals are entered in the notation shown here, either as algebraic
- formulas, or using incomplete forms. (@xref{Incomplete Objects}.)
- In algebraic formulas, multiple periods in a row are collected from
- left to right, so that @samp{1....1e2} is interpreted as @samp{1 ..@: ..@: 1e2}
- (a syntax error) rather than @samp{1.@: ..@: .1e2}. Use spaces or type
- @samp{1.0..0.1e2} to make the notation unambiguous. If you omit
- the lower or upper limit, a default of @samp{-inf} or @samp{inf}
- (respectively) is furnished.
- X
- ``Infinite mode'' also affects operations on intervals
- (@pxref{Infinities}). Calc will always introduce an open infinity,
- as in @samp{1 / (0 .. 2] = [0.5 .. inf)}. But closed infinities,
- @samp{1 / [0 .. 2] = [0.5 .. inf]}, arise only in infinite mode;
- otherwise they are left unevaluated. Note that the ``direction'' of
- a zero is not an issue in this case, since the zero is always assumed
- to be continuous with the rest of the interval. For intervals that
- contain zero inside them Calc is forced to give the result,
- @samp{1 / (-2 .. 2) = [-inf .. inf]}.
- X
- While it may seem that intervals and error forms are similar, they are
- based on entirely different concepts of inexact quantities. An error
- form `@i{x} @t{+/-} @c{$\sigma$}
- @i{sigma}' means a variable is random, and its value could
- be anything but is ``probably'' within one @c{$\sigma$}
- @i{sigma} of the mean value @cite{x}.
- An interval `@t{[}@i{a} @t{..@:} @i{b}@t{]}' means a variable's value
- is unknown, but guaranteed to lie in the specified range. Error forms
- are statistical or ``average case'' approximations; interval arithmetic
- tends to produce ``worst case'' bounds on an answer.@refill
- X
- Intervals may not contain complex numbers, but they may contain
- HMS forms or date forms.
- X
- @xref{Set Operations}, for commands that interpret interval forms
- as subsets of the set of real numbers.
- X
- @tindex intv
- The algebraic function @samp{intv(n, a, b)} builds an interval form
- from @samp{a} to @samp{b}; @samp{n} is an integer code which must
- be 0 for @samp{(..)}, 1 for @samp{(..]}, 2 for @samp{[..)}, or
- 3 for @samp{[..]}.
- X
- @node Incomplete Objects, Variables, Interval Forms, Data Types
- @section Incomplete Objects
- X
- @noindent
- @kindex [
- @kindex ]
- @kindex (
- @kindex )
- @kindex ,
- @kindex ;
- @cindex Incomplete vectors
- @cindex Incomplete complex numbers
- @cindex Incomplete interval forms
- When @kbd{(} or @kbd{[} is typed to begin entering a complex number or
- vector, respectively, the effect is to push an @dfn{incomplete} complex
- number or vector onto the stack. The @kbd{,} key adds the value(s) at
- the top of the stack onto the current incomplete object. The @kbd{)}
- and @kbd{]} keys ``close'' the incomplete object after adding any values
- on the top of the stack in front of the incomplete object.
- X
- As a result, the sequence of keystrokes @kbd{[ 2 , 3 @key{RET} 2 * , 9 ]}
- pushes the vector @samp{[2, 6, 9]} onto the stack. Likewise, @kbd{( 1 , 2 Q )}
- pushes the complex number @samp{(1, 1.414)} (approximately).
- X
- If several values lie on the stack in front of the incomplete object,
- all are collected and appended to the object. Thus the @kbd{,} key
- is redundant: @kbd{[ 2 @key{RET} 3 @key{RET} 2 * 9 ]}. Some people
- prefer the equivalent @key{SPC} key to @key{RET}.@refill
- X
- As a special case, typing @kbd{,} immediately after @kbd{(}, @kbd{[}, or
- @kbd{,} adds a zero or duplicates the preceding value in the list being
- formed. Typing @key{DEL} during incomplete entry removes the last item
- from the list.
- X
- The @kbd{;} key is used in the same way as @kbd{,} to create polar complex
- numbers: @kbd{( 1 ; 2 )}. When entering a vector, @kbd{;} is useful for
- creating a matrix. In particular, @kbd{[ [ 1 , 2 ; 3 , 4 ; 5 , 6 ] ]} is
- equivalent to @kbd{[ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ]}.
- X
- @pindex calc-dots
- Incomplete entry is also used to enter intervals. For example,
- @kbd{[ 2 ..@: 4 )} enters a semi-open interval. Note that when you type
- the first period, it will be interpreted as a decimal point, but when
- you type a second period immediately afterward, it is re-interpreted as
- part of the interval symbol. Typing @kbd{..} corresponds to executing
- the @code{calc-dots} command.
- X
- If you find incomplete entry distracting, you may wish to enter vectors
- and complex numbers as algebraic formulas by pressing the apostrophe key.
- X
- @node Variables, Formulas, Incomplete Objects, Data Types
- @section Variables
- X
- @noindent
- @cindex Variables, in formulas
- A @dfn{variable} is somewhere between a storage register on a conventional
- calculator, and a variable in a programming language. (In fact, a Calc
- variable is really just an Emacs Lisp variable that contains a Calc number
- or formula.) A variable's name is normally composed of letters and digits.
- Calc also allows apostrophes and underscores in variable names.
- The Calc variable @code{foo} corresponds to the Emacs Lisp variable
- @code{var-foo}. The @kbd{s s} (@code{calc-store}) command and other
- commands that operate on variables can
- be made to use any arbitrary Lisp variable simply by backspacing over the
- @samp{var-} prefix in the minibuffer.@refill
- X
- In a command that takes a variable name, you can either type the full
- name of a variable, or type a single digit to use one of the special
- convenience variables @code{var-q0} through @code{var-q9}. For example,
- @kbd{3 s s 2} stores the number 3 in variable @code{var-q2}, and
- @w{@kbd{3 s s foo @key{RET}}} stores that number in variable
- @code{var-foo}.@refill
- X
- To push a variable itself (as opposed to the variable's value) on the
- stack, enter its name as an algebraic expression using the apostrophe
- (@key{'}) key. Variable names in algebraic formulas implicitly have
- @samp{var-} prefixed to their names. The @samp{#} character in variable
- names used in algebraic formulas corresponds to a dash @samp{-} in the
- Lisp variable name. If the name contains any dashes, the prefix @samp{var-}
- is @emph{not} automatically added. Thus the two formulas @samp{foo + 1}
- and @samp{var#foo + 1} both refer to the same variable.
- X
- @kindex =
- @pindex calc-evaluate
- @cindex Evaluation of variables in a formula
- @cindex Variables, evaluation
- @cindex Formulas, evaluation
- The @kbd{=} (@code{calc-evaluate}) key ``evaluates'' a formula by
- replacing all variables in the formula which have been given values by a
- @code{calc-store} or @code{calc-let} command by their stored values.
- Other variables are left alone. Thus a variable that has not been
- stored acts like an abstract variable in algebra; a variable that has
- been stored acts more like a register in a traditional calculator.
- With a positive numeric prefix argument, @kbd{=} evaluates the top
- @var{n} stack entries; with a negative argument, @kbd{=} evaluates
- the @var{n}th stack entry.
- X
- @cindex @code{e} variable
- @cindex @code{pi} variable
- @cindex @code{i} variable
- @cindex @code{phi} variable
- @cindex @code{gamma} variable
- @vindex e
- @vindex pi
- @vindex i
- @vindex phi
- @vindex gamma
- A few variables are called @dfn{special constants}. Their names are
- @samp{e}, @samp{pi}, @samp{i}, @samp{phi}, and @samp{gamma}.
- (@xref{Scientific Functions}.) When they are evaluated with @kbd{=},
- their values are calculated if necessary according to the current precision
- or complex polar mode. If you wish to use these symbols for other purposes,
- simply undefine or redefine them using @code{calc-store}.@refill
- X
- The variables @samp{inf}, @samp{uinf}, and @samp{nan} stand for
- infinite or indeterminate values. It's best not to use them for
- regular variables, since Calc uses special algebraic rules when
- it manipulates them. Calc displays a warning message if you store
- a value into any of these special variables.
- X
- @xref{Store and Recall}, for a discussion of commands dealing with variables.
- X
- @node Formulas, , Variables, Data Types
- @section Formulas
- X
- @noindent
- @cindex Formulas
- @cindex Expressions
- @cindex Operators in formulas
- @cindex Precedence of operators
- When you press the apostrophe key you may enter any expression or formula
- in algebraic form. (Calc uses the terms ``expression'' and ``formula''
- interchangeably.) An expression is built up of numbers, variable names,
- and function calls, combined with various arithmetic operators.
- Parentheses may
- be used to indicate grouping. Spaces are ignored within formulas, except
- that spaces are not permitted within variable names or numbers.
- Arithmetic operators, in order from highest to lowest precedence, and
- with their equivalent function names, are:
- X
- @display
- @samp{_} [@code{subscr}] (subscripts);
- X
- postfix @samp{%} [@code{percent}] (as in @samp{25% = 0.25});
- X
- prefix @samp{+} and @samp{-} [@code{neg}] (as in @samp{-x})
- X and prefix @samp{!} [@code{lnot}] (logical ``not,'' as in @samp{!x});
- X
- @samp{+/-} [@code{sdev}] (the standard deviation symbol) and
- X @samp{mod} [@code{makemod}] (the symbol for modulo forms);
- X
- postfix @samp{!} [@code{fact}] (factorial, as in @samp{n!})
- X and postfix @samp{!!} [@code{dfact}] (double factorial);
- X
- @samp{^} [@code{pow}] (raised-to-the-power-of);
- X
- @samp{*} [@code{mul}];
- X
- @samp{/} [@code{div}], @samp{%} [@code{mod}] (modulo), and
- X @samp{\} [@code{idiv}] (integer division);
- X
- infix @samp{+} [@code{add}] and @samp{-} [@code{sub}] (as in @samp{x-y});
- X
- @samp{|} [@code{vconcat}] (vector concatenation);
- X
- relations @samp{=} [@code{eq}], @samp{!=} [@code{neq}], @samp{<} [@code{lt}], @samp{>} [@code{gt}],
- X @samp{<=} [@code{leq}], and @samp{>=} [@code{geq}];
- X
- @samp{&&} [@code{land}] (logical ``and'');
- X
- @samp{||} [@code{lor}] (logical ``or'');
- X
- the C-style ``if'' operator @samp{a?b:c} [@code{if}];
- X
- @samp{!!!} [@code{pnot}] (rewrite pattern ``not'');
- X
- @samp{&&&} [@code{pand}] (rewrite pattern ``and'');
- X
- @samp{|||} [@code{por}] (rewrite pattern ``or'');
- X
- @samp{:=} [@code{assign}] (for assignments and rewrite rules);
- X
- @samp{::} [@code{condition}] (rewrite pattern condition);
- X
- @samp{=>} [@code{evalto}].
- @end display
- X
- Note that, unlike in usual computer notation, multiplication binds more
- strongly than division: @samp{a*b/c*d} is equivalent to @c{$a b \over c d$}
- @cite{(a*b)/(c*d)}.
- X
- @cindex Multiplication, implicit
- @cindex Implicit multiplication
- The multiplication sign @samp{*} may be omitted in many cases. In particular,
- if the righthand side is a number, variable name, or parenthesized
- expression, the @samp{*} may be omitted. Implicit multiplication has the
- same precedence as the explicit @samp{*} operator. The one exception to
- the rule is that a variable name followed by a parenthesized expression,
- as in @samp{f(x)},
- is interpreted as a function call, not an implicit @samp{*}. In many
- cases you must use a space if you omit the @samp{*}: @samp{2a} is the
- same as @samp{2*a}, and @samp{a b} is the same as @samp{a*b}, but @samp{ab}
- is a variable called @code{ab}, @emph{not} the product of @samp{a} and
- @samp{b}! Also note that @samp{f (x)} is still a function call.@refill
- X
- @cindex Implicit comma in vectors
- The rules are slightly different for vectors written with square brackets.
- There, the space character is interpreted (like the comma) as a separator
- of elements of the vector. Thus @samp{[ 2a b+c d ]} is equivalent to
- @samp{[2*a, b+c, d]}, whereas @samp{2a b+c d} is equivalent to
- @samp{2*a*b + c*d}.
- Note that spaces around the brackets, and around explicit commas, are
- ignored. To force spaces to be interpreted as multiplication you can
- enclose a formula in parentheses as in @samp{[(a b) 2(c d)]}, which is
- interpreted as @samp{[a*b, 2*c*d]}. An implicit comma is also inserted
- between @samp{][}, as in the matrix @samp{[[1 2][3 4]]}.@refill
- X
- Vectors that contain commas (not embedded within nested parentheses or
- brackets) do not treat spaces specially: @samp{[a b, 2 c d]} is a vector
- of two elements. Also, vectors entered with curly braces instead of
- square brackets do not give spaces any special treatment. When Calc
- displays a vector that does not contain any commas, it will insert
- parentheses if necessary to make the meaning clear: @samp{[(a b)]}.
- X
- The expression @samp{5%-2} is ambiguous; is this five-percent minus two,
- or five modulo minus-two? Calc always interprets the leftmost symbol as
- an infix operator preferentially (modulo, in this case), so you would
- need to write @samp{(5%)-2} to get the former interpretation.
- X
- @cindex Function call notation
- A function call is, e.g., @samp{sin(1+x)}. Function names follow the same
- rules as variable names except that the default prefix @samp{calcFunc-} is
- used (instead of @samp{var-}) for the internal Lisp form.
- Most mathematical Calculator commands like
- @code{calc-sin} have function equivalents like @code{sin}.
- If no Lisp function is defined for a function called by a formula, the
- call is left as it is during algebraic manipulation: @samp{f(x+y)} is
- left alone. Beware that many innocent-looking short names like @code{in}
- and @code{re} have predefined meanings which could surprise you; however,
- single letters or single letters followed by digits are always safe.
- @xref{Function Index}.@refill
- X
- In the documentation for particular commands, the notation @kbd{H S}
- (@code{calc-sinh}) [@code{sinh}] means that the key sequence @kbd{H S}, the
- command @kbd{M-x calc-sinh}, and the algebraic function @code{sinh(x)} all
- represent the same operation.@refill
- X
- Commands that interpret (``parse'') text as algebraic formulas include
- algebraic entry (@kbd{'}), editing commands like @kbd{`} which parse
- the contents of the editing buffer when you finish, the @kbd{M-# g}
- and @kbd{M-# r} commands, the @kbd{C-y} command, the X window system
- ``paste'' mouse operation, and Embedded Mode. All of these operations
- use the same rules for parsing formulas; in particular, language modes
- (@pxref{Language Modes}) affect them all in the same way.
- X
- When you read a large amount of text into the Calculator (say a vector
- which represents a big set of rewrite rules; @pxref{Rewrite Rules}),
- you may wish to include comments in the text. Calc's formula parser
- ignores the symbol @samp{%%} and anything following it on a line:
- X
- @example
- [ a + b, %% the sum of "a" and "b"
- X c + d,
- X %% last line is coming up:
- X e + f ]
- @end example
- X
- @noindent
- This is parsed exactly the same as @samp{[ a + b, c + d, e + f ]}.
- X
- @xref{Algebra}, for commands for manipulating formulas symbolically.
- X
- @node Stack and Trail, Mode Settings, Data Types, Top
- @chapter Stack and Trail Commands
- X
- @noindent
- This chapter describes the Calc commands for manipulating objects in the
- stack and in the trail buffer. (These commands operate on objects of any
- type, such as numbers, vectors, formulas, and incomplete objects.)
- X
- @menu
- * Stack Manipulation::
- * Trail Commands::
- * Keep Arguments::
- @end menu
- X
- @node Stack Manipulation, Trail Commands, Stack and Trail, Stack and Trail
- @section Stack Manipulation Commands
- X
- @noindent
- @kindex RET
- @kindex SPC
- @pindex calc-enter
- @cindex Duplicating stack entries
- To duplicate the top object on the stack, press @key{RET} or @key{SPC}
- (two equivalent keys for the @code{calc-enter} command).
- Given a positive numeric prefix argument, these commands duplicate
- several elements at the top of the stack.
- Given a negative argument,
- these commands duplicate the specified element of the stack.
- Given an argument of zero, they duplicate the entire stack.
- For example, with @samp{10 20 30} on the stack,
- @key{RET} creates @samp{10 20 30 30},
- @kbd{C-u 2 @key{RET}} creates @samp{10 20 30 20 30},
- @kbd{C-u - 2 @key{RET}} creates @samp{10 20 30 20}, and
- @kbd{C-u 0 @key{RET}} creates @samp{10 20 30 10 20 30}.@refill
- X
- @kindex LFD
- @pindex calc-over
- The @key{LFD} (@code{calc-over}) command (on a key marked Line-Feed if you
- have it, else on @kbd{C-j}) is like @code{calc-enter}
- except that the sign of the numeric prefix argument is interpreted
- oppositely. Also, with no prefix argument the default argument is 2.
- Thus with @samp{10 20 30} on the stack, @key{LFD} and @kbd{C-u 2 @key{LFD}}
- are both equivalent to @kbd{C-u - 2 @key{RET}}, producing
- @samp{10 20 30 20}.@refill
- X
- @kindex DEL
- @kindex C-d
- @pindex calc-pop
- @cindex Removing stack entries
- @cindex Deleting stack entries
- To remove the top element from the stack, press @key{DEL} (@code{calc-pop}).
- The @kbd{C-d} key is a synonym for @key{DEL}.
- (If the top element is an incomplete object with at least one element, the
- last element is removed from it.) Given a positive numeric prefix argument,
- several elements are removed. Given a negative argument, the specified
- element of the stack is deleted. Given an argument of zero, the entire
- stack is emptied.
- For example, with @samp{10 20 30} on the stack,
- @key{DEL} creates @samp{10 20},
- @kbd{C-u 2 @key{DEL}} creates @samp{10},
- @kbd{C-u - 2 @key{DEL}} creates @samp{10 30}, and
- @kbd{C-u 0 @key{DEL}} creates an empty stack.@refill
- X
- @kindex M-DEL
- @pindex calc-pop-above
- The @kbd{M-DEL} (@code{calc-pop-above}) command is to @kbd{DEL} what
- @kbd{LFD} is to @kbd{RET}, i.e., it interprets the sign of the numeric
- prefix argument in the opposite way, and the default argument is 2.
- Thus @kbd{M-DEL} by itself removes the second-from-top stack element,
- leaving the first, third, fourth, and so on; @kbd{M-3 M-DEL} deletes
- the third stack element.
- X
- @kindex TAB
- @pindex calc-roll-down
- To exchange the top two elements of the stack, press @key{TAB}
- (@code{calc-roll-down}). Given a positive numeric prefix argument, the
- specified number of elements at the top of the stack are rotated downward.
- Given a negative argument, the entire stack is rotated downward the specified
- number of times. Given an argument of zero, the entire stack is reversed
- top-for-bottom.
- For example, with @samp{10 20 30 40 50} on the stack,
- @key{TAB} creates @samp{10 20 30 50 40},
- @kbd{C-u 3 @key{TAB}} creates @samp{10 20 50 30 40},
- @kbd{C-u - 2 @key{TAB}} creates @samp{40 50 10 20 30}, and
- @kbd{C-u 0 @key{TAB}} creates @samp{50 40 30 20 10}.@refill
- X
- @kindex M-TAB
- @pindex calc-roll-up
- The command @key{M-TAB} (@code{calc-roll-up}) is analogous to @key{TAB}
- except that it rotates upward instead of downward. Also, the default
- with no prefix argument is to rotate the top 3 elements.
- For example, with @samp{10 20 30 40 50} on the stack,
- @key{M-TAB} creates @samp{10 20 40 50 30},
- @kbd{C-u 4 @key{M-TAB}} creates @samp{10 30 40 50 20},
- @kbd{C-u - 2 @key{M-TAB}} creates @samp{30 40 50 10 20}, and
- @kbd{C-u 0 @key{M-TAB}} creates @samp{50 40 30 20 10}.@refill
- X
- A good way to view the operation of @key{TAB} and @key{M-TAB} is in
- terms of moving a particular element to a new position in the stack.
- With a positive argument @i{n}, @key{TAB} moves the top stack
- element down to level @i{n}, making room for it by pulling all the
- intervening stack elements toward the top. @key{M-TAB} moves the
- element at level @i{n} up to the top. (Compare with @key{LFD},
- which copies instead of moving the element in level @i{n}.)
- X
- With a negative argument @i{-n}, @key{TAB} rotates the stack
- to move the object in level @i{n} to the deepest place in the
- stack, and the object in level @i{n+1} to the top. @key{M-TAB}
- rotates the deepest stack element to be in level @i{n}, also
- putting the top stack element in level @i{n+1}.
- X
- @xref{Selecting Subformulas}, for a way to apply these commands to
- any portion of a vector or formula on the stack.
- X
- @node Trail Commands, Keep Arguments, Stack Manipulation, Stack and Trail
- @section Trail Commands
- X
- @noindent
- @cindex Trail buffer
- The commands for manipulating the Calc Trail buffer are two-key sequences
- beginning with the @kbd{t} prefix.
- X
- @kindex t d
- @pindex calc-trail-display
- The @kbd{t d} (@code{calc-trail-display}) command turns display of the
- trail on and off. Normally the trail display is toggled on if it was off,
- off if it was on. With a numeric prefix of zero, this command always
- turns the trail off; with a prefix of one, it always turns the trail on.
- The other trail-manipulation commands described here automatically turn
- the trail on. Note that when the trail is off values are still recorded
- there; they are simply not displayed. To set Emacs to turn the trail
- off by default, turn it off with @kbd{t d}, then save the mode settings
- with @kbd{m m} (@code{calc-save-modes}).
- X
- @kindex t i
- @pindex calc-trail-in
- @kindex t o
- @pindex calc-trail-out
- The @kbd{t i} (@code{calc-trail-in}) and @kbd{t o}
- (@code{calc-trail-out}) commands switch the cursor into and out of the
- Calc Trail window. In practice they are rarely used, since the commands
- shown below are a more convenient way to move around in the
- trail, and they work ``by remote control'' when the cursor is still
- in the Calculator window.@refill
- X
- @cindex Trail pointer
- There is a @dfn{trail pointer} which selects some entry of the trail at
- any given time. The trail pointer looks like a @samp{>} symbol right
- before the selected number. The following commands operate on the
- trail pointer in various ways.
- X
- @kindex t y
- @pindex calc-trail-yank
- @cindex Retrieving previous results
- The @kbd{t y} (@code{calc-trail-yank}) command reads the selected value in
- the trail and pushes it onto the Calculator stack. It allows you to
- re-use any previously computed value without retyping. With a numeric
- prefix argument @var{n}, it yanks the value @var{n} lines above the current
- trail pointer.
- X
- @kindex t <
- @pindex calc-trail-scroll-left
- @kindex t >
- @pindex calc-trail-scroll-right
- The @kbd{t <} (@code{calc-trail-scroll-left}) and @kbd{t >}
- (@code{calc-trail-scroll-right}) commands horizontally scroll the trail
- window left or right by one half of its width.@refill
- X
- @kindex t n
- @pindex calc-trail-next
- @kindex t p
- @pindex calc-trail-previous
- @kindex t f
- @pindex calc-trail-forward
- @kindex t b
- @pindex calc-trail-backward
- The @kbd{t n} (@code{calc-trail-next}) and @kbd{t p}
- (@code{calc-trail-previous)} commands move the trail pointer down or up
- one line. The @kbd{t f} (@code{calc-trail-forward}) and @kbd{t b}
- (@code{calc-trail-backward}) commands move the trail pointer down or up
- one screenful at a time. All of these commands accept numeric prefix
- arguments to move several lines or screenfuls at a time.@refill
- X
- @kindex t [
- @pindex calc-trail-first
- @kindex t ]
- @pindex calc-trail-last
- @kindex t h
- @pindex calc-trail-here
- The @kbd{t [} (@code{calc-trail-first}) and @kbd{t ]}
- (@code{calc-trail-last}) commands move the trail pointer to the first or
- last line of the trail. The @kbd{t h} (@code{calc-trail-here}) command
- moves the trail pointer to the cursor position; unlike the other trail
- commands, @kbd{t h} works only when Calc Trail is the selected window.@refill
- X
- @kindex t s
- @pindex calc-trail-isearch-forward
- @kindex t r
- @pindex calc-trail-isearch-backward
- @ifinfo
- The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
- (@code{calc-trail-isearch-backward}) commands perform an incremental
- search forward and backward through the trail. You can press @key{RET}
- to terminate the search; the trail pointer moves to the current line.
- If you cancel the search with @kbd{C-g}, the trail pointer does not
- move.@refill
- @end ifinfo
- @tex
- The @kbd{t s} (@code{calc-trail-isearch-forward}) and @kbd{t r}
- (@code{calc-trail-isearch-backward}) com\-mands perform an incremental
- search forward and backward through the trail. You can press @key{RET}
- to terminate the search; the trail pointer moves to the current line.
- If you cancel the search with @kbd{C-g}, the trail pointer does not
- move.
- @end tex
- X
- @kindex t m
- @pindex calc-trail-marker
- The @kbd{t m} (@code{calc-trail-marker}) command allows you to enter a
- line of text of your own choosing into the trail. The text is inserted
- after the line containing the trail pointer; this usually means it is
- added to the end of the trail. Trail markers are useful mainly as the
- targets for later incremental searches in the trail.
- X
- @kindex t k
- @pindex calc-trail-kill
- The @kbd{t k} (@code{calc-trail-kill}) command removes the selected line
- from the trail. The line is saved in the Emacs kill ring suitable for
- yanking into another buffer, but it is not easy to yank the text back
- into the trail buffer. With a numeric prefix argument, this command
- kills the @var{n} lines below or above the selected one.
- X
- The @kbd{t .} (@code{calc-full-trail-vectors}) command is described
- elsewhere; @pxref{Vector and Matrix Formats}.
- X
- @node Keep Arguments, , Trail Commands, Stack and Trail
- @section Keep Arguments
- X
- @noindent
- @kindex K
- @pindex calc-keep-args
- The @kbd{K} (@code{calc-keep-args}) command acts like a prefix for
- the following command that prevents that command from removing its
- arguments from the stack. For example, after @kbd{2 @key{RET} 3 +},
- the stack contains the sole number 5, but after @kbd{2 @key{RET} 3 K +},
- the stack contains the arguments and the result: @samp{2 3 5}.
- X
- This works for all commands that take arguments off the stack. As
- another example, @kbd{K a s} simplifies a formula, pushing the
- simplified version of the formula onto the stack after the original
- formula (rather than replacing the original formula).
- X
- Note that you could get the same effect by typing @kbd{RET a s},
- copying the formula and then simplifying the copy. One difference
- is that for a very large formula the time taken to format the
- intermediate copy in @kbd{RET a s} could be noticeable; @kbd{K a s}
- would avoid this extra work.
- X
- Even stack manipulation commands are affected. @key{TAB} works by
- popping two values and pushing them back in the opposite order,
- so @kbd{2 @key{RET} 3 K @key{TAB}} produces @samp{2 3 3 2}.
- X
- A few Calc commands provide other ways of doing the same thing.
- For example, @kbd{' sin($)} replaces the number on the stack with
- its sine using algebraic entry; to push the sine and keep the
- original argument you could use either @kbd{' sin($1)} or
- @kbd{K ' sin($)}. @xref{Algebraic Entry}. Also, the @kbd{s s}
- command is effectively the same as @kbd{K s t}. @xref{Storing Variables}.
- X
- Keyboard macros may interact surprisingly with the @kbd{K} prefix.
- If you have defined a keyboard macro to be, say, @samp{Q +} to add
- one number to the square root of another, then typing @kbd{K X} will
- execute @kbd{K Q +}, probably not what you expected. The @kbd{K}
- prefix will apply to just the first command in the macro rather than
- the whole macro.
- X
- If you execute a command and then decide you really wanted to keep
- the argument, you can press @kbd{M-@key{RET}} (@code{calc-last-args}).
- This command pushes the last arguments that were popped by any command
- onto the stack. Note that the order of things on the stack will be
- different than with @kbd{K}: @kbd{2 @key{RET} 3 + M-@key{RET}} leaves
- @samp{5 2 3} on the stack instead of @samp{2 3 5}. @xref{Undo}.
- X
- @node Mode Settings, Arithmetic, Stack and Trail, Top
- @chapter Mode Settings
- X
- @noindent
- This chapter describes commands that set modes in the Calculator.
- They do not affect the contents of the stack, although they may change
- the @emph{appearance} or @emph{interpretation} of the stack's contents.
- X
- @menu
- * General Mode Commands::
- * Precision::
- * Inverse and Hyperbolic::
- * Calculation Modes::
- * Simplification Modes::
- * Declarations::
- * Display Modes::
- * Language Modes::
- * Calc Mode Line::
- @end menu
- X
- @node General Mode Commands, Precision, Mode Settings, Mode Settings
- @section General Mode Commands
- X
- @noindent
- @kindex m m
- @pindex calc-save-modes
- @cindex Continuous memory
- @cindex Saving mode settings
- @cindex Permanent mode settings
- @cindex @file{.emacs} file, mode settings
- You can save all of the current mode settings in your @file{.emacs} file
- with the @kbd{m m} (@code{calc-save-modes}) command. This will cause
- Emacs to reestablish these modes each time it starts up. The modes saved
- in the file include everything controlled by the @kbd{m} and @kbd{d}
- prefix keys, the current precision and binary word size, whether or not
- the trail is displayed, and the current height of the Calc window.
- The current interface (used when you type @kbd{M-# M-#}) is also saved.
- If there were already saved mode settings in the file, they are replaced.
- Otherwise, the new mode information is appended to the end of the file.
- X
- @kindex m R
- @pindex calc-mode-record-mode
- The @kbd{m R} (@code{calc-mode-record-mode}) command tells Calc to
- record the new mode settings (as if by pressing @kbd{m m}) every
- time a mode setting changes. If Embedded Mode is enabled, other
- options are available; @pxref{Mode Settings in Embedded Mode}.
- X
- @kindex m F
- @pindex calc-settings-file-name
- The @kbd{m F} (@code{calc-settings-file-name}) command allows you to
- choose a different place than your @file{.emacs} file for @kbd{m m},
- @kbd{Z P}, and similar commands to save permanent information.
- You are prompted for a file name. All Calc modes are then reset to
- their default values, settings from the file you named are loaded
- if this file exists, and this file becomes the one that Calc will
- use in the future for commands like @kbd{m m}. The default settings
- file name is @file{~/.emacs}. You can see the current file name by
- giving a blank response to the @kbd{m F} prompt. See also the
- discussion of the @code{calc-settings-file} variable; @pxref{Installation}.
- X
- If the file name you give contains the string @samp{.emacs} anywhere
- inside it, @kbd{m F} will not automatically load the new file. This
- is because you are presumably switching to your @file{~/.emacs} file,
- which may contain other things you don't want to reread. You can give
- a numeric prefix argument of 1 to @kbd{m F} to force it to read the
- file no matter what its name. Conversely, an argument of @i{-1} tells
- @kbd{m F} @emph{not} to read the new file. An argument of 2 or @i{-2}
- tells @kbd{m F} not to reset the modes to their defaults beforehand,
- which is useful if you intend your new file to have a variant of the
- modes present in the file you were using before.
- X
- @kindex m x
- @pindex calc-always-load-extensions
- The @kbd{m x} (@code{calc-always-load-extensions}) command enables a mode
- in which the first use of Calc loads the entire program, including all
- extensions modules. Otherwise, the extensions modules will not be loaded
- until the various advanced Calc features are used. Since this mode only
- has effect when Calc is first loaded, @kbd{m x} is usually followed by
- @kbd{m m} to make the mode-setting permanent.
- X
- @kindex m X
- @kindex M-# L
- @pindex calc-load-everything
- The @kbd{m X} or @kbd{M-# L} (@code{calc-load-everything}) command loads
- all parts of Calc that have not yet been loaded. This is the command
- that Calc executes upon startup if @kbd{m x} mode has been enabled.
- X
- @kindex m S
- @pindex calc-shift-prefix
- The @kbd{m S} (@code{calc-shift-prefix}) command enables a mode in which
- all of Calc's letter prefix keys may be typed shifted as well as unshifted.
- If you are typing, say, @kbd{a S} (@code{calc-solve-for}) quite often
- you might find it easier to turn this mode on so that you can type
- @kbd{A S} instead. When this mode is enabled, the commands that used to
- be on those single shifted letters (e.g., @kbd{A} (@code{calc-abs})) can
- now be invoked by pressing the shifted letter twice: @kbd{A A}. Note
- that the @kbd{v} prefix key always works both shifted and unshifted, and
- the @kbd{z} and @kbd{Z} prefix keys are always distinct. Also, the @kbd{h}
- prefix is not affected by this mode. Press @kbd{m S} again to disable
- shifted-prefix mode.
- X
- @node Precision, Inverse and Hyperbolic, General Mode Commands, Mode Settings
- @section Precision
- X
- @noindent
- @kindex p
- @pindex calc-precision
- @cindex Precision of calculations
- The @kbd{p} (@code{calc-precision}) command controls the precision to
- which floating-point calculations are carried. The precision must be
- at least 3 digits and may be arbitrarily high, within the limits of
- memory and time. This affects only floats: Integer and rational
- calculations are always carried out with as many digits as necessary.
- X
- The @kbd{p} key prompts for the current precision. If you wish you
- can instead give the precision as a numeric prefix argument.
- X
- Many internal calculations are carried to one or two digits higher
- precision than normal. Results are rounded down afterward to the
- current precision. Unless a special display mode has been selected,
- floats are always displayed with their full stored precision, i.e.,
- what you see is what you get. Reducing the current precision does not
- round values already on the stack, but those values will be rounded
- down before being used in any calculation. The @kbd{c 0} through
- @kbd{c 9} commands (@pxref{Conversions}) can be used to round an
- existing value to a new precision.@refill
- X
- @cindex Accuracy of calculations
- It is important to distinguish the concepts of @dfn{precision} and
- @dfn{accuracy}. In the normal usage of these words, the number
- 123.4567 has a precision of 7 digits but an accuracy of 4 digits;
- the precision is the total number of digits not counting leading
- or trailing zeros (regardless of the position of the decimal point).
- The accuracy is simply the number of digits after the decimal point
- (again not counting trailing zeros). In Calc you control the precision,
- not the accuracy of computations. If you were to set the accuracy
- instead, then calculations like @samp{exp(100)} would generate many
- more digits than you would typically need, while @samp{exp(-100)} would
- probably round to zero! In Calc, both these computations give you
- exactly 12 (or the requested number of) significant digits.
- X
- The only Calc features that deal with accuracy instead of precision
- are fixed-point display mode for floats (@kbd{d f}; @pxref{Float Formats}),
- and the rounding functions like @code{floor} and @code{round}
- (@pxref{Integer Truncation}). Also, @kbd{c 0} through @kbd{c 9}
- deal with both precision and accuracy depending on the magnitudes
- of the numbers involved.
- X
- If you need to work with a particular fixed accuracy (say, dollars and
- cents with two digits after the decimal point), one solution is to work
- with integers and an ``implied'' decimal point. For example, $8.99
- divided by 6 would be entered @kbd{899 RET 6 /}, yielding 149.833
- (actually $1.49833 with our implied decimal point); pressing @kbd{R}
- would round this to 150 cents, i.e., $1.50.
- X
- @node Inverse and Hyperbolic, Calculation Modes, Precision, Mode Settings
- @section Inverse and Hyperbolic Flags
- X
- @noindent
- @kindex I
- @pindex calc-inverse
- There is no single-key equivalent to the @code{calc-arcsin} function.
- Instead, you must first press @kbd{I} (@code{calc-inverse}) to set
- the @dfn{Inverse Flag}, then press @kbd{S} (@code{calc-sin}).
- The @kbd{I} key actually toggles the Inverse Flag. When this flag
- is set, the word @samp{Inv} appears in the mode line.@refill
- X
- @kindex H
- @pindex calc-hyperbolic
- Likewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the
- Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}.
- If both of these flags are set at once, the effect will be
- @code{calc-arcsinh}. (The Hyperbolic flag is also used by some
- non-trigonometric commands; for example @kbd{H L} computes a base-10,
- instead of base-@i{e}, logarithm.)@refill
- X
- Command names like @code{calc-arcsin} are provided for completeness, and
- may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to
- toggle the Inverse and/or Hyperbolic flags and then execute the
- corresponding base command (@code{calc-sin} in this case).
- X
- The Inverse and Hyperbolic flags apply only to the next Calculator
- command, after which they are automatically cleared. (They are also
- cleared if the next keystroke is not a Calc command.) Digits you
- type after @kbd{I} or @kbd{H} (or @kbd{K}) are treated as prefix
- arguments for the next command, not as numeric entries. The same
- is true of @kbd{C-u}, but not of the minus sign (@kbd{K -} means to
- subtract and keep arguments).
- X
- The third Calc prefix flag, @kbd{K} (keep-arguments), is discussed
- elsewhere. @xref{Keep Arguments}.
- X
- @node Calculation Modes, Simplification Modes, Inverse and Hyperbolic, Mode Settings
- @section Calculation Modes
- X
- @noindent
- The commands in this section are two-key sequences beginning with
- the @kbd{m} prefix. (That's the letter @kbd{m}, not the @key{META} key.)
- X
- The @samp{m a} (@code{calc-algebraic-mode}) command is described elsewhere
- (@pxref{Algebraic Entry}).
- X
- @menu
- * Angular Modes::
- * Polar Mode::
- * Fraction Mode::
- * Infinite Mode::
- * Symbolic Mode::
- * Matrix Mode::
- * Automatic Recomputation::
- * Working Message::
- @end menu
- X
- @node Angular Modes, Polar Mode, Calculation Modes, Calculation Modes
- @subsection Angular Modes
- X
- @noindent
- @cindex Angular mode
- The Calculator supports three notations for angles: radians, degrees,
- and degrees-minutes-seconds. When a number is presented to a function
- like @code{sin} that requires an angle, the current angular mode is
- used to interpret the number as either radians or degrees. If an HMS
- form is presented to @code{sin}, it is always interpreted as
- degrees-minutes-seconds.
- X
- Functions that compute angles produce a number in radians, a number in
- degrees, or an HMS form depending on the current angular mode. If the
- result is a complex number and the current mode is HMS, the number is
- instead expressed in degrees. (Complex-number calculations would
- normally be done in radians mode, though. Complex numbers are converted
- to degrees by calculating the complex result in radians and then
- multiplying by 180 over @c{$\pi$}
- @cite{pi}.)
- X
- @kindex m r
- @pindex calc-radians-mode
- @kindex m d
- @pindex calc-degrees-mode
- @kindex m h
- @pindex calc-hms-mode
- The @kbd{m r} (@code{calc-radians-mode}), @kbd{m d} (@code{calc-degrees-mode}),
- and @kbd{m h} (@code{calc-hms-mode}) commands control the angular mode.
- The current angular mode is displayed on the Emacs mode line.
- The default angular mode is degrees.@refill
- X
- @node Polar Mode, Fraction Mode, Angular Modes, Calculation Modes
- @subsection Polar Mode
- X
- @noindent
- @cindex Polar mode
- The Calculator normally ``prefers'' rectangular complex numbers in the
- sense that rectangular form is used when the proper form can not be
- decided from the input. This might happen by multiplying a rectangular
- number by a polar one, by taking the square root of a negative real
- number, or by entering @kbd{( 2 @key{SPC} 3 )}.
- X
- @kindex m p
- @pindex calc-polar-mode
- The @kbd{m p} (@code{calc-polar-mode}) command toggles complex-number
- preference between rectangular and polar forms. In polar mode, all
- of the above example situations would produce polar complex numbers.
- X
- @node Fraction Mode, Infinite Mode, Polar Mode, Calculation Modes
- @subsection Fraction Mode
- X
- @noindent
- @cindex Fraction mode
- @cindex Division of integers
- Division of two integers normally yields a floating-point number if the
- result cannot be expressed as an integer. In some cases you would
- rather get an exact fractional answer. One way to accomplish this is
- to multiply fractions instead: @kbd{6 @key{RET} 1:4 *} produces @cite{3:2}
- even though @kbd{6 @key{RET} 4 /} produces @cite{1.5}.
- X
- @kindex m f
- @pindex calc-frac-mode
- To set the Calculator to produce fractional results for normal integer
- divisions, use the @kbd{m f} (@code{calc-frac-mode}) command.
- For example, @cite{8/4} produces @cite{2} in either mode,
- but @cite{6/4} produces @cite{3:2} in Fraction Mode, but @cite{1.5} in
- Float Mode.@refill
- X
- At any time you can use @kbd{c f} (@code{calc-float}) to convert a
- fraction to a float, or @kbd{c F} (@code{calc-fraction}) to convert a
- float to a fraction. @xref{Conversions}.
- X
- @node Infinite Mode, Symbolic Mode, Fraction Mode, Calculation Modes
- @subsection Infinite Mode
- X
- @noindent
- @cindex Infinite mode
- The Calculator normally treats results like @cite{1 / 0} as errors;
- formulas like this are left in unsimplified form. But Calc can be
- put into a mode where such calculations instead produce ``infinite''
- results.
- X
- @kindex m i
- @pindex calc-infinite-mode
- The @kbd{m i} (@code{calc-infinite-mode}) command turns this mode
- on and off. When the mode is off, infinities do not arise except
- in calculations that already had infinities as inputs. (One exception
- is that infinite open intervals like @samp{[0 .. inf)} can be
- generated; however, intervals closed at infinity (@samp{[0 .. inf]})
- will not be generated when infinite mode is off.)
- X
- With infinite mode turned on, @samp{1 / 0} will generate @code{uinf},
- an undirected infinity. @xref{Infinities}, for a discussion of the
- difference between @code{inf} and @code{uinf}. Also, @cite{0 / 0}
- evaluates to @code{nan}, the ``indeterminate'' symbol. Various other
- functions can also return infinities in this mode; for example,
- @samp{ln(0) = -inf}, and @samp{gamma(-7) = uinf}. Once again,
- note that @samp{exp(inf) = inf} regardless of infinite mode because
- this calculation has infinity as an input.
- X
- @cindex Positive infinite mode
- The @kbd{m i} command with a numeric prefix argument of zero,
- i.e., @kbd{C-u 0 m i}, turns on a ``positive infinite mode'' in
- which zero is treated as positive instead of being directionless.
- Thus, @samp{1 / 0 = inf} and @samp{-1 / 0 = -inf} in this mode.
- Note that zero never actually has a sign in Calc; there are no
- separate representations for @i{+0} and @i{-0}. Positive
- infinite mode merely changes the interpretation given to the
- single symbol, @samp{0}. One consequence of this is that, while
- you might expect @samp{1 / -0 = -inf}, actually @samp{1 / -0}
- is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}.
- X
- @node Symbolic Mode, Matrix Mode, Infinite Mode, Calculation Modes
- @subsection Symbolic Mode
- X
- @noindent
- @cindex Symbolic mode
- @cindex Inexact results
- Calculations are normally performed numerically wherever possible.
- For example, the @code{calc-sqrt} command, or @code{sqrt} function in an
- algebraic expression, produces a numeric answer if the argument is a
- number or a symbolic expression if the argument is an expression:
- @kbd{2 Q} pushes 1.4142 but @kbd{@key{'} x+1 @key{RET} Q} pushes @samp{sqrt(x+1)}.
- X
- @kindex m s
- @pindex calc-symbolic-mode
- In @dfn{symbolic mode}, controlled by the @kbd{m s} (@code{calc-symbolic-mode})
- command, functions which would produce inexact, irrational results are
- left in symbolic form. Thus @kbd{16 Q} pushes 4, but @kbd{2 Q} pushes
- @samp{sqrt(2)}.
- X
- @kindex N
- @pindex calc-eval-num
- The shift-@kbd{N} (@code{calc-eval-num}) command evaluates numerically
- the expression at the top of the stack, by temporarily disabling
- @code{calc-symbolic-mode} and executing @kbd{=} (@code{calc-evaluate}).
- Given a numeric prefix argument, it also
- sets the floating-point precision to the specified value for the duration
- of the command.@refill
- X
- To evaluate a formula numerically without expanding the variables it
- contains, you can use the key sequence @kbd{m s a v m s} (this uses
- @code{calc-alg-evaluate}, which resimplifies but doesn't evaluate
- variables.)
- X
- @node Matrix Mode, Automatic Recomputation, Symbolic Mode, Calculation Modes
- @subsection Matrix and Scalar Modes
- X
- @noindent
- @cindex Matrix mode
- @cindex Scalar mode
- Calc sometimes makes assumptions during algebraic manipulation that
- are awkward or incorrect when vectors and matrices are involved.
- Calc has two modes, @dfn{matrix mode} and @dfn{scalar mode}, which
- modify its behavior around vectors in useful ways.
- X
- @kindex m v
- @pindex calc-matrix-mode
- Press @kbd{m v} (@code{calc-matrix-mode}) once to enter matrix mode.
- In this mode, all objects are assumed to be matrices unless provably
- otherwise. One major effect is that Calc will no longer consider
- multiplication to be commutative. (Recall that in matrix arithmetic,
- @samp{A*B} is not the same as @samp{B*A}.) This assumption affects
- rewrite rules and algebraic simplification. Another effect of this
- mode is that calculations that would normally produce constants like
- 0 and 1 (e.g., @cite{a - a} and @cite{a / a}, respectively) will now
- produce function calls that represent ``generic'' zero or identity
- matrices: @samp{idn(0)}, @samp{idn(1)}. The @code{idn} function
- @samp{idn(@var{a},@var{n})} returns @var{a} times an @var{n}x@var{n}
- identity matrix; if @var{n} is omitted, it doesn't know what
- dimension to use and so the @code{idn} call remains in symbolic
- form. However, if this generic identity matrix is later combined
- with a matrix whose size is known, it will be converted into
- a true identity matrix of the appropriate size. On the other hand,
- if it is combined with a scalar (as in @samp{idn(1) + 2}), Calc
- will assume it really was a scalar after all and produce, e.g., 3.
- X
- Press @kbd{m v} a second time to get scalar mode. Here, objects are
- assumed @emph{not} to be vectors or matrices unless provably so.
- For example, normally adding a variable to a vector, as in
- @samp{[x, y, z] + a}, will leave the sum in symbolic form because
- as far as Calc knows, @samp{a} could represent either a number or
- another 3-vector. In scalar mode, @samp{a} is assumed to be a
- non-vector, and the addition is evaluated to @samp{[x+a, y+a, z+a]}.
- X
- Press @kbd{m v} a third time to return to the normal mode of operation.
- X
- If you press @kbd{m v} with a numeric prefix argument @var{n}, you
- get a special ``dimensioned matrix mode'' in which matrices of
- unknown size are assumed to be @var{n}x@var{n} square matrices.
- Then, the function call @samp{idn(1)} will expand into an actual
- matrix rather than representing a ``generic'' matrix.
- X
- @cindex Declaring scalar variables
- Of course these modes are approximations to the true state of
- affairs, which is probably that some quantities will be matrices
- and others will be scalars. One solution is to ``declare''
- certain variables or functions to be scalar-valued.
- @xref{Declarations}, to see how to make declarations in Calc.
- X
- There is nothing stopping you from declaring a variable to be
- scalar and then storing a matrix in it; however, if you do, the
- results you get from Calc may not be valid. Suppose you let Calc
- get the result @samp{[x+a, y+a, z+a]} shown above, and then stored
- @samp{[1, 2, 3]} in @samp{a}. The result would not be the same as
- for @samp{[x, y, z] + [1, 2, 3]}, but that's because you have broken
- your earlier promise to Calc that @samp{a} would be scalar.
- X
- Another way to mix scalars and matrices is to use selections
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 38'
- echo 'File calc.texinfo is continued in part 39'
- echo 39 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-