The problem is that the return type of 'coefficient' when called with 'Symbol' is of type 'Polynomial Fraction Integer'.
Try it this way: -- test2.input --------------------------------- R ==> Fraction Integer listCoeffs: Polynomial(R) -> List(R) listCoeffs p == v : Symbol := variables(p).1 d : NonNegativeInteger := degree(p,v) [retract coefficient(p,v,n) for n in 0..d] ------------------------------------------------ On 11 August 2015 at 16:03, Paul Onions <[email protected]> wrote: > Hi All, > > Does anybody understand why the following fails? > > -- test2.spad ---------------------------------- > )abbrev package TEST2 Test2 > > Test2 : Exports == Implementation where > R ==> Fraction Integer > > Exports == with > listCoeffs: Polynomial(R) -> List(R) > > Implementation == add > listCoeffs p == > v : Symbol := variables(p).1 > d : NonNegativeInteger := degree(p,v) > [coefficient(p,v,n) for n in 0..d] > ------------------------------------------------ > > When I attempt to )compile it I get:- > > ****** comp fails at level 1 with expression: ****** > error in function listCoeffs > > ((|coefficient| |p| |v| |n|)) > ****** level 1 ****** > $x:= (coefficient p v n) > $m:= (Fraction (Integer)) > $f:= > ((((|n| # #) (|d| #) (|v| #) (|last| #) ...))) > > >> Apparent user error: > cannot compile (coefficient p v n) > > > and similarly, if I put the code in a .input file as:- > > -- test2.input --------------------------------- > R ==> Fraction Integer > > listCoeffs: Polynomial(R) -> List(R) > > listCoeffs p == > v : Symbol := variables(p).1 > d : NonNegativeInteger := degree(p,v) > [coefficient(p,v,n) for n in 0..d] > ------------------------------------------------ > > then )read works, but when I try to call the function I get:- > > (4) -> f : POLY(Fraction Integer) := 3*x^2 + 1 > > 2 > (4) 3x + 1 > Type: > Polynomial(Fraction(Integer)) > (5) -> listCoeffs f > There are 2 exposed and 2 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) > Polynomial(Fraction(Integer)) > Symbol > NonNegativeInteger > > Perhaps you should use "@" to indicate the required return type, > or "$" to specify which version of the function you need. > FriCAS will attempt to step through and interpret the code. > Compiling function listCoeffs with type Polynomial(Fraction(Integer) > ) -> List(Fraction(Integer)) > There are 2 exposed and 2 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) > Polynomial(Fraction(Integer)) > Symbol > NonNegativeInteger > > Perhaps you should use "@" to indicate the required return type, > or "$" to specify which version of the function you need. > > > but looking at the SPAD source code in multpoly.spad and polycat.spad I see > there is a default implementation of coefficient(p,v,n) in the > PolynomialCategory(R,E,VarSet) definition. What's more, if I evaluate each > line of the function manually at the REPL then things work. > > This is in FriCAS 1.2.6. Am I doing something stupid? > > Any pointers appreciated, > Paul > > -- > You received this message because you are subscribed to the Google Groups > "FriCAS - computer algebra system" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/fricas-devel. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
