def dmp_mul(f, g, u, K):
 if (not u):
  return dup_mul(f, g, K)
 if (f == g):
  return dmp_sqr(f, u, K)
 df = dmp_degree(f, u)
 if (df < 0):
  return f
 dg = dmp_degree(g, u)
 if (dg < 0):
  return g
 (h, v) = ([], (u - 1))
 for i in range(0, ((df + dg) + 1)):
  coeff = dmp_zero(v)
  for j in range(max(0, (i - dg)), (min(df, i) + 1)):
   coeff = dmp_add(coeff, dmp_mul(f[j], g[(i - j)], v, K), v, K)
  h.append(coeff)
 return dmp_strip(h, u)

def dmp_mul ( f , g , u , K ) : if ( not u ) : return dup_mul ( f , g , K ) if ( f == g ) : return dmp_sqr ( f , u , K ) df = dmp_degree ( f , u ) if ( df < 0 ) : return f dg = dmp_degree ( g , u ) if ( dg < 0 ) : return g ( h , v ) = ( [ ] , ( u - 1 ) ) for i in range ( 0 , ( ( df + dg ) + 1 ) ) : coeff = dmp_zero ( v ) for j in range ( max ( 0 , ( i - dg ) ) , ( min ( df , i ) + 1 ) ) : coeff = dmp_add ( coeff , dmp_mul ( f [ j ] , g [ ( i - j ) ] , v , K ) , v , K ) h . append ( coeff ) return dmp_strip ( h , u )
multiply dense polynomials in k[x] .