3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-04-15 08:44:10 +00:00
Commit graph

461 commits

Author SHA1 Message Date
Guangyu (Gary) HU
fbd51981c3
mini_quip: port to Python 3 and fix several bugs (#9246)
* mini_quip: port to Python 3 and fix several bugs

examples/python/mini_quip.py was Python 2 only and had several
latent bugs that prevented it from running on Python 3 or producing
correct results on benchmarks beyond horn1..5.

Python 3 / import fixes:
- Convert `print stmt` to `print(...)` calls (lines 457-458, 567,
  710, 747, 765, 776).
- The bare `print("Test file: %s") % file` form was applying `%`
  to the return value of print() (None); rewrite as
  `print("Test file: %s" % file)`.
- Add `import sys` (used by sys.stdout.write/flush) and
  `import copy` (used by QReach.state2cube via copy.deepcopy);
  neither was previously imported.
- next()/prev() passed `zip(...)` directly to z3.substitute. In
  Python 3 zip returns a one-shot generator; wrap with list() the
  same way mini_ic3 already does.

Bug fixes:
- is_transition(): when an init rule's body is an And without any
  Invariant predicate, is_body() returns (And(...), None). The
  function then passed inv0=None to subst_vars and crashed inside
  get_vars(). Add an explicit None check so the rule falls through
  to is_init() (same fix as mini_ic3).
- generalize(): guard against an empty unsat core. Without the
  guard, an empty core can be returned and become
  cube2clause([])=Or([])=False, poisoning all frames (same class
  of bug as in mini_ic3).
- check_reachable(): self.prev(cube) on an empty cube produced an
  empty list which was then added to a solver as a no-op
  constraint, so an empty cube would always look reachable. Only
  add the constraint when cube is non-empty.
- quip_blocked() at f==0 for must goals contained
  `assert is_sat == s.check()` where `is_sat` is undefined in that
  scope; the intent is `assert sat == s.check()`.
- Inside the lemma-pushing loop in quip_blocked(), `is_sat == unsat`
  was a comparison whose result was discarded; the intended
  assignment is `is_sat = unsat`.

Verified on horn1..5 (unchanged behavior, all return same
SAFE/UNSAFE result and validate). Larger benchmarks (h_CRC,
h_FIFO, cache_coherence_three) now at least run without exceptions
(performance is a separate matter).

* mini_quip: guard against None from QReach.intersect in CEX trace loop

In quip_blocked, the must-goal CEX-tracing loop calls
self.reachable.intersect(self.prev(r)) and immediately uses
r.children() on the result. QReach.intersect can return None when
the model literals do not match any state in the partial reachable
set, which crashes with AttributeError: 'NoneType' object has no
attribute 'children'. Reproduces on data/h_FIFO.smt2.

Fix: save the model, and when intersect returns None fall back to
the raw self.project0(model) as the predecessor cube. This still
gives a concrete predecessor and lets the CEX trace make progress
instead of crashing.
2026-04-09 14:30:26 -07:00
Guangyu (Gary) HU
704dc9375d
mini_ic3: fix generalize() returning empty/init-overlapping core (#9245)
Two fixes in examples/python/mini_ic3.py:

1. generalize(): the polarity of the disjointness check was inverted,
   and there was no guard against an empty unsat core. With an empty
   core, And([])=True so check_disjoint(init, prev(True)) is always
   False (init is sat), and the code returned the empty core. That
   empty core then became cube2clause([])=Or([])=False, which got
   added as a lemma to all frames. The frame became inconsistent and
   is_valid() returned And(Or())=False as the "inductive invariant".

   Fix: require len(core) > 0 AND check_disjoint(init, prev(core))
   (without the spurious 'not'), so the core is only used when it
   is genuinely disjoint from init.

2. is_transition(): when an init rule's body happens to be an And
   without any Invariant predicate (e.g. (and (not A) (not B) ...)),
   is_body() returns (And(...), None). is_transition then passed
   inv0=None to subst_vars() which crashed inside get_vars(). Add an
   explicit None check so the rule falls through to is_init().

Verified on horn1..5 (unchanged behavior), h_CRC and h_FIFO from the
blocksys benchmarks (now correctly return CEX matching z3 spacer),
and cache_coherence_three (no longer collapses to (and or)).
2026-04-09 02:01:07 -07:00
Copilot
6893674392
fix: correct misleading API comments in fp.go and JavaExample.java (#9003)
* Initial plan

* fix: correct misleading API comments in fp.go and JavaExample.java

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-03-15 12:08:59 -07:00
Angelica Moreira
bebad7da50
Add numeral extraction helpers to Java API (#8978)
New methods:
- Expr.getNumeralDouble(): retrieve any numeral as a double
- IntNum.getUint(): extract numeral as unsigned 32-bit value
- IntNum.getUint64(): extract numeral as unsigned 64-bit value
- RatNum.getSmall(): numerator/denominator as int64 pair
- RatNum.getRationalInt64(): numerator/denominator (returns null on overflow)

Each is a thin wrapper around the existing Native binding.
Added examples to JavaExample.java covering all new methods.
2026-03-15 10:36:17 -07:00
Angelica Moreira
b8e15f2121
Add missing AST query methods to Java API (#8977)
* add Expr.isGround() to Java API

Expose Z3_is_ground as a public method on Expr. Returns true when the
expression contains no free variables.

* add Expr.isLambda() to Java API

Expose Z3_is_lambda as a public method on Expr. Returns true when the
expression is a lambda quantifier.

* add AST.getDepth() to Java API

Expose Z3_get_depth as a public method on AST. Returns the maximum
number of nodes on any path from root to leaf.

* add ArraySort.getArity() to Java API

Expose Z3_get_array_arity as a public method on ArraySort. Returns
the number of dimensions of a multi-dimensional array sort.

* add DatatypeSort.isRecursive() to Java API

Expose Z3_is_recursive_datatype_sort as a public method on
DatatypeSort. Returns true when the datatype refers to itself.

* add FPExpr.isNumeral() to Java API

Expose Z3_fpa_is_numeral as a public method on FPExpr. Returns true
when the expression is a concrete floating-point value.

* add isGroundExample test to JavaExample

Test Expr.isGround() on constants, variables, and compound
expressions.

* add astDepthExample test to JavaExample

Test AST.getDepth() on leaf nodes and nested expressions to verify
the depth computation.

* add arrayArityExample test to JavaExample

Test ArraySort.getArity() on single-domain and multi-domain array
sorts.

* add recursiveDatatypeExample test to JavaExample

Test DatatypeSort.isRecursive() on a recursive list datatype and a
non-recursive pair datatype.

* add fpNumeralExample test to JavaExample

Test FPExpr.isNumeral() on a floating point constant and a symbolic
variable.

* add isLambdaExample test to JavaExample

Test Expr.isLambda() on a lambda expression and a plain variable.
2026-03-14 10:13:42 -07:00
copilot-swe-agent[bot]
5dad1247de Fix variable naming: tmpFile -> tempFile for Go conventions
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 21:48:51 +00:00
copilot-swe-agent[bot]
c99baf45d0 Address code review feedback: use os.CreateTemp and remove unused vars
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 21:47:33 +00:00
copilot-swe-agent[bot]
6d3c41143c Fix duplicate example in advanced_example.go and add silent markers for unused vars
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 21:46:23 +00:00
copilot-swe-agent[bot]
188880a20c Add missing high-priority Go bindings to Solver
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 21:28:24 +00:00
copilot-swe-agent[bot]
3f4bd11f00 Fix Go bindings and enable in CI
- Fix all compilation errors in Go bindings
- Add missing type definitions (Pattern, ASTVector, ParamDescrs)
- Fix boolean comparisons to use bool() casts
- Fix Z3_app type casts using unsafe.Pointer
- Fix null symbol handling to use nil
- Fix unused variable in basic_example.go
- Fix CMake test target to run from examples/go directory
- Restore CI steps to build and test Go bindings

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 06:05:58 +00:00
Nikolaj Bjorner
66d0fb5477 git bindings v1.0 2026-02-15 21:24:40 -08:00
Copilot
db6e15361b
Add Java APIs for polymorphic datatypes (#8438)
* Initial plan

* Add Java APIs for polymorphic datatypes and type variables

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix code review issue and add documentation

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add TypeVarSort.java to CMakeLists.txt for Java bindings

The CMake build was failing because TypeVarSort.java was not included in the Z3_JAVA_JAR_SOURCE_FILES list in src/api/java/CMakeLists.txt. Added it in alphabetical order between TupleSort.java and UninterpretedSort.java.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-01-31 15:31:36 -08:00
Copilot
2ab9887478
Add comprehensive Java IDE setup documentation for ClassNotFoundException (#8260)
* Initial plan

* Add comprehensive Java IDE setup documentation

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix documentation issues: use version placeholder and fix Gradle syntax

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-01-19 22:24:22 -08:00
Copilot
ecea5e2b4e
Add sequence higher-order functions to Java API (#8226)
* Initial plan

* Add four sequence operations to Java API (SeqMap, SeqMapi, SeqFoldl, SeqFoldli)

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix checkContextMatch call and add test for sequence operations

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add 4-parameter checkContextMatch overload for consistency

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-01-17 13:02:54 -08:00
Nikolaj Bjorner
a2605e7b66 remove RCF example
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-01-14 17:07:25 -08:00
Nikolaj Bjorner
38d67b3c59 removing file to deal with build issue
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2026-01-13 09:15:14 -08:00
Copilot
bd0eba812d
Add RCF (Real Closed Field) bindings to C++, Java, C#, and TypeScript (#8171)
* Initial plan

* Add RCF (Real Closed Field) bindings to C++ API

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add RCF (Real Closed Field) bindings to Java API

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add RCF (Real Closed Field) bindings to C# (.NET) API

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add RCF (Real Closed Field) example for TypeScript/JavaScript API

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add comprehensive RCF implementation summary documentation

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-01-12 16:34:42 -08:00
Nikolaj Bjorner
c88295a7c7 fix C++ example and add polymorphic interface for C++
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2025-10-29 03:08:49 -07:00
Copilot
5163411f9b
Update Z3_mk_datatype_sort API to accept array of sort parameters and add Z3_mk_polymorphic_datatype (#7966)
* Initial plan

* Update Z3_mk_datatype_sort API to accept array of parameters

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Update language bindings for parametric datatype sort API

- Python: Updated DatatypeSort() to accept optional params list
- OCaml: Added mk_sort_ref_p/mk_sort_ref_ps for parametric datatypes
- .NET: Added MkDatatypeSortRef() methods with optional params
- Java: Added mkDatatypeSortRef() methods with optional params
- All changes maintain backward compatibility

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix .NET build error - rename params to parameters

The 'params' keyword is reserved in C#, causing compilation errors.
Renamed parameter from 'params' to 'parameters' in MkDatatypeSortRef methods.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add unit test for parametric datatypes

Added test_parametric_datatype.cpp to demonstrate polymorphic datatypes.
The test creates two concrete instantiations of a generic pair concept:
- pair_int_real with fields (first:Int, second:Real)
- pair_real_int with fields (first:Real, second:Int)
Then verifies that accessors work correctly and type checking is enforced.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Implement polymorphic type variables support for parametric datatypes

- Modified datatype_decl_plugin to allow type variables as parameters
- Updated mk_datatype_decl to extract type variables from field sorts
- Type variables are collected in order of first appearance
- Revised unit test to use Z3_mk_type_variable for polymorphic datatypes
- Test creates pair datatype with type variables alpha and beta
- Successfully instantiates with concrete types (pair Int Real) and (pair Real Int)
- Verifies accessor types match and equality terms are well-typed
- All tests pass

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add Z3_mk_polymorphic_datatype API and refactor datatype creation

- Added new API Z3_mk_polymorphic_datatype to z3_api.h
- Renamed static mk_datatype_decl to api_datatype_decl in api_datatype.cpp
- Modified api_datatype_decl to accept explicit type parameters
- Updated all callers to use renamed function
- Added test_polymorphic_datatype_api demonstrating new API usage
- Both tests pass successfully

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Remove type variable collection logic from constructors

Removed the logic for collecting type variables from field sorts based on constructors.

* Update comments on parameter handling in api_datatype.cpp

Clarify usage of parameters in API documentation.

* Fix OCaml build error - use list instead of array for mk_datatype_sort

Changed mk_sort_ref to pass empty list [] instead of empty array [||].
Changed mk_sort_ref_p to pass params list directly instead of converting to array.
Z3native.mk_datatype_sort expects a list, not an array.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add polymorphic datatype example to C++ examples

Added polymorphic_datatype_example() demonstrating:
- Creating type variables alpha and beta with Z3_mk_type_variable
- Defining parametric Pair datatype with fields of type alpha and beta
- Instantiating with concrete types (Pair Int Real) and (Pair Real Int)
- Getting constructors and accessors from instantiated datatypes
- Creating constants and expressions using the polymorphic types
- Verifying type correctness with equality (= (first p1) (second p2))

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2025-10-15 20:51:21 +02:00
Nikolaj Bjorner
1109139359 move to readme-cmake 2025-05-13 14:36:20 -07:00
Nikolaj Bjorner
ce1535119d include some build cheat sheet 2025-05-13 14:34:47 -07:00
Nikolaj Bjorner
0d3c29a250 handle larger buffers 2025-05-13 14:11:59 -07:00
Josh Berdine
934455a24b
Remove vestiges of old ml api (#7597) 2025-03-27 16:41:31 -07:00
Nikolaj Bjorner
ec14ef765e Update Ubuntu job name in Azure pipeline and add string variable creation in C API example 2024-09-23 17:42:39 +01:00
Nikolaj Bjorner
f7691d34fd fix generic example
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2024-02-21 08:16:01 -08:00
Bruce Mitchener
53f89a81c1
Fix some typos. (#7115) 2024-02-07 23:06:43 -08:00
Nikolaj Bjorner
ebe5ebf0ae Add branch and bound solver, for fun 2023-12-23 11:58:29 -08:00
Nikolaj Bjorner
4fe423482a bugfix on slack
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-12-21 15:36:26 -08:00
Nikolaj Bjorner
ae1d9270b5 improve add bin/item functions
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-12-21 15:27:11 -08:00
Nikolaj Bjorner
b09c237775 rudimentary bin cover solver using the user propagator
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-12-21 15:18:26 -08:00
Christoph M. Wintersteiger
68a2c08d5e
Add Z3_get_estimated_alloc_size to OCaml API (#7068) 2023-12-21 12:54:30 -08:00
Christoph M. Wintersteiger
16753e43f1
Add accessors for RCF numeral internals (#7013) 2023-11-23 17:54:23 +01:00
Christoph M. Wintersteiger
23de8056d7
Add RCF functions to OCaml API (#6932) 2023-10-06 11:49:22 +09:00
Nikolaj Bjorner
5b385bd2fe fix #6665
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-04-02 10:58:21 -07:00
Nikolaj Bjorner
ce09c2ea6d fix build 2023-03-27 09:56:09 -07:00
Nikolaj Bjorner
b4ad747e0b fix #6644 2023-03-27 09:00:38 -07:00
Nikolaj Bjorner
fa72ec5405 switch to expose fresh function instead of changing legacy function
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-01-24 13:05:34 -08:00
Nikolaj Bjorner
47c7ed3b17 update ml example to 64 bit
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-01-24 04:33:52 -08:00
Nikolaj Bjorner
f3d6856736 remove msf example, add option to make model converter not reduce models
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2023-01-19 20:24:31 -08:00
Nikolaj Bjorner
147fb0d9c1 fix tptp5 build 2022-11-30 21:41:44 -08:00
Nikolaj Bjorner
cfc8e19baf add more simplifiers, fix model reconstruction order for elim_unconstrained
- enable sat.smt in smt_tactic that
is invoked by default on first goals
add flatten-clauses
add push-ite
have tptp5 front-end pretty print SMT2 formulas a little nicer.
2022-12-01 02:35:43 +09:00
Nikolaj Bjorner
f6595c161f add examples with proof replay
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-10-19 17:43:56 -07:00
Nikolaj Bjorner
88d10f7fe4 add example for monitoring proof logs
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-10-19 13:37:51 -07:00
Nuno Lopes
87e45221fd add missing break stmt to example
Reported by Henrique Preto
2022-10-14 09:43:18 +01:00
Nikolaj Bjorner
9b7c66ea7b revert update to netcoreapp version
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-09-12 08:41:43 -07:00
Nikolaj Bjorner
ff679e0fce increment version number 2022-09-11 19:02:44 -07:00
Nikolaj Bjorner
5322d4f241 fix #6326 2022-09-06 23:48:21 -07:00
Nikolaj Bjorner
791ca02ab1 formula simplification example
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-08-11 09:33:36 +03:00
Bruce Mitchener
6835522a7f z3++.h: No longer include unused sstream.
This makes some code using the C++ API have to include `<sstream>`
if they used the functionality but didn't include it themselves.
2022-08-05 09:41:49 +03:00
Bruce Mitchener
7eb1e6dd23 userPropagator: Compile as C++20.
Using std::unordered_map::contains requires C++20.
2022-08-05 07:41:14 +03:00