Slide 1

Slide 1 text

cs2102: Discrete Mathematics Class 21: Review David Evans, Mohammad Mahmoody University of Virginia

Slide 2

Slide 2 text

Plan Today: review! • State Machine and Invariance  Program correctness and Termination • Recursive Defenitions  Structural Induction • Infinite Sets and Cardinalities

Slide 3

Slide 3 text

State Machine and Invariants • State Machine: M = , ⊆ × , 0 ∈ • is a preserved invariant if ∀ ∈ . ∧ ( → ) ∈ ⟹ () • Invariant Principle: If is preserved invariant and (0 ) is true  it is true for all reachable states.

Slide 4

Slide 4 text

State Machine and Invariants

Slide 5

Slide 5 text

State Machine and Invariants

Slide 6

Slide 6 text

State Machine and Invariants

Slide 7

Slide 7 text

Program Correctness • To prove a program P outputs “correctly” : 1. Model it as a state machine M 2. Show it eventually terminates 3. Show partial correctness (if it ends  it is correct) a) Find a “good” preserved invariant P for M b) Show ()=true for final state q implies correct output c) Show 0 =true for start state

Slide 8

Slide 8 text

Program Correctness • State Machine :

Slide 9

Slide 9 text

Program Correctness • Why does it terminate?

Slide 10

Slide 10 text

Program Correctness • What is a good invariant here?

Slide 11

Slide 11 text

Program Correctness • Proving partial correctness

Slide 12

Slide 12 text

Recursive Data Types • To define recursive data type – Base case(s) that specify some elements are in – Constructor case(s) that specify how to construct new data element ∈ from previously constructed 1 , 2 , … ∈ • To define (new) operators on we again use base and constructor cases!

Slide 13

Slide 13 text

Recursive Data Types

Slide 14

Slide 14 text

Recursive Data Types

Slide 15

Slide 15 text

Structural Induction Goal: To prove for all elements in data type 1. Prove for all base cases ∈ 2. Prove 1 ∧ (2 ) ⇒ for all constructable from 1 , 2 15

Slide 16

Slide 16 text

Using Structural Induction

Slide 17

Slide 17 text

Infinite Sets and Cardinalities A set is countably infinite iff there is a bijection between and ℕ. is infinite, if there is no bijection between and any ℕ . Equivalent : ℕ ≤ || : there is a surjective function from to ℕ is Countable : ≤ |ℕ| : there is a surjective function from ℕ to . A set is uncountable iff it is not countable.

Slide 18

Slide 18 text

Infinite Sets and Cardinalities • Set of all English words… is finite. • Set of all words using English letters… is an infinite set. It includes all the finite sequences of a,b, which by interpreting = 0, = 1 we get all the natural numbers written in binary (and a lot more). So there is a surjective function from this set to ℕ.

Slide 19

Slide 19 text

Infinite Sets and Cardinalities • We know (ℕ) is uncountable (Cantor’s theorem) and that ℕ = 0,1 = |ℝ| • To show is uncountable, prove that ≥ || for an uncountable set. • Example: 0,2 , 1,2 , .