# module 'poly' -- Polynomials
# A polynomial is represented by a list of coefficients, e.g.,
# [1, 10, 5] represents 1*x**0 + 10*x**1 + 5*x**2 (or 1 + 10x + 5x**2).
# There is no way to suppress internal zeros; trailing zeros are
# taken out by normalize().
def normalize(p
): # Strip unnecessary zero coefficients
if len(a
) < len(b
): a
, b
= b
, a
# make sure a is the longest
neg_b
= map(lambda x
: -x
, b
[:])
def one(power
, coeff
): # Representation of coeff * x**power
for i
in range(power
): res
.append(0)
res
= plus(res
, one(i
+j
, a
[i
]*b
[j
]))
def power(a
, n
): # Raise polynomial a to the positive integral power n
return times(power(a
, n
-1), a
)
def der(a
): # First derivative
for i
in range(len(res
)):
# Computing a primitive function would require rational arithmetic...