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([195,  89, 197, 203,  78,  25,  84, 227, 109, 120], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([234, 166, 180,  63, 132,  88, 208, 146, 165, 116])

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

In [9]: i = x.log(); i
Out[9]: array([175, 184, 240,  96, 218,  27,  10, 235,  12,  97])

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([ α^43, α^186,  α^10, α^161, α^191, α^217, α^181, α^181,  α^70,  α^40],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 43, 186,  10, 161, 191, 217, 181, 181,  70,  40])

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([237, 226,  72, 167, 141, 183,  69,  69,  20,  46])

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([237, 226,  72, 167, 141, 183,  69,  69,  20,  46])

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([237, 226,  72, 167, 141, 183,  69,  69,  20,  46])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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