示例#1
0
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
示例#2
0
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