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([199, 158,  48, 181,  62, 234,  96, 157,   5, 173], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([164, 145, 139, 135,  93, 133,  50, 176,   5, 213])

In [5]: assert np.array_equal(alpha ** i, x)
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 + 2, α^4 + α^3 + 2α^2 + α + 2,
               α^4 + α^2 + 1,      2α^4 + α^2 + 2α + 1,
         α^3 + 2α^2 + 2α + 1,            2α^2 + 2α + 1,
                 2α^4 + 2α^2,                  α^4 + 2,
       α^4 + 2α^3 + 2α^2 + α,                 2α^4 + 2], order=3^5)

In [9]: i = x.log(); i
Out[9]: array([119, 218, 148, 111,  79,  88, 169, 120,  80,  68])

In [10]: assert np.array_equal(alpha ** i, x)
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([α^142, α^218,  α^33, α^199, α^108, α^113,  α^70,   α^8, α^128,   α^5],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([142, 218,  33, 199, 108, 113,  70,   8, 128,   5])

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

With the default argument, numpy.log() and log() are equivalent.

In [16]: assert np.array_equal(np.log(x), x.log())

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([  6, 166, 165,   5, 100,  15,  20, 106,   2, 157])

In [19]: assert np.array_equal(beta ** i, x)
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([  6, 166, 165,   5, 100,  15,  20, 106,   2, 157])

In [22]: assert np.array_equal(beta ** i, x)
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([  6, 166, 165,   5, 100,  15,  20, 106,   2, 157])

In [25]: assert np.array_equal(beta ** i, x)

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

In [27]: bases = GF.primitive_elements

In [28]: i = x.log(bases); i
Out[28]: 
array([159,  97, 177,  19,  79,  85,  87, 107, 109, 125, 149,  53, 113,
        59, 163,  23, 157, 131,  67, 183, 155, 161,  29, 197, 117, 119,
       195, 111,  75,  63, 153,  17, 203, 211,  73, 239,  27,  95,  21,
        25,   1, 129, 167, 137,  45,  81,  43, 223, 217, 241,  51,  13,
        57, 237, 151, 229,  91,  71, 207,  15,  37,   9, 193,  41, 105,
       173,   7,  89, 191,  83, 199, 181, 179, 127,  61, 103, 139,  93,
       147, 141, 221, 175, 215,  35, 169, 135,  31, 213, 233, 185, 123,
       145,   3, 227,  39, 171, 219, 205, 133, 101, 115,  49,  47, 235,
        69,   5, 225, 189,  65, 201])

In [29]: assert np.all(bases ** i == x)
In [30]: x = GF.Random(low=1); x
Out[30]: GF(α^3 + 2, order=3^5)

In [31]: bases = GF.primitive_elements

In [32]: i = x.log(bases); i
Out[32]: 
array([ 15, 137,   3, 189, 149, 145,  63, 211, 129, 199, 183,   5, 207,
         1,  93,  25,  97, 195, 157, 241, 179, 175,  21, 151,  43, 203,
       233,  47,  71,  79,  19,  29, 147,  61, 153, 123, 103, 219, 107,
       185, 201,  35, 171, 191,  91,  67, 173,  53,  57,  41,  87, 193,
        83, 205, 101,  49, 141, 235, 225, 111, 177, 115,  73,  13,  51,
       167, 197, 223, 155, 227,  69,  81, 163, 117, 161, 133, 109,  59,
        23,  27, 135,  85, 139,  17,  89,  31, 181, 221, 127, 159,  39,
       105, 119, 131,  95,   7, 217,  65, 113, 215, 125, 169,   9,  45,
        75,  37, 213, 237, 239, 229])

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

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
array([ 39, 211, 153, 201,  97, 135,  67, 113,  45, 227, 137,  13, 151,
        51, 145,  65, 107,  23,  21, 191, 175, 213, 103, 199,  15, 189,
        25, 219, 233, 157,   1,  27, 237, 207,  59, 223, 171,  37, 133,
       239,  87,  91,   9,  61,  43,  29, 111,  41,   3, 155,  81, 163,
       119,  49,  69,  79, 173, 127, 101,  95,  73,  57,  93, 179, 181,
        47, 125, 241, 161, 203, 131,  17,  85, 159, 225,   7, 235, 105,
       205, 167, 109, 221,  71, 141, 183, 129,  35, 139, 185, 123,  53,
        31,  19, 147,   5, 115, 177, 169, 197,  75,  83, 149, 217, 117,
       195, 193, 215, 229,  89,  63])

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