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