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([187,  54, 199, 119,  39,  22,  23, 162,  57,  18], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([108, 124, 164, 118,  11, 101,  17, 125, 196, 123])

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

In [9]: i = x.log(); i
Out[9]: array([119,  66, 152,  77, 184,  39,  11,  74, 145, 224])

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([α^224,  α^24, α^112,  α^99, α^100, α^238,  α^87,  α^37, α^131, α^125],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([224,  24, 112,  99, 100, 238,  87,  37, 131, 125])

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([ 64,  76,  32,  11, 236,  68, 215,  97, 193,  53])

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([ 64,  76,  32,  11, 236,  68, 215,  97, 193,  53])

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([ 64,  76,  32,  11, 236,  68, 215,  97, 193,  53])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
array([ 22,  88, 198, 132, 154, 132,  44, 132,  44,  66, 220,  88, 110,
        66,  88, 198, 110,  44, 198, 176, 198, 176, 176,  44, 176,  88,
       132, 198,  88, 132,  44, 220,  22, 154, 176, 132,  22, 176,  44,
       110, 198, 132, 154,  22, 198,  66,  44, 110, 132,  44, 176, 154,
       154, 220, 132,  88, 110,  22,  88,  66,  66,  88, 220, 132, 220,
       132, 176, 198,  66, 220, 198,  22, 110, 220, 220,  66, 176,  22,
        66,  88, 198,  44, 220, 154,  66, 110,  88,  66, 154,  88, 154,
       154, 110, 176, 220, 220,  44, 176, 198, 154,  22,  22, 110,  66,
       110,  22,  22, 154,  44, 110])

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