Skip to content

hir: check the unsat answers of std::algo::smt for integer queries - #4438

Open
hiraditya wants to merge 1 commit into
smt-integer-queriesfrom
smt-integer-proof-check
Open

hiraditya wants to merge 1 commit into
smt-integer-queriesfrom
smt-integer-proof-check

Conversation

@hiraditya

Copy link
Copy Markdown
Collaborator

Step 7 of #4268, third task. Fixes #4390.

This PR needs #4417, which makes the proofs that it checks. It is a GitHub stacked PR on #4417.

What changes

  • src/hir/bv_check.rs is now src/hir/smt_check.rs, because it reads integer queries too. seam.rs and the tests use the new name.
  • The reader reads the Int sort, numerals of any size, +, -, *, mod, div, Int ite and the comparisons. It folds constants as the solver does, so the two see the same terms.
  • The translation makes the clauses of the assertions by the rules at the top of smt.vx. The sums, atoms, rows of the simplex and clauses are the same as in the solver, with the same numbers.
  • The lemmas. get-proof gives the lemmas before the LRAT steps. For each lemma, the checker does these steps:
    1. It checks that the id of the lemma is the next clause.
    2. It writes the literal of each leaf as the bound of its atom. A positive literal is terms <= b, and a negative one is terms >= b + 1.
    3. It checks that the lemma has the negation of each of these literals.
    4. It writes each row in a split as its sum over integer variables. Each (w split n) is the bound of split n on the path to the leaf.
    5. src/hir/farkas.rs checks the tree.
  • Then src/hir/lrat.rs checks the LRAT steps. The lemmas are input clauses, after the clauses of the assertions.
  • Big numbers. farkas.rs now uses exact fractions of big integers, from the crates num-bigint and num-rational. The two TooLarge errors are gone.
  • docs/solver/integers.md says how vxc checks a proof. simplex.md and the README no longer say that the checker uses i128.

The checker does not compute Int values yet, so it does not check the sat answers of integer queries. #4391 adds this when it sends the queries of prover.rs to the solver.

Numbers that do not fit an i128

The issue asked for this count. I took the 585 unsat answers to the QF_LIA queries of #4388, with :produce-proofs on. These are the 584 answers within 10 s of #4417, and one that took 21 s.

A number of 2^127 or more Answers
In the query 4
In a weight or a bound of the proof 19
In either 23

The largest number in a proof has 1,102 bits. So 23 of the 585 answers (4%) cannot pass a checker with i128 numbers. Products inside the check make this count higher. 200 queries have a constant of 2^63 or more, and 81 proofs have a number of 2^63 or more.

Tests

  • The unit tests of smt_check.rs:
    • The clauses of four small queries, found by hand with the rules. They cover these rules:
      • =, mod and ite.
      • The division by the GCD, and the change of sign.
      • The order of the condition and the branches of an ite.
    • Two of these queries also check the variables of the simplex.
    • Constants fold as the solver folds them.
    • Two proofs from the solver pass. One has a Gomory cut on a row and an integer split, and the other has two lemmas.
    • A changed proof fails, once for each check:
      • A wrong id.
      • A literal that is not in the lemma.
      • A literal that is not an atom.
      • A split that is not on the path.
      • An unknown variable.
      • Swapped children.
      • A wrong weight.
      • A child outside the tree.
    • The LRAT steps need the lemmas.
    • Lemmas outside the format give an error.
  • The tests of farkas.rs use big fractions. Three tests on numbers past i128 replace the four TooLarge tests.
  • smt_integer_queries_agree_with_z3.rs now asks for a proof of each query. vxc must accept the proof of each unsat answer. 25 of the 45 queries are unsat, 13 proofs have lemmas, and 5 have splits, with cuts among them.
  • vxc accepts the proofs of all 585 unsat answers of the full set.

I broke the checker 19 ways, one at a time, with a switch at run time. Each break made a unit test fail, at the assertion for that check. At first, two breaks passed:

  • The ite made the sums of its branches before the literal of its condition.
  • A bound on a single variable got a new row.

I added tests for both, and both breaks fail now. The two breaks also make the test of the 45 queries fail, because vxc does not accept a proof.

I also changed the 585 proofs in 4 ways, one at a time:

Change Proofs changed Rejected
Negate the first literal of the first lemma 329 329
Double the first weight of the first leaf 329 329
Add 1 to the bound of the first split 120 91
Remove the last LRAT step 585 585

In the 29 proofs that pass with a moved split, no leaf uses the bound of that split. So the proof stays valid.

Found on the way

(* 0 x) stopped the solver. The sum had a term with the coefficient 0, and the division by the GCD then divided by 0. The second commit of #4417 fixes this, with a test.

Not in this PR

vxc now checks an `unsat` answer of the integer solver, as it checks a
bit-vector answer. src/hir/bv_check.rs becomes smt_check.rs, because it
reads integer queries (QF_LIA) too.

- The reader reads Int terms, and folds constants as the solver does.
  The translation makes the same sums, atoms, rows and clauses, with the
  same numbers, by the rules at the top of smt.vx.
- Each lemma of `get-proof` must be the next clause. Each literal of a
  leaf must name an atom, and the lemma must have its negation.
  farkas.rs checks the tree, with each row of a split written as its
  sum over integer variables.
- lrat.rs then checks the LRAT steps, with the lemmas as input clauses.

farkas.rs now uses exact fractions of big integers, from the crates
num-bigint and num-rational. Of the 585 `unsat` answers to the queries
of the prover, 23 have a number of 2^127 or more. A checker with i128
numbers cannot accept them.

The unit tests give the clauses of small queries, found by hand. They
also change a proof of the solver in one place for each check. The test
of the 45 sample queries now checks the proof of each `unsat` answer.
vxc accepts all 585 proofs of the full set.

Fixes: #4390
@hiraditya
hiraditya added this pull request to stack #4439 December 1, 2026 18:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant