Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1022 Computer Programming & Principles Lecture 1 Logic and Proof.

Similar presentations


Presentation on theme: "CS1022 Computer Programming & Principles Lecture 1 Logic and Proof."— Presentation transcript:

1 CS1022 Computer Programming & Principles Lecture 1 Logic and Proof

2 Plan of lecture Introduction Propositional logic Truth tables Logical equivalence Conditionals Predicate logic Relation between quantifiers 2 CS1022

3 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 CS1022

4 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 CS1022

5 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 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 CS1022

6 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 CS1022 Syntax 1 - Propositions

7 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 CS1022

8 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 CS1022

9 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 and or. – (R or (P and Q)) Syntax 4 - Examples 9 CS1022

10 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” – “Today is not Friday and Logic is not Fun” – “Logic is fun or today is not Friday” not (P or Q) ((not Q) not (and P)) Syntax 5 - Examples 10 CS1022 (not (P and Q)) ((not Q) and (not P)) ((not P) and Q) (P or (not Q))

11 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)) – ((not S) and (not U)) Syntax 6 - Examples 11 CS1022 It is not true that cat videos are silly or that you owe me £10 Cat videos are not silly and you don’t owe me £10

12 Sometimes you will also see – “  ” for “and”; “  ” for “or”; “  ” for “not” – Small letters instead of capital letters for propositions – Strings for propositions (e.g., “catsRcool”) – “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 (not (not (not P)))) – (P and (Q and (R and (S and U)))) – ((((S or P) or R) or Q) or U) Syntax 7 - Examples 12 CS1022

13 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. Semantics 1 – Truth of a Proposition 13 CS1022

14 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 Semantics 2 – Truth of Complex Statements 14 CS1022

15 The negation of P, (not P), is the opposite of the truth value of P: A conjunction of P and Q, (P and Q), is true only when both P and Q are true (and false otherwise) Semantics 3 - Truth tables not, and 15 CS1022 P(not P) TF FT PQ(P and Q) TTT TFF FTF FFF

16 A disjunction (P or Q) is false only when both P and Q are false (and true otherwise) – 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) Semantics 4 - Truth tables or 16 CS1022 PQ(P or Q) TTT TFT FTT FFF

17 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) Semantics 5 – Building Truth tables 17 CS1022

18 Truth table for ((P and Q) or (not R)): Semantics 6 – Filling in Truth tables 18 CS1022 PQR(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

19 Truth table for ((P and Q) or (not R)): Semantics 7 – Step 1 19 CS1022 PQR(P and Q)(not R)((P and Q) or (not R)) Assign T (true) or F (false) to propositions Notice: get all possible combinations Easy way: T/F, then TT/FF, then TTTT/FFFF, etc. PQR(P and Q)(not R)((P and Q) or (not R)) T F T F T F T F PQR(P and Q)(not R)((P and Q) or (not R)) TT TF FT FF TT TF FT FF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF

20 Truth table for ((P and Q) or (not R)): Semantics 8 – Step 2 20 CS1022 Compute truth value of next most complex subformulae using the truth values of the parts. PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT

21 Truth table for ((P and Q) or (not R)): Semantics 8 – Step 3 21 CS1022 Compute truth value of next most complex subformulae using the truth values of the parts. PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFFF FTFFTT FFTFFF FFFFTT

22 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 Conditionals 1 22 CS1022

23 The formula P  Q is false when – The premise P is true and – The conclusion Q is false Truth table We read “P implies Q” or “P is sufficient for Q” Works for most lines of the truth table, but some intuitive oddness. Conditionals 2 23 CS1022 PQ (P  Q) TTT TFF FTT FFT

24 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   Logical equivalence 1 24 CS1022

25 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). Logical equivalence 2 25 CS1022

26 Prove that (P or Q) and not ((not P) and (not Q)) are logically equivalent Logical equivalence 3 26 CS1022 PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TT TF FT FF PQ(P or Q) TTT TFT FTT FFF PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTF TFF FTT FFT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTF TFF FTT FFT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFF TFFT FTTF FFTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFF TFFT FTTF FFTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFF TFFTF FTTFF FFTTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFF TFFTF FTTFF FFTTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFFT TFFTFT FTTFFT FFTTTF PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFFT TFFTFT FTTFFT FFTTTF PQ(P or Q) TTT TFT FTT FFF

27 Logical equivalence 4 27 CS1022 From Rosen (2007) T represents *any* true proposition. F represents *any* false proposition.

28 Logical equivalence 5 28 CS1022 From Rosen (2007)

29 You should now know: Why logic and proof are important to computing Propositional logic: syntax and meaning How to write truth tables Logical equivalences Summary 29 CS1022

30 Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 2) Wikipedia article (http://en.wikipedia.org/wiki/Propositi onal_calculus)http://en.wikipedia.org/wiki/Propositi onal_calculus Chapter of a book (http://www.cis.upenn.edu/~cis510/tcl /chap3.pdf)http://www.cis.upenn.edu/~cis510/tcl /chap3.pdf 30 CS1022


Download ppt "CS1022 Computer Programming & Principles Lecture 1 Logic and Proof."

Similar presentations


Ads by Google