]>
Book Contents Previous Section 0.3 Using Axiom as a Pocket Calculator Next Section 0.5 General Points about Axiom Book Index

## 0.4 Using Axiom as a Symbolic Calculator

In the previous section all the examples involved numbers and simple functions. Also none of the expressions entered were assigned to anything. In this section we will move on to simple algebra (i.e. expressions involving symbols and other features available on more sophisticated calculators).

### 0.4.1 Expressions Involving Symbols

Expressions involving symbols are entered just as they are written down, for example:

xSquared := x**2

x 2

Type: Polynomial Integer

where the assignment operator ``:='' represents immediate assignment. Later it will be seen that this form of assignment is not always desirable and the use of the delayed assignment operator ``=='' will be introduced. The type of the result is Polynomial Integer which is used to represent polynomials with integer coefficients. Some other examples along similar lines are:

xDummy := 3.21*x**2

3.21 x 2

Type: Polynomial Float
xDummy := x**2.5

x 2 x

Type: Expression Float
xDummy := x**3.3

x 3 x 10 3

Type: Expression Float
xyDummy := x**2 - y**2

-y 2+x 2

Type: Polynomial Integer

Given that we can define expressions involving symbols, how do we actually compute the result when the symbols are assigned values? The answer is to use the eval function which takes an expression as its first argument followed by a list of assignments. For example, to evaluate the expressions XDummy and {xyDummy} resulting from their respective assignments above we type:

eval(xDummy,x=3)

37.5405075985 29552193

Type: Expression Float
eval(xyDummy, [x=3, y=2.1])

4.59

Type: Polynomial Float

### 0.4.2 Complex Numbers

For many scientific calculations real numbers aren't sufficient and support for complex numbers is also required. Complex numbers are handled in an intuitive manner and Axiom, which uses the %i macro to represent the square root of -1. Thus expressions involving complex numbers are entered just like other expressions.

(2/3 + %i)**3

-46 27+1 3 i

Type: Complex Fraction Integer

The real and imaginary parts of a complex number can be extracted using the real and imag functions and the complex conjugate of a number can be obtained using conjugate:

real(3 + 2*%i)

3

Type: PositiveInteger
imag(3+ 2*%i)

2

Type: PositiveInteger
conjugate(3 + 2*%i)

3-2 i

Type: Complex Integer

The function factor can also be applied to complex numbers but the results aren't quite so obvious as for factoring integer:

144 + 24*%i

144+24 i

Type: Complex Integer

### 0.4.3 Number Representations

By default all numerical results are displayed in decimal with real numbers shown to 20 significant figures. If the integer part of a number is longer than 20 digits then nothing after the decimal point is shown and the integer part is given in full. To alter the number of digits shown the function digits can be called. The result returned by this function is the previous setting. For example, to find the value of π to 40 digits we type:

digits(40)

20

Type: PositiveInteger
%pi::Float

3.1415926535 8979323846 2643383279 502884197

Type: Float

As can be seen in the example above, there is a gap after every ten digits. This can be changed using the outputSpacing function where the argument is the number of digits to be displayed before a space is inserted. If no spaces are desired then use the value 0. Two other functions controlling the appearance of real numbers are outputFloating and outputFixed. The former causes Axiom to display floating-point values in exponent notation and the latter causes it to use fixed-point notation. For example:

outputFloating(); %

0.3141592653 5897932384 6264338327 9502884197 E 1

Type: Float
outputFloating(3); 0.00345

0.345 E-2

Type: Float
outputFixed(); %

0.00345

Type: Float
outputFixed(3); %

0.003

Type: Float
outputGeneral(); %

0.00345

Type: Float

Note that the semicolon ``;'' in the examples above allows several expressions to be entered on one line. The result of the last expression is displayed. remember also that the percent symbol ``%'' is used to represent the result of a previous calculation.

To display rational numbers in a base other than 10 the function radix is used. The first argument of this function is the expression to be displayed and the second is the base to be used.

radix(10**10,32)

9A0NP00

Type: RadixExpansion 32
radix(3/21,5)

0.0 3 2 4 1 2‾

Type: RadixExpansion 5

Rational numbers can be represented as a repeated decimal expansion using the decimal function or as a continued fraction using continuedFraction. Any attempt to call these functions with irrational values will fail.

decimal(22/7)

3.142857‾

Type: DecimalExpansion
continuedFraction(6543/210)

31+1 6+1 2+1 1+1 3

Type: ContinuedFraction Integer

Finally, partial fractions in compact and expanded form are available via the functions partialFraction and padicFraction respectively. The former takes two arguments, the first being the numerator of the fraction and the second being the denominator. The latter function takes a fraction and expands it further while the function compactFraction does the reverse:

partialFraction(234,40)

6-3 2 2+3 5

Type: PartialFraction Integer
padicFraction(%)

6-1 2-1 2 2+3 5

Type: PartialFraction Integer
compactFraction(%)

6-3 2 2+3 5

Type: PartialFraction Integer
padicFraction(234/40)

117 20

Type: PartialFraction Fraction Integer

To extract parts of a partial fraction the function nthFractionalTerm is available and returns a partial fraction of one term. To decompose this further the numerator can be obtained using firstNumer and the denominator with firstDenom. The whole part of a partial fraction can be retrieved using wholePart and the number of fractional parts can be found using the function numberOf FractionalTerms:

t := partialFraction(234,40)

6-3 2 2+3 5

Type: PartialFraction Integer
wholePart(t)

6

Type: PositiveInteger
numberOfFractionalTerms(t)

2

Type: PositiveInteger
p := nthFractionalTerm(t,1)

-3 2 2

Type: PartialFraction Integer
firstNumer(p)

-3

Type: Integer
firstDenom(p)

2 2

Type: Factored Integer

### 0.4.4 Modular Arithmetic

By using the type constructor PrimeField it is possible to do arithmetic modulo some prime number. For example, arithmetic module 7 can be performed as follows:

x : PrimeField 7 := 5

5

Type: PrimeField 7
x**5 + 6

2

Type: PrimeField 7
1/x

3

Type: PrimeField 7

The first example should be read as:

Let x be of type PrimeField(7) and assign to it the value 5

Note that it is only possible to invert non-zero values if the arithmetic is performed modulo a prime number. Thus arithmetic modulo a non-prime integer is possible but the reciprocal operation is undefined and will generate an error. Attempting to use the PrimeField type constructor with a non-prime argument will generate an error. An example of non-prime modulo arithmetic is:

y : IntegerMod 8 := 11

3

Type: IntegerMod 8
y*4 + 27

7

Type: IntegerMod 8

Note that polynomials can be constructed in a similar way:

(3*a**4 + 27*a - 36)::Polynomial PrimeField 7

3 a 4+6 a+6

Type: Polynomial PrimeField 7
Book Contents Previous Section 0.3 Using Axiom as a Pocket Calculator Next Section 0.5 General Points about Axiom Book Index