8.29 coeff on a generic polynomial (18.11.02)

8.29.1 Charles James Leonardo Quarra Cappiello
8.29.2 Robert Israel (19.11.02)
8.29.3 Edwin Clark (19.11.02)
8.29.4 Dr Francis J. Wright (20.11.02))

8.29.1 Charles James Leonardo Quarra Cappiello

A definite polynomial like

 > p: x -> a*x^2 + b*x + c;
 
can be accessed with coeff like
 > coeff( p(z), z, 0 ); 
                          c
 
But, if p is defined like
 >p:x->sum( a[i]*x^i , I=0..n );
 
this still is considered a polynom object
 > type ( p, polynom); 
                         true
 
But, coeff doesnt have the desired effect:
 > coeff( p(z) , z, 0); 
    Error, unable to compute coeff
 

8.29.2 Robert Israel (19.11.02)

Charles James Leonardo Quarra Cappiello wrote:

> p:x->sum( a[i]*x^i , I=0..n )

I assume you mean := and i here, not : and I.

Yes, p is a "polynom", as is any other name, but p(z) is not:

> type(p(z), polynom); 
                         false
 
Of course, p(z) is _not_ a polynomial, it is an unevaluated summation (assuming n has not been assigned a value).

But, coeff doesnt have the desired effect: ...

Not too surprising, since coeff is designed for polynomials rather than unevaluated series.

Actually, it’s not quite clear what you should want as the result of coeff for this example, if Maple doesn’t know whether n >= 0.

A simple work-around in this particular case is to evaluate p(z) with a definite value of n (>= 0). So:

> coeff(eval(p(z),n=0),z,0); 
                                 a[0]
 
But doing it in general (maybe for a sum that’s not in powers of z, but of powers of z-c, or something more general) would not be so simple.

8.29.3 Edwin Clark (19.11.02)

You might do this:

> p:=(x,n)->sum('a[i]*x^i','i'=0..n): 
> coeff(p(z,0),z,0); 
                                 a[0] 
 
> coeff(p(z,1),z,1); 
                                 a[1] 
 
> coeff(p(z,2),z,2); 
                                 a[2]
 

8.29.4 Dr Francis J. Wright (20.11.02))

Let me define p as follows (which I assume is what you intended):

p := x -> sum( a[i]*x^i , i=0..n );
 

It is true that p is of type polynom, because a variable to which a procedure (or table) has been assigned evaluates to itself, so p is (trivially) a polynomial in p of degree 1.

However, the test you should have made is this:

type(p(x), polynom); 
                                false
 

This is because p(x) is a symbolic sum and not a polynomial.

But, coeff doesnt have the desired effect: ...

I don’t know of any straightforward way to extract polynomial terms from an arbitrary symbolic sum of polynomial terms, although for this simple example there are trivial tricks one could use, e.g. this extracts the constant term, which appears to be what you wanted:

eval(op(1,p(x)), i=0); 
                                 a[0]
 
The general problem is an example of manipulating what one might call "indefinite objects", which seems to be something that CA systems are currently not very good at. I’m working on it.