Alternating Finite Automata

Alternating Finite Automata
Matthias Hengel
Seminar: Automata Theory
Software Engineering
Albert-Ludwigs-Universität Freiburg
24. July, 2013
Motivation
Problem: DFA occurring in practice are often very big with a
lot of states
How can they be represented efficiently?
Using alternating finite automata a DFA with 2k states can be
represented as a automaton with k + 1 states
Problem: The “complexity” of the automaton is shifted to the
transition function
How can the transition function be represented efficiently?
Matthias Hengel
Alternating Finite Automata
2/40
Motivation
Problem: DFA occurring in practice are often very big with a
lot of states
How can they be represented efficiently?
Using alternating finite automata a DFA with 2k states can be
represented as a automaton with k + 1 states
Problem: The “complexity” of the automaton is shifted to the
transition function
How can the transition function be represented efficiently?
Matthias Hengel
Alternating Finite Automata
2/40
Content
1
Motivation
2
Basic definitions
3
Construction from DFA to an equivalent AFA
4
Bit-wise implementation
5
Conclusion
Matthias Hengel
Alternating Finite Automata
3/40
Basic Definitions
Matthias Hengel
Alternating Finite Automata
4/40
AFA: Definition
Definition
A h-AFA is a tuple (Q, Σ, g , h, f ), where
Q is a finite set of states,
Σ is the input alphabet,
g : Q × Σ × B Q → B is the transition function, where B
denotes the two-element Boolean algebra,
h : B Q → B is the accepting function, and
F ⊆ Q is the set of final states.
Matthias Hengel
Alternating Finite Automata
5/40
AFA: Further definitions
Definition
The transition function g : Q × Σ × B Q → B is extended to a
function g : Q × Σ∗ × B Q → B as follows:
g (s, λ, u) = us , and
g (s, aw , u) = g (s, a, g (s, w , u)).
Definition
A word w ∈ Σ∗ is accepted by an AFA iff h(g (w , f )) = 1, where
f ∈ B Q and fq = 1 iff q ∈ F , and
g (w , f ) = g (s, w , f )s∈Q .
Matthias Hengel
Alternating Finite Automata
6/40
AFA: Further definitions
Definition
The transition function g : Q × Σ × B Q → B is extended to a
function g : Q × Σ∗ × B Q → B as follows:
g (s, λ, u) = us , and
g (s, aw , u) = g (s, a, g (s, w , u)).
Definition
A word w ∈ Σ∗ is accepted by an AFA iff h(g (w , f )) = 1, where
f ∈ B Q and fq = 1 iff q ∈ F , and
g (w , f ) = g (s, w , f )s∈Q .
Matthias Hengel
Alternating Finite Automata
6/40
Example
Example
Consider the automata A = (QA , Σ, g , h, FA ) where
QA = {s0 , s1 , s2 }
Σ = {a, b}
h(s0 , s1 , s2 ) = s0
FA = ∅
and g is defined by:
State
s0
s1
s2
Matthias Hengel
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
Alternating Finite Automata
7/40
Example
∧
a
s0
Matthias Hengel
b
s1
Alternating Finite Automata
s2
8/40
Example
∧
a
s0
s1
s2
b
∨
Matthias Hengel
Alternating Finite Automata
8/40
Example
s0
s1
a
s2
1
b
Matthias Hengel
Alternating Finite Automata
8/40
Example
∧
∧
a
s0
b
a
s1
a
s2
b
1
b
∨
Matthias Hengel
Alternating Finite Automata
8/40
Example run
Example
State
s0
s1
s2
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
Consider the word bba.
h(g (bba, f )) = h(g (b, g (b, g (a, f )))) = h(g (b, g (b, g (a, (0, 0, 0)))))
= h(g (b, g (b, (0, 0, 1))))
= h(g (b, (0, 1, 0))
= h(1, 1, 1)
=1
Matthias Hengel
Alternating Finite Automata
9/40
Example run
Example
State
s0
s1
s2
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
Consider the word bba.
h(g (bba, f )) = h(g (b, g (b, g (a, f )))) = h(g (b, g (b, g (a, (0, 0, 0)))))
= h(g (b, g (b, (0, 0, 1))))
= h(g (b, (0, 1, 0))
= h(1, 1, 1)
=1
Matthias Hengel
Alternating Finite Automata
9/40
Construction from DFA to an equivalent AFA
Matthias Hengel
Alternating Finite Automata
10/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Idea
Consider a DFA with 2k states
2k states can be encoded by Boolean vectors of length k
Idea: Every state of the DFA is represented as an assignment
of states of the AFA
This corresponds to an encoding of the states of the DFA as
Boolean vectors
The transition function must be build accordingly
The AFA accepts the reverse language
Matthias Hengel
Alternating Finite Automata
11/40
Construction
Theorem
A language L is accepted by a DFA with 2k states if and only if it’s
reversed language LR is accepted by an AFA with k + 1 states.
Matthias Hengel
Alternating Finite Automata
12/40
Construction
Let A = (QD , Σ, q0 , FD , δ), QD = {q0 , . . . , q2k −1 } be an DFA with
2k states.
Example
Consider a DFA A as following:
b
a
a
start
q0
a
q1
b
State
q0
q1
q2
q3
Matthias Hengel
a, b
b
q2
a
q1
q1
q1
q3
q3
b
q0
q2
q3
q3
Alternating Finite Automata
13/40
Construction: States
The set of states is constructed as QA = {s0 , s1 , . . . , sk }.
The state s0 has a special role as will be seen later.
Example
QA = {s0 , s1 , s2 }
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
14/40
Construction: States
The set of states is constructed as QA = {s0 , s1 , . . . , sk }.
The state s0 has a special role as will be seen later.
Example
QA = {s0 , s1 , s2 }
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
14/40
Construction: States
The set of states is constructed as QA = {s0 , s1 , . . . , sk }.
The state s0 has a special role as will be seen later.
Example
QA = {s0 , s1 , s2 }
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
14/40
Construction: Accepting function
The accepting function is constructed as h(s0 , s1 , . . . , sk ) = s0 .
Example
h(s0 , s1 , s2 ) = s0
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
15/40
Construction: Accepting function
The accepting function is constructed as h(s0 , s1 , . . . , sk ) = s0 .
Example
h(s0 , s1 , s2 ) = s0
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
15/40
Construction: Final states
(
{s0 }
The final states are constructed as FA =
∅
if q0 ∈ FD ,
.
otherwise.
Example
Start state is q0 and FD = {q3 }, therefore FA = ∅. The
characteristic vector now is (0, 0, 0).
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
16/40
Construction: Final states
(
{s0 }
The final states are constructed as FA =
∅
if q0 ∈ FD ,
.
otherwise.
Example
Start state is q0 and FD = {q3 }, therefore FA = ∅. The
characteristic vector now is (0, 0, 0).
s0
Matthias Hengel
s1
Alternating Finite Automata
s2
16/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Encoding
Choose an arbitrary bijection π : QD → B k such that
π(q0 ) = (0, . . . , 0).
Identify π(a), a ∈ QD , with an assignment of the states s1 , . . . , sk .
This represents an encoding scheme of the states of the DFA
A in B k
π(s) is chosen as (0, . . . , 0) because of the definition of FA
The state s0 is not considered by π
Example
State of A
Assignment of s1 and s2 under π
Matthias Hengel
0
(0, 0)
1
(0, 1)
Alternating Finite Automata
2
(1, 0)
3
(1, 1)
17/40
Construction: Transition function
Let θ1 (x) = x and θ0 (x) = x.
For si , i 6= 0, the transition function is constructed as:
_
g (si , a, u) =
(π(δ(π −1 (v ), a))i ∧ θv1 (u1 ) ∧ · · · ∧ θvk (uk )).
v ∈B k
Matthias Hengel
Alternating Finite Automata
18/40
Construction: Transition function
Let θ1 (x) = x and θ0 (x) = x.
For si , i 6= 0, the transition function is constructed as:
_
g (si , a, u) =
(π(δ(π −1 (v ), a))i ∧ θv1 (u1 ) ∧ · · · ∧ θvk (uk )).
v ∈B k
Matthias Hengel
Alternating Finite Automata
18/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Construction: Lemma
Lemma
Let z, x ∈ B. Then θz (x) = 1 if and only if z = x.
Proof.
⇒“: Let θz (x) be 1.
”
z = 1: Then θz (x) = x and therefore x = 1.
z = 0: Then θz (x) = x, therefore x = 1 and thus x = 0.
⇐“: Let z = x:
”
z = 1: Then θz (x) = x and therefore θz (x) = 1.
z = 0: Then θz (x) = x and therefore θz (x) = 0 = 1.
Matthias Hengel
Alternating Finite Automata
19/40
Transition function: Details
Using the lemma the transition function can be rearranged as
following:
_
g (si , a, u) =
(π(δ(π −1 (v ), a))i ∧ θv1 (u1 ) ∧ · · · ∧ θvk (uk ))
v ∈B k
= π(δ(π −1 (u1 , . . . , uk ), a))i
The transition function g directly represents the transitions of
A in the encoding scheme!
The reason for the initial notation is that in this way it can be
represented more easily as a Boolean function.
Matthias Hengel
Alternating Finite Automata
20/40
Transition function: Details
Using the lemma the transition function can be rearranged as
following:
_
g (si , a, u) =
(π(δ(π −1 (v ), a))i ∧ θv1 (u1 ) ∧ · · · ∧ θvk (uk ))
v ∈B k
= π(δ(π −1 (u1 , . . . , uk ), a))i
The transition function g directly represents the transitions of
A in the encoding scheme!
The reason for the initial notation is that in this way it can be
represented more easily as a Boolean function.
Matthias Hengel
Alternating Finite Automata
20/40
Transition function: Details
Using the lemma the transition function can be rearranged as
following:
_
g (si , a, u) =
(π(δ(π −1 (v ), a))i ∧ θv1 (u1 ) ∧ · · · ∧ θvk (uk ))
v ∈B k
= π(δ(π −1 (u1 , . . . , uk ), a))i
The transition function g directly represents the transitions of
A in the encoding scheme!
The reason for the initial notation is that in this way it can be
represented more easily as a Boolean function.
Matthias Hengel
Alternating Finite Automata
20/40
Transition function: Details
For s0 the transition function is constructed as:
_
g (s0 , a, u) =
θπ(q)1 (g (s1 , a, u)) ∧ · · · ∧ θπ(q)k (g (sk , a, u))
q∈FD
Again we consider the lemma: g (s0 , a, u) is true iff the
encoding of at least one of the final states of A is the current
assignment of the AFA.
Because of h(s0 , s1 , . . . , sk ) = s0 , the state s0 is the only state
which needs to be considered for acceptance.
Matthias Hengel
Alternating Finite Automata
21/40
Transition function: Details
For s0 the transition function is constructed as:
_
g (s0 , a, u) =
θπ(q)1 (g (s1 , a, u)) ∧ · · · ∧ θπ(q)k (g (sk , a, u))
q∈FD
Again we consider the lemma: g (s0 , a, u) is true iff the
encoding of at least one of the final states of A is the current
assignment of the AFA.
Because of h(s0 , s1 , . . . , sk ) = s0 , the state s0 is the only state
which needs to be considered for acceptance.
Matthias Hengel
Alternating Finite Automata
21/40
Transition function: Details
For s0 the transition function is constructed as:
_
g (s0 , a, u) =
θπ(q)1 (g (s1 , a, u)) ∧ · · · ∧ θπ(q)k (g (sk , a, u))
q∈FD
Again we consider the lemma: g (s0 , a, u) is true iff the
encoding of at least one of the final states of A is the current
assignment of the AFA.
Because of h(s0 , s1 , . . . , sk ) = s0 , the state s0 is the only state
which needs to be considered for acceptance.
Matthias Hengel
Alternating Finite Automata
21/40
Construction: Transition function
Example
g (s1 , a, u) =
_
(π(δ(π −1 (v ), a))1 ∧ θv1 (u1 ) ∧ θv2 (u2 ))
v ∈B k
= (π(δ(π −1 (00), a))1 ∧ θ0 (u1 ) ∧ θ0 (u2 ))
∨ (π(δ(π −1 (01), a))1 ∧ θ0 (u1 ) ∧ θ1 (u2 ))
∨ (π(δ(π −1 (10), a))1 ∧ θ1 (u1 ) ∧ θ0 (u2 ))
∨ (π(δ(π −1 (11), a))1 ∧ θ1 (u1 ) ∧ θ1 (u2 ))
=(0 ∧ u1 ∧ u2 ) ∨ (0 ∧ u1 ∧ u2 )
∨ (0 ∧ u1 ∧ u2 ) ∨ (1 ∧ u1 ∧ u2 )
=u1 ∧ u2
Matthias Hengel
Alternating Finite Automata
22/40
Construction: Transition function
Example
Overall the transition function is:
g
s0
s1
s2
Matthias Hengel
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
Alternating Finite Automata
23/40
Construction: Transition function
Example
∧
∧
a
s0
b
b
s1
a
a
s2
1
b
∨
Matthias Hengel
Alternating Finite Automata
24/40
Example run
Example
Consider the word w = abb.
w is accepted by A ⇔ w R is accepted by the constructed AFA
The word w is accepted iff h(g (w R , f )) = 1, where f is the
characteristic vector (0, 0, 0)
Only the last two numbers of a vector encode the state, the
first represents the state of s0
h(g (bba, f )) = h(g (b, g (b, g (a, (0, 0, 0)))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
25/40
Example run
Example
Consider the word w = abb.
w is accepted by A ⇔ w R is accepted by the constructed AFA
The word w is accepted iff h(g (w R , f )) = 1, where f is the
characteristic vector (0, 0, 0)
Only the last two numbers of a vector encode the state, the
first represents the state of s0
h(g (bba, f )) = h(g (b, g (b, g (a, (0, 0, 0)))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
25/40
Example run
Example
Consider the word w = abb.
w is accepted by A ⇔ w R is accepted by the constructed AFA
The word w is accepted iff h(g (w R , f )) = 1, where f is the
characteristic vector (0, 0, 0)
Only the last two numbers of a vector encode the state, the
first represents the state of s0
h(g (bba, f )) = h(g (b, g (b, g (a, (0, 0, 0)))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
25/40
Example run
Example
Consider the word w = abb.
w is accepted by A ⇔ w R is accepted by the constructed AFA
The word w is accepted iff h(g (w R , f )) = 1, where f is the
characteristic vector (0, 0, 0)
Only the last two numbers of a vector encode the state, the
first represents the state of s0
h(g (bba, f )) = h(g (b, g (b, g (a, (0, 0, 0)))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
25/40
Example run
Example
Consider the word w = abb.
w is accepted by A ⇔ w R is accepted by the constructed AFA
The word w is accepted iff h(g (w R , f )) = 1, where f is the
characteristic vector (0, 0, 0)
Only the last two numbers of a vector encode the state, the
first represents the state of s0
h(g (bba, f )) = h(g (b, g (b, g (a, (0, 0, 0)))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
25/40
Example run
Example
h(g (bba, f )) = h(g (b, g (b, (0, 0, 1))))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
26/40
Example run
Example
h(g (bba, f )) = h(g (b, (0, 1, 0))
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
27/40
Example run
Example
h(g (bba, f )) = h(1, 1, 1) = 1
b
a, b
a
a
start
Matthias Hengel
(0, 0)
a
(0, 1)
b
(1, 0)
b
Alternating Finite Automata
(1, 1)
28/40
Bit-wise implementation
Matthias Hengel
Alternating Finite Automata
29/40
Transformation DFA to AFA: Observations
Complexity of states of the DFA is transformed to complexity
of the transition function of the AFA
How can the transition function be represented efficiently?
Is there a efficient representation of Boolean functions?
Matthias Hengel
Alternating Finite Automata
30/40
Transformation DFA to AFA: Observations
Complexity of states of the DFA is transformed to complexity
of the transition function of the AFA
How can the transition function be represented efficiently?
Is there a efficient representation of Boolean functions?
Matthias Hengel
Alternating Finite Automata
30/40
Transformation DFA to AFA: Observations
Complexity of states of the DFA is transformed to complexity
of the transition function of the AFA
How can the transition function be represented efficiently?
Is there a efficient representation of Boolean functions?
Matthias Hengel
Alternating Finite Automata
30/40
Basic definitions
Let S = {x1 , . . . , xn } a set of Boolean variables, and
S = {x1 , . . . , xn }.
Definition
A term t defined on S ∪ S is a conjunction
t = y1 ∧ · · · ∧ yk , 1 ≤ k ≤ n
where yi ∈ S ∪ S, yi 6= yj , yi 6= yj for 1 ≤ i < j ≤ k, or t is
constant.
Definition
A Boolean
expression f is said to be in disjunctive normal form if
W
f = ki=1 ti , where ti , i = 1, . . . , k, is a term defined on S ∪ S.
Matthias Hengel
Alternating Finite Automata
31/40
Basic definitions
Let S = {x1 , . . . , xn } a set of Boolean variables, and
S = {x1 , . . . , xn }.
Definition
A term t defined on S ∪ S is a conjunction
t = y1 ∧ · · · ∧ yk , 1 ≤ k ≤ n
where yi ∈ S ∪ S, yi 6= yj , yi 6= yj for 1 ≤ i < j ≤ k, or t is
constant.
Definition
A Boolean
expression f is said to be in disjunctive normal form if
W
f = ki=1 ti , where ti , i = 1, . . . , k, is a term defined on S ∪ S.
Matthias Hengel
Alternating Finite Automata
31/40
Theorem: Bit-wise representation of Boolean functions
Theorem
For every Boolean function f defined on S that can be expressed
as a single term, there exist two n-bit vectors α and β such that
for all u ∈ B n
f (u) = 1 ⇔ (α&u) ↑ β = 0
where & is the bit-wise AND operator, ↑ the bit-wise exclusive-or
operator, and 0 is the zero vector (0, . . . , 0) ∈ B n .
Using this theorem we can represent a term of a Boolean function
as two n-bit integers.
Matthias Hengel
Alternating Finite Automata
32/40
Theorem: Bit-wise representation of Boolean functions
Theorem
For every Boolean function f defined on S that can be expressed
as a single term, there exist two n-bit vectors α and β such that
for all u ∈ B n
f (u) = 1 ⇔ (α&u) ↑ β = 0
where & is the bit-wise AND operator, ↑ the bit-wise exclusive-or
operator, and 0 is the zero vector (0, . . . , 0) ∈ B n .
Using this theorem we can represent a term of a Boolean function
as two n-bit integers.
Matthias Hengel
Alternating Finite Automata
32/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Proof
Proof.
Let f = yi1 ∧ · · · ∧ yik , where yij = xij or xij , ij 6= ij 0 for j 6= j 0 .
Let α = (α1 , . . . , αn ) and β = (β1 , . . . , βn ) be defined as follows:
αi = 1 iff xi or xi appears in f
βi = 1 iff xi appears in f
Then (α&u)i = 1 ⇔ ui = 1 and (xi or xi appears in f ).
Case 1: Neither xi nor xi appear in f , then ((α&u) ↑ β)i = 0
Case 2: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 1
Case 3: xi appears in f , then ((α&u) ↑ β)i = 0 iff ui = 0
All in all f (u) = 1 iff (α&u) ↑ β = 0.
Matthias Hengel
Alternating Finite Automata
33/40
Theorem: Example
Example
Consider f (u1 , u2 ) = u1 ∧ u2 . Then:
α = (1, 1)
β = (1, 0)
Therefore:
f (1, 0) = (α&(1, 0)) ↑ β
= ((1, 1)&(1, 0)) ↑ (1, 0)
= (1, 0) ↑ (1, 0)
= (0, 0)
Matthias Hengel
Alternating Finite Automata
34/40
Theorem: Example
Example
Consider f (u1 , u2 ) = u1 ∧ u2 . Then:
α = (1, 1)
β = (1, 0)
Therefore:
f (1, 0) = (α&(1, 0)) ↑ β
= ((1, 1)&(1, 0)) ↑ (1, 0)
= (1, 0) ↑ (1, 0)
= (0, 0)
Matthias Hengel
Alternating Finite Automata
34/40
Theorem: Example
Example
Consider f (u1 , u2 ) = u1 ∧ u2 . Then:
α = (1, 1)
β = (1, 0)
Therefore:
f (1, 0) = (α&(1, 0)) ↑ β
= ((1, 1)&(1, 0)) ↑ (1, 0)
= (1, 0) ↑ (1, 0)
= (0, 0)
Matthias Hengel
Alternating Finite Automata
34/40
Theorem: Example
Example
Consider f (u1 , u2 ) = u1 ∧ u2 . Then:
α = (1, 1)
β = (1, 0)
Therefore:
f (1, 0) = (α&(1, 0)) ↑ β
= ((1, 1)&(1, 0)) ↑ (1, 0)
= (1, 0) ↑ (1, 0)
= (0, 0)
Matthias Hengel
Alternating Finite Automata
34/40
Example
Example
Consider again the transition function (and the transition function
of the DFA):
g
s0
s1
s2
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
State
q0
q1
q2
q3
a
q1
q1
q1
q3
b
q0
q2
q3
q3
This gives the following representation (compared to the DFA):
g
s0
s1
s2
Matthias Hengel
a
((11), (11))
((11), (11))
((00), (00))
b
((10), (10))
((10), (10)), ((01), (01))
((10), (10))
Alternating Finite Automata
35/40
Example
Example
Consider again the transition function (and the transition function
of the DFA):
g
s0
s1
s2
a
u1 ∧ u2
u1 ∧ u2
1
b
u1
u1 ∨ u2
u1
State
q0
q1
q2
q3
a
q1
q1
q1
q3
b
q0
q2
q3
q3
This gives the following representation (compared to the DFA):
g
s0
s1
s2
Matthias Hengel
a
((11), (11))
((11), (11))
((00), (00))
b
((10), (10))
((10), (10)), ((01), (01))
((10), (10))
Alternating Finite Automata
35/40
Example: 232 state DFA
A DFA A with 232 states can be represented as an AFA A0
with 32 states
The transition function g of A0 can be represented as a
32 × |Σ|-Matrix, where Σ is the input alphabet of A and A0
Every entry of the matrix representation of g can be
represented as a List of pairs of integers
All this results in an efficient way for representing DFAs
Matthias Hengel
Alternating Finite Automata
36/40
Example: 232 state DFA
A DFA A with 232 states can be represented as an AFA A0
with 32 states
The transition function g of A0 can be represented as a
32 × |Σ|-Matrix, where Σ is the input alphabet of A and A0
Every entry of the matrix representation of g can be
represented as a List of pairs of integers
All this results in an efficient way for representing DFAs
Matthias Hengel
Alternating Finite Automata
36/40
Example: 232 state DFA
A DFA A with 232 states can be represented as an AFA A0
with 32 states
The transition function g of A0 can be represented as a
32 × |Σ|-Matrix, where Σ is the input alphabet of A and A0
Every entry of the matrix representation of g can be
represented as a List of pairs of integers
All this results in an efficient way for representing DFAs
Matthias Hengel
Alternating Finite Automata
36/40
Example: 232 state DFA
A DFA A with 232 states can be represented as an AFA A0
with 32 states
The transition function g of A0 can be represented as a
32 × |Σ|-Matrix, where Σ is the input alphabet of A and A0
Every entry of the matrix representation of g can be
represented as a List of pairs of integers
All this results in an efficient way for representing DFAs
Matthias Hengel
Alternating Finite Automata
36/40
Conclusion
Matthias Hengel
Alternating Finite Automata
37/40
Conclusion
AFAs are an efficient way to represent DFAs
It is even more efficient using a bit-wise representation of the
transition function
Furthermore:
Operations like the star operation, concatenation or reversal
can also be implemented more efficiently
Matthias Hengel
Alternating Finite Automata
38/40
Conclusion
AFAs are an efficient way to represent DFAs
It is even more efficient using a bit-wise representation of the
transition function
Furthermore:
Operations like the star operation, concatenation or reversal
can also be implemented more efficiently
Matthias Hengel
Alternating Finite Automata
38/40
Conclusion
AFAs are an efficient way to represent DFAs
It is even more efficient using a bit-wise representation of the
transition function
Furthermore:
Operations like the star operation, concatenation or reversal
can also be implemented more efficiently
Matthias Hengel
Alternating Finite Automata
38/40
Literatur I
Champarnaud, Jean-Marc, Denis Maurel und
Djelloul Ziadi (Herausgeber): Automata Implementation,
Third International Workshop on Implementing Automata,
WIA’98, Rouen, France, September 17-19, 1998, Revised
Papers, Band 1660 der Reihe Lecture Notes in Computer
Science. Springer, 1999.
Huerter, Sandra, Kai Salomaa, Xiuming Wu und
Sheng Yu: Implementing Reversed Alternating Finite
Automaton (r-AFA) Operations.
In: Champarnaud, Jean-Marc et al. [CMZ99], Seiten
69–81.
Salomaa, Kai, Xiuming Wu und Sheng Yu: Efficient
Implementation of Regular Languages Using R-AFA.
In: Wood, Derick und Sheng Yu [WY98], Seiten 176–184.
Matthias Hengel
Alternating Finite Automata
39/40
Literatur II
Wood, Derick und Sheng Yu (Herausgeber): Automata
Implementation, Second International Workshop on
Implementing Automata, WIA ’97, London, Ontario, Canada,
September 18-20, 1997, Revised Papers, Band 1436 der Reihe
Lecture Notes in Computer Science. Springer, 1998.
Yu, Sheng: Regular languages, Band 1 der Reihe Handbook
of formal languages, Seiten 41–110.
Springer-Verlag New York, Inc., New York, NY, USA, 1997.
Matthias Hengel
Alternating Finite Automata
40/40