For example, given the input [1, 4, 6, 14, 17, 20] the output could be {1, 4, 6, 20}, {14, 17}, since both partitions add up to 31. Given the input [3, 4, 6, 14, 17, 20] the output would be "FALSE" since no such partition exists. Consider the following solution to this problem using state space search: Let M = the sum of the elements in L.
[][] --- [1][] --- [1,2][] --- [1,2][3] fail | |- [1][2] --- [1,3][2] fail | |- [1][2,3] --- [1,4][2,3] succeed.
Answer: Branching factor: 2. Depth: 50. The size is certainly no more than 250 (one can construct problems where the state space has size 249, so that's a pretty tight estimate.)
(P <=> Q) => R.Answer: Going through the important intermediate steps.
[(P => Q) ^ (Q => P)] => R ~[(~P V Q) ^ (~Q V P)] V R [(P ^ ~Q) V (Q ^ ~P)] V R.Finally, one attains four clauses
1. P V ~P V R 2. P V ~Q V R 3 Q V ~P V R 4. Q V ~Q V R.But clauses (1) and (4) are tautologies (true for all valuations, since they have a literal and its negation) and therefore can be dropped.
1. ~P V Q V RStep 1: ~A is a pure literal. Set A=FALSE. Delete 7 and 8.
2. P V ~Q
3. P V ~R
4. ~P V ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
7. ~A V P.
8. ~A V R.
Set S1:
1. ~P V Q V RStep 2: No singleton clauses, no pure literals. Try P=TRUE. Delete clauses 2 and 3, delete ~P from 1 and 4.
2. P V ~Q
3. P V ~R
4. ~P V ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
Set S2:
1. Q V RStep 3: No singleton clauses, no pure literals. Try Q=TRUE. Delete clause 1, delete ~Q from 4 and 5.
4. ~Q V S
5. ~Q V R V ~S
6. ~R V ~S
Set S3:
4. SStep 4: 4 is a singleton clause. Set S=TRUE. Delete clause 4, delete ~S from 5 and 6.
5. R V ~S
6. ~R V ~S
5. RStep 5: 5 is a singleton clause. Set R=TRUE. Delete clause 5, delete ~R from clause 6.
6. ~R
Step 6: 6 is now the empty clause. Fail. Go back to step 3, set S2. Try Q=FALSE. Delete clauses 4, 5. Delete Q from 1.
Set S4.
1. RStep 7: 1 is a singleton clause set R=TRUE. Delete clause 1. Delete ~R from 6.
6. ~R V ~S
6. ~S.Step 8: 6 is a singleton clause. Set S=FALSE. Delete 6.
There are now no clauses left, so succeed. Return the current valuation: A=FALSE, P=TRUE, Q=FALSE, R=TRUE, S=FALSE.
Suppose that we want to build a compiler that turns a Hamiltonian path problem into a problem of satisfiability, which can then be input to Davis-Putnam. This can be done as follows: Let N be the number of vertices in the graph = the number of vertices in the desired path. For each vertex V and number I between 1 and N, construct a propositional atom V_I, meaning that vertex V is in place I in the target path.
Show how the following three types of constraints can be expressed:
Answer:
C_1 V C_2 V C_3 V C_4 V C_5 V C_6.
In general, for any vertex W, there is a sentence
W_1 V W_2 V ... V W_N.
Answer:
~(A_3 ^ C_3).
In general for each pair of vertices U,W and each I between 1 and N, assert
~(U_I ^ W_I).
Answer:
B_3 => A_4 V C_4 V E_4
In general, if U connects to vertices W1, W2 ... Wk,
then for each I=1 ... N-1 assert the sentence
U_I => W1_(I+1) V W2_(I+1) V ..Wk_(I+1)