galois.FieldArray.is_square() bool | ndarray

Determines if the elements of \(x\) are squares in the finite field.

Returns:

A boolean array indicating if each element in \(x\) is a square. The return value is a single boolean if the input array \(x\) is a scalar.

See also

squares, non_squares

Notes

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

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

References

Examples

Since \(\mathrm{GF}(2^3)\) has characteristic 2, every element has a square root.

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

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

In [3]: x.is_square()
Out[3]: array([ True,  True,  True,  True,  True,  True,  True,  True])
In [4]: GF = galois.GF(2**3, repr="poly")

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

In [6]: x.is_square()
Out[6]: array([ True,  True,  True,  True,  True,  True,  True,  True])
In [7]: GF = galois.GF(2**3, repr="power")

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

In [9]: x.is_square()
Out[9]: array([ True,  True,  True,  True,  True,  True,  True,  True])

In \(\mathrm{GF}(11)\), the characteristic is greater than 2 so only half of the elements have square roots.

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

In [11]: x = GF.elements; x
Out[11]: GF([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10], order=11)

In [12]: x.is_square()
Out[12]: 
array([ True,  True, False,  True,  True,  True, False, False, False,
        True, False])
In [13]: GF = galois.GF(11, repr="power")

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

In [15]: x.is_square()
Out[15]: 
array([ True,  True, False,  True,  True,  True, False, False, False,
        True, False])