From 4cd29987437a9a7ebf989f8e211d73304d4df820 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 10 Jan 2013 13:05:47 -0800 Subject: [PATCH] Add power operator to C and Python RCF APIs Signed-off-by: Leonardo de Moura --- src/api/api_rcf.cpp | 11 +++++++++++ src/api/python/z3rcf.py | 6 ++++++ src/api/z3_rcf.h | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/src/api/api_rcf.cpp b/src/api/api_rcf.cpp index c79dfbf20..a7feada42 100644 --- a/src/api/api_rcf.cpp +++ b/src/api/api_rcf.cpp @@ -203,6 +203,17 @@ extern "C" { Z3_CATCH_RETURN(0); } + Z3_rcf_num Z3_API Z3_rcf_power(Z3_context c, Z3_rcf_num a, unsigned k) { + Z3_TRY; + LOG_Z3_rcf_power(c, a, k); + RESET_ERROR_CODE(); + reset_rcf_cancel(c); + rcnumeral r; + rcfm(c).power(to_rcnumeral(a), k, r); + RETURN_Z3(from_rcnumeral(r)); + Z3_CATCH_RETURN(0); + } + Z3_bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) { Z3_TRY; LOG_Z3_rcf_lt(c, a, b); diff --git a/src/api/python/z3rcf.py b/src/api/python/z3rcf.py index 2ff29dc9f..dd0696594 100644 --- a/src/api/python/z3rcf.py +++ b/src/api/python/z3rcf.py @@ -102,6 +102,12 @@ class RCFNum: def __neg__(self): return self.__rsub__(0) + def power(self, k): + return RCFNum(Z3_rcf_power(self.ctx_ref(), self.num, k), self.ctx) + + def __pow__(self, k): + return self.power(k) + def decimal(self, prec=5): return Z3_rcf_num_to_decimal_string(self.ctx_ref(), self.num, prec) diff --git a/src/api/z3_rcf.h b/src/api/z3_rcf.h index 1bca7e391..87f376117 100644 --- a/src/api/z3_rcf.h +++ b/src/api/z3_rcf.h @@ -121,6 +121,13 @@ extern "C" { */ Z3_rcf_num Z3_API Z3_rcf_inv(__in Z3_context c, __in Z3_rcf_num a); + /** + \brief Return the value a^k + + def_API('Z3_rcf_power', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(UINT))) + */ + Z3_rcf_num Z3_API Z3_rcf_power(__in Z3_context c, __in Z3_rcf_num a, __in unsigned k); + /** \brief Return Z3_TRUE if a < b