galois.FieldArray.log(base: ElementLike | ArrayLike | None = None) integer | 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)

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([ 20, 109, 123, 226, 197, 187, 158,  31,  86,  88], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([167, 165, 217, 187, 180, 108, 145, 214,  73, 130])

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

In [9]: i = x.log(); i
Out[9]: array([ 80, 128,  33, 123, 165,  54, 212,  52, 123,  61])

In [10]: np.array_equal(alpha ** i, x)
Out[10]: True
In [11]: GF = galois.GF(3**5, display="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([α^214,  α^40,  α^14, α^224, α^232, α^216,  α^11, α^192,  α^11, α^195],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([214,  40,  14, 224, 232, 216,  11, 192,  11, 195])

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([234,  46,   4,  64, 170, 200,  55, 124,  55,  73])

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([234,  46,   4,  64, 170, 200,  55, 124,  55,  73])

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([234,  46,   4,  64, 170, 200,  55, 124,  55,  73])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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