跳到主要内容

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

Author

kainoj

Description

In the following, we represent a deterministic finite automaton as a quintuple A=(Q,Σ,δ,q0,F)\mathcal{A} = (Q, \Sigma, \delta, q_0, F) (where QQ is a finite set of states, Σ\Sigma is a finite set of input symbols, δQ×ΣQ\delta \in Q \times \Sigma \to Q is the transition function, q0Qq_0 \in Q is the initial state, and FQF \subseteq Q is the set of final states), and a context-free grammar as a quadruple G=(V,Σ,P,S)G = (V, \Sigma, P, S) (where VV is a finite set of non-terminal symbols, Σ\Sigma is a finite set of terminal symbols, PP is a finite set of production rules, and SVS \in V is the start symbol).

A context-free grammar G=(V,Σ,P,S)G = (V, \Sigma, P, S) is in Chomsky normal form if each production rule is of the form:

  • BCDB \to CD,
  • BaB \to a, or
  • SϵS \to \epsilon,

where BB is a non-terminal symbol, CC and DD are non-terminal symbols other than SS, aa is a terminal symbol, and ϵ\epsilon is an empty sequence. We write L(A)\mathcal{L}(\mathcal{A}) for the language accepted by a deterministic finite automaton A\mathcal{A}, and L(G)\mathcal{L}(G) for the language generated by a context-free grammar GG.

Answer the following questions:

(1) Let A=(Q,Σ,δ,q0,F)\mathcal{A} = (Q, \Sigma, \delta, q_0, F) be a deterministic finite automaton. Give a deterministic finite automaton that accepts the complement of L(A)\mathcal{L}(\mathcal{A}), i.e., ΣL(A)\Sigma^* \setminus \mathcal{L}(\mathcal{A}). Here, you may assume that δQ×ΣQ\delta \in Q \times \Sigma \to Q is a total function.

(2) Describe an algorithm that takes a context-free grammar GG as an input, and decides whether L(G)=L(G) = \emptyset.

(3) Given a context-free grammar G=(V,Σ,P,S)G = (V, \Sigma, P, S) in Chomsky normal form and a deterministic finite automaton A=(Q,Σ,δ,q0,F)\mathcal{A} = (Q, \Sigma, \delta, q_0, F), we define a context-free grammar GAG_\mathcal{A} as follows:

VA={S}{Bq,qBV(q,q)Q}PA={Bq,qCq,qDq,q(BCDP)(q,q,qQ)}{Bq,qa(BaP)(q,qQ)(δ(q,a)=q)}{SSq0,qqF}.\begin{aligned} V_{\mathcal{A}} &= \{ S' \} \cup \{ B_{q,q'} \mid B \in V \land (q, q') \in Q \} \\ P_{\mathcal{A}} &= \{ B_{q,q'} \to C_{q,q''} D_{q'',q'} \mid (B \to CD \in P) \land (q, q', q'' \in Q) \} \\ &\cup \{ B_{q,q'} \to a \mid (B \to a \in P) \land (q, q' \in Q) \land (\delta(q, a) = q') \} \\ &\cup \{ S' \to S_{q_0,q} \mid q \in F \}. \end{aligned}

Here, assume S{Bq,qBV(q,q)Q}S' \notin \{ B_{q,q'} \mid B \in V \land (q, q') \in Q \}. Prove that L(GA)=(L(G)L(A)){ϵ}\mathcal{L}(G_\mathcal{A}) = (\mathcal{L}(G) \cap \mathcal{L}(\mathcal{A})) \setminus \{\epsilon\} holds.

(4) Give a method to decide, given a context-free grammar GG in Chomsky normal form and a deterministic finite automaton A\mathcal{A} as inputs, whether or not L(G)L(A)\mathcal{L}(G) \subseteq \mathcal{L}(\mathcal{A}) holds. You may use the results of questions (1), (2), and (3).

题目描述

以下将 DFA 写成五元组 A=(Q,Σ,δ,q0,F)\mathcal{A}=(Q,\Sigma,\delta,q_0,F),其中 QQ 是有限状态集, Σ\Sigma 是有限输入字母表,δ:Q×ΣQ\delta:Q\times\Sigma\to Q 是转移函数, q0q_0 是初始状态,FQF\subseteq Q 是接受状态集;将上下文无关文法写成 G=(V,Σ,P,S)G=(V,\Sigma,P,S),其中 VV 是有限非终结符集,Σ\Sigma 是有限终结符集, PP 是有限产生式集,SVS\in V 是开始符号。

若文法的每条产生式均为 BCDB\to CDBaB\to aSεS\to\varepsilon,其中 BB 为非终结符, C,DC,D 为不同于 SS 的非终结符,aa 为终结符,则称该文法为乔姆斯基范式。 记 L(A)\mathcal{L}(\mathcal{A}) 为自动机接受的语言, L(G)\mathcal{L}(G) 为文法生成的语言。回答下列问题。

(1)给定 DFA A=(Q,Σ,δ,q0,F)\mathcal{A}=(Q,\Sigma,\delta,q_0,F),构造接受补语言 ΣL(A)\Sigma^*\setminus\mathcal{L}(\mathcal{A}) 的 DFA。可假设 δ\delta 为全函数。

(2)描述一个输入上下文无关文法 GG、判定 L(G)=\mathcal{L}(G)=\varnothing 是否成立的算法。

(3)给定乔姆斯基范式文法 G=(V,Σ,P,S)G=(V,\Sigma,P,S) 和 DFA A=(Q,Σ,δ,q0,F)\mathcal{A}=(Q,\Sigma,\delta,q_0,F),定义文法 GAG_{\mathcal A}

VA={S}{Bq,qBV, (q,q)Q2},PA={Bq,qCq,qDq,qBCDP, q,q,qQ}{Bq,qaBaP, q,qQ, δ(q,a)=q}{SSq0,qqF}.\begin{aligned} V_{\mathcal A} &=\{S'\}\cup\{B_{q,q'}\mid B\in V,\ (q,q')\in Q^2\},\\ P_{\mathcal A} &=\{B_{q,q'}\to C_{q,q''}D_{q'',q'} \mid B\to CD\in P,\ q,q',q''\in Q\}\\ &\quad\cup\{B_{q,q'}\to a \mid B\to a\in P,\ q,q'\in Q,\ \delta(q,a)=q'\}\\ &\quad\cup\{S'\to S_{q_0,q}\mid q\in F\}. \end{aligned}

假设 SS' 不属于其他形如 Bq,qB_{q,q'} 的非终结符。证明

L(GA)=(L(G)L(A)){ε}.\mathcal{L}(G_{\mathcal A}) =\bigl(\mathcal{L}(G)\cap\mathcal{L}(\mathcal A)\bigr) \setminus\{\varepsilon\}.

(4)给定乔姆斯基范式文法 GG 和 DFA A\mathcal A,给出判定 L(G)L(A)\mathcal{L}(G)\subseteq\mathcal{L}(\mathcal A) 是否成立的方法。可以使用前 三问的结论。

考点

  • 正则语言的补运算:在转移函数完备时翻转 DFA 的接受与非接受状态。
  • 上下文无关文法空语言判定:计算能够生成终结字符串的非终结符闭包。
  • 上下文无关语言与正则语言的交:用带自动机起止状态的非终结符构造交语言文法并证明其语义。
  • 语言包含关系判定:把 L(G)L(A)L(G)\subseteq L(\mathcal A) 化为 L(G)L(A)=L(G)\cap\overline{L(\mathcal A)}=\varnothing,同时正确处理空串。

Kai

(1)

Given DFA A=(Q,Σ,δ,q0,F)\mathcal{A} = (Q, \Sigma, \delta, q_0, F), give an automaton accepting complement of L(A)\mathcal{L(A)}, i.e. ΣL(A)\Sigma^*\setminus\mathcal{L(A)}.

Let A=(Q,Σ,δ,q0,QF)\mathcal{A}' = (Q, \Sigma, \delta, q_0, Q\setminus F) Now, wL(A)w \in \mathcal{L(A')} iff δ(w,q0)(QF\delta(w, q_0) \in (Q\setminus F) which is occurs only when wL(A)w\notin \mathcal{L(A)}

(2)

Given CFG G=(V,Σ,P,S)\mathcal{G} = (V, \Sigma, P, S), decide wheaterh L(G)=\mathcal{L(G)} = \varnothing.

We call symbol AVA\in V \emph{generating} if AwA\Rightarrow^* w for some string ww of terminals. If there's no such string, then AA is \emph{nongenerating}. Language of grammar G\mathcal{G} is empty iff start symbol SS is nongenerating. We can find set of generating symbols using the algorithm below. Symbols that are not marked generating, are nongenerating. The algorithm:

  • Base. Every terminal symbol form TT is generating.
  • Induction. If for some production AαA\rightarrow \alpha, α\alpha is known to be generating, then is AA.

(3)

Looks pretty obvious from the construction. A nice induction'd make it.

(4)

If (L(G)L(A))=(\mathcal{L(G)}\cap \overline{\mathcal{L(A)}}) = \varnothing, then L(G)L(A)\mathcal{L(G)} \subseteq \mathcal{L(A)} We can compute complement based on (Q1), intersection based on (Q3) and check for emptiness based on (Q2).