/usr/share/axiom-20170501/src/algebra/UNIFACT.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 | )abbrev package UNIFACT UnivariateFactorize
++ Author: Patrizia Gianni
++ Date Created: ???
++ Date Last Updated: December 1993
++ Description:
++ Package for the factorization of univariate polynomials with integer
++ coefficients. The factorization is done by "lifting" (HENSEL) the
++ factorization over a finite field.
UnivariateFactorize(ZP) : SIG == CODE where
Z ==> Integer
ZP : UnivariatePolynomialCategory Z
PI ==> PositiveInteger
NNI ==> NonNegativeInteger
SUPZ ==> SparseUnivariatePolynomial Z
FR ==> Factored ZP
fUnion ==> Union("nil", "sqfr", "irred", "prime")
FFE ==> Record(flg:fUnion, fctr:ZP, xpnt:Z)
ParFact ==> Record(irr: ZP,pow: Z)
FinalFact ==> Record(contp: Z,factors:List(ParFact))
SIG ==> with
factor : ZP -> FR
++ factor(m) returns the factorization of m
factorSquareFree : ZP -> FR
++ factorSquareFree(m) returns the factorization of m square free
++ polynomial
henselFact : (ZP,Boolean) -> FinalFact
++ henselFact(m,flag) returns the factorization of m,
++ FinalFact is a Record s.t. FinalFact.contp=content m,
++ FinalFact.factors=List of irreducible factors
++ of m with exponent , if flag =true the polynomial is
++ assumed square free.
CODE ==> add
--- local functions ---
henselfact : ZP -> List(ZP)
quadratic : ZP -> List(ZP)
remp : (Z, PI) -> Z
negShiftz : (Z, PI) -> Z
negShiftp : (ZP,PI) -> ZP
bound : ZP -> PI
choose : ZP -> FirstStep
eisenstein : ZP -> Boolean
isPowerOf2 : Z -> Boolean
subMinusX : SUPZ -> ZP
sqroot : Z -> Z
--- declarations ---
CYC ==> CyclotomicPolynomialPackage()
DDRecord ==> Record(factor: ZP,degree: Z)
DDList ==> List DDRecord
FirstStep ==> Record(prime:PI,factors:DDList)
ContPrim ==> Record(cont: Z,prim: ZP)
import GeneralHenselPackage(Z,ZP)
import ModularDistinctDegreeFactorizer ZP
factor(m: ZP) ==
flist := henselFact(m,false)
ctp:=unitNormal flist.contp
makeFR((ctp.unit)::ZP,cons(["nil",ctp.canonical::ZP,1$Z]$FFE,
[["prime",u.irr,u.pow]$FFE for u in flist.factors]))
factorSquareFree(m: ZP) ==
flist := henselFact(m,true)
ctp:=unitNormal flist.contp
makeFR((ctp.unit)::ZP,cons(["nil",ctp.canonical::ZP,1$Z]$FFE,
[["prime",u.irr,u.pow]$FFE for u in flist.factors]))
-- Integer square root: returns 0 if t is non-positive
sqroot(t: Z): Z ==
t <= 0 => 0
s:Integer:=t::Integer
s:=approxSqrt(s)$IntegerRoots(Integer)
t:=s::Z
t
-- Eisenstein criterion: returns true if polynomial is
-- irreducible. Result of false in inconclusive.
eisenstein(m : ZP): Boolean ==
-- calculate the content of the terms after the first
c := content reductum m
c = 0 => false
c = 1 => false
-- factor the content
-- if there is a prime in the factorization that does not divide
-- the leading term and appears to multiplicity 1, and the square
-- of this does not divide the last coef, return true.
-- Otherwise reurn false.
lead := leadingCoefficient m
trail := lead
m := reductum m
while m ^= 0 repeat
trail := leadingCoefficient m
m:= reductum m
fc := factor(c) :: Factored(Z)
for r in factors fc repeat
if (r.exponent = 1) and (0 ^= (lead rem r.factor)) and
(0 ^= (trail rem (r.factor ** 2))) then return true
false
negShiftz(n: Z,Modulus:PI): Z ==
if n < 0 then n := n+Modulus
n > (Modulus quo 2) => n-Modulus
n
negShiftp(pp: ZP,Modulus:PI): ZP ==
map(x +-> negShiftz(x,Modulus),pp)
-- Choose the bound for the coefficients of factors
bound(m: ZP):PI ==
nm,nmq2,lcm,bin0,bin1:NNI
cbound,j : PI
k:NNI
lcm := abs(leadingCoefficient m)::NNI
nm := (degree m)::NNI
nmq2:NNI := nm quo 2
norm: Z := sqroot(+/[coefficient(m,k)**2 for k in 0..nm])
if nmq2^=1 then nm := (nmq2-1):NNI
else nm := nmq2
bin0 := nm
cbound := (bin0*norm+lcm)::PI
for i in 2..(nm-1)::NNI repeat
bin1 := bin0
bin0 := (bin0*(nm+1-i):NNI) quo i
j := (bin0*norm+bin1*lcm)::PI
if cbound<j then cbound := j
(2*cbound*lcm)::PI -- adjusted by lcm to prepare for exquo in ghensel
remp(t: Z,q:PI): Z == ((t := t rem q)<0 => t+q ;t)
numFactors(ddlist:DDList): Z ==
ans: Z := 0
for dd in ddlist repeat
(d := degree(dd.factor)) = 0 => nil
ans := ans + ((d pretend Z) exquo dd.degree):: Z
ans
-- select the prime,try up to 4 primes,
-- choose the one yielding the fewest factors, but stopping if
-- fewer than 9 factors
choose(m: ZP):FirstStep ==
qSave:PI := 1
ddSave:DDList := []
numberOfFactors: Z := 0
lcm := leadingCoefficient m
k: Z := 1
ddRep := 5
disc:ZP:=0
q:PI:=2
while k<ddRep repeat
-- q must be a new prime number at each iteration
q:=nextPrime(q)$IntegerPrimesPackage(Z) pretend PI
(rr:=lcm rem q) = 0$Z => "next prime"
disc:=gcd(m,differentiate m,q)
(degree disc)^=0 => "next prime"
k := k+1
newdd := ddFact(m,q)
((n := numFactors(newdd)) < 9) =>
ddSave := newdd
qSave := q
k := 5
(numberOfFactors = 0) or (n < numberOfFactors) =>
ddSave := newdd
qSave := q
numberOfFactors := n
[qSave,ddSave]$FirstStep
-- Find the factors of m,primitive, square-free, with lc positive
-- and mindeg m = 0
henselfact1(m: ZP):List(ZP) ==
zero? degree m =>
(m = 1) => []
[m]
selected := choose(m)
(numFactors(selected.factors) = 1$Z) => [m]
q := selected.prime
fl := separateFactors(selected.factors,q)
--choose the bound
cbound := bound(m)
completeHensel(m,fl,q,cbound)
-- check for possible degree reduction
-- could use polynomial decomposition ?
henselfact(m: ZP):List ZP ==
deggcd:=degree m
mm:= m
while not zero? mm _
repeat (deggcd:=gcd(deggcd, degree mm); mm:=reductum mm)
deggcd>1 and deggcd<degree m =>
faclist := henselfact1(divideExponents(m, deggcd)::ZP)
"append"/[henselfact1 multiplyExponents(mm, deggcd) for mm in faclist]
henselfact1 m
quadratic(m: ZP):List(ZP) ==
d,d2: Z
d := coefficient(m,1)**2-4*coefficient(m,0)*coefficient(m,2)
d2 := sqroot(d)
(d-d2**2)^=0 => [m]
alpha: Z := coefficient(m,1)+d2
beta: Z := 2*coefficient(m,2)
d := gcd(alpha,beta)
if d ^=1 then
alpha := alpha quo d
beta := beta quo d
m0: ZP := monomial(beta,1)+monomial(alpha,0)
cons(m0,[(m exquo m0):: ZP])
isPowerOf2(n : Z): Boolean ==
n = 1 => true
qr : Record(quotient: Z, remainder: Z) := divide(n,2)
qr.remainder = 1 => false
isPowerOf2 qr.quotient
subMinusX(supPol : SUPZ): ZP ==
minusX : SUPZ := monomial(-1,1)$SUPZ
(elt(supPol,minusX)$SUPZ) : ZP
-- Factorize the polynomial m, test=true if m is known to be
-- square-free, false otherwise.
-- FinalFact.contp=content m, FinalFact.factors=List of irreducible
-- factors with exponent .
henselFact(m: ZP,test:Boolean):FinalFact ==
factorlist : List(ParFact) := []
c : Z
-- make m primitive
c := content m
m := (m exquo c)::ZP
-- make the lc m positive
if leadingCoefficient m < 0 then
c := -c
m := -m
-- is x**d factor of m?
if (d := minimumDegree m) >0 then
m := (monicDivide(m,monomial(1,d))).quotient
factorlist := [[monomial(1,1),d]$ParFact]
d := degree m
-- is m constant?
d=0 => [c,factorlist]$FinalFact
-- is m linear?
d=1 => [c,cons([m,1]$ParFact,factorlist)]$FinalFact
-- does m satisfy Eisenstein's criterion?
eisenstein m => [c,cons([m,1]$ParFact,factorlist)]$FinalFact
lcPol : ZP := leadingCoefficient(m) :: ZP
-- is m cyclotomic (x**n - 1)?
-lcPol = reductum(m) => -- if true, both will = 1
for fac in
(cyclotomicDecomposition(degree m)$CYC : List ZP) repeat
factorlist := cons([fac,1]$ParFact,factorlist)
[c,factorlist]$FinalFact
-- is m odd cyclotomic (x**(2*n+1) + 1)?
odd?(d) and (lcPol = reductum(m)) =>
for sfac in cyclotomicDecomposition(degree m)$CYC repeat
fac:=subMinusX sfac
if leadingCoefficient fac < 0 then fac := -fac
factorlist := cons([fac,1]$ParFact,factorlist)
[c,factorlist]$FinalFact
-- is the poly of the form x**n + 1 with n a power of 2?
-- if so, then irreducible
isPowerOf2(d) and (lcPol = reductum(m)) =>
factorlist := cons([m,1]$ParFact,factorlist)
[c,factorlist]$FinalFact
-- is m quadratic?
d=2 =>
lfq:List(ZP) := quadratic m
#lfq=1 => [c,cons([lfq.first,1]$ParFact,factorlist)]$FinalFact
(lf0,lf1) := (lfq.first,second lfq)
if lf0=lf1 then factorlist := cons([lf0,2]$ParFact,factorlist)
else factorlist := append([[v,1]$ParFact for v in lfq],factorlist)
[c,factorlist]$FinalFact
-- m is square-free
test =>
fln := henselfact(m)
[c,append(factorlist,[[pf,1]$ParFact for pf in fln])]$FinalFact
-- find the square-free decomposition of m
irrFact := squareFree(m)
llf := factors irrFact
-- factorize the square-free primitive terms
for l1 in llf repeat
d1 := l1.exponent
pol := l1.factor
degree pol=1 => factorlist := cons([pol,d1]$ParFact,factorlist)
degree pol=2 =>
fln := quadratic(pol)
factorlist := append([[pf,d1]$ParFact for pf in fln],factorlist)
fln := henselfact(pol)
factorlist := append([[pf,d1]$ParFact for pf in fln],factorlist)
[c,factorlist]$FinalFact
|