• 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
            • Html-encoding
            • Character-kinds
            • Substrings
            • Strtok
            • Equivalences
            • Url-encoding
            • Lines
            • Explode-implode-equalities
            • Ordering
              • Charlistnat<
              • Ichar<
              • Istr<
                • Icharlist<
                • Strnat<
                • Istrsort
              • 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
    • Ordering

    Istr<

    Case-insensitive string less-than test.

    (icharlist< x y) determines whether the string x preceeds y in alphabetical order without regards to case. The characters are compared with ichar< and shorter strings are considered smaller than longer strings.

    Logically, this is identical to:

    (icharlist< (explode x) (explode y))

    But we use a more efficient implementation which avoids coercing the strings into lists.

    NOTE: for reasoning, we leave this function enabled and prefer to work with icharlist< of the explodes as our normal form.

    Definitions and Theorems

    Function: istr<-aux

    (defun istr<-aux (x y n xl yl)
     (declare (type string x)
              (type string y)
              (type integer n)
              (type integer xl)
              (type integer yl)
              (xargs :guard (and (stringp x)
                                 (stringp y)
                                 (natp n)
                                 (<= n (length x))
                                 (<= n (length y))
                                 (equal xl (length x))
                                 (equal yl (length y)))))
     (mbe
      :logic (cond ((zp (- (nfix yl) (nfix n))) nil)
                   ((zp (- (nfix xl) (nfix n))) t)
                   ((ichar< (char x n) (char y n)) t)
                   ((ichar< (char y n) (char x n)) nil)
                   (t (istr<-aux x y (+ (nfix n) 1) xl yl)))
      :exec
      (cond
       ((= (the integer n) (the integer yl))
        nil)
       ((= (the integer n) (the integer xl)) t)
       (t
        (let* ((xc (the (unsigned-byte 8)
                        (char-code (the character
                                        (char (the string x)
                                              (the integer n))))))
               (yc (the (unsigned-byte 8)
                        (char-code (the character
                                        (char (the string y)
                                              (the integer n))))))
               (xc-fix (if (and (<= (big-a) (the (unsigned-byte 8) xc))
                                (<= (the (unsigned-byte 8) xc) (big-z)))
                           (the (unsigned-byte 8)
                                (+ (the (unsigned-byte 8) xc) 32))
                         (the (unsigned-byte 8) xc)))
               (yc-fix (if (and (<= (big-a) (the (unsigned-byte 8) yc))
                                (<= (the (unsigned-byte 8) yc) (big-z)))
                           (the (unsigned-byte 8)
                                (+ (the (unsigned-byte 8) yc) 32))
                         (the (unsigned-byte 8) yc))))
          (cond ((< (the (unsigned-byte 8) xc-fix)
                    (the (unsigned-byte 8) yc-fix))
                 t)
                ((< (the (unsigned-byte 8) yc-fix)
                    (the (unsigned-byte 8) xc-fix))
                 nil)
                (t (istr<-aux (the string x)
                              (the string y)
                              (the integer (+ (the integer n) 1))
                              (the integer xl)
                              (the integer yl)))))))))

    Function: istr<$inline

    (defun istr<$inline (x y)
      (declare (type string x)
               (type string y))
      (mbe :logic (icharlist< (explode x) (explode y))
           :exec (istr<-aux (the string x)
                            (the string y)
                            (the integer 0)
                            (the integer (length (the string x)))
                            (the integer (length (the string y))))))

    Theorem: istr<-aux-correct

    (defthm istr<-aux-correct
      (implies (and (stringp x)
                    (stringp y)
                    (natp n)
                    (<= n (length x))
                    (<= n (length y))
                    (equal xl (length x))
                    (equal yl (length y)))
               (equal (istr<-aux x y n xl yl)
                      (icharlist< (nthcdr n (coerce x 'list))
                                  (nthcdr n (coerce y 'list))))))

    Theorem: istreqv-implies-equal-istr<-1

    (defthm istreqv-implies-equal-istr<-1
      (implies (istreqv x x-equiv)
               (equal (istr< x y) (istr< x-equiv y)))
      :rule-classes (:congruence))

    Theorem: istreqv-implies-equal-istr<-2

    (defthm istreqv-implies-equal-istr<-2
      (implies (istreqv y y-equiv)
               (equal (istr< x y) (istr< x y-equiv)))
      :rule-classes (:congruence))