跳到主要内容

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

Author

zephyr, 祭音Myyura

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) 也是一个上下文无关语言。”

题目描述

Σ1={a,b}\Sigma_1=\{a,b\}Σ2={t,f}\Sigma_2=\{t,f\}w|w| 表示字符串长度, ε\varepsilon 为空串。对固定 wΣ1w\in\Sigma_1^*,定义 fw:Σ1Σ2f_w:\Sigma_1^*\to\Sigma_2^*:对输入 ww' 的每个位置 i=1,,wi=1,\ldots,|w'|,若 ww 从该位置开始作为 ww' 的子串出现,则输出第 ii 位为 tt,否则为 ff。例如 faa(baaab)=fttfff_{aa}(baaab)=fttfffab(abbab)=tttttf_{ab}(abbab)=ttttt。对语言 LΣ1L\subseteq\Sigma_1^*,进一步定义

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\ge0\}) =\{(tff)^n\mid n\ge0\}.

回答下列问题。

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

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

(3)给定非空字符串 wΣ1w\in\Sigma_1^* 和 DFA A=(Q,Σ1,δ,q0,F)A=(Q,\Sigma_1,\delta,q_0,F),其中 δ\delta 为全函数,且 AA 识别语言 LL。构造识别 fw(L)f_w^*(L) 的 NFA 并简要说明;允许使用 ε\varepsilon 转移。

(4)判断命题“对每个 wΣ1w\in\Sigma_1^*,若 LΣ1L\subseteq\Sigma_1^* 是上下文无关语言,则 fw(L)f_w^*(L) 也是上下文无关语言”是否成立。若成立,给出证明概要(构造相应 PDA 或 CFG 并简述即可);若不成立,给出反例。

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)

Two occurrences of aba cannot start at consecutive positions, and the last two output symbols are always ff. Conversely, every such output word is realizable. Hence

faba(Σ1)=ε+f+(f+tf)(ε+t)ff.f_{aba}(\Sigma_1^*) =\varepsilon+f+(f+tf)^*(\varepsilon+t)ff.

(3)

Put r=w1r=|w|-1. Construct an ε\varepsilon-NFA whose main states are (q,u)(q,u), where qQq\in Q and uΣ1ru\in\Sigma_1^{\le r} is a buffer of guessed input symbols. Its initial state is (q0,ε)(q_0,\varepsilon).

For each guessed cΣ1c\in\Sigma_1:

  • if u<r|u|<r, take an ε\varepsilon-transition to (δ(q,c),uc)(\delta(q,c),uc);
  • if u=r|u|=r, consume tt when uc=wuc=w, and consume ff otherwise, then move to (δ(q,c),suffixr(uc))(\delta(q,c),\operatorname{suffix}_r(uc)).

From every (q,u)(q,u) with qFq\in F, the automaton may stop guessing and enter a finite chain that consumes fuf^{|u|} and accepts. Thus it guesses some xLx\in L, checks every length-w|w| window, and accepts exactly fw(x)f_w(x). The state set is finite, so this is an NFA for fw(L)f_w^*(L).

(4)

The proposition is true. For wεw\ne\varepsilon, replace the DFA component in (3) by a PDA for LL; the finite buffer is kept in the control state, and the PDA stack is unchanged except when simulating a guessed input symbol. This PDA accepts exactly fw(L)f_w^*(L).

For w=εw=\varepsilon, fw(x)=txf_w(x)=t^{|x|}, which is the homomorphic image obtained by mapping both aa and bb to tt. Context-free languages are closed under homomorphism.

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