aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/sttaylor.spad.pamphlet
blob: febd20d14f183864669b4245b3da44d4b2beba78 (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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/algebra sttaylor.spad}
\author{William Burge, Stephen Watt, Clifton J. Williamson}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{package STTAYLOR StreamTaylorSeriesOperations}
Problems raising a UTS to a negative integer power.

The code in [[powern(rn,x)]] which raises an unnecessary error
where no distinction between rational and integer powers are made.

The fix is easy. Since the problem does not exist in SUPS we can
just take the definition there.

<<package STTAYLOR StreamTaylorSeriesOperations>>=
)abbrev package STTAYLOR StreamTaylorSeriesOperations
++ Author: William Burge, Stephen Watt, Clifton J. Williamson
++ Date Created: 1986
++ Date Last Updated: 26 May 1994
++ Basic Operations:
++ Related Domains: Stream(A), ParadoxicalCombinatorsForStreams(A),
++   StreamTranscendentalFunctions(A),
++   StreamTranscendentalFunctionsNonCommutative(A)
++ Also See:
++ AMS Classifications:
++ Keywords: stream, Taylor series
++ Examples:
++ References:
++ Description:
++   StreamTaylorSeriesOperations implements Taylor series arithmetic,
++   where a Taylor series is represented by a stream of its coefficients.
StreamTaylorSeriesOperations(A): Exports == Implementation where
  A :        Ring
  RN     ==> Fraction Integer
  I      ==> Integer
  NNI    ==> NonNegativeInteger
  ST     ==> Stream
  SP2    ==> StreamFunctions2
  SP3    ==> StreamFunctions3
  L      ==> List
  LA     ==> List A
  YS     ==> Y$ParadoxicalCombinatorsForStreams(A)
  UN     ==> Union(ST A,"failed")
  Exports ==> with
    +          : (ST A,ST A) -> ST A
      ++ a + b returns the power series sum of \spad{a} and \spad{b}:
      ++ \spad{[a0,a1,..] + [b0,b1,..] = [a0 + b0,a1 + b1,..]}
    -          : (ST A,ST A) -> ST A
      ++ a - b returns the power series difference of \spad{a} and
      ++ \spad{b}: \spad{[a0,a1,..] - [b0,b1,..] = [a0 - b0,a1 - b1,..]}
    -          : ST A -> ST A
      ++ - a returns the power series negative of \spad{a}:
      ++ \spad{- [a0,a1,...] = [- a0,- a1,...]}
    *          : (ST A,ST A) -> ST A
      ++ a * b returns the power series (Cauchy) product of \spad{a} and b:
      ++ \spad{[a0,a1,...] * [b0,b1,...] = [c0,c1,...]} where
      ++ \spad{ck = sum(i + j = k,ai * bk)}.
    *          : (A,ST A) -> ST A
      ++ r * a returns the power series scalar multiplication of r by \spad{a}:
      ++ \spad{r * [a0,a1,...] = [r * a0,r * a1,...]}
    *          : (ST A,A) -> ST A
      ++ a * r returns the power series scalar multiplication of \spad{a} by r:
      ++ \spad{[a0,a1,...] * r = [a0 * r,a1 * r,...]}
    exquo      : (ST A,ST A) -> Union(ST A,"failed")
      ++ exquo(a,b) returns the power series quotient of \spad{a} by b,
      ++ if the quotient exists, and "failed" otherwise
    /          : (ST A,ST A) -> ST A
      ++ a / b returns the power series quotient of \spad{a} by b.
      ++ An error message is returned if \spad{b} is not invertible.
      ++ This function is used in fixed point computations.
    recip        : ST A -> UN
      ++ recip(a) returns the power series reciprocal of \spad{a}, or
      ++ "failed" if not possible.
    monom        : (A,I) -> ST A
      ++ monom(deg,coef) is a monomial of degree deg with coefficient
      ++ coef.
    integers     : I -> ST I
      ++ integers(n) returns \spad{[n,n+1,n+2,...]}.
    oddintegers  : I -> ST I
      ++ oddintegers(n) returns \spad{[n,n+2,n+4,...]}.
    int          : A -> ST A
      ++ int(r) returns [r,r+1,r+2,...], where r is a ring element.
    mapmult      : (ST A,ST A) -> ST A
      ++ mapmult([a0,a1,..],[b0,b1,..])
      ++ returns \spad{[a0*b0,a1*b1,..]}.
    deriv        : ST A -> ST A
      ++ deriv(a) returns the derivative of the power series with
      ++ respect to the power series variable. Thus
      ++ \spad{deriv([a0,a1,a2,...])} returns \spad{[a1,2 a2,3 a3,...]}.
    gderiv       : (I -> A,ST A)  -> ST A
      ++ gderiv(f,[a0,a1,a2,..]) returns
      ++ \spad{[f(0)*a0,f(1)*a1,f(2)*a2,..]}.
    coerce       : A -> ST A
      ++ coerce(r) converts a ring element r to a stream with one element.
    eval         : (ST A,A) -> ST A
      ++ eval(a,r) returns a stream of partial sums of the power series
      ++ \spad{a} evaluated at the power series variable equal to r.
    compose      : (ST A,ST A) -> ST A
      ++ compose(a,b) composes the power series \spad{a} with
      ++ the power series b.
    lagrange     : ST A -> ST A
      ++ lagrange(g) produces the power series for f where f is
      ++ implicitly defined as \spad{f(z) = z*g(f(z))}.
    revert       : ST A -> ST A
      ++ revert(a) computes the inverse of a power series \spad{a}
      ++ with respect to composition.
      ++ the series should have constant coefficient 0 and first
      ++ order coefficient 1.
    addiag       : ST ST A -> ST A
      ++ addiag(x) performs diagonal addition of a stream of streams. if x =
      ++ \spad{[[a<0,0>,a<0,1>,..],[a<1,0>,a<1,1>,..],[a<2,0>,a<2,1>,..],..]}
      ++ and \spad{addiag(x) = [b<0,b<1>,...], then b<k> = sum(i+j=k,a<i,j>)}.
    lambert      : ST A -> ST A
      ++ lambert(st) computes \spad{f(x) + f(x**2) + f(x**3) + ...}
      ++ if st is a stream representing \spad{f(x)}.
      ++ This function is used for computing infinite products.
      ++ If \spad{f(x)} is a power series with constant coefficient 1 then
      ++ \spad{prod(f(x**n),n = 1..infinity) = exp(lambert(log(f(x))))}.
    oddlambert   : ST A -> ST A
      ++ oddlambert(st) computes \spad{f(x) + f(x**3) + f(x**5) + ...}
      ++ if st is a stream representing \spad{f(x)}.
      ++ This function is used for computing infinite products.
      ++ If f(x) is a power series with constant coefficient 1 then
      ++ \spad{prod(f(x**(2*n-1)),n=1..infinity) = exp(oddlambert(log(f(x))))}.
    evenlambert  : ST A -> ST A
      ++ evenlambert(st) computes \spad{f(x**2) + f(x**4) + f(x**6) + ...}
      ++ if st is a stream representing \spad{f(x)}.
      ++ This function is used for computing infinite products.
      ++ If \spad{f(x)} is a power series with constant coefficient 1, then
      ++ \spad{prod(f(x**(2*n)),n=1..infinity) = exp(evenlambert(log(f(x))))}.
    generalLambert : (ST A,I,I) -> ST A
      ++ generalLambert(f(x),a,d) returns
      ++ \spad{f(x**a) + f(x**(a + d)) + f(x**(a + 2 d)) + ...}.
      ++ \spad{f(x)} should have zero constant
      ++ coefficient and \spad{a} and d should be positive.
    multisect    : (I,I,ST A) -> ST A
      ++ multisect(a,b,st)
      ++ selects the coefficients of \spad{x**((a+b)*n+a)},
      ++ and changes them to \spad{x**n}.
    invmultisect : (I,I,ST A) -> ST A
      ++ invmultisect(a,b,st) substitutes \spad{x**((a+b)*n)} for \spad{x**n}
      ++ and multiplies by \spad{x**b}.
    if A has Algebra RN then
      integrate  : (A,ST A) -> ST A
        ++ integrate(r,a) returns the integral of the power series \spad{a}
        ++ with respect to the power series variableintegration where
        ++ r denotes the constant of integration. Thus
        ++ \spad{integrate(a,[a0,a1,a2,...]) = [a,a0,a1/2,a2/3,...]}.
      lazyIntegrate  : (A,() -> ST A) -> ST A
        ++ lazyIntegrate(r,f) is a local function
        ++ used for fixed point computations.
      nlde       : ST ST A -> ST A
        ++ nlde(u) solves a
        ++ first order non-linear differential equation described by u of the
        ++ form \spad{[[b<0,0>,b<0,1>,...],[b<1,0>,b<1,1>,.],...]}.
        ++ the differential equation has the form
        ++ \spad{y' = sum(i=0 to infinity,j=0 to infinity,b<i,j>*(x**i)*(y**j))}.
      powern : (RN,ST A) -> ST A
        ++ powern(r,f) raises power series f to the power r.
    if A has Field then
      mapdiv     : (ST A,ST A) -> ST A
        ++ mapdiv([a0,a1,..],[b0,b1,..]) returns
        ++ \spad{[a0/b0,a1/b1,..]}.
      lazyGintegrate : (I -> A,A,() -> ST A) -> ST A
        ++ lazyGintegrate(f,r,g) is used for fixed point computations.
      power      : (A,ST A) -> ST A
        ++ power(a,f) returns the power series f raised to the power \spad{a}.

  Implementation ==> add

--% definitions

    zro: () -> ST A
    -- returns a zero power series
    zro() == empty()$ST(A)

--% arithmetic

    x + y == delay
      empty? y => x
      empty? x => y
      eq?(x,rst x) => map(frst x + #1,y)
      eq?(y,rst y) => map(frst y + #1,x)
      concat(frst x + frst y,rst x + rst y)

    x - y == delay
      empty? y => x
      empty? x => -y
      eq?(x,rst x) => map(frst x - #1,y)
      eq?(y,rst y) => map(#1 - frst y,x)
      concat(frst x - frst y,rst x - rst y)

    -y == map(_-#1,y)

    (x:ST A) * (y:ST A) == delay
      empty? y => zro()
      empty? x => zro()
      concat(frst x * frst y,frst x * rst y + rst x * y)

    (s:A) * (x:ST A) ==
      zero? s => zro()
      map(s * #1,x)

    (x:ST A) * (s:A) ==
      zero? s => zro()
      map(#1 * s,x)

    iDiv: (ST A,ST A,A) -> ST A
    iDiv(x,y,ry0) == delay
      empty? x => empty()
      c0 := frst x * ry0
      concat(c0,iDiv(rst x - c0 * rst y,y,ry0))

    x exquo y ==
      for n in 1.. repeat
        n > 1000 => return "failed"
        empty? y => return "failed"
        empty? x => return empty()
        frst y = 0 =>
          frst x = 0 => (x := rst x; y := rst y)
          return "failed"
        leave "first entry in y is non-zero"
      (ry0 := recip frst y) case "failed" => "failed"
      empty? rst y => map(#1 * (ry0 :: A),x)
      iDiv(x,y,ry0 :: A)

    (x:ST A) / (y:ST A) == delay
      empty? y => error "/: division by zero"
      empty? x => empty()
      (ry0 := recip frst y) case "failed" =>
        error "/: second argument is not invertible"
      empty? rst y => map(#1 * (ry0 :: A),x)
      iDiv(x,y,ry0 :: A)

    recip x ==
      empty? x => "failed"
      rh1 := recip frst x
      rh1 case "failed" => "failed"
      rh := rh1 :: A
      delay
        concat(rh,iDiv(- rh * rst x,x,rh))

--% coefficients

    rp: (I,A) -> L A
    -- rp(z,s) is a list of length z each of whose entries is s.
    rp(z,s) ==
      z <= 0 => empty()
      concat(s,rp(z-1,s))

    rpSt: (I,A) -> ST A
    -- rpSt(z,s) is a stream of length z each of whose entries is s.
    rpSt(z,s) == delay
      z <= 0 => empty()
      concat(s,rpSt(z-1,s))

    monom(s,z) ==
      z < 0 => error "monom: cannot create monomial of negative degree"
      concat(rpSt(z,0),concat(s,zro()))

--% some streams of integers
    nnintegers: NNI -> ST NNI
    nnintegers zz == generate(#1 + 1,zz)
    integers z == generate(#1 + 1,z)
    oddintegers z == generate(#1 + 2,z)
    int s == generate(#1 + 1,s)

--% derivatives

    mapmult(x,y) == delay
      empty? y => zro()
      empty? x => zro()
      concat(frst x * frst y,mapmult(rst x,rst y))

    deriv x ==
      empty? x => zro()
      mapmult(int 1,rest x)

    gderiv(f,x) ==
      empty? x => zro()
      mapmult(map(f,integers 0)$SP2(I,A),x)

--% coercions

    coerce(s:A) ==
      zero? s => zro()
      concat(s,zro())

--% evaluations and compositions

    eval(x,at) == scan(0,#1 + #2,mapmult(x,generate(at * #1,1)))$SP2(A,A)

    compose(x,y) == delay
      empty? y => concat(frst x,zro())
      not zero? frst y =>
        error "compose: 2nd argument should have 0 constant coefficient"
      empty? x => zro()
      concat(frst x,compose(rst x,y) * rst(y))

--% reversion

    lagrangere:(ST A,ST A) -> ST A
    lagrangere(x,c) == delay(concat(0,compose(x,c)))
    lagrange x == YS(lagrangere(x,#1))

    revert x ==
      empty? x => error "revert should start 0,1,..."
      zero? frst x =>
        empty? rst x => error "revert: should start 0,1,..."
        one? frst rst x => lagrange(recip(rst x) :: (ST A))
      error "revert:should start 0,1,..."

--% lambert functions

    addiag(ststa:ST ST A) == delay
      empty? ststa => zro()
      empty? frst ststa => concat(0,addiag rst ststa)
      concat(frst(frst ststa),rst(frst ststa) + addiag(rst ststa))

-- lambert operates on a series +/[a[i]x**i for i in 1..] , and produces
-- the series +/[a[i](x**i/(1-x**i)) for i in 1..] i.e. forms the
-- coefficients A[n] which is the sum of a[i] for all divisors i of n
-- (including 1 and n)

    rptg1:(I,A) -> ST A
    --                               ---------
    -- returns the repeating stream [s,0,...,0]; (there are z zeroes)
    rptg1(z,s) == repeating concat(s,rp(z,0))

    rptg2:(I,A) -> ST A
    --                                       ---------
    -- returns the repeating stream [0,...,0,s,0,...,0]
    -- there are z leading zeroes and z-1 in the period
    rptg2(z,s) == repeating concat(rp(z,0),concat(s,rp(z-1,0)))

    rptg3:(I,I,I,A) -> ST A
    rptg3(a,d,n,s) ==
      concat(rpSt(n*(a-1),0),repeating(concat(s,rp(d*n-1,0))))

    lambert x == delay
      empty? x => zro()
      zero? frst x =>
        concat(0,addiag(map(rptg1,integers 0,rst x)$SP3(I,A,ST A)))
      error "lambert:constant coefficient should be zero"

    oddlambert x == delay
      empty? x => zro()
      zero? frst x =>
        concat(0,addiag(map(rptg1,oddintegers 1,rst x)$SP3(I,A,ST A)))
      error "oddlambert: constant coefficient should be zero"

    evenlambert x == delay
      empty? x => zro()
      zero? frst x =>
        concat(0,addiag(map(rptg2,integers 1,rst x)$SP3(I,A,ST A)))
      error "evenlambert: constant coefficient should be zero"

    generalLambert(st,a,d) == delay
      a < 1 or d < 1 =>
        error "generalLambert: both integer arguments must be positive"
      empty? st => zro()
      zero? frst st =>
        concat(0,addiag(map(rptg3(a,d,#1,#2),_
                 integers 1,rst st)$SP3(I,A,ST A)))
      error "generalLambert: constant coefficient should be zero"

--% misc. functions

    ms: (I,I,ST A) -> ST A
    ms(m,n,s) == delay
      empty? s => zro()
      zero? n => concat(frst s,ms(m,m-1,rst s))
      ms(m,n-1,rst s)

    multisect(b,a,x) == ms(a+b,0,rest(x,a :: NNI))

    altn: (ST A,ST A) -> ST A
    altn(zs,s) == delay
      empty? s => zro()
      concat(frst s,concat(zs,altn(zs,rst s)))

    invmultisect(a,b,x) ==
      concat(rpSt(b,0),altn(rpSt(a + b - 1,0),x))

-- comps(ststa,y) forms the composition of +/b[i,j]*y**i*x**j
-- where y is a power series in y.

    cssa ==> concat$(ST ST A)
    mapsa ==> map$SP2(ST A,ST A)
    comps: (ST ST A,ST A) -> ST ST A
    comps(ststa,x) == delay$(ST ST A)
       empty? ststa => empty()$(ST ST A)
       empty? x => cssa(frst ststa,empty()$(ST ST A))
       cssa(frst ststa,mapsa((rst x) * #1,comps(rst ststa,x)))

    if A has Algebra RN then
@

The following defines lazy integration on streams interpreted as Taylor series.
I.e. if [[x]] is $c_0,c_1,c_2,\dots$, then [[integ x]] returns
$c_0,\frac{1}{2}c_1,\frac{1}{3}c_2,\dots$. [[integrate]] prepends a given
constant of integration.

<<package STTAYLOR StreamTaylorSeriesOperations>>=
      integre: (ST A,I) -> ST A
      integre(x,n) == delay
        empty? x => zro()
        concat((1$I/n) * frst(x),integre(rst x,n + 1))

      integ: ST A -> ST A
      integ x == integre(x,1)

      integrate(a,x) == concat(a,integ x)
      lazyIntegrate(s,xf) == concat(s,integ(delay xf))

@

<<package STTAYLOR StreamTaylorSeriesOperations>>=
      nldere:(ST ST A,ST A) -> ST A
      nldere(lslsa,c) == lazyIntegrate(0,addiag(comps(lslsa,c)))
      nlde lslsa == YS(nldere(lslsa,#1))

      RATPOWERS : Boolean := A has "**": (A,RN) -> A

      smult: (RN,ST A) -> ST A
      smult(rn,x) == map(rn * #1,x)
@

The following helper function computes
\begin{equation*}
  1+\int (rn+1) c x' dz - c (x-a_0),
\end{equation*}
where $a_0$ is the constant term of [[x]].

<<package STTAYLOR StreamTaylorSeriesOperations>>=
      powerrn:(RN,ST A,ST A) -> ST A
      powerrn(rn,x,c) == delay
        concat(1,integ(smult(rn + 1,c * deriv x)) - rst x * c)
@

The following operation raises the power series [[x]] to a rational power
[[rn]]. We first outline the general strategy.

Suppose the constant term of [[x]] equals one. In this case, we have
\begin{equation*}
  x^{rn+1} = 1 + \int (rn+1) x^{rn} x' dz,  
\end{equation*}
since $(x^{rn+1})'= (rn+1)x^{rn} x'$.  Thus, $x^{rn}$ is the fixed point of %
[[g +-> powerrn(rn, x, g)]]. We use [[Y$ParadoxicalCombinatorsForStreams(A)]]%$
to compute this fixed point lazily.

If the constant term of [[x]] is neither zero nor one, we use the identity
\begin{equation*}
  (c_0 + c_1*z + c_2 z^2\dots)^{rn} = c_0^{rn} (1 + \frac{c_1}{c_0}*z +\dots)^{rn}.
\end{equation*}

Finally, if the constant term of [[x]] is zero, we use the identity
\begin{equation*}
  (c_0*z^o + c_1*z^{o+1} +\dots)^{rn} = z^{o rn} (c_0 + c_1*z +\dots)^{rn}.
\end{equation*}

This implementation should be compared with [[cRationalPower$ISUPS]].%$

<<package STTAYLOR StreamTaylorSeriesOperations>>=
      powern(rn, x) ==
        order : I := 0
        for n in 0.. repeat
          empty? x => return zro()
          not zero? frst x => (order := n; leave x)
          x := rst x
          n = 1000 =>
            error "**: series with many leading zero coefficients"
@
First we determine the order of [[x]], i.e., the index of the first non-zero
coefficient.

Remarks:
\begin{itemize}
\item Note that usually [[leave]] takes no arguments. I don't know what it does
      here.
\item [[empty? x]] tests whether the stream [[x]] has no elements. This is
      mathematically the same as the corresponding power series being zero.
\end{itemize}

<<package STTAYLOR StreamTaylorSeriesOperations>>=
        (ord := (order exquo denom(rn))) case "failed" =>
          error "**: rational power does not exist"
@

[[ord*numer(rn)]] will be the order of the new power series. If it is not an
integer, we won't get a Taylor expansion and thus raise an error.

<<package STTAYLOR StreamTaylorSeriesOperations>>=
        if ord > 0 and rn < 0 then
           error "**: negative power does not exist"
@

If [[order]] was non-zero, we may not raise to a negative power. This test
should really be done before the previous one.

<<package STTAYLOR StreamTaylorSeriesOperations>>=
        co := frst x
        (invCo := recip co) case "failed" =>
           error "** rational power of coefficient undefined"
@

We need to be able to invert the leading coefficient. The error message is
slightly misleading, see [[sups.spad/cRationalPower]].

<<package STTAYLOR StreamTaylorSeriesOperations>>=
        power :=
          one? co => YS(powerrn(rn, x, #1))
          (denom rn) = 1 =>
            not negative?(num := numer rn) =>
-- It seems that this cannot happen, but I don't know why
              (co**num::NNI) * YS(powerrn(rn, (invCo :: A) * x, #1))
            (invCo::A)**((-num)::NNI) * YS(powerrn(rn, (invCo :: A) * x, #1))

          RATPOWERS => co**rn * YS(powerrn(rn,(invCo :: A) * x, #1))
          error "** rational power of coefficient undefined"
@

We now invoke the fixed point computation as explained above. We can do the
computation if
\begin{itemize}
\item the constant term equals one, or
\item [[rn]] is an integer, or
\item we have rational powers in the coefficient ring.
\end{itemize}

<<package STTAYLOR StreamTaylorSeriesOperations>>=
        monom(1, (ord :: I) * numer(rn)) * power
@

Finally, we return the result with the correct order.

<<package STTAYLOR StreamTaylorSeriesOperations>>=
    if A has Field then
      mapdiv(x,y) == delay
        empty? y => error "stream division by zero"
        empty? x => zro()
        concat(frst x/frst y,mapdiv(rst x,rst y))

      ginteg: (I -> A,ST A) -> ST A
      ginteg(f,x) == mapdiv(x,map(f,integers 1)$SP2(I,A))

      lazyGintegrate(fntoa,s,xf) == concat(s,ginteg(fntoa,delay xf))

      finteg: ST A -> ST A
      finteg x == mapdiv(x,int 1)
      powerre: (A,ST A,ST A) -> ST A
      powerre(s,x,c) == delay
        empty? x => zro()
        frst x~=1 => error "**:constant coefficient should be 1"
        concat(frst x,finteg((s+1)*(c*deriv x))-rst x * c)
      power(s,x) == YS(powerre(s,x,#1))

@
\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>>

<<package STTAYLOR StreamTaylorSeriesOperations>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}