Section9.21

]>
Book Contents Previous Section 9.20 Exit Next Section 9.22 Factored Book Index

## 9.21 Expression

Expression is a constructor that creates domains whose objects can have very general symbolic forms. Here are some examples:

This is an object of type Expression Integer.

sin(x) + 3*cos(x)**2

sin(x)+3 cos(x)2

Type: Expression Integer

This is an object of type Expression Float.

tan(x) - 3.45*x

tan(x)-3. 45 x

Type: Expression Float

This object contains symbolic function applications, sums, products, square roots, and a quotient.

(tan sqrt 7 - sin sqrt 11)**2 / (4 - cos(x - y))

-tan(7)2+2 sin(11)tan(7)-sin(11)2 cos(y-x)-4

Type: Expression Integer

As you can see, Expression actually takes an argument domain. The coefficients of the terms within the expression belong to the argument domain. Integer and Float, along with Complex Integer and Complex Float are the most common coefficient domains.

The choice of whether to use a Complex coefficient domain or not is important since Axiom can perform some simplifications on real-valued objects

log(exp x)@Expression(Integer)

x

Type: Expression Integer

... which are not valid on complex ones.

log(exp x)@Expression(Complex Integer)

log(e x)

Type: Expression Complex Integer

Many potential coefficient domains, such as AlgebraicNumber, are not usually used because Expression can subsume them.

sqrt 3 + sqrt(2 + sqrt(-5))

-5+2+3

Type: AlgebraicNumber
% :: Expression Integer

-5+2+3

Type: Expression Integer

Note that we sometimes talk about ``an object of type Expression.'' This is not really correct because we should say, for example, ``an object of type Expression Integer'' or ``an object of type Expression Float.'' By a similar abuse of language, when we refer to an ``expression'' in this section we will mean an object of type Expression R for some domain R.

The Axiom documentation contains many examples of the use of Expression. For the rest of this section, we'll give you some pointers to those examples plus give you some idea of how to manipulate expressions.

It is important for you to know that Expression creates domains that have category Field. Thus you can invert any non-zero expression and you shouldn't expect an operation like factor to give you much information. You can imagine expressions as being represented as quotients of ``multivariate'' polynomials where the ``variables'' are kernels (see KernelXmpPage ). A kernel can either be a symbol such as x or a symbolic function application like sin(x + 4). The second example is actually a nested kernel since the argument to sin contains the kernel x.

height mainKernel sin(x + 4)

2

Type: PositiveInteger

Actually, the argument to sin is an expression, and so the structure of Expression is recursive. KernelXmpPage demonstrates how to extract the kernels in an expression.

Use the HyperDoc Browse facility to see what operations are applicable to expression. At the time of this writing, there were 262 operations with 147 distinct name in Expression Integer. For example, numernumerExpression and denomdenomExpression extract the numerator and denominator of an expression.

e := (sin(x) - 4)**2 / ( 1 - 2*y*sqrt(- y) )

-sin(x)2+8 sin(x)-16 2 y-y-1

Type: Expression Integer
numer e

-sin(x)2+8 sin(x)-16

Type: SparseMultivariatePolynomial(Integer,Kernel Expression Integer)
denom e

2 y-y-1

Type: SparseMultivariatePolynomial(Integer,Kernel Expression Integer)

Use DDExpression to compute partial derivatives.

D(e, x)

(4 y cos(x)sin(x)-16 y cos(x))-y-2 cos(x)sin(x)+8 cos(x)4 y-y+4 y 3-1

Type: Expression Integer

See ugIntroCalcDerivPage in Section ugIntroCalcDerivNumber for more examples of expressions and derivatives.

D(e, [x, y], [1, 2])

(((-2304 y 7+960 y 4)cos(x)sin(x)+(9216 y 7-3840 y 4)cos(x))-y+(-960 y 9+2160 y 6-180 y 3-3)cos(x)sin(x)+(3840 y 9-8640 y 6+720 y 3+12)cos(x))((256 y 12-1792 y 9+1120 y 6-112 y 3+1)-y-1024 y 11+1792 y 8-448 y 5+16 y 2)

Type: Expression Integer

See ugIntroCalcLimitsPage in Section ugIntroCalcLimitsNumber and ugIntroSeriesPage in Section ugIntroSeriesNumber for more examples of expressions and calculus. Differential equations involving expressions are discussed in ugProblemDEQPage in Section ugProblemDEQNumber . Chapter 8 has many advanced examples: see ugProblemIntegrationPage in Section ugProblemIntegrationNumber for a discussion of Axiom's integration facilities.

When an expression involves no ``symbol kernels'' (for example, x), it may be possible to numerically evaluate the expression.

If you suspect the evaluation will create a complex number, use complexNumeric.

complexNumeric(cos(2 - 3*%i))

-4. 1896256909 688072301+9. 1092278937 55336598 i

Type: Complex Float

If you know it will be real, use numeric.

numeric(tan 3.8)

0. 7735560905 0312607286

Type: Float

The numeric operation will display an error message if the evaluation yields a calue with an non-zero imaginary part. Both of these operations have an optional second argument n which specifies that the accuracy of the approximation be up to n decimal places.

When an expression involves no ``symbolic application'' kernels, it may be possible to convert it a polynomial or rational function in the variables that are present.

e2 := cos(x**2 - y + 3)

cos(y-x 2-3)

Type: Expression Integer
e3 := asin(e2) - %pi/2

-y+x 2+3

Type: Expression Integer
e3 :: Polynomial Integer

-y+x 2+3

Type: Polynomial Integer

This also works for the polynomial types where specific variables and their ordering are given.

e3 :: DMP([x, y], Integer)

x 2-y+3

Type: DistributedMultivariatePolynomial([x,y],Integer)

Finally, a certain amount of simplication takes place as expressions are constructed.

sin %pi

0

Type: Expression Integer
cos(%pi / 4)

2 2

Type: Expression Integer

For simplications that involve multiple terms of the expression, use simplify.

tan(x)**6 + 3*tan(x)**4 + 3*tan(x)**2 + 1

tan(x)6+3 tan(x)4+3 tan(x)2+1

Type: Expression Integer
simplify %

1 cos(x)6

Type: Expression Integer

See ugUserRulesPage in Section ugUserRulesNumber for examples of how to write your own rewrite rules for expressions.

Book Contents Previous Section 9.20 Exit Next Section 9.22 Factored Book Index