This file is indexed.

/usr/share/axiom-20170501/src/algebra/SYMBOL.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
)abbrev domain SYMBOL Symbol
++ Author: Stephen Watt
++ Date Created: 1986
++ Date Last Updated: 7 Mar 1991, 29 Apr. 1994 (FDLL)
++ References:
++ Corl00 According to Abramowitz and Stegun or arccoth needn't be Uncouth
++ Fate01a A Critique of OpenMath and Thoughts on Encoding Mathematics
++ Description:
++ Basic and scripted symbols.

Symbol() : SIG == CODE where

  L ==> List OutputForm
  Scripts ==> Record(sub:L,sup:L,presup:L,presub:L,args:L)

  SIG ==> Join(OrderedSet, ConvertibleTo InputForm, OpenMath,
        ConvertibleTo Symbol,
         ConvertibleTo Pattern Integer, ConvertibleTo Pattern Float,
          PatternMatchable Integer, PatternMatchable Float) with

    new: () -> %
      ++ new() returns a new symbol whose name starts with %.
      ++
      ++X new()$Symbol

    new: % -> %
      ++ new(s) returns a new symbol whose name starts with %s.
      ++
      ++X new("xyz")$Symbol

    resetNew: () -> Void
      ++ resetNew() resets the internals counters that new() and
      ++ new(s) use to return distinct symbols every time.
      ++
      ++X new()$Symbol
      ++X new()$Symbol
      ++X resetNew()
      ++X new()$Symbol

    coerce: String -> %
      ++ coerce(s) converts the string s to a symbol.
      ++
      ++X coerce("Hello")$Symbol
      ++X "Hello"::Symbol

    name: % -> %
      ++ name(s) returns s without its scripts.
      ++
      ++X U:=subscript(u,[1,2])
      ++X name(U)

    scripted?: % -> Boolean
      ++ scripted?(s) is true if s has been given any scripts.
      ++
      ++X U:=subscript(u,[1,2])
      ++X scripted? U
      ++X scripted? W

    scripts: % -> Scripts
      ++ scripts(s) returns all the scripts of s.
      ++
      ++X m:=script(Big,[[i,j],[k,1],[0,1],[2],[u,v,w]])
      ++X scripts m

    script: (%, List L) -> %
      ++ script(s, [a,b,c,d,e]) returns s with subscripts a,
      ++ superscripts b, pre-superscripts c, pre-subscripts d,
      ++ and argument-scripts e.  Omitted components are taken to be empty.
      ++ For example, \spad{script(s, [a,b,c])} is equivalent to
      ++ \spad{script(s,[a,b,c,[],[]])}.
      ++
      ++X m:=script(Big,[[i,j],[k,1],[0,1],[2],[u,v,w]])
      ++X scripts m

    script: (%, Scripts) -> %
      ++ script(s, [a,b,c,d,e]) returns s with subscripts a,
      ++ superscripts b, pre-superscripts c, pre-subscripts d,
      ++ and argument-scripts e.
      ++
      ++X m:=script(Big,[[i,j],[k,1],[0,1],[2],[u,v,w]])
      ++X n:=scripts m
      ++X script(Little,n)

    subscript: (%, L) -> %
      ++ subscript(s, [a1,...,an]) returns s
      ++ subscripted by \spad{[a1,...,an]}.
      ++
      ++X subscript(Big,[a,1])

    superscript: (%, L) -> %
      ++ superscript(s, [a1,...,an]) returns s
      ++ superscripted by \spad{[a1,...,an]}.
      ++
      ++X superscript(Big,[a,1])

    argscript: (%, L) -> %
      ++ argscript(s, [a1,...,an]) returns s
      ++ arg-scripted by \spad{[a1,...,an]}.
      ++
      ++X argscript(Big,[a,1])

    elt: (%, L) -> %
      ++ elt(s,[a1,...,an]) or s([a1,...,an]) 
      ++ returns s subscripted by \spad{[a1,...,an]}.
      ++
      ++X elt(S,[a1,a2])
      ++X s([a1,a2])

    string: % -> String
      ++ string(s) converts the symbol s to a string.
      ++ Error: if the symbol is subscripted.
      ++
      ++X S:="Hello"::Symbol
      ++X string S

    list: % -> List %
      ++ list(sy) takes a scripted symbol and produces a list
      ++ of the name followed by the scripts.
      ++
      ++X m:=script(Big,[[i,j],[k,1],[0,1],[2],[u,v,w]])
      ++X (list m)$Symbol

    sample: constant -> %
      ++ sample() returns a sample of %
      ++
      ++X sample()$Symbol

  CODE ==> add

    count: Reference(Integer) := ref 0

    xcount: AssociationList(%, Integer) := empty()

    istrings:PrimitiveArray(String) :=
                     construct ["0","1","2","3","4","5","6","7","8","9"]

    -- the following 3 strings shall be of empty intersection

    nums:String:="0123456789"

    ALPHAS:String:="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    alphas:String:="abcdefghijklmnopqrstuvwxyz"

    writeOMSym(dev: OpenMathDevice, x: %): Void ==
      scripted? x =>
        error "Cannot convert a scripted symbol to OpenMath"
      OMputVariable(dev, x pretend Symbol)

    OMwrite(x: %): String ==
      s: String := ""
      sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
      dev: OpenMathDevice := OMopenString(sp @ String, OMencodingXML)
      OMputObject(dev)
      writeOMSym(dev, x)
      OMputEndObject(dev)
      OMclose(dev)
      s := OM_-STRINGPTRTOSTRING(sp)$Lisp @ String
      s

    OMwrite(x: %, wholeObj: Boolean): String ==
      s: String := ""
      sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
      dev: OpenMathDevice := OMopenString(sp @ String, OMencodingXML)
      if wholeObj then
        OMputObject(dev)
      writeOMSym(dev, x)
      if wholeObj then
        OMputEndObject(dev)
      OMclose(dev)
      s := OM_-STRINGPTRTOSTRING(sp)$Lisp @ String
      s

    OMwrite(dev: OpenMathDevice, x: %): Void ==
      OMputObject(dev)
      writeOMSym(dev, x)
      OMputEndObject(dev)

    OMwrite(dev: OpenMathDevice, x: %, wholeObj: Boolean): Void ==
      if wholeObj then
        OMputObject(dev)
      writeOMSym(dev, x)
      if wholeObj then
        OMputEndObject(dev)

    hd:String    := "*"
    lhd          := #hd
    ord0         := ord char("0")$Character

    istring  : Integer -> String
    syprefix : Scripts -> String
    syscripts: Scripts -> L

    convert(s:%):InputForm == convert(s pretend Symbol)$InputForm

    convert(s:%):Symbol    == s pretend Symbol

    coerce(s:String):%     == VALUES(INTERN(s)$Lisp)$Lisp

    x = y                  == EQUAL(x,y)$Lisp

    x < y                  == GGREATERP(y, x)$Lisp

    coerce(x:%):OutputForm == outputForm(x pretend Symbol)

    subscript(sy, lx)      == script(sy, [lx, nil, nil(), nil(), nil()])

    elt(sy,lx)             == subscript(sy,lx)

    superscript(sy, lx)    == script(sy,[nil(),lx, nil(), nil(), nil()])

    argscript(sy, lx)      == script(sy,[nil(),nil(), nil(), nil(), lx])

    patternMatch(x:%,p:Pattern Integer,l:PatternMatchResult(Integer,%))==
      (patternMatch(x pretend Symbol, p, l pretend
       PatternMatchResult(Integer, Symbol))$PatternMatchSymbol(Integer))
         pretend PatternMatchResult(Integer, %)

    patternMatch(x:%, p:Pattern Float, l:PatternMatchResult(Float, %)) ==
      (patternMatch(x pretend Symbol, p, l pretend
       PatternMatchResult(Float, Symbol))$PatternMatchSymbol(Float))
         pretend PatternMatchResult(Float, %)

    convert(x:%):Pattern(Float) ==
      coerce(x pretend Symbol)$Pattern(Float)

    convert(x:%):Pattern(Integer) ==
      coerce(x pretend Symbol)$Pattern(Integer)

    syprefix sc ==
      ns: List Integer := [#sc.presub, #sc.presup, #sc.sup, #sc.sub]
      while #ns >= 2 and zero? first ns repeat ns := rest ns
      concat concat(concat(hd, istring(#sc.args)),
                                 [istring n for n in reverse_! ns])

    syscripts sc ==
      all := sc.presub
      all := concat(sc.presup, all)
      all := concat(sc.sup, all)
      all := concat(sc.sub, all)
      concat(all, sc.args)

    script(sy: %, ls: List L) ==
      sc: Scripts := [nil(), nil(), nil(), nil(), nil()]
      if not null ls then (sc.sub    := first ls; ls := rest ls)
      if not null ls then (sc.sup    := first ls; ls := rest ls)
      if not null ls then (sc.presup := first ls; ls := rest ls)
      if not null ls then (sc.presub := first ls; ls := rest ls)
      if not null ls then (sc.args   := first ls; ls := rest ls)
      script(sy, sc)

    script(sy: %, sc: Scripts) ==
      scripted? sy => error "Cannot add scripts to a scripted symbol"
      (concat(concat(syprefix sc, string name sy)::%::OutputForm,
                                                syscripts sc)) pretend %

    string e ==
      not scripted? e => PNAME(e)$Lisp
      error "Cannot form string from non-atomic symbols."

    -- Scripts ==> Record(sub:L,sup:L,presup:L,presub:L,args:L)
    latex e ==
      s : String := (PNAME(name e)$Lisp) @ String
      if #s > 1 and s.1 ^= char "\" then
        s := concat("\mbox{\it ", concat(s, "}")$String)$String
      not scripted? e => s
      ss : Scripts := scripts e
      lo : List OutputForm := ss.sub
      sc : String
      if not empty? lo then
        sc := "__{"
        while not empty? lo repeat
            sc := concat(sc, latex first lo)$String
            lo := rest lo
            if not empty? lo then sc := concat(sc, ", ")$String
        sc := concat(sc, "}")$String
        s := concat(s, sc)$String
      lo := ss.sup
      if not empty? lo then
        sc := "^{"
        while not empty? lo repeat
            sc := concat(sc, latex first lo)$String
            lo := rest lo
            if not empty? lo then sc := concat(sc, ", ")$String
        sc := concat(sc, "}")$String
        s := concat(s, sc)$String
      lo := ss.presup
      if not empty? lo then
        sc := "{}^{"
        while not empty? lo repeat
            sc := concat(sc, latex first lo)$String
            lo := rest lo
            if not empty? lo then sc := concat(sc, ", ")$String
        sc := concat(sc, "}")$String
        s := concat(sc, s)$String
      lo := ss.presub
      if not empty? lo then
        sc := "{}__{"
        while not empty? lo repeat
            sc := concat(sc, latex first lo)$String
            lo := rest lo
            if not empty? lo then sc := concat(sc, ", ")$String
        sc := concat(sc, "}")$String
        s := concat(sc, s)$String
      lo := ss.args
      if not empty? lo then
        sc := "\left( {"
        while not empty? lo repeat
            sc := concat(sc, latex first lo)$String
            lo := rest lo
            if not empty? lo then sc := concat(sc, ", ")$String
        sc := concat(sc, "} \right)")$String
        s := concat(s, sc)$String
      s

    anyRadix(n:Integer,s:String):String ==
      ns:String:=""
      repeat
        qr := divide(n,#s)
        n  := qr.quotient
        ns := concat(s.(qr.remainder+minIndex s),ns)
        if zero?(n) then return ns
      
    new() ==
      sym := anyRadix(count()::Integer,ALPHAS)
      count() := count() + 1
      concat("%",sym)::%

    new x ==
      n:Integer :=
        (u := search(x, xcount)) case "failed" => 0
        inc(u::Integer)
      xcount(x) := n
      xx := 
        not scripted? x => string x
        string name x
      xx := concat("%",xx)
      xx :=
        (position(xx.maxIndex(xx),nums)>=minIndex(nums)) => 
          concat(xx, anyRadix(n,alphas))
        concat(xx, anyRadix(n,nums))
      not scripted? x => xx::%
      script(xx::%,scripts x)

    resetNew() ==
      count() := 0
      for k in keys xcount repeat remove_!(k, xcount)
      void

    scripted? sy ==
      not ATOM(sy)$Lisp

    name sy ==
      not scripted? sy => sy
      str := string first list sy
      for i in lhd+1..#str repeat
        not digit?(str.i) => return((str.(i..#str))::%)
      error "Improper scripted symbol"

    scripts sy ==
      not scripted? sy => [nil(), nil(), nil(), nil(), nil()]
      nscripts: List NonNegativeInteger := [0, 0, 0, 0, 0]
      lscripts: List L := [nil(), nil(), nil(), nil(), nil()]
      str  := string first list sy
      nstr := #str
      m := minIndex nscripts
      for i in m.. for j in lhd+1..nstr while digit?(str.j) repeat
          nscripts.i := (ord(str.j) - ord0)::NonNegativeInteger
      -- Put the number of function scripts at the end.
      nscripts := concat(rest nscripts, first nscripts)
      allscripts := rest list sy
      m := minIndex lscripts
      for i in m.. for n in nscripts repeat
        #allscripts < n => error "Improper script count in symbol"
        lscripts.i := [a::OutputForm for a in first(allscripts, n)]
        allscripts := rest(allscripts, n)
      [lscripts.m, lscripts.(m+1), lscripts.(m+2),
                                         lscripts.(m+3), lscripts.(m+4)]

    istring n ==
      n > 9 => error "Can have at most 9 scripts of each kind"
      istrings.(n + minIndex istrings)

    list sy ==
      not scripted? sy =>
         error "Cannot convert a symbol to a list if it is not subscripted"
      sy pretend List(%)

    sample() == "aSymbol"::%