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([145,  30,  83, 216, 109,  13, 143, 153, 124,  93], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([179,  47, 120, 193, 165,  10,  26, 224,  41, 215])

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

In [9]: i = x.log(); i
Out[9]: array([130, 185,  26,  43, 213,  79,  33, 113, 128, 125])

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([α^132,  α^11, α^166,  α^66, α^236, α^222,  α^74,  α^50, α^142, α^215],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([132,  11, 166,  66, 236, 222,  74,  50, 142, 215])

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([176,  55,  82,  88, 102,  98, 194, 118,   6, 217])

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([176,  55,  82,  88, 102,  98, 194, 118,   6, 217])

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([176,  55,  82,  88, 102,  98, 194, 118,   6, 217])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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