The best way to work with variables b_i and x_i as you want
is to define multivariate polynomial rings Rb and Rx and inject
variables. Then any polynomial expression
in the b_i's and x_i's will be transformed as a polynomial
in the x_i's with coefficients in polynomials in the b_i's.
sage: Rb = PolynomialRing(ZZ,10,name='b')
sage: Rx = PolynomialRing(Rb,10,name='x')
sage: Rb.inject_variables()
Defining b0, b1, b2, b3, b4, b5, b6, b7, b8, b9
sage: Rx.inject_variables()
Defining x0, x1, x2, x3, x4, x5, x6, x7, x8, x9
sage: b1 * (x2 + x3) + b2 * (x3 + x8)
b1*x2 + (b1 + b2)*x3 + b2*x8
For your baby example, you could work in the symbolic ring and just ask coefficients,
sage: var('b c d e')
(b, c, d, e)
sage: a = b*d^2+c*e^2+e*(b+2*c*d)
sage: a
b*d^2 + c*e^2 + (2*c*d + b)*e
sage: a.coefficient(b)
d^2 + e
sage: a.coefficient(c)
2*d*e + e^2
or you could mix the two in the following way.
sage: S.<d,e> = PolynomialRing(QQ)
sage: R.<b,c> = PolynomialRing(S)
sage: R
Multivariate Polynomial Ring in b, c over Multivariate Polynomial Ring in d, e over Rational Field
sage: var('b c d e')
(b, c, d, e)
sage: a = b*d^2+c*e^2+e*(b+2*c*d)
sage: a
b*d^2 + c*e^2 + (2*c*d + b)*e
sage: R(a)
(d^2 + e)*b + (2*d*e + e^2)*c
But as a rule, it is best to avoid the symbolic ring altogether,
whenever possible. And the way your main question is formulated,
the most sensible approach is the polynomial rings one.
I'm not sure how to display the asterisks as literal asterisks...
To display code inline, put it in between backquotes. To display blocks of code, indent code by 4 spaces.
Thank you!
Try it: you can edit your question and make it look nicer!