Propositional LogicComputer exercises
Mario Alviano
University of Calabria, Italy
A.Y. 2017/2018
1 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
2 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
3 / 40
SAT solvers input: DIMACS format
Standard input format for SAT solversRepresentation of CNF formulas stemming from achallenge run by DIMACS (Center for DiscreteMathematics and Theoretical Computer Science) in 1992
Example
(x1 ∨ x2 ∨ ¬x3) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
DIMACS encoding
c This is a CNF in DIMACScp cnf 4 31 2 -3 0
-2 04 -3 0
4 / 40
SAT solvers input: DIMACS format
Standard input format for SAT solversRepresentation of CNF formulas stemming from achallenge run by DIMACS (Center for DiscreteMathematics and Theoretical Computer Science) in 1992
Example
(x1 ∨ x2 ∨ ¬x3) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
DIMACS encoding
c This is a CNF in DIMACScp cnf 4 31 2 -3 0
-2 04 -3 0
4 / 40
DIMACS format in BNF grammar
BNF grammar
<input> ::= <preamble> <formula> EOF
<preamble> ::= [<commentlines>] <problemline><commentlines> ::= <commentline> <commentlines> | <commentline><commentline> ::= c <text> EOL<problemline> ::= p cnf <pnum> <pnum> EOL
<formula> ::= <clauselist><clauselist> ::= <clause> <clauselist> | <clause><clause> ::= <literal> <clause> | <literal> 0<literal> ::= <num>
<text> ::= A sequence of non-special ASCII characters<pnum> ::= A signed integer greater than 0<num> ::= A signed integer different from 0
5 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
6 / 40
Setup
1 (I suggest to) Boot Linux
2 Download one of the solvers athttp://minisat.se/MiniSat.html
MiniSat 2.2.0: only sourcesMiniSat 1.14: sources and binary (if you are lazy)
3 Build and have a look at the help$ minisat --help
7 / 40
Setup
1 (I suggest to) Boot Linux2 Download one of the solvers athttp://minisat.se/MiniSat.html
MiniSat 2.2.0: only sourcesMiniSat 1.14: sources and binary (if you are lazy)
3 Build and have a look at the help$ minisat --help
7 / 40
Setup
1 (I suggest to) Boot Linux2 Download one of the solvers athttp://minisat.se/MiniSat.html
MiniSat 2.2.0: only sources
MiniSat 1.14: sources and binary (if you are lazy)
3 Build and have a look at the help$ minisat --help
7 / 40
Setup
1 (I suggest to) Boot Linux2 Download one of the solvers athttp://minisat.se/MiniSat.html
MiniSat 2.2.0: only sourcesMiniSat 1.14: sources and binary (if you are lazy)
3 Build and have a look at the help$ minisat --help
7 / 40
Setup
1 (I suggest to) Boot Linux2 Download one of the solvers athttp://minisat.se/MiniSat.html
MiniSat 2.2.0: only sourcesMiniSat 1.14: sources and binary (if you are lazy)
3 Build and have a look at the help$ minisat --help
7 / 40
Simple test (1)
(x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (¬x1 ∨ ¬x2)
c This is a CNF in DIMACScp cnf 2 31 2 01 -2 0
-1 -2 0
8 / 40
Simple test (1)
(x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (¬x1 ∨ ¬x2)
c This is a CNF in DIMACScp cnf 2 31 2 01 -2 0
-1 -2 0
8 / 40
Simple test (2)
(x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (¬x1 ∨ x2) ∧ (¬x1 ∨ ¬x2)
p cnf 2 41 2 01 -2 0
-1 2 0-1 -2 0
9 / 40
Simple test (2)
(x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (¬x1 ∨ x2) ∧ (¬x1 ∨ ¬x2)
p cnf 2 41 2 01 -2 0
-1 2 0-1 -2 0
9 / 40
More tests
Example
1 (x1 ∨ x2 ∨ ¬x3) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
2 (x1 ∨ x2 ∨ ¬x3 ∨ ¬x4) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
3 {x1 ∨ x2 ∨ x3, x1 ∨ x2 ∨ ¬x3, x1 ∨ ¬x2 ∨ x3, x1 ∨ ¬x2 ∨ ¬x3,¬x1 ∨ x4, x1 ∨ ¬x4 ∨ ¬x5 ∨ x6, ¬x1 ∨ x7}
10 / 40
More tests
Example
1 (x1 ∨ x2 ∨ ¬x3) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
2 (x1 ∨ x2 ∨ ¬x3 ∨ ¬x4) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
3 {x1 ∨ x2 ∨ x3, x1 ∨ x2 ∨ ¬x3, x1 ∨ ¬x2 ∨ x3, x1 ∨ ¬x2 ∨ ¬x3,¬x1 ∨ x4, x1 ∨ ¬x4 ∨ ¬x5 ∨ x6, ¬x1 ∨ x7}
10 / 40
More tests
Example
1 (x1 ∨ x2 ∨ ¬x3) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
2 (x1 ∨ x2 ∨ ¬x3 ∨ ¬x4) ∧ (¬x2) ∧ (x4 ∨ ¬x3)
3 {x1 ∨ x2 ∨ x3, x1 ∨ x2 ∨ ¬x3, x1 ∨ ¬x2 ∨ x3, x1 ∨ ¬x2 ∨ ¬x3,¬x1 ∨ x4, x1 ∨ ¬x4 ∨ ¬x5 ∨ x6, ¬x1 ∨ x7}
10 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
11 / 40
Pigeons and Holes
Pigeons in their Holes
12 / 40
Pigeon Hole Problem
Pigeon Hole Problem — PHP
The problem PHP(m,n) is whether m pigeons can enter into npigeon holes
Task
Find a family of formulas which are satisfiablewhen PHP(m,n) is
13 / 40
Pigeon Hole Problem
Pigeon Hole Problem — PHP
The problem PHP(m,n) is whether m pigeons can enter into npigeon holes
Task
Find a family of formulas which are satisfiablewhen PHP(m,n) is
13 / 40
PHP — Modellation
Modellation
m × n propositional variables:xi,j , where i ≤ m and j ≤ nxi,j means that pigeon i is put into hole j
The formula should express:
1 Each pigeon is in some hole2 Each pigeon is in at most one hole3 In each hole there is at most one pigeon
14 / 40
PHP — Modellation
Modellation
m × n propositional variables:xi,j , where i ≤ m and j ≤ nxi,j means that pigeon i is put into hole j
The formula should express:
1 Each pigeon is in some hole2 Each pigeon is in at most one hole3 In each hole there is at most one pigeon
14 / 40
PHP — Modellation
Modellation
m × n propositional variables:xi,j , where i ≤ m and j ≤ nxi,j means that pigeon i is put into hole j
The formula should express:1 Each pigeon is in some hole
2 Each pigeon is in at most one hole3 In each hole there is at most one pigeon
14 / 40
PHP — Modellation
Modellation
m × n propositional variables:xi,j , where i ≤ m and j ≤ nxi,j means that pigeon i is put into hole j
The formula should express:1 Each pigeon is in some hole2 Each pigeon is in at most one hole
3 In each hole there is at most one pigeon
14 / 40
PHP — Modellation
Modellation
m × n propositional variables:xi,j , where i ≤ m and j ≤ nxi,j means that pigeon i is put into hole j
The formula should express:1 Each pigeon is in some hole2 Each pigeon is in at most one hole3 In each hole there is at most one pigeon
14 / 40
Example: PHP(3,2)
1 Each pigeon is in some hole
x1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one hole
x1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeon
x1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one hole
x1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeon
x1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1
x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeon
x1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1
x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeon
x1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeon
x1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeonx1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1
x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeonx1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeonx1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeonx1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1
x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
Example: PHP(3,2)
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one holex1,1 → ¬x1,2x1,2 → ¬x1,1x2,1 → ¬x2,2x2,2 → ¬x2,1x3,1 → ¬x3,2x3,2 → ¬x3,1
3 In each hole there is at most one pigeonx1,1 → ¬x2,1 ∧ ¬x3,1x2,1 → ¬x1,1 ∧ ¬x3,1x3,1 → ¬x1,1 ∧ ¬x2,1x1,2 → ¬x2,2 ∧ ¬x3,2x2,2 → ¬x1,2 ∧ ¬x3,2x3,2 → ¬x1,2 ∧ ¬x2,2
≡
x1,1 → ¬x2,1, x1,1 → ¬x3,1x2,1 → ¬x1,1, x2,1 → ¬x3,1x3,1 → ¬x1,1, x3,1 → ¬x2,1x1,2 → ¬x2,2, x1,2 → ¬x3,2x2,2 → ¬x1,2, x2,2 → ¬x3,2x3,2 → ¬x1,2, x3,2 → ¬x2,2
15 / 40
PHP(m,n) — Formula
m∧i=1
n∨j=1
xi,j
∧m∧
i=1
n∧j=1
(xi,j →n∧
k=1k 6=j
¬xi,k ) ∧m∧
i=1
n∧j=1
(xi,j →m∧
k=1k 6=i
¬xk ,j)
CNF Formula
m∧i=1
n∨j=1
xi,j
∧m∧
i=1
n∧j=1
n∧k=1k 6=j
(¬xi,j ∨ ¬xi,k ) ∧m∧
i=1
n∧j=1
m∧k=1k 6=i
(¬xi,j ∨ ¬xk ,j)
16 / 40
PHP(m,n) — Formula
m∧i=1
n∨j=1
xi,j
∧m∧
i=1
n∧j=1
(xi,j →n∧
k=1k 6=j
¬xi,k ) ∧m∧
i=1
n∧j=1
(xi,j →m∧
k=1k 6=i
¬xk ,j)
CNF Formula
m∧i=1
n∨j=1
xi,j
∧m∧
i=1
n∧j=1
n∧k=1k 6=j
(¬xi,j ∨ ¬xi,k ) ∧m∧
i=1
n∧j=1
m∧k=1k 6=i
(¬xi,j ∨ ¬xk ,j)
16 / 40
Example: PHP(3,2) in CNF
1 Each pigeon is in some holex1,1 ∨ x1,2, x2,1 ∨ x2,2, x3,1 ∨ x3,2
2 Each pigeon is in at most one hole¬x1,1 ∨ ¬x1,2¬x1,2 ∨ ¬x1,1¬x2,1 ∨ ¬x2,2¬x2,2 ∨ ¬x2,1¬x3,1 ∨ ¬x3,2¬x3,2 ∨ ¬x3,1
3 In each hole there is at most one pigeon¬x1,1 ∨ ¬x2,1, ¬x1,1 ∨ ¬x3,1¬x2,1 ∨ ¬x1,1, ¬x2,1 ∨ ¬x3,1¬x3,1 ∨ ¬x1,1, ¬x3,1 ∨ ¬x2,1¬x1,2 ∨ ¬x2,2, ¬x1,2 ∨ ¬x3,2¬x2,2 ∨ ¬x1,2, ¬x2,2 ∨ ¬x3,2¬x3,2 ∨ ¬x1,2, ¬x3,2 ∨ ¬x2,2
17 / 40
PHP in DIMACS
We must convert the variables to positive integers
x1,1 7→ 1...
xm,1 7→ m
x1,2 7→ m + 1...
xm,2 7→ 2×m...
x1,n 7→ (n − 1)×m + 1...
xm,n 7→ n ×m
Therefore, xi,j will be represented by (j − 1)×m + i
18 / 40
PHP in DIMACS
We must convert the variables to positive integers
x1,1 7→ 1...
xm,1 7→ mx1,2 7→ m + 1
...xm,2 7→ 2×m
...x1,n 7→ (n − 1)×m + 1
...xm,n 7→ n ×m
Therefore, xi,j will be represented by (j − 1)×m + i
18 / 40
PHP in DIMACS
We must convert the variables to positive integers
x1,1 7→ 1...
xm,1 7→ mx1,2 7→ m + 1
...xm,2 7→ 2×m
...x1,n 7→ (n − 1)×m + 1
...xm,n 7→ n ×m
Therefore, xi,j will be represented by (j − 1)×m + i
18 / 40
PHP in DIMACS
We must convert the variables to positive integers
x1,1 7→ 1...
xm,1 7→ mx1,2 7→ m + 1
...xm,2 7→ 2×m
...x1,n 7→ (n − 1)×m + 1
...xm,n 7→ n ×m
Therefore, xi,j will be represented by (j − 1)×m + i
18 / 40
Example: PHP(3,2) in DIMACS
1 x1,1∨x1,2, x2,1∨x2,2, x3,1∨x3,2
2 ¬x1,1 ∨ ¬x1,2¬x1,2 ∨ ¬x1,1¬x2,1 ∨ ¬x2,2¬x2,2 ∨ ¬x2,1¬x3,1 ∨ ¬x3,2¬x3,2 ∨ ¬x3,1
3 ¬x1,1 ∨ ¬x2,1, ¬x1,1 ∨ ¬x3,1¬x2,1 ∨ ¬x1,1, ¬x2,1 ∨ ¬x3,1¬x3,1 ∨ ¬x1,1, ¬x3,1 ∨ ¬x2,1¬x1,2 ∨ ¬x2,2, ¬x1,2 ∨ ¬x3,2¬x2,2 ∨ ¬x1,2, ¬x2,2 ∨ ¬x3,2¬x3,2 ∨ ¬x1,2, ¬x3,2 ∨ ¬x2,2
p cnf 6 211 4 0 -1 -2 02 5 0 -1 -3 03 6 0 -4 -5 0
-1 -4 0 -4 -6 0-4 -1 0 -2 -1 0-2 -5 0 -2 -3 0-5 -2 0 -5 -4 0-3 -6 0 -5 -6 0-6 -3 0 -3 -1 0-3 -2 0-6 -4 0-6 -5 0
19 / 40
PHP — Why?
Hard problem for SAT solvers
PHP(m,n) is unsatisfiable if and only if m > n
SAT solvers have an exponential behaviorSymmetries tend to mess up backtracking algorithmsTry it with the PHP(m,n) formula generator!
20 / 40
PHP — Why?
Hard problem for SAT solvers
PHP(m,n) is unsatisfiable if and only if m > nSAT solvers have an exponential behavior
Symmetries tend to mess up backtracking algorithmsTry it with the PHP(m,n) formula generator!
20 / 40
PHP — Why?
Hard problem for SAT solvers
PHP(m,n) is unsatisfiable if and only if m > nSAT solvers have an exponential behaviorSymmetries tend to mess up backtracking algorithms
Try it with the PHP(m,n) formula generator!
20 / 40
PHP — Why?
Hard problem for SAT solvers
PHP(m,n) is unsatisfiable if and only if m > nSAT solvers have an exponential behaviorSymmetries tend to mess up backtracking algorithmsTry it with the PHP(m,n) formula generator!
20 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
21 / 40
Rook Independence Problem
Rook Independence Problem — RIP(m,n)
Place m rooks on an n × n chessboard so that they do notthreaten each other
Reminder: Rook moves
8 0Z0Z0Z0Z7 Z0Z0Z0Z06 0Z0Z0Z0Z5 Z0Z0Z0Z04 0Z0ZrZ0Z3 Z0Z0Z0Z02 0Z0Z0Z0Z1 Z0Z0Z0Z0
1 2 3 4 5 6 7 8
Example. RIP(2,2)
2 rZ1 Zr
1 2
22 / 40
Rook Independence Problem
Rook Independence Problem — RIP(m,n)
Place m rooks on an n × n chessboard so that they do notthreaten each other
Reminder: Rook moves
8 0Z0Z0Z0Z7 Z0Z0Z0Z06 0Z0Z0Z0Z5 Z0Z0Z0Z04 0Z0ZrZ0Z3 Z0Z0Z0Z02 0Z0Z0Z0Z1 Z0Z0Z0Z0
1 2 3 4 5 6 7 8
Example. RIP(2,2)
2 rZ1 Zr
1 2
22 / 40
Rook Independence Problem
Rook Independence Problem — RIP(m,n)
Place m rooks on an n × n chessboard so that they do notthreaten each other
Reminder: Rook moves
8 0Z0Z0Z0Z7 Z0Z0Z0Z06 0Z0Z0Z0Z5 Z0Z0Z0Z04 0Z0ZrZ0Z3 Z0Z0Z0Z02 0Z0Z0Z0Z1 Z0Z0Z0Z0
1 2 3 4 5 6 7 8
Example. RIP(2,2)
2 rZ1 Zr
1 2
22 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:
1 Each rook is placed on some field2 Each rook is placed on at most one field3 Each field holds at most one rook4 No rook threatens another rook
23 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:
1 Each rook is placed on some field2 Each rook is placed on at most one field3 Each field holds at most one rook4 No rook threatens another rook
23 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:1 Each rook is placed on some field
2 Each rook is placed on at most one field3 Each field holds at most one rook4 No rook threatens another rook
23 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:1 Each rook is placed on some field2 Each rook is placed on at most one field
3 Each field holds at most one rook4 No rook threatens another rook
23 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:1 Each rook is placed on some field2 Each rook is placed on at most one field3 Each field holds at most one rook
4 No rook threatens another rook
23 / 40
RIP — Modellation
Modellation
m × n × n propositional variables:xi,j,k , where i ≤ n, j ≤ n, k ≤ mxi,j,k means that rook k is put onto field (i , j)
The formula should express:1 Each rook is placed on some field2 Each rook is placed on at most one field3 Each field holds at most one rook4 No rook threatens another rook
23 / 40
Example: RIP(3,2) (1)
1 Each rook is placed on some field
x1,1,1 ∨ x1,2,1 ∨ x2,1,1 ∨ x2,2,1x1,1,2 ∨ x1,2,2 ∨ x2,1,2 ∨ x2,2,2x1,1,3 ∨ x1,2,3 ∨ x2,1,3 ∨ x2,2,3
2 Each rook is placed on at most one fieldx1,1,1 → ¬x1,2,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x1,2,1 → ¬x1,1,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x2,1,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,2,1x2,2,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,1,1
...x1,1,3 → ¬x1,2,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x1,2,3 → ¬x1,1,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x2,1,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,2,3x2,2,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,1,3
24 / 40
Example: RIP(3,2) (1)
1 Each rook is placed on some fieldx1,1,1 ∨ x1,2,1 ∨ x2,1,1 ∨ x2,2,1x1,1,2 ∨ x1,2,2 ∨ x2,1,2 ∨ x2,2,2x1,1,3 ∨ x1,2,3 ∨ x2,1,3 ∨ x2,2,3
2 Each rook is placed on at most one fieldx1,1,1 → ¬x1,2,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x1,2,1 → ¬x1,1,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x2,1,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,2,1x2,2,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,1,1
...x1,1,3 → ¬x1,2,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x1,2,3 → ¬x1,1,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x2,1,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,2,3x2,2,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,1,3
24 / 40
Example: RIP(3,2) (1)
1 Each rook is placed on some fieldx1,1,1 ∨ x1,2,1 ∨ x2,1,1 ∨ x2,2,1x1,1,2 ∨ x1,2,2 ∨ x2,1,2 ∨ x2,2,2x1,1,3 ∨ x1,2,3 ∨ x2,1,3 ∨ x2,2,3
2 Each rook is placed on at most one fieldx1,1,1 → ¬x1,2,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x1,2,1 → ¬x1,1,1 ∧ ¬x2,1,1 ∧ ¬x2,2,1x2,1,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,2,1x2,2,1 → ¬x1,1,1 ∧ ¬x1,2,1 ∧ ¬x2,1,1
...x1,1,3 → ¬x1,2,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x1,2,3 → ¬x1,1,3 ∧ ¬x2,1,3 ∧ ¬x2,2,3x2,1,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,2,3x2,2,3 → ¬x1,1,3 ∧ ¬x1,2,3 ∧ ¬x2,1,3
24 / 40
Example: RIP(3,2) (1)
1 Each rook is placed on some fieldx1,1,1 ∨ x1,2,1 ∨ x2,1,1 ∨ x2,2,1x1,1,2 ∨ x1,2,2 ∨ x2,1,2 ∨ x2,2,2x1,1,3 ∨ x1,2,3 ∨ x2,1,3 ∨ x2,2,3
2 Each rook is placed on at most one fie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,3x2,1,2 → ¬x2,1,1 ∧ ¬x2,1,3x2,1,3 → ¬x2,1,1 ∧ ¬x2,1,2
x2,2,1 → ¬x2,2,2 ∧ ¬x2,2,3x2,2,2 → ¬x2,2,1 ∧ ¬x2,2,3x2,2,3 → ¬x2,2,1 ∧ ¬x2,2,2
25 / 40
Example: RIP(3,2) (2)
3 Each field holds at most one rookx1,1,1 → ¬x1,1,2 ∧ ¬x1,1,3x1,1,2 → ¬x1,1,1 ∧ ¬x1,1,3x1,1,3 → ¬x1,1,1 ∧ ¬x1,1,2
x1,2,1 → ¬x1,2,2 ∧ ¬x1,2,3x1,2,2 → ¬x1,2,2 ∧ ¬x1,2,3x1,2,3 → ¬x1,2,1 ∧ ¬x1,2,2
x2,1,1 → ¬x2,1,2 ∧ ¬x2,1,3x2,1,2 → ¬x2,1,1 ∧ ¬x2,1,3x2,1,3 → ¬x2,1,1 ∧ ¬x2,1,2
x2,2,1 → ¬x2,2,2 ∧ ¬x2,2,3x2,2,2 → ¬x2,2,1 ∧ ¬x2,2,3x2,2,3 → ¬x2,2,1 ∧ ¬x2,2,2
25 / 40
Example: RIP(3,2) (2)
3 Each field holds at most one rookx1,1,1 → ¬x1,1,2 ∧ ¬x1,1,3x1,1,2 → ¬x1,1,1 ∧ ¬x1,1,3x1,1,3 → ¬x1,1,1 ∧ ¬x1,1,2
x1,2,1 → ¬x1,2,2 ∧ ¬x1,2,3x1,2,2 → ¬x1,2,2 ∧ ¬x1,2,3x1,2,3 → ¬x1,2,1 ∧ ¬x1,2,2
x2,1,1 → ¬x2,1,2 ∧ ¬x2,1,3x2,1,2 → ¬x2,1,1 ∧ ¬x2,1,3x2,1,3 → ¬x2,1,1 ∧ ¬x2,1,2
x2,2,1 → ¬x2,2,2 ∧ ¬x2,2,3x2,2,2 → ¬x2,2,1 ∧ ¬x2,2,3x2,2,3 → ¬x2,2,1 ∧ ¬x2,2,2
25 / 40
Example: RIP(3,2) (2)
3 Each field holds at most one rookx1,1,1 → ¬x1,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¬x1,2,3 ∧ ¬x2,1,1 ∧ ¬x2,1,3x1,1,3 → ¬x1,2,1 ∧ ¬x1,2,2 ∧ ¬x2,1,1 ∧ ¬x2,1,2
x2,1,1 → ¬x2,2,2 ∧ ¬x2,2,3 ∧ ¬x1,1,2 ∧ ¬x1,1,3...
x1,2,1 → ¬x1,1,2 ∧ ¬x1,1,3 ∧ ¬x2,2,2 ∧ ¬x2,2,3...
x2,2,1 → ¬x2,1,2 ∧ ¬x2,1,3 ∧ ¬x1,2,2 ∧ ¬x1,2,3...
26 / 40
RIP(m,n) — Formula
1
m∧k=1
n∨i=1
n∨j=1
xi,j,k
2
n∧i=1
n∧j=1
m∧k=1
(xi,j,k →
nn∧
l=1h=1
(l,h)6=(i,j)
¬xl,h,k )
3
n∧i=1
n∧j=1
m∧k=1
(xi,j,k →m∧
l=1l 6=k
¬xi,j,l)
4
n∧i=1
n∧j=1
m∧k=1
(xi,j,k →
mn∧
l=1h=1
(l,h)6=(i,k)
¬xl,j,h ∧
mn∧
l=1h=1
(l,h)6=(j,k)
¬xi,l,h)
27 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...
3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF
2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...
3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...
3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — CNF Formula
Your turn!
1 Figure out CNF2 Use variable enumeration as in the following slide
Or trick with some hashmap, associative array, dictionary, ...3 Copy php.pl to rip.pl and modify accordingly
Or start with php.py if you like pythonic solutions!
4 Try it with MiniSat for some m,n
28 / 40
RIP — Variable enumeration
x1,1,1 7→ 1...
xn,1,1 7→ nx1,2,1 7→ n + 1
...xn,2,1 7→ 2× n
...x1,n,1 7→ (n − 1)× n + 1
...xn,n,1 7→ n × n
x1,1,2 7→ n × n + 1...
x1,n,2 7→ n × n + (n − 1)× n + 1...
xn,n,2 7→ 2× n × n...
xn,n,m 7→ m × n × n
xi,j,k 7→ (k − 1)× n × n + (j − 1)× n + i
29 / 40
Queen Independence Problem
Queen Independence Problem — QIP(m,n)
Place m queens on an n × n chessboard so that they do notthreaten each other
Reminder: Queen moves
8 0Z0Z0Z0Z7 Z0Z0Z0Z06 0Z0Z0Z0Z5 Z0Z0Z0Z04 0Z0ZqZ0Z3 Z0Z0Z0Z02 0Z0Z0Z0Z1 Z0Z0Z0Z0
1 2 3 4 5 6 7 8
30 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3 1,2
1,1
2,1 3,1 4,12,4 2,3
2,2
3,2 4,23,4
3,3
4,3
4,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3
1,2 1,1
2,1 3,1 4,12,4
2,3 2,2
3,2 4,2
3,4 3,3
4,3
4,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4
1,3 1,2 1,1
2,1 3,1 4,1
2,4 2,3 2,2
3,2 4,2
3,4 3,3
4,3
4,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3 1,2 1,1
2,1 3,1 4,1
2,4 2,3 2,2
3,2 4,2
3,4 3,3
4,3
4,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3 1,2 1,1 2,1
3,1 4,1
2,4 2,3 2,2 3,2
4,2
3,4 3,3 4,34,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3 1,2 1,1 2,1 3,1
4,1
2,4 2,3 2,2 3,2 4,23,4 3,3 4,3
4,4
31 / 40
Queen Independence Problem: Diagonals (1)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,4 1,3 1,2 1,1 2,1 3,1 4,12,4 2,3 2,2 3,2 4,2
3,4 3,3 4,34,4
31 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2 1,3
1,4
2,4 3,4 4,42,1 2,2
2,3
3,3 4,33,1
3,2
4,2
4,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2
1,3 1,4
2,4 3,4 4,42,1
2,2 2,3
3,3 4,3
3,1 3,2
4,2
4,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1
1,2 1,3 1,4
2,4 3,4 4,4
2,1 2,2 2,3
3,3 4,3
3,1 3,2
4,2
4,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2 1,3 1,4
2,4 3,4 4,4
2,1 2,2 2,3
3,3 4,3
3,1 3,2
4,2
4,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2 1,3 1,4 2,4
3,4 4,4
2,1 2,2 2,3 3,3
4,3
3,1 3,2 4,24,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2 1,3 1,4 2,4 3,4
4,4
2,1 2,2 2,3 3,3 4,33,1 3,2 4,2
4,1
32 / 40
Queen Independence Problem: Diagonals (2)
4 0Z0Z3 Z0Z02 0Z0Z1 Z0Z0
1 2 3 4
1,1 1,2 1,3 1,4 2,4 3,4 4,42,1 2,2 2,3 3,3 4,3
3,1 3,2 4,24,1
32 / 40
Homework (1)
1 Write a CNF formula generator for the BishopIndependence Problem
2 Write a CNF formula generator for the King IndependenceProblem
33 / 40
Homework (2)
Latin Square
http://mathworld.wolfram.com/LatinSquare.html
1 Model the Latin Square problemStart with a few examplesThen, work out a general formulaFinally, transform the formula in CNF
2 Write a CNF generator for Latin Square3 Test your CNF with a SAT solver!
34 / 40
Homework (2)
Latin Square
http://mathworld.wolfram.com/LatinSquare.html
1 Model the Latin Square problemStart with a few examplesThen, work out a general formulaFinally, transform the formula in CNF
2 Write a CNF generator for Latin Square
3 Test your CNF with a SAT solver!
34 / 40
Homework (2)
Latin Square
http://mathworld.wolfram.com/LatinSquare.html
1 Model the Latin Square problemStart with a few examplesThen, work out a general formulaFinally, transform the formula in CNF
2 Write a CNF generator for Latin Square3 Test your CNF with a SAT solver!
34 / 40
Homework (3)
1 Represent a 4× 4 Sudoku with 2× 2 squares using apropositional logic formula. This means that there is a4× 4 grid of fields, each of which should be filled withexactly one number between 1 and 4. The grid is dividedinto 4 non-overlapping regions of dimension 2× 2.
2 Generalize the formula for grids of n2 × n2 fields, into eachof which a number between 1 and n2 should be written.The grid is divided into n2 non-overlapping square regionsof dimension n × n. Here n is an arbitrary positive integer(so the previous example was a special case for n = 2).
35 / 40
Outline
1 DIMACS format
2 Setup and simple tests
3 Pigeon Hole Problem
4 Chess Piece Independence
5 Hardware correctness
36 / 40
Full Adder
Standard circuit
Alternative circuit
Full Adder Equivalence Problem
Do these two circuits implement the same functionality?
37 / 40
Full Adder
Standard circuit Alternative circuit
Full Adder Equivalence Problem
Do these two circuits implement the same functionality?
37 / 40
Full Adder
Standard circuit Alternative circuit
Full Adder Equivalence Problem
Do these two circuits implement the same functionality?
37 / 40
Homework (1)Represent the following Boolean circuit using a set of wffs:
Each component of the circuit has inputs at its left-hand side andoutput at its right-hand side. The output of a component is 1 if andonly if the sum of its inputs satisfies the condition written inside thecomponent; so if the sum of the inputs does not satisfy the condition,the output is 0. The inputs and outputs of the circuit (A, B, C, D, E, F)may have values 1 or 0. Bifurcations are indicated using a dot;crossing wires without a dot.The modelled formula must have models that correspond exactly tothe admissible input and output values of the circuit. 38 / 40
Homework (2)
1 In the previous exercise, how can you find out whether thevalue of F can ever be 1 in an admissible state of thecircuit?
2 Whether the value of E can ever be equal to the value of A?3 Whether the value of F is 1 if and only if the value of D is 0?
39 / 40
END OF THELECTURE
40 / 40