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([ 55, 108,  31, 111,  90,  67, 163,  59, 154, 219], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([136,  72, 214, 228,  48,  39, 241,  77, 154, 110])

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

In [9]: i = x.log(); i
Out[9]: array([121, 135,  72, 175, 163,   4, 135,  24,  19,  21])

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([α^179,  α^68,  α^73,  α^54, α^163,  α^75, α^132,  α^31,  α^66,  α^49],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([179,  68,  73,  54, 163,  75, 132,  31,  66,  49])

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([103,  54, 211,  50, 133, 177, 176, 199,  88, 135])

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([103,  54, 211,  50, 133, 177, 176, 199,  88, 135])

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([103,  54, 211,  50, 133, 177, 176, 199,  88, 135])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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