aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/mts.spad.pamphlet
blob: e83ae506c5680ec092350b3b4f4d7738480d5bd1 (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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
\documentclass{article}
\usepackage{open-axiom}
\begin{document}
\title{\$SPAD/src/algebra mts.spad}
\author{William Burge, Stephen Watt, Clifton Williamson}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject

\section{domain SMTS SparseMultivariateTaylorSeries}

<<domain SMTS SparseMultivariateTaylorSeries>>=
import NonNegativeInteger
import List
import Stream
)abbrev domain SMTS SparseMultivariateTaylorSeries
++ This domain provides multivariate Taylor series
++ Authors: William Burge, Stephen Watt, Clifton Williamson
++ Date Created: 15 August 1988
++ Date Last Updated: 18 May 1991
++ Basic Operations:
++ Related Domains:
++ Also See: UnivariateTaylorSeries
++ AMS Classifications:
++ Keywords: multivariate, Taylor, series
++ Examples:
++ References:
++ Description:
++   This domain provides multivariate Taylor series with variables
++   from an arbitrary ordered set.  A Taylor series is represented
++   by a stream of polynomials from the polynomial domain SMP.
++   The nth element of the stream is a form of degree n.  SMTS is an
++   internal domain.
SparseMultivariateTaylorSeries(Coef,Var,SMP):_
 Exports == Implementation where
  Coef : Ring
  Var  : OrderedSet
  SMP  : PolynomialCategory(Coef,IndexedExponents Var,Var)
  I   ==> Integer
  L   ==> List
  NNI ==> NonNegativeInteger
  OUT ==> OutputForm
  PS  ==> InnerTaylorSeries SMP
  RN  ==> Fraction Integer
  ST  ==> Stream
  StS ==> Stream SMP
  STT ==> StreamTaylorSeriesOperations SMP
  STF ==> StreamTranscendentalFunctions SMP
  ST2 ==> StreamFunctions2
  ST3 ==> StreamFunctions3
 
  Exports ==> MultivariateTaylorSeriesCategory(Coef,Var) with
    coefficient: (%,NNI) -> SMP
      ++ \spad{coefficient(s, n)} gives the terms of total degree n.
    coerce: Var -> %
      ++ \spad{coerce(var)} converts a variable to a Taylor series
    coerce: SMP -> %
      ++ \spad{coerce(poly)} regroups the terms by total degree and forms
      ++ a series.
    *:(SMP,%)->%
      ++\spad{smp*ts} multiplies a TaylorSeries by a monomial SMP.
    csubst:(L Var,L StS) -> (SMP -> StS)
      ++\spad{csubst(a,b)} is for internal use only
 
    if Coef has Algebra Fraction Integer then
      integrate: (%,Var,Coef) -> %
        ++\spad{integrate(s,v,c)} is the integral of s with respect
        ++ to v and having c as the constant of integration.
      fintegrate: (() -> %,Var,Coef) -> %
        ++\spad{fintegrate(f,v,c)} is the integral of \spad{f()} with respect
        ++ to v and having c as the constant of integration.
        ++ The evaluation of \spad{f()} is delayed.
 
  Implementation ==> PS add
 
    Rep := StS -- Below we use the fact that Rep of PS is Stream SMP.
    -- FIXME: These come for free if assignment to Rep is removed.
    rep(x: %): Rep == x pretend Rep
    per(x: Rep): % == x pretend %

    extend(x,n) == extend(x,n + 1)$Rep
    complete x == complete(x)$Rep

    evalstream:(%,L Var,L SMP) -> StS
    evalstream(s:%,lv:(L Var),lsmp:(L SMP)):(ST SMP) ==
      scan(0,_+$SMP,map(eval(#1,lv,lsmp),s pretend StS))$ST2(SMP,SMP)
 
    addvariable:(Var,InnerTaylorSeries Coef) -> %
    addvariable(v,s) ==
      ints := integers(0)$STT pretend ST NNI
      map(monomial(#2 :: SMP,v,#1)$SMP,ints,s pretend ST Coef)$ST3(NNI,Coef,SMP)
 
    coefficient(s:%,n: NNI) == 
      elt(s,n + 1)$Rep  -- 1-based indexing for streams
 
--% creation of series
 
    coerce(r:Coef) == monom(r::SMP,0)$STT
    smp:SMP * p:% == (((smp) *  (p pretend Rep))$STT)pretend %
    r:Coef * p:% == (((r::SMP) *  (p pretend Rep))$STT)pretend %
    p:% * r:Coef == (((r::SMP) * ( p pretend Rep))$STT)pretend %
    mts(p:SMP):% ==
      (uv := mainVariable p) case "failed" => monom(p,0)$STT
      v := uv :: Var
      s : % := 0
      up := univariate(p,v)
      while not zero? up repeat
        s := s + monomial(1,v,degree up) * mts(leadingCoefficient up)
        up := reductum up
      s
 
    coerce(p:SMP) == mts p
    coerce(v:Var) == v :: SMP :: %
 
    monomial(r:%,v:Var,n:NNI) ==
      r * monom(monomial(1,v,n)$SMP,n)$STT
 
--% evaluation
 
    substvar: (SMP,L Var,L %) -> %
    substvar(p,vl,q) ==
      null vl => monom(p,0)$STT
      (uv := mainVariable p) case "failed" => monom(p,0)$STT
      v := uv :: Var
      v = first vl =>
        s : % := 0
        up := univariate(p,v)
        while not zero? up repeat
          c := leadingCoefficient up
          s := s + first q ** degree up * substvar(c,rest vl,rest q)
          up := reductum up
        s
      substvar(p,rest vl,rest q)
 
    sortmfirst:(SMP,L Var,L %) -> %
    sortmfirst(p,vl,q) ==
      nlv : L Var := sort(#1 > #2,vl)
      nq : L % := [q position$(L Var) (i,vl) for i in nlv]
      substvar(p,nlv,nq)
 
    csubst(vl,q) == sortmfirst(#1,vl,q pretend L(%)) pretend StS
 
    restCheck(s:StS):StS ==
      -- checks that stream is null or first element is 0
      -- returns empty() or rest of stream
      empty? s => s
      not zero? frst s =>
        error "eval: constant coefficient should be 0"
      rst s
 
    eval(s:%,v:L Var,q:L %) ==
      #v ~= #q =>
        error "eval: number of variables should equal number of values"
      nq : L StS := [restCheck(i pretend StS) for i in q]
      addiag(map(csubst(v,nq),s pretend StS)$ST2(SMP,StS))$STT pretend %
 
    substmts(v:Var,p:SMP,q:%):% ==
      up := univariate(p,v)
      ss : % := 0
      while not zero? up repeat
        d:=degree up
        c:SMP:=leadingCoefficient up
        ss := ss + c* q ** d
        up := reductum up
      ss
 
    subststream(v:Var,p:SMP,q:StS):StS==
      substmts(v,p,q pretend %) pretend StS
 
    comp1:(Var,StS,StS) -> StS
    comp1(v,r,t)== addiag(map(subststream(v,#1,t),r)$ST2(SMP,StS))$STT
 
    comp(v:Var,s:StS,t:StS):StS == delay
      empty? s => s
      f := frst s; r : StS := rst s;
      empty? r => s
      empty? t => concat(f,comp1(v,r,empty()$StS))
      not zero? frst t =>
        error "eval: constant coefficient should be zero"
      concat(f,comp1(v,r,rst t))
 
    eval(s:%,v:Var,t:%) == comp(v,s pretend StS,t pretend StS)
 
--% differentiation and integration
 
    differentiate(s:%,v:Var):% ==
      empty? s => 0
      map(differentiate(#1,v),rst s)
 
    if Coef has Algebra Fraction Integer then
      (x:%) ** (r:RN) == powern(r,rep x)$STT
      (r:RN) * (x:%)  == per map(r * #1, rep x)$ST2(SMP,SMP)
      (x:%) * (r:RN)  == per map(#1 * r,rep x )$ST2(SMP,SMP)
 
      exp x == exp(rep x)$STF
      log x == log(rep x)$STF
 
      sin x == sin(rep x)$STF
      cos x == cos(rep x)$STF
      tan x == tan(rep x)$STF
      cot x == cot(rep x)$STF
      sec x == sec(rep x)$STF
      csc x == csc(rep x)$STF
 
      asin x == asin(rep x)$STF
      acos x == acos(rep x)$STF
      atan x == atan(rep x)$STF
      acot x == acot(rep x)$STF
      asec x == asec(rep x)$STF
      acsc x == acsc(rep x)$STF
 
      sinh x == sinh(rep x)$STF
      cosh x == cosh(rep x)$STF
      tanh x == tanh(rep x)$STF
      coth x == coth(rep x)$STF
      sech x == sech(rep x)$STF
      csch x == csch(rep x)$STF
 
      asinh x == asinh(rep x)$STF
      acosh x == acosh(rep x)$STF
      atanh x == atanh(rep x)$STF
      acoth x == acoth(rep x)$STF
      asech x == asech(rep x)$STF
      acsch x == acsch(rep x)$STF
 
      intsmp(v:Var,p: SMP): SMP ==
        up := univariate(p,v)
        ss : SMP := 0
        while not zero? up repeat
          d := degree up
          c := leadingCoefficient up
          ss := ss + inv((d+1) :: RN) * monomial(c,v,d+1)$SMP
          up := reductum up
        ss
 
      fintegrate(f,v,r) ==
        concat(r::SMP,delay map(intsmp(v,#1),f() pretend StS))
      integrate(s,v,r) ==
        concat(r::SMP,map(intsmp(v,#1),s pretend StS))
 
    -- If there is more than one term of the same order, group them.
    tout(p:SMP):OUT ==
      pe := p :: OUT
      monomial? p => pe
      paren pe
 
    showAll?: () -> Boolean
    -- check a global Lisp variable
    showAll?() == true
 
    coerce(s:%):OUT ==
      uu := s pretend Stream(SMP)
      empty? uu => (0$SMP) :: OUT
      count : NNI := _$streamCount$Lisp
      l : List OUT := empty()
      n : NNI := 0
      while n <= count and not empty? uu repeat
        if frst(uu) ~= 0 then l := concat(tout frst uu,l)
        uu := rst uu
        n := n + 1
      if showAll?() then
        while explicitEntries? uu and not eq?(uu,rst uu) repeat
          if frst(uu) ~= 0 then l := concat(tout frst uu,l)
          uu := rst uu
          n := n + 1
      l :=
        explicitlyEmpty? uu => l
        eq?(uu,rst uu) and frst uu = 0 => l
        concat(prefix("O" :: OUT,[n :: OUT]),l)
      empty? l => (0$SMP) :: OUT
      reduce("+",reverse! l)
    if Coef has Field then
      p:% / r:Coef == per map(#1/$SMP r,rep p)$StreamFunctions2(SMP,SMP)

@
\section{domain TS TaylorSeries}
<<domain TS TaylorSeries>>=
)abbrev domain TS TaylorSeries
++ Authors: Burge, Watt, Williamson
++ Date Created: 15 August 1988
++ Date Last Updated: 18 May 1991
++ Basic Operations:
++ Related Domains: SparseMultivariateTaylorSeries
++ Also See: UnivariateTaylorSeries
++ AMS Classifications:
++ Keywords: multivariate, Taylor, series
++ Examples:
++ References:
++ Description:
++   \spadtype{TaylorSeries} is a general multivariate Taylor series domain
++   over the ring Coef and with variables of type Symbol.
TaylorSeries(Coef): Exports == Implementation where
  Coef  : Ring
  L   ==> List
  NNI ==> NonNegativeInteger
  SMP ==> Polynomial Coef
  StS ==> Stream SMP
 
  Exports ==> MultivariateTaylorSeriesCategory(Coef,Symbol) with
    coefficient: (%,NNI) -> SMP
      ++\spad{coefficient(s, n)} gives the terms of total degree n.
    coerce: Symbol -> %
      ++\spad{coerce(s)} converts a variable to a Taylor series
    coerce: SMP -> %
      ++\spad{coerce(s)} regroups terms of s by total degree
      ++ and forms a series.
 
    if Coef has Algebra Fraction Integer then
      integrate: (%,Symbol,Coef) -> %
        ++\spad{integrate(s,v,c)} is the integral of s with respect
        ++ to v and having c as the constant of integration.
      fintegrate: (() -> %,Symbol,Coef) -> %
        ++\spad{fintegrate(f,v,c)} is the integral of \spad{f()} with respect
        ++ to v and having c as the constant of integration.
        ++ The evaluation of \spad{f()} is delayed.
 
  Implementation ==> SparseMultivariateTaylorSeries(Coef,Symbol,SMP) add
    Rep := StS -- Below we use the fact that Rep of PS is Stream SMP.
 
    polynomial(s,n) ==
      sum : SMP := 0
      for i in 0..n while not empty? s repeat
        sum := sum + frst s
        s:= rst s
      sum

@
\section{License}
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>
 
<<domain SMTS SparseMultivariateTaylorSeries>>
<<domain TS TaylorSeries>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}