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

In [4]: i = x.log(); i
Out[4]: array([ 66, 241,  81, 107, 239,  31, 196, 173, 236, 109])

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([ 88,  17,  75, 117,  51, 199,  56, 205, 102,  83])

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

In [11]: bases = GF.primitive_elements

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

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

Last update: Aug 27, 2022