Beispiel #1
0
def test_separatevars_advanced_factor():
    x, y = symbols('x,y')
    assert (separatevars(1 + log(x) * log(y) + log(x) +
                         log(y)) == (log(x) + 1) * (log(y) + 1))
    assert (separatevars(1 + x - log(z) - x * log(z) - exp(y) * log(z) -
                         x * exp(y) * log(z) + x * exp(y) +
                         exp(y)) == -((exp(y) + 1) * (x + 1) * (log(z) - 1)))
    x, y = symbols('x,y', positive=True)
    assert (separatevars(1 + log(x**log(y)) + log(x * y)) == (log(x) + 1) *
            (log(y) + 1))
Beispiel #2
0
def test_sympyissue_6249():
    A = MatrixSymbol('A', 3, 3)
    B = MatrixSymbol('B', 3, 3)
    p = A * B - B * A
    assert cancel(p) == p
    assert combsimp(p) == p
    assert factor(p) == p
    assert separatevars(p) == p
    assert sqrtdenest(p) == p

    M = MatrixSymbol('M', 2, 1)
    assert simplify(M[0] / 2) == M[0] / 2
Beispiel #3
0
def test_separatevars():
    n = Symbol('n')
    assert separatevars(2 * n * x * z + 2 * x * y * z) == 2 * x * z * (n + y)
    assert separatevars(x * z + x * y * z) == x * z * (1 + y)
    assert separatevars(pi * x * z + pi * x * y * z) == pi * x * z * (1 + y)
    assert separatevars(x*y**2*sin(x) + x*sin(x)*sin(y)) == \
        x*(sin(y) + y**2)*sin(x)
    assert separatevars(x * exp(x + y) +
                        x * exp(x)) == x * (1 + exp(y)) * exp(x)
    assert separatevars((x * (y + 1))**z).is_Pow  # != x**z*(1 + y)**z
    assert separatevars(1 + x + y + x * y) == (x + 1) * (y + 1)
    assert separatevars(y/pi*exp(-(z - x)/cos(n))) == \
        y*exp(x/cos(n))*exp(-z/cos(n))/pi
    assert separatevars((x + y) * (x - y) + y**2 + 2 * x + 1) == (x + 1)**2
    # issue sympy/sympy#4858
    p = Symbol('p', positive=True)
    assert separatevars(sqrt(p**2 + x * p**2)) == p * sqrt(1 + x)
    assert separatevars(sqrt(y * (p**2 + x * p**2))) == p * sqrt(y * (1 + x))
    assert separatevars(sqrt(y*(p**2 + x*p**2)), force=True) == \
        p*sqrt(y)*sqrt(1 + x)
    # issue sympy/sympy#4865
    assert separatevars(sqrt(x * y)).is_Pow
    assert separatevars(sqrt(x * y), force=True) == sqrt(x) * sqrt(y)
    # issue sympy/sympy#4957
    # any type sequence for symbols is fine
    assert separatevars(((2*x + 2)*y), dict=True, symbols=()) == \
        {'coeff': 1, x: 2*x + 2, y: y}
    # separable
    assert separatevars(((2*x + 2)*y), dict=True, symbols=[x]) == \
        {'coeff': y, x: 2*x + 2}
    assert separatevars(((2*x + 2)*y), dict=True, symbols=[]) == \
        {'coeff': 1, x: 2*x + 2, y: y}
    assert separatevars(((2*x + 2)*y), dict=True) == \
        {'coeff': 1, x: 2*x + 2, y: y}
    assert separatevars(((2*x + 2)*y), dict=True, symbols=None) == \
        {'coeff': y*(2*x + 2)}
    # not separable
    assert separatevars(3, dict=True) is None
    assert separatevars(2 * x + y, dict=True, symbols=()) is None
    assert separatevars(2 * x + y, dict=True) is None
    assert separatevars(2 * x + y, dict=True, symbols=None) == {
        'coeff': 2 * x + y
    }
    # issue sympy/sympy#4808
    n, m = symbols('n,m', commutative=False)
    assert separatevars(m + n * m) == (1 + n) * m
    assert separatevars(x + x * n) == x * (1 + n)
    # issue sympy/sympy#4910
    f = Function('f')
    assert separatevars(f(x) + x * f(x)) == f(x) + x * f(x)
    # a noncommutable object present
    eq = x * (1 + hyper((), (), y * z))
    assert separatevars(eq) == eq