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

In [4]: i = x.log(); i
Out[4]: array([  6,  14, 144,  22,  59, 241, 136, 130, 186, 239])

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([140,   4, 214, 110, 207,  17, 108, 210, 226,  51])

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

In [11]: bases = GF.primitive_elements

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

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

Last update: Aug 27, 2022