This file is indexed.

/usr/share/axiom-20170501/src/algebra/RECOP.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
)abbrev package RECOP RecurrenceOperator
++ Author: Martin Rubey
++ Description:
++ This package provides an operator for the n-th term of a recurrence and an
++ operator for the coefficient of x^n in a function specified by a functional
++ equation.

RecurrenceOperator(R, F) : SIG == CODE where
  R: Join(OrderedSet, IntegralDomain, ConvertibleTo InputForm)
  F: Join(FunctionSpace R, AbelianMonoid, RetractableTo Integer, _
          RetractableTo Symbol, PartialDifferentialRing Symbol, _
          CombinatorialOpsCategory)

  SIG ==> with

    evalRec : (BasicOperator, Symbol, F, F, F, List F) -> F
      ++ \spad{evalRec(u, dummy, n, n0, eq, values)} creates an expression that
      ++ stands for u(n0), where u(n) is given by the equation eq. However, for
      ++ technical reasons the variable n has to be replaced by a dummy
      ++ variable dummy in eq. The argument values specifies the initial values
      ++ of the recurrence u(0), u(1),...
      ++ For the moment we don't allow recursions that contain u inside of
      ++ another operator.

    evalADE : (BasicOperator, Symbol, F, F, F, List F) -> F
      ++ \spad{evalADE(f, dummy, x, n, eq, values)} creates an expression that
      ++ stands for the coefficient of x^n in the Taylor expansion of f(x),
      ++ where f(x) is given by the functional equation eq. However, for
      ++ technical reasons the variable x has to be replaced by a dummy
      ++ variable dummy in eq. The argument values specifies the first few
      ++ Taylor coefficients.

    getEq : F -> F
      ++ \spad{getEq f} returns the defining equation, if f represents the
      ++ coefficient of an ADE or a recurrence.

    getOp : F -> BasicOperator
      ++ \spad{getOp f}, if f represents the coefficient of a recurrence or
      ++ ADE, returns the operator representing the solution

-- should be local
    numberOfValuesNeeded : (Integer, BasicOperator, Symbol, F) -> Integer

-- should be local
    if R has Ring then

      getShiftRec : (BasicOperator, Kernel F, Symbol) -> Union(Integer, "failed")

      shiftInfoRec : (BasicOperator, Symbol, F) -> 
                      Record(max: Union(Integer, "failed"), 
                             ord: Union(Integer, "failed"),
                             ker: Kernel F)

  CODE ==> add

    oprecur := operator("rootOfRec"::Symbol)$BasicOperator

    opADE := operator("rootOfADE"::Symbol)$BasicOperator

    setProperty(oprecur, "%dummyVar", 2 pretend None)
    setProperty(opADE, "%dummyVar", 2 pretend None)
    eqAsF: List F -> F
    eqAsF l == l.1
    dummy: List F -> Symbol
    dummy l == retract(l.2)@Symbol

    dummyAsF: List F -> F
    dummyAsF l == l.2
    displayVariable: List F -> F
    displayVariable l == l.3
    operatorName: List F -> BasicOperator
    operatorName l == operator(kernels(l.4).1)

    operatorNameAsF: List F -> F
    operatorNameAsF l == l.4

    operatorArgument: List F -> F
    operatorArgument l == argument(kernels(l.4).1).1
    initialValues: List F -> List F
    initialValues l == rest(l, 4)
    if R has Ring then
      getShiftRec(op: BasicOperator, f: Kernel F, n: Symbol)
                 : Union(Integer, "failed") ==
          a := argument f
          if every?(z +-> freeOf?(z, n::F), a) then return 0

          if #a ~= 1 then error "RECOP: operator should have only one argument"

          p := univariate(a.1, retract(n::F)@Kernel(F))
          if denominator p ~= 1 then return "failed"

          num := numer p

          if degree num = 1 and coefficient(num, 1) = 1
             and every?(z +-> freeOf?(z, n::F), coefficients num)
          then return retractIfCan(coefficient(num, 0))
          else return "failed"

-- if the recurrence is of the form 
-- $p(n, f(n+m-o), f(n+m-o+1), \dots, f(n+m)) = 0$
-- in which case shiftInfoRec returns [m, o, f(n+m)].

      shiftInfoRec(op: BasicOperator, argsym: Symbol, eq: F): 
                   Record(max: Union(Integer, "failed"), 
                          ord: Union(Integer, "failed"),
                          ker: Kernel F) ==

-- ord and ker are valid only if all shifts are Integers
-- ker is the kernel of the maximal shift.
        maxShift: Integer
        minShift: Integer
        nextKernel: Kernel F

-- We consider only those kernels that have op as operator. If there is none,
-- we raise an error. For the moment we don't allow recursions that contain op
-- inside of another operator.

        error? := true

        for f in kernels eq repeat
          if is?(f, op) then
            shift := getShiftRec(op, f, argsym)
            if error? then
              error? := false
              nextKernel := f
              if shift case Integer then
                maxShift := shift
                minShift := shift
              else return ["failed", "failed", nextKernel]
            else
              if shift case Integer then 
                if maxShift < shift then
                  maxShift := shift
                  nextKernel := f
                if minShift > shift then
                  minShift := shift
              else return ["failed", "failed", nextKernel]

        if error? then error "evalRec: equation does not contain operator"

        [maxShift, maxShift - minShift, nextKernel]
      evalRec(op, argsym, argdisp, arg, eq, values) == 
        if ((n := retractIfCan(arg)@Union(Integer, "failed")) case "failed")
           or (n < 0)
        then
          shiftInfo := shiftInfoRec(op, argsym, eq)

          if (shiftInfo.ord case "failed") or ((shiftInfo.ord)::Integer > 0) 
          then
            kernel(oprecur, 
                   append([eq, argsym::F, argdisp, op(arg)], values))
          else
            p := univariate(eq, shiftInfo.ker)
            num := numer p

-- If the degree is 1, we can return the function explicitly.

            if degree num = 1 then
              eval(-coefficient(num, 0)/coefficient(num, 1), argsym::F, 
                   arg::F-(shiftInfo.max)::Integer::F)
            else 
              kernel(oprecur, 
                     append([eq, argsym::F, argdisp, op(arg)], values))
        else 
          len: Integer := #values
          if n < len
          then values.(len-n)
          else
            shiftInfo := shiftInfoRec(op, argsym, eq)

            if shiftInfo.max case Integer then
              p := univariate(eq, shiftInfo.ker)

              num := numer p

              if degree num = 1 then

                next := -coefficient(num, 0)/coefficient(num, 1)
                nextval := eval(next, argsym::F, 
                                (len-(shiftInfo.max)::Integer)::F)
                newval := eval(nextval, op, 
                           z+->evalRec(op, argsym, argdisp, z, eq, values))
                evalRec(op, argsym, argdisp, arg, eq, cons(newval, values))
              else
                kernel(oprecur, 
                       append([eq, argsym::F, argdisp, op(arg)], values))

            else
              kernel(oprecur, 
                     append([eq, argsym::F, argdisp, op(arg)], values))

      numberOfValuesNeeded(numberOfValues: Integer, 
                            op: BasicOperator, 
                             argsym: Symbol, eq: F): Integer ==
        order := shiftInfoRec(op, argsym, eq).ord
        if order case Integer
        then min(numberOfValues, retract(order)@Integer)
        else numberOfValues


    else
      evalRec(op, argsym, argdisp, arg, eq, values) == 
        kernel(oprecur, 
               append([eq, argsym::F, argdisp, op(arg)], values))

      numberOfValuesNeeded(numberOfValues: Integer, 
                           op: BasicOperator, argsym: Symbol, eq: F): Integer ==
        numberOfValues
    irecur: List F -> F
    irecur l ==
      evalRec(operatorName l,
              dummy l, displayVariable l,
              operatorArgument l, eqAsF l, initialValues l)

    evaluate(oprecur, irecur)$BasicOperatorFunctions1(F)

    ddrec: List F -> OutputForm
    ddrec l ==
      op := operatorName l
      values := reverse l
      eq := eqAsF l

      numberOfValues := numberOfValuesNeeded(#values-4, op, dummy l, eq)

      vals: List OutputForm
           := cons(eval(eq, dummyAsF l, displayVariable l)::OutputForm = _
                   0::OutputForm,
                   [elt(op::OutputForm, [(i-1)::OutputForm]) = _
                    (values.i)::OutputForm
                    for i in 1..numberOfValues])

      bracket(hconcat([(operatorNameAsF l)::OutputForm,
                       ": ",
                       commaSeparate vals]))

    setProperty(oprecur, "%specialDisp", 
                ddrec@(List F -> OutputForm) pretend None)

    getOrder(op: BasicOperator, f: Kernel F): NonNegativeInteger ==
      res: NonNegativeInteger := 0
      g := f
      while is?(g, %diff) repeat
        g := kernels(argument(g).1).1
        res := res+1

      if is?(g, op) then res else 0

    evalADE(op, argsym, argdisp, arg, eq, values) == 
      if not freeOf?(eq, retract(argdisp)@Symbol) 
      then error "RECOP: The argument should not be used in the equation of the_
 ADE"

      if ((n := retractIfCan(arg)@Union(Integer, "failed")) case "failed")
      then 
-- try to determine the necessary number of initial values
         keq := kernels eq
         order := getOrder(op, keq.1)
         for k in rest keq repeat order := max(order, getOrder(op, k))

         p: Fraction SparseUnivariatePolynomial F 
           := univariate(eq, kernels(D(op(argsym::F), argsym, order)).1)$F

         if one? degree numer p 
-- the equation is holonomic
         then kernel(opADE, 
                     append([eq, argsym::F, argdisp, op(arg)], 
                            reverse first(reverse values, order)))
         else kernel(opADE, 
                     append([eq, argsym::F, argdisp, op(arg)], values))
      else
        if n < 0
        then 0
        else
          keq := kernels eq
          order := getOrder(op, keq.1)
--          output(hconcat("The order is ", order::OutputForm))$OutputPackage
          for k in rest keq repeat order := max(order, getOrder(op, k))

          p: Fraction SparseUnivariatePolynomial F 
            := univariate(eq, kernels(D(op(argsym::F), argsym, order)).1)$F

--          output(hconcat("p: ", p::OutputForm))$OutputPackage

          if degree numer p > 1
          then
--            kernel(opADE, 
--                   append([eq, argsym::F, argdisp, op(arg)], values))

            s := seriesSolve(eq, op, argsym, reverse values)
                            $ExpressionSolve(R, F, 
                                             UnivariateFormalPowerSeries F, 
                                             UnivariateFormalPowerSeries
                                               SparseUnivariatePolynomialExpressions F)

            elt(s, n::Integer::NonNegativeInteger)

          else
            s := seriesSolve(eq, op, argsym, first(reverse values, order))
                            $ExpressionSolve(R, F, 
                                             UnivariateFormalPowerSeries F, 
                                             UnivariateFormalPowerSeries
                                               SparseUnivariatePolynomialExpressions F)

            elt(s, n::Integer::NonNegativeInteger)


    iADE: List F -> F
-- This is just a wrapper that allows us to write a recurrence relation as an
-- operator.
    iADE l ==
      evalADE(operatorName l,
              dummy l, displayVariable l,
              operatorArgument l, eqAsF l, initialValues l)

    evaluate(opADE, iADE)$BasicOperatorFunctions1(F)

    getEq(f: F): F ==
      ker := kernels f
      if one?(#ker) and _
         (is?(operator(ker.1), "rootOfADE"::Symbol) or _
          is?(operator(ker.1), "rootOfRec"::Symbol)) then
        l := argument(ker.1)
        eval(eqAsF l, dummyAsF l, displayVariable l)
      else
        error "getEq: argument should be a single rootOfADE or rootOfRec object"

    getOp(f: F): BasicOperator ==
      ker := kernels f
      if one?(#ker) and _
         (is?(operator(ker.1), "rootOfADE"::Symbol) or _
          is?(operator(ker.1), "rootOfRec"::Symbol)) then
        operatorName argument(ker.1)
      else
        error "getOp: argument should be a single rootOfADE or rootOfRec object"



    ddADE: List F -> OutputForm
    ddADE l ==
      op := operatorName l
      values := reverse l

      vals: List OutputForm
           := cons(eval(eqAsF l, dummyAsF l, displayVariable l)::OutputForm = _
                   0::OutputForm,
                   [eval(D(op(dummyAsF l), dummy l, i), _
                         dummyAsF l=0)::OutputForm = _
                    (values.(i+1))::OutputForm * _
                    factorial(box(i::R::F)$F)::OutputForm _
                    for i in 0..min(4,#values-5)])

      bracket(hconcat([bracket((displayVariable l)::OutputForm ** _
                               (operatorArgument l)::OutputForm), 
                       (op(displayVariable l))::OutputForm, ": ",
                       commaSeparate vals]))

    setProperty(opADE, "%specialDisp", 
                ddADE@(List F -> OutputForm) pretend None)