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 uses primitive_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 from primitive_element, then explicit calculation will be used (which is slower than using lookup tables).

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([232, 165, 136,  82, 224, 124,   2, 216, 150,  73], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([ 97, 137,  99, 189, 155,  41, 121, 193,  52, 109])

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 + α^3 + α + 1,              2α^3 + α + 1,
    α^4 + 2α^3 + α^2 + 2α + 1,           2α^3 + 2α^2 + 1,
          2α^3 + 2α^2 + α + 2, 2α^4 + α^3 + 2α^2 + α + 1,
        2α^4 + α^3 + 2α^2 + 2,      2α^4 + α^3 + α^2 + 1,
                      α^4 + α,            2α^3 + α^2 + 1], order=3^5)

In [9]: i = x.log(); i
Out[9]: array([ 34,  28, 174, 109, 151, 178,  58, 164, 208, 157])

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([α^116,  α^33, α^231, α^177,  α^62,  α^20, α^203,  α^10, α^239, α^105],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([116,  33, 231, 177,  62,  20, 203,  10, 239, 105])

In [15]: np.array_equal(alpha ** i, x)
Out[15]: True

With the default argument, numpy.log() and log() 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([206, 165, 187, 137, 156, 144, 179,  72,  51, 151])

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([206, 165, 187, 137, 156, 144, 179,  72,  51, 151])

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([206, 165, 187, 137, 156, 144, 179,  72,  51, 151])

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(126, order=3^5)

In [27]: bases = GF.primitive_elements

In [28]: i = x.log(bases); i
Out[28]: 
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 [29]: np.all(bases ** i == x)
Out[29]: np.True_
In [30]: x = GF.Random(low=1); x
Out[30]: GF(α^3 + α^2 + 2α + 2, order=3^5)

In [31]: bases = GF.primitive_elements

In [32]: i = x.log(bases); i
Out[32]: 
array([143, 209,  77,  11,  33,  11, 165,  11, 165, 187,  99, 209, 231,
       187, 209,  77, 231, 165,  77,  55,  77,  55,  55, 165,  55, 209,
        11,  77, 209,  11, 165,  99, 143,  33,  55,  11, 143,  55, 165,
       231,  77,  11,  33, 143,  77, 187, 165, 231,  11, 165,  55,  33,
        33,  99,  11, 209, 231, 143, 209, 187, 187, 209,  99,  11,  99,
        11,  55,  77, 187,  99,  77, 143, 231,  99,  99, 187,  55, 143,
       187, 209,  77, 165,  99,  33, 187, 231, 209, 187,  33, 209,  33,
        33, 231,  55,  99,  99, 165,  55,  77,  33, 143, 143, 231, 187,
       231, 143, 143,  33, 165, 231])

In [33]: np.all(bases ** i == x)
Out[33]: np.True_
In [34]: x = GF.Random(low=1); x
Out[34]: GF(α^209, order=3^5)

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
array([209, 231, 187, 165,  11, 165,  55, 165,  55, 143,  33, 231,  77,
       143, 231, 187,  77,  55, 187,  99, 187,  99,  99,  55,  99, 231,
       165, 187, 231, 165,  55,  33, 209,  11,  99, 165, 209,  99,  55,
        77, 187, 165,  11, 209, 187, 143,  55,  77, 165,  55,  99,  11,
        11,  33, 165, 231,  77, 209, 231, 143, 143, 231,  33, 165,  33,
       165,  99, 187, 143,  33, 187, 209,  77,  33,  33, 143,  99, 209,
       143, 231, 187,  55,  33,  11, 143,  77, 231, 143,  11, 231,  11,
        11,  77,  99,  33,  33,  55,  99, 187,  11, 209, 209,  77, 143,
        77, 209, 209,  11,  55,  77])

In [37]: np.all(bases ** i == x)
Out[37]: np.True_