Esempio n. 1
0
def test_mul_noncommutative():
    A, B = symbols('A B', commutative=False)
    u, v = symbols('u v', cls=Wild)
    w, z = symbols('u v', cls=Wild, commutative=False)

    assert x.match(u * v) in ({v: x, u: 1}, {u: x, v: 1})
    assert (x * y).match(u * v) in ({v: y, u: x}, {u: y, v: x})
    assert A.match(u * v) is None
    assert (A * B).match(u * v) is None
    assert (x * A).match(u * v) is None
    assert (x * y * A).match(u * v) is None
    assert (x * A * B).match(u * v) is None
    assert (x * y * A * B).match(u * v) is None

    assert x.match(v * w) is None
    assert (x * y).match(v * w) is None
    assert A.match(v * w) == {w: A, v: 1}
    assert (A * B).match(v * w) == {w: A * B, v: 1}
    assert (x * A).match(v * w) == {w: A, v: x}
    assert (x * y * A).match(v * w) == {w: A, v: x * y}
    assert (x * A * B).match(v * w) == {w: A * B, v: x}
    assert (x * y * A * B).match(v * w) == {w: A * B, v: x * y}

    assert (-x).match(v * w) is None
    assert (-x * y).match(v * w) is None
    assert (-A).match(v * w) == {w: A, v: -1}
    assert (-A * B).match(v * w) == {w: A * B, v: -1}
    assert (-x * A).match(v * w) == {w: A, v: -x}
    assert (-x * y * A).match(v * w) == {w: A, v: -x * y}
    assert (-x * A * B).match(v * w) == {w: A * B, v: -x}
    assert (-x * y * A * B).match(v * w) == {w: A * B, v: -x * y}

    assert (x * y * A).match(u * v * w) == {u: x, v: y, w: A}
    assert (x * A).match(w * z) is None
Esempio n. 2
0
def test_mul_noncommutative():
    A, B = symbols('A B', commutative=False)
    u, v = symbols('u v', cls=Wild)
    w, z = symbols('u v', cls=Wild, commutative=False)

    assert x.match(u*v) in ({v: x, u: 1}, {u: x, v: 1})
    assert (x*y).match(u*v) in ({v: y, u: x}, {u: y, v: x})
    assert A.match(u*v) is None
    assert (A*B).match(u*v) is None
    assert (x*A).match(u*v) is None
    assert (x*y*A).match(u*v) is None
    assert (x*A*B).match(u*v) is None
    assert (x*y*A*B).match(u*v) is None

    assert x.match(v*w) is None
    assert (x*y).match(v*w) is None
    assert A.match(v*w) == {w: A, v: 1}
    assert (A*B).match(v*w) == {w: A*B, v: 1}
    assert (x*A).match(v*w) == {w: A, v: x}
    assert (x*y*A).match(v*w) == {w: A, v: x*y}
    assert (x*A*B).match(v*w) == {w: A*B, v: x}
    assert (x*y*A*B).match(v*w) == {w: A*B, v: x*y}

    assert (-x).match(v*w) is None
    assert (-x*y).match(v*w) is None
    assert (-A).match(v*w) == {w: A, v: -1}
    assert (-A*B).match(v*w) == {w: A*B, v: -1}
    assert (-x*A).match(v*w) == {w: A, v: -x}
    assert (-x*y*A).match(v*w) == {w: A, v: -x*y}
    assert (-x*A*B).match(v*w) == {w: A*B, v: -x}
    assert (-x*y*A*B).match(v*w) == {w: A*B, v: -x*y}

    assert (x*y*A).match(u*v*w) == {u: x, v: y, w: A}
    assert (x*A).match(w*z) is None
Esempio n. 3
0
def test_sympyissue_5168():
    a, b, c = symbols('a b c', cls=Wild)
    f = Function('f')

    assert x.match(a) == {a: x}
    assert x.match(a * f(x)**c) == {a: x, c: 0}
    assert x.match(a * b) == {a: 1, b: x}
    assert x.match(a * b * f(x)**c) == {a: 1, b: x, c: 0}

    assert (-x).match(a) == {a: -x}
    assert (-x).match(a * f(x)**c) == {a: -x, c: 0}
    assert (-x).match(a * b) == {a: -1, b: x}
    assert (-x).match(a * b * f(x)**c) == {a: -1, b: x, c: 0}

    assert (2 * x).match(a) == {a: 2 * x}
    assert (2 * x).match(a * f(x)**c) == {a: 2 * x, c: 0}
    assert (2 * x).match(a * b) == {a: 2, b: x}
    assert (2 * x).match(a * b * f(x)**c) == {a: 2, b: x, c: 0}

    assert (-2 * x).match(a) == {a: -2 * x}
    assert (-2 * x).match(a * f(x)**c) == {a: -2 * x, c: 0}
    assert (-2 * x).match(a * b) == {a: -2, b: x}
    assert (-2 * x).match(a * b * f(x)**c) == {a: -2, b: x, c: 0}
Esempio n. 4
0
def test_sympyissue_5168():
    a, b, c = symbols('a b c', cls=Wild)
    f = Function('f')

    assert x.match(a) == {a: x}
    assert x.match(a*f(x)**c) == {a: x, c: 0}
    assert x.match(a*b) == {a: 1, b: x}
    assert x.match(a*b*f(x)**c) == {a: 1, b: x, c: 0}

    assert (-x).match(a) == {a: -x}
    assert (-x).match(a*f(x)**c) == {a: -x, c: 0}
    assert (-x).match(a*b) == {a: -1, b: x}
    assert (-x).match(a*b*f(x)**c) == {a: -1, b: x, c: 0}

    assert (2*x).match(a) == {a: 2*x}
    assert (2*x).match(a*f(x)**c) == {a: 2*x, c: 0}
    assert (2*x).match(a*b) == {a: 2, b: x}
    assert (2*x).match(a*b*f(x)**c) == {a: 2, b: x, c: 0}

    assert (-2*x).match(a) == {a: -2*x}
    assert (-2*x).match(a*f(x)**c) == {a: -2*x, c: 0}
    assert (-2*x).match(a*b) == {a: -2, b: x}
    assert (-2*x).match(a*b*f(x)**c) == {a: -2, b: x, c: 0}