Skip to content

Latest commit

 

History

History
113 lines (71 loc) · 2.72 KB

field_arithmetic.rst

File metadata and controls

113 lines (71 loc) · 2.72 KB

Galois field array arithmetic

Addition, subtraction, multiplication, division

A finite field is a set that defines the operations addition, subtraction, multiplication, and division. The field is closed under these operations.

python

GF7 = galois.GF_factory(7, 1) print(GF7)

# Create a random GF(7) array with 10 elements x = GF7.Random(10); x

# Create a random GF(7) array with 10 elements, with the lowest element being 1 (used to prevent ZeroDivisionError later on) y = GF7.Random(10, low=1); y

# Addition in the finite field x + y

# Subtraction in the finite field x - y

# Multiplication in the finite field x * y

# Divison in the finite field x / y x // y

One can easily create the addition, subtraction, multiplication, and divison tables for any field. Here is an example using GF(7).

python

X, Y = np.meshgrid(GF7.Elements(), GF7.Elements(), indexing="ij") X + Y X - Y X * Y

X, Y = np.meshgrid(GF7.Elements(), GF7.Elements()[1:], indexing="ij") X / Y

Multiple addition

A finite field GF(pm) is a set that is closed under four operations: addition, subtraction, multiplication, and division. For multiplication, x * y = z for x, y, z ∈ GF(pm).

Let's define another notation x ⋅ r = z for x, z ∈ GF(pm) and r ∈ ℤ, which represents r additions of x, i.e. $x + \dotsb + x = z$. In prime fields GF(p), multiplication * and "multiple addition" are equivalent. However, in extension fields GF(pm) they are not.

Warning

There is a difference between GF8(6) * GF8(2) and GF8(6) * 2. The former represents the field element "6" multiplied by the field element "2" using field multiplication. The latter represents adding the field element "6" two times.

python

GF8 = galois.GF_factory(2, 3) print(GF8)

a = GF8.Random(10)

# Calculates a x "2" in the finite field a * GF8(2)

# Calculates a + a a * 2

Exponentiation

python

GF7 = galois.GF_factory(7, 1) print(GF7)

x = GF7.Random(10); x

# Calculates "x" * "x", note 2 is not a field element x ** 2

Logarithm

python

GF7 = galois.GF_factory(7, 1) print(GF7)

# The primitive element of the field GF7.alpha

x = GF7.Random(10, low=1); x

# Notice the outputs of log(x) are not field elements, but integers e = np.log(x); e

GF7.alpha**e

np.all(GF7.alpha**e == x)