This file is indexed.

/usr/share/axiom-20170501/src/algebra/ULSCONS.spad is in axiom-source 20170501-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
)abbrev domain ULSCONS UnivariateLaurentSeriesConstructor
++ Authors: Bill Burge, Clifton J. Williamson
++ Date Created: August 1988
++ Date Last Updated: 17 June 1996
++ Description:
++ This package enables one to construct a univariate Laurent series
++ domain from a univariate Taylor series domain. Univariate
++ Laurent series are represented by a pair \spad{[n,f(x)]}, where n is
++ an arbitrary integer and \spad{f(x)} is a Taylor series.  This pair
++ represents the Laurent series \spad{x**n * f(x)}.

UnivariateLaurentSeriesConstructor(Coef,UTS) : SIG == CODE where
  Coef : Ring
  UTS : UnivariateTaylorSeriesCategory Coef

  I     ==> Integer
  L     ==> List
  NNI   ==> NonNegativeInteger
  OUT   ==> OutputForm
  P     ==> Polynomial Coef
  RF    ==> Fraction Polynomial Coef
  RN    ==> Fraction Integer
  ST    ==> Stream Coef
  TERM  ==> Record(k:I,c:Coef)
  monom ==> monomial$UTS
  EFULS ==> ElementaryFunctionsUnivariateLaurentSeries(Coef,UTS,%)
  STTAYLOR ==> StreamTaylorSeriesOperations Coef

  SIG ==> UnivariateLaurentSeriesConstructorCategory(Coef,UTS)

  CODE ==> add

    Rep := Record(expon:I,ps:UTS)

    getExpon : % -> I
    getUTS   : % -> UTS

    getExpon x == x.expon

    getUTS   x == x.ps

    laurent(n,psr) == [n,psr]

    taylorRep x    == getUTS x

    degree x       == getExpon x

    0 == laurent(0,0)

    1 == laurent(0,1)

    monomial(s,e) == laurent(e,s::UTS)

    coerce(uts:UTS):% == laurent(0,uts)

    coerce(r:Coef):%  == r :: UTS  :: %

    coerce(i:I):%     == i :: Coef :: %

    taylorIfCan uls ==
      n := getExpon uls
      n < 0 =>
        uls := removeZeroes(-n,uls)
        getExpon(uls) < 0 => "failed"
        getUTS uls
      n = 0 => getUTS uls
      getUTS(uls) * monom(1,n :: NNI)

    taylor uls ==
      (uts := taylorIfCan uls) case "failed" =>
        error "taylor: Laurent series has a pole"
      uts :: UTS

    termExpon: TERM -> I
    termExpon term == term.k

    termCoef: TERM -> Coef
    termCoef term == term.c

    rec: (I,Coef) -> TERM
    rec(exponent,coef) == [exponent,coef]

    recs: (ST,I) -> Stream TERM
    recs(st,n) == delay
      empty? st => empty()
      zero? (coef := frst st) => recs(rst st,n + 1)
      concat(rec(n,coef),recs(rst st,n + 1))

    terms x == recs(coefficients getUTS x,getExpon x)

    recsToCoefs: (Stream TERM,I) -> ST
    recsToCoefs(st,n) == delay
      empty? st => empty()
      term := frst st; ex := termExpon term
      n = ex => concat(termCoef term,recsToCoefs(rst st,n + 1))
      concat(0,recsToCoefs(rst st,n + 1))

    series st ==
      empty? st => 0
      ex := termExpon frst st
      laurent(ex,series recsToCoefs(st,ex))

--% normalizations

    removeZeroes x ==
      empty? coefficients(xUTS := getUTS x) => 0
      coefficient(xUTS,0) = 0 =>
        removeZeroes laurent(getExpon(x) + 1,quoByVar xUTS)
      x

    removeZeroes(n,x) ==
      n <= 0 => x
      empty? coefficients(xUTS := getUTS x) => 0
      coefficient(xUTS,0) = 0 =>
        removeZeroes(n - 1,laurent(getExpon(x) + 1,quoByVar xUTS))
      x

--% predicates

    x = y ==
      EQ(x,y)$Lisp => true
      (expDiff := getExpon(x) - getExpon(y)) = 0 =>
        getUTS(x) = getUTS(y)
      abs(expDiff) > _$streamCount$Lisp => false
      expDiff > 0 =>
        getUTS(x) * monom(1,expDiff :: NNI) = getUTS(y)
      getUTS(y) * monom(1,(- expDiff) :: NNI) = getUTS(x)

    pole? x ==
      (n := degree x) >= 0 => false
      x := removeZeroes(-n,x)
      degree x < 0

--% arithmetic

    x + y  ==
      n := getExpon(x) - getExpon(y)
      n >= 0 =>
        laurent(getExpon y,getUTS(y) + getUTS(x) * monom(1,n::NNI))
      laurent(getExpon x,getUTS(x) + getUTS(y) * monom(1,(-n)::NNI))

    x - y  ==
      n := getExpon(x) - getExpon(y)
      n >= 0 =>
        laurent(getExpon y,getUTS(x) * monom(1,n::NNI) - getUTS(y))
      laurent(getExpon x,getUTS(x) - getUTS(y) * monom(1,(-n)::NNI))

    x:% * y:% == laurent(getExpon x + getExpon y,getUTS x * getUTS y)

    x:% ** n:NNI ==
      zero? n =>
        zero? x => error "0 ** 0 is undefined"
        1
      laurent(n * getExpon(x),getUTS(x) ** n)

    recip x ==
      x := removeZeroes(1000,x)
      zero? coefficient(x,d := degree x) => "failed"
      (uts := recip getUTS x) case "failed" => "failed"
      laurent(-d,uts :: UTS)

    elt(uls1:%,uls2:%) ==
      (uts := taylorIfCan uls2) case "failed" =>
        error "elt: second argument must have positive order"
      uts2 := uts :: UTS
      not zero? coefficient(uts2,0) =>
        error "elt: second argument must have positive order"
      if (deg := getExpon uls1) < 0 then uls1 := removeZeroes(-deg,uls1)
      (deg := getExpon uls1) < 0 =>
        (recipr := recip(uts2 :: %)) case "failed" =>
          error "elt: second argument not invertible"
        uts1 := taylor(uls1 * monomial(1,-deg))
        (elt(uts1,uts2) :: %) * (recipr :: %) ** ((-deg) :: NNI)
      elt(taylor uls1,uts2) :: %

    eval(uls:%,r:Coef) ==
      if (n := getExpon uls) < 0 then uls := removeZeroes(-n,uls)
      uts := getUTS uls
      (n := getExpon uls) < 0 =>
        zero? r => error "eval: 0 raised to negative power"
        (recipr := recip r) case "failed" =>
          error "eval: non-unit raised to negative power"
        (recipr :: Coef) ** ((-n) :: NNI) *$STTAYLOR eval(uts,r)
      zero? n => eval(uts,r)
      r ** (n :: NNI) *$STTAYLOR eval(uts,r)

--% values

    variable x == variable getUTS x

    center   x == center   getUTS x

    coefficient(x,n) ==
      a := n - getExpon(x)
      a >= 0 => coefficient(getUTS x,a :: NNI)
      0

    elt(x:%,n:I) == coefficient(x,n)

--% other functions

    order x == getExpon x + order getUTS x

    order(x,n) ==
      (m := n - (e := getExpon x)) < 0 => n
      e + order(getUTS x,m :: NNI)

    truncate(x,n) ==
      (m := n - (e := getExpon x)) < 0 => 0
      laurent(e,truncate(getUTS x,m :: NNI))

    truncate(x,n1,n2) ==
      if n2 < n1 then (n1,n2) := (n2,n1)
      (m1 := n1 - (e := getExpon x)) < 0 => truncate(x,n2)
      laurent(e,truncate(getUTS x,m1 :: NNI,(n2 - e) :: NNI))

    if Coef has IntegralDomain then

      rationalFunction(x,n) ==
        (m := n - (e := getExpon x)) < 0 => 0
        poly := polynomial(getUTS x,m :: NNI) :: RF
        zero? e => poly
        v := variable(x) :: RF; c := center(x) :: P :: RF
        positive? e => poly * (v - c) ** (e :: NNI)
        poly / (v - c) ** ((-e) :: NNI)

      rationalFunction(x,n1,n2) ==
        if n2 < n1 then (n1,n2) := (n2,n1)
        (m1 := n1 - (e := getExpon x)) < 0 => rationalFunction(x,n2)
        poly := polynomial(getUTS x,m1 :: NNI,(n2 - e) :: NNI) :: RF
        zero? e => poly
        v := variable(x) :: RF; c := center(x) :: P :: RF
        positive? e => poly * (v - c) ** (e :: NNI)
        poly / (v - c) ** ((-e) :: NNI)

      x exquo y ==
        x := removeZeroes(1000,x)
        y := removeZeroes(1000,y)
        zero? coefficient(y, d := degree y) => "failed"
        (uts := (getUTS x) exquo (getUTS y)) case "failed" => "failed"
        laurent(degree x-d,uts :: UTS)

    if Coef has coerce: Symbol -> Coef then
      if Coef has "**": (Coef,I) -> Coef then

        approximate(x,n) ==
          (m := n - (e := getExpon x)) < 0 => 0
          app := approximate(getUTS x,m :: NNI)
          zero? e => app
          app * ((variable(x) :: Coef) - center(x)) ** e

    complete x == laurent(getExpon x,complete getUTS x)

    extend(x,n) ==
      e := getExpon x
      (m := n - e) < 0 => x
      laurent(e,extend(getUTS x,m :: NNI))

    map(f:Coef -> Coef,x:%) == laurent(getExpon x,map(f,getUTS x))

    multiplyCoefficients(f,x) ==
      e := getExpon x
      laurent(e,multiplyCoefficients((z1:I):Coef +-> f(e + z1),getUTS x))

    multiplyExponents(x,n) ==
      laurent(n * getExpon x,multiplyExponents(getUTS x,n))

    differentiate x ==
      e := getExpon x
      laurent(e - 1,
              multiplyCoefficients((z1:I):Coef +-> (e + z1)::Coef,getUTS x))

    if Coef has PartialDifferentialRing(Symbol) then

      differentiate(x:%,s:Symbol) ==
        (s = variable(x)) => differentiate x
        map((z1:Coef):Coef +-> differentiate(z1,s),x) 
                                 - differentiate(center x,s)*differentiate(x)

    characteristic() == characteristic()$Coef

    if Coef has Field then

      retract(x:%):UTS                      == taylor x

      retractIfCan(x:%):Union(UTS,"failed") == taylorIfCan x

      (x:%) ** (n:I) ==
        zero? n =>
          zero? x => error "0 ** 0 is undefined"
          1
        n > 0 => laurent(n * getExpon(x),getUTS(x) ** (n :: NNI))
        xInv := inv x; minusN := (-n) :: NNI
        laurent(minusN * getExpon(xInv),getUTS(xInv) ** minusN)

      (x:UTS) * (y:%) == (x :: %) * y

      (x:%) * (y:UTS) == x * (y :: %)

      inv x ==
        (xInv := recip x) case "failed" =>
          error "multiplicative inverse does not exist"
        xInv :: %

      (x:%) / (y:%) ==
        (yInv := recip y) case "failed" =>
          error "inv: multiplicative inverse does not exist"
        x * (yInv :: %)

      (x:UTS) / (y:UTS) == (x :: %) / (y :: %)

      numer x ==
        (n := degree x) >= 0 => taylor x
        x := removeZeroes(-n,x)
        (n := degree x) = 0 => taylor x
        getUTS x

      denom x ==
        (n := degree x) >= 0 => 1
        x := removeZeroes(-n,x)
        (n := degree x) = 0 => 1
        monom(1,(-n) :: NNI)

--% algebraic and transcendental functions

    if Coef has Algebra Fraction Integer then

      coerce(r:RN) == r :: Coef :: %

      if Coef has Field then
         (x:%) ** (r:RN) == x **$EFULS r

      exp x   == exp(x)$EFULS

      log x   == log(x)$EFULS

      sin x   == sin(x)$EFULS

      cos x   == cos(x)$EFULS

      tan x   == tan(x)$EFULS

      cot x   == cot(x)$EFULS

      sec x   == sec(x)$EFULS

      csc x   == csc(x)$EFULS

      asin x  == asin(x)$EFULS

      acos x  == acos(x)$EFULS

      atan x  == atan(x)$EFULS

      acot x  == acot(x)$EFULS

      asec x  == asec(x)$EFULS

      acsc x  == acsc(x)$EFULS

      sinh x  == sinh(x)$EFULS

      cosh x  == cosh(x)$EFULS

      tanh x  == tanh(x)$EFULS

      coth x  == coth(x)$EFULS

      sech x  == sech(x)$EFULS

      csch x  == csch(x)$EFULS

      asinh x == asinh(x)$EFULS

      acosh x == acosh(x)$EFULS

      atanh x == atanh(x)$EFULS

      acoth x == acoth(x)$EFULS

      asech x == asech(x)$EFULS

      acsch x == acsch(x)$EFULS

      ratInv: I -> Coef
      ratInv n ==
        zero? n => 1
        inv(n :: RN) :: Coef

      integrate x ==
        not zero? coefficient(x,-1) =>
          error "integrate: series has term of order -1"
        e := getExpon x
        laurent(e+1,multiplyCoefficients((z:I):Coef+->ratInv(e+1+z),getUTS x))

      if Coef has integrate: (Coef,Symbol) -> Coef and _
         Coef has variables: Coef -> List Symbol then

        integrate(x:%,s:Symbol) ==
          (s = variable(x)) => integrate x
          not entry?(s,variables center x)
             => map((z1:Coef):Coef+->integrate(z1,s),x)
          error "integrate: center is a function of variable of integration"

      if Coef has TranscendentalFunctionCategory and _
         Coef has PrimitiveFunctionCategory and _
         Coef has AlgebraicallyClosedFunctionSpace Integer then

        integrateWithOneAnswer: (Coef,Symbol) -> Coef
        integrateWithOneAnswer(f,s) ==
          res := integrate(f,s)$FunctionSpaceIntegration(I,Coef)
          res case Coef => res :: Coef
          first(res :: List Coef)

        integrate(x:%,s:Symbol) ==
          (s = variable(x)) => integrate x
          not entry?(s,variables center x) =>
            map((z1:Coef):Coef +-> integrateWithOneAnswer(z1,s),x)
          error "integrate: center is a function of variable of integration"

    termOutput:(I,Coef,OUT) -> OUT
    termOutput(k,c,vv) ==
    -- creates a term c * vv ** k
      k = 0 => c :: OUT
      mon :=
        k = 1 => vv
        vv ** (k :: OUT)
      c = 1 => mon
      c = -1 => -mon
      (c :: OUT) * mon

    -- check a global Lisp variable
    showAll?:() -> Boolean
    showAll?() == true

    termsToOutputForm:(I,ST,OUT) -> OUT
    termsToOutputForm(m,uu,xxx) ==
      l : L OUT := empty()
      empty? uu => (0$Coef) :: OUT
      n : NNI ; count : NNI := _$streamCount$Lisp
      for n in 0..count while not empty? uu repeat
        if frst(uu) ^= 0 then
          l := concat(termOutput((n :: I) + m,frst(uu),xxx),l)
        uu := rst uu
      if showAll?() then
        for n in (count + 1).. while explicitEntries? uu and _
               not eq?(uu,rst uu) repeat
          if frst(uu) ^= 0 then
            l := concat(termOutput((n::I) + m,frst(uu),xxx),l)
          uu := rst uu
      l :=
        explicitlyEmpty? uu => l
        eq?(uu,rst uu) and frst uu = 0 => l
        concat(prefix("O" :: OUT,[xxx ** ((n :: I) + m) :: OUT]),l)
      empty? l => (0$Coef) :: OUT
      reduce("+",reverse_! l)

    coerce(x:%):OUT ==
      x := removeZeroes(_$streamCount$Lisp,x)
      m := degree x
      uts := getUTS x
      p := coefficients uts
      var := variable uts; cen := center uts
      xxx :=
        zero? cen => var :: OUT
        paren(var :: OUT - cen :: OUT)
      termsToOutputForm(m,p,xxx)