File: char-fix.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (119 lines) | stat: -rw-r--r-- 4,569 bytes parent folder | download | duplicates (8)
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
; ACL2 String Library
; Copyright (C) 2009-2014 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/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com>

(in-package "STR")
(include-book "std/basic/defs" :dir :system)
(include-book "std/util/define" :dir :system)

(defsection code-char-lemmas
  :parents (code-char)
  :short "Lemmas about @(see code-char) from the @(see std/strings) library."

  (defthm default-code-char
    (implies (or (zp x)
                 (not (< x 256)))
             (equal (code-char x)
                    (code-char 0)))
    :hints(("Goal" :use ((:instance completion-of-code-char)))))

  (local (defthm l0
           (implies (not (or (zp x)
                             (not (< x 256))))
                    (not (equal (code-char x)
                                (code-char 0))))
           :hints(("Goal" :use ((:instance char-code-code-char-is-identity (n x)))))))

  (local (defthm l1
           (equal (equal (code-char x)
                         (code-char 0))
                  (or (zp x)
                      (not (< x 256))))))

  (local (defthm l2
           (implies (and (natp n)
                         (natp m)
                         (< n 256)
                         (< m 256))
                    (equal (equal (code-char n) (code-char m))
                           (equal n m)))
           :hints(("Goal"
                   :in-theory (disable char-code-code-char-is-identity)
                   :use ((:instance char-code-code-char-is-identity (n n))
                         (:instance char-code-code-char-is-identity (n m)))))))

  (defthm equal-of-code-char-and-code-char
    (equal (equal (code-char x) (code-char y))
           (let ((zero-x (or (zp x) (>= x 256)))
                 (zero-y (or (zp y) (>= y 256))))
             (if zero-x
                 zero-y
               (equal x y))))
    :hints(("Goal"
            :in-theory (disable l2)
            :use ((:instance l2 (n x) (m y))))))

  (defthm equal-of-code-code-and-constant
    (implies (syntaxp (quotep c))
             (equal (equal (code-char x) c)
                    (and (characterp c)
                         (if (equal c (code-char 0))
                             (or (zp x)
                                 (not (< x 256)))
                           (equal x (char-code c))))))
    :hints(("goal" :use ((:instance completion-of-code-char))))))




(defsection char-code-lemmas
  :parents (char-code)
  :short "Lemmas about @(see char-code) from the @(see std/strings) library."

  (defthm equal-of-char-code-and-constant
    (implies (syntaxp (quotep c))
             (equal (equal (char-code x) c)
                    (if (characterp x)
                        (and (natp c)
                             (<= c 255)
                             (equal x (code-char c)))
                      (equal c 0)))))

  (local (defthm l0
           (implies (and (characterp x)
                         (characterp y))
                    (equal (equal (char-code x) (char-code y))
                           (equal x y)))
           :hints(("Goal" :use acl2::equal-char-code))))

  (defthm equal-of-char-codes
    (equal (equal (char-code x) (char-code y))
           (equal (char-fix x)
                  (char-fix y)))
    :hints(("Goal" :in-theory (enable char-fix)))))