@public
def guess_generating_function_rational(v, X=Symbol('x')):
 q = find_simple_recurrence_vector(v)
 n = len(q)
 if (n <= 1):
  return None
 p = [sum(((v[(i - k)] * q[k]) for k in range(min((i + 1), n)))) for i in range(len(v))]
 return (sum(((p[k] * (X ** k)) for k in range(len(p)))) / sum(((q[k] * (X ** k)) for k in range(n))))

@ public def guess_generating_function_rational ( v , X = Symbol ( 'x' ) ) : q = find_simple_recurrence_vector ( v ) n = len ( q ) if ( n <= 1 ) : return None p = [ sum ( ( ( v [ ( i - k ) ] * q [ k ] ) for k in range ( min ( ( i + 1 ) , n ) ) ) ) for i in range ( len ( v ) ) ] return ( sum ( ( ( p [ k ] * ( X ** k ) ) for k in range ( len ( p ) ) ) ) / sum ( ( ( q [ k ] * ( X ** k ) ) for k in range ( n ) ) ) )
tries to "guess" a rational generating function for a sequence of rational numbers v .