def test_is_constant(): from sympy.solvers.solvers import checksol Sum(x, (x, 1, 10)).is_constant() == True Sum(x, (x, 1, n)).is_constant() == False Sum(x, (x, 1, n)).is_constant(y) == True Sum(x, (x, 1, n)).is_constant(n) == False Sum(x, (x, 1, n)).is_constant(x) == True eq = a * cos(x)**2 + a * sin(x)**2 - a eq.is_constant() == True assert eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0 assert x.is_constant() is False assert x.is_constant(y) is True assert checksol(x, x, Sum(x, (x, 1, n))) == False assert checksol(x, x, Sum(x, (x, 1, n))) == False f = Function('f') assert checksol(x, x, f(x)) == False p = symbols('p', positive=True) assert Pow(x, S(0), evaluate=False).is_constant() == True # == 1 assert Pow(S(0), x, evaluate=False).is_constant() == False # == 0 or 1 assert Pow(S(0), p, evaluate=False).is_constant() == True # == 1 assert (2**x).is_constant() == False assert Pow(S(2), S(3), evaluate=False).is_constant() == True z1, z2 = symbols('z1 z2', zero=True) assert (z1 + 2 * z2).is_constant
def test_is_constant(): from sympy.solvers.solvers import checksol Sum(x, (x, 1, 10)).is_constant() == True Sum(x, (x, 1, n)).is_constant() == False Sum(x, (x, 1, n)).is_constant(y) == True Sum(x, (x, 1, n)).is_constant(n) == False Sum(x, (x, 1, n)).is_constant(x) == True eq = a * cos(x) ** 2 + a * sin(x) ** 2 - a eq.is_constant() == True assert eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0 assert x.is_constant() is False assert x.is_constant(y) is True assert checksol(x, x, Sum(x, (x, 1, n))) == False assert checksol(x, x, Sum(x, (x, 1, n))) == False f = Function("f") assert checksol(x, x, f(x)) == False p = symbols("p", positive=True) assert Pow(x, S(0), evaluate=False).is_constant() == True # == 1 assert Pow(S(0), x, evaluate=False).is_constant() == False # == 0 or 1 assert Pow(S(0), p, evaluate=False).is_constant() == True # == 1 assert (2 ** x).is_constant() == False assert Pow(S(2), S(3), evaluate=False).is_constant() == True z1, z2 = symbols("z1 z2", zero=True) assert (z1 + 2 * z2).is_constant() is True assert meter.is_constant() is True assert (3 * meter).is_constant() is True assert (x * meter).is_constant() is False
def __eval_cond(cls, cond): """Return the truth value of the condition.""" from sympy.solvers.solvers import checksol if cond is True: return True if isinstance(cond, Equality): if checksol(cond, {}, minimal=True): # the equality is trivially solved return True return None
def __eval_cond(cls, cond): """Return the truth value of the condition.""" from sympy.solvers.solvers import checksol if cond == True: return True if isinstance(cond, Equality): if checksol(cond, {}, minimal=True): # the equality is trivially solved return True diff = cond.lhs - cond.rhs if diff.is_commutative: return diff.is_zero return None
def _solve_radical(f, symbol, solveset_solver): """ Helper function to solve equations with radicals """ eq, cov = unrad(f) if not cov: result = solveset_solver(eq, symbol) - Union(*[solveset_solver(g, symbol) for g in denoms(f, [symbol])]) else: y, yeq = cov if not solveset_solver(y - I, y): yreal = Dummy("yreal", real=True) yeq = yeq.xreplace({y: yreal}) eq = eq.xreplace({y: yreal}) y = yreal g_y_s = solveset_solver(yeq, symbol) f_y_sols = solveset_solver(eq, y) result = Union(*[imageset(Lambda(y, g_y), f_y_sols) for g_y in g_y_s]) return FiniteSet(*[s for s in result if checksol(f, symbol, s) is True])
def _solve_radical(f, symbol, solveset_solver): """ Helper function to solve equations with radicals """ eq, cov = unrad(f) if not cov: result = solveset_solver(eq, symbol) - \ Union(*[solveset_solver(g, symbol) for g in denoms(f, [symbol])]) else: y, yeq = cov if not solveset_solver(y - I, y): yreal = Dummy('yreal', real=True) yeq = yeq.xreplace({y: yreal}) eq = eq.xreplace({y: yreal}) y = yreal g_y_s = solveset_solver(yeq, symbol) f_y_sols = solveset_solver(eq, y) result = Union(*[imageset(Lambda(y, g_y), f_y_sols) for g_y in g_y_s]) return FiniteSet(*[s for s in result if checksol(f, symbol, s) is True])
def _solve_radical(f, symbol, solveset_solver): """ Helper function to solve equations with radicals """ from sympy.solvers.solvers import unrad try: eq, cov, dens = unrad(f) if cov == []: result = solveset_solver(eq, symbol) - \ Union(*[solveset_solver(g, symbol) for g in dens]) else: if len(cov) > 1: raise NotImplementedError("Multivariate solver is " "not implemented.") else: y = cov[0][0] g_y_s = solveset_solver(cov[0][1], symbol) f_y_sols = solveset_solver(eq, y) result = Union(*[imageset(Lambda(y, g_y), f_y_sols) for g_y in g_y_s]) return FiniteSet(*[s for s in result if checksol(f, symbol, s) is True]) except ValueError: raise NotImplementedError
def _solve_radical(f, symbol, solveset_solver): """ Helper function to solve equations with radicals """ from sympy.solvers.solvers import unrad try: eq, cov, dens = unrad(f) if cov == []: result = solveset_solver(eq, symbol) - \ Union(*[solveset_solver(g, symbol) for g in dens]) else: if len(cov) > 1: raise NotImplementedError("Multivariate solver is " "not implemented.") else: y = cov[0][0] g_y_s = solveset_solver(cov[0][1], symbol) f_y_sols = solveset_solver(eq, y) result = Union( *[imageset(Lambda(y, g_y), f_y_sols) for g_y in g_y_s]) return FiniteSet( *[s for s in result if checksol(f, symbol, s) is True]) except ValueError: raise NotImplementedError
def test_issue_2574(): eq = -x + exp(exp(LambertW(log(x)))*LambertW(log(x))) assert checksol(eq, x, 2) is True assert checksol(eq, x, 2, numerical=False) is None
def test_issue_2574(): eq = -x + exp(exp(LambertW(log(x))) * LambertW(log(x))) assert checksol(eq, x, 2) is True assert checksol(eq, x, 2, numerical=False) is None