• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Testing-utilities
    • Math
      • Arithmetic
        • Lispfloat
        • Arithmetic-1
        • Number-theory
          • Tonelli-shanks-modular-sqrt-algorithm
          • Defprime
          • Defprime-alias
          • Prime
          • Dm::primep
          • Has-square-root?
            • Prime-fix
            • Secp256k1-group-prime
            • Secp256k1-field-prime
            • Jubjub-subgroup-prime
            • Edwards-bls12-subgroup-prime
            • Bn-254-group-prime
            • Bls12-381-scalar-field-prime
            • Baby-jubjub-subgroup-prime
            • Goldilocks-prime
          • Proof-by-arith
          • Arith-equivs
          • Number-theory
          • Arithmetic-3
          • Arithmetic-2
          • Arithmetic-light
          • Arithmetic-5
        • Bit-vectors
        • Algebra
    • Number-theory

    Has-square-root?

    Modular square root

    Signature
    (has-square-root? a p) → y/n
    Arguments
    a — Guard (natp a).
    p — Guard (natp p).
    Returns
    y/n — Type (booleanp y/n).

    Checks if a has a modular square root in the field \mathbb{F}_p, using Euler's criterion.

    p must be an odd prime.
    0 is considered to have a square root.

    Definitions and Theorems

    Function: has-square-root?

    (defun has-square-root? (a p)
           (declare (xargs :guard (and (natp a) (natp p))))
           (declare (xargs :guard (and (natp a)
                                       (primep p)
                                       (not (equal p 2))
                                       (< a p))))
           (let ((acl2::__function__ 'has-square-root?))
                (declare (ignorable acl2::__function__))
                (and (primep p)
                     (or (= a 0)
                         (equal (acl2::mod-expt-fast a (/ (- p 1) 2) p)
                                1)))))

    Theorem: booleanp-of-has-square-root?

    (defthm booleanp-of-has-square-root?
            (b* ((y/n (has-square-root? a p)))
                (booleanp y/n))
            :rule-classes :rewrite)