don't understand piece of code

21 views
Skip to first unread message

Paul Royik

unread,
Nov 9, 2015, 3:49:20 AM11/9/15
to sympy
In Mul class I see this piece of code:

    def _eval_is_real(self):
        real = True
        zero = one_neither = False

        for t in self.args:
            if not t.is_complex:
                return t.is_complex


Don't understand last two lines. How is it possible that if t is not complex, then return that all Mul is not real?

Mateusz Paprocki

unread,
Nov 9, 2015, 5:42:51 AM11/9/15
to sympy
Hi,
I think this is because t.is_real implies t.is_complex, so saying
t.is_complex == False doesn't mean t.is_real == True; it means that t
is perhaps not a number (e.g. a MatrixExpr). As we employ three-valued
logic (yes, no, don't know), then returning t.is_complex is the
correct approach. Also see [1], because this code was originally wrong
(perhaps Chris can give you better explanation).

[1] https://github.com/sympy/sympy/commit/4d9c756d031e3965867701a65d3970a915495944

Mateusz

> --
> 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/cbc7af32-9220-4351-9035-03eeac60a6a2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Paul Royik

unread,
Nov 9, 2015, 6:11:20 AM11/9/15
to sympy
OK. Thanks.
Reply all
Reply to author
Forward
0 new messages