Boolean Satisfiability Problem (SAT)

Distribute Education like Computer Geek

Introduction

.

The Boolean Satisfiability Problem (SAT) is one of the most important problems in computer science. It asks whether a given Boolean formula can be made true by assigning truth values (true or false) to its variables. SAT was the first problem to be proven NP-complete.

.

What is SAT?

The Boolean Satisfiability Problem asks whether there is a way to assign truth values (true or false) to variables in a Boolean formula, so that the entire formula evaluates to true.

A Boolean formula is built using

  • Variables (e.g., x1, x2, …)
  • Logical operators like AND ( ∧ ), OR ( ∨ ), and NOT ( ¬ ).

For example, a SAT problem could be

(x1 ∨ x2) ∧ (¬x2 ∨ x3)

Boolean Satisfiability Problem (SAT)

The question is that can we assign values to x1, x2, x3 such that this formula evaluates to true?

If there exists such an assignment, the formula is said to be satisfiable. If no such assignment exists, the formula is unsatisfiable.

.

The Discovery of NP-Complete Problems

The breakthrough came in 1971, when American computer scientist Stephen Cook made a revolutionary discovery. He introduced the concept of NP-completeness in his paper “The Complexity of Theorem-Proving Procedures.”

Cook identified a set of problems that were the hardest problems in NP. These problems are called NP-complete problems. If you could find a fast (polynomial-time) solution for any one NP-complete problem, you could solve all NP problems quickly.

.

Boolean Satisfiability Problem is NP-Complete

Cook’s most famous result was showing that the Boolean Satisfiability Problem (SAT) is NP-complete. This means:

  1. SAT belongs to NP.
  2. Every other problem in NP can be reduced to SAT in polynomial time.

This makes SAT the first NP-complete problem, and it opened the door to a vast new field of research on NP-completeness.

Cook’s theorem, called the Cook-Levin Theorem, proves that any problem in NP can be transformed into an instance of SAT in polynomial time. This means that if we could find a fast algorithm to solve SAT, we could also solve every other NP-complete problem quickly.

.

Variants of SAT

Variants of SAT, such as 2-SAT and 3-SAT, are based on the number of literals in each clause. Additionally, the terms 2-CNF and 3-CNF refer to specific forms of SAT where the formula is in Conjunctive Normal Form (CNF), meaning it consists of a conjunction of clauses, and each clause is a disjunction of literals.

.

Conjunctive Normal Form (CNF) or Product of Sums (POS)

CNF is a way of structuring a Boolean formula. A formula in CNF is a conjunction (AND) of one or more clauses, where each clause is a disjunction (OR) of literals. A literal is either a variable or its negation.

For example, the formula

(x1 ​∨ ¬x2​) ∧ (x1 ​∨ ¬x3​)

is in CNF or POS because it is an AND of two clauses, and each clause is an OR of literals.

A Boolean formula is in 2-CNF if each clause has exactly two literals. For example, (x1​ ∨ ¬x2​) ∧ (x2 ​∨ x3​) is a 2-CNF formula.

A Boolean formula is in 3-CNF if each clause has exactly three literals. For example, (x1 ​∨ ¬x2 ​∨ x3​) ∧ (¬x1 ​∨ x2​∨ ¬x3​) is a 3-CNF formula.

.

Working of SAT

A Boolean formula consists of variables and logical operators like AND ( ∧ ), OR ( ∨ ), and NOT ( ¬ ). The goal of the SAT problem is to determine if there is a way to assign true or false values to the variables such that the formula evaluates to true.

.

SAT Algorithm (Brute Force Approach)

A simple way to solve SAT is by brute force, where all possible combinations of truth values are tried for the variables to check if the formula evaluates to true.

  1. Input – A Boolean formula in CNF with variables.
  2. For each possible assignment of truth values to the variables:
  3. Substitute the truth values into the formula.
  4. Evaluate the formula.
  5. If the formula evaluates to true, return “Satisfiable“.
  6. If no truth assignment satisfies the formula, return “Unsatisfiable“.

.

2-SAT Problem

2-SAT is a special case where the Boolean formula is in 2-CNF, meaning each clause has exactly two literals. 2-SAT can be solved in polynomial time. It is easier to solve than general SAT or 3-SAT problems, which are NP-complete.

(x1​ ∨ ¬x2​) ∧ (¬x1 ​∨ x3​)

This formula can be solved efficiently using graph-based algorithms such as Kosaraju’s Algorithm for strongly connected components.

.

Algorithm for 2-SAT

  1. Convert each clause into two implications.
    • For (x1 ¬x2), If x2 is true, then x1​ must be true. If x1 is false, then x2​ must be false.
  2. Build the implication graph.
  3. Find strongly connected components using Kosaraju’s Algorithm.
  4. If no variable and its negation appear in the same strongly connected component, the formula is satisfiable.

.

Example of a 2-SAT problem

(x1 ​∨ ¬x2​) ∧ (¬x1​ ∨ x3​)

  1. We have three variables – x1, x2, x3​.
  2. Possible assignments of truth values are {T, F} (True or False).

For x1 = True, x2 = True, x3 = True, the formula becomes True. Therefore, this formula is satisfiable.

.

3-SAT Problem

3-SAT is a more complex variant where the formula is in 3-CNF, and each clause has exactly three literals. Unlike 2-SAT, 3-SAT is NP-complete, meaning it is computationally hard to solve.

(x1 ​∨ ¬x2​ ∨ x3​) ∧ (¬x1​ ∨ x2 ​∨ ¬x3​)

Since 3-SAT is NP-complete, there is no known polynomial-time algorithm to solve it. We cannot solve it as an implication graph. It is generally solved using brute force, backtracking, or the DPLL (Davis–Putnam–Logemann–Loveland) algorithm.

.

Algorithm for 3-SAT

  1. Try all possible truth assignments for the variables.
  2. Evaluate the formula for each combination.
  3. If a combination satisfies the formula, the formula is satisfiable; otherwise, it is unsatisfiable.

.

Example of a 3-SAT formula

(x1 ¬x2 ∨ x3) ∧ (¬x1 ∨ x2 ¬x4)

x1​=True, x2​=True, x3​=False, x4​=False. Since all the two clauses are true, the formula is satisfiable for this truth assignment.

For small problems (like the example with only 4 variables), you can easily try different combinations of truth values to find a satisfying assignment.

However, if the number of variables becomes large, the number of possible assignments grows exponentially.

So, if n=10, there are 210 = 1024 assignments to check. For n=100, there are 2100, which is more than 1 trillion possible combinations!

.

Q – If we produce 100 variables in 2-SAT problem than 2-SAT is also np complete?

Answer – 2-SAT can be represented as an implication graph where each clause corresponds to two implications. Using graph algorithms like Tarjan’s algorithm or Kosaraju’s algorithm, we can efficiently find strongly connected components (SCCs) in the implication graph.

(x1​ ∨ ¬x2​) ∧ (¬x3​ ∨ x4​) ∧ (¬x1 ​∨ x2​)

  • (x1​ ∨ ¬x2​) becomes ¬x1 → x2 and x2 → ¬x1​
  • (¬x3 ∨ x4) becomes x3 → x4 and ¬x4 ​→ x3​
  • (¬x1 ∨ x2) becomes x1 → x2​ and ¬x2 → ¬x1

Using an SCC algorithm, we can check whether the formula is satisfiable in linear time. Even if you have 100 variables in a 2-SAT problem, it can still be solved in polynomial time.

Test Yourself

Q1- What is the significance of the Boolean Satisfiability Problem (SAT) in computer science?

SAT is significant because it was the first problem proven to be NP-complete, which means all other problems in NP can be reduced to it in polynomial time. Solving SAT efficiently could potentially solve all NP problems quickly.

Q2- How does the NP-completeness of SAT impact other NP problems?

Since SAT is NP-complete, if an efficient (polynomial-time) algorithm for SAT is found, it can be adapted to solve every NP-complete problem, making it a pivotal problem in complexity theory.

Q3- What is the difference between 2-SAT and 3-SAT problems?

The main difference is the number of literals in each clause. 2-SAT problems have two literals per clause and can be solved in polynomial time, while 3-SAT problems have three literals per clause and are NP-complete, making them computationally harder.

Q4- Why is the Cook-Levin Theorem important in computer science?

The Cook-Levin Theorem proved that SAT is NP-complete, providing the foundation for the theory of NP-completeness and helping identify which problems are the hardest to solve within NP.

Q5- What role do implication graphs play in solving 2-SAT problems?

Implication graphs are used to represent the relationships between variables in 2-SAT. By finding strongly connected components (SCCs), we can determine whether a formula is satisfiable or not in polynomial time.

Q6- Which of the following is the first problem proven to be NP-complete?
  1. 2-SAT
  2. Hamiltonian Path
  3. Boolean Satisfiability Problem (SAT)
  4. Traveling Salesman Problem

Ans – (3)

Explanation – SAT was the first problem proven to be NP-complete, according to Cook’s Theorem.

Q7- What is the primary goal of the SAT problem?
  1. Find the shortest path
  2. Find an assignment of truth values
  3. Optimize a Boolean function
  4. Factorize Numbers

Ans – (2)

Explanation – SAT aims to find an assignment of truth values to variables such that the Boolean formula evaluates to true.

Q8- What does CNF stand for in Boolean formulas?
  1. Conjunctive Normal Form
  2. Convolutional Neural Formula
  3. Configurable Network Form
  4. Computational Numeric Formula

Ans – (1)

Explanation – CNF stands for Conjunctive Normal Form, which is an AND of ORs structure in Boolean logic.

Q9- What is the key difference between 2-SAT and 3-SAT in terms of complexity?
  1. 2-SAT is harder than 3-SAT
  2. 2-SAT is solvable in polynomial time, while 3-SAT is NP-complete
  3. Both are NP-complete
  4. Both are solvable in polynomial time

Ans – (2)

Explanation – 2-SAT is solvable in polynomial time, but 3-SAT is NP-complete, making it harder to solve.

Q10- Which of the following is a method for solving 3-SAT problems?
  1. Brute force
  2. Dijkstra’s Algorithm
  3. Greedy Algorithm
  4. Dynamic Programming

Ans – (1)

Explanation – 3-SAT problems are often solved using brute force, as there is no known polynomial-time solution.

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha