CS 541 Lecture -*- Outline -*- * Reasoning about functional programs ** Equational reasoning in general *** equations formally a triple, (X, P, Q) X a set of vars, P and Q terms with free vars from X universally quantified formla of the form P(X) = Q(X) where P(X) and Q(X) are terms over X (T_{OP}(X)) formed from some operations and the vars X valid if holds in all environments (for all X) *** equational rule e1, ..., en |- e means if e1 and ... and en are valid, then so is e *** equational calculus [reflexive] |- (X, t1, t1) [symmetric] (X, t1, t2) |- (X, t2, t1) [transitive] (X, t1, t2), (X, t2, t3) |- (X, t1, t3) [substitution] (X, t1, t2) |- (X \cup Y, h(t1), h(t2)) for h: X -> T_{OP}(Y) [equals] (X, t1, t2) |- (X \cup Y, h_1(t), h_2(t)) for h_i: Y -> T_{OP} where h_i(y) = ti if y = y0, y otherwise (i=1,2), y0 given e.g., ({}, 0, 0+0) |- ({a,y0}, a*0, a*(0+0)) [dropvar] (X, t1, t2) |- (X0, t1, t2) for X0 \subseteq X such that free vars of t1 and t2 in X0 if X has variable of a type s, then T_{OP}(X0) has terms of sort s (for all types s) e.g., ({a,b,c}, a*0, 0) |- ({a}, a*0, 0) ** Specific rules for equational reasoning in functional langauges *** lists (car (cons a l)) = a (cdr (cons a l)) = l (length '()) = 0 (length (cons a l)) = (+ 1 (length l)) *** other data structures can also be defined equationally (e.g., streams) *** induction **** well-ordered set induction or transfinite induction (omit) a well-ordered set is a set and an ordering <= such that the set contains no infinite decreasing chain (i.e., of the form a0 >= a1 >= a2, ...) well-ordered sets have minimal elements transfinite induction principle: if for all a in A, ((for all a' in A, a'