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([193,  31,  67,  90,  28, 238,  76,  37,  96, 241], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([147, 214,  39,  48, 207, 186,  22, 227,  50, 238])

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

In [9]: i = x.log(); i
Out[9]: array([170, 138, 163, 160,  30, 225, 126, 122, 156,  33])

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([α^156,  α^18,  α^12, α^150,  α^82, α^142, α^212, α^199, α^195,  α^13],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([156,  18,  12, 150,  82, 142, 212, 199, 195,  13])

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([ 10, 178,  38, 112,  58,   6,  26,   5,  73,  21])

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([ 10, 178,  38, 112,  58,   6,  26,   5,  73,  21])

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([ 10, 178,  38, 112,  58,   6,  26,   5,  73,  21])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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