login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit

 Submitted by : (unknown) at: 2007-11-17T22:28:35-08:00 (11 years ago) Name : Axiom Version : default friCAS-20090114 Axiom-20050901 OpenAxiom-20091012 OpenAxiom-20110220 OpenAxiom-Release-141 Category : Axiom Aldor Interface Axiom Compiler Axiom Library Axiom Interpreter Axiom Documentation Axiom User Interface building Axiom from source lisp system MathAction Doyen CD Reduce Axiom on Windows Axiom on Linux Severity : critical serious normal minor wishlist Status : open closed rejected not reproducible fix proposed fixed somewhere duplicate need more info Optional subject :   Optional comment :

I must type the variable if I want the right result.

With theses types there is no problem :

axiom
coefficient (numer (12 * (sin x)^3 * z), (sin x)::Kernel Expression Integer, 3) (1)
Type: SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer)))

But without type I get 0 :

axiom
coefficient (numer (12 * (sin x)^3 * z), sin z, 3)
There are 4 exposed and 0 unexposed library operations named coefficient having 3 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op coefficient to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named coefficient with argument type(s) SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer))) Expression(Integer) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. A simpler example is: axiom coefficient (numer((sin z)^2), sin z::Kernel EXPR INT, 2) (2) Type: SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer))) axiom coefficient (numer((sin z)^2), sin z, 2) There are 4 exposed and 0 unexposed library operations named coefficient having 3 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op coefficient to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named coefficient with argument type(s) SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer))) Expression(Integer) PositiveInteger Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

I modified POLYCAT as follows:

coefficient(p,v,n) ==
output(hconcat(["POLYCAT:", p::OutputForm, v::OutputForm, n::OutputForm]))$OutputPackage output(hconcat(["POLYCAT:", univariate(p,v)::OutputForm]))$OutputPackage
coefficient(univariate(p,v),n)

)abbrev category POLYCAT PolynomialCategory
++ Author:
++ Date Created:
++ Date Last Updated:
++ Basic Functions: Ring, monomial, coefficient, differentiate, eval
++ Related Constructors: Polynomial, DistributedMultivariatePolynomial
++ Also See: UnivariatePolynomialCategory
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++ The category for general multi-variate polynomials over a ring
++ R, in variables from VarSet, with exponents from the
-- 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 == -- zero? p => empty() -- concat(leadingMonomial p, monomials reductum p) -- replaced by sequential version for efficiency, by WMSIT, 7/30/90 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] -- one?(r := leadingCoefficient p) => ((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,v,n) == output(hconcat(["POLYCAT:", p::OutputForm, v::OutputForm, n::OutputForm]))$OutputPackage output(hconcat(["POLYCAT:", univariate(p,v)::OutputForm]))$OutputPackage 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, i.e. 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 == unitNormal((p exquo content p) ::%).canonical primitivePart(p,v) == 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) spad Compiling FriCAS source code from file /var/zope2/var/LatexWiki/5427536097468235958-25px004.spad using old system compiler. POLYCAT abbreviates category PolynomialCategory ------------------------------------------------------------------------ initializing NRLIB POLYCAT for PolynomialCategory compiling into NRLIB POLYCAT ;;; *** |PolynomialCategory| REDEFINED Time: 0.13 SEC. POLYCAT- abbreviates domain PolynomialCategory& ------------------------------------------------------------------------ initializing NRLIB POLYCAT- for PolynomialCategory& compiling into NRLIB POLYCAT- compiling exported eval : (S,List Equation S) -> S ;;; *** |POLYCAT-;eval;SLS;1| REDEFINED Time: 0.52 SEC. compiling exported monomials : S -> List S ****** comp fails at level 3 with expression: ****** error in function monomials (SEQ (LET |ml| (|elt| (|List| S) |empty|)) (REPEAT (WHILE | << | (^= |p| 0) | >> |) (SEQ (LET |ml| (|concat| (|leadingMonomial| |p|) |ml|)) (|exit| 1 (LET |p| (|reductum| |p|))))) (|exit| 1 (|reverse| |ml|))) ****** level 3 ******$x:= (^= p (Zero)) $m:= (Boolean)$f:= ((((|ml| #) (|p| # #) (* #) (+ #) ...)))
>> Apparent user error: WHILE operand: (^= p (Zero)) is not Boolean valued

and obtained the following output:

axiom
coefficient(numer(sin x)^2, (sin x)::Kernel EXPR INT, 2) (3)
Type: SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer)))
axiom
coefficient(numer(sin x)^2, (sin x), 2)
There are 4 exposed and 0 unexposed library operations named coefficient having 3 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op coefficient to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named coefficient with argument type(s) SparseMultivariatePolynomial(Integer,Kernel(Expression(Integer))) Expression(Integer) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "\$" to specify which version of the function you need.

Note also, that the result types are different.

Status: open => not reproducible

 Subject: (replying)   Be Bold !! ( 15 subscribers )