# HG changeset patch
# User Mario Pernici <mario.pernici@gmail.com>
# Date 1297264977 3600
# Node ID 4fc3ac12bee5ee0c652e2289b2b0c2b0b5f44506
# Parent 34aa7eff3b5a026162349dc6658d6a75a4f8fb54
added _square_trunc_generic
diff r 34aa7eff3b5a r 4fc3ac12bee5 sage/rings/polynomial/polynomial_element.pyx
a

b


1724  1724  return self._parent(coeffs) 
1725  1725  
1726  1726  def _mul_trunc_generic(self, right, prec): 
1727   # TODO optimize case self is right 
1728  1727  # merge with _mul_generic? 
 1728  if right is self: 
 1729  return self._square_trunc_generic(prec) 
1729  1730  x = self.list() 
1730  1731  y = right.list() 
1731  1732  cdef Py_ssize_t i, k, start, end 
… 
… 

1763  1764  coeffs[i+j] += two * x[i] * x[j] 
1764  1765  return self._parent(coeffs) 
1765  1766  
 1767  def _square_trunc_generic(self, prec): 
 1768  x = self.list() 
 1769  cdef Py_ssize_t i, k, start, end 
 1770  cdef Py_ssize_t d = len(x)1 
 1771  if d == 1: 
 1772  return self 
 1773  elif d == 0: 
 1774  return [x[0]**2] 
 1775  coeffs = [] 
 1776  if d == prec1: 
 1777  coeffs.append(x[0]**2) 
 1778  for k from 1 <= k <= prec1: 
 1779  k2 = k//2 
 1780  s = x[0]*x[k] 
 1781  if k%2 == 0: 
 1782  for i from 0 < i < k2: 
 1783  s += x[i]*x[ki] 
 1784  s *= 2 
 1785  s += x[k2]**2 
 1786  else: 
 1787  for i from 0 < i <= k2: 
 1788  s += x[i]*x[ki] 
 1789  s *= 2 
 1790  coeffs.append(s) 
 1791  return self._parent(coeffs) 
 1792  for k from 0 <= k <= min(2*d,prec1): 
 1793  start = 0 if k <= d else kd # max(0, kd) 
 1794  end = k if k <= d else d # min(k, d1) 
 1795  sum = x[start] * x[kstart] 
 1796  for i from start < i <= end: 
 1797  sum += x[i] * x[ki] 
 1798  coeffs.append(sum) 
 1799  return self._parent(coeffs) 
 1800  
1766  1801  def _mul_fateman(self, right): 
1767  1802  r""" 
1768  1803  Returns the product of two polynomials using Kronecker's trick to 