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