Introduction to Alternating Finite Automata - uni-freiburg.de · Outline 1.Accepting with DFAs and...

128
Introduction to Alternating Finite Automata Pascal Raiola July 24th, 2013

Transcript of Introduction to Alternating Finite Automata - uni-freiburg.de · Outline 1.Accepting with DFAs and...

Introduction to Alternating Finite Automata

Pascal Raiola

July 24th, 2013

Outline

1. Accepting with DFAs and NFAs

2. Generalization

3. Alternating finite automata (AFA)

4. Concatenation of two AFAs

Accepting with DFAs

Example: ababa

q1 q2

b b

a

a

Accepting with DFAs

Example: q1ababa

q1 q2

b b

a

a

Accepting with DFAs

Example: aq2baba

q1 q2

b b

a

a

Accepting with DFAs

Example: abq2aba

q1 q2

b b

a

a

Accepting with DFAs

Example: abaq1ba

q1 q2

b b

a

a

Accepting with DFAs

Example: ababq1a

q1 q2

b b

a

a

Accepting with DFAs

Example: ababaq2

q1 q2

b b

a

a

⇒ Not accepted.

Accepting with DFAs

Example: ababaq2

q1 q2

b b

a

a

⇒ Not accepted.

Accepting with NFAs

Example: ababa

q1 q2

b a,b

a

a

Accepting with NFAs

Example: {q1}ababa

q1 q2

b a,b

a

a

Accepting with NFAs

Example: a{q2}baba

q1 q2

b a,b

a

a

Accepting with NFAs

Example: ab{q2}aba

q1 q2

b a,b

a

a

Accepting with NFAs

Example: aba{q1, q2}ba

q1 q2

b a,b

a

a

Accepting with NFAs

Example: abab{q1, q2}a

q1 q2

b a,b

a

a

Accepting with NFAs

Example: ababa{q1, q2}

q1 q2

b a,b

a

a

At least one accepting state ⇒ Accepted.

Accepting with NFAs

Example: ababa{q1, q2}

q1 q2

b a,b

a

a

At least one accepting state ⇒ Accepted.

I NFAs look more general than DFAs,

I but accept the same class of languages.

Can it be even more general?

I NFAs look more general than DFAs,

I but accept the same class of languages.

Can it be even more general?

I NFAs look more general than DFAs,

I but accept the same class of languages.

Can it be even more general?

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Restrictions (NFA)

If we know:

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

and we know

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

Then

q1

q2

q3

⇒ Reading a ⇒

q1

q2

q3

The transition can be more general!

Acceptance condition

I DFAs accept iff the run ends in a final state.

I NFAs accept iff the run ends in a set containing at least onefinal state.

I More general: A function h deciding acceptance for eachsubset of Q:

h : 2Q → {0, 1}

Acceptance condition

I DFAs accept iff the run ends in a final state.

I NFAs accept iff the run ends in a set containing at least onefinal state.

I More general: A function h deciding acceptance for eachsubset of Q:

h : 2Q → {0, 1}

Acceptance condition

I DFAs accept iff the run ends in a final state.

I NFAs accept iff the run ends in a set containing at least onefinal state.

I More general: A function h deciding acceptance for eachsubset of Q:

h : 2Q → {0, 1}

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

An h-AFA/r -AFA is a 5-tuple (Q,Σ, g , h,F ), where

I Q is the finite set of states,

I Σ is the input alphabet,

I g : Q × Σ× 2Q → {0, 1} is the transition function,

I h : 2Q → {0, 1} is the accepting function and

I F ⊆ Q is the set of final states.

I f ∈ {0, 1}Q is the to F corresponding vector, e.g.

Q = {q1, q2, q3, q4, q5},F = {q2, q3}⇒ f = (0 , 1 , 1 , 0 , 0)

Formal definition: h-AFA & r -AFA

I The transition function g : Q × Σ× 2Q → {0, 1} isuniversalized from getting just one letter as an input to awhole word:

I g(q, ε, v) = vqI g(q, aw , v) = g(q, a, g(w , v))

I Notation: g(w , v) := (g(q,w , v))q∈Q .

Formal definition: h-AFA & r -AFA

I The transition function g : Q × Σ× 2Q → {0, 1} isuniversalized from getting just one letter as an input to awhole word:

I g(q, ε, v) = vq

I g(q, aw , v) = g(q, a, g(w , v))

I Notation: g(w , v) := (g(q,w , v))q∈Q .

Formal definition: h-AFA & r -AFA

I The transition function g : Q × Σ× 2Q → {0, 1} isuniversalized from getting just one letter as an input to awhole word:

I g(q, ε, v) = vqI g(q, aw , v) = g(q, a, g(w , v))

I Notation: g(w , v) := (g(q,w , v))q∈Q .

Formal definition: h-AFA & r -AFA

I The transition function g : Q × Σ× 2Q → {0, 1} isuniversalized from getting just one letter as an input to awhole word:

I g(q, ε, v) = vqI g(q, aw , v) = g(q, a, g(w , v))

I Notation: g(w , v) := (g(q,w , v))q∈Q .

Acceptance

An input w is accepted by an h-AFA iff

h(g(w , f )) = 1

and by an r-AFA iff

h(g(wR , f )) = 1.

Acceptance

An input w is accepted by an h-AFA iff

h(g(w , f )) = 1

and by an r-AFA iff

h(g(wR , f )) = 1.

Example: r -AFA

Let A = (Q,Σ, g , h,F ) be an r-AFA with

I Q = {q1, q2},I Σ = {a, b},I F = {q2}, f = (0,1)

I h(q1, q2) = q1 ∨ q2I and g is given by

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

Example: r -AFA

Let A = (Q,Σ, g , h,F ) be an r-AFA with

I Q = {q1, q2},I Σ = {a, b},I F = {q2}, f = (0,1)

I h(q1, q2) = q1 ∨ q2

I and g is given by

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

Example: r -AFA

Let A = (Q,Σ, g , h,F ) be an r-AFA with

I Q = {q1, q2},I Σ = {a, b},I F = {q2}, f = (0,1)

I h(q1, q2) = q1 ∨ q2I and g is given by

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f ))

= h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1

= 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Example: r -AFALet w = ab, then w is accepted by A as follows:

h(g(wR , f )) = h(g(ba, f ))

= h(g(b, g(a, f )))

= h(g(b, g(a, (0, 1))))

= h(g(b, (0 ∨ 1, 0 ∧ 1)))

= h(g(b, (0, 0)))

= h((0 ∧ 0, 0 ∨ 0))

= h((0, 1))

= 0 ∨ 1 = 1

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

h(q1, q2) = q1 ∨ q2, f = (0, 1)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}

I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “DFA ⇒ r-AFA”

Let AD = (QD ,Σ, δ, s,FD) be a DFA. Let AA = (QA,Σ, g , h,FA)be an r-AFA with:

I QA = QD

I FA = {s}I g(q, a, v) = 1 ⇔ ∃p ∈ QD . vp = 1 ∧ δ(p, a) = q

I h(v) = 1 ⇔ ∃q ∈ FD . vq = 1

Then L(AD) = L(AA).

Highly inefficient (see next talk)

Equivalence of DFAs and r-AFAs: “r-AFA ⇒ DFA”:

Let AA = (QA,Σ, g , h,FA) be an r-AFA. The DFAAD = (QD ,Σ, δ, s,FD) is defined as follows:

I QD := {0, 1}QA .

I s := fA.

I g and h as in the next slide.

Equivalence of DFAs and r-AFAs: “r-AFA ⇒ DFA”:

Let AA = (QA,Σ, g , h,FA) be an r-AFA. The DFAAD = (QD ,Σ, δ, s,FD) is defined as follows:

I QD := {0, 1}QA .

I s := fA.

I g and h as in the next slide.

Equivalence of DFAs and r-AFAs: “r-AFA ⇒ DFA”:

Let AA = (QA,Σ, g , h,FA) be an r-AFA. The DFAAD = (QD ,Σ, δ, s,FD) is defined as follows:

I QD := {0, 1}QA .

I s := fA.

I g and h as in the next slide.

Equivalence of DFAs and r-AFAs: “r-AFA ⇒ DFA”:

Let AA = (QA,Σ, g , h,FA) be an r-AFA. The DFAAD = (QD ,Σ, δ, s,FD) is defined as follows:

I QD := {0, 1}QA .

I s := fA.

I g and h as in the next slide.

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Example:

g(a, (q1, q2)) = (q1 ∨ q2, q1 ∧ q2)

g(b, (q1, q2)) = (q1 ∧ q2, q1 ∨ q2)

F = {q2}, h(q1, q2) = q1 ∨ q2

q1 = 0,q2 = 0

q1 = 1,q2 = 0

q1 = 0,q2 = 1

q1 = 1,q2 = 1

a

q1 = 0,q2 = 0

b

q1 = 0,q2 = 1

q1 = 0,q2 = 0

a

q1 = 1,q2 = 1

b

q1 = 0,q2 = 0

And so on...

Equivalence of DFAs and r-AFAs

r-AFAs ∼ regular languages

Regular languages are closed under reversion

⇒ h-AFAs ∼ regular languages

Equivalence of DFAs and r-AFAs

r-AFAs ∼ regular languages

Regular languages are closed under reversion

⇒ h-AFAs ∼ regular languages

Equivalence of DFAs and r-AFAs

r-AFAs ∼ regular languages

Regular languages are closed under reversion

⇒ h-AFAs ∼ regular languages

Concatenation of two r -AFAs

Two r -AFAs:

A1 = (Q1,Σ, g1, h1,F1), A2 = (Q2,Σ, g2, h2,F2)

Target: r-AFA A = (Q,Σ, g , h,F ) with L(A) = L(A1) · L(A2).

Concatenation of two r -AFAs

Two r -AFAs:

A1 = (Q1,Σ, g1, h1,F1), A2 = (Q2,Σ, g2, h2,F2)

Target: r-AFA A = (Q,Σ, g , h,F ) with L(A) = L(A1) · L(A2).

Concatenation of two r-AFAs: Idea

•Zacatecas

bla

Concatenation of two r-AFAs: Idea

Z•acatecas

bla

Concatenation of two r-AFAs: Idea

Za•catecas

bla

Concatenation of two r-AFAs: Idea

Za•catecas •catecas

A1: Za

Concatenation of two r-AFAs: Idea

Zac•atecas c•atecas

A1: Za

Concatenation of two r-AFAs: Idea

Zaca•tecas ca•tecas

A1: Za

Concatenation of two r-AFAs: Idea

Zacat•ecas cat•ecas

A1: Za

Concatenation of two r-AFAs: Idea

Zacat•ecas cat•ecas •ecas

A1: Za A1: Zacat

Concatenation of two r-AFAs: Idea

Zacate•cas cate•cas e•cas

A1: Za A1: Zacat

Concatenation of two r-AFAs: Idea

Zacate•cas cate•cas e•cas •cas

A1: Za A1: Zacat A1: Zacate

Concatenation of two r-AFAs: Idea

Zacatec•as catec•as ec•as c•as

A1: Za A1: Zacat A1: Zacate

Concatenation of two r-AFAs: Idea

Zacateca•s cateca•s eca•s ca•s

A1: Za A1: Zacat A1: Zacate

Concatenation of two r-AFAs: Idea

Zacatecas• catecas• ecas• cas•

A1: Za A1: Zacat A1: Zacate

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel - for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel - for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel

- for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel - for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel - for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Definitions

Let n := |Q1| and m := |Q2|, w.l.o.g m 6= 0 and n 6= 0. Then weneed:

I n states to simulate the one run of A1.

I 2m states to simulate each run in parallel - for each subset ofQ2 we store if there’s a copy of A2 in exactly these states.

Q = {q0, . . . , qn−1︸ ︷︷ ︸n states

, p0, . . . , p2m−1︸ ︷︷ ︸m states

}

Each subset x ∈ 2Q2 is associated to a state px .

Concatenation of two r-AFAs: Where to start?

If ε /∈ L(A1) A should be forced to start with A1: F = F1,

otherwise it can also directly launch a copy of A2,formally:

F = F1 ∪ {pf2}

Concatenation of two r-AFAs: Where to start?

If ε /∈ L(A1) A should be forced to start with A1: F = F1,

otherwise it can also directly launch a copy of A2,

formally:

F = F1 ∪ {pf2}

Concatenation of two r-AFAs: Where to start?

If ε /∈ L(A1) A should be forced to start with A1: F = F1,

otherwise it can also directly launch a copy of A2,formally:

F = F1 ∪ {pf2}

Concatenation of two r-AFAs: Accepting

h has only to care for A2, formally:

h(v) = 1 ⇔ ∃x ∈ [0, 2m − 1]. vn+x︸︷︷︸ px

= 1 ∧ h2(x) = 1

A1: Zacat

Concatenation of two r-AFAs: Accepting

h has only to care for A2, formally:

h(v) = 1 ⇔ ∃x ∈ [0, 2m − 1]. vn+x︸︷︷︸ px

= 1 ∧ h2(x) = 1

A1: Zacat

Concatenation of two r-AFAs: g on the first n states

A has to run A1 on the whole input word without any possibility ofinterruption:

g(a, v)|Q1 = g1(a, v |Q1)

Concatenation of two r-AFAs: g on the last 2m states

Copies of A2 should work parallel on the states pk (k ≥ 0)

⇒ pk should be reached from pjiff

A2 reaches k from j .

formally:

For all k ≥ 0, k 6= f2

g(pk , a, v) = 1 ⇔ ∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = k

Concatenation of two r-AFAs: g on the last 2m states

Copies of A2 should work parallel on the states pk (k ≥ 0)

⇒ pk should be reached from pjiff

A2 reaches k from j .

formally:

For all k ≥ 0, k 6= f2

g(pk , a, v) = 1 ⇔ ∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = k

Concatenation of two r-AFAs: g on the last 2m states

Copies of A2 should work parallel on the states pk (k ≥ 0)

⇒ pk should be reached from pjiff

A2 reaches k from j .

formally:

For all k ≥ 0, k 6= f2

g(pk , a, v) = 1 ⇔ ∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = k

Concatenation of two r-AFAs: g on the last 2m states

Copies of A2 should work parallel on the states pk (k ≥ 0)

⇒ pk should be reached from pjiff

A2 reaches k from j .

formally:

For all k ≥ 0, k 6= f2

g(pk , a, v) = 1 ⇔ ∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = k

Concatenation of two r-AFAs: Special treatment for pf2

The state pf2 can be reached:

I as before and

I if A1 accepts a substring.

Formally:

g(pf2 , a, v) = 1 ⇔ (∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = f2)

∨ h1(g(a, v)|Q1) = 1

Concatenation of two r-AFAs: Special treatment for pf2

The state pf2 can be reached:

I as before and

I if A1 accepts a substring.

Formally:

g(pf2 , a, v) = 1 ⇔ (∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = f2)

∨ h1(g(a, v)|Q1) = 1

Concatenation of two r-AFAs: Special treatment for pf2

The state pf2 can be reached:

I as before and

I if A1 accepts a substring.

Formally:

g(pf2 , a, v) = 1 ⇔ (∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = f2)

∨ h1(g(a, v)|Q1) = 1

Concatenation of two r-AFAs: Special treatment for pf2

The state pf2 can be reached:

I as before and

I if A1 accepts a substring.

Formally:

g(pf2 , a, v) = 1 ⇔ (∃j ∈ [0, 2m − 1]. vn+j = 1 ∧ g2(a, j) = f2)

∨ h1(g(a, v)|Q1) = 1

Concatenation of two r-AFAs

Then L(A) = L(A1) · L(A2).

Sources

Literature:

I Efficient implementation of regular languages using reversedalternating finite automata, K. Salomaa, X. Wu, S. Yu,Theoretical Computer Science, Elsevier, 17 January 2000

I Implementing Reversed Alternating Finite Automaton (r-AFA)Operations, S. Huerter, K. Salomaa, Xiuming Wu, S. Yu

Pictures:

I A1: Larry D. Moore CC BY-SA 3.0.

I A2: Disney/Pixar

Sources

Literature:

I Efficient implementation of regular languages using reversedalternating finite automata, K. Salomaa, X. Wu, S. Yu,Theoretical Computer Science, Elsevier, 17 January 2000

I Implementing Reversed Alternating Finite Automaton (r-AFA)Operations, S. Huerter, K. Salomaa, Xiuming Wu, S. Yu

Pictures:

I A1: Larry D. Moore CC BY-SA 3.0.

I A2: Disney/Pixar

Thank you!

Additional operations: Union and intersection

Acceptance-checking for AFAs allows working with multiple statesin parallel.

⇒ For both the intersection and the union of two AFAs A1 andA2, one can run both AFAs in one AFA A = (Q,Σ, g , h,F ):

I Q = Q1 ∪ Q2

I g(q, a, u) =

{g1(q, a, u|Q1) q ∈ Q1

g2(q, a, u|Q2) q ∈ Q2

I h = h1 ∨ h2 (union) resp. h = h1 ∧ h2 (intersection).

I F = F1 ∪ F2

Additional operations: Union and intersection

Acceptance-checking for AFAs allows working with multiple statesin parallel.⇒ For both the intersection and the union of two AFAs A1 andA2, one can run both AFAs in one AFA A = (Q,Σ, g , h,F ):

I Q = Q1 ∪ Q2

I g(q, a, u) =

{g1(q, a, u|Q1) q ∈ Q1

g2(q, a, u|Q2) q ∈ Q2

I h = h1 ∨ h2 (union) resp. h = h1 ∧ h2 (intersection).

I F = F1 ∪ F2

Additional operations: Union and intersection

Acceptance-checking for AFAs allows working with multiple statesin parallel.⇒ For both the intersection and the union of two AFAs A1 andA2, one can run both AFAs in one AFA A = (Q,Σ, g , h,F ):

I Q = Q1 ∪ Q2

I g(q, a, u) =

{g1(q, a, u|Q1) q ∈ Q1

g2(q, a, u|Q2) q ∈ Q2

I h = h1 ∨ h2 (union) resp. h = h1 ∧ h2 (intersection).

I F = F1 ∪ F2

Additional operations: Union and intersection

Acceptance-checking for AFAs allows working with multiple statesin parallel.⇒ For both the intersection and the union of two AFAs A1 andA2, one can run both AFAs in one AFA A = (Q,Σ, g , h,F ):

I Q = Q1 ∪ Q2

I g(q, a, u) =

{g1(q, a, u|Q1) q ∈ Q1

g2(q, a, u|Q2) q ∈ Q2

I h = h1 ∨ h2 (union) resp. h = h1 ∧ h2 (intersection).

I F = F1 ∪ F2

Additional operations: Complemet

For the complement B of an AFA A, define hB = hA.