File: cons.lisp

package info (click to toggle)
acl2 8.3dfsg-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 309,408 kB
  • sloc: lisp: 3,311,842; javascript: 22,569; cpp: 9,029; ansic: 7,872; perl: 6,501; xml: 3,838; java: 3,738; makefile: 3,383; ruby: 2,633; sh: 2,489; ml: 763; python: 741; yacc: 721; awk: 260; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (168 lines) | stat: -rw-r--r-- 5,604 bytes parent folder | download | duplicates (5)
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
; Standard Utilities Library
; Copyright (C) 2008-2016 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 authors: Jared Davis <jared@centtech.com>
;                   Sol Swords <sswords@centtech.com>

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

(defsection prod-consp
  :parents (prod-cons)
  :short "Special recognizer for conses, except that to save space we require
          that (nil . nil) be represented just as nil."

  (defund prod-consp (x)
    (declare (xargs :guard t))
    (if (consp x)
        (and (or (car x) (cdr x))
             t)
      (not x)))

  (local (in-theory (enable prod-consp)))

  (defthm booleanp-of-prod-consp
    (booleanp (prod-consp x))
    :rule-classes :type-prescription)

  (defthm prod-consp-compound-recognizer
    (implies (prod-consp x)
             (or (consp x) (not x)))
    :rule-classes :compound-recognizer))


(defsection prod-cons
  :parents (defaggregate)
  :short "Special constructor for products that collapses (nil . nil) into nil."

  (defund-inline prod-cons (x y)
    (declare (xargs :guard t))
    (and (or x y)
         (cons x y)))

  (local (in-theory (enable prod-cons)))

  (defthm prod-consp-of-prod-cons
    (prod-consp (prod-cons x y))
    :rule-classes (:rewrite :type-prescription)
    :hints(("Goal" :in-theory (enable prod-consp))))

  (defthm car-of-prod-cons
    (equal (car (prod-cons x y)) x))

  (defthm cdr-of-prod-cons
    (equal (cdr (prod-cons x y)) y))

  (defthm prod-cons-of-car/cdr
    (implies (prod-consp x)
             (equal (prod-cons (car x) (cdr x))
                    x))
    :hints(("Goal" :in-theory (enable prod-consp))))

  (defthmd equal-of-prod-cons
    (implies (prod-consp x)
             (equal (equal x (prod-cons a b))
                    (and (equal (car x) a)
                         (equal (cdr x) b))))
    :hints(("Goal" :in-theory (enable prod-consp))))

  (defthm acl2-count-of-prod-cons
    (and (>= (acl2-count (prod-cons x y))
             (acl2-count x))
         (>= (acl2-count (prod-cons x y))
             (acl2-count y)))
    :rule-classes :linear)

  (defthm prod-cons-equal-cons
    (implies (or a b)
             (equal (equal (prod-cons a b) (cons c d))
                    (and (equal a c)
                         (equal b d))))
    :hints(("Goal" :in-theory (enable prod-cons))))

  (defthm prod-cons-when-either
    (implies (or a b)
             (and (prod-cons a b)
                  (consp (prod-cons a b))))
    :rule-classes ((:rewrite)
                   (:type-prescription :corollary
                    (implies (or a b)
                             (consp (prod-cons a b)))))
    :hints(("Goal" :in-theory (enable prod-cons))))

  (defthm prod-cons-not-consp-forward
    (implies (not (consp (prod-cons a b)))
             (and (not a) (not b)))
    :hints(("Goal" :in-theory (enable prod-cons)))
    :rule-classes ((:forward-chaining :trigger-terms ((prod-cons a b))))))


(defsection prod-cons-with-hint
  :parents (prod-cons)
  :short "Same as @(see prod-cons), but avoids reconsing like @(see cons-with-hint)."
  :long "<p>We leave this enabled and expect to reason about @(see prod-cons) instead.</p>"

  (defun-inline prod-cons-with-hint (x y hint)
    (declare (xargs :guard t))
    (mbe :logic (prod-cons x y)
         :exec  (and (or x y)
                     (cons-with-hint x y hint)))))


(defsection prod-car
  :parents (prod-cons)
  :short "Same as @(see car), but guarded with @(see prod-consp)."
  :long "<p>We leave this enabled and expect to reason about @(see car) instead.</p>"

  (defun-inline prod-car (x)
    (declare (xargs :guard (prod-consp x)))
    (car x)))


(defsection prod-cdr
  :parents (prod-cons)
  :short "Same as @(see cdr), but guarded with @(see prod-consp)."
  :long "<p>We leave this enabled and expect to reason about @(see car) instead.</p>"

  (defun-inline prod-cdr (x)
    (declare (xargs :guard (prod-consp x)))
    (cdr x)))


(defsection prod-hons
  :parents (prod-cons)
  :short "Same as @(see prod-cons) but uses @(see hons)."
  :long "<p>We leave this enabled and expect to reason about @(see prod-cons) instead.</p>"

  (local (in-theory (enable prod-cons)))

  (defun-inline prod-hons (x y)
    (declare (xargs :guard t))
    (mbe :logic (prod-cons x y)
         :exec (and (or x y)
                    (hons x y)))))