From 9b3bea00c789dc043b078c7930d90e01860a6bbc Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 20 Feb 2018 18:08:54 -0500 Subject: [PATCH] started work on field class: --- GF.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 GF.py diff --git a/GF.py b/GF.py new file mode 100644 index 0000000..b40adc9 --- /dev/null +++ b/GF.py @@ -0,0 +1,44 @@ +from math import log + +#defines the field itself +#responsible for creating elements and performing operations +#all elements contain a pointer to the field that created them +#elements from different fields can't interact, even if they're equivalent + +class GF: + def __init__(self, *args): + + def characteristic(a): + if a%2 == 0: + b = log(a, 2) + if b != int(b): + raise ValueError('%i is not a prime power' % a) + return 2, int(b) + i = 3 + while i <= 23: + if a%i == 0: + b = log(a, i) + if b != int(b): + raise ValueError('%i is not a prime power' % a) + return i, int(b) + i += 2 + + if len(args) == 1: + p, n = characteristic(args[0]) + elif len(args) > 2: + raise TypeError('too many arguments') + else: + p, n = args + self.characteristic = p + self.order = p**n + self.degree = n + file = open('gf' + str(p) + '.txt', 'r') + pol = file.readlines()[n-2] + file.close() + pol = pol.split(',') + #integer coefficients of defining polynomial + #index is the exponent + self.poly = [None]*n + [1] + if p == 2: + self.poly[0] = 1 + for i in pol \ No newline at end of file