/usr/share/axiom-20170501/src/algebra/PACRAT.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 | )abbrev domain PACRAT PseudoAlgebraicClosureOfRationalNumber
++ Authors: Gaetan Hache
++ Date Created: feb 1997
++ Date Last Updated: May 2010 by Tim Daly
++ Description:
++ This domain implements dynamic extension using the simple notion of
++ tower extensions. A tower extension T of the ground field K is any
++ sequence of field extension (T : K_0, K_1, ..., K_i...,K_n) where K_0 = K
++ and for i =1,2,...,n, K_i is an extension of K_{i-1} of degree > 1 and
++ defined by an irreducible polynomial p(Z) in K_{i-1}.
++ Two towers (T_1: K_01, K_11,...,K_i1,...,K_n1) and
++ (T_2: K_02, K_12,...,K_i2,...,K_n2) are said to be related if T_1 <= T_2
++ (or T_1 >= T_2), that is if K_i1 = K_i2 for i=1,2,...,n1
++ (or i=1,2,...,n2). Any algebraic operations defined for several elements
++ are only defined if all of the concerned elements are comming from
++ a set of related tour extensions.
PseudoAlgebraicClosureOfRationalNumber() : SIG == CODE where
INT ==> Integer
K ==> Fraction Integer
NNI ==> NonNegativeInteger
SUP ==> SparseUnivariatePolynomial
BOOLEAN ==> Boolean
PI ==> PositiveInteger
FACTRN ==> FactorisationOverPseudoAlgebraicClosureOfRationalNumber
recRep ==> Record(recEl:SUP(%),_
recTower:SUP(%),_
recDeg:PI,_
recPrevTower:%,_
recName:Symbol)
SIG ==> PseudoAlgebraicClosureOfRationalNumberCategory with
fullOutput : % -> OutputForm
newElement : (SUP(%), SUP(%), PI, %, Symbol) -> %
CODE ==> add
Rep := Union(recRep,K)
-- signature of local function
replaceRecEl: (%,SUP(%)) -> %
down: % -> %
down(a:%) ==
a case K => a
aa:=(a pretend recRep)
elel := aa.recEl
^ground?(elel)$SUP(%) => a
gel:%:=ground(elel)
down(gel)
coerce(a:Integer):%== (a :: K)
n:INT * a:% ==
one?(n) => a
zero?(a) or zero?(n) => 0
(n < 0) => - ((-n)*a)
mm:PositiveInteger:=(n pretend PositiveInteger)
double(mm,a)$RepeatedDoubling(%)
replaceRecEl(a,el)==
a case K => a
aa:=copy a
aa.recEl := el
aa
-- local variable
localTower :% := 1$K
-- implemetation of exported function
lift(a) ==
a case K => monomial(a,0)
(a pretend recRep).recEl
lift(a,b)==
extDegree a > extDegree b => _
error "Cannot lift something at lower level !!!!!"
extDegree a < extDegree b => monomial(a,0)$SUP(%)
lift a
reduce(a)==
localTower case K =>
coefficient(a,0)
ar:= a rem (localTower pretend recRep).recTower
replaceRecEl(localTower,ar)
maxTower(la)==
--return an element from the list la which is in the largest
--extension of the ground field
--PRECONDITION: all elements in same tower, else no meaning?
m:="max"/[extDegree(a)$% for a in la]
first [b for b in la | extDegree(b)=m]
ground?(a)== a case K
vectorise(a,lev)==
da:=extDegree a
dlev:=extDegree lev
dlev < da => _
error "Cannot vectorise at a lower level than the element to vectorise"
lev case K => [a]
pa:SUP(%)
na:%
^(da = dlev) =>
pa:= monomial(a,0)$SUP(%)
na:= replaceRecEl(lev,pa)
vectorise(na,lev)$%
prevLev:=previousTower(lev)
a case K => error "At this point a is not suppose to be in K"
aEl:=(a pretend recRep).recEl
daEl:=degree definingPolynomial(a)$%
lv:=[vectorise(c,prevLev)$% for c in entries(vectorise(aEl,daEl)$SUP(%))]
concat lv
setTower!(a) ==
localTower:=a
void()
definingPolynomial == definingPolynomial(localTower)
a:% + b:% ==
(a case K) and (b case K) => a +$K b
extDegree(a) > extDegree(b) => b + a
res1:SUP(%)
res2:%
if extDegree(a) = extDegree(b) then
res1:= b.recEl +$SUP(%) a.recEl
res2:= replaceRecEl(b,res1)
else
res1:= b.recEl +$SUP(%) monomial(a,0)$SUP(%)
res2:= replaceRecEl(b,res1)
down(res2)
a:% * b:% ==
(a case K) and (b case K) => a *$K b
extDegree(a) > extDegree(b) => b * a
res1:SUP(%)
res2:%
if extDegree(a) = extDegree(b) then
res1:= b.recEl *$SUP(%) a.recEl rem b.recTower
res2:= replaceRecEl(b,res1)
else
res1:= b.recEl *$SUP(%) monomial(a,0)$SUP(%)
res2:= replaceRecEl(b,res1)
down(res2)
distinguishedRootsOf(polyZero,ee) ==
setTower!(ee)
zero?(polyZero) => error "to lazy to give you all the roots of 0 !!!"
factorf: Factored SUP % := factor(polyZero,ee)$FACTRN(%)
listFact:List SUP % := [pol.fctr for pol in factorList(factorf)]
listOfZeros:List(%):=empty()
for p in listFact repeat
root:=newElement(p, new(D::Symbol)$Symbol)
listOfZeros:List(%):=concat([ root ], listOfZeros)
listOfZeros
1 == 1$K
0 == 0$K
newElement(pol:SUP(%),subF:%,inName:Symbol): % ==
-- pol is an irreducible polynomial over the field extension
-- given by subF.
-- The output of this function is a root of pol.
dp:=degree pol
one?(dp) =>
listCoef:=coefficients(pol)
one?(#listCoef) => 0
- last(listCoef) / first(listCoef)
ground?(pol) => error "Cannot create a new element with a constant"
d:PI := (dp pretend PI) * extDegree(subF)
[monomial(1$%,1),pol,d,subF,inName] :: Rep
newElement(poll:SUP(%),inName:Symbol)==
newElement(poll,localTower,inName)
newElement(elPol:SUP(%),pol:SUP(%),d:PI,subF:%,inName:Symbol): % ==
[elPol, pol,d,subF,inName] :: Rep
--Field operations
inv(a)==
a case K => inv(a)$K
aRecEl:= (a pretend recRep).recEl
aDefPoly:= (a pretend recRep).recTower
aInv := extendedEuclidean( aRecEl , aDefPoly, 1 )
aInv case "failed" => error "PACOFF : division by zero"
-- On doit retourner un Record représentant l'inverse de a.
-- Ce Record est exactement le même que celui de a sauf
-- qu'il faut remplacer le polynôme du selecteur recEl
-- par le polynôme représentant l'inverse de a :
-- C'est ce que fait la fonction replaceRecEl.
replaceRecEl( a , aInv.coef1 )
a:% / b:% == a * inv(b)
a:K * b:%==
(a :: %) * b
b:% * a:K == a*b
a:% - b:% ==
a + (-b)
a:% * b:Fraction(Integer) ==
bn:=numer b
bd:=denom b
ebn:%:= bn * 1$%
ebd:%:= bd * 1$%
a * ebn * inv(ebd)
-a:% ==
a case K => -$K a
[-$SUP(%) (a pretend recRep).recEl,_
(a pretend recRep).recTower,_
(a pretend recRep).recDeg,_
(a pretend recRep).recPrevTower,_
(a pretend recRep).recName ]
bb:% = aa:% ==
b:=down bb
a:=down aa
^( extDegree(b) =$NNI extDegree(a) ) => false
(b case K) => ( (retract a)@K =$K (retract b)@K )
rda := a :: recRep
rdb := b :: recRep
not (rda.recTower =$SUP(%) rdb.recTower) => false
rdb.recEl =$SUP(%) rda.recEl
zero?(a:%) ==
da:=down a -- just to be sure !!!
^(da case K) => false
zero?(da)$K
one?(a:%) ==
da:= down a -- just to be sure !!!
^(da case K) => false
one?(da)$K
--Coerce Functions
coerce(a:K):% == a
retractIfCan(a:%):Union(Integer,"failed")==
a case K => retractIfCan(a)$K
"failed"
retractIfCan(a:%):Union(K,"failed")==
a case K => a
"failed"
coerce(a:%):OutputForm ==
a case K => ((retract a)@K) ::OutputForm
outputForm((a pretend recRep).recEl,_
((a pretend recRep).recName)::OutputForm) $SUP(%)
fullOutput(a:%):OutputForm==
a case K => ((retract a)@K) ::OutputForm
(a pretend recRep)::OutputForm
definingPolynomial(a:%): SUP % ==
a case K => monomial(1,1)$SUP(%)
(a pretend recRep).recTower
extDegree(a:%): PI ==
a case K => 1
(a pretend recRep).recDeg
previousTower(a:%):% ==
a case K => error "No previous extension for ground field element"
(a pretend recRep).recPrevTower
name(a:%):Symbol ==
a case K => error "No name for ground field element"
(a pretend recRep).recName
-- function related to the ground field
characteristic == characteristic()$K
|