Esempio n. 1
0
File: gosper.py Progetto: Aang/sympy
def gosper(term, k, a, n):
    from sympy.solvers import rsolve_poly

    if not term:
        return None
    else:
        p, q = term.as_numer_denom()
        A, B, C = normal(p, q, k)

        B = B.subs(k, k-1)

        R = rsolve_poly([-B, A], C, k)
        symbol = []

        if not (R is None  or  R is S.Zero):
            if symbol != []:
                symbol = symbol[0]

                W = R.subs(symbol, S.Zero)

                if W is S.Zero:
                    R = R.subs(symbol, S.One)
                else:
                    R = W

            Z = B*R*term/C
            return simplify(Z.subs(k, n+1) - Z.subs(k, a))
        else:
            return None
Esempio n. 2
0
def gosper(term, k, a, n):
    from sympy.solvers import rsolve_poly

    #expr, hyper = combsimp(term.subs(k, k+1)/term, k, verify=True)

    if not hyper:
        return None
    else:
        p, q = expr.as_numer_denom()
        A, B, C = normal(p, q, k)

        B = B.subs(k, k-1)

        R = rsolve_poly([-B, A], C, k)
        symbol = []

        if not (R is None or isinstance(R, Basic.Zero)):
            if symbol != []:
                symbol = symbol[0]

                W = R.subs(symbol, S.Zero)

                if isinstance(W, Basic.Zero):
                    R = R.subs(symbol, S.One)
                else:
                    R = W

            Z = B*R*term/C
            return simplify(Z.subs(k, n+1) - Z.subs(k, a))
        else:
            return None
Esempio n. 3
0
def gosper(term, k, a, n):
    from sympy.solvers import rsolve_poly

    if not term:
        return None
    else:
        p, q = term.as_numer_denom()
        A, B, C = normal(p, q, k)

        B = B.subs(k, k - 1)

        R = rsolve_poly([-B, A], C, k)
        symbol = []

        if not (R is None or R is S.Zero):
            if symbol != []:
                symbol = symbol[0]

                W = R.subs(symbol, S.Zero)

                if W is S.Zero:
                    R = R.subs(symbol, S.One)
                else:
                    R = W

            Z = B * R * term / C
            return simplify(Z.subs(k, n + 1) - Z.subs(k, a))
        else:
            return None