跳到主要内容

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

Author

zephyr

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)

Let L2={(ab)nn0}L_2 = \{(ab)^n \mid n \geq 0\}. The language L2L_2 consists of strings of even length formed by repeating the substring "ab".

Solution: To find Γ(L2)\Gamma(L_2), consider what Γ(L)\Gamma(L) does. For each string vΓ(L2)v \in \Gamma(L_2), there exists a string ww of the same length such that vwL2vw \in L_2.

Given that L2L_2 consists of strings of the form (ab)n(ab)^n, the possible strings vv must have lengths that can be paired with some ww such that their concatenation results in a string from L2L_2.

The key observation is that vv can be any prefix of strings from L2L_2. This gives us the possible regular expression:

Γ(L2)=(a+b)\Gamma(L_2) = (a + b)^*

This is because for any string vv formed from letters aa and bb, there is a corresponding ww such that vwL2vw \in L_2 as long as the length condition is satisfied.

(2)

Let L3={anbnambmn0,m0}L_3 = \{a^n b^n a^m b^m \mid n \geq 0, m \geq 0\}. This language consists of strings where the numbers of aas and bbs are matched in pairs.

Solution: To generate Γ(L3)\Gamma(L_3), consider the strings that can form the beginning of valid strings in L3L_3. Specifically, Γ(L3)\Gamma(L_3) includes any prefix of L3L_3 that can be completed to a string in L3L_3. Therefore, Γ(L3)\Gamma(L_3) includes strings of the form apbqarbsa^p b^q a^r b^s where 0pn0 \leq p \leq n, 0qn0 \leq q \leq n, 0rm0 \leq r \leq m, and 0sm0 \leq s \leq m.

A context-free grammar G=(V,Σ,R,S)G = (V, \Sigma, R, S) generating Γ(L3)\Gamma(L_3) can be defined as follows:

  • Variables: S,A,B,C,DS, A, B, C, D

  • Alphabet: Σ={a,b}\Sigma = \{a, b\}

  • Rules:

    • SABϵS \rightarrow AB \mid \epsilon
    • AaABA \rightarrow aA \mid B
    • BbBCB \rightarrow bB \mid C
    • CaCDC \rightarrow aC \mid D
    • DbDϵD \rightarrow bD \mid \epsilon
  • Start Symbol: SS

This grammar generates strings in the form of prefixes of the strings in L3L_3.

(3)

Let M=(Q,Σ,δ,q0,F)\mathcal{M} = (Q, \Sigma, \delta, q_0, F) be a deterministic finite automaton (DFA) that accepts a language LML_{\mathcal{M}}. We need to construct a DFA M\mathcal{M}' that accepts Γ(LM)\Gamma(L_{\mathcal{M}}).

Solution: To construct M\mathcal{M}', consider that Γ(LM)\Gamma(L_{\mathcal{M}}) consists of strings vv such that there exists some ww with v=w|v| = |w| and vwLMvw \in L_{\mathcal{M}}.

  • States: The states of M\mathcal{M}' will be pairs of states from Q×QQ \times Q, representing the DFA being in a state corresponding to the prefixes vv and ww of equal length.
  • Transitions: For each (p,q)Q×Q(p, q) \in Q \times Q and for each letter aΣa \in \Sigma, if δ(p,a)=p\delta(p, a) = p' and δ(q,a)=q\delta(q, a) = q', then (p,q)a(p,q)(p, q) \xrightarrow{a} (p', q').
  • Start State: The start state is (q0,q0)(q_0, q_0).
  • Final States: A pair (p,q)(p, q) is a final state if there exists some pQp' \in Q and qFq' \in F such that (p,q)(p, q) transitions to (p,q)(p', q') by some string.

This DFA M\mathcal{M}' accepts exactly the strings in Γ(LM)\Gamma(L_{\mathcal{M}}) by simulating the original DFA on both halves of the string in parallel.

(4)

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

Solution: The proposition is false. A counterexample can be constructed as follows:

Consider the context-free language L={anbncnn1}L = \{a^n b^n c^n \mid n \geq 1\}, which is known to be context-free. However, Γ(L)\Gamma(L) would include strings like apbqcra^p b^q c^r where p,q,rp, q, r do not necessarily follow the strict condition p=q=rp = q = r. The language Γ(L)\Gamma(L) can be shown to be non-context-free because it requires balancing different parts of the string in a way that a context-free grammar cannot generally handle.

This counterexample demonstrates that Γ(L)\Gamma(L) is not necessarily context-free even if LL is.

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.