Conversion

Conversion is the process of changing an object of one type into an object of another type. The syntax for conversion is object::newType.

By default, 3 has the type PositiveInteger

We can change thisinto an object of type Fraction Integer by using "::".

A coercion is a special kind of conversion that Axiom is allowed to do automatically when you enter an expression. Coercions are usually somewhat safer than more general conversions. The Axiom library contains operations called coerce and convert. Only the coerce operations can be used by the interpreter to change an object into an object of another type unless you explicitly use a "::". By now you will be quite familiar with what types and modes look like. It is useful to think of a type or mode as a pattern for what you want the result to be. Let's start with a square matrix of polynomials with complex rational number coefficients.

We first want to interchange the Complex and Fraction layers. We do the conversion by doing the interchange in the type expression.

Interchange the Polynomial and the Fraction levels.

Interchange the Polynomial and the Complex levels.

All the entries have changed types, although in comparing the last two results only the entry in the lower left corner looks different. We did all the intermediate steps to show you what Axiom can do. In fact, we could have combined all these into one conversion.

There are times when Axiom is not able to do the conversion in one step. You may need to break up the transformation into several conversions in order to get an object of the desired type. We cannot move either the Fraction or Complex above (or to the left of, depending on how you look at it) SquareMatrix because each of these levels requires that its argument type have commutative multiplication, whereas SquareMatrix does not. (Fraction requires that its argument belong to the category IntegralDomain and Complex requires that its argument belongs to CommutativeRing. See the Jenks section 2.1 for a brief discussion of categories. The Integer level did not move anywhere because it does not allow any arguments. We also did not move the SquareMatrix part anywhere, but we could have. Recall that m looks like this:

If we want a polynomial with matrxi coefficients rather than a matrix with polynomial entries, we can just do the conversion.

We have not yet used modes for any conversions. Modes are a great shorthand for indicating the type of the object you want. Instead of using the long type expression in the last example we could have simply said this:

We can also indicate more structure if we want the entries of the matrices to be fractions.