3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-14 04:45:39 +00:00

Add SMT-LIB choice support via array OP_CHOICE and instantiate choice axioms in array solvers (#9649)

This change wires SMT-LIB Hilbert choice parsing to a concrete
array-theory operator and ensures both array backends enforce the
expected semantic axiom. Previously, `(choice ((x T)) phi)` parsed as
NYI and had no solver-side instantiation path.

- **Parser: lower `choice_k` into array `OP_CHOICE`**
- `pop_quant_frame(choice_k)` now builds `(choice p)` instead of
throwing.
- Added parser include/use of array utilities to construct the term
directly from the generated lambda predicate.

- **Array decl plugin: add `OP_CHOICE` typing + surface syntax**
  - Added declaration support for `choice` with signature:
- `(Array T Bool) -> T` (encoded as `('a -> Bool) -> 'a` in HO view).
- Added recognizer/util helpers (`is_choice`, `mk_choice`) and exposed
`"choice"` in op names.

- **SMT array theory (`theory_array_full`): instantiate choice axiom**
  - Added instantiation for each encountered `choice(p)`:
    - `forall x . p(x) => p(choice(p))`
  - Integrated into internalization/relevancy paths and statistics.

- **SAT/SMT array backend (`sat/smt/array_*`): instantiate choice
axiom**
- Added new axiom record kind for choice, internalization hook,
assertion routine, and diagnostics/stat tracking.
  - Uses the same quantified implication schema as above.

- **Regression coverage**
- Extended SMT2 parser regression with an HO `choice` example to ensure
parser/eval pipeline accepts and processes choice terms.

Example of the now-supported input:

```smt2
(set-logic HO_ALL)
(declare-sort U 0)
(declare-fun P () (-> U Bool))
(assert (exists ((x U)) (P x)))
(assert (= witness (choice ((x U)) (P x))))
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot 2026-05-27 10:05:06 -07:00 committed by GitHub
parent 690cdd3f25
commit 51da9db615
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 124 additions and 17 deletions

View file

@ -176,6 +176,23 @@ void test_ho_curried_application() {
Z3_del_context(ctx);
}
void test_ho_choice_expression() {
char const* spec =
"(set-logic HO_ALL)\n"
"(declare-sort U 0)\n"
"(declare-fun P () (-> U Bool))\n"
"(assert (exists ((x U)) (P x)))\n"
"(declare-fun witness () U)\n"
"(assert (= witness (choice ((x U)) (P x))))\n"
"(assert (not (P witness)))\n"
"(check-sat)\n";
Z3_context ctx = Z3_mk_context(nullptr);
Z3_set_error_handler(ctx, setError);
test_eval(ctx, spec, false);
Z3_del_context(ctx);
}
void test_name(Z3_string spec, Z3_string expected_name) {
Z3_context ctx = Z3_mk_context(nullptr);
Z3_set_error_handler(ctx, setError);
@ -306,6 +323,7 @@ void tst_smt2print_parse() {
test_repeated_eval();
test_ho_curried_application();
test_ho_choice_expression();
test_symbol_escape();