-
classmethod galois.FieldArray.repr(element_repr: Literal[int] | Literal[poly] | Literal[power] =
'int'
) Generator[None, None, None] Sets the element representation for all arrays from this
FieldArray
subclass.- Parameters:¶
- element_repr: Literal[int] | Literal[poly] | Literal[power] =
'int'
¶ The field element representation to be set.
"int"
(default): The integer representation."poly"
: The polynomial representation."power"
: The power representation.
Slower performance
To display elements in the power representation,
galois
must compute the discrete logarithm of each element displayed. For large fields or fields using explicit calculation, this process can take a while. However, when using lookup tables this representation is just as fast as the others.
- element_repr: Literal[int] | Literal[poly] | Literal[power] =
- Returns:¶
A context manager for use in a
with
statement. If permanently setting the element representation, disregard the return value.
Notes¶
This function updates
element_repr
.Examples¶
The default element representation is the integer representation.
In [1]: GF = galois.GF(3**2) In [2]: x = GF.elements; x Out[2]: GF([0, 1, 2, 3, 4, 5, 6, 7, 8], order=3^2)
Permanently set the element representation by calling
repr()
.In [3]: GF.repr("poly"); In [4]: x Out[4]: GF([ 0, 1, 2, α, α + 1, α + 2, 2α, 2α + 1, 2α + 2], order=3^2)
In [5]: GF.repr("power"); In [6]: x Out[6]: GF([ 0, 1, α^4, α, α^2, α^7, α^5, α^3, α^6], order=3^2)
Temporarily modify the element representation by using
repr()
as a context manager.In [7]: print(x) [0 1 2 3 4 5 6 7 8] In [8]: with GF.repr("poly"): ...: print(x) ...: [ 0 1 2 α α + 1 α + 2 2α 2α + 1 2α + 2] # Outside the context manager, the element representation reverts to its previous value In [9]: print(x) [0 1 2 3 4 5 6 7 8]
In [10]: print(x) [0 1 2 3 4 5 6 7 8] In [11]: with GF.repr("power"): ....: print(x) ....: [ 0 1 α^4 α α^2 α^7 α^5 α^3 α^6] # Outside the context manager, the element representation reverts to its previous value In [12]: print(x) [0 1 2 3 4 5 6 7 8]