-
galois.FieldArray.log(base: ElementLike | ArrayLike | None =
None
) integer | ndarray Computes the logarithm of the array \(x\) base \(\beta\).
Important
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.- 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([ 14, 20, 210, 7, 61, 159, 3, 223, 65, 132], order=3^5) In [4]: i = x.log(); i Out[4]: array([209, 167, 173, 126, 170, 161, 1, 134, 233, 144]) In [5]: np.array_equal(alpha ** i, x) Out[5]: True
In [6]: GF = galois.GF(3**5, display="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 + α + 1, 2α^4 + α^3 + 2α^2 + α + 1, α^3 + 2α^2 + α, 2α^4 + α^2 + α + 2, 2α^3 + 2α, α^4 + α^3 + 2α^2 + α + 1, 2α^4 + α^3, α^3 + α + 2, α^3 + α^2, 2α^3 + 2], order=3^5) In [9]: i = x.log(); i Out[9]: array([221, 178, 139, 114, 168, 56, 129, 49, 71, 86]) In [10]: np.array_equal(alpha ** i, x) Out[10]: True
In [11]: GF = galois.GF(3**5, display="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([α^123, α^207, α^152, α^82, α^66, α^104, α^183, α^196, α^189, α^69], order=3^5) In [14]: i = x.log(); i Out[14]: array([123, 207, 152, 82, 66, 104, 183, 196, 189, 69]) 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([ 87, 111, 78, 58, 88, 168, 35, 56, 175, 37]) 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([ 87, 111, 78, 58, 88, 168, 35, 56, 175, 37]) 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([ 87, 111, 78, 58, 88, 168, 35, 56, 175, 37]) 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(136, order=3^5) In [27]: bases = GF.primitive_elements In [28]: i = x.log(bases); i Out[28]: array([ 99, 33, 165, 231, 209, 231, 77, 231, 77, 55, 143, 33, 11, 55, 33, 165, 11, 77, 165, 187, 165, 187, 187, 77, 187, 33, 231, 165, 33, 231, 77, 143, 99, 209, 187, 231, 99, 187, 77, 11, 165, 231, 209, 99, 165, 55, 77, 11, 231, 77, 187, 209, 209, 143, 231, 33, 11, 99, 33, 55, 55, 33, 143, 231, 143, 231, 187, 165, 55, 143, 165, 99, 11, 143, 143, 55, 187, 99, 55, 33, 165, 77, 143, 209, 55, 11, 33, 55, 209, 33, 209, 209, 11, 187, 143, 143, 77, 187, 165, 209, 99, 99, 11, 55, 11, 99, 99, 209, 77, 11]) In [29]: np.all(bases ** i == x) Out[29]: True
In [30]: x = GF.Random(low=1); x Out[30]: GF(α^4 + α^3 + 2α, order=3^5) In [31]: bases = GF.primitive_elements In [32]: i = x.log(bases); i Out[32]: array([231, 77, 143, 55, 165, 55, 99, 55, 99, 209, 11, 77, 187, 209, 77, 143, 187, 99, 143, 33, 143, 33, 33, 99, 33, 77, 55, 143, 77, 55, 99, 11, 231, 165, 33, 55, 231, 33, 99, 187, 143, 55, 165, 231, 143, 209, 99, 187, 55, 99, 33, 165, 165, 11, 55, 77, 187, 231, 77, 209, 209, 77, 11, 55, 11, 55, 33, 143, 209, 11, 143, 231, 187, 11, 11, 209, 33, 231, 209, 77, 143, 99, 11, 165, 209, 187, 77, 209, 165, 77, 165, 165, 187, 33, 11, 11, 99, 33, 143, 165, 231, 231, 187, 209, 187, 231, 231, 165, 99, 187]) In [33]: np.all(bases ** i == x) Out[33]: True
In [34]: x = GF.Random(low=1); x Out[34]: GF(α^68, order=3^5) In [35]: bases = GF.primitive_elements In [36]: i = x.log(bases); i Out[36]: array([ 68, 8, 62, 34, 14, 12, 92, 166, 4, 160, 152, 184, 164, 182, 228, 194, 230, 158, 18, 60, 150, 148, 192, 136, 82, 162, 56, 84, 96, 100, 70, 196, 134, 212, 16, 122, 112, 170, 114, 32, 40, 78, 146, 156, 106, 94, 26, 208, 210, 202, 104, 36, 102, 42, 232, 206, 10, 178, 52, 116, 28, 118, 218, 188, 86, 144, 38, 172, 138, 174, 216, 222, 142, 240, 20, 6, 236, 90, 72, 74, 128, 224, 130, 190, 226, 76, 30, 50, 124, 140, 80, 234, 120, 126, 108, 64, 48, 214, 238, 168, 2, 24, 186, 204, 98, 200, 46, 58, 180, 54]) In [37]: np.all(bases ** i == x) Out[37]: True
Last update:
Nov 10, 2022