% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. % !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. \newcommand{\ExpressionXmpTitle}{Expression} \newcommand{\ExpressionXmpNumber}{9.21} % % ===================================================================== \begin{page}{ExpressionXmpPage}{9.21 Expression} % ===================================================================== \beginscroll % \axiomType{Expression} is a constructor that creates domains whose objects can have very general symbolic forms. Here are some examples: \xtc{ This is an object of type \axiomType{Expression Integer}. }{ \spadpaste{sin(x) + 3*cos(x)**2} } \xtc{ This is an object of type \axiomType{Expression Float}. }{ \spadpaste{tan(x) - 3.45*x} } \xtc{ This object contains symbolic function applications, sums, products, square roots, and a quotient. }{ \spadpaste{(tan sqrt 7 - sin sqrt 11)**2 / (4 - cos(x - y))} } As you can see, \axiomType{Expression} actually takes an argument domain. The {\it coefficients} of the terms within the expression belong to the argument domain. \axiomType{Integer} and \axiomType{Float}, along with \axiomType{Complex Integer} and \axiomType{Complex Float} are the most common coefficient domains. \xtc{ The choice of whether to use a \axiomType{Complex} coefficient domain or not is important since \Language{} can perform some simplifications on real-valued objects }{ \spadpaste{log(exp x)@Expression(Integer)} } \xtc{ ... which are not valid on complex ones. }{ \spadpaste{log(exp x)@Expression(Complex Integer)} } \xtc{ Many potential coefficient domains, such as \axiomType{AlgebraicNumber}, are not usually used because \axiomType{Expression} can subsume them. }{ \spadpaste{sqrt 3 + sqrt(2 + sqrt(-5)) \bound{algnum1}} } \xtc{ }{ \spadpaste{\% :: Expression Integer \free{algnum1}} } Note that we sometimes talk about ``an object of type \axiomType{Expression}.'' This is not really correct because we should say, for example, ``an object of type \axiomType{Expression Integer}'' or ``an object of type \axiomType{Expression Float}.'' By a similar abuse of language, when we refer to an ``expression'' in this section we will mean an object of type \axiomType{Expression R} for some domain {\bf R}. The \Language{} documentation contains many examples of the use of \axiomType{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 \axiomType{Expression} creates domains that have category \axiomType{Field}. Thus you can invert any non-zero expression and you shouldn't expect an operation like \axiomFun{factor} to give you much information. You can imagine expressions as being represented as quotients of ``multivariate'' polynomials where the ``variables'' are kernels (see \downlink{`Kernel'}{KernelXmpPage}\ignore{Kernel}). A kernel can either be a symbol such as \axiom{x} or a symbolic function application like \axiom{sin(x + 4)}. The second example is actually a nested kernel since the argument to \axiomFun{sin} contains the kernel \axiom{x}. \xtc{ }{ \spadpaste{height mainKernel sin(x + 4)} } Actually, the argument to \axiomFun{sin} is an expression, and so the structure of \axiomType{Expression} is recursive. \downlink{`Kernel'}{KernelXmpPage}\ignore{Kernel} demonstrates how to extract the kernels in an expression. Use the \HyperName{} 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 \axiomType{Expression Integer}. For example, \axiomFunFrom{numer}{Expression} and \axiomFunFrom{denom}{Expression} extract the numerator and denominator of an expression. \xtc{ }{ \spadpaste{e := (sin(x) - 4)**2 / ( 1 - 2*y*sqrt(- y) ) \bound{e}} } \xtc{ }{ \spadpaste{numer e \free{e}} } \xtc{ }{ \spadpaste{denom e \free{e}} } \xtc{ Use \axiomFunFrom{D}{Expression} to compute partial derivatives. }{ \spadpaste{D(e, x) \free{e}} } \xtc{ See \downlink{``\ugIntroCalcDerivTitle''}{ugIntroCalcDerivPage} in Section \ugIntroCalcDerivNumber\ignore{ugIntroCalcDeriv} for more examples of expressions and derivatives. }{ \spadpaste{D(e, [x, y], [1, 2]) \free{e}} } See \downlink{``\ugIntroCalcLimitsTitle''}{ugIntroCalcLimitsPage} in Section \ugIntroCalcLimitsNumber\ignore{ugIntroCalcLimits} and \downlink{``\ugIntroSeriesTitle''}{ugIntroSeriesPage} in Section \ugIntroSeriesNumber\ignore{ugIntroSeries} for more examples of expressions and calculus. Differential equations involving expressions are discussed in \downlink{``\ugProblemDEQTitle''}{ugProblemDEQPage} in Section \ugProblemDEQNumber\ignore{ugProblemDEQ}. Chapter 8 has many advanced examples: see \downlink{``\ugProblemIntegrationTitle''}{ugProblemIntegrationPage} in Section \ugProblemIntegrationNumber\ignore{ugProblemIntegration} for a discussion of \Language{}'s integration facilities. When an expression involves no ``symbol kernels'' (for example, \axiom{x}), it may be possible to numerically evaluate the expression. \xtc{ If you suspect the evaluation will create a complex number, use \axiomFun{complexNumeric}. }{ \spadpaste{complexNumeric(cos(2 - 3*\%i))} } \xtc{ If you know it will be real, use \axiomFun{numeric}. }{ \spadpaste{numeric(tan 3.8)} } The \axiomFun{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 \axiom{n} which specifies that the accuracy of the approximation be up to \axiom{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. \xtc{ }{ \spadpaste{e2 := cos(x**2 - y + 3) \bound{e2}} } \xtc{ }{ \spadpaste{e3 := asin(e2) - \%pi/2 \free{e2}\bound{e3}} } \xtc{ }{ \spadpaste{e3 :: Polynomial Integer \free{e3}} } \xtc{ This also works for the polynomial types where specific variables and their ordering are given. }{ \spadpaste{e3 :: DMP([x, y], Integer) \free{e3}} } Finally, a certain amount of simplication takes place as expressions are constructed. \xtc{ }{ \spadpaste{sin \%pi} } \xtc{ }{ \spadpaste{cos(\%pi / 4)} } \xtc{ For simplications that involve multiple terms of the expression, use \axiomFun{simplify}. }{ \spadpaste{tan(x)**6 + 3*tan(x)**4 + 3*tan(x)**2 + 1 \bound{tan6}} } \xtc{ }{ \spadpaste{simplify \% \free{tan6}} } See \downlink{``\ugUserRulesTitle''}{ugUserRulesPage} in Section \ugUserRulesNumber\ignore{ugUserRules} for examples of how to write your own rewrite rules for expressions. \endscroll \autobuttons \end{page} %