-
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([221, 101, 30, 71, 98, 159, 183, 49, 107, 14], order=3^5) In [4]: i = x.log(); i Out[4]: array([225, 85, 47, 182, 35, 161, 171, 61, 105, 209]) 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 + 2α^3 + 2α^2 + 2, α^4 + 2α^3 + α^2, α^4 + α^3 + 2α^2 + α + 1, 2α^4 + 2α^3 + α^2 + α + 2, 2α^4 + 2α^3 + 2α^2 + α + 1, 2α^3 + 2, 2α^3 + α^2, 2α^4 + 2α^2 + α + 1, α^4 + α^2 + 2α + 1, 2α], order=3^5) In [9]: i = x.log(); i Out[9]: array([ 43, 140, 56, 81, 186, 86, 128, 156, 159, 122]) 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([α^199, α^203, α^20, α^6, α^70, α^240, α^160, α^38, α^59, α^198], order=3^5) In [14]: i = x.log(); i Out[14]: array([199, 203, 20, 6, 70, 240, 160, 38, 59, 198]) 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([ 5, 179, 144, 140, 20, 34, 184, 80, 207, 22]) 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([ 5, 179, 144, 140, 20, 34, 184, 80, 207, 22]) 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([ 5, 179, 144, 140, 20, 34, 184, 80, 207, 22]) 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(115, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([104, 240, 166, 52, 178, 118, 98, 140, 120, 202, 204, 196, 80, 136, 64, 12, 124, 142, 56, 106, 144, 84, 194, 208, 40, 20, 228, 100, 218, 96, 164, 72, 148, 68, 238, 30, 214, 18, 32, 234, 232, 162, 24, 82, 34, 158, 54, 190, 8, 10, 216, 112, 156, 50, 184, 130, 58, 16, 108, 92, 114, 152, 6, 74, 160, 206, 172, 78, 26, 138, 188, 126, 146, 182, 116, 180, 62, 38, 224, 42, 210, 186, 28, 134, 4, 102, 174, 48, 90, 86, 222, 2, 212, 150, 94, 226, 230, 128, 122, 200, 60, 236, 14, 70, 36, 192, 170, 46, 76, 168]) In [29]: np.all(bases ** i == x) Out[29]: np.True_
In [30]: x = GF.Random(low=1); x Out[30]: GF(α^4 + α^3 + α^2 + α + 1, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([ 64, 36, 158, 32, 184, 54, 172, 142, 18, 236, 200, 102, 12, 214, 58, 26, 188, 106, 202, 28, 70, 182, 138, 128, 6, 124, 10, 136, 190, 208, 194, 156, 240, 228, 72, 186, 20, 160, 150, 144, 180, 230, 52, 218, 114, 60, 238, 210, 98, 62, 226, 162, 96, 68, 76, 80, 166, 196, 234, 38, 126, 168, 134, 120, 24, 164, 50, 48, 16, 178, 4, 152, 34, 112, 90, 148, 94, 42, 82, 212, 92, 40, 222, 8, 170, 100, 14, 104, 74, 146, 118, 206, 56, 204, 2, 46, 216, 116, 224, 30, 130, 108, 232, 192, 78, 174, 86, 140, 84, 122]) In [33]: np.all(bases ** i == x) Out[33]: np.True_
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^77, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([ 77, 187, 209, 99, 55, 99, 33, 99, 33, 231, 165, 187, 143, 231, 187, 209, 143, 33, 209, 11, 209, 11, 11, 33, 11, 187, 99, 209, 187, 99, 33, 165, 77, 55, 11, 99, 77, 11, 33, 143, 209, 99, 55, 77, 209, 231, 33, 143, 99, 33, 11, 55, 55, 165, 99, 187, 143, 77, 187, 231, 231, 187, 165, 99, 165, 99, 11, 209, 231, 165, 209, 77, 143, 165, 165, 231, 11, 77, 231, 187, 209, 33, 165, 55, 231, 143, 187, 231, 55, 187, 55, 55, 143, 11, 165, 165, 33, 11, 209, 55, 77, 77, 143, 231, 143, 77, 77, 55, 33, 143]) In [37]: np.all(bases ** i == x) Out[37]: np.True_