3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-05-26 03:46:22 +00:00

Go/OCaml API gaps: substitution, AST introspection, Spacer, Goal completion (#9277)

* fix: address issues 1,2,4,5 and add Goal API to Go bindings

Issue 2 (Go): Add Substitute, SubstituteVars, SubstituteFuns to Expr
Issue 4 (Go): Add GetDecl, NumArgs, Arg to Expr for AST app introspection
Goal API (Go): Add IsInconsistent and ToDimacsString to Goal
ASTVector (Go): Add public Size, Get, String methods
ASTMap (Go): Add ASTMap type with full CRUD API in spacer.go
Issue 1 (Go): Add Spacer fixedpoint methods QueryFromLvl, GetGroundSatAnswer,
  GetRulesAlongTrace, GetRuleNamesAlongTrace, AddInvariant, GetReachable
Issue 1 (Go): Add context-level QE functions ModelExtrapolate, QeLite,
  QeModelProject, QeModelProjectSkolem, QeModelProjectWithWitness
Issue 5 (OCaml): Add substitute_funs to z3.ml and z3.mli

Agent-Logs-Url: https://github.com/Z3Prover/z3/sessions/afa18588-47af-4720-8cea-55fe0544ae55

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

* fix: add substitute_funs to Expr module sig in z3.ml

The internal sig...end block in z3.ml (the module type declaration for Expr)
was missing val substitute_funs, causing OCaml compiler error:
  The value substitute_funs is required but not provided

Agent-Logs-Url: https://github.com/Z3Prover/z3/sessions/c6662702-46a3-4aa0-b225-d6b73c2a2505

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>
This commit is contained in:
Copilot 2026-04-12 14:00:03 -07:00 committed by GitHub
parent 1566d3cc41
commit 68e528eaf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 290 additions and 0 deletions

View file

@ -218,6 +218,59 @@ func (f *Fixedpoint) FromFile(filename string) {
C.Z3_fixedpoint_from_file(f.ctx.ptr, f.ptr, cstr)
}
// QueryFromLvl poses a query against the asserted rules at the given level.
// This is a Spacer-specific function.
func (f *Fixedpoint) QueryFromLvl(query *Expr, lvl uint) Status {
result := C.Z3_fixedpoint_query_from_lvl(f.ctx.ptr, f.ptr, query.ptr, C.uint(lvl))
switch result {
case C.Z3_L_TRUE:
return Satisfiable
case C.Z3_L_FALSE:
return Unsatisfiable
default:
return Unknown
}
}
// GetGroundSatAnswer retrieves a bottom-up sequence of ground facts.
// The previous call to Query or QueryFromLvl must have returned Satisfiable.
// This is a Spacer-specific function.
func (f *Fixedpoint) GetGroundSatAnswer() *Expr {
ptr := C.Z3_fixedpoint_get_ground_sat_answer(f.ctx.ptr, f.ptr)
if ptr == nil {
return nil
}
return newExpr(f.ctx, ptr)
}
// GetRulesAlongTrace returns the list of rules along the counterexample trace.
// This is a Spacer-specific function.
func (f *Fixedpoint) GetRulesAlongTrace() *ASTVector {
return newASTVector(f.ctx, C.Z3_fixedpoint_get_rules_along_trace(f.ctx.ptr, f.ptr))
}
// GetRuleNamesAlongTrace returns the list of rule names along the counterexample trace.
// This is a Spacer-specific function.
func (f *Fixedpoint) GetRuleNamesAlongTrace() *Symbol {
return newSymbol(f.ctx, C.Z3_fixedpoint_get_rule_names_along_trace(f.ctx.ptr, f.ptr))
}
// AddInvariant adds an assumed invariant for the predicate pred.
// This is a Spacer-specific function.
func (f *Fixedpoint) AddInvariant(pred *FuncDecl, property *Expr) {
C.Z3_fixedpoint_add_invariant(f.ctx.ptr, f.ptr, pred.ptr, property.ptr)
}
// GetReachable retrieves the reachable states of a predicate.
// This is a Spacer-specific function.
func (f *Fixedpoint) GetReachable(pred *FuncDecl) *Expr {
ptr := C.Z3_fixedpoint_get_reachable(f.ctx.ptr, f.ptr, pred.ptr)
if ptr == nil {
return nil
}
return newExpr(f.ctx, ptr)
}
// Statistics represents statistics for Z3 solvers
type Statistics struct {
ctx *Context