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

In [4]: i = x.log(); i
Out[4]: array([129, 139, 210,  66,  48,  32, 181, 162,  24,  33])

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([227,  57,  60,  88, 152, 182,  69, 150,  76, 165])

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

In [11]: bases = GF.primitive_elements

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

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