• 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
          • 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-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

    Strval2

    Interpret a string as a binary number.

    Signature
    (strval2 x) → value?
    Arguments
    x — Guard (stringp x).
    Returns
    value? — Type (or (natp value?) (not value?)).

    For example, (strval2 "1000") is 8. If the string has any characters other than 0 or 1, or is empty, we return nil.

    Definitions and Theorems

    Function: strval2

    (defun strval2 (x)
      (declare (xargs :guard (stringp x)))
      (declare (type string x))
      (declare (xargs :split-types t))
      (let ((acl2::__function__ 'strval2))
        (declare (ignorable acl2::__function__))
        (mbe :logic
             (let ((chars (explode x)))
               (and (consp chars)
                    (bin-digit-char-list*p chars)
                    (bin-digit-chars-value chars)))
             :exec
             (b* (((the unsigned-byte xl) (length x))
                  ((mv (the unsigned-byte val)
                       (the unsigned-byte len))
                   (parse-bits-from-string x 0 0 0 xl)))
               (and (not (eql 0 len))
                    (eql len xl)
                    val)))))

    Theorem: return-type-of-strval2

    (defthm return-type-of-strval2
      (b* ((value? (strval2 x)))
        (or (natp value?) (not value?)))
      :rule-classes :type-prescription)

    Theorem: istreqv-implies-equal-strval2-1

    (defthm istreqv-implies-equal-strval2-1
      (implies (istreqv x x-equiv)
               (equal (strval2 x) (strval2 x-equiv)))
      :rule-classes (:congruence))