1 | initial version |
For a symbolic approach you can use a substitution with a wildcard:
sage: var('p,a')
sage: f = (a*p+1)^2
sage: w0 = SR.wild()
sage: f.expand().subs({p^w0 : 0})
2*a*p + 1
This makes use of the fact that p^1
does not appear in an expanded symbolic expression.
Using a different ring would probably be more efficient, though.