SatyPy: SAT Solver through Minimum Independent Dominating Set
This work builds upon SatyPy: SAT Solver.
SatyPy decides Boolean formulas in CNF by reducing them directly to Minimum Independent Dominating Set (MIDS): a vertex for
every literal and for every clause, one independence edge between the two literals of each variable, and each clause
adjacent to its literals. An independent dominating set of this graph without clause vertices is exactly a satisfying
assignment: one literal per variable (the independence edge) and every clause dominated by a true literal. SatyPy asks the
MIDS search of Siriaisa (satypy.siriaisa) for such a set, with the clause vertices as its forbidden vertices. Every
SATISFIABLE comes with a checked assignment. UNSATISFIABLE is printed when an exact stage proves it, when every branch is
proved unsatisfiable, or, if algorithm.ASSUME_SEARCH_COMPLETE is True, at the deepest level, under the assumption that the
search finds such a set whenever one exists; with the assumption off (ASSUME_SEARCH_COMPLETE = False) the answer there is
UNKNOWN (see What Is Proved and What Is Assumed).
Boolean Satisfiability (SAT) Problem
Problem: Given a Boolean formula in Conjunctive Normal Form (CNF), is there a truth assignment that makes the formula evaluate to true?
Background:
The Boolean Satisfiability Problem (SAT) is a fundamental problem in computer science. It is known to be NP-complete, which means that any problem whose solution can be verified in polynomial time can be reduced to SAT. This implies that SAT is likely to be computationally difficult, although there is no proof of this.
Concepts:
- Literal: A variable or its negation (e.g., $x$ or $\neg x$).
- Clause: A disjunction (OR) of one or more literals (e.g., $x \vee \neg y \vee z$).
- Conjunctive Normal Form (CNF): A Boolean formula where each clause is connected by conjunction (AND).
- Truth Assignment: An assignment of truth values (true or false) to all variables in a formula.
- Satisfying Truth Assignment: A truth assignment that makes a formula evaluate to true.
- Satisfiable Formula: A formula that has a satisfying truth assignment.
Example:
Consider the formula $(x_1 \vee ¬x_3 \vee ¬x_2) \wedge (x_3 \vee x_2 \vee x_4)$, where $\vee$ (OR), $\wedge$ (AND) and $\neg$ (NEGATION) are the logic operations. This formula is in CNF with four variables ($x_1$, $x_2$, $x_3$, and $x_4$) and two clauses. A possible satisfying truth assignment is ($x_1$: False, $x_2$: False, $x_3$: True, and $x_4$: False).
Input format:
The input for SAT solvers is typically provided in DIMACS format (.cnf files). A DIMACS file consists of three parts:
- Header: The first line specifies the number of variables (n) and clauses (m) in the formula using the format
p cnf n m. - Clauses: Each subsequent line represents a clause, where each literal is represented by a variable's index (positive for the variable, negative for its negation). A zero at the end of the line indicates the end of the clause.
Example .cnf file:
p cnf 4 2
1 -3 -2 0
3 2 4 0
This is a .cnf file representing a Boolean formula in Conjunctive Normal Form (CNF) for the Boolean Satisfiability Problem (SAT). Let's break down what each line means:
-
Header (p cnf 4 2):
p cnfindicates it's a CNF formula in DIMACS format.4specifies the number of variables in the formula ($x_1$, $x_2$, $x_3$, and $x_4$ in this case).2specifies the number of clauses (disjunctions of literals) in the formula.
-
Clauses (1 -3 -2 0 and 3 2 4 0):
- Each line represents a clause.
- A positive integer represents a variable (e.g.,
1represents variable $x_1$). - A negative integer represents the negation of a variable (e.g.,
-3represents $\neg x_3$). 0at the end of the line indicates the end of the clause.
Explanation of the clauses:
1 -3 -2 0: This clause translates to $(x_1 \vee \neg x_3 \vee \neg x_2)$, which means at least one of $x_1$, $\neg x_3$, or $\neg x_2$ must be true for the clause to be true.3 2 4 0: This clause translates to $(x_3 \vee x_2 \vee x_4)$, which means at least one of $x_3$, $x_2$, or $x_3$ must be true for the clause to be true.
In essence, the formula represented by this .cnf file is asking if there exists an assignment of truth values (true or false) to the variables $x_1$, $x_2$, $x_3$, and $x_4$ that makes both clauses true simultaneously.
Installation and Setup
1. Install Python:
- Ensure you have Python 3.12 or a later version installed on your system. You can download and install it from the official Python website: https://www.python.org/downloads/
2. Install SatyPy's Library:
- Open your terminal or command prompt.
- Use
pipto install the SatyPy library and its dependencies:
pip install satypy
Running the SAT Solver with SatyPy
Download the repository (it contains sample formulas):
git clone https://github.com/frankvegadelgado/satypy.git
cd satypy
and run saty on a DIMACS file (.cnf, also compressed as .xz, .lzma, .bz2 or .bzip2):
saty -i benchmarks/test_formulas/formula2.cnf
Variable identifiers may be any positive integers: they need not be 1..n, contiguous, or sorted.
Output Interpretation
SatyPy prints its answer in the DIMACS output format.
-
Satisfiable, with an assignment:
s SATISFIABLE v 1 2 -3 0Positive numbers are variables assigned True, negative numbers variables assigned False, and
0ends the line. The assignment has been checked against every clause of the input. -
Unsatisfiable:
s UNSATISFIABLE, when an exact stage proves it, when every branch on a clause falsified by the set found by the search is unsatisfiable, or, at the deepest level, when the search leaves vertices undominated andalgorithm.ASSUME_SEARCH_COMPLETEis True (the default; this answer is an assumption, not a proof). -
Comment lines: before the answer, SatyPy prints DIMACS comment lines (
c ...) that report what the MIDS stage found and, when the formula is decided, a linec decided by: ...naming the stage that decided it (empty clause, simplification, 2-SAT, MIDS graph, branching, or MIDS graph under the assumption). -
Undecided:
s UNKNOWN, preceded by the comment lines. It is printed when the assignment of a set that dominates every vertex does not satisfy the formula, or, only withASSUME_SEARCH_COMPLETE = False, when the search leaves vertices undominated and branching decides nothing.
Examples
The directory benchmarks/test_formulas contains five small formulas; planted_unique_v6_2.cnf (6 variables, 16
clauses, a single satisfying assignment) exercises the branching step.
saty -i benchmarks/test_formulas/formula2.cnf
saty -i benchmarks/test_formulas/formula3.cnf
saty -i benchmarks/test_formulas/planted_unique_v6_2.cnf -b -l
batch_saty -i benchmarks/test_formulas -a -b -c
Command-Line Options
To view the available command-line options for the saty command, use the following command in your terminal or command prompt:
saty -h
This will display the help message, which provides information about the available options and their usage:
usage: saty [-h] -i INPUTFILE [-a] [-b] [-c] [-v] [-t] [-l] [--version]
Solve the Boolean Satisfiability (SAT) problem using a DIMACS file as input.
options:
-h, --help show this help message and exit
-i INPUTFILE, --inputFile INPUTFILE
Input file path
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
-b, --bruteForce enable comparison with the exponential-time brute-force approach (at most 30 variables)
-c, --count only state whether the formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
-v, --verbose Enable verbose output
-t, --timer Enable timer output
-l, --log Enable file logging
--version show program's version number and exit
Available Options:
-h, --help: Displays this help message and exits the program.
-i INPUTFILE, --inputFile INPUTFILE: Specifies the path to the input file containing the Boolean formula. This option is required.
-a, --approximation: Also solves the formula with MiniSat 2.2 and reports both answers.
-b, --bruteForce: Also solves the formula by exhaustive search (skipped above 30 variables).
-c, --count: Prints only SATISFIABLE, UNSATISFIABLE or UNKNOWN instead of the DIMACS assignment.
-v, --verbose: Enables verbose output, providing more detailed information about the solver's progress.
-t, --timer: Enables timer output, displaying the time taken by the solver to find a solution.
-l, --log: Enables file logging, writing detailed information about the solver's execution to a log file.
With -a or -b every answer is prefixed by its source and any disagreement is reported, for example:
saty -i benchmarks/simple/file.cnf -a -b -c
file.cnf: (MiniSat) SATISFIABLE
file.cnf: (Brute Force) SATISFIABLE
file.cnf: (SatyPy) SATISFIABLE
By using these command-line options, you can customize the behavior of the saty command to suit your specific needs.
Batch Execution
Batch execution allows you to solve multiple formulas within a directory simultaneously.
To view available command-line options for the batch_saty command, use the following in your terminal or command prompt:
batch_saty -h
This will display the following help information:
usage: batch_saty [-h] -i INPUTDIRECTORY [-a] [-b] [-c] [-v] [-t] [-l] [--version]
Solve the Boolean Satisfiability (SAT) problem using a directory with DIMACS files as input.
options:
-h, --help show this help message and exit
-i INPUTDIRECTORY, --inputDirectory INPUTDIRECTORY
Input directory path
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
-b, --bruteForce enable comparison with the exponential-time brute-force approach (at most 30 variables)
-c, --count only state whether each formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
-v, --verbose Enable verbose output
-t, --timer Enable timer output
-l, --log Enable file logging
--version show program's version number and exit
The options have the same meaning as for saty and apply to every file of the directory (processed in name order).
Testing with Random Formulas
The test_saty command generates random CNF formulas and compares SatyPy against a brute-force search (-b) and
against MiniSat 2.2 through python-sat (-a):
test_saty -h
usage: test_saty [-h] -d DIMENSION [-m CLAUSES] [-k WIDTH] [-n NUM_TESTS] [-g] [-r SEED] [-a] [-b] [-c] [-w] [-v] [-l] [--version]
options:
-d DIMENSION, --dimension DIMENSION number of variables of each formula
-m CLAUSES, --clauses CLAUSES number of clauses (default: round(4.26 * dimension))
-k WIDTH, --width WIDTH literals per clause (default: 3)
-n NUM_TESTS, --num_tests NUM_TESTS number of tests to run
-g, --gaps use random non-contiguous variable IDs instead of 1..dimension
-r SEED, --seed SEED random seed
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
-b, --bruteForce enable comparison with the exponential-time brute-force approach
-c, --count only state whether each formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
-w, --write write each generated formula to a DIMACS file in the current directory
-v, --verbose enable verbose output
-l, --log enable file logging
Example:
test_saty -d 6 -m 12 -n 8 -g -r 7 -a -b -c
How SatyPy Solves a Formula
Variable IDs may be any positive integers (not necessarily 1..n, contiguous, or sorted).
- Empty clause: a formula containing the empty clause (a lone
0in DIMACS) is unsatisfiable. - Simplification (
reduction.reduce_sat_to_simplified_sat): unit propagation and pure literals. A conflict proves the formula unsatisfiable. - 2-SAT: if every remaining clause has at most two literals, the formula is decided exactly by the
strongly-connected-components algorithm (
algorithm._solve_two_sat). - Reduction to MIDS (
reduction.reduce_cnf_to_mids): the residual formula is used as it is. For each variablevthere are the vertices(v)and(¬v), joined by an independence edge, and each clauseiis a vertex adjacent to the vertices of its literals. There is no other edge. WithNthe number of variables, the graph has2Nliteral vertices and one vertex per clause. - MIDS search with forbidden vertices (
siriaisa.algorithm.find_independent_dominating_setwith the clause vertices asforbidden, implemented bysiriaisa.forbidden_search): a weighted local search over independent sets without clause vertices. It starts from a random maximal independent set of the literal vertices (one literal per variable) and minimises the weight of the undominated vertices. A step picks a random undominated vertex and inserts the vertex of its closed neighbourhood (a literal vertex) that decreases the weight most, evicting its neighbours in the set (the opposite literal); with probability 0.02 a random candidate is taken instead. After every step the weight of every undominated vertex grows by one (halved when the mean exceeds 50), and the work is bounded bymax(50(n + m), 400000)units, so the search is linear for fixed parameters. It returns the independent set with fewest undominated vertices that it met; the set is a dominating set exactly when it leaves none. The search of the formula given tosolve(which runs once) getsmax(1 + 2d, R/10)times that work,dbeing the branching depth andRthe number of searches that the whole branching runs at most (so the extra work is at most a tenth of the work of the branching); the searches of the branches get the work above. Then:- if it leaves no vertex undominated,
reduction.decode_midsreads the literals of its vertices; the completed assignment is verified against the input (s SATISFIABLE), and if it does not satisfy the formula the answer iss UNKNOWN; - otherwise step 6 runs.
- if it leaves no vertex undominated,
- Branching on a clause falsified by the set found by the search (
algorithm._branch, up to depthd = max(2, ⌊log₃(m + n)⌋),algorithm.default_branch_depth, withmclauses andnvariables in the input): the literals of the set, completed with False, either satisfy the formula (s SATISFIABLE) or falsify some clauses. SatyPy takes a shortest falsified clauseCand decides every formulaφ ∧ ℓ,ℓ ∈ C, with steps 2–6 and one level less: the formula impliesC, so it is satisfiable exactly when some branch is.- some branch satisfiable:
s SATISFIABLE, with the checked assignment of that branch; - every branch unsatisfiable:
s UNSATISFIABLE; - at depth 0 (no branching left):
s UNSATISFIABLEifalgorithm.ASSUME_SEARCH_COMPLETEis True,s UNKNOWNotherwise.
- some branch satisfiable:
s SATISFIABLE is printed only after the assignment has been checked to be consistent and to contain a literal of
every clause of the input (a final certification gate in algorithm.solve). s UNSATISFIABLE comes from steps 1–3, from
the branching, or from the assumption at depth 0. algorithm.solve(formula, branch_depth=0) gives the answer without
branching. Use -l to see the stages of the formula in app.log; the answer is also printed on the console.
What Is Proved and What Is Assumed
Write N for the number of variables of the residual formula and G for its MIDS graph (one vertex per clause).
Proved.
- The graph. The two literal vertices of a variable are adjacent and are the only edge between literal vertices; a clause vertex is adjacent only to the literal vertices of its literals. Each literal vertex dominates the pair of its variable.
- Independent dominating sets without clause vertices. Let
Sbe an independent dominating set ofGwith no clause vertex. The two literals of a variable are adjacent, soSholds at most one of them, and it holds at least one because the literal vertices of the variable must be dominated and only literal vertices are inS; soSis one literal per variable, and every clause vertex is adjacent to a vertex ofS, a true literal of that clause. Conversely an assignment gives such a set. SoGhas an independent dominating set without clause vertices exactly when the formula is satisfiable, and its size is thenN. - The answers. Every
SATISFIABLEanswer carries a checked assignment.UNSATISFIABLEcomes from the exact stages 1–3, from branching when every branch is unsatisfiable, or, at depth 0, from the assumption below. - Branching. Splitting on a clause is exact, and branching to depth
druns the MIDS stage at most1 + w + … + w^dtimes (wthe largest clause width). Withd = max(2, ⌊log₃(m + n)⌋)andw = 3that is(3^(d+1) − 1)/2 ≤ max(13, 3(m + n)/2)runs.
Not proved.
- The assumption.
UNSATISFIABLEat depth 0 assumes that the search finds an independent dominating set without clause vertices whenever one exists. Deciding whether one exists is deciding satisfiability, so the search is a heuristic and this answer is not a proof;ASSUME_SEARCH_COMPLETE = Falseturns it intoUNKNOWN.
Running the Experiments
The folder car/ contains three experiment scripts. All run from the repository root (or from car/) with or without
SatyPy installed: they use the repository's own satypy/ (Siriaisa included). networkx must be installed, and
python-sat for the comparison with MiniSat.
car/small_formulas.py decides every formula with SatyPy and with exhaustive search over all assignments and
compares the answers. Its formulas are the small DIMACS files of benchmarks/simple and benchmarks/test_formulas
(at most --max-file-variables variables) and random k-CNF formulas.
python car/small_formulas.py
python car/small_formulas.py --variables 3 6 --clauses 16 --repeat 10 --seed 7
python car/small_formulas.py --no-files --width 4
| Option | Meaning (default) |
|---|---|
--variables MIN MAX |
number of variables of the random formulas (3 5) |
--clauses M |
largest number of clauses; every number from 1 to M is used (12) |
--width K |
literals per clause (3) |
--repeat R |
random formulas per number of variables and clauses (5) |
--seed S |
random seed (2026) |
--max-file-variables V |
largest DIMACS file included (10) |
--no-files |
random formulas only |
-o FILE |
output CSV (car/small_formulas_results.csv) |
For each formula it prints and writes the expected answer, SatyPy's answer, whether it is correct, the deciding stage, and, for the formulas that reach the MIDS graph, its vertices, edges, maximum degree, the size of the set found by the search and the number of vertices it leaves undominated. The summary counts correct, wrong and unknown answers and lists every wrong one.
car/medium_formulas.py and car/large_formulas.py compare SatyPy with MiniSat 2.2 (python-sat) on random
k-CNF formulas with round(ratio · variables) clauses; MiniSat runs with a conflict budget, and a formula it does not
finish has no reference answer (a SATISFIABLE answer of SatyPy is always checked against the formula).
python car/medium_formulas.py
python car/medium_formulas.py --variables 30 50 --ratios 4.27 --repeat 20 --seed 7
python car/large_formulas.py
python car/large_formulas.py --variables 100 200 --ratios 4.27 --repeat 3 --reference-conflicts 5000000
| Option | Meaning (medium default; large default) |
|---|---|
--variables V ... |
numbers of variables (30 50 75; 100 200 400) |
--ratios R ... |
clauses per variable (3.0 4.0 4.27 4.5) |
--width K |
literals per clause (3) |
--repeat R |
random formulas per setting (5; 3) |
--seed S |
random seed (2026) |
--reference-conflicts C |
conflict budget of MiniSat (1000000; 2000000) |
-o FILE |
output CSV (car/medium_formulas_results.csv, car/large_formulas_results.csv) |
For each formula they print and write MiniSat's answer, SatyPy's answer and its correctness, the deciding stage, the vertices of the MIDS graph, the size of the set found by the search, the vertices it leaves undominated and both running times.
Testing a single formula. Any DIMACS file can be checked against exhaustive search (-b, at most 30 variables) and
MiniSat 2.2 (-a), with the deciding stage in app.log (-l):
saty -i benchmarks/test_formulas/planted_unique_v6_2.cnf -a -b -l
test_saty -d 5 -m 12 -n 20 -r 7 -a -b -c
References
- R. M. Karp, Reducibility among combinatorial problems, 1972; M. R. Garey and D. S. Johnson, Computers and Intractability, Freeman, 1979.
- B. Aspvall, M. F. Plass and R. E. Tarjan, A linear-time algorithm for testing the truth of certain quantified Boolean formulas, Inform. Process. Lett. 8 (1979) 121–123.
- Y. Cai, K. Su, C. Luo and A. Sattar, NuMVC: An efficient local search algorithm for minimum vertex cover, J. Artif. Intell. Res. 46 (2013) 687–716.
Implementation
- Programming Language: Python
- Author: Frank Vega
License
This code is released under the MIT License.
Metadata
Release files for satypy 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| satypy-0.0.5.tar.gz | 68.0 kB | With provenance | Details for satypy-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| satypy-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for satypy-0.0.5-py3-none-any.whl |
Total release size: 141.3 kB
Release files / satypy-0.0.5.tar.gz
| Download URL | satypy-0.0.5.tar.gz |
|---|---|
| Size | 68.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
630795b8c2ee2ade534f8024e5ad4da4371ce4421d75b5695e6e2871d82c1632
|
|
BLAKE2b-256 checksum How to use checksums |
6b760269d5caa22488de2d1bc3731ba2ead3ebec9390124202651c82b27152cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logRelease files / satypy-0.0.5-py3-none-any.whl
| Download URL | satypy-0.0.5-py3-none-any.whl |
|---|---|
| Size | 73.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e89c115d009d62f56b7f1412bbdaf0dee15cb8a5df5288d8691a2ec13dfd08a6
|
|
BLAKE2b-256 checksum How to use checksums |
302099f42e19be56ff854d43f6dc0db86f1c5eb22c291e82aa38f71bfd646d3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logSecurity for satypy 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for satypy-0.0.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.