Repository navigation
Conversation
…e SAT solver and simplex The session of std::algo::smt now reads the Int sort, numerals of any size, `+`, `-`, `*` by a constant, `mod` and `div` by a constant, `ite` of Ints, and the comparisons `<=`, `<`, `>=`, `>`, `=` and `distinct`. The reader folds each term of constants, so the wrapping arithmetic of the prover becomes one constant when its argument is a constant. Each comparison becomes a fact `s <= b` over integer variables. The solver divides the fact by the GCD of its coefficients, and gives it a sign so that equal facts are one Boolean variable, an atom. `mod` and `div` add the variables `q` and `r` with four unit clauses, and an Int `ite` adds a variable with four clauses. The SAT solver sets the atoms, the simplex checks the bounds of the atoms, and each conflict of the simplex comes back as a lemma clause. `get-value` gives the value of each Int name, and `get-proof` gives each lemma with its certificate tree before the LRAT proof. The top of smt.vx lists the rules, so that the checker of #4390 can make the same clauses. tests/backend/pass/std_algo_smt_integers.vx checks one small query for each operator by hand. tests/integration_test/smt_integer_queries_agree_with_z3.rs runs the 45 queries of tests/solver/queries/: each answer is the answer of z3, and z3 accepts the values of each `sat`. docs/solver/integers.md describes the reader, the atoms, the loop and the proof. Fixes: #4389
`(* 0 x)` made the term `0*x` in its sum. A fact on that sum then divided its coefficients by their GCD, which was 0, and the solver stopped with "BigInt::div_rem: division by zero". A sum now drops each term whose coefficient is 0. The rules at the top of smt.vx say so, because the checker in vxc must make the same sums. std_algo_smt_integers.vx checks `0x + y = 7` and `0x >= 1`. Part of #4389.
This branch has not been deployed
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.
Step 7 of #4268, second task. Fixes #4389.
What changes
std::algo::smtnow reads theIntsort and numerals of any size. It also reads+,-,*by a constant,modanddivby a constant, anditeof Ints. The comparisons are<=,<,>=,>,=anddistinct, also with more than two arguments.set-logic QF_LIAworks. A product of two names andmodby a name are errors, because they areQF_NIA.(- (mod (+ x 2^63) 2^64) 2^63). Whenxis a constant, the whole term becomes one constant. Anitewhose condition folds totrueorfalseis its branch.s <= bover integer variables. The solver divides the fact by the GCD of its coefficients and roundsbdown. It gives the fact a sign, so that equal facts are one Boolean variable, an atom. So(= (* 2 x) 1)is the AND ofx <= 0and its negation, which is false with no search. Atoms with the same sum share one row of the simplex.modanddivadd the variablesqandrwith four unit clauses, and two of them with the sametandkshareqandr. An Intiteadds a variable with four clauses.s <= bfor a true atom ands >= b + 1for a false one, and searches with branch-and-bound and cuts. Each conflict of the simplex comes back as a lemma, the negation of the atoms in its certificate.:rlimitlimits the steps of the two together.get-valuegives an Int as5or(- 5).get-proofgives each lemma with its certificate tree, and then the LRAT proof. The lemmas are input clauses of the LRAT proof.smt.vxlists the rules of the translation, with the order of the numbers of the variables. hir: check the unsat answers of the integer solver in vxc, with the LRAT proof and a certificate for each clause from simplex #4390 can then make the same clauses in vxc.docs/solver/integers.mdis a new page with a compiled example, the rules, the loop step by step, and the proof format.Tests
tests/backend/pass/std_algo_smt_integers.vxhas one small query for each operator, each with one answer that is easy to find by hand. It also checks three proofs, the step limit, a constant above 2^128 in a scope, and the errors. It prints the same with--legacy-codegen.(* 0 x), made a term with the coefficient 0. The division by the GCD then divided by 0, and the solver stopped. The second commit drops such terms, and the test checks0x + y = 7and0x >= 1.tests/integration_test/smt_integer_queries_agree_with_z3.rsruns the 45 queries oftests/solver/queries/. Each answer must be the answer of z3. For eachsatanswer, z3 must accept the values ofget-value.std_algo_smt_scopes_and_errors.vxnow usesQF_NIAas its unsupported logic.I broke
smt.vx20 ways, one at a time, and ran the hand test after each break. Each break made a check fail:s >= b.r <= |k| - 1, and the wrong sign ofcin anite.<read as<=, and=without its negation.modanddivof constants folded toward zero, the wrong branch of a foldedite, and a folded<read as<=.r >= 0, and atoms ormodvariables that are not shared. The answers stay the same. The proof checks catch these, so the test covers the rules that hir: check the unsat answers of the integer solver in vxc, with the LRAT proof and a certificate for each clause from simplex #4390 needs.(- 7)written as(-7)changed the printed values. A missing step limit gaveunsatin place ofunknown. Lemmas with the wrong signs made the test run until the 300 s timeout.I also broke the code 4 ways for the test of the 45 queries. Values plus 1, a false atom read as
s >= b, and<read as<=each gave values that z3 did not accept. Asatof the simplex read asunsatfailed the check of the answer.The queries of the prover
I ran each of the 1,569
QF_LIAqueries of #4388 through the solver, in its own process, 8 at a time, with a time cap. Each query kept its(set-option :rlimit 1000000). The setup: an Apple M4 with 32 GB, macOS 27.0.1, z3 4.15.4, and this branch on main 4f861d5. A debug vxc compiled the runner withvxc -O2 --action emit-obj.satunsatunknown.satanswers.unsatfor each of the 12 queries that did not end. Each has the wrapping arithmetic of the prover, and the integer search of the simplex branches many times on theqof amod 2^64. I listed them in std::algo::sat: let simplex check the values during the search, and set the literals that follow from the bounds #4392, with the bounds from bounds that end the search at once. The cost of each drop (runtime: each drop outside another drop reads the clock, also when the drop cannot wait #4349) also makes each step of the simplex slow.prover.rscannot use this loop as it is for these queries. hir: prover.rs sends its integer queries to the Vx solver when VX_SOLVER=vx #4391 needs the step limit and std::algo::sat: let simplex check the values during the search, and set the literals that follow from the bounds #4392 first.Found on the way
let found = match m.get(&key) { Some(v) => { *v } ... }fails with--legacy-codegen. I added this case to the issue.smt.vxgives theselets the typei32.Vecreads the clock and changes thread-local lists. ForBigIntandRationalarithmetic, this takes about 90% of the time. I added the profile to the issue.Not in this PR
i128fractions, and the queries have constants as large as 2^128, so it needs big numbers too.prover.rswithVX_SOLVER=vxis hir: prover.rs sends its integer queries to the Vx solver when VX_SOLVER=vx #4391.