def squareroot(self):
    ' This method returns the positive square root of\n            an element of the field\n            using the Tonelli-Shanks algorithm\n\n            Carefull : if the element has no square root, the method does not\n            check this case and raises an error. Verification has to be done\n            before calling the method.\n        '
    g = self.F.g
    if (g == None):
        g = self.F.findnonresidue()
        self.F.g = g
    q = self.F.q
    s = 0
    t = (self.F.q - 1)
    while ((t % 2) == 0):
        s = (s + 1)
        t = (t / 2)
    e = 0
    for i in range(2, (s + 1)):
        b = (2 ** (i - 1))
        b1 = (b * 2)
        c = ((self * (g ** (- e))) ** ((q - 1) / b1))
        if (not (c == self.F.one())):
            e = (e + b)
    h = (self * (g ** (- e)))
    b = ((g ** (e / 2)) * (h ** ((t + 1) / 2)))
    assert ((b ** 2) == self)
    return b
This method returns the positive square root of
an element of the field
using the Tonelli-Shanks algorithm

Carefull : if the element has no square root, the method does not
check this case and raises an error. Verification has to be done
before calling the method.
def squareroot(self):
    ' This method returns the positive square root of\n            an element of the field\n            using the Tonelli-Shanks algorithm\n\n            Carefull : if the element has no square root, the method does not\n            check this case and raises an error. Verification has to be done\n            before calling the method.\n        '
    g = self.F.g
    if (g == None):
        g = self.F.findnonresidue()
        self.F.g = g
    q = self.F.q
    s = 0
    t = (self.F.q - 1)
    while ((t % 2) == 0):
        s = (s + 1)
        t = (t / 2)
    e = 0
    for i in range(2, (s + 1)):
        b = (2 ** (i - 1))
        b1 = (b * 2)
        c = ((self * (g ** (- e))) ** ((q - 1) / b1))
        if (not (c == self.F.one())):
            e = (e + b)
    h = (self * (g ** (- e)))
    b = ((g ** (e / 2)) * (h ** ((t + 1) / 2)))
    assert ((b ** 2) == self)
    return b