Extremely large fields

Arbitrarily-large \(\mathrm{GF}(2^m)\), \(\mathrm{GF}(p)\), \(\mathrm{GF}(p^m)\) fields are supported. Because field elements can’t be represented with numpy.int64, we use dtype=object in the numpy arrays. This enables use of native python int, which doesn’t overflow. It comes at a performance cost though. There are no JIT-compiled arithmetic ufuncs. All the arithmetic is done in pure python. All the same array operations, broadcasting, ufunc methods, etc are supported.

Large GF(p) fields

In [1]: prime = 36893488147419103183

In [2]: galois.is_prime(prime)
Out[2]: True

In [3]: GF = galois.GF(prime)

In [4]: print(GF)
<class 'numpy.ndarray' over GF(36893488147419103183)>

In [5]: a = GF.Random(10); a
Out[5]: 
GF([30854606659339420874, 4421830543909009536, 2448863568344492219,
    34011112280950332785, 5786904973023557440, 27754397132812983493,
    25567564647666155429, 187877405147098142, 28242416241873434289,
    15730891211189878489], order=36893488147419103183)

In [6]: b = GF.Random(10); b
Out[6]: 
GF([22484712070955705870, 20868596969784923375, 22629324920265060581,
    34056675688434072287, 5109846737591426729, 14772296296814139759,
    2447963610306050746, 32207284752544187550, 13319674696309166468,
    17283690769779619573], order=36893488147419103183)

In [7]: a + b
Out[7]: 
GF([16445830582876023561, 25290427513693932911, 25078188488609552800,
    31174299821965301889, 10896751710614984169, 5633205282208020069,
    28015528257972206175, 32395162157691285692, 4668602790763497574,
    33014581980969498062], order=36893488147419103183)

Large GF(2^m) fields

In [8]: GF = galois.GF(2**100)

In [9]: print(GF)
<class 'numpy.ndarray' over GF(2^100)>

In [10]: a = GF([2**8, 2**21, 2**35, 2**98]); a
Out[10]: 
GF([256, 2097152, 34359738368, 316912650057057350374175801344],
   order=2^100)

In [11]: b = GF([2**91, 2**40, 2**40, 2**2]); b
Out[11]: 
GF([2475880078570760549798248448, 1099511627776, 1099511627776, 4],
   order=2^100)

In [12]: a + b
Out[12]: 
GF([2475880078570760549798248704, 1099513724928, 1133871366144,
    316912650057057350374175801348], order=2^100)

# Display elements as polynomials
In [13]: GF.display("poly")
Out[13]: <galois.gf.DisplayContext at 0x7f906cc8bfd0>

In [14]: a
Out[14]: GF([x^8, x^21, x^35, x^98], order=2^100)

In [15]: b
Out[15]: GF([x^91, x^40, x^40, x^2], order=2^100)

In [16]: a + b
Out[16]: GF([x^91 + x^8, x^40 + x^21, x^40 + x^35, x^98 + x^2], order=2^100)

In [17]: a * b
Out[17]: 
GF([x^99, x^61, x^75,
    x^57 + x^56 + x^55 + x^52 + x^48 + x^47 + x^46 + x^45 + x^44 + x^43 + x^41 + x^37 + x^36 + x^35 + x^34 + x^31 + x^30 + x^27 + x^25 + x^24 + x^22 + x^20 + x^19 + x^16 + x^15 + x^11 + x^9 + x^8 + x^6 + x^5 + x^3 + 1],
   order=2^100)

# Reset the display mode
In [18]: GF.display()
Out[18]: <galois.gf.DisplayContext at 0x7f906cc8bba8>