1
#|-*-Lisp-*-=================================================================|#
3
#| coi: Computational Object Inference |#
5
#|===========================================================================|#
1
; Computational Object Inference
2
; Copyright (C) 2005-2014 Kookamara LLC
7
; 11410 Windermere Meadows
8
; Austin, TX 78759, USA
9
; http://www.kookamara.com/
11
; License: (An MIT/X11-style license)
13
; Permission is hereby granted, free of charge, to any person obtaining a
14
; copy of this software and associated documentation files (the "Software"),
15
; to deal in the Software without restriction, including without limitation
16
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
; and/or sell copies of the Software, and to permit persons to whom the
18
; Software is furnished to do so, subject to the following conditions:
20
; The above copyright notice and this permission notice shall be included in
21
; all copies or substantial portions of the Software.
23
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
; DEALINGS IN THE SOFTWARE.
8
33
(include-book "meta")
24
49
(:REWRITE MEMBERSHIP-EXTRACTION-INSTANCE)
29
54
(:REWRITE *TRIGGER*-UNIQUE-SUBBAGPS-IMPLIES-DISJOINTNESS)
30
55
(:REWRITE *TRIGGER*-SUBBAGP-PAIR-DISJOINT) ;can we get rid of this then?
33
;we look through HYPS for a term of the form (subbagp x y)
58
;we look through HYPS for a term of the form (subbagp x y)
34
59
;if such an item is found, we return (mv t y). else, we return (mv nil nil)
35
60
;what if multple such things might be found?
36
61
(defun find-exact-subbagp-instance (x hyps)
73
98
(consp (cdr (cadr entry)))
74
99
(consp (cddr (cadr entry)))
75
100
(let ((term (cadr (cadr entry)))
76
(zed (caddr (cadr entry))))
101
(zed (caddr (cadr entry))))
77
102
(and (syntax-subbagp-fn nil x term)
78
103
(cons term zed))))))
102
127
(or (find-bounded-subbagp-path t x1 hyps y hyps (1- n) (cons (cons x1 t) (cons (cons x0 nil) res)))
103
128
(find-bounded-subbagp-path nil x nrh y hyps (1- n) res))))))))))
105
130
(defun reverse-path (path res)
106
131
(declare (type t path res))
114
139
;what does this do?
115
;we look through HYPS for a term of the form (subbagp x BLAH)
140
;we look through HYPS for a term of the form (subbagp x BLAH)
116
141
;if such an item is found, we test whether BLAH equals y. else, we return nil
117
142
;what if multple such things might be found?
118
143
(defun subbagp-instance (x y hyps)
427
452
(if (and (consp xlist)
428
453
(consp (car xlist)))
429
454
(met ((hit syn p q ylist2) (find-disjointness* (caar xlist) ylist hyps))
431
456
(mv hit syn xlist ylist2 p q)
432
457
(find-disjointness** (cdr xlist) ylist hyps)))
433
458
(mv nil nil nil nil nil nil)))
435
;checks for subbagp paths up to disjoint
460
;checks for subbagp paths up to disjoint
436
461
;argument for disjointness comes from a disjoint in hyps
437
462
(defun disjoint-disjointness (x y hyps)
438
463
(declare (type t x hyps)
625
650
(let ((xlist (revlist xlist nil))
626
651
(ylist (revlist ylist nil))) ; smallest to largest
627
652
(met ((xlist ylist zlist) (find-shared-ancestor xlist ylist nil)) ; x/y largest to smallest
629
(let ((newzlist (find-unique-instance-list (revlist zlist nil) hyps)))
654
(let ((newzlist (find-unique-instance-list (revlist zlist nil) hyps)))
630
655
;; newzlist path from something unique down subbagps
631
656
(met ((hit newxlist x0 newylist y0 z zlist z0) (find-unique-subbagp** xlist ylist newzlist hyps))
632
657
(mv hit (reverse-path newxlist '(quote t))
659
684
(let ((hyps (mfc-clause mfc)))
662
687
(mfc-ancestors mfc) ;bzo why are we doing these checks?
663
688
(in-clause-disjoint x y hyps)
665
(met ((hit xlist* x0* ylist* y0* z* zlist* z0*) (unique-disjointness x y hyps))
690
(met ((hit xlist* x0* ylist* y0* z* zlist* z0*) (unique-disjointness x y hyps))
667
692
`((,key . (quote :unique))
668
693
(,xlist . ,xlist*)
689
714
(subbagp-pair x y x y)
690
715
:hints (("goal" :in-theory (enable subbagp-pair))))
693
718
(defun unique-subbagp-chain (x0 y0 z zlist z0)
694
719
(and (unique-subbagps x0 y0 z)
695
720
(unique-chain z zlist z0)))
698
723
(defun disjoint-hyp (key x xlist x0 y ylist y0 z-syn zlist-p z0-q)
700
725
((equal key ':disjoint)
776
801
:rule-classes :forward-chaining)
778
803
(defthm disjoint-computation
779
(implies (and (bind-free (bind-disjoint-argument nil 'key 'xlist 'x0 'ylist 'y0 'z 'zlist 'z0 x y mfc state)
804
(implies (and (bind-free (bind-disjoint-argument nil 'key 'xlist 'x0 'ylist 'y0 'z 'zlist 'z0 x y mfc state)
780
805
(key xlist x0 ylist y0 z zlist z0))
781
806
(disjoint-hyp key x xlist x0 y ylist y0 z zlist z0))
869
894
(consp (cdr (cadr entry)))
870
895
(consp (cddr (cadr entry)))
871
896
(equal (cadr (cadr entry)) x))
872
(find-memberp-instance-list x (cdr clause)
897
(find-memberp-instance-list x (cdr clause)
873
898
(cons (caddr (car (cdr entry))) res))
874
899
(find-memberp-instance-list x (cdr clause) res)))
1176
1201
(,val . ,(cdr x)))))))))
1178
1203
(defmacro bind-remove-bag-instance (y z which val)
1179
`(bind-free (bind-remove-bag-instance-fn ,y ,z (quote ,which) (quote ,val) mfc state)
1204
`(bind-free (bind-remove-bag-instance-fn ,y ,z (quote ,which) (quote ,val) mfc state)
1180
1205
(,which ,val)))
1183
1208
(defun disjoint-other-hyp (which x y z)
1185
1210
(disjoint (append x (remove-bag x y))
1187
1212
(disjoint (append x (remove-bag x z)) y)))
1189
1214
(defthm disjoint-other-memberp
1190
1215
(implies (and (bind-remove-bag-instance y z which x)
1191
1216
(disjoint-other-hyp which x y z))
1192
1217
(disjoint y z)))
1195
1220
(defun collect-list (term)
1196
1221
(if (and (consp term)
1197
1222
(equal (car term) 'remove-1))
1199
1224
,(collect-list (caddr term)))
1203
1228
(defun collect-rest (term)
1204
1229
(if (and (consp term)
1205
1230
(equal (car term) 'remove-1))
1206
1231
(collect-rest (caddr term))
1210
1235
(defun bind-list (list rest term)
1211
1236
`((,list . ,(collect-list term))
1212
1237
(,rest . ,(collect-rest term))))