Closure under the Regular Operations
Application of NFA Now we use the NFA to show that collection of regular languages is closed under regular operations union, concatenation, and star Earlier we have shown this closure for union using a Cartesian product of DFA For uniformity reason we reconstruct that proof using NFA
Theorem 1.22 The class of regular languages is closed under the union operation Proof idea: Let regular languages A 1 and A 2 be recognized by NFA N 1 and N 2, respectively To show that A 1 A 2 is regular we will construct an NFA N that recognizes A 1 A 2 N must accept its input if either N 1 or N 2 accepts its input. Hence, N must have a new state that will allow it to guess nondeterministically which of N 1 or N 2 accepts it Guessing is implemented by ɛ transitions from the new state to the start states of N 1 and N 2, as seen in Figure 1
An NFA recognizing A 1 A 2 N N 1 ɛ ɛ N 2 Figure 1: Construction of N to recognize A 1 A 2
Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1), and N 2 = (Q 2, Σ, δ 2, q 2 0, F 2) Construct N = (Q, Σ, δ, q 0, F ) to recognize A 1 A 2 using the following procedure:
Construction procedure 1. Q = {q 0 } Q 1 Q 2 : That is, the states of N are all states on N 1 and N 2 with the addition of a new state q 0 2. The start state of N is q 0 3. The accept states of N are F = F 1 F 2 : That is, the accept states of N are all the accept states of N 1 and N 2 4. Define δ so that for any q Q and any a Σ ɛ : δ(q, a) = δ 1 (q, a), if q Q 1 δ 2 (q, a), if q Q 2 {q0, 1 q0}, 2 if q = q 0 and a = ɛ, if q = q 0 and a ɛ.
Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w begins with 1 and ends with 0} B = {w w contains at least three 1} C = {w w = x0101y, x, y Σ } D = {w w does not contain the substring 110} Use the construction given in the proof of theorem 1.22 to give the state diagrams recognizing the languages A B and C D.
Theorem 1.23 The class of regular languages is closed under concatenation operation Proof idea: Assume two regular languages, A 1 and A 2 recognized by NFAs N 1 and N 2, respectively. Construct N as suggested in Figure 2
Construction of NFA N N 1 N 2 N ɛ ɛ ɛ Figure 2: Construction of N to recognize A 1 A 2
Construction procedure Combine N 1 and N 2 into a new automaton N that starts in the start state of N 1 Add ɛ transitions from the accept states of N 1 to the start state of N 2 Set accept states of N to be the accept states on N 2
Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1) recognize A 1 and N 2 = (Q 2, Σ, δ 2, q 2 0, F 2) recognize A 2. Construct N = (Q, Σ, δ, q 1 0, F 2) by the following procedure:
Construction procedure 1. Q = Q 1 Q 2. The states of N are all states of N 1 and N 2 2. The start state is the state q0 1 of N 1 3. The accept states is the set F 2 of the accept states of N 2 4. Define δ so that for any q Q and any a Σ ɛ : δ 1 (q, a), if q Q 1 and q F 1 δ 1 (q, a), if q F 1 and a ɛ δ(q, a) = δ 1 (q, a) {q0}, 2 if q F 1 and a = ɛ δ 2 (q, a), if q Q 2.
Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w 5} B = {w every odd position of w is 1} C = {w w contains at least three 1} D = {ɛ} Use the construction given in the proof of theorem 1.23 to give the state diagrams recognizing the languages A B and C D where is concatenation operator.
Theorem 1.24 The class of regular languages is closed under star operation Proof idea: we have a regular language A 1, recognized by the NFA N 1 and want to prove that A 1 is also a regular language. The procedure to prove this theorem is by construction of the NFA N that recognizes A 1 as shown in Figure 3
Procedure for the construction of N N N 1 ɛ ɛ ɛ Figure 3: Construction of N to recognize A 1
More on the proof idea N is like N 1 with a new start state and an ɛ transition from the new start state to q 1 Since ɛ A 1 the new start state is an accepts state We add ɛ transitions from the previous accept states of N 1 to the start state of N 1 allowing the machine to read and recognize strings of the form w 1... w k where w 1,..., w k A 1
Proof Let N 1 = (Q 1, Σ, δ 1, q 1 0, F 1) recognize A 1. Construct N = (Q, Σ, δ, q 0, F ) by the procedure:
Construction procedure 1. Q = {q 0 } Q 1 ; that is, states of N are the states of N 1 plus a new state q 0 2. Start state if N is q 0 3. F = {q 0 } F 1 ; that is, the accept states of N are the accept states of N 1 plus the new start state 4. Define δ so that for any q Q and a Σ ɛ : δ(q, a) = δ 1 (q, a), if q Q 1 and q F 1 δ 1 (q, a), δ 1 (q, a) {q0}, 1 if q F 1 and a ɛ if q F 1 and a = ɛ {q0}, 1 if q = q 0 and a = ɛ, if q = q 0 and a ɛ.
Application Consider the alphabet Σ = {0, 1} and the languages: A = {w w contains at least three 1s} B = {w w contains at least two 0s and at most one 1} C = {ɛ} Use the construction given in the proof of theorem 1.24 to give the state diagrams recognizing the languages A, B and C.
Closure under complementation We show here that class of regular languages is closed under complementation. For that we will first show that if M is a DFA that recognizes a language B, swapping the accept and non-accept states in M yields a new DFA that recognizes the complement of B.
Proof Let M be the DFA M with accept and non-accept states swapped. We will show that M recognizes the complement of B 1. Suppose M accept x, i.e., if we run M on x we end in an accept state of M 2. Because M and M have swapped accept/non-accept states, if we run M on x we would end in a non-accept state. Hence, x B 3. Similarly, if x is not accepted by M, it would be accepted by M Consequently, M accepts those strings that are not accepted by M and therefore M recognizes the complement of B.
Conclusion B has been an arbitrary regular language. Therefore, our construction shows how to build an automaton to recognize its complement Hence, the complement of any regular language is also regular Consequently the class of regular languages is closed under complementation
Interesting property If M is an NFA that recognizes language C, swapping its accept and non-accept states doesn t necessarily yield a new NFA that recognizes the complement of C.
Proof: We prove the interesting property by constructing a counter-example. Consider the construction in Figure 4, where both NFA-s, M and M, accept a a 1 a,b 2 a 1 a,b 2 b b Figure 4: NFAs M and M
Question Is the class of languages recognized by NFAs closed under complementation?
Note If we swap the accept and non-accept states of the NFA in Figure 4 the string a is still accepted.
Closure under complementation The class of languages recognized by NFA is still closed under complementation This follows from the fact that the class of languages recognized by NFAs is precisely the class of languages recognized by DFA The counter-example in Figure 4 shows the difference between the process of computations performed by DFAs and NFAs
Transducers
Transducers Transducers are DFA that produce output Since transducers have interesting applications in natural language processing I decided to present them to this class though they are not discussed by Sipser We follow Fleck s book to present transducers
Adding output Transducers regard the input to a DFA as being transformed by the machine into the output. This may be considered as a more realistic model of computation than simple acceptance or rejection. We will observe that adding output to the DFA amounts to extending the model of computation. However, the difference between DFAs and transducers is in fact quite small
Transition systems Definition: A deterministic transition system, DTS, is a triple T = (Q, Σ, δ), where Q is a finite set of states, Σ is an alphabet, and δ : Q Σ Q is the transition function Note: the set of states is regarded here as the memory of computation A DTS captures the way memory configurations of a computation device change when a single input symbol is presented to it The memory (states) permit the model to retain information about its past input, and this may affect the reaction to later input symbols Observation: in a real computer the states are mappings from variables to values while transitions are operators (instructions) mapping states to states
Extending δ If T = (Q, Σ, δ) is a DTS then δ : Q Σ Q is defined inductively for all q Q by: δ (q, ɛ) = q; For all w Σ and x Σ, δ (q, wx) = δ(δ (q, w), x)
Example 1: Take Q = {q 0, q 1, q 2 } and Σ = {0, 1}. Define δ by the Table: δ 0 1 q 0 q 0 q 1 q 1 q 2 q 1 q 2 q 2 q 2 That is: δ(q 0, 0) = q 0, δ(q 0, 1) = q 1, δ(q 1, 0) = q 2, δ(q 1, 1) = q 1, δ(q 2, 0) = q 2, δ(q 2, 1) = q 2. The transition diagram of this system is in Figure 1
Transition diagram 0 q 0 1 1 q 1 0 q 2 0, 1 Figure 1: Example transition system Essentials: Transition function show how states change. δ is described by edges and records the next state δ is described by paths, i.e., sequence of edges.
Deterministic finite acceptor The concept of a deterministic finite acceptor is the same as the concept of deterministic finite automaton, DFA. Using the notion of transition system, a DFA A is defined by the 5-tuple A = (Q, Σ, δ, q 0, F ) where 1. (Q, Σ, δ) is a DTS 2. q 0 Q is the start state 3. F Q is the set of accepting states
Using transition diagrams The transition diagram of a DFA differ from the transition diagram of a DTS, see Figure 2, by: 1. q 0 is marked by an arrow from nowhere; 2. states in F are double-circled. 0 q 0 1 1 q 1 0 q 2 0, 1 Figure 2: Example transition system
Transducers Definition: A transducer M is a 6-tuple M = (Q, Σ,, δ, ρ, q 0 ) where: 1. (Q, Σ, δ) is a deterministic transition system 2. is a finite non-empty set called the output alphabet 3. q 0 Q is the start state 4. ρ : Q Σ is the output function Note: termination occurs when all input has been consumed Note: Transducers are called by Fleck Deterministic Generalized Sequential Machines (DGSM)
Extending ρ Here we extend ρ : Q Σ to ρ : Q Σ by: ρ (q, ɛ) = ɛ, for each q Q ρ (q, wx) = ρ (q, w)ρ(δ (q, w), x) for all w Σ and x Σ Note: this allows us to regard M as defining a function M : Σ, namely, M(w) = ρ (q 0, w) and refer to it as DGSM function.
DGSM Computation Computation performed by a transducer parallels that of a DFA except that there is a sequence of outputs as well as a sequence of states Since ρ captures exactly this information we do not formalize this notion Note: a transducer terminates when all symbols of the output are consumed.
Example transducer Consider the transducer M = (Q, Σ,, δ, ρ, q 0 ) where Σ = = {a, b} which copies its input to its output while deleting the second occurrence (if any) of the symbol a. Note: The state diagram of this machine is in Figure 3 The arrows are labeled by y/x where y Σ is the input and x is the output
Transition diagram of M q 0 b/b a/a q 1 b/b a/ɛ a/a, b/b q 2 Figure 3: Example transition system
Note This machine copies b"s in state q 0 until first a"occurs. When first a" occurs, M copies it to the output and then goes to state q 1. In this state it copies b"s to output until first a" occurs. When first a" occurs in state q 1 the machine removes it and goes to state q 2 where it copies all input to output. Note: here we need output of length 0; this justifies the usage of ρ (the length of any symbol in the alphabet is 1)
Example 2: In this example Σ = = {0, 1, #} and the DGSM M 2 computes the odd parity, i.e., it transforms w# where w {0, 1} into wπ#, π {0, 1} such that the sequence wπ contains an odd numbers of 1s, Figure 4. 0/0, #/1# 1/1 q 0 1/1 0/0, #/0# q 1 Figure 4: DGSM M 2 computing odd parity
Interpretation M 2 is in state q 0 whenever input has even parity and it is in state q 1 whenever input has an odd parity When the output # (i.e., end of string) is encountered in state q 0 the machine adds 1 to the output thus making it of the odd parity When the output # is encountered in state q 1 the machine adds a 0 to the output thus maintaining the odd parity
Note With DFA our interest is in the language a DFA D recognizes With transducers our interest is in the function f : Σ a transducer M computes
Extensible functions Definition: A function f : Σ is called extendible if f(ɛ) = ɛ and for each x, y Σ, there is z so that f(xy) = f(x)z Note: For an extendible function, results of the function acting on prefixes of an argument occur as prefixes of the result of a longer argument This captures the DGSM characteristic of output accumulating as input is processed from left to right
Observations Functions realized by DGSMs are always extendible, i.e., x, y Σ M(xy) = ρ (q 0, xy) = ρ (q 0, x)ρ (δ (q 0, x), y) = M(x)z Consequently, if a string-to-string function is not extendible, it is not computable by a DGSM But not all extendible functions are computable by DGSM
Example 3: Consider the function : {a, b} {0} defined by: f(x) = 0 k where x contains k a"s Note: if f(xy) = 0 m then xy contains m a"s and so f(x) = 0 k, k m. Hence, f(xy) = 0 k 0 m k, i.e., f(xy) = f(x)0 m k and thus f is extendible
Example 4 Consider the function f : {a, b} {0, 1} defined by: 0 k, if x contains k more a"s than b"s f(x) = 1 k, if x contains k more b"s than a"s ɛ, if x contains the same number of a"s and b"s. Since f(a) = 0 while f(ab) = ɛ and ɛ f(a)z for every z, it results that f is not extendible
Note For a given extendible function f and string x, for each string y the string z (whose existence is guaranteed by the definition, f(xy) = f(x)z) is uniquely determined by y Hence: f(x) and f(xy) are uniquely determined
Conclusion There can be only one z that can satisfy the extensibility conditions. That is, with f and x fixed, z is a function of y.
Derived function Given an extendible function f : Σ and x Σ, the function f x : Σ defined by: y Σ [f x (y) = z if f(xy) = f(x)z] is the derived function associated to f Note: if f is extendible then: x, y Σ [f(xy) = f(x)f x (y)] Since Σ is infinite there is a potential for infinite many derived functions associated to f However, it may also be that f x1 = f x2 even though x1 x2
Definition An extendible function f : Σ is said to be of finite index if its set of distinct derived function {f x x Σ } is finite. Cardinality of {f x x Σ } is called the index of f; f is of infinite index if {f x x Σ } =
Example 1 Construct the derived function of the identity id : Σ Σ defined by x Σ [id(x) = x]. Since id(xy) = id(x)y, id is extendible. Since id x = id for all x Σ, i.e., id x (y) = y = id(y), the index of id is 1 That is, id is of finite index
Example 2 Construct the derived function of the unit delay function f : {0, 1} {0, 1} defined by: f(ɛ) = ɛ, f(w 1 w 2... w k ) = w 1 w 2... w k 1, for k 1 and w i Σ, 1 i k. f(w 1 ) = ɛ, f(w 1 w 2 ) = w 1, etc., and f is clearly extendible There are only three distinct derived functions for f: 1. f(0) = f(1) = ɛ and x, y Σ, and y ɛ, f(0y) = 0f(y) from the definition of f 2. f(0y) = f(0)f 0 (y) by extensibility condition, so f 0 (y) = 0f(y); 3. Since f(x0y) = x0f(y) and f(x0y) = f(x0)f x0 (y) = xf x0 (y) this implies f x0 (y) = 0f(y), i.e., x Σ [f x0 = f 0 ]; 4. Similarly, x Σ [f x1 = f 1 ] and f ɛ = f That is {f x x Σ } = {f ɛ, f 0, f 1 }
Fundamental results If f : Σ is extendible then f ɛ = f and x Σ [f x (ɛ) = ɛ] A function f : Σ is a DGSM function iff it is extendible and of finite index If M is a DGSM and L Σ is regular then M(L) is regular See proof in Fleck, pages 143 147