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