• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
        • Syntax-for-tools
          • Formalized-subset
          • Mapping-to-language-definition
          • Input-files
          • Compilation-database
          • Printer
            • Print-exprs/decls/stmts
            • Print-expr
            • Pristate
            • Print-dec/oct/hex-const
              • Priopt
              • Print-fundef
              • Print-filepath-transunit-map
              • Print-s-char
              • Print-c-char
              • Print-q-char
              • Print-h-char
              • Print-fileset
              • Print-typequal/attribspec-list-list
              • Print-file
              • Print-hex-core-fconst
              • Print-dec-core-fconst
              • Print-ident-list
              • Print-fsuffix
              • Print-oct-digit-achar
              • Print-label-declaration-list
              • Print-hex-frac-const
              • Print-hex-digit-achar
              • Print-dec-frac-const
              • Print-dec-digit-achar
              • Print-asm-clobber-list
              • Print-stringlit-list
              • Print-inc/dec-op-list
              • Print-astring
              • Print-asm-name-spec
              • Print-univ-char-name
              • Print-struni-spec
              • Print-simple-escape
              • Print-label-declaration
              • Print-isuffix-option
              • Print-fsuffix-option
              • Print-extdecl-list
              • Print-eprefix-option
              • Print-dec-expo-option
              • Print-cprefix-option
              • Print-binop
              • Print-attrib-name
              • Print-type-qual
              • Print-s-char-list
              • Print-q-char-list
              • Print-indent
              • Print-ident
              • Print-h-char-list
              • Print-dec-expo-prefix
              • Print-char
              • Print-c-char-list
              • Print-bin-expo-prefix
              • Print-asm-qual-list
              • Print-stringlit
              • Print-stor-spec
              • Print-sign-option
              • Print-oct-escape
              • Print-header-name
              • Print-extdecl
              • Print-escape
              • Print-cconst
              • Print-asm-qual
              • Print-asm-clobber
              • Init-pristate
              • Dec-pristate-indent
              • Print-isuffix
              • Print-fun-spec
              • Print-fconst
              • Print-dec-expo
              • Print-bin-expo
              • Print-unop
              • Print-transunit
              • Print-new-line
              • Print-lsuffix
              • Print-inc/dec-op
              • Print-hex-quad
              • Print-eprefix
              • Print-cprefix
              • Print-usuffix
              • Print-iconst
              • Print-hprefix
              • Print-const
              • Print-comp-stmt
              • Print-hex-digit-achars
              • Print-sign
              • Print-oct-digit-achars
              • Print-dec-digit-achars
              • Print-chars
              • Inc-pristate-indent
              • Print-expr-list
              • Print-struct-declon-list
              • Print-stmt
              • Print-param-declor
              • Print-dirdeclor
              • Default-priopt
              • Print-struct-declor
              • Print-initer
              • Print-decl-inline
              • Print-struct-declon
              • Print-genassoc-list
              • Print-enum-spec
              • Print-absdeclor
              • Print-typequal/attribspec-list
              • Print-desiniter-list
              • Print-const-expr
              • Print-attrib
              • Print-tyname
              • Print-struct-declor-list
              • Print-spec/qual-list
              • Print-param-declon-list
              • Print-param-declon
              • Print-initdeclor-list
              • Print-designor-list
              • Print-decl-spec-list
              • Print-decl-list
              • Print-attrib-spec-list
              • Print-asm-output-list
              • Print-asm-input-list
              • Print-typequal/attribspec
              • Print-statassert
              • Print-spec/qual
              • Print-member-designor
              • Print-initdeclor
              • Print-enumer-list
              • Print-dirabsdeclor
              • Print-desiniter
              • Print-decl-spec
              • Print-decl
              • Print-block-item-list
              • Print-attrib-spec
              • Print-attrib-list
              • Print-asm-output
              • Print-align-spec
              • Print-type-spec
              • Print-label
              • Print-genassoc
              • Print-enumer
              • Print-designor
              • Print-declor
              • Print-block-item
              • Print-asm-stmt
              • Print-asm-input
            • Output-files
            • Abstract-syntax-operations
            • Implementation-environments
            • Abstract-syntax
            • Concrete-syntax
            • Disambiguation
            • Validation
            • Gcc-builtins
            • Preprocessing
            • Parsing
          • Atc
          • Transformation-tools
          • Language
          • Representation
          • Insertion-sort
          • Pack
        • Proof-checker-array
        • Soft
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Ethereum
        • Leftist-trees
        • Java
        • Riscv
        • Taspi
        • Bitcoin
        • Zcash
        • Des
        • X86isa
        • Sha-2
        • Yul
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Axe
        • Poseidon
        • Where-do-i-place-my-book
        • Aleo
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Printer

    Print-dec/oct/hex-const

    Print a decimal, octal, or hexadecimal constant.

    Signature
    (print-dec/oct/hex-const dohconst pstate) → new-pstate
    Arguments
    dohconst — Guard (dec/oct/hex-constp dohconst).
    pstate — Guard (pristatep pstate).
    Returns
    new-pstate — Type (pristatep new-pstate).

    For a decimal constant, the abstract syntax gives us the value (a positive integer), which we convert to ACL2 decimal digit characters, which we print.

    For an octal constant, first we print the leading zeros. We convert the value, which is a non-negative integer, into octal digits, using an auxiliary function from the library that turns 0 into nil, which is what we want, because the octal constant 0 is represented as one leading zero and value zero.

    For a hexadecimal constant, first we print the prefix. We ensure that there is at least one digit (otherwise it is not a syntactically valid hexadecimal constant), and we print them.

    Definitions and Theorems

    Function: print-dec/oct/hex-const

    (defun print-dec/oct/hex-const (dohconst pstate)
     (declare (xargs :guard (and (dec/oct/hex-constp dohconst)
                                 (pristatep pstate))))
     (let ((__function__ 'print-dec/oct/hex-const))
      (declare (ignorable __function__))
      (dec/oct/hex-const-case
       dohconst :dec
       (print-dec-digit-achars (str::nat-to-dec-chars dohconst.value)
                               pstate)
       :oct
       (b*
        ((pstate
             (print-oct-digit-achars (repeat dohconst.leading-zeros #\0)
                                     pstate))
         (pstate (print-oct-digit-achars
                      (str::nat-to-oct-chars-aux dohconst.value nil)
                      pstate)))
        pstate)
       :hex
       (b*
        (((unless dohconst.digits)
          (raise
           "Misusage error: ~
                          the hexadecimal constant has no digits.")
          (pristate-fix pstate))
         (pstate (print-hprefix dohconst.prefix pstate))
         (pstate (print-hex-digit-achars dohconst.digits pstate)))
        pstate))))

    Theorem: pristatep-of-print-dec/oct/hex-const

    (defthm pristatep-of-print-dec/oct/hex-const
      (b* ((new-pstate (print-dec/oct/hex-const dohconst pstate)))
        (pristatep new-pstate))
      :rule-classes :rewrite)

    Theorem: pristate->gcc-of-print-dec/oct/hex-const

    (defthm pristate->gcc-of-print-dec/oct/hex-const
      (b* ((?new-pstate (print-dec/oct/hex-const dohconst pstate)))
        (equal (pristate->gcc new-pstate)
               (pristate->gcc pstate))))

    Theorem: print-dec/oct/hex-const-of-dec/oct/hex-const-fix-dohconst

    (defthm print-dec/oct/hex-const-of-dec/oct/hex-const-fix-dohconst
      (equal (print-dec/oct/hex-const (dec/oct/hex-const-fix dohconst)
                                      pstate)
             (print-dec/oct/hex-const dohconst pstate)))

    Theorem: print-dec/oct/hex-const-dec/oct/hex-const-equiv-congruence-on-dohconst

    (defthm
     print-dec/oct/hex-const-dec/oct/hex-const-equiv-congruence-on-dohconst
     (implies (dec/oct/hex-const-equiv dohconst dohconst-equiv)
              (equal (print-dec/oct/hex-const dohconst pstate)
                     (print-dec/oct/hex-const dohconst-equiv pstate)))
     :rule-classes :congruence)

    Theorem: print-dec/oct/hex-const-of-pristate-fix-pstate

    (defthm print-dec/oct/hex-const-of-pristate-fix-pstate
      (equal (print-dec/oct/hex-const dohconst (pristate-fix pstate))
             (print-dec/oct/hex-const dohconst pstate)))

    Theorem: print-dec/oct/hex-const-pristate-equiv-congruence-on-pstate

    (defthm print-dec/oct/hex-const-pristate-equiv-congruence-on-pstate
      (implies (pristate-equiv pstate pstate-equiv)
               (equal (print-dec/oct/hex-const dohconst pstate)
                      (print-dec/oct/hex-const dohconst pstate-equiv)))
      :rule-classes :congruence)