-
classmethod galois.FieldArray.arithmetic_table(operation: '+' | '-' | '*' | '/', x: FieldArray | None =
None
, y: FieldArray | None =None
) str Generates the specified arithmetic table for the finite field.
- Parameters¶
- operation: '+' | '-' | '*' | '/'¶
The arithmetic operation.
- x: FieldArray | None =
None
¶ Optionally specify the \(x\) values for the arithmetic table. The default is
None
which represents \(\{0, \dots, p^m - 1\}\).- y: FieldArray | None =
None
¶ Optionally specify the \(y\) values for the arithmetic table. The default is
None
which represents \(\{0, \dots, p^m - 1\}\) for addition, subtraction, and multiplication and \(\{1, \dots, p^m - 1\}\) for division.
- Returns¶
A string representation of the arithmetic table.
Examples¶
Arithmetic tables can be displayed using any element representation.
In [1]: GF = galois.GF(3**2) In [2]: print(GF.arithmetic_table("+")) x + y | 0 1 2 3 4 5 6 7 8 ------|--------------------------- 0 | 0 1 2 3 4 5 6 7 8 1 | 1 2 0 4 5 3 7 8 6 2 | 2 0 1 5 3 4 8 6 7 3 | 3 4 5 6 7 8 0 1 2 4 | 4 5 3 7 8 6 1 2 0 5 | 5 3 4 8 6 7 2 0 1 6 | 6 7 8 0 1 2 3 4 5 7 | 7 8 6 1 2 0 4 5 3 8 | 8 6 7 2 0 1 5 3 4
In [3]: GF = galois.GF(3**2, display="poly") In [4]: print(GF.arithmetic_table("+")) x + y | 0 1 2 α α + 1 α + 2 2α 2α + 1 2α + 2 -------|------------------------------------------------------------------------ 0 | 0 1 2 α α + 1 α + 2 2α 2α + 1 2α + 2 1 | 1 2 0 α + 1 α + 2 α 2α + 1 2α + 2 2α 2 | 2 0 1 α + 2 α α + 1 2α + 2 2α 2α + 1 α | α α + 1 α + 2 2α 2α + 1 2α + 2 0 1 2 α + 1 | α + 1 α + 2 α 2α + 1 2α + 2 2α 1 2 0 α + 2 | α + 2 α α + 1 2α + 2 2α 2α + 1 2 0 1 2α | 2α 2α + 1 2α + 2 0 1 2 α α + 1 α + 2 2α + 1 | 2α + 1 2α + 2 2α 1 2 0 α + 1 α + 2 α 2α + 2 | 2α + 2 2α 2α + 1 2 0 1 α + 2 α α + 1
In [5]: GF = galois.GF(3**2, display="power") In [6]: print(GF.arithmetic_table("+")) x + y | 0 1 α α^2 α^3 α^4 α^5 α^6 α^7 ------|--------------------------------------------- 0 | 0 1 α α^2 α^3 α^4 α^5 α^6 α^7 1 | 1 α^4 α^2 α^7 α^6 0 α^3 α^5 α α | α α^2 α^5 α^3 1 α^7 0 α^4 α^6 α^2 | α^2 α^7 α^3 α^6 α^4 α 1 0 α^5 α^3 | α^3 α^6 1 α^4 α^7 α^5 α^2 α 0 α^4 | α^4 0 α^7 α α^5 1 α^6 α^3 α^2 α^5 | α^5 α^3 0 1 α^2 α^6 α α^7 α^4 α^6 | α^6 α^5 α^4 0 α α^3 α^7 α^2 1 α^7 | α^7 α α^6 α^5 0 α^2 α^4 1 α^3
An arithmetic table may also be constructed from arbitrary \(x\) and \(y\).
In [7]: GF = galois.GF(3**2) In [8]: x = GF([7, 2, 8]); x Out[8]: GF([7, 2, 8], order=3^2) In [9]: y = GF([1, 4, 5, 3]); y Out[9]: GF([1, 4, 5, 3], order=3^2) In [10]: print(GF.arithmetic_table("+", x=x, y=y)) x + y | 1 4 5 3 ------|------------ 7 | 8 2 0 1 2 | 0 3 4 5 8 | 6 0 1 2
In [11]: GF = galois.GF(3**2, display="poly") In [12]: x = GF([7, 2, 8]); x Out[12]: GF([2α + 1, 2, 2α + 2], order=3^2) In [13]: y = GF([1, 4, 5, 3]); y Out[13]: GF([ 1, α + 1, α + 2, α], order=3^2) In [14]: print(GF.arithmetic_table("+", x=x, y=y)) x + y | 1 α + 1 α + 2 α -------|-------------------------------- 2α + 1 | 2α + 2 2 0 1 2 | 0 α α + 1 α + 2 2α + 2 | 2α 0 1 2
In [15]: GF = galois.GF(3**2, display="power") In [16]: x = GF([7, 2, 8]); x Out[16]: GF([α^3, α^4, α^6], order=3^2) In [17]: y = GF([1, 4, 5, 3]); y Out[17]: GF([ 1, α^2, α^7, α], order=3^2) In [18]: print(GF.arithmetic_table("+", x=x, y=y)) x + y | 1 α^2 α^7 α ------|-------------------- α^3 | α^6 α^4 0 1 α^4 | 0 α α^2 α^7 α^6 | α^5 0 1 α^4