class property galois.FieldArray.squares : FieldArray

All squares in the finite field.

An element \(x\) in \(\mathrm{GF}(p^m)\) is a square if there exists a \(y\) such that \(y^2 = x\) in the field.

See also

is_square

Examples

In fields with characteristic 2, every element is a square (with two identical square roots).

In [1]: GF = galois.GF(2**3)

In [2]: x = GF.squares; x
Out[2]: GF([0, 1, 2, 3, 4, 5, 6, 7], order=2^3)

In [3]: y1 = np.sqrt(x); y1
Out[3]: GF([0, 1, 6, 7, 2, 3, 4, 5], order=2^3)

In [4]: y2 = -y1; y2
Out[4]: GF([0, 1, 6, 7, 2, 3, 4, 5], order=2^3)

In [5]: np.array_equal(y1 ** 2, x)
Out[5]: True

In [6]: np.array_equal(y2 ** 2, x)
Out[6]: True
In [7]: GF = galois.GF(2**3, display="poly")

In [8]: x = GF.squares; x
Out[8]: 
GF([          0,           1,           α,       α + 1,         α^2,
        α^2 + 1,     α^2 + α, α^2 + α + 1], order=2^3)

In [9]: y1 = np.sqrt(x); y1
Out[9]: 
GF([          0,           1,     α^2 + α, α^2 + α + 1,           α,
          α + 1,         α^2,     α^2 + 1], order=2^3)

In [10]: y2 = -y1; y2
Out[10]: 
GF([          0,           1,     α^2 + α, α^2 + α + 1,           α,
          α + 1,         α^2,     α^2 + 1], order=2^3)

In [11]: np.array_equal(y1 ** 2, x)
Out[11]: True

In [12]: np.array_equal(y2 ** 2, x)
Out[12]: True
In [13]: GF = galois.GF(2**3, display="power")

In [14]: x = GF.squares; x
Out[14]: GF([  0,   1,   α, α^3, α^2, α^6, α^4, α^5], order=2^3)

In [15]: y1 = np.sqrt(x); y1
Out[15]: GF([  0,   1, α^4, α^5,   α, α^3, α^2, α^6], order=2^3)

In [16]: y2 = -y1; y2
Out[16]: GF([  0,   1, α^4, α^5,   α, α^3, α^2, α^6], order=2^3)

In [17]: np.array_equal(y1 ** 2, x)
Out[17]: True

In [18]: np.array_equal(y2 ** 2, x)
Out[18]: True

In fields with characteristic greater than 2, exactly half of the nonzero elements are squares (with two unique square roots).

In [19]: GF = galois.GF(11)

In [20]: x = GF.squares; x
Out[20]: GF([0, 1, 3, 4, 5, 9], order=11)

In [21]: y1 = np.sqrt(x); y1
Out[21]: GF([0, 1, 5, 2, 4, 3], order=11)

In [22]: y2 = -y1; y2
Out[22]: GF([ 0, 10,  6,  9,  7,  8], order=11)

In [23]: np.array_equal(y1 ** 2, x)
Out[23]: True

In [24]: np.array_equal(y2 ** 2, x)
Out[24]: True
In [25]: GF = galois.GF(11, display="power")

In [26]: x = GF.squares; x
Out[26]: GF([  0,   1, α^8, α^2, α^4, α^6], order=11)

In [27]: y1 = np.sqrt(x); y1
Out[27]: GF([  0,   1, α^4,   α, α^2, α^8], order=11)

In [28]: y2 = -y1; y2
Out[28]: GF([  0, α^5, α^9, α^6, α^7, α^3], order=11)

In [29]: np.array_equal(y1 ** 2, x)
Out[29]: True

In [30]: np.array_equal(y2 ** 2, x)
Out[30]: True