• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
            • Pretty-printing
            • Printtree
            • Base64
            • Charset-p
            • Strtok!
            • Cases
            • Concatenation
              • Revappend-chars
              • Join
              • Append-chars
                • Cat
                • Rchars-to-string
                • Prefix-strings
              • Html-encoding
              • Character-kinds
              • Substrings
              • Strtok
              • Equivalences
              • Url-encoding
              • Lines
              • Explode-implode-equalities
              • Ordering
              • Numbers
              • Pad-trim
              • Coercion
              • Std/strings/digit-to-char
              • Substitution
              • Symbols
            • String-listp
            • Stringp
            • Length
            • Search
            • Remove-duplicates
            • Position
            • Coerce
            • Concatenate
            • Reverse
            • String
            • Subseq
            • Substitute
            • String-upcase
            • String-downcase
            • Count
            • Char
            • String<
            • String-equal
            • String-utilities
            • String-append
            • String>=
            • String<=
            • String>
            • Hex-digit-char-theorems
            • String-downcase-gen
            • String-upcase-gen
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • 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))