计算理论复习

考点列表

常见单词 / 术语

Language

常见的 Language 及其属于的范畴

运算符闭包性

Operator Regular Context-free recursive recursively enumerable
×
× ×

Finite Automata and Regular Languages

Sequence of Configurations

Problem
Consider the following DFA. What sequence of configurations does the machine go through on input aab?
image.png

Solution

(q1,aab)M(q2,ab)M(q3,b)M(q1,e)
NFA ⇒ RL

解题思路

  1. 将 NFA 的起点和终点剥离出来
  2. 将中间状态依次等价转换
    • 只关注 Simple Path 和 Simple Cycle
  3. 最终获得起点到终点的等价式

Problem
将以下的 NFA 转化为 RL
image.png

Solution
image.png

NFA ⇒ DFA

解题思路

  1. 构造 2|K| 个状态的 DFA(不要忘记
  2. 建立转移关系
  3. 删除无用状态

Problem
Convert the following NFA to an equivalent DFA. Give only the portion of the DFA that is reachable from the initial state.
image.png
Answer
image.png

Prove languages are regular

简单的 画出有限自动机即可;复杂的 构造 (K,σ,δ,s,F) 就更好了

Problem1
The set of all binary strings that end with 00.
Solution1


Problem2
Let A and B be two regular languages over some alphabet Σ. Let # be a symbol not in Σ. Consider the following language.

L={w1#w2:w1Aw2B}

Solution2
Contruct a new FA M3=(K3,Σ,δ3,s3,F3) as following.
(需要为接收到 # 的非法情况建立新的状态 q0

Σ= Σ{#}K3= K1K2{q0}s3= s1F3= F2δ3= δ1δ2{((q,#),q0)|q((K1F1)K2)}{((q0,a),q0)|aΣ}{((q,#),s2)|qF1}
& e &

  • 是什么都没有的意思
  • e 表示接受空串
  • e
  • R=
  • R=R
  • R=R

Construct NFA which accepts Regular Expressions

Problem
Construct a NFA that accepts (ababa).

Solution

Regular Language

  • 判断题:If A is regular and B is non-regular, then AB must be non-regular.
    • 错误
    • 反例:A= 的时候。
  • 判断题:Language { aibjck | i,j,kN and i+jkmod3 } is not regular.
    • 错误
    • 同余的情况只有有限种,可以拆封成类似 {a3ib3jc3k} 的形式。
  • 判断题:If L1L2 is a regular language, then either L1 or L2 is regular.
    • 错误
    • 反例:Assume A is non-regular ⇒ A is non-regular ⇒ A{e} and A{e} are non-regular ⇒ (A{e})(A{e})=Σ is regular.

Pumping Theorem

Problem1
L1={wtw | w,t{a,b}+} is regular or not.
Solution1
Pumping Theorem.
假设 Pumping length 为 p,构造 w=apbaapb=xyzL1,
因为 (2) |y|>0 (3) |xy≤p|,所以 y=ai
xy2z=an+ibaanbL2(特别小心这里的判断)

Problem2
L4={uvuR | u,v{a,b}+} is regular or not.
Solution2
注意 L4 其实只用判断首尾内容是否一致就行,故是正则的

Context Free Language

Suppose that L is context-free and R is regular, then LR is context-free language.

正确。

  1. LR=LR
  2. L is CFL, R is RL, CFL RL = CFL
  3. LR is CFL
CFL ⇒ CFG

Problem1
Construct a context-free grammar that generatesthe following language.

{xy{0,1}:x has equal number of 0s and 1s, and y=yR}

Solution1
SAB
AAA | 0A1 | 1A0 | e
B0B0 | 1B1 | 0 | 1 | e

Problem2
L={ w{a,b} | ab },试用 CFG 写出能表示 L 的文法

Solution2
SP | Q
QXAX | QQ
PXBX | PP
XaXb | bXa | XX | e
AaA | a
BbB | b

CFL ⇒ PDA

Problem
Construct a pushdown automaton that accepts the following language.

{w{a,b}:in w,2#a=#b+3}

Solution

P=(K,Σ,Γ,Δ,s,F)K={s,f}Σ={a,b}Γ={A,B}s=sF={f}

The list of ((q,α,β),(p,γ)) shown below contains all elements in Δ
image.png

Parse tree

Problem
Consider the following context-free grammar.

EE+EEE×EEa

Show two distinct parse trees with root E and yield a×a+a
Solution
image.png

Turing Machine and Undecidability

Turing Machine

从基本定义出发构造图灵机

Problem
image.png
Solution

注意事项

图灵机之间状态转移时可能会出现不合法的情况

image.png

Design a right-shifting machine S that transforms w into w, where w is a string that contains no blank symbol.

image.png

Try to construct a Turing Machine to decide the following language. L={wwR|w{0,1}}.

p.s. You can assume the start configuration of the Turing machine is w.
image.png

Undecidability

使用 Reduction 的基本定义

Problem
Let A and B be two languages. Suppose that we have a reduction f from A to B. If B is recursively enumerable, what conclusion can you draw about A?
Solution
A is also recursively enumerable.
根据定义,wA if and only if f(w)B
对于 MB semidecides B, 我们可以构造
M = on input w, run MB on f(w)
L(M)=A,故 A is recursively enumerable.

for ArB

  • If B is recursive, A is recursive.
  • If B is recursively enumerable, A is recursively enumerable.
  • If A is not recursive, B is not recursive.
  • If A is not recursively enumerable, B is not recursively enumerable.

一些关于 Recursive 的判断题

  • 判断题 1:If A is recursive and BA, then B is recursive as well.
  • 回答:错误,因为 Recursive Language 的子集不一定 Recursive。
  • 判断题 2:There's a function ϕ such that ϕ can be computed by some Turing machines, yet ϕ is not a primitive recursive function.
  • 回答:正确,因为 primitive recursive function 是 recursive function 的子集。
flowchart LR
	subgraph recursive function = μ-recursive function
		p[primitive recursive function]
	end
  • 判断题 3:If L1,L2, and L3 are all recursively enumerable, then L1(L2L3) must be recursively enumerable.
  • 判断题 4:Let L be a recursively enumerable language and LrH, then L is recursive, where H = { “M”“w” | Turing machine M halts on w }.
  • 回答:正确。因为 LrHL is recursively enumerable ⇒ L is recursive。 - 回答:正确,因为 Recursive Language 在 , 下封闭。

Let L1 and L2 be two recursively enumerable languages. If L1L2 and L1L2 are recursive, then both L1 and L2 are recursive.

正确。

Prove that every recursively enumerable language can be reduced to H

构造 f("w") = "M""w",即可证明 LrH

Prove that the following language is not recursive. L = { "M1" "M2" "k": M1 and M2 are two Turing machines with |L(M1)L(M2)|k }

构造 f("M") = "M""Mall""1" (Mall 在所有输入下停机)
已知 A = { "M": M halt on some inputs. } is not recursive.
MA, |L(M)L(Mall)|=|L(M)|1f(M)L
MA, |L(M)L(Mall)|=|L(M)|=||=0f(M)L
ArL
A is not recursive
L is not recursive

Leven = { "M" | M is a TM and L(M) contains at least one string of even number of b's }

(1) Show that Leven is recursively enumerable.
Constrcut MA = on input "M"

for i = 1, 2, 3, ...
	// 将满足 even number of b's 的字符串按字典序枚举
	for s = s1, s2, s3, ..., si 
		run M on s for i steps
		if M halts on s within i steps
			halt

(2) Show that Leven is non-recursive.
答:使用 Rice's Theorem
构造 f("M""w") = on input v
step1 run M on w
step2 run MA on v, where MA accepts string b.
M wH 时,L[f(M w)]=L(MA)f(M w)Leven
M wH 时,L[f(M w)]=f(M w)Leven
所以 HRLevenLeven is non-recursive

Classify whether each of the following languages are recursive, recursively enumerable but not recursive, or non-recursively enumerable.

(1) The language AL = {"M" | TM M accepts at least 2018 strings.}
首先,AL 递归可枚举,可以构造如下自动机

Constrcut MA = on input "M"

for i = 1, 2, 3, ...
	count = 0
	for s = s1, s2, s3, ..., si
		run M on s for i steps
		if M halts on s within i steps
			count = count + 1
	if count >= 2023
		halts

其次,AL 非递归,可进行如下归约 HAL

Contruct f("M""w") = on input v
step1 run M on w
step2 run MA on v which accepts everything

M wH 时,|L[f(M w)]|=|L(MA)|2018f(M w)AL
M wH 时,|L[f(M w)]|=||=0f(M w)AL
所以 HRAL, AL is non-recursive

(2) The language E = {"M" | TM M accepts at exactly 2018 strings.}
E 非递归可枚举

Contruct f("M""w") = on input v
if v=ui then halt// u1,,u2018 是事先规定好的 2018 个串
else run M on w

M wH 时,|L(f(M w))|=2018f(M w)E
M wH 时,|L(f(M w))|=>2018f(M w)E

(3) The language AM = {"M" | TM M accepts at most 2018 strings.}
AM 时非递归可枚举的,可以使用反证法。
AM 递归可枚举,由 (1) 知 AM 也递归可枚举,则 AMAM 递归,又因为 AM 非递归,故矛盾。

Grammar

Contruct a grammar that generates {ww:w{a,b}}

V = { S, S', T, A, B, a, b }, Σ = { a, b }, R is the set of the following rules
S → TS'
S' → AaS' | BbS' | e
aA → Aa
aB → Ba
bA → Ab
bB → Bb
TA → aT
TB → bT
T → e

Numerical Function

Show that the function: φ:NN given by ϕ(x)={xmod3,if x is a composite number;x2+1,otherwise. is primitive recursive.

Since

φ(x)=rem(x,3)(1prime(x))+(x2+1)prime(x)

and rem(x,3), x2+1 are primitive recursive functions, prime(x) is a primitive recursive predicate, hence φ(x) is primitive recursive.

Show the following function ϕk:N×N××NkN, and kN,k2, ϕk(n1,n2,,nk)=maxk{n1,n2,,nk} is primitive recursive.

使用 recursive definition 推导

  1. 构造 {f(n1,,nk,0)=g(n1,,nk)f(n1,,nk,t+1)=h(n1,,nk,t,f(n1,,nk,t))
  2. 证明 gh 均为原始递归函数

f(n1,n2,,nk,k)=max{n1,n2,,nk}

f(n1,n2,,nk,0)=max2{n1,n2}=n1(n1>n2)+n2(n2n1)f(n1,n2,,nk,k)=max{n1,n2,,nk}=max2{f(n1,n2,,nk1,k1),nk}

所以 f(n1,n2,,nk,k) 是原始递归函数
所以 φk(n1,n2,,nk) 是原始递归函数

Countable

Countable 相关问题

Problem1
Prove that every language is countable.
Solution1
Σ is countable and a subset of a countable set is countable.
LΣ is countable.

Problem2
Prove that there is an undecidable subset of {1}.
Solution2
Every language is countable
The recursive languages is countable.
The power set of {1} is uncountable.
There is an uncountable subset of {1}

Problem3
Prove that the set of undecidable languages is uncountable.
Solution3
The set of Turing Machine is countable.
The set of decidable languages is countable.
The set of undecidable languages is uncountable.

Problem4
Prove that countable does not imply Turing enumerable(recursively enumerable)
Solution4
All the language is enumerable and not all the language is recursively enumerable, like H
There exists languages(must be countable) which are not recursively enumerable.