• 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
            • Parse-nat-from-string
            • Parse-nat-from-charlist
            • Nat-to-dec-chars
            • Dec-digit-chars-value
            • Dec-digit-char-p
              • Dec-digit-char
            • Dec-digit-char-listp
            • Take-leading-dec-digit-chars
            • Dec-digit-char-value
            • Dec-digit-char-list*p
            • Nat-to-dec-string-width
            • Nat-to-dec-string
            • Dec-digit-string-p
            • Strval
            • Skip-leading-digits
            • Nat-to-dec-string-size
            • Int-to-dec-string-width
            • Int-to-dec-string
            • Nonzero-dec-digit-char-p
            • Nat-to-dec-string-list
            • Int-to-dec-string-list
            • Revappend-nat-to-dec-chars
          • Hex
          • Octal
          • 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
  • Decimal

Dec-digit-char-p

Recognizer for numeric characters (0-9).

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

ACL2 provides digit-char-p which is more flexible and can recognize numeric characters in other bases. (dec-digit-char-p x) only recognizes base-10 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 256 collect (code-char i)))

;; 17.130 seconds, no garbage
(time (loop for i fixnum from 1 to 10000000 do
            (loop for c in *chars* do (digit-char-p c))))

;; 3.772 seconds, no garbage
(time (loop for i fixnum from 1 to 10000000 do
            (loop for c in *chars* do (str::dec-digit-char-p c))))

Definitions and Theorems

Function: dec-digit-char-p$inline

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

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

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

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

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

Subtopics

Dec-digit-char
Fixtype of decimal digit characters.