1 / 30

CS1022 Computer Programming & Principles

CS1022 Computer Programming & Principles. Lecture 2.1 Logic and Proof. Plan of lecture. Introduction Propositional logic Truth tables Logical equivalence Conditionals Predicate logic Relation between quantifiers. Introduction. Logic Essential in formal disciplines (science)

lexiss
Download Presentation

CS1022 Computer Programming & Principles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1022Computer Programming & Principles Lecture 2.1 Logic and Proof

  2. Plan of lecture • Introduction • Propositional logic • Truth tables • Logical equivalence • Conditionals • Predicate logic • Relation between quantifiers 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) 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 CS1022

  5. Why logic is important to Computing • If-then-else constructs: ifCONDITIONthenSTATEMENT • CONDITION can be true or false • STATEMENTdepends 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) thenSTATEMENT • 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. CS1022

  6. 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” CS1022

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

  9. 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 (notand 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)) CS1022

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

  11. 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)) • ((not S) and (not U)) 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 CS1022

  12. 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., “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) CS1022

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

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

  15. Semantics 3 - Truth tables not, and • 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) CS1022

  16. Semantics 4 - Truth tables or • 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) CS1022

  17. Semantics 5 – Building Truth tables • How to build truth tables? • Given propositions P, Q, R, S,..., we do: • Get all possible combinations of T (true) and F (false) for the propositions • Break down the formula into smaller sub-formulae • 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) CS1022

  18. Semantics 6 – Filling in Truth tables • Truth table for ((P and Q) or (not R)): • Left-most columns are single/individualpropositions • Break-down of formulae to the right of propositions • Right-most column is the formula we are dealing with CS1022

  19. Semantics 7 – Step 1 • Truth table for ((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. CS1022

  20. Semantics 8 – Step 2 • Truth table for ((P and Q) or (not R)): • Compute truth value of next most complex subformulae using the truth values of the parts. CS1022

  21. Semantics 8 – Step 3 • Truth table for ((P and Q) or (not R)): • Compute truth value of next most complex subformulae using the truth values of the parts. CS1022

  22. Conditionals 1 • A logical operator for conditionals • iftoday is Friday thenI am wearing a green shirt • ifPthenQ • PQ • Add to the earlier Definition: (αβ) is a statement • Factual vs. logical truth • If we accept that the conditional is true PQand that P(the premise) is true, then it follows logically that Q(the conclusion) is also true • Accept: iftoday is Friday thenI am wearing a green shirt • Accept: Today is Friday • Infer: I am wearing a green shirt CS1022

  23. Conditionals 2 • The formula PQ is false when • The premise P is true and • The conclusionQ 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. CS1022

  24. 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 •   CS1022

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

  26. Logical equivalence 3 • Prove that (P or Q) and not ((not P) and (not Q)) are logically equivalent CS1022

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

  28. Logical equivalence 5 From Rosen (2007) CS1022

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

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

More Related