1 / 144

Computing Fundamentals 1 Lecture 3

Computing Fundamentals 1 Lecture 3. Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 3 Propositional Calculus. A Logical approach to Discrete Math By David Gries and Fred B. Schneider. Need for formalism 1. It is difficult to reason in natural language:

Download Presentation

Computing Fundamentals 1 Lecture 3

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. Computing Fundamentals 1Lecture 3 Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 3 Propositional Calculus. A Logical approach to Discrete Math By David Gries and Fred B. Schneider

  2. Need for formalism1 • It is difficult to reason in natural language: • “The sun is shinning and I feel happy”1. • Are the two facts related, do I feel happy because the sun shining? • “Roses are red and violets are blue” • Are roses red because violets are blue? • Both sentences have the same form, two facts connect with ‘and’.

  3. Need for formalism • There is no known way to formally handle all the ambiguities of English. So, we need a separate ‘logical language’ where many of the ambiguities are filtered out. • We start with propositional logic. • There are several mathematical systems (calculi) for reasoning about propositions: • Truth tables (semantic), Equational Logic (syntactic/semantic) which we use on this course, Boolean Algebra (axiomatic)1, Natural Deduction (can be used as an alternative to equational logic)

  4. Propositional Calculus • Boolean expressions can be defined: • By how they are evaluated or • By how they can be manipulated. • To help use manipulate Boolean expressions we need proofs, heuristics, and principles. • A calculus is a method or process of reasoning by calculation with symbols. • The propositional calculus uses Boolean expressions and propositional variables.

  5. Propositional Calculus • A calculus is a method of reasoning by calculating with symbols. Logic is the study of correct reasoning. Equational reasoning is a style of logic. The propositional calculus used on this course is called equational logicE. • E has two parts: • A set of axioms, • Four inference rules

  6. Propositional Calculus • The axioms are Boolean expressions that define the basic manipulative properties of the Boolean operators. For example, • p ⋁ q  q ⋁ p • Indicates that ⋁ is symmetric. • An inference rule asserts the if the premises are assumed to be truths, then the conclusion is also a truth. On the next slide are the four inference rules for E.

  7. Four Inference Rules for E • Leibniz: • Transitivity: • Substitution • Equanimity Example X+1>0 (X+1>0)[x:=3] 4 > 0

  8. CafeOBJ’s version of Equational Logic

  9. Reminder on observation & interpretation

  10. Reminder on Interpretation • Our scientific theories about the world can be expressed using mathematics and logic. The models of these theories often match the actual world. But our scientific theories can be wrong.

  11. Reminder on Interpretation • Before 1674 it was generally though that that the main source of water in rivers was from underground springs. In 1674 Pierre Perrault measured and compared rainfall and river flow. He found that the annual rainfall of part of a river catchment exceeded the annual river flow and that no underground water supply was needed to sustain the river. Other reasonable theories had been published previously (Bernard Plassy, 1580), but in general it was thought that rivers were maintained from underground sources rather than rainfall. • In this case does measurement validate Perrault theory?

  12. Reminder on Interpretation • We use the following definitions: Volume of underground source (Underground ) Volume rainfall (Rainfall) Volume flowing in river (Riverflow) • Assume that there are only two possible sources. Assume only Rainfalland RiverFlow are measured. A working assumption could be that the volume of the sum of sources is greater or equal to river flow: (Underground + Rainfall) ≥ RiverFlow • Perrault’s experiment tells us: Rainfall > RiverFlow • Would the above allow us to conclude anything about the value of Underground in this experiment?

  13. Reminder on Interpretation • Can Perrault’s experiment be used to prove that rivers are feed by rainfall only? • Can Perrault’s experiment be used to prove that the flow of a river does not depend on any underground source? • Are any of the following true? (Rainfall > RiverFlow) ⇒ (Underground < RiverFlow) (Rainfall > RiverFlow) ⇒ (Underground > RiverFlow)

  14. Theorems in E • A theorem of the prepositional calculus E is either: • An axiom • The conclusion of an inference rule whose premises are theorems • A Boolean expression, that using the rules of inference is proved to be equal to an axiom or a previously proved theorem.

  15. Proof Method in E • To prove that P  Q is a theorem (where P and Q are expressions e.g. P is say a ˅ b and Q is b ˅ a), transform P to Q or Q to P using Leibniz. • Proofs in E have the form: P < Hint for proof step 1 > R . . < Hint for proof step n > Q

  16. Helpful Hints • Focus on ‘manipulation’ rather than ‘evaluation’. These are syntactic operations that do not consider meaning. • There are many axioms and theorems, you do not have to memorise them. Details of precedence rules, theorems, axioms, etc. will be supplied for examination questions.

  17. The Axioms of equational propositional logic. • The next slide present the main axioms of equational propositional logic. The full list is at: • http://www.cs.cornell.edu/courses/cs400/2004fa/theoremsfoot.pdf • You are not expected to learn these off by heart! But you should be able to see how they are used in a proof.

  18. Note these axiom numbers differ from those in the book.

  19. Heuristics • Heuristic: (3.21) Identify an applicable theorem from table 2 by matching its structure to the given expressions or sub-expressions to be proved. The operators that appear in a Boolean expression and the shape of its sub-expressions can focus the choice of theorems, from table 2, that can be used to manipulate it. • Principle: Structure proofs to avoid repeating the same sub-expression many times.

  20. A Proof • Prove theorem: p  q  p  q p  q  p  q = <axiom(3.9,5), (p  q)  p  q> (p  q)  p  q = <axiom(3.9,3.17),with p,q:=q,p (q  p)  q  p > (p  q)  (p  q) = <(3.5,3.8) Reflexivity of  > true

  21. Heuristic (3.33) Heuristic: To prove P  Q, transform the expression with the most structure (either P or Q) into the other. To illustrate this heuristic we prove: p ˅ true  true. Start with LHS. p ⋁ true = <(3.3) Identity of  > p ⋁ (p p) = < (3.27,3.32) Distributivity of ⋁ over  > p ⋁ p p ⋁ p = <(3.3,3.7) Identity of  > true Which is the same as the RHS.

  22. Heuristic (3.23) Heuristic of definition of elimination: To prove a theorem concerning an operator  that is defined in terms of another operator , expand the definition of  to arrive at a formula that contains : exploit the properties of  to manipulate the formula and then (possibly) reintroduce  using its definition.

  23. Using a Heuristic To illustrate the heuristic (3.23) we prove (p  q) (q  p), where  is  and  is  LHS (p  q) = < (3.10) Def of  > (p  q) = <(3.2)Symmetry of  > (q  p) = < (3.10) Def of  with p,q:=q,p> (q  p) RHS

  24. Equational Proof

  25. The Golden rule1 Check that GR is an in CafeOBJ module PROPC: set trace on whole red p and q <-> p <-> q <-> p or q . • p˄q  p  q  p˅q • On one hand the Golden Rule2 can be seen as a definition of conjunction (˄) in terms of equivalence () and disjunction (˅): • (p˄q)  (p  q  p˅q) • But it can also be read in other ways, e.g. assertion of equality: • (p˄q  p) = (q  p˅q) • This can be used to define logical implication.

  26. Golden Rule definition of ˄

  27. From Roland Backhouse http://www.cs.nott.ac.uk/~rcb/

  28. The Golden rule1 • The GR can also be read as a definition of disjunction (˅) in terms of conjunction (˄) • (p˄q  p  q)  (p˅q) • This form can be useful in calculations replacing disjunctions by conjunctions. • GR can say p and q are equal iff their conjunction & disjunction are equal. • (p  q)  (p˄q  p˅q)

  29. Using Golden Rule • Since the GR is the definition of ˄, it can be used with the heuristic of Definition Elimination (3.23). The GR can be used to eliminate ˄. The next slide shows a proof of : • p ˄ (p ˅ q)  p ˄ q

  30. Using Golden Rule(*) Check that substitution is justified LHS=RHS: red (p and q) <-> (p <-> q <-> p or q) • Prove: p ˄ (p ˅ q)  p ˄ q • LHS • p ˄ (p ˅ q) = < (3.35) GR, with q:= p ˅ q> p p ˅ q p ˅p˅ q = < (3.28) Excluded Middle > p p ˅ q true˅ q = <(3.29) Zero for ˅ > p p ˅q true = < (3.3)Identity of  > p p ˅ q = < (3.32) p ˅ q  p ˅q p, with p,q:=q,p > p p ˅ q  q = < (3.35) GR> p ˄ q Which is RHS. Line 1 First Step Line 2 Using GR as definition of ‘and’,the first inference substitutes the q:=  p ˅ q in GR LHS = RHS p˄q  p  q p ˅ q (GR) p ( p ˅ q) p ˅ ( p ˅ q) Hence the ˄ gone after step 1.

  31. DeMorgan and Monoticity • 3.47(a)(b) DeMorgan: (p ˄ q) p ˅q (p ˅ q) p ˄q • 4.2 Monoticity of ˅: (p  q)  (p ˅ r  q ˅ r)

  32. Implication and Consequence • Axiom, Definition of Implication: • p  q  p ˅ q  q • Axiom, Definition of Consequence: • p  q  q  p • Rewriting Implication • p  q  p ˅ q • p  q  p ˄ q  p • Contrapositive: • p  q  q p • Negation • not(p  q)  p ˄q

  33. Implication, Converse, Inverse • Original statement: p  q • Converse: q  p • Inverse: p  q • Contrapositive: q  p • If a statement is true, the contrapositive is also logically true • If the converse is true, the inverse is also logically true.

  34. Implication, Converse, Inverse • From a given implication we get three derived implications (inverse, converse, inverse. • P -> Q (original implication) • -Q -> -P (contrapositive of original) • Q -> P (converse of original) • -P -> -Q (inverse of original) • They all obey the truth table for implication. However, the derived implications contain negations and/or are in a different order than the original implication.

  35. Implication (⇒), or (˅) • The statement (P ⇒ Q)is equivalent to (not P ˅ Q). • “If I finish this chapter then I will learn" • This is equivalent to saying, • “I do not finish this chapter or I will learn."

  36. Implication (⇒), or (˅) • The statement ((not P) ⇒ Q) is propositionally equivalent to P ˅ Q. • “If I don't finish this chapter, I'm in trouble" • This is equivalent to saying, • “I (must) finish this chapter or I'm in trouble."

  37. Negation of ⇒in terms of ⋀ • The negation of an implication is an and statement: • not(p implies q) = (p and not q) • ~(p -> q) <-> (p & ~q) • Example: “if I hit my thumb with a hammer, then my thumb will hurt” The negation is: “I hit my thumb with a hammer and my thumb does not hurt.”

  38. Truth Table for Contrapositive p  q  q p Note p and q are swapped In General statement: if p then q converse: if q then p inverse: if not p then not q contrapositive: if not q then not p

  39. Truth Table for Implication P is stronger than Q In General statement: if p then q converse: if q then p inverse: if not p then not q contrapositive: if not q then not p Q is weaker than P. When  is true then Q is true in more than cases P.

  40. Weakening & Strengthening • Suppose P  Q. Then we say that P is stronger than Q and Q is weaker than P. This because Q is true in more (or at least the same) states than P. P imposes more restrictions on a state. The strongest formula is false (true in fewer case) and the weakest is true (true in more case). • The following theorems are called weakening or strengthen depending on whether it is used to transform the antecedent into the consequent, thus weakening it, or transform the consequent into the antecedent, thus strengthening it.

  41. Weakening & Strengthening • p  p (starting with) • p  p ˅ q (weaken RHS) • p ˄ q  p (strengthen LHS) • p ˄ q  p ˅ q (strg/weak) • p ˅ (q ˄ r)  (p ˅ q) • (p ˄ q)  p ˅ (q ˄ r)

  42. Modus ponens • Modus ponens. • p ˄ (p  q)  q • In many propositional calculi MP is a major inference rule. It is somewhat less important in E where the emphasis is on equational reasoning.

  43. Heuristic (3.33) Heuristic: To prove P  Q, transform the expression with the most structure (either P or Q) into the other. (3.34)Principle: Structure proofs to minimize the number of rabbits pulled out of the hat – make each step seem obvious, based on the structure of the expression and the goal of the manipulation. (3.54)Principle: Lemmas (small proofs) can provide structure, bring to light interesting facts, and should shorten proofs.

  44. Implication • Is the following valid? i.e. true in all states. • x > 2  x > 0 • What about when x is 0? • What about when x is 1? • Can we use a truth table?

  45. Definition of implication 3.60 • (3.60) p  q ≡ p ˄ q ≡ p • Use TTG • (p⇒q) ⇔ (p ˅ q) ⇔ p p q Result is a tautology F F T T F T F T T T T T

  46. Definition of implication 3.60 Equivalence is associative and has the lowest precedence. If we evaluate the first line left to right we get (T  F)  F , which gives true If we evaluate the first line right to left we get T  (F  F) , which gives true The two evaluations are the same which demonstrated the associative property.

  47. Proof Implication Theorem • Prove: p  (q  r)  p˄q  p˄r • Start with LHS p  (q  r) = < Def of Implication (3.60) > p ˄ (q  r)  p = <(3.49)relates and equivalence > p ˄ q  p ˄ r • Which gives us RHS. • Prove this by truth table

  48. Abbreviation for proving implication • This abbreviation allows us to use  as well as = in proof steps • Given (pq)and (q  r) • We show (p  r) holds. • ------------------------------- We want to prove (p  q)˄ (q  r)  (p  r) = <Why? p  q  true> true ˄ (q  r)  (p  r) = <Why? q  r  true> true ˄ true (p  r) = < (3.38 and 3.73) > p  r (LHS true gives RHS) 3.38 idempotency of ˄ : p ˄ p  p 3.73 left identity of  : true  p  p

  49. Abbreviation for proving implication • Previously, we only used = in the proof steps, now we can use . • A shorter proof of previous slide, given: • (pq)and (q  r) • We prove that (p  r) holds. p = <Why? pq> q  <Why? q  r > r • Note we use in the second proof step.

More Related