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([230, 138,   8, 242,  48, 142, 114,  23, 241, 158], order=3^5)

In [4]: i = x.log(); i
Out[4]: array([ 81, 113, 190, 185, 139,  20, 231,  17, 238, 145])

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

In [9]: i = x.log(); i
Out[9]: array([129, 128,  82, 202,  91,  63,  68,  13,  89, 161])

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([α^214,  α^57, α^146, α^105,  α^34,  α^95, α^103, α^195, α^185, α^132],
   order=3^5)

In [14]: i = x.log(); i
Out[14]: array([214,  57, 146, 105,  34,  95, 103, 195, 185, 132])

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, 241, 180, 151, 148,  79, 185,  73,   1, 176])

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, 241, 180, 151, 148,  79, 185,  73,   1, 176])

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, 241, 180, 151, 148,  79, 185,  73,   1, 176])

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

In [27]: bases = GF.primitive_elements

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

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

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

In [35]: bases = GF.primitive_elements

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

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