<br><span style="font-family: arial,helvetica,sans-serif;">Hello!</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">Here is my representation of polynomials in Python as dictionaries.</span><br style="font-family: arial,helvetica,sans-serif;">
<br style="font-family: arial,helvetica,sans-serif;"><pre style="font-family: arial,helvetica,sans-serif;">zero = {}                <br>one = {0:1}<br>two = {0:2}<br>x = {1:1}<br>x2 = {2:1}                  # x^2<br>poly = {2:3, 1:4, 0:5}   # 3*x^2 + 4*x + 5<br>
</pre># Some functions...<br style="font-family: arial,helvetica,sans-serif;"><pre style="font-family: arial,helvetica,sans-serif;">def add_poly(poly1, poly2):   # w1(x)+w2(x)<br>        tmp = dict(poly1)<br>        for k in poly2:<br>
                tmp[k] = tmp.get(k,0) + poly2[k]<br>                if tmp[k] == 0: del tmp[k]<br>        return tmp<br><br>def times_poly(number, poly):   # n*w(x)<br>        if number == 0: return {}<br>        tmp = {}<br>        for k in poly:<br>                tmp[k] = number*poly[k]<br>
        return tmp<br><br>def mul_poly(poly1, poly2):   # w1(x)*w2(x)<br>        tmp = {}<br>        for i in poly1:<br>                for j in poly2:<br>                        tmp[i+j] = tmp.get(i+j,0) + poly1[i]*poly2[j]<br>        return tmp<br><br>def diff_poly(poly):   #  [c*x^n]&#39; = c*n*x^(n-1)<br>
        tmp = {}<br>        for i in poly:<br>                tmp[i-1] = i*poly[i]<br>        if -1 in tmp: del tmp[-1]<br>        return tmp<br><br>def eval_poly(poly, x):   # w(x), Horner<br>        i = max(i for i in poly)<br>        p = poly[i]<br>        while i &gt; 0:<br>                i = i-1<br>
                p = p * x + poly.get(i,0)<br>        return p<br><br>def combine_poly(poly1, poly2):   # w1(w2(x)),  Horner<br>        i = max(k for k in poly1)<br>        tmp = {0:poly1[i]}<br>        while i &gt; 0:<br>                i = i-1<br>                tmp = add_poly(mul_poly(tmp, poly2), {0:poly1.get(i,0)})<br>
        return tmp<br><br>def pow_poly(poly, n):<br>        # return combine_poly({n:1}, poly)<br>        tmp = {0:1}<br>        while n &gt; 0:<br>                tmp = mul_poly(tmp, poly)<br>                n = n-1<br>        return tmp<br></pre><br>Regards,<br>Andrzej Kapanowski<br style="font-family: arial,helvetica,sans-serif;">
<br style="font-family: arial,helvetica,sans-serif;"><br>