跳到主要内容

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

Author

zephyr, 祭音Myyura

Description

Let Σ\Sigma be the set {a,b}\{a, b\} of letters. For a language LΣL \subseteq \Sigma^* over Σ\Sigma, we define Γ(L)\Gamma(L) as follows.

Γ(L)={vΣwΣ(v=wvwL)}.\Gamma(L) = \{v \in \Sigma^* \mid \exists w \in \Sigma^* \cdot (|v| = |w| \land vw \in L)\}.

Here, x|x| denotes the length of the string xx. For example, if L1={aa,ba,abb,abbb}L_1 = \{aa, ba, abb, abbb\}, then Γ(L1)={a,b,ab}\Gamma(L_1) = \{a, b, ab\}.

Answer the following questions.

(1) Let L2={(ab)nn0}L_2 = \{(ab)^n \mid n \geq 0\}. Express Γ(L2)\Gamma(L_2) using a regular expression.

(2) Let L3={anbnambmn0,m0}L_3 = \{a^n b^n a^m b^m \mid n \geq 0, m \geq 0\}. Give a context-free grammar that generates Γ(L3)\Gamma(L_3).

(3) Let M=(Q,Σ,δ,q0,F)\mathcal{M} = (Q, \Sigma, \delta, q_0, F) be a deterministic finite automaton, and let LML_{\mathcal{M}} be the language accepted by M\mathcal{M}. Here, QQ, Σ\Sigma, δ\delta, q0q_0, and FF are the set of states, the transition function, the initial state, and the set of final states of M\mathcal{M}, respectively. You may assume that the transition function δ:Q×ΣQ\delta : Q \times \Sigma \to Q is total. Give a finite automaton that accepts Γ(LM)\Gamma(L_{\mathcal{M}}), with a brief explanation.

(4) If the proposition given below is true, then give how to construct a context-free grammar that generates Γ(L)\Gamma(L), from a context-free grammar that generates LL (you may use push-down automata instead of context-free grammars), with a brief explanation. Otherwise, give a counterexample, with a brief explanation.

Proposition: "For every context-free language LΣL \subseteq \Sigma^*, Γ(L)\Gamma(L) is a context-free language."


Σ\Sigma 为字母集 {a,b}\{a, b\}。对于 Σ\Sigma 上的语言 LΣL \subseteq \Sigma^*,我们定义 Γ(L)\Gamma(L) 如下。

Γ(L)={vΣwΣ(v=wvwL)}.\Gamma(L) = \{v \in \Sigma^* \mid \exists w \in \Sigma^* \cdot (|v| = |w| \land vw \in L)\}.

这里,x|x| 表示字符串 xx 的长度。例如,如果 L1={aa,ba,abb,abbb}L_1 = \{aa, ba, abb, abbb\},那么 Γ(L1)={a,b,ab}\Gamma(L_1) = \{a, b, ab\}

回答以下问题。

(1) 设 L2={(ab)nn0}L_2 = \{(ab)^n \mid n \geq 0\}。用正则表达式表示 Γ(L2)\Gamma(L_2)

(2) 设 L3={anbnambmn0,m0}L_3 = \{a^n b^n a^m b^m \mid n \geq 0, m \geq 0\}。给出生成 Γ(L3)\Gamma(L_3) 的上下文无关文法。

(3) 设 M=(Q,Σ,δ,q0,F)\mathcal{M} = (Q, \Sigma, \delta, q_0, F) 为一个确定性有限自动机,并且设 LML_{\mathcal{M}}M\mathcal{M} 接受的语言。这里,QQ, Σ\Sigma, δ\delta, q0q_0, 和 FF 分别为 M\mathcal{M} 的状态集合、字母表、转移函数、初始状态和终止状态集合。可以假设转移函数 δ:Q×ΣQ\delta : Q \times \Sigma \to Q 是全定义的。给出一个接受 Γ(LM)\Gamma(L_{\mathcal{M}}) 的有限自动机,并简要解释。

(4) 如果以下命题为真,请给出如何从生成 LL 的上下文无关文法构造生成 Γ(L)\Gamma(L) 的上下文无关文法(可以使用下推自动机代替上下文无关文法),并简要解释。否则,请给出一个反例,并简要解释。

命题: " 对于每个上下文无关语言 LΣL \subseteq \Sigma^*Γ(L)\Gamma(L) 是一个上下文无关语言。"

题目描述

Σ={a,b}\Sigma=\{a,b\}。对语言 LΣL\subseteq\Sigma^*,定义

Γ(L)={vΣ存在 wΣ,使 v=w 且 vwL}.\Gamma(L) =\{v\in\Sigma^*\mid \text{存在 }w\in\Sigma^*\text{,使 }|v|=|w|\text{ 且 }vw\in L\}.

其中 x|x| 是字符串长度。例如 L1={aa,ba,abb,abbb}L_1=\{aa,ba,abb,abbb\} 时, Γ(L1)={a,b,ab}\Gamma(L_1)=\{a,b,ab\}。回答下列问题。

(1)令 L2={(ab)nn0}L_2=\{(ab)^n\mid n\ge0\},用正则表达式表示 Γ(L2)\Gamma(L_2)

(2)令 L3={anbnambmn,m0}L_3=\{a^nb^na^mb^m\mid n,m\ge0\},给出生成 Γ(L3)\Gamma(L_3) 的上下文无关文法。

(3)设 DFA M=(Q,Σ,δ,q0,F)\mathcal M=(Q,\Sigma,\delta,q_0,F) 识别语言 LML_{\mathcal M},且 δ\delta 为全函数。构造识别 Γ(LM)\Gamma(L_{\mathcal M}) 的有限自动机并简要说明。

(4)判断命题“对每个上下文无关语言 LΣL\subseteq\Sigma^*Γ(L)\Gamma(L) 仍为上下文无关语言”是否成立。若成立,说明如何由生成 LL 的 CFG 构造生成 Γ(L)\Gamma(L) 的 CFG(也可改用 PDA);若不成立,给出反例并简要解释。

Kai

(1)

If (ab)n=vw(ab)^n=vw and v=w|v|=|w|, then v=n|v|=n. According as nn is even or odd,

v=(ab)rorv=(ab)ra.v=(ab)^r\quad\text{or}\quad v=(ab)^r a.

Hence

Γ(L2)=(ab)(ε+a).\Gamma(L_2)=(ab)^*(\varepsilon+a).

(2)

The midpoint of anbnambma^n b^n a^m b^m lies in the first bb-block when mnm\le n, and in the second aa-block when m>nm>n. Thus

Γ(L3)={anbrnr0}{anbnarn,r0}.\Gamma(L_3) =\{a^n b^r\mid n\ge r\ge0\} \cup\{a^n b^n a^r\mid n,r\ge0\}.

It is generated by

SABC,AaAaAbε,BaBbε,CaCε.\begin{aligned} S&\to A\mid BC,\\ A&\to aA\mid aAb\mid\varepsilon,\\ B&\to aBb\mid\varepsilon,\\ C&\to aC\mid\varepsilon. \end{aligned}

(3)

For RQR\subseteq Q, put

Pre(R)={qQcΣ:δ(q,c)R}.\operatorname{Pre}(R)=\{q\in Q\mid \exists c\in\Sigma:\delta(q,c)\in R\}.

Use the DFA with state set Q×2QQ\times2^Q, initial state (q0,F)(q_0,F), transition

(q,R)c(δ(q,c),Pre(R)),(q,R)\xrightarrow{c}(\delta(q,c),\operatorname{Pre}(R)),

and accepting states {(q,R)qR}\{(q,R)\mid q\in R\}. After reading vv, its second component is

{qQwΣv:δ(q,w)F}.\{q\in Q\mid \exists w\in\Sigma^{|v|}:\delta(q,w)\in F\}.

It therefore accepts exactly when some such ww satisfies vwLMvw\in L_{\mathcal M}.

(4)

The proposition is false. Over Σ={a,b}\Sigma=\{a,b\}, regard

A=aa,B=ab,C=ba,D=bbA=aa,\qquad B=ab,\qquad C=ba,\qquad D=bb

as fixed-length codewords, and let

L={AnBnCiD3in,i1}.L=\{A^nB^nC^iD^{3i}\mid n,i\ge1\}.

This is context-free. Intersecting its half-prefix language with the regular language A+B+C+DA^+B^+C^+D gives

Γ(L)A+B+C+D={AnBnCn+1Dn1},\Gamma(L)\cap A^+B^+C^+D =\{A^nB^nC^{n+1}D\mid n\ge1\},

because equality of the two half-lengths gives 2n+i+1=n+2i2n+i+1=n+2i, hence i=n+1i=n+1. The language on the right is not context-free: fixed-length inverse decoding and removal of the final C,DC,D would yield {AnBnCnn1}\{A^nB^nC^n\mid n\ge1\}. Since context-free languages are closed under intersection with regular languages, Γ(L)\Gamma(L) cannot be context-free.

Knowledge

RegularExpression ContextFreeGrammar DeterministicFiniteAutomaton ContextFreeLanguage

解题技巧和信息

  1. Constructing Regular Expressions: Understanding the structure of the language is crucial to forming the correct regular expression.
  2. Designing CFGs: Consider the form of prefixes when designing CFGs for Γ(L)\Gamma(L).
  3. DFA Construction: For automaton-based constructions, consider pairs of states to account for parallel processing of string halves.
  4. Non-context-free Languages: Remember that some operations can lead to languages that are not context-free even if the original language is.

重点词汇

  • Prefix: 前缀
  • Context-free grammar (CFG): 上下文无关文法
  • Deterministic finite automaton (DFA): 确定性有限自动机
  • Regular expression: 正则表达式

参考资料

  1. Hopcroft, J.E., Motwani, R., Ullman, J.D. (2006). Introduction to Automata Theory, Languages, and Computation. Addison-Wesley. Chapter 2, 5.
  2. Sipser, M. (2012). Introduction to the Theory of Computation. Cengage Learning. Chapter 2, 4.