Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 5: CNF, Quantifiers, Proofs about Software

David Evans
September 06, 2016
4.4k

Class 5: CNF, Quantifiers, Proofs about Software

cs2102: Discrete Mathematics
University of Virginia, Fall 2016

See course site for notes:
https://uvacs2102.github.io

David Evans

September 06, 2016
Tweet

Transcript

  1. Plan Review: Logic Formulas, Valid, Satisfiable Conjunctive Normal Form, 3CNF

    PS1: Problems 1 and 2 This week’s goal: understand the SAT problem (3.5), and why it is so significant. (graded PS1s should be returned by tomorrow)
  2. A formula is valid if there is no way to

    make it false. A formula is satisfiable if there is some way to make it true. If NOT(X) is valid, what does that mean about X?
  3. Logical Formula to Truth Table How big is the table?

    a1 a2 a3 … an Result T T T … T T T T … F … … … … … … … … F F F … T F F F … F
  4. Truth Table to Disjunctive Normal Form Disjunctive normal form: OR

    of clauses, each clause is AND of literals. a1 a2 a3 … an Result T T T … T T T T … F … … … … … … … … F F F … T F F F … F
  5. Truth Table to Disjunctive Normal Form a1 a2 a3 …

    an Result T T T … T T T T … F … … … … … … … … F F F … T F F F … F clauses = Set() # empty is False for each row in table: if result(row): clauses.add(row as conjunt clause)
  6. Truth Table to Conjunctive Normal Form a1 a2 a3 …

    an Result T T T … T T T T … F … … … … … … … … F F F … T F F F … F clauses = Set() for each row in table: if not result(row): clauses.add(row as disjunctive clause)
  7. 3CNF Definition. A logical formula that is written as a

    conjunction of clauses, where each clause is a disjunction of exactly three literals, and each literal is either a variable or a negation of a variable, is in three- conjunctive normal form (3CNF).
  8. 3CNF Definition. A logical formula that is written as a

    conjunction of clauses, where each clause is a disjunction of exactly three literals, and each literal is either a variable or a negation of a variable, is in three- conjunctive normal form (3CNF). (A ∨ B ∨ ¬C) ∧ (A ∨ B ∨ C) ∧ (¬A ∨ ¬B ∨ C)
  9. Definition. A logical formula that is written as a conjunction

    of clauses, where each clause is a disjunction of exactly three literals, and each literal is either a variable or a negation of a variable, is in three- conjunctive normal form (3CNF). (A ∨ B) Convert clause with two literals to 3CNF:
  10. Definition. A logical formula that is written as a conjunction

    of clauses, where each clause is a disjunction of exactly three literals, and each literal is either a variable or a negation of a variable, is in three- conjunctive normal form (3CNF). (A) Convert clause with one literal to 3CNF:
  11. Definition. A logical formula that is written as a conjunction

    of clauses, where each clause is a disjunction of exactly three literals, and each literal is either a variable or a negation of a variable, is in three- conjunctive normal form (3CNF). (A ∨ B ∨ C ∨ D) Convert clause with four literals to 3CNF:
  12. (A ∨ B ∨ C ∨ D ∨ E) Convert

    clause with five (or more) literals to 3CNF:
  13. Can any logical formula be converted to 2CNF? (Slack break…)

    Definition. A logical formula that is written as a conjunction of clauses, where each clause is a disjunction of exactly two literals, and each literal is either a variable or a negation of a variable, is in two- conjunctive normal form (2CNF).
  14. Disambiguating the English “Proofs also play a growing role in

    computer science; they are used to certify that software and hardware will always behave correctly, something that no amount of testing can do.” “Proofs can certify that a computing system will always behave correctly, something that no amount of testing can do.”
  15. Logical Formula “Proofs can certify that a computing system will

    always behave correctly, something that no amount of testing can do.”
  16. Well-Ordering Principle Every nonempty set of non-negative integers has a

    smallest element. Can we express this using a quantified logical formula?
  17. Certifying Computing Systems “Proofs can certify that a computing system

    will always behave correctly, something that no amount of testing can do.”
  18. Certifying Computing Systems “Proofs can certify that a computing system

    will always behave correctly, something that no amount of testing can do.” ∀ ∈ . ¬(Test ⟹ Correct()) What does it mean to test a computing system?
  19. Certifying Computing Systems “Proofs can certify that a computing system

    will always behave correctly, something that no amount of testing can do.” ∀ ∈ . ¬(Test ⟹ Correct()) Test s = ∀ ∈ (). ℎ , ∈ ℎ(, ) Correct s = ∀ ∈ (). ℎ , ∈ ℎ(, )
  20. ∀ ∈ . ¬(Test ⟹ Correct()) Test s = ∀

    ∈ (). ℎ , ∈ ℎ(, ) Correct s = ∀ ∈ (). ℎ , ∈ ℎ(, ) When can testing certify a computing system?
  21. TicTacToe(boardstate) – Acceptable behavior is to always pick a move

    that is legal (when one exists) and leads to best possible outcome.
  22. Proofs about Computing Systems “Proofs can certify that a computing

    system will always behave correctly, something that no amount of testing can do.” ∀ ∈ . ∃ ∈ . ⟹ Correct() ∃ ∈ . ∃ ∈ . ⟹ Correct()
  23. Proving Programs Correct def max(a, b): “Returns maximum of a

    and b” How should we define AcceptableBehaviors(max, x)?
  24. Proving Programs Correct def max(a, b): “Returns maximum of a

    and b” AcceptableBehaviors(max, x = (a, b)): result = max , no other state modified result ∈ , ∧ result ≥ ∧ result ≥ .
  25. Proving Programs Correct AcceptableBehaviors(max, x = (a, b)): result =

    max , no other state modified result ∈ , ∧ result ≥ ∧ result ≥ . def max(a, b): if a > b: result = a else: result = b return result
  26. def max(a, b): if a > b: result = a

    else: result = b return result AcceptableBehaviors(max, x = (a, b)): result ≡ max , no other state modified result ∈ , ∧ result ≥ ∧ result ≥ . Hoare triple for if statement: ∧ 1 , ∧ ¬ 2 if then 1 else 2
  27. def max(a, b): if a > b: result = a

    else: result = b return result AcceptableBehaviors(max, x = (a, b)): result ≡ max , no other state modified result ∈ , ∧ result ≥ ∧ result ≥ . Hoare triple for if statement: ∧ 1 , ∧ ¬ 2 if then 1 else 2 P = True = result ∈ , ∧ result ≥ ∧ result ≥
  28. def max(a, b): if a > b: result = a

    else: result = b return result Hoare triple for if statement: ∧ 1 , ∧ ¬ 2 if then 1 else 2 P = True = result ∈ , ∧ result ≥ ∧ result ≥ ∧ a > b result = a
  29. def max(a, b): if a > b: result = a

    else: result = b return result AcceptableBehaviors(max, x = (a, b)): result ≡ max , no other state modified result ∈ , ∧ result ≥ ∧ result ≥ . ∃ ∈ . ⟹ Correct()
  30. def max(a, b): if a > b: result = a

    … Idealized Computing Systems ∧ a > b result = a result ∈ , , result ≥
  31. Real Computing Systems def max(a, b): if a > b:

    result = a … Idealized Computing Systems ∧ a > b result = a result ∈ , , result ≥
  32. Charge • Add date is today: make sure you are

    enrolled (or bring me a course action to sign now!) • Be paranoid: assumptions about computing systems are not true in practice • Thursday: how hard is it to determine if a 3CNF can be satisfied (and why we care) Due Friday (6:29pm): PS2