-
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([ 69, 186, 98, 134, 91, 239, 117, 67, 55, 12], order=3^5) In [4]: i = x.log(); i Out[4]: array([ 18, 94, 35, 42, 148, 162, 12, 39, 136, 70]) 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([ 2α^3 + 2α^2 + 2α + 2, α^4 + 2α^3 + α^2 + 2α + 1, 2α^4 + 2α^3 + α + 2, α^4 + 2α^3 + α + 2, 2α^4 + α^3 + 2α^2 + α + 1, α^3 + 1, 2α^3 + 2α^2, α^4 + 2α^3 + α^2 + 2α, 2α + 2, α^4 + 2α^2 + 2α + 2], order=3^5) In [9]: i = x.log(); i Out[9]: array([236, 174, 225, 212, 178, 207, 192, 52, 190, 105]) 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([α^193, α^165, α^238, α^30, α^151, α^130, α^120, α^38, α^34, α^213], order=3^5) In [14]: i = x.log(); i Out[14]: array([193, 165, 238, 30, 151, 130, 120, 38, 34, 213]) 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([107, 99, 68, 216, 95, 210, 138, 80, 148, 9]) 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([107, 99, 68, 216, 95, 210, 138, 80, 148, 9]) 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([107, 99, 68, 216, 95, 210, 138, 80, 148, 9]) 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(210, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([173, 241, 83, 147, 89, 59, 49, 191, 181, 101, 223, 219, 161, 189, 153, 127, 183, 71, 149, 53, 193, 163, 97, 225, 141, 131, 235, 171, 109, 169, 203, 157, 195, 155, 119, 15, 107, 9, 137, 117, 237, 81, 133, 41, 17, 79, 27, 95, 125, 5, 229, 177, 199, 25, 213, 65, 29, 129, 175, 167, 57, 197, 3, 37, 201, 103, 207, 39, 13, 69, 215, 63, 73, 91, 179, 211, 31, 19, 233, 21, 105, 93, 135, 67, 123, 51, 87, 145, 45, 43, 111, 1, 227, 75, 47, 113, 115, 185, 61, 221, 151, 239, 7, 35, 139, 217, 85, 23, 159, 205]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(2α^4 + α^2 + 2, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([213, 203, 91, 167, 83, 123, 217, 189, 41, 67, 227, 71, 229, 111, 159, 113, 119, 107, 3, 131, 25, 65, 153, 63, 175, 27, 211, 135, 137, 57, 173, 73, 103, 237, 43, 101, 59, 109, 19, 207, 47, 13, 105, 147, 179, 177, 85, 75, 35, 195, 219, 127, 17, 7, 79, 115, 163, 191, 49, 221, 45, 181, 117, 233, 95, 145, 87, 69, 23, 29, 157, 37, 185, 161, 205, 1, 241, 15, 133, 93, 223, 239, 183, 193, 199, 53, 5, 89, 61, 225, 215, 39, 141, 21, 139, 51, 129, 197, 201, 149, 81, 125, 31, 155, 97, 235, 169, 171, 151, 9]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^123, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([123, 107, 73, 1, 157, 221, 81, 133, 235, 83, 97, 41, 197, 105, 85, 205, 21, 147, 29, 137, 161, 225, 27, 125, 159, 19, 23, 95, 195, 67, 59, 141, 189, 113, 93, 89, 167, 5, 103, 65, 51, 45, 47, 211, 117, 17, 15, 241, 177, 191, 181, 179, 3, 229, 199, 63, 43, 233, 151, 39, 193, 217, 163, 155, 31, 111, 115, 183, 61, 119, 227, 35, 175, 185, 207, 171, 71, 145, 237, 173, 139, 213, 75, 91, 149, 109, 129, 215, 25, 239, 223, 135, 153, 203, 53, 9, 37, 49, 7, 69, 57, 79, 219, 127, 131, 13, 101, 201, 169, 87]) In [37]: np.all(bases ** i == x) Out[37]: True