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([ 24,  87, 197,  33, 231, 185, 129, 122,  28, 143], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([191,  16, 180,  75, 152,  38,  31, 117, 207,  26])

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

In [9]: i = x.log(); i
Out[9]: array([ 63, 114, 113, 123,  98, 223,  51, 177,   9,  74])

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([ α^31,  α^68,  α^51,  α^29, α^184,  α^82,  α^43,  α^41, α^241,  α^98],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 31,  68,  51,  29, 184,  82,  43,  41, 241,  98])

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([199,  54, 101, 233,  18,  58, 237,  29,  17,  28])

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([199,  54, 101, 233,  18,  58, 237,  29,  17,  28])

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([199,  54, 101, 233,  18,  58, 237,  29,  17,  28])

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

In [31]: bases = GF.primitive_elements

In [32]: i = x.log(bases); i
Out[32]: 
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 [33]: np.all(bases ** i == x)
Out[33]: True
In [34]: x = GF.Random(low=1); x
Out[34]: GF(α^89, order=3^5)

In [35]: bases = GF.primitive_elements

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

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