In [51]:
import plotly.io as pio
import plotly.express as px
import galois
import numpy as np
pio.renderers.default = "notebook"
In [52]:
xs = range(256)
ys = list(map(lambda x: x ** 2, xs))
px.scatter(x=xs, y=ys)
In [56]:
import plotly.express as px
import galois
GF = galois.GF(2**8)
xs = GF.Range(0, 256)
ys = list(map(lambda x: x ** 2, xs))
px.scatter(x=xs, y=ys)
If the number of elements in our ring is prime, then all of our elements have multiplicative inverses and we have a finite field.
In [59]:
xs = np.arange(0, 5)
xs[:, np.newaxis] * xs % 5
Out[59]:
array([[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 1, 3], [0, 3, 1, 4, 2], [0, 4, 3, 2, 1]])
If we have a non-prime number, we aren't able to assign multiplicative inverses to all elements and we can't have a field.
In [63]:
xs = np.arange(0, 4)
xs[:, np.newaxis] * xs % 4
Out[63]:
array([[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 0, 2], [0, 3, 2, 1]])
In [64]:
GF = galois.GF(2**2)
xs = GF.Range(0, 4)
xs[:, np.newaxis] * xs
Out[64]:
GF([[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]], order=2^2)
In [76]:
GF.irreducible_poly
Out[76]:
Poly(x^2 + x + 1, GF(2))
In [75]:
GF2 = galois.GF(2)
galois.Poly([1, 1, 1], field=GF2)
galois.Poly([1, 0, 0], field=GF2) % GF.irreducible_poly
Out[75]:
Poly(x + 1, GF(2))