Ask Your Question
2

substitution not working properly

asked 2015-10-18 18:32:21 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have the following code and I want to substitute all B^2=17.

B,x,y= var('B x y')
eq=81*x^16*B^6 + 40662*x^15*B^3 + 14353281*x^14*B^2;eq
eq1=eq.subs({B^2: (17)});eq1

and I get

81*B^6*x^16 + 40662*B^3*x^15 + 244005777*x^14

I am not sure why the substitution didn't bother to simplify B^6=17^3 and B^3=17*B

I also tried using this code which was suggested earlier :

B,x,y= var('B x y')
eq=81*x^16*B^6 + 40662*x^15*B^3 + 14353281*x^14*B^2;eq
eq1=eq.subs({B: sqrt(17)});eq1

which yields

397953*x^16 + 691254*sqrt(17)*x^15 + 244005777*x^14

and I have this sqrt(17) terms which is not written as B. I need it to be written as B because later on I need to collect the coefficient of B. Perhaps I should use something like while{B^2 : 17} but no idea how to do that.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-10-18 21:13:40 -0500

tmonteil gravatar image

updated 2015-10-18 21:19:56 -0500

Not satisfactory, but you can do:

sage: eq.subs({B: sqrt(17)}).subs({sqrt(17):B})
691254*B*x^15 + 397953*x^16 + 244005777*x^14

That said, since your expressions are polynomials (they do not involve things like log, sin,...), you can work in a well defined polynomial ring:

sage: R.<B,x,y> = QQ[]
sage: R
Multivariate Polynomial Ring in B, x, y over Rational Field
sage: eq.mod(B^2-17)
691254*B*x^15 + 397953*x^16 + 244005777*x^14
edit flag offensive delete link more

Comments

Thank you @tmonteil. This solved my problem.

Sha gravatar imageSha ( 2015-10-20 23:17:13 -0500 )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: 2015-10-18 18:32:21 -0500

Seen: 58 times

Last updated: Oct 18 '15