mirror of
https://github.com/Z3Prover/z3
synced 2026-07-15 19:45:41 +00:00
## Problem Maximizing/minimizing under a **strict** inequality has a delta-rational optimum. For ```smt2 (declare-const r Real) (assert (< r 1)) (maximize r) (check-sat) (get-objectives) ``` the optimum is the supremum `1 - epsilon`, but z3 reported `r = 0`. The same defect makes shared-symbol objectives report a value matching **neither the model nor the true optimum** (issue #10028 follow-up). Minimal reproducer — a 6-mark Golomb ruler (a `>32`-arg `distinct`, so the objective is coupled to EUF) with a strict real objective `obj > x5`, whose true optimum is `17 + epsilon`: | case | before | after | |---|---|---| | `maximize r`, `r < 1` | `0` ❌ | `1 - epsilon` ✅ | | `minimize r`, `r > 1` | `0` ❌ | `1 + epsilon` ✅ | | Golomb `minimize obj`, `obj > x5` | `35/2` / `7+eps` ❌ | `17 + epsilon` ✅ | ## Root cause `check_bound` validates the LP hint by asserting `objective >= optimum`. For a supremum `1 - epsilon` this is a **lower** bound whose value carries a **negative** infinitesimal `(1, -1)`. No `lconstraint_kind` can express that. The kind->infinitesimal map only yields the *matching-sign* cases — `GT` -> lower `(r, +1)`, `LT` -> upper `(r, -1)` — or zero (`GE`/`LE`). The opposite-sign lower bound `(r, -1)` (i.e. `r >= r0 - delta`) is a *relaxation* that no strict inequality produces. `opt_solver::mk_ge` therefore projected the `-epsilon` away, turning `r >= 1 - epsilon` into the over-strong, unsatisfiable `r >= 1`; validation failed and the strictly smaller current model value was reported instead. ## Fix — carry the infinitesimal faithfully through the bound pipeline - **`lp_api::bound`** gains an `eps` component so `get_value` returns the true delta value (no spurious rational fixed-variable equality is propagated to EUF). - **`lar_base_constraint`** stores its right-hand side as a delta-rational `impq` pair; `rhs()` returns the rational component, `bound_eps()` the infinitesimal one. - **`lar_solver`** bound activation/update threads the whole `impq` bound, so a lower bound `(r, -1)` can be asserted. `constraint_holds` accounts for it using the **same** strict-bounds delta that flattens the model, computed **once per model**. - **`theory_lra::mk_ge`** builds a *fresh* predicate for the `(r, -1)` lower bound (to avoid colliding with an already-internalized `v >= r` literal) and attaches `eps = -1`. **`opt_solver::mk_ge`** passes the unprojected value to `theory_lra` / `theory_mi_arith` / `theory_inf_arith` (whose bounds are already `inf_rational`). The pair machinery is what makes the supremum both representable (optimum `1 - epsilon`) and validatable; the reported witness model remains the flattened rational (`find_delta_for_strict_bounds`), consistent with the existing epsilon semantics. ## Validation - Strict optima correct: `1-eps`, `1+eps`, bounded `2<r<5 -> 5-eps`, and lex/box variants. - Integer optima and the #10028 shared-symbol cases unchanged (Golomb n=6/7/8 -> 17/25/34, consistent with the model). - Unit tests **92/92** (release); no new debug-suite failures. - Opt regression corpus (73 files, `model_validate=true`) **byte-identical** to baseline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
118 lines
3.4 KiB
YAML
118 lines
3.4 KiB
YAML
name: OCaml Binding CI (Ubuntu + macOS)
|
|
|
|
on:
|
|
push:
|
|
branches: [ "**" ]
|
|
pull_request:
|
|
branches: [ "**" ]
|
|
|
|
jobs:
|
|
build-test:
|
|
strategy:
|
|
matrix:
|
|
os: [ ubuntu-latest, macos-latest ]
|
|
ocaml-version: ["5"]
|
|
fail-fast: false
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v7.0.0
|
|
|
|
# Cache ccache (shared across runs)
|
|
- name: Cache ccache
|
|
uses: actions/cache@v6.1.0
|
|
with:
|
|
path: ~/.ccache
|
|
key: ${{ runner.os }}-ccache-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-ccache-
|
|
|
|
# Setup OCaml via action (handles opam caching internally)
|
|
- uses: ocaml/setup-ocaml@v3
|
|
with:
|
|
ocaml-compiler: ${{ matrix.ocaml-version }}
|
|
opam-disable-sandboxing: true
|
|
cache-prefix: v1
|
|
|
|
# Platform-specific dependencies
|
|
- name: Install system dependencies (Ubuntu)
|
|
if: matrix.os == 'ubuntu-latest'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
bubblewrap m4 libgmp-dev pkg-config ninja-build ccache
|
|
|
|
- name: Install system dependencies (macOS)
|
|
if: matrix.os == 'macos-latest'
|
|
run: |
|
|
brew install gmp pkg-config ninja ccache
|
|
|
|
- name: Install required opam packages
|
|
run: opam install -y ocamlfind zarith
|
|
|
|
# Configure
|
|
- name: Configure with CMake
|
|
env:
|
|
CC: ${{ matrix.os == 'macos-latest' && 'ccache clang' || 'ccache gcc' }}
|
|
CXX: ${{ matrix.os == 'macos-latest' && 'ccache clang++' || 'ccache g++' }}
|
|
run: |
|
|
mkdir -p build
|
|
cd build
|
|
eval $(opam env)
|
|
echo "CC: $CC"
|
|
echo "CXX: $CXX"
|
|
echo "OCAMLFIND: $(which ocamlfind)"
|
|
echo "OCAMLC: $(which ocamlc)"
|
|
echo "OCAMLOPT: $(which ocamlopt)"
|
|
echo "OCAML_VERSION: $(ocamlc -version)"
|
|
echo "OCAMLLIB: $OCAMLLIB"
|
|
cmake .. \
|
|
-G Ninja \
|
|
-DZ3_BUILD_LIBZ3_SHARED=ON \
|
|
-DZ3_BUILD_OCAML_BINDINGS=ON \
|
|
-DZ3_BUILD_JAVA_BINDINGS=OFF \
|
|
-DZ3_BUILD_PYTHON_BINDINGS=OFF \
|
|
-DZ3_BUILD_CLI=OFF \
|
|
-DZ3_BUILD_TEST_EXECUTABLES=OFF \
|
|
-DCMAKE_VERBOSE_MAKEFILE=TRUE
|
|
|
|
- name: Build Z3 and OCaml bindings
|
|
run: |
|
|
ccache -z || true
|
|
eval $(opam env)
|
|
cd build
|
|
ninja build_z3_ocaml_bindings
|
|
ccache -s || true
|
|
|
|
- name: Compile ml_example.byte
|
|
run: |
|
|
eval $(opam env)
|
|
ocamlfind ocamlc -o ml_example.byte \
|
|
-package zarith \
|
|
-linkpkg \
|
|
-I build/src/api/ml \
|
|
-dllpath build/src/api/ml \
|
|
build/src/api/ml/z3ml.cma \
|
|
examples/ml/ml_example.ml
|
|
|
|
- name: Run ml_example.byte
|
|
run: |
|
|
eval $(opam env)
|
|
export DYLD_LIBRARY_PATH=$(pwd)/build
|
|
ocamlrun ./ml_example.byte
|
|
|
|
- name: Compile ml_example (native)
|
|
run: |
|
|
eval $(opam env)
|
|
ocamlfind ocamlopt -o ml_example \
|
|
-package zarith \
|
|
-linkpkg \
|
|
-I build/src/api/ml \
|
|
build/src/api/ml/z3ml.cmxa \
|
|
examples/ml/ml_example.ml
|
|
|
|
- name: Run ml_example (native)
|
|
run: |
|
|
export DYLD_LIBRARY_PATH=$(pwd)/build
|
|
./ml_example
|