Exemplo n.º 1
0
    def test_subterm(u, u_diff):
        substituted = simplify(integrand / u_diff)
        if symbol not in substituted.free_symbols:
            # replaced everything already
            return False

        substituted_ = substituted.subs(u, u_var).cancel()
        if symbol not in substituted_.free_symbols:
            _, denom = integrand.as_numer_denom()
            _, denom2 = substituted_.as_numer_denom()
            denom2 = denom2.subs(u_var, u)
            constant = denom/denom2
            if symbol not in constant.free_symbols:
                return (constant, substituted_ / constant)
        if u.is_polynomial(symbol):
            h = Poly(u, symbol)
            if h.degree() == 1 and h.nth(0) != 0:
                t = (u_var - h.nth(0)) / h.nth(1)
                substituted_ = simplify(integrand.subs(symbol, t))
                args = list(get_args(substituted_, u_var))
                if symbol not in substituted_.free_symbols and len(args) == 1 and args[0] == u_var:
                    return (1/h.nth(1), substituted_)


        return False