def dup_prem(f, g, K):
 df = dup_degree(f)
 dg = dup_degree(g)
 (r, dr) = (f, df)
 if (not g):
  raise ZeroDivisionError('polynomial division')
 elif (df < dg):
  return r
 N = ((df - dg) + 1)
 lc_g = dup_LC(g, K)
 while True:
  lc_r = dup_LC(r, K)
  (j, N) = ((dr - dg), (N - 1))
  R = dup_mul_ground(r, lc_g, K)
  G = dup_mul_term(g, lc_r, j, K)
  r = dup_sub(R, G, K)
  (_dr, dr) = (dr, dup_degree(r))
  if (dr < dg):
   break
  elif (not (dr < _dr)):
   raise PolynomialDivisionFailed(f, g, K)
 return dup_mul_ground(r, (lc_g ** N), K)

def dup_prem ( f , g , K ) : df = dup_degree ( f ) dg = dup_degree ( g ) ( r , dr ) = ( f , df ) if ( not g ) : raise ZeroDivisionError ( 'polynomial division' ) elif ( df < dg ) : return r N = ( ( df - dg ) + 1 ) lc_g = dup_LC ( g , K ) while True : lc_r = dup_LC ( r , K ) ( j , N ) = ( ( dr - dg ) , ( N - 1 ) ) R = dup_mul_ground ( r , lc_g , K ) G = dup_mul_term ( g , lc_r , j , K ) r = dup_sub ( R , G , K ) ( _dr , dr ) = ( dr , dup_degree ( r ) ) if ( dr < dg ) : break elif ( not ( dr < _dr ) ) : raise PolynomialDivisionFailed ( f , g , K ) return dup_mul_ground ( r , ( lc_g ** N ) , K )
polynomial pseudo-remainder in k[x] .