Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

P.subs() should work only for the variables of the polynomials, ie. x and y. a is a not a polynomial variable but rather a parameter, which polynomial coefficients depend on. Hence, you need to perform symbolic substitution in each of the coefficients. For example, this will do the job:

R.<x, y> = SR[]
a = SR.var('a')
P = a*x
print( sum(map(lambda t: t[0].subs({a:1})*t[1], P)) )

P.subs() should work only for the variables of the polynomials, ie. x and y. a is a not a polynomial variable but rather a parameter, which polynomial coefficients depend on. Hence, you need to perform symbolic substitution in each of the coefficients. For example, this will do the job:

R.<x, y> = SR[]
a = SR.var('a')
P = a*x
print( sum(map(lambda t: t[0].subs({a:1})*t[1], P)) )

or (as suggested by @achrzesz):

print( P.map_coefficients(lambda t: t.subs({a:1})) )