# Revision history [back]

### Conversion from symbolic expression to polynomial stuck

I have a very long symbolic expression with six variables:

(E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, mu, n_I, n_P, xi_1, xi_3)

I call the expression AN. I want to convert it in a polynomial of two variables (mu and xi_3). I tried the following command:

AP = AN.polynomial(None,ring=SR['mu,xi_3'])


This works for simple expressions but the command remains stuck for the given expression. My aim is to get the monomials of the polynomial. mu and xi_3 are random variables and I want to compute the expectation of AN (E[AN]). Thus, I could substitute the expectations in the expression.

AN is a numerator, so it is not a fraction. Moreover, I also tried simply_rational but it did not help to convert.

Is there anyway to convert easily ?

### Conversion from symbolic expression to polynomial stuck

I have a very long symbolic expression with six variables:

(E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, mu, n_I, n_P, xi_1, xi_3)

I call the expression AN. I want to convert it in a polynomial of two variables (mu and xi_3). I tried the following command:

AP = AN.polynomial(None,ring=SR['mu,xi_3'])


This works for simple expressions but the command remains stuck for the given expression. My aim is to get the monomials of the polynomial. mu and xi_3 are random variables and I want to compute the expectation of AN (E[AN]). Thus, I could substitute the expectations in the expression.

AN is a numerator, so it is not a fraction. Moreover, I also tried simply_rational but it did not help to convert.

Is there anyway to convert easily ?

EDIT : $-E_{\xi_{3}} T^{2} m^{6} \mu + T^{2} m^{6} \mu^{2} + T^{2} m^{4} n_{I}^{2} \xi_{1}^{2} + {\left({\left(E_{\mu}^{2} - E_{\xi_{3}}^{2}\right)} T^{2} m^{4} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(4 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} - {\left(4 \, E_{\mu} T^{2} m^{4} + 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(T^{2} Z^{2} m^{6} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{5} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{4} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(T^{2} m^{4} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} + {\left(T^{2} Z^{2} m^{4} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{3} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{2} + {\left(T^{2} m^{2} + V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m\right)} \mu^{2} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m - {\left(2 \, T^{2} Z m^{3} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{2} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m\right)} \mu\right)} n_{I}^{2} - {\left(2 \, T^{2} Z m^{5} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu + 2 \, {\left(T^{2} Z^{2} m^{5} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{4} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left(T^{2} m^{3} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu^{2} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m - {\left(2 \, T^{2} Z m^{4} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}\right)} n_{P}^{2} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} m^{5} + {\left(E_{\xi_{3}} \mathit{ISP} T V_{\mu} + E_{\xi_{3}} \mathit{ISP} T V_{\xi_{3}}\right)} m^{4} + 2 \, {\left(2 \, T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu^{2} - 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4}\right)} \mu\right)} n_{I} + {\left(E_{\xi_{3}} T^{2} Z m^{6} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} m^{5} + {\left(E_{\xi_{3}} \mathit{ISP} T V_{\mu} + E_{\xi_{3}} \mathit{ISP} T V_{\xi_{3}}\right)} m^{4} + 2 \, {\left(T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu^{2} + {\left(2 \, E_{\mu} T^{2} Z m^{4} + {\left({\left(2 \, E_{\mu}^{2} - E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} E_{\xi_{3}} - 2 \, E_{\xi_{3}}^{2} + {\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} E_{\xi_{3}} - 2 \, E_{\xi_{3}}^{2} + {\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + 2 \, {\left(2 \, T^{2} m^{3} + 3 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu^{2} + 2 \, {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m - 2 \, {\left(2 \, T^{2} Z m^{4} + {\left({\left(3 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} + E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} + E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}^{2} - 2 \, {\left(T^{2} Z m^{6} + E_{\mu} T^{2} m^{5} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4}\right)} \mu + {\left({\left(2 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} Z m^{5} + {\left(2 \, {\left(E_{\mu}^{2} - E_{\xi_{3}}^{2}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + 2 \, {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + 2 \, {\left(3 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} - 2 \, {\left(3 \, T^{2} Z m^{5} + {\left({\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}\right)} n_{P} + {\left({\left(2 \, E_{\mu} T^{2} m^{4} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} - 2 \, {\left(2 \, T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} \mu\right)} n_{I}^{2} + {\left(E_{\xi_{3}} T^{2} m^{5} - 2 \, T^{2} m^{5} \mu\right)} n_{I} + {\left({\left(2 \, T^{2} Z m^{4} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} - 2 \, {\left(T^{2} m^{3} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(2 \, T^{2} Z m^{5} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} m^{4} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} - 2 \, {\left(T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} \mu\right)} n_{I}\right)} n_{P}\right)} \xi_{1} + {\left(E_{\xi_{3}} T^{2} m^{6} - T^{2} m^{6} \mu + {\left(2 \, {\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{4} + {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} - {\left(4 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(T^{2} Z m^{5} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(T^{2} Z m^{3} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{2} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m - {\left(T^{2} m^{2} + V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m\right)} \mu\right)} n_{I}^{2} - {\left(T^{2} m^{4} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu + 2 \, {\left(T^{2} Z m^{4} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m - {\left(T^{2} m^{3} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}\right)} n_{P}^{2} + {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4} - 2 \, {\left(2 \, T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu\right)} n_{I} + {\left(T^{2} Z m^{6} + {\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4} + {\left(2 \, T^{2} Z m^{4} + {\left({\left(3 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} + 4 \, E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} + 4 \, E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + 2 \, {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m - 2 \, {\left(2 \, T^{2} m^{3} + 3 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}^{2} - 2 \, {\left(T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu + {\left(3 \, T^{2} Z m^{5} + {\left(2 \, {\left(2 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + 2 \, {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} - 2 \, {\left(3 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}\right)} n_{P} + {\left(T^{2} m^{5} n_{I} + {\left(2 \, T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} n_{I}^{2} + {\left({\left(T^{2} m^{3} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2}\right)} n_{I}^{2} + {\left(T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} n_{I}\right)} n_{P}\right)} \xi_{1}\right)} \xi_{3}$

### Conversion from symbolic expression to polynomial stuck

I have a very long symbolic expression with six variables:

(E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, mu, n_I, n_P, xi_1, xi_3)

I call the expression AN. I want to convert it in a polynomial of two variables (mu and xi_3). I tried the following command:

AP = AN.polynomial(None,ring=SR['mu,xi_3'])


This works for simple expressions but the command remains stuck for the given expression. My aim is to get the monomials of the polynomial. mu and xi_3 are random variables and I want to compute the expectation of AN (E[AN]). Thus, I could substitute the expectations in the expression.

AN is a numerator, so it is not a fraction. Moreover, I also tried simply_rational but it did not help to convert.

Is there anyway to convert easily ?

EDIT : $-E_{\xi_{3}} T^{2} m^{6} \mu + T^{2} m^{6} \mu^{2} + T^{2} m^{4} n_{I}^{2} \xi_{1}^{2} + {\left({\left(E_{\mu}^{2} - E_{\xi_{3}}^{2}\right)} T^{2} m^{4} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(4 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} - {\left(4 \, E_{\mu} T^{2} m^{4} + 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(T^{2} Z^{2} m^{6} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{5} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{4} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(T^{2} m^{4} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} + {\left(T^{2} Z^{2} m^{4} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{3} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{2} + {\left(T^{2} m^{2} + V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m\right)} \mu^{2} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m - {\left(2 \, T^{2} Z m^{3} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{2} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m\right)} \mu\right)} n_{I}^{2} - {\left(2 \, T^{2} Z m^{5} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu + 2 \, {\left(T^{2} Z^{2} m^{5} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} Z m^{4} + {\left({\left(E_{\mu}^{2} - E_{\mu} E_{\xi_{3}}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left(T^{2} m^{3} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu^{2} + {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m - {\left(2 \, T^{2} Z m^{4} + {\left({\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + 2 \, {\left({\left(E_{\mu} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}\right)} n_{P}^{2} + {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} m^{5} + {\left(E_{\xi_{3}} \mathit{ISP} T V_{\mu} + E_{\xi_{3}} \mathit{ISP} T V_{\xi_{3}}\right)} m^{4} + 2 \, {\left(2 \, T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu^{2} - 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4}\right)} \mu\right)} n_{I} + {\left(E_{\xi_{3}} T^{2} Z m^{6} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} m^{5} + {\left(E_{\xi_{3}} \mathit{ISP} T V_{\mu} + E_{\xi_{3}} \mathit{ISP} T V_{\xi_{3}}\right)} m^{4} + 2 \, {\left(T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu^{2} + {\left(2 \, E_{\mu} T^{2} Z m^{4} + {\left({\left(2 \, E_{\mu}^{2} - E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} E_{\xi_{3}} - 2 \, E_{\xi_{3}}^{2} + {\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} E_{\xi_{3}} - 2 \, E_{\xi_{3}}^{2} + {\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + 2 \, {\left(2 \, T^{2} m^{3} + 3 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu^{2} + 2 \, {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m - 2 \, {\left(2 \, T^{2} Z m^{4} + {\left({\left(3 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} + E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} + E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}^{2} - 2 \, {\left(T^{2} Z m^{6} + E_{\mu} T^{2} m^{5} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4}\right)} \mu + {\left({\left(2 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} Z m^{5} + {\left(2 \, {\left(E_{\mu}^{2} - E_{\xi_{3}}^{2}\right)} T^{2} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} E_{\xi_{3}} - E_{\xi_{3}}^{2} + 2 \, E_{\mu} \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + 2 \, {\left({\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} \mathit{ISP} + \mathit{ISP}^{2}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + 2 \, {\left(3 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu^{2} - 2 \, {\left(3 \, T^{2} Z m^{5} + {\left({\left(4 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}\right)} n_{P} + {\left({\left(2 \, E_{\mu} T^{2} m^{4} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} - 2 \, {\left(2 \, T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} \mu\right)} n_{I}^{2} + {\left(E_{\xi_{3}} T^{2} m^{5} - 2 \, T^{2} m^{5} \mu\right)} n_{I} + {\left({\left(2 \, T^{2} Z m^{4} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} m^{3} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} - 2 \, {\left(T^{2} m^{3} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(2 \, T^{2} Z m^{5} + {\left(2 \, E_{\mu} - E_{\xi_{3}}\right)} T^{2} m^{4} + {\left({\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} - 2 \, {\left(T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} \mu\right)} n_{I}\right)} n_{P}\right)} \xi_{1} + {\left(E_{\xi_{3}} T^{2} m^{6} - T^{2} m^{6} \mu + {\left(2 \, {\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{4} + {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} - {\left(4 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}^{2} + {\left(T^{2} Z m^{5} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} + {\left(T^{2} Z m^{3} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{2} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m - {\left(T^{2} m^{2} + V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m\right)} \mu\right)} n_{I}^{2} - {\left(T^{2} m^{4} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu + 2 \, {\left(T^{2} Z m^{4} + {\left(E_{\mu} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m - {\left(T^{2} m^{3} + 2 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}\right)} n_{P}^{2} + {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4} - 2 \, {\left(2 \, T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu\right)} n_{I} + {\left(T^{2} Z m^{6} + {\left(E_{\mu} + E_{\xi_{3}}\right)} T^{2} m^{5} + {\left({\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\xi_{3}} + \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{4} + {\left(2 \, T^{2} Z m^{4} + {\left({\left(3 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{3} + {\left({\left(2 \, E_{\mu} + 4 \, E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\mu} + {\left(2 \, E_{\mu} + 4 \, E_{\xi_{3}} + 3 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{2} + 2 \, {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m - 2 \, {\left(2 \, T^{2} m^{3} + 3 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m\right)} \mu\right)} n_{I}^{2} - 2 \, {\left(T^{2} m^{5} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{4}\right)} \mu + {\left(3 \, T^{2} Z m^{5} + {\left(2 \, {\left(2 \, E_{\mu} + E_{\xi_{3}}\right)} T^{2} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} Z\right)} m^{4} + 2 \, {\left({\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\mu} + {\left(E_{\mu} + 3 \, E_{\xi_{3}} + 2 \, \mathit{ISP}\right)} T V_{\xi_{3}}\right)} m^{3} + 2 \, {\left({\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu}^{2} + 2 \, {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\mu} V_{\xi_{3}} + {\left(E_{\xi_{3}} + \mathit{ISP}\right)} V_{\xi_{3}}^{2}\right)} m^{2} - 2 \, {\left(3 \, T^{2} m^{4} + 4 \, {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3} + {\left(V_{\mu}^{2} + 2 \, V_{\mu} V_{\xi_{3}} + V_{\xi_{3}}^{2}\right)} m^{2}\right)} \mu\right)} n_{I}\right)} n_{P} + {\left(T^{2} m^{5} n_{I} + {\left(2 \, T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} n_{I}^{2} + {\left({\left(T^{2} m^{3} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{2}\right)} n_{I}^{2} + {\left(T^{2} m^{4} + {\left(T V_{\mu} + T V_{\xi_{3}}\right)} m^{3}\right)} n_{I}\right)} n_{P}\right)} \xi_{1}\right)} \xi_{3}$I put the symbolic expression in a framabin.

### Conversion from symbolic expression to polynomial stuck

I have a very long symbolic expression with six variables:

(E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, mu, n_I, n_P, xi_1, xi_3)

I call the expression AN. I want to convert it in a polynomial of two variables (mu and xi_3). I tried the following command:

AP = AN.polynomial(None,ring=SR['mu,xi_3'])


This works for simple expressions but the command remains stuck for the given expression. My aim is to get the monomials of the polynomial. mu and xi_3 are random variables and I want to compute the expectation of AN (E[AN]). Thus, I could substitute the expectations in the expression.

AN is a numerator, so it is not a fraction. Moreover, I also tried simply_rational but it did not help to convert.

Is there anyway to convert easily ?