東京大学 情報理工学系研究科 コンピュータ科学専攻 2018年8月実施 専門科目I 問題3
Author
kainoj
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) 是否成立的方法。可以使用前
三问的结论。
- 正则语言的补运算:在转移函数完备时翻转 DFA 的接受与非接受状态。
- 上下文无关文法空语言判定:计算能够生成终结字符串的非终结符闭包。
- 上下文无关语言与正则语言的交:用带自动机起止状态的非终结符构造交语言文法并证明其语义。
- 语言包含关系判定:把 L(G)⊆L(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 δ(w,q0)∈(Q∖F) which is occurs only when w∈/L(A)
(2)
Given CFG G=(V,Σ,P,S), decide wheaterh L(G)=∅.
We call symbol A∈V \emph{generating} if A⇒∗w for some string w of terminals.
If there's no such string, then A is \emph{nongenerating}.
Language of grammar G is empty iff start symbol S 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 T is generating.
- Induction. If for some production A→α, α is known to be generating, then is A.
(3)
Looks pretty obvious from the construction.
A nice induction'd make it.
(4)
If (L(G)∩L(A))=∅, then L(G)⊆L(A)
We can compute complement based on (Q1), intersection based on (Q3) and check for emptiness based on (Q2).