Simplifying symbolic complex norm

asked 2020-06-30 08:57:16 +0100

Jun gravatar image

updated 2020-07-01 02:07:31 +0100

Sage's simplifier seems to have trouble expanding the square-absolute value of complex numbers:

sage: x,y = var('x,y', domain=RR)
sage: (x^2 + y^2 - abs(x + i*y)^2).simplify_full ()
x^2 + y^2 - abs(x + I*y)^2

How can I ensure sage expands the square-absolute value and simplify this down to zero? I'm aware that using (x + i*y).norm() instead of abs(x + i*y)^2 helps in this particular example, but that solution doesn't generalize. For instance, when I stick expressions involving x, y into vectors and compute the vector norm, the vector norm is expressed in terms of absolute values, so I still need a way to deal with the abs.

edit retag flag offensive close merge delete

Comments

I just want to bump this question.

var('x y')
assume(x,y,'real')
z = x+I*y
print(abs(z))

I'd like this to give me x^2 + y^2, but it doesn't. As the OP writes, one can get the symbolic magnitude using sqrt(z.norm()), but this is inelegant. (Also, note that for reasons drawn from algebraic field theory, the .norm() here gives only the magnitude squared of the complex number.)

UncountableSet gravatar imageUncountableSet ( 2022-02-21 22:34:53 +0100 )edit