aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/EXPR.ht
blob: 0984b52f295fa4af221fec64916287726bb1c8d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
% 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}
%