Go to the first, previous, next, last section, table of contents.

# Data Types

This chapter discusses the various types of objects that can be placed on the Calculator stack, how they are displayed, and how they are entered. (See section Data Type Formats, for information on how these data types are represented as underlying Lisp objects.)

Integers, fractions, and floats are various ways of describing real numbers. HMS forms also for many purposes act as real numbers. These types can be combined to form complex numbers, modulo forms, error forms, or interval forms. (But these last four types cannot be combined arbitrarily: error forms may not contain modulo forms, for example.) Finally, all these types of numbers may be combined into vectors, matrices, or algebraic formulas.

## Integers

The Calculator stores integers to arbitrary precision. Addition, subtraction, and multiplication of integers always yields an exact integer result. (If the result of a division or exponentiation of integers is not an integer, it is expressed in fractional or floating-point form according to the current Fraction Mode. See section Fraction Mode.)

A decimal integer is represented as an optional sign followed by a sequence of digits. Grouping (see section Grouping Digits) can be used to insert a comma at every third digit for display purposes, but you must not type commas during the entry of numbers.

A non-decimal integer is represented as an optional sign, a radix between 2 and 36, a #' symbol, and one or more digits. For radix 11 and above, the letters A through Z (upper- or lower-case) count as digits and do not terminate numeric entry mode. See section Radix Modes, for how to set the default radix for display of integers. Numbers of any radix may be entered at any time. If you press # at the beginning of a number, the current display radix is used.

## Fractions

A fraction is a ratio of two integers. Fractions are traditionally written "2/3" but Calc uses the notation 2:3'. (The / key performs RPN division; the following two sequences push the number 2:3' on the stack: 2 : 3 RET, or 2 RET 3 / assuming Fraction Mode has been enabled.) When the Calculator produces a fractional result it always reduces it to simplest form, which may in fact be an integer.

Fractions may also be entered in a three-part form, where 2:3:4' represents two-and-three-quarters. See section Fraction Formats, for fraction display formats.

Non-decimal fractions are entered and displayed as radix#num:denom' (or in the analogous three-part form). The numerator and denominator always use the same radix.

## Floats

A floating-point number or float is a number stored in scientific notation. The number of significant digits in the fractional part is governed by the current floating precision (see section Precision). The range of acceptable values is from @c{$10^{-3999999}$} 10^-3999999 (inclusive) to @c{$10^{4000000}$} 10^4000000 (exclusive), plus the corresponding negative values and zero.

Calculations that would exceed the allowable range of values (such as exp(exp(20))') are left in symbolic form by Calc. The messages "floating-point overflow" or "floating-point underflow" indicate that during the calculation a number would have been produced that was too large or too close to zero, respectively, to be represented by Calc. This does not necessarily mean the final result would have overflowed, just that an overflow occurred while computing the result. (In fact, it could report an underflow even though the final result would have overflowed!)

If a rational number and a float are mixed in a calculation, the result will in general be expressed as a float. Commands that require an integer value (such as k g [gcd]) will also accept integer-valued floats, i.e., floating-point numbers with nothing after the decimal point.

Floats are identified by the presence of a decimal point and/or an exponent. In general a float consists of an optional sign, digits including an optional decimal point, and an optional exponent consisting of an e', an optional sign, and up to seven exponent digits. For example, 23.5e-2' is 23.5 times ten to the minus-second power, or 0.235.

Floating-point numbers are normally displayed in decimal notation with all significant figures shown. Exceedingly large or small numbers are displayed in scientific notation. Various other display options are available. See section Float Formats.

Floating-point numbers are stored in decimal, not binary. The result of each operation is rounded to the nearest value representable in the number of significant digits specified by the current precision, rounding away from zero in the case of a tie. Thus (in the default display mode) what you see is exactly what you get. Some operations such as square roots and transcendental functions are performed with several digits of extra precision and then rounded down, in an effort to make the final result accurate to the full requested precision. However, accuracy is not rigorously guaranteed. If you suspect the validity of a result, try doing the same calculation in a higher precision. The Calculator's arithmetic is not intended to be IEEE-conformant in any way.

While floats are always stored in decimal, they can be entered and displayed in any radix just like integers and fractions. The notation radix#ddd.ddd' is a floating-point number whose digits are in the specified radix. Note that the .' is more aptly referred to as a "radix point" than as a decimal point in this case. The number 8#123.4567' is defined as 8#1234567 * 8^-4'. If the radix is 14 or less, you can use e' notation to write a non-decimal number in scientific notation. The exponent is written in decimal, and is considered to be a power of the radix: 8#1234567e-4'. If the radix is 15 or above, the letter e' is a digit, so scientific notation must be written out, e.g., 16#123.4567*16^2'. The first two exercises of the Modes Tutorial explore some of the properties of non-decimal floats.

## Complex Numbers

There are two supported formats for complex numbers: rectangular and polar. The default format is rectangular, displayed in the form (real,imag)' where real is the real part and imag is the imaginary part, each of which may be any real number. Rectangular complex numbers can also be displayed in a+bi' notation; see section Complex Formats.

Polar complex numbers are displayed in the form (r;@c{$\theta$} theta)' where r is the nonnegative magnitude and @c{$\theta$} theta is the argument or phase angle. The range of @c{$\theta$} theta depends on the current angular mode (see section Angular Modes); it is generally between -180 and +180 degrees or the equivalent range in radians.

Complex numbers are entered in stages using incomplete objects. See section Incomplete Objects.

Operations on rectangular complex numbers yield rectangular complex results, and similarly for polar complex numbers. Where the two types are mixed, or where new complex numbers arise (as for the square root of a negative real), the current Polar Mode is used to determine the type. See section Polar Mode.

A complex result in which the imaginary part is zero (or the phase angle is 0 or 180 degrees or @c{$\pi$} pi radians) is automatically converted to a real number.

## Infinities

The word inf represents the mathematical concept of infinity. Calc actually has three slightly different infinity-like values: inf, uinf, and nan. These are just regular variable names (see section Variables); you should avoid using these names for your own variables because Calc gives them special treatment. Infinities, like all variable names, are normally entered using algebraic entry.

Mathematically speaking, it is not rigorously correct to treat "infinity" as if it were a number, but mathematicians often do so informally. When they say that 1 / inf = 0', what they really mean is that 1 / x, as x becomes larger and larger, becomes arbitrarily close to zero. So you can imagine that if x got "all the way to infinity," then 1 / x would go all the way to zero. Similarly, when they say that exp(inf) = inf', they mean that @c{$e^x$} exp(x) grows without bound as x grows. The symbol -inf' likewise stands for an infinitely negative real value; for example, we say that exp(-inf) = 0'. You can have an infinity pointing in any direction on the complex plane: sqrt(-inf) = i inf'.

The same concept of limits can be used to define 1 / 0. We really want the value that 1 / x approaches as x approaches zero. But if all we have is 1 / 0, we can't tell which direction x was coming from. If x was positive and decreasing toward zero, then we should say that 1 / 0 = inf'. But if x was negative and increasing toward zero, the answer is 1 / 0 = -inf'. In fact, x could be an imaginary number, giving the answer i inf' or -i inf'. Calc uses the special symbol uinf' to mean undirected infinity, i.e., a value which is infinitely large but with an unknown sign (or direction on the complex plane).

Calc actually has three modes that say how infinities are handled. Normally, infinities never arise from calculations that didn't already have them. Thus, 1 / 0 is treated simply as an error and left unevaluated. The m i (calc-infinite-mode) command (see section Infinite Mode) enables a mode in which 1 / 0 evaluates to uinf instead. There is also an alternative type of infinite mode which says to treat zeros as if they were positive, so that 1 / 0 = inf'. While this is less mathematically correct, it may be the answer you want in some cases.

Since all infinities are "as large" as all others, Calc simplifies, e.g., 5 inf' to inf'. Another example is 5 - inf = -inf', where the -inf' is so large that adding a finite number like five to it does not affect it. Note that a - inf' also results in -inf'; Calc assumes that variables like a always stand for finite quantities. Just to show that infinities really are all the same size, note that sqrt(inf) = inf^2 = exp(inf) = inf' in Calc's notation.

It's not so easy to define certain formulas like 0 * inf' and inf / inf'. Depending on where these zeros and infinities came from, the answer could be literally anything. The latter formula could be the limit of x / x (giving a result of one), or 2 x / x (giving two), or x^2 / x (giving inf), or x / x^2 (giving zero). Calc uses the symbol nan to represent such an indeterminate value. (The name "nan" comes from analogy with the "NAN" concept of IEEE standard arithmetic; it stands for "Not A Number." This is somewhat of a misnomer, since nan does stand for some number or infinity, it's just that which number it stands for cannot be determined.) In Calc's notation, 0 * inf = nan' and inf / inf = nan'. A few other common indeterminate expressions are inf - inf' and inf ^ 0'. Also, 0 / 0 = nan' if you have turned on "infinite mode" (as described above).

Infinities are especially useful as parts of intervals. See section Interval Forms.

## Vectors and Matrices

The vector data type is flexible and general. A vector is simply a list of zero or more data objects. When these objects are numbers, the whole is a vector in the mathematical sense. When these objects are themselves vectors of equal (nonzero) length, the whole is a matrix. A vector which is not a matrix is referred to here as a plain vector.

A vector is displayed as a list of values separated by commas and enclosed in square brackets: [1, 2, 3]'. Thus the following is a 2 row by 3 column matrix: [[1, 2, 3], [4, 5, 6]]'. Vectors, like complex numbers, are entered as incomplete objects. See section Incomplete Objects. During algebraic entry, vectors are entered all at once in the usual brackets-and-commas form. Matrices may be entered algebraically as nested vectors, or using the shortcut notation [1, 2, 3; 4, 5, 6]', with rows separated by semicolons. The commas may usually be omitted when entering vectors: [1 2 3]'. Curly braces may be used in place of brackets: {1, 2, 3}', but the commas are required in this case.

Traditional vector and matrix arithmetic is also supported; see section Basic Arithmetic and see section Vector/Matrix Functions. Many other operations are applied to vectors element-wise. For example, the complex conjugate of a vector is a vector of the complex conjugates of its elements.

Algebraic functions for building vectors include vec(a, b, c)' to build [a, b, c]', cvec(a, n, m)' to build an @c{$n\times m$} nxm matrix of a's, and index(n)' to build a vector of integers from 1 to n'.

## Strings

Character strings are not a special data type in the Calculator. Rather, a string is represented simply as a vector all of whose elements are integers in the range 0 to 255 (ASCII codes). You can enter a string at any time by pressing the " key. Quotation marks and backslashes are written \"' and \\', respectively, inside strings. Other notations introduced by backslashes are:

\a     7          \^@    0
\b     8          \^a-z  1-26
\e     27         \^[    27
\f     12         \^\\   28
\n     10         \^]    29
\r     13         \^^    30
\t     9          \^_    31
\^?    127


Finally, a backslash followed by three octal digits produces any character from its ASCII code.

Strings are normally displayed in vector-of-integers form. The d " (calc-display-strings) command toggles a mode in which any vectors of small integers are displayed as quoted strings instead.

The backslash notations shown above are also used for displaying strings. Characters 128 and above are not translated by Calc; unless you have an Emacs modified for 8-bit fonts, these will show up in backslash-octal-digits notation. For characters below 32, and for character 127, Calc uses the backslash-letter combination if there is one, or otherwise uses a \^' sequence.

The only Calc feature that uses strings is compositions; see section Compositions. Strings also provide a convenient way to do conversions between ASCII characters and integers.

There is a string function which provides a different display format for strings. Basically, string(s)', where s is a vector of integers in the proper range, is displayed as the corresponding string of characters with no surrounding quotation marks or other modifications. Thus string("ABC")' (or string([65 66 67])') will look like ABC' on the stack. This happens regardless of whether d " has been used. The only way to turn it off is to use d U (unformatted language mode) which will display string("ABC")' instead.

Control characters are displayed somewhat differently by string. Characters below 32, and character 127, are shown using ^' notation (same as shown above, but without the backslash). The quote and backslash characters are left alone, as are characters 128 and above.

The bstring function is just like string except that the resulting string is breakable across multiple lines if it doesn't fit all on one line. Potential break points occur at every space character in the string.

## HMS Forms

HMS stands for Hours-Minutes-Seconds; when used as an angular argument, the interpretation is Degrees-Minutes-Seconds. All functions that operate on angles accept HMS forms. These are interpreted as degrees regardless of the current angular mode. It is also possible to use HMS as the angular mode so that calculated angles are expressed in degrees, minutes, and seconds.

The default format for HMS values is hours@ mins' secs"'. During entry, the letters h' (for "hours") or o' (approximating the "degrees" symbol) are accepted as well as @', m' is accepted in place of '', and s' is accepted in place of "'. The hours value is an integer (or integer-valued float). The mins value is an integer or integer-valued float between 0 and 59. The secs value is a real number between 0 (inclusive) and 60 (exclusive). A positive HMS form is interpreted as hours + mins/60 + secs/3600. A negative HMS form is interpreted as - hours - mins/60 - secs/3600. Display format for HMS forms is quite flexible. See section HMS Formats.

HMS forms can be added and subtracted. When they are added to numbers, the numbers are interpreted according to the current angular mode. HMS forms can also be multiplied and divided by real numbers. Dividing two HMS forms produces a real-valued ratio of the two angles.

Just for kicks, M-x calc-time pushes the current time of day on the stack as an HMS form.

## Date Forms

A date form represents a date and possibly an associated time. Simple date arithmetic is supported: Adding a number to a date produces a new date shifted by that many days; adding an HMS form to a date shifts it by that many hours. Subtracting two date forms computes the number of days between them (represented as a simple number). Many other operations, such as multiplying two date forms, are nonsensical and are not allowed by Calc.

Date forms are entered and displayed enclosed in < >' brackets. The default format is, e.g., <Wed Jan 9, 1991>' for dates, or <3:32:20pm Wed Jan 9, 1991>' for dates with times. Input is flexible; date forms can be entered in any of the usual notations for dates and times. See section Date Formats.

Date forms are stored internally as numbers, specifically the number of days since midnight on the morning of January 1 of the year 1 AD. If the internal number is an integer, the form represents a date only; if the internal number is a fraction or float, the form represents a date and time. For example, <6:00am Wed Jan 9, 1991>' is represented by the number 726842.25. The standard precision of 12 decimal digits is enough to ensure that a (reasonable) date and time can be stored without roundoff error.

If the current precision is greater than 12, date forms will keep additional digits in the seconds position. For example, if the precision is 15, the seconds will keep three digits after the decimal point. Decreasing the precision below 12 may cause the time part of a date form to become inaccurate. This can also happen if astronomically high years are used, though this will not be an issue in everyday (or even everymillenium) use. Note that date forms without times are stored as exact integers, so roundoff is never an issue for them.

You can use the v p (calc-pack) and v u (calc-unpack) commands to get at the numerical representation of a date form. See section Packing and Unpacking.

Date forms can go arbitrarily far into the future or past. Negative year numbers represent years BC. Calc uses a combination of the Gregorian and Julian calendars, following the history of Great Britain and the British colonies. This is the same calendar that is used by the cal program in most Unix implementations.

Some historical background: The Julian calendar was created by Julius Caesar in the year 46 BC as an attempt to fix the gradual drift caused by the lack of leap years in the calendar used until that time. The Julian calendar introduced an extra day in all years divisible by four. After some initial confusion, the calendar was adopted around the year we call 8 AD. Some centuries later it became apparent that the Julian year of 365.25 days was itself not quite right. In 1582 Pope Gregory XIII introduced the Gregorian calendar, which added the new rule that years divisible by 100, but not by 400, were not to be considered leap years despite being divisible by four. Many countries delayed adoption of the Gregorian calendar because of religious differences; in Britain it was put off until the year 1752, by which time the Julian calendar had fallen eleven days behind the true seasons. So the switch to the Gregorian calendar in early September 1752 introduced a discontinuity: The day after Sep 2, 1752 is Sep 14, 1752. Calc follows this convention. To take another example, Russia waited until 1918 before adopting the new calendar, and thus needed to remove thirteen days (between Feb 1, 1918 and Feb 14, 1918). This means that Calc's reckoning will be inconsistent with Russian history between 1752 and 1918, and similarly for various other countries.

Today's timekeepers introduce an occasional "leap second" as well, but Calc does not take these minor effects into account. (If it did, it would have to report a non-integer number of days between, say, <12:00am Mon Jan 1, 1900>' and <12:00am Sat Jan 1, 2000>'.)

Calc uses the Julian calendar for all dates before the year 1752, including dates BC when the Julian calendar technically had not yet been invented. Thus the claim that day number -10000 is called "August 16, 28 BC" should be taken with a grain of salt.

Please note that there is no "year 0"; the day before <Sat Jan 1, +1>' is <Fri Dec 31, -1>'. These are days 0 and -1 respectively in Calc's internal numbering scheme.

Another day counting system in common use is, confusingly, also called "Julian." It was invented in 1583 by Joseph Justus Scaliger, who named it in honor of his father Julius Caesar Scaliger. For obscure reasons he chose to start his day numbering on Jan 1, 4713 BC at noon, which in Calc's scheme is -1721423.5 (recall that Calc starts at midnight instead of noon). Thus to convert a Calc date code obtained by unpacking a date form into a Julian day number, simply add 1721423.5. The Julian code for 6:00am Jan 9, 1991' is 2448265.75. The built-in t J command performs this conversion for you.

The Unix operating system measures time as an integer number of seconds since midnight, Jan 1, 1970. To convert a Calc date value into a Unix time stamp, first subtract 719164 (the code for <Jan 1, 1970>'), then multiply by 86400 (the number of seconds in a day) and press R to round to the nearest integer. If you have a date form, you can simply subtract the day <Jan 1, 1970>' instead of unpacking and subtracting 719164. Likewise, divide by 86400 and add <Jan 1, 1970>' to convert from Unix time to a Calc date form. (Note that Unix normally maintains the time in the GMT time zone; you may need to subtract five hours to get New York time, or eight hours for California time. The same is usually true of Julian day counts.) The built-in t U command performs these conversions.

## Modulo Forms

A modulo form is a real number which is taken modulo (i.e., within an integer multiple of) some value M. Arithmetic modulo M often arises in number theory. Modulo forms are written a mod M', where a and M are real numbers or HMS forms, and 0 <= a < M. In many applications a and M will be integers but this is not required.

Modulo forms are not to be confused with the modulo operator %'. The expression 27 % 10' means to compute 27 modulo 10 to produce the result 7. Further computations treat this 7 as just a regular integer. The expression 27 mod 10' produces the result 7 mod 10'; further computations with this value are again reduced modulo 10 so that the result always lies in the desired range.

When two modulo forms with identical M's are added or multiplied, the Calculator simply adds or multiplies the values, then reduces modulo M. If one argument is a modulo form and the other a plain number, the plain number is treated like a compatible modulo form. It is also possible to raise modulo forms to powers; the result is the value raised to the power, then reduced modulo M. (When all values involved are integers, this calculation is done much more efficiently than actually computing the power and then reducing.)

Two modulo forms a mod M' and b mod M' can be divided if a, b, and M are all integers. The result is the modulo form which, when multiplied by b mod M', produces a mod M'. If there is no solution to this equation (which can happen only when 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 (a mod M)^.5' will compute a "modulo square root" in the sense of reducing @c{$\sqrt a$} sqrt(a) modulo M, this is not a useful definition from the number-theoretical point of view.)

To create a modulo form during numeric entry, press the shift-M key to enter the word mod'. As a special convenience, pressing shift-M a second time automatically enters the value of M that was most recently used before. During algebraic entry, either type mod' by hand or press M-m (that's META-m). Once again, pressing this a second time enters the current modulo.

You can also use v p and % to modify modulo forms. See section Building Vectors. See section Basic Arithmetic.

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 M also be an HMS form eliminates troubles that would arise if the angular mode were inadvertently set to Radians, in which case 2@ 0' 0" mod 24' would be interpreted as two degrees modulo 24 radians!

Modulo forms cannot have variables or formulas for components. If you enter the formula (x + 2) mod 5', Calc propagates the modulus to each of the coefficients: (1 mod 5) x + (2 mod 5)'.

The algebraic function makemod(a, m)' builds the modulo form a mod m'.

## Error Forms

An error form is a number with an associated standard deviation, as in 2.3 +/- 0.12'. The notation x +/- @c{$\sigma$} sigma' stands for an uncertain value which follows a normal or Gaussian distribution of mean x and standard deviation or "error" @c{$\sigma$} 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.

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 f(x) (such as @c{$\sin x$} sin(x)) is defined by the error of x times the derivative of f evaluated at the mean value of x. For a two-argument function f(x,y) (such as addition) the error is the square root of the sum of the squares of the errors due to x and y. Note that this definition assumes the errors in x and y are uncorrelated. A side effect of this definition is that (2 +/- 1) * (2 +/- 1)' is not the same as (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.

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 sin(x +/- @c{$\sigma$} sigma)' is @c{$\sigma$\nobreak} sigma abs(cos(x))'. When x is close to zero, cos(x) is close to one so the error in the sine is close to @c{$\sigma$} sigma; this makes sense, since @c{$\sin x$} sin(x) is approximately x near zero, so a given error in x will produce about the same error in the sine. Likewise, near 90 degrees @c{$\cos x$} 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 x has relatively little effect on the value of @c{$\sin x$} sin(x). However, consider 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 x had been small, the error in @c{$\sin x$} sin(x) would indeed have been negligible.

To enter an error form during regular numeric entry, use the p ("plus-or-minus") key to type the +/-' symbol. (If you try actually typing +/-' the + key will be interpreted as the Calculator's + command!) Within an algebraic formula, you can press M-p to type the +/-' symbol, or type it out by hand.

Error forms and complex numbers can be mixed; the formulas shown above are used for complex numbers, too; note 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.

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.

The algebraic function sdev(a, b)' builds the error form a +/- b'.

## Interval Forms

An interval is a subset of consecutive real numbers. For example, the interval [2 .. 4]' represents all the numbers from 2 to 4, inclusive. If you multiply it by the interval [0.5 .. 2]' you obtain [1 .. 8]'. This calculation represents the fact that if you multiply some number in the range [2 .. 4]' by some other number in the range [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.

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 -inf' and inf'. In general the lower limit must be less than the upper limit. A closed interval containing only one value, [3 .. 3]', is converted to a plain number (3) automatically. An interval containing no values at all (such as [3 .. 2]' or [2 .. 2)') can be represented but is not guaranteed to behave well when used in arithmetic. Note that the interval [3 .. inf)' represents all real numbers greater than or equal to 3, and (-inf .. inf)' represents all real numbers. In fact, [-inf .. inf]' represents all real numbers including the real infinities.

Intervals are entered in the notation shown here, either as algebraic formulas, or using incomplete forms. (See section Incomplete Objects.) In algebraic formulas, multiple periods in a row are collected from left to right, so that 1...1e2' is interpreted as 1.0 .. 1e2' rather than 1 .. 0.1e2'. Add spaces or zeros if you want to get the other interpretation. If you omit the lower or upper limit, a default of -inf' or inf' (respectively) is furnished.

"Infinite mode" also affects operations on intervals (see section Infinities). Calc will always introduce an open infinity, as in 1 / (0 .. 2] = [0.5 .. inf)'. But closed infinities, 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, 1 / (-2 .. 2) = [-inf .. inf]'.

While it may seem that intervals and error forms are similar, they are based on entirely different concepts of inexact quantities. An error form x +/- @c{$\sigma$} sigma' means a variable is random, and its value could be anything but is "probably" within one @c{$\sigma$} sigma of the mean value x. An interval [a .. b]' 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.

Intervals may not contain complex numbers, but they may contain HMS forms or date forms.

See section Set Operations using Vectors, for commands that interpret interval forms as subsets of the set of real numbers.

The algebraic function intv(n, a, b)' builds an interval form from a' to b'; n' is an integer code which must be 0 for (..)', 1 for (..]', 2 for [..)', or 3 for [..]'.

Please note that in fully rigorous interval arithmetic, care would be taken to make sure that the computation of the lower bound rounds toward minus infinity, while upper bound computations round toward plus infinity. Calc's arithmetic always uses a round-to-nearest mode, which means that roundoff errors could creep into an interval calculation to produce intervals slightly smaller than they ought to be. For example, entering [1..2]' and pressing Q 2 ^ should yield the interval [1..2]' again, but in fact it yields the (slightly too small) interval [1..1.9999999]' due to roundoff error.

## Incomplete Objects

When ( or [ is typed to begin entering a complex number or vector, respectively, the effect is to push an incomplete complex number or vector onto the stack. The , key adds the value(s) at the top of the stack onto the current incomplete object. The ) and ] keys "close" the incomplete object after adding any values on the top of the stack in front of the incomplete object.

As a result, the sequence of keystrokes [ 2 , 3 RET 2 * , 9 ] pushes the vector [2, 6, 9]' onto the stack. Likewise, ( 1 , 2 Q ) pushes the complex number (1, 1.414)' (approximately).

If several values lie on the stack in front of the incomplete object, all are collected and appended to the object. Thus the , key is redundant: [ 2 RET 3 RET 2 * 9 ]. Some people prefer the equivalent SPC key to RET.

As a special case, typing , immediately after (, [, or , adds a zero or duplicates the preceding value in the list being formed. Typing DEL during incomplete entry removes the last item from the list.

The ; key is used in the same way as , to create polar complex numbers: ( 1 ; 2 ). When entering a vector, ; is useful for creating a matrix. In particular, [ [ 1 , 2 ; 3 , 4 ; 5 , 6 ] ] is equivalent to [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ].

Incomplete entry is also used to enter intervals. For example, [ 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 .. corresponds to executing the calc-dots command.

If you find incomplete entry distracting, you may wish to enter vectors and complex numbers as algebraic formulas by pressing the apostrophe key.

## Variables

A 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 # signs in variable names. The Calc variable foo corresponds to the Emacs Lisp variable var-foo. Commands like s s (calc-store) that operate on variables can be made to use any arbitrary Lisp variable simply by backspacing over the var-' prefix in the minibuffer.

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 var-q0 through var-q9. For example, 3 s s 2 stores the number 3 in variable var-q2, and 3 s s foo RET stores that number in variable var-foo.

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. Variable names in algebraic formulas implicitly have var-' prefixed to their names. The #' character in variable names used in algebraic formulas corresponds to a dash -' in the Lisp variable name. If the name contains any dashes, the prefix var-' is not automatically added. Thus the two formulas foo + 1' and var#foo + 1' both refer to the same variable.

The = (calc-evaluate) key "evaluates" a formula by replacing all variables in the formula which have been given values by a calc-store or 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, = evaluates the top n stack entries; with a negative argument, = evaluates the nth stack entry.

A few variables are called special constants. Their names are e', pi', i', phi', and gamma'. (See section Scientific Functions.) When they are evaluated with =, 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 calc-store.

The variables inf', uinf', and nan' stand for infinite or indeterminate values. It's best not to use them as 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.

See section Storing and Recalling, for a discussion of commands dealing with variables.

## Formulas

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:

_' [subscr] (subscripts);

postfix %' [percent] (as in 25% = 0.25');

prefix +' and -' [neg] (as in -x') and prefix !' [lnot] (logical "not," as in !x');

+/-' [sdev] (the standard deviation symbol) and mod' [makemod] (the symbol for modulo forms);

postfix !' [fact] (factorial, as in n!') and postfix !!' [dfact] (double factorial);

^' [pow] (raised-to-the-power-of);

*' [mul];

/' [div], %' [mod] (modulo), and \' [idiv] (integer division);

infix +' [add] and -' [sub] (as in x-y');

|' [vconcat] (vector concatenation);

relations =' [eq], !=' [neq], <' [lt], >' [gt], <=' [leq], and >=' [geq];

&&' [land] (logical "and");

||' [lor] (logical "or");

the C-style "if" operator a?b:c' [if];

!!!' [pnot] (rewrite pattern "not");

&&&' [pand] (rewrite pattern "and");

|||' [por] (rewrite pattern "or");

:=' [assign] (for assignments and rewrite rules);

::' [condition] (rewrite pattern condition);

=>' [evalto].

Note that, unlike in usual computer notation, multiplication binds more strongly than division: a*b/c*d' is equivalent to @c{$a b \over c d$} (a*b)/(c*d).

The multiplication sign *' may be omitted in many cases. In particular, if the righthand side is a number, variable name, or parenthesized expression, the *' may be omitted. Implicit multiplication has the same precedence as the explicit *' operator. The one exception to the rule is that a variable name followed by a parenthesized expression, as in f(x)', is interpreted as a function call, not an implicit *'. In many cases you must use a space if you omit the *': 2a' is the same as 2*a', and a b' is the same as a*b', but ab' is a variable called ab, not the product of a' and b'! Also note that f (x)' is still a function call.

The rules are slightly different for vectors written with square brackets. In vectors, the space character is interpreted (like the comma) as a separator of elements of the vector. Thus [ 2a b+c d ]' is equivalent to [2*a, b+c, d]', whereas 2a b+c d' is equivalent to 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 [(a b) 2(c d)]', which is interpreted as [a*b, 2*c*d]'. An implicit comma is also inserted between ][', as in the matrix [[1 2][3 4]]'.

Vectors that contain commas (not embedded within nested parentheses or brackets) do not treat spaces specially: [a b, 2 c d]' is a vector of two elements. Also, if it would be an error to treat spaces as separators, but not otherwise, then Calc will ignore spaces: [a - b]' is a vector of one element, but [a -b]' is a vector of two elements. Finally, 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: [(a b)]'.

The expression 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 (5%)-2' to get the former interpretation.

A function call is, e.g., sin(1+x)'. Function names follow the same rules as variable names except that the default prefix calcFunc-' is used (instead of var-') for the internal Lisp form. Most mathematical Calculator commands like calc-sin have function equivalents like sin. If no Lisp function is defined for a function called by a formula, the call is left as it is during algebraic manipulation: f(x+y)' is left alone. Beware that many innocent-looking short names like in and re have predefined meanings which could surprise you; however, single letters or single letters followed by digits are always safe to use for your own function names. See section Index of Algebraic Functions.

In the documentation for particular commands, the notation H S (calc-sinh) [sinh] means that the key sequence H S, the command M-x calc-sinh, and the algebraic function sinh(x) all represent the same operation.

Commands that interpret ("parse") text as algebraic formulas include algebraic entry ('), editing commands like  which parse the contents of the editing buffer when you finish, the M-# g and M-# r commands, the 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 (see section Language Modes) affect them all in the same way.

When you read a large amount of text into the Calculator (say a vector which represents a big set of rewrite rules; see section Rewrite Rules), you may wish to include comments in the text. Calc's formula parser ignores the symbol %%' and anything following it on a line:

[ a + b,   %% the sum of "a" and "b"
c + d,
%% last line is coming up:
e + f ]


This is parsed exactly the same as `[ a + b, c + d, e + f ]'.

See section Syntax Tables, for a way to create your own operators and other input notations. See section Compositions, for a way to create new display formats.

See section Algebra, for commands for manipulating formulas symbolically.

Go to the first, previous, next, last section, table of contents.