This file is indexed.

/usr/share/axiom-20170501/src/algebra/ARR2CAT.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
)abbrev category ARR2CAT TwoDimensionalArrayCategory
++ Date Created: 27 October 1989
++ Date Last Updated: 27 June 1990
++ Keywords: array, data structure
++ Description:
++ Two dimensional array categories and domains

TwoDimensionalArrayCategory(R,Row,Col) : Category == SIG where
  R   : Type
  Row : FiniteLinearAggregate R
  Col : FiniteLinearAggregate R

  SIG ==> HomogeneousAggregate(R) with

    shallowlyMutable
      ++ one may destructively alter arrays
  
    finiteAggregate
      ++ two-dimensional arrays are finite
  
    --% Array creation
  
    new : (NonNegativeInteger,NonNegativeInteger,R) -> %
      ++ new(m,n,r) is an m-by-n array all of whose entries are r
      ++
      ++X arr : ARRAY2 INT := new(5,4,0)
      
    fill_! : (%,R) -> %
      ++ fill!(m,r) fills m with r's
      ++
      ++X arr : ARRAY2 INT := new(5,4,0)
      ++X fill!(arr,10)
  
    --% Size inquiries
  
    minRowIndex : % -> Integer
      ++ minRowIndex(m) returns the index of the 'first' row of the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X minRowIndex(arr)
  
    maxRowIndex : % -> Integer
      ++ maxRowIndex(m) returns the index of the 'last' row of the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X maxRowIndex(arr)
  
    minColIndex : % -> Integer
      ++ minColIndex(m) returns the index of the 'first' column of the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X minColIndex(arr)
  
    maxColIndex : % -> Integer
      ++ maxColIndex(m) returns the index of the 'last' column of the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X maxColIndex(arr)
  
    nrows : % -> NonNegativeInteger
      ++ nrows(m) returns the number of rows in the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X nrows(arr)
  
    ncols : % -> NonNegativeInteger
      ++ ncols(m) returns the number of columns in the array m
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X ncols(arr)
  
    --% Part extractions
  
    elt : (%,Integer,Integer) -> R
      ++ elt(m,i,j) returns the element in the ith row and jth
      ++ column of the array m
      ++ error check to determine if indices are in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X elt(arr,1,1)
  
    qelt : (%,Integer,Integer) -> R
      ++ qelt(m,i,j) returns the element in the ith row and jth
      ++ column of the array m
      ++ NO error check to determine if indices are in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X qelt(arr,1,1)
  
    elt : (%,Integer,Integer,R) -> R
      ++ elt(m,i,j,r) returns the element in the ith row and jth
      ++ column of the array m, if m has an ith row and a jth column,
      ++ and returns r otherwise
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X elt(arr,1,1,6)
      ++X elt(arr,1,10,6)
  
    row : (%,Integer) -> Row
      ++ row(m,i) returns the ith row of m
      ++ error check to determine if index is in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X row(arr,1)
  
    column : (%,Integer) -> Col
      ++ column(m,j) returns the jth column of m
      ++ error check to determine if index is in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X column(arr,1)
  
    parts : % -> List R
      ++ parts(m) returns a list of the elements of m in row major order
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X parts(arr)
  
    --% Part assignments
  
    setelt : (%,Integer,Integer,R) -> R
      ++ setelt(m,i,j,r) sets the element in the ith row and jth
      ++ column of m to r
      ++ error check to determine if indices are in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,0)
      ++X setelt(arr,1,1,17)
  
    qsetelt_! : (%,Integer,Integer,R) -> R
      ++ qsetelt!(m,i,j,r) sets the element in the ith row and jth
      ++ column of m to r
      ++ NO error check to determine if indices are in proper ranges
      ++
      ++X arr : ARRAY2 INT := new(5,4,0)
      ++X qsetelt!(arr,1,1,17)
  
    setRow_! : (%,Integer,Row) -> %
      ++ setRow!(m,i,v) sets to ith row of m to v
      ++
      ++X T1:=TwoDimensionalArray Integer
      ++X arr:T1:= new(5,4,0)
      ++X T2:=OneDimensionalArray Integer
      ++X arow:=construct([1,2,3,4]::List(INT))$T2
      ++X setRow!(arr,1,arow)$T1
  
    setColumn_! : (%,Integer,Col) -> %
      ++ setColumn!(m,j,v) sets to jth column of m to v
      ++
      ++X T1:=TwoDimensionalArray Integer
      ++X arr:T1:= new(5,4,0)
      ++X T2:=OneDimensionalArray Integer
      ++X acol:=construct([1,2,3,4,5]::List(INT))$T2
      ++X setColumn!(arr,1,acol)$T1
  
    --% Map and Zip
  
    map : (R -> R,%) -> %
      ++ map(f,a) returns \spad{b}, where \spad{b(i,j) = f(a(i,j))} 
      ++ for all \spad{i, j}
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X map(-,arr)
      ++X map((x +-> x + x),arr)
  
    map_! : (R -> R,%) -> %
      ++ map!(f,a)  assign \spad{a(i,j)} to \spad{f(a(i,j))} 
      ++ for all \spad{i, j}
      ++
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X map!(-,arr)
  
    map : ((R,R) -> R,%,%) -> %
      ++ map(f,a,b) returns \spad{c}, where \spad{c(i,j) = f(a(i,j),b(i,j))}
      ++ for all \spad{i, j}
      ++
      ++X adder(a:Integer,b:Integer):Integer == a+b
      ++X arr : ARRAY2 INT := new(5,4,10)
      ++X map(adder,arr,arr)
  
    map : ((R,R) -> R,%,%,R) -> %
      ++ map(f,a,b,r) returns \spad{c}, where \spad{c(i,j) = f(a(i,j),b(i,j))}
      ++ when both \spad{a(i,j)} and \spad{b(i,j)} exist;
      ++ else \spad{c(i,j) = f(r, b(i,j))} when \spad{a(i,j)} does not exist;
      ++ else \spad{c(i,j) = f(a(i,j),r)} when \spad{b(i,j)} does not exist;
      ++ otherwise \spad{c(i,j) = f(r,r)}.
      ++
      ++X adder(a:Integer,b:Integer):Integer == a+b
      ++X arr1 : ARRAY2 INT := new(5,4,10)
      ++X arr2 : ARRAY2 INT := new(3,3,10)
      ++X map(adder,arr1,arr2,17)
  
   add

     --% Predicates
  
     any?(f,m) ==
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           f(qelt(m,i,j)) => return true
       false
  
     every?(f,m) ==
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           not f(qelt(m,i,j)) => return false
       true
  
     size?(m,n) == nrows(m) * ncols(m) = n

     less?(m,n) == nrows(m) * ncols(m) < n

     more?(m,n) == nrows(m) * ncols(m) > n

     --% Size inquiries
  
     # m == nrows(m) * ncols(m)
  
     --% Part extractions
  
     elt(m,i,j,r) ==
       i < minRowIndex(m) or i > maxRowIndex(m) => r
       j < minColIndex(m) or j > maxColIndex(m) => r
       qelt(m,i,j)
  
     count(f:R -> Boolean,m:%) ==
       num : NonNegativeInteger := 0
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           if f(qelt(m,i,j)) then num := num + 1
       num
  
     parts m ==
       entryList : List R := nil()
       for i in maxRowIndex(m)..minRowIndex(m) by -1 repeat
         for j in maxColIndex(m)..minColIndex(m) by -1 repeat
           entryList := concat(qelt(m,i,j),entryList)
       entryList
  
     --% Creation
  
     copy m ==
       ans := new(nrows m,ncols m,NIL$Lisp)
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           qsetelt_!(ans,i,j,qelt(m,i,j))
       ans
  
     fill_!(m,r) ==
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           qsetelt_!(m,i,j,r)
       m
  
     map(f,m) ==
       ans := new(nrows m,ncols m,NIL$Lisp)
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           qsetelt_!(ans,i,j,f(qelt(m,i,j)))
       ans
  
     map_!(f,m) ==
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           qsetelt_!(m,i,j,f(qelt(m,i,j)))
       m
  
     map(f,m,n) ==
       (nrows(m) ^= nrows(n)) or (ncols(m) ^= ncols(n)) =>
         error "map: arguments must have same dimensions"
       ans := new(nrows m,ncols m,NIL$Lisp)
       for i in minRowIndex(m)..maxRowIndex(m) repeat
         for j in minColIndex(m)..maxColIndex(m) repeat
           qsetelt_!(ans,i,j,f(qelt(m,i,j),qelt(n,i,j)))
       ans
  
     map(f,m,n,r) ==
       maxRow := max(maxRowIndex m,maxRowIndex n)
       maxCol := max(maxColIndex m,maxColIndex n)
       ans := new(max(nrows m,nrows n),max(ncols m,ncols n),NIL$Lisp)
       for i in minRowIndex(m)..maxRow repeat
         for j in minColIndex(m)..maxCol repeat
           qsetelt_!(ans,i,j,f(elt(m,i,j,r),elt(n,i,j,r)))
       ans
  
     setRow_!(m,i,v) ==
       i < minRowIndex(m) or i > maxRowIndex(m) =>
         error "setRow!: index out of range"
       for j in minColIndex(m)..maxColIndex(m) _
         for k in minIndex(v)..maxIndex(v) repeat
           qsetelt_!(m,i,j,v.k)
       m
  
     setColumn_!(m,j,v) ==
       j < minColIndex(m) or j > maxColIndex(m) =>
         error "setColumn!: index out of range"
       for i in minRowIndex(m)..maxRowIndex(m) _
         for k in minIndex(v)..maxIndex(v) repeat
           qsetelt_!(m,i,j,v.k)
       m
  
     if R has _= : (R,R) -> Boolean then
  
       m = n ==
         eq?(m,n) => true
         (nrows(m) ^= nrows(n)) or (ncols(m) ^= ncols(n)) => false
         for i in minRowIndex(m)..maxRowIndex(m) repeat
           for j in minColIndex(m)..maxColIndex(m) repeat
             not (qelt(m,i,j) = qelt(n,i,j)) => return false
         true
  
       member?(r,m) ==
         for i in minRowIndex(m)..maxRowIndex(m) repeat
           for j in minColIndex(m)..maxColIndex(m) repeat
             qelt(m,i,j) = r => return true
         false
  
       count(r:R,m:%) == count(x +-> x = r,m)
  
     if Row has shallowlyMutable then
  
       row(m,i) ==
         i < minRowIndex(m) or i > maxRowIndex(m) =>
           error "row: index out of range"
         v : Row := new(ncols m,NIL$Lisp)
         for j in minColIndex(m)..maxColIndex(m) _
           for k in minIndex(v)..maxIndex(v) repeat
             qsetelt_!(v,k,qelt(m,i,j))
         v
  
     if Col has shallowlyMutable then
  
       column(m,j) ==
         j < minColIndex(m) or j > maxColIndex(m) =>
           error "column: index out of range"
         v : Col := new(nrows m,NIL$Lisp)
         for i in minRowIndex(m)..maxRowIndex(m) _
           for k in minIndex(v)..maxIndex(v) repeat
             qsetelt_!(v,k,qelt(m,i,j))
         v
  
     if R has CoercibleTo(OutputForm) then
  
       coerce(m:%) ==
         l : List List OutputForm
         l := [[qelt(m,i,j) :: OutputForm _
                   for j in minColIndex(m)..maxColIndex(m)] _
                   for i in minRowIndex(m)..maxRowIndex(m)]
         matrix l