• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Memoize
        • Mbe
        • Io
        • Apply$
        • Defpkg
        • Mutual-recursion
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Loop$-primer
        • Fast-alists
        • Defmacro
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
          • Natp
          • Unsigned-byte-p
          • Posp
          • +
          • Bitp
          • Zero-test-idioms
          • Nat-listp
          • Integerp
          • <
          • *
          • Zp
          • -
          • Signed-byte-p
          • Logbitp
          • Expt
          • Ash
          • Rationalp
          • Sharp-f-reader
          • Logand
          • =
          • <=
          • Floor
          • Random$
          • Nfix
          • Truncate
          • Complex
          • Numbers-introduction
          • Code-char
          • Integer-length
          • Zip
          • Logior
          • Sharp-u-reader
          • Char-code
          • Unary--
          • Integer-listp
          • Boole$
          • /
          • Mod
          • Logxor
          • Lognot
          • Integer-range-p
          • Ifix
          • ACL2-numberp
          • Ceiling
          • Mod-expt
          • Round
            • Logeqv
            • Explode-nonnegative-integer
            • Max
            • Evenp
            • Nonnegative-integer-quotient
            • Zerop
            • Abs
            • Fix
            • Allocate-fixnum-range
            • Rem
            • 1+
            • Pos-listp
            • Signum
            • Real/rationalp
            • Rational-listp
            • Rfix
            • >=
            • >
            • Logcount
            • ACL2-number-listp
            • /=
            • Unary-/
            • Complex/complex-rationalp
            • Logtest
            • Logandc1
            • Logorc1
            • Logandc2
            • 1-
            • Numerator
            • Logorc2
            • Denominator
            • The-number
            • Realfix
            • Complex-rationalp
            • Min
            • Lognor
            • Zpf
            • Oddp
            • Minusp
            • Lognand
            • Imagpart
            • Conjugate
            • Int=
            • Realpart
            • Plusp
          • Irrelevant-formals
          • Efficiency
          • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
          • Redefining-programs
          • Lists
          • Invariant-risk
          • Errors
          • Defabbrev
          • Conses
          • Alists
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Defmacro-untouchable
          • Primitive
          • <<
          • Revert-world
          • Set-duplicate-keys-action
          • Unmemoize
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Defopen
          • Sleep
        • Start-here
        • Real
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Numbers
    • ACL2-built-ins

    Round

    Division returning an integer by rounding off

    Example Forms:
    ACL2 !>(round 14 3)
    5
    ACL2 !>(round -14 3)
    -5
    ACL2 !>(round 14 -3)
    -5
    ACL2 !>(round -14 -3)
    5
    ACL2 !>(round 13 3)
    4
    ACL2 !>(round -13 3)
    -4
    ACL2 !>(round 13 -3)
    -4
    ACL2 !>(round -13 -3)
    4
    ACL2 !>(round -15 -3)
    5
    ACL2 !>(round 15 -2)
    -8

    (Round i j) is the result of taking the quotient of i and j and rounding off to the nearest integer. When the quotient is exactly halfway between consecutive integers, it rounds to the even one.

    The guard for (round i j) requires that i and j are rational (real, in ACL2(r)) numbers and j is non-zero.

    Round is a Common Lisp function. See any Common Lisp documentation for more information. However, note that unlike Common Lisp, the ACL2 round function returns only a single value,

    Function: round

    (defun
         round (i j)
         (declare (xargs :guard (and (real/rationalp i)
                                     (real/rationalp j)
                                     (not (eql j 0)))))
         (let ((q (* i (/ j))))
              (cond ((integerp q) q)
                    ((>= q 0)
                     (let* ((fl (floor q 1)) (remainder (- q fl)))
                           (cond ((> remainder 1/2) (+ fl 1))
                                 ((< remainder 1/2) fl)
                                 (t (cond ((integerp (* fl (/ 2))) fl)
                                          (t (+ fl 1)))))))
                    (t (let* ((cl (ceiling q 1))
                              (remainder (- q cl)))
                             (cond ((< (- 1/2) remainder) cl)
                                   ((> (- 1/2) remainder) (+ cl -1))
                                   (t (cond ((integerp (* cl (/ 2))) cl)
                                            (t (+ cl -1))))))))))