Ask Your Question
2

Conversion from symbolic expression to polynomial stuck

asked 2018-11-16 12:54:52 +0100

borostack gravatar image

updated 2018-11-16 13:56:31 +0100

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 : https://framabin.org/p/?2417942055fc9fc9#Oenpb+BI567QXYcVCzjO4zkLRC0byQaNdhi2XW/CUkY= (I put the symbolic expression in a framabin.)

edit retag flag offensive close merge delete

Comments

1

Could you please provide the (construction of the) symbolic expression ?

tmonteil gravatar imagetmonteil ( 2018-11-16 13:03:20 +0100 )edit

https://framabin.org/p/?2417942055fc9fc9#Oenpb+BI567QXYcVCzjO4zkLRC0byQaNdhi2XW/CUkY= (I added a framabin where you can read the symbolic expression.)

borostack gravatar imageborostack ( 2018-11-16 13:57:30 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-11-16 14:17:35 +0100

rburing gravatar image

updated 2018-11-16 16:15:50 +0100

Since the whole expression is a polynomial with rational coefficients, the following works:

sage: R = PolynomialRing(PolynomialRing(QQ, names='E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, n_I, n_P, xi_1'), names='mu, xi_3')
sage: map(SR, R(AN).monomials())
[mu^2, mu*xi_3, mu, xi_3, 1]
sage: map(SR, R(AN).coefficients())
[T^2*m^6 + 4*T^2*m^5*n_I + 4*T^2*m^4*n_I^2 + 2*T^2*m^5*n_P + 6*T^2*m^4*n_I*n_P + 4*T^2*m^3*n_I^2*n_P + T^2*m^4*n_P^2 + 2*T^2*m^3*n_I*n_P^2 + T^2*m^2*n_I^2*n_P^2 + 2*T*V_mu*m^4*n_I + 2*T*V_xi3*m^4*n_I + 4*T*V_mu*m^3*n_I^2 + 4*T*V_xi3*m^3*n_I^2 + ...

For expressions involving fractions you would want to replace the inner PolynomialRing by wrapping it in FractionField(...), like this:

sage: R = PolynomialRing(FractionField(PolynomialRing(QQ, names='E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z, m, n_I, n_P, xi_1')), names='mu, xi_3')
edit flag offensive delete link more

Comments

https://doc.sagemath.org/html/en/reference/rings/sage/rings/fraction_field_element.html (I found the page about the Fraction Field Elements.)

AN is my numerator and AD is my denominator of my symbolic expression A. There is not the values of interest (mu and xi_3) in the denominator AD. How should I wrap the whole in the Fraction Field ?

BTW, thank you very much :)

borostack gravatar imageborostack ( 2018-11-16 15:08:42 +0100 )edit

I added the precise instruction to my answer. You should then be able to do R(A) etc. The coefficients of the polynomial R(A) will then be Fraction Field Elements. You're welcome :)

rburing gravatar imagerburing ( 2018-11-16 16:18:09 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-16 12:53:39 +0100

Seen: 790 times

Last updated: Nov 16 '18