]>
Book Contents Previous Section 1.3 The Axiom Language Next Section 1.5 Data Structures Book Index

## 1.4 Numbers

Axiom distinguishes very carefully between different kinds of numbers, how they are represented and what their properties are. Here are a sampling of some of these kinds of numbers and some things you can do with them.

Integer arithmetic is always exact.

11**13 * 13**11 * 17**7 - 19**5 * 23**3

25387751112538918594666224484237298

Type: PositiveInteger

Integers can be represented in factored form.

factor 643238070748569023720594412551704344145570763243

11 13 13 11 17 7 19 5 23 3 29 2

Type: Factored Integer

Results stay factored when you do arithmetic. Note that the 12 is automatically factored for you.

% * 12

radix 2 2 3 11 13 13 11 17 7 19 5 23 3 29 2

Type: Factored Integer

Integers can also be displayed to bases other than 10. This is an integer in base 11.

radix(25937424601,11)

10000000000

Type: RadixExpansion 11

Roman numerals are also available for those special occasions. Roman numerals

roman(1992)

MCMXCII

Type: RomanNumeral

Rational number arithmetic is also exact.

r := 10 + 9/2 + 8/3 + 7/4 + 6/5 + 5/6 + 4/7 + 3/8 + 2/9

55739 2520

Type: Fraction Integer

To factor fractions, you have to pmap factor onto the numerator and denominator.

map(factor,r)

139 401 2 3 3 2 5 7

Type: Fraction Factored Integer

SingleInteger refers to machine word-length integers.

In English, this expression means ``11 as a small integer''.

11@SingleInteger

11

Type: SingleInteger

Machine double-precision floating-point numbers are also available for numeric and graphical applications.

123.21@DoubleFloat

123.21000000000001

Type: DoubleFloat

The normal floating-point type in Axiom, Float, is a software implementation of floating-point numbers in which the exponent and the mantissa may have any number of digits. The types Complex(Float) and Complex(DoubleFloat) are the corresponding software implementations of complex floating-point numbers.

This is a floating-point approximation to about twenty digits. floating point The ``::'' is used here to change from one kind of object (here, a rational number) to another (a floating-point number).

r :: Float

22.1186507936 50793651

Type: Float

Use digits digits Float to change the number of digits in the representation. This operation returns the previous value so you can reset it later.

digits(22)

20

Type: PositiveInteger

To 22 digits of precision, the number e π 163.0 appears to be an integer.

exp(%pi * sqrt 163.0)

26253741 2640768744.0

Type: Float

Increase the precision to forty digits and try again.

digits(40); exp(%pi * sqrt 163.0)

26253741 2640768743.9999999999 9925007259 76

Type: Float

Here are complex numbers with rational numbers as real and complex numbers imaginary parts.

(2/3 + %i)**3

-46 27+1 3 i

Type: Complex Fraction Integer

The standard operations on complex numbers are available.

conjugate %

-46 27-1 3 i

Type: Complex Fraction Integer

You can factor complex integers.

factor(89 - 23 * %i)

-(1+i)(2+i)2(3+2 i)2

Type: Factored Complex Integer

Complex numbers with floating point parts are also available.

exp(%pi/4.0 * %i)

0.7071067811 8654752440 0844362104 8490392849+

0.7071067811 8654752440 0844362104 8490392848 i

Type: Complex Float

The real and imaginary parts can be symbolic.

complex(u,v)

u+v i

Type: Complex Polynomial Integer

Of course, you can do complex arithmetic with these also.

% ** 2

-v 2+u 2+2 u v i

Type: Complex Polynomial Integer

Every rational number has an exact representation as a repeating decimal expansion

decimal(1/352)

0.00284

Type: DecimalExpansion

A rational number can also be expressed as a continued fraction.

continuedFraction(6543/210)

31

Type: ContinuedFraction Integer

Also, partial fractions can be used and can be displayed in a partial fraction compact format fraction:partial

partialFraction(1,factorial(10))

159 2 8-23 3 4-12 5 2+1 7

Type: PartialFraction Integer

or expanded format.

padicFraction(%)

1 2+1 2 4+1 2 5+1 2 6+1 2 7+1 2 8-2 3 2-1 3 3-2 3 4-2 5-2 5 2+1 7

Type: PartialFraction Integer

Like integers, bases (radices) other than ten can be used for rational numbers. Here we use base eight.

radix(4/7, 8)

0.

Type: RadixExpansion 8

Of course, there are complex versions of these as well. Axiom decides to make the result a complex rational number.

% + 2/3*%i

4 7+2 3 i

Type: Complex Fraction Integer

You can also use Axiom to manipulate fractional powers. radical

(5 + sqrt 63 + sqrt 847)**(1/3)

14 7+5 3

Type: AlgebraicNumber

You can also compute with integers modulo a prime.

x : PrimeField 7 := 5

5

Type: PrimeField 7

Arithmetic is then done modulo 7.

x**3

6

Type: PrimeField 7

Since 7 is prime, you can invert nonzero values.

1/x

3

Type: PrimeField 7

You can also compute modulo an integer that is not a prime.

y : IntegerMod 6 := 5

5

Type: IntegerMod 6

All of the usual arithmetic operations are available.

y**3

5

Type: IntegerMod 6

Inversion is not available if the modulus is not a prime number. Modular arithmetic and prime fields are discussed in Section ugxProblemFinitePrime .

1/y
There are 12 exposed and 13 unexposed library operations named /
having 2 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op /
to learn more about the available operations. Perhaps
package-calling the operation or using coercions on the arguments
will allow you to apply the operation.
Cannot find a definition or applicable library operation named /
with argument type(s)
PositiveInteger
IntegerMod 6
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.

This defines a to be an algebraic number, that is, a root of a polynomial equation.

a := rootOf(a**5 + a**3 + a**2 + 3,a)

a

Type: Expression Integer

Computations with a are reduced according to the polynomial equation.

(a + 1)**10

-85 a 4-264 a 3-378 a 2-458 a-287

Type: Expression Integer

Define b to be an algebraic number involving a.

b := rootOf(b**4 + a,b)

b

Type: Expression Integer

Do some arithmetic.

2/(b - 1)

2 b-1

Type: Expression Integer

To expand and simplify this, call ratDenom to rationalize the denominator.

ratDenom(%)

(a 4-a 3+2 a 2-a+1)b 3+(a 4-a 3+2 a 2-a+1)b 2+(a 4-a 3+2 a 2-a+1)b+a 4-a 3+2 a 2-a+1

Type: Expression Integer

If we do this, we should get b.

2/%+1

((a 4-a 3+2 a 2-a+1)b 3+(a 4-a 3+2 a 2-a+1)b 2+(a 4-a 3+2 a 2-a+1)b+a 4-a 3+2 a 2-a+3)((a 4-a 3+2 a 2-a+1)b 3+(a 4-a 3+2 a 2-a+1)b 2+(a 4-a 3+2 a 2-a+1)b+a 4-a 3+2 a 2-a+1)

Type: Expression Integer

But we need to rationalize the denominator again.

ratDenom(%)

b

Type: Expression Integer

Types Quaternion and Octonion are also available. Multiplication of quaternions is non-commutative, as expected.

q:=quatern(1,2,3,4)*quatern(5,6,7,8) - quatern(5,6,7,8)*quatern(1,2,3,4)

-8 i+16 j-8 k

Type: Quaternion Integer
Book Contents Previous Section 1.3 The Axiom Language Next Section 1.5 Data Structures Book Index