def test_mod(self): str1, str2 = "1010110101011", "1010101011" p1, p2 = Polynome(value=str1), Polynome(value=str2) p = p1 % p2 self.assertEqual(p2 % p1, p1) print p1.order, p2.order print p1.printf(), p2.printf(), p.printf()
def test_add(self): str1, str2 = "1010110101011", "1010101011" p1, p2 = Polynome(value=str1), Polynome(value=str2) p = p1 + p2 print p1.order, p2.order, p.order self.assertEqual(p.order, len(str1)) self.assertEqual((p1+p1).order, 0) print p1.printf(), p2.printf(), p.printf()
def generate(self, gen, module): self.__gfGen = gen % self.__gfBound self.__gfModule = module a, c = Polynome(value=gen), Polynome(value=gen) m = Polynome(value=module) a2n, uniq = {0: 1}, set([1]) order = 0 while order < len(uniq) and len(a2n) < self.__gfMaximum: order = (order + 1) % self.__gfMaximum a2n[order] = val = c.value c = a * c % m uniq.add(val) self.__gfMaximum = len(uniq - set([0])) n2a = {v: k for k, v in a2n.items()} if n2a.get(self.__gfMaximum): n2a[0] = n2a[self.__gfMaximum] #a2n[n2a[0]] = 0 self.__ord2val = tuple(map(lambda x: a2n[x], xrange(len(a2n)))) self.__val2ord = n2a return self
def main(): setting = Setting() setting.parser() poly = Polynome(*setting.tab, setting.verbose, setting.graph) poly.process() poly.final() exit(0)
def test_printf(self): value = "1010110101011" polynome = "x^12+x^10+x^8+x^7+x^5+x^3+x^1+x^0" p = Polynome(value=value) self.assertEqual(value, p.printf()) self.assertEqual(value, p.printf(binary=True)) self.assertEqual(polynome, p.printf(polynome=True)) self.assertEqual(value, p.printf(polynome=True, binary=True)) self.assertEqual(value[::-1], p.printf(binary=True, desc=True)) self.assertEqual(value[::-1], p.printf(desc=True)) self.assertEqual("+".join(polynome.split("+")[::-1]), p.printf(polynome=True, desc=True)) p = Polynome(order=12) value = "0"*12 polynome = "" self.assertEqual(value, p.printf()) self.assertEqual(value, p.printf(binary=True)) self.assertEqual(polynome, p.printf(polynome=True)) self.assertEqual(value, p.printf(polynome=True, binary=True)) self.assertEqual(value[::-1], p.printf(binary=True, desc=True)) self.assertEqual(value[::-1], p.printf(desc=True)) self.assertEqual("+".join(polynome.split("+")[::-1]), p.printf(polynome=True, desc=True))
def test_mul(self): p1, p2 = Polynome(value="1010110101011"), Polynome(value="1010101011") p = p1 * p2 print p1.order, p2.order print p1.printf(), p2.printf(), p.printf()
def division(a): a1 = Polynome(str(a)) text = "(" + str(a1) + ")=" + str(Polynome.nmr(a1)) return text
def division(a): a1 = Polynome(str(a)) text = "(" + str(a1) + ")'=" + str(Polynome.derivative(a1)) return text
def sum(a, b): a1 = Polynome(str(a)) b1 = Polynome(str(b)) text = "GCD( [" + str(a1) + "] , [" + str(b1) + "] ) = " + str(Polynome.gcd(a1,b1)) return text
def sum(a, b): a1 = Polynome(str(a)) b1 = Polynome(str(b)) text = "( "+str(a1)+ " ) % (" + str(b1) + ") = " + str(a1 % b1) return text