Ask Your Question

Revision history [back]

The documentation does not specify it, but it is true. (It should be added to the documentation.)

When you call a.sqrt() first a square root x is computed, and then x = x._balanced_abs() is called.

def _balanced_abs(self):
    """
    This function returns `x` or `-x`, whichever has a
    positive representative in `-n/2 < x \leq n/2`.
    This is used so that the same square root is always returned,
    despite the possibly probabilistic nature of the underlying
    algorithm.
    """
    if self.lift() > self.__modulus.sageInteger >> 1:
        return -self
    else:
        return self