def test_rewrite1(): e = exp(x) assert mrewrite(mrv(e, x), x, m) == (1/m, -x) e = exp(x**2) assert mrewrite(mrv(e, x), x, m) == (1/m, -x**2) e = exp(x + 1/x) assert mrewrite(mrv(e, x), x, m) == (1/m, -x - 1/x) e = 1/exp(-x + exp(-x)) - exp(x) assert mrewrite(mrv(e, x), x, m) == (1/(m*exp(m)) - 1/m, -x)
def test_rewrite1(): e = exp(x) assert mrewrite(mrv(e, x), x, m) == (1 / m, -x) e = exp(x**2) assert mrewrite(mrv(e, x), x, m) == (1 / m, -x**2) e = exp(x + 1 / x) assert mrewrite(mrv(e, x), x, m) == (1 / m, -x - 1 / x) e = 1 / exp(-x + exp(-x)) - exp(x) assert mrewrite(mrv(e, x), x, m) == (1 / (m * exp(m)) - 1 / m, -x)
def test_mrv1(): assert mrv(x, x) == set([x]) assert mrv(x + 1 / x, x) == set([x]) assert mrv(x**2, x) == set([x]) assert mrv(log(x), x) == set([x]) assert mrv(exp(x), x) == set([exp(x)]) assert mrv(exp(-x), x) == set([exp(-x)]) assert mrv(exp(x**2), x) == set([exp(x**2)]) assert mrv(-exp(1 / x), x) == set([x]) assert mrv(exp(x + 1 / x), x) == set([exp(x + 1 / x)])
def test_mrv1(): assert mrv(x, x) == set([x]) assert mrv(x+1/x, x) == set([x]) assert mrv(x**2, x) == set([x]) assert mrv(log(x), x) == set([x]) assert mrv(exp(x), x) == set([exp(x)]) assert mrv(exp(-x), x) == set([exp(-x)]) assert mrv(exp(x**2), x) == set([exp(x**2)]) assert mrv(-exp(1/x), x) == set([x]) assert mrv(exp(x+1/x), x) == set([exp(x+1/x)])
def test_rewrite3(): e = exp(-x + 1 / x ** 2) - exp(x + 1 / x) # both of these are correct and should be equivalent: assert mrewrite(mrv(e, x), x, m) in [ (-1 / m + m * exp(1 / x + 1 / x ** 2), -x - 1 / x), (m - 1 / m * exp(1 / x + x ** (-2)), x ** (-2) - x), ]
def test_mrv3(): assert mrv(exp(x**2)+x*exp(x)+log(x)**x/x, x) == set([exp(x**2)]) assert mrv(exp(x)*(exp(1/x+exp(-x))-exp(1/x)), x) == set([exp(x), exp(-x)]) assert mrv(log(x**2+2*exp(exp(3*x**3*log(x)))), x) == set([exp(exp(3*x**3*log(x)))]) assert mrv(log(x-log(x))/log(x), x) == set([x]) assert mrv((exp(1/x-exp(-x))-exp(1/x))*exp(x), x) == set([exp(x), exp(-x)]) assert mrv(1/exp(-x+exp(-x))-exp(x), x) == set([exp(x), exp(-x), exp(x-exp(-x))]) assert mrv(log(log(x*exp(x*exp(x))+1)), x) == set([exp(x*exp(x))]) assert mrv(exp(exp(log(log(x)+1/x))), x) == set([x])
def test_mrv2b(): assert mrv(exp(x+exp(-x**2)), x) == set([exp(-x**2)])
def mmrv(a, b): return set(mrv(a, b)[0].keys())
def mmrv(a, b): return set(mrv(a, b)[0].keys()) def test_mrv1():
def test_mrv2c(): assert mrv(exp(-x+1/x**2)-exp(x+1/x), x) == set([exp(x+1/x), exp(1/x**2-x)])
def test_mrv_leadterm3(): #Gruntz: p56, 3.27 assert mrv(exp(-x+exp(-x)*exp(-x*log(x))), x) == set([exp(-x-x*log(x))]) assert mrv_leadterm(exp(-x+exp(-x)*exp(-x*log(x))), x) == (exp(-x), 0)
def test_rewrite2(): e = exp(x) * log(log(exp(x))) assert mmrv(e, x) == {exp(x)} assert mrewrite(mrv(e, x), x, m) == (1 / m * log(x), -x)
def test_mrv2c(): assert mrv(exp(-x + 1 / x**2) - exp(x + 1 / x), x) == set([exp(x + 1 / x), exp(1 / x**2 - x)])
def test_mrv2b(): assert mrv(exp(x + exp(-x**2)), x) == set([exp(-x**2)])
def test_mrv2a(): assert mrv(exp(x + exp(-exp(x))), x) == set([exp(-exp(x))]) assert mrv(exp(x + exp(-x)), x) == set([exp(x + exp(-x)), exp(-x)]) assert mrv(exp(1 / x + exp(-x)), x) == set([exp(-x)])
def test_mrv2a(): assert mrv(exp(x+exp(-exp(x))), x) == set([exp(-exp(x))]) assert mrv(exp(x+exp(-x)), x) == set([exp(x+exp(-x)), exp(-x)]) assert mrv(exp(1/x+exp(-x)), x) == set([exp(-x)])
def test_rewrite2(): e = exp(x)*log(log(exp(x))) assert mmrv(e, x) == set([exp(x)]) assert mrewrite(mrv(e, x), x, m) == (1/m*log(x), -x)
def test_MrvTestCase_page47_ex3_21(): h = exp(-x/(1 + exp(-x))) expr = exp(h)*exp(-x/(1 + h))*exp(exp(-x + h))/h**2 - exp(x) + x expected = set([1/h, exp(x), exp(x - h), exp(x/(1 + h))]) # XXX Incorrect result assert mrv(expr, x).difference(expected) == set()
def test_mrv_leadterm3(): #Gruntz: p56, 3.27 assert mrv(exp(-x + exp(-x) * exp(-x * log(x))), x) == set([exp(-x - x * log(x))]) assert mrv_leadterm(exp(-x + exp(-x) * exp(-x * log(x))), x) == (exp(-x), 0)
def test_mrv4(): ln = log assert mrv((ln(ln(x) + ln(ln(x))) - ln(ln(x))) / ln(ln(x) + ln(ln(ln(x)))) * ln(x), x) == set([x]) assert mrv(log(log(x*exp(x*exp(x))+1)) - exp(exp(log(log(x)+1/x))), x) == \ set([exp(x*exp(x))])
def test_mrv4(): ln = log assert mrv((ln(ln(x)+ln(ln(x)))-ln(ln(x)))/ln(ln(x)+ln(ln(ln(x))))*ln(x), x) == set([x]) assert mrv(log(log(x*exp(x*exp(x))+1)) - exp(exp(log(log(x)+1/x))), x) == \ set([exp(x*exp(x))])
def test_MrvTestCase_page47_ex3_21(): h = exp(-x / (1 + exp(-x))) expr = exp(h) * exp(-x / (1 + h)) * exp(exp(-x + h)) / h**2 - exp(x) + x expected = {1 / h, exp(x), exp(x - h), exp(x / (1 + h))} # XXX Incorrect result assert mrv(expr, x).difference(expected) == set()
def test_rewrite2(): e = exp(x) * log(log(exp(x))) assert mrv(e, x) == set([exp(x)]) assert rewrite(e, mrv(e, x), x, m) == (1 / m * log(x), -x)