(func, z)
return Hyper_Function(nap, nbq), ops, -p
Try to recognise a hypergeometric sum that starts from k > 0.
Try to recognise a hypergeometric sum that starts from k > 0.
Try to recognise a hypergeometric sum that starts from k > 0 .
def try_shifted_sum(func, z):
    """ Try to recognise a hypergeometric sum that starts from k > 0. """
    abuckets, bbuckets = sift(func.ap, _mod1), sift(func.bq, _mod1)
    if len(abuckets[S(0)]) != 1:
        return None
    r = abuckets[S(0)][0]
    if r <= 0:
        return None
    if not S(0) in bbuckets:
        return None
    l = list(bbuckets[S(0)])
    l.sort()
    k = l[0]
    if k <= 0:
        return None

    nap = list(func.ap)
    nap.remove(r)
    nbq = list(func.bq)
    nbq.remove(k)
    k -= 1
    nap = [x - k for x in nap]
    nbq = [x - k for x in nbq]

    ops = []
    for n in xrange(r - 1):
        ops.append(ShiftA(n + 1))
    ops.reverse()

    fac = factorial(k)/z**k
    for a in nap:
        fac /= rf(a, k)
    for b in nbq:
        fac *= rf(b, k)

    ops += [MultOperator(fac)]

    p = 0
    for n in xrange(k):
        m = z**n/factorial(n)
        for a in nap:
            m *= rf(a, n)
        for b in nbq:
            m /= rf(b, n)
        p += m

    return Hyper_Function(nap, nbq), ops, -p
def try_shifted_sum ( func , z ) : abuckets , bbuckets = sift ( func . ap , _mod1 ) , sift ( func . bq , _mod1 ) if len ( abuckets [ S ( 0 ) ] ) != 1 : return None r = abuckets [ S ( 0 ) ] [ 0 ] if r <= 0 : return None if not S ( 0 ) in bbuckets : return None l = list ( bbuckets [ S ( 0 ) ] ) l . sort ( ) k = l [ 0 ] if k <= 0 : return None nap = list ( func . ap ) nap . remove ( r ) nbq = list ( func . bq ) nbq . remove ( k ) k -= 1 nap = [ x - k for x in nap ] nbq = [ x - k for x in nbq ] ops = [ ] for n in xrange ( r - 1 ) : ops . append ( ShiftA ( n + 1 ) ) ops . reverse ( ) fac = factorial ( k ) / z ** k for a in nap : fac /= rf ( a , k ) for b in nbq : fac *= rf ( b , k ) ops += [ MultOperator ( fac ) ] p = 0 for n in xrange ( k ) : m = z ** n / factorial ( n ) for a in nap : m *= rf ( a , n ) for b in nbq : m /= rf ( b , n ) p += m return Hyper_Function ( nap , nbq ) , ops , - p