CSC 173 Thurs. Nov 26, 2002 ======================================= ------------------------------------------------------------------------ Tautologies A tautology is a logical expression that is always TRUE, regardless of the assignment of truth values to the variables in the expressions. Examples of tautologies: * TRUE * TRUE OR p * p OR NOT p * NOT (p AND NOT p) * p == p * (p OR q) == p OR (NOT p AND q) * (p == q) -> (p -> q) If we can establish that "LE1 == LE2" is a tautology, then no matter what values we assign to the variables in LE1 and LE2, we know that "LE1 == LE2" has the value TRUE. If "LE1 == LE2" is a tautology, then we can substitute LE2 for LE1 (or vice versa) in any expression, without changing the value of the expression. ------------------------------------------------------------------------ The Tautology Problem It is an interesting question to ask whether a given logical expression is a tautology. This question is known as the "tautology problem." To solve the tautology problem, we need only construct the truth table for the logical expression. If the expression has the value TRUE for all possible assignment values for the variables in the expression (that is, if the entire column for the expression in the truth table is TRUE), then the expression is a tautology. Note that the truth table will have 2^k rows and n columns, where the original expression has k variables and n operators. Thus, this algorithm requires O(2^kn) time, ie. exponential time. There is no known algorithm for the tautology problem that takes less than exponential time. Such problems are called "intractable" because large instances of the these problems cannot be solved in a reasonable amount of time. Another such intractable problem is the "satisfiability problem" which asks whether there is an assignment of truth values to variables in a logical expression that makes the expression TRUE. There is no known algorithm for this problem that is more efficient than cycling through all possible combinations of truth assignments for the variables. Satisfiability is the canonical NP-complete problem. The tautology problem is believed to be harder: i.e., not in NP. (The problem is that you can't even check the correctness of a 'yes' or 'no' answer in polynomial time.) ------------------------------------------------------------------------ Algebraic Laws for Logical Expressions As with arithmetic expressions, there are algebraic laws for logical expressions that establish the equivalence of two expressions. Each of these laws can be proven by showing the equivalence is a tautology. * AND and OR are commutative p AND q == q AND p p OR q == q OR p * AND and OR are associative p AND (q AND r) == (p AND q) AND r p OR (q OR r) == (p OR q) OR r * AND is distributive over OR; OR is distributive over AND p AND (q OR r) == (p AND q) OR (p AND r) p OR (q AND r) == (p OR q) AND (p OR r) * TRUE is the identity for AND; FALSE is the identity for OR p AND TRUE == p p OR FALSE == p * FALSE annihilates AND; TRUE annihilates for OR p AND FALSE == FALSE p OR TRUE == TRUE * AND and OR are idempotent p AND p == p p OR p == p ------------------------------------------------------------------------ DeMorgan's Laws DeMorgan's Laws are algebraic laws (or equivalences) that allow us to rewrite any logical expression so that NOT is only applied to propositional variables (and not to other logical expressions). DeMorgan's Laws: 1. NOT (p AND q) == (NOT p) OR (NOT q) 2. NOT (p OR q) == (NOT p) AND (NOT q) These laws state that the negation of the conjunction (or disjunction) of two propositions is logically equivalent to the disjunction (or conjunction) of their negations. By repeated application of DeMorgan's laws, we can push the NOT operators inward in an expression until they apply to variables only. This is an important step in transforming expressions into conjunctive or disjunctive normal form. Example: NOT ((p AND q) OR (NOT p AND r)) == NOT (p AND q) AND NOT (NOT p AND r) == (NOT p OR NOT q) AND (p OR NOT r) Example: NOT (NOT p OR (q AND ( NOT(r OR NOT s) ) ) == NOT NOT p AND NOT (q AND (NOT(r OR NOT s)) == p AND (NOT q OR NOT (NOT(r OR NOT s)) == p AND (NOT q OR NOT (NOT r AND NOT NOT s) == p AND (NOT q OR (r OR NOT s) ) ------------------------------------------------------------------------ Laws of Implication * (p -> q) AND (q -> p) == (p == q) Two expressions are equivalent if they imply each other. * (p == q) -> (p -> q) If two expressions are equivalent, they imply each other. * ((p -> q) AND (q -> r)) -> (p -> r) Implies is transitive. * (p -> q) == (NOT p OR q) We can express "implies" in terms of NOT and OR. * (p1 AND p2 AND ... pn -> q) == (NOT p1 OR NOT p2 OR ... NOT pn OR q) We can express a series of implicants using NOT and OR. * (p -> q) == (NOT q -> NOT p) This equivalence is known as the contrapositive law. * ((p -> q) AND (NOT p -> q)) == q This equivalence follows from expressing implies in terms of NOT and OR: (Not p OR q) AND (p OR q) == q. ======================================================================== Reasoning with Propositional Logic We can use propositional logic to reason formally about (or construct proofs of) propositions. A deductive argument takes as given a set of premises (or hypotheses) which are known to be true and attempts to prove a conclusion valid by a sequence of steps, termed inferences. Each inference follows from the premises or a previous inference by the application of an inference rule. Given premises (or inferences) P1..Pn, we can infer expression E if P1 AND P2 AND .. Pn -> E is a tautology. * Whenever E is a tautology, P1 AND P2 AND .. Pn -> E is a tautology. * Given two premises P1 and P2, we can infer P1 AND P2. * If P1 and (P1 -> P2) are given or inferred, then we can infer P2 by the rule of *modus ponens* (p AND (p->q) -> q). * If NOT P2 and (P1 -> P2) are given or inferred, then we can infer NOT P1 by the rule of *modens tollens*. * If P1 and (P1==P2) are given or inferred, we can infer P2. ------------------------------------------------------------------------ Proving Tautologies Using Inferences Prove (p -> q) AND (NOT p -> q) == q: 1. (p -> q) AND (NOT p -> q) Given 2. (NOT p OR q) AND (NOT NOT p OR q) Rewriting -> in terms of NOT and OR 3. (NOT p OR q) AND (p OR q) Elimination of double negation 4. ((NOT p OR q) AND p) OR ((NOT p OR q) AND q) Distribute AND over OR 5. ( NOT p AND p OR q AND p) OR (NOT p AND q OR q) Distribute AND over OR 6. (q AND p) OR (NOT p AND q OR q) Eliminate p AND NOT p 7. (q AND p) OR q Subsumption 8. q Subsumption QED ------------------------------------------------------------------------ Deductive Proof If the weather is warm and the sky is clear, then either we go swimming or we go boating. It is not the case that if the sky is clear then we go swimming. Therefore, if we do not go boating, then the weather is not warm. We can rewrite this argument formally, using the following variables to correspond to each of the propositions in the argument: w = weather is warm c = sky is clear s = we go swimming b = we go boating If the weather is warm and the sky is clear, then either we go swimming or we go boating: (w AND c) -> (s OR b) It is not the case that if the sky is clear then we go swimming. NOT (c -> s) Therefore, if we do not go boating, then the weather is not warm. NOT b -> NOT w To prove the conclusion given the premises, we need to be able to infer the conclusion from the premises. 1. (w AND c) -> (s OR b) Premise 1 2. NOT (c -> s) Premise 2 3. NOT (w AND c) OR (s OR b) L1, rewriting -> 4. (NOT w OR NOT c) OR (s OR b) L3, DeMorgan's law 5. NOT (NOT c OR s) L2, rewriting -> 6. c AND NOT s L5, DeMorgan's law 7. c L6 8. NOT s L6 9. (NOT w OR b) OR (NOT c OR s) L4, assoc/comm OR 10. (NOT w OR b) OR s L7,L9, (F OR p == p) 11. NOT w OR b L8,L10, (p OR F == p) 12. w -> b L11, rewriting -> 13. NOT b -> NOT w QED L12, contrapositive law ------------------------------------------------------------------------ Finding Proofs The previous examples of proofs show how to start with a set of premises and prove a conclusion (or infer an equivalence). In proving an equivalence using inferences, we repeatedly simplify a complex logical expression until the result is the simplified expression for which equivalence is desired. In proving a conclusion from a set of premises, we repeatedly establish inferences from the premises until we are able to infer the conclusion. In each case, the process is somewhat ad hoc, with no guarantee that the simplifications we choose will lead to the desired conclusion (or equivalence) quickly. Since the best known algorithm for the tautology problem is exponential, there is no optimal algorithm for finding a proof that doesn't explore all possible simplifications (in the worst case). However, there are heuristic techniques that help direct our search for a proof in the right direction. Resolution is one such technique. ======================================================================== Resolution The idea of resolution is simple: if we know p OR q and p -> r then we can deduce q OR r Put another way: (p OR q) AND (NOT p OR r) -> q OR r This is the *Resolution Tautology*. In order to apply resolution in a proof: 1. we express our hypotheses and conclusion as a product of sums (conjunctive normal form), such as those that appear in the Resolution Tautology. 2. each maxterm in the CNF of the hypothesis becomes a clause in the proof. 3. we apply the resolution tautology to pairs of clauses, producing new clauses. 4. if we produce all the clauses of the conclusion, we have proven it. ------------------------------------------------------------------------ Creating CNF 1) get rid of all operators except AND and OR 2) use DeMorgan's laws to push NOTs inward 3) distribute to push ORs inside ANDs Example: p OR (q AND NOT(r AND (s -> t))) p OR (q AND NOT(r AND (-s OR t))) p OR (q AND (-r OR NOT(-s OR t))) p OR (q AND (-r OR (s AND -t))) (p OR q) AND (p OR (-r OR (s AND -t))) (p OR q) AND (p OR -r OR s) AND (p OR -r OR -t) ------------------------------------------------------------------------ Proof with Resolution Given the following hypotheses: 1. If it rains, Joe brings his umbrella (r -> u) 2. If Joe has an umbrella, he doesn't get wet (u -> NOT w) 3. If it doesn't rain, Joe doesn't get wet (NOT r -> NOT w) prove that Joe doesn't get wet (NOT w) We first put each hypothesis in CNF: 1. r -> u == (NOT r OR u) 2. u -> NOT w == (NOT u OR NOT w) 3. NOT r -> NOT w == (r OR NOT w) We then use resolution on the hypotheses to derive the conclusion (NOT w): 1. NOT r OR u Premise 2. NOT u OR NOT w Premise 3. r OR NOT w Premise 4. NOT r OR NOT w L1, L2, resolution 5. NOT w OR NOT w L3, L4, resolution 6. NOT w L5, idempotence 7. QED ------------------------------------------------------------------------ Proofs by Contradiction using Resolution We can combine resolution with proof by contradiction (where we assert the negation of what we wish to prove, and from that premise derive FALSE) to direct our search towards smaller and smaller clauses, with the goal of producing FALSE. This approach (working toward smaller clauses) constitutes a heuristic that helps guide us toward an efficient proof. Proof by contradiction: (NOT p -> 0) == p We use proof by contradiction to drive our search for a proof; we are looking for the smallest possible goal clause (false), so any use of equivalences or resolution that brings us to simpler expressions is working towards that goal. We can redo the previous proof (about Joe and his umbrella) using proof by contradiction with resolution: 1. NOT r OR u Premise 2. NOT u OR NOT w Premise 3. r OR NOT w Premise 4. w Negation of conclusion 5. r 3, 4 resolution 6. u 1, 5 resolution 7. NOT w 2, 6 resolution 8. FALSE 4, 7 resolution ------------------------------------------------------------------------ Proof by Resolution: Example 2 If either C173 or C108 is required, then all students will take computer science. C173 and C252 are required. Prove that all students will take computer science. We formalize the proof as follows: P1. (C173 OR C108) -> ACS P2. C173 P3. C252 Prove: ACS We then rewrite our hypotheses in conjunctive normal form: P1: (NOT C173 OR ACS) (NOT C108 OR ACS) P2: C173 P3: C252 Then we use proof by contradiction, by asserting the clauses of the premises and the negation of the conclusion, and deriving false. 1. NOT C173 OR ACS Premise 2. NOT C108 OR ACS Premise 3. C173 Premise 4. C252 Premise 5. NOT ACS Negation of conclusion 6. NOT C173 1, 5 resolution 7. FALSE 3, 6 resolution ------------------------------------------------------------------------ Proof by Resolution: Example 3 Either Heather attended the meeting or Heather was not invited. If the boss wanted Heather at the meeting, then she was invited. Heather did not attend the meeting. If the boss did not want Heather there, and the boss did not invite her there, then she is going to be fired. Prove Heather is going to be fired. 1. A OR NOT I Premise 2. NOT W OR I Premise 3. NOT A Premise 4. W OR I OR F Premise 5. NOT F Negation of conclusion 6. W OR I 4, 5 resolution 7. I 2, 6 resolution, idempotence 8. A 1, 7 resolution 9. FALSE 3, 8 resolution ------------------------------------------------------------------------ Proof by Resolution: Example 4 Either taxes are increased or if expenditures rise then the debt ceiling is raised. If taxes are increased, then the cost of collecting taxes rises. If a rise in expenditures implies that the government borrows more money, then if the debt ceiling is raised, then interest rates increase. If taxes are not increased and the cost of collecting taxes does not increase then if the debt ceiling is raised, then the government borrows more money. The cost of collecting taxes does not increase. Either interest rates do not increase or the government does not borrow more money. Prove either the debt ceiling isn't raised or expenditures don't rise. 1. T OR NOT E OR D Premise 2. NOT T OR C Premise 3. (E AND NOT G) OR NOT D OR I Premise 4. T OR C OR NOT D OR G Premise 5. NOT C Premise 6. NOT I OR NOT G Premise 7. D AND E Negation of conclusion 8. (E AND NOT G) OR I L3, L7, resolution 9. C OR NOT D OR G L2, L4, resolution 10. C OR G L7, L9, resolution 11. G L5, L10, resolution 12. NOT I L6, L11, resolution 13. E AND NOT G L8, L12, resolution 14. NOT G L13, tautology 15. FALSE L11, L14, contradiction ------------------------------------------------------------------------ Proof by Resolution: Example 5 Reprise: If the weather is warm and the sky is clear, then either we go swimming or we go boating. It is not the case that if the sky is clear then we go swimming. Prove: if we do not go boating, then the weather is not warm. w = weather is warm c = sky is clear s = we go swimming b = we go boating premise 1: (w AND c) -> (s OR b) NOT (w AND c) OR (s OR b) (NOT w OR NOT c) OR (s OR b) (NOT w OR NOT c OR s OR b) premise 2: NOT (c -> s) NOT (NOT c OR s) c AND NOT s negated conclusion: NOT (NOT b -> NOT w) NOT (b OR NOT w) NOT b AND w 1. NOT w OR NOT c OR s OR b premise 1 2. c premise 2a 3. NOT s premise 2b 4. NOT b negated conclusion 1 5. w negated conclusion 2 6. NOT w OR s OR b 1 & 2 7. NOT w OR b 6 & 3 8. NOT w 7 & 4 9. FALSE 8 & 5 ------------------------------------------------------------------------ Prolog is a programming language based on the resolution principle. It isn't a pure realization of resolution -- there is no way to express negative terms as facts (only as possibilities), and (conversely) there are ways to express things beyond even first-order predicate calculus -- but basically it works by resolution.