Share
Embed
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
Transcript
49 slides
-
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) -
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? -
Conjunctive Normal Form Can we write any logical formula in
CNF? A ∧ B A ⇒ B -
Logical Formula to Truth Table Can we convert any logical
formula to a truth table? -
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 -
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 -
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) -
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) -
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). -
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) -
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: -
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: -
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: -
(A ∨ B ∨ C ∨ D ∨ E) Convert
clause with five (or more) literals to 3CNF: -
Any logical formula → truth table → CNF → 3CNF
Universality of 3CNF -
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). -
(A ∨ B ∨ C ∨ D) Convert clause with
four literals to 2CNF? -
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.” -
Logical Formula “Proofs can certify that a computing system will
always behave correctly, something that no amount of testing can do.” -
Well-Ordering Principle Every nonempty set of non-negative integers has a
smallest element. Can we express this using a quantified logical formula? -
Well-Ordering Principle Every nonempty set of non-negative integers has a
smallest element. ∀ ∈ pow ℕ − ∅ . -
Well-Ordering Principle ∀ ∈ pow ℕ − ∅ . ∃
∈ . ∀ ∈ − . < -
Certifying Computing Systems “Proofs can certify that a computing system
will always behave correctly, something that no amount of testing can do.” -
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? -
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 = ∀ ∈ (). ℎ , ∈ ℎ(, ) -
∀ ∈ . ¬(Test ⟹ Correct()) Test s = ∀
∈ (). ℎ , ∈ ℎ(, ) Correct s = ∀ ∈ (). ℎ , ∈ ℎ(, ) When can testing certify a computing system? -
TicTacToe(boardstate) – Acceptable behavior is to always pick a move
that is legal (when one exists) and leads to best possible outcome. -
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() -
Proving Programs Correct def max(a, b): “Returns maximum of a
and b” How should we define AcceptableBehaviors(max, x)? -
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 ≥ . -
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 -
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 -
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 ≥ -
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 -
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() -
def max(a, b): if a > b: result = a
… Idealized Computing Systems ∧ a > b result = a result ∈ , , result ≥ -
Real Computing Systems def max(a, b): if a > b:
result = a … Idealized Computing Systems ∧ a > b result = a result ∈ , , result ≥ -
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