Repository navigation
Add samples ported from SAT/SMT by Example - #120
Open
HowardvanRooijen wants to merge 10 commits into
Open
HowardvanRooijen wants to merge 10 commits into
HowardvanRooijen wants to merge 10 commits into
Conversation
Proves XOR and add/subtract swap, Dietz's average, branchless abs and min/max, the has-a-zero-byte test and the multiplicative inverse of 3 modulo 2^32 by asking Z3 for a counterexample. Shows counterexamples for the naive average and the misprinted zero-byte test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports sections 8.10, 8.2.1 and 8.4 of Dennis Yurichev's book as Examples models, MSTest suites and single-file Spectre.Console demos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Map colouring of Europe (4 colours; 3 unsatisfiable; fewest/most of one colour 3/22) and committee scheduling (3 hours) share one GraphColouring model. Job-shop scheduling finds the 11-unit optimum for the book's three-job instance and proves 10 unsatisfiable. Each has a Spectre.Console demo and MSTest acceptance tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom SAT/SMT by Example Four single-file demos (sections 14.5, 3.3, 10.1 + 3.2, 22.5.1), a reusable PackageManager model in Z3.Linq.Examples, and tests that pin each unique optimum and prove it unique. The package manager uses version 0 for "not installed" and minimises an explicit install cost, instead of the book's 999 sentinel and maximised version sum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a uint bit-vector Sudoku grid (SudokuGrid / SudokuGridTheorem) with WithClues, WithCages, WithGreaterThan and Excluding, the puzzle data from sections 8.1.4 and 8.1.3, a demo, and tests. Killer is pinned and proved unique; the Greater-Than signs admit several grids, so it is tested by invariants only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the eleven new demos to the interactive launcher (and raise its page size so they all show), the demos README table and run list, and a section in the root README with a bit-twiddling proof example. Widen the Examples package description and tags to cover the new samples. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unconstrained objective variables cause empty graphs and empty job workloads to return int.MinValue instead of 0, requiring unconditional nonnegative bounds on Colours and Makespan.
2 open issues
What changed in this PR
Adds 11 demos adapted from SAT/SMT by Example, expanding the examples and tests without changing the core Z3.Linq library.
Changes:
- Adds puzzle, optimisation, scheduling, dependency-resolution and bit-vector proof examples.
- Adds tests for solutions, invariants, optimality, uniqueness and unsatisfiable cases.
- Updates the interactive launcher, documentation and example-package metadata.
| File | Description |
|---|---|
solutions/Z3.Linq.Tests/ZebraPuzzleTests.cs |
Checks house assignments and uniqueness. |
solutions/Z3.Linq.Tests/WoodWorkshopTests.cs |
Verifies the unique optimal cutting plan. |
solutions/Z3.Linq.Tests/SudokuGridTheoremTests.cs |
Tests Sudoku variants, clues and uniqueness. |
solutions/Z3.Linq.Tests/PackageManagerTests.cs |
Checks optimal installation plans and conflicts. |
solutions/Z3.Linq.Tests/NQueensTests.cs |
Tests valid placements and impossible sizes. |
solutions/Z3.Linq.Tests/KnapsackTests.cs |
Verifies optimal purchases and enumerated orders. |
solutions/Z3.Linq.Tests/JobShopTests.cs |
Checks scheduling rules and minimum makespan. |
solutions/Z3.Linq.Tests/GraphColouringTests.cs |
Tests colour counts and graph constraints. |
solutions/Z3.Linq.Tests/BitTwiddlingTheoremsTests.cs |
Checks proofs, counterexamples and modular inverses. |
solutions/Z3.Linq.Tests/AssignmentProblemTests.cs |
Verifies assignment optimality independently. |
solutions/Z3.Linq.Tests/AlphameticsTests.cs |
Tests SEND + MORE = MONEY and uniqueness. |
solutions/Z3.Linq.Examples/Z3.Linq.Examples.csproj |
Updates package description and tags. |
solutions/Z3.Linq.Examples/Sudoku/SudokuGridTheorem.cs |
Adds Sudoku constraints and solution exclusion. |
solutions/Z3.Linq.Examples/Sudoku/SudokuGrid.cs |
Adds an unsigned bit-vector Sudoku grid. |
solutions/Z3.Linq.Examples/Sudoku/KillerSudokuPuzzles.cs |
Supplies Killer Sudoku cage data. |
solutions/Z3.Linq.Examples/Sudoku/GreaterThanSudokuPuzzles.cs |
Supplies inequalities and the book’s answer. |
solutions/Z3.Linq.Examples/Scheduling/JobShop.cs |
Models task precedence and machine constraints. |
solutions/Z3.Linq.Examples/Puzzles/ZebraPuzzle.cs |
Models the Zebra puzzle with nested properties. |
solutions/Z3.Linq.Examples/Puzzles/NQueens.cs |
Models variable-size queen placements. |
solutions/Z3.Linq.Examples/Puzzles/Alphametics.cs |
Models the alphametic and digit conversion. |
solutions/Z3.Linq.Examples/Packaging/PackageManager.cs |
Models dependencies and installation cost. |
solutions/Z3.Linq.Examples/GraphColouring/GraphColouring.cs |
Adds reusable graph-colouring constraints. |
solutions/Z3.Linq.Examples/GraphColouring/Europe.cs |
Supplies country and border data. |
solutions/Z3.Linq.Examples/GraphColouring/Committees.cs |
Converts shared membership into scheduling conflicts. |
solutions/Z3.Linq.Examples/BitTwiddling/BitTwiddlingTheorems.cs |
Adds counterexample searches and inverse models. |
README.md |
Introduces the ports and XOR-swap proof. |
demos/zebra.cs |
Displays solved houses and puzzle answers. |
demos/wood-workshop.cs |
Displays the optimal cutting plan. |
demos/sudoku-variants.cs |
Displays cages, inequalities and solved grids. |
demos/README.md |
Lists new demos and run commands. |
demos/package-manager.cs |
Displays installation plans and conflicts. |
demos/n-queens.cs |
Displays placements and unsatisfiable boards. |
demos/menu.cs |
Registers demos and enlarges the menu page. |
demos/map-colouring.cs |
Demonstrates map colouring and committee scheduling. |
demos/knapsack.cs |
Optimises purchases and enumerates exact-cost orders. |
demos/job-shop.cs |
Displays a Gantt chart and optimality check. |
demos/bit-twiddling.cs |
Displays proof verdicts and modular inverses. |
demos/assignment.cs |
Displays the least-cost worker assignment. |
demos/alphametics.cs |
Displays the solution and uniqueness check. |
Review effort: Balanced
An empty graph, or a job shop with no tasks, left the objective symbol with no constraint at all, so minimising it returned the library's implicit int.MinValue instead of 0. Constrain both to be non-negative up front and cover the empty cases with tests. Addresses the Copilot review comments on #120. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Bit twiddling: the zero-byte variant without ~v is no longer called the book's misprint (the book's SMT-LIB model uses bvnot; the tilde is lost from its code font in text extraction), and the text now says it fails both ways. Modular inverses are described as exact division and divisibility tests, not general division by a constant. - Package manager: say that the book's 999 encoding gives the same plans for this catalogue, and rename a test that exercises Resolve. - N queens: enumerate every 4 x 4 placement, so a model that is too strict would fail; bring the demo header up to date. - Soften test timing remarks to what a run actually shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Say int cells took about a minute (Greater-Than) or several (Killer), not minutes for both, and drop the Z3-version-specific "27 cells". - Pin the Greater-Than data at 48 distinct signs and the Killer data at 25 cages over 77 cells summing to 384, so a dropped clue fails a test. - Spot-check the Europe borders, including the four mutual neighbours that make three colours impossible. - Reflow the committee panel to fit 80 columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The book is CC BY-SA 4.0. The samples reuse only the problems' data, so say "based on a problem in" rather than "adapted from" or "ported from", and note the book's licence and what was reused in both READMEs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code Coverage Summary Report - Linux (No TFM)Summary
CoverageZ3.Linq - 93.8%
Z3.Linq.Examples - 91.3%
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds 11 new demos, with models in
Z3.Linq.Examplesand tests inZ3.Linq.Tests. Each one is based on a problem from Dennis Yurichev's book SAT/SMT by Example. The library itself is unchanged: every sample uses features Z3.Linq already supports.Samples
bit-twiddling.csuint/ulongbit-vectors: XOR swap, Dietz's average, branchless abs/min/max, the has-a-zero-byte hack, modular inverse. WhenTrySolvefinds no counterexample, that is the proof.alphametics.csZ3Methods.Distinctzebra.csn-queens.csassignment.cswood-workshop.csknapsack.cspackage-manager.csmap-colouring.csjob-shop.cssudoku-variants.csThe menu,
demos/README.mdand the root README list the new demos. The root README also has a short XOR-swap proof example.Notes for review
uint[81]grid,SudokuGrid. Z3 bit-blasts bit-vectors, so these puzzles solve in about 1 s, where anintgrid took minutes. The existingSudokuTableandSudokuTheoremare unchanged. Cells are read throughCell(row, col)rather than an indexer, because Z3.Linq writes every public property back through a setter and an indexer has no setter.Testing
dotnet build solutions/Z3.Linq.slnx: 0 warnings, 0 errorsdotnet test: 457 of 457 passed (368 existing and 89 new)dotnet runand no input. All exited 0, printed no warnings and showed the expected answers.demos/menu.cs, which is interactive and needs a real terminal.🤖 Generated with Claude Code