/usr/share/axiom-20170501/src/algebra/OFMONOID.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 | )abbrev domain OFMONOID OrderedFreeMonoid
++ Author: Michel Petitot petitot@lifl.fr
++ Date Created: 91
++ Date Last Updated: 7 Juillet 92
++ Fix History: compilation v 2.1 le 13 dec 98
++ Description:
++ The free monoid on a set \spad{S} is the monoid of finite products of
++ the form \spad{reduce(*,[si ** ni])} where the si's are in S, and the ni's
++ are non-negative integers. The multiplication is not commutative.
++ For two elements \spad{x} and \spad{y} the relation \spad{x < y}
++ holds if either \spad{length(x) < length(y)} holds or if these lengths
++ are equal and if \spad{x} is smaller than \spad{y} w.r.t. the
++ lexicographical ordering induced by \spad{S}.
++ This domain inherits implementation from \spadtype{FreeMonoid}.
OrderedFreeMonoid(S) : SIG == CODE where
S : OrderedSet
NNI ==> NonNegativeInteger
REC ==> Record(gen:S, exp:NNI)
RESULT ==> Union(Record(lm:Union(%,"failed"),rm:Union(%,"failed")),"failed")
SIG ==> Join(OrderedMonoid, RetractableTo S) with
"*": (S, %) -> %
++ \spad{s*x} returns the product of \spad{x} by \spad{s} on the left.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X x*m1
"*" : (%, S) -> %
++ \spad{x*s} returns the product of \spad{x} by \spad{s} on the right.
++
++X m1:=(y**3)$OFMONOID(Symbol)
++X m1*x
"**" : (S, NNI) -> %
++ \spad{s**n} returns the product of \spad{s} by itself \spad{n} times.
++
++X m1:=(y**3)$OFMONOID(Symbol)
first : % -> S
++ \spad{first(x)} returns the first letter of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X first m1
rest : % -> %
++ \spad{rest(x)} returns \spad{x} except the first letter.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X rest m1
mirror : % -> %
++ \spad{mirror(x)} returns the reversed word of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X mirror m1
lexico : (%,%) -> Boolean
++ \spad{lexico(x,y)} returns \spad{true}
++ iff \spad{x} is smaller than \spad{y}
++ w.r.t. the pure lexicographical ordering induced by \spad{S}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X m2:=(x*y)$OFMONOID(Symbol)
++X lexico(m1,m2)
++X lexico(m2,m1)
hclf : (%, %) -> %
++ \spad{hclf(x, y)} returns the highest common left factor
++ of \spad{x} and \spad{y},
++ that is the largest \spad{d} such that \spad{x = d a}
++ and \spad{y = d b}.
++
++X m1:=(x*y*z)$OFMONOID(Symbol)
++X m2:=(x*y)$OFMONOID(Symbol)
++X hclf(m1,m2)
hcrf : (%, %) -> %
++ \spad{hcrf(x, y)} returns the highest common right
++ factor of \spad{x} and \spad{y},
++ that is the largest \spad{d} such that \spad{x = a d}
++ and \spad{y = b d}.
++
++X m1:=(x*y*z)$OFMONOID(Symbol)
++X m2:=(y*z)$OFMONOID(Symbol)
++X hcrf(m1,m2)
lquo : (%, %) -> Union(%, "failed")
++ \spad{lquo(x, y)} returns the exact left quotient of \spad{x}
++ by \spad{y} that is \spad{q} such that \spad{x = y * q},
++ "failed" if \spad{x} is not of the form \spad{y * q}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X m2:=(x*y)$OFMONOID(Symbol)
++X lquo(m1,m2)
rquo : (%, %) -> Union(%, "failed")
++ \spad{rquo(x, y)} returns the exact right quotient of \spad{x}
++ by \spad{y} that is \spad{q} such that \spad{x = q * y},
++ "failed" if \spad{x} is not of the form \spad{q * y}.
++
++X m1:=(q*y^3)$OFMONOID(Symbol)
++X m2:=(y^2)$OFMONOID(Symbol)
++X lquo(m1,m2)
lquo : (%, S) -> Union(%, "failed")
++ \spad{lquo(x, s)} returns the exact left quotient of \spad{x}
++ by \spad{s}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X lquo(m1,x)
rquo : (%, S) -> Union(%, "failed")
++ \spad{rquo(x, s)} returns the exact right quotient
++ of \spad{x} by \spad{s}.
++
++X m1:=(x*y)$OFMONOID(Symbol)
++X div(m1,y)
divide : (%, %) -> RESULT
++ \spad{divide(x,y)} returns the left and right exact quotients of
++ \spad{x} by \spad{y}, that is \spad{[l,r]} such that \spad{x = l*y*r}.
++ "failed" is returned iff \spad{x} is not of the form \spad{l * y * r}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X m2:=(x*y)$OFMONOID(Symbol)
++X divide(m1,m2)
overlap : (%, %) -> Record(lm: %, mm: %, rm: %)
++ \spad{overlap(x, y)} returns \spad{[l, m, r]} such that
++ \spad{x = l * m} and \spad{y = m * r} hold and such that
++ \spad{l} and \spad{r} have no overlap,
++ that is \spad{overlap(l, r) = [l, 1, r]}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X m2:=(x*y)$OFMONOID(Symbol)
++X overlap(m1,m2)
size : % -> NNI
++ \spad{size(x)} returns the number of monomials in \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X size(m1,2)
nthExpon : (%, Integer) -> NNI
++ \spad{nthExpon(x, n)} returns the exponent of the
++ \spad{n-th} monomial of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X nthExpon(m1,2)
nthFactor : (%, Integer) -> S
++ \spad{nthFactor(x, n)} returns the factor of the \spad{n-th}
++ monomial of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X nthFactor(m1,2)
factors : % -> List REC
++ \spad{factors(a1\^e1,...,an\^en)} returns
++ \spad{[[a1, e1],...,[an, en]]}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X factors m1
length : % -> NNI
++ \spad{length(x)} returns the length of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X length m1
varList : % -> List S
++ \spad{varList(x)} returns the list of variables of \spad{x}.
++
++X m1:=(x*y*y*z)$OFMONOID(Symbol)
++X varList m1
CODE ==> FreeMonoid(S) add
Rep := ListMonoidOps(S, NNI, 1)
-- definitions
lquo(w:%, l:S) ==
x: List REC := listOfMonoms(w)$Rep
null x => "failed"
fx: REC := first x
fx.gen ^= l => "failed"
fx.exp = 1 => makeMulti rest(x)
makeMulti [[fx.gen, (fx.exp - 1)::NNI ]$REC, :rest x]
rquo(w:%, l:S) ==
u:% := reverse w
(r := lquo (u,l)) case "failed" => "failed"
reverse_! (r::%)
divide(left:%,right:%) ==
a:=lquo(left,right)
b:=rquo(left,right)
[a,b]
length x == reduce("+" ,[f.exp for f in listOfMonoms x], 0)
varList x ==
le: List S := [t.gen for t in listOfMonoms x]
sort_! removeDuplicates(le)
first w ==
x: List REC := listOfMonoms w
null x => error "empty word !!!"
x.first.gen
rest w ==
x: List REC := listOfMonoms w
null x => error "empty word !!!"
fx: REC := first x
fx.exp = 1 => makeMulti rest x
makeMulti [[fx.gen , (fx.exp - 1)::NNI ]$REC , :rest x]
lexico(a,b) == -- ordre lexicographique
la := listOfMonoms a
lb := listOfMonoms b
while (not null la) and (not null lb) repeat
la.first.gen > lb.first.gen => return false
la.first.gen < lb.first.gen => return true
if la.first.exp = lb.first.exp then
la:=rest la
lb:=rest lb
else if la.first.exp > lb.first.exp then
la:=concat([la.first.gen,
(la.first.exp - lb.first.exp)::NNI], rest lb)
lb:=rest lb
else
lb:=concat([lb.first.gen,
(lb.first.exp-la.first.exp)::NNI], rest la)
la:=rest la
empty? la and not empty? lb
a < b == -- ordre lexicographique par longueur
la:NNI := length a; lb:NNI := length b
la = lb => lexico(a,b)
la < lb
mirror x == reverse(x)$Rep
|