File: ocat.lisp

package info (click to toggle)
acl2 6.5-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 108,856 kB
  • ctags: 110,136
  • sloc: lisp: 1,492,565; xml: 7,958; perl: 3,682; sh: 2,103; cpp: 1,477; makefile: 1,470; ruby: 453; ansic: 358; csh: 125; java: 24; haskell: 17
file content (370 lines) | stat: -rw-r--r-- 11,594 bytes parent folder | download | duplicates (6)
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
(in-package "ACL2")

(defund bvecp (x k)
  (declare (xargs :guard (integerp k)))
  (and (integerp x)
       (<= 0 x)
       (< x (expt 2 k))))

(local ; ACL2 primitive
 (defun natp (x)
   (declare (xargs :guard t))
   (and (integerp x)
        (<= 0 x))))

(local (include-book "../arithmetic/expt"))
(local (include-book "../arithmetic/expo"))
(local (include-book "../arithmetic/arith2"))
(local (include-book "../arithmetic/fp2"))
(local (include-book "../arithmetic/integerp"))                

(local (in-theory (enable expt-minus)))

(defund ocat (x y n)
  (declare (xargs :guard t))
  (+ (* (expt 2 (nfix n)) (nfix x)) (nfix y)))


(defthm ocat-nonnegative-integer-type
  (and (integerp (OCAT X Y N))
       (<= 0 (OCAT X Y N)))
  :rule-classes (:type-prescription)
  )

;this rule is no better than ocat-nonnegative-integer-type and might be worse
(in-theory (disable (:type-prescription ocat)))

;just a rewrite rule
(defthm ocat-natp
  (natp (ocat x y n)))

;became less general when we made ocat nfix its args
(defthm ocat-0
    (implies (and (case-split (<= 0 y))
                  (case-split (integerp y)))		  
	     (equal (ocat 0 y n) y))
    :hints (("Goal" :in-theory (enable ocat))))

;became less general when we made ocat nfix its args
(defthm ocat-x-0-0
  (implies (and (case-split (<= 0 x))
                (case-split (integerp x)))
           (equal (ocat x 0 0)
                  x))
  :hints (("Goal" :in-theory (enable ocat))))


#|
;old form:
(defthm ocat-upper-bound
  (implies (and (integerp x)
                (bvecp y n) ;expensive?
                (integerp n))
           (< (ocat x y n)
              (+ (* (expt 2 n) x) (expt 2 n))))
  :hints (("Goal" :in-theory (enable ocat bvecp)))
  :rule-classes (:rewrite (:linear :trigger-terms ((ocat x y n))))
  )

|#

;this can be really expensive
;old form:
(defthm ocat-upper-bound
  (implies (and (< y (expt 2 n))
                (<= 0 x)
                (integerp x)
                (<= 0 y)
                (integerp n)
                (<= 0 n)
                )
           (< (ocat x y n)
              (+ (* (expt 2 n) x) (expt 2 n))))
  :hints (("Goal" :in-theory (enable ocat )))
  :rule-classes (:rewrite (:linear :trigger-terms ((ocat x y n))))
  )






(encapsulate
 ()
 (local (defthm ocat-bvecp-rewrite-fw
          (implies (and (integerp n)
                        (<= 0 n)
                        (integerp k)
                        (<= 0 k)
                        (integerp x)
                        (<= 0 x)
                        (>= k n) ;drop?
                        (force (bvecp y n))
                        )
                   (implies (bvecp (ocat x y n) k)
                            (bvecp x (- k n))))
          :rule-classes nil
          :hints (("goal" :in-theory (enable bvecp expt-split ocat)))
          ))

 (local (defthm hack-hack
          (implies (and (integerp x)
                        (integerp y)
                        (integerp m)
                        (<= 0 m)
                        (integerp n)
                        (<= 0 n)
                        (< x (expt 2 m))
                        (< y (expt 2 n))
                        )
                   (< (+ (/ y (expt 2 n)) x)
                      (expt 2 m)))
          :hints (("goal" :in-theory (set-difference-theories
                                      (enable expt-split)
                                      '())))))

 (local (defthm hack-ocat
          (implies (and (integerp x)
                        (integerp y)
                        (integerp m)
                        (<= 0 m)
                        (integerp n)
                        (<= 0 n)

                        (< x (expt 2 m))
                        (< y (expt 2 n))
                        )
                   (< (+ y (* x (expt 2 n)))
                      (expt 2 (+ m n))))
          :hints (("goal" :in-theory (set-difference-theories
                                      (enable expt-split)
                                      '( hack-hack))
                   :use (hack-hack
                         (:instance  mult-both-sides-of-<-by-positive (a (+ x (* y (/ (expt 2 n)))))
                                     (b (expt 2 m))
                                     (c (expt 2 n))))))))

 (local (in-theory (enable bvecp)))
           
 (local (defthm ocat-bvecp-rewrite-bk
          (implies (and (integerp n)
                        (<= 0 n)
                        (integerp k)
                        (<= 0 k)
                        (integerp x)
                        (<= 0 x)
                        (>= k n) ;drop?
                        (force (bvecp y n))
                        )
                   (implies
                    (bvecp x (- k n))
                    (bvecp (ocat x y n) k)))
          :rule-classes nil
          :hints (("goal" :in-theory (set-difference-theories
                                      (enable ocat)
                                      '(hack-ocat))
                   :use (:instance hack-ocat (n n) (m (- k n)))))))

 (defthm ocat-bvecp-rewrite
   (implies (and (>= k n) ;handle the other case?
                 (case-split (integerp x))
                 (case-split (<= 0 x))
                 (case-split (bvecp y n))
                 (case-split (natp n))
                 (case-split (natp k))
                 )
            (equal (bvecp (ocat x y n) k)
                   (bvecp x (- k n))))
   :hints (("goal" 
            :use (ocat-bvecp-rewrite-fw ocat-bvecp-rewrite-bk))
           ))

 (local (defthm hack-4
          (implies (and (integerp x)
                        (<= 0 x)
                        (not (equal x 0)))
                   (>= x 1))))

;expensive? handle this better somehow?
 (local (defthm hack-3
          (implies (and (integerp x)
                        (<= 0 x)
                        (not (equal x 0))
                        (rationalp a)
                        (<= 0 a)
                        )
                   (>= (* x a) a))
          :rule-classes :linear
          :hints (("goal" :in-theory (disable
                                      hack-4
;                                      cancel-in-prods-<
 ;                                     cancel-times-<-eric-1
                                      )
                   :use (hack-4
                         (:instance mult-both-sides-of-<-by-positive
                                    (b a) (a (* a x)) (c (/ a))))))))


;better names?
 (defthm ocat-bvecp-other-case
   (implies (and (< p n)
                 (integerp n)
                 (<= 0 n)
                 (integerp p)
                 (<= 0 p)
                 (integerp x)
                 (<= 0 x)
                 (integerp y)
                 (<= 0 y)
                 )
            (equal (bvecp (ocat x y n) p)
                   (and (bvecp y p)
                        (equal 0 x)))
            )
   :hints (("goal" :in-theory (set-difference-theories
                               (enable power2p ocat)
                               '(expt-compare
                                 ))
            :use (:instance expt-compare (lhs (expt 2 p)) (rhs (expt 2 n)))))
   :otf-flg t
   )
 )


#|
;make more general
;also make ncat ver
(defthm highbits-ocat
  (implies (and (integerp x)
                (<= 0 x)
                (force (bvecp y n))
                (integerp n)
                (<= 0 n)
                )
           (equal (highbits (OCAT x y n) n)
                  x))
  :hints (("Goal" :in-theory (enable expt-split
                                     ocat 
                                     highbits))))
|#

(local (defthm hack-10
    (implies (and (integerp x)
		  (integerp y)
		  (< x y))
	     (<= x (1- y)))
  :rule-classes ()))

(local (defthm ocat-bvecp-simple
    (implies (and (natp n)
		  (natp k)
		  (bvecp x m)
		  (natp m)
		  (bvecp y n)
		  (>= k (+ m n)))
	     (bvecp (ocat x y n) k))
  :rule-classes ()
  :hints (("Goal" :in-theory (set-difference-theories
                              (enable natp bvecp ocat)
                              '(expt-compare EXPT-COMPARE-EQUAL))
		  :use ((:instance expt-split (i m) (j n) (r 2))
			(:instance hack-10 (y (expt 2 m)))
			(:instance expt-weak-monotone (m p))
			(:instance expt-weak-monotone (m k) (n (+ m n))))))))

(defthm ocat-bvecp
    (implies (and (>= k n) ;handle other case?
                  (bvecp x (- k n))
                  (case-split (natp n))
		  (case-split (natp k))
		  (case-split (bvecp y n))
                  )
	     (bvecp (ocat x y n) k))
  :hints (("Goal" :in-theory (enable natp bvecp)
		  :use ((:instance ocat-bvecp-simple (m (- k n)))))))

(defthm ocat-0-rewrite
    (implies (and (case-split (integerp x))
		  (case-split (<= 0 x)))
	     (equal (ocat 0 x n) x))
    :hints (("Goal" :in-theory (enable ocat))))

(defthm ocat-with-x-not-a-natural
  (implies (or (not (integerp x))
               (< x 0))
           (equal (ocat x y n)
                  (nfix y)))
  :hints (("Goal" :in-theory (enable ocat))))

(defthm ocat-with-y-not-a-natural
  (implies (or (not (integerp y))
               (< y 0))
           (equal (ocat x y n)
                  (* (nfix x) (expt 2 (nfix n)))))
  :hints (("Goal" :in-theory (enable ocat))))

(defthm ocat-with-n-not-a-natural
  (implies (or (not (integerp n))
               (< n 0))
           (equal (ocat x y n)
                  (+ (nfix x) (nfix y))))
  :hints (("Goal" :in-theory (enable ocat))))



;might be able to generalize this more
;this look like it will fire as often as we'd like
(defthm ocat-upper-bound-2
  (implies (and (< x (expt 2 k)) ; k is a free var. huh?
                (case-split (< y (expt 2 n)))
                (case-split (integerp k))
                (case-split (<= 0 k))
                (case-split (integerp n))
                (case-split (<= 0 n))
                )
           (< (ocat x y n)
              (expt 2 (+ n k))))
  :hints (("Goal" :in-theory (set-difference-theories
                              (enable bvecp expt-split)
                              '(OCAT-BVECP-REWRITE OCAT-BVECP ))
           :use ((:instance <-TRANSITIVE (a y) (b (expt 2 n)) (c (* (EXPT 2 K) (EXPT 2 N))))
                 (:instance ocat-bvecp (k (+ n k)))))))

(defthm ocat-associative
  (implies (and (case-split (<= 0 m)) ;new now that ocat fixes its args
                (case-split (<= 0 n)) ;new now that ocat fixes its args
                (case-split (integerp m))
                (case-split (integerp n))
                )
           (equal (ocat (ocat x y m) z n)
                  (ocat x (ocat y z n) (+ m n))))
  :hints (("Goal" :in-theory (enable ocat))))

(defthm ocat-equal-0
  (implies  (and (case-split (<= 0 x))
                 (case-split (<= 0 y))
                 (case-split (integerp x))
                 (case-split (integerp y))
                 )
            (equal (equal (ocat x y n) 0)
                   (and (equal x 0)
                        (equal y 0))))
  :hints (("Goal" :in-theory (enable ocat)))
  )

(defthm ocat-combine-constants
  (implies (and (syntaxp (and (quotep x)
                              (quotep y)
                              (quotep n)
                              (quotep m)))
                (case-split (<= 0 m))
                (case-split (<= 0 n))
                (case-split (<= m n))
                (case-split (integerp m))
                (case-split (integerp n)))
           (equal (ocat x (ocat y z m) n)
                  (ocat (ocat x y (- n m)) z m)))
  :otf-flg t
  :hints
  (("goal" :in-theory (enable ocat))))