File: cons-size.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 (186 lines) | stat: -rw-r--r-- 5,316 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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
(in-package "ACL2")
(include-book "std/lists/top" :dir :system)
(include-book "std/alists/top" :dir :system)
(include-book "std/strings/top" :dir :system)
(include-book "acl2s/defdata/records" :dir :system)

(defun cons-size (x)
  (declare (xargs :guard t))
  (if (consp x)
      (+ 1 (cons-size (car x)) (cons-size (cdr x)))
    0))

(defmacro tree-size (x)
  `(cons-size ,x))

(defthm cons-size-type
  (natp (cons-size x))
  :rule-classes
  ((:type-prescription)
   (:forward-chaining :trigger-terms ((cons-size x)))))

(defthm acons-cons-size-lemma
  (= (cons-size (acons x1 x2 x3))
     (+ 2 (cons-size x1)
        (cons-size x2)
        (cons-size x3)))
  :rule-classes ((:linear) (:rewrite)))

(defthm split-list-1-cons-size
  (implies (consp x)
           (< (cons-size (mv-nth 1 (str::split-list-1 x str::del)))
              (cons-size x)))
  :hints (("Goal" :in-theory (enable str::split-list-1)))
  :rule-classes :linear)

(defthm head-cons-size
  (implies (not (set::emptyp x))
           (< (cons-size (set::head x))
              (cons-size x)))
  :hints (("Goal" :in-theory (enable set::emptyp set::head)))
  :rule-classes :linear)

(defthm tail-cons-size
  (implies (not (set::emptyp x))
           (< (cons-size (set::tail x))
              (cons-size x)))
  :hints (("Goal" :in-theory (enable set::emptyp set::tail)))
  :rule-classes :linear)

(defthm cons-size-append
  (= (cons-size (append x y))
     (+ (cons-size x) (cons-size y)))
  :rule-classes ((:linear) (:rewrite)))

(defthm rev-cons-size-lemma
  (= (cons-size (rev x))
     (cons-size x))
  :hints (("Goal" :in-theory (enable rev)))
  :rule-classes ((:linear) (:rewrite)))

(defthm cons-size-evens-strong
  (implies (and (consp x)
                (consp (cdr x)))
           (< (cons-size (evens x))
              (cons-size x)))
  :rule-classes :linear)

(defthm cons-size-evens-weak
  (<= (cons-size (evens x))
      (cons-size x))
  :hints (("Goal" :induct (evens x)))
  :rule-classes :linear)

(defthm cons-size-of-remove-assoc-equal-upper-bound
  (<= (cons-size (remove-assoc-equal a x))
      (cons-size x))
  :hints (("Goal" :in-theory (enable remove-assoc-equal)))
  :rule-classes :linear)

(defthm cons-size-when-member
  (implies (member-equal a x)
           (< (cons-size a)
              (cons-size x)))
  :hints (("Goal" :in-theory (enable member-equal)))
  :rule-classes :linear)

(defthm cons-size-of-remove-duplicates
  (<= (cons-size (remove-duplicates-equal x))
      (cons-size x))
  :rule-classes :linear)

(defthm cons-size-of-hons-remove-duplicates
  (<= (cons-size (acl2::hons-remove-duplicates x))
      (cons-size x))
  :hints (("Goal" :in-theory (enable acl2::hons-remove-duplicates)))
  :rule-classes :linear)

(defthm cons-size-of-nthcdr-linear
  (implies (and (not (zp n)) (consp x))
           (< (cons-size (nthcdr n x))
              (cons-size x)))
  :hints (("Goal" :in-theory (enable nthcdr)))
  :rule-classes :linear)

(defthm cons-size-of-nthcdr-linear-weak
  (<= (cons-size (nthcdr n x))
      (cons-size x))
  :hints (("Goal" :in-theory (enable nthcdr)))
  :rule-classes :linear)

(defthm cons-size-of-nth-linear-weak
  (<= (cons-size (nth i x))
      (cons-size x))
  :rule-classes :linear)

(defthm cons-size-of-nth-linear
  (implies  (consp x)
            (< (cons-size (nth i x))
               (cons-size x)))
  :rule-classes :linear)

(defthm cons-size-of-prod-cons1
  (<= (cons-size std::y)
      (cons-size (std::prod-cons std::x std::y)))
  :rule-classes :linear)

(defthm cons-size-of-prod-cons2
  (<= (cons-size std::x)
      (cons-size (std::prod-cons std::x std::y)))
  :rule-classes :linear)

(defthm records-cons-size-linear-arith-<=
  (<= (cons-size (mget k r))
      (cons-size r))
  :hints (("goal" :in-theory
           (enable mget recordp no-nil-val-alistp ordered-unique-key-alistp)))
  :rule-classes :linear)

(defthm records-cons-size-linear-arith-<
  (implies (mget k r)
           (< (cons-size (mget k r))
              (cons-size r)))
  :hints (("goal" :in-theory
           (enable mget recordp no-nil-val-alistp ordered-unique-key-alistp)))
  :rule-classes :linear)

(defthm records-cons-size
  (implies (consp r)
           (< (cons-size (mget k r))
              (cons-size r)))
  :hints (("goal" :in-theory
           (enable mget recordp no-nil-val-alistp ordered-unique-key-alistp)))
  :rule-classes :linear)

(defthm len-<=-cons-size
  (<= (len x) (cons-size x))
  :rule-classes :linear)

(defthm cons-size-<=-acl2-count
  (<= (cons-size x)
      (acl2-count x))
  :rule-classes :linear)

; This shows that cons-size can be used to prove termination of
; acl2-count (which is what acl2-size is).

(defun acl2-size (x)
  (declare (xargs :guard t
                  :measure (if (and (not (rationalp x))
                                    (complex/complex-rationalp x))
                               1
                             (* 2 (cons-size x)))))
  (if (consp x)
      (+ 1 (acl2-size (car x))
         (acl2-size (cdr x)))
    (if (rationalp x)
        (if (integerp x)
            (integer-abs x)
          (+ (integer-abs (numerator x))
             (denominator x)))
      (if (complex/complex-rationalp x)
          (+ 1 (acl2-size (realpart x))
             (acl2-size (imagpart x)))
        (if (stringp x)
            (length x)
          0)))))