Skip to content

Commit 8207731

Browse files
A quotient of polynomials is one-to-one where it is strictly monotone, and a family of intervals with monotone ends is an interval (#1574)
* A quotient of polynomials is one-to-one on an interval where it is strictly monotone forall a in S : forall b in S : f(a) = f(b) implies a = b, one-to-one on S (Sullivan and Mackey's Def 7.4.1), is decided for a quotient of polynomials on an interval by the sign of its derivative between the zeros inside: x^3 is one-to-one on RR, x^2 on [0; +oo) and not on RR, and a cubic with two turning points is not. On the whole numbers only a yes carries over from the interval around them. Part of #1409. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura * A family of intervals with monotone ends is the interval between their extremes union(A_n, n in I) and intersection(A_n, n in I) of intervals whose ends are quotients of polynomials in the index, monotone over its range, are evaluated to the interval between the extremes of the ends: an intersection always, a union where the family is a chain or the index runs over an interval. Sullivan and Mackey's §3.9.5 Try 8-10: the intersection of (-1/n; 1/n) over ZZ+ is { 0 }, the union of (x; x + 1) over (0; 1) is (0; 2), and the union of [0; (n - 1)/n) is [0; 1), the intersection of (-1/n; 1). The one-to-one test becomes Monotone, which both read. Part of #1409. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ecc9d01 commit 8207731

6 files changed

Lines changed: 280 additions & 0 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,39 @@ onto `B`, Sullivan and Mackey's Def 7.4.1, [#1409](https://github.com/asc-commun
903903
| `(-oo)^2` | `NaN` — wrong | `+oo` |
904904
| `forall b in RR : exists a in RR : a^3 = b` | `UnhandledParseException` (quantifiers are new since; left as written when they arrived) | `True` |
905905
| `forall b in RR : exists a in RR : e^a = b` | `UnhandledParseException` | `False` |
906+
907+
### One-to-one is decided for a quotient of polynomials on an interval
908+
909+
`forall a in S : forall b in S : f(a) = f(b) implies a = b` — `f` one-to-one on `S`, Sullivan and
910+
Mackey's Def 7.4.1 — is decided for a quotient of polynomials on an interval by the sign of its
911+
derivative between the zeros inside: strictly monotone is one-to-one, and a turn is not. The cube
912+
is one-to-one on the reals although its derivative is zero at 0; the square is on `[0; +oo)`. On the
913+
whole numbers only a yes carries over from the interval around them
914+
([#1409](https://github.com/asc-community/AngouriMath/issues/1409)).
915+
916+
| Input | Was (2.5.0) | Now |
917+
|---|---|---|
918+
| `forall a in RR : forall b in RR : a^3 = b^3 implies a = b` | `UnhandledParseException` (left as written when quantifiers arrived) | `True` |
919+
| `forall a in [0; +oo) : forall b in [0; +oo) : a^2 = b^2 implies a = b` | `UnhandledParseException` (left as written when quantifiers arrived) | `True` |
920+
| `forall a in RR : forall b in RR : a^3 - 3 a = b^3 - 3 b implies a = b` | `UnhandledParseException` | `False` |
921+
922+
### A family of intervals with monotone ends is the interval between their extremes
923+
924+
`union(A_n, n in I)` and `intersection(A_n, n in I)` of intervals whose ends are quotients of
925+
polynomials in the index, monotone over its range, are the interval between the extremes of the
926+
ends: an intersection always, a union where the family is a chain or the index runs over an
927+
interval. An end is closed where the family's ends are and the extreme is reached, or, in an
928+
intersection, where it is only approached. Sullivan and Mackey's §3.9.5 Try 8–10: the intersection
929+
of `(-1/n; 1/n)` over `ZZ+` is `{ 0 }`, the union of `(x; x + 1)` over `(0; 1)` is `(0; 2)`, and
930+
the union of `[0; (n - 1)/n)` is `[0; 1)`, which is the intersection of `(-1/n; 1)`
931+
([#1409](https://github.com/asc-community/AngouriMath/issues/1409)).
932+
933+
| Input | Was (2.5.0) | Now |
934+
|---|---|---|
935+
| `intersection((-1/n; 1/n), n in ZZ+)` | `UnhandledParseException` (left as written when families arrived) | `{ 0 }` |
936+
| `union((x; x + 1), x in (0; 1))` | `UnhandledParseException` (left as written when families arrived) | `(0; 2)` |
937+
| `union([0; (n - 1)/n), n in ZZ+) = intersection((-1/n; 1), n in ZZ+)` | `UnhandledParseException` | `True` |
938+
906939
### The binomial coefficient's identities, and its sums in closed form
907940

908941
Pascal's rule, the chairperson identity and the symmetry are rewrite rules, each in the direction

‎Sources/AngouriMath/Functions/Boolean/Quantifiers.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,23 @@ private static Entity Quantified(Kind kind, Entity var, Entity over, Entity body
259259
return covered;
260260
}
261261
}
262+
// forall a in S : forall b in S : f(a) = f(b) implies a = b is the statement that f is
263+
// one-to-one on S (Sullivan and Mackey's Def 7.4.1), which a quotient of polynomials is
264+
// on an interval exactly where it is strictly monotone there: x^3 on RR is, x^2 on RR is
265+
// not. On the whole numbers only a yes carries over from the interval they lie in,
266+
// since x^2 is one-to-one on ZZ+ and not monotone on RR.
267+
// https://github.com/asc-community/AngouriMath/issues/1409
268+
if (kind == Kind.All && body is Forallf(Variable twin, Set twinSet, Impliesf(Equalsf(var atThis, var atTwin), Equalsf(var sideA, var sideB)))
269+
&& twinSet == set && twin != x && (sideA == x && sideB == twin || sideA == twin && sideB == x)
270+
&& (atTwin == atThis.Substitute(x, twin) ? atThis : atThis == atTwin.Substitute(x, twin) ? atTwin : null) is { } mapping
271+
&& (set is SpecialSet wholeSet && IsIntegerSet(wholeSet) ? IntervalAround(wholeSet) : set) is { } around
272+
&& Functions.ImageByCalculus.OneToOne(mapping, x, around) is { } oneToOne && (oneToOne || around == set))
273+
{
274+
by = oneToOne
275+
? ($"{mapping} is strictly monotone on {around}, so it is one-to-one", "StrictMono.injective")
276+
: ($"{mapping} turns inside {set}, so two members share a value", "intermediate_value_Icc");
277+
return oneToOne ? Entity.Boolean.True : Entity.Boolean.False;
278+
}
262279
// An equation whose two sides differ by a polynomial that expands to nothing holds
263280
// at every member, whatever the set: (x + 1)^2 = x^2 + 2 x + 1 is True of each.
264281
if (body is Equalsf(var left, var right))
@@ -1507,6 +1524,16 @@ private static IEnumerable<Entity> Candidates(Set set)
15071524
0, 1, -1, 2, -2, 10, -10, Rational.Create(1, 2), Rational.Create(-1, 2),
15081525
};
15091526

1527+
/// <summary>The interval a set of whole numbers lies in, or <see langword="null"/>.</summary>
1528+
private static Set? IntervalAround(SpecialSet whole)
1529+
=> whole switch
1530+
{
1531+
SpecialSet.Integers => new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false),
1532+
SpecialSet.NonNegativeIntegers => new Interval(Integer.Zero, true, Real.PositiveInfinity, false),
1533+
SpecialSet.PositiveIntegers or SpecialSet.Primes => new Interval(Integer.One, true, Real.PositiveInfinity, false),
1534+
_ => null,
1535+
};
1536+
15101537
private static Entity? BySolving(Kind kind, Variable x, Set set, Entity body)
15111538
{
15121539
// The inequality solver answers over the reals, so an order comparison is asked

‎Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,177 @@ internal static class ImageByCalculus
8585
_ => null,
8686
};
8787

88+
/// <summary>
89+
/// Whether a quotient of polynomials is one-to-one on an interval, or <see langword="null"/>
90+
/// where that is not settled here. A continuous function on an interval is one-to-one
91+
/// exactly where it is strictly monotone: <c>x^3</c> on <c>RR</c> is, and <c>x^2</c> on
92+
/// <c>RR</c> is not. Sullivan and Mackey's Def 7.4.1.
93+
/// </summary>
94+
internal static bool? OneToOne(Entity f, Variable x, Entity over)
95+
=> Monotone(f, x, over) switch
96+
{
97+
null => null,
98+
0 => false,
99+
_ => true,
100+
};
101+
102+
/// <summary>
103+
/// The direction a quotient of polynomials runs in on an interval: <c>1</c> where it is
104+
/// strictly increasing, <c>-1</c> where strictly decreasing, <c>0</c> where it is neither,
105+
/// and <see langword="null"/> where that is not settled here. A differentiable function is
106+
/// strictly monotone exactly where its derivative keeps one sign away from the points
107+
/// where it is zero: the derivative of <c>x^3</c> is zero at 0 and positive on either
108+
/// side, and that of <c>x^2</c> changes sign at 0. A pole inside the interval leaves it
109+
/// unsettled.
110+
/// </summary>
111+
internal static int? Monotone(Entity f, Variable x, Entity over)
112+
{
113+
if (!f.ContainsNode(x) || !IsRational(f, x) || Pieces(over) is not { Count: 1 } pieces)
114+
return null;
115+
var piece = pieces[0];
116+
var (numerator, denominator) = SingleQuotient.Of(f);
117+
var slope = numerator.Differentiate(x) * denominator - numerator * denominator.Differentiate(x);
118+
if (Polynomial(denominator, x) is not { } bottom || Polynomial(slope, x) is not { } top
119+
|| RealRoots(bottom, x) is not { } poles || RealRoots(top, x) is not { } critical
120+
|| AsReal(piece.Left) is not { } left || AsReal(piece.Right) is not { } right || left.CompareTo(right) >= 0
121+
|| poles.Any(pole => pole.Value.CompareTo(left) > 0 && pole.Value.CompareTo(right) < 0))
122+
return null;
123+
// The derivative's sign between each two consecutive of the ends and the zeros
124+
// inside, which is its numerator's, the denominator being a square.
125+
var ends = new List<Real> { left };
126+
ends.AddRange(critical.Select(point => point.Value).Where(at => at.CompareTo(left) > 0 && at.CompareTo(right) < 0).OrderBy(at => at));
127+
ends.Add(right);
128+
int? sign = null;
129+
for (var i = 0; i + 1 < ends.Count; i++)
130+
{
131+
if (AsReal(top.Substitute(x, Between(ends[i], ends[i + 1]))) is not { IsFinite: true } value)
132+
return null;
133+
var here = value.EDecimal.Sign;
134+
// Zero on a whole stretch is a constant there, and a change of sign a turn.
135+
if (here == 0 || sign is { } before && before != here)
136+
return 0;
137+
sign = here;
138+
}
139+
return sign;
140+
}
141+
142+
/// <summary>
143+
/// A union or an intersection of a family of intervals whose ends are quotients of
144+
/// polynomials in the index, monotone over its range, as the interval between the extremes
145+
/// of the ends; <see langword="null"/> where that is not settled here. Sullivan and
146+
/// Mackey's §3.9.5: the intersection of <c>(-1/n, 1/n)</c> over the positive whole numbers
147+
/// is <c>{0}</c>, the union of <c>(x, x + 1)</c> over <c>(0, 1)</c> is <c>(0, 2)</c>, and
148+
/// the union of <c>[0, (n - 1)/n)</c> is <c>[0, 1)</c>, the intersection of <c>(-1/n, 1)</c>.
149+
/// </summary>
150+
/// <remarks>
151+
/// <para>
152+
/// An intersection of intervals is an interval, from the supremum of the left ends to the
153+
/// infimum of the right ones. An end of it is closed where the family's ends are, and where
154+
/// the extreme is only approached: every <c>(-1/n, 1/n)</c> holds 0, where both ends tend.
155+
/// </para>
156+
/// <para>
157+
/// A union is an interval from the infimum of the left ends to the supremum of the right
158+
/// ones where the family is a chain, each member inside the next -- ends moving apart, or
159+
/// one still -- and where the index runs over an interval and every member is not empty,
160+
/// so that the members overlap as it moves. Over the whole numbers a sliding family,
161+
/// <c>(k, k + 1)</c>, leaves gaps, and is not read. An end of the union is closed where the
162+
/// family's ends are and the extreme is reached.
163+
/// </para>
164+
/// <para>
165+
/// A monotone end has its extremes at the ends of the index's range: at a least or a
166+
/// greatest member, where it is reached, and in the limit, where it is not.
167+
/// </para>
168+
/// </remarks>
169+
internal static Set? Family(bool union, Interval member, Variable k, Entity over)
170+
{
171+
if (Range(over) is not var (range, whole)
172+
|| Extremes(member.Left, k, range) is not var (leftLow, leftHigh, leftDirection)
173+
|| Extremes(member.Right, k, range) is not var (rightLow, rightHigh, rightDirection))
174+
return null;
175+
(Entity Value, bool Closed) lower, upper;
176+
if (union)
177+
{
178+
var chain = leftDirection <= 0 && rightDirection >= 0 || leftDirection >= 0 && rightDirection <= 0;
179+
if (!chain && (whole || !NeverEmpty(member, k, range)))
180+
return null;
181+
lower = (leftLow.Value, member.LeftClosed && leftLow.Reached);
182+
upper = (rightHigh.Value, member.RightClosed && rightHigh.Reached);
183+
}
184+
else
185+
{
186+
lower = (leftHigh.Value, member.LeftClosed || !leftHigh.Reached);
187+
upper = (rightLow.Value, member.RightClosed || !rightLow.Reached);
188+
}
189+
if (AsReal(lower.Value) is not { IsNaN: false } from || AsReal(upper.Value) is not { IsNaN: false } to)
190+
return null;
191+
// Simplified, so that [0; 0] is the point it is and (0; 0) nothing.
192+
return new Interval(lower.Value, lower.Closed && from.IsFinite, upper.Value, upper.Closed && to.IsFinite).InnerSimplified as Set;
193+
}
194+
195+
/// <summary>The index's range as an interval, and whether the index is a whole number.</summary>
196+
private static (Interval Range, bool Whole)? Range(Entity over)
197+
=> over switch
198+
{
199+
SpecialSet.PositiveIntegers => (new Interval(Integer.One, true, Real.PositiveInfinity, false), true),
200+
SpecialSet.NonNegativeIntegers => (new Interval(Integer.Zero, true, Real.PositiveInfinity, false), true),
201+
SpecialSet.Integers => (new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false), true),
202+
SpecialSet.Reals => (new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false), false),
203+
Interval interval when interval.IsNumeric => (interval, false),
204+
_ => null,
205+
};
206+
207+
/// <summary>
208+
/// The least and the greatest of an end over the range, each with whether it is reached,
209+
/// and the end's direction, <c>0</c> for one that does not move; <see langword="null"/>
210+
/// where the end is not monotone there.
211+
/// </summary>
212+
private static ((Entity Value, bool Reached) Low, (Entity Value, bool Reached) High, int Direction)? Extremes(Entity end, Variable k, Interval range)
213+
{
214+
if (!end.ContainsNode(k))
215+
return ((end, true), (end, true), 0);
216+
if (Monotone(end, k, range) is not { } direction || direction == 0)
217+
return null;
218+
if (At(end, k, range.Left, range.LeftClosed, Core.ApproachFrom.Right) is not { } atStart
219+
|| At(end, k, range.Right, range.RightClosed, Core.ApproachFrom.Left) is not { } atEnd)
220+
return null;
221+
return direction > 0 ? (atStart, atEnd, 1) : (atEnd, atStart, -1);
222+
}
223+
224+
/// <summary>The end's value at an end of the range, reached, or its limit there, not reached.</summary>
225+
private static (Entity Value, bool Reached)? At(Entity end, Variable k, Entity at, bool included, Core.ApproachFrom side)
226+
{
227+
if (AsReal(at) is not { } point)
228+
return null;
229+
if (included && point.IsFinite)
230+
return (end.Substitute(k, at).Simplify(), true);
231+
var limit = point.IsFinite ? end.Limit(k, at, side) : end.Limit(k, at);
232+
return AsReal(limit) is { IsNaN: false } ? (limit, false) : null;
233+
}
234+
235+
/// <summary>Whether every member of a family is not empty: its right end above its left one over the whole range.</summary>
236+
private static bool NeverEmpty(Interval member, Variable k, Interval range)
237+
{
238+
var width = (member.Right - member.Left).Simplify();
239+
if (!width.ContainsNode(k))
240+
return AsReal(width) is { } constant && constant.EDecimal.Sign > 0;
241+
return Of(width, k, range) switch
242+
{
243+
Interval { Left: var least, LeftClosed: var reached } => AsReal(least) is { } bound && (bound.EDecimal.Sign > 0 || bound.EDecimal.Sign == 0 && !reached),
244+
FiniteSet { Count: 1 } single => AsReal(single.First()) is { } only && only.EDecimal.Sign > 0,
245+
_ => false,
246+
};
247+
}
248+
249+
/// <summary>A point strictly between two ends, either of which may be infinite.</summary>
250+
private static Entity Between(Real low, Real high)
251+
=> (low.IsFinite, high.IsFinite) switch
252+
{
253+
(true, true) => ((Entity)low + high) / 2,
254+
(true, false) => (Entity)low + 1,
255+
(false, true) => (Entity)high - 1,
256+
_ => Integer.Zero,
257+
};
258+
88259
/// <summary>The image of one interval with no pole inside.</summary>
89260
private static Set? Of(Entity f, Variable x, Interval piece, List<(Entity Root, Real Value)> critical)
90261
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ protected override Entity InnerSimplify(bool isExact)
241241
if (this is IndexedUnionf && Var is Variable name && body is FiniteSet { Count: 1 } single
242242
&& Functions.ImageByCalculus.Of(single.First(), name, over) is { } byCalculus)
243243
return byCalculus;
244+
// A family of intervals whose ends are monotone in the index, as the interval
245+
// between the extremes of its ends: the intersection of (-1/n; 1/n) over ZZ+ is
246+
// { 0 }. https://github.com/asc-community/AngouriMath/issues/1409
247+
if (Var is Variable familyIndex && body is Interval familyMember
248+
&& Functions.ImageByCalculus.Family(this is IndexedUnionf, familyMember, familyIndex, over) is { } family)
249+
return family;
244250
if (over is FiniteSet indices)
245251
{
246252
if (indices.Count == 0)

‎Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ public void AFamilyOverAListedIndexSetIsFolded(string expression, string expecte
6666
public void MembershipOfAnInfiniteFamilyIsDecidedByTheQuantifiers(string expression, string expected)
6767
=> Assert.Equal(expected.ToEntity(), Evaluated(expression));
6868

69+
/// <summary>
70+
/// A family of intervals whose ends are monotone in the index is the interval between the
71+
/// extremes of its ends, closed where they are reached, or approached by the ends of an
72+
/// intersection: Sullivan and Mackey's §3.9.5 Try 8–10, and growing and shrinking families.
73+
/// A sliding family over the whole numbers leaves gaps and stays a family.
74+
/// </summary>
75+
[Theory]
76+
[InlineData("intersection((-1/n; 1/n), n in ZZ+)", "{0}")]
77+
[InlineData("union((x; x + 1), x in (0; 1))", "(0; 2)")]
78+
[InlineData("union([0; (n - 1)/n), n in ZZ+)", "[0; 1)")]
79+
[InlineData("intersection((-1/n; 1), n in ZZ+)", "[0; 1)")]
80+
[InlineData("intersection([0; 1/n), n in ZZ+)", "{0}")]
81+
[InlineData("union([1/n; 1], n in ZZ+)", "(0; 1]")]
82+
[InlineData("union([1; (k + 1)/k], k in ZZ+)", "[1; 2]")]
83+
public void AFamilyWithMonotoneEndsIsAnInterval(string expression, string expected)
84+
=> Assert.Equal(expected.ToEntity().Evaled, Evaluated(expression));
85+
86+
[Fact]
87+
public void TwoFamiliesAreEqualWhereTheirIntervalsAre()
88+
{
89+
Assert.Equal(Entity.Boolean.True, Evaluated("union([0; (n - 1)/n), n in ZZ+) = intersection((-1/n; 1), n in ZZ+)"));
90+
var sliding = "union((n; n + 1), n in ZZ+)".ToEntity();
91+
Assert.Equal(sliding, sliding.Evaled);
92+
}
93+
6994
/// <summary>Ex 3.5.11: the complement of a set in a universe is the universe less the set.</summary>
7095
[Theory]
7196
[InlineData("complement({1, 2}, ZZ+ /\\ [1; 5])", "{3, 4, 5}")]

0 commit comments

Comments
 (0)