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