• 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

    Ichar<

    Case-insensitive character less-than test.

    (ichar< x y) determines if x is "smaller" than y, but ignoring case. Our approach is basically to downcase upper-case letters and then compare the resulting character codes.

    Something subtle about this is that, in the ASCII character ordering, the upper-case characters do not immediately preceede the lower-case ones. That is, upper-case Z is at 90, but lower-case a does not start until 97. So, in our approach, the 6 intervening characters (the square brackets, backslash, hat, underscore, and backtick) are considered "smaller" than letters, even though in regular ASCII ordering they are "larger" than the upper-case letters.

    Definitions and Theorems

    Function: ichar<$inline

    (defun ichar<$inline (x y)
     (declare (type character x)
              (type character y))
     (mbe
        :logic
        (< (char-code (downcase-char x))
           (char-code (downcase-char y)))
        :exec
        (let* ((xc (the (unsigned-byte 8)
                        (char-code (the character x))))
               (yc (the (unsigned-byte 8)
                        (char-code (the character y))))
               (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))))
          (< (the (unsigned-byte 8) xc-fix)
             (the (unsigned-byte 8) yc-fix)))))

    Theorem: ichar<-irreflexive

    (defthm ichar<-irreflexive
      (not (ichar< x x)))

    Theorem: ichar<-antisymmetric

    (defthm ichar<-antisymmetric
      (implies (ichar< x y)
               (not (ichar< y x))))

    Theorem: ichar<-transitive

    (defthm ichar<-transitive
      (implies (and (ichar< x y) (ichar< y z))
               (ichar< x z)))

    Theorem: ichar<-transitive-two

    (defthm ichar<-transitive-two
      (implies (and (ichar< y z) (ichar< x y))
               (ichar< x z)))

    Theorem: ichar<-trichotomy-weak

    (defthm ichar<-trichotomy-weak
      (implies (and (not (ichar< x y))
                    (not (ichar< y x)))
               (equal (ichareqv x y) t)))

    Theorem: ichareqv-implies-equal-ichar<-1

    (defthm ichareqv-implies-equal-ichar<-1
      (implies (ichareqv x x-equiv)
               (equal (ichar< x y) (ichar< x-equiv y)))
      :rule-classes (:congruence))

    Theorem: ichareqv-implies-equal-ichar<-2

    (defthm ichareqv-implies-equal-ichar<-2
      (implies (ichareqv y y-equiv)
               (equal (ichar< x y) (ichar< x y-equiv)))
      :rule-classes (:congruence))

    Theorem: ichar<-trichotomy-strong

    (defthm ichar<-trichotomy-strong
      (equal (ichar< x y)
             (and (not (ichareqv x y))
                  (not (ichar< y x))))
      :rule-classes ((:rewrite :loop-stopper ((x y)))))