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