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([239,  36,  45, 187, 160, 165,  99, 151,  45, 171], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([162,  71,   7, 108, 184, 137,  76, 174,   7, 197])

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

In [9]: i = x.log(); i
Out[9]: array([ 59, 181, 157,  31, 167, 235,  92, 165,  25, 148])

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([ α^15,   α^7, α^184, α^116,  α^52, α^164, α^212,   α^5,  α^95, α^197],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 15,   7, 184, 116,  52, 164, 212,   5,  95, 197])

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([229, 123,  18, 206,  84, 116,  26, 157,  79,  39])

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([229, 123,  18, 206,  84, 116,  26, 157,  79,  39])

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([229, 123,  18, 206,  84, 116,  26, 157,  79,  39])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

In [32]: i = x.log(bases); i
Out[32]: 
array([ 55,  99,  11, 209, 143, 209, 231, 209, 231, 165, 187,  99,  33,
       165,  99,  11,  33, 231,  11,  77,  11,  77,  77, 231,  77,  99,
       209,  11,  99, 209, 231, 187,  55, 143,  77, 209,  55,  77, 231,
        33,  11, 209, 143,  55,  11, 165, 231,  33, 209, 231,  77, 143,
       143, 187, 209,  99,  33,  55,  99, 165, 165,  99, 187, 209, 187,
       209,  77,  11, 165, 187,  11,  55,  33, 187, 187, 165,  77,  55,
       165,  99,  11, 231, 187, 143, 165,  33,  99, 165, 143,  99, 143,
       143,  33,  77, 187, 187, 231,  77,  11, 143,  55,  55,  33, 165,
        33,  55,  55, 143, 231,  33])

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

In [35]: bases = GF.primitive_elements

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

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