• 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
            • Oct-digit-chars-value
            • Oct-digit-char-p
              • Oct-digit-char
            • 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

Oct-digit-char-p

Recognizer for octal digit characters: 0-7.

Signature
(oct-digit-char-p x) → bool

ACL2 provides digit-char-p which is more flexible and can recognize numeric characters in other bases. (oct-digit-char-p x) only recognizes base-8 digits, but is much faster, at least on CCL. Here is an experiment you can run in raw lisp, with times reported in CCL on an AMD FX-8350.

(defconstant *chars*
  (loop for i from 0 to 255 collect (code-char i)))

;; 18.137 seconds
(time (loop for i fixnum from 1 to 10000000 do
            (loop for c in *chars* do (digit-char-p c 16))))

;; 3.435 seconds
(time (loop for i fixnum from 1 to 10000000 do
            (loop for c in *chars* do (str::oct-digit-char-p c))))

Definitions and Theorems

Function: oct-digit-char-p$inline

(defun oct-digit-char-p$inline (x)
  (declare (xargs :guard t))
  (let ((acl2::__function__ 'oct-digit-char-p))
    (declare (ignorable acl2::__function__))
    (mbe :logic
         (let ((code (char-code (char-fix x))))
           (and (<= (char-code #\0) code)
                (<= code (char-code #\7))))
         :exec (and (characterp x)
                    (b* (((the (unsigned-byte 8) code)
                          (char-code (the character x))))
                      (and (<= code 55) (<= 48 code)))))))

Theorem: ichareqv-implies-equal-oct-digit-char-p-1

(defthm ichareqv-implies-equal-oct-digit-char-p-1
  (implies (ichareqv x x-equiv)
           (equal (oct-digit-char-p x)
                  (oct-digit-char-p x-equiv)))
  :rule-classes (:congruence))

Theorem: characterp-when-oct-digit-char-p

(defthm characterp-when-oct-digit-char-p
  (implies (oct-digit-char-p char)
           (characterp char))
  :rule-classes :compound-recognizer)

Theorem: oct-digit-char-p-cases

(defthm oct-digit-char-p-cases
  (iff (oct-digit-char-p x)
       (member x '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7))))

Subtopics

Oct-digit-char
Fixtype of octal digit characters.