• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Html-encoding
        • Character-kinds
        • Substrings
        • Strtok
        • Equivalences
        • Url-encoding
        • Lines
        • Explode-implode-equalities
        • Ordering
        • Numbers
          • Decimal
          • Hex
          • Octal
            • Parse-octal-from-string
            • Parse-octal-from-charlist
            • Nat-to-oct-chars
              • Basic-nat-to-oct-chars
              • Nat-to-oct-chars-aux
            • Oct-digit-chars-value
            • Oct-digit-char-p
            • Take-leading-oct-digit-chars
            • Oct-digit-char-value
            • Oct-digit-char-list*p
            • Oct-digit-char-listp
            • Skip-leading-octal-digits
            • Oct-digit-string-p
            • Nat-to-oct-string
            • Strval8
            • Nat-to-oct-string-list
            • Revappend-nat-to-oct-chars
            • Nonzero-oct-digit-char-p
            • Nat-to-oct-string-size
            • Octal-digit-to-char
          • Binary
        • Pad-trim
        • Coercion
        • Std/strings/digit-to-char
        • Substitution
        • Symbols
      • Std/osets
      • Std/io
      • Std/basic
      • Std/system
      • Std/typed-lists
      • Std/bitsets
      • Std/testing
      • Std/typed-alists
      • Std/stobjs
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Octal

Nat-to-oct-chars

Convert a natural number into a list of octal bits.

Signature
(nat-to-oct-chars n) → chars
Arguments
n — Guard (natp n).
Returns
chars — Type (oct-digit-char-list*p chars).

For instance, (nat-to-oct-chars 15) is (#\1 #\7).

This is like ACL2's built-in function explode-nonnegative-integer, except that it doesn't deal with accumulators and is limited to base-8 numbers. These simplifications lead to particularly nice rules, e.g., about oct-digit-chars-value, and somewhat better performance:

;; Times reported by an AMD FX-8350, Linux, 64-bit CCL:

;; 1.114 seconds, 1.241 GB allocated
(progn (gc$)
       (time (loop for i fixnum from 1 to 10000000 do
                   (str::nat-to-oct-chars i))))

;; 4.727 seconds, 1.241 GB allocated
(progn (gc$)
       (time (loop for i fixnum from 1 to 10000000 do
          (explode-nonnegative-integer i 8 nil))))

Definitions and Theorems

Function: nat-to-oct-chars$inline

(defun nat-to-oct-chars$inline (n)
  (declare (xargs :guard (natp n)))
  (let ((acl2::__function__ 'nat-to-oct-chars))
    (declare (ignorable acl2::__function__))
    (or (nat-to-oct-chars-aux n nil)
        '(#\0))))

Theorem: oct-digit-char-list*p-of-nat-to-oct-chars

(defthm oct-digit-char-list*p-of-nat-to-oct-chars
  (b* ((chars (nat-to-oct-chars$inline n)))
    (oct-digit-char-list*p chars))
  :rule-classes :rewrite)

Theorem: true-listp-of-nat-to-oct-chars

(defthm true-listp-of-nat-to-oct-chars
  (and (true-listp (nat-to-oct-chars n))
       (consp (nat-to-oct-chars n)))
  :rule-classes :type-prescription)

Theorem: character-listp-of-nat-to-oct-chars

(defthm character-listp-of-nat-to-oct-chars
  (character-listp (nat-to-oct-chars n)))

Theorem: nat-to-oct-chars-one-to-one

(defthm nat-to-oct-chars-one-to-one
  (equal (equal (nat-to-oct-chars n)
                (nat-to-oct-chars m))
         (equal (nfix n) (nfix m))))

Theorem: oct-digit-chars-value-of-nat-to-oct-chars

(defthm oct-digit-chars-value-of-nat-to-oct-chars
  (equal (oct-digit-chars-value (nat-to-oct-chars n))
         (nfix n)))

Subtopics

Basic-nat-to-oct-chars
Logically simple definition that is similar to nat-to-oct-chars.
Nat-to-oct-chars-aux