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