跳到主要内容

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

Author

kainoj, 祭音Myyura

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) 是否成立的方法。可以使用前 三问的结论。

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(\mathcal A') iff δ(q0,w)QF\delta^*(q_0,w)\in Q\setminus F, which holds exactly when wL(A)w\notin\mathcal L(\mathcal A).

(2)

Call a nonterminal AVA\in V generating if AwA\Rightarrow^*w for some wΣw\in\Sigma^*; otherwise it is nongenerating. The language is empty exactly when the start symbol SS is nongenerating.

Compute the generating symbols as follows. Initially mark every AA for which a production AwA\to w has wΣw\in\Sigma^*, including w=ϵw=\epsilon. Then repeatedly mark AA whenever a production AαA\to\alpha has only terminals and already marked nonterminals on its right-hand side. Stop when no new symbol can be marked.

Since VV is finite, this process terminates. Induction on derivation height shows that exactly the generating nonterminals are marked; hence L(G)=\mathcal L(G)=\varnothing iff SS remains unmarked.

(3)

For every BVB\in V, p,qQp,q\in Q, and nonempty word ww, induction on a Chomsky-normal-form derivation gives

Bp,qGAw    BGw and δ(p,w)=q.B_{p,q}\Rightarrow_{G_{\mathcal A}}^*w \iff B\Rightarrow_G^*w\ \text{and}\ \delta^*(p,w)=q.

The terminal-rule case follows directly from the second set of rules. In the binary-rule case BCDB\to CD, split w=uvw=uv according to the two subderivations and use the intermediate state r=δ(p,u)r=\delta^*(p,u); the converse uses the same split.

Therefore SwS'\Rightarrow^*w iff SGwS\Rightarrow_G^*w and δ(q0,w)F\delta^*(q_0,w)\in F. Since GAG_{\mathcal A} has no rule generating ϵ\epsilon, its language is (L(G)L(A)){ϵ}(\mathcal L(G)\cap\mathcal L(\mathcal A))\setminus\{\epsilon\}.

(4)

Complement A\mathcal A using (1), construct the grammar for

(L(G)L(A)){ϵ}(\mathcal L(G)\cap\overline{\mathcal L(\mathcal A)})\setminus\{\epsilon\}

using (3), and test it for emptiness using (2). Also test the omitted word separately: if SϵS\to\epsilon is a rule of GG, require q0Fq_0\in F. The inclusion holds iff both tests pass.