satypy 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- satypy-0.0.1/LICENSE +21 -0
- satypy-0.0.1/PKG-INFO +391 -0
- satypy-0.0.1/README.md +352 -0
- satypy-0.0.1/pyproject.toml +26 -0
- satypy-0.0.1/satypy/__init__.py +4 -0
- satypy-0.0.1/satypy/algorithm.py +166 -0
- satypy-0.0.1/satypy/app.py +128 -0
- satypy-0.0.1/satypy/applogger.py +83 -0
- satypy-0.0.1/satypy/batch.py +57 -0
- satypy-0.0.1/satypy/parser.py +98 -0
- satypy-0.0.1/satypy/reduction.py +553 -0
- satypy-0.0.1/satypy/test.py +93 -0
- satypy-0.0.1/satypy/utils.py +124 -0
- satypy-0.0.1/satypy.egg-info/PKG-INFO +391 -0
- satypy-0.0.1/satypy.egg-info/SOURCES.txt +19 -0
- satypy-0.0.1/satypy.egg-info/dependency_links.txt +1 -0
- satypy-0.0.1/satypy.egg-info/entry_points.txt +4 -0
- satypy-0.0.1/satypy.egg-info/requires.txt +2 -0
- satypy-0.0.1/satypy.egg-info/top_level.txt +1 -0
- satypy-0.0.1/setup.cfg +4 -0
- satypy-0.0.1/setup.py +52 -0
satypy-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Frank Vega
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
satypy-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: satypy
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Solve the Boolean Satisfiability (SAT) problem using a DIMACS file as input.
|
|
5
|
+
Home-page: https://github.com/frankvegadelgado/satypy
|
|
6
|
+
Author: Frank Vega
|
|
7
|
+
Author-email: vega.frank@gmail.com
|
|
8
|
+
License: MIT License
|
|
9
|
+
Project-URL: Source Code, https://github.com/frankvegadelgado/satypy
|
|
10
|
+
Project-URL: Documentation Research, https://github.com/frankvegadelgado/satypy
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering
|
|
12
|
+
Classifier: Topic :: Software Development
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Education
|
|
19
|
+
Classifier: Intended Audience :: Information Technology
|
|
20
|
+
Classifier: Intended Audience :: Science/Research
|
|
21
|
+
Classifier: Natural Language :: English
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: salvador>=0.1.0
|
|
26
|
+
Requires-Dist: python-sat>=1.9.dev5
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: author-email
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: license
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: project-url
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
Dynamic: summary
|
|
39
|
+
|
|
40
|
+
# SatyPy: SAT Solver through Unique Games and Vertex Cover
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
This work builds upon [SatyPy: SAT Solver](https://github.com/frankvegadelgado/satypy).
|
|
45
|
+
|
|
46
|
+
# Boolean Satisfiability (SAT) Problem
|
|
47
|
+
|
|
48
|
+
**Problem:** Given a Boolean formula in Conjunctive Normal Form (CNF), is there a truth assignment that makes the formula evaluate to true?
|
|
49
|
+
|
|
50
|
+
**Background:**
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
**Concepts:**
|
|
55
|
+
|
|
56
|
+
- **Literal:** A variable or its negation (e.g., $x$ or $\neg x$).
|
|
57
|
+
- **Clause:** A disjunction (OR) of one or more literals (e.g., $x \vee \neg y \vee z$).
|
|
58
|
+
- **Conjunctive Normal Form (CNF):** A Boolean formula where each clause is connected by conjunction (AND).
|
|
59
|
+
- **Truth Assignment:** An assignment of truth values (true or false) to all variables in a formula.
|
|
60
|
+
- **Satisfying Truth Assignment:** A truth assignment that makes a formula evaluate to true.
|
|
61
|
+
- **Satisfiable Formula:** A formula that has a satisfying truth assignment.
|
|
62
|
+
|
|
63
|
+
**Example:**
|
|
64
|
+
|
|
65
|
+
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).
|
|
66
|
+
|
|
67
|
+
**Input format:**
|
|
68
|
+
|
|
69
|
+
The input for SAT solvers is typically provided in [DIMACS](https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html) format (`.cnf` files). A DIMACS file consists of three parts:
|
|
70
|
+
|
|
71
|
+
1. **Header:** The first line specifies the number of variables (n) and clauses (m) in the formula using the format `p cnf n m`.
|
|
72
|
+
2. **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.
|
|
73
|
+
|
|
74
|
+
**Example `.cnf` file:**
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
p cnf 4 2
|
|
78
|
+
1 -3 -2 0
|
|
79
|
+
3 2 4 0
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
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:
|
|
83
|
+
|
|
84
|
+
- **Header (p cnf 4 2):**
|
|
85
|
+
|
|
86
|
+
- `p cnf` indicates it's a CNF formula in DIMACS format.
|
|
87
|
+
- `4` specifies the number of variables in the formula ($x_1$, $x_2$, $x_3$, and $x_4$ in this case).
|
|
88
|
+
- `2` specifies the number of clauses (disjunctions of literals) in the formula.
|
|
89
|
+
|
|
90
|
+
- **Clauses (1 -3 -2 0 and 3 2 4 0):**
|
|
91
|
+
- Each line represents a clause.
|
|
92
|
+
- A positive integer represents a variable (e.g., `1` represents variable $x_1$).
|
|
93
|
+
- A negative integer represents the negation of a variable (e.g., `-3` represents $\neg x_3$).
|
|
94
|
+
- `0` at the end of the line indicates the end of the clause.
|
|
95
|
+
|
|
96
|
+
**Explanation of the clauses:**
|
|
97
|
+
|
|
98
|
+
- `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.
|
|
99
|
+
- `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.
|
|
100
|
+
|
|
101
|
+
**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.**
|
|
102
|
+
|
|
103
|
+
## Installation and Setup
|
|
104
|
+
|
|
105
|
+
**1. Install Python:**
|
|
106
|
+
|
|
107
|
+
- 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/
|
|
108
|
+
|
|
109
|
+
**2. Install SatyPy's Library:**
|
|
110
|
+
|
|
111
|
+
- Open your terminal or command prompt.
|
|
112
|
+
- Use `pip` to install the SatyPy library and its dependencies:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pip install satypy
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Running the SAT Solver with SatyPy
|
|
119
|
+
|
|
120
|
+
**Using SatyPy's built-in benchmarks:**
|
|
121
|
+
|
|
122
|
+
1. **Install SatyPy's library:**
|
|
123
|
+
|
|
124
|
+
If you haven't already, follow the installation steps in the previous section to install SatyPy.
|
|
125
|
+
|
|
126
|
+
2. **Download SatyPy's library:**
|
|
127
|
+
|
|
128
|
+
Download the benchmarks from the GitHub repository.
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git clone https://github.com/frankvegadelgado/satypy.git
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
3. **Execute the script:**
|
|
135
|
+
|
|
136
|
+
Open your terminal or command prompt and navigate to the directory where you downloaded SatyPy (e.g., using `cd satypy`).
|
|
137
|
+
|
|
138
|
+
Run the following command to solve a sample `.cnf` file named `file.cnf` included with SatyPy's benchmarks:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
saty -i benchmarks/simple/file.cnf
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
SatyPy supports compressed `.cnf` files, including `.xz`, `.lzma`, `.bz2`, and `.bzip2` formats.
|
|
145
|
+
|
|
146
|
+
**Output Interpretation:**
|
|
147
|
+
|
|
148
|
+
## If the formula is satisfiable, the console output will display:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
s SATISFIABLE
|
|
152
|
+
v 2 4 -3 -1 0
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- **`s SATISFIABLE`:** This line indicates that the SAT solver found a satisfying truth assignment for the given formula.
|
|
156
|
+
- **`v 3 -4 -1 -2 0`:** This line provides the satisfying truth assignment.
|
|
157
|
+
- Positive numbers (e.g., `2`, `4`) represent variables assigned the value "True".
|
|
158
|
+
- Negative numbers (e.g., `-1`, `-3`) represent variables assigned the value "False".
|
|
159
|
+
- `0` marks the end of the truth assignment.
|
|
160
|
+
|
|
161
|
+
## If the formula is unsatisfiable, the console output will display:
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
s UNSATISFIABLE
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## If the solver cannot decide, the console output will display:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
s UNKNOWN
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## SAT Benchmarks and Testing
|
|
174
|
+
|
|
175
|
+
SatyPy includes a collection of sample `.cnf` files in the `benchmarks/file-dimacs-aim` directory. These files can be used to test the functionality of the SAT solver. The files are derived from the well-known [SAT Benchmarks](https://www.cs.ubc.ca/~hoos/SATLIB/Benchmarks/SAT/DIMACS/AIM/descr.html) dataset.
|
|
176
|
+
|
|
177
|
+
**Running Sample Benchmarks:**
|
|
178
|
+
|
|
179
|
+
1. **Ensure SatyPy is installed:** Follow the installation steps in the previous section if you haven't already installed SatyPy.
|
|
180
|
+
|
|
181
|
+
2. **Execute the script:** Open your terminal or command prompt and navigate to the directory where SatyPy was downloaded.
|
|
182
|
+
|
|
183
|
+
You can then use the `saty` command to run the sample benchmarks. For example, the following commands demonstrate running two sample files:
|
|
184
|
+
|
|
185
|
+
- Test the satisfiable formula `aim-50-1_6-yes1-1.cnf`:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
saty -i benchmarks/file-dimacs-aim/aim-50-1_6-yes1-1.cnf
|
|
189
|
+
s SATISFIABLE
|
|
190
|
+
v 2 3 7 8 9 14 17 18 19 20 21 22 23 24 26 27 28 30 31 35 36 38 39 40 41 42 43 46 48 -50 -49 -47 -45 -44 -37 -34 -33 -32 -29 -25 -16 -15 -13 -12 -11 -10 -6 -5 -4 -1 0
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
A satisfiable formula means there exists a truth assignment that makes the formula true. The output will indicate this with s SATISFIABLE followed by the satisfying truth assignment.
|
|
194
|
+
|
|
195
|
+
- Test the unsatisfiable formula `aim-50-1_6-no-1.cnf`:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
saty -i benchmarks/file-dimacs-aim/aim-50-1_6-no-1.cnf
|
|
199
|
+
s UNSATISFIABLE
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
running these sample benchmarks, you can verify that SatyPy is functioning correctly and gain experience using the `saty`
|
|
203
|
+
|
|
204
|
+
## Command-Line Options
|
|
205
|
+
|
|
206
|
+
To view the available command-line options for the `saty` command, use the following command in your terminal or command prompt:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
saty -h
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
This will display the help message, which provides information about the available options and their usage:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
usage: saty [-h] -i INPUTFILE [-a] [-b] [-c] [-m MAX_CLAUSES] [-v] [-t] [-l] [--version]
|
|
216
|
+
|
|
217
|
+
Solve the Boolean Satisfiability (SAT) problem using a DIMACS file as input.
|
|
218
|
+
|
|
219
|
+
options:
|
|
220
|
+
-h, --help show this help message and exit
|
|
221
|
+
-i INPUTFILE, --inputFile INPUTFILE
|
|
222
|
+
Input file path
|
|
223
|
+
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
|
|
224
|
+
-b, --bruteForce enable comparison with the exponential-time brute-force approach (at most 30 variables)
|
|
225
|
+
-c, --count only state whether the formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
|
|
226
|
+
-m MAX_CLAUSES, --max_clauses MAX_CLAUSES
|
|
227
|
+
largest 3-SAT formula sent to the Vertex Cover stage (about 1,900 vertices,
|
|
228
|
+
11,800 edges and 24 MB per clause; default: 100)
|
|
229
|
+
-v, --verbose Enable verbose output
|
|
230
|
+
-t, --timer Enable timer output
|
|
231
|
+
-l, --log Enable file logging
|
|
232
|
+
--version show program's version number and exit
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Available Options:
|
|
236
|
+
|
|
237
|
+
-h, --help: Displays this help message and exits the program.
|
|
238
|
+
-i INPUTFILE, --inputFile INPUTFILE: Specifies the path to the input file containing the Boolean formula. This option is required.
|
|
239
|
+
-a, --approximation: Also solves the formula with MiniSat 2.2 and reports both answers.
|
|
240
|
+
-b, --bruteForce: Also solves the formula by exhaustive search (skipped above 30 variables).
|
|
241
|
+
-c, --count: Prints only SATISFIABLE, UNSATISFIABLE or UNKNOWN instead of the DIMACS assignment.
|
|
242
|
+
-m MAX_CLAUSES, --max_clauses MAX_CLAUSES: Larger 3-SAT formulas skip the Vertex Cover stage and are reported as UNKNOWN.
|
|
243
|
+
-v, --verbose: Enables verbose output, providing more detailed information about the solver's progress.
|
|
244
|
+
-t, --timer: Enables timer output, displaying the time taken by the solver to find a solution.
|
|
245
|
+
-l, --log: Enables file logging, writing detailed information about the solver's execution to a log file.
|
|
246
|
+
|
|
247
|
+
With `-a` or `-b` every answer is prefixed by its source and any disagreement is reported, for example:
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
saty -i benchmarks/simple/file.cnf -a -b -c
|
|
251
|
+
file.cnf: (MiniSat) SATISFIABLE
|
|
252
|
+
file.cnf: (Brute Force) SATISFIABLE
|
|
253
|
+
file.cnf: (SatyPy) SATISFIABLE
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
By using these command-line options, you can customize the behavior of the `saty` command to suit your specific needs.
|
|
257
|
+
|
|
258
|
+
### Batch Execution
|
|
259
|
+
|
|
260
|
+
Batch execution allows you to solve multiple formulas within a directory simultaneously.
|
|
261
|
+
|
|
262
|
+
To view available command-line options for the `batch_saty` command, use the following in your terminal or command prompt:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
batch_saty -h
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
This will display the following help information:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
usage: batch_saty [-h] -i INPUTDIRECTORY [-a] [-b] [-c] [-m MAX_CLAUSES] [-v] [-t] [-l] [--version]
|
|
272
|
+
|
|
273
|
+
Solve the Boolean Satisfiability (SAT) problem using a directory with DIMACS files as input.
|
|
274
|
+
|
|
275
|
+
options:
|
|
276
|
+
-h, --help show this help message and exit
|
|
277
|
+
-i INPUTDIRECTORY, --inputDirectory INPUTDIRECTORY
|
|
278
|
+
Input directory path
|
|
279
|
+
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
|
|
280
|
+
-b, --bruteForce enable comparison with the exponential-time brute-force approach (at most 30 variables)
|
|
281
|
+
-c, --count only state whether each formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
|
|
282
|
+
-m MAX_CLAUSES, --max_clauses MAX_CLAUSES
|
|
283
|
+
largest 3-SAT formula sent to the Vertex Cover stage (default: 100)
|
|
284
|
+
-v, --verbose Enable verbose output
|
|
285
|
+
-t, --timer Enable timer output
|
|
286
|
+
-l, --log Enable file logging
|
|
287
|
+
--version show program's version number and exit
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
The options have the same meaning as for `saty` and apply to every file of the directory (processed in name order).
|
|
291
|
+
|
|
292
|
+
### Testing with Random Formulas
|
|
293
|
+
|
|
294
|
+
The `test_saty` command generates random CNF formulas and compares SatyPy against a brute-force search (`-b`) and
|
|
295
|
+
against MiniSat 2.2 through [python-sat](https://pypi.org/project/python-sat/) (`-a`):
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
test_saty -h
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
usage: test_saty [-h] -d DIMENSION [-m CLAUSES] [-k WIDTH] [-n NUM_TESTS] [-g] [-r SEED] [-a] [-b] [-c] [-w] [-M MAX_CLAUSES] [-v] [-l] [--version]
|
|
303
|
+
|
|
304
|
+
options:
|
|
305
|
+
-d DIMENSION, --dimension DIMENSION number of variables of each formula
|
|
306
|
+
-m CLAUSES, --clauses CLAUSES number of clauses (default: round(4.26 * dimension))
|
|
307
|
+
-k WIDTH, --width WIDTH literals per clause (default: 3)
|
|
308
|
+
-n NUM_TESTS, --num_tests NUM_TESTS number of tests to run
|
|
309
|
+
-g, --gaps use random non-contiguous variable IDs instead of 1..dimension
|
|
310
|
+
-r SEED, --seed SEED random seed
|
|
311
|
+
-a, --approximation enable comparison with a known SAT solver (MiniSat 2.2 via python-sat)
|
|
312
|
+
-b, --bruteForce enable comparison with the exponential-time brute-force approach
|
|
313
|
+
-c, --count only state whether each formula is SATISFIABLE, UNSATISFIABLE or UNKNOWN
|
|
314
|
+
-w, --write write each generated formula to a DIMACS file in the current directory
|
|
315
|
+
-M MAX_CLAUSES, --max_clauses MAX_CLAUSES
|
|
316
|
+
largest 3-SAT formula sent to the Vertex Cover stage (default: 100)
|
|
317
|
+
-v, --verbose enable verbose output
|
|
318
|
+
-l, --log enable file logging
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Example:
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
test_saty -d 6 -m 12 -n 8 -g -r 7 -a -b -c
|
|
325
|
+
1-MiniSat Test: SATISFIABLE
|
|
326
|
+
1-Brute Force Test: SATISFIABLE
|
|
327
|
+
1-SatyPy Test: UNKNOWN
|
|
328
|
+
...
|
|
329
|
+
Summary: 1 SATISFIABLE (verified), 0 UNSATISFIABLE, 7 UNKNOWN, 0 disagreements
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## How SatyPy Solves a Formula
|
|
333
|
+
|
|
334
|
+
Variable IDs may be any positive integers (not necessarily `1..n`, contiguous, or sorted).
|
|
335
|
+
|
|
336
|
+
1. **Simplification** (`reduction.reduce_sat_to_simplified_sat`): unit propagation and pure literals. A conflict proves the
|
|
337
|
+
formula unsatisfiable.
|
|
338
|
+
2. **2-SAT**: if every remaining clause has at most two literals, the formula is decided exactly by the
|
|
339
|
+
strongly-connected-components algorithm (`algorithm._solve_two_sat`).
|
|
340
|
+
3. **3-SAT → Vertex Cover**: otherwise `reduction.reduce_sat_to_3sat` converts the residual formula to exactly three
|
|
341
|
+
literals per clause, and `reduction.reduce_3sat_to_unweighted_vertex_cover` runs the chain
|
|
342
|
+
|
|
343
|
+
```
|
|
344
|
+
3SAT → weighted parity (exact 10-equation gadget) → translation Unique Game (matrix test, OpenAI 2026, §4)
|
|
345
|
+
→ unweighted simple bipartite game (rounding + subdivision, Lemma 7.1) → strong-left form (Khot–Regev)
|
|
346
|
+
→ p-biased Vertex Cover graph (Khot–Regev 2008) → unweighted graph (blow-up)
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
With `p = 1/3`, a satisfiable formula admits a cover of at most 2/3 of the vertices, so the relevant approximation
|
|
350
|
+
threshold is 1.5. The cover is computed by [Salvador](https://pypi.org/project/salvador/) 0.1.0
|
|
351
|
+
(`from salvador.algorithm import find_vertex_cover`), decoded back into a truth assignment
|
|
352
|
+
(`reduction.decode_vertex_cover_to_assignment`), and **verified** against the original formula.
|
|
353
|
+
|
|
354
|
+
SatyPy prints `s SATISFIABLE` only with a verified assignment and `s UNSATISFIABLE` only when steps 1–2 prove it. A
|
|
355
|
+
decoded assignment that fails verification gives `s UNKNOWN`: the Khot–Regev gap needs very large parameters (the
|
|
356
|
+
reference's repetition exponent alone is at least 10,240,000·log(1/δ)), and at the small parameters used here
|
|
357
|
+
the Unique Game takes the same value under every assignment, so the Vertex Cover does not determine satisfiability and
|
|
358
|
+
no unsatisfiability is ever inferred from it. Use `-l` to see each stage (instance sizes, cover fraction, ratio bound)
|
|
359
|
+
in `app.log`.
|
|
360
|
+
|
|
361
|
+
References: OpenAI Math Team, *The Unique Games Conjecture and Optimal Approximation Thresholds* (Result Family 102,
|
|
362
|
+
[openai/math](https://github.com/openai/math/blob/main/lean/docs/102.md), 2026); S. Khot and O. Regev, *Vertex cover
|
|
363
|
+
might be hard to approximate to within 2 − ε*, J. Comput. System Sci. 74 (2008) 335–349.
|
|
364
|
+
|
|
365
|
+
## Experiments
|
|
366
|
+
|
|
367
|
+
`experiments/run_benchmarks.py` runs SatyPy and a reference solver from python-sat on directories of DIMACS files and
|
|
368
|
+
writes one CSV row per instance (expected answer from AIM file names, reference answer and time, deciding stage, sizes of
|
|
369
|
+
the parity instance, Unique Game and Vertex Cover graph, Salvador's cover and time, peak memory):
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
python -m experiments.run_benchmarks -j 2 -s 300 -m 100 -o experiments/results.csv \
|
|
373
|
+
benchmarks/file-dimacs-aim benchmarks/sat23 benchmarks/sat24
|
|
374
|
+
python -m experiments.run_benchmarks -r cadical195 -s 3600 -o prp.csv <directory with PRP_40_40.cnf.xz>
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Results on the 72 AIM instances and the 12 SAT Competition 2023/2024 instances are in `experiments/results.csv` and
|
|
378
|
+
`experiments/results_pass2.csv`. SatyPy never answered incorrectly and answered `UNKNOWN` on all 84 instances. Every
|
|
379
|
+
Vertex Cover graph it built (147,312 to 311,112 vertices, up to 1.9 million edges) was covered optimally by Salvador with exactly 2/3 of the
|
|
380
|
+
vertices: at the default parameters the graph is a disjoint union of copies of one 18-vertex graph with minimum cover 12,
|
|
381
|
+
so it does not depend on whether the formula is satisfiable. MiniSat decided all AIM instances in at most 2 ms and 11
|
|
382
|
+
of the 12 competition instances within 300 s; CaDiCaL proved `PRP_40_40` satisfiable in 35 s.
|
|
383
|
+
|
|
384
|
+
## Implementation
|
|
385
|
+
|
|
386
|
+
- **Programming Language:** Python
|
|
387
|
+
- **Author:** Frank Vega
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
This code is released under the MIT License.
|