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