跳到主要内容

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

Author

zephyr

Description

Let Σ1={a,b}\Sigma_1 = \{a, b\} and Σ2={t,f}\Sigma_2 = \{t, f\}. For a word wΣ1w \in \Sigma_1^*, we write w|w| for the length of ww. We also write ϵ\epsilon for the empty word (i.e., the word of length 0). For a word wΣ1w \in \Sigma_1^*, we define the function fwΣ1Σ2f_w \in \Sigma_1^{*} \to \Sigma_2^{*} by:

fw(w)={x1xwΣ2xi={tif w=uwv for some u,vΣ1 such that u=i1fotherwise for each i{1,,w}}.f_w(w') = \{x_1 \cdots x_{|w'|} \in \Sigma_2^{*} \mid x_i = \begin{cases} t & \text{if } w' = uwv \text{ for some } u, v \in \Sigma_1^* \text{ such that } |u| = i - 1 \\ f & \text{otherwise} \end{cases} \text{ for each } i \in \{1, \ldots, |w'|\} \}.

In other words, fw(w)f_w(w') is the word obtained from ww' by replacing the start position of each subword that matches ww with tt and any other position with ff. For example, faa(baaab)=fttfff_{aa}(baaab) = fttff and fab(abbab)=tttttf_{ab}(abbab) = ttttt. Furthermore, we extend the function fwf_w to the function fwf_w^* that maps a language over Σ1\Sigma_1 to a language over Σ2\Sigma_2 by the following definition:

fw(L)={fw(w)wL}.f_w^*(L) = \{f_w(w') \mid w' \in L \}.

For example, fab({(abb)nn0})={(tff)nn0}f_{ab}^* (\{(abb)^n \mid n \geq 0 \}) = \{(tff)^n \mid n \geq 0 \}.

Answer the following questions.

(1) Compute faba(babababa)f_{aba}(babababa).

(2) Express faba(Σ1)f_{aba}(\Sigma_1^*) by using a regular expression.

(3) Suppose that a word wΣ1w \in \Sigma_1^* (where w>0|w| > 0) and a deterministic finite automaton A=(Q,Σ1,δ,q0,F)A = (Q, \Sigma_1, \delta, q_0, F) are given, and that LL is the language accepted by AA. Here, Q,Σ1,δ,q0,FQ, \Sigma_1, \delta, q_0, F are respectively the set of states, the transition function, the initial state, and the set of accepting states of AA. Assume that the transition function δQ×Σ1Q\delta \in Q \times \Sigma_1 \to Q is total. Give a non-deterministic finite automaton that accepts fw(L)f_w^*(L), with a brief explanation. You may use ϵ\epsilon-transitions.

(4) If the following proposition is true, then give a proof sketch (it suffices to show a pushdown automaton that accepts fw(L)f_w^*(L) or a context-free grammar that generates fw(L)f_w^*(L), with a brief explanation). Otherwise, give a counterexample.

Proposition: "For every word wΣ1w \in \Sigma_1^*, if LΣ1L \subseteq \Sigma_1^* is a context-free language, then fw(L)f_w^*(L) is also a context-free language."


Σ1={a,b}\Sigma_1 = \{a, b\}Σ2={t,f}\Sigma_2 = \{t, f\}。对于一个单词 wΣ1w \in \Sigma_1^*,我们用 w|w| 表示 ww 的长度。我们也用 ϵ\epsilon 表示空字(即长度为 0 的字)。对于一个单词 wΣ1w \in \Sigma_1^*,我们定义函数 fwΣ1Σ2f_w \in \Sigma_1^* \to \Sigma_2^{*} 如下:

fw(w)={x1xwΣ2xi={tif w=uwv for some u,vΣ1 such that u=i1fotherwise for each i{1,,w}}.f_w(w') = \{x_1 \cdots x_{|w'|} \in \Sigma_2^{*} \mid x_i = \begin{cases} t & \text{if } w' = uwv \text{ for some } u, v \in \Sigma_1^* \text{ such that } |u| = i - 1 \\ f & \text{otherwise} \end{cases} \text{ for each } i \in \{1, \ldots, |w'|\} \}.

换句话说,fw(w)f_w(w') 是从 ww' 获得的单词,通过用 tt 替换每个匹配 ww 的子单词的起始位置,并用 ff 替换其他任何位置。例如,faa(baaab)=fttfff_{aa}(baaab) = fttfffab(abbab)=tttttf_{ab}(abbab) = ttttt。此外,我们将函数 fwf_w 扩展为函数 fwf_w^*,该函数将 Σ1\Sigma_1 上的语言映射到 Σ2\Sigma_2 上的语言,定义如下:

fw(L)={fw(w)wL}.f_w^*(L) = \{f_w(w') \mid w' \in L \}.

例如,fab({(abb)nn0})={(tff)nn0}f_{ab}^* (\{(abb)^n \mid n \geq 0 \}) = \{(tff)^n \mid n \geq 0 \}

回答以下问题。

(1) 计算 faba(babababa)f_{aba}(babababa)

(2) 使用正则表达式表示 faba(Σ1)f_{aba}(\Sigma_1^*)

(3) 假设一个单词 wΣ1w \in \Sigma_1^*(其中 w>0|w| > 0)和一个确定性有限自动机 A=(Q,Σ1,δ,q0,F)A = (Q, \Sigma_1, \delta, q_0, F) 已给出,且 LLAA 接受的语言。这里,Q,Σ1,δ,q0,FQ, \Sigma_1, \delta, q_0, F 分别是状态集、转移函数、初始状态和接受状态集。假设转移函数 δQ×Σ1Q\delta \in Q \times \Sigma_1 \to Q 是完全的。给出一个接受 fw(L)f_w^*(L) 的非确定性有限自动机,并简要解释。您可以使用 ϵ\epsilon-转换。

(4) 如果以下命题为真,则给出一个证明草图(证明接受 fw(L)f_w^*(L) 的下推自动机或生成 fw(L)f_w^*(L) 的上下文无关文法即可,简要说明)。否则,给出一个反例。

命题:“对于每个单词 wΣ1w \in \Sigma_1^*,如果 LΣ1L \subseteq \Sigma_1^* 是一个上下文无关语言,则 fw(L)f_w^*(L) 也是一个上下文无关语言。”

Kai

(1)

Let's analyze the string babababa and mark the positions where "aba" appears as a subword:

b a b a b a b a
^ ^ ^
^ ^ ^
^ ^ ^

Now, let's replace these starting positions with 't' and the rest with 'f':

faba(babababa)=ftftftfff_{aba}(babababa) = ftftftff

(2)

To construct this regular expression, we need to consider all possible ways aba can appear in a string:

  1. The string might start with aba: (tf)(tf)^*
  2. There might be any number of a's or b's before ab: (ftf)(f^*tf)^*
  3. The string might end with any number of a's or b's: ff^*

Combining these, we get:

(ftf)f(f^*tf)^*f^*

Therefore, fab(Σ1)=(ftf)ff_{ab}(\Sigma_1^*) = (f^*tf)^*f^*

(3)

Let A=(Q,Σ1,δ,q0,F)A = (Q, \Sigma_1, \delta, q_0, F) be the given DFA that accepts LL. Let wnΣ1w_n \in \Sigma_1 be the nn-th figure of word ww. We can construct an NFA A=(Q,Σ2,δ,q0,F)A' = (Q', \Sigma_2, \delta', q_0', F') that accepts fw(L)f_w^*(L) as follows:

  1. Q=Q×{0,1,,w}Q' = Q \times \{0, 1, …, |w|\}
  2. q0=(q0,0)q_0' = (q_0, 0)
  3. F={(q,i)qF,0iw}F' = \{(q, i) \mid q \in F, 0 \leq i \leq |w|\}
  4. For the transition function δ\delta':
    • For each (q,i)Q(q, i) \in Q' and λΣ1\lambda \in \Sigma_1:
      • If i<wi < |w| and λ=wi+1\lambda = w_{i+1}:
        • Add ϵ\epsilon-transition from (q,i)(q, i) to (δ(q,λ),i+1)(\delta(q, \lambda), i+1)
      • If i<wi < |w| and λwi+1\lambda \neq w_{i+1}:
        • Add ff-transition from (q,i)(q, i) to (δ(q,λ),0)(\delta(q, \lambda), 0)
      • If i=wi = |w|:
        • Add tt-transition from (q,i)(q, i) to (δ(q,λ),0)(\delta(q, \lambda), 0)

This NFA simulates the DFA AA while keeping track of potential matches of ww during each of the transitions in AA. When a complete match is found, it accepts 't', otherwise 'f'.

(4)

This proposition is true. We can prove it by constructing a pushdown automaton (PDA) that accepts fw(L)f_w^*(L), using a similar approach to the NFA construction in Question 3.

Proof Sketch: Let M=(Q,Σ1,Γ,δ,q0,Z0,F)M = (Q, \Sigma_1, \Gamma, \delta, q_0, Z_0, F) be a PDA that accepts LL. Let wnΣ1w_n \in \Sigma_1 be the nn-th symbol of word ww. We can construct a PDA M=(Q,Σ2,Γ,δ,q0,Z0,F)M' = (Q', \Sigma_2, \Gamma, \delta', q_0', Z_0, F') that accepts fw(L)f_w^*(L) as follows:

  1. Q=Q×{0,1,,w}Q' = Q \times \{0, 1, …, |w|\}
  2. q0=(q0,0)q_0' = (q_0, 0)
  3. F={(q,i)qF,0iw}F' = \{(q, i) \mid q \in F, 0 \leq i \leq |w|\}
  4. For the transition function δ\delta':
    • For each ((q,i),λ,γ)Q×(Σ2{ϵ})×Γ((q, i), \lambda, \gamma) \in Q' \times (\Sigma_2 \cup \{\epsilon\}) \times \Gamma:
      • If i<wi < |w| and λ=wi+1\lambda = w_{i+1}:
        • For each (p,α)δ(q,λ,γ)(p, \alpha) \in \delta(q, \lambda, \gamma), add ((p,i+1),α)((p, i+1), \alpha) to δ((q,i),ϵ,γ)\delta'((q, i), \epsilon, \gamma)
      • If i<wi < |w| and λwi+1\lambda \neq w_{i+1}:
        • For each (p,α)δ(q,λ,γ)(p, \alpha) \in \delta(q, \lambda, \gamma), add ((p,0),α)((p, 0), \alpha) to δ((q,i),f,γ)\delta'((q, i), f, \gamma)
      • If i=wi = |w| and a=ta = t:
        • For each λΣ1\lambda \in \Sigma_1 and (p,α)δ(q,λ,γ)(p, \alpha) \in \delta(q, \lambda, \gamma), add ((p,0),α)((p, 0), \alpha) to δ((q,i),t,γ)\delta'((q, i), t, \gamma)

Explanation:

  • Similar to the NFA construction in Question 3, the state (q,i)(q, i) represents that we are in state qq of the original PDA and have matched ii symbols of ww.
  • The ϵ\epsilon-transitions simulate the original PDA's transitions for matching the next symbol of ww.
  • The ff-transition occurs for positions where ww is not matched, resetting the match counter to 0.
  • The tt-transition occurs when we complete a match of ww, also resetting the match counter to 0.

This PDA MM' simulates the computations of MM while keeping track of occurrences of ww and outputting the corresponding string in Σ2\Sigma_2^*. Therefore, fw(L)f_w^*(L) is context-free.

Note: The key difference between this construction and the one in Question 3 is that we're now working with a PDA instead of a DFA, which allows us to handle the stack operations necessary for context-free languages. However, the core idea of tracking partial matches of ww remains the same.

Knowledge

DFA NFA PDA 正则表达式 上下文无关语言 下推自动机

难点思路

  1. 理解函数 fwf_wfwf_w^* 的定义及其在字符串和语言上的作用。
  2. 构造接受 fw(L)f_w^*(L) 的非确定性有限自动机,需要巧妙地结合原 DFA 和模式匹配。
  3. 将 NFA 构造的思路扩展到 PDA,以证明 fw(L)f_w^*(L) 的上下文无关性。

解题技巧和信息

  1. 在处理形式语言问题时,尝试从简单的例子开始,然后推广到一般情况。
  2. 在构造自动机或文法时,考虑如何将问题的不同方面(如这里的 PDA 转换和模式匹配)结合起来。
  3. 对于复杂的语言操作,考虑如何使用现有的形式语言工具(如 NFA、PDA)来模拟这些操作。
  4. 注意识别问题之间的联系,如第三问和第四问之间的关系,可以帮助简化解题过程。
  5. 在扩展 NFA 到 PDA 时,要注意保持状态转换的基本结构,同时增加对栈操作的处理。

重点词汇

  • deterministic finite automaton (DFA) 确定性有限自动机
  • non-deterministic finite automaton (NFA) 非确定性有限自动机
  • pushdown automaton (PDA) 下推自动机
  • context-free grammar (CFG) 上下文无关文法
  • regular expression 正则表达式
  • ϵ\epsilon-transition ϵ\epsilon-转换

参考资料

  1. Introduction to Automata Theory, Languages, and Computation by John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman. Chapter 2 (Finite Automata), Chapter 3 (Regular Expressions and Languages), Chapter 5 (Context-Free Grammars and Languages), Chapter 6 (Pushdown Automata)
  2. Formal Languages and Automata Theory by C. K. Nagpal. Chapters on Regular Languages, Context-Free Languages, and Pushdown Automata