Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ melior = "0.27.0"
clap = { version = "4.4", features = ["derive"] }
anyhow = "1.0"
similar = "2.7"
# Exact big integers and fractions, for the checker of the answers of the integer solver.
num-bigint = "0.4.8"
num-integer = "0.1.46"
num-rational = "0.4.2"
num-traits = "0.2.19"
# The commit for `vxc --version`. A crate of its own, so a new commit does not rerun build.rs.
vx-build-commit = { path = "vx-build-commit", version = "0.1.0" }
vx-config = { path = "vx-config", version = "0.1.0" }
Expand Down
6 changes: 3 additions & 3 deletions docs/solver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compiles and runs it, and checks that it prints the text below it.
| SAT solver | `stdlib/std/algo/sat.vx` | Finds values for Boolean variables that make each clause true, or writes a proof that no such values exist. | [sat.md](sat.md) |
| Proof checker | `src/hir/lrat.rs` | Checks the proofs of the SAT solver, in vxc. | [sat.md](sat.md#how-vxc-checks-a-proof) |
| Bit-vector solver | `stdlib/std/algo/smt.vx` | Reads SMT-LIB, makes one Boolean variable for each bit, and solves the clauses with the SAT solver. | [bit_vectors.md](bit_vectors.md) |
| Answer checker | `src/hir/bv_check.rs` | Checks each answer of the bit-vector solver, in vxc. | [bit_vectors.md](bit_vectors.md#how-vxc-checks-an-answer) |
| Answer checker | `src/hir/smt_check.rs` | Checks each answer of the bit-vector solver, and each `unsat` answer of the integer solver, in vxc. | [bit_vectors.md](bit_vectors.md#how-vxc-checks-an-answer), [integers.md](integers.md#how-vxc-checks-the-proof) |
| Big numbers | `stdlib/std/bigint.vx` | Integers and fractions of any size, for the arithmetic of the next steps. | [bigint.md](bigint.md) |
| Simplex | `stdlib/std/algo/simplex.vx` | Decides whether linear bounds over the rationals have a solution, or gives a Farkas certificate that shows why not. With integer variables, it searches with branch-and-bound and Gomory cuts, and the certificate is a tree. | [simplex.md](simplex.md) |
| Certificate checker | `src/hir/farkas.rs` | Checks the Farkas certificates of the simplex, and their trees for integers, in vxc. | [simplex.md](simplex.md#farkas-certificates) |
Expand All @@ -26,8 +26,8 @@ compiles and runs it, and checks that it prints the text below it.
it.

Today `src/hir/seam.rs` can use the solver, with `VX_SOLVER=vx`. `src/hir/prover.rs` still uses
z3. The integer solver answers its `QF_LIA` queries. #4390 plans the check of these answers in
vxc, and #4391 plans to send the queries of `prover.rs` to the solver.
z3. The integer solver answers its `QF_LIA` queries, and vxc checks each `unsat` answer. #4391
plans to send the queries of `prover.rs` to the solver.

## vxc checks every answer

Expand Down
2 changes: 1 addition & 1 deletion docs/solver/bit_vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ clauses. The SAT solver gives each free bit the value false, so `val_data` is 0.

## How vxc checks an answer

`src/hir/bv_check.rs` reads the same commands that vxc sends, with their `push` and `pop`. It keeps
`src/hir/smt_check.rs` reads the same commands that vxc sends, with their `push` and `pop`. It keeps
the assertions in scope at the `check-sat`.

- **`sat`:** it reads the values of `get-value`. Then it computes each assertion with those values,
Expand Down
30 changes: 24 additions & 6 deletions docs/solver/integers.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,41 @@ assertions.
- `(split <k> int|cut <below> <above> (<coefficient> <variable>) ...)` is a split of the tree, on
a sum over the variables of the simplex.

#4390 plans the check of these proofs in vxc.
### How vxc checks the proof

`src/hir/smt_check.rs` checks an `unsat` answer in vxc:

1. It reads the query, and makes the clauses of the assertions itself, by the rules at the top of
`smt.vx`. It makes the atoms and the variables of the simplex too, with the same numbers.
1. For each lemma, it writes each literal of a leaf as the bound of its atom, and each row of a
split as its sum. Then `src/hir/farkas.rs` checks the tree. The lemma must be the next clause,
and it must have the negation of each literal in the leaves.
1. `src/hir/lrat.rs` checks the LRAT steps against the clauses of the assertions and the lemmas.

So a bug in the solver can make a check fail, but it cannot make vxc accept a false `unsat`. For the
second query of the example, the leaf is the table of [The loop](#the-loop), and the lemma
`-4 5 -3` has the negation of each of its three literals.

The numbers of a proof can be large. The constants of wrapping arithmetic reach 2^128, and a weight
of a leaf can have hundreds of digits. So the checker uses exact fractions of big integers.

## Tests

- `tests/backend/pass/std_algo_smt_integers.vx` has one small query for each operator. Each has
one answer that is easy to find by hand. It also checks the proof of a small query, the step
limit, a constant above 2^128 in a scope, and the errors.
- The unit tests of `src/hir/smt_check.rs` give the clauses of small queries, found by hand with
the rules. They also change a proof of the solver in one place for each check of a lemma, and
vxc must not accept it.
- `tests/integration_test/smt_integer_queries_agree_with_z3.rs` runs the 45 queries of
`tests/solver/queries/`, which the prover sent to z3 in a run of the test suite. Each answer
must be the answer of z3. For each `sat` answer, z3 must accept the values of `get-value`.
must be the answer of z3. For each `sat` answer, z3 must accept the values of `get-value`. For
each `unsat` answer, vxc must accept the proof.

## Not yet

- **The check in vxc.** #4390 checks each lemma with its tree, and the LRAT proof against the
clauses that vxc makes itself. The Farkas checker of vxc uses `i128` fractions, and the queries
have constants as large as 2^128. So the checker needs big numbers too.
- **The prover.** #4391 sends the queries of `prover.rs` to this solver with `VX_SOLVER=vx`.
- **The prover.** #4391 sends the queries of `prover.rs` to this solver with `VX_SOLVER=vx`. vxc
does not compute Int terms yet, so #4391 also checks the values of a `sat` answer in vxc.
- **Speed.** The simplex sees the atoms only after the SAT solver sets all of them. #4392 checks
the bounds during the search of the SAT solver.
- **Bounds from bounds.** The rows `t - 2^64*q - r == 0` of wrapping arithmetic make the integer
Expand Down
6 changes: 2 additions & 4 deletions docs/solver/simplex.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ checker does what the table above does:
- The weighted sum must have no variables. Its number must be above zero, or zero with a strict
fact in the sum.

The checker uses fractions of two `i128` numbers. When a number of the sum does not fit, it reports
`TooLarge`, and vxc reports that it could not prove the fact. So a large number can make a check
fail, but it cannot make the checker accept a wrong certificate. Nothing calls the checker yet. The
step that connects simplex to the SAT solver will call it.
The checker uses exact fractions of big integers, so a number of any size fits. vxc checks the
certificate of each lemma of the [integer solver](integers.md#how-vxc-checks-the-proof) with it.

## Integers

Expand Down
Loading
Loading