/usr/share/acl2-4.3/books/str/iless.lisp is in acl2-books-source 4.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | ; ACL2 String Library
; Copyright (C) 2009-2010 Centaur Technology
;
; Contact:
; Centaur Technology Formal Verification Group
; 7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
; http://www.centtech.com/
;
; This program is free software; you can redistribute it and/or modify it under
; the terms of the GNU General Public License as published by the Free Software
; Foundation; either version 2 of the License, or (at your option) any later
; version. This program is distributed in the hope that it will be useful but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
; more details. You should have received a copy of the GNU General Public
; License along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
;
; Original author: Jared Davis <jared@centtech.com>
(in-package "STR")
(include-book "doc")
(include-book "ieqv")
(local (include-book "unicode/nthcdr" :dir :system))
(local (include-book "arithmetic"))
(local (include-book "char-support"))
(defund ichar< (x y)
":Doc-Section Str
Case-insensitive character less-than test~/
Our approach is basically to downcase upper-case letters. 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.
~/
~l[str::istr<] and ~pl[str::icharlist<]"
(declare (type character x)
(type character y))
(mbe :logic
(let* ((xc (if (characterp x)
(char-code x)
0))
(yc (if (characterp y)
(char-code y)
0))
(xc-fix (if (and (<= (char-code #\A) xc) (<= xc (char-code #\Z)))
(+ xc 32)
xc))
(yc-fix (if (and (<= (char-code #\A) yc) (<= yc (char-code #\Z)))
(+ yc 32)
yc)))
(< xc-fix yc-fix))
: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 (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) xc))
(<= (the (unsigned-byte 8) xc) (the (unsigned-byte 8) 90)))
(the (unsigned-byte 8) (+ (the (unsigned-byte 8) xc) 32))
(the (unsigned-byte 8) xc)))
(yc-fix (if (and (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) yc))
(<= (the (unsigned-byte 8) yc) (the (unsigned-byte 8) 90)))
(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)))))
(defthm ichar<-irreflexive
(not (ichar< x x))
:hints(("Goal" :in-theory (enable ichar<))))
(defthm ichar<-antisymmetric
(implies (ichar< x y)
(not (ichar< y x)))
:hints(("Goal" :in-theory (enable ichar<))))
(defthm ichar<-transitive
(implies (and (ichar< x y)
(ichar< y z))
(ichar< x z))
:hints(("Goal" :in-theory (enable ichar<))))
(defthm ichar<-transitive-two
(implies (and (ichar< y z)
(ichar< x y))
(ichar< x z))
:hints(("Goal" :in-theory (enable ichar<))))
(encapsulate
()
(local (defthm lemma
(implies (and (<= 65 (char-code x))
(<= (char-code x) 90)
(equal (char-code y) (+ 32 (char-code x))))
(standard-char-p y))
:hints(("Goal"
:in-theory (disable standard-char-p-of-char-downcase)
:use ((:instance standard-char-p-of-char-downcase))))))
(defthm ichar<-trichotomy-weak
(implies (and (not (ichar< x y))
(not (ichar< y x)))
(equal (ichareqv x y)
t))
:hints(("Goal" :in-theory (enable ichar< ichareqv)))))
(defcong ichareqv equal (ichar< x y) 1
:hints(("Goal" :in-theory (enable ichar<
ichareqv
char-downcase-redefinition
standard-char-p-of-char-downcase))))
(defcong ichareqv equal (ichar< x y) 2
:hints(("Goal" :in-theory (enable ichar<
ichareqv
char-downcase-redefinition
standard-char-p-of-char-downcase))))
(defthm ichar<-trichotomy-strong
(equal (ichar< x y)
(and (not (ichareqv x y))
(not (ichar< y x))))
:rule-classes ((:rewrite :loop-stopper ((x y)))))
(defund icharlist< (x y)
":Doc-Section Str
Case-insensitive character-list less-than test~/
We determine whether one character list alphabetically preceeds another,
where each character is tested with ~il[str::ichar<] and shorter strings are
said to come before longer strings. ~/
~l[str::ichar<] and ~pl[str::istr<]"
(declare (xargs :guard (and (character-listp x)
(character-listp y))
:verify-guards nil))
(mbe :logic (cond ((atom y)
nil)
((atom x)
t)
((ichar< (car x) (car y))
t)
((ichar< (car y) (car x))
nil)
(t
(icharlist< (cdr x) (cdr y))))
:exec
(cond ((atom y)
nil)
((atom x)
t)
(t
(let* ((xc (the (unsigned-byte 8) (char-code (the character (car x)))))
(yc (the (unsigned-byte 8) (char-code (the character (car y)))))
(xc-fix (if (and (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) xc))
(<= (the (unsigned-byte 8) xc) (the (unsigned-byte 8) 90)))
(the (unsigned-byte 8) (+ (the (unsigned-byte 8) xc) 32))
(the (unsigned-byte 8) xc)))
(yc-fix (if (and (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) yc))
(<= (the (unsigned-byte 8) yc) (the (unsigned-byte 8) 90)))
(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
(icharlist< (cdr x) (cdr y)))))))))
(verify-guards icharlist<
:hints(("Goal" :in-theory (e/d (ichar<)
(ichar<-trichotomy-strong)))))
(defthm icharlist<-irreflexive
(equal (icharlist< x x)
nil)
:hints(("Goal" :in-theory (enable icharlist<))))
(defthm icharlist<-antisymmetric
(implies (icharlist< x y)
(not (icharlist< y x)))
:hints(("Goal" :in-theory (enable icharlist<))))
(defthm icharlist<-transitive
(implies (and (icharlist< x y)
(icharlist< y z))
(icharlist< x z))
:hints(("Goal" :in-theory (enable icharlist<))))
(defthm icharlist<-trichotomy-weak
(implies (and (not (icharlist< x y))
(not (icharlist< y x)))
(equal (icharlisteqv x y)
t))
:hints(("Goal" :in-theory (enable icharlist<))))
(defcong icharlisteqv equal (icharlist< x y) 1
:hints(("Goal" :in-theory (enable icharlist<))))
(defcong icharlisteqv equal (icharlist< x y) 2
:hints(("Goal" :in-theory (enable icharlist< icharlisteqv))))
(defthm icharlist<-trichotomy-strong
(equal (icharlist< x y)
(and (not (icharlisteqv x y))
(not (icharlist< y x))))
:rule-classes ((:rewrite :loop-stopper ((x y)))))
(defund 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)))
:verify-guards nil
:measure (nfix (- (nfix xl) (nfix n)))))
(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 (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) xc))
(<= (the (unsigned-byte 8) xc) (the (unsigned-byte 8) 90)))
(the (unsigned-byte 8) (+ (the (unsigned-byte 8) xc) 32))
(the (unsigned-byte 8) xc)))
(yc-fix (if (and (<= (the (unsigned-byte 8) 65) (the (unsigned-byte 8) yc))
(<= (the (unsigned-byte 8) yc) (the (unsigned-byte 8) 90)))
(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)))))))))
(verify-guards istr<-aux
:hints(("Goal" :in-theory (e/d (ichar<)
(ichar<-trichotomy-strong)))))
(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)))))
:hints(("Goal" :in-theory (enable istr<-aux icharlist<))))
(defun istr< (x y)
":Doc-Section Str
Case-insensitive string less-than test~/
We determine whether one string alphabetically preceeds another, where each
character is tested with ~il[str::ichar<] and shorter strings are said to
come before longer strings.
Logically, ~c[(istr< x y)] is ~c[(icharlist< (coerce x 'list) (coerce y 'list)],
but we use a more efficient implementation which avoids coercing the strings.~/
~l[str::ichar<] and ~pl[str::icharlist<]"
(declare (type string x)
(type string y))
(mbe :logic
(icharlist< (coerce x 'list) (coerce y 'list))
:exec
(istr<-aux (the string x)
(the string y)
(the integer 0)
(the integer (length (the string x)))
(the integer (length (the string y))))))
|