File: trivial-ancestors-check.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,138,276 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,978; makefile: 3,840; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (164 lines) | stat: -rw-r--r-- 7,068 bytes parent folder | download | duplicates (4)
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
; Trivial-ancestors-check: replace the ACL2 ancestors check heuristic with a
; simpler one

; Copyright (C) 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/
;
; License: (An MIT/X11-style license)
;
;   Permission is hereby granted, free of charge, to any person obtaining a
;   copy of this software and associated documentation files (the "Software"),
;   to deal in the Software without restriction, including without limitation
;   the rights to use, copy, modify, merge, publish, distribute, sublicense,
;   and/or sell copies of the Software, and to permit persons to whom the
;   Software is furnished to do so, subject to the following conditions:
;
;   The above copyright notice and this permission notice shall be included in
;   all copies or substantial portions of the Software.
;
;   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;   DEALINGS IN THE SOFTWARE.
;
; Original author: Sol Swords <sswords@centtech.com>

; Very lightly modified April 2013 by Matt K. to accommodate introduction of
; defrec for ancestors.

(in-package "ACL2")

(include-book "xdoc/top" :dir :system)

; Sometimes the ACL2 ancestors-check heuristic prevents rules from applying
; when you think they should.  Fortunately it's an attachable function, so we
; can make it into a simple loop check without too much trouble.

; The constraint it needs to satisfy:

;; (defthmd ancestors-check-constraint
;;    (implies (and (pseudo-termp lit)
;;                  (ancestor-listp ancestors)
;;                  (true-listp tokens))
;;             (mv-let (on-ancestors assumed-true)
;;                     (ancestors-check lit ancestors tokens)
;;                     (implies (and on-ancestors
;;                                   assumed-true)
;;                              (member-equal-mod-commuting
;;                               lit
;;                               (strip-ancestor-literals ancestors)
;;                               nil))))
;;    :hints (("Goal" :use ancestors-check-builtin-property)))

(local (in-theory (disable mv-nth equal-mod-commuting)))

(defun check-assumed-true-or-false (lit lit-atm ancestors)
  (declare (xargs :guard (and (pseudo-termp lit)
                              (pseudo-termp lit-atm)
                              (ancestor-listp ancestors))))
  (cond ((endp ancestors) (mv nil nil))
        ((ancestor-binding-hyp-p (car ancestors))
         (check-assumed-true-or-false lit lit-atm (cdr ancestors)))
        ((equal-mod-commuting lit
                              (access ancestor (car ancestors) :lit) ;; first lit
                              nil)
         (mv t t))
        ((equal-mod-commuting lit-atm
                              (access ancestor (car ancestors) :atm) ;; atom of first lit
                              nil)
         (mv t nil))
        (t (check-assumed-true-or-false lit lit-atm (cdr ancestors)))))

(defthmd check-assumed-true-or-false-ok
  (mv-let (present true)
    (check-assumed-true-or-false lit lit-atm ancestors)
    (implies (and present true)
             (member-equal-mod-commuting
              lit (strip-ancestor-literals ancestors) nil))))

(in-theory (disable check-assumed-true-or-false))

(defun trivial-ancestors-check (lit ancestors tokens)
  (declare (xargs :guard (and (pseudo-termp lit)
                              (ancestor-listp ancestors)
                              (true-listp tokens)))
           (ignorable tokens))
  (cond ((endp ancestors)
         (mv nil nil))
        (t (mv-let (not-flg lit-atm)
             (strip-not lit)
             (declare (ignore not-flg))
             (check-assumed-true-or-false lit lit-atm ancestors)))))

(defthmd trivial-ancestors-check-ok
  (mv-let (present true)
    (trivial-ancestors-check lit ancestors tokens)
    (implies (and present true)
             (member-equal-mod-commuting
              lit (strip-ancestor-literals ancestors) nil)))
  :hints(("Goal" :in-theory (enable check-assumed-true-or-false-ok))))

(in-theory (disable trivial-ancestors-check))

;; test
(local (defattach (ancestors-check trivial-ancestors-check)
         :system-ok t
         :hints (("goal" :in-theory '(trivial-ancestors-check-ok)))))

;; This macro makes a local event, but you can also do
;; (local (include-book "centaur/misc/defeat-ancestors" :dir :system))
;; (local (use-trivial-ancestors-check))
;; if you want this book to be included only locally.
(defmacro use-trivial-ancestors-check ()
  '(local (defattach (ancestors-check trivial-ancestors-check)
            :system-ok t
            :hints (("goal" :in-theory '(trivial-ancestors-check-ok))))))


(defxdoc use-trivial-ancestors-check
  :short "Override ACL2's built-in ancestors check heuristic with a simpler and less surprising one."
  :parents (proof-automation) ;; ???
  :long "<p>Usage: as an embeddable event,</p>

@({
 (include-book \"tools/trivial-ancestors-check\" :dir :system)
 (use-trivial-ancestors-check)
 })
<p>or</p>
@({
 (local (include-book \"tools/trivial-ancestors-check\" :dir :system))
 (local (use-trivial-ancestors-check)).
 })

<p>(Note: @('use-trivial-ancestors-check') expands to a local event, but you
can still wrap it in local, in which case the trivial-ancestors-check book may
be included locally.)</p>

<p>ACL2 has a heuristic called @('ancestors-check') which it uses to
prevent loops in backchaining during rewriting.  The @('ancestors'), in this
context, are the sequence of hyps we have backchained to in order to get to the
one we are currently trying to relieve.  Among other things, ACL2's built in
ancestors check decides whether the current hyp is more complicated than any
ancestral hyp, and gives up on backchaining if so.  Occasionally this can cause
a rewriting strategy to mysteriously fail to work.  Fortunately, ACL2 allows
its default ancestors check to be replaced by an attachment.</p>

<p>Running @('(use-trivial-ancestors-check)') replaces the default ancestors
check with one that does much less: it only checks whether the current hyp
occurs, exactly or negated, in the ancestors, and doesn't try to prevent
backchaining to more complicated hyps.</p>

<p>This could cause rewriting to fail due to a chain of increasingly
complicated hyps.  But when we tried replacing ACL2's default heuristic with
this new one, we only found a couple of examples in the regression where this
was the case, and these were due to (in our view) bad rules.  So in practice,
this seems to be fairly undisruptive.</p>")

(defpointer trivial-ancestors-check use-trivial-ancestors-check)