mirror of
https://github.com/Z3Prover/z3
synced 2026-05-25 11:26:21 +00:00
Add missing API functions to C++, Java, C#, and TypeScript bindings (#8152)
* Initial plan * Add missing API functions to C++, Java, C#, and TypeScript bindings Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix TypeScript type errors in new API functions Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Address code review comments and add documentation Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix TypeScript async issue in polynomialSubresultants Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Delete API_COHERENCE_FIXES.md --------- 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>
This commit is contained in:
parent
854d7a5af1
commit
5aac5c98b3
5 changed files with 158 additions and 1 deletions
|
|
@ -82,6 +82,36 @@ namespace z3 {
|
||||||
inline void set_param(char const * param, int value) { auto str = std::to_string(value); Z3_global_param_set(param, str.c_str()); }
|
inline void set_param(char const * param, int value) { auto str = std::to_string(value); Z3_global_param_set(param, str.c_str()); }
|
||||||
inline void reset_params() { Z3_global_param_reset_all(); }
|
inline void reset_params() { Z3_global_param_reset_all(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return Z3 version number information.
|
||||||
|
*/
|
||||||
|
inline void get_version(unsigned& major, unsigned& minor, unsigned& build_number, unsigned& revision_number) {
|
||||||
|
Z3_get_version(&major, &minor, &build_number, &revision_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return a string that fully describes the version of Z3 in use.
|
||||||
|
*/
|
||||||
|
inline std::string get_full_version() {
|
||||||
|
return std::string(Z3_get_full_version());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Enable tracing messages tagged as \c tag when Z3 is compiled in debug mode.
|
||||||
|
It is a NOOP otherwise.
|
||||||
|
*/
|
||||||
|
inline void enable_trace(char const * tag) {
|
||||||
|
Z3_enable_trace(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable tracing messages tagged as \c tag when Z3 is compiled in debug mode.
|
||||||
|
It is a NOOP otherwise.
|
||||||
|
*/
|
||||||
|
inline void disable_trace(char const * tag) {
|
||||||
|
Z3_disable_trace(tag);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Exception used to sign API usage errors.
|
\brief Exception used to sign API usage errors.
|
||||||
*/
|
*/
|
||||||
|
|
@ -2315,6 +2345,19 @@ namespace z3 {
|
||||||
return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
|
return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Return the nonzero subresultants of p and q with respect to the "variable" x.
|
||||||
|
|
||||||
|
\pre p, q and x are Z3 expressions where p and q are arithmetic terms.
|
||||||
|
Note that, any subterm that cannot be viewed as a polynomial is assumed to be a variable.
|
||||||
|
*/
|
||||||
|
inline expr_vector polynomial_subresultants(expr const& p, expr const& q, expr const& x) {
|
||||||
|
check_context(p, q); check_context(p, x);
|
||||||
|
Z3_ast_vector r = Z3_polynomial_subresultants(p.ctx(), p, q, x);
|
||||||
|
p.check_error();
|
||||||
|
return expr_vector(p.ctx(), r);
|
||||||
|
}
|
||||||
|
|
||||||
template<> class cast_ast<ast> {
|
template<> class cast_ast<ast> {
|
||||||
public:
|
public:
|
||||||
ast operator()(context & c, Z3_ast a) { return ast(c, a); }
|
ast operator()(context & c, Z3_ast a) { return ast(c, a); }
|
||||||
|
|
|
||||||
|
|
@ -4849,6 +4849,44 @@ namespace Microsoft.Z3
|
||||||
return a.NativeObject;
|
return a.NativeObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a partial order relation over a sort.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">The sort of the relation.</param>
|
||||||
|
/// <param name="index">The index of the relation.</param>
|
||||||
|
public FuncDecl MkPartialOrder(Sort a, uint index)
|
||||||
|
{
|
||||||
|
return new FuncDecl(this, Native.Z3_mk_partial_order(this.nCtx, a.NativeObject, index));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create the transitive closure of a binary relation.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>The resulting relation is recursive.</remarks>
|
||||||
|
/// <param name="f">A binary relation represented as a function declaration.</param>
|
||||||
|
public FuncDecl MkTransitiveClosure(FuncDecl f)
|
||||||
|
{
|
||||||
|
return new FuncDecl(this, Native.Z3_mk_transitive_closure(this.nCtx, f.NativeObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the nonzero subresultants of p and q with respect to the "variable" x.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// p, q and x are Z3 expressions where p and q are arithmetic terms.
|
||||||
|
/// Note that any subterm that cannot be viewed as a polynomial is assumed to be a variable.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="p">First arithmetic term.</param>
|
||||||
|
/// <param name="q">Second arithmetic term.</param>
|
||||||
|
/// <param name="x">The variable with respect to which subresultants are computed.</param>
|
||||||
|
public ASTVector PolynomialSubresultants(Expr p, Expr q, Expr x)
|
||||||
|
{
|
||||||
|
CheckContextMatch(p);
|
||||||
|
CheckContextMatch(q);
|
||||||
|
CheckContextMatch(x);
|
||||||
|
return new ASTVector(this, Native.Z3_polynomial_subresultants(this.nCtx, p.NativeObject, q.NativeObject, x.NativeObject));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a string describing all available parameters to <c>Expr.Simplify</c>.
|
/// Return a string describing all available parameters to <c>Expr.Simplify</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -4291,7 +4291,7 @@ public class Context implements AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates or a partial order.
|
* Creates a partial order.
|
||||||
* @param index The index of the order.
|
* @param index The index of the order.
|
||||||
* @param sort The sort of the order.
|
* @param sort The sort of the order.
|
||||||
*/
|
*/
|
||||||
|
|
@ -4306,6 +4306,40 @@ public class Context implements AutoCloseable {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the transitive closure of a binary relation.
|
||||||
|
* The resulting relation is recursive.
|
||||||
|
* @param f function declaration of a binary relation
|
||||||
|
*/
|
||||||
|
public final <R extends Sort> FuncDecl<BoolSort> mkTransitiveClosure(FuncDecl<BoolSort> f) {
|
||||||
|
return (FuncDecl<BoolSort>) FuncDecl.create(
|
||||||
|
this,
|
||||||
|
Native.mkTransitiveClosure(
|
||||||
|
nCtx(),
|
||||||
|
f.getNativeObject()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the nonzero subresultants of p and q with respect to the "variable" x.
|
||||||
|
* Note that any subterm that cannot be viewed as a polynomial is assumed to be a variable.
|
||||||
|
* @param p arithmetic term
|
||||||
|
* @param q arithmetic term
|
||||||
|
* @param x variable
|
||||||
|
*/
|
||||||
|
public final <R extends Sort> ASTVector polynomialSubresultants(Expr<R> p, Expr<R> q, Expr<R> x) {
|
||||||
|
return new ASTVector(
|
||||||
|
this,
|
||||||
|
Native.polynomialSubresultants(
|
||||||
|
nCtx(),
|
||||||
|
p.getNativeObject(),
|
||||||
|
q.getNativeObject(),
|
||||||
|
x.getNativeObject()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps an AST.
|
* Wraps an AST.
|
||||||
* Remarks: This function is used for transitions between
|
* Remarks: This function is used for transitions between
|
||||||
|
|
|
||||||
|
|
@ -1732,6 +1732,19 @@ export function createApi(Z3: Z3Core): Z3HighLevel {
|
||||||
return new BoolImpl(check(Z3.mk_set_subset(contextPtr, a.ast, b.ast)));
|
return new BoolImpl(check(Z3.mk_set_subset(contextPtr, a.ast, b.ast)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mkPartialOrder(sort: Sort<Name>, index: number): FuncDecl<Name> {
|
||||||
|
return new FuncDeclImpl(check(Z3.mk_partial_order(contextPtr, sort.ptr, index)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function mkTransitiveClosure(f: FuncDecl<Name>): FuncDecl<Name> {
|
||||||
|
return new FuncDeclImpl(check(Z3.mk_transitive_closure(contextPtr, f.ptr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function polynomialSubresultants(p: Arith<Name>, q: Arith<Name>, x: Arith<Name>): Promise<AstVector<Name, Arith<Name>>> {
|
||||||
|
const result = await Z3.polynomial_subresultants(contextPtr, p.ast, q.ast, x.ast);
|
||||||
|
return new AstVectorImpl<ArithImpl>(check(result));
|
||||||
|
}
|
||||||
|
|
||||||
class AstImpl<Ptr extends Z3_ast> implements Ast<Name, Ptr> {
|
class AstImpl<Ptr extends Z3_ast> implements Ast<Name, Ptr> {
|
||||||
declare readonly __typename: Ast['__typename'];
|
declare readonly __typename: Ast['__typename'];
|
||||||
readonly ctx: Context<Name>;
|
readonly ctx: Context<Name>;
|
||||||
|
|
@ -4632,6 +4645,9 @@ export function createApi(Z3: Z3Core): Z3HighLevel {
|
||||||
FullSet,
|
FullSet,
|
||||||
isMember,
|
isMember,
|
||||||
isSubset,
|
isSubset,
|
||||||
|
mkPartialOrder,
|
||||||
|
mkTransitiveClosure,
|
||||||
|
polynomialSubresultants,
|
||||||
};
|
};
|
||||||
cleanup.register(ctx, () => Z3.del_context(contextPtr));
|
cleanup.register(ctx, () => Z3.del_context(contextPtr));
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
|
||||||
|
|
@ -827,6 +827,32 @@ export interface Context<Name extends string = 'main'> {
|
||||||
|
|
||||||
/** @category Operations */
|
/** @category Operations */
|
||||||
isSubset<ElemSort extends AnySort<Name>>(a: SMTSet<Name, ElemSort>, b: SMTSet<Name, ElemSort>): Bool<Name>;
|
isSubset<ElemSort extends AnySort<Name>>(a: SMTSet<Name, ElemSort>, b: SMTSet<Name, ElemSort>): Bool<Name>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a partial order relation over a sort.
|
||||||
|
* @param sort The sort of the relation
|
||||||
|
* @param index The index of the relation
|
||||||
|
* @category Operations
|
||||||
|
*/
|
||||||
|
mkPartialOrder(sort: Sort<Name>, index: number): FuncDecl<Name>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the transitive closure of a binary relation.
|
||||||
|
* The resulting relation is recursive.
|
||||||
|
* @param f A binary relation represented as a function declaration
|
||||||
|
* @category Operations
|
||||||
|
*/
|
||||||
|
mkTransitiveClosure(f: FuncDecl<Name>): FuncDecl<Name>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the nonzero subresultants of p and q with respect to the "variable" x.
|
||||||
|
* Note that any subterm that cannot be viewed as a polynomial is assumed to be a variable.
|
||||||
|
* @param p Arithmetic term
|
||||||
|
* @param q Arithmetic term
|
||||||
|
* @param x Variable with respect to which subresultants are computed
|
||||||
|
* @category Operations
|
||||||
|
*/
|
||||||
|
polynomialSubresultants(p: Arith<Name>, q: Arith<Name>, x: Arith<Name>): Promise<AstVector<Name, Arith<Name>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Ast<Name extends string = 'main', Ptr = unknown> {
|
export interface Ast<Name extends string = 'main', Ptr = unknown> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue