def dup_half_gcdex(f, g, K):
 if (not K.has_Field):
  raise DomainError(("can't compute half extended GCD over %s" % K))
 (a, b) = ([K.one], [])
 while g:
  (q, r) = dup_div(f, g, K)
  (f, g) = (g, r)
  (a, b) = (b, dup_sub_mul(a, q, b, K))
 a = dup_quo_ground(a, dup_LC(f, K), K)
 f = dup_monic(f, K)
 return (a, f)

def dup_half_gcdex ( f , g , K ) : if ( not K . has_Field ) : raise DomainError ( ( "can't compute half extended GCD over %s" % K ) ) ( a , b ) = ( [ K . one ] , [ ] ) while g : ( q , r ) = dup_div ( f , g , K ) ( f , g ) = ( g , r ) ( a , b ) = ( b , dup_sub_mul ( a , q , b , K ) ) a = dup_quo_ground ( a , dup_LC ( f , K ) , K ) f = dup_monic ( f , K ) return ( a , f )
half extended euclidean algorithm in f[x] .