/usr/share/axiom-20170501/src/algebra/XRPOLY.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 | )abbrev domain XRPOLY XRecursivePolynomial
++ Author: Michel Petitot petitot@lifl.fr
++ Date Created: 91
++ Date Last Updated: 7 Juillet 92
++ Description:
++ This type supports multivariate polynomials whose variables do not commute.
++ The representation is recursive. The coefficient ring may be
++ non-commutative. Coefficients and variables commute.
XRecursivePolynomial(VarSet,R) : SIG == CODE where
VarSet : OrderedSet
R : Ring
I ==> Integer
NNI ==> NonNegativeInteger
XDPOLY ==> XDistributedPolynomial(VarSet, R)
EX ==> OutputForm
WORD ==> OrderedFreeMonoid(VarSet)
TERM ==> Record(k:VarSet , c:%)
LTERMS ==> List(TERM)
REGPOLY==> FreeModule1(%, VarSet)
VPOLY ==> Record(c0:R, reg:REGPOLY)
SIG ==> XPolynomialsCat(VarSet,R) with
expand : % -> XDPOLY
++ \spad{expand(p)} returns \spad{p} in distributed form.
unexpand : XDPOLY -> %
++ \spad{unexpand(p)} returns \spad{p} in recursive form.
RemainderList : % -> LTERMS
++ \spad{RemainderList(p)} returns the regular part of \spad{p}
++ as a list of terms.
CODE ==> add
import(VPOLY)
-- representation
Rep := Union(R,VPOLY)
-- local functions
construct: LTERMS -> REGPOLY
simplifie: VPOLY -> %
lquo1: (LTERMS,LTERMS) -> % -- a ajouter
coef1: (LTERMS,LTERMS) -> R -- a ajouter
outForm: REGPOLY -> EX
--define
construct(lt) == lt pretend REGPOLY
p1:% = p2:% ==
p1 case R =>
p2 case R => p1 =$R p2
false
p2 case R => false
p1.c0 =$R p2.c0 and p1.reg =$REGPOLY p2.reg
monom(w, r) ==
r =0 => 0
r * w::%
rquo(p1:%, p2:%):% ==
p2 case R => p1 * p2::R
p1 case R => p1 * p2.c0
x:REGPOLY := construct [[t.k, a]$TERM for t in listOfTerms(p1.reg) _
| (a:= rquo(t.c,p2)) ^= 0$% ]$LTERMS
simplifie [coef(p1,p2) , x]$VPOLY
trunc(p,n) ==
n = 0 or (p case R) => (constant p)::%
n1: NNI := (n-1)::NNI
lt: LTERMS := [[t.k, r]$TERM for t in listOfTerms p.reg _
| (r := trunc(t.c, n1)) ^= 0]$LTERMS
x: REGPOLY := construct lt
simplifie [constant p, x]$VPOLY
unexpand p ==
constant? p => (constant p)::%
vl: List VarSet := sort((y,z) +-> y > z, varList p)
x : REGPOLY := _
construct [[v, unexpand r]$TERM for v in vl| (r:=lquo(p,v)) ^= 0]
[constant p, x]$VPOLY
if R has CommutativeRing then
sh(p:%, n:NNI):% ==
n = 0 => 1
p case R => (p::R)** n
n1: NNI := (n-1)::NNI
p1: % := n * sh(p, n1)
lt: LTERMS := [[t.k, sh(t.c, p1)]$TERM for t in listOfTerms p.reg]
[p.c0 ** n, construct lt]$VPOLY
sh(p1:%, p2:%) ==
p1 case R => p1::R * p2
p2 case R => p1 * p2::R
lt1:LTERMS := listOfTerms p1.reg ; lt2:LTERMS := listOfTerms p2.reg
x: REGPOLY := construct [[t.k,sh(t.c,p2)]$TERM for t in lt1]
y: REGPOLY := construct [[t.k,sh(p1,t.c)]$TERM for t in lt2]
[p1.c0*p2.c0,x + y]$VPOLY
RemainderList p ==
p case R => []
listOfTerms( p.reg)$REGPOLY
lquo(p1:%,p2:%):% ==
p2 case R => p1 * p2
p1 case R => p1 *$R p2.c0
p1 * p2.c0 +$% lquo1(listOfTerms p1.reg, listOfTerms p2.reg)
lquo1(x:LTERMS,y:LTERMS):% ==
null x => 0$%
null y => 0$%
x.first.k < y.first.k => lquo1(x,y.rest)
x.first.k = y.first.k =>
lquo(x.first.c,y.first.c) + lquo1(x.rest,y.rest)
return lquo1(x.rest,y)
coef(p1:%, p2:%):R ==
p1 case R => p1::R * constant p2
p2 case R => p1.c0 * p2::R
p1.c0 * p2.c0 +$R coef1(listOfTerms p1.reg, listOfTerms p2.reg)
coef1(x:LTERMS,y:LTERMS):R ==
null x => 0$R
null y => 0$R
x.first.k < y.first.k => coef1(x,y.rest)
x.first.k = y.first.k =>
coef(x.first.c,y.first.c) + coef1(x.rest,y.rest)
return coef1(x.rest,y)
--------------------------------------------------------------
outForm(p:REGPOLY): EX ==
le : List EX := [t.k::EX * t.c::EX for t in listOfTerms p]
reduce(_+, reverse_! le)$List(EX)
coerce(p:$): EX ==
p case R => (p::R)::EX
p.c0 = 0 => outForm p.reg
p.c0::EX + outForm p.reg
0 == 0$R::%
1 == 1$R::%
constant? p == p case R
constant p ==
p case R => p
p.c0
simplifie p ==
p.reg = 0$REGPOLY => (p.c0)::%
p
coerce (v:VarSet):% ==
[0$R,coerce(v)$REGPOLY]$VPOLY
coerce (r:R):% == r::%
coerce (n:Integer) == n::R::%
coerce (w:WORD) ==
w = 1 => 1$R
(first w) * coerce(rest w)
expand p ==
p case R => p::R::XDPOLY
lt:LTERMS := listOfTerms(p.reg)
ep:XDPOLY := (p.c0)::XDPOLY
for t in lt repeat
ep:= ep + t.k * expand(t.c)
ep
- p:% ==
p case R => -$R p
[- p.c0, - p.reg]$VPOLY
p1 + p2 ==
p1 case R and p2 case R => p1 +$R p2
p1 case R => [p1 + p2.c0 , p2.reg]$VPOLY
p2 case R => [p2 + p1.c0 , p1.reg]$VPOLY
simplifie [p1.c0 + p2.c0 , p1.reg +$REGPOLY p2.reg]$VPOLY
p1 - p2 ==
p1 case R and p2 case R => p1 -$R p2
p1 case R => [p1 - p2.c0 , -p2.reg]$VPOLY
p2 case R => [p1.c0 - p2 , p1.reg]$VPOLY
simplifie [p1.c0 - p2.c0 , p1.reg -$REGPOLY p2.reg]$VPOLY
n:Integer * p:% ==
n=0 => 0$%
p case R => n *$R p
-- [ n*p.c0,n*p.reg]$VPOLY
simplifie [ n*p.c0,n*p.reg]$VPOLY
r:R * p:% ==
r=0 => 0$%
p case R => r *$R p
-- [ r*p.c0,r*p.reg]$VPOLY
simplifie [ r*p.c0,r*p.reg]$VPOLY
p:% * r:R ==
r=0 => 0$%
p case R => p *$R r
-- [ p.c0 * r,p.reg * r]$VPOLY
simplifie [ r*p.c0,r*p.reg]$VPOLY
v:VarSet * p:% ==
p = 0 => 0$%
[0$R, v *$REGPOLY p]$VPOLY
p1:% * p2:% ==
p1 case R => p1::R * p2
p2 case R => p1 * p2::R
x:REGPOLY := p1.reg *$REGPOLY p2
y:REGPOLY := (p1.c0)::% *$REGPOLY p2.reg -- maladroit:(p1.c0)::% !!
-- [ p1.c0 * p2.c0 , x+y ]$VPOLY
simplifie [ p1.c0 * p2.c0 , x+y ]$VPOLY
lquo(p:%, v:VarSet):% ==
p case R => 0
coefficient(p.reg,v)$REGPOLY
lquo(p:%, w:WORD):% ==
w = 1$WORD => p
lquo(lquo(p,first w),rest w)
rquo(p:%, v:VarSet):% ==
p case R => 0
x:REGPOLY := construct [[t.k, a]$TERM for t in listOfTerms(p.reg)
| (a:= rquo(t.c,v)) ^= 0 ]
simplifie [constant(coefficient(p.reg,v)) , x]$VPOLY
rquo(p:%, w:WORD):% ==
w = 1$WORD => p
rquo(rquo(p,rest w),first w)
coef(p:%, w:WORD):R ==
constant lquo(p,w)
quasiRegular? p ==
p case R => p = 0$R
p.c0 = 0$R
quasiRegular p ==
p case R => 0$%
[0$R,p.reg]$VPOLY
characteristic == characteristic()$R
recip p ==
p case R => recip(p::R)
"failed"
mindeg p ==
p case R =>
p = 0 => error "XRPOLY.mindeg: polynome nul !!"
1$WORD
p.c0 ^= 0 => 1$WORD
"min"/[(t.k) *$WORD mindeg(t.c) for t in listOfTerms p.reg]
maxdeg p ==
p case R =>
p = 0 => error "XRPOLY.maxdeg: polynome nul !!"
1$WORD
"max"/[(t.k) *$WORD maxdeg(t.c) for t in listOfTerms p.reg]
degree p ==
p = 0 => error "XRPOLY.degree: polynome nul !!"
length(maxdeg p)
map(fn,p) ==
p case R => fn(p::R)
x:REGPOLY := construct [[t.k,a]$TERM for t in listOfTerms p.reg
|(a := map(fn,t.c)) ^= 0$R]
simplifie [fn(p.c0),x]$VPOLY
varList p ==
p case R => []
lv: List VarSet:= "setUnion"/[varList(t.c) for t in listOfTerms p.reg]
lv:= setUnion(lv,[t.k for t in listOfTerms p.reg])
sort_!(lv)
|