def continued_fraction_convergents(cf):
 (p_2, q_2) = (Integer(0), Integer(1))
 (p_1, q_1) = (Integer(1), Integer(0))
 for a in cf:
  (p, q) = (((a * p_1) + p_2), ((a * q_1) + q_2))
  (p_2, q_2) = (p_1, q_1)
  (p_1, q_1) = (p, q)
  (yield (p / q))

def continued_fraction_convergents ( cf ) : ( p_2 , q_2 ) = ( Integer ( 0 ) , Integer ( 1 ) ) ( p_1 , q_1 ) = ( Integer ( 1 ) , Integer ( 0 ) ) for a in cf : ( p , q ) = ( ( ( a * p_1 ) + p_2 ) , ( ( a * q_1 ) + q_2 ) ) ( p_2 , q_2 ) = ( p_1 , q_1 ) ( p_1 , q_1 ) = ( p , q ) ( yield ( p / q ) )
return an iterator over the convergents of a continued fraction .