如何证明一种语言是上下文无关的?


26

许多技术可以证明某种语言不是上下文无关的,但是如何证明一种语言不是上下文无关的?

有什么技术可以证明这一点?显然,一种方法是展现该语言的上下文无关语法。是否有系统的技术来查找给定语言的无上下文语法?

对于常规语言中, 系统的方法来得到一个正规文法/状态自动:例如,迈希尔-尼罗德定理提供了一种方法。上下文无关的语言是否有相应的技术?


在这里,我的动机是(希望)建立一个参考问题,其中包含一系列试图证明给定语言不受上下文限制时通常有用的技术。由于这里有很多问题是特殊情况,因此,如果我们能记录面对此类问题时可以使用的通用方法或通用技术,那就太好了。


请允许我留下我通常的笔记:在为手头语言提供上下文无关的语法时,您需要正确性证明,这可能会使方法变得笨拙。
拉斐尔

为了使它成为一个适当的参考问题,我们可以向问题转储者抛出,您能否添加一个有关语法和自动机的答案,也许每个例子都包含一个?谢谢!
拉斐尔

在将材料移到此处之前,请注意,Rick Decker和babou 在一个重复的问题上收集了一些典型的与上下文无关的成语。
拉斐尔

Answers:


13

在许多示例中有效的实用方法(但并非总是如此,我知道)正在尝试查找语言中字符串的嵌套结构。必须在字符串的不同部分中同时生成“嵌套依赖项”。

我们还有基本的工具箱

  1. 串联:如果可以将语言分成两个连续的部分,请使用此产生形式SS1S2

  2. 并集:分成不相交的部分SS1S2

  3. 迭代:SS1Sε

例子1

这是嵌套的示例(谢谢Raphael)。

L={bkal(bc)manbok,l,m,n,oN,ko,2l=n,m2}

替换为2 l。现在我们可以将n置于条件中。n2ln

替换为k > o  或  k < o(混淆?o是“哦”而不是“零”)。应用工会工具。我们在这里使用k > o。同样,k > o,如果k = s + os > 0,其中s是一个新变量。替换ķ通过小号+ Ökok>o or k<ook>ok>ok=s+os>0sks+o

L1={bs+oal(bc)ma2lbol,m,o,sN,s>0,m2}

一些简单的重写。

L1={bbsboalbcbc(bc)m(aa)lbol,m,o,sN}

现在,我们看到了嵌套结构,并开始构建语法。

Ť b ü ü b ù | ε(参见:级联和迭代这里)S1TVTbUUbUε

(我们在两侧生成 o bVbVbWo b

WaWaaX

ÿ b Ç b Ç ž b Ç ž | εXYZYbcbcZbcZε

例子2

K={akblcml=m+k}

第一个“显而易见的”重写。

K={akbm+kcmm,k0}={akbmbkcmm,k0}

在语言学上,这称为“跨序列依赖”:交织(通常)强烈表示无上下文无关性。当然,m + k = k + m,我们就得救了。k,m,k,mm+k=k+m

K={akbk+mcmm,k0}={akbkbmcmm,k0}

与制作X 一个X b | εÿ b ý Ç | εSXYXaXbεYbYcε

类似地K={akblcmm=k+l}={akblclckk,l0}

与制作X b X C ^ | εSaScXXbXcε


最后的评论:这些技术可以帮助您提出一种与上下文无关的候选语法,希望能识别您的语言。 可能仍需要正确性证明,以确保语法确实可以识别您的语言(仅此而已,仅此而已)。


11

可以使用CFL的一个特征,即Chomsky-Schützenberger定理

戴克语言

为字母。我们定义戴克 -language d ŤŤ Ť*Ť由上下文无关文法ģ = { 小号} Ť Ťδ 小号δ由下式给出TDT(TT^)TG=({S},TT^,δ,S)δ

SaSa^Sε,aT

乔姆斯基-舒岑贝格定理

是如果上下文且仅当有LΣ

  • 字母表T
  • 一个正则语言R(TT^)
  • 同态ψ:(TT^)Σ

以便

L=ψ(DTR)

请注意,同态性扩展到单词(逐个符号),然后扩展到语言(逐个单词)。

考虑。用L={anbncmn,mN

  • (和,规范地Ť = { ] }),T={[,}T^={],}
  • 并且R=L([])
  • ψ(x)={a,x=[b,x= ]ε,x=c,x= 

该定理暗示是上下文无关的,特别是因为L

DTR={[n]nmmn,mN}

例子2

表明,是上下文无关。L={bkal(bc)manbok,l,m,n,oN,ko,2l=n,m2}

这里,我们需要对一种类型的括号的,一个用于b Ç,一个用于b,和另一用于将模拟b那个原因ķ Ò。我们用abcbbko

  • T={[,,,<}
  • R=L(<+>+[++])L([++]<+>+)
  • ψ(x)={b,x{,,<}a,x=[aa,x= ]bc,x=ε,else

and apply the theorem. In order to see that L=ψ(DTR), we don't need more than the fact that matching symbols (e.g. [ and ]) have to occur equally often in any wDT. Adding this contraint to the regular expressions we defined R by, we get

DTR={<p>po[lmm]lop1,o0,l0,m2} {}

and therewith

ψ(DTR)={bp+oal(bc)ma2lbop1,o0,l0,m2} {}={bkal(bc)manbok,l,m,n,oN,k>o,2l=n,m2} {}=L.

To grammars and automata

If we want to have an automaton or grammar in the end, we have some more work ahead of us.

  • Towards an automaton, construct the NPDA for DT and an NFA for R. The former is standard and we have algorithms for the latter, provided the language is given in a suitable representation (see also here). Intersection both is another standard construction and ψ can be applied to every transition individually.

  • Towards a grammar, build one for R (again, should be standard), take the one for DT and intersect them. Then apply ψ to the rule set (symbol for symbol).

Arguably, this is easy since algorithmic; the complexity lies in finding suitable T, R and ψ. I don't know if this approach is (often) simpler than constructing PDA/grammars directly but it may allow to focus on the important features of the language at hand. Try for yourself!


It is undecidable whether any given language is context-free.
reinierpost
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.