0x01 从判定问题到形式语言

这篇讲知识证明的wiki([1]):

https://en.wikipedia.org/wiki/Proof_of_knowledge

里面有一句话:

Let x be a language element of language L in NP

这篇讲NPC的文章([2])

http://www.cs.princeton.edu/courses/archive/spr11/cos423/Lectures/NP-completeness.pdf

里面提到Decision Problem([4),Decision Problem就是判定yes/no的问题,一个Decision Problem Q可以等价于一个Formal language L

L = {x ∈ {0,1}* : Q(x) = 1}

资料[4]里举例了Graphs, Deterministic Finite Automaton, DFA问题,Context Free Grammar, CFG问题,Turing Machine问题,素数分解,Boolean satisfiability problem等等都可以通过编码成字符串,进而转成形式语言。

例如,下面是一个上下文无关语言的产生式:

  • S->XSY|e
  • X->aX|a
  • Y->bY|e

可以编码成:

  • a list of its variables
  • a list of its terminal symbols
  • a list of its rules as (LHS, RHS) pairs
  • its start variable

那么,转成字符串就是:

  • '<G>=(S,X,Y)(a,b)((S,XSY),(S,e),(X,aX),(X,a),(Y,bY),(Y,e))S'

实际上,字符串二进制化后就变成了只用两个字符({0,1})表示的字符串:

  1. const decesionProblem = '<G>=(S,X,Y)(a,b)((S,XSY),(S,e),(X,aX),(X,a),(Y,bY),(Y,e))S'.split('')
  2. const reducer =
  3. (accumulator, currentValue) =>
  4. accumulator + currentValue.charCodeAt(0).toString(2);
  5. const binaryString = decesionProblem.reduce(reducer,'');
  6. console.log(binaryString);

输出:

  1. "11110010001111111101111011010001010011101100101100010110010110011010011010001100001101100110001010100110100010100010100111011001011000101001110110011010011011001010001010011101100110010110100110110010100010110001011001100001101100010100110110010100010110001011001100001101001101100101000101100110110011000101011001101001101100101000101100110110011001011010011010011010011"

可以理解为Q是判定算法,该判定算法能确定一个具体的Decision Problem,其结果是yes还是no。

那么,L是一个集合,其中每个x都是被Q判定为yes的Decison Problem的实例。

那么,P问题等价于如下的语言集合:

P = {L \subseteq {0, 1}* : exist an algorithm A that decides L in p-time}

我们可以理解为,P是由所有能在多项式时间内确定yes/no的Q所导出的语言L组成。是不是很绕?分解一下:

  • Q是一个判定算法。
  • Q是一个能在多项式时间内判定yes/no的判定算法。
  • L是被Q判定结果为yes的所有输入x的集合。
  • L是被Q判定结果为yes的所有输入x的集合所表示的形式语言。

0x02 P问题

在[3]里面描述:

P is the set of languages whose memberships are decidable by a Turing Machine that makes a polynomial number of steps.

这里增加了Turing Machine的限定,也就是Q是在Turing Machine上执行的。参考链接[5],[6]里是对确定性图灵机和非确定性图灵机的描述。

例如,下面的k路径问题,属于P ([2]):

PATH = {< G, u, v, k > : G = (V, E) is an undirected

graph, u,v ∈ V, k ≥ 0 is an integer, and exist a path

from u to v in G with ≤ k edges}

因此,P是一类判定问题的集合,同时等价于一类形式语言的集合,这些语言在确定性图灵机上存在多项式(Polynomial)时间复杂度算法。

0x03 证明凭据(certificate),证明(certifier)

算法A验证了语言L,iff([2]):

L = {x ∈ {0, 1}* : exist y ∈ {0, 1}* s.t. A(x, y) = 1}

通过例子理解Certificate,例如下面的Independent Set属于NP([3]):

Given a graph G, is there set S of size ≥ k such that no two nodes in S are connected by an edge?

  • Finding the set S is hard
  • But if I give you a set S∗, checking whether S∗ is the answer is easy
  • S∗ acts as a certificate that ⟨G,k⟩ is a yes instance of Independent Set

Certificate是否有效(efficient)([3]):

An algorithm B is an efficient certifier for problem X if:

  • B is a polynomial time algorithm that takes two input strings I (instance of X) and C (a certificate)
  • B outputs either yes or no.
  • There is a polynomial p(n) such that for every string I: I ∈ X if and only if there exists string C of length ≤ p(|I|) such that B(I,C) = yes.

Certification的含义是“帮手”([3]):

B is an algorithm that can decide whether an instance I is a yes instance if it is given some “help” in the form of a polynomially long certificate.

注意,C是Certificate,而算法B是certifier

Let’s say you had an efficient certifier B for the Independent Set problem.

怎样找到Certificate呢?

Try every string C of length ≤ p(|I|) and ask is B(I,C) = yes?

0x04 NP问题

那么,NP问题等价于如下的语言集合([2]):

NP = {L \subseteq {0, 1}* : exist a certificate y, |y| = O(|x|^k), and an algorithm A s.t. A(x, y) = 1}

在[3]里面描述NP:

NP is the set of languages for which there exists an efficient certifier.

区别于P:

P is the set of languages for which there exists an efficient certifier that ignores the certificate.

就是说P和NP问题都能在多项式时间内判定,但是NP问题的判定需要certificate的帮助:

A problem is in P if we can decided them in polynomial time. It is in NP if we can decide them in polynomial time, if we are given the right certificate.

我们可以理解为,如果:

  • 存在长度是字符串x的多项式倍的字符串y
  • 存在验证算法A
  • 使得A(x,y)=1

那么:

  • 能通过A(x,y)=1的所有x构成的语言是L
  • 所有L的集合是NP语言集合

例如,下面的子集求和问题,属于NP:

SUBSET-SUM: Given finite set S of integers, is there a subset whose sum is exactly t?

因此,P问题是一类判定问题的集合,同时等价于一类形式语言的集合,这类语言在确定性图灵机上存在依赖于Certificate的多项式(Polynomial)时间复杂度的验证算法(Certifier),在非确定性图灵机上(例如量子计算机)存在多项式时间复杂度的求解算法。

0x05 P vs NP vs NPC

中间讨论了P、NP、NPC问题,简单说:

  • P \subseteq NP \subseteq NP-hard
  • Co-NP = {L': L ∈ NP}
  • NPC=NP中最难的集合,并且他们等价

证明P \subseteq NP是很容易的:

Proof. Suppose X ∈ P. Then there is a polynomial-time algorithm A for X.

To show that X ∈ NP, we need to design an efficient certifier B(I,C).

JusttakeB(I,C)=A(I).

0x06 夹逼法(Reduction and NPC Reduction)

下面是对L语言进行规约,两个步骤:

Reduce language L1 to L2 via function f:

  1. Convert input x of L1 to instance f(x) of L2
  2. Apply decision algorithm for L2 to f(x)

则L2的判定时间>=L1的判定时间,即:L1≤L2

引入p≤的概念:

L1is p-time reducible to L2, or L1 p≤ L2, if exist a ptime

computable function f : {0, 1}* -> {0, 1}* s.t. for all x ∈ {0, 1}*, x ∈ L1

iff f(x) ∈ L2

从而,要判定一个形式语言是否是P的,使用夹逼法:

If L1 p≤ L2 and L2 ∈ P, then L1 ∈ P

进一步,要判定一个形式语言是否是NPC的,使用夹逼法:

A language L ∈ {0, 1}* is NP-complete if:

  1. L ∈ NP, and
  2. L’ p≤ L for every L’ ∈ NP, i.e. L is NP-hard

利用其他已知的NPC问题,就可以夹逼:

  1. If L is language s.t. L’ p≤L where L’ ∈ NPC, then L is NP-hard.
  2. If L ∈ NP, then L ∈ NPC.

这样就得到证明NPC的步骤:

This gives us a recipe for proving any L ∈ NPC:

  1. Prove L ∈ NP
  2. Select L’ ∈ NPC
  3. Describe algorithm to compute f mapping every input x of L’ to input f(x) of L
  4. Prove f satisfies x ∈ L’ iff f(x) ∈ L, for all x ∈ {0, 1}*
  5. Prove computing f takes p-time

最后,如果P=NP,那么....:

“If P = NP, then the world would be a profoundly different place than we usually assume it to be. There would be no special value in "creative leaps," no fundamental gap between solving a problem and recognizing the solution once it's found. Everyone who could appreciate a symphony would be Mozart; everyone who could follow a step-by-step argument would be Gauss...”

— Scott Aaronson, MIT

但是证明或者证伪P=NP是很难的。

0x07 wait to be continue...

我们最开始是为了理解在Proof of knowledge ([1]) 里面这句话的作用:

Let x be a language element of language L in NP

我们需要一步一步拆解。

0x08 参考

[1] wiki:Proof_of_knowledge

[2] cs.princeton.edu:NP-completeness.pdf

[3] cs.cmu.edu:np.pdf

[4] ccs.neu.edu:Decision-Problems

[5] wiki:Turing_machine

[6] wiki:Non-deterministic_Turing_machine

证明与计算(1): Decision Problem, Formal Language L, P and NP的更多相关文章

  1. 证明与计算(2): 离散对数问题(Discrete logarithm Problem, DLP)

    离散对数问题,英文是Discrete logarithm Problem,有时候简写为Discrete log,该问题是十几个开放数学问题(Open Problems in Mathematics, ...

  2. [HNOI2004]Language L语言

    2777: [HNOI2004]Language L语言 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 10  Solved: 5[Submit][S ...

  3. 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)

    0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...

  4. 证明与计算(7): 有限状态机(Finite State Machine)

    什么是有限状态机(Finite State Machine)? 什么是确定性有限状态机(deterministic finite automaton, DFA )? 什么是非确定性有限状态机(nond ...

  5. 证明与计算(4): 完美散列函数(Perfect Hash function)

    原文:wiki: 完美散列函数 假设,写一个SQL语句解析器,词法分析对SQL语句解析,把语句分成了多个token,一般这个时候会需要查询这个token是否是一个关键字token. 例如keyword ...

  6. NP问题/NP完全问题(NP-complete problem)如何判断是否是NP完全问题

    在算法复杂度分析的过程中,人们常常用特定的函数来描述目标算法,随着变量n的增长,时间或者空间消耗的增长曲线,近而进一步分析算法的可行性(有效性). 引入了Big-O,Big-Ω,来描述目标算法的上限. ...

  7. feilong's blog | 目录

    每次把新博客的链接分享到技术群里,我常常会附带一句:蚂蚁搬家.事实上也确实如此,坚持1篇1篇的把自己做过.思考过.阅读过.使用过的技术和教育相关的知识.方法.随笔.索引记录下来,并持续去改进它们,希望 ...

  8. Formal Grammars of English -10 chapter(Speech and Language Processing)

    determiner  限定词 DET propernoun 专有名词 NP (or noun phrase) mass noun 不可数名词 Det Nouns 限定词名词 relative pro ...

  9. Formal Definitions Using ASN.1 - SNMP Tutorial

    30.7 Formal Definitions Using ASN.1 The SMI standard specifies that all MIB variables must be define ...

随机推荐

  1. Elasticsearch Index模块

    1.  Index Setting(索引设置) 每个索引都可以设置索引级别.可选值有: static  :只能在索引创建的时候,或者在一个关闭的索引上设置 dynamic:可以动态设置 1.1.  S ...

  2. Android6.0运行时权限(基于RxPermission开源库)

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 在6.0以前的系统,都是权限一刀切的处理方式,只要用户安装,Manifest申请的权限都会被赋予,并且安装后权限也撤销不了. And ...

  3. Tesseract 在 windows 下的安装及简单应用

    Tesseract 是一个开源的 OCR 引擎,可以识别多种格式的图像文件并将其转换成文本,最初由 HP 公司开发,后来由 Google 维护.下载地址:https://digi.bib.uni-ma ...

  4. Docker进阶之八:搭建LNMP网站平台实战

    搭建LNMP网站平台实战 LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可 ...

  5. 玩转Spring Cloud之API网关(zuul)

    最近因为工作原因,一直没有空写文章,所以都是边忙项目,边利用空闲时间,周末时间学习总结,最终在下班回家后加班加点写完本篇文章,若有不足之处,还请谅解,谢谢! 本文内容导航: 一.网关的作用 二.网关与 ...

  6. k8s应用机密信息与配置管理(九)--技术流ken

    secret 应用启动过程中可能需要一些敏感信息,比如访问数据库的用户名密码或者秘钥.将这些信息直接保存在容器镜像中显然不妥,Kubernetes 提供的解决方案是 Secret. Secret 会以 ...

  7. 第三章:shiro授权认证

    授权:也叫访问控制,即在应用中控制谁能访问哪些资源(如访问页面/编辑数据/页面操作等). 主体:即访问应用的用户,在Shiro中使用Subject代表该用户.用户只有授权后才允许访问相应的资源. 资源 ...

  8. PHP八大设计模式

    设计模式 单例模式解决的是如何在整个项目中创建唯一对象实例的问题,工厂模式解决的是如何不通过new建立实例对象的方法. 单例模式 $_instance必须声明为静态的私有变量 构造函数和析构函数必须声 ...

  9. 对于python爬虫urllib库的一些理解(抽空更新)

    urllib库是Python中一个最基本的网络请求库.可以模拟浏览器的行为,向指定的服务器发送一个请求,并可以保存服务器返回的数据. urlopen函数: 在Python3的urllib库中,所有和网 ...

  10. 【CSS学习】--- 字体样式

    一.前言 CSS字体属性可以定义文本的字体系列.大小.加粗.颜色.风格(如斜体)和变形(如小型大写字母). CSS的字体属性: font-family 设置字体系列 font-size 设置字体的尺寸 ...