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([ 95, 132, 183, 210,  37, 117, 176,  20,  79, 109], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([229, 144, 171, 173, 227,  12, 114, 167,  95, 165])

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

In [9]: i = x.log(); i
Out[9]: array([116, 121, 102, 129, 221,  17, 180, 190, 217, 158])

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([α^151,  α^39, α^144,  α^11, α^224, α^133, α^116, α^207,  α^47, α^108],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([151,  39, 144,  11, 224, 133, 116, 207,  47, 108])

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([ 95,  63, 214,  55,  64, 159, 206, 111, 169, 100])

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([ 95,  63, 214,  55,  64, 159, 206, 111, 169, 100])

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([ 95,  63, 214,  55,  64, 159, 206, 111, 169, 100])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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