]>
Axiom provides many operations for manipulating arbitrary precision integers. In this section we will show some of those that come from Integer itself plus some that are implemented in other packages. More examples of using integers are in the following sections: ugIntroNumbersPage in section ugIntroNumbersNumber IntegerNumberTheoryFunctionsXmpPage , DecimalExpansionXmpPage , BinaryExpansionXmpPage , HexadecimalExpansionXmpPage , and RadixExpansionXmpPage .
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 this x as an example.
First of all, there is the absolute value function.
The signsignInteger 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?zero?Integer operation whenever you are
testing any mathematical object for equality with zero. This is
usually more efficient that using = (think of matrices: it is
easier to tell if a matrix is zero by just checking term by term than
constructing another ``zero'' matrix 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?odd?Integer and even?even?Integer determine whether an integer is odd or even, respectively. They each return a Boolean object.
The operation gcdgcdInteger computes the greatest common divisor of two integers.
The operation lcmlcmInteger computes their least common multiple.
To determine the maximum of two integers, use maxmaxInteger.
To determine the minimum, use minminInteger.
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 the list.
The infix operator ``/'' is not used to compute the quotient of integers. Rather, it is used to create rational numbers as described in FractionXmpPage .
The infix operation quoquoInteger computes the integer quotient.
The infix operation remremInteger computes the integer remainder.
One integer is evenly divisible by another if the remainder is zero. The operation exquoexquoInteger can also be used. See ugTypesUnionsPage in Section ugTypesUnionsNumber for an example.
The operation dividedivideInteger returns a record of the quotient and remainder and thus is more efficient when both are needed.
Records are discussed in detail in Section ugTypesRecords .
Use the operation factorfactorInteger to factor integers. It returns an object of type Factored Integer. See FactoredXmpPage for a discussion of the manipulation of factored objects.
The operation prime?prime?Integer returns true or false depending on whether its argument is a prime.
The operation nextPrimenextPrimeIntegerPrimesPackage returns the least prime number greater than its argument.
The operation prevPrimeprevPrimeIntegerPrimesPackage returns the greatest prime number less than its argument.
To compute all primes between two integers (inclusively), use the operation primesprimesIntegerPrimesPackage.
You might sometimes want to see the factorization of an integer when it is considered a Gaussian integer. See ComplexXmpPage for more details.
Axiom provides several number theoretic operations for integers. More examples are in IntegerNumberTheoryFunctionsXmpPage .
The operation fibonaccifibonacciIntegerNumberTheoryFunctions computes the Fibonacci numbers. The algorithm has running time for argument n.
The operation legendrelegendreIntegerNumberTheoryFunctions computes the Legendre symbol for its two integer arguments where the second one is prime. If you know the second argument to be prime, use jacobijacobiIntegerNumberTheoryFunctions instead where no check is made.
The operation jacobijacobiIntegerNumberTheoryFunctions computes the Jacobi symbol for its two integer arguments. By convention, 0 is returned if the greatest common divisor of the numerator and denominator is not 1.
The operation eulerPhieulerPhiIntegerNumberTheoryFunctions computes the values of Euler's -function where equals the number of positive integers less than or equal to n that are relatively prime to the positive integer n.
The operation moebiusMumoebiusMuIntegerNumberTheoryFunctions computes the Möbius function.
Although they have somewhat limited utility, Axiom provides Roman numerals.