Lecture 3 Logic and Proof Plan of lecture






























- Slides: 30
Lecture 3 Logic and Proof
Plan of lecture • • Introduction Propositional logic Truth tables Logical equivalence Conditionals Predicate logic Relation between quantifiers 2
Introduction Logic • Essential in formal disciplines (science) • Consists of rules for drawing inferences • Does not depend on any specific topic • Provides a suitable tool for reasoning – Propositional logic – simple statements and their truth – Predicate logic – statements with variables Proof • Means to convince someone (us!) about something • Systematic arguments (template and strategies) 3
Why logic is important to Computing • Provides a way to precisely and clearly state what is being reasoned about, e. g. propositions in simple and complex forms, properties, relations, quantifiers. . • Helps us understand how the meaning of complex expressions can be understood in terms of the meaning of the basic parts and their construction • Enables reasoning in a systematic fashion over long chains for inferences • Useful for proving general properties of a program specification. • Different "logics" for different reasoning issues, e. g. static (no time), dynamic (change), modal (possibilities), . . • Important level of abstraction 4
Why logic is important to Computing • If-then-else constructs: if CONDITION then STATEMENT – CONDITION can be true or false – STATEMENT depends on CONDITION • Logic studies when truth/falsity of a statement can be inferred • Example: – if (A > 20 and B < 34) or (A > 20 and B > 50) then STATEMENT • If we know how operators and, or, etc. combine basic propositions into larger propositions, and if we know what is the case, then we can determine if the STATEMENT follows. 5
Syntax 1 - Propositions • Building blocks of formal logic: propositions – Propositions are statements – (later about truth/falsity) – Examples: – “It is sunny now” – “There are 35 students here” – “This slide has a flying pig” – “It is too far to walk to the city centre” • To save us writing, we will abbreviate statements: – “It is sunny now” abbreviated as “S” – “There are 35 students here” abbreviated as “L” – “This slide has a flying pig” abbreviated as “P” 6
Syntax 2 - Connectives • Building blocks of formal logic: connectives • Construct complex statements from simpler ones: – (not S) – it is not sunny now (Language v Logic) – (S or P) – it is sunny now or this slide has a flying pig – (P and L) – this slide has a flying pig and there are 35 students here – (conditional later) • We are not concerned (at this point) with the internal content or structure of the propositions. We see and understand a sentence "it is not sunny now", but the logic just sees (not S). 7
Syntax 3 – Syntax Definition • General (recursive) definition for statements – All proposition letters (P, Q, R, S, etc. ) are statements – If α and β are statements then • • (not α) is a statement (and so is (not β)) (α or β) is a statement (α and β) is a statement (conditional later) 8
Syntax 4 - Examples • Suppose we have propositions letters P, Q, R • We can create the following statements – (P and Q) – ((Q and P) or R) – (not (Q and (P or R))) • These are not propositional statements (why? ) – P (not and Q R) – (or P not Q (and R)) • We might drop outermost brackets • Order doesn't matter for and or. – (R or (P and Q)) 9
Syntax 5 - Examples • Suppose – P stands for “logic is fun” – Q stands for “today is Friday” • Express in propositional logic – “Logic is not fun and today is Friday” (not ((not(P P)and and. Q)) Q) – “Today is not Friday and Logic is not Fun” ((not Q) Q) not and(and (not P)) – “Logic is fun or today is not Friday” (P not or(P (not or Q)) Q) 10
Syntax 6 - Examples • Suppose – S stands for “Cat videos are silly” – U stands for “You owe me £ 10” • What does each propositional statement mean: – (not (S or U)) It is not true that cat videos are silly or that you owe me £ 10 – ((not S) and (not U)) Cat videos are not silly and you don’t owe me £ 10 11
Syntax 7 - Examples • Sometimes you will also see – “ ” for “and”; “ ” for “or”; “ ” for “not” – Small letters instead of capital letters for propositions – Strings for propositions (e. g. , “cats. Rcool”) – “Compound proposition” or “formulae” for statements – Propositional “variables” for propositional “letters” • They are “variables” because they can vary over the propositional letters • Question: are the following statements OK? – (not P)))) – (P and (Q and (R and (S and U)))) – ((((S or P) or R) or Q) or U) 12
Semantics 1 – Truth of a Proposition • Not concerned with the "meaning" of a proposition other than whether it is true or false. Not about "how" we know it is true or false, but supposing it is, what else do we know. Abstraction. • The "truth" of a proposition determined "by inspection" – The book is on the table. The "real" world. • The "truth" determined by "stipulation"- suppose The book is on the table is true. Not the "real" world. • Mostly we are not concerned with the internal content or the "real" world, and we stipulate truth of a proposition. The truth value of P is true/false. 13
Semantics 2 – Truth of Complex Statements • Given the truth value of the individual propositions, we can systematically compute the truth value of complex statements. • This shows us what we "know" about the meaning of the connectives. • Truth tables: – Represent the effect of logical operators • Next slides show truth tables for operators • Each line represents a different circumstance 14
Semantics 3 - Truth tables not, and • The negation of P, (not P), is the opposite of the truth value of P: P (not P) T F F T • A conjunction of P and Q, (P and Q), is true only when both P and Q are true (and false otherwise) P T T F F Q T F (P and Q) T F F F 15
Semantics 4 - Truth tables or • A disjunction (P or Q) is false only when both P and Q are false (and true otherwise) P T T F F Q T F (P or Q) T T T F – Meaning (P or Q) is true where either P is true, or Q is true, or both are true (inclusive or) – Does not mean (P or Q) is true where either P is true or Q is true, but not both are true (exclusive or) 16
Semantics 5 – Building Truth tables • How to build truth tables? • Given propositions P, Q, R, S, . . . , we do: 1. Get all possible combinations of T (true) and F (false) for the propositions 2. Break down the formula into smaller sub-formulae 3. Combine truth-values of sub-formulae using the truth tables, and combine until final value is computed • General strategy – Analyse a complex statement by breaking it down to fundamental parts (propositions and connectives) and basic meanings (truth values of propositions and connectives) 17
Semantics 6 – Filling in Truth tables • Truth table for ((P and Q) or (not R)): P Q R (P and Q) (not R) ((P and Q) or (not R)) • Left-most columns are single/individual propositions • Break-down of formulae to the right of propositions • Right-most column is the formula we are dealing with 18
Semantics 7 – Step 1 • Truth table for ((P and Q) or (not R)): P T T F F Q R (P and Q) (not R) ((P and Q) or (not R)) T T T F F • Assign T (true) or F (false) to propositions • Notice: get all possible combinations • Easy way: T/F, then TT/FF, then TTTT/FFFF, etc. 19
Semantics 8 – Step 2 • Truth table for ((P and Q) or (not R)): P T T F F Q T T F F R (P and Q) (not R) T T F F T T T F F F F T T F F T ((P and Q) or (not R)) T T F T • Compute truth value of next most complex subformulae using the truth values of the parts. 20
Semantics 8 – Step 3 • Truth table for ((P and Q) or (not R)): P T T F F Q T T F F R (P and Q) (not R) T T F F T T T F F F F T T F F T ((P and Q) or (not R)) T T F T F T • Compute truth value of next most complex subformulae using the truth values of the parts. 21
Conditionals 1 • A logical operator for conditionals – if today is Friday then I am wearing a green shirt – if P then Q – P Q • Add to the earlier Definition: (α β) is a statement • Factual vs. logical truth – If we accept that the conditional is true P Q and that P (the premise) is true, then it follows logically that Q (the conclusion) is also true – Accept: if today is Friday then I am wearing a green shirt – Accept: Today is Friday – Infer: I am wearing a green shirt 22
Conditionals 2 • The formula P Q is false when – The premise P is true and – The conclusion Q is false • Truth table P T T F F Q T F (P Q) T F T T • We read “P implies Q” or “P is sufficient for Q” • Works for most lines of the truth table, but some intuitive oddness. 23
Logical equivalence 1 • Two formulae with same propositions may have the same final truth value, for any truth values of the propositions (or can prove each entails the other) – Suppose propositions P and Q – We can build formulae • (P or Q) • not ((not P) and (not Q)) • Such formulae are logically equivalent; they "mean" the same thing. – We represent two logically equivalent formulae and as 24
Logical equivalence 2 • We can prove that two formulae α and β are logically equivalent via truth-tables: – Build a truth table for α and another truth table for β – Compare their final columns; if they are equal then they are equivalent – You must use the truth values of the propositions exactly in the same order, that is, if a proposition is true/false in one formula, it is true/false in the other – Moral is: two formulae may appear different, yet they "mean" the same thing. – Issues about meaning the same thing (morning star and evening star). 25
Logical equivalence 3 • Prove that (P or Q) and not ((not P) and (not Q)) are logically equivalent P T T F F Q T F (P or Q) T T T F Q not P not Q (not P) and (not Q) T F F F T T T not ((not P) and (not Q)) T T T F 26
Logical equivalence 4 From Rosen (2007) T represents *any* true proposition. F represents *any* false proposition. 27
Logical equivalence 5 From Rosen (2007) 28
Summary You should now know: • Why logic and proof are important to computing • Propositional logic: syntax and meaning • How to write truth tables • Logical equivalences 29
Further reading • R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 2) • Wikipedia article (http: //en. wikipedia. org/wiki/Propositi onal_calculus) • Chapter of a book (http: //www. cis. upenn. edu/~cis 510/tc l/chap 3. pdf) 30