// // Course: BU CAS CS 520 // Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) // This file is for Assignment 3, BU CAS CS 520, Fall, 2010 // (* ****** ****** *) dataprop FIB (int, int) = | {n:int | n >= 2} {r1,r2:int} FIBind (n, r1+r2) of (FIB (n-1, r1), FIB (n-2, r2)) | {n:nat | n < 2} FIBbas (n, n) of () // end of [FIB] (* ****** ****** *) // fib(n) is a nat for every nat n. prfun fib_nat_nat {n:nat} {r:int} .. (pf: FIB (n, r)):<> [r>=0] void = case+ pf of | FIBind (pf1, pf2) => let prval () = fib_nat_nat (pf1) and () = fib_nat_nat (pf2) in // nothing end // end of [FIBind] | FIBbas () => () // end of [fib_nat_nat] extern prfun fib_istot {n:nat} (): [r:int] FIB (n, r) extern prfun fib_isfun {n:nat} {r1,r2:int} (pf1: FIB (n, r1), pf2: FIB (n, r2)): [r1==r2] void // end of [fib_isfun] (* ****** ****** *) (* // 20 points // fib(m+n+1) = fib(m+1) * fib(n+1) + fib(m) * fib(n) LHS = fib(m+1+n+1) = fib(m+(n+1)+1) RHS = fib(m+2) * fib(n+1) + fib(m+1) * fib(n) = fib(m+1) * fib(n+1) + fib(m) * fib(n+1) + fib(m+1) * fib(n) = fib(m+1) * fib(n+2) + fib(m) * fib(n+1) = LHS (by IH) *) extern prfun fibeq {m,n:nat} {r1,r2,r3,r4:int} {r12,r34:int} ( pf1: FIB (m, r1) // r1 = fib(m) , pf2: FIB (n, r2) // r2 = fib(n) , pf3: FIB (m+1, r3) // r3 = fib(m+1) , pf4: FIB (n+1, r4) // r4 = fib(n+1) , pf5: MUL (r1, r2, r12) // r12 = r1*r2 , pf6: MUL (r3, r4, r34) // r34 = r3*r4 ) : FIB (m+n+1, r12+r34) // r12+r34 = fib(m+n+1) // end of [fibeq] (* ****** ****** *) implement main () = () (* ****** ****** *) (* end of [fibeq.dats] *)