1. Introduction
The Boolean satisfiability problem (SAT) is the first known NP-complete problem [
1]. It has applications in different fields, such as cryptanalysis [
2], hardware verification [
3], AI planning [
4] and medicine [
5].
There are two main ways to face the SAT problem from the algorithmic perspective. On one hand, those supported by the Davis–Putnam–Logemann–Loveland (DPLL) algorithm [
6] focus on, in essence, backtracking, and on the other hand, those based on local searching are led by some heuristics changing from one state to another one until reaching an ending condition that corresponds to a valid interpretation. Some examples of the second option are hill climbing/gradient descent and simulated annealing [
7], where the latter can be directly powered by annealing quantum computing.
SAT problems can be dealt with as a structured searching problem, as shown in [
8]. This work presents a quantum algorithm for nested searching over structured problems. First, a Grover’s search is carried out over the
i first qubits out of a total of
n. This uses an oracle that inverts the phase of a possible solution, conditioned by the set of clauses that contains the
i first variables that were satisfied. The number of iterations of this first step is
, where
is the number of possible solutions. The second step performs
iterations of a standard search in the remaining
qubits. The last step applies
iterations of
, where:
U is the circuit of the two previous steps.
is the inverse ordered U circuit (right to left).
and are the conditional phase inversion of initial states of the i first qubits and qubits, respectively.
is the oracle for the solutions of the problem.
is the number of solutions of the problem.
In order to develop such a structured quantum search, some extra information about the number of tentative solutions at different levels, together with where these levels should be located, is required. This is not available in our case.
A more restrictive version of this problem focused on exact satisfiabiality, XSAT, and occupation problems, with
n variables and
m clauses has been studied in [
9] and solved by Grover’s algorithm in
, where
is the number of independent clauses for the corresponding XORSAT problem that the original problem is reduced to. In fact, it provides a reduction in the searching space by means of a transformation of the original problem. The Oracle used in this article is formed of three main blocks. The first block is a mapping between the
k-configuration of the XORSAT problem and the
n-configuration of the original problem. The second block is devoted to computing the number of satisfied clauses. The third block is a conditional phase inversion over the satisfied clauses (the phase inversion is applied when the number of satisfied clauses equals the number of clauses).
In addition, Grover’s algorithm can be applied when solving a wide variety of problems, ranging from the most common decision problems to global optimization problems, as [
10] shows, where finding an input element
x satisfying
for whatever
is the goal. This method starts with a random element
y and then repeats two steps until no solution is found. The first step means executing Grover’s algorithm with
as Oracle. The second step updates the value of
y with
x.
Variations in this sort of algorithms range from combining them with heuristics, such as as Variable State Independent Decaying Sum (VSIDS) branching heuristics, or a passing trough focusing on parallelism, with ManySAT solvers [
11] using efficient Boolean constraint propagation (BCP) together with an optimised decision strategy [
12], to using hardware solvers focused on FPGAs [
13].
Other quantum computing approaches used to solve this problem can be seen in [
14]. This work encodes each clause as a circuit called filter box, which holds that states satisfying this clause have a higher amplitude than the rest. This is achieved by using ancillary qubits, CNOT gates, rotation gates around
y-axis, and two non-unitary transformations named boost Hamiltonian and projection Hamiltonian. If a qubit is used for other clauses, that qubit will be teleported to the other one by the circuit teleportation box; otherwise, it will finish with a boost Hamiltonian transformation.
In [
15], Leporati et al. propose three different algorithms to deal with the 3-SAT problem. These algorithms are mainly leveraged by quantum parallelism, computing the 3-SAT function for all states at once, and therefore obtaining a linear combination
such that either
, when the instance on the problem is unsatisfiable, or
measures a proportion of the number of solutions with respect to the domain of Boolean variables when it is satisfiable (which obviously includes the first option). These different proposals are focused on a quantum Fredkin circuit, a register in a quantum register machine, and the energy of a given membrane in a quantum P system. All these proposals assume the ability to discriminate a null vector from a non-zero one.
Other quantum computing approaches to solve 3-SAT problem can be found in [
16], where a sort of diabatic quantum annealing (not universal) is proposed, and [
17], using Rydberg Atom Graphs based on neutral atoms’ quantum computing. Both approaches are supported by quantum systems that evolve mechanically.
Meuli et al. proposed, in [
18], a way of synthesising CNOT gates in order to build the Oracle operator within SAT problem-solving.
Cheng et al. proposed, in [
19], a sort of cooperative quantum searching in which Boolean variables are split into two sets. In one of them, the values of the variables are set by a local search algorithm, such as, for example, GenSAT; in the other set, Grover’s searching algorithm is applied.
The SAT problem has also been faced from a hybrid Classical/Quantum perspective, as Zhang et al. addressed in [
20], where an algorithm that first unfolds the branches of the tree of states until reaching a given threshold, from which Grover’s algorithm is applied, is presented. Finally, the solutions must be properly linked in order to obtain the solutions of the former SAT problem. Our proposal shares some similarities with this one but, as far as we know, the amount of information we extract from the problem domain, together with the size of the experiment set we provide, makes us quite confident that our proposal is still value, and distinct from that of Zhang et al.
In this work, we focus on DPLL-based algorithms. Specifically, we focus on both the GRASP (Generic seaRch Algorithm for the Satisfiability Problem) [
21], based on conflict-driven clause learning and non-chronological backtracking, and miniSAT [
22], which is based on VSIDS dynamic variable order and on conflict-driven clause learning.
This paper is structured as follows:
Section 2 refreshes some preliminary notions,
Section 3 presents our proposal,
Section 4 and
Section 5 are devoted to, first, describing the experimental setup, and then gathering the results to empirically validate our algorithm.
Section 5 concludes the paper.
2. Preliminaries
2.1. SAT Problem
In this section, we are going to set the notation that is to be used in the rest of the paper. We will consider a numerable set of Boolean variables; two symbols—⊤ for the constant true atomic formula and ⊥ for the constant false atomic formula; the ordinary symbols ∧ and ∨ stand for conjunction and disjunction logical operators; the negation of a formula is denoted by .
Definition 1. (Popositional formula)
. The set of propositional formulas is generated by the following Backus–Naur Form BNF form:where .We will denote the set of propositional formulas by .
A truth assignment is a function . We can extend v to the set of propositional formulas in the usual way:
, ,
if , ,
We say that v satisfies φ (written ) when ; if we write .
The vocabulary of a formula ϕ, , is the set of Boolean variables it contains. Formally, A SAT problem is the problem of determining whether a truth assignment v can be given to the variables of a given formula , such that . If this is the case, the referred formula is said to be satisfiable. Otherwise, i.e., when there is no such assignment, the formula is said to be insatisfiable.
As SAT belongs to the class of NP-problems, there is no known algorithm capable of solving SAT in sub-exponential time. Nevertheless, we could find algorithms capable of solving quite large instances of the SAT problem by following some heuristics.
We will consider as a numerable set of Boolean variables.
We are going to consider a restricted version of the SAT problem: k-SAT, k-satisfiability, problem. This consists of determining whether the k-SAT formula is satisfiable. K-SAT is also an NP-problem. Therefore, we then defined a k-SAT formula.
Definition 2. (K-SAT formulas). First, define the set of atomic formulas
We will denote the elements of as . We assume . An OR clause, or just a clause for us, is a Boolean formula with this shape , where is an atomic formula. For simplicity, we assume that and for . If , we assume that .
A k-SAT formula is a Boolean expression shaped as , where each is a clause with, at most, k variables. If , we assume that .
Since the logical operators (∧ and ∨ are independent, commutative and associative), we can see a k-SAT formula as a set of clauses (connected by ∧ operators), and a clause a set of atoms (connected by ∨ operators).
An important metric for dealing with k-SAT problem is the density. This metric is related to the difficulty associated with determining whether a formula is satisfiable.
Definition 3. (Density). The density of a k-SAT formula is the ratio between the number of clauses (m) and the number of Boolean variables:
In the related literature, it is assumed that , and there exists a threshold value for the density of k-SAT formulas such that:
The farther
is from
, the fewer calls to the DPLL algorithm [
6] are required to solve the k-SAT problem.
If , the formula would be unsatisfiable with high probability, but the opposite occurs when , i.e., a high is usually associated with an unsatisfiable formula.
Some examples are:
For the 3-SAT problem, Mitchell, Selman and Levesque estimated in 1991 [
23] that
for about 20 variables and
for larger number of variables
2.2. Incremental SAT—Definition and Complexity
We perform an incremental solving approach also followed by [
24]. In practice, we are going to build a sequence of k-SAT formulas, which will finish either with the former k-SAT formula
when it is satisfiable or before in the other case.
Figure 1 provides a graphical view of this process.
where
, being
a new set of clauses. In each step, we assume that there is
v, such that
. The new set of clauses
is defined according to the Algorithm 1. If there is no such
, this identifies an unsatisfiability of
.
In [
24], the authors propose a
branch and bound algorithm that can be used to find the truth assignments in steps with numbers 5–7 within our algorithm. In our case, we will use a Quantum Algorihtm based on the Grover Algorithm to solve the problem. In our case, we propose a novel heuristic (see
Section 3.3) to choose the most convenient clauses in each step.
Algorithm 1 Algorithm to extend the set of clauses |
Find , if the following tests hold: - 1.
If , is unsatisfiable, it cannot be considered the new set. - 2.
can be simplified by removing the trivially true clauses, so there is no such that or . - 3.
is split into two sets: where is the maximal set of clauses of such that the variables in do not appear in :
is also split into two sets: where is the maximal set of whose variables are not contained in :
- 4.
If , go to step 7. - 5.
Look to for a truth assignment such that and for all . If such a truth assignment exists, go to step 7. - 6.
Look for a truth assignment such that . If such a truth assignment does not exist, cannot be added to . - 7.
Look for a truth assignment for .
|
2.3. Convert SAT to Oracle
To begin with, practice with an oracle is required to test satisfiability; for this reason, we follow the usual [
25] rewriting process. First, we eliminate the disjunctions according to De Morgan laws. In this way, a clause such as
is transformed into the equivalent formula
, whose negations can easily be implemented in a quantum circuit with the
operator. Since the conjunction is not a reversible connector, we need to implement it as an oracle
:
Therefore, implementing a k-SAT formula, which is a conjunction of m clauses, would require (one qubit per variable, one qubit per clause and one extra qubit for the final result).
3. Heuristics to Save Space and Computational Complexity
3.1. Grover’s Algorithm
Grover’s algorithm [
26] searches for an element in an unordered space within a time belonging to
, where
N is the size of the search space. More precisely, the input of the Grover Algorithm takes an oracle
, which implements a Boolean function
where the elements of the search space are encoded in
and, as usual, 1 represents success (goal achieved) and 0 means failure.
One of the drawbacks of this method is the need to know the number of solutions in advance in order to determine the number of rotations to perform. This problem can be dealt by executing Grover algorithm with , which can be costly; instead, Monte Carlo algorithms can be used.
3.2. Grover’s Bounded Algorithm
In this section, we first refer to the corresponding version of Grover’s Algorithm [
27], based on which we developed our main contribution. This version reduces the work domain to a subset of the original set of states to be searched.
Let us assume that we want to find the solutions of , where .
We start from the following quantum circuit
, which stands for the phase oracle of
:
In a nutshell, our algorithm selects with in order to search for the solutions in . More precisely, if S was the set of solutions of , our algorithm will find unique solutions to the set . We denote as the complementary of with respect to
As previously recalled, general Grover’s algorithm starts by setting the system into a full superposed state by applying a Hadamard quantum gate over the former
n qubits; nevertheless, we are only going to apply a superposition to states belonging to
. We call this superposition operator
.
The construction of the
operator
is discussed in
Section 3.2 for our specific case. In general, this operator can be performed as described in [
28] when no extra qubits are required, and as described in [
29] when some extra ancillary qubits are required.
Figure 2 graphically presents how the first operator performs.
Once the previously described configuration is set, the evolution of our algorithm is similar to the original one. As we will explain, it is based on rotations towards the solution vector (see
Figure 2). More specifically, we consider two ortonormal vectors: one corresponds to the states that contain a solution and the other corresponds to the states that do not.
Then belongs to the vector subspace generated by and .
This last equation shows that is symmetrical with respect to the vector .
The second step to be developed, as in Grover’s algorithm, is the inversion about the mean, i.e., a symmetry with respect to the initial vector. In our case, we perform a symmetry with respect to
vector. The operator that performs this symmetry is the following:
Let us note that is symmetrical with respect to vector.
Let us consider the angle , such that is the angle between and .
The operator means a rotation of amplitude .
All this means rotating around and amplifying the distance to the vector until as close as possible to the hyper-plane .
This procedure is graphically shown in
Figure 2.
Similar to Grover’s algorithm, we assume for ours that , so . The number of iterations k is determined such that ; therefore, . If we measure the final state, we obtain the probability of the solution states as follows, and the probability of the non-solution states is .
Specific Case
Let us consider F a formula (or, equivalently, a set of clauses connected by conjunctions) whose vocabulary is the set of Boolean variables in it, i.e., . We are creating an incremental approach, regarding the amount of clauses considered, such that at any step i, we consider a subset of clauses that is satisfiable. At this point, we have a partial truth assignment v, i.e., a pair of sets of indices such that and . Let represent the complementary set of indices, i.e., the set of indices for which the truth value of is not decided .
, we define the unitary gate
as follows:
The operator
of Equation (
9) in
Section 3.2 is defined as follows
where ⊗ stands for the tensorial product.
When this operator acts over
, the following outcome is obtained
3.3. Clauses Heuristics
We finally define a heuristic to lead the incorporation of clauses to the process until they conform with the whole (former) SAT formula, since the algorithm pseudo-coded in 1 does not provide any criteria to develop this “incremental” procedure.
Aiming to save computational costs, we defined a heuristic to detect conflict with the decisions already taken on the variables in either I or in J as quickly as possible, meaning that these unsatisfiable formulas are identified as soon as possible.
We propose an order on the clauses that extends the statistical fact that those atoms whose variables appear less in the former formula would generate a lower number of conflicts, i.e., contradictions.
Definition 4. Let us consider a k-SAT formula F, and a Boolean variable x; we define the number of occurrences of x in F, and stands for the number of occurrences of in F:
If is a clause () If F is a set of clauses ()Finally, we define .
Intuitively, if is low, the probability of conflict coming from x when considering a clause containing x is low. We use this value for each of the variables in a clause in order to grade the tentative conflictivity of clauses to be added to , therefore leading the previously referenced incremental fashion.
Definition 5. Let F be a k-SAT formula and a clause within F. The order function is defined as followswhere is i-th value of the decreasingly ordered list of the NOC of variables belonging to F, i.e., . Finally, our incremental approach chooses the unitary set at any stage, such that the clause C minimizes .
4. Testing the Proposal
4.1. Testbed
In order to test the performance of the proposed algorithm, we measured four parameters:
The first parameter is the maximum number of qubits superposed in the execution of the algorithm. This parameter, in the original Grover’s algorithm, is the total number of variables in the problem, whereas in our proposed algorithm it is the maximum number of qubits superposed along all Grover’s bounded algorithm circuits that are executed when applying the proposal.
The second parameter is the maximum number of clauses in Oracle; that is, the maximum number of clauses in Oracle along all Grover’s bounded algorithm circuits that are executed.
The third parameter is the total number of quantum iterations; that is, the total number of requests to Oracle in both Grover’s algorithms and in Grover’s bounded algorithms.
The last parameter analysed is the maximum number of qubits used in circuit; this is the maximum number of qubits used along all Grover’s bounded algorithm circuits that are executed.
This performance testing can be reproduced by executing the code of the repository [
30], typesetting the following commands to generate the test cases (
Figure 3):
where:
-v: number of variables for the test case (ranging from 5 to 16).
--densities: densities for each test case (ranging from 2 to 5).
-k: number of variables per clause (3-SAT).
-e: number of examples per test case (below can be found more detailed).
--seed: seed governing the stochastic behaviour in the process (1 in the proposed case).
Additionally, this one can be used to execute our algorithm:
More on detail:
- 1.
A test case for us is a pair (density, number of variables). Ten examples per each test case are generated.
- 2.
The process of generating test cases was supported by
CNFgen [
31]. In particular, 10 3-SAT problems were generated for each pair (density, number of variables): in total, 4 × 12 different test cases, which compute 480 3-SAT problems. The density values range from 2 to 5 (both included). The number of variables ranges from 5 to 16 since, below 5, this incremental scheme is not needed because computing requirements are affordable enough and, over 16, it is more computationally expensive which, as evidence was found that the advantage we provide could be made smaller, meant that we did not consider using bigger values.
- 3.
Each of the 480 3-SAT problems was executed in each of the three scenarios to be compared and, for random measuring issues, five different seeds were also involved; therefore, in the end, different executions were performed over each of the three scenarios under comparison.
- 4.
The experimental set up was powered by Qsimov Quantum Simulator [
32]. Unfortunately, the space computational complexity requirements prevented us from running examples with more than five variables; therefore, for the remaining cases we computed the probability amplitudes of the states instead of simulating the whole quantum computing process, according to the well-known formulas in [
33]:
where
t is the number of iterations,
k is the number of solutions and
N is the total number of states. Afterwards, we randomly (five previously referenced seeds) chose the final quantum state among the obtained solutions.
- 5.
The algorithm finishes when there are no more clauses to be added before the former SAT problem is reached.
We decided to start from scratch regarding the definition of function , i.e., from an empty truth assignment over the set of Boolean variables. This is because once we developed multiple experiments considering a variety of partial definitions of v to start from (either considering random chosen values or values coming from a frequency data analysis of variables in the SAT formula), the results we obtained did not improve on those we have chosen; therefore, for the sake of simplicity, this is our decision.
Some other non-relevant assumptions we made are as follows:
We know the number of solutions needed to determine the number of iterations in each execution in advance for both original and modified Grover’s algorithms.
The result of the measurement is always one of the maximum probability states. In both cases, we have to repeat the algorithm to obtain a probability distribution, so we simplified this step.
Each 3-SAT problem has at least one solution because no version of Grover’s algorithm works for problems with no solution.
To finish with, the scenarios we considered are as follows:
- 1.
Grover’s algorithm.
- 2.
New approach algorithm that is randomly ordered.
- 3.
New approach algorithm with heuristic order.
4.2. Results
Once the experiments were performed, we summarised the outcomes as follows:
As the number of qubits on superposition is a key issue from the performance perspective, the following four graphs show a very noticeable improvement almost regardless of the density of the 3-SAT formulas under consideration. This advantage was maintained in cases in which there was no predefined order to the clauses added to our
incremental scheme, although it was not as big as that with respect to the former Grover’s algorithm (
Figure 4).
Another very important part of the quantum algorithm is performing the oracle, where the amount of clauses directly affects the number of ancillary qubits required; therefore, the next four graphs are devoted to measuring this fact, again using the densities of 3-SAT formulas. The results obtained clearly show the advantage of the proposed algorithm (
Figure 5):
Finally, we conducted a space computational complexity analysis; in the following four graphs, wepresent the results obtained when measuring the upper bound for the number of qubits used along the whole of the proposed algorithm. In our opinion, these are the most representative graphs showing the improvement provided by our proposal (
Figure 6).
The next four raphs are devoted to capturing issues within the temporal computational complexity. In particular, we measured the number of Grover’s iterations. The following results show that our algorithm requires both a high number of variables as well as high-density formulas in order to improve the results of the original Grover’s algorithm (
Figure 7).
The results provided by our experiments show that, although the space computational complexity of the proposed algorithm is the same than that of Grover´s algorithm, in practice, the number of qubits needed to perform the computations is reduced in a factor that can range between 1.5 and 2.2. This fact, in practice, represents a noticeable improvement since the main drawback to dealing with quantum computing is the number of qubits that are required.
Going beyond this, we found that the extra auxiliary qubits required for each clause under consideration is reduced at least as much as the total number of qubits.
Finally, the biggest advantage pertains to the number of superposed qubits which, as the graphs show, is really important. This last feature is of paramount importance in quantum computing, whether actual or simulated.
Appendix A provides all the raw numbers we used to create the previous 16 maps that summarize the performance in the comparative study we developed. Green numbers highlight advantages, while red numbers highlight disadvantages compared to Grover´s algorithm.
5. Conclusions and Further Work
We dealt with the classic problem of deciding whether any truth assignments exist for a Boolean formula. This is a widely studied problem in the related literature in Maths, Physics, Engineering, etc. From the quantum computing perspective, Grover’s algorithm has proven to be a useful tool.
We presented an algorithm which, inspired by Grover´s one, has improved the amount of quantum computational resources by a significant ratio. For this algorithm to be designed, we described a sort of incremental strategy over the sets of clauses that conforms to the 3-SAT formula under scope. The aim of this process is, on the one hand, to use the advantages of Grover´s modified algorithm and, on the other hand, to choose an appropriate conforming order (within this incremental scheme) such that the assumptions required for Grover’s modified algorithm to be used are as useful as possible. This last issue led us to define an heuristics for the set of clauses to be added to the previously described incremental scheme.
This algorithm solves 3-SAT problems with significantly less quantum computational resources, namely qubits, and fewer iterations than those required for former Grover’s algorithm. As the ordinary bottleneck at quantum computing is strongly dependant on the total number of qubits (especially those that are entangled) that are required, this algorithm extends the scope of 3-SAT problems to be solved given a quantum computing machine.
As future work, we plan to further elaborate the heuristics and the process of incorporating clauses within our incremental scheme, mainly by incorporating more than one clause at each step, perhaps under a dynamic criterion.