Slide 1

Slide 1 text

cs2102: Discrete Mathematics Class 6: Quantifiers, Program Correctness, Equivalence David Evans, Mohammad Mahmoody University of Virginia

Slide 2

Slide 2 text

Plan Finish Well-Ordering with Quantifiers Program Correctness (PS1) Validity, Satisfiability, Equivalence Negating Quantifiers Converting Formulas to DNF/CNF/3CNF SAT Solving: why satisfiability matters

Slide 3

Slide 3 text

Well-Ordering Principle Every nonempty set of non-negative integers has a smallest element. ∀ ∈ pow ℕ − ∅ .

Slide 4

Slide 4 text

Well-Ordering Principle ∀ ∈ pow ℕ − ∅ . ∃ ∈ . ∀ ∈ − . <

Slide 5

Slide 5 text

Problem Set 1

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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?

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

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 = ∀ ∈ (). ℎ , ∈ ℎ(, )

Slide 11

Slide 11 text

∀ ∈ . ¬(Test ⟹ Correct()) Test s = ∀ ∈ (). ℎ , ∈ ℎ(, ) Correct s = ∀ ∈ (). ℎ , ∈ ℎ(, ) When can testing certify a computing system is correct?

Slide 12

Slide 12 text

TicTacToe(boardstate) – Acceptable behavior is to always pick a move that is legal (when one exists) and leads to best possible outcome.

Slide 13

Slide 13 text

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()

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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 ≥ .

Slide 16

Slide 16 text

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 Coq

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Review • Validity, Satisfiability, Equivalence • Negating Quantifiers • Converting Formulas to DNF/CNF/3CNF

Slide 21

Slide 21 text

Valid Formulas A formula is valid if there is no way to make it false. → ∧ → ⇒ ( → )

Slide 22

Slide 22 text

Satisfiable Formulas A formula is satisfiable if there is some way to make it true. How to say something *is* valid using quantifiers? → ∧ → ⇒ ( → )

Slide 23

Slide 23 text

∀ , , ∈ , , → ∧ → ↔ ( → )= Two Equivalent Formulas Two formulas are equivalent, if for all true/false assignment to the variables they evaluate to equal values. How to say it using quantifiers? → ∧ → ≡ ( → )

Slide 24

Slide 24 text

Negating Universal Quantifiers • What is the negation of ∀ ∈ , () ?

Slide 25

Slide 25 text

Negating Existential Quantifiers • What is the negation of ∃ ∈ , () ? All integers

Slide 26

Slide 26 text

Proof by Contradiction vs. Counter Example • Suppose we want to prove ∀ ∈ , () is True. How prove it by contradiction? • Suppose we want to show that ∀ ∈ , () is False. What should we do?

Slide 27

Slide 27 text

Review of DNF, CNF and 3CNF

Slide 28

Slide 28 text

DNF: Disjunctive Normal Form • Disjunction (OR) of some number of conjunctive clauses. • Conjunctive clause: AND of distinct literals • Literal: a variable or its negation • Disjunction of 0 number of clauses is also a DNF, but what is it? 1 ∧ 2 ∧ ¬3 ∨ 1 ∧ ¬2 ∧ 3 ∨ ¬1 ∧ 2 ∧ ¬3 F F

Slide 29

Slide 29 text

Converting to DNF ⊕ T T F T F T F T T F F F

Slide 30

Slide 30 text

T T T T F T F T T F F T T T F T F F F T F F F F ( ∧ ) ∨ ( ∧ ¬) ∨ (¬ ∧ ) ∨ (¬ ∧ ¬)

Slide 31

Slide 31 text

CNF: Conjunctive Normal Form • Conjunction (AND) of some number of (disjunctive) clauses. • Clause: OR of distinct literals • Literal: a variable or its negation • Disjunction of 0 number of clauses is also a CNF, but what is it?

Slide 32

Slide 32 text

Converting to CNF ⊕ T T F T F T F T T F F F

Slide 33

Slide 33 text

T T T T F T F T T F F T T T F T F F F T F F F F (¬ ∨ ¬) ∧ (¬ ∨ ) ∧ ( ∨ ¬) ∧ ( ∨ )

Slide 34

Slide 34 text

Any logical formula → truth table → CNF or DNF Universality of CNF/DNF

Slide 35

Slide 35 text

Converting to 3CNF Suppose we convert CNF = ( ∨ ∨ ∨ ) Into 3CNF = ∨ ∨ ∧ (¬ ∨ ∨ ) In this case, it is easy to see that is satisfiable if and only if is satisfiable. Using quantifiers: ∃ , , , . ↔ ∃ , , , .

Slide 36

Slide 36 text

Charge • PS2 Due Friday (6:29pm) • Next week: (Mathematical) Data Types – Sets, Functions – Read MCS Chapter 4