-
galois.FieldArray.log(base: ElementLike | ArrayLike | None =
None
) int | ndarray Computes the discrete logarithm of the array \(x\) base \(\beta\).
- Parameters:¶
- base: ElementLike | ArrayLike | None =
None
¶ A primitive element or elements \(\beta\) of the finite field that is the base of the logarithm. The default is
None
which usesprimitive_element
.Slower performance
If the
FieldArray
is configured to use lookup tables (ufunc_mode == "jit-lookup"
) and this method is invoked with a base different fromprimitive_element
, then explicit calculation will be used (which is slower than using lookup tables).
- 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) In [2]: alpha = GF.primitive_element; alpha Out[2]: GF(3, order=3^5) In [3]: x = GF.Random(10, low=1); x Out[3]: GF([118, 93, 131, 235, 4, 121, 76, 194, 38, 174], order=3^5) In [4]: i = x.log(); i Out[4]: array([ 83, 215, 218, 239, 69, 64, 22, 141, 230, 29]) In [5]: np.array_equal(alpha ** i, x) Out[5]: True
In [6]: GF = galois.GF(3**5, repr="poly") In [7]: alpha = GF.primitive_element; alpha Out[7]: GF(α, order=3^5) In [8]: x = GF.Random(10, low=1); x Out[8]: GF([ α^4 + 2α^2 + 2α, α^4 + 2α, α + 1, 2α^2 + α + 2, α^4 + α^3 + 2, 2α, α^3 + 2α^2 + 1, 2α^4 + 2α^3 + 2α^2 + 2α, α^3 + α^2 + α, α^4 + α^3 + 2α^2 + 1], order=3^5) In [9]: i = x.log(); i Out[9]: array([150, 16, 69, 17, 119, 122, 112, 237, 11, 25]) In [10]: np.array_equal(alpha ** i, x) Out[10]: True
In [11]: GF = galois.GF(3**5, repr="power") In [12]: alpha = GF.primitive_element; alpha Out[12]: GF(α, order=3^5) In [13]: x = GF.Random(10, low=1); x Out[13]: GF([ α^54, α^200, α^88, α^56, α^55, α^192, α^229, α^14, α^62, α^171], order=3^5) In [14]: i = x.log(); i Out[14]: array([ 54, 200, 88, 56, 55, 192, 229, 14, 62, 171]) In [15]: np.array_equal(alpha ** i, x) Out[15]: True
With the default argument,
numpy.log()
andlog()
are equivalent.In [16]: np.array_equal(np.log(x), x.log()) Out[16]: True
Compute the logarithm of \(x\) with a different base \(\beta\), which is another primitive element of the field.
In [17]: beta = GF.primitive_elements[-1]; beta Out[17]: GF(242, order=3^5) In [18]: i = x.log(beta); i Out[18]: array([ 50, 230, 198, 16, 33, 124, 221, 4, 156, 239]) In [19]: np.array_equal(beta ** i, x) Out[19]: True
In [20]: beta = GF.primitive_elements[-1]; beta Out[20]: GF(2α^4 + 2α^3 + 2α^2 + 2α + 2, order=3^5) In [21]: i = x.log(beta); i Out[21]: array([ 50, 230, 198, 16, 33, 124, 221, 4, 156, 239]) In [22]: np.array_equal(beta ** i, x) Out[22]: True
In [23]: beta = GF.primitive_elements[-1]; beta Out[23]: GF(α^185, order=3^5) In [24]: i = x.log(beta); i Out[24]: array([ 50, 230, 198, 16, 33, 124, 221, 4, 156, 239]) In [25]: np.array_equal(beta ** i, x) Out[25]: True
Compute the logarithm of a single finite field element base all of the primitive elements of the field.
In [26]: x = GF.Random(low=1); x Out[26]: GF(234, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([133, 37, 75, 127, 95, 237, 123, 193, 79, 135, 219, 125, 93, 25, 147, 141, 5, 35, 53, 217, 119, 19, 41, 145, 107, 235, 17, 207, 81, 39, 233, 241, 45, 73, 195, 171, 155, 151, 13, 27, 185, 149, 161, 177, 97, 223, 211, 115, 215, 57, 239, 227, 139, 43, 105, 15, 137, 67, 59, 113, 69, 213, 131, 83, 65, 61, 85, 9, 3, 109, 31, 89, 203, 21, 153, 179, 63, 23, 91, 191, 229, 189, 87, 183, 47, 49, 169, 201, 29, 103, 7, 205, 71, 129, 197, 175, 101, 173, 163, 51, 221, 111, 225, 157, 181, 199, 1, 117, 167, 159]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(2α^4 + 2α^3 + 2α^2 + 1, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([239, 21, 193, 59, 67, 213, 181, 103, 71, 57, 157, 241, 7, 145, 175, 237, 29, 203, 17, 97, 61, 207, 141, 115, 185, 153, 147, 39, 131, 81, 93, 91, 19, 133, 163, 169, 173, 53, 27, 205, 105, 235, 111, 107, 127, 35, 159, 183, 37, 137, 31, 155, 177, 201, 125, 87, 117, 195, 197, 123, 13, 219, 179, 191, 135, 15, 9, 149, 211, 3, 83, 129, 161, 25, 113, 167, 75, 85, 189, 43, 215, 225, 69, 45, 79, 139, 109, 101, 23, 65, 89, 221, 73, 119, 223, 47, 5, 229, 171, 199, 217, 63, 95, 233, 227, 41, 151, 1, 49, 51]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^43, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([ 43, 183, 57, 203, 169, 93, 229, 137, 31, 151, 89, 95, 61, 19, 73, 233, 149, 75, 79, 223, 13, 179, 157, 207, 91, 227, 71, 167, 139, 49, 119, 67, 131, 191, 3, 159, 21, 47, 97, 127, 189, 181, 103, 241, 35, 63, 141, 39, 115, 53, 201, 37, 125, 23, 225, 205, 17, 109, 161, 173, 217, 7, 177, 5, 1, 27, 113, 123, 41, 199, 101, 87, 193, 45, 155, 107, 135, 153, 195, 29, 145, 163, 221, 81, 239, 105, 51, 85, 235, 117, 15, 59, 83, 69, 111, 133, 9, 25, 211, 213, 197, 65, 171, 129, 215, 219, 175, 147, 185, 237]) In [37]: np.all(bases ** i == x) Out[37]: True