東京大学 情報理工学系研究科 コンピュータ科学専攻 2018年8月実施 専門科目I 問題3
Author
kainoj, 祭音Myyura
Description
In the following, we represent a deterministic finite automaton as a quintuple A=(Q,Σ,δ,q0,F) (where Q is a finite set of states, Σ is a finite set of input symbols, δ∈Q×Σ→Q is the transition function, q0∈Q is the initial state, and F⊆Q is the set of final states), and a context-free grammar as a quadruple G=(V,Σ,P,S) (where V is a finite set of non-terminal symbols, Σ is a finite set of terminal symbols, P is a finite set of production rules, and S∈V is the start symbol).
A context-free grammar G=(V,Σ,P,S) is in Chomsky normal form if each production rule is of the form:
- B→CD,
- B→a, or
- S→ϵ,
where B is a non-terminal symbol, C and D are non-terminal symbols other than S, a is a terminal symbol, and ϵ is an empty sequence. We write L(A) for the language accepted by a deterministic finite automaton A, and L(G) for the language generated by a context-free grammar G.
Answer the following questions:
(1) Let A=(Q,Σ,δ,q0,F) be a deterministic finite automaton. Give a deterministic finite automaton that accepts the complement of L(A), i.e., Σ∗∖L(A). Here, you may assume that δ∈Q×Σ→Q is a total function.
(2) Describe an algorithm that takes a context-free grammar G as an input, and decides whether L(G)=∅.
(3) Given a context-free grammar G=(V,Σ,P,S) in Chomsky normal form and a deterministic finite automaton A=(Q,Σ,δ,q0,F), we define a context-free grammar GA as follows:
VAPA={S′}∪{Bq,q′∣B∈V∧(q,q′)∈Q}={Bq,q′→Cq,q′′Dq′′,q′∣(B→CD∈P)∧(q,q′,q′′∈Q)}∪{Bq,q′→a∣(B→a∈P)∧(q,q′∈Q)∧(δ(q,a)=q′)}∪{S′→Sq0,q∣q∈F}.
Here, assume S′∈/{Bq,q′∣B∈V∧(q,q′)∈Q}. Prove that L(GA)=(L(G)∩L(A))∖{ϵ} holds.
(4) Give a method to decide, given a context-free grammar G in Chomsky normal form and a deterministic finite automaton A as inputs, whether or not L(G)⊆L(A) holds. You may use the results of questions (1), (2), and (3).
题目描述
以下将 DFA 写成五元组
A=(Q,Σ,δ,q0,F),其中 Q 是有限状态集,
Σ 是有限输入字母表,δ:Q×Σ→Q 是转移函数,
q0 是初始状态,F⊆Q 是接受状态集;将上下文无关文法写成
G=(V,Σ,P,S),其中 V 是有限非终结符集,Σ 是有限终结符集,
P 是有限产生式集,S∈V 是开始符号。
若文法的每条产生式均为
B→CD、B→a 或 S→ε,其中 B 为非终结符,
C,D 为不同于 S 的非终结符,a 为终结符,则称该文法为乔姆斯基范式。
记 L(A) 为自动机接受的语言,
L(G) 为文法生成的语言。回答下列问题。
(1)给定 DFA A=(Q,Σ,δ,q0,F),构造接受补语言
Σ∗∖L(A) 的 DFA。可假设 δ 为全函数。
(2)描述一个输入上下文无关文法 G、判定
L(G)=∅ 是否成立的算法。
(3)给定乔姆斯基范式文法 G=(V,Σ,P,S) 和 DFA
A=(Q,Σ,δ,q0,F),定义文法 GA:
VAPA={S′}∪{Bq,q′∣B∈V, (q,q′)∈Q2},={Bq,q′→Cq,q′′Dq′′,q′∣B→CD∈P, q,q′,q′′∈Q}∪{Bq,q′→a∣B→a∈P, q,q′∈Q, δ(q,a)=q′}∪{S′→Sq0,q∣q∈F}.
假设 S′ 不属于其他形如 Bq,q′ 的非终结符。证明
L(GA)=(L(G)∩L(A))∖{ε}.
(4)给定乔姆斯基范式文法 G 和 DFA A,给出判定
L(G)⊆L(A) 是否成立的方法。可以使用前
三问的结论。
Kai
(1)
Given DFA A=(Q,Σ,δ,q0,F), give an automaton accepting complement of L(A), i.e. Σ∗∖L(A).
Let A′=(Q,Σ,δ,q0,Q∖F)
Now w∈L(A′) iff δ∗(q0,w)∈Q∖F, which holds exactly when w∈/L(A).
(2)
Call a nonterminal A∈V generating if A⇒∗w for some w∈Σ∗; otherwise it is nongenerating. The language is empty exactly when the start symbol S is nongenerating.
Compute the generating symbols as follows. Initially mark every A for which a production A→w has w∈Σ∗, including w=ϵ. Then repeatedly mark A whenever a production A→α has only terminals and already marked nonterminals on its right-hand side. Stop when no new symbol can be marked.
Since V is finite, this process terminates. Induction on derivation height shows that exactly the generating nonterminals are marked; hence L(G)=∅ iff S remains unmarked.
(3)
For every B∈V, p,q∈Q, and nonempty word w, induction on a Chomsky-normal-form derivation gives
Bp,q⇒GA∗w⟺B⇒G∗w and δ∗(p,w)=q.
The terminal-rule case follows directly from the second set of rules. In the binary-rule case B→CD, split w=uv according to the two subderivations and use the intermediate state r=δ∗(p,u); the converse uses the same split.
Therefore S′⇒∗w iff S⇒G∗w and δ∗(q0,w)∈F. Since GA has no rule generating ϵ, its language is (L(G)∩L(A))∖{ϵ}.
(4)
Complement A using (1), construct the grammar for
(L(G)∩L(A))∖{ϵ}
using (3), and test it for emptiness using (2). Also test the omitted word separately: if S→ϵ is a rule of G, require q0∈F. The inclusion holds iff both tests pass.