mirror of
https://github.com/Z3Prover/z3
synced 2025-06-27 08:28:44 +00:00
Merge branch 'master' of https://github.com/z3prover/z3
This commit is contained in:
commit
187f1a8cbd
2 changed files with 90 additions and 36 deletions
|
@ -1901,13 +1901,17 @@ def is_quantifier(a):
|
||||||
|
|
||||||
def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
|
def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
|
||||||
if __debug__:
|
if __debug__:
|
||||||
_z3_assert(is_bool(body), "Z3 expression expected")
|
_z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
|
||||||
_z3_assert(is_const(vs) or (len(vs) > 0 and all([ is_const(v) for v in vs])), "Invalid bounded variable(s)")
|
_z3_assert(is_const(vs) or (len(vs) > 0 and all([ is_const(v) for v in vs])), "Invalid bounded variable(s)")
|
||||||
_z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
|
_z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
|
||||||
_z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
|
_z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
|
||||||
ctx = body.ctx
|
|
||||||
if is_app(vs):
|
if is_app(vs):
|
||||||
|
ctx = vs.ctx
|
||||||
vs = [vs]
|
vs = [vs]
|
||||||
|
else:
|
||||||
|
ctx = vs[0].ctx
|
||||||
|
if not is_expr(body):
|
||||||
|
body = BoolVal(body, ctx)
|
||||||
num_vars = len(vs)
|
num_vars = len(vs)
|
||||||
if num_vars == 0:
|
if num_vars == 0:
|
||||||
return body
|
return body
|
||||||
|
|
110
src/util/mpz.cpp
110
src/util/mpz.cpp
|
@ -45,43 +45,93 @@ Revision History:
|
||||||
#define LEHMER_GCD
|
#define LEHMER_GCD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static T gcd_core(T u, T v) {
|
|
||||||
if (u == 0)
|
|
||||||
return v;
|
|
||||||
if (v == 0)
|
|
||||||
return u;
|
|
||||||
|
|
||||||
int k;
|
#include <immintrin.h>
|
||||||
|
|
||||||
for (k = 0; ((u | v) & 1) == 0; ++k) {
|
#if defined(__GNUC__)
|
||||||
u >>= 1;
|
#define _trailing_zeros32(X) __builtin_ctz(X)
|
||||||
v >>= 1;
|
#else
|
||||||
}
|
#define _trailing_zeros32(X) _tzcnt_u32(X)
|
||||||
|
#endif
|
||||||
|
|
||||||
while ((u & 1) == 0)
|
#if defined(_AMD64_)
|
||||||
u >>= 1;
|
#if defined(__GNUC__)
|
||||||
|
#define _trailing_zeros64(X) __builtin_ctzll(X)
|
||||||
|
#else
|
||||||
|
#define _trailing_zeros64(X) _tzcnt_u64(X)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
inline uint64_t _trailing_zeros64(uint64_t x) {
|
||||||
|
uint64_t r = 0;
|
||||||
|
for (; 0 == (x & 1) && r < 64; ++r, x >>= 1);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define _bit_min(x, y) (y + ((x - y) & ((int)(x - y) >> 31)))
|
||||||
|
#define _bit_max(x, y) (x - ((x - y) & ((int)(x - y) >> 31)))
|
||||||
|
|
||||||
|
|
||||||
|
unsigned u_gcd(unsigned u, unsigned v) {
|
||||||
|
if (u == 0) return v;
|
||||||
|
if (v == 0) return u;
|
||||||
|
unsigned shift = _trailing_zeros32(u | v);
|
||||||
|
u >>= _trailing_zeros32(u);
|
||||||
|
if (u == 1 || v == 1) return 1 << shift;
|
||||||
|
if (u == v) return u << shift;
|
||||||
do {
|
do {
|
||||||
while ((v & 1) == 0)
|
v >>= _trailing_zeros32(v);
|
||||||
v >>= 1;
|
#if 1
|
||||||
|
unsigned diff = u - v;
|
||||||
if (u < v) {
|
unsigned mdiff = diff & (unsigned)((int)diff >> 31);
|
||||||
v -= u;
|
u = v + mdiff; // min
|
||||||
}
|
v = diff - 2 * mdiff; // if v <= u: u - v, if v > u: v - u = u - v - 2 * (u - v)
|
||||||
else {
|
#endif
|
||||||
T diff = u - v;
|
#if 0
|
||||||
u = v;
|
unsigned t = _bit_max(u, v);
|
||||||
v = diff;
|
u = _bit_min(u, v);
|
||||||
}
|
v = t;
|
||||||
v >>= 1;
|
v -= u;
|
||||||
} while (v != 0);
|
#endif
|
||||||
|
#if 0
|
||||||
return u << k;
|
unsigned t = std::max(u, v);
|
||||||
|
u = std::min(u,v);
|
||||||
|
v = t;
|
||||||
|
v -= u;
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
if (u > v) std::swap(u, v);
|
||||||
|
v -= u;
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
unsigned d1 = u - v;
|
||||||
|
unsigned d2 = v - u;
|
||||||
|
unsigned md21 = d2 & (unsigned)((int)d1 >> 31);
|
||||||
|
unsigned md12 = d1 & (unsigned)((int)d2 >> 31);
|
||||||
|
u = _bit_min(u, v);
|
||||||
|
v = md12 | md21;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
while (v != 0);
|
||||||
|
return u << shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t u64_gcd(uint64_t u, uint64_t v) {
|
||||||
|
if (u == 0) return v;
|
||||||
|
if (v == 0) return u;
|
||||||
|
if (u == 1 || v == 1) return 1;
|
||||||
|
auto shift = _trailing_zeros64(u | v);
|
||||||
|
u >>= _trailing_zeros64(u);
|
||||||
|
do {
|
||||||
|
v >>= _trailing_zeros64(v);
|
||||||
|
if (u > v) std::swap(u, v);
|
||||||
|
v -= u;
|
||||||
|
}
|
||||||
|
while (v != 0);
|
||||||
|
return u << shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned u_gcd(unsigned u, unsigned v) { return gcd_core(u, v); }
|
|
||||||
uint64_t u64_gcd(uint64_t u, uint64_t v) { return gcd_core(u, v); }
|
|
||||||
|
|
||||||
template<bool SYNCH>
|
template<bool SYNCH>
|
||||||
mpz_manager<SYNCH>::mpz_manager():
|
mpz_manager<SYNCH>::mpz_manager():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue