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

Class 14: Invariant Principle

Avatar for David Evans David Evans
October 14, 2016
5.1k

Class 14: InvariantΒ Principle

cs2102: Discrete Mathematics
University of Virginia, Fall 2016

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

Avatar for David Evans

David Evans

October 14, 2016

Transcript

  1. Class 14: Invariant Principle cs2102: Discrete Mathematics | F16 uvacs2102.github.io

    David Evans | University of Virginia Last chance to avoid storage fees on Exam 1: pick up after class today
  2. Reachable States A state is reachable if it appears in

    some execution. The execution of a state machine, = (, βŠ† Γ—, + ∈ ) is a (possibly infinite) sequence of states, (+ , 2 , … , 4 ) that: 1. + = + (it begins with the start state) 2. βˆ€ ∈ 0, 1, … , βˆ’ 1 . < β†’ <=2 ∈ (if and are consecutive states in the sequence, there is an edge β†’ ∈ .
  3. Bishop Moves = , , ∈ β„• } + =

    (0, 2) What states are reachable? = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 }
  4. = , , ∈ β„• } + = (0, 2)

    = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 }
  5. Preserved Invariant is a preserved invariant of = (, βŠ†

    Γ—, + ∈ ) if βˆ€ ∈ . ∧ ( β†’ ) ∈ ⟹ ()
  6. = , ∢= > 3 Is a preserved invariant? =

    , , ∈ β„• } + = (0, 2) = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = + ∧ C β‰₯ 0 ∧ C = + ∧ C β‰₯ 0 } (up-right only bishops)
  7. Is a preserved invariant? = , , ∈ β„• }

    = , ∢= ( = ) = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = + ∧ C β‰₯ 0 ∧ C = + ∧ C β‰₯ 0 } (up-right only bishops)
  8. What is an example of a that is not a

    preserved invariant? = , , ∈ β„• } (up-right only bishops) = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = + ∧ C β‰₯ 0 ∧ C = + ∧ C β‰₯ 0 }
  9. = , , ∈ β„• } = , β†’ C,

    β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 } regular bishops What are preserved invariants for the Bishop machine? Any questions about definitions: state machine, execution, reachable, preserved invariant
  10. = , , ∈ β„• } ∢= is a purple

    square = , β†’ C, β€² , ∈ β„• ∧ βˆƒ ∈ β„•= such that C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 } regular bishops
  11. = , , ∈ β„• } = , β†’ C,

    β€² , ∈ β„• ∧ ∈ β„•= ∧ C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 } = (, ) ∢= + is even
  12. Invariant Principle If a preserved invariant is true for the

    start state, it is true for all reachable states.
  13. = , , ∈ β„• } = , β†’ C,

    β€² , ∈ β„• ∧ ∈ β„•= ∧ C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 } + = (0, 2) Prove never enters a state corresponding to a white square.
  14. = , , ∈ β„• } = , β†’ C,

    β€² , ∈ β„• ∧ ∈ β„•= ∧ C = Β± ∧ C β‰₯ 0 ∧ C = Β± ∧ C β‰₯ 0 } + = (0, 2) Prove never enters a state where + is odd.
  15. Correctness of Slow Exponentiation ∷= β„• Γ— β„• ∷= {

    , ⟢ , βˆ’ 1 | βˆ€, ∈ β„•=} + ∷= (1, ) What preserved invariant would be useful?
  16. Correctness of Slow Exponentiation ∷= β„• Γ— β„• ∷= {

    , ⟢ , βˆ’ 1 | βˆ€, ∈ β„•=} + ∷= (1, ) What preserved invariant would be useful? = , ∷= ∈ β„• ∧ ^ = _ = , ∷= ∈ β„• ∧ = _`^
  17. Invariant is Preserved ∷= { , ⟢ , βˆ’ 1

    | βˆ€, ∈ β„•=} = , ∷= ∈ β„• ∧ = _`^
  18. Invariant is Preserved ∷= { , ⟢ , βˆ’ 1

    | βˆ€, ∈ β„•=} = , ∷= ∈ β„• ∧ = _`^ Does this prove slow_power(a, b) =
  19. Invariant Principle = , ∷= ∈ β„• ∧ = _`^

    Base case: If a preserved invariant is true for the start state, it is true for all reachable states.
  20. Invariant Principle = , ∷= ∈ β„• ∧ = _`^

    Prove slow_power(a, b) = Base case: (+ = 1, ) ∈ β„• since = and ∈ β„• = _`^ since = 1 = + and βˆ’ = 0. Inductive case: is a preserved invariant
  21. Partial Correctness = , ∷= ∈ β„• ∧ = _`^

    Prove slow_power(a, b) = If machine reaches terminating state e = (, 0) the result is correct: = . What else do we need to show?
  22. Invariant Principle = , ∷= ∈ β„• ∧ = _`^

    Prove slow_power(a, b) = Eventually reaches state e = = , 0
  23. Reachability Reaches state (, ): ∷= { , ⟢ ,

    βˆ’ 1 | βˆ€, ∈ β„•=} + ∷= (1, )
  24. Fast Exponentiation Read this example in the book: same idea,

    but more complex preserved invariant needed.
  25. Charge β€’ PS6 will be posted by tomorrow, due next

    Friday β€’ Read rest of Chapter 6 β€’ Tuesday: stable marriages!