Section9.72

]>
Book Contents Previous Section 9.71 Set Next Section 9.73 SparseTable Book Index

## 9.72 SingleInteger

The SingleInteger domain is intended to provide support in Axiom for machine integer arithmetic. It is generally much faster than (bignum) Integer arithmetic but suffers from a limited range of values. Since Axiom can be implemented on top of various dialects of Lisp, the actual representation of small integers may not correspond exactly to the host machines integer representation.

In the CCL implementation of AXIOM (Release 2.1 onwards) the underlying representation of SingleInteger is the same as Integer. The underlying Lisp primitives treat machine-word sized computations specially.

You can discover the minimum and maximum values in your implementation by using minminSingleInteger and maxmaxSingleInteger.

min()$SingleInteger

-134217728

Type: SingleInteger
max()$SingleInteger

134217727

Type: SingleInteger

To avoid confusion with Integer, which is the default type for integers, you usually need to work with declared variables (ugTypesDeclarePage in Section ugTypesDeclareNumber ) ...

a := 1234 :: SingleInteger

1234

Type: SingleInteger

or use package calling (ugTypesPkgCallPage in Section ugTypesPkgCallNumber ).

b := 124$SingleInteger

124

Type: SingleInteger

You can add, multiply and subtract SingleInteger objects, and ask for the greatest common divisor (gcd).

gcd(a,b)

2

Type: SingleInteger

The least common multiple (lcm) is also available.

lcm(a,b)

76508

Type: SingleInteger

Operations mulmodmulmodSingleInteger, addmodaddmodSingleInteger, submodsubmodSingleInteger, and invmodinvmodSingleInteger are similar---they provide arithmetic modulo a given small integer. Here is 5*6 mod 13.

mulmod(5,6,13)$SingleInteger

4

Type: SingleInteger

To reduce a small integer modulo a prime, use positiveRemainderpositiveRemainderSingleInteger.

positiveRemainder(37,13)$SingleInteger

11

Type: SingleInteger

Operations AndAndSingleInteger, OrOrSingleInteger, xorxorSingleInteger, and NotNotSingleInteger provide bit level operations on small integers.

And(3,4)$SingleInteger

0

Type: SingleInteger

Use shift(int,numToShift) to shift bits, where i is shifted left if numToShift is positive, right if negative.

shift(1,4)$SingleInteger

16

Type: SingleInteger
shift(31,-1)$SingleInteger

15

Type: SingleInteger

Many other operations are available for small integers, including many of those provided for Integer. To see the other operations, use the Browse HyperDoc facility (ugBrowsePage in Section ugBrowseNumber ).

Book Contents Previous Section 9.71 Set Next Section 9.73 SparseTable Book Index