• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
        • Syntax-for-tools
        • Atc
        • Language
          • Abstract-syntax
          • Integer-ranges
            • Def-integer-range
              • Integer-type-rangep
              • Ushort-integer
              • Ullong-integer
              • Sshort-integer
              • Sllong-integer
              • Ulong-integer
              • Uint-integer
              • Uchar-integer
              • Slong-integer
              • Sint-integer
              • Schar-integer
              • Ushort-max
              • Slong-max
              • Integer-type-max
              • Sllong-max
              • Integer-type-min
              • Uint-max
              • Sint-max
              • Ulong-max
              • Uchar-max
              • Def-integer-range-loop
              • Sshort-min
              • Sshort-max
              • Slong-min
              • Sint-min
              • Ullong-max
              • Sllong-min
              • Schar-min
              • Schar-max
              • Ushort-integer-list
              • Ulong-integer-list
              • Ullong-integer-list
              • Uint-integer-list
              • Uchar-integer-list
              • Sshort-integer-list
              • Slong-integer-list
              • Sllong-integer-list
              • Sint-integer-list
              • Schar-integer-list
              • Uchar-integerp-alt-def
              • Ushort-integerp-alt-def
              • Ulong-integerp-alt-def
              • Ullong-integerp-alt-def
              • Uint-integerp-alt-def
              • Sshort-integerp-alt-def
              • Slong-integerp-alt-def
              • Sllong-integerp-alt-def
              • Sint-integerp-alt-def
              • Schar-integerp-alt-def
            • Implementation-environments
            • Dynamic-semantics
            • Static-semantics
            • Grammar
            • Integer-formats
            • Types
            • Portable-ascii-identifiers
            • Values
            • Integer-operations
            • Computation-states
            • Object-designators
            • Operations
            • Errors
            • Tag-environments
            • Function-environments
            • Character-sets
            • Flexible-array-member-removal
            • Arithmetic-operations
            • Pointer-operations
            • Bytes
            • Keywords
            • Real-operations
            • Array-operations
            • Scalar-operations
            • Structure-operations
          • Representation
          • Transformation-tools
          • Insertion-sort
          • Pack
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Integer-ranges

    Def-integer-range

    Event to generate fixtypes, functions, and theorems for ranges of integer types.

    Signature
    (def-integer-range type) → event
    Arguments
    type — Guard (typep type).
    Returns
    event — Type (pseudo-event-formp event).

    Definitions and Theorems

    Function: def-integer-range

    (defun def-integer-range (type)
     (declare (xargs :guard (typep type)))
     (declare (xargs :guard (type-nonchar-integerp type)))
     (let ((__function__ 'def-integer-range))
      (declare (ignorable __function__))
      (b* ((type-string (integer-type-xdoc-string type))
           (minbits (integer-type-minbits type))
           (signedp (type-signed-integerp type))
           (maxbound (if signedp (1- (expt 2 (1- minbits)))
                       (1- (expt 2 minbits))))
           (minbound (if signedp (- (expt 2 (1- minbits)))
                       0))
           (<type>-bits (integer-type-bits-nulfun type))
           (<type> (intern$ (symbol-name (type-kind type))
                            "C"))
           (<type>-integer (pack <type> '-integer))
           (<type>-integerp (pack <type>-integer 'p))
           (<type>-integerp-alt-def (pack <type>-integerp '-alt-def))
           (<type>-integer-list (pack <type>-integer '-list))
           (<type>-integer-listp (pack <type>-integer-list 'p))
           (<type>-max (pack <type> '-max))
           (<type>-min (pack <type> '-min)))
       (cons
        'progn
        (cons
         (cons
          'fty::defbyte
          (cons
           <type>-integer
           (cons
            ':short
            (cons
             (str::cat "Fixtype of ACL2 integers in the range of "
                       type-string ".")
             (cons
              ':size
              (cons
                  (cons <type>-bits 'nil)
                  (cons ':signed
                        (cons signedp
                              (cons ':pred
                                    (cons <type>-integerp 'nil))))))))))
         (cons
          (cons
           'fty::deflist
           (cons
            <type>-integer-list
            (cons
             ':short
             (cons
              (str::cat
                   "Fixtype of lists of ACL2 integers in the range of "
                   type-string ".")
              (cons
               ':elt-type
               (cons
                <type>-integer
                (cons
                 ':true-listp
                 (cons
                  't
                  (cons
                   ':elementp-of-nil
                   (cons
                       'nil
                       (cons ':pred
                             (cons <type>-integer-listp 'nil))))))))))))
          (cons
           (cons
            'define
            (cons
             <type>-max
             (cons
              'nil
              (cons
               ':returns
               (cons
                (cons <type>-max
                      '(integerp :rule-classes :type-prescription))
                (cons
                 ':short
                 (cons
                  (str::cat "Maximum ACL2 integer value of "
                            type-string ".")
                  (cons
                   (cons
                    '1-
                    (cons
                     (cons
                      'expt
                      (cons
                       '2
                       (cons
                          (if signedp
                              (cons '1-
                                    (cons (cons <type>-bits 'nil) 'nil))
                            (cons <type>-bits 'nil))
                          'nil)))
                     'nil))
                   (cons
                    '///
                    (cons
                     (cons
                      'in-theory
                      (cons
                           (cons 'disable
                                 (cons (cons ':e (cons <type>-max 'nil))
                                       'nil))
                           'nil))
                     (cons
                      (cons
                       'defrule
                       (cons
                        (pack <type>-max '-bound)
                        (cons
                         (cons '>=
                               (cons (cons <type>-max 'nil)
                                     (cons maxbound 'nil)))
                         (cons
                          ':rule-classes
                          (cons
                           ':linear
                           (cons
                            ':enable
                            (cons
                             <type>-max
                             (cons
                              ':use
                              (cons
                               (cons
                                ':instance
                                (cons
                                 'acl2::expt-is-weakly-increasing-for-base->-1
                                 (cons
                                  (cons
                                   'm
                                   (cons
                                       (if signedp (1- minbits) minbits)
                                       'nil))
                                  (cons
                                   (cons
                                    'n
                                    (cons
                                     (if signedp
                                      (cons
                                           '1-
                                           (cons (cons <type>-bits 'nil)
                                                 'nil))
                                      (cons <type>-bits 'nil))
                                     'nil))
                                   '((x 2))))))
                               'nil)))))))))
                      'nil)))))))))))
           (append
            (and
             signedp
             (cons
              (cons
               'define
               (cons
                <type>-min
                (cons
                 'nil
                 (cons
                  ':returns
                  (cons
                   (cons <type>-min
                         '(integerp :rule-classes :type-prescription))
                   (cons
                    ':short
                    (cons
                     (str::cat "Minimum ACL2 integer value of "
                               type-string ".")
                     (cons
                      (cons
                       '-
                       (cons
                        (cons
                         'expt
                         (cons
                          '2
                          (cons
                              (cons '1-
                                    (cons (cons <type>-bits 'nil) 'nil))
                              'nil)))
                        'nil))
                      (cons
                       '///
                       (cons
                        (cons
                         'in-theory
                         (cons
                           (cons 'disable
                                 (cons (cons ':e (cons <type>-min 'nil))
                                       'nil))
                           'nil))
                        (cons
                         (cons
                          'defrule
                          (cons
                           (pack <type>-min '-bound)
                           (cons
                            (cons '<=
                                  (cons (cons <type>-min 'nil)
                                        (cons minbound 'nil)))
                            (cons
                             ':rule-classes
                             (cons
                              ':linear
                              (cons
                               ':enable
                               (cons
                                <type>-min
                                (cons
                                 ':use
                                 (cons
                                  (cons
                                   ':instance
                                   (cons
                                    'acl2::expt-is-weakly-increasing-for-base->-1
                                    (cons
                                     (cons 'm (cons (1- minbits) 'nil))
                                     (cons
                                      (cons
                                       'n
                                       (cons
                                        (cons
                                           '1-
                                           (cons (cons <type>-bits 'nil)
                                                 'nil))
                                        'nil))
                                      '((x 2))))))
                                  'nil)))))))))
                         'nil)))))))))))
              'nil))
            (cons
             (cons
              'defruled
              (cons
               <type>-integerp-alt-def
               (cons
                ':short
                (cons
                 (str::cat
                    "Alternative definition of @(tsee "
                    (str::downcase-string (symbol-name <type>-integerp))
                    ") as integer range.")
                 (cons
                  (cons
                   'equal
                   (cons
                    (cons <type>-integerp '(x))
                    (cons
                     (cons
                      'and
                      (cons
                       '(integerp x)
                       (cons
                        (cons
                             '<=
                             (cons (if signedp (cons <type>-min 'nil) 0)
                                   '(x)))
                        (cons
                         (cons
                              '<=
                              (cons 'x
                                    (cons (cons <type>-max 'nil) 'nil)))
                         'nil))))
                     'nil)))
                  (cons
                   ':enable
                   (cons
                      (cons <type>-integerp
                            (cons <type>-max
                                  (and signedp (cons <type>-min 'nil))))
                      'nil)))))))
             'nil)))))))))

    Theorem: pseudo-event-formp-of-def-integer-range

    (defthm pseudo-event-formp-of-def-integer-range
      (b* ((event (def-integer-range type)))
        (pseudo-event-formp event))
      :rule-classes :rewrite)

    Theorem: def-integer-range-of-type-fix-type

    (defthm def-integer-range-of-type-fix-type
      (equal (def-integer-range (type-fix type))
             (def-integer-range type)))

    Theorem: def-integer-range-type-equiv-congruence-on-type

    (defthm def-integer-range-type-equiv-congruence-on-type
      (implies (type-equiv type type-equiv)
               (equal (def-integer-range type)
                      (def-integer-range type-equiv)))
      :rule-classes :congruence)