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([ 89,  98,  47,  63,  96, 241, 197,  25, 230, 200], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([166,  35,  36, 128,  50, 238, 180,  88,  81,  33])

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

In [9]: i = x.log(); i
Out[9]: array([108, 183, 235, 175, 223,  77,   1, 147,  52,  15])

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([ α^41, α^224,  α^39, α^114,  α^28, α^119, α^204,  α^19, α^161, α^185],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 41, 224,  39, 114,  28, 119, 204,  19, 161, 185])

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([ 29,  64,  63, 240,   8, 155, 162, 161, 167,   1])

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([ 29,  64,  63, 240,   8, 155, 162, 161, 167,   1])

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([ 29,  64,  63, 240,   8, 155, 162, 161, 167,   1])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
array([228,  98,  94, 114, 232,  26,  38, 158, 170,  24, 168,  76, 194,
       112,  10, 138, 216,  60, 160, 130, 204, 240, 174, 214, 218, 230,
       202, 182, 208, 136, 192, 102,   8,  56, 196, 224, 162,  86, 126,
       150,   6,  48,  34,  96,  28,   2,  16, 128,  92, 236,  64,  78,
       100, 212, 180, 164,  62, 184,  32,  90, 222,  54, 190,   4, 146,
        70,  42,  50, 178,  14, 226, 118, 106,  36, 124, 134, 108,  74,
       156, 120, 116,  82,  80, 210,  46,  84, 186,  68, 188, 142,  12,
       144,  18, 152, 234,  58, 104,  20,  72, 122, 206,  52,  40, 200,
       172,  30, 140, 166, 148, 238])

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