def mysimp(expr): from diofant import expand, logcombine, powsimp return expand(powsimp(logcombine(expr, force=True), force=True, deep=True), force=True).replace(exp_polar, exp)
def mysimp(expr): return expand(powsimp(logcombine(expr, force=True), force=True, deep=True), force=True).replace(exp_polar, exp)
def test_logcombine_1(): z, w = symbols("z,w", positive=True) b = Symbol("b", extended_real=True) assert logcombine(log(x) + 2 * log(y)) == log(x) + 2 * log(y) assert logcombine(log(x) + 2 * log(y), force=True) == log(x * y**2) assert logcombine(a * log(w) + log(z)) == a * log(w) + log(z) assert logcombine(b * log(z) + b * log(x)) == log(z**b) + b * log(x) assert logcombine(b * log(z) - log(w)) == log(z**b / w) assert logcombine(log(x) * log(z)) == log(x) * log(z) assert logcombine(log(w) * log(x)) == log(w) * log(x) assert logcombine(cos(-2 * log(z) + b * log(w))) in [ cos(log(w**b / z**2)), cos(log(z**2 / w**b)) ] assert logcombine(log(log(x) - log(y)) - log(z), force=True) == \ log(log(x/y)/z) assert logcombine((2 + I) * log(x), force=True) == (2 + I) * log(x) assert logcombine((x**2 + log(x) - log(y))/(x*y), force=True) == \ (x**2 + log(x/y))/(x*y) # the following could also give log(z*x**log(y**2)), what we # are testing is that a canonical result is obtained assert logcombine(log(x)*2*log(y) + log(z), force=True) == \ log(z*y**log(x**2)) assert logcombine( (x * y + sqrt(x**4 + y**4) + log(x) - log(y)) / (pi * x**Rational(2, 3) * sqrt(y)**3), force=True) == (x * y + sqrt(x**4 + y**4) + log(x / y)) / ( pi * x**Rational(2, 3) * y**Rational(3, 2)) assert logcombine(gamma(-log(x/y))*acos(-log(x/y)), force=True) == \ acos(-log(x/y))*gamma(-log(x/y)) assert logcombine(2*log(z)*log(w)*log(x) + log(z) + log(w)) == \ log(z**log(w**2))*log(x) + log(w*z) assert logcombine(3 * log(w) + 3 * log(z)) == log(w**3 * z**3) assert logcombine(x * (y + 1) + log(2) + log(3)) == x * (y + 1) + log(6) assert logcombine((x + y) * log(w) + (-x - y) * log(3)) == (x + y) * log(w / 3)
def test_logcombine_complex_coeff(): i = Integral((sin(x**2) + cos(x**3)) / x, x) assert logcombine(i, force=True) == i assert logcombine(i + 2 * log(x), force=True) == i + log(x**2)
def mysimp(expr): return expand( powsimp(logcombine(expr, force=True), force=True, deep=True), force=True).replace(exp_polar, exp)