]>
The Axiom language is a rich language for performing interactive computations and for building components of the Axiom library. Here we present only some basic aspects of the language that you need to know for the rest of this chapter. Our discussion here is intentionally informal, with details unveiled on an ``as needed'' basis. For more information on a particular construct, we suggest you consult the index.
For arithmetic expressions, use the ``+'' and ``-'' operator as in mathematics. Use ``*'' for multiplication, and ``**'' for exponentiation. To create a fraction, use ``/''. When an expression contains several operators, those of highest precedence are evaluated first. For arithmetic operators, ``**'' has highest precedence, ``*'' and ``/'' have the next highest precedence, and ``+'' and ``-'' have the lowest precedence.
Axiom puts implicit parentheses around operations of higher precedence, and groups those of equal precedence from left to right.
The above expression is equivalent to this.
If an expression contains subexpressions enclosed in parentheses, the parenthesized subexpressions are evaluated first (from left to right, from inside out).
Use the percent sign ``%'' to refer to the last result. result:previous Also, use ``%%" to refer to previous results. percentpercent@{%%} ``%%(-1)'' is equivalent to ``%'', ``%%(-2)'' returns the next to the last result, and so on. ``%%(1)'' returns the result from step number 1, ``%%(2)'' returns the result from step number 2, and so on. ``%%(0)'' is not defined.
This is ten to the tenth power.
This is the last result minus one.
This is the last result.
This is the result from step number 1.
Everything in Axiom has a type. The type determines what operations you can perform on an object and how the object can be used. Chapter~ugTypes is dedicated to the interactive use of types. Several of the final chapters discuss how types are built and how they are organized in the Axiom library.
Positive integers are given type PositiveInteger.
Negative ones are given type Integer. This fine distinction is helpful to the Axiom interpreter.
Here a positive integer exponent gives a polynomial result.
Here a negative integer exponent produces a fraction.
A symbol is a literal used for the input of things like the ``variables'' in polynomials and power series.
We use the three symbols , , and in entering this polynomial.
A symbol has a name beginning with an uppercase or lowercase alphabetic symbol:naming character, ``%'', or ``!''. Successive characters (if any) can be any of the above, digits, or ``?''. Case is distinguished: the symbol points is different from the symbol Points.
A symbol can also be used in Axiom as a variable. A variable refers to a value. To assign a value to a variable, variable:naming the operator ``:='' assignment is used. Axiom actually has two forms of assignment: immediate assignment, as discussed here, and delayed assignment. See Section ugLangAssign for details. A variable initially has no restrictions on the kinds of declaration values to which it can refer.
This assignment gives the value (an integer) to a variable named .
This gives the value (a polynomial) to .
To restrict the types of objects that can be assigned to a variable, use a declaration
After a variable is declared to be of some type, only values of that type can be assigned to that variable.
The declaration for forces values assigned to to be converted to integer values.
If no such conversion is possible, Axiom refuses to assign a value to .
A type declaration can also be given together with an assignment. The declaration can assist Axiom in choosing the correct operations to apply.
Any number of expressions can be given on input line. Just separate them by semicolons. Only the result of evaluating the last expression is displayed.
These two expressions have the same effect as the previous single expression.
The type of a symbol is either Symbol or Variable(name) where name is the name of the symbol.
By default, the interpreter gives this symbol the type Variable(q).
When multiple symbols are involved, Symbol is used.
What happens when you try to use a symbol that is the name of a variable?
Use a single quote ``''' before quote the name to get the symbol.
Quoting a name creates a symbol by preventing evaluation of the name as a variable. Experience will teach you when you are most likely going to need to use a quote. We try to point out the location of such trouble spots.
Objects of one type can usually be ``converted'' to objects of several other types. To convert an object to a new type, use the ``::'' infix operator. Conversion is discussed in detail in ugTypesConvert. For example, to display an object, it is necessary to convert the object to type OutputForm.
This produces a polynomial with rational number coefficients.
Create a quotient of polynomials with integer coefficients by using ``::''.
Some conversions can be performed automatically when Axiom tries to evaluate your input. Others conversions must be explicitly requested.
As we saw earlier, when you want to add or subtract two values, you place the arithmetic operator ``+'' or ``-'' between the two arguments denoting the values. To use most other Axiom operations, however, you use another syntax: function:calling write the name of the operation first, then an open parenthesis, then each of the arguments separated by commas, and, finally, a closing parenthesis. If the operation takes only one argument and the argument is a number or a symbol, you can omit the parentheses.
This calls the operation factor with the single integer argument .
This is a call to divide with the two integer arguments and .
This calls quatern with four floating-point arguments.
This is the same as factorial(10).
An operation that returns a Boolean value (that is, true or false) frequently has a name suffixed with a question mark (``?''). For example, the even? operation returns true if its integer argument is an even number, false otherwise.
An operation that can be destructive on one or more arguments usually has a name ending in a exclamation point (``!''). This actually means that it is allowed to update its arguments but it is not required to do so. For example, the underlying representation of a collection type may not allow the very last element to be removed and so an empty object may be returned instead. Therefore it is important that you use the object returned by the operation and not rely on a physical change having occurred within the object. Usually destructive operations are provided for efficiency reasons.
Axiom provides several macros for your convenience.See ugUserMacros for a discussion on how to write your own macros. Macros are names macro:predefined (or forms) that expand to larger expressions for commonly used values.
%i | The square root of -1. |
%e | The base of the natural logarithm. |
%pi | . |
%infinity | . |
%plusInfinity | . |
%minusInfinity | . |
%i %e %pi pi@{ (= %pi)} %infinity infinity@{ (= %infinity)} %plusInfinity %minusInfinity
To display all the macros (along with anything you have defined in the workspace), issue the system command )display all.
When you enter Axiom expressions from your keyboard, there will be times when they are too long to fit on one line. Axiom does not care how long your lines are, so you can let them continue from the right margin to the left side of the next line.
Alternatively, you may want to enter several shorter lines and have Axiom glue them together. To get this glue, put an underscore (_) at the end of each line you wish to continue.
is the same as if you had entered
Axiom statements in an input file (see Section ugInOutIn ), can use indentation to indicate the program structure (see Section ugLangBlocks ).
Comment statements begin with two consecutive hyphens or two consecutive plus signs and continue until the end of the line.
The comment beginning with ``--'' is ignored by Axiom.
There is no way to write long multi-line comments other than starting each line with ``--'' or ``++''.