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