cdclkit 0.1.0__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.
Files changed (38) hide show
  1. cdclkit-0.1.0/LICENSE +202 -0
  2. cdclkit-0.1.0/PKG-INFO +136 -0
  3. cdclkit-0.1.0/README.md +109 -0
  4. cdclkit-0.1.0/cdclkit/__init__.py +152 -0
  5. cdclkit-0.1.0/cdclkit/__main__.py +10 -0
  6. cdclkit-0.1.0/cdclkit/brute.py +210 -0
  7. cdclkit-0.1.0/cdclkit/cli.py +513 -0
  8. cdclkit-0.1.0/cdclkit/encodings.py +842 -0
  9. cdclkit-0.1.0/cdclkit/heap.py +180 -0
  10. cdclkit-0.1.0/cdclkit/model.py +420 -0
  11. cdclkit-0.1.0/cdclkit/mus.py +159 -0
  12. cdclkit-0.1.0/cdclkit/native.py +111 -0
  13. cdclkit-0.1.0/cdclkit/pipeline.py +212 -0
  14. cdclkit-0.1.0/cdclkit/portfolio.py +683 -0
  15. cdclkit-0.1.0/cdclkit/preprocess.py +500 -0
  16. cdclkit-0.1.0/cdclkit/pyeq.py +824 -0
  17. cdclkit-0.1.0/cdclkit/solver.py +1377 -0
  18. cdclkit-0.1.0/cdclkit.egg-info/PKG-INFO +136 -0
  19. cdclkit-0.1.0/cdclkit.egg-info/SOURCES.txt +36 -0
  20. cdclkit-0.1.0/cdclkit.egg-info/dependency_links.txt +1 -0
  21. cdclkit-0.1.0/cdclkit.egg-info/entry_points.txt +2 -0
  22. cdclkit-0.1.0/cdclkit.egg-info/requires.txt +1 -0
  23. cdclkit-0.1.0/cdclkit.egg-info/top_level.txt +1 -0
  24. cdclkit-0.1.0/pyproject.toml +43 -0
  25. cdclkit-0.1.0/setup.cfg +4 -0
  26. cdclkit-0.1.0/tests/test_core.py +237 -0
  27. cdclkit-0.1.0/tests/test_encodings.py +617 -0
  28. cdclkit-0.1.0/tests/test_integration.py +370 -0
  29. cdclkit-0.1.0/tests/test_mus.py +147 -0
  30. cdclkit-0.1.0/tests/test_native.py +206 -0
  31. cdclkit-0.1.0/tests/test_native_solver.py +353 -0
  32. cdclkit-0.1.0/tests/test_packaging.py +226 -0
  33. cdclkit-0.1.0/tests/test_pipeline.py +186 -0
  34. cdclkit-0.1.0/tests/test_portfolio.py +336 -0
  35. cdclkit-0.1.0/tests/test_preprocess.py +173 -0
  36. cdclkit-0.1.0/tests/test_proof.py +426 -0
  37. cdclkit-0.1.0/tests/test_pyeq.py +666 -0
  38. cdclkit-0.1.0/tests/test_solver.py +344 -0
cdclkit-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
cdclkit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: cdclkit
3
+ Version: 0.1.0
4
+ Summary: A CDCL SAT solver, preprocessor, encoding library and modelling layer, written from scratch in readable Python. Every answer comes with a certificate.
5
+ Author: Carlo Perassi
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/carlok/cdclkit
8
+ Project-URL: Source, https://github.com/carlok/cdclkit
9
+ Project-URL: Proof checker, https://github.com/carlok/dratify
10
+ Keywords: sat,solver,cdcl,dpll,drat,constraint,smt
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Rust
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: dratify>=0.1.1
26
+ Dynamic: license-file
27
+
28
+ # cdclkit
29
+
30
+ **A conflict-driven clause-learning SAT solver, a preprocessor, an encoding
31
+ library and a modelling layer — written from scratch in readable Python.**
32
+
33
+ Every answer comes with a certificate, and the certificate gets checked.
34
+
35
+ ```bash
36
+ pip install cdclkit
37
+ ```
38
+
39
+ ```bash
40
+ python3 -m cdclkit solve instance.cnf --self-check --check-model
41
+ ```
42
+
43
+ - **SAT** → the model is re-evaluated against the input formula, clause by clause.
44
+ - **UNSAT** → the solver emits a DRAT proof and [`dratify`](https://github.com/carlok/dratify)
45
+ replays it, confirming every derived clause really follows and the empty
46
+ clause is reached.
47
+
48
+ A solver that says "unsatisfiable" and offers nothing else is asking to be
49
+ trusted. This one hands you the proof — and the checker that reads it shares no
50
+ code with the solver that wrote it.
51
+
52
+ ## Quick start
53
+
54
+ ```python
55
+ from cdclkit import parse_dimacs, solve
56
+
57
+ formula = parse_dimacs("p cnf 2 4\n1 2 0\n1 -2 0\n-1 2 0\n-1 -2 0\n")
58
+ sat, model = solve(formula)
59
+ print(sat) # False -- and `solve` returns (False, None)
60
+ ```
61
+
62
+ Note the shape: `solve()` returns a **tuple**, so `if solve(f):` is always
63
+ true. Unpack it.
64
+
65
+ Worked examples live in `examples/` — Sudoku with a uniqueness proof, the zebra
66
+ puzzle, graph colouring, bounded model checking, circuit equivalence.
67
+
68
+ ## What's in it
69
+
70
+ | module | what it does |
71
+ |---|---|
72
+ | `solver` | CDCL: two watched literals, first-UIP learning, LBD, Luby restarts, phase saving, target phases, probSAT rephasing |
73
+ | `preprocess` | subsumption, self-subsumption, blocked-clause elimination, pure literals, bounded variable elimination with model reconstruction |
74
+ | `encodings` | at-most-one (pairwise, binary, commander), cardinality (sequential, totalizer), pseudo-Boolean |
75
+ | `model` | a modelling layer — integer variables, all-different, differential encoding |
76
+ | `mus` | minimal unsatisfiable subsets, deletion-based and QuickXplain |
77
+ | `portfolio` | parallel configurations |
78
+ | `pyeq` | **experimental** — bounded equivalence of two Python integer functions |
79
+
80
+ An optional Rust engine (built from source with `make native` -- it is not
81
+ on PyPI yet) is roughly 18x faster
82
+ and **bit-exact** with the Python one: identical conflicts, decisions and
83
+ propagations on every instance. The pure-Python path has zero third-party
84
+ dependencies and is the one that must never break.
85
+
86
+ ## Relationship to dratify
87
+
88
+ Proof checking lives in a separate package, [`dratify`](https://github.com/carlok/dratify),
89
+ which `cdclkit` depends on. That split is deliberate:
90
+
91
+ - You should not have to install a SAT solver to verify a proof someone else
92
+ produced.
93
+ - The checker stays small enough to audit, which is the point of a checker.
94
+ - `cdclkit` exercises it on every test run, so the checker is dogfooded by the
95
+ solver rather than only by its own suite.
96
+
97
+ `dratify` has no dependencies of its own, so installing `cdclkit` pulls in no
98
+ third-party code.
99
+
100
+ ## Performance
101
+
102
+ See [BENCHMARKS.md](BENCHMARKS.md). Read the caveats there before quoting any
103
+ number — in particular, all figures come from a single machine, and the
104
+ comparison against `kissat` is against its default configuration on a public
105
+ benchmark suite whose instances are small enough that process startup is part
106
+ of what is being measured.
107
+
108
+ If you need raw speed, install [PySAT](https://pypi.org/project/python-sat/):
109
+ it ships kissat, CaDiCaL and Glucose as binary wheels on every platform. This
110
+ project is not trying to beat them. It is trying to be a complete, readable,
111
+ self-checking implementation you can audit.
112
+
113
+ ## Honest limitations
114
+
115
+ - **No Windows.** Never tested; the classifiers say so rather than implying support.
116
+ - Pure Python is ~18x slower than its own Rust port, which is itself far from
117
+ kissat. Not a tool for competition-scale instances.
118
+ - No inprocessing, no XOR/Gaussian reasoning. Parity families are a known
119
+ weakness and `bench/` includes one to keep that visible.
120
+ - `pyeq` models a small subset of Python and is **experimental**. Measured
121
+ against CrossHair on a 48-function corpus it found nothing CrossHair missed
122
+ (0 of 105). See `experiments/pyeq-llm-refactor/report.md` for the full
123
+ negative result.
124
+ - Every performance figure comes from one machine.
125
+
126
+ ## Documentation
127
+
128
+ - [docs/ALGORITHMS.md](docs/ALGORITHMS.md) — the mathematics, from resolution
129
+ through first-UIP, LBD, DRAT, encodings and preprocessing, including a
130
+ section on what is deliberately absent.
131
+ - [docs/ROADMAP.md](docs/ROADMAP.md) — what is planned, in sprints.
132
+ - [docs/RELEASING.md](docs/RELEASING.md) — the release checklist.
133
+
134
+ ## Licence
135
+
136
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,109 @@
1
+ # cdclkit
2
+
3
+ **A conflict-driven clause-learning SAT solver, a preprocessor, an encoding
4
+ library and a modelling layer — written from scratch in readable Python.**
5
+
6
+ Every answer comes with a certificate, and the certificate gets checked.
7
+
8
+ ```bash
9
+ pip install cdclkit
10
+ ```
11
+
12
+ ```bash
13
+ python3 -m cdclkit solve instance.cnf --self-check --check-model
14
+ ```
15
+
16
+ - **SAT** → the model is re-evaluated against the input formula, clause by clause.
17
+ - **UNSAT** → the solver emits a DRAT proof and [`dratify`](https://github.com/carlok/dratify)
18
+ replays it, confirming every derived clause really follows and the empty
19
+ clause is reached.
20
+
21
+ A solver that says "unsatisfiable" and offers nothing else is asking to be
22
+ trusted. This one hands you the proof — and the checker that reads it shares no
23
+ code with the solver that wrote it.
24
+
25
+ ## Quick start
26
+
27
+ ```python
28
+ from cdclkit import parse_dimacs, solve
29
+
30
+ formula = parse_dimacs("p cnf 2 4\n1 2 0\n1 -2 0\n-1 2 0\n-1 -2 0\n")
31
+ sat, model = solve(formula)
32
+ print(sat) # False -- and `solve` returns (False, None)
33
+ ```
34
+
35
+ Note the shape: `solve()` returns a **tuple**, so `if solve(f):` is always
36
+ true. Unpack it.
37
+
38
+ Worked examples live in `examples/` — Sudoku with a uniqueness proof, the zebra
39
+ puzzle, graph colouring, bounded model checking, circuit equivalence.
40
+
41
+ ## What's in it
42
+
43
+ | module | what it does |
44
+ |---|---|
45
+ | `solver` | CDCL: two watched literals, first-UIP learning, LBD, Luby restarts, phase saving, target phases, probSAT rephasing |
46
+ | `preprocess` | subsumption, self-subsumption, blocked-clause elimination, pure literals, bounded variable elimination with model reconstruction |
47
+ | `encodings` | at-most-one (pairwise, binary, commander), cardinality (sequential, totalizer), pseudo-Boolean |
48
+ | `model` | a modelling layer — integer variables, all-different, differential encoding |
49
+ | `mus` | minimal unsatisfiable subsets, deletion-based and QuickXplain |
50
+ | `portfolio` | parallel configurations |
51
+ | `pyeq` | **experimental** — bounded equivalence of two Python integer functions |
52
+
53
+ An optional Rust engine (built from source with `make native` -- it is not
54
+ on PyPI yet) is roughly 18x faster
55
+ and **bit-exact** with the Python one: identical conflicts, decisions and
56
+ propagations on every instance. The pure-Python path has zero third-party
57
+ dependencies and is the one that must never break.
58
+
59
+ ## Relationship to dratify
60
+
61
+ Proof checking lives in a separate package, [`dratify`](https://github.com/carlok/dratify),
62
+ which `cdclkit` depends on. That split is deliberate:
63
+
64
+ - You should not have to install a SAT solver to verify a proof someone else
65
+ produced.
66
+ - The checker stays small enough to audit, which is the point of a checker.
67
+ - `cdclkit` exercises it on every test run, so the checker is dogfooded by the
68
+ solver rather than only by its own suite.
69
+
70
+ `dratify` has no dependencies of its own, so installing `cdclkit` pulls in no
71
+ third-party code.
72
+
73
+ ## Performance
74
+
75
+ See [BENCHMARKS.md](BENCHMARKS.md). Read the caveats there before quoting any
76
+ number — in particular, all figures come from a single machine, and the
77
+ comparison against `kissat` is against its default configuration on a public
78
+ benchmark suite whose instances are small enough that process startup is part
79
+ of what is being measured.
80
+
81
+ If you need raw speed, install [PySAT](https://pypi.org/project/python-sat/):
82
+ it ships kissat, CaDiCaL and Glucose as binary wheels on every platform. This
83
+ project is not trying to beat them. It is trying to be a complete, readable,
84
+ self-checking implementation you can audit.
85
+
86
+ ## Honest limitations
87
+
88
+ - **No Windows.** Never tested; the classifiers say so rather than implying support.
89
+ - Pure Python is ~18x slower than its own Rust port, which is itself far from
90
+ kissat. Not a tool for competition-scale instances.
91
+ - No inprocessing, no XOR/Gaussian reasoning. Parity families are a known
92
+ weakness and `bench/` includes one to keep that visible.
93
+ - `pyeq` models a small subset of Python and is **experimental**. Measured
94
+ against CrossHair on a 48-function corpus it found nothing CrossHair missed
95
+ (0 of 105). See `experiments/pyeq-llm-refactor/report.md` for the full
96
+ negative result.
97
+ - Every performance figure comes from one machine.
98
+
99
+ ## Documentation
100
+
101
+ - [docs/ALGORITHMS.md](docs/ALGORITHMS.md) — the mathematics, from resolution
102
+ through first-UIP, LBD, DRAT, encodings and preprocessing, including a
103
+ section on what is deliberately absent.
104
+ - [docs/ROADMAP.md](docs/ROADMAP.md) — what is planned, in sprints.
105
+ - [docs/RELEASING.md](docs/RELEASING.md) — the release checklist.
106
+
107
+ ## Licence
108
+
109
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,152 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2026 Carlo Perassi. Licensed under the Apache License 2.0.
3
+ """cdclkit -- a CDCL SAT solving toolkit with checkable proofs, in pure Python.
4
+
5
+ Everything here is written from scratch against the standard library only.
6
+ The public surface:
7
+
8
+ from cdclkit import Solver, CNF, Encoder, solve
9
+
10
+ f = CNF()
11
+ a, b, c = f.new_var(), f.new_var(), f.new_var()
12
+ f.add([lit(a), lit(b)]) # a v b
13
+ f.add([lit(a, True), lit(c)]) # ~a v c
14
+ status, model = solve(f)
15
+
16
+ Modules:
17
+
18
+ ``lits`` literal encoding and three-valued logic
19
+ ``cnf`` clause/formula containers and DIMACS I/O
20
+ ``heap`` indexed activity heap for VSIDS
21
+ ``solver`` the CDCL core
22
+ ``proof`` DRAT emission and an independent DRAT checker
23
+ ``preprocess`` subsumption, strengthening, variable elimination
24
+ ``mus`` minimal unsatisfiable subsets (deletion, QuickXplain)
25
+ ``encodings`` Tseitin, cardinality, pseudo-boolean, totalizer, optimisation
26
+ ``model`` a small typed modelling layer over the encoder
27
+ ``pyeq`` prove two Python functions equivalent, or find an input where
28
+ they are not
29
+ ``brute`` reference solvers used to cross-check everything else
30
+ ``cli`` the ``python -m cdclkit`` command line
31
+
32
+ Public API
33
+ ----------
34
+ Everything in ``__all__`` below is public and follows semantic versioning: it
35
+ will not change incompatibly without a major version bump, and anything due to
36
+ be removed gets a ``DeprecationWarning`` for one minor release first.
37
+
38
+ Everything else is internal, including ``cdclkit.pipeline``, ``cdclkit.portfolio``
39
+ and ``cdclkit.native``. They are importable because Python has no way to stop
40
+ you, not because they are stable. If you need something from them, say so and
41
+ it can be promoted -- that is a smaller problem than finding out from a broken
42
+ build that someone depended on it.
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ from dratify.cnf import CNF, Clause, parse_dimacs, parse_dimacs_file, write_dimacs
48
+ from .encodings import Encoder, Totalizer, optimise
49
+ from dratify.lits import from_dimacs, mk_lit, neg, to_dimacs
50
+ from .mus import MUSExtractor, mus
51
+ from .preprocess import Preprocessor, preprocess
52
+ from dratify.proof import DRATChecker, MemoryProof, ProofWriter, check_proof
53
+ from .solver import Config, SAT, Solver, Stats, UNKNOWN, UNSAT
54
+
55
+ __version__ = "0.1.0"
56
+
57
+ __all__ = [
58
+ "CNF",
59
+ "Clause",
60
+ "Config",
61
+ "DRATChecker",
62
+ "Encoder",
63
+ "EncodingDisagreement",
64
+ "EquivalenceResult",
65
+ "MUSExtractor",
66
+ "MemoryProof",
67
+ "Preprocessor",
68
+ "ProofRejected",
69
+ "ProofWriter",
70
+ "SAT",
71
+ "UNKNOWN",
72
+ "UNSAT",
73
+ "Solver",
74
+ "Stats",
75
+ "Totalizer",
76
+ "UnsupportedConstruct",
77
+ "check_proof",
78
+ "differential_solve",
79
+ "equivalent",
80
+ "from_dimacs",
81
+ "lit",
82
+ "mk_lit",
83
+ "mus",
84
+ "neg",
85
+ "optimise",
86
+ "parse_dimacs",
87
+ "parse_dimacs_file",
88
+ "preprocess",
89
+ "solve",
90
+ "to_dimacs",
91
+ "write_dimacs",
92
+ "__version__",
93
+ ]
94
+
95
+
96
+ #: Public names that live in `cdclkit.pyeq`, resolved on first access rather than
97
+ #: at import. `pyeq` needs `inspect` to read a function's source, and `inspect`
98
+ #: drags in `re` and `functools`: importing it eagerly was 5.5 ms of an 8.8 ms
99
+ #: `import cdclkit`, paid by everyone including the CLI solving a DIMACS file.
100
+ #: Startup is not a rounding error here -- the benchmark harness discards
101
+ #: instances a competitor finishes in under 50 ms because process startup
102
+ #: dominates them.
103
+ _LAZY = {
104
+ "equivalent": "pyeq",
105
+ "EquivalenceResult": "pyeq",
106
+ "differential_solve": "model",
107
+ "EncodingDisagreement": "model",
108
+ "UnsupportedConstruct": "pyeq",
109
+ "ProofRejected": "pyeq",
110
+ }
111
+
112
+
113
+ # Imported eagerly, not lazily: importing it is what registers the native
114
+ # checker with `dratify`, and a checker that is present but unregistered would
115
+ # silently cost ~18x on proof checking. The import is a single guarded attempt
116
+ # at a compiled module and costs nothing when it is absent.
117
+ from . import native as _native_loader # noqa: F401,E402
118
+
119
+
120
+ def __getattr__(name: str):
121
+ """PEP 562 lazy attribute access for the heavier public names."""
122
+ mod = _LAZY.get(name)
123
+ if mod is None:
124
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
125
+ import importlib
126
+
127
+ value = getattr(importlib.import_module(f".{mod}", __name__), name)
128
+ globals()[name] = value # resolve once; subsequent lookups skip __getattr__
129
+ return value
130
+
131
+
132
+ def __dir__() -> list[str]:
133
+ return sorted(__all__)
134
+
135
+
136
+ def lit(var: int, negated: bool = False) -> int:
137
+ """Alias for :func:`cdclkit.lits.mk_lit`, the common spelling in user code."""
138
+ return mk_lit(var, negated)
139
+
140
+
141
+ def solve(formula: CNF, proof=None, config: Config | None = None):
142
+ """Solve a formula in one call.
143
+
144
+ Returns ``(True, model)`` or ``(False, None)``. ``model`` is a list of
145
+ booleans indexed by variable.
146
+ """
147
+ s = Solver(formula.nvars, proof=proof, config=config)
148
+ if not s.add_cnf(formula):
149
+ return False, None
150
+ if s.solve():
151
+ return True, s.model
152
+ return False, None
@@ -0,0 +1,10 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2026 Carlo Perassi. Licensed under the Apache License 2.0.
3
+ """Entry point for ``python -m cdclkit``."""
4
+
5
+ import sys
6
+
7
+ from .cli import main
8
+
9
+ if __name__ == "__main__":
10
+ sys.exit(main())