Skip to content

Commit

Permalink
add API to access symbols associated with quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Nov 20, 2023
1 parent d272acc commit 9382b96
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/api/api_quant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,36 @@ extern "C" {
Z3_CATCH_RETURN(0);
}

Z3_symbol Z3_API Z3_get_quantifier_skolem_id(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_get_quantifier_skolem_id(c, a);
RESET_ERROR_CODE();
ast * _a = to_ast(a);
if (_a->get_kind() == AST_QUANTIFIER) {
return of_symbol(to_quantifier(_a)->get_skid());
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR, nullptr);
return of_symbol(symbol::null);
}
Z3_CATCH_RETURN(of_symbol(symbol::null));
}

Z3_symbol Z3_API Z3_get_quantifier_id(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_get_quantifier_skolem_id(c, a);
RESET_ERROR_CODE();
ast * _a = to_ast(a);
if (_a->get_kind() == AST_QUANTIFIER) {
return of_symbol(to_quantifier(_a)->get_qid());
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR, nullptr);
return of_symbol(symbol::null);
}
Z3_CATCH_RETURN(of_symbol(symbol::null));
}

unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_get_quantifier_num_patterns(c, a);
Expand Down
10 changes: 10 additions & 0 deletions src/api/python/z3/z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,16 @@ def weight(self):
"""
return int(Z3_get_quantifier_weight(self.ctx_ref(), self.ast))

def skolem_id(self):
"""Return the skolem id of `self`.
"""
return _symbol2py(self.ctx, Z3_get_quantifier_skolem_id(self.ctx_ref(), self.ast))

def qid(self):
"""Return the quantifier id of `self`.
"""
return _symbol2py(self.ctx, Z3_get_quantifier_id(self.ctx_ref(), self.ast))

def num_patterns(self):
"""Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
Expand Down
18 changes: 18 additions & 0 deletions src/api/z3_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5206,6 +5206,24 @@ extern "C" {
*/
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a);

/**
\brief Obtain skolem id of quantifier.
\pre Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST
def_API('Z3_get_quantifier_skolem_id', SYMBOL, (_in(CONTEXT), _in(AST)))
*/
Z3_symbol Z3_API Z3_get_quantifier_skolem_id(Z3_context c, Z3_ast a);

/**
\brief Obtain id of quantifier.
\pre Z3_get_ast_kind(a) == Z3_QUANTIFIER_AST
def_API('Z3_get_quantifier_id', SYMBOL, (_in(CONTEXT), _in(AST)))
*/
Z3_symbol Z3_API Z3_get_quantifier_id(Z3_context c, Z3_ast a);

/**
\brief Return number of patterns used in quantifier.
Expand Down

0 comments on commit 9382b96

Please sign in to comment.