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

Computes the discrete logarithm of the array x base β.

Parameters:
base: ElementLike | ArrayLike | None = None

A primitive element or elements β 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 β such that βi=x. The return array shape obeys NumPy broadcasting rules.

Examples

Compute the logarithm of x with default base α, 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, 160, 170,  66,  25,  72, 145,  27, 153,  86], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([179, 184, 100, 102,  88, 192, 179,   3, 224,  73])

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

In [9]: i = x.log(); i
Out[9]: array([100, 133,  15, 183, 210, 201,  47,  29,  41,  37])

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([α^180,  α^11, α^103,  α^48,  α^22, α^129,  α^39, α^241, α^174,  α^98],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([180,  11, 103,  48,  22, 129,  39, 241, 174,  98])

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 β, 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([ 86,  55, 185, 152, 110, 227,  63,  17, 188,  28])

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([ 86,  55, 185, 152, 110, 227,  63,  17, 188,  28])

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([ 86,  55, 185, 152, 110, 227,  63,  17, 188,  28])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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