# Why does factor() assume that variables are real?

I am sure that I am doing something wrong, so I would appreciate if you could tell me what is going on. Consider the following code:

z1, z2 = var('z1, z2')
term = z1 * z2.conjugate() - z2 * z1.conjugate()
show(term)
show(term.factor())


The first one outputs the correct result, but the second one gives 0. It looks like sage is assuming that things are real when passing to factor(). Is this a bug or the correct behaviour? What do I need to do to avoid this? (Right now, I am expressing all such variables as Real + I * Imag explicitly, but I suspect there is a better way)

edit retag close merge delete

Sort by » oldest newest most voted

like this

sage: z=var('z', domain='complex')
sage: z.conjugate()
conjugate(z)
sage: z=var('z', domain='real')
sage: z.conjugate()
z

more

1

sage: var("z1, z2", domain="complex")
(z1, z2)
sage: term=z1*z2.conjugate()-z2*z1.conjugate()
sage: term
-z2*conjugate(z1) + z1*conjugate(z2)
sage: term.factor()
-z2*conjugate(z1) + z1*conjugate(z2sage: var("a, b, c, d", domain="real")
(a, b, c, d)
sage: term.subs({z1: a+I*b, z2:c+I*d})
-(a - I*b)*(c + I*d) + (a + I*b)*(c - I*d)
sage: term.subs({z1: a+I*b, z2:c+I*d}).factor()
2*I*b*c - 2*I*a*d
sage: term.subs({z1: a+I*b, z2:c+I*d}).collect_common_factors()
-(a - I*b)*(c + I*d) + (a + I*b)*(c - I*d)


(Maxima's) factor seems to sloppily assume that a typeless symbolic variable is real. This bug should be more filed, explored and possibly reported to Maxima's developpers.

HTH,

( 2024-08-29 08:53:00 +0200 )edit

Indeed, in (native) Maxima 5.47.0 :

(%i2) factor(z1*conjugate(z2)-z2*conjugate(z1));
(%o2)                                  0


HTH,

( 2024-08-29 08:56:27 +0200 )edit