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([ 54, 162, 181,  21, 179,  97, 130, 211, 237, 221], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([124, 125, 135, 127,  60, 159,  56, 178,  96, 225])

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

In [9]: i = x.log(); i
Out[9]: array([119,  47, 216, 164,  21, 193, 152, 171, 178,  39])

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([ α^91,  α^47,  α^16, α^181,  α^58, α^223, α^169,   α^8, α^161,  α^73],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 91,  47,  16, 181,  58, 223, 169,   8, 161,  73])

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([147, 169, 212,  69, 224,  81,  31, 106, 167, 211])

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([147, 169, 212,  69, 224,  81,  31, 106, 167, 211])

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([147, 169, 212,  69, 224,  81,  31, 106, 167, 211])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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