comp 2600 formal methods for software engineeing
play

COMP 2600: Formal Methods for Software Engineeing Dirk Pattinson - PowerPoint PPT Presentation

COMP 2600: Formal Methods for Software Engineeing Dirk Pattinson Australian National University Semester 2, 2013 Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 1 / 24 What do we mean by FORMAL ? Oxford Dictionary in accordance with


  1. COMP 2600: Formal Methods for Software Engineeing Dirk Pattinson Australian National University Semester 2, 2013 Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 1 / 24

  2. What do we mean by FORMAL ? Oxford Dictionary ▸ in accordance with convention or etiquette ▸ or denoting a style of writing or public speaking characterized by more elaborate grammatical structures and more conservative and technical vocabulary. ▸ officially sanctioned or recognized ▸ of or concerned with outward form or appearance as distinct from content The validity of logical arguments depends on form , rather than content . 1. Abstracting content allows us to study the mechanics of reasoning 2. We have more confidence in formalised arguments 3. Automation requires formalisation. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 2 / 24

  3. Topics in COMP 2600 ▸ Logic and Natural Deduction ▸ Proving Properties of Functional Programs (Induction) ▸ Proving Properties of Imperative Programs ▸ Formal Specification of Systems ▸ Automata, Languages and Parsing ▸ Turing Machines and Computability Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 3 / 24

  4. Assessment Assignments: 4 × 9% ▸ One for each major topic, released in weeks 5, 7, 9 and 12 Tutorials: 4% ▸ demonstrate a reasonable attempt at the tutorial questions Mid-Semester Quiz: 10% ▸ redeemable: replaced by exam mark if better, covers weeks 2 – 6 Final Exam: 50% ▸ or 60% if quiz not attempted or quiz score < exam score Final Mark ▸ capped at Exam * (100/60) + 10% Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 4 / 24

  5. Boring Administrative Stuff Tutorials Register for a tutorial in Streams. Tutorials start in week 3. Use the Course Web Page ▸ Textbooks ▸ Tentative Schedule ▸ Forum ▸ Lecture Notes Course Web Page: http://cs.anu.edu.au/Student/comp2600/ Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 5 / 24

  6. History of Logic, the Science of Reasoning ▸ Aristotle: syllogistic logic logic. ▸ Leibniz: symbolic logic ▸ Boole: algebraic logic (boolean algebras) algebra. ▸ Russel: logic as foundation of mathematics logic. ▸ Later: Church, Turing, Curry, Goedel, Scott, Milner etc.: Formal models of computational systems Aristotle Leibniz Boole Russel (384–322BC) (1646– 1716) (1815 – 1884) (1872 – 1970) Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 6 / 24

  7. Why study logic? Coolness: Logic is cool — trust me. Hardware: Binary logic is logical. Software: Programming languages have logical constructs. Semantics: The language of logic is unambiguous and can be used to give meaning to programs. Proof: Arguments should be logical. Every day: Clearer thinking in every day situations. More effective communication. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 7 / 24

  8. Propositions: Basic Building Blocks Definition A statement is a sentence for which it makes sense to ask whether it is true or false. A proposition is a statement that does not depend on any variables. Example ▸ John had tea for breakfast. ▸ x 2 > 12 ▸ Every integer > 2 is the sum of two primes (Goldbach’s conjecture) We often use variables p , q , r to denote propositions (‘atomic propositions’ or ‘propositional variables’). Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 8 / 24

  9. Logical Connectives Operators on Statements ∧ conjunction, and ¬ negation, not ∨ disjunction, or ↔ , equivalence, if and only if → implication, if . . . then . . . ⊺ , � true, false Definition Propositional Formulae are built from a set of atomic propositions using the logical connectives. Example If p , q and ‘John had toast for breakfast’ and ’John is hungry’ are atomic propositions, then ▸ p → (¬ q ∨ ( p ↔ ⊺)) → ( p ∧ q ) ∨ r ▸ ’John had toast for breakfast’ → ’John is hungry’ are propositional formulae. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 9 / 24

  10. Precedences and Meaning Precedences Operator priorities (‘strength of binding’) to minimise parentheses ¬ ≻ ∧ ≻ ∨ ≻ → ≻ ↔ where ≻ stands for ‘binds more strongly’ or ‘has higher precedence’. Example ¬ p ∨ q → r ∧ s ≡ ( (¬ p ) ∨ q ) → ( r ∧ s ) p ∨ q ∧ r ≡ p ∨ ( q ∧ r ) Meaning of Connectives: Truth Tables p ∧ q p q ⊺ ⊺ ⊺ ⊺ � � � ⊺ � � � � (and similarly for other connectives) Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 10 / 24

  11. Tautologies Definition A propositional formula is said to be a tautology if it is true for all possible assignments of truth values to its atomic propositions. Example ¬ p p ∨ ¬ p p ⊺ � ⊺ � ⊺ ⊺ In general, to prove a tautology, one can construct a truth table for the proposition and checks that its column is all ⊺ s. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 11 / 24

  12. Contradictions and Contingencies Definition A contradiction is a compound proposition which evaluates to � for all values of its elementary propositions. A contingency is a compound proposition which may evaluate to ⊺ or � for different values of its elementary propositions. Example 1. ’John had toast for breakfast’ is a contingency. 2. ’John had toast for breakfast’ ∧¬ ’John had toast for breakfast’ is a contradiction 3. p → (¬ q ∨ ( p ↔ ⊺)) → ( p ∧ q ) ∨ r – can be complicated! Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 12 / 24

  13. (Algebraic) Laws of Propositional Calculus Associative laws ▸ p ∨ ( q ∨ r ) ≡ ( p ∨ q ) ∨ r ▸ p ∧ ( q ∧ r ) ≡ ( p ∧ q ) ∧ r Distributive laws ▸ p ∧ ( q ∨ r ) ≡ ( p ∧ q ) ∨ ( p ∧ r ) ▸ p ∨ ( q ∧ r ) ≡ ( p ∨ q ) ∧ ( p ∨ r ) (These are just a representative few. Replacing ≡ by ↔ they are all tautologies.) Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 13 / 24

  14. Logical Arguments, or: Formal Proofs Example: Arguments in English ▸ If the professor is naked then the class is amused. ▸ If the class is amused and the material is organized then the class is happy. ▸ The lecture is good if both the material is organized and the class is happy. ▸ Therefore, the lecture is good if the professor is naked. Typical Structure ▸ the assumptions appear above the horizontal line ▸ the conclusions appear below. (Is this a valid argument?) Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 14 / 24

  15. Exercise: Reconstruct the Argument in Logic ▸ identify the atomic propositions, or variables ▸ translate assumptions and conclusions into logical form For Example Propositions n – naked, a – amused, o – organised, h – happy, g – good Translation ▸ If the professor is naked then the class is amused: n → a ▸ If the class is amused and the material is organised, then the class is happy: a ∧ o → h ▸ . . . In Logical Form As a single formula: n → a a ∧ o → h ( n → a ) ∧ ( a ∧ o → h ) o ∧ h → g ∧ ( o ∧ h → g ) → ( n → g ) n → g Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 15 / 24

  16. Disjunctive Syllogism — An inference rule Definition An inference rule is a blueprint for a valid argument. Its propositions are variables, and applying an inference rule amounts to providing formulae for the variables. Disjunctive Syllogism One of Aristotle’ patterns of valid deduction: p ∨ q ¬ p q Example The student was happy ∨ The student was awake ¬ The student was happy The student was awake Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 16 / 24

  17. Disjunctive Syllogism — Proof in the Algebraic Style ( p ∨ q ) ∧ ¬ p → q ≡ ¬ p ∧ ( p ∨ q ) → q (commutativity) ≡ (¬ p ∧ p ) ∨ (¬ p ∧ q ) → q (distribution) ≡ � ∨ (¬ p ∧ q ) → q (contradiction) ≡ ¬ p ∧ q → q (or-simplification) ≡ ¬(¬ p ∧ q ) ∨ q (implication) ≡ ( p ∨ ¬ q ) ∨ q (De Morgan) ≡ p ∨ (¬ q ∨ q ) (associativity) ≡ p ∨ ⊺ (excluded middle) ≡ ⊺ (or-simplification) Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 17 / 24

  18. A non-example ‘Or’ in logic In natural language, ’or’ is almost always exclusive. ▸ ‘Do you want to have chips or peas with your dinner?’ ▸ ‘The car was grey or green’ In logic, ’or’ is always inclusive – see the truth table. Non-Example The student was happy ∨ The student was awake The student was happy ¬ The student was awake This “reasoning” is INVALID. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 18 / 24

  19. Modus ponens — Inference rule Modus Ponens: the most important rule p → q p q Example The student worked hard → The student passed The student worked hard The student passed Non-Example The student worked hard → The student passed The student passed The student worked hard This “reasoning” is INVALID. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 19 / 24

  20. Limitations of propositional logic Is this argument valid? useful? Natural language Propositional logic All COMP2600 students are happy. p Lisa is a COMP2600 student. q Therefore, Lisa is happy. ∴ r Maybe – but not in propositional logic! Not a valid in terms of propositional logic, since p ∧ q → r is not a tautology. (No relationship between the propositions.) Problem The identity of Lisa is not maintained through the propositions. In other words, the propositions don’t take arguments. Dirk Pattinson (ANU) COMP 2600 Semester 2, 2013 20 / 24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend