-
galois.FieldArray.log(base: ElementLike | ArrayLike | None =
None
) ndarray Computes the logarithm of the array \(x\) base \(\beta\).
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) \(\beta\) of the finite field that is the base of the logarithm. The default is
None
which usesprimitive_element
.
- base: ElementLike | ArrayLike | None =
- Returns¶
An integer array \(i\) of powers of \(\beta\) such that \(\beta^i = x\). The return array shape obeys NumPy broadcasting rules.
Examples¶
Compute the logarithm of \(x\) with default base \(\alpha\), 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, 2α^4 + α + 1, α^4 + 2α^2 + α + 2, 2α^4 + 2α^2 + 2α, α^4 + α^2 + 2, α^4 + 2α^2 + 2α, 2α^2 + α + 2, α^4 + 2α + 1, 2α^3 + α + 1, α^4 + α^3 + α + 2], order=3^5) In [4]: i = x.log(); i Out[4]: array([ 2, 45, 232, 94, 14, 150, 17, 130, 28, 13]) 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 \(x\) with a different base \(\beta\), 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([208, 203, 170, 96, 4, 112, 195, 210, 8, 21]) 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 + α^2 + 2α + 1, order=3^5) In [11]: bases = GF.primitive_elements In [12]: i = x.log(bases); i Out[12]: array([172, 6, 228, 86, 192, 130, 190, 64, 124, 120, 114, 138, 2, 76, 50, 206, 112, 58, 74, 166, 52, 232, 144, 102, 122, 182, 42, 184, 72, 196, 234, 26, 40, 38, 12, 152, 84, 188, 146, 24, 30, 240, 170, 238, 140, 10, 80, 156, 218, 212, 78, 148, 16, 92, 174, 94, 68, 194, 160, 208, 142, 28, 224, 20, 4, 108, 210, 8, 164, 70, 162, 106, 46, 180, 136, 186, 56, 128, 54, 116, 96, 168, 158, 82, 230, 178, 204, 98, 214, 226, 60, 236, 90, 34, 202, 48, 36, 100, 118, 126, 62, 18, 200, 32, 134, 150, 216, 104, 14, 222]) In [13]: np.all(bases ** i == x) Out[13]: True
Last update:
Jul 28, 2022