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([119,  61,  15,  99,  50, 147, 138, 174, 239, 156], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([118, 170,   6,  76,  51,  62, 113,  29, 162,  80])

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

In [9]: i = x.log(); i
Out[9]: array([ 53,  70,   6, 104, 240,  30, 177, 179,  19,  56])

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([α^163,     α, α^116, α^170, α^142, α^180, α^121,  α^40,  α^74,  α^41],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([163,   1, 116, 170, 142, 180, 121,  40,  74,  41])

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([133, 225, 206,  14,   6,  86, 121,  46, 194,  29])

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([133, 225, 206,  14,   6,  86, 121,  46, 194,  29])

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([133, 225, 206,  14,   6,  86, 121,  46, 194,  29])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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