(self, other, failing_expression=False)
return None
Return True if self == other, False if it doesn't, or None. If
        failing_expression is True then the expression which did not simplify
        to a 0 will be returned instead of None.

        If ``self`` is a Number (or complex number) that is not zero, then
        the result is False.

        If ``self`` is a number and has not evaluated to zero, evalf will be
        used to test whether the expression evaluates to zero. If it does so
        and the result has significance (i.e. the precision is either -1, for
        a Rational result, or is greater than 1) then the evalf value will be
        used to return True or False.
Return True if self == other, False if it doesn't, or None. If
        failing_expression is True then the expression which did not simplify
        to a 0 will be returned instead of None.
Return True if self == other False if it doesn t or None . If failing_expression is True then the expression which did not simplify to a 0 will be returned instead of None .
def equals(self, other, failing_expression=False):
        """Return True if self == other, False if it doesn't, or None. If
        failing_expression is True then the expression which did not simplify
        to a 0 will be returned instead of None.

        If ``self`` is a Number (or complex number) that is not zero, then
        the result is False.

        If ``self`` is a number and has not evaluated to zero, evalf will be
        used to test whether the expression evaluates to zero. If it does so
        and the result has significance (i.e. the precision is either -1, for
        a Rational result, or is greater than 1) then the evalf value will be
        used to return True or False.

        """
        from sympy.simplify.simplify import nsimplify, simplify
        from sympy.solvers.solvers import solve
        from sympy.polys.polyerrors import NotAlgebraic
        from sympy.polys.numberfields import minimal_polynomial

        other = sympify(other)
        if self == other:
            return True

        # they aren't the same so see if we can make the difference 0;
        # don't worry about doing simplification steps one at a time
        # because if the expression ever goes to 0 then the subsequent
        # simplification steps that are done will be very fast.
        diff = factor_terms((self - other).simplify(), radical=True)

        if not diff:
            return True

        if not diff.has(Add):
            # if there is no expanding to be done after simplifying
            # then this can't be a zero
            return False

        constant = diff.is_constant(simplify=False, failing_number=True)

        if constant is False:
            return False

        if constant is None and (diff.free_symbols or not diff.is_number):
            # e.g. unless the right simplification is done, a symbolic
            # zero is possible (see expression of issue 6829: without
            # simplification constant will be None).
            return

        if constant is True:
            ndiff = diff._random()
            if ndiff:
                return False

        # sometimes we can use a simplified result to give a clue as to
        # what the expression should be; if the expression is *not* zero
        # then we should have been able to compute that and so now
        # we can just consider the cases where the approximation appears
        # to be zero -- we try to prove it via minimal_polynomial.
        if diff.is_number:
            approx = diff.nsimplify()
            if not approx:
                # try to prove via self-consistency
                surds = [s for s in diff.atoms(Pow) if s.args[0].is_Integer]
                # it seems to work better to try big ones first
                surds.sort(key=lambda x: -x.args[0])
                for s in surds:
                    try:
                        # simplify is False here -- this expression has already
                        # been identified as being hard to identify as zero;
                        # we will handle the checking ourselves using nsimplify
                        # to see if we are in the right ballpark or not and if so
                        # *then* the simplification will be attempted.
                        sol = solve(diff, s, check=False, simplify=False)
                        if sol:
                            if s in sol:
                                return True
                            if any(nsimplify(si, [s]) == s and simplify(si) == s
                                    for si in sol):
                                return True
                    except NotImplementedError:
                        pass

                # try to prove with minimal_polynomial but know when
                # *not* to use this or else it can take a long time.
                if True:  # change True to condition that assures non-hang
                    try:
                        mp = minimal_polynomial(diff)
                        if mp.is_Symbol:
                            return True
                        return False
                    except NotAlgebraic:
                        pass

        # diff has not simplified to zero; constant is either None, True
        # or the number with significance (prec != 1) that was randomly
        # calculated twice as the same value.
        if constant not in (True, None) and constant != 0:
            return False

        if failing_expression:
            return diff
        return None
def equals ( self , other , failing_expression = False ) : from sympy . simplify . simplify import nsimplify , simplify from sympy . solvers . solvers import solve from sympy . polys . polyerrors import NotAlgebraic from sympy . polys . numberfields import minimal_polynomial other = sympify ( other ) if self == other : return True # they aren't the same so see if we can make the difference 0; # don't worry about doing simplification steps one at a time # because if the expression ever goes to 0 then the subsequent # simplification steps that are done will be very fast. diff = factor_terms ( ( self - other ) . simplify ( ) , radical = True ) if not diff : return True if not diff . has ( Add ) : # if there is no expanding to be done after simplifying # then this can't be a zero return False constant = diff . is_constant ( simplify = False , failing_number = True ) if constant is False : return False if constant is None and ( diff . free_symbols or not diff . is_number ) : # e.g. unless the right simplification is done, a symbolic # zero is possible (see expression of issue 6829: without # simplification constant will be None). return if constant is True : ndiff = diff . _random ( ) if ndiff : return False # sometimes we can use a simplified result to give a clue as to # what the expression should be; if the expression is *not* zero # then we should have been able to compute that and so now # we can just consider the cases where the approximation appears # to be zero -- we try to prove it via minimal_polynomial. if diff . is_number : approx = diff . nsimplify ( ) if not approx : # try to prove via self-consistency surds = [ s for s in diff . atoms ( Pow ) if s . args [ 0 ] . is_Integer ] # it seems to work better to try big ones first surds . sort ( key = lambda x : - x . args [ 0 ] ) for s in surds : try : # simplify is False here -- this expression has already # been identified as being hard to identify as zero; # we will handle the checking ourselves using nsimplify # to see if we are in the right ballpark or not and if so # *then* the simplification will be attempted. sol = solve ( diff , s , check = False , simplify = False ) if sol : if s in sol : return True if any ( nsimplify ( si , [ s ] ) == s and simplify ( si ) == s for si in sol ) : return True except NotImplementedError : pass # try to prove with minimal_polynomial but know when # *not* to use this or else it can take a long time. if True : # change True to condition that assures non-hang try : mp = minimal_polynomial ( diff ) if mp . is_Symbol : return True return False except NotAlgebraic : pass # diff has not simplified to zero; constant is either None, True # or the number with significance (prec != 1) that was randomly # calculated twice as the same value. if constant not in ( True , None ) and constant != 0 : return False if failing_expression : return diff return None