Z3 API in Python: From Sudoku to N-Queens in Under 20 Lines (2015)
Mood
supportive
Sentiment
positive
Category
tech
Key topics
Z3 API
SMT Solvers
Constraint Programming
Python
The post showcases the Z3 API in Python for solving constraint satisfaction problems like Sudoku and N-Queens, sparking discussion on its applications and related projects.
Snapshot generated from the HN discussion
Discussion Activity
Moderate engagementFirst comment
12h
Peak period
9
Day 1
Avg / period
5
Based on 10 loaded comments
Key moments
- 01Story posted
11/16/2025, 6:38:37 PM
3d ago
Step 01 - 02First comment
11/17/2025, 6:49:01 AM
12h after posting
Step 02 - 03Peak activity
9 comments in Day 1
Hottest window of the conversation
Step 03 - 04Latest activity
11/17/2025, 9:21:59 PM
1d ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
Page 19 in https://smt.st/SAT_SMT_by_example.pdf shows an example in both Python and SMTLIB. After looking at a guide like TFA this book is a good next step.
The algorithms differ mainly in how they keep track of all possibilities and how they update them
I think this answer is pretty good https://cstheory.stackexchange.com/a/29428 (take note at the end "sat is csp on boolean domains")
I always use that instead of the z3-solver directly.
It offers basically the same API and could be faster in many cases
Satisfiability: In 1971, Stephen A. Cook established that Boolean satisfiability, given an arbitrary Boolean formula whether an assignment to its variables exists that evaluates true, is NP-complete.
https://dl.acm.org/doi/10.1145/800157.805047
Translating between NP-complete problems is at most a polynomial (“fast”) amount of work, so every improvement gained on satisfiability (whose worst case is exponential rather than polynomial time complexity) benefits all other NP-complete problems, and thus the rest of NP.
Modulo Theories: We can think of SMT as a high-level language that automates encoding of other problems into raw Boolean formulas. Applications built on Z3 outsource search by encoding problems via one or more theories and then decoding results back to the problem domain at hand.
The benefits of doing this are (1) using an existing robust, well-tested suite of algorithms where (2) lots of research effort is concentrated and (3) improvements to Z3 improve your problem’s results more-or-less for free. According to Microsoft, “Z3 is used in a wide range of software engineering applications, ranging from program verification, compiler validation, testing, fuzzing using dynamic symbolic execution, model-based software development, network verification, and optimization.”
https://www.microsoft.com/en-us/research/project/z3-3/
See also:
4 more comments available on Hacker News
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.