-
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([ 6, 183, 144, 52, 230, 149, 70, 104, 79, 159], order=3^5) In [4]: i = x.log(); i Out[4]: array([122, 171, 140, 79, 81, 32, 172, 232, 95, 161]) 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([ α^3 + 2α^2 + 2α + 2, 2α^4 + 2α^3 + 2α^2 + α, 2α^4 + α^3 + 2α + 2, α^4 + α^3 + α^2 + 1, 2α^4 + α^2 + 1, α^4 + 2α^2 + 2, 2α^4 + α^3 + 2α^2 + α + 2, α^3 + 2α^2 + α + 2, α^4 + α^3, 2α^3 + 2α^2 + α + 1], order=3^5) In [9]: i = x.log(); i Out[9]: array([160, 96, 180, 83, 206, 85, 53, 51, 72, 22]) 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([α^220, α^94, α^30, α^216, α^220, α^127, α^137, α^181, α^207, α^166], order=3^5) In [14]: i = x.log(); i Out[14]: array([220, 94, 30, 216, 220, 127, 137, 181, 207, 166]) 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([132, 96, 216, 200, 132, 19, 91, 69, 111, 82]) 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([132, 96, 216, 200, 132, 19, 91, 69, 111, 82]) 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([132, 96, 216, 200, 132, 19, 91, 69, 111, 82]) 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(146, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([219, 161, 189, 49, 191, 181, 97, 225, 141, 195, 155, 73, 215, 63, 51, 123, 61, 185, 211, 179, 145, 135, 113, 75, 47, 205, 159, 57, 117, 137, 229, 133, 65, 213, 201, 5, 197, 3, 207, 39, 79, 27, 125, 175, 167, 107, 9, 193, 203, 163, 157, 59, 147, 89, 71, 183, 171, 43, 139, 217, 19, 227, 1, 93, 67, 115, 69, 13, 85, 23, 233, 21, 105, 111, 221, 151, 91, 87, 239, 7, 35, 31, 45, 103, 41, 17, 29, 129, 15, 95, 37, 81, 237, 25, 177, 199, 119, 223, 101, 235, 131, 241, 83, 173, 127, 153, 109, 169, 53, 149]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(2α^4 + α^3 + 2α^2 + 2α, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([183, 171, 85, 31, 27, 75, 91, 9, 25, 153, 103, 61, 57, 109, 215, 63, 167, 201, 173, 133, 151, 199, 111, 3, 89, 105, 229, 41, 237, 141, 135, 15, 51, 115, 221, 97, 95, 155, 47, 79, 129, 185, 5, 7, 239, 43, 223, 211, 163, 113, 45, 225, 93, 81, 119, 17, 123, 205, 83, 241, 175, 193, 213, 207, 235, 53, 177, 107, 197, 59, 19, 117, 101, 169, 125, 219, 23, 139, 87, 39, 195, 69, 147, 159, 21, 233, 127, 131, 49, 149, 137, 71, 145, 1, 191, 37, 179, 67, 217, 203, 73, 29, 13, 65, 189, 161, 227, 181, 157, 35]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^140, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([140, 230, 28, 70, 100, 224, 104, 114, 236, 2, 14, 208, 238, 90, 142, 72, 18, 126, 94, 152, 138, 20, 196, 38, 240, 120, 158, 116, 98, 92, 16, 190, 162, 166, 218, 180, 74, 108, 192, 194, 182, 4, 144, 8, 204, 222, 82, 172, 48, 60, 86, 188, 210, 58, 136, 54, 106, 96, 164, 68, 200, 186, 36, 202, 234, 26, 64, 226, 156, 102, 160, 30, 150, 124, 212, 112, 130, 228, 134, 10, 50, 148, 168, 78, 24, 128, 76, 46, 56, 32, 122, 12, 62, 174, 80, 146, 170, 42, 6, 232, 118, 206, 84, 178, 216, 184, 52, 34, 214, 40]) In [37]: np.all(bases ** i == x) Out[37]: True