classmethod galois.Array.repr(element_repr: 'int' | 'poly' | 'power' = 'int') Generator[None, None, None]

Sets the element representation for all arrays from this FieldArray subclass.

The element representation can be set to either the integer, polynomial, or power representation. See Element Representation for a further discussion.

This function updates element_repr.

Danger

For the power representation, numpy.log() is computed on each element. So for large fields without lookup tables, displaying arrays in the power representation may take longer than expected.

Parameters
element_repr: 'int' | 'poly' | 'power' = 'int'

The field element representation.

Returns

A context manager for use in a with statement. If permanently setting the element representation, disregard the return value.

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]