]>
At the simplest level Axiom can be used as a pocket calculator where expressions involving numbers and operators are entered directly in infix notation. In this sense the more advanced features of the calculator can be regarded as operators (e.g sin, cos, etc).
An example of this might be to calculate the cosine of 2.45 (in radians). To do this one would type:
Before proceeding any further it would be best to explain the previous three lines. Firstly the text ``(1) -> '' is part of the prompt that the Axiom system provides when in interactive mode. The full prompt has other text preceding this but it is not relevant here. The number in parenthesis is the step number of the input which may be used to refer to the results of previous calculations. The step number appears at the start of the second line to tell you which step the result belongs to. Since the interpreter probably loaded numberous libraries to calculate the result given above and listed each one in the prcess, there could easily be several pages of text between your input and the answer.
The last line contains the type of the result. The type Float is used to represent real numbers of arbitrary size and precision (where the user is able to define how big arbitrary is -- the default is 20 digits but can be as large as your computer system can handle). The type of the result can help track down mistakes in your input if you don't get the answer you expected.
Other arithmetic operations such as addition, subtraction, and multiplication behave as expected:
but integer division isn't quite so obvious. For example, if one types:
a fractional result is obtained. The function used to display fractions attempts to produce the most readable answer. In the example:
the result is stored as the fraction 2/1 but is displayed as the integer 2. This fraction could be converted to type Integer with no loss of informatin but Axiom will not do so automatically.
To obtain the floating point value of a fraction one must convert ( conversions are applied by the user and coercions are applied automatically by the interpreter) the result to type Float using the ``::'' operator as follows:
Although Axiom can convert this back to a fraction it might not be the same fraction you started with as due to rounding errors. For example, the following conversion appears to be without error but others might not:
where ``%'' represents the previous result (not the calculation).
Although Axiom has the ability to work with floating-point numbers to a very high precision it must be remembered that calculations with these numbers are not exact. Since Axiom is a computer algebra package and not a numerical solutions package this should not create too many problems. The idea is that the user should use Axiom to do all the necessary symbolic manipulation and only at the end should actual numerical results be extracted.
If you bear in mind that Axiom appears to store expressions just as you have typed them and does not perform any evalutation of them unless forced to then programming in the system will be much easier. It means that anything you ask Axiom to do (within reason) will be carried with complete accuracy.
In the previous examples the ``::'' operator was used to convert values from one type to another. This type conversion is not possible for all values. For instance, it is not possible to convert the number 3.4 to an integer type since it can't be represented as an integer. The number 4.0 can be converted to an integer type since it has no fractional part.
Conversion from floating point values to integers is performed using the functions round and truncate. The first of these rounds a floating point number to the nearest integer while the other truncates (i.e. removes the fractional part). Both functions return the result as a floating point number. To extract the fractional part of a floating point number use the function fractionPart but note that the sign of the result depends on the sign of the argument. Axiom obtains the fractional part of using :
To obtain the absolute value of a number the abs function can be used. This takes a single argument which is usually an integer or a floating point value but doesn't necessarily have to be. The sign of a value can be obtained via the sign function which rturns , , or depending on the sign of the argument.
Tests on values can be done using various functions which are generally more efficient than using relational operators such as particularly if the value is a matrix. Examples of some of these functions are:
Some other functions that are quite useful for manipulating numerical values are:
Some simple infix and prefix operators:
Some useful Axiom macros: