• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defconst
        • Fast-alists
        • Defmacro
        • Loop$-primer
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
          • String-listp
          • Stringp
          • Length
          • Search
          • Remove-duplicates
          • Position
          • Coerce
          • Concatenate
          • Reverse
          • String
          • Subseq
          • Substitute
          • String-upcase
          • String-downcase
          • Count
          • Char
          • String<
          • String-equal
          • String-utilities
            • Code-char-injectivity-theorem
            • 8bitbytes-hexchars-conversions
            • Code-char-inverses-theorems
            • String-kinds
            • String-codelist-conversions
            • Charlist-codelist-conversions
              • Chars=>nats
              • Nats=>chars
                • Nats<=>chars-inverses-theorems
            • 8bitbytes-hexstrings-conversions
          • String-append
          • String>=
          • String<=
          • String>
          • Hex-digit-char-theorems
          • String-downcase-gen
          • String-upcase-gen
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Miscellaneous
      • Output-controls
      • Bdd
      • Macros
      • Installation
      • Mailing-lists
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Charlist-codelist-conversions

Nats=>chars

Convert a true list of natural numbers below 256 to the corresponding true list of characters.

Signature
(nats=>chars nats) → chars
Arguments
nats — Guard (unsigned-byte-listp 8 nats).
Returns
chars — Type (character-listp chars).

This operation has a natural-recursive definition for logic reasoning and a tail-recursive executional for execution.

Definitions and Theorems

Function: nats=>chars-exec

(defun nats=>chars-exec (nats rev-chars)
  (declare (xargs :guard (and (unsigned-byte-listp 8 nats)
                              (character-listp rev-chars))))
  (let ((__function__ 'nats=>chars-exec))
    (declare (ignorable __function__))
    (cond ((endp nats) (rev rev-chars))
          (t (nats=>chars-exec (cdr nats)
                               (cons (code-char (car nats))
                                     rev-chars))))))

Function: nats=>chars

(defun nats=>chars (nats)
  (declare (xargs :guard (unsigned-byte-listp 8 nats)))
  (let ((__function__ 'nats=>chars))
    (declare (ignorable __function__))
    (mbe :logic (cond ((endp nats) nil)
                      (t (cons (code-char (car nats))
                               (nats=>chars (cdr nats)))))
         :exec (nats=>chars-exec nats nil))))

Theorem: character-listp-of-nats=>chars

(defthm character-listp-of-nats=>chars
  (b* ((chars (nats=>chars nats)))
    (character-listp chars))
  :rule-classes :rewrite)

Theorem: len-of-nats=>chars

(defthm len-of-nats=>chars
  (equal (len (nats=>chars nats))
         (len nats)))

Theorem: nats=>chars-of-cons

(defthm nats=>chars-of-cons
  (equal (nats=>chars (cons nat nats))
         (cons (code-char nat)
               (nats=>chars nats))))

Theorem: nats=>chars-of-append

(defthm nats=>chars-of-append
  (equal (nats=>chars (append nats1 nats2))
         (append (nats=>chars nats1)
                 (nats=>chars nats2))))

Theorem: nats=>chars-of-repeat

(defthm nats=>chars-of-repeat
  (equal (nats=>chars (repeat n char))
         (repeat n (code-char char))))

Theorem: nth-of-nats=>chars

(defthm nth-of-nats=>chars
  (equal (nth i (nats=>chars nats))
         (if (< (nfix i) (len nats))
             (code-char (nth i nats))
           nil)))

Theorem: nats=>chars-of-revappend

(defthm nats=>chars-of-revappend
  (equal (nats=>chars (revappend x y))
         (revappend (nats=>chars x)
                    (nats=>chars y))))

Theorem: nats=>chars-of-nthcdr

(defthm nats=>chars-of-nthcdr
  (equal (nats=>chars (nthcdr n nats))
         (nthcdr n (nats=>chars nats))))

Theorem: nats=>chars-of-take

(defthm nats=>chars-of-take
  (implies (<= (nfix n) (len nats))
           (equal (nats=>chars (take n nats))
                  (take n (nats=>chars nats)))))

Subtopics

Nats<=>chars-inverses-theorems
nats=>chars and chars=>nats are mutual inverses.