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

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

Danger

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 (which is slower than lookup tables).

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)

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

In [3]: x = GF.Random(10, low=1); x
Out[3]: GF([ 14, 118,  81, 101,   9,  58, 167, 230,  41, 186], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([209,  83,   4,  85,   2,  28,   9,  81, 216,  94])

In [5]: np.array_equal(alpha ** i, x)
Out[5]: True
In [6]: GF = galois.GF(3**5, repr="poly")

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

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

In [9]: i = x.log(); i
Out[9]: array([222, 132, 240,  71, 133, 186, 226, 237, 138, 227])

In [10]: np.array_equal(alpha ** i, x)
Out[10]: True
In [11]: GF = galois.GF(3**5, repr="power")

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

In [13]: x = GF.Random(10, low=1); x
Out[13]: 
GF([α^171,  α^61,   α^4,  α^81, α^100, α^133,  α^65,  α^66,  α^93, α^169],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([171,  61,   4,  81, 100, 133,  65,  66,  93, 169])

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

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

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

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

In [17]: beta = GF.primitive_elements[-1]; beta
Out[17]: GF(242, order=3^5)

In [18]: i = x.log(beta); i
Out[18]: array([239, 173, 174,  75, 236, 159, 105,  88, 113,  31])

In [19]: np.array_equal(beta ** i, x)
Out[19]: True
In [20]: beta = GF.primitive_elements[-1]; beta
Out[20]: GF(2α^4 + 2α^3 + 2α^2 + 2α + 2, order=3^5)

In [21]: i = x.log(beta); i
Out[21]: array([239, 173, 174,  75, 236, 159, 105,  88, 113,  31])

In [22]: np.array_equal(beta ** i, x)
Out[22]: True
In [23]: beta = GF.primitive_elements[-1]; beta
Out[23]: GF(α^185, order=3^5)

In [24]: i = x.log(beta); i
Out[24]: array([239, 173, 174,  75, 236, 159, 105,  88, 113,  31])

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

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

In [26]: x = GF.Random(low=1); x
Out[26]: GF(218, order=3^5)

In [27]: bases = GF.primitive_elements

In [28]: i = x.log(bases); i
Out[28]: 
array([ 44, 176, 154,  22,  66,  22,  88,  22,  88, 132, 198, 176, 220,
       132, 176, 154, 220,  88, 154, 110, 154, 110, 110,  88, 110, 176,
        22, 154, 176,  22,  88, 198,  44,  66, 110,  22,  44, 110,  88,
       220, 154,  22,  66,  44, 154, 132,  88, 220,  22,  88, 110,  66,
        66, 198,  22, 176, 220,  44, 176, 132, 132, 176, 198,  22, 198,
        22, 110, 154, 132, 198, 154,  44, 220, 198, 198, 132, 110,  44,
       132, 176, 154,  88, 198,  66, 132, 220, 176, 132,  66, 176,  66,
        66, 220, 110, 198, 198,  88, 110, 154,  66,  44,  44, 220, 132,
       220,  44,  44,  66,  88, 220])

In [29]: np.all(bases ** i == x)
Out[29]: True
In [30]: x = GF.Random(low=1); x
Out[30]: GF(2α^4 + 2α^2 + α, order=3^5)

In [31]: bases = GF.primitive_elements

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

In [33]: np.all(bases ** i == x)
Out[33]: True
In [34]: x = GF.Random(low=1); x
Out[34]: GF(α^52, order=3^5)

In [35]: bases = GF.primitive_elements

In [36]: i = x.log(bases); i
Out[36]: 
array([ 52, 120, 204,  26, 210, 180, 170,  70,  60, 222, 102,  98,  40,
        68,  32,   6,  62, 192,  28, 174,  72,  42, 218, 104,  20,  10,
       114,  50, 230,  48,  82,  36,  74,  34, 240, 136, 228, 130,  16,
       238, 116, 202,  12, 162, 138, 200, 148, 216,   4, 126, 108,  56,
        78, 146,  92, 186, 150,   8,  54,  46, 178,  76, 124, 158,  80,
       224,  86, 160, 134, 190,  94, 184, 194, 212,  58,  90, 152, 140,
       112, 142, 226, 214,  14, 188,   2, 172, 208,  24, 166, 164, 232,
       122, 106, 196, 168, 234, 236,  64, 182, 100,  30, 118, 128, 156,
        18,  96, 206, 144,  38,  84])

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