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([225, 240, 164, 149,  32,  32,  61, 125, 149,   2], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([ 90, 237,  68,  32,  49,  49, 170,  65,  32, 121])

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

In [9]: i = x.log(); i
Out[9]: array([142, 122,  46,  71,   2, 102, 192,  29,  28, 241])

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([ α^80,  α^52, α^216, α^147, α^120,  α^86,  α^92,  α^47,   α^5, α^114],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 80,  52, 216, 147, 120,  86,  92,  47,   5, 114])

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([ 92,  84, 200, 163, 138, 232, 130, 169, 157, 240])

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([ 92,  84, 200, 163, 138, 232, 130, 169, 157, 240])

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([ 92,  84, 200, 163, 138, 232, 130, 169, 157, 240])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
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 [37]: np.all(bases ** i == x)
Out[37]: np.True_