COMP2111 Week 10 Term 1, 2020 State machines 1 Summary - - PowerPoint PPT Presentation

comp2111 week 10 term 1 2020 state machines
SMART_READER_LITE
LIVE PREVIEW

COMP2111 Week 10 Term 1, 2020 State machines 1 Summary - - PowerPoint PPT Presentation

COMP2111 Week 10 Term 1, 2020 State machines 1 Summary Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata 2 Summary Motivation Definitions The invariant principle


slide-1
SLIDE 1

COMP2111 Week 10 Term 1, 2020 State machines

1

slide-2
SLIDE 2

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

2

slide-3
SLIDE 3

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

3

slide-4
SLIDE 4

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example The semantics of a program in L: States: functions from variables to numerical values Transitions: defined by the program

4

slide-5
SLIDE 5

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example A chess solving engine States: Board positions Transitions: Legal moves

5

slide-6
SLIDE 6

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example “Stateful” communication protocols: e.g. SMTP States: Stages of communication Transitions: Determined by commands given (e.g. HELO, DATA, etc)

6

slide-7
SLIDE 7

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example A bounded counter that counts from 0 to 99 and overflows at 100: 1 2 · · · 99

  • verflow

7

slide-8
SLIDE 8

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example A robot that moves diagonally States: Locations Transitions: Moves

8

slide-9
SLIDE 9

Motivation: Models of computation

State machines model step-by-step processes: Set of “states”, possibly including a designated “start state” For each state, a set of actions detailing how to move (transition) to other states Example Die Hard jug problem: Given jugs of 3L and 5L, measure out exactly 4L. States: Defined by amount of water in each jug Start state: No water in both jugs Transitions: Pouring water (in, out, jug-to-jug)

9

slide-10
SLIDE 10

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

10

slide-11
SLIDE 11

Definitions

A transition system is a pair (S, →) where: S is a set (of states), and →⊆ S × S is a (transition) relation. If (s, s′) ∈→ we write s → s′. S may have a designated start state, s0 ∈ S S may have designated final states, F ⊆ S The transitions may be labelled by elements of a set Λ:

→⊆ S × Λ × S (s, a, s′) ∈→ is written as s

a

− → s′

If → is a function we say the system is deterministic,

  • therwise it is non-deterministic

11

slide-12
SLIDE 12

Definitions

A transition system is a pair (S, →) where: S is a set (of states), and →⊆ S × S is a (transition) relation. If (s, s′) ∈→ we write s → s′. S may have a designated start state, s0 ∈ S S may have designated final states, F ⊆ S The transitions may be labelled by elements of a set Λ:

→⊆ S × Λ × S (s, a, s′) ∈→ is written as s

a

− → s′

If → is a function we say the system is deterministic,

  • therwise it is non-deterministic

12

slide-13
SLIDE 13

Definitions

A transition system is a pair (S, →) where: S is a set (of states), and →⊆ S × S is a (transition) relation. If (s, s′) ∈→ we write s → s′. S may have a designated start state, s0 ∈ S S may have designated final states, F ⊆ S The transitions may be labelled by elements of a set Λ:

→⊆ S × Λ × S (s, a, s′) ∈→ is written as s

a

− → s′

If → is a function we say the system is deterministic,

  • therwise it is non-deterministic

13

slide-14
SLIDE 14

Definitions

A transition system is a pair (S, →) where: S is a set (of states), and →⊆ S × S is a (transition) relation. If (s, s′) ∈→ we write s → s′. S may have a designated start state, s0 ∈ S S may have designated final states, F ⊆ S The transitions may be labelled by elements of a set Λ:

→⊆ S × Λ × S (s, a, s′) ∈→ is written as s

a

− → s′

If → is a function we say the system is deterministic,

  • therwise it is non-deterministic

14

slide-15
SLIDE 15

Example: Bounded counter

Example A bounded counter that counts from 0 to 99 and overflows at 100: 1 2 · · · 99

  • verflow

S = {0, 1, . . . , 99, overflow} →= {(i, i + 1) : 0 ≤ i < 99} ∪ {(99, overflow)} ∪ {(overflow, overflow)} s0 = 0 Deterministic

15

slide-16
SLIDE 16

Example: Diagonally moving robot

Example States: Locations Transitions: Moves

16

slide-17
SLIDE 17

Example: Diagonally moving robot

Example S = Z × Z (x, y) → (x ± 1, y ± 1) Non-deterministic

17

slide-18
SLIDE 18

Example: Diagonally moving robot

Example S = Z × Z Λ = {NW , NE, SW , SE} (x, y) NW − − → (x − 1, y + 1) (x, y) NE − − → (x + 1, y + 1) (x, y) SW − − → (x − 1, y − 1) (x, y) SE − − → (x + 1, y − 1) Deterministic

18

slide-19
SLIDE 19

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. States: Defined by amount of water in each jug Start state: No water in both jugs Transitions: Pouring water (in, out, jug-to-jug)

19

slide-20
SLIDE 20

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

20

slide-21
SLIDE 21

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

21

slide-22
SLIDE 22

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

22

slide-23
SLIDE 23

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

23

slide-24
SLIDE 24

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

24

slide-25
SLIDE 25

Example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by

(i, j) → (0, j) [empty 5L jug] (i, j) → (i, 0) [empty 3L jug] (i, j) → (5, j) [fill 5L jug] (i, j) → (i, 3) [fill 3L jug] (i, j) → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j) → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j) → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j) → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug]

25

slide-26
SLIDE 26

Runs and reachability

Given a transition system (S, →) and states s, s′ ∈ S, a run from s is a (possibly infinite) sequence s1, s2, . . . such that s = s1 and si → si+1 for all i ≥ 1. we say s′ is reachable from s, written s →∗ s′, if (s, s′) is in the transitive closure of →. NB s′ is reachable from s if there is a run from s which contains s′.

26

slide-27
SLIDE 27

Runs and reachability

Given a transition system (S, →) and states s, s′ ∈ S, a run from s is a (possibly infinite) sequence s1, s2, . . . such that s = s1 and si → si+1 for all i ≥ 1. we say s′ is reachable from s, written s →∗ s′, if (s, s′) is in the transitive closure of →. NB s′ is reachable from s if there is a run from s which contains s′.

27

slide-28
SLIDE 28

Safety and Liveness

Common problem (Safety) Will a transition system always avoid a particular state or states? Equivalently, can a transition system reach a particular state or states? Common problem (Liveness) Will a transition system always reach a particular state or states? Equivalently, can a transition system avoid a particular state or states?

28

slide-29
SLIDE 29

Safety and Liveness

Common problem (Safety) Will a transition system always avoid a particular state or states? Equivalently, can a transition system reach a particular state or states? Common problem (Liveness) Will a transition system always reach a particular state or states? Equivalently, can a transition system avoid a particular state or states?

29

slide-30
SLIDE 30

Safety and Liveness

Common problem (Safety) Will a transition system always avoid a particular state or states? Equivalently, can a transition system reach a particular state or states? Common problem (Liveness) Will a transition system always reach a particular state or states? Equivalently, can a transition system avoid a particular state or states?

30

slide-31
SLIDE 31

Reachability example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. States: S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} Transition relation: (i, j) → (0, j) etc. Is (4, 0) reachable from (0, 0)? Yes: (0, 0) → (0, 3) → (3, 0) ↓ (0, 1) ← (5, 1) ← (3, 3) ↓ (1, 0) → (1, 3) → (4, 0)

31

slide-32
SLIDE 32

Reachability example: Die Hard jug problem

Example Given jugs of 3L and 5L, measure out exactly 4L. States: S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} Transition relation: (i, j) → (0, j) etc. Is (4, 0) reachable from (0, 0)? Yes: (0, 0) → (0, 3) → (3, 0) ↓ (0, 1) ← (5, 1) ← (3, 3) ↓ (1, 0) → (1, 3) → (4, 0)

32

slide-33
SLIDE 33

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)?

33

slide-34
SLIDE 34

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)?

34

slide-35
SLIDE 35

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)? No

35

slide-36
SLIDE 36

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)? No isBlue((m, n)) := 2|(m + n)

36

slide-37
SLIDE 37

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)? No isBlue((m, n)) := 2|(m + n) if isBlue(s) and s → s′ then isBlue(s′)

37

slide-38
SLIDE 38

Safety example: Diagonally moving robot

Example Starting at (0, 0) Can the robot get to (0, 1)? No isBlue((m, n)) := 2|(m + n) if isBlue(s) and s → s′ then isBlue(s′) isBlue((0, 0)) and ¬isBlue((0, 1))

38

slide-39
SLIDE 39

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

39

slide-40
SLIDE 40

The invariant principle

A preserved invariant of a transition system is a unary predicate ϕ on states such that if ϕ(s) holds and s → s′ then ϕ(s′) holds. Invariant principle If a preserved invariant holds at a state s, then it holds for all states reachable from s. Proof:

40

slide-41
SLIDE 41

The invariant principle

A preserved invariant of a transition system is a unary predicate ϕ on states such that if ϕ(s) holds and s → s′ then ϕ(s′) holds. Invariant principle If a preserved invariant holds at a state s, then it holds for all states reachable from s. Proof:

41

slide-42
SLIDE 42

Invariant example: Modified Die Hard problem

Example Given jugs of 3L and 6L, measure out exactly 4L. States: S = {(i, j) ∈ N × N : 0 ≤ i ≤ 6 and 0 ≤ j ≤ 3} Transition relation: (i, j) → (0, j) etc. Is (4, 0) reachable from (0, 0)?

  • No. Consider ϕ((i, j)) = (3|i) ∧ (3|j).

42

slide-43
SLIDE 43

Invariant example: Modified Die Hard problem

Example Given jugs of 3L and 6L, measure out exactly 4L. States: S = {(i, j) ∈ N × N : 0 ≤ i ≤ 6 and 0 ≤ j ≤ 3} Transition relation: (i, j) → (0, j) etc. Is (4, 0) reachable from (0, 0)?

  • No. Consider ϕ((i, j)) = (3|i) ∧ (3|j).

43

slide-44
SLIDE 44

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

44

slide-45
SLIDE 45

Partial correctness

Let (S, →, s0, F) be a transition system with start state s0 and final states F and a ϕ be a unary predicate on S. We say the system is partially correct for ϕ if ϕ(s′) holds for all states s′ ∈ F that are reachable from s0. NB Partial correctness does not guarantee a transition system will reach a final state.

45

slide-46
SLIDE 46

Partial correctness example: Fast GCD

Example Consider the following program in L: x := m; y := n; r := m%n; while r > 0 do x := y; y := r; r := x%y;

  • d

46

slide-47
SLIDE 47

Partial correctness example: Fast GCD

Example States: Functions from {m, n, x, y, r} to N Transitions: Effect of each line of code (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

47

slide-48
SLIDE 48

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each line of code (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

48

slide-49
SLIDE 49

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

49

slide-50
SLIDE 50

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

50

slide-51
SLIDE 51

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

51

slide-52
SLIDE 52

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

52

slide-53
SLIDE 53

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

53

slide-54
SLIDE 54

Partial correctness example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Start state: (m, n, m%n) Final states: {(x, y, 0) : x, y ∈ N} Goal: Show partial correctness for ϕ((x, y, r)) := (y = gcd(m, n)) Show ψ((x, y, r)) := (gcd(m, n) = gcd(y, r)) is a preserved invari- ant... How can we show total correctness?

54

slide-55
SLIDE 55

Total correctness

A transition system (S, →) terminates from a state s ∈ S if there is an N ∈ N such that all runs from s have length at most N. A transition system is totally correct for a unary predicate ϕ, if it terminates (from s0) and ϕ holds in the last state of every run.

55

slide-56
SLIDE 56

Derived variables

In a transition system (S, →), a derived variable is a function f : S → R. A derived variable is strictly decreasing if s → s′ implies f (s′) < f (s). Theorem If f is an N-valued, strictly decreasing derived variable, then the length of any run from s is at most f (s).

56

slide-57
SLIDE 57

Derived variables

In a transition system (S, →), a derived variable is a function f : S → R. A derived variable is strictly decreasing if s → s′ implies f (s′) < f (s). Theorem If f is an N-valued, strictly decreasing derived variable, then the length of any run from s is at most f (s).

57

slide-58
SLIDE 58

Termination example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Derived variable: f ((x, y, r)) = x + y

58

slide-59
SLIDE 59

Termination example: Fast GCD

Example States: (x, y, r) ∈ N × N × N Transitions: Effect of each iteration of while loop: (x, y, r) → (y, r, y%r) Derived variable: f ((x, y, r)) = x + y

59

slide-60
SLIDE 60

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

60

slide-61
SLIDE 61

Interaction with the environment

We can model the system interacting with an external entity via inputs (Σ) and outputs (Γ) by using labelled transitions: →⊆ S × Λ × S where Λ = Σ × Γ Two main categories of input/output transition systems: Acceptors: Accept/reject a sequence of inputs (Relations) Transducers: Take a sequence of inputs and produce a sequence

  • f outputs (Functions)

61

slide-62
SLIDE 62

Interaction with the environment

We can model the system interacting with an external entity via inputs (Σ) and outputs (Γ) by using labelled transitions: →⊆ S × Λ × S where Λ = Σ × Γ Two main categories of input/output transition systems: Acceptors: Accept/reject a sequence of inputs (Relations) Transducers: Take a sequence of inputs and produce a sequence

  • f outputs (Functions)

62

slide-63
SLIDE 63

Acceptor example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y) NW − − → (x − 1, y + 1) (x, y) NE − − → (x + 1, y + 1) (x, y) SW − − → (x − 1, y − 1) (x, y) SE − − → (x + 1, y − 1) Accept if (2, 2) reached

63

slide-64
SLIDE 64

Acceptor example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y) NW − − → (x − 1, y + 1) (x, y) NE − − → (x + 1, y + 1) (x, y) SW − − → (x − 1, y − 1) (x, y) SE − − → (x + 1, y − 1) Accept if (2, 2) reached Accepted sequences: NE, NE

64

slide-65
SLIDE 65

Acceptor example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y) NW − − → (x − 1, y + 1) (x, y) NE − − → (x + 1, y + 1) (x, y) SW − − → (x − 1, y − 1) (x, y) SE − − → (x + 1, y − 1) Accept if (2, 2) reached Accepted sequences: NE, NE NE, SE, NE, NW

65

slide-66
SLIDE 66

Acceptor example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y) NW − − → (x − 1, y + 1) (x, y) NE − − → (x + 1, y + 1) (x, y) SW − − → (x − 1, y − 1) (x, y) SE − − → (x + 1, y − 1) Accept if (2, 2) reached Accepted sequences: NE, NE NE, SE, NE, NW NE, NE, NE, SW ...

66

slide-67
SLIDE 67

Transducer example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y)

NW /x

− − − − → (x − 1, y + 1) (x, y)

NE/x

− − − → (x + 1, y + 1) (x, y)

SW /x

− − − − → (x − 1, y − 1) (x, y)

SE/x

− − − → (x + 1, y − 1) Input direction Output x-coordinate

67

slide-68
SLIDE 68

Transducer example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y)

NW /x

− − − − → (x − 1, y + 1) (x, y)

NE/x

− − − → (x + 1, y + 1) (x, y)

SW /x

− − − − → (x − 1, y − 1) (x, y)

SE/x

− − − → (x + 1, y − 1) Input direction Output x-coordinate Input: NE, SE, NE, NW Output: 1, 2, 3, 2

68

slide-69
SLIDE 69

Transducer example: Diagonally moving robot

Example S = Z × Z s0 = (0, 0) (x, y)

NW /y

− − − − → (x − 1, y + 1) (x, y)

NE/y

− − − → (x + 1, y + 1) (x, y)

SW /y

− − − − → (x − 1, y − 1) (x, y)

SE/y

− − − → (x + 1, y − 1) Input direction Output y-coordinate Input: NE, SE, NE, NW Output: 1, 0, 1, 2

69

slide-70
SLIDE 70

Acceptor example: Die Hard jug problem

Example

S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by (i, j)

E5

− → (0, j) [empty 5L jug] (i, j)

E3

− → (i, 0) [empty 3L jug] (i, j)

F5

− → (5, j) [fill 5L jug] (i, j)

F3

− → (i, 3) [fill 3L jug] (i, j)

E35

− − → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j)

E53

− − → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j)

F53

− − → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j)

F35

− − → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug] Accept if (4, 0) is reached: e.g. F3, E35, F3, F53, E5, E35, F3, E35

70

slide-71
SLIDE 71

Acceptor example: Die Hard jug problem

Example

S = {(i, j) ∈ N × N : 0 ≤ i ≤ 5 and 0 ≤ j ≤ 3} s0 = (0, 0) → given by (i, j)

E5

− → (0, j) [empty 5L jug] (i, j)

E3

− → (i, 0) [empty 3L jug] (i, j)

F5

− → (5, j) [fill 5L jug] (i, j)

F3

− → (i, 3) [fill 3L jug] (i, j)

E35

− − → (i + j, 0) if i + j ≤ 5 [empty 3L jug into 5L jug] (i, j)

E53

− − → (0, i + j) if i + j ≤ 3 [empty 5L jug into 3L jug] (i, j)

F53

− − → (5, j − 5 + i)) if i + j ≥ 5 [fill 5L jug from 3L jug] (i, j)

F35

− − → (i − 3 + j, 3) if i + j ≥ 3 [fill 3L jug from 5L jug] Accept if (4, 0) is reached: e.g. F3, E35, F3, F53, E5, E35, F3, E35

71

slide-72
SLIDE 72

ǫ-transitions

It can be useful to allow the system to transition without taking input or producing output. We use the special symbol ǫ to denote such transitions.

72

slide-73
SLIDE 73

Formal definitions

An acceptor is a Σ ∪ {ǫ}-labelled transition system A = (S, →, Σ, s0, F) with a start state s0 ∈ S and a set of final states F ⊆ S. A transducer is a (Σ ∪ {ǫ}) × (Γ ∪ {ǫ})-labelled transition system T = (S, →, Σ, s0, F) with a start state s0 ∈ S and a set of final states F ⊆ S.

73

slide-74
SLIDE 74

Summary

Motivation Definitions The invariant principle Partial correctness and termination Input and output Finite automata

74

slide-75
SLIDE 75

Finite state transition systems

State transition systems with a finite set of states are particularly useful in Computer Science. Acceptors: Finite state automata Transducers: Mealy machines

75