Ask Your Question
1

Why does factor() assume that variables are real?

asked 2024-08-28 13:38:06 +0100

razimantv gravatar image

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

1 Answer

Sort by » oldest newest most voted
2

answered 2024-08-28 18:27:53 +0100

FrédéricC gravatar image

like this

sage: z=var('z', domain='complex')
sage: z.conjugate()
conjugate(z)
sage: z=var('z', domain='real')
sage: z.conjugate()
z
edit flag offensive delete link more

Comments

1

To clarify @FrédéricC's answer :

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,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-08-29 08:53:00 +0100 )edit

Indeed, in (native) Maxima 5.47.0 :

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

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-08-29 08:56:27 +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-08-28 13:38:06 +0100

Seen: 189 times

Last updated: Aug 28