Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In your code, conversion PR(s) does not map symbolic variables into polynomial ones. Instead, it creates a zero-degree polynomial, where the whole s is the free term. Also, it's a bad idea to give different variables the same name.

Here is an explicit conversion and follow-up substitution:

PR.<A1_, A3_> = R[]
s_ = sum(s.coefficient(A1^i * A3^j) * A1_^i * A3_^j for i in range(s.degree(A1)+1) for j in range(s.degree(A3)+1))
print( s_.subs({A1_:a1, A3_:a3}) )

In your code, conversion PR(s) does not map symbolic variables into polynomial ones. Instead, it creates a zero-degree polynomial, where the whole s is the free term. Also, it's a bad idea to give different variables the same name.

Here Still, it is an possible to force the conversion you want via intermediate conversion of s to a string:

print( PR(str(s)).subs({A1:a1, A3:a3}) )

Personally, I'd prefer a more straightforward and explicit conversion and follow-up substitution:substitution like this:

PR.<A1_, A3_> = R[]
s_ = sum(s.coefficient(A1^i * A3^j) * A1_^i * A3_^j for i in range(s.degree(A1)+1) for j in range(s.degree(A3)+1))
print( s_.subs({A1_:a1, A3_:a3}) )