This file is indexed.

/usr/share/acl2-6.3/books/str/coerce.lisp is in acl2-books-source 6.3-5.

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
; ACL2 String Library
; Copyright (C) 2009-2013 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>
;
; Additional copyright notice for coerce.lisp:
;
; This file is adapted from the Unicode library, Copyright (C) 2005-2013 by
; Jared Davis, which was also released under the GPL.

(in-package "STR")
(include-book "make-character-list")


(defsection str/coerce
  :parents (coercion coerce)
  :short "Lemmas about @(see coerce) available in the @(see str) library."

  :long "<p>We typically do not want to ever reason about coerce.  Instead, we
rewrite it away into @(see explode) or @(see implode).</p>"

  (local (defthm coerce-string-lemma
           (implies (and (character-listp x)
                         (character-listp y)
                         (not (equal x y)))
                    (not (equal (coerce x 'string)
                                (coerce y 'string))))
           :hints(("Goal" :use ((:instance coerce-inverse-1 (x x))
                                (:instance coerce-inverse-1 (x y)))))))

  (defthm equal-of-coerce-strings
    (implies (and (character-listp x)
                  (character-listp y))
             (equal (equal (coerce x 'string)
                           (coerce y 'string))
                    (equal x y))))

  (local (defthm coerce-list-lemma
           (implies (and (stringp x)
                         (stringp y)
                         (not (equal x y)))
                    (not (equal (coerce x 'list)
                                (coerce y 'list))))
           :hints(("Goal" :use ((:instance coerce-inverse-2 (x x))
                                (:instance coerce-inverse-2 (x y)))))))

  (defthm equal-of-coerce-lists
    (implies (and (stringp x)
                  (stringp y))
             (equal (equal (coerce x 'list)
                           (coerce y 'list))
                    (equal x y))))

  ;; Redundant with built-in ACL2 rule character-listp-coerce
  ;; (defthm character-listp-of-coerce-list
  ;;   (character-listp (coerce x 'list)))

  (defthm coerce-list-under-iff
    (iff (coerce string 'list)
         (and (stringp string)
              (not (equal "" string))))
    :hints(("Goal"
            :in-theory (disable equal-of-coerce-lists)
            :use ((:instance equal-of-coerce-lists
                             (x string)
                             (y ""))))))


  (defthm length-of-coerce
    ;; Wow, coerce is sort of awful in that (coerce "foo" 'string) returns ""
    ;; and (coerce '(1 2 3) 'list) returns nil.  This leads to a weird length
    ;; theorem.  We normally just leave length enabled, so this rule won't have
    ;; many uses.
    (equal (length (coerce x y))
           (cond ((equal y 'list)
                  (if (stringp x)
                      (length x)
                    0))
                 (t
                  (if (stringp x)
                      0
                    (len x)))))
    :hints(("Goal"
            :use ((:instance completion-of-coerce
                             (x x)
                             (y y))))))

  (defthm len-of-coerce-to-string
    (equal (len (coerce x 'string))
           0))

  (defthm coerce-inverse-1-better
    (equal (coerce (coerce x 'string) 'list)
           (if (stringp x)
               nil
             (make-character-list x)))
    :hints(("Goal"
            :use ((:instance acl2::completion-of-coerce
                             (acl2::x x)
                             (acl2::y 'string))))))

  (defthm coerce-inverse-2-better
    (equal (coerce (coerce x 'list) 'string)
           (if (stringp x)
               x
             "")))

  (in-theory (disable coerce-inverse-1 coerce-inverse-2))

  (defthm coerce-to-list-of-make-character-list
    (equal (coerce (make-character-list x) 'string)
           (coerce x 'string))
    :hints(("Goal"
            :use ((:instance acl2::completion-of-coerce
                             (acl2::x x)
                             (acl2::y 'string)))))))



(defsection explode
  :parents (coercion coerce)
  :short "Convert a string to a character list."

  :long "<p>@(call explode) is logically nothing more than @('(coerce x
'list)').</p>

<p>Even though @(see coerce) is built into ACL2, we prefer to use @('explode') as
our normal form.  We rewrite all uses of @('(coerce x 'list)') into
@('(str::explode x')') with the following rule:</p>

@(def coerce-to-list-removal)

<p>The basic rationale for this is that @('coerce')'s extra @(''list') argument
means we can't write, e.g., congruence relations about @('(coerce x 'list)'),
whereas this is no problem for @('(explode x)').</p>

<p>We do the same thing for @('(coerce x 'string)') &mdash; see @(see
implode).</p>

<p><b>BOZO</b> consider using misc/fast-coerce here.</p>"

  (definlined explode (x)
    (declare (type string x))
    (coerce x 'list))

  (in-theory (disable (:t explode)))
  (local (in-theory (enable explode)))

  (defthm true-listp-of-explode
    (true-listp (explode x))
    :rule-classes :type-prescription)

  (defthm character-listp-of-explode
    (character-listp (explode x)))

  (defthm explode-when-not-stringp
    (implies (not (stringp x))
             (equal (explode x)
                    nil)))

  (defthm equal-of-explodes
    (implies (and (stringp x)
                  (stringp y))
             (equal (equal (explode x)
                           (explode y))
                    (equal x y))))

  (defthm explode-under-iff
    (iff (explode string)
         (and (stringp string)
              (not (equal "" string)))))

  (local (defthm l0
           (implies (true-listp x)
                    (iff (consp x)
                         x))))

  (defthm consp-of-explode
    (equal (consp (explode string))
           (and (stringp string)
                (not (equal "" string)))))

  (defthm coerce-to-list-removal
    (equal (coerce x 'list)
           (explode x)))

  (local (in-theory (disable acl2::explode)))

  (theory-invariant (incompatible (:definition acl2::explode$inline)
                                  (:rewrite coerce-to-list-removal))))



(defsection implode
  :parents (coercion coerce)
  :short "Convert a character list into a string."

  :long "<p>@(call implode) is logically nothing more than @('(coerce x
'string)').</p>

<p>Even though @(see coerce) is built into ACL2, we prefer to use @('implode')
as our normal form.  We rewrite all uses of @('(coerce x 'string)') into
@('(str::implode x')') with the following rule:</p>

@(def coerce-to-string-removal)

<p>The basic rationale for this is that @('coerce')'s extra @(''string')
argument means we can't write, e.g., congruence relations about @('(coerce x
'string)'), whereas this is no problem for @('(implode x)').</p>

<p>We do the same thing for @('(coerce x 'list)') &mdash; see @(see
explode).</p>"

  (definlined implode (x)
    (declare (xargs :guard (character-listp x)))
    (coerce x 'string))

  (in-theory (disable (:t implode)))
  (local (in-theory (enable implode)))

  (defthm stringp-of-implode
    (stringp (implode x))
    :rule-classes :type-prescription)

  (defthm equal-of-implodes
    (implies (and (character-listp x)
                  (character-listp y))
             (equal (equal (implode x)
                           (implode y))
                    (equal x y))))

  (defthm implode-of-make-character-list
    (equal (implode (make-character-list x))
           (implode x)))

  (local (defthm l0
           (equal (equal (len x) 0)
                  (atom x))))

  (defthm equal-of-implode-with-empty-string
    (equal (equal "" (implode x))
           (atom x))
    :hints(("Goal"
            :in-theory (disable length-of-coerce)
            :use ((:instance length-of-coerce
                             (x x)
                             (y 'string))))))

  (defthm coerce-to-string-removal
    (equal (coerce x 'string)
           (implode x)))

  (local (in-theory (disable acl2::implode$inline)))

  (theory-invariant (incompatible (:definition acl2::implode$inline)
                                  (:rewrite coerce-to-string-removal))))



(defsection implode-explode-inversion
  :parents (implode explode)
  :short "Inversion theorems for @(see implode) and @(see explode)."

  (local (in-theory (e/d (implode explode)
                         (coerce-to-string-removal
                          coerce-to-list-removal))))

  (defthm explode-of-implode
    (equal (explode (implode x))
           (if (stringp x)
               nil
             (make-character-list x))))

  (defthm implode-of-explode
    (equal (implode (explode x))
           (if (stringp x)
               x
             ""))))