// // Title: Object-Oriented Software Principles // Number: CAS CS 511 // Semester: Spring 2012 // Class Time: MW 1:00-2:30 // Instructor: Hongwei Xi (hwxiATcsDOTbuDOTedu) // (* // // Assigment #4, due Wednesday, the 15th of February // *) (* ****** ****** *) (* ** Please prove the following algebraic equation. ** You may use the axioms or theorems in prelude/SATS/arith.sats *) extern prfun // 10 points lemma_algequ {a,b:int}{a2,b2:int} (pfa: MUL (a, a, a2), pfb: MUL (b, b, b2)): MUL (a+b, a-b, a2-b2) // end of [lemma_algequ] (* ****** ****** *) // // TODD (n, s): s = (2*0+1) + ... + (2*n+1) // dataprop TODD (int, int) = | TODDbas (0, 1) of () | {n:nat}{s:int} TODDind (n+1, s+2*(n+1)+1) of TODD (n, s) // end of [TODD] (* ****** ****** *) extern prfun // 20 points lemma_todd // 1 + 3 + ... + (2*n + 1) = (n+1)*(n+1) {n:nat}{s:int} (pf: TODD (n, s)): MUL (n+1, n+1, s) // end of [lemma_todd] (* ****** ****** *) // // FIB (n, s): fib(n) = s // fib(n): Fibonacci numbers // dataprop FIB (int, int) = | FIB0 (0, 0) of () | FIB1 (1, 1) of () | {n:nat}{r0,r1:int} FIB2 (n+2, r0+r1) of (FIB (n, r0), FIB (n+1, r1)) // end of [FIB] (* ****** ****** *) (* ** ** 20 points ** Please encode the following theorem in ATS and then ** construct an inductive proof for it: ** ** for every natural number n, ** fib(0) + fib(1) + ... + fib(n) = fib (n+2) - 1 ** *) (* ****** ****** *) (* ** 30 bonus points *) 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] (* ****** ****** *) (* end of [assignment.dats] *)