Slide 1

Slide 1 text

Class 14: Invariant Principle cs2102: Discrete Mathematics David Evans & Mohammad Mahmoody University of Virginia

Slide 2

Slide 2 text

Plan State Machines Review Invariant Principle Read this week: MCS Chapter 6

Slide 3

Slide 3 text

State Machine = (, ⊆ × , 0 ∈ )

Slide 4

Slide 4 text

= , = → , → 0 = Binary Relation View State Machine View

Slide 5

Slide 5 text

Bishop Moves = = 0 =

Slide 6

Slide 6 text

Reachable States A state is reachable if it appears in some execution. The execution of a state machine, = (, ⊆ × , 0 ∈ ) is a (possibly infinite) sequence of states, (0 , 1 , … , ) that: 1. 0 = 0 (it begins with the start state) 2. ∀ ∈ 0, 1, … , − 1 . → +1 ∈ (if and are consecutive states in the sequence, there is an edge → ∈ .

Slide 7

Slide 7 text

Bishop Moves = , , ∈ ℕ } 0 = (0, 2) What states are reachable? = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± }

Slide 8

Slide 8 text

Preserved Invariant is a preserved invariant of = (, ⊆ × , 0 ∈ ) if ∀ ∈ . ∧ ( → ) ∈ ⟹ ()

Slide 9

Slide 9 text

= , ≔ ( > 3) Is a preserved invariant? = , , ∈ ℕ } 0 = (0, 2) = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = + and ′ = + } (up-right only bishops)

Slide 10

Slide 10 text

Is a preserved invariant? = , , ∈ ℕ } = , ∶= ( = ) = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = + and ′ = + } (up-right only bishops)

Slide 11

Slide 11 text

Is a preserved invariant? = , , ∈ ℕ } = , ∶= ( is even) = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = + and ′ = + } (up-right only bishops)

Slide 12

Slide 12 text

= , , ∈ ℕ } = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } regular bishops What are preserved invariants for the Bishop machine? Any questions about definitions: state machine, execution, reachable, preserved invariant

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

= , , ∈ ℕ } = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } regular bishops What are preserved invariants for the Bishop machine?

Slide 15

Slide 15 text

= , , ∈ ℕ } ∶= ’s color = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } regular bishops

Slide 16

Slide 16 text

= , , ∈ ℕ } = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } = (, ) ∶= + is even regular bishops

Slide 17

Slide 17 text

Invariant Principle If a preserved invariant is true for the start state, it is true for all reachable states.

Slide 18

Slide 18 text

= , , ∈ ℕ } = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } 0 = (0, 2) Prove never enters a state corresponding to a white square.

Slide 19

Slide 19 text

= , , ∈ ℕ } = , → ′, ′ , , ′, ′ ∈ ℕ ∧ ∃ ∈ ℕ+ : ′ = ± and ′ = ± } 0 = (0, 2) Prove never enters a state where + is odd.

Slide 20

Slide 20 text

Fast (and Slow) Exponentiation

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Exponentiation in RSA

Slide 24

Slide 24 text

Slow Exponentiation How many multiplications?

Slide 25

Slide 25 text

Modeling Slow Exponentiation ∷= ∷= 0 ∷=

Slide 26

Slide 26 text

Correctness of Slow Exponentiation ∷= ℕ × ℕ ∷= { , ⟶ , − 1 | ∀ ∈ ℕ, ∈ ℕ+} 0 ∷= (1, ) What preserved invariant would be useful? If we prove this to be invariant, at the end, 0 = means = . We will see more subtle aspects of this argument next time..

Slide 27

Slide 27 text

Charge • PS6 will be posted by tomorrow, due next Friday • Read rest of Chapter 6