Example #1
0
def limited_integrate(fa, fd, G, DE):
    """
    Solves the limited integration problem:  f = Dv + Sum(ci*wi, (i, 1, n))
    """
    fa, fd = fa * Poly(1 / fd.LC(), DE.t), fd.monic()
    A, B, h, N, g, V = limited_integrate_reduce(fa, fd, G, DE)
    V = [g] + V
    g = A.gcd(B)
    A, B, V = A.quo(g), B.quo(g), [
        via.cancel(vid * g, include=True) for via, vid in V
    ]
    Q, M = prde_linear_constraints(A, B, V, DE)
    M, _ = constant_system(M, zeros(M.rows, 1), DE)
    l = M.nullspace()
    if M == Matrix() or len(l) > 1:
        # Continue with param_rischDE()
        raise NotImplementedError("param_rischDE() is required to solve this "
                                  "integral.")
    elif len(l) == 0:
        raise NonElementaryIntegralException
    elif len(l) == 1:
        # The c1 == 1.  In this case, we can assume a normal Risch DE
        if l[0][0].is_zero:
            raise NonElementaryIntegralException
        else:
            l[0] *= 1 / l[0][0]
            C = sum([Poly(i, DE.t) * q for (i, q) in zip(l[0], Q)])
            # Custom version of rischDE() that uses the already computed
            # denominator and degree bound from above.
            B, C, m, alpha, beta = spde(A, B, C, N, DE)
            y = solve_poly_rde(B, C, m, DE)

            return ((alpha * y + beta, h), list(l[0][1:]))
    else:
        raise NotImplementedError
Example #2
0
def limited_integrate(fa, fd, G, DE):
    """
    Solves the limited integration problem:  f = Dv + Sum(ci*wi, (i, 1, n))
    """
    fa, fd = fa*Poly(1/fd.LC(), DE.t), fd.monic()
    A, B, h, N, g, V = limited_integrate_reduce(fa, fd, G, DE)
    V = [g] + V
    g = A.gcd(B)
    A, B, V = A.quo(g), B.quo(g), [via.cancel(vid*g, include=True) for
        via, vid in V]
    Q, M = prde_linear_constraints(A, B, V, DE)
    M, _ = constant_system(M, zeros(M.rows, 1), DE)
    l = M.nullspace()
    if M == Matrix() or len(l) > 1:
        # Continue with param_rischDE()
        raise NotImplementedError("param_rischDE() is required to solve this "
            "integral.")
    elif len(l) == 0:
        raise NonElementaryIntegralException
    elif len(l) == 1:
        # The c1 == 1.  In this case, we can assume a normal Risch DE
        if l[0][0].is_zero:
            raise NonElementaryIntegralException
        else:
            l[0] *= 1/l[0][0]
            C = sum([Poly(i, DE.t)*q for (i, q) in zip(l[0], Q)])
            # Custom version of rischDE() that uses the already computed
            # denominator and degree bound from above.
            B, C, m, alpha, beta = spde(A, B, C, N, DE)
            y = solve_poly_rde(B, C, m, DE)

            return ((alpha*y + beta, h), list(l[0][1:]))
    else:
        raise NotImplementedError
Example #3
0
def test_solve_poly_rde_no_cancel():
    # deg(b) large
    DE = DifferentialExtension(extension={"D": [Poly(1, x), Poly(1 + t ** 2, t)]})
    assert solve_poly_rde(Poly(t ** 2 + 1, t), Poly(t ** 3 + (x + 1) * t ** 2 + t + x + 2, t), oo, DE) == Poly(t + x, t)
    # deg(b) small
    DE = DifferentialExtension(extension={"D": [Poly(1, x)]})
    assert solve_poly_rde(Poly(0, x), Poly(x / 2 - S(1) / 4, x), oo, DE) == Poly(x ** 2 / 4 - x / 4, x)
    DE = DifferentialExtension(extension={"D": [Poly(1, x), Poly(t ** 2 + 1, t)]})
    assert solve_poly_rde(Poly(2, t), Poly(t ** 2 + 2 * t + 3, t), 1, DE) == Poly(t + 1, t, x)
    # deg(b) == deg(D) - 1
    DE = DifferentialExtension(extension={"D": [Poly(1, x), Poly(t ** 2 + 1, t)]})
    assert no_cancel_equal(Poly(1 - t, t), Poly(t ** 3 + t ** 2 - 2 * x * t - 2 * x, t), oo, DE) == (
        Poly(t ** 2, t),
        1,
        Poly((-2 - 2 * x) * t - 2 * x, t),
    )
Example #4
0
def test_solve_poly_rde_no_cancel():
    # deg(b) large
    DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(1 + t**2, t)]})
    assert solve_poly_rde(Poly(t**2 + 1, t), Poly(t**3 + (x + 1)*t**2 + t + x + 2, t),
    oo, DE) == Poly(t + x, t)
    # deg(b) small
    DE = DifferentialExtension(extension={'D': [Poly(1, x)]})
    assert solve_poly_rde(Poly(0, x), Poly(x/2 - S(1)/4, x), oo, DE) == \
        Poly(x**2/4 - x/4, x)
    DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t**2 + 1, t)]})
    assert solve_poly_rde(Poly(2, t), Poly(t**2 + 2*t + 3, t), 1, DE) == \
        Poly(t + 1, t, x)
    # deg(b) == deg(D) - 1
    DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(t**2 + 1, t)]})
    assert no_cancel_equal(Poly(1 - t, t),
    Poly(t**3 + t**2 - 2*x*t - 2*x, t), oo, DE) == \
        (Poly(t**2, t), 1, Poly((-2 - 2*x)*t - 2*x, t))