• 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
        • Strtok!
        • Cases
        • Concatenation
          • Revappend-chars
          • Append-chars
            • Join
            • Cat
            • Rchars-to-string
            • Prefix-strings
          • 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
    • Concatenation

    Append-chars

    Append a string's characters onto a list.

    Signature
    (append-chars x y) → *

    (append-chars x y) takes the characters from the string x and appends them onto y.

    Its logical definition is nothing more than (append (explode x) y).

    In the execution, we traverse the string x using char to avoid the overhead of coerce-ing it into a character list before performing the append. This reduces the overhead from 2n conses to n conses, where n is the length of x.

    Definitions and Theorems

    Function: append-chars-aux

    (defun append-chars-aux (x n y)
           "Appends the characters from x[0:n] onto y"
           (declare (type string x)
                    (type (integer 0 *) n)
                    (xargs :guard (< n (length x))))
           (if (zp n)
               (cons (char x 0) y)
               (append-chars-aux x (the (integer 0 *) (- n 1))
                                 (cons (char x n) y))))

    Theorem: append-chars-aux-correct

    (defthm append-chars-aux-correct
            (implies (and (stringp x)
                          (natp n)
                          (< n (length x)))
                     (equal (append-chars-aux x n y)
                            (append (take (+ 1 n) (explode x)) y))))

    Function: append-chars$inline

    (defun append-chars$inline (x y)
           (declare (type string x))
           (let ((acl2::__function__ 'append-chars))
                (declare (ignorable acl2::__function__))
                (mbe :logic (append (explode x) y)
                     :exec (b* (((the (integer 0 *) xl) (length x))
                                ((when (eql xl 0)) y)
                                ((the (integer 0 *) n) (- xl 1)))
                               (append-chars-aux x n y)))))

    Theorem: character-listp-of-append-chars

    (defthm character-listp-of-append-chars
            (equal (character-listp (append-chars x y))
                   (character-listp y)))

    Theorem: streqv-implies-equal-append-chars-1

    (defthm streqv-implies-equal-append-chars-1
            (implies (streqv x x-equiv)
                     (equal (append-chars x y)
                            (append-chars x-equiv y)))
            :rule-classes (:congruence))

    Theorem: istreqv-implies-icharlisteqv-append-chars-1

    (defthm istreqv-implies-icharlisteqv-append-chars-1
            (implies (istreqv x x-equiv)
                     (icharlisteqv (append-chars x y)
                                   (append-chars x-equiv y)))
            :rule-classes (:congruence))

    Theorem: list-equiv-implies-list-equiv-append-chars-2

    (defthm list-equiv-implies-list-equiv-append-chars-2
            (implies (list-equiv y y-equiv)
                     (list-equiv (append-chars x y)
                                 (append-chars x y-equiv)))
            :rule-classes (:congruence))

    Theorem: charlisteqv-implies-charlisteqv-append-chars-2

    (defthm charlisteqv-implies-charlisteqv-append-chars-2
            (implies (charlisteqv y y-equiv)
                     (charlisteqv (append-chars x y)
                                  (append-chars x y-equiv)))
            :rule-classes (:congruence))

    Theorem: icharlisteqv-implies-icharlisteqv-append-chars-2

    (defthm icharlisteqv-implies-icharlisteqv-append-chars-2
            (implies (icharlisteqv y y-equiv)
                     (icharlisteqv (append-chars x y)
                                   (append-chars x y-equiv)))
            :rule-classes (:congruence))