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

In [4]: i = x.log(); i
Out[4]: array([ 51, 114,  93, 101, 137,  65, 116,  56, 199, 210])

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([101, 240, 113, 219,  91, 105, 206,  16,   5,  60])

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

In [11]: bases = GF.primitive_elements

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

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

Last update: Sep 02, 2022