Skip to content

Solve an inequality with x on both sides of ln, exp or sqrt (#2660) - #2663

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
both-sides-monotone-2660
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
both-sides-monotone-2660

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Solve threw NotSufficientlySupportedException for an inequality with x on both sides of a logarithm, an exponential or a square root. MonotoneInverted (#2586) read such a function only against a constant.

Fix

  • Same function on both sides: F(u) op F(v) is u op v wherever both are defined. This covers a logarithm or an exponential to one constant base, and a square root on each side. A base below 1 reverses the comparison.
  • Square root against an expression without one: the inequality is squared where both sides are nonnegative.
    • sqrt(u) < w is u >= 0, w > 0 and u < w^2.
    • sqrt(u) > w holds where u >= 0 and w < 0, or where w >= 0 and u > w^2.
.Solve("x") 2.10.0 / master this branch
sqrt(x + 5) <= x throws [(1 + sqrt(21))/2; +oo)
sqrt(4 - x) <= x - 1 throws [(1 + sqrt(13))/2; 4]
sqrt(x + 3) > x throws [-3; 0) \/ [0; (sqrt(13) + 1)/2)
exp(x) > exp(3x - 1) throws (-oo; 1/2)
ln(x) < ln(4 - x) throws (0; 2)
sqrt(x) < sqrt(2 - x) throws [0; 1)

Checks

  • Sweep: 230 generated inequalities (polynomial, rational, abs, ln, exp, sqrt), each answer checked against direct evaluation at 160 points across and between its boundaries.
    • On master: 188 correct, 42 throw, 0 wrong. All 42 throws are the shapes above.
    • On this branch: 226 correct and 0 throws.
    • The other 4 are flagged at x = -1000.5 only, for exp(x) > exp(3x - 1) and similar. There the evaluator answers exp(-1000.5) > exp(-3002.5) as False, because both sides underflow to 0. That is an evaluator defect that exists on master too, not a solver error.
  • New test: 15 cases, 7 exact and 8 checked at 21 points each. It fails all 15 on master.
  • Full UnitTests suite: 21880 passed, 0 failed, 13 skipped (net10.0).
  • Build: 0 errors for every target framework.

sqrt(x + 3) > x comes back as two adjacent intervals that are not merged. That is a separate cosmetic issue in set union.

Closes #2660.

🤖 Generated with Claude Code

Solve threw NotSufficientlySupportedException for an inequality with x
on both sides of a logarithm, an exponential or a square root.
MonotoneInverted (#2586) read such a function only against a constant.

F(u) op F(v), for the same strictly increasing F on both sides, is
u op v where both are defined: ln(u) < ln(v) is u > 0, v > 0 and u < v.
A base below 1 reverses the comparison. A square root against an
expression without one is squared where both sides are nonnegative.
sqrt(u) < w is u >= 0, w > 0 and u < w^2. sqrt(u) > w holds where
u >= 0 and w < 0, or w >= 0 and u > w^2. Each is then solved as those
polynomial or monotone inequalities.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.70%. Comparing base (f8a822d) to head (47e47ec).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 86.95% 0 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2663   +/-   ##
=======================================
  Coverage   86.70%   86.70%           
=======================================
  Files         346      346           
  Lines       75724    75761   +37     
  Branches    22145    22162   +17     
=======================================
+ Hits        65654    65689   +35     
  Misses       5431     5431           
- Partials     4639     4641    +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.20% <86.95%> (+<0.01%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ontinuous/Solvers/EquationSolver/SolveStatement.cs 83.66% <86.95%> (+0.13%) ⬆️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

An inequality with x on both sides of ln, exp or sqrt throws: sqrt(x + 5) <= x, exp(x) > exp(3x - 1)

1 participant