CSC302 2005S, Class 6: Gries 2: Boolean Reasoning Admin: * Late: SAM, Arjun * Please don't forget to submit questions. * Homework for Monday: Sections 1-5 of the Scheme Report. * Scheme Report available this afternoon. * Homework for Friday: Questions from Gries. Overview: * How to prove * Some basic laws * Terminology * "What is the alternative?" Goals of Gries's book: * To teach you a mechanism for proving programs correct * To teach you a new mechanism for *developing* programs * To describe the semantics of a simple language Focus of this chapter: Issues in proof * Need to look at proof a little bit more formally (ooh, semantics) What kinds of things might you want to prove in Boolean logic (at this point)? * Proposition is a tautology * Tautology: True for every state in which it is well-defined * State: Mapping of variables in a statement to true and false * Can a proposition every be ill-defined? * When some variables are not defined * When some variables have definitions other than true or false What techniques do you know for proving that E is a tautology? * Make a truth table Example not (a and b) = (not a) or (not b) a b 1:(a and b) 2:(not 1) 3:(not a) 4:(not b) 5:(3 or 4) 6:(2 = 5) F F 1:F 2:T 3:T 4:T 5:T 6:T F T 1:F 2:T 3:T 4:F 5:T 6:T T F 1:F 2:T 3:F 4:T 6:T 6:T T T 1:T 2:F 3:F 4:F 5:F 6:T What permitted the intermediate computations of (intermeidate value 1) and (intermediate value 2) and ... * Definitions of and, or, not * Rule of variable substitution * Rule of recursive computation Proof that E is a tautology, v1: Truth table Strength * Easy to read proof (intuitive) * Confidence * AUTOMATABLE Weaknesses * Time-consuming 2^#variables*time-to-eval-expression * Errors can crop up in carelessly-constructed truth tables * Limited help of proving other tautologies Other ways to prove that E is a tautology? * Reduce to something simpler and equivalent, E', and prove that E' is a tautology * Normalize (automatically) and hope that normal form helps Need a system (Calculus) which describes the valid transformations Valid transformations? (Rules for transforming equations) * Substitution * IF E1 = S then L(E1) = L(S) * Transitivity if E1 = S and S = E2 then E1 = E2 Goal: E1 = E2; prove E1 = S and S = E2 * Human intelligence normally helps us identify a good intermediate S Alternate view of substitution If E1 = E2 then E1(S) = E2(S) Laws * Reflexivity: E1 = E2 then E2 = E1 Question: If I have proven that L(E1) = L(S) have I also proven that E1 = S? * Yes: 4 * No: 9 * Doesn't think: 1 Suppose L(x) = (F and x) L(T) = F L(F) = F but T != F SUBSTITUTION IS NOT BI-DIRECTIONAL * General facts let us prove more specific facts * More-specific facts do not let us prove more general facts (unless we accumulate a lot of them into a truth table) * Law is a specific proposition you can use in substitution and transitivity Open questions for Monday: * Suppose I want to prove that E1 = E2. How does substitution help? * Are there systems in which some of Gries's laws don't hold?