• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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
            • Parse-hex-from-string
            • Hex-digit-char-p
            • 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
              • Hex-digit-string-p-aux
            • 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
      • Std/osets
      • Std/io
      • Std/basic
      • Std/system
      • Std/typed-lists
      • Std/bitsets
      • Std/testing
      • Std/typed-alists
      • Std/stobjs
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Hex

Hex-digit-string-p

Recognizer for strings whose characters are hexadecimal digits.

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

Corner case: this accepts the empty string since all of its characters are hex digits.

Logically this is defined in terms of hex-digit-char-list*p. But in the execution, we use a char-based function that avoids exploding the string. This provides much better performance, e.g., on an AMD FX-8350 with CCL:

;; 0.97 seconds, no garbage
(let ((x "deadbeef"))
  (time$ (loop for i fixnum from 1 to 10000000 do
               (str::hex-digit-string-p x))))

;; 1.74 seconds, 1.28 GB allocated
(let ((x "deadbeef"))
  (time$ (loop for i fixnum from 1 to 10000000 do
               (str::hex-digit-char-list*p (explode x)))))

Definitions and Theorems

Function: hex-digit-string-p$inline

(defun hex-digit-string-p$inline (x)
  (declare (type string x))
  (let ((acl2::__function__ 'hex-digit-string-p))
    (declare (ignorable acl2::__function__))
    (mbe :logic (hex-digit-char-list*p (explode x))
         :exec (hex-digit-string-p-aux x 0 (length x)))))

Theorem: istreqv-implies-equal-hex-digit-string-p-1

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

Subtopics

Hex-digit-string-p-aux