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