Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,22 @@ class SolveForInterval : public IRVisitor {
equiv.accept(this);
}

void visit(const Min *op) override {
// min of bools is a logical And. These arise from
// and_condition_over_domain and the simplifier. Treat it as such so
// that Not distributes correctly (otherwise !min(a, b) is mis-solved).
internal_assert(op->type.is_bool());
Expr equiv = op->a && op->b;
equiv.accept(this);
}

void visit(const Max *op) override {
// max of bools is a logical Or.
internal_assert(op->type.is_bool());
Expr equiv = op->a || op->b;
equiv.accept(this);
}

void visit(const Not *op) override {
target = !target;
op->a.accept(this);
Expand Down
14 changes: 14 additions & 0 deletions test/correctness/solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,20 @@ void test_interval_solutions() {

check_inner_interval(x / 5 < 17, Interval::neg_inf(), 84);
check_outer_interval(x / 5 < 17, Interval::neg_inf(), 84);

// min/max of booleans are logical And/Or (and_condition_over_domain and the
// simplifier produce these). Solving must treat them as such so that Not
// distributes (De Morgan). Regression: !min(...) was solved like !a && !b
// instead of !a || !b.
// min(x<0, x<2) == (x<0), so !min(...) == (x>=0):
check_inner_interval(!min(x < 0, x < 2), 0, Interval::pos_inf());
check_outer_interval(!min(x < 0, x < 2), 0, Interval::pos_inf());
// max(x<0, x<2) == (x<2), so !max(...) == (x>=2):
check_inner_interval(!max(x < 0, x < 2), 2, Interval::pos_inf());
check_outer_interval(!max(x < 0, x < 2), 2, Interval::pos_inf());
// Non-negated forms: min(x<5,x<9) == (x<5); max(x<5,x<9) == (x<9):
check_outer_interval(min(x < 5, x < 9), Interval::neg_inf(), 4);
check_outer_interval(max(x < 5, x < 9), Interval::neg_inf(), 8);
}

void test_and_condition_over_domain() {
Expand Down
Loading