3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-07-20 19:32:04 +00:00

simplify interval

This commit is contained in:
Jakob Rath 2023-01-18 18:40:48 +01:00
parent c62ba26cf4
commit 8385452d91

View file

@ -13,13 +13,11 @@ Author:
--*/ --*/
#pragma once #pragma once
#include "math/polysat/types.h" #include "math/polysat/types.h"
#include "util/optional.h" #include <optional>
namespace polysat { namespace polysat {
enum class ikind_t { full, proper }; struct pdd_bounds {
struct bounds {
pdd lo; ///< lower bound, inclusive pdd lo; ///< lower bound, inclusive
pdd hi; ///< upper bound, exclusive pdd hi; ///< upper bound, exclusive
}; };
@ -30,19 +28,17 @@ namespace polysat {
* Membership test t \in [lo; hi[ is equivalent to t - lo < hi - lo. * Membership test t \in [lo; hi[ is equivalent to t - lo < hi - lo.
*/ */
class interval { class interval {
ikind_t m_kind; std::optional<pdd_bounds> m_bounds = std::nullopt;
optional<bounds> m_bounds;
interval(): m_kind(ikind_t::full) {} interval() = default;
interval(pdd const& lo, pdd const& hi): interval(pdd const& lo, pdd const& hi): m_bounds({lo, hi}) {}
m_kind(ikind_t::proper), m_bounds({lo, hi}) {}
public: public:
static interval empty(dd::pdd_manager& m) { return proper(m.zero(), m.zero()); } static interval empty(dd::pdd_manager& m) { return proper(m.zero(), m.zero()); }
static interval full() { return {}; } static interval full() { return {}; }
static interval proper(pdd const& lo, pdd const& hi) { return {lo, hi}; } static interval proper(pdd const& lo, pdd const& hi) { return {lo, hi}; }
bool is_full() const { return m_kind == ikind_t::full; } bool is_full() const { return !m_bounds; }
bool is_proper() const { return m_kind == ikind_t::proper; } bool is_proper() const { return !!m_bounds; }
bool is_always_empty() const { return is_proper() && lo() == hi(); } bool is_always_empty() const { return is_proper() && lo() == hi(); }
pdd const& lo() const { SASSERT(is_proper()); return m_bounds->lo; } pdd const& lo() const { SASSERT(is_proper()); return m_bounds->lo; }
pdd const& hi() const { SASSERT(is_proper()); return m_bounds->hi; } pdd const& hi() const { SASSERT(is_proper()); return m_bounds->hi; }
@ -89,7 +85,7 @@ namespace polysat {
rational current_len() const { rational current_len() const {
SASSERT(is_proper()); SASSERT(is_proper());
return mod(hi_val() - lo_val(), rational::power_of_two(lo().power_of_2())); return mod(hi_val() - lo_val(), lo().manager().two_to_N());
} }
bool currently_contains(rational const& val) const { bool currently_contains(rational const& val) const {