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