• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
          • Syntax-for-tools
          • Atc
            • Atc-implementation
              • Atc-abstract-syntax
              • Atc-pretty-printer
              • Atc-event-and-code-generation
              • Fty-pseudo-term-utilities
              • Atc-term-recognizers
              • Atc-input-processing
              • Atc-shallow-embedding
              • Atc-process-inputs-and-gen-everything
              • Atc-table
              • Atc-fn
              • Atc-pretty-printing-options
              • Atc-types
                • Type-to-tyname
                • Ident+type-to-tyspec+declor
                • Positive-to-iconst
                  • Type-to-maker
                  • Irr-type
                • Atc-macro-definition
              • Atc-tutorial
              • Pure-expression-execution
            • Transformation-tools
            • Language
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Atc-types

    Positive-to-iconst

    Turn a positive integer into an integer constant.

    Signature
    (positive-to-iconst pos) → iconst
    Arguments
    pos — Guard (posp pos).
    Returns
    iconst — Type (iconstp iconst).

    We always generate a decimal constant of the smallest type that can represent it. We cause an internal error if the integer is too large even for unsigned long long. This is never expected to happen, given expected invariants that hold when this function is called.

    Definitions and Theorems

    Function: positive-to-iconst

    (defun positive-to-iconst (pos)
      (declare (xargs :guard (posp pos)))
      (let ((__function__ 'positive-to-iconst))
        (declare (ignorable __function__))
        (cond ((<= pos (sint-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp nil
                            :length (iconst-length-none)))
              ((<= pos (uint-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp t
                            :length (iconst-length-none)))
              ((<= pos (slong-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp nil
                            :length (iconst-length-long)))
              ((<= pos (ulong-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp t
                            :length (iconst-length-long)))
              ((<= pos (sllong-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp nil
                            :length (iconst-length-llong)))
              ((<= pos (ullong-max))
               (make-iconst :value pos
                            :base (iconst-base-dec)
                            :unsignedp t
                            :length (iconst-length-llong)))
              (t (prog2$ (raise "Internal error: ~x0 too large." pos)
                         (ec-call (iconst-fix :irrelevant)))))))

    Theorem: iconstp-of-positive-to-iconst

    (defthm iconstp-of-positive-to-iconst
      (b* ((iconst (positive-to-iconst pos)))
        (iconstp iconst))
      :rule-classes :rewrite)