/usr/share/axiom-20170501/src/algebra/LSAGG.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 | )abbrev category LSAGG ListAggregate
++ Author: Michael Monagan; revised by Manuel Bronstein and Richard Jenks
++ Date Created: August 87 through August 88
++ Date Last Updated: April 1991
++ Description:
++ A list aggregate is a model for a linked list data structure.
++ A linked list is a versatile
++ data structure. Insertion and deletion are efficient and
++ searching is a linear operation.
ListAggregate(S) : Category == SIG where
S : Type
SA ==> StreamAggregate(S)
FLA ==> FiniteLinearAggregate(S)
ELA ==> ExtensibleLinearAggregate(S)
SIG ==> Join(SA,FLA,ELA) with
list : S -> %
++ list(x) returns the list of one element x.
add
cycleMax ==> 1000
mergeSort: ((S, S) -> Boolean, %, Integer) -> %
sort_!(f, l) == mergeSort(f, l, #l)
list x == concat(x, empty())
reduce(f, x) ==
empty? x => _
error "reducing over an empty list needs the 3 argument form"
reduce(f, rest x, first x)
merge(f, p, q) == merge_!(f, copy p, copy q)
select_!(f, x) ==
while not empty? x and not f first x repeat x := rest x
empty? x => x
y := x
z := rest y
while not empty? z repeat
if f first z then (y := z; z := rest z)
else (z := rest z; setrest_!(y, z))
x
merge_!(f, p, q) ==
empty? p => q
empty? q => p
eq?(p, q) => error "cannot merge a list into itself"
if f(first p, first q)
then (r := t := p; p := rest p)
else (r := t := q; q := rest q)
while not empty? p and not empty? q repeat
if f(first p, first q)
then (setrest_!(t, p); t := p; p := rest p)
else (setrest_!(t, q); t := q; q := rest q)
setrest_!(t, if empty? p then q else p)
r
insert_!(s:S, x:%, i:Integer) ==
i < (m := minIndex x) => error "index out of range"
i = m => concat(s, x)
y := rest(x, (i - 1 - m)::NonNegativeInteger)
z := rest y
setrest_!(y, concat(s, z))
x
insert_!(w:%, x:%, i:Integer) ==
i < (m := minIndex x) => error "index out of range"
i = m => concat_!(w, x)
y := rest(x, (i - 1 - m)::NonNegativeInteger)
z := rest y
setrest_!(y, w)
concat_!(y, z)
x
remove_!(f:S -> Boolean, x:%) ==
while not empty? x and f first x repeat x := rest x
empty? x => x
p := x
q := rest x
while not empty? q repeat
if f first q then q := setrest_!(p, rest q)
else (p := q; q := rest q)
x
delete_!(x:%, i:Integer) ==
i < (m := minIndex x) => error "index out of range"
i = m => rest x
y := rest(x, (i - 1 - m)::NonNegativeInteger)
setrest_!(y, rest(y, 2))
x
delete_!(x:%, i:UniversalSegment(Integer)) ==
(l := lo i) < (m := minIndex x) => error "index out of range"
h := if hasHi i then hi i else maxIndex x
h < l => x
l = m => rest(x, (h + 1 - m)::NonNegativeInteger)
t := rest(x, (l - 1 - m)::NonNegativeInteger)
setrest_!(t, rest(t, (h - l + 2)::NonNegativeInteger))
x
find(f, x) ==
while not empty? x and not f first x repeat x := rest x
empty? x => "failed"
first x
position(f:S -> Boolean, x:%) ==
for k in minIndex(x).. while not empty? x and not f first x repeat
x := rest x
empty? x => minIndex(x) - 1
k
mergeSort(f, p, n) ==
if n = 2 and f(first rest p, first p) then p := reverse_! p
n < 3 => p
l := (n quo 2)::NonNegativeInteger
q := split_!(p, l)
p := mergeSort(f, p, l)
q := mergeSort(f, q, n - l)
merge_!(f, p, q)
sorted?(f, l) ==
empty? l => true
p := rest l
while not empty? p repeat
not f(first l, first p) => return false
p := rest(l := p)
true
reduce(f, x, i) ==
r := i
while not empty? x repeat (r := f(r, first x); x := rest x)
r
if S has SetCategory then
reduce(f, x, i,a) ==
r := i
while not empty? x and r ^= a repeat
r := f(r, first x)
x := rest x
r
new(n, s) ==
l := empty()
for k in 1..n repeat l := concat(s, l)
l
map(f, x, y) ==
z := empty()
while not empty? x and not empty? y repeat
z := concat(f(first x, first y), z)
x := rest x
y := rest y
reverse_! z
reverse_! x ==
empty? x => x
empty?(y := rest x) => x
setrest_!(x, empty())
while not empty? y repeat
z := rest y
setrest_!(y, x)
x := y
y := z
x
copy x ==
y := empty()
for k in 0.. while not empty? x repeat
k = cycleMax and cyclic? x => error "cyclic list"
y := concat(first x, y)
x := rest x
reverse_! y
copyInto_!(y, x, s) ==
s < (m := minIndex y) => error "index out of range"
z := rest(y, (s - m)::NonNegativeInteger)
while not empty? z and not empty? x repeat
setfirst_!(z, first x)
x := rest x
z := rest z
y
if S has SetCategory then
position(w, x, s) ==
s < (m := minIndex x) => error "index out of range"
x := rest(x, (s - m)::NonNegativeInteger)
for k in s.. while not empty? x and w ^= first x repeat
x := rest x
empty? x => minIndex x - 1
k
removeDuplicates_! l ==
p := l
while not empty? p repeat
p := setrest_!(p, remove_!((x:S):Boolean +-> x = first p, rest p))
l
if S has OrderedSet then
x < y ==
while not empty? x and not empty? y repeat
first x ^= first y => return(first x < first y)
x := rest x
y := rest y
empty? x => not empty? y
false
|