Пример #1
0
    def _eval_simplify(self, **kwargs):
        from sympy.simplify.simplify import expand_log, simplify, inversecombine
        if len(self.args) == 2:  # it's unevaluated
            return simplify(self.func(*self.args), **kwargs)

        expr = self.func(simplify(self.args[0], **kwargs))
        if kwargs['inverse']:
            expr = inversecombine(expr)
        expr = expand_log(expr, deep=True)
        return min([expr, self], key=kwargs['measure'])
Пример #2
0
 def _eval_simplify(self, ratio, measure, rational, inverse):
     from sympy.simplify.simplify import expand_log, simplify, inversecombine
     if (len(self.args) == 2):
         return simplify(self.func(*self.args), ratio=ratio, measure=measure,
                         rational=rational, inverse=inverse)
     expr = self.func(simplify(self.args[0], ratio=ratio, measure=measure,
                      rational=rational, inverse=inverse))
     if inverse:
         expr = inversecombine(expr)
     expr = expand_log(expr, deep=True)
     return min([expr, self], key=measure)
Пример #3
0
 def _eval_simplify(self, ratio, measure, rational, inverse):
     from sympy.simplify.simplify import expand_log, simplify, inversecombine
     if (len(self.args) == 2):
         return simplify(self.func(*self.args), ratio=ratio, measure=measure,
                         rational=rational, inverse=inverse)
     expr = self.func(simplify(self.args[0], ratio=ratio, measure=measure,
                      rational=rational, inverse=inverse))
     if inverse:
         expr = inversecombine(expr)
     expr = expand_log(expr, deep=True)
     return min([expr, self], key=measure)
Пример #4
0
def test_simplify_function_inverse():
    # "inverse" attribute does not guarantee that f(g(x)) is x
    # so this simplification should not happen automatically.
    # See issue #12140
    x, y = symbols('x, y')
    g = Function('g')

    class f(Function):
        def inverse(self, argindex=1):
            return g

    assert simplify(f(g(x))) == f(g(x))
    assert inversecombine(f(g(x))) == x
    assert simplify(f(g(x)), inverse=True) == x
    assert simplify(f(g(sin(x)**2 + cos(x)**2)), inverse=True) == 1
    assert simplify(f(g(x, y)), inverse=True) == f(g(x, y))
    assert simplify(2 * asin(sin(3 * x)), inverse=True) == 6 * x
Пример #5
0
def test_simplify_function_inverse():
    # "inverse" attribute does not guarantee that f(g(x)) is x
    # so this simplification should not happen automatically.
    # See issue #12140
    x, y = symbols('x, y')
    g = Function('g')

    class f(Function):
        def inverse(self, argindex=1):
            return g

    assert simplify(f(g(x))) == f(g(x))
    assert inversecombine(f(g(x))) == x
    assert simplify(f(g(x)), inverse=True) == x
    assert simplify(f(g(sin(x)**2 + cos(x)**2)), inverse=True) == 1
    assert simplify(f(g(x, y)), inverse=True) == f(g(x, y))
    assert simplify(2*asin(sin(3*x)), inverse=True) == 6*x
Пример #6
0
def test_simplify_function_inverse():
    # "inverse" attribute does not guarantee that f(g(x)) is x
    # so this simplification should not happen automatically.
    # See issue #12140
    x, y = symbols("x, y")
    g = Function("g")

    class f(Function):
        def inverse(self, argindex=1):
            return g

    assert simplify(f(g(x))) == f(g(x))
    assert inversecombine(f(g(x))) == x
    assert simplify(f(g(x)), inverse=True) == x
    assert simplify(f(g(sin(x)**2 + cos(x)**2)), inverse=True) == 1
    assert simplify(f(g(x, y)), inverse=True) == f(g(x, y))
    assert unchanged(asin, sin(x))
    assert simplify(asin(sin(x))) == asin(sin(x))
    assert simplify(2 * asin(sin(3 * x)), inverse=True) == 6 * x
    assert simplify(log(exp(x))) == log(exp(x))
    assert simplify(log(exp(x)), inverse=True) == x
    assert simplify(log(exp(x), 2), inverse=True) == x / log(2)
    assert simplify(log(exp(x), 2, evaluate=False), inverse=True) == x / log(2)