====================================================================
Expression examples
====================================================================

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

This is an object of type Expression Float.

  tan(x) - 3.45*x

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

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

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)

... which are not valid on complex ones.

  log(exp  x)@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))

  % :: 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. 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)

Actually, the argument to sin is an expression, and so the structure
of Expression is recursive. See Kernel which 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, numer and
denom extract the numerator and denominator of an expression.

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

  numer e 

  denom e

Use D to compute partial derivatives.

  D(e, x) 

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

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))

If you know it will be real, use numeric.

  numeric(tan 3.8)

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) 

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

  e3 :: Polynomial Integer

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

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

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

  sin %pi

  cos(%pi / 4)

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

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

  simplify % 

See Also:
o )show Kernel
o )show Expression

