1
; Introduction of an arbitrary tail-recursive function.
2
; Copyright (C) 2001 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.
25
; Last modified 26 September 2001.
27
To certify in ACL2 Version 2.5:
28
(certify-book "tail" 0 nil ; compile-flg
33
Show for Pete & J's construction, as reported in defpun.lisp, of
34
tail-recursive f, any constant would do in place of nil in the
53
(if (zp n) x (stn (st x) (1- n))))
55
(defchoose fch (n) (x)
59
(declare (xargs :measure (nfix n)))
60
(if (or (zp n) (test x))
64
;; Here an arbitrary constant, (const), is used in place of nil in
65
;; Pete & J's original definition.
67
(if (test (stn x (fch x)))
71
;;; This proof of generic-tail-recursive-f is a minor
72
;;; variation of Pete & J's proof of generic-tail-recursive-f
76
(local (defthm test-fch
78
(test (stn x (fch x))))
80
(("goal" :use ((:instance fch (n 0)))))))
82
;; Not needed for Pete & J's proof of generic-tail-recursive-f.
83
;; Also not needed for this proof of generic-tail-recursive-f.
84
;;(local (defthm test-f-def
86
;; (equal (f x) (base x)))))
88
(local (defthm open-stn
89
(implies (and (integerp n) (< 0 n))
91
(stn (st x) (1- n))))))
93
(local (defthm +1-1 (equal (+ -1 +1 x) (fix x))))
95
(local (defthm st-stn-fch
96
(implies (test (stn (st x) (fch (st x))))
97
(test (stn x (fch x))))
100
((:instance fch (n (1+ (nfix (fch (st x))))))
101
(:instance fch (n 1)))))
102
:rule-classes :forward-chaining))
104
(local (defthm test-nil-fch
105
(implies (not (test x))
106
(iff (test (stn (st x)
108
(test (stn x (fch x)))))
110
(("subgoal 2" :expand (stn x (fch x))
112
((:instance fch (x (st x))
113
(n (+ -1 (fch x)))))))))
116
(implies (and (test (stn x n))
118
(equal (fn x n) (fn x m)))
121
(defthm generic-tail-recursive-f
123
(if (test x) (base x) (f (st x))))
125
(("subgoal 1" :expand (fn x (fch x)))
127
((:instance fn-st (x (st x))