Ask Your Question

Should I always use .expand() before using .coefficient()?

asked 2018-03-08 08:35:57 -0500

DanialBagh gravatar image

I used the following code in SageMath (Windows binary, version 8.1):

q,x,t,bb_1_1_0,bb_1_1_1,aa_1_1_1,cc_1,eps=var('q x t bb_1_1_0 bb_1_1_1 aa_1_1_1 cc_1 eps')

const1=-(bb_1_1_1*eps*cos(t)*cos(x) + bb_1_1_0*eps*cos(x) + q)*aa_1_1_1*eps*cos(x)*sin(t) - bb_1_1_1*cc_1*eps*cos(x)*sin(t)

Obtaining the coefficients of polynomial with respect to eps: const1.coefficient(eps,1) gives

-(bb_1_1_1*cos(t)*cos(x) + bb_1_1_0*cos(x))*aa_1_1_1*cos(x)*sin(t) - bb_1_1_1*cc_1*cos(x)*sin(t)

but using const1.expand().coefficient(eps,1) gives

-bb_1_1_1*cc_1*cos(x)*sin(t) - aa_1_1_1*q*cos(x)*sin(t)

Clearly the second one is correct. Does this mean that I should always use .expand() before using .coefficient()? In another instance I was forced to use simplify_full() before using coefficient().

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-08 12:05:58 -0500

Richard_L gravatar image

"...should always use ...?" Probably not. Since there is no canonical "simplest" form for any expression, various combinations of .expand(), .factor(), .simplify_full(), etc. may be appropriate in different circumstances.

edit flag offensive delete link more

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


Asked: 2018-03-08 06:49:38 -0500

Seen: 29 times

Last updated: Mar 08