From 80452d4adcd8560e69422d2916136fc0f2901719 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 28 Sep 2026 22:35:24 +0000 Subject: [PATCH 1/2] 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) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 16 ++++++ .../Functions/Boolean/Quantifiers.cs | 27 ++++++++++ .../Functions/Continuous/ImageByCalculus.cs | 50 +++++++++++++++++++ .../Tests/UnitTests/Core/SurjectivityTest.cs | 18 +++++++ 4 files changed, 111 insertions(+) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 8a3ed02c4..00094fab1 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -885,6 +885,22 @@ onto `B`, Sullivan and Mackey's Def 7.4.1, [#1409](https://github.com/asc-commun | `(-oo)^2` | `NaN` — wrong | `+oo` | | `forall b in RR : exists a in RR : a^3 = b` | `UnhandledParseException` (quantifiers are new since; left as written when they arrived) | `True` | | `forall b in RR : exists a in RR : e^a = b` | `UnhandledParseException` | `False` | + +### One-to-one is decided for a quotient of polynomials on an interval + +`forall a in S : forall b in S : f(a) = f(b) implies a = b` — `f` 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: strictly monotone is one-to-one, and a turn is not. The cube +is one-to-one on the reals although its derivative is zero at 0; the square is on `[0; +oo)`. On the +whole numbers only a yes carries over from the interval around them +([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `forall a in RR : forall b in RR : a^3 = b^3 implies a = b` | `UnhandledParseException` (left as written when quantifiers arrived) | `True` | +| `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` | +| `forall a in RR : forall b in RR : a^3 - 3 a = b^3 - 3 b implies a = b` | `UnhandledParseException` | `False` | + ### The binomial coefficient's identities, and its sums in closed form Pascal's rule, the chairperson identity and the symmetry are rewrite rules, each in the direction diff --git a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs index 8a1b60566..edc69bb0c 100644 --- a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs +++ b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs @@ -259,6 +259,23 @@ private static Entity Quantified(Kind kind, Entity var, Entity over, Entity body return covered; } } + // forall a in S : forall b in S : f(a) = f(b) implies a = b is the statement that f is + // one-to-one on S (Sullivan and Mackey's Def 7.4.1), which a quotient of polynomials is + // on an interval exactly where it is strictly monotone there: x^3 on RR is, x^2 on RR is + // not. On the whole numbers only a yes carries over from the interval they lie in, + // since x^2 is one-to-one on ZZ+ and not monotone on RR. + // https://github.com/asc-community/AngouriMath/issues/1409 + if (kind == Kind.All && body is Forallf(Variable twin, Set twinSet, Impliesf(Equalsf(var atThis, var atTwin), Equalsf(var sideA, var sideB))) + && twinSet == set && twin != x && (sideA == x && sideB == twin || sideA == twin && sideB == x) + && (atTwin == atThis.Substitute(x, twin) ? atThis : atThis == atTwin.Substitute(x, twin) ? atTwin : null) is { } mapping + && (set is SpecialSet wholeSet && IsIntegerSet(wholeSet) ? IntervalAround(wholeSet) : set) is { } around + && Functions.ImageByCalculus.OneToOne(mapping, x, around) is { } oneToOne && (oneToOne || around == set)) + { + by = oneToOne + ? ($"{mapping} is strictly monotone on {around}, so it is one-to-one", "StrictMono.injective") + : ($"{mapping} turns inside {set}, so two members share a value", "intermediate_value_Icc"); + return oneToOne ? Entity.Boolean.True : Entity.Boolean.False; + } // An equation whose two sides differ by a polynomial that expands to nothing holds // at every member, whatever the set: (x + 1)^2 = x^2 + 2 x + 1 is True of each. if (body is Equalsf(var left, var right)) @@ -1507,6 +1524,16 @@ private static IEnumerable Candidates(Set set) 0, 1, -1, 2, -2, 10, -10, Rational.Create(1, 2), Rational.Create(-1, 2), }; + /// The interval a set of whole numbers lies in, or . + private static Set? IntervalAround(SpecialSet whole) + => whole switch + { + SpecialSet.Integers => new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false), + SpecialSet.NonNegativeIntegers => new Interval(Integer.Zero, true, Real.PositiveInfinity, false), + SpecialSet.PositiveIntegers or SpecialSet.Primes => new Interval(Integer.One, true, Real.PositiveInfinity, false), + _ => null, + }; + private static Entity? BySolving(Kind kind, Variable x, Set set, Entity body) { // The inequality solver answers over the reals, so an order comparison is asked diff --git a/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs b/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs index 8917e9baf..a13896b68 100644 --- a/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs +++ b/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs @@ -85,6 +85,56 @@ internal static class ImageByCalculus _ => null, }; + /// + /// Whether a quotient of polynomials is one-to-one on an interval, or + /// where that is not settled here. A continuous function on an interval is one-to-one + /// exactly where it is strictly monotone, and a differentiable one is exactly where its + /// derivative keeps one sign away from the points where it is zero: x^3 on + /// RR, whose derivative is zero at 0 and positive on either side, is one-to-one, + /// and x^2 on RR, whose derivative changes sign at 0, is not. A pole inside + /// the interval leaves it unsettled. Sullivan and Mackey's Def 7.4.1. + /// + internal static bool? OneToOne(Entity f, Variable x, Entity over) + { + if (!f.ContainsNode(x) || !IsRational(f, x) || Pieces(over) is not { Count: 1 } pieces) + return null; + var piece = pieces[0]; + var (numerator, denominator) = SingleQuotient.Of(f); + var slope = numerator.Differentiate(x) * denominator - numerator * denominator.Differentiate(x); + if (Polynomial(denominator, x) is not { } bottom || Polynomial(slope, x) is not { } top + || RealRoots(bottom, x) is not { } poles || RealRoots(top, x) is not { } critical + || AsReal(piece.Left) is not { } left || AsReal(piece.Right) is not { } right || left.CompareTo(right) >= 0 + || poles.Any(pole => pole.Value.CompareTo(left) > 0 && pole.Value.CompareTo(right) < 0)) + return null; + // The derivative's sign between each two consecutive of the ends and the zeros + // inside, which is its numerator's, the denominator being a square. + var ends = new List { left }; + ends.AddRange(critical.Select(point => point.Value).Where(at => at.CompareTo(left) > 0 && at.CompareTo(right) < 0).OrderBy(at => at)); + ends.Add(right); + int? sign = null; + for (var i = 0; i + 1 < ends.Count; i++) + { + if (AsReal(top.Substitute(x, Between(ends[i], ends[i + 1]))) is not { IsFinite: true } value) + return null; + var here = value.EDecimal.Sign; + // Zero on a whole stretch is a constant there, and a change of sign a turn. + if (here == 0 || sign is { } before && before != here) + return false; + sign = here; + } + return true; + } + + /// A point strictly between two ends, either of which may be infinite. + private static Entity Between(Real low, Real high) + => (low.IsFinite, high.IsFinite) switch + { + (true, true) => ((Entity)low + high) / 2, + (true, false) => (Entity)low + 1, + (false, true) => (Entity)high - 1, + _ => Integer.Zero, + }; + /// The image of one interval with no pole inside. private static Set? Of(Entity f, Variable x, Interval piece, List<(Entity Root, Real Value)> critical) { diff --git a/Sources/Tests/UnitTests/Core/SurjectivityTest.cs b/Sources/Tests/UnitTests/Core/SurjectivityTest.cs index 8175096f2..767e4c438 100644 --- a/Sources/Tests/UnitTests/Core/SurjectivityTest.cs +++ b/Sources/Tests/UnitTests/Core/SurjectivityTest.cs @@ -45,6 +45,24 @@ public sealed class SurjectivityTest public void SurjectivityIsTheImageCoveringTheCodomain(string statement, string expected) => Assert.Equal(expected.ToEntity(), statement.ToEntity().Evaled); + /// + /// forall a in A : forall b in A : f(a) = f(b) implies a = b -- one-to-one, Def 7.4.1 + /// -- for a quotient of polynomials on an interval, by the sign of its derivative: the cube + /// is one-to-one on the reals though its derivative is zero at 0, the square is on + /// [0, +oo) and not on the reals, and a cubic with two turning points is not. On + /// the whole numbers only a yes carries over from the interval around them. + /// + [Theory] + [InlineData("forall a in RR : forall b in RR : a^3 = b^3 implies a = b", "True")] + [InlineData("forall a in [0; +oo) : forall b in [0; +oo) : a^2 = b^2 implies a = b", "True")] + [InlineData("forall a in RR : forall b in RR : a^2 = b^2 implies a = b", "False")] + [InlineData("forall a in RR : forall b in RR : a^3 - 3 a = b^3 - 3 b implies a = b", "False")] + [InlineData("forall a in (-1; 1) : forall b in (-1; 1) : a/(1 + a^2) = b/(1 + b^2) implies a = b", "True")] + [InlineData("forall a in ZZ+ : forall b in ZZ+ : a^2 = b^2 implies a = b", "True")] + [InlineData("forall a in (0; +oo) : forall b in (0; +oo) : 1/a = 1/b implies a = b", "True")] + public void OneToOneIsMonotonicity(string statement, string expected) + => Assert.Equal(expected.ToEntity(), statement.ToEntity().Evaled); + /// The extended reals' whole powers: by parity for -oo, and 0 for a negative exponent. Each was NaN. [Theory] [InlineData("(-oo)^3", "-oo")] From 896f2a64b4cebb04412131012f3a60dad9302ab7 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 28 Sep 2026 22:58:41 +0000 Subject: [PATCH 2/2] A family of intervals with monotone ends is the interval between their extremes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 17 +++ .../Functions/Continuous/ImageByCalculus.cs | 137 +++++++++++++++++- .../Evaluation.Omni.Classes.cs | 6 + .../Core/Sets/IndexedSetOperationTest.cs | 25 ++++ 4 files changed, 177 insertions(+), 8 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 00094fab1..3e4dad131 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -901,6 +901,23 @@ whole numbers only a yes carries over from the interval around them | `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` | | `forall a in RR : forall b in RR : a^3 - 3 a = b^3 - 3 b implies a = b` | `UnhandledParseException` | `False` | +### 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 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. An end is closed where the family's ends are and the extreme is reached, or, in an +intersection, where it is only approached. 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)`, which is the intersection of `(-1/n; 1)` +([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `intersection((-1/n; 1/n), n in ZZ+)` | `UnhandledParseException` (left as written when families arrived) | `{ 0 }` | +| `union((x; x + 1), x in (0; 1))` | `UnhandledParseException` (left as written when families arrived) | `(0; 2)` | +| `union([0; (n - 1)/n), n in ZZ+) = intersection((-1/n; 1), n in ZZ+)` | `UnhandledParseException` | `True` | + ### The binomial coefficient's identities, and its sums in closed form Pascal's rule, the chairperson identity and the symmetry are rewrite rules, each in the direction diff --git a/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs b/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs index a13896b68..beef968e2 100644 --- a/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs +++ b/Sources/AngouriMath/Functions/Continuous/ImageByCalculus.cs @@ -88,13 +88,27 @@ internal static class ImageByCalculus /// /// Whether a quotient of polynomials is one-to-one on an interval, or /// where that is not settled here. A continuous function on an interval is one-to-one - /// exactly where it is strictly monotone, and a differentiable one is exactly where its - /// derivative keeps one sign away from the points where it is zero: x^3 on - /// RR, whose derivative is zero at 0 and positive on either side, is one-to-one, - /// and x^2 on RR, whose derivative changes sign at 0, is not. A pole inside - /// the interval leaves it unsettled. Sullivan and Mackey's Def 7.4.1. + /// exactly where it is strictly monotone: x^3 on RR is, and x^2 on + /// RR is not. Sullivan and Mackey's Def 7.4.1. /// internal static bool? OneToOne(Entity f, Variable x, Entity over) + => Monotone(f, x, over) switch + { + null => null, + 0 => false, + _ => true, + }; + + /// + /// The direction a quotient of polynomials runs in on an interval: 1 where it is + /// strictly increasing, -1 where strictly decreasing, 0 where it is neither, + /// and where that is not settled here. A differentiable function is + /// strictly monotone exactly where its derivative keeps one sign away from the points + /// where it is zero: the derivative of x^3 is zero at 0 and positive on either + /// side, and that of x^2 changes sign at 0. A pole inside the interval leaves it + /// unsettled. + /// + internal static int? Monotone(Entity f, Variable x, Entity over) { if (!f.ContainsNode(x) || !IsRational(f, x) || Pieces(over) is not { Count: 1 } pieces) return null; @@ -114,15 +128,122 @@ internal static class ImageByCalculus int? sign = null; for (var i = 0; i + 1 < ends.Count; i++) { - if (AsReal(top.Substitute(x, Between(ends[i], ends[i + 1]))) is not { IsFinite: true } value) + if (AsReal(top.Substitute(x, Between(ends[i], ends[i + 1]))) is not { IsFinite: true } value) return null; var here = value.EDecimal.Sign; // Zero on a whole stretch is a constant there, and a change of sign a turn. if (here == 0 || sign is { } before && before != here) - return false; + return 0; sign = here; } - return true; + return sign; + } + + /// + /// A union or an intersection of a family of intervals whose ends are quotients of + /// polynomials in the index, monotone over its range, as the interval between the extremes + /// of the ends; where that is not settled here. Sullivan and + /// Mackey's §3.9.5: the intersection of (-1/n, 1/n) over the positive whole numbers + /// 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). + /// + /// + /// + /// An intersection of intervals is an interval, from the supremum of the left ends to the + /// infimum of the right ones. An end of it is closed where the family's ends are, and where + /// the extreme is only approached: every (-1/n, 1/n) holds 0, where both ends tend. + /// + /// + /// A union is an interval from the infimum of the left ends to the supremum of the right + /// ones where the family is a chain, each member inside the next -- ends moving apart, or + /// one still -- and where the index runs over an interval and every member is not empty, + /// so that the members overlap as it moves. Over the whole numbers a sliding family, + /// (k, k + 1), leaves gaps, and is not read. An end of the union is closed where the + /// family's ends are and the extreme is reached. + /// + /// + /// A monotone end has its extremes at the ends of the index's range: at a least or a + /// greatest member, where it is reached, and in the limit, where it is not. + /// + /// + internal static Set? Family(bool union, Interval member, Variable k, Entity over) + { + if (Range(over) is not var (range, whole) + || Extremes(member.Left, k, range) is not var (leftLow, leftHigh, leftDirection) + || Extremes(member.Right, k, range) is not var (rightLow, rightHigh, rightDirection)) + return null; + (Entity Value, bool Closed) lower, upper; + if (union) + { + var chain = leftDirection <= 0 && rightDirection >= 0 || leftDirection >= 0 && rightDirection <= 0; + if (!chain && (whole || !NeverEmpty(member, k, range))) + return null; + lower = (leftLow.Value, member.LeftClosed && leftLow.Reached); + upper = (rightHigh.Value, member.RightClosed && rightHigh.Reached); + } + else + { + lower = (leftHigh.Value, member.LeftClosed || !leftHigh.Reached); + upper = (rightLow.Value, member.RightClosed || !rightLow.Reached); + } + if (AsReal(lower.Value) is not { IsNaN: false } from || AsReal(upper.Value) is not { IsNaN: false } to) + return null; + // Simplified, so that [0; 0] is the point it is and (0; 0) nothing. + return new Interval(lower.Value, lower.Closed && from.IsFinite, upper.Value, upper.Closed && to.IsFinite).InnerSimplified as Set; + } + + /// The index's range as an interval, and whether the index is a whole number. + private static (Interval Range, bool Whole)? Range(Entity over) + => over switch + { + SpecialSet.PositiveIntegers => (new Interval(Integer.One, true, Real.PositiveInfinity, false), true), + SpecialSet.NonNegativeIntegers => (new Interval(Integer.Zero, true, Real.PositiveInfinity, false), true), + SpecialSet.Integers => (new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false), true), + SpecialSet.Reals => (new Interval(Real.NegativeInfinity, false, Real.PositiveInfinity, false), false), + Interval interval when interval.IsNumeric => (interval, false), + _ => null, + }; + + /// + /// The least and the greatest of an end over the range, each with whether it is reached, + /// and the end's direction, 0 for one that does not move; + /// where the end is not monotone there. + /// + private static ((Entity Value, bool Reached) Low, (Entity Value, bool Reached) High, int Direction)? Extremes(Entity end, Variable k, Interval range) + { + if (!end.ContainsNode(k)) + return ((end, true), (end, true), 0); + if (Monotone(end, k, range) is not { } direction || direction == 0) + return null; + if (At(end, k, range.Left, range.LeftClosed, Core.ApproachFrom.Right) is not { } atStart + || At(end, k, range.Right, range.RightClosed, Core.ApproachFrom.Left) is not { } atEnd) + return null; + return direction > 0 ? (atStart, atEnd, 1) : (atEnd, atStart, -1); + } + + /// The end's value at an end of the range, reached, or its limit there, not reached. + private static (Entity Value, bool Reached)? At(Entity end, Variable k, Entity at, bool included, Core.ApproachFrom side) + { + if (AsReal(at) is not { } point) + return null; + if (included && point.IsFinite) + return (end.Substitute(k, at).Simplify(), true); + var limit = point.IsFinite ? end.Limit(k, at, side) : end.Limit(k, at); + return AsReal(limit) is { IsNaN: false } ? (limit, false) : null; + } + + /// Whether every member of a family is not empty: its right end above its left one over the whole range. + private static bool NeverEmpty(Interval member, Variable k, Interval range) + { + var width = (member.Right - member.Left).Simplify(); + if (!width.ContainsNode(k)) + return AsReal(width) is { } constant && constant.EDecimal.Sign > 0; + return Of(width, k, range) switch + { + Interval { Left: var least, LeftClosed: var reached } => AsReal(least) is { } bound && (bound.EDecimal.Sign > 0 || bound.EDecimal.Sign == 0 && !reached), + FiniteSet { Count: 1 } single => AsReal(single.First()) is { } only && only.EDecimal.Sign > 0, + _ => false, + }; } /// A point strictly between two ends, either of which may be infinite. diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs index 18405caad..9482b0d62 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs @@ -241,6 +241,12 @@ protected override Entity InnerSimplify(bool isExact) if (this is IndexedUnionf && Var is Variable name && body is FiniteSet { Count: 1 } single && Functions.ImageByCalculus.Of(single.First(), name, over) is { } byCalculus) return byCalculus; + // A family of intervals whose ends are monotone in the index, as the interval + // between the extremes of its ends: the intersection of (-1/n; 1/n) over ZZ+ is + // { 0 }. https://github.com/asc-community/AngouriMath/issues/1409 + if (Var is Variable familyIndex && body is Interval familyMember + && Functions.ImageByCalculus.Family(this is IndexedUnionf, familyMember, familyIndex, over) is { } family) + return family; if (over is FiniteSet indices) { if (indices.Count == 0) diff --git a/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs b/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs index ff3df98af..d20ef0236 100644 --- a/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs +++ b/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs @@ -66,6 +66,31 @@ public void AFamilyOverAListedIndexSetIsFolded(string expression, string expecte public void MembershipOfAnInfiniteFamilyIsDecidedByTheQuantifiers(string expression, string expected) => Assert.Equal(expected.ToEntity(), Evaluated(expression)); + /// + /// A family of intervals whose ends are monotone in the index is the interval between the + /// extremes of its ends, closed where they are reached, or approached by the ends of an + /// intersection: Sullivan and Mackey's §3.9.5 Try 8–10, and growing and shrinking families. + /// A sliding family over the whole numbers leaves gaps and stays a family. + /// + [Theory] + [InlineData("intersection((-1/n; 1/n), n in ZZ+)", "{0}")] + [InlineData("union((x; x + 1), x in (0; 1))", "(0; 2)")] + [InlineData("union([0; (n - 1)/n), n in ZZ+)", "[0; 1)")] + [InlineData("intersection((-1/n; 1), n in ZZ+)", "[0; 1)")] + [InlineData("intersection([0; 1/n), n in ZZ+)", "{0}")] + [InlineData("union([1/n; 1], n in ZZ+)", "(0; 1]")] + [InlineData("union([1; (k + 1)/k], k in ZZ+)", "[1; 2]")] + public void AFamilyWithMonotoneEndsIsAnInterval(string expression, string expected) + => Assert.Equal(expected.ToEntity().Evaled, Evaluated(expression)); + + [Fact] + public void TwoFamiliesAreEqualWhereTheirIntervalsAre() + { + Assert.Equal(Entity.Boolean.True, Evaluated("union([0; (n - 1)/n), n in ZZ+) = intersection((-1/n; 1), n in ZZ+)")); + var sliding = "union((n; n + 1), n in ZZ+)".ToEntity(); + Assert.Equal(sliding, sliding.Evaled); + } + /// Ex 3.5.11: the complement of a set in a universe is the universe less the set. [Theory] [InlineData("complement({1, 2}, ZZ+ /\\ [1; 5])", "{3, 4, 5}")]