Minimizing Finite Automata with Graph Programs Detlef Plump 1 Robin - - PowerPoint PPT Presentation

minimizing finite automata with graph programs
SMART_READER_LITE
LIVE PREVIEW

Minimizing Finite Automata with Graph Programs Detlef Plump 1 Robin - - PowerPoint PPT Presentation

Minimizing Finite Automata with Graph Programs Detlef Plump 1 Robin Suri 2 Ambuj Singh 3 1 The University of York 2 Indian Institute of Technology Roorkee 3 Indian Institute of Technology Kanpur Automata Minimization Problem Input: A


slide-1
SLIDE 1

Minimizing Finite Automata with Graph Programs

Detlef Plump1 Robin Suri2 Ambuj Singh3

1The University of York 2Indian Institute of Technology Roorkee 3Indian Institute of Technology Kanpur

slide-2
SLIDE 2

Automata Minimization

Problem

Input: A deterministic finite automaton A = (Q, Σ, δ, q0, F). Output: A′ = (Q′, Σ, δ′, q′

0, F ′) such that L(A) = L(A′) and

|Q′| is minimal.

slide-3
SLIDE 3

Automata Minimization

Problem

Input: A deterministic finite automaton A = (Q, Σ, δ, q0, F). Output: A′ = (Q′, Σ, δ′, q′

0, F ′) such that L(A) = L(A′) and

|Q′| is minimal.

Definition

States p and q are equivalent if for all strings w, δ∗(p, w) ∈ F if and only if δ∗(q, w) ∈ F.

slide-4
SLIDE 4

Algorithm of Hopcroft, Motwani and Ullman

Marking phase Stage 1: for each p ∈ F and q ∈ Q − F do mark the pair {p, q} Stage 2: repeat for each non-marked pair {p, q} do for each a ∈ Σ do if {δ(p, a), δ(q, a)} is marked then mark {p, q} until no new pair is marked

slide-5
SLIDE 5

Algorithm of Hopcroft, Motwani and Ullman

Marking phase Stage 1: for each p ∈ F and q ∈ Q − F do mark the pair {p, q} Stage 2: repeat for each non-marked pair {p, q} do for each a ∈ Σ do if {δ(p, a), δ(q, a)} is marked then mark {p, q} until no new pair is marked

Lemma (HMU 07)

Two states p,q are equivalent if and only if the pair {p, q} is not marked by the marking phase.

slide-6
SLIDE 6

Algorithm of Hopcroft, Motwani and Ullman (cont’d)

Merging phase Construct A′ = (Q′, Σ, δ′, q′

0, F ′) as follows: ◮ Q′ = {[p] | p ∈ Q}, where [p] is the equivalence class of p ◮ q′ 0 = [q0] ◮ δ′([p], a) = [δ(p, a)], for each [p] ∈ Q′ and a ∈ Σ ◮ F ′ = {[p] ∈ Q′ | [p] ∩ F = ∅}

slide-7
SLIDE 7

Algorithm of Hopcroft, Motwani and Ullman (cont’d)

Merging phase Construct A′ = (Q′, Σ, δ′, q′

0, F ′) as follows: ◮ Q′ = {[p] | p ∈ Q}, where [p] is the equivalence class of p ◮ q′ 0 = [q0] ◮ δ′([p], a) = [δ(p, a)], for each [p] ∈ Q′ and a ∈ Σ ◮ F ′ = {[p] ∈ Q′ | [p] ∩ F = ∅}

Theorem (HMU 07)

The automaton A′ accepts the same language as A and is minimal.

slide-8
SLIDE 8

Implementation in GP

Automata are given by their transition diagrams, where

◮ final/non-final states are labelled i 1 resp. i 0, with i ∈ Z, ◮ only q0 is labelled 1 b (with b ∈ {0, 1}), ◮ the symbols in Σ are character strings, ◮ all states are reachable from q0.

1 0 3 0 4 1 2 0 b a b a b a a b

slide-9
SLIDE 9

Minimization program

main = mark; merge; clean up mark = distinguish!; propagate!; equate! merge = init; add tag!; (choose; add tag!)!; disconnect!; redirect! clean up = remove edge!; remove node!; untag!

slide-10
SLIDE 10

mark = distinguish!; propagate!; equate!

distinguish(x, y, i, j: int) x i

1

y j

2

⇒ x i

1

y j

2

1 where i = j and not edge(1, 2, 1)

slide-11
SLIDE 11

Example: execution of distinguish!

1 0 3 0 4 1 2 0 b a b a b a a b − → 1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1

slide-12
SLIDE 12

mark = distinguish!; propagate!; equate!

propagate(x, y, u, v, i, j, m, n: int; s: str) x i

1

u m

3

y j

2

v n

4

s s 1 ⇒ x i

1

u m

3

y j

2

v n

4

s s 1 1 where not edge(1, 2, 1) all matches

slide-13
SLIDE 13

Quotients of propagate

propagate 2(x, u, v, i, m, n: int; s: str) x i

1

u m

3

v n

4

s s 1 ⇒ x i

1

u m

3

v n

4

s s 1 1 where not edge(1, 4, 1) propagate 3(x, u, v, i, m, n: int; s: str) x i

1

u m

3

v n

4

s 1 s ⇒ x i

1

u m

3

v n

4

s 1 1 s where not edge(1, 3, 1)

slide-14
SLIDE 14

Example: execution of propagate!

1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1 − → 1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1 1 1

slide-15
SLIDE 15

mark = distinguish!; propagate!; equate!

equate(x, y, i, j: int) x i

1

y j

2

⇒ x i

1

y j

2

where not edge(1, 2, 1) and not edge(1, 2, 0)

slide-16
SLIDE 16

Example: execution of equate!

1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1 1 1 − → 1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1 1 1

slide-17
SLIDE 17

merge = init; add tag!; (choose; add tag!)!; disconnect!; redirect!

init(i: int) 1 i

1

⇒ 1 i 0

1

add tag(x, y, i, j: int) x i 0

1

y j

2

⇒ x i 0

1

y j 1

2

choose(x, i: int) x i

1

⇒ x i 0

1

slide-18
SLIDE 18

Example: execution of init; add tag!; (choose; add tag!)!

1 0 3 0 4 1 2 0 b a b a b a a b 1 1 1 1 1 − → 1 0 0 3 0 1 4 1 0 2 0 0 b a b a b a a b 1 1 1 1 1

slide-19
SLIDE 19

merge = init; add tag!; (choose; add tag!)!; disconnect!; redirect!

disconnect(x, u, i, m, p: int; s: str) u m p

2

x i 1

1

s ⇒ u m p

2

x i 1

1

all matches

slide-20
SLIDE 20

merge = init; add tag!; (choose; add tag!)!; disconnect!; redirect!

redirect(x, y, u, i, j, m: int; s: str) u m 0

2

x i 1

1

y j 0

3

s ⇒ u m 0

2

x i 1

1

y j 0

3

s all matches

slide-21
SLIDE 21

Example: execution of disconnect!; redirect!

1 0 0 3 0 1 4 1 0 2 0 0 b a b a b a a b 1 1 1 1 1 − → 1 0 0 3 0 1 4 1 0 2 0 0 b b b 1 1 1 1 1 a a a

slide-22
SLIDE 22

clean up = remove edge!; remove node!; untag!

remove edge(x, y, i, j, k, m, n: int) x i k

1

y j m

2

n ⇒ x i k

1

y j m

2

remove node(x, i: int) x i 1 ⇒ ∅ untag(x, i: int) x i 0

1

⇒ x i

1

slide-23
SLIDE 23

Example: execution of remove edge!

1 0 0 3 0 1 4 1 0 2 0 0 b b b 1 1 1 1 1 a a a − → 1 0 0 3 0 1 4 1 0 2 0 0 b b b a a a

slide-24
SLIDE 24

Example: execution of remove node!; untag!

1 0 0 3 0 1 4 1 0 2 0 0 b b b a a a − → 1 0 4 1 2 0 b b b a a a

slide-25
SLIDE 25

Correctness of the implementation

main = mark; merge; clean up mark = distinguish!; propagate!; equate! merge = init; add tag!; (choose; add tag!)!; disconnect!; redirect! clean up = remove edge!; remove node!; untag!

Proposition

For every input automaton A, the minimization program produces an automaton A′ that is equivalent to A and minimal.

slide-26
SLIDE 26

Time complexity

Proposition

The minimization program terminates after at most O(|Σ| · |Q|2) rule applications.

slide-27
SLIDE 27

Time complexity

Proposition

The minimization program terminates after at most O(|Σ| · |Q|2) rule applications. Note: We abstract from the complexity of rule matching.

slide-28
SLIDE 28

Complexity of distinguish!

distinguish(x, y, i, j: int) x i

1

y j

2

⇒ x i

1

y j

2

1 where i = j and not edge(1, 2, 1)

slide-29
SLIDE 29

Complexity of distinguish!

distinguish(x, y, i, j: int) x i

1

y j

2

⇒ x i

1

y j

2

1 where i = j and not edge(1, 2, 1) G = ⇒

distinguish H implies #G > #H, where

#X = |{{q, q′} | q = q′ ∧ ¬edge(q, q′, 1)}| < |Q|2 2

slide-30
SLIDE 30

Complexity of propagate!

propagate(x, y, u, v, i, j, m, n: int; s: str) x i

1

u m

3

y j

2

v n

4

s s 1 ⇒ x i

1

u m

3

y j

2

v n

4

s s 1 1 where not edge(1, 2, 1) all matches

slide-31
SLIDE 31

Complexity of propagate!

propagate(x, y, u, v, i, j, m, n: int; s: str) x i

1

u m

3

y j

2

v n

4

s s 1 ⇒ x i

1

u m

3

y j

2

v n

4

s s 1 1 where not edge(1, 2, 1) all matches G = ⇒

propagate H implies #G > #H, where

#X = |{{q, q′} | q = q′ ∧ ¬edge(q, q′, 1)}| < |Q|2 2

slide-32
SLIDE 32

Complexity of disconnect!

disconnect(x, u, i, m, p: int; s: str) u m p

2

x i 1

1

s ⇒ u m p

2

x i 1

1

all matches

slide-33
SLIDE 33

Complexity of disconnect!

disconnect(x, u, i, m, p: int; s: str) u m p

2

x i 1

1

s ⇒ u m p

2

x i 1

1

all matches G = ⇒

disconnect H implies #G > #H, where

#X = |{e ∈ EX | lab(e) ∈ Σ}| ≤ |Σ| · |Q|2

slide-34
SLIDE 34

Complexity of redirect!

redirect(x, y, u, i, j, m: int; s: str) u m 0

2

x i 1

1

y j 0

3

s ⇒ u m 0

2

x i 1

1

y j 0

3

s all matches

slide-35
SLIDE 35

Complexity of redirect!

redirect(x, y, u, i, j, m: int; s: str) u m 0

2

x i 1

1

y j 0

3

s ⇒ u m 0

2

x i 1

1

y j 0

3

s all matches G = ⇒

redirect H implies #G > #H, where

#X = |{e ∈ EX | lab(e) ∈ Σ∧lab(target(e)) = x i 1}| ≤ |Σ|·|Q|2

slide-36
SLIDE 36

Conclusion

◮ Minimizing automata with rule-based, visual programming ◮ Direct manipulation of transition diagrams (augmented with

auxiliary labels and edges); no need to implement transition functions, state tables, etc.

◮ Rule schemata and control constructs allow formal reasoning

at a high level of abstraction

◮ Case study reveals convenience/necessity of certain GP

constructs, e.g. ‘all matches’ attribute and ternary edge predicate

slide-37
SLIDE 37

Possible extensions

◮ Implementing state merging by non-injective rules — requires

GP extension

◮ Implementing more efficient minimization algorithms such as

the n2 algorithm of Hopcroft and Ullman or the nlogn algorithm of Hopcroft

◮ Minimizing nondeterministic finite automata