File: gen-guards.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 (109 lines) | stat: -rw-r--r-- 4,212 bytes parent folder | download | duplicates (2)
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
(in-package "ACL2")
(include-book "misc/file-io" :dir :system)
(program)

(set-state-ok t)
(defun guard-thm-fn (name args state)

; This is adapted from ACL2 source function guard-clauses-for-fn.

 (let* ((ens (ens state))
        (wrld (w state))
        (newvar ; Matt K. mod; see ACL2 source function guard-clauses-for-fn1
         (genvar (cond ((symbolp name) name)
                       ((lambda-formals name) (car (lambda-formals name)))
                       (t 'APPLY$))
                 "NEWV"
                 nil
                 (all-vars!-of-fn name wrld))))
   (mv-let
     (normal-guard ttree)
; Matt K. mod: Update normalize call.
     (normalize (guard name nil wrld)
                t ; iff-flg
                nil ; type-alist
                ens wrld nil
                (backchain-limit wrld :ts))
     (mv-let
       (cl-set ttree)
; Matt K. mod: Update guard-clauses-for-body call.
       (guard-clauses-for-body (clausify (dumb-negate-lit normal-guard)
                                         nil t wrld)
                               (getprop name 'unnormalized-body
                                        '(:error "See GUARD-CLAUSES-FOR-FN.")
                                        'current-acl2-world wrld)
                               nil ; debug-info
                               nil ; stobj-optp
                               ens
                               wrld
                               nil ; safe-mode
                               nil ; gc-off
                               ttree
                               newvar)
       (declare (ignore ttree))
       (let ((guard-thm-name
              (intern-in-package-of-symbol
               (concatenate 'string (symbol-name name) "$GUARD-THM")
               name))
             (guard-op-name
              (intern-in-package-of-symbol
               (concatenate 'string (symbol-name name) "-GUARD")
               name)))
         `(defthm ,guard-thm-name
            ,(conjoin (prettyify-clause-lst cl-set nil wrld))
            :rule-classes ((:forward-chaining
                            :trigger-terms
                            ((,guard-op-name ,@args))))))))))


(defun defpredicate-fn (name args rest)
 `(progn (defun ,name ,args ,@rest)
         (defthm ,(intern-in-package-of-symbol
                   (concatenate 'string (symbol-name name) "$FORWARD")
                   name)
           (implies (,name ,@args)
                    ,(car (last rest)))
           :hints (("Goal"
                    :in-theory
                    (union-theories (theory 'ground-zero)
                                    '(,name))))
           :rule-classes :forward-chaining)))

(defmacro defpredicate (name args &rest rest)
 (defpredicate-fn name args rest))

(defmacro guard-thm (&rest args)
 `(value-triple ',args))

(defun guard-forms (forms acc state)
 (cond ((endp forms)
        (reverse acc))
       (t (guard-forms (cdr forms)
                       (let ((form (car forms)))
                         (if (and (consp form)
                                  (eq (car form) 'guard-thm))
                             (cons (guard-thm-fn (cadr form)
                                                 (cddr form)
                                                 state)
                                   acc)
                           acc))
                       state))))

(defun write-guards-fn (infile outfile state)
 (let ((ctx 'write-guards))
   (er-let* ((forms (read-list infile ctx state)))
            (let ((pkg-form (car forms)))
              (if (and (consp pkg-form)
                       (eq (car pkg-form) 'in-package)
                       (eql (length pkg-form) 2)
                       (equal (cadr pkg-form)
                              (current-package state)))
                  (write-list (guard-forms forms (list pkg-form) state)
                              outfile ctx state)
                (er soft 'write-guards
                    "Need to be in the package matching the first form of ~
                     ~x0,which should be an IN-PACKAGE form."
                    infile))))))

(defmacro write-guards (infile outfile)
 `(write-guards-fn ,infile ,outfile state))