/usr/share/axiom-20170501/src/algebra/POLYCAT.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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | )abbrev category POLYCAT PolynomialCategory
++ Description:
++ The category for general multi-variate polynomials over a ring
++ R, in variables from VarSet, with exponents from the
++ \spadtype{OrderedAbelianMonoidSup}.
PolynomialCategory(R,E,VarSet) : Category == SIG where
R : Ring
E : OrderedAbelianMonoidSup
VarSet : OrderedSet
PDR ==> PartialDifferentialRing(VarSet)
FAMR ==> FiniteAbelianMonoidRing(R, E)
EV ==> Evalable(%)
IEVR ==> InnerEvalable(VarSet, R)
IEVP ==> InnerEvalable(VarSet, %)
RT ==> RetractableTo(VarSet)
FLERO ==> FullyLinearlyExplicitRingOver(R)
SIG ==> Join(PDR,FAMR,EV,IEVR,IEVP,RT,FLERO) with
degree : (%,VarSet) -> NonNegativeInteger
++ degree(p,v) gives the degree of polynomial p with respect
++ to the variable v.
degree : (%,List(VarSet)) -> List(NonNegativeInteger)
++ degree(p,lv) gives the list of degrees of polynomial p
++ with respect to each of the variables in the list lv.
coefficient : (%,VarSet,NonNegativeInteger) -> %
++ coefficient(p,v,n) views the polynomial p as a univariate
++ polynomial in v and returns the coefficient of the \spad{v**n} term.
coefficient : (%,List VarSet,List NonNegativeInteger) -> %
++ coefficient(p, lv, ln) views the polynomial p as a polynomial
++ in the variables of lv and returns the coefficient of the term
++ \spad{lv**ln}, \spad{prod(lv_i ** ln_i)}.
monomials : % -> List %
++ monomials(p) returns the list of non-zero monomials of
++ polynomial p,
++ \spad{monomials(sum(a_(i) X^(i))) = [a_(1) X^(1),...,a_(n) X^(n)]}.
univariate : (%,VarSet) -> SparseUnivariatePolynomial(%)
++ univariate(p,v) converts the multivariate polynomial p
++ into a univariate polynomial in v, whose coefficients are still
++ multivariate polynomials (in all the other variables).
univariate : % -> SparseUnivariatePolynomial(R)
++ univariate(p) converts the multivariate polynomial p,
++ which should actually involve only one variable,
++ into a univariate polynomial
++ in that variable, whose coefficients are in the ground ring.
++ Error: if polynomial is genuinely multivariate
mainVariable : % -> Union(VarSet,"failed")
++ mainVariable(p) returns the biggest variable which actually
++ occurs in the polynomial p, or "failed" if no variables are
++ present.
++ fails precisely if polynomial satisfies ground?
minimumDegree : (%,VarSet) -> NonNegativeInteger
++ minimumDegree(p,v) gives the minimum degree of polynomial p
++ with respect to v, viewed a univariate polynomial in v
minimumDegree : (%,List(VarSet)) -> List(NonNegativeInteger)
++ minimumDegree(p, lv) gives the list of minimum degrees of the
++ polynomial p with respect to each of the variables in the list lv
monicDivide : (%,%,VarSet) -> Record(quotient:%,remainder:%)
++ monicDivide(a,b,v) divides the polynomial a by the polynomial b,
++ with each viewed as a univariate polynomial in v returning
++ both the quotient and remainder.
++ Error: if b is not monic with respect to v.
monomial : (%,VarSet,NonNegativeInteger) -> %
++ monomial(a,x,n) creates the monomial \spad{a*x**n} where \spad{a} is
++ a polynomial, x is a variable and n is a nonnegative integer.
monomial : (%,List VarSet,List NonNegativeInteger) -> %
++ monomial(a,[v1..vn],[e1..en]) returns \spad{a*prod(vi**ei)}.
multivariate : (SparseUnivariatePolynomial(R),VarSet) -> %
++ multivariate(sup,v) converts an anonymous univariable
++ polynomial sup to a polynomial in the variable v.
multivariate : (SparseUnivariatePolynomial(%),VarSet) -> %
++ multivariate(sup,v) converts an anonymous univariable
++ polynomial sup to a polynomial in the variable v.
isPlus : % -> Union(List %, "failed")
++ isPlus(p) returns \spad{[m1,...,mn]} if polynomial
++ \spad{p = m1 + ... + mn} and
++ \spad{n >= 2} and each mi is a nonzero monomial.
isTimes : % -> Union(List %, "failed")
++ isTimes(p) returns \spad{[a1,...,an]} if polynomial
++ \spad{p = a1 ... an} and \spad{n >= 2}, and, for each i,
++ ai is either a nontrivial constant in R or else of the
++ form \spad{x**e}, where \spad{e > 0} is an integer
++ and x in a member of VarSet.
isExpt : % -> Union(Record(var:VarSet, exponent:NonNegativeInteger),_
"failed")
++ isExpt(p) returns \spad{[x, n]} if polynomial p has the
++ form \spad{x**n} and \spad{n > 0}.
totalDegree : % -> NonNegativeInteger
++ totalDegree(p) returns the largest sum over all monomials
++ of all exponents of a monomial.
totalDegree : (%,List VarSet) -> NonNegativeInteger
++ totalDegree(p, lv) returns the maximum sum (over all monomials
++ of polynomial p) of the variables in the list lv.
variables : % -> List(VarSet)
++ variables(p) returns the list of those variables actually
++ appearing in the polynomial p.
primitiveMonomials : % -> List %
++ primitiveMonomials(p) gives the list of monomials of the
++ polynomial p with their coefficients removed. Note that
++ \spad{primitiveMonomials(sum(a_(i) X^(i))) = [X^(1),...,X^(n)]}.
if R has OrderedSet then OrderedSet
-- OrderedRing view removed to allow EXPR to define abs
--if R has OrderedRing then OrderedRing
if (R has ConvertibleTo InputForm) and
(VarSet has ConvertibleTo InputForm) then
ConvertibleTo InputForm
if (R has ConvertibleTo Pattern Integer) and
(VarSet has ConvertibleTo Pattern Integer) then
ConvertibleTo Pattern Integer
if (R has ConvertibleTo Pattern Float) and
(VarSet has ConvertibleTo Pattern Float) then
ConvertibleTo Pattern Float
if (R has PatternMatchable Integer) and
(VarSet has PatternMatchable Integer) then
PatternMatchable Integer
if (R has PatternMatchable Float) and
(VarSet has PatternMatchable Float) then
PatternMatchable Float
if R has CommutativeRing then
resultant : (%,%,VarSet) -> %
++ resultant(p,q,v) returns the resultant of the polynomials
++ p and q with respect to the variable v.
discriminant : (%,VarSet) -> %
++ discriminant(p,v) returns the disriminant of the polynomial p
++ with respect to the variable v.
if R has GcdDomain then
GcdDomain
content : (%,VarSet) -> %
++ content(p,v) is the gcd of the coefficients of the polynomial p
++ when p is viewed as a univariate polynomial with respect to the
++ variable v.
++ Thus, for polynomial 7*x**2*y + 14*x*y**2, the gcd of the
++ coefficients with respect to x is 7*y.
primitivePart : % -> %
++ primitivePart(p) returns the unitCanonical associate of the
++ polynomial p with its content divided out.
primitivePart : (%,VarSet) -> %
++ primitivePart(p,v) returns the unitCanonical associate of the
++ polynomial p with its content with respect to the variable v
++ divided out.
squareFree : % -> Factored %
++ squareFree(p) returns the square free factorization of the
++ polynomial p.
squareFreePart : % -> %
++ squareFreePart(p) returns product of all the irreducible factors
++ of polynomial p each taken with multiplicity one.
-- assertions
if R has canonicalUnitNormal then canonicalUnitNormal
++ we can choose a unique representative for each
++ associate class.
++ This normalization is chosen to be normalization of
++ leading coefficient (by default).
if R has PolynomialFactorizationExplicit then
PolynomialFactorizationExplicit
add
p:%
v:VarSet
ln:List NonNegativeInteger
lv:List VarSet
n:NonNegativeInteger
pp,qq:SparseUnivariatePolynomial %
eval(p:%, l:List Equation %) ==
empty? l => p
for e in l repeat
retractIfCan(lhs e)@Union(VarSet,"failed") case "failed" =>
error "cannot find a variable to evaluate"
lvar:=[retract(lhs e)@VarSet for e in l]
eval(p, lvar,[rhs e for e in l]$List(%))
monomials p ==
ml:= empty$List(%)
while p ^= 0 repeat
ml:=concat(leadingMonomial p, ml)
p:= reductum p
reverse ml
isPlus p ==
empty? rest(l := monomials p) => "failed"
l
isTimes p ==
empty?(lv := variables p) or not monomial? p => "failed"
l := [monomial(1, v, degree(p, v)) for v in lv]
((r := leadingCoefficient p) = 1) =>
empty? rest lv => "failed"
l
concat(r::%, l)
isExpt p ==
(u := mainVariable p) case "failed" => "failed"
p = monomial(1, u::VarSet, d := degree(p, u::VarSet)) =>
[u::VarSet, d]
"failed"
coefficient(p,v,n) == coefficient(univariate(p,v),n)
coefficient(p,lv,ln) ==
empty? lv =>
empty? ln => p
error "mismatched lists in coefficient"
empty? ln => error "mismatched lists in coefficient"
coefficient(coefficient(univariate(p,first lv),first ln),
rest lv,rest ln)
monomial(p,lv,ln) ==
empty? lv =>
empty? ln => p
error "mismatched lists in monomial"
empty? ln => error "mismatched lists in monomial"
monomial(monomial(p,first lv, first ln),rest lv, rest ln)
retract(p:%):VarSet ==
q := mainVariable(p)::VarSet
q::% = p => q
error "Polynomial is not a single variable"
retractIfCan(p:%):Union(VarSet, "failed") ==
((q := mainVariable p) case VarSet) and (q::VarSet::% = p) => q
"failed"
mkPrim(p:%):% == monomial(1,degree p)
primitiveMonomials p == [mkPrim q for q in monomials p]
totalDegree p ==
ground? p => 0
u := univariate(p, mainVariable(p)::VarSet)
d: NonNegativeInteger := 0
while u ^= 0 repeat
d := max(d, degree u + totalDegree leadingCoefficient u)
u := reductum u
d
totalDegree(p,lv) ==
ground? p => 0
u := univariate(p, v:=(mainVariable(p)::VarSet))
d: NonNegativeInteger := 0
w: NonNegativeInteger := 0
if member?(v, lv) then w:=1
while u ^= 0 repeat
d := max(d, w*(degree u) + totalDegree(leadingCoefficient u,lv))
u := reductum u
d
if R has CommutativeRing then
resultant(p1,p2,mvar) ==
resultant(univariate(p1,mvar),univariate(p2,mvar))
discriminant(p,var) ==
discriminant(univariate(p,var))
if R has IntegralDomain then
allMonoms(l:List %):List(%) ==
removeDuplicates_! concat [primitiveMonomials p for p in l]
P2R(p:%, b:List E, n:NonNegativeInteger):Vector(R) ==
w := new(n, 0)$Vector(R)
for i in minIndex w .. maxIndex w for bj in b repeat
qsetelt_!(w, i, coefficient(p, bj))
w
eq2R(l:List %, b:List E):Matrix(R) ==
matrix [[coefficient(p, bj) for p in l] for bj in b]
reducedSystem(m:Matrix %):Matrix(R) ==
l := listOfLists m
b := removeDuplicates_!
concat [allMonoms r for r in l]$List(List(%))
d := [degree bj for bj in b]
mm := eq2R(first l, d)
l := rest l
while not empty? l repeat
mm := vertConcat(mm, eq2R(first l, d))
l := rest l
mm
reducedSystem(m:Matrix %, v:Vector %):
Record(mat:Matrix R, vec:Vector R) ==
l := listOfLists m
r := entries v
b : List % := removeDuplicates_! concat(allMonoms r,
concat [allMonoms s for s in l]$List(List(%)))
d := [degree bj for bj in b]
n := #d
mm := eq2R(first l, d)
w := P2R(first r, d, n)
l := rest l
r := rest r
while not empty? l repeat
mm := vertConcat(mm, eq2R(first l, d))
w := concat(w, P2R(first r, d, n))
l := rest l
r := rest r
[mm, w]
if R has PolynomialFactorizationExplicit then
-- we might be in trouble if its actually only
-- a univariate polynomial category - have to remember to
-- over-ride these in UnivariatePolynomialCategory
PFBR ==>PolynomialFactorizationByRecursion(R,E,VarSet,%)
gcdPolynomial(pp,qq) ==
gcdPolynomial(pp,qq)$GeneralPolynomialGcdPackage(E,VarSet,R,%)
solveLinearPolynomialEquation(lpp,pp) ==
solveLinearPolynomialEquationByRecursion(lpp,pp)$PFBR
factorPolynomial(pp) ==
factorByRecursion(pp)$PFBR
factorSquareFreePolynomial(pp) ==
factorSquareFreeByRecursion(pp)$PFBR
factor p ==
v:Union(VarSet,"failed"):=mainVariable p
v case "failed" =>
ansR:=factor leadingCoefficient p
makeFR(unit(ansR)::%,
[[w.flg,w.fctr::%,w.xpnt] for w in factorList ansR])
up:SparseUnivariatePolynomial %:=univariate(p,v)
ansSUP:=factorByRecursion(up)$PFBR
makeFR(multivariate(unit(ansSUP),v),
[[ww.flg,multivariate(ww.fctr,v),ww.xpnt]
for ww in factorList ansSUP])
if R has CharacteristicNonZero then
mat: Matrix %
conditionP mat ==
ll:=listOfLists transpose mat --hence each list corresponds to a
--column, to one variable
llR:List List R := [ empty() for z in first ll]
monslist:List List % := empty()
ch:=characteristic()$%
for l in ll repeat
mons:= "setUnion"/[primitiveMonomials u for u in l]
redmons:List % :=[]
for m in mons repeat
vars:=variables m
degs:=degree(m,vars)
deg1:List NonNegativeInteger
deg1:=[ ((nd:=d:Integer exquo ch:Integer)
case "failed" => return "failed" ;
nd::Integer::NonNegativeInteger)
for d in degs ]
redmons:=[monomial(1,vars,deg1),:redmons]
llR:=[[ground coefficient(u,vars,degs),:v]_
for u in l for v in llR]
monslist:=[redmons,:monslist]
ans:=conditionP transpose matrix llR
ans case "failed" => "failed"
i:NonNegativeInteger:=0
[ +/[m*(ans.(i:=i+1))::% for m in mons ]
for mons in monslist]
if R has CharacteristicNonZero then
charthRootlv:(%,List VarSet,NonNegativeInteger) ->
Union(%,"failed")
charthRoot p ==
vars:= variables p
empty? vars =>
ans := charthRoot ground p
ans case "failed" => "failed"
ans::R::%
ch:=characteristic()$%
charthRootlv(p,vars,ch)
charthRootlv(p,vars,ch) ==
empty? vars =>
ans := charthRoot ground p
ans case "failed" => "failed"
ans::R::%
v:=first vars
vars:=rest vars
d:=degree(p,v)
ans:% := 0
while (d>0) repeat
(dd:=(d::Integer exquo ch::Integer)) case "failed" =>
return "failed"
cp:=coefficient(p,v,d)
p:=p-monomial(cp,v,d)
ansx:=charthRootlv(cp,vars,ch)
ansx case "failed" => return "failed"
d:=degree(p,v)
ans:=ans+monomial(ansx,v,dd::Integer::NonNegativeInteger)
ansx:=charthRootlv(p,vars,ch)
ansx case "failed" => return "failed"
return ans+ansx
monicDivide(p1,p2,mvar) ==
result:=monicDivide(univariate(p1,mvar),univariate(p2,mvar))
[multivariate(result.quotient,mvar),
multivariate(result.remainder,mvar)]
if R has GcdDomain then
if R has EuclideanDomain and R has CharacteristicZero then
squareFree p == squareFree(p)$MultivariateSquareFree(E,VarSet,R,%)
else
squareFree p == squareFree(p)$PolynomialSquareFree(VarSet,E,R,%)
squareFreePart p ==
unit(s := squareFree p) * */[f.factor for f in factors s]
content(p,v) == content univariate(p,v)
primitivePart p ==
zero? p => p
unitNormal((p exquo content p) ::%).canonical
primitivePart(p,v) ==
zero? p => p
unitNormal((p exquo content(p,v)) ::%).canonical
if R has OrderedSet then
p:% < q:% ==
(dp:= degree p) < (dq := degree q) => (leadingCoefficient q) > 0
dq < dp => (leadingCoefficient p) < 0
leadingCoefficient(p - q) < 0
if (R has PatternMatchable Integer) and
(VarSet has PatternMatchable Integer) then
patternMatch(p:%, pat:Pattern Integer,
l:PatternMatchResult(Integer, %)) ==
patternMatch(p, pat,
l)$PatternMatchPolynomialCategory(Integer,E,VarSet,R,%)
if (R has PatternMatchable Float) and
(VarSet has PatternMatchable Float) then
patternMatch(p:%, pat:Pattern Float,
l:PatternMatchResult(Float, %)) ==
patternMatch(p, pat,
l)$PatternMatchPolynomialCategory(Float,E,VarSet,R,%)
if (R has ConvertibleTo Pattern Integer) and
(VarSet has ConvertibleTo Pattern Integer) then
convert(x:%):Pattern(Integer) ==
map(convert, convert,
x)$PolynomialCategoryLifting(E,VarSet,R,%,Pattern Integer)
if (R has ConvertibleTo Pattern Float) and
(VarSet has ConvertibleTo Pattern Float) then
convert(x:%):Pattern(Float) ==
map(convert, convert,
x)$PolynomialCategoryLifting(E, VarSet, R, %, Pattern Float)
if (R has ConvertibleTo InputForm) and
(VarSet has ConvertibleTo InputForm) then
convert(p:%):InputForm ==
map(convert, convert,
p)$PolynomialCategoryLifting(E,VarSet,R,%,InputForm)
|