question sheet

ICS-E5050 Advanced Course in Boolean Satisfiability
Round 1, January 12
Spring 2016
Problems
Demonstration Exercises
D1: Syntax trees for propositional formulas
Let us assume that propositional formulas are based on Boolean variables x 1 , . . . ,x n ,
Boolean constants ⊥ and >, and Boolean connectives ¬, ∧, ∨, →, ↔, and ⊕.
(a) Write a formal definition for the syntax tree ST (α) of a formula α.
(b) Write an algorithm that computes the truth value of a formula. You may assume
that a syntax tree is given as an input for your algorithm and there is function
value(·) that returns the truth value assigned to a Boolean variable.
(c) Define a canonical order for syntax trees so that each syntax tree can be uniquely
ordered (internally) and a well-defined order for all syntax trees is obtained.
Solution:
a) The syntax trees of formulas can be defined recursively as follows:
1. The first three syntax trees in the figure below are the syntax trees ST (⊥),
ST (>), and ST (x i ) for a Boolean variable x i , respectively.
2. The fourth syntax tree is ST (¬α) and it contains ST (α) is its only subtree.
3. The fifth syntax tree is ST (α ∗ β) where ∗ is one of the binary connectives (∧,
∨, →, ↔, or ⊕), α and β are formulas, and it contains ST (α) and ST (β) as
its subtrees.
¬
⊥
>
xi
ST (α)
∗
ST (α)
ST (β)
b) The algorithm eval(n) operates as follows:
— If n is a leaf, then value(n) is returned.
— Otherwise, let ∗ be the k-ary1 operator assigned to n and c1 , . . . ,ck the children
of n. Let v1 , . . . ,vk be the values obtained from recursive calls eval(c1 ), . . . ,
eval(ck ). Return the result of applying ∗ to v1 , . . . ,vk .
1
For the moment k = 1 for ¬ and k = 2 for other connectives, but ∨ and ∧ can be generalized for k > 2.
1
c) We should first agree about an order of the symbols of the language (excluding
parentheses because they are no longer present in the syntax trees). Let us use:
⊥, >, x 1 , . . . ,x n , ¬, ∧, ∨, →, ↔, ⊕.
Let us denote the order above by < (e.g., > < ¬ holds according to this order).
In what follows, we generalize < for syntax trees and the respective formulas.
Let r oot(T ) denote the root symbol of a syntax tree T . Now arbitrary syntax trees
T1 and T2 can be ordered as follows:
1. If r oot(T1 ) < r oot(T2 ), then T1 < T2 .
2. If r oot(T1 ) = r oot(T2 ), the first subtrees S1 and S2 of T1 and T2 differ, and
S1 < S2 , then T1 < T2 .
3. If r oot(T1 ) = r oot(T2 ), the first subtrees of T1 and T2 coincide, the second
subtrees S1 and S2 of T1 and T2 differ, and S1 < S2 , then T1 < T2 .
4. Otherwise, T1 = T2 .
Note that the orientation of syntax trees matter in these considerations. The order
defined above can also be imposed on the internal structure of a formula and its
syntax tree. For instance, we write α ∧ β, if ST (α) < ST (β), and β ∧ α otherwise.
This principle can be applied to all symmetric connectives (∨, ∧, ↔, ⊕) whereas
implications α → β must remain intact because α → β and β → α typically have
a different meaning.
For example, the outcome of ordering the formula (x 3 ∨ x 1 ) ∧ ¬x 2 internally is the
formula ¬x 2 ∧(x 1 ∨ x 3 ) because ¬x 2 precedes x 3 ∨ x 1 in the order and x 1 precedes
x 3 in the order.
D2: Definability of propositional connectives in terms of others
Let us assume the same Boolean connectives as above.
(a) Define the other connectives using → and the false formula ⊥.
(b) Define all connectives using Sheffer’s stroke | which can be defined by the equivalence α | β ⇔ ¬(α ∧ β).
(c) Show that positive formulas that are formed using connectives ∧ and ∨ only cannot
express negation.
Solution:
a) The definitions of the connectives can be worked out as follows:
2
¬α ⇔ α → ⊥
α ∨ β ⇔ ¬¬α ∨ β ⇔ ¬α → β ⇔ (α → ⊥) → β
α ∧ β ⇔ ¬(¬α ∨ ¬β) ⇔ ¬(α → ¬β) ⇔ ¬(α → (β → ⊥)) ⇔
⇔ (α → (β → ⊥)) → ⊥
α ↔ β ⇔ (α → β) ∧ (β → α)
⇔ ((α → β) → ((β → α) → ⊥)) → ⊥
α ⊕ β ⇔ α ↔ ¬β ⇔ ((α → (β → ⊥)) → (((β → ⊥) → α) → ⊥)) → ⊥
b) Sheffer’s stroke is defined by α | β ⇔ ¬(α ∧ β).
¬α ⇔ α | α
α ∧ β ⇔ ¬¬(α ∧ β) ⇔ ¬(α | β) ⇔ (α | β) | (α | β)
α ∨ β ⇔ ¬¬(α ∨ β) ⇔ ¬(¬α ∧ ¬β) ⇔ ¬α | ¬β ⇔ (α | α) | (β | β)
α → β ⇔ ¬α ∨ β ⇔ ¬(α ∧ ¬β) ⇔ α | ¬β ⇔ α | (β | β)
α ↔ β ⇔ (α → β) ∧ (β → α) ⇔ (α | (β | β)) ∧ (β | (α | α))
⇔ ((α | (β | β)) | (β | (α | α))) | ((α | (β | β)) | (β | (α | α)))
α ⊕ β ⇔ α ↔ ¬β
⇔ ((α | ((β | β) | (β | β))) | ((β | β) | (α | α))) |
((α | ((β | β) | (β | β))) | ((β | β) | (α | α)))
⇔ ((α | β) | ((β | β) | (α | α))) | ((α | β) | ((β | β) | (α | α)))
In the last derivation, we used β ⇔ β ∧ β ⇔ (β | β) | (β | β) to simplify the
formula obtained by the respective substitutions.
c) Consider a propositional language based on a single variable x. Let φ be any
positive formula, consisting only connectives ∨ and ∧ and this particular variable
x. Since x ∧ x ⇔ x and x ∨ x ⇔ x by the absorption laws, it is easy to show
by induction over the structure of φ that every subformula of φ is equivalent to
x. Thus φ ⇔ x. Since φ was picked arbitrarily, it is clear that we cannot express
¬x with such positive formulas.
D3: Basic concepts
Inside a flashlight there is a lamp connected to a battery with appropriate wiring and a
switch. Suppose that the following Boolean variables are used to describe the feasible
states of the device:
b The battery is properly charged.
l The lamp is emitting light.
s The switch is on, i.e., connects the lamp to the battery through wires.
There are two independently written specifications for the device:
Σ1 = {¬b → ¬l, b → (l ↔ s)} and Σ2 = {l → b, b → s ∨ ¬l, b ∧ s → l}.
(a) Find out the models of Σ1 and Σ2 using a truth table.
(b) Show that Σ1 |= α for each α ∈ Σ2 and that Σ2 |= β for each β ∈ Σ1 .
3
(c) Show in general that if the preceding conditions hold for two sets of formulas Σ1
and Σ2 , then Σ1 and Σ2 are logically equivalent (have the same models).
Solution:
a) The models of the first specification can be found, e.g., using a truth table:
b
F
F
F
F
T
T
T
T
l
F
F
T
T
F
F
T
T
s ¬b ¬l ¬b → ¬l l ↔ s b → (l ↔ s)
F T T
T
T
T
T T T
T
F
T
F T F
F
F
T
T T F
F
T
T
F F T
T
T
T
T F T
T
F
F
F F F
T
F
F
T F F
T
T
T
The table for the second specification looks like this:
b
F
F
F
F
T
T
T
T
l
F
F
T
T
F
F
T
T
s l → b ¬l s ∨ ¬l
F
T
T
T
T
T
T
T
F
F
F
F
T
F
F
T
F
T
T
T
T
T
T
T
F
T
F
F
T
T
F
T
b → s ∨ ¬l
T
T
T
T
T
T
F
T
b∧s b∧s → l
F
T
F
T
F
T
F
T
F
T
T
F
F
T
T
T
The lines marked with green satisfy all formulas in the specification in question.
Thus, it is easy to see that the two specifications have exactly the same models.
b) The truth tables reveal that each formula of Σ2 is true in every model of Σ1 , and
vice versa. This is a further indication that the two specifications are logically
equivalent, as to be made precise in the following.
c) ( =⇒ ) Suppose that Σ1 |= Σ2 and Σ2 |= Σ1 , which we introduce as shorthands
for the conditions of item (b). Let us then assume that Σ1 and Σ2 do not have the
same models. Without loss of generality, Σ1 has a model ν which is not a model
of Σ2 . Thus ν(β) = F for some β ∈ Σ2 . It follows that Σ1 6|= β and Σ1 6|= Σ2 ,
a contradiction. ( ⇐= ) Suppose that Σ1 and Σ2 have the same model. Further
assuming that Σ1 6|= Σ2 , there is a formula β ∈ Σ2 such that Σ1 6|= β. Then Σ1 has
a model ν such that ν(β) = F. But then ν is not a model of Σ2 and, consequently,
Σ1 and Σ2 do not have the same models, a contradiction. Thus Σ1 |= Σ2 must
hold and Σ2 |= Σ1 follows by symmetry.
4
D4: Derivation of conjunctive and disjunctive normal forms
Transform the following formulas into CNF and DNF using transformation rules.
(a) a → (b → c).
(b) ¬a ↔ ((a ∨ ¬b) → b).
(c) ¬((a ↔ ¬b) → c).
(d) a ∧ b ↔ (a → b) ∨ (b → c).
Solution:
a) We start by removing implications from the formula.
a → (b → c) ¬a ∨ (¬b ∨ c)
¬a ∨ ¬b ∨ c.
This formula is both in CNF (only one conjunct) and DNF (three disjuncts).
b) First, we remove the equivalence and the implication from the formula. Then,
negations are pushed into the structure of the formula so that they only appear in
front of Boolean variables (double negations are removed as they appear). After
that we push disjunctions inside conjunctions using the distributivity laws.
¬a ↔ ((a ∨ ¬b) → b)
(¬a → ((a ∨ ¬b) → b)) ∧ (((a ∨ ¬b) → b) → ¬a)
[↔ elim.]
(a ∨ (¬(a ∨ ¬b) ∨ b)) ∧ (¬(¬(a ∨ ¬b) ∨ b) ∨ ¬a)
[→ elim.]
(a ∨ ((¬a ∧ b) ∨ b)) ∧ (((a ∨ ¬b) ∧ ¬b) ∨ ¬a)
[¬ in]
(a ∨ ((¬a ∨ b) ∧ (b ∨ b))) ∧ ((a ∨ ¬b ∨ ¬a) ∧ (¬b ∨ ¬a))
[∨ dist.]
(a ∨ ¬a ∨ b) ∧ (a ∨ b) ∧ (a ∨ ¬a ∨ b) ∧ (¬a ∨ ¬b)
[∨ dist.]
(a ∨ b) ∧ (¬a ∨ ¬b).
The final formula is in CNF. In the last step, the vacuously true disjunctions (containing both a variable and its negation) have been removed. Next, we distribute
conjunctions over disjunctions in order to arrive at a formula in DNF:
(a ∨ b) ∧ (¬a ∨ ¬b)
(a ∧ (¬a ∨ ¬b)) ∨ (b ∧ (¬a ∨ ¬b))
[∨ dist.]
(a ∧ ¬a) ∨ (a ∧ ¬b) ∨ (¬a ∧ b) ∨ (b ∧ ¬b)
[∨ dist.]
(a ∧ ¬b) ∨ (¬a ∧ b).
Again, in the last step, we have removed conjunctions which contain an atom and
its negation and are unconditionally false. The CNF/DNF made it evident that the
original formula is logically equivalent to a ⊕ b.
5
c) We proceed as above:
¬((a ↔¬b) → c)
¬((a → ¬b) ∧ (¬b → a) → c)
[↔ elim.]
¬(¬((¬a ∨ ¬b) ∧ (¬¬b ∨ a)) ∨ c) [→ elim.]
(¬a ∨ ¬b) ∧ (a ∨ b) ∧ ¬c.
[¬ in]
The formula above is in CNF and we may proceed towards a DNF:
(¬a ∨ ¬b) ∧ (a ∨ b) ∧ ¬c
(¬a ∨ ¬b) ∧ ((b ∧ ¬c) ∨ (a ∧ ¬c))
[∧ dist.]
(¬a ∧ ((b ∧ ¬c) ∨ (a ∧ ¬c))) ∨
(¬b ∧ ((b ∧ ¬c) ∨ (a ∧ ¬c)))
[∧ dist.]
(¬a ∧ b ∧ ¬c) ∨ (¬a ∧ a ∧ ¬c) ∨
(¬b ∧ b ∧ ¬c) ∨ (¬b ∧ a ∧ ¬c)
[∧ dist.]
(¬a ∧ b ∧ ¬c) ∨ (a ∧ ¬b ∧ ¬c).
The formula is in DNF.
d) We proceed as before:
a ∧ b ↔ (a → b) ∨ (b → c)
a ∧ b ↔ (¬a ∨ b ∨ ¬b ∨ c)
[→ elim.]
(a ∧ b ↔ >)
[simp.]
(a ∧ b → >) ∧ (> → a ∧ b)
[↔ elim.]
(¬(a ∧ b) ∨ >) ∧ (¬> ∨ (a ∧ b))
[→ elim.]
(¬a ∨ ¬b ∨ >) ∧ (⊥ ∨ a) ∧ (⊥ ∨ b)
[¬ in]
a ∧ b.
The key observation is that a major part of the formula can be eliminated as it
happens to be vacuously true. Recall that α ∨ > ⇔ > and α ∨ ⊥ ⇔ α in general.
Obviously, the formulas (a ∧ b ↔ >) and a ∧ b are logically equivalent. The final
formula is in CNF (two conjuncts) and DNF (only one disjunct).
D5: Equivalence-preserving transformations for formulas
Prove formally that the transformations used to derive CNFs and DNFs for formulas
preserve the logical equivalence of the formulas.
Solution:
We should verify for each step of rewriting that logical equivalence is preserved. For
instance, implications α → β are removed by expressing them as ¬α ∨ β. As clear by
the truth table below, these formulas are logically equivalent.
6
α
F
F
T
T
β
F
T
F
T
α→β
T
T
F
T
¬α
T
T
F
F
¬α ∨ β
T
T
F
T
As another example, let us consider the distribution of ∨ over ∧, i.e., replacing α∨(β ∧γ)
with (α ∨ β) ∧ (α ∨ γ). We could show the equivalence using a truth table as above.
However, it is easy to get convinced of the equivalence by a simple case analysis:
1. If α is false, the first formula reduces to β ∧γ and the second to (⊥∨β)∧(⊥∨γ) ⇔
β ∧ γ.
2. If α is true, the first formula reduces to > and the second to (> ∨ β) ∧ (> ∨ γ) ⇔
> ∧ > ⇔ >.
Once all equivalences of this kind have been established, we have to appeal to the
substitution property of propositional logic, i.e., if α[β] is a formula containing a subformula β and α[β 0 ] is the result of substituting β 0 for β in α, then β ⇔ β 0 implies
α[β] ⇔ α[β 0 ]. In words, if a subformula is replaced by an equivalent formula, the
meaning of the formula is unchanged.
D6: Modeling SuDoku puzzles with propositional logic
Below you will find an example of a solution to a SuDoku problem (the original 16
hints designed by Gordon Royle are given in boldface).
1
4
7
6
5
9
2
8
3
9
6
5
2
3
8
1
7
4
3
8
2
1
4
7
6
5
9
8
5
1
4
9
2
3
6
7
6
3
4
7
1
5
9
2
8
7
2
9
3
8
6
5
4
1
4
9
6
5
7
3
8
1
2
2
1
8
9
6
4
7
3
5
5
7
3
8
2
1
4
9
6
Model the SuDoku problem using propositional logic. How many Boolean variables
are needed? Provide the propositional formulas to express the essential constraints:
(i) Exactly one number is placed in each position in the grid.
(ii) Within each of the nine regions, each number 1..9 occurs at most once.
7
(iii) On every row, each number 1..9 occurs at most once.
(iv) In every column, each number 1..9 occurs at most once.
If your formulas are not in CNF, derive the respective CNFs. Write a simple generator
for the CNF and use some SAT solver to solve the SuDoku problem given above.
Solution:
One possibility to encode the sudoku problem is to introduce 93 = 729 Boolean variables v(i, j,n) meaning that number n is placed at coordinates (i, j) in the grid. The
constraints are then expressed by the following formulas:
(i) For each position (i, j), introduce a disjunction v(i, j,1) ∨ . . . ∨v(i, j,9) and the formulas
¬(v(i, j,n) ∧ v(i, j,m) ) for 1 ≤ n < m ≤ 9.
(ii) For any two positions (i1, j1) and (i2, j2) in the same region (such that i1 < i2, or
i1 = i2 and j1 < j2, additionally hold), introduce the formula ¬(v(i1, j1,n) ∧v(i2, j2,n) )
for every number n.
(iii) For each row j and a number n, introduce the formula ¬(v(i1, j,n) ∧ v(i2, j,n) ) for every
1 ≤ i1 < i2 ≤ 9.
(iv) For each column i and a number n, introduce the formula ¬(v(i, j1,n) ∧ v(i, j2,n) ) for
every 1 ≤ j1 < j2 ≤ 9.
A clue n at (i, j) can simply be added as a fact v(i, j,n) .
An implementation of this encoding in a logic programming style syntax can be found
under http://research.ics.aalto.fi/software/sat/satgrnd/
8