• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
          • Defcharset
          • Count-leading-charset
          • Str-count-leading-charset-fast
            • Str-count-leading-charset
            • Chars-in-charset-p
            • Code-in-charset-p
            • Char-in-charset-p
          • Strtok!
          • Cases
          • Concatenation
          • Html-encoding
          • Character-kinds
          • Substrings
          • Strtok
          • Equivalences
          • Url-encoding
          • Lines
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings-extensions
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/io
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Charset-p

    Str-count-leading-charset-fast

    Fixnum optimized version of str-count-leading-charset.

    Signature
    (str-count-leading-charset-fast n x xl set) → n
    Arguments
    n — Current position in the string.
        Guard (natp n).
    x — String we're iterating through.
        Guard (stringp x).
    xl — Precomputed length of x.
        Guard (eql xl (length x)).
    set — Set of characters we're counting.
        Guard (charset-p set).
    Returns
    n — Type (natp n).

    Definitions and Theorems

    Function: str-count-leading-charset-fast

    (defun str-count-leading-charset-fast (n x xl set)
     (declare (xargs :guard (and (natp n)
                                 (stringp x)
                                 (charset-p set)
                                 (eql xl (length x)))))
     (declare (type (unsigned-byte 60) n xl)
              (type string x))
     (declare (xargs :guard (<= n xl)))
     (let ((acl2::__function__ 'str-count-leading-charset-fast))
      (declare (ignorable acl2::__function__))
      (mbe :logic
           (let ((chars (nthcdr n (coerce x 'list))))
             (count-leading-charset chars set))
           :exec
           (b* (((when (eql n xl)) 0)
                ((the character char1) (char x n))
                ((the (unsigned-byte 60) n) (+ 1 n))
                ((when (char-in-charset-p char1 set))
                 (the (integer 0 *)
                      (+ 1
                         (str-count-leading-charset-fast n x xl set)))))
             0))))

    Theorem: natp-of-str-count-leading-charset-fast

    (defthm natp-of-str-count-leading-charset-fast
      (b* ((n (str-count-leading-charset-fast n x xl set)))
        (natp n))
      :rule-classes :type-prescription)