~ubuntu-branches/ubuntu/karmic/axiom/karmic

« back to all changes in this revision

Viewing changes to src/hyper/pages/POLY.ht

  • Committer: Bazaar Package Importer
  • Author(s):
  • Date: 2005-02-21 17:08:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050221170837-34vm4j33v4t9hsk4
Tags: 20050201-1
* New upstream release
* Bug fix: "axiom graphics missing?", thanks to Daniel Lakeland (Closes:
  #277692).
* Bug fix: "axiom: Feb 2005 release for sarge would be nice", thanks to
  Balbir Thomas (Closes: #295000).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
 
2
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
 
3
\newcommand{\PolynomialXmpTitle}{Polynomial}
 
4
\newcommand{\PolynomialXmpNumber}{9.63}
 
5
%
 
6
% =====================================================================
 
7
\begin{page}{PolynomialXmpPage}{9.63 Polynomial}
 
8
% =====================================================================
 
9
\beginscroll
 
10
 
 
11
The domain constructor \spadtype{Polynomial} (abbreviation: \spadtype{POLY})
 
12
provides polynomials with an arbitrary number of unspecified
 
13
variables.
 
14
 
 
15
\xtc{
 
16
It is used to create the default polynomial domains
 
17
in \Language{}.
 
18
Here the coefficients are integers.
 
19
}{
 
20
\spadpaste{x + 1}
 
21
}
 
22
\xtc{
 
23
Here the coefficients have type \spadtype{Float}.
 
24
}{
 
25
\spadpaste{z - 2.3}
 
26
}
 
27
\xtc{
 
28
And here we have a polynomial in two variables with coefficients which
 
29
have type \spadtype{Fraction Integer}.
 
30
}{
 
31
\spadpaste{y**2 - z + 3/4}
 
32
}
 
33
 
 
34
The representation of objects of domains created by \spadtype{Polynomial}
 
35
is that of recursive univariate polynomials.\footnote{The term
 
36
\spad{univariate} means ``one variable.'' \spad{multivariate} means
 
37
``possibly more than one variable.''}
 
38
\xtc{
 
39
This recursive structure is sometimes obvious from the display of
 
40
a polynomial.
 
41
}{
 
42
\spadpaste{y **2 + x*y + y \bound{prev}}
 
43
}
 
44
In this example, you see that the polynomial is stored as a polynomial in
 
45
\spad{y} with coefficients that are polynomials in \spad{x} with integer
 
46
coefficients.
 
47
In fact, you really don't need to worry about the representation unless
 
48
you are working on an advanced application where it is critical.
 
49
The polynomial types created from
 
50
\spadtype{DistributedMultivariatePolynomial} and
 
51
\spadtype{NewDistributedMultivariatePolynomial} (discussed in
 
52
\downlink{`DistributedMultivariatePolynomial'}{DistributedMultivariatePolynomialXmpPage}\ignore{DistributedMultivariatePolynomial}) are stored and displayed in a
 
53
non-recursive manner.
 
54
\xtc{
 
55
You see a ``flat'' display of the above
 
56
polynomial by converting to one of those types.
 
57
}{
 
58
\spadpaste{\% :: DMP([y,x],INT) \free{prev}}
 
59
}
 
60
 
 
61
We will demonstrate many of the polynomial facilities by using two
 
62
polynomials with integer coefficients.
 
63
\xtc{
 
64
By default, the interpreter expands polynomial expressions, even if they
 
65
are written in a factored format.
 
66
}{
 
67
\spadpaste{p := (y-1)**2 * x * z \bound{p}}
 
68
}
 
69
\xtc{
 
70
See \downlink{`Factored'}{FactoredXmpPage}\ignore{Factored} to see
 
71
how to create objects in factored form directly.
 
72
}{
 
73
\spadpaste{q := (y-1) * x * (z+5) \bound{q}}
 
74
}
 
75
\xtc{
 
76
The fully factored form can be recovered by using
 
77
\spadfunFrom{factor}{Polynomial}.
 
78
}{
 
79
\spadpaste{factor(q) \free{q}}
 
80
}
 
81
This is the same name used for the operation to factor integers.
 
82
Such reuse of names is called \spadglos{overloading} and makes it much easier
 
83
to think of solving problems in general ways.
 
84
\Language{} facilities for factoring polynomials created with
 
85
\spadtype{Polynomial} are currently restricted to
 
86
the integer and rational number coefficient cases.
 
87
There are more complete facilities for factoring univariate polynomials:
 
88
see \downlink{``\ugProblemFactorTitle''}{ugProblemFactorPage} in Section \ugProblemFactorNumber\ignore{ugProblemFactor}.
 
89
 
 
90
\xtc{
 
91
The standard arithmetic operations are available for polynomials.
 
92
}{
 
93
\spadpaste{p - q**2\free{p q}}
 
94
}
 
95
\xtc{
 
96
The operation \spadfunFrom{gcd}{Polynomial} is used to compute the
 
97
greatest common divisor of two polynomials.
 
98
}{
 
99
\spadpaste{gcd(p,q) \free{p q}\bound{prev4}}
 
100
}
 
101
\xtc{
 
102
In the case of \spad{p} and \spad{q}, the gcd is obvious from their
 
103
definitions.
 
104
We factor the gcd to show this relationship better.
 
105
}{
 
106
\spadpaste{factor \% \free{prev4}}
 
107
}
 
108
\xtc{
 
109
The least common multiple is computed by using \spadfunFrom{lcm}{Polynomial}.
 
110
}{
 
111
\spadpaste{lcm(p,q) \free{p q}}
 
112
}
 
113
\xtc{
 
114
Use \spadfunFrom{content}{Polynomial} to compute the greatest common divisor of the
 
115
coefficients of the polynomial.
 
116
}{
 
117
\spadpaste{content p \free{p}}
 
118
}
 
119
 
 
120
Many of the operations on polynomials require you to specify a variable.
 
121
For example, \spadfunFrom{resultant}{Polynomial} requires you to give the
 
122
variable in which the polynomials should be expressed.
 
123
\xtc{
 
124
This computes the resultant of the values of \spad{p} and
 
125
\spad{q}, considering them as polynomials in the variable \spad{z}.
 
126
They do not share a root when thought of as polynomials in \spad{z}.
 
127
}{
 
128
\spadpaste{resultant(p,q,z) \free{p q}}
 
129
}
 
130
\xtc{
 
131
This value is \spad{0} because as polynomials in \spad{x} the polynomials
 
132
have a common root.
 
133
}{
 
134
\spadpaste{resultant(p,q,x) \free{p}\free{q}}
 
135
}
 
136
The data type used for the variables created by \spadtype{Polynomial} is
 
137
\spadtype{Symbol}.
 
138
As mentioned above, the representation used by \spadtype{Polynomial} is
 
139
recursive and so there is a main variable for nonconstant polynomials.
 
140
\xtc{
 
141
The operation \spadfunFrom{mainVariable}{Polynomial} returns this
 
142
variable.
 
143
The return type is actually a union of \spadtype{Symbol} and
 
144
\spad{"failed"}.
 
145
}{
 
146
\spadpaste{mainVariable p \free{p}}
 
147
}
 
148
\xtc{
 
149
The latter branch of the union is be used if the polynomial has no
 
150
variables, that is, is a constant.
 
151
}{
 
152
\spadpaste{mainVariable(1 :: POLY INT)}
 
153
}
 
154
\xtc{
 
155
You can also use the predicate \spadfunFrom{ground?}{Polynomial} to test
 
156
whether a polynomial is in fact a member of its ground ring.
 
157
}{
 
158
\spadpaste{ground? p \free{p}}
 
159
}
 
160
\xtc{
 
161
}{
 
162
\spadpaste{ground?(1 :: POLY INT)}
 
163
}
 
164
\xtc{
 
165
The complete list of variables actually used in a particular polynomial is
 
166
returned by \spadfunFrom{variables}{Polynomial}.
 
167
For constant polynomials, this list is empty.
 
168
}{
 
169
\spadpaste{variables p \free{p}}
 
170
}
 
171
 
 
172
\xtc{
 
173
The \spadfunFrom{degree}{Polynomial} operation returns the
 
174
degree of a polynomial in a specific variable.
 
175
}{
 
176
\spadpaste{degree(p,x) \free{p}}
 
177
}
 
178
\xtc{
 
179
}{
 
180
\spadpaste{degree(p,y) \free{p}}
 
181
}
 
182
\xtc{
 
183
}{
 
184
\spadpaste{degree(p,z) \free{p}}
 
185
}
 
186
\xtc{
 
187
If you give a list of variables for the second argument, a list
 
188
of the degrees in those variables is returned.
 
189
}{
 
190
\spadpaste{degree(p,[x,y,z]) \free{p}}
 
191
}
 
192
\xtc{
 
193
The minimum degree of a variable in a polynomial is computed using
 
194
\spadfunFrom{minimumDegree}{Polynomial}.
 
195
}{
 
196
\spadpaste{minimumDegree(p,z) \free{p}}
 
197
}
 
198
\xtc{
 
199
The total degree of a polynomial is returned by
 
200
\spadfunFrom{totalDegree}{Polynomial}.
 
201
}{
 
202
\spadpaste{totalDegree p \free{p}}
 
203
}
 
204
 
 
205
\xtc{
 
206
It is often convenient to think of a polynomial as a leading monomial plus
 
207
the remaining terms.
 
208
}{
 
209
\spadpaste{leadingMonomial p \free{p}}
 
210
}
 
211
\xtc{
 
212
The \spadfunFrom{reductum}{Polynomial} operation returns a polynomial
 
213
consisting of the sum of the monomials after the first.
 
214
}{
 
215
\spadpaste{reductum p \free{p}}
 
216
}
 
217
\xtc{
 
218
These have the obvious relationship that the original polynomial
 
219
is equal to the leading monomial plus the reductum.
 
220
}{
 
221
\spadpaste{p - leadingMonomial p - reductum p \free{p}}
 
222
}
 
223
\xtc{
 
224
The value returned by \spadfunFrom{leadingMonomial}{Polynomial} includes
 
225
the coefficient of that term.
 
226
This is extracted by using
 
227
\spadfunFrom{leadingCoefficient}{Polynomial} on the original polynomial.
 
228
}{
 
229
\spadpaste{leadingCoefficient p \free{p}}
 
230
}
 
231
\xtc{
 
232
The operation \spadfunFrom{eval}{Polynomial} is used to substitute a value
 
233
for a variable in a polynomial.
 
234
}{
 
235
\spadpaste{p  \free{p}}
 
236
}
 
237
\xtc{
 
238
This value may be another variable, a constant or a polynomial.
 
239
}{
 
240
\spadpaste{eval(p,x,w) \free{p}}
 
241
}
 
242
\xtc{
 
243
}{
 
244
\spadpaste{eval(p,x,1) \free{p}}
 
245
}
 
246
\xtc{
 
247
Actually, all the things being substituted are just polynomials,
 
248
some more trivial than others.
 
249
}{
 
250
\spadpaste{eval(p,x,y**2 - 1) \free{p}}
 
251
}
 
252
 
 
253
\xtc{
 
254
Derivatives are computed using the \spadfunFrom{D}{Polynomial}
 
255
operation.
 
256
}{
 
257
\spadpaste{D(p,x) \free{p}}
 
258
}
 
259
\xtc{
 
260
The first argument is the polynomial and the second is the variable.
 
261
}{
 
262
\spadpaste{D(p,y) \free{p}}
 
263
}
 
264
\xtc{
 
265
Even if the polynomial has only one variable, you must specify it.
 
266
}{
 
267
\spadpaste{D(p,z) \free{p}}
 
268
}
 
269
 
 
270
Integration of polynomials is similar and the
 
271
\spadfunFrom{integrate}{Polynomial} operation is used.
 
272
 
 
273
\xtc{
 
274
Integration requires that the coefficients support division.
 
275
Consequently,
 
276
\Language{} converts polynomials over the integers to polynomials over
 
277
the rational numbers before integrating them.
 
278
}{
 
279
\spadpaste{integrate(p,y) \free{p}}
 
280
}
 
281
 
 
282
It is not possible, in general, to divide two polynomials.
 
283
In our example using polynomials over the integers, the operation
 
284
\spadfunFrom{monicDivide}{Polynomial} divides a polynomial by a monic
 
285
polynomial (that is, a polynomial with leading coefficient equal to 1).
 
286
The result is a record of the quotient and remainder of the
 
287
division.
 
288
\xtc{
 
289
You must specify the variable in which to express the polynomial.
 
290
}{
 
291
\spadpaste{qr := monicDivide(p,x+1,x) \free{p}\bound{qr}}
 
292
}
 
293
\xtc{
 
294
The selectors of the components of the record are
 
295
\spad{quotient} and \spad{remainder}.
 
296
Issue this to extract the remainder.
 
297
}{
 
298
\spadpaste{qr.remainder \free{qr}}
 
299
}
 
300
\xtc{
 
301
Now that we can extract the components, we can demonstrate the
 
302
relationship among them and the arguments to our original expression
 
303
\spad{qr := monicDivide(p,x+1,x)}.
 
304
}{
 
305
\spadpaste{p - ((x+1) * qr.quotient + qr.remainder) \free{p}\free{qr}}
 
306
}
 
307
 
 
308
\xtc{
 
309
If the \spadopFrom{/}{Fraction} operator is used with polynomials, a
 
310
fraction object is created.
 
311
In this example, the result is an object of type \spadtype{Fraction
 
312
Polynomial Integer}.
 
313
}{
 
314
\spadpaste{p/q \free{p}\free{q}}
 
315
}
 
316
\xtc{
 
317
If you use rational numbers as polynomial coefficients, the
 
318
resulting object is of type \spadtype{Polynomial Fraction Integer}.
 
319
}{
 
320
\spadpaste{(2/3) * x**2 - y + 4/5 \bound{prev1}}
 
321
}
 
322
\xtc{
 
323
This can be converted to a fraction of polynomials and back again, if
 
324
required.
 
325
}{
 
326
\spadpaste{\% :: FRAC POLY INT \free{prev1}\bound{prev2}}
 
327
}
 
328
\xtc{
 
329
}{
 
330
\spadpaste{\% :: POLY FRAC INT \free{prev2}\bound{prev3}}
 
331
}
 
332
\xtc{
 
333
To convert the coefficients to floating point,
 
334
map the \spadfun{numeric} operation on the coefficients of the polynomial.
 
335
}{
 
336
\spadpaste{map(numeric,\%) \free{prev3}}
 
337
}
 
338
 
 
339
For more information on related topics, see
 
340
\downlink{`UnivariatePolynomial'}{UnivariatePolynomialXmpPage}\ignore{UnivariatePolynomial},
 
341
\downlink{`MultivariatePolynomial'}{MultivariatePolynomialXmpPage}\ignore{MultivariatePolynomial}, and
 
342
\downlink{`DistributedMultivariatePolynomial'}{DistributedMultivariatePolynomialXmpPage}\ignore{DistributedMultivariatePolynomial}.
 
343
You can also issue the system command
 
344
\spadcmd{)show Polynomial}
 
345
to display the full list of operations defined by
 
346
\spadtype{Polynomial}.
 
347
\endscroll
 
348
\autobuttons
 
349
\end{page}
 
350
%