File: index.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites:
  • 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 (382 lines) | stat: -rw-r--r-- 13,790 bytes parent folder | download | duplicates (3)
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
;; Copyright (C) 2018, Regents of the University of Texas
;; Written by Cuong Chau
;; License: A 3-clause BSD license.  See the LICENSE file distributed with
;; ACL2.

;; Cuong Chau <ckcuong@cs.utexas.edu>
;; May 2019

;; Utility functions for indices

(in-package "ADE")

(include-book "utils")

(include-book "std/strings/decimal" :dir :system)
(defthm acl2::equal-of-appends-when-true-listps
    (implies (and (true-listp x1)
                  (true-listp x2))
             (equal (equal (append x1 y)
                           (append x2 y))
                    (equal x1 x2))))
(in-theory (disable acl2::equal-of-append-and-append-same-arg2))
(include-book "std/strings/istrprefixp" :dir :system)

;; ======================================================================

(defun str-append-symbol-underscore (s)
  (declare (xargs :guard (symbolp s)))
  (string-append (symbol-name s) "_"))

(defun append-symbol-string (s str)
  (declare (xargs :guard (and (symbolp s)
                              (stringp str))))
  (string-append (str-append-symbol-underscore s)
                 str))

;; SI

(defun si (s idx)
  (declare (xargs :guard (and (symbolp s)
                              (natp idx))))
  (intern$ (append-symbol-string s (nat-to-dec-string (nfix idx)))
           "ADE"))

(local
 (defthm symbol-inequality
   (implies (and (not (equal (symbol-name s1)
                             (symbol-name s2)))
                 (symbolp s1)
                 (symbolp s2))
            (not (equal s1 s2)))))

(defthm not-iprefixp-append
  (implies (not (iprefixp x y))
           (not (iprefixp (append x a) y)))
  :hints (("Goal" :in-theory (enable iprefixp))))

(defthm not-istrprefixp-str-append-symbol-underscore
  (implies (not (istrprefixp (str-append-symbol-underscore s2)
                             (symbol-name s1)))
           (not (istrprefixp (str-append-symbol-underscore (si s2 n))
                             (symbol-name s1))))
  :hints (("Goal"
           :use (:instance not-iprefixp-append
                           (x (append (explode (symbol-name s2))
                                      '(#\_)))
                           (y (explode (symbol-name s1)))
                           (a (append (explode (nat-to-dec-string (nfix n)))
                                      '(#\_))))
           :in-theory (disable not-iprefixp-append))))

(defthm not-equal-with-si-of-diff-symbol
  (implies (not (istrprefixp (str-append-symbol-underscore s2)
                             (symbol-name s1)))
           (and (not (equal (symbol-name s1)
                            (symbol-name (si s2 n))))
                (not (equal s1 (si s2 n)))))
  :hints (("Goal" :in-theory (disable str-append-symbol-underscore)))
  :rule-classes ((:rewrite
                  :corollary
                  (implies (not (istrprefixp (str-append-symbol-underscore s2)
                                             (symbol-name s1)))
                           (not (equal (symbol-name s1)
                                       (symbol-name (si s2 n))))))
                 (:rewrite
                  :corollary
                  (implies (not (istrprefixp (str-append-symbol-underscore s2)
                                             (symbol-name s1)))
                           (not (equal s1 (si s2 n)))))))

(encapsulate
  ()

  (local
   (defthm not-member-underscore-nat-to-dec-string
     (not (member #\_ (explode (nat-to-dec-string n))))
     :hints (("Goal" :in-theory (enable basic-nat-to-dec-chars
                                        nat-to-dec-chars
                                        nat-to-dec-string)))))

  (local
   (defthmd si-of-diff-symbols-aux-1
     (implies (and (< (length str1) (length str2))
                   (equal (char str1 (1- (length str1)))
                          (char str2 (1- (length str2))))
                   (char str1 (1- (length str1)))
                   (not (member (char str1 (1- (length str1)))
                                (explode str3))))
              (not (equal (char (string-append str1 str3)
                                (1- (length str2)))
                          (char (string-append str2 str4)
                                (1- (length str2))))))
     :hints (("Goal" :in-theory (enable not-member=>not-equal-nth)))))

  (local
   (defthmd si-of-diff-symbols-aux-2
     (implies (not (equal (char str1 n) (char str2 n)))
              (not (equal str1 str2)))))

  (local
   (defthm si-of-diff-symbols-aux-3
     (implies (not (equal (length (symbol-name s1))
                          (length (symbol-name s2))))
              (not (equal (symbol-name (si s1 n1))
                          (symbol-name (si s2 n2)))))
     :hints (("Goal"
              :use ((:instance
                     si-of-diff-symbols-aux-1
                     (str1 (str-append-symbol-underscore s1))
                     (str2 (str-append-symbol-underscore s2))
                     (str3 (nat-to-dec-string (nfix n1)))
                     (str4 (nat-to-dec-string (nfix n2))))
                    (:instance
                     si-of-diff-symbols-aux-1
                     (str1 (str-append-symbol-underscore s2))
                     (str2 (str-append-symbol-underscore s1))
                     (str3 (nat-to-dec-string (nfix n2)))
                     (str4 (nat-to-dec-string (nfix n1))))
                    (:instance
                     si-of-diff-symbols-aux-2
                     (n (length (symbol-name s2)))
                     (str1 (append-symbol-string s1 (nat-to-dec-string (nfix n1))))
                     (str2 (append-symbol-string s2 (nat-to-dec-string (nfix n2)))))
                    (:instance
                     si-of-diff-symbols-aux-2
                     (n (length (symbol-name s1)))
                     (str1 (append-symbol-string s2 (nat-to-dec-string (nfix n2))))
                     (str2 (append-symbol-string s1 (nat-to-dec-string (nfix n1))))))))))

  (local
   (defun diff-elementp (x y)
     (declare (xargs :guard t))
     (cond ((atom x) (consp y))
           ((atom y) (consp x))
           (t (or (not (equal (car x) (car y)))
                  (diff-elementp (cdr x) (cdr y)))))))

  (local
   (defthmd not-equal-equiv-diff-elementp
     (implies (and (true-listp x)
                   (true-listp y))
              (equal (not (equal x y))
                     (diff-elementp x y)))))

  (local
   (defthmd diff-elementp-append
     (implies (and (diff-elementp x1 y1)
                   (equal (len x1) (len y1)))
              (diff-elementp (append x1 x2) (append y1 y2)))))

  (local
   (defthm si-of-diff-symbols-aux-4
     (implies (and (equal (length (symbol-name s1))
                          (length (symbol-name s2)))
                   (not (equal (symbol-name s1) (symbol-name s2))))
              (not (equal (symbol-name (si s1 n1))
                          (symbol-name (si s2 n2)))))
     :hints (("Goal"
              :use ((:instance
                     not-equal-equiv-diff-elementp
                     (x (explode (symbol-name s1)))
                     (y (explode (symbol-name s2))))
                    (:instance
                     not-equal-equiv-diff-elementp
                     (x (append (explode (symbol-name s1))
                                (cons #\_ (explode (nat-to-dec-string (nfix n1))))))
                     (y (append (explode (symbol-name s2))
                                (cons #\_ (explode (nat-to-dec-string (nfix n2)))))))
                    (:instance
                     diff-elementp-append
                     (x1 (explode (symbol-name s1)))
                     (x2 (cons #\_ (explode (nat-to-dec-string (nfix n1)))))
                     (y1 (explode (symbol-name s2)))
                     (y2 (cons #\_ (explode (nat-to-dec-string (nfix n2)))))))))))

  (in-theory (disable istrprefixp
                      str-append-symbol-underscore
                      append-symbol-string
                      si))

  (defthm si-of-diff-symbols
    (implies (not (equal (symbol-name s1) (symbol-name s2)))
             (and (not (equal (symbol-name (si s1 n1))
                              (symbol-name (si s2 n2))))
                  (not (equal (si s1 n1) (si s2 n2)))))
    :hints (("Goal" :cases ((equal (length (symbol-name s1))
                                   (length (symbol-name s2))))))
    :rule-classes ((:rewrite
                    :corollary
                    (implies (not (equal (symbol-name s1) (symbol-name s2)))
                             (not (equal (symbol-name (si s1 n1))
                                         (symbol-name (si s2 n2))))))
                   (:rewrite
                    :corollary
                    (implies (not (equal (symbol-name s1) (symbol-name s2)))
                             (not (equal (si s1 n1) (si s2 n2)))))))
  )

(defthm append-symbol-diff-strings
  (implies (and (not (equal str1 str2))
                (stringp str1)
                (stringp str2))
           (not (equal (append-symbol-string s str1)
                       (append-symbol-string s str2))))
  :hints (("Goal" :in-theory (enable append-symbol-string))))

(defthm si-of-diff-idxes
  (implies (and (natp m)
                (natp n)
                (not (equal m n)))
           (and (not (equal (symbol-name (si s m))
                            (symbol-name (si s n))))
                (not (equal (si s m)
                            (si s n)))))
  :hints (("Goal" :in-theory (enable si)))
  :rule-classes ((:rewrite
                  :corollary
                  (implies (and (natp m)
                                (natp n)
                                (not (equal m n)))
                           (not (equal (symbol-name (si s m))
                                       (symbol-name (si s n))))))
                 (:rewrite
                  :corollary
                  (implies (and (natp m)
                                (natp n)
                                (not (equal m n)))
                           (not (equal (si s m)
                                       (si s n)))))))

;; ======================================================================

;; SIS

(defun sis (s start-idx count)
  (declare (xargs :guard (and (symbolp s)
                              (natp start-idx)
                              (natp count))))
  (if (zp count)
      nil
    (cons (si s start-idx)
          (sis s (1+ start-idx) (1- count)))))

(defthm consp-sis
  (implies (posp n)
           (consp (sis s m n)))
  :hints (("Goal" :expand (sis s m n)))
  :rule-classes :type-prescription)

(defthm not-member-with-sis-of-diff-symbol
  (implies (not (istrprefixp (str-append-symbol-underscore s2)
                             (symbol-name s1)))
           (not (member s1 (sis s2 m n)))))

(defthm si-sis-diff-symbols
  (implies (not (equal (symbol-name s1) (symbol-name s2)))
           (not (member (si s1 k) (sis s2 m n)))))

(defthm si-sis-diff-idxes
  (implies (and (natp k)
                (natp m)
                (< k m))
           (not (member (si s k) (sis s m n)))))

(defthm len-sis
  (equal (len (sis s m n))
         (nfix n)))

(defthm no-duplicatesp-sis
  (implies (natp m)
           (no-duplicatesp (sis s m n))))

(defthm sis-of-singleton
  (equal (sis s m 1)
         (list (si s m)))
  :hints (("Goal" :expand (sis s m 1))))

(defthm disjoint-sis-diff-syms
  (implies (not (equal (symbol-name s1) (symbol-name s2)))
           (disjoint (sis s1 m1 n1) (sis s2 m2 n2))))

(defthm disjoint-sis-same-sym-1
  (implies (and (natp i)
                (natp m)
                (<= (+ i j) m))
           (disjoint (sis s i j) (sis s m n))))

(defthm disjoint-sis-same-sym-2
  (implies (and (natp i)
                (natp m)
                (<= (+ m n) i))
           (disjoint (sis s i j) (sis s m n)))
  :hints (("Goal" :in-theory (enable disjoint-commutative))))

(defthm si-member-sis
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (< i (+ m n)))
           (member (si s i) (sis s m n)))
  :hints (("Goal"
           :expand ((sis s 0 n)
                    (sis s i 1)
                    (sis s i n)))))

(defthm sis-subset-sis
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (<= (+ i j) (+ m n)))
           (subsetp (sis s i j)
                    (sis s m n))))

(defthmd si-is-nth-of-sis
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (< i (+ m n)))
           (equal (si s i)
                  (nth (- i m) (sis s m n))))
  :hints (("Goal"
           :expand ((sis s 0 n)
                    (sis s i 1)
                    (sis s i n)))))

(defthmd nth-of-sis-is-si
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (< i (+ m n)))
           (equal (nth (- i m) (sis s m n))
                  (si s i)))
  :hints (("Goal" :use si-is-nth-of-sis)))

(defthm position1-si-sis
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (< i (+ m n)))
           (equal (position1 (si s i) (sis s m n))
                  (- i m)))
  :hints (("Goal" :in-theory (enable position1))))

(defthmd sis-of-subset
  (implies (and (natp i)
                (natp m)
                (natp n)
                (<= m i)
                (<= (+ i j) (+ m n)))
           (equal (sis s i j)
                  (take j (nthcdr (- i m) (sis s m n)))))
  :hints (("Goal"
           :in-theory (enable nth-of-sis-is-si
                              car-nthcdr
                              cdr-nthcdr))))

(in-theory (disable sis))