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([136, 239, 224,   6, 134,  71, 109,  41,  96, 148], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([ 99, 162, 155, 122,  42, 182, 165, 216,  50,  54])

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

In [9]: i = x.log(); i
Out[9]: array([222, 198, 211,  19,  33, 105, 179, 183,  93,   3])

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([ α^79, α^123,  α^56, α^194, α^219, α^212, α^194, α^184,  α^84, α^132],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 79, 123,  56, 194, 219, 212, 194, 184,  84, 132])

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([109,  87,  16,  90, 149,  26,  90,  18,  24, 176])

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([109,  87,  16,  90, 149,  26,  90,  18,  24, 176])

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([109,  87,  16,  90, 149,  26,  90,  18,  24, 176])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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