File: hifat-entry-count.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 (277 lines) | stat: -rw-r--r-- 10,256 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
(in-package "ACL2")

;  hifat-entry-count.lisp                                 Mihir Mehta

; hifat-entry-count is related to the problem of transforming a potentially loopy
; FAT32 disk image into a tree in a bounded amount of time. Some lemmas for
; reasoning about it are placed here.

(include-book "hifat-equiv")

;; We're not counting this very directory, because the root does not have a
;; directory entry for itself.
(defund
  hifat-entry-count (fs)
  (declare (xargs :guard (and (m1-file-alist-p fs)
                              (hifat-no-dups-p fs))
                  :guard-hints
                  (("Goal" :in-theory (disable m1-directory-file-p-of-m1-file-fix)))))
  (if
   (atom fs)
   0
   (+
    (hifat-entry-count (cdr fs))
    (if
     (consp
      (assoc-equal (mbe :logic (fat32-filename-fix (caar fs))
                        :exec (caar fs))
                   (mbe :logic (hifat-file-alist-fix (cdr fs))
                        :exec (cdr fs))))
     0
     (if
      (m1-directory-file-p (mbe :logic (m1-file-fix (cdar fs))
                                :exec (cdar fs)))
      (+ 1
         (hifat-entry-count (m1-file->contents (cdar fs))))
      1)))))

(defthm hifat-entry-count-of-hifat-file-alist-fix
  (equal (hifat-entry-count (hifat-file-alist-fix fs))
         (hifat-entry-count fs))
  :hints (("Goal" :in-theory (enable hifat-entry-count hifat-file-alist-fix))))

(defthm
  m1-file-alist-p-of-remove1-assoc-equal
  (implies (m1-file-alist-p m1-file-alist)
           (m1-file-alist-p (remove1-assoc-equal key m1-file-alist))))

(defthmd
  hifat-entry-count-when-hifat-no-dups-p
  (implies
   (and (m1-file-alist-p m1-file-alist)
        (hifat-no-dups-p m1-file-alist)
        (consp (assoc-equal x m1-file-alist)))
   (equal
    (hifat-entry-count m1-file-alist)
    (+
     (hifat-entry-count (remove1-assoc x m1-file-alist))
     1
     (if
      (m1-directory-file-p (cdr (assoc-equal x m1-file-alist)))
      (hifat-entry-count
       (m1-file->contents (cdr (assoc-equal x m1-file-alist))))
      0))))
  :hints
  (("goal"
    :in-theory (enable hifat-entry-count hifat-no-dups-p))))

(defthm
  hifat-entry-count-of-cdr-1
  (implies (and (consp fs)
                (m1-file-alist-p fs)
                (hifat-no-dups-p fs))
           (< (hifat-entry-count (cdr fs))
              (hifat-entry-count fs)))
  :rule-classes :linear
  :hints
  (("goal"
    :in-theory (enable hifat-no-dups-p hifat-entry-count))))

(defthm
  hifat-entry-count-of-cdr-2
  (implies
   (and (consp fs)
        (hifat-no-dups-p fs)
        (m1-file-alist-p fs)
        (not (m1-regular-file-p (cdr (car fs)))))
   (< (+ (hifat-entry-count (m1-file->contents (cdr (car fs))))
         (hifat-entry-count (cdr fs)))
      (hifat-entry-count fs)))
  :rule-classes :linear
  :hints (("goal" :in-theory (enable hifat-no-dups-p)
           :expand (hifat-entry-count fs))))

(encapsulate
  ()

  (local
   (defun
       induction-scheme
       (m1-file-alist1 m1-file-alist2)
     (declare
      (xargs
       :ruler-extenders nil ; Matt K. change for ruler-extenders mod 2/2021
       :guard (and (m1-file-alist-p m1-file-alist1)
                   (m1-file-alist-p m1-file-alist2))
       :hints (("goal" :in-theory (enable m1-file->contents
                                          m1-directory-file-p)))))
     (b* (((when (atom m1-file-alist1)) t)
          ((when (or (atom (car m1-file-alist1))
                     (not (stringp (car (car m1-file-alist1))))))
           (and (member-equal (car m1-file-alist1)
                              m1-file-alist2)
                (induction-scheme (cdr m1-file-alist1)
                                  (remove1-assoc-equal
                                   (caar m1-file-alist1)
                                   m1-file-alist2))))
          (name (caar m1-file-alist1))
          (file1 (cdar m1-file-alist1))
          ((unless (consp (assoc-equal name m1-file-alist2)))
           nil)
          (file2 (cdr (assoc-equal name m1-file-alist2))))
       (if (not (m1-directory-file-p file1))
           (and (not (m1-directory-file-p file2))
                (induction-scheme (cdr m1-file-alist1)
                                  (remove1-assoc-equal
                                   name
                                   m1-file-alist2))
                (equal (m1-file->contents file1)
                       (m1-file->contents file2)))
         (and (m1-directory-file-p file2)
              (induction-scheme (cdr m1-file-alist1)
                                (remove1-assoc-equal
                                 name
                                 m1-file-alist2))
              (induction-scheme (m1-file->contents file1)
                                (m1-file->contents file2)))))))

  (local
   (defthm
     induction-scheme-correctness
     (implies (and (hifat-no-dups-p m1-file-alist1)
                   (m1-file-alist-p m1-file-alist1))
              (iff (induction-scheme m1-file-alist1 m1-file-alist2)
                   (hifat-subsetp m1-file-alist1 m1-file-alist2)))
     :hints (("goal" :induct (induction-scheme m1-file-alist1 m1-file-alist2)
              :in-theory (enable hifat-no-dups-p hifat-subsetp)))))

  (defthm
    hifat-entry-count-when-hifat-subsetp
    (implies (and (hifat-no-dups-p m1-file-alist1)
                  (m1-file-alist-p m1-file-alist1)
                  (hifat-no-dups-p m1-file-alist2)
                  (m1-file-alist-p m1-file-alist2)
                  (hifat-subsetp m1-file-alist1 m1-file-alist2))
             (<= (hifat-entry-count m1-file-alist1)
                 (hifat-entry-count m1-file-alist2)))
    :rule-classes :linear
    :hints
    (("goal" :induct (induction-scheme m1-file-alist1 m1-file-alist2)
      :in-theory (enable hifat-no-dups-p hifat-entry-count hifat-subsetp))
     ("subgoal *1/7"
      :use (:instance (:rewrite hifat-entry-count-when-hifat-no-dups-p)
                      (m1-file-alist m1-file-alist2)
                      (x (car (car m1-file-alist1)))))
     ("subgoal *1/4"
      :use (:instance (:rewrite hifat-entry-count-when-hifat-no-dups-p)
                      (m1-file-alist m1-file-alist2)
                      (x (car (car m1-file-alist1))))))))

;; This rule is kinda problematic because it has caused an infinite rewrite at
;; least once in hifat-to-lofat-inversion-big-induction, which was only
;; resolved by disabling it. It would be nice to make this a plain congruence
;; rule - but that would require the m1-file-alist and hifat-no-dups-p
;; hypotheses to be removed, which in turn would require the definition of
;; hifat-entry-count to be changed.
(defthm
  hifat-entry-count-when-hifat-equiv
  (implies (hifat-equiv m1-file-alist1 m1-file-alist2)
           (equal (hifat-entry-count m1-file-alist1)
                  (hifat-entry-count m1-file-alist2)))
  :rule-classes :congruence
  :hints
  (("goal"
    :in-theory (e/d (hifat-equiv)
                    (hifat-entry-count-when-hifat-subsetp))
    :use
    ((:instance hifat-entry-count-when-hifat-subsetp
                (m1-file-alist1 (hifat-file-alist-fix m1-file-alist2))
                (m1-file-alist2 (hifat-file-alist-fix m1-file-alist1)))
     (:instance hifat-entry-count-when-hifat-subsetp
                (m1-file-alist1 (hifat-file-alist-fix m1-file-alist1))
                (m1-file-alist2 (hifat-file-alist-fix m1-file-alist2)))))))

(defthm hifat-entry-count-of-remove-assoc-equal
  (implies (and (m1-file-alist-p fs)
                (hifat-no-dups-p fs)
                (consp (assoc-equal x fs)))
           (< (hifat-entry-count (remove-assoc-equal x fs))
              (hifat-entry-count fs)))
  :hints (("goal" :in-theory (e/d (hifat-entry-count hifat-no-dups-p))
           :induct (assoc-equal x fs)))
  :rule-classes :linear)

(local
 (defthm hifat-entry-count-of-put-assoc-equal-lemma-1
   (implies (and (m1-file-alist-p fs)
                 (not (fat32-filename-p x)))
            (not (consp (assoc-equal x fs))))
   :hints (("goal" :in-theory (enable m1-file-alist-p)))))

(defthm
  consp-of-assoc-of-hifat-file-alist-fix
  (implies (m1-file-alist-p hifat-file-alist)
           (iff (consp (assoc-equal name
                                    (hifat-file-alist-fix hifat-file-alist)))
                (consp (assoc-equal name hifat-file-alist))))
  :hints (("goal" :in-theory (enable hifat-file-alist-fix)
           :induct (assoc-equal name hifat-file-alist))))

(defthm
  hifat-entry-count-of-put-assoc-equal
  (implies
   (and (m1-file-alist-p fs)
        (hifat-no-dups-p fs)
        (m1-file-p val)
        (fat32-filename-p name))
   (equal
    (hifat-entry-count (put-assoc-equal name val fs))
    (+
     (hifat-entry-count fs)
     (if
      (atom (assoc-equal name fs))
      1
      (if
       (m1-directory-file-p (cdr (assoc-equal name fs)))
       (- (hifat-entry-count (m1-file->contents (cdr (assoc-equal name fs)))))
       0))
     (if (m1-directory-file-p val)
         (hifat-entry-count (m1-file->contents val))
         0))))
  :hints (("goal" :in-theory (enable hifat-entry-count hifat-no-dups-p)
           :induct (assoc-equal name fs))))

(defthm
  hifat-entry-count-of-hifat-remove-file
  (implies (equal (mv-nth 1 (hifat-remove-file fs path))
                  0)
           (< (hifat-entry-count (mv-nth 0 (hifat-remove-file fs path)))
              (hifat-entry-count fs)))
  :hints (("goal" :in-theory (enable hifat-remove-file)))
  :rule-classes :linear)

(defthm
  hifat-entry-count-of-hifat-place-file
  (implies
   (m1-file-p file)
   (equal
    (hifat-entry-count (mv-nth 0 (hifat-place-file fs path file)))
    (if
     (zp (mv-nth 1 (hifat-place-file fs path file)))
     (+
      (hifat-entry-count fs)
      (if (m1-regular-file-p file)
          0
          (hifat-entry-count (m1-file->contents file)))
      (cond
       ((not (zp (mv-nth 1 (hifat-find-file fs path))))
        1)
       ((m1-regular-file-p (mv-nth 0 (hifat-find-file fs path)))
        0)
       (t
        (-
         (hifat-entry-count
          (m1-file->contents (mv-nth 0 (hifat-find-file fs path))))))))
     (hifat-entry-count fs))))
  :hints (("goal" :induct (hifat-place-file fs path file)
           :in-theory (enable hifat-place-file hifat-find-file))))