galois.FieldArray.is_square()

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.

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).

Examples

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

In : GF = galois.GF(2**3)

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

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

In : GF = galois.GF(2**3, repr="poly")

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

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

In : GF = galois.GF(2**3, repr="power")

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

In : x.is_square()
Out: 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 : GF = galois.GF(11)

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

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

In : GF = galois.GF(11, repr="power")

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

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