-
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α^4 + 2α^3 + 2α^2 + 2α + 1, 2α + 1, 2α^2 + 2α, 2α^3 + α^2 + 2, 2α^4 + 2α^3 + 2α^2 + 2, 2α, 2α^3 + α^2 + 2α + 2, α^4 + 2α^2 + 1, α^3 + α^2, α^3 + 2α^2 + α + 1], order=3^5) In [4]: i = x.log(); i Out[4]: array([238, 126, 191, 233, 204, 122, 182, 92, 71, 61]) 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([ 68, 36, 141, 153, 162, 104, 52, 130, 3, 173]) 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(α^3, order=3^5) In [11]: bases = GF.primitive_elements In [12]: i = x.log(bases); i Out[12]: array([ 3, 221, 49, 183, 175, 29, 61, 139, 171, 185, 85, 1, 235, 97, 67, 5, 213, 39, 225, 145, 181, 35, 101, 127, 57, 89, 95, 203, 111, 161, 149, 151, 223, 109, 79, 73, 69, 189, 215, 37, 137, 7, 131, 135, 115, 207, 83, 59, 205, 105, 211, 87, 65, 41, 117, 155, 125, 47, 45, 119, 229, 23, 63, 51, 107, 227, 233, 93, 31, 239, 159, 113, 81, 217, 129, 75, 167, 157, 53, 199, 27, 17, 173, 197, 163, 103, 133, 141, 219, 177, 153, 21, 169, 123, 19, 195, 237, 13, 71, 43, 25, 179, 147, 9, 15, 201, 91, 241, 193, 191]) In [13]: np.all(bases ** i == x) Out[13]: True