should complex, non-real, objects be comparable?

42 views
Skip to first unread message

Chris Smith

unread,
Aug 6, 2014, 11:40:04 AM8/6/14
to sy...@googlegroups.com
Python and SymPy both raise an error for something like I < 2*I -- is there a good reason to disallow comparison of numbers that have the same arg even though it is not 0 (as in the comparison of real numbers)? Allowing this would allow 1 + 2*I < 2 + 4*I to be true, too.

Richard Fateman

unread,
Aug 7, 2014, 10:23:41 PM8/7/14
to sy...@googlegroups.com
What would the result  from   a>b   if a and b are not comparable by your rule?  false? error?  abs(a)>abs(b)?

Aaron Meurer

unread,
Aug 8, 2014, 12:07:49 AM8/8/14
to sy...@googlegroups.com
Aside from consistency with Python, the reason is that you can't
really define a so-called algebraic ordering on complex numbers.
Algebraic means that you can add both sides of an inequality (if a > b
then a + c > b + c), and multiply them by something positive (if a > b
and c > 0, then a*c > b*c).

For example, if you allow 1 + 2*I < 2 + 4*I, then rearranging by the
first rule, you get 2*I + 1> 0. By the second rule, this is positive,
so we can multiply it by both sides of the first inequality, giving -3
+ 4*I < -6 + 8*I. Rearranging gives 4*I > 3. Since we still would have
normal positive, numbers, 3 > 0, so by transitivity, 4*I > 0. But then
multiplying that equation by 4*I by the first rule gives -8 > 0, which
is not true.

Basically, no matter how you try to define it, you can't make complex
numbers into an algebraic ordering, because the way that I**2 gives a
negative number screws up the second rule, and the first rule always
lets you get to I > 0 or I < 0 (i.e., -I > 0), and since I**2 =
(-I)**2 = -1, you get a contradiction either way.

We *definitely* want > to mean an algebraic ordering in SymPy, since
it implicitly lets us perform operations on inequalities like moving
things to one side (saying a > b is equivalent to a - b being
positive) and multiplying by positive things, which is really how you
combine inequalities to do useful algebra with them. I say implicitly
because things like, "solve (x - 1)*(x + 4) > 0 by finding where x - 1
and x + 4 are both positive or both negative" inherently rely on this
rule.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/c5adea66-a3e3-40f2-add4-17ee85dee5c9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Aug 14, 2014, 1:34:09 PM8/14/14
to sy...@googlegroups.com
Very informative. Thanks for taking the time to give this answer, Aaron.
Reply all
Reply to author
Forward
0 new messages