1
; An ACL2 Tarai Function book.
2
; Copyright (C) 2000 John R. Cowles, University of Wyoming
4
; This book is free software; you can redistribute it and/or modify
5
; it under the terms of the GNU General Public License as published by
6
; the Free Software Foundation; either version 2 of the License, or
7
; (at your option) any later version.
9
; This book is distributed in the hope that it will be useful,
10
; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
; GNU General Public License for more details.
14
; You should have received a copy of the GNU General Public License
15
; along with this book; if not, write to the Free Software
16
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
; Department of Computer Science
21
; University of Wyoming
22
; Laramie, WY 82071-3682 U.S.A.
24
;; The function Fb satisfies the tarai recursion and the
25
;; restricted tarai recursion for lists of length 6.
27
;; (certify-book "C:/acl2/tak/tarai2")
33
"Return the last element in the list lst."
34
(list 'car (list 'last lst)))
38
"Bailey's g function for Knuth's Theorem 4.
39
The input lst is intended to be a nonempty
41
(declare (xargs :guard (and (integer-listp lst)
43
(cond ((consp (nthcdr 3 lst)) ;; (len lst) > 3
44
(if (or (equal (first lst)
51
(t (last-el lst)))) ;; (len lst) <= 3
54
"Determine if the elements in lst are strictly decreasing."
55
(declare (xargs :guard (rational-listp lst)))
56
(if (consp (rest lst)) ;; (len lst) > 1
57
(and (> (first lst)(second lst))
58
(decreasing-p (rest lst)))
62
first-non-decrease (lst)
63
"Return the front of lst up to and including the first
64
element that does not strictly decrease."
65
(declare (xargs :guard (and (rational-listp lst)
66
(not (decreasing-p lst)))))
67
(if (consp (rest lst)) ;; (len lst) > 1
68
(if (<= (first lst)(second lst))
69
(list (first lst)(second lst))
71
(first-non-decrease (rest lst))))
76
"Bailey's f function for Knuth's theorem 4.
77
The input lst is intended to be a nonempty
79
(declare (xargs :guard (and (integer-listp lst)
81
(if (decreasing-p lst)
83
(Gb (first-non-decrease lst))))
86
"Return the result of shifting the first element
87
of the list lst onto the tail end of lst."
88
(declare (xargs :guard (true-listp lst)))
90
(append (rest lst)(list (first lst)))
95
"Return the result of replacing (first lst)
96
with (first lst) - 1."
97
(declare (xargs :guard (and (rational-listp lst)
100
(cons (- (first lst) 1)
105
lst-rotates-with-minus-1 (n lst)
106
"Return the list of n+1 successive rotates of the
107
list lst with the first of each rotate replaced
108
by the first minus 1."
109
(declare (xargs :guard (and (rational-listp lst)
116
(lst-rotates-with-minus-1 (- n 1)
122
(cons (Fb (first lst))
128
"Return the number of strictly decreasing elements
129
at the front of the list lst."
130
(declare (xargs :guard (rational-listp lst)))
131
(cond ((consp (rest lst)) ;; (len lst) > 1
132
(if (<= (first lst)(second lst))
134
(+ 1 (dec-front-len (rest lst)))))
135
((consp lst) 1) ;; (len lst) = 1
136
(t 0))) ;; (len lst) = 0
137
;;----------------------------------------------------------
138
;; Fb satisfies the tarai recursion equation when lst is a
139
;; true list of integers of length 5.
143
lst-rotates-with-minus-1-6a
144
(let ((lst (list first second third forth fifth sixth)))
145
(equal (lst-rotates-with-minus-1 1 lst)
146
(list (list (- first 1) second third forth fifth sixth)
147
(list (- second 1) third forth fifth sixth first))))
149
:expand ((lst-rotates-with-minus-1
151
(list first second third forth fifth sixth))))))
156
lst-rotates-with-minus-1-6b
157
(let ((lst (list first second third forth fifth sixth)))
158
(equal (lst-rotates-with-minus-1 2 lst)
159
(list (list (- first 1) second third forth fifth sixth)
160
(list (- second 1) third forth fifth sixth first)
161
(list (- third 1) forth fifth sixth first second)))))
166
lst-rotates-with-minus-1-6c
167
(let ((lst (list first second third forth fifth sixth)))
168
(equal (lst-rotates-with-minus-1 3 lst)
169
(list (list (- first 1) second third forth fifth sixth)
170
(list (- second 1) third forth fifth sixth first)
171
(list (- third 1) forth fifth sixth first second)
172
(list (- forth 1) fifth sixth first second third)))))
177
lst-rotates-with-minus-1-6d
178
(let ((lst (list first second third forth fifth sixth)))
179
(equal (lst-rotates-with-minus-1 4 lst)
180
(list (list (- first 1) second third forth fifth sixth)
181
(list (- second 1) third forth fifth sixth first)
182
(list (- third 1) forth fifth sixth first second)
183
(list (- forth 1) fifth sixth first second third)
184
(list (- fifth 1) sixth first second third forth)
190
lst-rotates-with-minus-1-6e
191
(let ((lst (list first second third forth fifth sixth)))
193
(lst-rotates-with-minus-1 5 lst)
194
(list (list (- first 1) second third forth fifth sixth)
195
(list (- second 1) third forth fifth sixth first)
196
(list (- third 1) forth fifth sixth first second)
197
(list (- forth 1) fifth sixth first second third)
198
(list (- fifth 1) sixth first second third forth)
199
(list (- sixth 1) first second third forth fifth)
204
;;Time: 703.87 seconds (prove: 327.38, print: 376.44, other: 0.05)
206
(implies (and (integerp first)
212
(let ((lst (list first second third forth fifth sixth)))
217
(Fb (Fb-lst (lst-rotates-with-minus-1
223
;;Time: 253.60 seconds (prove: 122.80, print: 130.74, other: 0.06)
225
(implies (and (integerp first)
231
(let ((lst (list first second third forth fifth sixth)))
236
(Fb (Fb-lst (lst-rotates-with-minus-1
237
(- (dec-front-len lst) 1)