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

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

Parameters:
base: ElementLike | ArrayLike | None = None

A primitive element or elements \(\beta\) of the finite field that is the base of the logarithm. The default is None which uses primitive_element.

Slower performance

If the FieldArray is configured to use lookup tables (ufunc_mode == "jit-lookup") and this method is invoked with a base different from primitive_element, then explicit calculation will be used (which is slower than using lookup tables).

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([138, 199,  70, 208, 186, 122, 203, 142, 208, 173], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([113, 164, 172,  98,  94, 117,  63,  20,  98, 213])

In [5]: assert np.array_equal(alpha ** i, x)
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α^3 + 2α^2 + α + 2,  2α^4 + 2α^3 + α^2 + α + 2,
                   2α^4 + 2α^3,                    α^4 + 2,
                       α^4 + 1, 2α^4 + 2α^3 + 2α^2 + α + 1,
                       α^2 + 2,                    α^2 + 2,
                α^4 + 2α^3 + 1,                          α], order=3^5)

In [9]: i = x.log(); i
Out[9]: array([151,  81, 193, 120, 189, 186,  74,  74,  99,   1])

In [10]: assert np.array_equal(alpha ** i, x)
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([  α^5, α^159, α^164, α^226, α^200,  α^46, α^128, α^179,   α^6, α^144],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([  5, 159, 164, 226, 200,  46, 128, 179,   6, 144])

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

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

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

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([157, 201, 116,  30, 230, 186,   2, 103, 140, 214])

In [19]: assert np.array_equal(beta ** i, x)
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([157, 201, 116,  30, 230, 186,   2, 103, 140, 214])

In [22]: assert np.array_equal(beta ** i, x)
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([157, 201, 116,  30, 230, 186,   2, 103, 140, 214])

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

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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