galois.FieldArray.log(base: ElementLike | ArrayLike | None = None) ndarray

Computes the logarithm of the array \(x\) base \(\beta\).

Important

If the Galois field is configured to use lookup tables, ufunc_mode == "jit-lookup", and this function is invoked with a base different from primitive_element, then explicit calculation will be used.

Parameters
base: ElementLike | ArrayLike | None = None

A primitive element(s) \(\beta\) of the finite field that is the base of the logarithm. The default is None which uses primitive_element.

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, display="poly")

In [2]: alpha = GF.primitive_element; alpha
Out[2]: GF(α, order=3^5)

In [3]: x = GF.Random(10, low=1); x
Out[3]: 
GF([                 2α^3,                     2,          2α^2 + α + 2,
              α^2 + α + 2,          2α^4 + α + 2, α^4 + 2α^3 + 2α^2 + α,
           α^4 + 2α^2 + 1,            α^4 + 2α^3,   α^3 + 2α^2 + 2α + 2,
             α^4 + 2α + 2], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([124, 121,  17, 209,   9,  80,  92,   8, 160, 166])

In [5]: np.array_equal(alpha ** i, x)
Out[5]: True

With the default argument, numpy.log() and log() are equivalent.

In [6]: np.array_equal(np.log(x), x.log())
Out[6]: True

Compute the logarithm of \(x\) with a different base \(\beta\), which is another primitive element of the field.

In [7]: beta = GF.primitive_elements[-1]; beta
Out[7]: GF(2α^4 + 2α^3 + 2α^2 + 2α + 2, order=3^5)

In [8]: i = x.log(beta); i
Out[8]: array([ 70, 121, 195,  77,  89,  92, 130, 106, 184,  82])

In [9]: np.array_equal(beta ** i, x)
Out[9]: True

Compute the logarithm of a single finite field element base all of the primitive elements of the field.

In [10]: x = GF.Random(low=1); x
Out[10]: GF(2α^2 + α + 2, order=3^5)

In [11]: bases = GF.primitive_elements

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

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