计算机科学中的逻辑

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Encoding the N-queens in SAT
We illustrate the case where n = 8 Introduce 8 × 8 atoms pij saying “there is a queen at row i and column j” There is at least 1 queen on every row 8 8 i=1 j=1 pij There is at most 1 queen on every row 8 7 8 i=1 j=1 k=j+1 (¬pij ∨ ¬pik ) There is at least 1 queen on every column There is at most 1 queen on every column There is at most 1 queen on every left diagonal There is at most 1 queen on every right diagonal
1 / 41
Introduction and outline
Focus on applications of logic in computer Science
1
SAT solvers and applications Program verification Model checking Cognitive robotics
*: more than 10100 years
Y. Liu Logic in Computer Science 5 / 41
P vs. NP
P: the class of problems for which there exists a procedure that runs in polynomial time O(nb )
Y. Liu Logic in Computer Science 12 / 41
Running the Running the N-queens N-queens
In general, the procedure we use is this: 1. we read the problem input (in this case, just n) 2. we construct the clausal formula F 3. we call a SAT solver 4. we translate the satisfying truth assignment back into the desired problem output All but step (3) should be done in polynomial time. For the N-queens, if we run a SAT solver for n=8, we will get back a truth assignment with exactly 8 of the 64 atoms true. one such is the following: p11, p25, p38, p46, p53, p67, p72, p84 (this is the first solution in left-to-right order) For n larger than 20 or 30, dpss runs into difficulties But gsat can solve these for n in the thousands.
Q
each queen must be on its own • row • column • left diagonal • right diagonal
Y. Liu Logic the problem 11 41 We will show how to solve in Computer Science by encoding /it
Y. Liu
Logic in Computer Science
4 / 41
Time complexity of algorithms
Expressed in terms of the number of operations used Decide if a truth assignment satisfies a CNF formula: O(m) Naive algorithm to solve SAT: O(2n m) n – the number of atoms, m – the length of the formula The computer time used by algorithms
Y. Liu
Logic in Computer Science
3 / 41
What is SAT?
A literal is an atom or the negation of an atom A clause is a disjunction of literals A formula is in Conjunctive Normal Form (CNF) if it is a conjunction of clauses Example: (b ∨ c) ∧ (¬a ∨ ¬d) ∧ (¬b ∨ d) SAT: Given a propositional formula in CNF, decide if there exists a truth assignment that satisfies the formula
Y. Liu
Logic in Computer Science
10 / 41
the encoded formula using a SAT solver
The N-queens problem
An example: the N-queens problem Given N queens and an NxN chess board, find a way of placing those queens in such a way that none of them can attack any of the others.
Example: decide if a propositional formula is satisfiable
P = NP ? One of the seven Millennium Prize Problems selected by the Clay Mathematics Institute to carry a US$ 1,000,000 prize for the first correct solution. It is generally accepted that P = N P
Y. Liu Logic in Computer Science 8 / 41
The GSAT procedure
We start with a random truth assignment to all atoms, and then start changing the truth of certain atoms until we either obtain a satisfying assignment or give up and try again (up to a maximum) GSAT often outperforms dpll Incomplete SAT solver
Logic in Computer Science
Yongmei Liu ymliu@mail.sysu.edu.cn
Dept. of Computer Science Sun Yat-sen University
December 14, 2009
Y. Liu
Logic in Computer Science
simplify F using M , get G, return dpll(G)
2
3
4
Choose an atom A return dp1(A, F ) ∨ dp1(¬A, F )
5
Hale Waihona Puke Baidu
Example: (b ∨ c) ∧ (¬a ∨ ¬d) ∧ (¬b ∨ d) Complete SAT solver
2
3
4
Y. Liu
Logic in Computer Science
2 / 41
A motivating example
We would like to select people from Ann, Bob, Carol and Dan for a certain job. The following constraints must be satisfied: Bob or Carol should be selected Ann and Dan cannot be both selected If Bob is selected, Dan should also be selected How should we select the people? (b ∨ c) ∧ (¬a ∨ ¬d) ∧ (¬b ∨ d) {B, D} What if we have many people and many constraints?
Y. Liu
Logic in Computer Science
9 / 41
Progress of SAT solvers
1960–2010, about 50 years history 1995–2010, significant growth and success in SAT solver, research based on DPLL The number of variables: 10 → 106 Many practical applications emerged, push solvers to their limits, and motivate more efficient algorithm New techniques for SAT solvers emerge one after the other GRASP (1996): the pioneer of 2nd generation of SAT solver CHAFF (2001): careful engineering all aspects of the search
Y. Liu
Logic in Computer Science
7 / 41
The DPLL procedure
Named after the authors Davis, Putnam, Logemann, and Loveland dpll(F ):
1
If the set of clauses F is empty, return 1 If F contains an empty clause, return 0 If F contains a unit clause M , return dp1(M, F )
Y. Liu
Logic in Computer Science
6 / 41
NP Completeness
A problem is NP-complete if it is in NP and any problem in NP can be reduced to it in polynomial time if any NP-complete problem is in P, then P=NP SAT is a classical NP-complete problem, so any problem in NP can be reduced to SAT in poly time There are thousands of computational problems of economic significance that are known to be in NP Stephen Cook received the 1982 Turing award for his work on NP-completeness
Example: decide if a truth assignment satisfies a formula
NP: the class of problems where we are searching for an item in a large space of possibilities, but where we can test if a candidate item is a solution in polynomial time
相关文档
最新文档