-
galois.FieldArray.log(base: ElementLike | ArrayLike | None =
None
) int | ndarray Computes the logarithm of the array \(x\) base \(\beta\).
Danger
If the Galois field is configured to use lookup tables,
ufunc_mode == "jit-lookup"
, and this function is invoked with a base different fromprimitive_element
, then explicit calculation will be used (which is slower than lookup tables).- Parameters¶
- base: ElementLike | ArrayLike | None =
None
¶ A primitive element(s) \(\beta\) of the finite field that is the base of the logarithm. The default is
None
which usesprimitive_element
.
- 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([ 13, 55, 218, 224, 139, 199, 84, 156, 33, 194], order=3^5) In [4]: i = x.log(); i Out[4]: array([ 10, 136, 44, 155, 59, 164, 208, 80, 75, 141]) 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 + α^3 + α^2 + 2α, α^4 + α^3 + α^2 + 2α, α^4 + 2α^2 + 2α, 2α^3 + α^2 + 2α + 1, α^2 + 2α + 2, 2α^4 + α^3 + 2α + 1, 2α^3 + 2α^2 + α + 1, α^4 + 2α^3 + α^2 + α + 1, α^2 + 2, 2α^4 + 2α], order=3^5) In [9]: i = x.log(); i Out[9]: array([201, 217, 150, 172, 222, 91, 22, 54, 74, 87]) 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([α^112, α^66, α^83, α^173, α^175, α^185, α^141, α^35, α^59, α^179], order=3^5) In [14]: i = x.log(); i Out[14]: array([112, 66, 83, 173, 175, 185, 141, 35, 59, 179]) 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([ 32, 88, 41, 205, 171, 1, 23, 131, 207, 103]) 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([ 32, 88, 41, 205, 171, 1, 23, 131, 207, 103]) 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([ 32, 88, 41, 205, 171, 1, 23, 131, 207, 103]) 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(112, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([ 34, 4, 152, 138, 128, 6, 46, 204, 2, 80, 76, 92, 82, 212, 114, 218, 236, 200, 130, 30, 196, 74, 96, 68, 162, 202, 28, 42, 48, 50, 156, 98, 188, 106, 8, 182, 56, 206, 178, 16, 20, 160, 194, 78, 174, 168, 134, 104, 226, 222, 52, 18, 172, 142, 116, 224, 126, 210, 26, 58, 14, 180, 230, 94, 164, 72, 140, 86, 190, 208, 108, 232, 192, 120, 10, 124, 118, 166, 36, 158, 64, 112, 186, 216, 234, 38, 136, 146, 62, 70, 40, 238, 60, 184, 54, 32, 24, 228, 240, 84, 122, 12, 214, 102, 170, 100, 144, 150, 90, 148]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(α^4 + 2α^3 + 2α + 2, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([ 26, 60, 102, 134, 226, 90, 206, 156, 30, 232, 172, 170, 20, 34, 16, 124, 152, 96, 14, 208, 36, 142, 230, 52, 10, 126, 178, 146, 236, 24, 162, 18, 158, 138, 120, 68, 114, 186, 8, 240, 58, 222, 6, 202, 190, 100, 74, 108, 2, 184, 54, 28, 160, 194, 46, 214, 196, 4, 148, 144, 210, 38, 62, 200, 40, 112, 164, 80, 188, 216, 168, 92, 218, 106, 150, 166, 76, 70, 56, 192, 234, 228, 128, 94, 122, 86, 104, 12, 204, 82, 116, 182, 174, 98, 84, 238, 118, 32, 212, 50, 136, 180, 64, 78, 130, 48, 224, 72, 140, 42]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^132, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([132, 44, 220, 66, 198, 66, 22, 66, 22, 154, 110, 44, 176, 154, 44, 220, 176, 22, 220, 88, 220, 88, 88, 22, 88, 44, 66, 220, 44, 66, 22, 110, 132, 198, 88, 66, 132, 88, 22, 176, 220, 66, 198, 132, 220, 154, 22, 176, 66, 22, 88, 198, 198, 110, 66, 44, 176, 132, 44, 154, 154, 44, 110, 66, 110, 66, 88, 220, 154, 110, 220, 132, 176, 110, 110, 154, 88, 132, 154, 44, 220, 22, 110, 198, 154, 176, 44, 154, 198, 44, 198, 198, 176, 88, 110, 110, 22, 88, 220, 198, 132, 132, 176, 154, 176, 132, 132, 198, 22, 176]) In [37]: np.all(bases ** i == x) Out[37]: True