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([ 29, 197,  24,  14,   4, 179, 104,  84, 214, 130], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([ 15, 180, 191, 209,  69,  60, 232, 208, 153,  56])

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

In [9]: i = x.log(); i
Out[9]: array([111, 171,  95,  63,  88,  58,  19,  81,  25,   2])

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([α^162,  α^40, α^130, α^150,  α^25,  α^23, α^130, α^115,  α^11, α^174],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([162,  40, 130, 150,  25,  23, 130, 115,  11, 174])

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([150,  46, 210, 112,  59,  93, 210, 223,  55, 188])

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([150,  46, 210, 112,  59,  93, 210, 223,  55, 188])

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([150,  46, 210, 112,  59,  93, 210, 223,  55, 188])

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

In [27]: bases = GF.primitive_elements

In [28]: i = x.log(bases); i
Out[28]: 
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 [29]: np.all(bases ** i == x)
Out[29]: True
In [30]: x = GF.Random(low=1); x
Out[30]: GF(2α^4 + 2α^3 + 2α^2 + α + 2, order=3^5)

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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