Skip to content

Commit 40b7e58

Browse files
A quotient of polynomials is solved as an inequality (#1539)
N/D > 0 holds exactly where N D > 0: D^2 is positive wherever the quotient is defined, and the product is zero at the poles, so the strict inequality leaves them out; the product is a polynomial the solver already reads. The pre-image of (1; +oo) under x/(1 + x) is (-oo; -1), where Sullivan and Mackey's §7.3.5 Try 1 says (-1, oo), and a pre-image whose inequality the solver cannot read stays written instead of throwing from its evaluation. A set difference meets another set through its minuend, and an interval meets a union of intervals piece by piece, so the quantifier over the reals decides §4.9.5's implication between two quotients. Part of #1409. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 8012530 commit 40b7e58

4 files changed

Lines changed: 109 additions & 1 deletion

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,25 @@ names are keywords now, and were names.
757757
| `preimage(x^2, x in RR, {1})` | `UnhandledParseException` | `{ 1, -1 }` |
758758
| `{ x in ZZ : x^2 in {1, 4} }` | `{ x in ZZ : x ^ 2 in { 1, 4 } }` — left as written | `{ 1, -1, 2, -2 }` |
759759

760+
### A quotient of polynomials is solved as an inequality
761+
762+
`"x/(1 + x) > 1".Solve("x")` threw `NotSufficientlySupportedException`; it is `(-oo; -1)`. A
763+
quotient `N/D > 0` holds exactly where `N D > 0`, since `D^2` is positive wherever the quotient is
764+
defined and the product is zero at its poles, and the product is a polynomial the solver reads. So
765+
`preimage(x/(1 + x), x in RR \ {-1}, (1; +oo))` is `(-oo; -1)`, where Sullivan and Mackey's
766+
§7.3.5 Try 1 gives `(-1, oo)`. A pre-image whose inequality the solver cannot read, `sin(x) > 0`,
767+
stays the set builder it is, where its evaluation threw. A set difference meets another set through
768+
its minuend, `(A \ B) /\ C = (A /\ C) \ B`, and an interval meets a union of intervals piece by
769+
piece. With both, a quantifier over the reals decides an implication between two quotients: §4.9.5's
770+
`x > 0 implies ((x - 3)/(x + 2) > 1 - 1/x implies (x + 3)/(x + 2) < 1 + 1/x)` is `True`
771+
([#1409](https://github.com/asc-community/AngouriMath/issues/1409)).
772+
773+
| Input | Was (2.5.0) | Now |
774+
|---|---|---|
775+
| `"x/(1 + x) > 1".Solve("x")` | `NotSufficientlySupportedException` | `(-oo; -1)` |
776+
| `"(RR \ {-1}) /\ (-oo; -1)".ToEntity().Evaled` | `(RR \ { -1 }) /\ (-oo; -1)` | `(-oo; -1)` |
777+
| `"preimage(sin(x), x in RR, (0; 1))".ToEntity().Evaled` | `UnhandledParseException`, and `NotSufficientlySupportedException` since `preimage` was added | the set builder, unsolved |
778+
760779
### An infinite base has its whole powers, and surjectivity is decided through the image
761780

762781
`(-oo)^3` was `NaN` — a claim that the value does not exist — and so were `(-oo)^2` and

‎Sources/AngouriMath/Functions/Continuous/Solvers/InequalitySolver/AnalyticalInequalitySolver.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using AngouriMath.Core.Exceptions;
99
using static AngouriMath.Entity;
10+
using static AngouriMath.Entity.Number;
1011
using static AngouriMath.Entity.Set;
1112

1213
namespace AngouriMath.Functions.Algebra.AnalyticalSolving
@@ -104,6 +105,15 @@ Set NeverZero() => ByLeadingSign(a, x, SpecialSet.Create(Domain.Real), Empty,
104105
// makes the root list complete, which is the whole difficulty.
105106
if (PolynomialSignTable.TrySolve(expr, x, out var bySign))
106107
return bySign;
108+
// A quotient of polynomials: N/D > 0 exactly where N D > 0, since D^2 is positive
109+
// wherever the quotient is defined and N D is zero where D is, so the strict
110+
// inequality leaves the poles out by itself. x/(1 + x) > 1 is -1/(1 + x) > 0, which
111+
// is -(1 + x) > 0, x < -1 -- the pre-image Sullivan and Mackey's §7.3.5 Try 1 gives
112+
// as (-1, oo), wrongly. The product is polynomial, so this recursion ends there.
113+
// https://github.com/asc-community/AngouriMath/issues/1409
114+
var (numerator, denominator) = SingleQuotient.Of(expr);
115+
if (denominator.ContainsNode(x) && denominator != Integer.One)
116+
return Solve(numerator * denominator, x);
107117
throw new NotSufficientlySupportedException(
108118
"Only polynomial inequalities are supported, and of those only the ones "
109119
+ "whose real roots can be established completely: linear and quadratic "

‎Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Website: https://am.angouri.org.
66
//
77

8+
using AngouriMath.Core.Exceptions;
89
using AngouriMath.Core.Sets;
910
using System;
1011
using System.Linq;
@@ -116,7 +117,17 @@ protected override Entity InnerSimplify(bool isExact)
116117
|| predicate is not Andf(Inf(var name, Set declared), Inf(var image, Set) membership)
117118
|| name != x || !image.ContainsNode(x) || image == x)
118119
return null;
119-
var solved = Functions.Algebra.AnalyticalSolving.StatementSolver.Solve(membership, x);
120+
// An inequality the solver cannot read -- sin(x) > 0 -- leaves the set as
121+
// written: an evaluation does not throw for a set it cannot list.
122+
Set solved;
123+
try
124+
{
125+
solved = Functions.Algebra.AnalyticalSolving.StatementSolver.Solve(membership, x);
126+
}
127+
catch (NotSufficientlySupportedException)
128+
{
129+
return null;
130+
}
120131
if (solved is ConditionalSet)
121132
return null;
122133
return declared.Intersect(solved).InnerSimplified(isExact);
@@ -170,6 +181,19 @@ protected override Entity InnerSimplify(bool isExact)
170181
// meet each other: regrouped, they do, and A meets one bounded interval.
171182
(Intersectionf(var rest, Interval one), Interval another)
172183
=> MathS.Intersection(rest, SetOperators.IntersectIntervalAndInterval(one, another)).InnerSimplified(isExact),
184+
// An interval meets a union of intervals piece by piece, which is what
185+
// an inequality's solution set is: (0; +oo) /\ ((-oo; -2) \/ (0; 1/2))
186+
// is (0; 1/2), where as written it met nothing it could read.
187+
(Interval interval, Unionf(var left, var right)) when left is Interval or FiniteSet && right is Interval or FiniteSet
188+
=> MathS.Union(MathS.Intersection(interval, left).InnerSimplified(isExact), MathS.Intersection(interval, right).InnerSimplified(isExact)).InnerSimplified(isExact),
189+
(Unionf(var left, var right), Interval interval) when left is Interval or FiniteSet && right is Interval or FiniteSet
190+
=> MathS.Union(MathS.Intersection(left, interval).InnerSimplified(isExact), MathS.Intersection(right, interval).InnerSimplified(isExact)).InnerSimplified(isExact),
191+
// (A \ B) /\ C is (A /\ C) \ B, where A meets C first: the pre-image
192+
// (RR \ { -1 }) /\ (-oo; -1) is (-oo; -1) \ { -1 }, which is the interval.
193+
(SetMinusf(var from, var removed), Set other) when other is not SetMinusf
194+
=> MathS.SetSubtraction(MathS.Intersection(from, other).InnerSimplified(isExact), removed).InnerSimplified(isExact),
195+
(Set other, SetMinusf(var from, var removed)) when other is not SetMinusf
196+
=> MathS.SetSubtraction(MathS.Intersection(other, from).InnerSimplified(isExact), removed).InnerSimplified(isExact),
173197
_ => null
174198
},
175199
(@this, a, b) => ((Intersectionf)@this).New(a, b), isExact, propagateSet: false);

‎Sources/Tests/UnitTests/Algebra/SolveTest/SolveInequality.cs‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,61 @@ private static void AssertSolvesLike(string inequality, string value)
5858
+ $"{symbolic}, which disagrees with the inequality itself at x = {point}");
5959
}
6060

61+
/// <summary>
62+
/// A quotient of polynomials is solved as the product of its numerator and denominator,
63+
/// which has the quotient's sign wherever the quotient is defined and is zero at its
64+
/// poles. Sullivan and Mackey's §7.3.5 Try 1 asks for the pre-image of <c>(1, oo)</c> under
65+
/// <c>x/(1 + x)</c>, which is <c>(-oo, -1)</c> where the book says <c>(-1, oo)</c>. Checked at
66+
/// points, the poles among them, where the inequality holds nowhere.
67+
/// <a href="https://github.com/asc-community/AngouriMath/issues/1409">#1409</a>
68+
/// </summary>
69+
[Theory]
70+
[InlineData("x / (1 + x) > 1")]
71+
[InlineData("(x - 1) / (x + 2) > 0")]
72+
[InlineData("(x - 1) / (x + 2) >= 0")]
73+
[InlineData("(x - 1) / (x + 2) <= 0")]
74+
[InlineData("1 / x < 2")]
75+
[InlineData("(x^2 - 4) / (x - 1) < 0")]
76+
[InlineData("x / (x^2 + 1) > 1/3")]
77+
[InlineData("(x - 3) / (x + 2) > 1 - 1 / x")]
78+
public void AQuotientOfPolynomialsIsSolved(string inequality)
79+
{
80+
Variable x = "x";
81+
var solved = (Set)((Entity)inequality).Solve(x).Simplify();
82+
foreach (var point in new Entity[] { -7, -3, -2, "-3/2".ToEntity(), -1, "-1/2".ToEntity(), 0,
83+
"1/2".ToEntity(), 1, "3/2".ToEntity(), 2, 3, 7 })
84+
{
85+
var holds = ((Entity)inequality).Substitute(x, point).Evaled is Boolean(true);
86+
Assert.True(solved.TryContains(point, out var contains), $"{solved} does not decide {point}");
87+
Assert.True(contains == holds, $"solving {inequality} gives {solved}, which disagrees with the inequality at x = {point}");
88+
}
89+
}
90+
91+
/// <summary>
92+
/// §4.9.5: an implication between two rational inequalities under a hypothesis, decided by
93+
/// solving where it fails, and its converse refuted at <c>x = 1</c> as the book does.
94+
/// </summary>
95+
[Theory]
96+
[InlineData("forall x in RR : x > 0 implies ((x - 3)/(x + 2) > 1 - 1/x implies (x + 3)/(x + 2) < 1 + 1/x)", true)]
97+
[InlineData("forall x in RR : x > 0 implies ((x + 3)/(x + 2) < 1 + 1/x implies (x - 3)/(x + 2) > 1 - 1/x)", false)]
98+
public void AnImplicationBetweenQuotientsIsDecided(string statement, bool holds)
99+
=> Assert.Equal(holds ? Boolean.True : Boolean.False, statement.ToEntity().Evaled);
100+
101+
[Fact]
102+
public void ThePreImageTheBookGetsWrong()
103+
=> Assert.Equal("(-oo; -1)".ToEntity().Evaled, "preimage(x / (1 + x), x in RR \\ { -1 }, (1; +oo))".ToEntity().Evaled);
104+
105+
/// <summary>
106+
/// A pre-image whose inequality the solver cannot read stays the set builder it is, and
107+
/// the evaluation does not throw: <c>sin(x) &gt; 0</c> is no polynomial.
108+
/// </summary>
109+
[Fact]
110+
public void AnUnreadPreImageDoesNotThrow()
111+
{
112+
var preimage = "preimage(sin(x), x in RR, (0; 1))".ToEntity();
113+
Assert.IsType<ConditionalSet>(preimage.Evaled);
114+
}
115+
61116
[Theory]
62117
[InlineData("(x - a)(x + a) <= 0", "3")]
63118
[InlineData("(x - a)(x + a) <= 0", "-3")]

0 commit comments

Comments
 (0)