Improve solve_for_outer_interval for max/min comparisons#9162
Open
alexreinking wants to merge 1 commit into
Open
Improve solve_for_outer_interval for max/min comparisons#9162alexreinking wants to merge 1 commit into
alexreinking wants to merge 1 commit into
Conversation
Two related improvements to SolveForInterval:
1. SolveExpression::visit(Sub): add f(x)*a - f(x) → f(x)*(a-1) and the
symmetric f(x) - f(x)*a → f(x)*(1-a) reduction rules. Without these,
expressions like 2*x - x couldn't be simplified, blocking the solver
from rearranging comparisons such as 2*x <= x into x <= 0.
2. SolveForInterval::visit(LE/GE): when solve_expression fails to fully
isolate the variable, try a direct max/min decomposition on the LHS
before falling back to fail(). The rules applied are:
max(a, b) <= c ⟺ a <= c && b <= c
min(a, b) <= c ⟺ a <= c || b <= c
max(a, b) * pos_c <= rhs ⟺ a*pos_c <= rhs && b*pos_c <= rhs
min(a, b) * pos_c <= rhs ⟺ a*pos_c <= rhs || b*pos_c <= rhs
(and symmetric >= variants)
Together these enable two previously unhandled cases:
- max(x, 1) * 2 <= x → Interval::nothing() (always false)
- max(abs(select(x < 0, f(x-1), 5)), 2) <= x → [2, +∞)
(the constant branch forces x >= 2 even when f is opaque)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9162 +/- ##
=======================================
Coverage ? 69.29%
=======================================
Files ? 254
Lines ? 78258
Branches ? 18726
=======================================
Hits ? 54230
Misses ? 18498
Partials ? 5530 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
abadams
approved these changes
May 29, 2026
Member
abadams
left a comment
There was a problem hiding this comment.
lgtm provided the fuzzer accepts it
Member
Author
|
The fuzz failure in CI is not related to this change. It's in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related improvements to SolveForInterval:
SolveExpression::visit(Sub): add
f(x)*a - f(x) → f(x)*(a-1)and the symmetricf(x) - f(x)*a → f(x)*(1-a)reduction rules. Without these, expressions like2*x - xcouldn't be simplified, blocking the solver from rearranging comparisons such as2*x <= xintox <= 0.SolveForInterval::visit(LE/GE): when solve_expression fails to fully isolate the variable, try a direct max/min decomposition on the LHS before falling back to fail(). The rules applied are:
max(a, b) <= c ⟺ a <= c && b <= c min(a, b) <= c ⟺ a <= c || b <= c max(a, b) * pos_c <= rhs ⟺ a*pos_c <= rhs && b*pos_c <= rhs min(a, b) * pos_c <= rhs ⟺ a*pos_c <= rhs || b*pos_c <= rhs(and symmetric >= variants)Together these enable two previously unhandled cases:
max(x, 1) * 2 <= x→Interval::nothing()(always false)max(abs(select(x < 0, f(x-1), 5)), 2) <= x→[2, +∞)(the constant branch forces x >= 2 even when f is opaque)These limitations were found by @stevenraphael
Checklist