# Assumptions on symbolic expressions

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 close merge delete

Sort by ยป oldest newest most voted

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

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

more

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.

( 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}).

( 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>.

( 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}).

( 2024-01-18 22:38:21 +0100 )edit

( 2024-01-18 22:51:20 +0100 )edit