-
galois.FieldArray.log(base: ElementLike | ArrayLike | None =
None
) ndarray Computes the logarithm of the array
base .Important
If the Galois field is configured to use lookup tables,
ufunc_mode == "jit-lookup"
, and this function is invoked with a base different fromprimitive_element
, then explicit calculation will be used.- Parameters¶
- base: ElementLike | ArrayLike | None =
None
¶ A primitive element(s)
of the finite field that is the base of the logarithm. The default isNone
which usesprimitive_element
.
- base: ElementLike | ArrayLike | None =
- Returns¶
An integer array
of powers of such that . The return array shape obeys NumPy broadcasting rules.
Examples¶
Compute the logarithm of
with default base , which is the specified primitive element of the field.In [1]: GF = galois.GF(3**5, display="poly") In [2]: alpha = GF.primitive_element; alpha Out[2]: GF(α, order=3^5) In [3]: x = GF.Random(10, low=1); x Out[3]: GF([ 2α^4 + α^2 + 1, α^4 + α^3 + α + 1, 2α^4 + 2α^2 + α + 2, 2α^4 + 2α^2 + α + 1, α^4 + α^3, 2α^4 + 2α^3 + 2α^2 + α + 1, 2α^4 + 2α^3 + 2α^2 + α, α^4 + α^3 + α^2 + 2, α^4 + 2α + 2, α^2 + α + 2], order=3^5) In [4]: i = x.log(); i Out[4]: array([206, 34, 38, 156, 72, 186, 96, 118, 166, 209]) In [5]: np.array_equal(alpha ** i, x) Out[5]: True
With the default argument,
numpy.log()
andlog()
are equivalent.In [6]: np.array_equal(np.log(x), x.log()) Out[6]: True
Compute the logarithm of
with a different base , which is another primitive element of the field.In [7]: beta = GF.primitive_elements[-1]; beta Out[7]: GF(2α^4 + 2α^3 + 2α^2 + 2α + 2, order=3^5) In [8]: i = x.log(beta); i Out[8]: array([128, 148, 80, 10, 228, 226, 62, 172, 82, 77]) In [9]: np.array_equal(beta ** i, x) Out[9]: True
Compute the logarithm of a single finite field element base all of the primitive elements of the field.
In [10]: x = GF.Random(low=1); x Out[10]: GF(2α^3 + α, order=3^5) In [11]: bases = GF.primitive_elements In [12]: i = x.log(bases); i Out[12]: array([196, 80, 136, 98, 140, 120, 194, 208, 40, 148, 68, 146, 188, 126, 102, 4, 122, 128, 180, 116, 48, 28, 226, 150, 94, 168, 76, 114, 234, 32, 216, 24, 130, 184, 160, 10, 152, 6, 172, 78, 158, 54, 8, 108, 92, 214, 18, 144, 164, 84, 72, 118, 52, 178, 142, 124, 100, 86, 36, 192, 38, 212, 2, 186, 134, 230, 138, 26, 170, 46, 224, 42, 210, 222, 200, 60, 182, 174, 236, 14, 70, 62, 90, 206, 82, 34, 58, 16, 30, 190, 74, 162, 232, 50, 112, 156, 238, 204, 202, 228, 20, 240, 166, 104, 12, 64, 218, 96, 106, 56]) In [13]: np.all(bases ** i == x) Out[13]: True