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