File: substitute.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 (162 lines) | stat: -rw-r--r-- 6,127 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
; Centaur Meta-reasoning Library
; Copyright (C) 2019 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>

(in-package "CMR")

(include-book "subst")
(include-book "term-vars")
(local (include-book "std/alists/alist-keys" :dir :system))
(local (include-book "std/lists/sets" :dir :system))

(defines term-subst
  :flag-local nil
  (define term-subst ((x pseudo-termp)
                      (a pseudo-term-subst-p))
    :returns (new-x pseudo-termp)
    :measure (pseudo-term-count x)
    :verify-guards nil
    (pseudo-term-case x
      :const (pseudo-term-fix x)
      :var (let ((look (assoc-eq x.name (pseudo-term-subst-fix a))))
             (if look (cdr look) (pseudo-term-fix x)))
      :call (pseudo-term-call x.fn (termlist-subst x.args a))))
  (define termlist-subst ((x pseudo-term-listp)
                          (a pseudo-term-subst-p))
    :returns (new-x pseudo-term-listp)
    :measure (pseudo-term-list-count x)
    (if (Atom x)
        nil
      (cons (term-subst (car x) a)
            (termlist-subst (cdr x) a))))
  ///
  (defthm len-of-termlist-subst
    (equal (len (termlist-subst x a))
           (len x)))

  (verify-guards term-subst)

  (local (defthm assoc-of-append
           (implies k
                    (equal (assoc k (append a b))
                           (or (assoc k a) (assoc k b))))))

  (defret-mutual base-ev-of-term-subst
    (defret base-ev-of-term-subst
      (equal (base-ev (term-subst x a) env)
             (base-ev x (append (base-ev-alist a env) env)))
      :hints ('(:expand (<call>)
                :in-theory (enable acl2::base-ev-when-pseudo-term-call
                                   acl2::base-ev-of-pseudo-term-call)))
      :fn term-subst)
    (defret base-ev-list-of-termlist-subst
      (equal (base-ev-list (termlist-subst x a) env)
             (base-ev-list x (append (base-ev-alist a env) env)))
      :hints ('(:expand (<call>)))
      :fn termlist-subst))

  
  (defret-mutual acons-non-var-preserves-<fn>
    (defret acons-non-var-preserves-<fn>
      (implies (not (member k (term-vars x)))
               (equal (term-subst x (cons (cons k v) a))
                      new-x))
      :hints ('(:expand ((term-vars x)
                         (:free (a) <call>))))
      :fn term-subst)
    (defret acons-non-var-preserves-<fn>
      (implies (not (member k (termlist-vars x)))
               (equal (termlist-subst x (cons (cons k v) a))
                      new-x))
      :hints ('(:expand ((termlist-vars x)
                         (:free (a) <call>))))
      :fn termlist-subst))

  (fty::deffixequiv-mutual term-subst))



(defines term-subst-strict
  :flag-local nil
  (define term-subst-strict ((x pseudo-termp)
                             (a pseudo-term-subst-p))
    :returns (new-x pseudo-termp)
    :measure (pseudo-term-count x)
    :verify-guards nil
    (pseudo-term-case x
      :const (pseudo-term-fix x)
      :var (cdr (assoc-eq x.name (pseudo-term-subst-fix a)))
      :call (pseudo-term-call x.fn (termlist-subst-strict x.args a))))
  (define termlist-subst-strict ((x pseudo-term-listp)
                          (a pseudo-term-subst-p))
    :returns (new-x pseudo-term-listp)
    :measure (pseudo-term-list-count x)
    (if (Atom x)
        nil
      (cons (term-subst-strict (car x) a)
            (termlist-subst-strict (cdr x) a))))
  ///
  (defthm len-of-termlist-subst-strict
    (equal (len (termlist-subst-strict x a))
           (len x)))

  (verify-guards term-subst-strict)

  (defret-mutual base-ev-of-term-subst-strict
    (defret base-ev-of-term-subst-strict
      (equal (base-ev (term-subst-strict x a) env)
             (base-ev x (base-ev-alist a env)))
      :hints ('(:expand (<call>)
                :in-theory (enable acl2::base-ev-when-pseudo-term-call
                                   acl2::base-ev-of-pseudo-term-call)))
      :fn term-subst-strict)
    (defret base-ev-list-of-termlist-subst-strict
      (equal (base-ev-list (termlist-subst-strict x a) env)
             (base-ev-list x (base-ev-alist a env)))
      :hints ('(:expand (<call>)))
      :fn termlist-subst-strict))

  (defret-mutual acons-non-var-preserves-<fn>
    (defret acons-non-var-preserves-<fn>
      (implies (not (member k (term-vars x)))
               (equal (term-subst-strict x (cons (cons k v) a))
                      new-x))
      :hints ('(:expand ((term-vars x)
                         (:free (a) <call>))))
      :fn term-subst-strict)
    (defret acons-non-var-preserves-<fn>
      (implies (not (member k (termlist-vars x)))
               (equal (termlist-subst-strict x (cons (cons k v) a))
                      new-x))
      :hints ('(:expand ((termlist-vars x)
                         (:free (a) <call>))))
      :fn termlist-subst-strict))

  (fty::deffixequiv-mutual term-subst-strict))