跳到主要内容

東京大学 情報理工学系研究科 コンピュータ科学専攻 2020年8月実施 専門科目 問題2

Author

zephyr

Description

Let Σ\Sigma be the set {a,b}\{a, b\} of letters. For a word wΣw \in \Sigma^* and two languages La,LbΣL_a, L_b \subseteq \Sigma^* over Σ\Sigma, we define the language w{aLa,bLb}Σw\{a \mapsto L_a, b \mapsto L_b\} \subseteq \Sigma^* as follows, by induction on ww.

ϵ{aLa,bLb}={ϵ}\epsilon\{a \mapsto L_a, b \mapsto L_b\} = \{\epsilon\}
(aw){aLa,bLb}={w1w2w1La,w2w{aLa,bLb}}(aw)\{a \mapsto L_a, b \mapsto L_b\} = \{w_1 w_2 \mid w_1 \in L_a, w_2 \in w\{a \mapsto L_a, b \mapsto L_b\}\}
(bw){aLa,bLb}={w1w2w1Lb,w2w{aLa,bLb}}(bw)\{a \mapsto L_a, b \mapsto L_b\} = \{w_1 w_2 \mid w_1 \in L_b, w_2 \in w\{a \mapsto L_a, b \mapsto L_b\}\}

Here, ϵ\epsilon represents the empty word. For example, if w=abaw = aba, La={bnn0}L_a = \{b^n \mid n \geq 0\}, and Lb={ann0}L_b = \{a^n \mid n \geq 0\}, then w{aLa,bLb}={blambnl,m,n0}w\{a \mapsto L_a, b \mapsto L_b\} = \{b^l a^m b^n \mid l, m, n \geq 0\}. Furthermore, for languages L,La,LbΣL, L_a, L_b \subseteq \Sigma^*, we define L{aLa,bLb}L\{a \mapsto L_a, b \mapsto L_b\} as wLw{aLa,bLb}\bigcup_{w \in L} w\{a \mapsto L_a, b \mapsto L_b\}. For example, if L={anbn0}L = \{a^n b \mid n \geq 0\}, La={ab}L_a = \{ab\}, and Lb={ann0}L_b = \{a^n \mid n \geq 0\}, then L{aLa,bLb}={(ab)manm,n0}L\{a \mapsto L_a, b \mapsto L_b\} = \{(ab)^m a^n \mid m, n \geq 0\}.

Answer the following questions.

(1) Let L={(ab)manm,n0}L = \{(ab)^m a^n \mid m, n \geq 0\}, La={bb}L_a = \{bb\}, and Lb={ab,a}L_b = \{ab, a\}. Express L{aLa,bLb}L\{a \mapsto L_a, b \mapsto L_b\} using a regular expression.

(2) Let L={ambnmn0}L' = \{a^m b^n \mid m \geq n \geq 0\}, La={ann0}L_a' = \{a^n \mid n \geq 0\}, and Lb={ambmm0}L_b' = \{a^m b^m \mid m \geq 0\}. Express {wΣw{aLa,bLb}L}\{w \in \Sigma^* \mid w\{a \mapsto L_a', b \mapsto L_b'\} \subseteq L'\} using a regular expression.

(3) Let A0=(Q0,Σ,δ0,q0,0,F0)A_0 = (Q_0, \Sigma, \delta_0, q_{0,0}, F_0), A1=(Q1,Σ,δ1,q1,0,F1)A_1 = (Q_1, \Sigma, \delta_1, q_{1,0}, F_1), and A2=(Q2,Σ,δ2,q2,0,F2)A_2 = (Q_2, \Sigma, \delta_2, q_{2,0}, F_2) be deterministic finite automata, and for each i{0,1,2}i \in \{0, 1, 2\}, let LiL_i be the language accepted by AiA_i. Here, Qi,δi,qi,0,FiQ_i, \delta_i, q_{i,0}, F_i are the set of states, the transition function, the initial state, and the set of final states of AiA_i (i{0,1,2}i \in \{0, 1, 2\}), respectively. Assume that the transition functions δiQi×ΣQi\delta_i \in Q_i \times \Sigma \rightarrow Q_i (i{0,1,2}i \in \{0, 1, 2\}) are total. Give a non-deterministic finite automaton that accepts L0{aL1,bL2}L_0 \{a \mapsto L_1, b \mapsto L_2\}, with a brief explanation. You may use ϵ\epsilon-transitions.

(4) For AiA_i and LiL_i (i{0,1,2}i \in \{0, 1, 2\}) in question (3), give a deterministic finite automaton that accepts {wΣw{aL1,bL2}L0}\{w \in \Sigma^* \mid w\{a \mapsto L_1, b \mapsto L_2\} \subseteq L_0\}, with a brief explanation.

题目描述

Σ={a,b}\Sigma=\{a,b\}。对 wΣw\in\Sigma^* 及语言 La,LbΣL_a,L_b\subseteq\Sigma^*,递归定义语言替换:

ε{aLa,bLb}={ε},\varepsilon\{a\mapsto L_a,b\mapsto L_b\}=\{\varepsilon\},
(aw){aLa,bLb}={w1w2w1La,w2w{aLa,bLb}},(aw)\{a\mapsto L_a,b\mapsto L_b\} =\{w_1w_2\mid w_1\in L_a,\quad w_2\in w\{a\mapsto L_a,b\mapsto L_b\}\},
(bw){aLa,bLb}={w1w2w1Lb,w2w{aLa,bLb}}.(bw)\{a\mapsto L_a,b\mapsto L_b\} =\{w_1w_2\mid w_1\in L_b,\quad w_2\in w\{a\mapsto L_a,b\mapsto L_b\}\}.

对语言 LL,再定义

L{aLa,bLb}=wLw{aLa,bLb}.L\{a\mapsto L_a,b\mapsto L_b\} =\bigcup_{w\in L}w\{a\mapsto L_a,b\mapsto L_b\}.

回答下列问题。

(1)令 L={(ab)manm,n0}L=\{(ab)^ma^n\mid m,n\ge0\}La={bb}L_a=\{bb\}Lb={ab,a}L_b=\{ab,a\}。用正则表达式表示 L{aLa,bLb}L\{a\mapsto L_a,b\mapsto L_b\}

(2)令 L={ambnmn0}L'=\{a^mb^n\mid m\ge n\ge0\}La={ann0}L'_a=\{a^n\mid n\ge0\}Lb={ambmm0}L'_b=\{a^mb^m\mid m\ge0\}。用正则表达式表示

{wΣw{aLa,bLb}L}.\{w\in\Sigma^*\mid w\{a\mapsto L'_a,b\mapsto L'_b\}\subseteq L'\}.

(3)设 DFA Ai=(Qi,Σ,δi,qi,0,Fi)A_i=(Q_i,\Sigma,\delta_i,q_{i,0},F_i) 识别语言 Li (i=0,1,2)L_i\ (i=0,1,2),且各 δi\delta_i 均为全函数。构造识别 L0{aL1,bL2}L_0\{a\mapsto L_1,b\mapsto L_2\} 的 NFA 并简要说明;允许使用 ε\varepsilon 转移。

(4)对同一组自动机,构造识别

{wΣw{aL1,bL2}L0}\{w\in\Sigma^*\mid w\{a\mapsto L_1,b\mapsto L_2\}\subseteq L_0\}

的 DFA,并简要说明。

考点

  • 语言替换运算:按原字符串中的字符逐段选择替换语言中的字符串,并化简具体正则表达式。
  • ε\varepsilon-NFA 拼接构造:让外层自动机的每个字符转移调用相应替换语言的自动机。
  • 正则语言闭包性质:通过乘积、子集构造及补集处理“所有替换结果均属于目标语言”的全称条件。

Kai

(1)

Given L={(ab)manm,n0}L = \{(ab)^m a^n \mid m, n \geq 0\}, La={bb}L_a = \{bb\}, and Lb={ab,a}L_b = \{ab, a\}:

L{aLa,bLb}=(bb(ab+a))(bb)L\{a \mapsto L_a, b \mapsto L_b\} = (bb(ab+a))^*(bb)^*

This expression represents the language where every aa in the original language is replaced by bbbb and every bb is replaced by either abab or aa.

(2)

Given L={ambnmn0}L' = \{a^m b^n \mid m \geq n \geq 0\}, La={ann0}L_a' = \{a^n \mid n \geq 0\}, and Lb={ambmm0}L_b' = \{a^m b^m \mid m \geq 0\}, for wΣw \in \Sigma^*, suppose w=w{aLa,bLb}w' = w\{a \mapsto L_a', b \mapsto L_b'\}.

Since wLw' \subseteq L', we can express any element of ww', wiw'_i as axaybya^x a^y b^y where x,y0x, y \geq 0. This implies that ww' contains axa^x followed by aybya^y b^y for some x,y0x, y \geq 0.

Since all of the bb in wiw'_i can only come from bb in ww, we can reverse the substitution process to get w=axbyw = a^x b^y, where yy can only be 00 or 11.

Therefore, the regular expression for {wΣw{aLa,bLb}L}\{w \in \Sigma^* \mid w\{a \mapsto L_a', b \mapsto L_b'\} \subseteq L'\} is:

a(ϵ+b)a^*(\epsilon + b)

(3)

We will construct an NFA that accepts L0{aL1,bL2}L_0 \{a \mapsto L_1, b \mapsto L_2\} using ϵ\epsilon-transitions. The NFA will have the same structure as A0A_0, but the transitions will be replaced based on the input letter with the transitions from A1A_1 and A2A_2, and ϵ\epsilon-transitions will be used to connect the states.

For example, supposing the original transitions for the input letter aa in A0A_0 are q0,0aq0,1q_{0,0} \xrightarrow{a} q_{0,1}, we will replace these transitions with the corresponding transitions from A1A_1:

q0,0ϵq1,0F1,iϵq0,1q_{0,0} \xrightarrow{\epsilon} q_{1,0} \xrightarrow{} \ldots \xrightarrow{} F_{1,i} \xrightarrow{\epsilon} q_{0,1}

Similarly, for the input letter bb, we will replace the transitions with the corresponding transitions from A2A_2.

The final states of the NFA will be those states where the original final states of A0A_0 are reached after the substitution process.

Explanation: Since the language L0{aL1,bL2}L_0 \{a \mapsto L_1, b \mapsto L_2\} is obtained by substituting the strings in L1L_1 and L2L_2 for aa and bb in the strings of L0L_0, the NFA needs to simulate this substitution process by transitioning to the corresponding states in A1A_1 and A2A_2 based on the input letter.

(4)

To construct a DFA for {wΣw{aLi,bLj}Lk}\{w \in \Sigma^* \mid w\{a \mapsto L_i, b \mapsto L_j\} \subseteq L_k\}:

Explanation:

  • We need to track the states of AiA_i, AjA_j, and AkA_k simultaneously.
  • The DFA will have states (qi,qj,qk)(q_i, q_j, q_k), where qiQiq_i \in Q_i, qjQjq_j \in Q_j, and qkQkq_k \in Q_k.
  • The initial state is (qi0,qj0,qk0)(q_{i0}, q_{j0}, q_{k0}).
  • The transition function will be defined as:
    • (qi,qj,qk)a(δi(qi,a),qj,δk(qk,wLi))(q_i, q_j, q_k) \xrightarrow{a} (\delta_i(q_i, a), q_j, \delta_k(q_k, w_{L_i})) for all wLiLiw_{L_i} \in L_i.
    • (qi,qj,qk)b(qi,δj(qj,b),δk(qk,wLj))(q_i, q_j, q_k) \xrightarrow{b} (q_i, \delta_j(q_j, b), \delta_k(q_k, w_{L_j})) for all wLjLjw_{L_j} \in L_j.
  • The final states are those where the third component is a final state in FkF_k.

This DFA ensures that as we read ww, we keep track of the corresponding states in AiA_i, AjA_j, and AkA_k to ensure the substitution process results in strings that belong to LkL_k.

Knowledge

语言替换 正则表达式 NFA DFA

难点解题思路

  1. 语言替换的正则表达式表达形式,需要理解替换过程以及结果语言的模式。
  2. 识别满足特定替换条件的字符串集合,需要考虑原语言和替换后的语言的关系。
  3. 构造非确定性有限自动机 (NFA) 以处理语言替换,需要使用 ϵ\epsilon-transitions 连接不同自动机的状态。
  4. 构造确定性有限自动机 (DFA) 来接受满足条件的字符串集合,需要同时跟踪多个自动机的状态。

解题技巧和信息

  • 在处理语言替换问题时,理解每一步替换过程对最终结果的影响非常重要。
  • 构造 NFA 和 DFA 时,注意状态之间的转换关系以及如何利用 ϵ\epsilon-transitions 连接不同语言的自动机。

重点词汇

  • ϵ\epsilon-transitions: ϵ\epsilon-转换
  • Regular Expression: 正则表达式
  • Non-deterministic Finite Automaton (NFA): 非确定性有限自动机
  • Deterministic Finite Automaton (DFA): 确定性有限自动机

参考资料

  1. Michael Sipser, "Introduction to the Theory of Computation", Chapter 2
  2. John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman, "Introduction to Automata Theory, Languages, and Computation", Chapter 3