Ask Your Question

Revision history [back]

Yes. I guess you have it as a symbolic expression, like this:

sage: var('p,x,D,w0')
sage: z = -(D*p-p*x - D + w0)/(p-1)

You can consider it as an element of the ring $\mathbb{Q}(p,D,w_0)[x]$, and then get the coefficients:

sage: A = PolynomialRing(QQ, names='p,D,w0').fraction_field()
sage: B = PolynomialRing(A, names='x')
sage: f = B(z); f
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: f.coefficients()
[(-p*D + D - w0)/(p - 1), p/(p - 1)]
sage: f.monomial_coefficient(B(x))
p/(p - 1)
sage: f.monomial_coefficient(B(1))
(-p*D + D - w0)/(p - 1)

Yes. I guess you have it as a symbolic expression, like this:

sage: var('p,x,D,w0')
sage: z = -(D*p-p*x - D + w0)/(p-1)

You can consider it as an element of the ring $\mathbb{Q}(p,D,w_0)[x]$, and then get the coefficients:

sage: A = PolynomialRing(QQ, names='p,D,w0').fraction_field()
sage: B = PolynomialRing(A, names='x')
sage: f = B(z); f
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: f.coefficients()
[(-p*D + D - w0)/(p - 1), p/(p - 1)]
sage: f.monomial_coefficient(B(x))
p/(p - 1)
sage: f.monomial_coefficient(B(1))
(-p*D + D - w0)/(p - 1)

You might want to convert these back to symbolic expressions again:

sage: SR(f.monomial_coefficient(B(x)))
p/(p - 1)
sage: SR(f.monomial_coefficient(B(1)))
-(D*p - D + w0)/(p - 1)

Yes. I guess you have it as a symbolic expression, like this:

sage: var('p,x,D,w0')
sage: z = -(D*p-p*x - D + w0)/(p-1)

You can consider it as an element of the ring $\mathbb{Q}(p,D,w_0)[x]$, and then get the coefficients:

sage: A = PolynomialRing(QQ, names='p,D,w0').fraction_field()
sage: B = PolynomialRing(A, names='x')
sage: f = B(z); f
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: f.coefficients()
[(-p*D + D - w0)/(p - 1), p/(p - 1)]
sage: f.monomial_coefficient(B(x))
p/(p - 1)
sage: f.monomial_coefficient(B(1))
(-p*D + D - w0)/(p - 1)

You might want to convert these back to symbolic expressions again:

sage: SR(f.monomial_coefficient(B(x)))
p/(p - 1)
sage: SR(f.monomial_coefficient(B(1)))
-(D*p - D + w0)/(p - 1)

Or avoid symbolic expressions entirely, by defining z as a polynomial directly:

sage: A.<p,D,w0> = PolynomialRing(QQ)
sage: B.<x> = PolynomialRing(A.fraction_field())
sage: z = -(D*p-p*x - D + w0)/(p-1); z
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: z.monomial_coefficient(x)
p/(p - 1)

etc.