This file is indexed.

/usr/share/axiom-20170501/src/algebra/POLYVEC.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
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
)abbrev package POLYVEC U32VectorPolynomialOperations
++ Description: 
++ This is a low-level package which implements operations
++ on vectors treated as univariate modular polynomials.  Most
++ operations takes modulus as parameter.  Modulus is machine
++ sized prime which should be small enough to avoid overflow
++ in intermediate calculations.

U32VectorPolynomialOperations() : SIG == CODE where

  PA ==> U32Vector

  SIG ==> with

    copy_first : (PA, PA, Integer) -> Void
      ++ copy_first(v1, v2, n) copies first n elements
      ++ of v2 into n first positions in v1.

    copy_slice : (PA, PA, Integer, Integer) -> Void
      ++ copy_first(v1, v2, m, n) copies the slice of v2 starting
      ++ at m elements and having n elements into corresponding
      ++ positions in v1.

    eval_at : (PA, Integer, Integer, Integer) -> Integer
      ++ eval_at(v, deg, pt, p) treats v as coefficients of
      ++ polynomial of degree deg and evaluates the
      ++ polynomial at point pt modulo p
      ++
      ++X a:=new(3,1)$U32VEC
      ++X a.1:=2
      ++X eval_at(a,2,3,1024)
      ++X eval_at(a,2,2,8)
      ++X eval_at(a,2,3,10)

    vector_add_mul : (PA, PA, Integer, Integer, Integer, Integer) _
            -> Void
      ++ vector_add_mul(v1, v2, m, n, c, p) sets v1(m), ...,
      ++ v1(n) to corresponding extries in v1 + c*v2
      ++ modulo p.

    mul_by_binomial : (PA, Integer, Integer) -> Void
      ++ mul_by_binomial(v,  pt, p) treats v a polynomial
      ++ and multiplies in place this polynomial by binomial (x + pt).
      ++ Highest coefficient of product is ignored.

    mul_by_binomial : (PA, Integer, Integer, Integer) -> Void
      ++ mul_by_binomial(v, deg, pt, p) treats v as
      ++ coefficients of polynomial of degree deg and
      ++ multiplies in place this polynomial by binomial (x + pt).
      ++ Highest coefficient of product is ignored.

    mul_by_scalar : (PA, Integer, Integer, Integer) -> Void
      ++ mul_by_scalar(v, deg, c, p) treats v as
      ++ coefficients of polynomial of degree deg and
      ++ multiplies in place this polynomial by scalar c

    mul : (PA, PA, Integer) -> PA
      ++ mul(p1,p2,i) does polynomial multiplication.

    truncated_multiplication : (PA, PA, Integer, Integer) -> PA
      ++ truncated_multiplication(x, y, d, p) computes
      ++ x*y truncated after degree d

    truncated_mul_add : (PA, PA, PA, Integer, Integer) -> Void
      ++ truncated_mul_add(x, y, z, d, p) adds to z
      ++ the produce x*y truncated after degree d

    pow : (PA, PositiveInteger, NonNegativeInteger, Integer) -> PA
      ++ pow(u, n, d, p) returns u^n truncated after degree d, except if
      ++ n=1, in which case u itself is returned

    differentiate : (PA, Integer) -> PA
      ++ differentiate(p,i) does polynomial differentiation.

    differentiate : (PA, NonNegativeInteger, Integer) -> PA
      ++ differentiate(p,n,i) does polynomial differentiation.

    divide! : (PA, PA, PA, Integer) -> Void
      ++ divide!(p1,p2,p3,i) does polynomial division.

    remainder! : (PA, PA, Integer) -> Void
      ++ remainder!(p1,p2,i) does polynomial remainder

    vector_combination : (PA, Integer, PA, Integer, _
                               Integer, Integer, p : Integer) -> Void
      ++ vector_combination(v1, c1, v2, c2, n, delta, p) replaces
      ++ first n + 1 entires of v1 by corresponding entries of
      ++ c1*v1+c2*x^delta*v2 mod p.

    to_mod_pa : (SparseUnivariatePolynomial Integer, Integer) -> PA
      ++ to_mod_pa(s, p) reduces coefficients of polynomial
      ++ s modulo prime p and converts the result to vector

    gcd : (PA, PA, Integer) -> PA
      ++ gcd(v1, v2, p) computes monic gcd of v1 and v2 modulo p.

    gcd : (PrimitiveArray PA, Integer, Integer, Integer) -> PA
      ++ gcd(a, lo, hi, p) computes gcd of elements
      ++ a(lo), a(lo+1), ..., a(hi).

    lcm : (PrimitiveArray PA, Integer, Integer, Integer) -> PA
      ++ lcm(a, lo, hi, p) computes lcm of elements
      ++ a(lo), a(lo+1), ..., a(hi).

    degree : PA -> Integer
      ++ degree(v) is degree of v treated as polynomial

    extended_gcd : (PA, PA, Integer) -> List(PA)
      ++ extended_gcd(v1, v2, p) gives [g, c1, c2] such
      ++ that g is \spad{gcd(v1, v2, p)}, \spad{g = c1*v1 + c2*v2}
      ++ and degree(c1) < max(degree(v2) - degree(g), 0) and
      ++ degree(c2) < max(degree(v1) - degree(g), 1)

    resultant : (PA, PA, Integer) -> Integer
      ++ resultant(v1, v2, p) computes resultant of v1 and v2
      ++ modulo p.

  CODE ==> add

        Qmuladdmod ==> QSMULADDMOD6432$Lisp
        Qmuladd    ==> QSMULADD6432$Lisp
        Qmul       ==> QSMULMOD32$Lisp
        Qdot2      ==> QSDOT2MOD6432$Lisp
        Qrem       ==> QSMOD6432$Lisp
        modInverse ==> invmod

        copy_first(np : PA, op : PA, n : Integer) : Void ==
            ns := n pretend SingleInteger
            for j in 0..(ns - 1) repeat
                np(j) := op(j)

        copy_slice(np : PA, op : PA, m : Integer, _
                    n : Integer) : Void ==
            ms := m pretend SingleInteger
            ns := n pretend SingleInteger
            for j in ms..(ms + ns - 1) repeat
                np(j) := op(j)

        eval_at(v : PA, deg : Integer, pt : Integer, _
               p : Integer) : Integer ==
            i : SingleInteger := deg::SingleInteger
            res : Integer := 0
            while not(i < 0) repeat
                res := Qmuladdmod(pt, res, v(i), p)
                i := i - 1
            res

        to_mod_pa(s : SparseUnivariatePolynomial Integer, p : Integer) : PA ==
            zero?(s) => new(1, 0)$PA
            n0 := degree(s) pretend SingleInteger
            ncoeffs := new((n0+1) pretend NonNegativeInteger, 0)$PA
            while not(zero?(s)) repeat
                n := degree(s)
                ncoeffs(n) := positiveRemainder(leadingCoefficient(s), p)
                s := reductum(s)
            ncoeffs

        vector_add_mul(v1 : PA, v2 : PA, m : Integer, n : Integer, _
                         c : Integer, p : Integer) : Void ==
            ms := m pretend SingleInteger
            ns := n pretend SingleInteger
            for i in ms..ns repeat
                v1(i) := Qmuladdmod(c, v2(i), v1(i), p)

        mul_by_binomial(v : PA, n : Integer, pt : Integer, _
                          p : Integer) : Void ==
            prev_coeff : Integer := 0
            ns := n pretend SingleInteger
            for i in 0..(ns - 1) repeat
                pp := v(i)
                v(i) := Qmuladdmod(pt, pp, prev_coeff, p)
                prev_coeff := pp

        mul_by_binomial(v : PA, pt : Integer, _
                          p : Integer) : Void ==
            mul_by_binomial(v, #v, pt, p)

        mul_by_scalar(v : PA, n : Integer, c : Integer, _
                        p : Integer) : Void ==
            ns := n pretend SingleInteger
            for i in 0..ns repeat
                v(i) := Qmul(c, v(i), p)

        degree(v : PA) : Integer ==
            n := #v
            for i in (n - 1)..0 by -1 repeat
                not(v(i) = 0) => return i
            -1

        vector_combination(v1 : PA, c1 : Integer, _
                            v2 : PA, c2 : Integer, _
                            n : Integer, delta : Integer, _
                            p : Integer) : Void ==
            ns := n pretend SingleInteger
            ds := delta pretend SingleInteger
            if not(c1 = 1) then
                ns + 1 < ds =>
                    for i in 0..ns repeat
                        v1(i) := Qmul(v1(i), c1, p)
                for i in 0..(ds - 1) repeat
                    v1(i) := Qmul(v1(i), c1, p)
                for i in ds..ns repeat
                    v1(i) := Qdot2(v1(i), c1, v2(i - ds), c2, p)
            else
                for i in ds..ns repeat
                    v1(i) := Qmuladdmod(c2, v2(i - ds), v1(i), p)

        divide!(r0 : PA, r1 : PA, res : PA, p: Integer) : Void ==
            dr0 := degree(r0) pretend SingleInteger
            dr1 := degree(r1) pretend SingleInteger
            c0 := r1(dr1)
            c0 := modInverse(c0, p)
            while not(dr0 < dr1) repeat
                delta := dr0 - dr1
                c1 := Qmul(c0, r0(dr0), p)
                res(delta) := c1
                c1 := p - c1
                r0(dr0) := 0
                dr0 := dr0 - 1
                if dr0 < 0 then break
                vector_combination(r0, 1, r1, c1, dr0, delta, p)
                while r0(dr0) = 0 repeat
                    dr0 := dr0 - 1
                    if dr0 < 0 then break

        remainder!(r0 : PA, r1 : PA, p: Integer) : Void ==
            dr0 := degree(r0) pretend SingleInteger
            dr1 := degree(r1) pretend SingleInteger
            c0 := r1(dr1)
            c0 := modInverse(c0, p)
            while not(dr0 < dr1) repeat
                delta := dr0 - dr1
                c1 := Qmul(c0, r0(dr0), p)
                c1 := p - c1
                r0(dr0) := 0
                dr0 := dr0 - 1
                if dr0 < 0 then break
                vector_combination(r0, 1, r1, c1, dr0, delta, p)
                while r0(dr0) = 0 repeat
                    dr0 := dr0 - 1
                    if dr0 < 0 then break

        gcd(x : PA, y : PA, p : Integer) : PA ==
            dr0 := degree(y) pretend SingleInteger
            dr1 : SingleInteger
            if dr0 < 0 then
                tmpp := x
                x := y
                y := tmpp
                dr1 := dr0
                dr0 := degree(y) pretend SingleInteger
            else
                dr1 := degree(x) pretend SingleInteger
            dr0 < 0 => return new(1, 0)$PA
            r0 := new((dr0 + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r0, y, dr0 + 1)
            dr1 < 0 =>
                c := r0(dr0)
                c := modInverse(c, p)
                mul_by_scalar(r0, dr0, c, p)
                return r0
            r1 := new((dr1 + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r1, x, dr1 + 1)
            while 0 < dr1 repeat
                while not(dr0 < dr1) repeat
                    delta := dr0 - dr1
                    c1 := sub_SI(p, r0(dr0))$Lisp
                    c0 := r1(dr1)
                    if c0 ~= 1 and delta > 30 then
                        c0 :=  modInverse(c0, p)
                        mul_by_scalar(r1, dr1, c0, p)
                        c0 := 1
                    r0(dr0) := 0
                    dr0 := dr0 - 1
                    vector_combination(r0, c0, r1, c1, dr0, delta, p)
                    while r0(dr0) = 0 repeat
                        dr0 := dr0 - 1
                        if dr0 < 0 then break
                tmpp := r0
                tmp := dr0
                r0 := r1
                dr0 := dr1
                r1 := tmpp
                dr1 := tmp
            not(dr1 < 0) =>
                r1(0) := 1
                return r1
            c := r0(dr0)
            c := modInverse(c, p)
            mul_by_scalar(r0, dr0, c, p)
            r0

        gcd(a : PrimitiveArray PA, lo : Integer, hi: Integer, p: Integer) _
              : PA ==
            res := a(lo)
            for i in (lo + 1)..hi repeat
                res := gcd(a(i), res, p)
            res

        lcm2(v1 : PA, v2 : PA, p : Integer) : PA ==
            pp := gcd(v1, v2, p)
            dv2 := degree(v2)
            dpp := degree(pp)
            dv2 = dpp =>
                v1
            dpp = 0 => mul(v1, v2, p)
            tmp1 := new((dv2 + 1) pretend NonNegativeInteger, 0)$PA
            tmp2 := new((dv2 - dpp + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(tmp1, v2, dv2 + 1)
            divide!(tmp1, pp, tmp2, p)
            mul(v1, tmp2, p)

        lcm(a : PrimitiveArray PA, lo : Integer, hi: Integer, p: Integer) _
              : PA ==
            res := a(lo)
            for i in (lo + 1)..hi repeat
                res := lcm2(a(i), res, p)
            res

        inner_mul : (PA, PA, PA,  SingleInteger, SingleInteger, _
                      SingleInteger, Integer) -> Void

        mul(x : PA, y : PA, p : Integer) : PA ==
            xdeg := degree(x) pretend SingleInteger
            ydeg := degree(y) pretend SingleInteger
            if xdeg > ydeg then
                tmpp := x
                tmp := xdeg
                x := y
                xdeg := ydeg
                y := tmpp
                ydeg := tmp
            xcoeffs := x
            ycoeffs := y
            xdeg < 0 => x
            xdeg = 0 and xcoeffs(0) = 1 => copy(y)
            zdeg : SingleInteger := xdeg + ydeg
            zdeg0 := ((zdeg + 1)::Integer) pretend NonNegativeInteger
            zcoeffs := new(zdeg0, 0)$PA
            inner_mul(xcoeffs, ycoeffs, zcoeffs, xdeg, ydeg, zdeg, p)
            zcoeffs

        inner_mul(x, y, z, xdeg, ydeg, zdeg, p) ==
            if ydeg < xdeg then
                tmpp := x
                tmp := xdeg
                x := y
                xdeg := ydeg
                y := tmpp
                ydeg := tmp
            xdeg :=
                zdeg < xdeg => zdeg
                xdeg
            ydeg :=
                zdeg < ydeg => zdeg
                ydeg
            ss : Integer
            i : SingleInteger
            j : SingleInteger
            for i in 0..xdeg repeat
                ss := z(i)
                for j in 0..i repeat
                    ss := Qmuladd(x(i - j), y(j), ss)
                z(i) := Qrem(ss, p)
            for i in (xdeg+1)..ydeg repeat
                ss := z(i)
                for j in 0..xdeg repeat
                    ss := Qmuladd(x(j), y(i-j), ss)
                z(i) := Qrem(ss, p)
            for i in (ydeg+1)..zdeg repeat
                ss := z(i)
                for j in (i-xdeg)..ydeg repeat
                    ss := Qmuladd(x(i - j), y(j), ss)
                z(i) := Qrem(ss, p)

        truncated_mul_add(x, y, z, m, p) ==
            xdeg := (#x - 1) pretend SingleInteger
            ydeg := (#y - 1) pretend SingleInteger
            inner_mul(x, y, z, xdeg, ydeg, m pretend SingleInteger, p)

        truncated_multiplication(x, y, m, p) ==
            xdeg := (#x - 1) pretend SingleInteger
            ydeg := (#y - 1) pretend SingleInteger
            z := new((m pretend SingleInteger + 1)
                        pretend NonNegativeInteger, 0)$PA
            inner_mul(x, y, z, xdeg, ydeg, m pretend SingleInteger, p)
            z

        pow(x : PA, n : PositiveInteger, d: NonNegativeInteger, _
            p : Integer) : PA ==
            one? n => x
            odd?(n)$Integer =>
                truncated_multiplication(x,
                    pow(truncated_multiplication(x, x, d, p),
                        shift(n,-1) pretend PositiveInteger,
                        d,
                        p),
                    d,
                    p)
            pow(truncated_multiplication(x, x, d, p),
                shift(n,-1) pretend PositiveInteger,
                d,
                p)

        differentiate(x: PA, p: Integer): PA ==
            d := #x - 1
            if zero? d then empty()$PA
            else
                r := new(d::NonNegativeInteger, 0)$PA
                for i in 0..d-1 repeat
                    i1 := i+1
                    r.i := Qmul(i1, x.i1, p)
                r

        differentiate(x: PA, n: NonNegativeInteger, p: Integer): PA ==
            zero? n => x
            d := #x - 1
            if d < n then empty()$PA
            else
                r := new((d-n+1) pretend NonNegativeInteger, 0)$PA
                for i in n..d repeat
                    j := i-n
                    f := j+1
                    for k in j+2..i repeat f := Qmul(f, k, p)
                    r.(j pretend NonNegativeInteger) := Qmul(f, x.i, p)
                r

        extended_gcd(x : PA, y : PA, p : Integer) : List(PA) ==
            dr0 := degree(x) pretend SingleInteger
            dr1 : SingleInteger
            swapped : Boolean := false
            t0 : PA
            if dr0 < 0 then
                (x, y) := (y, x)
                dr1 := dr0
                dr0 := degree(x) pretend SingleInteger
                swapped := true
            else
                dr1 := degree(y) pretend SingleInteger
            dr1 < 0 =>
                dr0 < 0 =>
                    return [new(1, 0)$PA, new(1, 0)$PA, new(1, 1)$PA]
                r0 := new((dr0 + 1) pretend NonNegativeInteger, 0)$PA
                copy_first(r0, x, dr0 + 1)
                c := r0(dr0)
                c := modInverse(c, p)
                mul_by_scalar(r0, dr0, c, p)
                t0 := new(1, c)$PA
                if swapped then
                    return [r0, new(1, 0)$PA, t0]
                else
                    return [r0, t0, new(1, 0)$PA]
            swapped => error "impossible"
            dt := (dr0 > 0 => dr0 - 1 ; 0)
            ds := (dr1 > 0 => dr1 - 1 ; 0)
            -- invariant: r0 = s0*x + t0*y, r1 = s1*x + t1*y
            r0 := new((dr0 + 1) pretend NonNegativeInteger, 0)$PA
            t0 := new((dt + 1) pretend NonNegativeInteger, 0)$PA
            s0 := new((ds + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r0, x, dr0 + 1)
            s0(0) := 1
            r1 := new((dr1 + 1) pretend NonNegativeInteger, 0)$PA
            t1 := new((dt + 1) pretend NonNegativeInteger, 0)$PA
            s1 := new((ds + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r1, y, dr1 + 1)
            t1(0) := 1
            while dr1 > 0 repeat
                while dr0 >= dr1 repeat
                    delta := dr0 - dr1
                    c1 := sub_SI(p, r0(dr0))$Lisp
                    c0 := r1(dr1)
                    if c0 ~= 1 and delta > 30 then
                        c0 :=  modInverse(c0, p)
                        mul_by_scalar(r1, dr1, c0, p)
                        mul_by_scalar(t1, dt, c0, p)
                        mul_by_scalar(s1, ds, c0, p)
                        c0 := 1
                    r0(dr0) := 0
                    dr0 := dr0 - 1
                    vector_combination(r0, c0, r1, c1, dr0, delta, p)
                    vector_combination(t0, c0, t1, c1, dt, delta, p)
                    vector_combination(s0, c0, s1, c1, ds, delta, p)
                    while r0(dr0) = 0 repeat
                        dr0 := dr0 - 1
                        if dr0 < 0 then break
                (r0, r1) := (r1, r0)
                (dr0, dr1) := (dr1, dr0)
                (s0, s1) := (s1, s0)
                (t0, t1) := (t1, t0)
            dr1 >= 0 =>
                c := r1(0)
                c := modInverse(c, p)
                r1(0) := 1
                mul_by_scalar(s1, ds, c, p)
                mul_by_scalar(t1, dt, c, p)
                return [r1, s1, t1]
            c := r0(dr0)
            c := modInverse(c, p)
            mul_by_scalar(r0, dr0, c, p)
            mul_by_scalar(s0, ds, c, p)
            mul_by_scalar(t0, dt, c, p)
            [r0, s0, t0]

        resultant(x : PA, y : PA, p : Integer) : Integer ==
            dr0 := degree(x) pretend SingleInteger
            dr0 < 0 => 0
            dr1 := degree(y) pretend  SingleInteger
            dr1 < 0 => 0
            r0 := new((dr0 + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r0, x, dr0 + 1)
            r1 := new((dr1 + 1) pretend NonNegativeInteger, 0)$PA
            copy_first(r1, y, dr1 + 1)
            res : SingleInteger := 1
            repeat
                dr0 < dr1 =>
                    (r0, r1) := (r1, r0)
                    (dr0, dr1) := (dr1, dr0)
                c0 := r1(dr1)
                dr1 = 0 =>
                    while 0 < dr0 repeat
                        res := Qmul(res, c0, p)
                        dr0 := dr0 - 1
                    return res
                delta := dr0 - dr1
                c1 := sub_SI(p, r0(dr0))$Lisp
                if c0 ~= 1 then
                    c1 :=  Qmul(c1, modInverse(c0, p), p)
                r0(dr0) := 0
                dr0 := dr0 - 1
                vector_combination(r0, 1, r1, c1, dr0, delta, p)
                res := Qmul(res, c0, p)
                while r0(dr0) = 0 repeat
                    dr0 := dr0 - 1
                    dr0 < 0 => return 0
                    res := Qmul(res, c0, p)