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

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

Danger

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 (which is slower than lookup tables).

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([194,   8, 143, 164, 105, 105, 202,  10,  72,  90], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([141, 190,  26,  68, 150, 150,  82,  46, 192,  48])

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

In [9]: i = x.log(); i
Out[9]: array([ 17, 203,   5, 158, 127, 182, 178,  12,  73,  11])

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([ α^68,  α^26,  α^74, α^151, α^138, α^207,  α^15,  α^47,  α^66, α^153],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([ 68,  26,  74, 151, 138, 207,  15,  47,  66, 153])

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([ 54,  42, 194,  95,  74, 111, 229, 169,  88,  61])

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([ 54,  42, 194,  95,  74, 111, 229, 169,  88,  61])

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([ 54,  42, 194,  95,  74, 111, 229, 169,  88,  61])

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

In [27]: bases = GF.primitive_elements

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

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

In [31]: bases = GF.primitive_elements

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

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

In [35]: bases = GF.primitive_elements

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

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