示例#1
0
def test_simple():
    rl = rewriterule(Basic(p, 1), Basic(p, 2), variables=(p,))
    assert list(rl(Basic(3, 1))) == [Basic(3, 2)]

    p1 = p**2
    p2 = p**3
    rl = rewriterule(p1, p2, variables=(p,))

    expr = x**2
    assert list(rl(expr)) == [x**3]
示例#2
0
def test_simple():
    rl = rewriterule(Basic(p, 1), Basic(p, 2), variables=(p, ))
    assert list(rl(Basic(3, 1))) == [Basic(3, 2)]

    p1 = p**2
    p2 = p**3
    rl = rewriterule(p1, p2, variables=(p, ))

    expr = x**2
    assert list(rl(expr)) == [x**3]
示例#3
0
def test_moderate():
    p1 = p**2 + q**3
    p2 = (p * q)**4
    rl = rewriterule(p1, p2, (p, q))

    expr = x**2 + y**3
    assert list(rl(expr)) == [(x * y)**4]
示例#4
0
def test_sincos():
    p1 = sin(p)**2 + sin(p)**2
    p2 = 1
    rl = rewriterule(p1, p2, (p, q))

    assert list(rl(sin(x)**2 + sin(x)**2)) == [1]
    assert list(rl(sin(y)**2 + sin(y)**2)) == [1]
示例#5
0
def test_moderate():
    p1 = p**2 + q**3
    p2 = (p*q)**4
    rl = rewriterule(p1, p2, (p, q))

    expr = x**2 + y**3
    assert list(rl(expr)) == [(x*y)**4]
示例#6
0
def test_sincos():
    p1 = sin(p)**2 + sin(p)**2
    p2 = 1
    rl = rewriterule(p1, p2, (p, q))

    assert list(rl(sin(x)**2 + sin(x)**2)) == [1]
    assert list(rl(sin(y)**2 + sin(y)**2)) == [1]
示例#7
0
def test_simple():
    p1 = p**2
    p2 = p**3
    rl = rewriterule(p1, p2)

    expr = x**2
    assert list(rl(expr)) == [x**3]
示例#8
0
def test_simple():
    p1 = p ** 2
    p2 = p ** 3
    rl = rewriterule(p1, p2)

    expr = x ** 2
    assert list(rl(expr)) == [x ** 3]
示例#9
0
def test_condition_multiple():
    rl = rewriterule(x + y, x**y, [x, y], lambda x, y: x.is_integer)

    a = Symbol('a')
    b = Symbol('b', integer=True)
    expr = a + b
    assert list(rl(expr)) == [b**a]

    c = Symbol('c', integer=True)
    d = Symbol('d', integer=True)
    assert set(rl(c + d)) == set([c**d, d**c])
示例#10
0
def test_condition_multiple():
    rl = rewriterule(x + y, x**y, [x, y], lambda x, y: x.is_integer)

    a = Symbol("a")
    b = Symbol("b", integer=True)
    expr = a + b
    assert list(rl(expr)) == [b**a]

    c = Symbol("c", integer=True)
    d = Symbol("d", integer=True)
    assert set(rl(c + d)) == {c**d, d**c}
示例#11
0
def test_condition_multiple():
    rl = rewriterule(x + y, x**y, [x,y], lambda x, y: x.is_integer)

    a = Symbol('a')
    b = Symbol('b', integer=True)
    expr = a + b
    assert list(rl(expr)) == [b**a]

    c = Symbol('c', integer=True)
    d = Symbol('d', integer=True)
    assert set(rl(c + d)) == set([c**d, d**c])
示例#12
0
def test_condition_simple():
    rl = rewriterule(x, x + 1, [x], lambda x: x < 10)
    assert not list(rl(S(15)))
    assert rebuild(next(rl(S(5)))) == 6
示例#13
0
def test_Exprs_ok():
    rl = rewriterule(p + q, q + p, (p, q))
    next(rl(x + y)).is_commutative
    str(next(rl(x + y)))
示例#14
0
def test_simple_variables():
    rl = rewriterule(Basic(x, 1), Basic(x, 2), variables=(x,))
    assert list(rl(Basic(3, 1))) == [Basic(3, 2)]

    rl = rewriterule(x**2, x**3, variables=(x,))
    assert list(rl(y**2)) == [y**3]
示例#15
0
def test_Exprs_ok():
    rl = rewriterule(p+q, q+p, (p, q))
    next(rl(x+y)).is_commutative
    str(next(rl(x+y)))
示例#16
0
def test_simple_variables():
    rl = rewriterule(Basic(x, 1), Basic(x, 2), variables=(x, ))
    assert list(rl(Basic(3, 1))) == [Basic(3, 2)]

    rl = rewriterule(x**2, x**3, variables=(x, ))
    assert list(rl(y**2)) == [y**3]
示例#17
0
def test_condition_simple():
    rl = rewriterule(x, x+1, [x], lambda x: x < 10)
    assert not list(rl(S(15)))
    assert rebuild(next(rl(S(5)))) == 6
示例#18
0
def test_assumptions():
    rl = rewriterule(x + y, x**y, [x, y], assume=Q.integer(x))

    a, b = map(Symbol, 'ab')
    expr = a + b
    assert list(rl(expr, Q.integer(b))) == [b**a]
示例#19
0
def test_assumptions():
    rl = rewriterule(x + y, x**y, [x, y], assume=Q.integer(x))

    a, b = map(Symbol, 'ab')
    expr = a + b
    assert list(rl(expr, Q.integer(b))) == [b**a]
示例#20
0
def test_simple_variables():
    rl = rewriterule(Basic(x, S(1)), Basic(x, S(2)), variables=(x,))
    assert list(rl(Basic(S(3), S(1)))) == [Basic(S(3), S(2))]

    rl = rewriterule(x**2, x**3, variables=(x,))
    assert list(rl(y**2)) == [y**3]