• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
      • Std/lists
      • Omaps
      • Std/alists
      • Obags
      • Std/util
      • 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
          • Octal
          • Binary
            • Parse-bits-from-string
            • Parse-bits-from-charlist
            • Nat-to-bin-chars
            • Bin-digit-chars-value
            • Take-leading-bin-digit-chars
            • Bin-digit-char-listp
            • Skip-leading-bit-digits
            • Bin-digit-char-list*p
            • Bin-digit-string-p
              • Bin-digit-string-p-aux
            • Bin-digit-char-value
            • Strval2
            • Nat-to-bin-string
            • Bin-digit-char-p
            • Nat-to-bin-string-list
            • Nat-to-bin-string-size
            • Revappend-nat-to-bin-chars
            • Binify-width
            • Binify
        • 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
  • Binary

Bin-digit-string-p

Recognizer for strings whose characters are all 0 or 1.

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

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

Logically this is defined in terms of bin-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.53 seconds, no garbage
(let ((x "01001"))
  (time$ (loop for i fixnum from 1 to 10000000 do
               (str::bin-digit-string-p x))))

;; 0.99 seconds, 800 MB allocated
(let ((x "01001"))
  (time$ (loop for i fixnum from 1 to 10000000 do
               (str::bin-digit-char-list*p (explode x)))))

Definitions and Theorems

Function: bin-digit-string-p$inline

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

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

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

Subtopics

Bin-digit-string-p-aux