Ask Your Question
0

Assumptions on symbolic expressions

asked 2024-01-17 23:26:43 +0100

kejv2 gravatar image
a, b = var('a,b')
((a + b)^2).expand()

How can I compute/expand the last expression assuming that $ab=0$? I.e. I would like the result to be $a^2+b^2$. I tried with assuming(..) but that doesn't have any effect.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-01-18 06:17:54 +0100

Max Alekseyev gravatar image

It's easy for polynomial (rather than symbolic) variables:

K.<a,b> = QQ[]
J = K.ideal( [a*b] )
((a+b)^2).reduce(J)
edit flag offensive delete link more

Comments

Thanks, makes sense. What if the base field is more complicated, though? E.g. E.<w> = CyclotomicField(3) and I would like to assume $a + b + c = 0$ in the expression $(a + bw + cw^2)^3$ and would like to group the monomials by the powers of w instead of the monomials in a,b,c.

kejv2 gravatar imagekejv2 ( 2024-01-18 19:52:50 +0100 )edit

Something like this will do the job:

K.<w,a,b,c> = QQ[]
J = K.ideal( [cyclotomic_polynomial(3,w), a+b+c] )
f = ((a+b*w+c*w^2)^3).reduce(J)

Then you can extract the coefficients of powers of w as f.coefficient({w:0}) and f.coefficient({w:1}).

Max Alekseyev gravatar imageMax Alekseyev ( 2024-01-18 21:59:14 +0100 )edit

That's great! The only downside to this approach is the false symmetry between w,a,b,c in the poly ring definition. This doesn't correspond to reality and brings additional problems. For instance, I want to express various combinations of the w-coefficients as elementary symmetric polynomials. Is there a better way than this?

ABC.<a,b,c> = QQ[]
fABC = ABC(f.coefficient({w:0}))
SymK = SymmetricFunctions(QQ).e()
SymK.from_polynomial(fABC)

Plugging in f to SymK directly doesn't work because f.coefficient({w:0}) is of course not symmetric in K.<w,a,b,c>.

kejv2 gravatar imagekejv2 ( 2024-01-18 22:32:09 +0100 )edit

Instead of ABC(f.coefficient({w:0})) you can use f.coefficient({w:0}).specialization({w:0}). In fact for w^0 you can have simply f.specialization({w:0}) but for w^1 it has to be f.coefficient({w:1}).specialization({w:0}).

Max Alekseyev gravatar imageMax Alekseyev ( 2024-01-18 22:38:21 +0100 )edit

For an alternative approach, see my answer in https://ask.sagemath.org/question/75522/

Max Alekseyev gravatar imageMax Alekseyev ( 2024-01-18 22:51:20 +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: 2024-01-17 23:26:43 +0100

Seen: 221 times

Last updated: Jan 18