Basic Functions
The size of an integer in Axiom is only limited by the amount of computer
storage you have available. The usual arithmetic operations are available.
There are a number of ways of working with the sign of an integer. Let's
use the x as an example.
First of all, there is the absolute value function.
The sign operation returns -1 if its argument
is negative, 0 if zero and 1 if positive.
You can determine if an integer is negative in several other ways.
Similarly, you can find out if it is positive.
This is the recommended way of determining whether an integer is zero.
Use the zero? whenever you are testing any
mathematical object for equality with zero. This is usually more efficient
than using = (think of matrices: it is easier
to tell if a matrix is zero by just checking term by term than constructing
another "zero" amtrix and comparing the two matrices term by term) and also
avoids the problem that = is usually used
for creating equations.
This is the recommended way of determining whether an integer is equal to one.
This syntax is used to test equality using =.
It says that you want a Boolean (true or false)
answer rather than an equation.
The operations odd? and
even? determine whether an integer is odd
or even, respectively. They each return a
Boolean
object.
The operation gcd computes the greatest common
divisor of two integers.
The operation lcm computes their least common
multiple.
To determine the maximum of two integers, use max.
To determine the minimum, use min.
The reduce operation is used to extend
binary operations to more than two arguments. For example, you can use
reduce to find the maximum integer in a
list or compute the least common multiple of all integers in a list.
The infix operator "/" is not used to compute the quotient of integers.
Rather , it is used to create rational numbers as described in
Fractions.
The infix operator quo computes the integer
quotient.
The infix operation rem computes the integer
remainder.
One integer is evenly divisible by another if the remainder is zero.
The operation exquo can also be used. See
Unions for an example.
The operation divide returns a record of
the quotient and remainder and thus is more efficient when both are needed.
Records are discussed in detail in
Records.