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