计算理论笔记(五)Grammar Function

本文介绍了上下文无关文法(CFG)的基本概念,包括文法的定义、产生式规则和推导过程。并探讨了文法与图灵机之间的关系,指出一个语言由文法生成当且仅当该语言能被图灵机半决定。接着,讨论了关于文法的不可解问题,如 Rice's 定理,以及非确定上下文无关文法(NDCFG)集合的定义。此外,还阐述了递归函数和原始递归函数的概念,以及它们在计算理论中的重要性。最后,提出了一个计算历史的减少方法,用于证明某些函数是不可计算的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Grammar(unrestricted grammar)
  • Context-free grammar: A→wA\to wAw
  • Grammar: uAv→wuAv\to wuAvw
Definition
  • A grammar is a 4-tuple G=(V,Σ,S,R)G=(V,\Sigma,S,R)G=(V,Σ,S,R)
    • VVV is an alphabet
    • Σ⊆V\Sigma\subseteq VΣV is the set of terminals
      • V−ΣV-\SigmaVΣ is the set of non-terminals
    • S∈V−ΣS\in V-\SigmaSVΣ is the start symbol
    • RRR, the set of rules, is a finite subset of (V∗(V−Σ)V∗)×V∗(V^*(V-\Sigma)V^*)\times V^*(V(VΣ)V)×V
  • (u,v)∈R,u→v(u,v)\in R,u\to v(u,v)R,uv
  • derives in one step, u⇒Gvu\xRightarrow[G]{}vuGv
  • derives ,u⇒G∗vu\xRightarrow[G]{}^*vuGv
  • GGG generates w∈Σ∗w\in\Sigma^*wΣ if S⇒GwS\xRightarrow[G]{}wSGw
  • L(G)={w∈Σ∗L(G)=\{w\in\Sigma^*L(G)={wΣ: S⇒Gw∗}S\xRightarrow[G]{}w^*\}SGw}, GGG generates L(G)L(G)L(G)
Example
  • The following grammar generates {anbncn:n≥1}\{a^nb^nc^n:n\ge1\}{anbncn:n1}
    • S→ABCSS\to ABCSSABCS
    • BA→ABBA\to ABBAAB, CA→ACCA\to ACCAAC, CB→BCCB\to BCCBBC
    • S→TcS\to T_cSTc, CTc→TccCT_c\to T_ccCTcTcc
    • BTc→BTbBT_c\to BT_bBTcBTb, BTb→TbbBT_b\to T_bbBTbTbb
    • ATb→ATaAT_b\to AT_aATbATa, ATa→TaaAT_a\to T_aaATaTaa
    • Ta→eT_a\to eTae
Theorem
  • A language is generated by a grammar iff it is semidecided by a TM
  • G→MG\to MGM
    • M=M=M= on input www
      1. layer 000 is {S}\{S\}{S}
      2. for i=1,2,3,…i=1,2,3,\dotsi=1,2,3,
      3. construct layer iii from layer i−1i-1i1
      4. if www in layer iii, halts
  • M→GM\to GMG
    • WLOG, assume that
      • K∩Σ=∅K\cap\Sigma=\varnothingKΣ=
      • H={h}H=\{h\}H={h}, and if MMM halts, it is always in configuration (h,⊳⊔‾)(h,\rhd\underline{\sqcup})(h,)
    • G=(V,Σ′,S,R)G=(V,\Sigma',S,R)G=(V,Σ,S,R)
      • V=K∪Σ∪{S,⊲}V=K\cup\Sigma\cup\{S,\lhd\}V=KΣ{S,}
      • Σ′=Σ−{⊳,⊔}\Sigma'=\Sigma-\{\rhd,\sqcup\}Σ=Σ{,}
      • R=R=R=
        1. S→⊳⊔h⊲S\to\rhd\sqcup h\lhdSh
        2. ⊳⊔S→e\rhd\sqcup S\to eSe, ⊲→e\lhd\to ee
        3. writing: if MMM has δ(q,a)=(p,b)\delta(q,a)=(p,b)δ(q,a)=(p,b), GGG has bp→aqbp\to aqbpaq
        4. moving right: if MMM has δ(q,a)=(p,→)\delta(q,a)=(p,\rightarrow)δ(q,a)=(p,), GGG has abp→aqbabp\to aqbabpaqb
        5. moving left: if MMM has δ(q,a)=(p,←)\delta(q,a)=(p,\leftarrow)δ(q,a)=(p,), GGG has pa→aqpa\to aqpaaq
Undecidable problems about grammar
  • G1 Problem
    • AG={A_G=\{AG={GGG”“www”: GGG is a grammar that generates w}w\}w}
      • f(f(f(MMM”“www)=)=)=GGG”“www
      • H⪯AGH\preceq A_GHAG
Rice’s Theorem
  • Suppose L\mathcal{L}L is a proper, non-empty subset of all R.E. languages, the following is undecidable: given a grammar GGG, is L(G)∈LL(G)\in\mathcal{L}L(G)L?
Theorem
  • Language: NDCFG={ND_\mathrm{CFG}=\{NDCFG={"G1G_1G1"“G2G_2G2”: G1G_1G1 and G2G_2G2 are two CFGs with L(G1)∩L(G2)≠∅}L(G_1)\cap L(G_2)\ne\varnothing\}L(G1)L(G2)=}
  • Reduction by computation history
Numerical function
  • We say a TM MMM computes a numerical function f:Nk→Nf:\mathbb{N}^k\to\mathbb{N}f:NkN if for any n1,n2,…,nk∈Nn_1,n_2,\dots,n_k\in\mathbb{N}n1,n2,,nkN, M(bin(n1),bin(n2),…,bin(nk))=bin(f(n1,n2,…,nk))M(\mathrm{bin}(n_1),\mathrm{bin}(n_2),\dots,\mathrm{bin}(n_k))=\mathrm{bin}(f(n_1,n_2,\dots,n_k))M(bin(n1),bin(n2),,bin(nk))=bin(f(n1,n2,,nk))
Basic functions
  • for any k≥0k\ge0k0, the kkk-ary zero function is zero(n1,…,nk)=0\mathrm{zero}(n_1,\dots,n_k)=0zero(n1,,nk)=0
  • for any k,j≥0k,j\ge0k,j0, the jjj-th kkk-ary identity function is idk,j(n1,…,nk)=nj\mathrm{id}_{k,j}(n_1,\dots,n_k)=n_jidk,j(n1,,nk)=nj
  • for any n∈Nn\in\mathbb{N}nN, the successor function succ(n)=n+1\mathrm{succ}(n)=n+1succ(n)=n+1
Operations
  • Composition: given g:Nk→Ng:\mathbb{N}^k\to\mathbb{N}g:NkN and h1,h2,…,hk:Nt→Nh_1,h_2,\dots,h_k:\mathbb{N}^t\to\mathbb{N}h1,h2,,hk:NtN, the composition of ggg with h1,h2,…,hkh_1,h_2,\dots,h_kh1,h2,,hk is the ttt-ary function f(n1,n2,…,nt)=g(h1(n1,n2,…,nt),h2(n1,n2,…,nt),…,hk(n1,n2,…,nt))f(n_1,n_2,\dots,n_t)=g(h_1(n_1,n_2,\dots,n_t),h_2(n_1,n_2,\dots,n_t),\dots,h_k(n_1,n_2,\dots,n_t))f(n1,n2,,nt)=g(h1(n1,n2,,nt),h2(n1,n2,,nt),,hk(n1,n2,,nt))
  • Recursive definition: given g:Nk→Ng:\mathbb{N}^k\to\mathbb{N}g:NkN and h:Nk+2→Nh:\mathbb{N}^{k+2}\to\mathbb{N}h:Nk+2N, the function defined recursively by ggg and hhh is the (k+1)(k+1)(k+1)-ary function f(n1,n2,…,nk,0)=g(n1,n2,…,nk),f(n1,n2,…,nk,m+1)=h(n1,n2,…,nk,m,f(n1,n2,…,nk,m))f(n_1,n_2,\dots,n_k,0)=g(n_1,n_2,\dots,n_k),f(n_1,n_2,\dots,n_k,m+1)=h(n_1,n_2,\dots,n_k,m,f(n_1,n_2,\dots,n_k,m))f(n1,n2,,nk,0)=g(n1,n2,,nk),f(n1,n2,,nk,m+1)=h(n1,n2,,nk,m,f(n1,n2,,nk,m))
  • Given f:Nk→Nf:\mathbb{N}^k\to\mathbb{N}f:NkN, there exists g:Nt+k→Ng:\mathbb{N}^{t+k}\to\mathbb{N}g:Nt+kN such that g(m1,…,mt,n1,…,nk)=f(n1,…,nk)g(m_1,\dots,m_t,n_1,\dots,n_k)=f(n_1,\dots,n_k)g(m1,,mt,n1,,nk)=f(n1,,nk)
Example: plus(m,n)=m+n\mathrm{plus}(m,n)=m+nplus(m,n)=m+n
  • plus(m,0)=id2,1(m,0)=m\mathrm{plus}(m,0)=\mathrm{id}_{2,1}(m,0)=mplus(m,0)=id2,1(m,0)=m
  • plus(m,n+1)=succ(id3,3(m,n,plus(m,n)))\mathrm{plus}(m,n+1)=\mathrm{succ}(\mathrm{id}_{3,3}(m,n,\mathrm{plus}(m,n)))plus(m,n+1)=succ(id3,3(m,n,plus(m,n)))
Definition
  • The primitive recursive functions are all the basic functions and all the functions obtained from the basic function by composition and recursive definition
  • Collary
    • Compositions of primitive functions are primitive recursive
    • Functions defined recursively by primitive recursive functions are primitive recursive
Example
  • plus2(n)=n+2\mathrm{plus_2}(n)=n+2plus2(n)=n+2
  • plus(m,n)=m+n\mathrm{plus}(m,n)=m+nplus(m,n)=m+n
  • mul(m,n)=m⋅n\mathrm{mul}(m,n)=m\cdot nmul(m,n)=mn
  • exp⁡(m,n)=mn\exp(m,n)=m^nexp(m,n)=mn
  • Constant function: f(n1,…,nk)=cf(n_1,\dots,n_k)=cf(n1,,nk)=c
  • Sign function: sgn(0)=0,sgn(n+1)=1\mathrm{sgn}(0)=0,\mathrm{sgn}(n+1)=1sgn(0)=0,sgn(n+1)=1
  • Predessor function: pred(0)=0,pred(n)=n−1\mathrm{pred}(0)=0,\mathrm{pred}(n)=n-1pred(0)=0,pred(n)=n1
    • pred(0)=0\mathrm{pred}(0)=0pred(0)=0
    • pred(n+1)=succ(id2,1(n,pred(n)))\mathrm{pred}(n+1)=\mathrm{succ}(\mathrm{id}_{2,1}(n,\mathrm{pred}(n)))pred(n+1)=succ(id2,1(n,pred(n)))
  • Non-negative substraction: m∼n=max⁡{m−n,0}m\sim n=\max\{m-n,0\}mn=max{mn,0}
Definition
  • A primitive recursive function is a primitive recursive predicate if it only takes values of 000 and 111
Example
  • Is-zero function: iszero(0)=1,iszero(n+1)=0\mathrm{iszero}(0)=1,\mathrm{iszero}(n+1)=0iszero(0)=1,iszero(n+1)=0
  • Is-positive function: ispos(n)=sgn(n)\mathrm{ispos}(n)=\mathrm{sgn}(n)ispos(n)=sgn(n)
  • Great-or-equal function: geq(m,n)=iszero(n∼m)\mathrm{geq}(m,n)=\mathrm{iszero}(n\sim m)geq(m,n)=iszero(nm)
Theorem
  • The negation of a primitive recursive predicate is primitive recursive
    • ¬p(m)=1∼p(m)\neg p(m)=1\sim p(m)¬p(m)=1p(m)
  • The disjunction and conjunction of primitive recursive predicates are primitive recursive
    • p(m)∨q(m)=1∼iszero(p(m)+q(m))p(m)\lor q(m)=1\sim\mathrm{iszero}(p(m)+q(m))p(m)q(m)=1iszero(p(m)+q(m))
    • p(m)∧q(m)=1∼iszero(p(m)⋅q(m))p(m)\land q(m)=1\sim\mathrm{iszero}(p(m)\cdot q(m))p(m)q(m)=1iszero(p(m)q(m))
  • Let g,h:Nk→Ng,h:\mathbb{N}^k\to\mathbb{N}g,h:NkN be primitive recursive functions and p:Nk→Np:\mathbb{N}^k\to\mathbb{N}p:NkN be a primitive recursive predicate, the following function is primitive recursive
    • f(n1,…,nk)={g(n1,…,nk),if p(n1,…,nk)h(n1,…,nk),otherwisef(n_1,\dots,n_k)=\begin{cases}g(n_1,\dots,n_k),\mathrm{if} \ p(n_1,\dots,n_k) \\ h(n_1,\dots,n_k),\mathrm{otherwise}\end{cases}f(n1,,nk)={g(n1,,nk),if p(n1,,nk)h(n1,,nk),otherwise
    • f=p⋅g+(1∼p)⋅hf=p\cdot g+(1\sim p)\cdot hf=pg+(1p)h
Example
  • Equal function: eq(m,n)=geq(m,n)∧geq(n,m)\mathrm{eq}(m,n)=\mathrm{geq}(m,n)\land\mathrm{geq}(n,m)eq(m,n)=geq(m,n)geq(n,m)
  • Remainder function: rem(m,n)\mathrm{rem}(m,n)rem(m,n) is the remainder of mmm divided by nnn
    • rem(0,n)=0\mathrm{rem}(0,n)=0rem(0,n)=0
    • rem(m+1,n)={0,if eq(rem(m,n),pred(n))rem(m,n)+1,otherwise\mathrm{rem}(m+1,n)=\begin{cases}0,\mathrm{if} \ \mathrm{eq}(\mathrm{rem}(m,n),\mathrm{pred}(n)) \\ \mathrm{rem}(m,n)+1,\mathrm{otherwise}\end{cases}rem(m+1,n)={0,if eq(rem(m,n),pred(n))rem(m,n)+1,otherwise
  • Division function: div(m,n)\mathrm{div}(m,n)div(m,n) is the quotient of mmm divided by nnn
    • div(0,n)=0\mathrm{div}(0,n)=0div(0,n)=0
    • div(m+1,n)={div(m,n)+1,if eq(rem(m,n),pred(n))div(m,n),otherwise\mathrm{div}(m+1,n)=\begin{cases}\mathrm{div}(m,n)+1,\mathrm{if} \ \mathrm{eq}(\mathrm{rem}(m,n),\mathrm{pred}(n)) \\ \mathrm{div}(m,n),\mathrm{otherwise}\end{cases}div(m+1,n)={div(m,n)+1,if eq(rem(m,n),pred(n))div(m,n),otherwise
  • Digit function: digit(m,n,p)\mathrm{digit}(m,n,p)digit(m,n,p) is the mmm-th digit of the base-ppp representation of nnn
    • digit(m,n,p)=div(rem(n,pm),pm−1)\mathrm{digit}(m,n,p)=\mathrm{div}(\mathrm{rem}(n,p^m),p^{m-1})digit(m,n,p)=div(rem(n,pm),pm1)
  • If f(m,n)f(m,n)f(m,n) is primitive recursive, so is sumf(m,n)=∑k=0nf(m,k)\mathrm{sum}_f(m,n)=\sum_{k=0}^n{f(m,k)}sumf(m,n)=k=0nf(m,k)
    • sumf(m,0)=f(m,0)\mathrm{sum}_f(m,0)=f(m,0)sumf(m,0)=f(m,0)
    • sumf(m,n+1)=sumf(m,n)+f(m,n+1)\mathrm{sum}_f(m,n+1)=\mathrm{sum}_f(m,n)+f(m,n+1)sumf(m,n+1)=sumf(m,n)+f(m,n+1)
Theorem
  • If a function is primitive recursive, it is computable
Theorem
  • There exists a function that is computable but not primitive recursive
  • Claim: The set of all unary primitive recursive functions can be lexicographically enumerated by a TM
    • M=M=M=
      1. enumerate all strings in Σ∗\Sigma^*Σ in lexico order
      2. every time a string is enumerated, output it if it is a valid encoding of a unary primitive recursive function
  • Name all the unary primitive recursive functions as f0,f1,f2,…f_0,f_1,f_2,\dotsf0,f1,f2,
  • Define f∗(n)=fn(n)+1f^*(n)=f_n(n)+1f(n)=fn(n)+1, for ∀n∈N\forall n\in\mathbb{N}nN
    • f∗≠fnf^*\ne f_nf=fn, therefore f∗f^*f is not primitive recursive
  • f∗f^*f is computable
    • M=M=M= on input nnn
      1. enumerat all the unary primitive recursive functions until it output fn(n)f_n(n)fn(n)
      2. output fn(n)+1f_n(n)+1fn(n)+1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值