Great! Thank you.
But expr.is_zero always implies, that simplified expr equals 0. Correct?

On Friday, March 19, 2021 at 3:51:31 PM UTC+2 Oscar wrote:

> On Fri, 19 Mar 2021 at 13:19, Paul Royik <distan...@gmail.com> wrote:
> >
> > Is there a difference between checking b.is_zero or b == 0?
>
> Yes, there is.
>
> Checking is_zero is part of the core assumptions system that will run
> a bunch of tests to try and determine if the expression is zero or not
> and will ultimately return True, False or None with None meaning
> "unknown". When checking with == 0 you are checking structural
> equality so you will get True if the expression is precisely zero and
> False otherwise but the expression might still be mathematically zero:
>
> In [12]: expr1 = sin(1)**2 + cos(1)**2 - 1
>
> In [13]: print(expr1.is_zero)
> None
>
> In [14]: print(expr1 == 0)
> False
>
> Usually the interesting part about is_zero is distinguishing between
> when it returns False and None. Knowing that an expression is
> definitely not zero (is_zero = False) allows simplifications that are
> not possible for an expression that is possibly zero (is_zero = None)
>
> It's unusual that an expression that is not structurally zero will
> have is_zero = True (since it would usually have simplified to 0
> automatically) but it can happen particularly with algebraic
> expressions:
>
> In [26]: phi = GoldenRatio
>
> In [27]: expr2 = phi**2 - phi - 1
>
> In [28]: expr2
> Out[28]:
> 2
> -φ - 1 + φ
>
> In [29]: expr2.is_zero
> Out[29]: True
>
> In [30]: simplify(expr2)
> Out[30]: 0
>
>
> Oscar
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/3784b7ac-f54d-499b-b65a-8f7b9d565b40n%40googlegroups.com.

Reply via email to