On Fri, Mar 19, 2021 at 2:36 PM Paul Royik <distantjob...@gmail.com> wrote: > > Great! Thank you. > But expr.is_zero always implies, that simplified expr equals 0. Correct?
Yes, if is_zero is true, then the expression is identically 0. The interesting cases are as Oscar noted, when it is None or False. False means definitely not (identically) 0, whereas None means it could not determine. == 0 on the other hand only checks if the expression is itself literally 0, without any mathematical checks. Keep in mind that zero equivalence is in general an undecidable problem, so it is not always possible for SymPy to return definitively if something is zero or not. Aaron Meurer > > 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. -- 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/CAKgW%3D6%2ByFgcfEJPTbzHRFfLBUXYACuHNaN9VZ-hu%2BKQCnywkag%40mail.gmail.com.