Go to the previous, next section.

Mode Settings

This chapter describes commands that set modes in the Calculator. They do not affect the contents of the stack, although they may change the appearance or interpretation of the stack's contents.

General Mode Commands

You can save all of the current mode settings in your `.emacs' file with the m m (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 m and d prefix keys, the current precision and binary word size, whether or not the trail is displayed, the current height of the Calc window, and more. The current interface (used when you type 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.

The m R (calc-mode-record-mode) command tells Calc to record the new mode settings (as if by pressing m m) every time a mode setting changes. If Embedded Mode is enabled, other options are available; see section Mode Settings in Embedded Mode.

The m F (calc-settings-file-name) command allows you to choose a different place than your `.emacs' file for m m, 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, then 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 m m. The default settings file name is `~/.emacs'. You can see the current file name by giving a blank response to the m F prompt. See also the discussion of the calc-settings-file variable; see section Installation.

If the file name you give contains the string `.emacs' anywhere inside it, m F will not automatically load the new file. This is because you are presumably switching to your `~/.emacs' file, which may contain other things you don't want to reread. You can give a numeric prefix argument of 1 to m F to force it to read the file no matter what its name. Conversely, an argument of -1 tells m F not to read the new file. An argument of 2 or -2 tells 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.

The m x (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, m x is usually followed by m m to make the mode-setting permanent. To load all of Calc just once, rather than always in the future, you can press M-# L.

The m S (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, a S (calc-solve-for) quite often you might find it easier to turn this mode on so that you can type A S instead. When this mode is enabled, the commands that used to be on those single shifted letters (e.g., A (calc-abs)) can now be invoked by pressing the shifted letter twice: A A. Note that the v prefix key always works both shifted and unshifted, and the z and Z prefix keys are always distinct. Also, the h prefix is not affected by this mode. Press m S again to disable shifted-prefix mode.

Precision

The p (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.

The p key prompts for the current precision. If you wish you can instead give the precision as a numeric prefix argument.

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 c 0 through c 9 commands (see section Conversions) can be used to round an existing value to a new precision.

It is important to distinguish the concepts of precision and 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 `exp(100)' would generate many more digits than you would typically need, while `exp(-100)' would probably round to zero! In Calc, both these computations give you exactly 12 (or the requested number of) significant digits.

The only Calc features that deal with accuracy instead of precision are fixed-point display mode for floats (d f; see section Float Formats), and the rounding functions like floor and round (see section Integer Truncation). Also, c 0 through c 9 deal with both precision and accuracy depending on the magnitudes of the numbers involved.

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 899 RET 6 /, yielding 149.833 (actually $1.49833 with our implied decimal point); pressing R would round this to 150 cents, i.e., $1.50.

See section Floats, for still more on floating-point precision and related issues.

Inverse and Hyperbolic Flags

There is no single-key equivalent to the calc-arcsin function. Instead, you must first press I (calc-inverse) to set the Inverse Flag, then press S (calc-sin). The I key actually toggles the Inverse Flag. When this flag is set, the word `Inv' appears in the mode line.

Likewise, the H key (calc-hyperbolic) sets or clears the Hyperbolic Flag, which transforms calc-sin into calc-sinh. If both of these flags are set at once, the effect will be calc-arcsinh. (The Hyperbolic flag is also used by some non-trigonometric commands; for example H L computes a base-10, instead of base-e, logarithm.)

Command names like calc-arcsin are provided for completeness, and may be executed with x or M-x. Their effect is simply to toggle the Inverse and/or Hyperbolic flags and then execute the corresponding base command (calc-sin in this case).

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 I or H (or K) are treated as prefix arguments for the next command, not as numeric entries. The same is true of C-u, but not of the minus sign (K - means to subtract and keep arguments).

The third Calc prefix flag, K (keep-arguments), is discussed elsewhere. See section Keep Arguments.

Calculation Modes

The commands in this section are two-key sequences beginning with the m prefix. (That's the letter m, not the META key.) The `m a' (calc-algebraic-mode) command is described elsewhere (see section Algebraic Entry).

Angular Modes

The Calculator supports three notations for angles: radians, degrees, and degrees-minutes-seconds. When a number is presented to a function like 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 sin, it is always interpreted as degrees-minutes-seconds.

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$} pi.)

The m r (calc-radians-mode), m d (calc-degrees-mode), and m h (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.

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 ( 2 SPC 3 ).

The m p (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.

Fraction Mode

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: 6 RET 1:4 * produces 3:2 even though 6 RET 4 / produces 1.5.

To set the Calculator to produce fractional results for normal integer divisions, use the m f (calc-frac-mode) command. For example, 8/4 produces 2 in either mode, but 6/4 produces 3:2 in Fraction Mode, 1.5 in Float Mode.

At any time you can use c f (calc-float) to convert a fraction to a float, or c F (calc-fraction) to convert a float to a fraction. See section Conversions.

Infinite Mode

The Calculator normally treats results like 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.

The m i (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 `[0 .. inf)' can be generated; however, intervals closed at infinity (`[0 .. inf]') will not be generated when infinite mode is off.)

With infinite mode turned on, `1 / 0' will generate uinf, an undirected infinity. See section Infinities, for a discussion of the difference between inf and uinf. Also, 0 / 0 evaluates to nan, the "indeterminate" symbol. Various other functions can also return infinities in this mode; for example, `ln(0) = -inf', and `gamma(-7) = uinf'. Once again, note that `exp(inf) = inf' regardless of infinite mode because this calculation has infinity as an input.

The m i command with a numeric prefix argument of zero, i.e., C-u 0 m i, turns on a "positive infinite mode" in which zero is treated as positive instead of being directionless. Thus, `1 / 0 = inf' and `-1 / 0 = -inf' in this mode. Note that zero never actually has a sign in Calc; there are no separate representations for +0 and -0. Positive infinite mode merely changes the interpretation given to the single symbol, `0'. One consequence of this is that, while you might expect `1 / -0 = -inf', actually `1 / -0' is equivalent to `1 / 0', which is equal to positive inf.

Symbolic Mode

Calculations are normally performed numerically wherever possible. For example, the calc-sqrt command, or 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: 2 Q pushes 1.4142 but ' x+1 RET Q pushes `sqrt(x+1)'.

In symbolic mode, controlled by the m s (calc-symbolic-mode) command, functions which would produce inexact, irrational results are left in symbolic form. Thus 16 Q pushes 4, but 2 Q pushes `sqrt(2)'.

The shift-N (calc-eval-num) command evaluates numerically the expression at the top of the stack, by temporarily disabling calc-symbolic-mode and executing = (calc-evaluate). Given a numeric prefix argument, it also sets the floating-point precision to the specified value for the duration of the command.

To evaluate a formula numerically without expanding the variables it contains, you can use the key sequence m s a v m s (this uses calc-alg-evaluate, which resimplifies but doesn't evaluate variables.)

Matrix and Scalar Modes

Calc sometimes makes assumptions during algebraic manipulation that are awkward or incorrect when vectors and matrices are involved. Calc has two modes, matrix mode and scalar mode, which modify its behavior around vectors in useful ways.

Press m v (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, `A*B' is not the same as `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., a - a and a / a, respectively) will now produce function calls that represent "generic" zero or identity matrices: `idn(0)', `idn(1)'. The idn function `idn(a,n)' returns a times an nxn identity matrix; if n is omitted, it doesn't know what dimension to use and so the 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 `idn(1) + 2'), Calc will assume it really was a scalar after all and produce, e.g., 3.

Press m v a second time to get scalar mode. Here, objects are assumed not to be vectors or matrices unless provably so. For example, normally adding a variable to a vector, as in `[x, y, z] + a', will leave the sum in symbolic form because as far as Calc knows, `a' could represent either a number or another 3-vector. In scalar mode, `a' is assumed to be a non-vector, and the addition is evaluated to `[x+a, y+a, z+a]'.

Press m v a third time to return to the normal mode of operation.

If you press m v with a numeric prefix argument n, you get a special "dimensioned matrix mode" in which matrices of unknown size are assumed to be nxn square matrices. Then, the function call `idn(1)' will expand into an actual matrix rather than representing a "generic" matrix.

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. See section Declarations, to see how to make declarations in Calc.

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 `[x+a, y+a, z+a]' shown above, and then stored `[1, 2, 3]' in `a'. The result would not be the same as for `[x, y, z] + [1, 2, 3]', but that's because you have broken your earlier promise to Calc that `a' would be scalar.

Another way to mix scalars and matrices is to use selections (see section Selecting Sub-Formulas). Use matrix mode when operating on your formula normally; then, to apply scalar mode to a certain part of the formula without affecting the rest just select that part, change into scalar mode and press = to resimplify the part under this mode, then change back to matrix mode before deselecting.

Automatic Recomputation

The evaluates-to operator, `=>', has the special property that any `=>' formulas on the stack are recomputed whenever variable values or mode settings that might affect them are changed. See section The Evaluates-To Operator.

The m C (calc-auto-recompute) command turns this automatic recomputation on and off. If you turn it off, Calc will not update `=>' operators on the stack (nor those in the attached Embedded Mode buffer, if there is one). They will not be updated unless you explicitly do so by pressing = or until you press m C to turn recomputation back on. (While automatic recomputation is off, you can think of m C m C as a command to update all `=>' operators while leaving recomputation off.)

To update `=>' operators in an Embedded buffer while automatic recomputation is off, use M-# u. See section Embedded Mode.

Working Messages

Since the Calculator is written entirely in Emacs Lisp, which is not designed for heavy numerical work, many operations are quite slow. The Calculator normally displays the message `Working...' in the echo area during any command that may be slow. In addition, iterative operations such as square roots and trigonometric functions display the intermediate result at each step. Both of these types of messages can be disabled if you find them distracting.

Type m w (calc-working) with a numeric prefix of 0 to disable all "working" messages. Use a numeric prefix of 1 to enable only the plain `Working...' message. Use a numeric prefix of 2 to see intermediate results as well. With no numeric prefix this displays the current mode.

While it may seem that the "working" messages will slow Calc down considerably, experiments have shown that their impact is actually quite small. But if your terminal is slow you may find that it helps to turn the messages off.

Simplification Modes

The current simplification mode controls how numbers and formulas are "normalized" when being taken from or pushed onto the stack. Some normalizations are unavoidable, such as rounding floating-point results to the current precision, and reducing fractions to simplest form. Others, such as simplifying a formula like a+a (or 2+3), are done by default but can be turned off when necessary.

When you press a key like + when 2 and 3 are on the stack, Calc pops these numbers, normalizes them, creates the formula 2+3, normalizes it, and pushes the result. Of course the standard rules for normalizing 2+3 will produce the result 5.

Simplification mode commands consist of the lower-case m prefix key followed by a shifted letter.

The m O (calc-no-simplify-mode) command turns off all optional simplifications. These would leave a formula like 2+3 alone. In fact, nothing except simple numbers are ever affected by normalization in this mode.

The m N (calc-num-simplify-mode) command turns off simplification of any formulas except those for which all arguments are constants. For example, 1+2 is simplified to 3, and a+(2-2) is simplified to a+0 but no further, since one argument of the sum is not a constant. Unfortunately, (a+2)-2 is not simplified because the top-level `-' operator's arguments are not both constant numbers (one of them is the formula a+2). A constant is a number or other numeric object (such as a constant error form or modulo form), or a vector all of whose elements are constant.

The m D (calc-default-simplify-mode) command restores the default simplifications for all formulas. This includes many easy and fast algebraic simplifications such as a+0 to a, and a + 2 a to 3 a, as well as evaluating functions like deriv(x^2, x) to 2 x.

The m B (calc-bin-simplify-mode) mode applies the default simplifications to a result and then, if the result is an integer, uses the b c (calc-clip) command to clip the integer according to the current binary word size. See section Binary Number Functions. Real numbers are rounded to the nearest integer and then clipped; other kinds of results (after the default simplifications) are left alone.

The m A (calc-alg-simplify-mode) mode does algebraic simplification; it applies all the default simplifications, and also the more powerful (and slower) simplifications made by a s (calc-simplify). See section Algebraic Simplifications.

The m E (calc-ext-simplify-mode) mode does "extended" algebraic simplification, as by the a e (calc-simplify-extended) command. See section "Unsafe" Simplifications.

The m U (calc-units-simplify-mode) mode does units simplification; it applies the command u s (calc-simplify-units), which in turn is a superset of a s. In this mode, variable names which are identifiable as unit names (like `mm' for "millimeters") are simplified with their unit definitions in mind.

A common technique is to set the simplification mode down to the lowest amount of simplification you will allow to be applied automatically, then use manual commands like a s and c c (calc-clean) to perform higher types of simplifications on demand. See section Programming with Formulas, for another sample use of no-simplification mode.

Declarations

A declaration is a statement you make that promises you will use a certain variable or function in a restricted way. This may give Calc the freedom to do things that it couldn't do if it had to take the fully general situation into account.

Declaration Basics

The s d (calc-declare-variable) command is the easiest way to make a declaration for a variable. This command prompts for the variable name, then prompts for the declaration. The default at the declaration prompt is the previous declaration, if any. You can edit this declaration, or press C-k to erase it and type a new declaration. (Or, erase it and press RET to clear the declaration, effectively "undeclaring" the variable.)

A declaration is in general a vector of type symbols and range values. If there is only one type symbol or range value, you can write it directly rather than enclosing it in a vector. For example, s d foo RET real RET declares foo to be a real number, and s d bar RET [int, const, [1..6]] RET declares bar to be a constant integer between 1 and 6. (Actually, you can omit the outermost brackets and Calc will provide them for you: s d bar RET int, const, [1..6] RET.)

Declarations in Calc are kept in a special variable called Decls. This variable encodes the set of all outstanding declarations in the form of a matrix. Each row has two elements: A variable or vector of variables declared by that row, and the declaration specifier as described above. You can use the s D command to edit this variable if you wish to see all the declarations at once. See section Other Operations on Variables, for a description of this command and the s p command that allows you to save your declarations permanently if you wish.

Items being declared can also be function calls. The arguments in the call are ignored; the effect is to say that this function returns values of the declared type for any valid arguments. The s d command declares only variables, so if you wish to make a function declaration you will have to edit the Decls matrix yourself.

For example, the declaration matrix

[ [ foo,       real       ]
  [ [j, k, n], int        ]
  [ f(1,2,3),  [0 .. inf) ] ]

declares that foo represents a real number, j, k and n represent integers, and the function f always returns a real number in the interval shown.

If there is a declaration for the variable All, then that declaration applies to all variables that are not otherwise declared. It does not apply to function names. For example, using the row `[All, real]' says that all your variables are real unless they are explicitly declared without real in some other row. The s d command declares All if you give a blank response to the variable-name prompt.

Kinds of Declarations

The type-specifier part of a declaration (that is, the second prompt in the s d command) can be a type symbol, an interval, or a vector consisting of zero or more type symbols followed by zero or more intervals or numbers that represent the set of possible values for the variable.

[ [ a, [1, 2, 3, 4, 5] ]
  [ b, [1 .. 5]        ]
  [ c, [int, 1 .. 5]   ] ]

Here a is declared to contain one of the five integers shown; b is any number in the interval from 1 to 5 (any real number since we haven't specified), and c is any integer in that interval. Thus the declarations for a and c are nearly equivalent (see below).

The type-specifier can be the empty vector `[]' to say that nothing is known about a given variable's value. This is the same as not declaring the variable at all except that it overrides any All declaration which would otherwise apply.

The initial value of Decls is the empty vector `[]'. If Decls has no stored value or if the value stored in it is not valid, it is ignored and there are no declarations as far as Calc is concerned. (The s d command will replace such a malformed value with a fresh empty matrix, `[]', before recording the new declaration.) Unrecognized type symbols are ignored.

The following type symbols describe what sorts of numbers will be stored in a variable:

int
Integers.
numint
Numerical integers. (Integers or integer-valued floats.)
frac
Fractions. (Rational numbers which are not integers.)
rat
Rational numbers. (Either integers or fractions.)
float
Floating-point numbers.
real
Real numbers. (Integers, fractions, or floats. Actually, intervals and error forms with real components also count as reals here.)
pos
Positive real numbers. (Strictly greater than zero.)
nonneg
Nonnegative real numbers. (Greater than or equal to zero.)
number
Numbers. (Real or complex.)

Calc uses this information to determine when certain simplifications of formulas are safe. For example, `(x^y)^z' cannot be simplified to `x^(y z)' in general; for example, `((-3)^2)^1:2' is 3, but `(-3)^(2*1:2) = (-3)^1' is -3. However, this simplification is safe if z is known to be an integer, or if x is known to be a nonnegative real number. If you have given declarations that allow Calc to deduce either of these facts, Calc will perform this simplification of the formula.

Calc can apply a certain amount of logic when using declarations. For example, `(x^y)^(2n+1)' will be simplified if n has been declared int; Calc knows that an integer times an integer, plus an integer, must always be an integer. (In fact, Calc would simplify `(-x)^(2n+1)' to `-(x^(2n+1))' since it is able to determine that `2n+1' must be an odd integer.)

Similarly, `(abs(x)^y)^z' will be simplified to `abs(x)^(y z)' because Calc knows that the abs function always returns a nonnegative real. If you had a myabs function that also had this property, you could get Calc to recognize it by adding the row `[myabs(), nonneg]' to the Decls matrix.

One instance of this simplification is `sqrt(x^2)' (since the sqrt function is effectively a one-half power). Normally Calc leaves this formula alone. After the command s d x RET real RET, however, it can simplify the formula to `abs(x)'. And after s d x RET nonneg RET, Calc can simplify this formula all the way to `x'.

If there are any intervals or real numbers in the type specifier, they comprise the set of possible values that the variable or function being declared can have. In particular, the type symbol real is effectively the same as the range `[-inf .. inf]' (note that infinity is included in the range of possible values); pos is the same as `(0 .. inf]', and nonneg is the same as `[0 .. inf]'. Saying `[real, [-5 .. 5]]' is redundant because the fact that the variable is real can be deduced just from the interval, but `[int, [-5 .. 5]]' and `[rat, [-5 .. 5]]' are useful combinations.

Note that the vector of intervals or numbers is in the same format used by Calc's set-manipulation commands. See section Set Operations using Vectors.

The type specifier `[1, 2, 3]' is equivalent to `[numint, 1, 2, 3]', not to `[int, 1, 2, 3]'. In other words, the range of possible values means only that the variable's value must be numerically equal to a number in that range, but not that it must be equal in type as well. Calc's set operations act the same way; `in(2, [1., 2., 3.])' and `in(1.5, [1:2, 3:2, 5:2])' both report "true."

If you use a conflicting combination of type specifiers, the results are unpredictable. An example is `[pos, [0 .. 5]]', where the interval does not lie in the range described by the type symbol.

"Real" declarations mostly affect simplifications involving powers like the one described above. Another case where they are used is in the a P command which returns a list of all roots of a polynomial; if the variable has been declared real, only the real roots (if any) will be included in the list.

"Integer" declarations are used for simplifications which are valid only when certain values are integers (such as `(x^y)^z' shown above).

Another command that makes use of declarations is a s, when simplifying equations and inequalities. It will cancel x from both sides of `a x = b x' only if it is sure x is non-zero, say, because it has a pos declaration. To declare specifically that x is real and non-zero, use `[[-inf .. 0), (0 .. inf]]'. (There is no way in the current notation to say that x is nonzero but not necessarily real.) The a e command does "unsafe" simplifications, including cancelling `x' from the equation when `x' is not known to be nonzero.

Another set of type symbols distinguish between scalars and vectors.

scalar
The value is not a vector.
vector
The value is a vector.
matrix
The value is a matrix (a rectangular vector of vectors).

These type symbols can be combined with the other type symbols described above; `[int, matrix]' describes an object which is a matrix of integers.

Scalar/vector declarations are used to determine whether certain algebraic operations are safe. For example, `[a, b, c] + x' is normally not simplified to `[a + x, b + x, c + x]', but it will be if x has been declared scalar. On the other hand, multiplication is usually assumed to be commutative, but the terms in `x y' will never be exchanged if both x and y are known to be vectors or matrices. (Calc currently never distinguishes between vector and matrix declarations.)

See section Matrix and Scalar Modes, for a discussion of "matrix mode" and "scalar mode," which are similar to declaring `[All, matrix]' or `[All, scalar]' but much more convenient.

One more type symbol that is recognized is used with the H a d command for taking total derivatives of a formula. See section Calculus.

const
The value is a constant with respect to other variables.

Calc does not check the declarations for a variable when you store a value in it. However, storing -3.5 in a variable that has been declared pos, int, or matrix may have unexpected effects; Calc may evaluate `sqrt(x^2)' to 3.5 if it substitutes the value first, or to -3.5 if x was declared pos and the formula `sqrt(x^2)' is simplified to `x' before the value is substituted. Before using a variable for a new purpose, it is best to use s d or s D to check to make sure you don't still have an old declaration for the variable that will conflict with its new meaning.

Functions for Declarations

Calc has a set of functions for accessing the current declarations in a convenient manner. These functions return 1 if the argument can be shown to have the specified property, or 0 if the argument can be shown not to have that property; otherwise they are left unevaluated. These functions are suitable for use with rewrite rules (see section Conditional Rewrite Rules) or programming constructs (see section Conditionals in Keyboard Macros). They can be entered only using algebraic notation. See section Logical Operations, for functions that perform other tests not related to declarations.

For example, `dint(17)' returns 1 because 17 is an integer, as do `dint(n)' and `dint(2 n - 3)' if n has been declared int, but `dint(2.5)' and `dint(n + 0.5)' return 0. Calc consults knowledge of its own built-in functions as well as your own declarations: `dint(floor(x))' returns 1.

The dint function checks if its argument is an integer. The dnatnum function checks if its argument is a natural number, i.e., a nonnegative integer. The dnumint function checks if its argument is numerically an integer, i.e., either an integer or an integer-valued float. Note that these and the other data type functions also accept vectors or matrices composed of suitable elements, and that real infinities `inf' and `-inf' are considered to be integers for the purposes of these functions.

The drat function checks if its argument is rational, i.e., an integer or fraction. Infinities count as rational, but intervals and error forms do not.

The dreal function checks if its argument is real. This includes integers, fractions, floats, real error forms, and intervals.

The dimag function checks if its argument is imaginary, i.e., is mathematically equal to a real number times i.

The dpos function checks for positive (but nonzero) reals. The dneg function checks for negative reals. The dnonneg function checks for nonnegative reals, i.e., reals greater than or equal to zero. Note that the a s command can simplify an expression like x > 0 to 1 or 0 using dpos, and that a s is effectively applied to all conditions in rewrite rules, so the actual functions dpos, dneg, and dnonneg are rarely necessary.

The dnonzero function checks that its argument is nonzero. This includes all nonzero real or complex numbers, all intervals that do not include zero, all nonzero modulo forms, vectors all of whose elements are nonzero, and variables or formulas whose values can be deduced to be nonzero. It does not include error forms, since they represent values which could be anything including zero. (This is also the set of objects considered "true" in conditional contexts.)

The deven function returns 1 if its argument is known to be an even integer (or integer-valued float); it returns 0 if its argument is known not to be even (because it is known to be odd or a non-integer). The a s command uses this to simplify a test of the form `x % 2 = 0'. There is also an analogous dodd function.

The drange function returns a set (an interval or a vector of intervals and/or numbers; see section Set Operations using Vectors) that describes the set of possible values of its argument. If the argument is a variable or a function with a declaration, the range is copied from the declaration. Otherwise, the possible signs of the expression are determined using a method similar to dpos, etc., and a suitable set like `[0 .. inf]' is returned. If the expression is not provably real, the drange function remains unevaluated.

The dscalar function returns 1 if its argument is provably scalar, or 0 if its argument is provably non-scalar. It is left unevaluated if this cannot be determined. (If matrix mode or scalar mode are in effect, this function returns 1 or 0, respectively, if it has no other information.) When Calc interprets a condition (say, in a rewrite rule) it considers an unevaluated formula to be "false." Thus, `dscalar(a)' is "true" only if a is provably scalar, and `!dscalar(a)' is "true" only if a is provably non-scalar; both are "false" if there is insufficient information to tell.

Display Modes

The commands in this section are two-key sequences beginning with the d prefix. The d l (calc-line-numbering) and d b (calc-line-breaking) commands are described elsewhere; see section Stack Basics and see section Normal Language Modes, respectively. Display formats for vectors and matrices are also covered elsewhere; see section Vector and Matrix Display Formats.

One thing all display modes have in common is their treatment of the H prefix. This prefix causes any mode command that would normally refresh the stack to leave the stack display alone. The word "Dirty" will appear in the mode line when Calc thinks the stack display may not reflect the latest mode settings.

The d RET (calc-refresh-top) command reformats the top stack entry according to all the current modes. Positive prefix arguments reformat the top n entries; negative prefix arguments reformat the specified entry, and a prefix of zero is equivalent to d SPC (calc-refresh), which reformats the entire stack. For example, H d s M-2 d RET changes to scientific notation but reformats only the top two stack entries in the new mode.

The I prefix has another effect on the display modes. The mode is set only temporarily; the top stack entry is reformatted according to that mode, then the original mode setting is restored. In other words, I d s is equivalent to H d s d RET H d (old mode).

Radix Modes

Calc normally displays numbers in decimal (base-10 or radix-10) notation. Calc can actually display in any radix from two (binary) to 36. When the radix is above 10, the letters A to Z are used as digits. When entering such a number, letter keys are interpreted as potential digits rather than terminating numeric entry mode.

The key sequences d 2, d 8, d 6, and d 0 select binary, octal, hexadecimal, and decimal as the current display radix, respectively. Numbers can always be entered in any radix, though the current radix is used as a default if you press # without any initial digits. A number entered without a # is always interpreted as decimal.

To set the radix generally, use d r (calc-radix) and enter an integer from 2 to 36. You can specify the radix as a numeric prefix argument; otherwise you will be prompted for it.

Integers normally are displayed with however many digits are necessary to represent the integer and no more. The d z (calc-leading-zeros) command causes integers to be padded out with leading zeros according to the current binary word size. (See section Binary Number Functions, for a discussion of word size.) If the absolute value of the word size is w, all integers are displayed with at least enough digits to represent @c{$2^w-1$} (2^w)-1 in the current radix. (Larger integers will still be displayed in their entirety.)

Grouping Digits

Long numbers can be hard to read if they have too many digits. For example, the factorial of 30 is 33 digits long! Press d g (calc-group-digits) to enable grouping mode, in which digits are displayed in clumps of 3 or 4 (depending on the current radix) separated by commas.

The d g command toggles grouping on and off. With a numerix prefix of 0, this command displays the current state of the grouping flag; with an argument of minus one it disables grouping; with a positive argument N it enables grouping on every N digits. For floating-point numbers, grouping normally occurs only before the decimal point. A negative prefix argument -N enables grouping every N digits both before and after the decimal point.

The d , (calc-group-char) command allows you to choose any character as the grouping separator. The default is the comma character. If you find it difficult to read vectors of large integers grouped with commas, you may wish to use spaces or some other character instead. This command takes the next character you type, whatever it is, and uses it as the digit separator. As a special case, d , \ selects `\,' (TeX's thin-space symbol) as the digit separator.

Please note that grouped numbers will not generally be parsed correctly if re-read in textual form, say by the use of M-# y and M-# g. (See section Kill and Yank Functions, for details on these commands.) One exception is the `\,' separator, which doesn't interfere with parsing because it is ignored by TeX language mode.

Float Formats

Floating-point quantities are normally displayed in standard decimal form, with scientific notation used if the exponent is especially high or low. All significant digits are normally displayed. The commands in this section allow you to choose among several alternative display formats for floats.

The d n (calc-normal-notation) command selects the normal display format. All significant figures in a number are displayed. With a positive numeric prefix, numbers are rounded if necessary to that number of significant digits. With a negative numerix prefix, the specified number of significant digits less than the current precision is used. (Thus C-u -2 d n displays 10 digits if the current precision is 12.)

The d f (calc-fix-notation) command selects fixed-point notation. The numeric argument is the number of digits after the decimal point, zero or more. This format will relax into scientific notation if a nonzero number would otherwise have been rounded all the way to zero. Specifying a negative number of digits is the same as for a positive number, except that small nonzero numbers will be rounded to zero rather than switching to scientific notation.

The d s (calc-sci-notation) command selects scientific notation. A positive argument sets the number of significant figures displayed, of which one will be before and the rest after the decimal point. A negative argument works the same as for d n format. The default is to display all significant digits.

The d e (calc-eng-notation) command selects engineering notation. This is similar to scientific notation except that the exponent is rounded down to a multiple of three, with from one to three digits before the decimal point. An optional numeric prefix sets the number of significant digits to display, as for d s.

It is important to distinguish between the current precision and the current display format. After the commands C-u 10 p and C-u 6 d n the Calculator computes all results to ten significant figures but displays only six. (In fact, intermediate calculations are often carried to one or two more significant figures, but values placed on the stack will be rounded down to ten figures.) Numbers are never actually rounded to the display precision for storage, except by commands like C-k and M-# y which operate on the actual displayed text in the Calculator buffer.

The d . (calc-point-char) command selects the character used as a decimal point. Normally this is a period; users in some countries may wish to change this to a comma. Note that this is only a display style; on entry, periods must always be used to denote floating-point numbers, and commas to separate elements in a list.

Complex Formats

There are three supported notations for complex numbers in rectangular form. The default is as a pair of real numbers enclosed in parentheses and separated by a comma: `(a,b)'. The d c (calc-complex-notation) command selects this style.

The other notations are d i (calc-i-notation), in which numbers are displayed in `a+bi' form, and d j (calc-j-notation) which displays the form `a+bj' preferred in some disciplines.

Complex numbers are normally entered in `(a,b)' format. If you enter `2+3i' as an algebraic formula, it will be stored as the formula `2 + 3 * i'. However, if you use = to evaluate this formula and you have not changed the variable `i', the `i' will be interpreted as `(0,1)' and the formula will be simplified to `(2,3)'. Other commands (like calc-sin) will not interpret the formula `2 + 3 * i' as a complex number. See section Variables, under "special constants."

Fraction Formats

Display of fractional numbers is controlled by the d o (calc-over-notation) command. By default, a number like eight thirds is displayed in the form `8:3'. The d o command prompts for a one- or two-character format. If you give one character, that character is used as the fraction separator. Common separators are `:' and `/'. (During input of numbers, the : key must be used regardless of the display format; in particular, the / is used for RPN-style division, not for entering fractions.)

If you give two characters, fractions use "integer-plus-fractional-part" notation. For example, the format `+/' would display eight thirds as `2+2/3'. If two colons are present in a number being entered, the number is interpreted in this form (so that the entries 2:2:3 and 8:3 are equivalent).

It is also possible to follow the one- or two-character format with a number. For example: `:10' or `+/3'. In this case, Calc adjusts all fractions that are displayed to have the specified denominator, if possible. Otherwise it adjusts the denominator to be a multiple of the specified value. For example, in `:6' mode the fraction 1:6 will be unaffected, but 2:3 will be displayed as 4:6, 1:2 will be displayed as 3:6, and 1:8 will be displayed as 3:24. Integers are also affected by this mode: 3 is displayed as 18:6. Note that the format `:1' writes fractions the same as `:', but it writes integers as n:1.

The fraction format does not affect the way fractions or integers are stored, only the way they appear on the screen. The fraction format never affects floats.

HMS Formats

The d h (calc-hms-notation) command controls the display of HMS (hours-minutes-seconds) forms. It prompts for a string which consists basically of an "hours" marker, optional punctuation, a "minutes" marker, more optional punctuation, and a "seconds" marker. Punctuation is zero or more spaces, commas, or semicolons. The hours marker is one or more non-punctuation characters. The minutes and seconds markers must be single non-punctuation characters.

The default HMS format is `@ ' "', producing HMS values of the form `23@ 30' 15.75"'. The format `deg, ms' would display this same value as `23deg, 30m15.75s'. During numeric entry, the h or o keys are recognized as synonyms for @ regardless of display format. The m and s keys are recognized as synonyms for ' and ", respectively, but only if an @ (or h or o) has already been typed; otherwise, they have their usual meanings (m- prefix and s- prefix). Thus, 5 ", 0 @ 5 ", and 0 h 5 s are some of the ways to enter the quantity "five seconds." The ' key is recognized as "minutes" only if @ (or h or o) has already been pressed; otherwise it means to switch to algebraic entry.

Date Formats

The d d (calc-date-notation) command controls the display of date forms (see section Date Forms). It prompts for a string which contains letters that represent the various parts of a date and time. To show which parts should be omitted when the form represents a pure date with no time, parts of the string can be enclosed in `< >' marks. If you don't include `< >' markers in the format, Calc guesses at which parts, if any, should be omitted when formatting pure dates.

The default format is: `<H:mm:SSpp >Www Mmm D, YYYY'. An example string in this format is `3:32pm Wed Jan 9, 1991'. If you enter a blank format string, this default format is reestablished.

Calc uses `< >' notation for nameless functions as well as for dates. See section Specifying Operators. To avoid confusion with nameless functions, your date formats should avoid using the `#' character.

Date Formatting Codes

When displaying a date, the current date format is used. All characters except for letters and `<' and `>' are copied literally when dates are formatted. The portion between `< >' markers is omitted for pure dates, or included for date/time forms. Letters are interpreted according to the table below.

When dates are read in during algebraic entry, Calc first tries to match the input string to the current format either with or without the time part. The punctuation characters (including spaces) must match exactly; letter fields must correspond to suitable text in the input. If this doesn't work, Calc checks if the input is a simple number; if so, the number is interpreted as a number of days since Jan 1, 1 AD. Otherwise, Calc tries a much more relaxed and flexible algorithm which is described in the next section.

Weekday names are ignored during reading.

Two-digit year numbers are interpreted as lying in the range from 1941 to 2039. Years outside that range are always entered and displayed in full. Year numbers with a leading `+' sign are always interpreted exactly, allowing the entry and display of the years 1 through 99 AD.

Here is a complete list of the formatting codes for dates:

Y
Year: "91" for 1991, "7" for 2007, "+23" for 23 AD.
YY
Year: "91" for 1991, "07" for 2007, "+23" for 23 AD.
BY
Year: "91" for 1991, " 7" for 2007, "+23" for 23 AD.
YYY
Year: "1991" for 1991, "23" for 23 AD.
YYYY
Year: "1991" for 1991, "+23" for 23 AD.
aa
Year: "ad" or blank.
AA
Year: "AD" or blank.
aaa
Year: "ad " or blank. (Note trailing space.)
AAA
Year: "AD " or blank.
aaaa
Year: "a.d." or blank.
AAAA
Year: "A.D." or blank.
bb
Year: "bc" or blank.
BB
Year: "BC" or blank.
bbb
Year: " bc" or blank. (Note leading space.)
BBB
Year: " BC" or blank.
bbbb
Year: "b.c." or blank.
BBBB
Year: "B.C." or blank.
M
Month: "8" for August.
MM
Month: "08" for August.
BM
Month: " 8" for August.
MMM
Month: "AUG" for August.
Mmm
Month: "Aug" for August.
mmm
Month: "aug" for August.
MMMM
Month: "AUGUST" for August.
Mmmm
Month: "August" for August.
D
Day: "7" for 7th day of month.
DD
Day: "07" for 7th day of month.
BD
Day: " 7" for 7th day of month.
W
Weekday: "0" for Sunday, "6" for Saturday.
WWW
Weekday: "SUN" for Sunday.
Www
Weekday: "Sun" for Sunday.
www
Weekday: "sun" for Sunday.
WWWW
Weekday: "SUNDAY" for Sunday.
Wwww
Weekday: "Sunday" for Sunday.
d
Day of year: "34" for Feb. 3.
ddd
Day of year: "034" for Feb. 3.
bdd
Day of year: " 34" for Feb. 3.
h
Hour: "5" for 5 AM; "17" for 5 PM.
hh
Hour: "05" for 5 AM; "17" for 5 PM.
bh
Hour: " 5" for 5 AM; "17" for 5 PM.
H
Hour: "5" for 5 AM and 5 PM.
HH
Hour: "05" for 5 AM and 5 PM.
BH
Hour: " 5" for 5 AM and 5 PM.
p
AM/PM: "a" or "p".
P
AM/PM: "A" or "P".
pp
AM/PM: "am" or "pm".
PP
AM/PM: "AM" or "PM".
pppp
AM/PM: "a.m." or "p.m.".
PPPP
AM/PM: "A.M." or "P.M.".
m
Minutes: "7" for 7.
mm
Minutes: "07" for 7.
bm
Minutes: " 7" for 7.
s
Seconds: "7" for 7; "7.23" for 7.23.
ss
Seconds: "07" for 7; "07.23" for 7.23.
bs
Seconds: " 7" for 7; " 7.23" for 7.23.
SS
Optional seconds: "07" for 7; blank for 0.
BS
Optional seconds: " 7" for 7; blank for 0.
N
Numeric date/time: "726842.25" for 6:00am Wed Jan 9, 1991.
n
Numeric date: "726842" for any time on Wed Jan 9, 1991.
J
Julian date/time: "2448265.75" for 6:00am Wed Jan 9, 1991.
j
Julian date: "2448266" for any time on Wed Jan 9, 1991.
U
Unix time: "663400800" for 6:00am Wed Jan 9, 1991.
X
Brackets suppression. An "X" at the front of the format causes the surrounding `< >' delimiters to be omitted when formatting dates. Note that the brackets are still required for algebraic entry.

If "SS" or "BS" (optional seconds) is preceded by a colon, the colon is also omitted if the seconds part is zero.

If "bb," "bbb" or "bbbb" or their upper-case equivalents appear in the format, then negative year numbers are displayed without a minus sign. Note that "aa" and "bb" are mutually exclusive. Some typical usages would be `YYYY AABB'; `AAAYYYYBBB'; `YYYYBBB'.

The formats "YY," "YYYY," "MM," "DD," "ddd," "hh," "HH," "mm," "ss," and "SS" actually match any number of digits during reading unless several of these codes are strung together with no punctuation in between, in which case the input must have exactly as many digits as there are letters in the format.

The "j," "J," and "U" formats do not make any time zone adjustment. They effectively use `julian(x,0)' and `unixtime(x,0)' to make the conversion; see section Date Arithmetic.

Free-Form Dates

When reading a date form during algebraic entry, Calc falls back on the algorithm described here if the input does not exactly match the current date format. This algorithm generally "does the right thing" and you don't have to worry about it, but it is described here in full detail for the curious.

Calc does not distinguish between upper- and lower-cnversion; see section Date Arithmetic.

Free-Form Dates

When reading a date form during algebraic entry, Calc falls back on the algorithm described here if the input does not exactly match the current date format. This algorithm generally "does the right thing" and you don't have to worry about it, but it is described here in full detail for the curious.

Calc does not distinguish between upper- and lower-c