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
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
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
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
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
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
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
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
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 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
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 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 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
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 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
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 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
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 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 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
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 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
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
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
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
Time complexity
Proposition
The minimization program terminates after at most O(|Σ| · |Q|2) rule applications.
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 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 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 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 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 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 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 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 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
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
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