-
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([110, 182, 137, 26, 229, 36, 186, 192, 219, 79], order=3^5) In [4]: i = x.log(); i Out[4]: array([119, 27, 67, 131, 163, 71, 94, 158, 110, 95]) 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 + α^3 + 2, α + 1, α^4 + 2α^3 + 2α, 2α^4 + 2α^3 + α^2 + α, 2α^3 + α^2 + 2α + 1, 2α^4 + 2α^3, 2α^2 + 2, 2α^4 + 2α^3 + α + 1, 2α^4 + 2α + 1, α^4 + 2α^3 + 2α^2 + α + 1], order=3^5) In [9]: i = x.log(); i Out[9]: array([119, 69, 37, 23, 172, 193, 167, 205, 194, 176]) 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([ α^49, α^151, α^69, α^90, α^95, α^80, α^39, α^91, α^99, α^66], order=3^5) In [14]: i = x.log(); i Out[14]: array([ 49, 151, 69, 90, 95, 80, 39, 91, 99, 66]) 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([135, 95, 37, 164, 79, 92, 63, 147, 11, 88]) 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([135, 95, 37, 164, 79, 92, 63, 147, 11, 88]) 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([135, 95, 37, 164, 79, 92, 63, 147, 11, 88]) 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(147, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([ 62, 50, 206, 152, 148, 196, 212, 130, 146, 32, 224, 182, 178, 230, 94, 184, 46, 80, 52, 12, 30, 78, 232, 124, 210, 226, 108, 162, 116, 20, 14, 136, 172, 236, 100, 218, 216, 34, 168, 200, 8, 64, 126, 128, 118, 164, 102, 90, 42, 234, 166, 104, 214, 202, 240, 138, 2, 84, 204, 120, 54, 72, 92, 86, 114, 174, 56, 228, 76, 180, 140, 238, 222, 48, 4, 98, 144, 18, 208, 160, 74, 190, 26, 38, 142, 112, 6, 10, 170, 28, 16, 192, 24, 122, 70, 158, 58, 188, 96, 82, 194, 150, 134, 186, 68, 40, 106, 60, 36, 156]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(α^3 + α^2 + 2α + 2, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([143, 209, 77, 11, 33, 11, 165, 11, 165, 187, 99, 209, 231, 187, 209, 77, 231, 165, 77, 55, 77, 55, 55, 165, 55, 209, 11, 77, 209, 11, 165, 99, 143, 33, 55, 11, 143, 55, 165, 231, 77, 11, 33, 143, 77, 187, 165, 231, 11, 165, 55, 33, 33, 99, 11, 209, 231, 143, 209, 187, 187, 209, 99, 11, 99, 11, 55, 77, 187, 99, 77, 143, 231, 99, 99, 187, 55, 143, 187, 209, 77, 165, 99, 33, 187, 231, 209, 187, 33, 209, 33, 33, 231, 55, 99, 99, 165, 55, 77, 33, 143, 143, 231, 187, 231, 143, 143, 33, 165, 231]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^94, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([ 94, 68, 164, 168, 240, 102, 56, 80, 34, 150, 82, 112, 184, 216, 2, 76, 140, 12, 32, 26, 186, 48, 180, 188, 92, 46, 234, 230, 90, 124, 232, 214, 50, 108, 136, 190, 226, 114, 122, 30, 98, 58, 152, 116, 54, 194, 100, 74, 212, 144, 158, 64, 20, 236, 36, 178, 206, 182, 200, 18, 238, 156, 38, 146, 126, 14, 202, 10, 84, 148, 142, 72, 118, 104, 170, 172, 70, 160, 128, 24, 120, 210, 16, 42, 106, 162, 134, 62, 86, 222, 196, 174, 52, 224, 192, 60, 166, 4, 208, 218, 138, 204, 8, 40, 228, 6, 28, 130, 78, 96]) In [37]: np.all(bases ** i == x) Out[37]: True