Exercise 1 (Conversion to CNF): (2 points) Exercise 2 (Tseitin`s

advertisement
Logic Programming WS 2010/2011
Exercise Sheet 3 (due November 10th, 2010)
Carsten Fuhs, Carsten Otto, Thomas Ströder
Prof.aa
Dr. Jürgen Giesl
Hints:
• Please solve these exercises in groups of two!
• The solutions must be handed in directly before (very latest: at the beginning of) the exercise course
on Wednesday, November 10th, 2010, in lecture hall AH 3. Alternatively you can drop your solutions into
a box which located right next to Prof. Giesl’s office (until the exercise course starts).
• Please write the names and immatriculation numbers of all (two) students on your solution. Also please
staple the individual sheets!
• As the topics related to the exercises on this sheet are relevant for all versions of the lecture, all exercises
on this sheet are relevant for all students.
Exercise 1 (Conversion to CNF):
(2 points)
Consider the following formula ϕ with p1 , . . . , p6 ∈ ∆0 :
ϕ = ((p1 ∨ ¬p2 ) ∧ (¬p3 ∨ p4 )) → (p5 ∧ ¬p6 )
Use the algorithm presented in the proof of Theorem 3.3.2 to convert ϕ to an equivalent formula in conjunctive
normal form (CNF).
Exercise 2 (Tseitin’s transformation):
(3 + 1 + 2 = 6 points)
If one uses the algorithm defined in the proof of Theorem 3.3.2 to convert a propositional formula ψ to an
equivalent CNF ψ 0 , in the worst case the size of ψ 0 can be exponential in the size of ψ. Therefore, in practice
instead one usually applies a different algorithm (attributed to Tseitin) in order to convert a formula to CNF. Here
the idea is to introduce additional propositional variables qθ for every non-atomic subformula θ of the formula ψ.
Then one adds constraints in CNF which ensure that qθ ↔ θ holds. In the end one adds the singleton conjunct
qψ to the CNF to enforce that any model of the CNF will also satisfy ψ.
Consider the following example with p1 , p2 , p3 ∈ ∆0 :
τ1
z}|{
τ = (p1 ∧ ¬p2 ) ∨p3
| {z }
τ2
The formula τ contains the three non-atomic subformulas τ1 , τ2 , and τ . Hence, we introduce the three new
predicate symbols qτ1 , qτ2 , and qτ which are added to ∆0 (i.e., qτ1 , qτ2 , and qτ are propositional variables which
can be assigned to true or to false). Now we still need to ensure that they are assigned the correct truth values:
(qτ1
↔
¬p2 ) ∧
(qτ2
↔ p1 ∧ qτ1 ) ∧
(qτ
↔ qτ2 ∨ p3 ) ∧
qτ
We eliminate the ↔-junctors and obtain the following CNF:
(qτ1 ∨ p2 ) ∧ (¬qτ1 ∨ ¬p2 ) ∧
(¬qτ2 ∨ p1 ) ∧ (¬qτ2 ∨ qτ1 ) ∧ (qτ2 ∨ ¬p1 ∨ ¬qτ1 ) ∧
(qτ ∨ ¬qτ2 ) ∧ (qτ ∨ ¬p3 ) ∧ (¬qτ ∨ qτ2 ∨ p3 ) ∧
qτ
1
Logic Programming WS 2010/2011
Exercise Sheet 3 (due November 10th, 2010)
To define Tseitin’s transformation ts formally, we need the set of all non-atomic subformulas na(ψ) for a propositional formula ψ. In our example, we have na(τ ) = {τ1 , τ2 , τ }. For each of these non-variable subformulas θ,
we use a corresponding new variable qθ .
In order to make sure that the new variables qθ take the correct values, we define formulas C¬ (γ, θ) to express
γ ↔ ¬θ, C∧ (γ, θ1 , θ2 ) to express γ ↔ θ1 ∧ θ2 , and C∨ (γ, θ1 , θ2 ) to express γ ↔ θ1 ∨ θ2 , respectively:
• C¬ (γ, θ) = (γ ∨ θ) ∧ (¬γ ∨ ¬θ)
• C∧ (γ, θ1 , θ2 ) = (¬γ ∨ θ1 ) ∧ (¬γ ∨ θ2 ) ∧ (γ ∨ ¬θ1 ∨ ¬θ2 )
• C∨ (γ, θ1 , θ2 ) = (γ ∨ ¬θ1 ) ∧ (γ ∨ ¬θ2 ) ∧ (¬γ ∨ θ1 ∨ θ2 )
Note that if the arguments of C¬ , C∧ , and C∨ are atomic formulas, then the resulting formulas are in CNF. Now
we can define Tseitin’s transformation ts as follows. Here, qθ should be replaced by θ whenever θ is an atomic
formula.
^
^
^
ts(ψ) = qψ ∧
C¬ (q¬θ , qθ ) ∧
C∧ (qθ1 ∧θ2 , qθ1 , qθ2 ) ∧
C∨ (qθ1 ∨θ2 , qθ1 , qθ2 )
¬θ∈na(ψ)
θ1 ∧θ2 ∈na(ψ)
θ1 ∨θ2 ∈na(ψ)
Without loss of generality, here we assume that ψ does not contain the junctors → and ↔ (they can be eliminated
by a preprocessing step as described in the proof of Theorem 3.3.2).
Remark: Note that Tseitin’s transformation to CNF does not preserve equivalence (because it introduces new
predicate symbols qθ which were not present in the original formula and which influence the truth value of the
resulting CNF). Nevertheless, an important property of Tseitin’s transformation from a propositional formula ψ
to a CNF ts(ψ) is that any model of ts(ψ) is also a model of ψ (and moreover, any model of ψ can be extended
to a model of ts(ψ)). Since most modern satisfiability checkers for propositional logic require their input to be in
CNF, this transformation is very useful for extending applicability of these SAT solvers to arbitrary propositional
formulas.
a) Please apply first the necessary preprocessing to eliminate the junctor → and then Tseitin’s transformation
to the formula ϕ from Exercise 1. In your solution you do not need to expand the subformulas C◦ (...) for
◦ ∈ {¬, ∧, ∨}.
b) How many clauses does your formula contain (after expanding C◦ (...))?
c) Please provide a tight bound for the size complexity (in O-notation) for ts(ψ) for a given propositional
formula ψ of size n. Here the size of a formula is the number of its junctors and its atoms. Please also give
a short explanation for your result.
Exercise 3 (Tseitin’s transformation in Prolog):
(6 points)
In this exercise we are going to implement Tseitin’s transformation in Prolog. To represent propositional formulas
in Prolog, we use the binary function symbols and and or and the unary function symbols not and atom. Here
and, or, and not correspond to the usual Boolean junctors. The function symbol atom marks an atomic formula
(i.e., a propositional variable which can become either true or false). For instance, the term atom(p) corresponds
to the propositional variable p. Propositional formulas are translated to Prolog terms by the function D:
D(p)
=
atom(p)
D((θ1 ∧ θ2 ))
=
and(D(θ1 ),D(θ2 ))
D((θ1 ∨ θ2 ))
=
or(D(θ1 ),D(θ2 ))
D(¬θ)
=
not(D(θ))
for all atomic formulas p
For instance, for the formula τ from Exercise 2 we have:
D(τ ) = or(and(atom(p1), not(atom(p2))), atom(p3))
2
Logic Programming WS 2010/2011
Exercise Sheet 3 (due November 10th, 2010)
To represent the fresh predicate symbols qθ that are introduced by Tseitin’s transformation, we define:
D(qθ ) = atom(q_D(θ))
So for example if p ∈ ∆0 , then D(q¬p ) = atom(q_not(atom(p))).
As usual, we represent of CNFs via sets of clauses. For instance, the CNF
q¬p ∧ (q¬p ∨ p) ∧ (¬q¬p ∨ ¬p)
corresponds to the clause set:
{{q¬p }, {(q¬p , p)}, {(¬q¬p , ¬p)}}
In our translation to Prolog, we represent clauses by lists and clause sets by lists of lists. So the above clause set
would be represented by:
[[atom(q_not(atom(p)))], [atom(q_not(atom(p))), atom(p)], [not(atom(q_not(atom(p)))), not(atom(p))]]
Please implement a predicate tseitin/2 which takes a given propositional formula in the first argument. It then
computes a list representation of the clause set returned by Tseitin’s transformation in the second argument.
For instance, the query ?- tseitin(not(atom(p)), Css). should have the result
Css = [[atom(q_not(atom(p)))], [atom(q_not(atom(p))), atom(p)], [not(atom(q_not(atom(p)))), not(atom(p))]].
(where list elements may occur in a different order).
On the web page of the course, you can find a file tseitin.pl, where it says FILLME in several places. Please
replace FILLME to complete the implementation for the predicate tseitinList/3, which is used by tseitin/2.
%%% P l e a s e r e p l a c e "FILLME" by y o u r i m p l e m e n t a t i o n !
/∗ We c o n s t r u c t p r o p o s i t i o n a l f o r m u l a s a s f o l l o w s :
∗ − atom (X) i s a p r o p o s i t i o n a l v a r i a b l e w i t h t h e name X .
∗ − not (F) i s the n e g a t i o n of the formula F .
∗ − and ( F , G) i s t h e c o n j u n c t i o n o f t h e f o r m u l a s F and G .
∗ − o r ( F , G) i s t h e d i s j u n c t i o n o f t h e f o r m u l a s F and G .
∗/
% t s e i t i n /2:
% t s e i t i n ( F , Cs ) h o l d s i f a n y m o d e l o f F c a n be e x t e n d e d t o a m o d e l
% o f Cs and c o n v e r s e l y a n y m o d e l o f Cs i s a l s o a m o d e l o f F .
% H e r e F must be i n s t a n t i a t e d by a g r o u n d t e r m i n a q u e r y ,
% w h e r e a s Cs h a s no r e s t r i c t i o n s .
t s e i t i n ( F , [ [ X ] | Cs ] ) :− t s e i t i n L i s t ( F , X , Cs ) .
%
%
%
%
%
%
%
%
%
t s e i t i n L i s t /3 h a s t h e f o l l o w i n g i n t e n d e d m e a n i n g :
t s e i t i n L i s t ( F , X , Cs ) h o l d s i f X i s t h e p r o p o s i t i o n a l v a r i a b l e t h a t
r e p r e s e n t s t h e f o r m u l a F , and Cs a r e c l a u s e s r e q u i r e d t o make s u r e
that X h o l d s i f f F does .
Example :
The q u e r y ?− t s e i t i n L i s t ( n o t ( atom ( p ) ) , X , Cs ) . h a s t h e r e s u l t
X = atom ( q_not ( atom ( p ) ) ) ,
Cs = [ [ atom ( q_not ( atom ( p ) ) ) , atom ( p ) ] , [ n o t ( atom ( q_not ( atom ( p ) ) ) ) , n o t ( atom ( p ) ) ] ] .
% p r o p . v a r i a b l e s f r o m t h e i n p u t f o r m u l a a r e r e p r e s e n t e d by t h e m s e l v e s
t s e i t i n L i s t ( atom (Y ) , atom (Y ) , [ ] ) .
% T s e i t i n v a r i a b l e " names " f o r c o m p l e x f o r m u l a s a r e l a b e l e d
% by t h e f o r m u l a s
t s e i t i n L i s t ( n o t ( F ) , atom ( q_not ( F ) ) , FILLME ) :− FILLME .
t s e i t i n L i s t ( o r ( F , G ) , atom ( q_or ( F , G ) ) ,
t s e i t i n L i s t ( and ( F , G ) , atom ( q_and ( F , G ) ) ,
FILLME ) :−
FILLME ) :−
3
FILLME .
FILLME .
Logic Programming WS 2010/2011
Exercise Sheet 3 (due November 10th, 2010)
Exercise 4 (Resolution for propositional logic):
(3 points)
Consider the following clause set K with p1 , . . . , p4 ∈ ∆0 :
K = {{p1 , p2 }, {¬p2 }, {¬p1 , p2 , ¬p4 }, {p3 , p4 }, {¬p3 , ¬p4 }, {¬p3 , ¬p1 }}
Please show that K is unsatisfiable by using resolution for propositional logic (cf. Definition 3.3.4 and Example
3.3.5).
Hint: It suffices to perform five resolution steps.
4
Download