10Endpoint Endpoint::neg_inf() {
11 return Endpoint{
nullptr,
true,
true,
false};
14Endpoint Endpoint::pos_inf() {
15 return Endpoint{
nullptr,
true,
false,
true};
18Endpoint Endpoint::closed(std::shared_ptr<SymbolicExpr> val) {
19 return Endpoint{std::move(val),
false,
false,
false};
22Endpoint Endpoint::open(std::shared_ptr<SymbolicExpr> val) {
23 return Endpoint{std::move(val),
true,
false,
false};
26bool Interval::contains(
double value)
const {
28 return result ? result.value() :
false;
31bool Interval::is_empty()
const {
33 return result ? result.value() :
false;
36bool Interval::is_entire_line()
const {
37 return lower.is_neg_infinity &&
upper.is_pos_infinity;
40Interval Interval::empty() {
42 return Interval{Endpoint::open(SymbolicExpr::number(1)), Endpoint::open(SymbolicExpr::number(0))};
45Interval Interval::entire_line() {
46 return Interval{Endpoint::neg_inf(), Endpoint::pos_inf()};
49Interval Interval::point(std::shared_ptr<SymbolicExpr> val) {
50 return Interval{Endpoint::closed(val), Endpoint::closed(val)};
53IntervalUnion::IntervalUnion() : intervals_() {}
55IntervalUnion::IntervalUnion(std::vector<Interval> intervals) : intervals_(std::move(intervals)) {
59IntervalUnion IntervalUnion::from_single(
const Interval& iv) {
60 return IntervalUnion(std::vector<Interval>{iv});
63Result<IntervalUnion> IntervalUnion::from_intervals_checked(
64 std::vector<Interval> intervals,
65 ComputationContext& context) {
68 return Result<IntervalUnion>::failure(normalized.error());
70 return Result<IntervalUnion>::success(
71 from_checked_normalized(std::move(normalized.value())));
74Result<IntervalUnion> IntervalUnion::from_intervals_checked(
75 std::vector<Interval> intervals) {
77 return from_intervals_checked(std::move(intervals), context);
80IntervalUnion IntervalUnion::empty() {
81 return IntervalUnion();
84IntervalUnion IntervalUnion::entire_line() {
85 return IntervalUnion::from_single(Interval::entire_line());
88bool IntervalUnion::contains(
double value)
const {
89 for (
const auto& iv : intervals_) {
90 if (iv.contains(value)) {
97bool IntervalUnion::is_empty()
const {
98 return intervals_.empty();
101bool IntervalUnion::is_entire_line()
const {
102 return intervals_.size() == 1 && intervals_[0].is_entire_line();
105const std::vector<Interval>& IntervalUnion::intervals()
const {
109IntervalUnion IntervalUnion::from_checked_normalized(std::vector<Interval> intervals) {
110 IntervalUnion result;
111 result.intervals_ = std::move(intervals);
115void IntervalUnion::normalize() {
118 intervals_ = std::move(normalized.value());
126 constexpr const char* operation =
"interval_contains";
127 auto point_step =
context.consume_steps(1, operation);
136 0, std::move(
point.value()), Rational(0), Rational(0)};
151 if (lower_cmp.value() < 0 ||
152 (lower_cmp.value() == 0 &&
interval.lower.is_open)) {
159 if (upper_cmp.value() > 0 ||
160 (upper_cmp.value() == 0 &&
interval.upper.is_open)) {
176 constexpr const char* operation =
"interval_is_empty";
190 comparison.value() > 0 ||
191 (comparison.value() == 0 &&
200IntervalUnion IntervalUnion::intersect(
const IntervalUnion& other)
const {
201 auto result = intersect_checked(other);
202 return result ? result.value() : IntervalUnion::empty();
205IntervalUnion IntervalUnion::unite(
const IntervalUnion& other)
const {
206 auto result = unite_checked(other);
207 return result ? result.value() : IntervalUnion::empty();
210IntervalUnion IntervalUnion::complement()
const {
211 auto result = complement_checked();
212 return result ? result.value() : IntervalUnion::empty();
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(T value)
ExpressionResult normalize(const Node &value, ComputationContext &context)
Result< ComparableEndpoint > comparable_endpoint(const Endpoint &endpoint, ComputationContext &context, const std::string &operation)
Result< Rational > exact_double_rational(double value, ComputationContext &context, const std::string &operation)
Result< int > compare_comparable(const ComparableEndpoint &left, const ComparableEndpoint &right, ComputationContext &context)
const std::string const LimitExprPtr & point
Result< ComparableEndpoint > comparable_endpoint(const Endpoint &endpoint, ComputationContext &context, const std::string &operation)
__attribute__((visibility("default"))) ExprResult function(const std __attribute__((visibility("default"))) ExprResult finite_set(std ExprPtr upper
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
ExprResult interval(ExprPtr lower, ExprPtr upper, bool lower_closed, bool upper_closed)
Result< bool > interval_is_empty_checked(const Interval &interval, ComputationContext &context)
Result< Rational > exact_double_rational(double value, ComputationContext &context, const std::string &operation)
Result< std::vector< Interval > > normalize_intervals_checked(std::vector< Interval > intervals, ComputationContext &context)
Result< bool > interval_contains_checked(const Interval &interval, double value, ComputationContext &context)
const std::string const ExprPtr & value
Result< int > compare_comparable(const ComparableEndpoint &left, const ComparableEndpoint &right, ComputationContext &context)