• 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
            • Pretty-printing
            • Printtree
            • Base64
            • Charset-p
            • Strtok!
            • Cases
            • Concatenation
            • Character-kinds
            • Html-encoding
            • Substrings
            • Strtok
            • Equivalences
            • Url-encoding
            • Lines
            • Explode-implode-equalities
            • Ordering
            • Numbers
              • Decimal
              • Hex
                • Parse-hex-from-string
                • Hex-digit-char-p
                  • Hex-digit-char
                • Nat-to-hex-chars
                • Parse-hex-from-charlist
                • Hex-digit-chars-value
                • Hex-digit-char-value
                • Take-leading-hex-digit-chars
                • Hexify
                • Hex-digit-char-listp
                • Hex-digit-char-list*p
                • Hex-digit-string-p
                • Strval16
                • Skip-leading-hex-digits
                • Nat-to-hex-string
                • Hexify-width
                • Nonzero-hex-digit-char-p
                • Nat-to-hex-string-list
                • Revappend-nat-to-hex-chars
                • Hex-digit-to-char
                • Nat-to-hex-string-size
              • Octal
              • Binary
            • Pad-trim
            • Coercion
            • Std/strings/digit-to-char
            • Substitution
            • Symbols
          • 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
          • 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
  • Hex

Hex-digit-char-p

Recognizer for hexadecimal digit characters: 0-9, A-F, a-f.

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

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

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

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

Definitions and Theorems

Function: hex-digit-char-p$inline

(defun hex-digit-char-p$inline (x)
  (declare (xargs :guard t))
  (let ((acl2::__function__ 'hex-digit-char-p))
    (declare (ignorable acl2::__function__))
    (mbe :logic
         (let ((code (char-code (char-fix x))))
           (or (and (<= (char-code #\0) code)
                    (<= code (char-code #\9)))
               (and (<= (char-code #\a) code)
                    (<= code (char-code #\f)))
               (and (<= (char-code #\A) code)
                    (<= code (char-code #\F)))))
         :exec (and (characterp x)
                    (b* (((the (unsigned-byte 8) code)
                          (char-code (the character x))))
                      (if (<= code 70)
                          (if (<= code 57)
                              (<= 48 code)
                            (<= 65 code))
                        (and (<= code 102) (<= 97 code))))))))

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

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

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

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

Theorem: hex-digit-char-p-cases

(defthm hex-digit-char-p-cases
  (iff (hex-digit-char-p x)
       (member x
               '(#\0 #\1 #\2
                     #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\a #\b #\c
                     #\d #\e #\f #\A #\B #\C #\D #\E #\F))))

Subtopics

Hex-digit-char
Fixtype of hexadecimal digit characters.