From 51c7968f10ac043ec39f21e4aa249521f6478bcd Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 08:29:20 +0000 Subject: [PATCH 1/5] A statement about a sum up to n is decided by induction, and an identity is read over atoms forall n in ZZ+ : sum(f, k, a, n) = g is proved from the least member of the set: the statement there, and the statement at n + 1 with the sum unfolded by one term and the sum to n replaced by g, decided as an identity. A piecewise body -- what a closed form comes as -- is read as the case whose condition holds at every member; the polynomial identity test reads over atoms (2^(n + 1) is 2 * 2^n, (n + 2)! is (n + 2)(n + 1) n!) and puts quotients over one denominator, claimed where the denominator is not zero -- decided over the set for the quantified name, stated as a condition for a free parameter. ZZ+ /\ [2; +oo) has a least member, and Closed knows it is not empty. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 23 ++ Sources/.editorconfig | 3 + Sources/AngouriMath/Docs/Usage/Syntax.md | 21 +- .../Functions/Boolean/Quantifiers.cs | 262 +++++++++++++++++- Sources/Tests/UnitTests/Core/InductionTest.cs | 116 ++++++++ 5 files changed, 416 insertions(+), 9 deletions(-) create mode 100644 Sources/Tests/UnitTests/Core/InductionTest.cs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 76933adfb..e3d0ee8d5 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -744,6 +744,29 @@ carried a condition the piecewise read as no value, so the sum was `0` at `n = 0 | `"sum(binomial(n, k), k, 0, n)".ToEntity().Evaled` | `UnhandledParseException` | `piecewise((2 ^ n) provided (n >= 0), 0 provided True)` | | `"sum(n! / (k! (n - k)!) (-1)^k, k, 0, n)".ToEntity().Evaled` | `piecewise(0 provided True)` — wrong at `n = 0` | `piecewise(1 provided (n = 0), 0 provided True)` | +### A statement about a sum up to `n` is decided by induction + +`forall n in ZZ+ : sum(f, k, a, n) = g` is proved from the least member of the set: the statement +there, and the statement at `n + 1` with the sum unfolded by one term and the sum to `n` replaced +by `g`, decided as an identity. A sum the summation already folds is read through the piecewise +its closed form comes as, and an identity is read over atoms — `2^n`, `n!`, `(-1)^n`, `sin(x)` — +with a whole shift in an exponent or a factorial's argument unfolded, and a difference of +quotients put over one denominator — claimed where that denominator is not zero, which is decided +over the set for the quantified name and stated as a condition for a free parameter. A statement +that fails at the least member is `False`; an inequality, or a closed form with a case on a free +parameter, is left as written +([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's chapter 5). + +| Input | Was (2.5.0) | Now | +|---|---|---| +| `"forall n in ZZ+ : sum(k, k, 1, n) = n (n + 1) / 2".ToEntity().Evaled` | `UnhandledParseException` — quantifiers are new since; left as written when they arrived, the body being a `piecewise` | `True` | +| `"forall n in ZZ+ : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)".ToEntity().Evaled` | `UnhandledParseException` | `True`, by induction | +| `"forall n in ZZ+ : sum(k k!, k, 1, n) = (n + 1)!".ToEntity().Evaled` | `UnhandledParseException` | `False`, at `n = 1` | +| `"forall n in ZZ+ : (n + 1)! + (n + 1) (n + 1)! = (n + 2)!".ToEntity().Evaled` | `UnhandledParseException` | `True` | +| `"forall x in RR : (sin(x) + 1)^2 = sin(x)^2 + 2 sin(x) + 1".ToEntity().Evaled` | `UnhandledParseException` | `True` | +| `"forall n in ZZ+ /\\ [2; +oo) : n = n".ToEntity().Evaled` | `UnhandledParseException` | `True` — the set is known not to be empty | +| `"forall n in ZZ+ : sum(1 / (a k (k + 1)), k, 1, n) = n / (a (n + 1))".ToEntity().Evaled` | `UnhandledParseException` | `True provided not a = 0` | + ### `binomial(n, k)` is a function **Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 40ba68a05..97854260f 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -291,6 +291,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed [AngouriMath/Functions/NumberTheory/ResidueClasses.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n +[Tests/UnitTests/Core/InductionTest.cs] +file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n + [Tests/UnitTests/Core/BinomialIdentityTest.cs] file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n diff --git a/Sources/AngouriMath/Docs/Usage/Syntax.md b/Sources/AngouriMath/Docs/Usage/Syntax.md index d2e300bad..0ec5ce12d 100644 --- a/Sources/AngouriMath/Docs/Usage/Syntax.md +++ b/Sources/AngouriMath/Docs/Usage/Syntax.md @@ -292,8 +292,25 @@ about `y`. Decided over a finite set by evaluating the body at every member (`fo False}`, and over an infinite set by a counterexample (`forall n in ZZ : n^2 <= n^3` is `False` at `n = -1`) or by solving where the solver reads the body (`forall x in RR : x^2 >= 0` is `True`, `exists x in RR : x^2 + 1 = 0` is `False` and `exists x in CC : x^2 + 1 = 0` is `True`); left as -written otherwise, never guessed. `not` passes through a quantifier by flipping it: `not forall -x in S : P` is `exists x in S : not P`. In LaTeX, `\forall x \in S : P`. `forall`, `exists` and +written otherwise, never guessed. A body that is a `piecewise` — what `sum` and `product` fold to, +`sum(k, k, 1, n)` being `(n + n^2)/2 provided n >= 0` — is read as the case whose condition holds +at every member, so `forall n in ZZ+ : sum(k, k, 1, n) = n (n + 1)/2` is `True`. An equation whose +sides differ by a polynomial that expands to nothing is `True` over any set, where a polynomial is +read over *atoms*: whatever is not a sum, product, quotient or whole power is one indeterminate, +a whole shift in an exponent is a factor (`2^(n + 1)` is `2 · 2^n`) and a factorial of a shifted +argument is the smaller one times the numbers between (`(n + 2)!` is `(n + 2)(n + 1) n!`), so +`forall n in ZZ+ : (n + 1)! + (n + 1)(n + 1)! = (n + 2)!` is `True`. And **a statement about a sum +or a product up to `n`, over the whole numbers from some least one, is decided by induction**: +`forall n in ZZ+ : sum(1/(k (k + 1)), k, 1, n) = n/(n + 1)` is `True` because it holds at `n = 1` +and, with the sum to `n + 1` unfolded to the sum to `n` plus one term and that sum replaced by +`n/(n + 1)`, the statement at `n + 1` is an identity; `forall n in ZZ+ /\ [2; +oo) : ...` starts at +`2`. A difference of quotients is put over one denominator, and the identity is claimed where the +denominator is not zero: decided over the set for the quantified name (`n + 1` is never `0` on +`ZZ+`), and stated as a condition for a free parameter (`forall n in ZZ+ : sum(1/(a k (k + 1)), k, 1, n) = +n/(a (n + 1))` is `True provided not a = 0`). Only the shape with one sum or product +alone on a side of an equation is read this way; an inequality, or a sum whose closed form has a +case on a free parameter, is left as written. `not` +passes through a quantifier by flipping it: `not forall x in S : P` is `exists x in S : not P`. In LaTeX, `\forall x \in S : P`. `forall`, `exists` and `exists!` are keywords, so they are not names. `domain` takes a special set — `CC` `RR` `QQ` `ZZ` `ZZ*` `ZZ+` `BB` — or the keyword `Any`, and diff --git a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs index 0ef1da4f2..e59ae97f0 100644 --- a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs +++ b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs @@ -81,10 +81,26 @@ internal enum Kind { All, Some, Unique } set = new FiniteSet(Entity.Boolean.True, Entity.Boolean.False); if (!body.ContainsNode(x)) return Closed(kind, set, body); + // A piecewise body -- what a closed form comes as, sum(k, k, 1, n) being + // (n + n^2)/2 provided n >= 0 -- is the case whose condition holds at every member of + // the set, or the next case where a condition holds at none: over ZZ+ the condition + // n >= 0 is the membership itself, and the statement is about the closed form. + // https://github.com/asc-community/AngouriMath/issues/1409 + if (body is Piecewise piecewise) + { + foreach (var @case in piecewise.Cases) + { + var holds = @case.Predicate == Entity.Boolean.True ? Entity.Boolean.True : Decide(Kind.All, x, set, @case.Predicate.InnerSimplified(isExact), isExact); + if (holds == Entity.Boolean.True) + return Decide(kind, x, set, @case.Expression.InnerSimplified(isExact), isExact); + if (Decide(Kind.Some, x, set, @case.Predicate.InnerSimplified(isExact), isExact) != Entity.Boolean.False) + break; + } + } // 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) && IsIdentity(left, right)) - return Closed(kind, set, Entity.Boolean.True); + if (body is Equalsf(var left, var right) && IsIdentity(left, right, x, set, isExact) is { } identity) + return Closed(kind, set, Entity.Boolean.True) is Entity.Boolean(true) ? identity : Closed(kind, set, Entity.Boolean.True); if (set is FiniteSet finite) return OverFinite(kind, x, finite, body, isExact); if (set is SpecialSet integers && IsIntegerSet(integers) && kind != Kind.Unique) @@ -101,11 +117,112 @@ internal enum Kind { All, Some, Unique } if (ImpossibleByResidues(kind, x, integers, body) is { } verdict) return verdict; } + // A statement about a sum or a product up to x, over the whole numbers from some + // least one, is proved by induction: it holds at the least member, and holding at + // x it holds at x + 1, where the sum to x + 1 is the sum to x and one more term. + // The reference's chapter 5. https://github.com/asc-community/AngouriMath/issues/1409 + if (kind == Kind.All && LeastMember(set) is { } least && ByInduction(x, set, least, body, isExact) is { } byInduction) + return byInduction; if (Witness(kind, x, set, body, isExact) is { } byWitness) return byWitness; return BySolving(kind, x, set, body); } + /// + /// The least member of a set of whole numbers bounded below -- ZZ+, ZZ*, + /// either cut by an interval -- or where the set is something else. + /// + private static Integer? LeastMember(Set set) + { + switch (set) + { + case SpecialSet special: + return special.ToDomain() switch + { + Domain.PositiveInteger => Integer.One, + Domain.NonNegativeInteger => Integer.Zero, + _ => null, + }; + case Intersectionf(Set left, Set right): + { + var (integers, cut) = (left, right) switch + { + (SpecialSet whole, Interval interval) when IsIntegerSet(whole) => (whole, interval), + (Interval interval, SpecialSet whole) when IsIntegerSet(whole) => (whole, interval), + _ => (null, null), + }; + if (integers is null || cut is null || cut.Left.Evaled is not Real { IsFinite: true } low) + return null; + var floor = low.EDecimal.RoundToExponent(0, ERounding.Floor).ToEInteger(); + // The first whole number at or after the end: the end itself when it + // is whole and included, the next one otherwise. + var first = Integer.Create(low.EDecimal.IsInteger() && cut.LeftClosed ? floor : floor + 1); + var own = LeastMember(integers); + return own is not null && own > first ? own : first; + } + default: + return null; + } + } + + /// + /// forall x in S : sum(f, k, a, x) = g by induction from the least member of + /// S: the statement at that member evaluates to , and the + /// statement at x + 1, with the sum to x + 1 unfolded to the sum to x + /// plus f(x + 1) and that sum then replaced by g -- the hypothesis -- holds + /// at every member. A product unfolds with a factor. Only the shape with one sum or + /// product, standing alone on a side of the equation, is read; a statement that fails at + /// the least member is . + /// + private static Entity? ByInduction(Variable x, Set set, Integer least, Entity body, bool isExact) + { + if (body is not Equalsf(var left, var right)) + return null; + var (accumulated, closed) = (left, right) switch + { + (Summationf or Productf, _) when !right.ContainsNode(left) => (left, right), + (_, Summationf or Productf) when !left.ContainsNode(right) => (right, left), + _ => (null, null), + }; + if (accumulated is null || closed is null) + return null; + var (term, index, from, to) = accumulated switch + { + Summationf sum => (sum.Expression, sum.Var, sum.From, sum.To), + Productf product => (product.Expression, product.Var, product.From, product.To), + _ => throw new AngouriBugException("A sum or a product was matched above"), + }; + if (to != x || from.ContainsNode(x) || term.ContainsNode(x) || index is not Variable k) + return null; + var atLeast = body.Substitute(x, least).InnerSimplified(isExact); + if (atLeast is Equalsf(var l, var r) && IsIdentity(l, r, x, set, isExact) is { } identity) + atLeast = identity; + if (atLeast == Entity.Boolean.False) + return Entity.Boolean.False; + if (Truth(atLeast) is not { } baseCondition) + return null; + var next = x + Integer.One; + var oneMore = term.Substitute(k, next); + var unfolded = accumulated is Summationf ? closed + oneMore : closed * oneMore; + var step = new Equalsf(unfolded, closed.Substitute(x, next)).InnerSimplified(isExact); + if (Truth(Decide(Kind.All, x, set, step, isExact)) is not { } stepCondition) + return null; + return Entity.Boolean.True.Provided((baseCondition & stepCondition).InnerSimplified(isExact)); + } + + /// + /// The condition under which a decision is -- True for + /// True itself, the predicate for True provided P -- or + /// for anything else. + /// + private static Entity? Truth(Entity? decision) + => decision switch + { + Entity.Boolean(true) => Entity.Boolean.True, + Providedf(Entity.Boolean(true), var predicate) => predicate, + _ => null, + }; + private static bool IsIntegerSet(SpecialSet set) => set.ToDomain() is Domain.Integer or Domain.NonNegativeInteger or Domain.PositiveInteger; @@ -248,20 +365,145 @@ private static bool HasRootModulo(MultivariatePolynomial polynomial, int variabl } /// Whether two sides are the same polynomial, read by expansion. - private static bool IsIdentity(Entity left, Entity right) + /// + /// True where the two sides differ by a polynomial that expands to nothing, + /// True provided P where they do once quotients are put over one denominator + /// and P says the denominator's factors in the free names are not zero, and + /// otherwise. A factor in the quantified name has to be decided + /// non-zero over the set, or the identity is not claimed. + /// + private static Entity? IsIdentity(Entity left, Entity right, Variable x, Set set, bool isExact) { var difference = (left - right).InnerSimplified; if (difference is Integer { IsZero: true }) - return true; + return Entity.Boolean.True; if (difference.Complexity > LargestDifferenceRead) - return false; - var variables = difference.Vars.OrderBy(v => v.Name, System.StringComparer.Ordinal).ToArray(); + return null; + // Whatever is not a polynomial connective -- 2^(n + 1), n!, sin(x) -- is an atom the + // polynomial is over: -(1 - 2^(n + 1)) = 2^(n + 1) - 1 is p - p in one atom, and a + // polynomial that is zero in its atoms is zero at every value of them. + var atoms = new Dictionary(); + difference = Atomized(difference, atoms, FactorialsUnfolded(difference)); + Entity condition = Entity.Boolean.True; + if (difference.Nodes.Any(node => node is Divf)) + { + // A difference of quotients is zero where its numerator over the common + // denominator is, and where that denominator is not: n/(n + 1) + 1/((n + 1)(n + 2)) + // = (n + 1)/(n + 2) at every whole n >= 1, and sum(k x^k, k, 1, n)'s closed form + // over (1 - x)^2 holds provided x != 1. + var (numerator, denominator) = SingleQuotient.Of(difference); + foreach (var factor in Mulf.LinearChildren(denominator).Distinct()) + { + var written = factor; + foreach (var pair in atoms) + written = written.Substitute(pair.Value, pair.Key); + if (written.Evaled is Number) + continue; + if (written.ContainsNode(x)) + { + if (Decide(Kind.Some, x, set, new Equalsf(written, Integer.Zero).InnerSimplified(isExact), isExact) is not Entity.Boolean(false)) + return null; + continue; + } + condition &= new Notf(new Equalsf(written, Integer.Zero)); + } + difference = numerator; + } + if (!IsZeroPolynomial(difference)) + return null; + var simplified = condition.InnerSimplified(isExact); + return simplified == Entity.Boolean.True ? Entity.Boolean.True : Entity.Boolean.True.Provided(simplified); + } + + private static bool IsZeroPolynomial(Entity expr) + { + var variables = expr.Vars.OrderBy(v => v.Name, System.StringComparer.Ordinal).ToArray(); if (variables.Length == 0 || variables.Length > MultivariatePolynomial.MaxVariables) return false; var indices = new Dictionary(); for (var i = 0; i < variables.Length; i++) indices[variables[i]] = i; - return MultivariatePolynomial.TryParse(difference, indices) is { IsZero: true }; + return MultivariatePolynomial.TryParse(expr, indices) is { IsZero: true }; + } + + /// The whole number by which exceeds identically, or . + private static Integer? WholeGap(Entity left, Entity right) + { + var difference = (left - right).InnerSimplified; + if (difference is Integer whole) + return whole; + var atOrigin = difference; + foreach (var v in difference.Vars) + atOrigin = atOrigin.Substitute(v, Integer.Zero); + return atOrigin.Evaled is Integer gap && IsZeroPolynomial(difference - gap) ? gap : null; + } + + /// + /// Each factorial whose argument is a smaller factorial's argument plus a whole number, + /// as that factorial times the numbers in between: (n + 2)! beside n! is + /// (n + 2) (n + 1) n!, so that the two are one atom rather than two. + /// + private static Dictionary FactorialsUnfolded(Entity expr) + { + var unfolded = new Dictionary(); + var factorials = expr.Nodes.OfType().Distinct().ToList(); + foreach (var factorial in factorials) + { + Factorialf @base = factorial; + foreach (var other in factorials) + if (WholeGap(@base.Argument, other.Argument) is { IsNegative: false, IsZero: false } gap && gap.EInteger.CompareTo(EInteger.FromInt32(LargestFactorialGap)) <= 0) + @base = other; + if (ReferenceEquals(@base, factorial) || WholeGap(factorial.Argument, @base.Argument) is not { } distance) + continue; + Entity product = @base; + for (var j = 1; j <= distance.EInteger.ToInt32Checked(); j++) + product *= @base.Argument + Integer.Create(j); + unfolded[factorial] = product; + } + return unfolded; + } + + private const int LargestFactorialGap = 16; + + /// + /// The expression with every maximal subterm that is not a sum, a difference, a product, + /// a whole power or a division replaced by one variable per distinct subterm. + /// + private static Entity Atomized(Entity expr, Dictionary atoms, Dictionary unfolded) + { + switch (expr) + { + case Number or Variable: + return expr; + case Sumf(var a, var b): + return Atomized(a, atoms, unfolded) + Atomized(b, atoms, unfolded); + case Minusf(var a, var b): + return Atomized(a, atoms, unfolded) - Atomized(b, atoms, unfolded); + case Mulf(var a, var b): + return Atomized(a, atoms, unfolded) * Atomized(b, atoms, unfolded); + case Divf(var a, var b): + return Atomized(a, atoms, unfolded) / Atomized(b, atoms, unfolded); + case Powf(var a, Integer n): + return n.IsNegative ? Integer.One / Atomized(a, atoms, unfolded).Pow(-n) : Atomized(a, atoms, unfolded).Pow(n); + case Factorialf when unfolded.TryGetValue(expr, out var product): + return Atomized(product, atoms, unfolded); + // A power whose exponent carries a whole term, 2^(n + 1), is the power without + // it times a number, 2 * 2^n, so that it is the atom 2^n is. + case Powf(var a, var e) when Sumf.LinearChildren(e).Any(t => t.Evaled is Integer): + { + var shift = Sumf.LinearChildren(e).Select(t => t.Evaled).OfType().Aggregate((Integer)Integer.Zero, (acc, t) => (Integer)(acc + t)); + var rest = Sumf.LinearChildren(e).Where(t => t.Evaled is not Integer).Aggregate((Entity)Integer.Zero, (acc, t) => acc + t).InnerSimplified; + var scaled = shift.IsNegative ? Integer.One / Atomized(a, atoms, unfolded).Pow(-shift) : Atomized(a, atoms, unfolded).Pow(shift); + return Atomized(a.Pow(rest), atoms, unfolded) * scaled; + } + // And a whole multiple in the exponent is a whole power of the atom: x^(2 n) is (x^n)^2. + case Powf(var a, Mulf(Integer { IsNegative: false, IsZero: false } times, var r)): + return Atomized(a.Pow(r), atoms, unfolded).Pow(times); + default: + if (!atoms.TryGetValue(expr, out var atom)) + atoms[expr] = atom = Variable.CreateUnique(expr, "atom_" + atoms.Count); + return atom; + } } private const int LargestDifferenceRead = 2048; @@ -281,6 +523,12 @@ private static bool IsIdentity(Entity left, Entity right) Interval interval => interval.IsNumeric && interval.Left.Evaled is Real from && interval.Right.Evaled is Real to && (Compare(from, to) > 0 || Compare(from, to) == 0 && !(interval.LeftClosed && interval.RightClosed)), SpecialSet => false, + // The whole numbers from some least one, cut by an interval: empty exactly + // when the interval ends before the least one. + Intersectionf intersection when LeastMember(intersection) is { } least + => (intersection.Left as Interval ?? intersection.Right as Interval) is { } cut + ? cut.Right.Evaled is Real to && (Compare(least, to) > 0 || Compare(least, to) == 0 && !cut.RightClosed) + : (bool?)null, _ => (bool?)null, }; return (kind, empty) switch diff --git a/Sources/Tests/UnitTests/Core/InductionTest.cs b/Sources/Tests/UnitTests/Core/InductionTest.cs new file mode 100644 index 000000000..7c8a76177 --- /dev/null +++ b/Sources/Tests/UnitTests/Core/InductionTest.cs @@ -0,0 +1,116 @@ +// +// Copyright (c) 2019-2026 Angouri. +// AngouriMath is licensed under MIT. +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. +// Website: https://am.angouri.org. +// + +using AngouriMath; +using AngouriMath.Extensions; +using Xunit; +using static AngouriMath.Entity; + +namespace AngouriMath.Tests.Core +{ + /// + /// forall n in ZZ+ : sum(f, k, a, n) = g decided by induction from the least member of + /// the set: the statement at that member, and the statement at n + 1 with the sum + /// unfolded by one term and the sum to n replaced by g. A closed form the sum + /// has already is read through the piecewise it comes as, and an identity is read over + /// atoms -- 2^n, n!, (-1)^n -- with a whole shift in an exponent or a + /// factorial's argument unfolded. The rows are chapter 5 of Sullivan and Mackey's proofs + /// book. #1409 + /// + [Trait("Area", "Discrete")] + public sealed class InductionTest + { + [Theory] + // Sums the summation folds: the closed form comes as a piecewise on n >= 0, and over + // ZZ+ that case holds at every member (Ex 5.2.5, §5.2.4 Try 1, Prob 5.7.1). + [InlineData("forall n in ZZ+ : sum(k, k, 1, n) = n (n + 1) / 2")] + [InlineData("forall n in ZZ+ : sum(2 k - 1, k, 1, n) = n^2")] + [InlineData("forall n in ZZ+ : sum(k^2, k, 1, n) = n (n + 1) (2 n + 1) / 6")] + [InlineData("forall n in ZZ+ : sum(k^3, k, 1, n) = (sum(k, k, 1, n))^2")] + [InlineData("forall n in ZZ* : sum(2^k, k, 0, n) = 2^(n + 1) - 1")] + [InlineData("forall n in ZZ* : sum(binomial(n, k), k, 0, n) = 2^n")] + [InlineData("forall n in ZZ+ : product(k, k, 1, n) = n!")] + // Both bounds depend on n (Prob 5.7.16), and the bound is a multiple of n. + [InlineData("forall n in ZZ+ : sum(2 k + 1, k, n, 2 n - 1) = 3 n^2")] + [InlineData("forall n in ZZ+ : sum(k, k, 1, 2 n) = n (2 n + 1)")] + // Sums the summation leaves as written, proved by induction: telescoping (Prob 5.7.18's + // shape), a factorial, an exponential, an alternating sign (§5.3.4 Try 6), a parameter. + [InlineData("forall n in ZZ+ : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)")] + [InlineData("forall n in ZZ+ : sum(1 / (k (k + 1)), k, 1, n) = 1 - 1 / (n + 1)")] + [InlineData("forall n in ZZ+ : sum(1 / (k (k + 1) (k + 2)), k, 1, n) = 1/4 - 1 / (2 (n + 1) (n + 2))")] + [InlineData("forall n in ZZ+ : sum(k k!, k, 1, n) = (n + 1)! - 1")] + [InlineData("forall n in ZZ+ : (n + 1)! - 1 = sum(k k!, k, 1, n)")] + [InlineData("forall n in ZZ+ : sum(1 / 2^k, k, 1, n) = 1 - 1 / 2^n")] + [InlineData("forall n in ZZ+ : sum(k * 2^k, k, 1, n) = (n - 1) * 2^(n + 1) + 2")] + [InlineData("forall n in ZZ+ : sum(k^2 * 2^k, k, 1, n) = 2^(n + 1) * (n^2 - 2 n + 3) - 6")] + [InlineData("forall n in ZZ+ : sum((-1)^(k - 1) * k^2, k, 1, n) = (-1)^(n - 1) * n (n + 1) / 2")] + // Products. + [InlineData("forall n in ZZ+ : product(1 + 1/k, k, 1, n) = n + 1")] + [InlineData("forall n in ZZ+ : product(k / (k + 1), k, 1, n) = 1 / (n + 1)")] + [InlineData("forall n in ZZ+ : product(1 - 1 / (k + 1)^2, k, 1, n) = (n + 2) / (2 (n + 1))")] + [InlineData("forall n in ZZ+ : product((2 k - 1) / (2 k), k, 1, n) = (2 n)! / (4^n (n!)^2)")] + // Induction from any base (Thm 5.3.1): the least member of the set is where it starts. + [InlineData("forall n in ZZ* : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)")] + [InlineData("forall n in ZZ+ /\\ [2; +oo) : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)")] + [InlineData("forall n in ZZ+ /\\ (3/2; +oo) : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)")] + public void ProvedByInduction(string statement) + => Assert.Equal(Entity.Boolean.True, statement.ToEntity().Evaled); + + [Theory] + // A closed form over a denominator in a free parameter holds where the denominator is + // not zero, and the answer says so; a denominator in the quantified name is decided + // non-zero over the set instead, so those rows above carry no condition. + [InlineData("forall n in ZZ+ : sum(k x^k, k, 1, n) = x (1 - (n + 1) x^n + n x^(n + 1)) / (1 - x)^2", "True provided not (1 - x)^2 = 0")] + [InlineData("forall n in ZZ+ : sum(1 / (a k (k + 1)), k, 1, n) = n / (a (n + 1))", "True provided not a = 0")] + public void ProvedWhereTheClosedFormExists(string statement, string expected) + => Assert.Equal(expected.ToEntity(), statement.ToEntity().Evaled); + + [Theory] + // Wrong at the least member, which is a counterexample. + [InlineData("forall n in ZZ+ : sum(k, k, 1, n) = n^2")] + [InlineData("forall n in ZZ+ : sum(k, k, 1, n) = n (n + 1) / 2 + 1")] + [InlineData("forall n in ZZ+ : sum(k k!, k, 1, n) = (n + 1)!")] + [InlineData("forall n in ZZ+ : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 2)")] + [InlineData("forall n in ZZ+ : sum(1 / 2^k, k, 1, n) = 1 - 1 / 2^(n - 1)")] + [InlineData("forall n in ZZ+ : sum(1 / k, k, 1, n) = n")] + // The empty sum is 0, so over ZZ the closed form's other case is a counterexample. + [InlineData("forall n in ZZ : sum(k, k, 1, n) = n (n + 1) / 2")] + public void RefutedAtAMember(string statement) + => Assert.Equal(Entity.Boolean.False, statement.ToEntity().Evaled); + + [Theory] + // Not decided: a closed form with a case on a free parameter (q = 1 has its own), a wrong + // closed form with a free parameter, an inequality, and a term the induction cannot unfold. + [InlineData("forall n in ZZ+ : sum(q^k, k, 0, n - 1) = (q^n - 1) / (q - 1)")] + [InlineData("forall n in ZZ+ : sum(k x^k, k, 1, n) = x (1 - (n + 1) x^n + n x^(n + 1)) / (1 - x)")] + [InlineData("forall n in ZZ+ : sum(1 / k^2, k, 1, n) <= 2 - 1 / n")] + [InlineData("forall n in ZZ+ : sum(1 / sqrt(k), k, 1, n) >= sqrt(n)")] + // A denominator that is zero at a member: the identity is not claimed there. + [InlineData("forall x in RR : x / (x - 1) - 1 / (x - 1) = 1")] + [InlineData("forall n in ZZ : n / (n + 1) + 1 / ((n + 1) (n + 2)) = (n + 1) / (n + 2)")] + public void LeftAsWritten(string statement) + => Assert.IsType(statement.ToEntity().Evaled); + + [Theory] + // An identity over atoms: whatever is not a polynomial connective is one indeterminate, + // a whole shift in an exponent is a factor, and a factorial of a shifted argument is the + // smaller factorial times the numbers in between. + [InlineData("forall x in RR : (sin(x) + 1)^2 = sin(x)^2 + 2 sin(x) + 1", "True")] + [InlineData("forall x in RR : (sin(x) + 1)^2 = sin(x)^2 + 2 sin(x) + 2", "False")] + [InlineData("forall n in ZZ+ : -(1 - 2^(n + 1)) = 2^(n + 1) - 1", "True")] + [InlineData("forall n in ZZ+ : 2^(n + 1) = 2 * 2^n", "True")] + [InlineData("forall n in ZZ+ : x^(2 n) = (x^n)^2", "True")] + [InlineData("forall n in ZZ+ : (n + 2)! = (n + 2) (n + 1) n!", "True")] + [InlineData("forall n in ZZ+ : (n + 1)! + (n + 1) (n + 1)! = (n + 2)!", "True")] + [InlineData("forall n in ZZ+ : n / (n + 1) + 1 / ((n + 1) (n + 2)) = (n + 1) / (n + 2)", "True")] + // Over the whole numbers from 2 the body is closed: the set is not empty. + [InlineData("forall n in ZZ+ /\\ [2; +oo) : (n + 1)^2 = n^2 + 2 n + 1", "True")] + [InlineData("exists n in ZZ+ /\\ [2; 1] : n = n", "False")] + public void AnIdentityOverAtoms(string statement, string expected) + => Assert.Equal(expected.ToEntity(), statement.ToEntity().Evaled); + } +} From 34b378602ca4c508316f262870baabab6a614ab3 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 08:53:19 +0000 Subject: [PATCH 2/5] An inequality with an exponential or a factorial is decided by induction, and the whole numbers from m are ZZ* shifted by m forall n in S : L > R (or >=, <, <=) with an exponential or a factorial in n, from the least member of S: it holds there, and with P = L - R, P(n + 1) = c P(n) + D for a multiplier c >= 0 -- one, the base of an exponential, n + 1 beside a factorial -- and a remainder D >= 0 read by a sign calculus: a positive base to any power, a factorial of a whole number, a polynomial in n decided over the set, sums and products of these, and a sum read per atom product with its collected coefficient. ZZ+ /\ [4; +oo) is decided as a statement about 4 + t over ZZ*, so every route reads a cut set, and a sum whose upper bound is n plus a whole number still unfolds. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 12 +- Sources/AngouriMath/Docs/Usage/Syntax.md | 12 +- .../Functions/Boolean/Quantifiers.cs | 217 +++++++++++++++++- Sources/Tests/UnitTests/Core/InductionTest.cs | 37 ++- 4 files changed, 270 insertions(+), 8 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 35f7b632f..418ef7fcd 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -767,9 +767,12 @@ by `g`, decided as an identity. A sum the summation already folds is read throug its closed form comes as, and an identity is read over atoms — `2^n`, `n!`, `(-1)^n`, `sin(x)` — with a whole shift in an exponent or a factorial's argument unfolded, and a difference of quotients put over one denominator — claimed where that denominator is not zero, which is decided -over the set for the quantified name and stated as a condition for a free parameter. A statement -that fails at the least member is `False`; an inequality, or a closed form with a case on a free -parameter, is left as written +over the set for the quantified name and stated as a condition for a free parameter. An +inequality with an exponential or a factorial is decided by induction as well, the step read off +a multiple of the hypothesis (`P(n + 1) = c P(n) + D` with `c >= 0` and `D >= 0` by a sign +calculus), and the whole numbers from `m` are read as `ZZ*` shifted by `m`. A statement that +fails at the least member is `False`; a closed form with a case on a free parameter is left as +written ([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's chapter 5). | Input | Was (2.5.0) | Now | @@ -781,6 +784,9 @@ parameter, is left as written | `"forall x in RR : (sin(x) + 1)^2 = sin(x)^2 + 2 sin(x) + 1".ToEntity().Evaled` | `UnhandledParseException` | `True` | | `"forall n in ZZ+ /\\ [2; +oo) : n = n".ToEntity().Evaled` | `UnhandledParseException` | `True` — the set is known not to be empty | | `"forall n in ZZ+ : sum(1 / (a k (k + 1)), k, 1, n) = n / (a (n + 1))".ToEntity().Evaled` | `UnhandledParseException` | `True provided not a = 0` | +| `"forall n in ZZ+ /\\ [5; +oo) : 2^n > n^2".ToEntity().Evaled` | `UnhandledParseException` | `True` | +| `"forall n in ZZ+ : n! >= 2^(n - 1)".ToEntity().Evaled` | `UnhandledParseException` | `True` | +| `"forall n in ZZ+ /\\ [4; +oo) : n^2 - 2 n - 1 > 0".ToEntity().Evaled` | `UnhandledParseException` | `True` — decided about `4 + t` over `ZZ*` | ### `binomial(n, k)` is a function diff --git a/Sources/AngouriMath/Docs/Usage/Syntax.md b/Sources/AngouriMath/Docs/Usage/Syntax.md index 0ec5ce12d..35f9e47e6 100644 --- a/Sources/AngouriMath/Docs/Usage/Syntax.md +++ b/Sources/AngouriMath/Docs/Usage/Syntax.md @@ -308,8 +308,16 @@ and, with the sum to `n + 1` unfolded to the sum to `n` plus one term and that s denominator is not zero: decided over the set for the quantified name (`n + 1` is never `0` on `ZZ+`), and stated as a condition for a free parameter (`forall n in ZZ+ : sum(1/(a k (k + 1)), k, 1, n) = n/(a (n + 1))` is `True provided not a = 0`). Only the shape with one sum or product -alone on a side of an equation is read this way; an inequality, or a sum whose closed form has a -case on a free parameter, is left as written. `not` +alone on a side of an equation is read this way; a sum whose closed form has a case on a free +parameter is left as written. **An inequality with an exponential or a factorial in `n`** is +decided by induction too, with the step read off a multiple of the hypothesis: writing it as +`P(n) >= 0`, `P(n + 1) = c P(n) + D` for a `c >= 0` (one, the base of an exponential, `n + 1` +beside a factorial) and a `D` whose sign is read from its shape — a positive base to any power, a +factorial, a polynomial in `n` decided over the set, sums and products of these — so `forall n in +ZZ+ /\ [5; +oo) : 2^n > n^2` is `True` (`2^(n + 1) - 2 · 2^n` leaves `n^2 - 2 n - 1`, positive +from `5`), `forall n in ZZ+ /\ [4; +oo) : 2^n > n^2` is `False` at `4`, and `forall n in ZZ+ : +n! >= 2^(n - 1)` is `True`. The whole numbers from `m` are `ZZ*` shifted by `m`, so a statement +over `ZZ+ /\ [4; +oo)` is decided as one about `4 + t` over `ZZ*`, whichever route reads it. `not` passes through a quantifier by flipping it: `not forall x in S : P` is `exists x in S : not P`. In LaTeX, `\forall x \in S : P`. `forall`, `exists` and `exists!` are keywords, so they are not names. diff --git a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs index d94f01464..a19770335 100644 --- a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs +++ b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs @@ -81,6 +81,13 @@ internal enum Kind { All, Some, Unique } set = new FiniteSet(Entity.Boolean.True, Entity.Boolean.False); if (!body.ContainsNode(x)) return Closed(kind, set, body); + // The whole numbers from m are ZZ* shifted by m, so a statement over ZZ+ /\ [4; +oo) + // is the statement about 4 + t over ZZ*, where every route below reads the set. + if (set is Intersectionf cut && LeastMember(cut) is { } start && IsUnboundedAbove(cut)) + { + var t = Variable.CreateUnique(body + start, "t"); + return Decide(kind, t, MathS.Sets.NonNegativeIntegers, body.Substitute(x, start + t).InnerSimplified(isExact), isExact); + } // A piecewise body -- what a closed form comes as, sum(k, k, 1, n) being // (n + n^2)/2 provided n >= 0 -- is the case whose condition holds at every member of // the set, or the next case where a condition holds at none: over ZZ+ the condition @@ -135,6 +142,11 @@ internal enum Kind { All, Some, Unique } // The reference's chapter 5. https://github.com/asc-community/AngouriMath/issues/1409 if (kind == Kind.All && LeastMember(set) is { } least && ByInduction(x, set, least, body, isExact) is { } byInduction) return byInduction; + // And an inequality with an exponential or a factorial in x, by induction with the + // step read off a multiple of the hypothesis: P(x + 1) = c P(x) + D with c >= 0 and + // D >= 0 keeps P >= 0 (Ex 5.3.2, Prob 5.7.2, 5.7.8 of the reference). + if (kind == Kind.All && LeastMember(set) is { } first && ByInductionOnAnInequality(x, set, first, body, isExact) is { } byGrowth) + return byGrowth; if (Witness(kind, x, set, body, isExact) is { } byWitness) return byWitness; return BySolving(kind, x, set, body); @@ -204,7 +216,8 @@ internal enum Kind { All, Some, Unique } Productf product => (product.Expression, product.Var, product.From, product.To), _ => throw new AngouriBugException("A sum or a product was matched above"), }; - if (to != x || from.ContainsNode(x) || term.ContainsNode(x) || index is not Variable k) + // The upper bound is x, or x plus a whole number after a shift of the set. + if (WholeGap(to, x) is null || from.ContainsNode(x) || term.ContainsNode(x) || index is not Variable k) return null; var atLeast = body.Substitute(x, least).InnerSimplified(isExact); if (atLeast is Equalsf(var l, var r) && IsIdentity(l, r, x, set, isExact) is { } identity) @@ -214,7 +227,7 @@ internal enum Kind { All, Some, Unique } if (Truth(atLeast) is not { } baseCondition) return null; var next = x + Integer.One; - var oneMore = term.Substitute(k, next); + var oneMore = term.Substitute(k, to.Substitute(x, next)); var unfolded = accumulated is Summationf ? closed + oneMore : closed * oneMore; var step = new Equalsf(unfolded, closed.Substitute(x, next)).InnerSimplified(isExact); if (Truth(Decide(Kind.All, x, set, step, isExact)) is not { } stepCondition) @@ -222,6 +235,206 @@ internal enum Kind { All, Some, Unique } return Entity.Boolean.True.Provided((baseCondition & stepCondition).InnerSimplified(isExact)); } + private static bool IsUnboundedAbove(Intersectionf cut) + => (cut.Left as Interval ?? cut.Right as Interval) is { } interval && interval.Right.Evaled is Real { EDecimal: var end } && end.IsInfinity() && !end.IsNegative; + + /// + /// forall x in S : L > R (or >=, <, <=) with an exponential + /// or a factorial in x, from the least member of S: it holds there, and + /// with P = L - R, P(x + 1) = c P(x) + D for a multiplier c >= 0 -- + /// 1, the base of an exponential, x + 1 beside a factorial -- and a + /// remainder D >= 0 read by the sign calculus, so that P(x) >= 0 carries to + /// x + 1; strictly, where c > 0 or D > 0. + /// + private static Entity? ByInductionOnAnInequality(Variable x, Set set, Integer least, Entity body, bool isExact) + { + var (positive, strict) = body switch + { + Greaterf(var l, var r) => (l - r, true), + GreaterOrEqualf(var l, var r) => (l - r, false), + Lessf(var l, var r) => (r - l, true), + LessOrEqualf(var l, var r) => (r - l, false), + _ => (null, false), + }; + if (positive is null || !positive.Nodes.Any(node => node is Powf(_, var e) && e.ContainsNode(x) || node is Factorialf f && f.ContainsNode(x))) + return null; + // The sign calculus asks the decision about polynomials only, so the step never asks + // for an inequality of this shape again; the guard is against that ceasing to hold. + if (inductionDepth > 0) + return null; + inductionDepth++; + try + { + return ByInductionOnAnInequalityCore(x, set, least, body, positive, strict, isExact); + } + finally + { + inductionDepth--; + } + } + + [System.ThreadStatic] private static int inductionDepth; + + private static Entity? ByInductionOnAnInequalityCore(Variable x, Set set, Integer least, Entity body, Entity positive, bool strict, bool isExact) + { + var atLeast = body.Substitute(x, least).InnerSimplified(isExact); + if (atLeast == Entity.Boolean.False) + return Entity.Boolean.False; + if (atLeast != Entity.Boolean.True) + return null; + var next = positive.Substitute(x, x + Integer.One); + foreach (var c in Multipliers(positive, x)) + { + if (Sign(c, x, set, isExact) is not { } multiplier) + continue; + if (Sign(Collected(next - c * positive), x, set, isExact) is not { } remainder) + continue; + if (!strict || multiplier == Signum.Positive || remainder == Signum.Positive) + return Entity.Boolean.True; + } + return null; + } + + /// The multipliers tried for the step: one, the whole base of each exponential in , and x + 1 beside a factorial. + private static IEnumerable Multipliers(Entity positive, Variable x) + { + yield return Integer.One; + foreach (var @base in positive.Nodes.OfType().Where(p => p.Exponent.ContainsNode(x)).Select(p => p.Base).Where(b => b.Evaled is Integer).Distinct()) + yield return @base; + if (positive.Nodes.Any(node => node is Factorialf f && f.ContainsNode(x))) + yield return x + Integer.One; + } + + /// + /// The expression as a polynomial over its atoms, collected: 3^(x + 1) - 3 * 3^x is + /// 0, (x + 1)! - (x + 1) x! is 0, 2^(x + 1) - 2^x is 2^x. + /// + private static Entity Collected(Entity expr) + { + var atoms = new Dictionary(); + var atomized = Atomized(expr.InnerSimplified, atoms, FactorialsUnfolded(expr.InnerSimplified)); + var variables = atomized.Vars.OrderBy(v => v.Name, System.StringComparer.Ordinal).ToArray(); + var indices = new Dictionary(); + for (var i = 0; i < variables.Length; i++) + indices[variables[i]] = i; + var collected = variables.Length <= MultivariatePolynomial.MaxVariables && MultivariatePolynomial.TryParse(atomized, indices) is { } polynomial + ? polynomial.ToEntity(variables) + : atomized; + foreach (var pair in atoms) + collected = collected.Substitute(pair.Value, pair.Key); + return collected.InnerSimplified; + } + + private enum Signum { Positive, NonNegative } + + /// + /// Whether the expression is positive, or non-negative, at every member of the set, read + /// off its shape: a positive base to any power, a factorial of a whole number, sums and + /// products of these, and a polynomial in decided over the set. + /// where neither is known. + /// + private static Signum? Sign(Entity expr, Variable x, Set set, bool isExact) + { + switch (expr) + { + case Real real: + return real.IsPositive ? Signum.Positive : real.IsNegative ? null : Signum.NonNegative; + case Number: + return null; + case Variable v when v == x: + return LeastMember(set) is { } least ? least.IsPositive ? Signum.Positive : least.IsNegative ? null : Signum.NonNegative : null; + case Sumf(var a, var b): + return (Sign(a, x, set, isExact), Sign(b, x, set, isExact)) switch + { + (null, _) or (_, null) => SignByAtoms(expr, x, set, isExact), + (Signum.Positive, _) or (_, Signum.Positive) => Signum.Positive, + _ => Signum.NonNegative, + }; + case Minusf: + return SignOfPolynomial(expr, x, set, isExact) ?? SignByAtoms(expr, x, set, isExact); + case Mulf(var a, var b): + return (Sign(a, x, set, isExact), Sign(b, x, set, isExact)) switch + { + (null, _) or (_, null) => null, + (Signum.Positive, Signum.Positive) => Signum.Positive, + _ => Signum.NonNegative, + }; + case Divf(var a, var b): + return (Sign(a, x, set, isExact), Sign(b, x, set, isExact)) switch + { + (null, _) or (_, null) or (_, Signum.NonNegative) => null, + (Signum.Positive, Signum.Positive) => Signum.Positive, + _ => Signum.NonNegative, + }; + // A positive base to any real power; the exponent is real where it mentions + // nothing but x, which ranges over whole numbers. + case Powf(var @base, var exponent) when exponent.Vars.All(v => v == x): + return Sign(@base, x, set, isExact) switch + { + Signum.Positive => Signum.Positive, + Signum.NonNegative when exponent.Evaled is Integer { IsNegative: false } => Signum.NonNegative, + _ => exponent.Evaled is Integer { EInteger.IsEven: true } && @base.Vars.All(v => v == x) ? Signum.NonNegative : null, + }; + case Factorialf(var argument) when argument.Vars.All(v => v == x) && IsWholePolynomial(argument): + return Sign(argument, x, set, isExact) is not null ? Signum.Positive : null; + default: + return SignOfPolynomial(expr, x, set, isExact); + } + } + + /// + /// A polynomial in and nothing else, decided over the set by the + /// routes that read one, which do not come back here; for anything else. + /// + private static Signum? SignOfPolynomial(Entity expr, Variable x, Set set, bool isExact) + { + if (!expr.Vars.All(v => v == x) || !expr.Vars.Any() || MultivariatePolynomial.TryParse(expr, new Dictionary { [x] = 0 }) is null) + return null; + if (Decide(Kind.All, x, set, new Greaterf(expr, Integer.Zero).InnerSimplified(isExact), isExact) is Entity.Boolean(true)) + return Signum.Positive; + if (Decide(Kind.All, x, set, new GreaterOrEqualf(expr, Integer.Zero).InnerSimplified(isExact), isExact) is Entity.Boolean(true)) + return Signum.NonNegative; + return null; + } + + /// + /// The sign of a sum read term by term: each term is a product of atoms -- exponentials + /// and factorials in -- times a polynomial in , + /// the polynomials are collected per atom product, and the sum is non-negative where + /// every atom product and its collected coefficient are: (n + 1) n! - 2 n! is + /// (n - 1) n!, non-negative on ZZ+. + /// + private static Signum? SignByAtoms(Entity expr, Variable x, Set set, bool isExact) + { + var groups = new Dictionary(); + foreach (var term in Sumf.LinearChildren(expr)) + { + Entity atomic = Integer.One; + Entity coefficient = Integer.One; + foreach (var factor in Mulf.LinearChildren(term)) + if (factor.Vars.All(v => v == x) && MultivariatePolynomial.TryParse(factor, new Dictionary { [x] = 0 }) is not null) + coefficient *= factor; + else + atomic *= factor; + atomic = atomic.InnerSimplified; + groups[atomic] = groups.TryGetValue(atomic, out var sum) ? sum + coefficient : coefficient; + } + if (groups.Count < 2 && expr is not Minusf) + return null; + var result = Signum.NonNegative; + foreach (var pair in groups) + { + var atomSign = pair.Key == Integer.One ? Signum.Positive : Sign(pair.Key, x, set, isExact); + var collected = pair.Value.InnerSimplified; + var coefficientSign = collected is Number ? Sign(collected, x, set, isExact) : SignOfPolynomial(collected, x, set, isExact); + if (atomSign is null || coefficientSign is null) + return null; + if (atomSign == Signum.Positive && coefficientSign == Signum.Positive) + result = Signum.Positive; + } + return result; + } + /// /// The condition under which a decision is -- True for /// True itself, the predicate for True provided P -- or diff --git a/Sources/Tests/UnitTests/Core/InductionTest.cs b/Sources/Tests/UnitTests/Core/InductionTest.cs index 7c8a76177..59de6c28e 100644 --- a/Sources/Tests/UnitTests/Core/InductionTest.cs +++ b/Sources/Tests/UnitTests/Core/InductionTest.cs @@ -82,13 +82,48 @@ public void ProvedWhereTheClosedFormExists(string statement, string expected) public void RefutedAtAMember(string statement) => Assert.Equal(Entity.Boolean.False, statement.ToEntity().Evaled); + [Theory] + // An inequality with an exponential or a factorial, by induction with the step read off + // a multiple of the hypothesis: P(n + 1) = c P(n) + D with c >= 0 and D >= 0 keeps + // P >= 0. Ex 5.3.2, §5.3.4 Try 4, Prob 5.7.2, 5.7.8-9, 5.7.12 of the reference, each + // from the threshold the book names; the whole numbers from m are ZZ* shifted by m. + [InlineData("forall n in ZZ+ /\\ [5; +oo) : 2^n > n^2", "True")] + [InlineData("forall n in ZZ+ /\\ [4; +oo) : 2^n > n^2", "False")] + [InlineData("forall n in ZZ+ /\\ [6; +oo) : n^3 < 3^(n - 1)", "True")] + [InlineData("forall n in ZZ+ /\\ [8; +oo) : 3^n > n^4", "True")] + [InlineData("forall n in ZZ+ /\\ [5; +oo) : 4^n > n^4", "True")] + [InlineData("forall n in ZZ+ /\\ [4; +oo) : n! > 2^n", "True")] + [InlineData("forall n in ZZ+ /\\ [7; +oo) : n! > 3^n", "True")] + [InlineData("forall n in ZZ+ /\\ [12; +oo) : n! > 5^n", "True")] + [InlineData("forall n in ZZ+ : n! >= 2^(n - 1)", "True")] + [InlineData("forall n in ZZ+ : 7^n + 7 < 7^(n + 1)", "True")] + [InlineData("forall n in ZZ+ : 3^n + 3 < 3^(n + 1)", "True")] + [InlineData("forall n in ZZ+ : 2^n + 2 < 2^(n + 1)", "False")] + [InlineData("forall n in ZZ+ : 2^n >= n + 1", "True")] + [InlineData("forall n in ZZ* : 2^n >= n + 1", "True")] + [InlineData("forall n in ZZ+ : 2^n >= 2 n + 1", "False")] + [InlineData("forall n in ZZ+ /\\ [3; +oo) : 2^n >= 2 n + 1", "True")] + [InlineData("forall n in ZZ+ /\\ [2; +oo) : 3^n >= 2^(n + 1)", "True")] + [InlineData("forall n in ZZ+ : 3^n >= 2^(n + 1)", "False")] + // The sign calculus on its own, and the shift reaching the other routes. + [InlineData("forall n in ZZ+ : 2^(n + 1) > 0", "True")] + [InlineData("forall n in ZZ+ : n! > 0", "True")] + [InlineData("forall n in ZZ+ /\\ [4; +oo) : n^2 - 2 n - 1 > 0", "True")] + [InlineData("forall n in ZZ+ /\\ [2; +oo) : 8 divides (2 n + 1)^2 - 1", "True")] + [InlineData("exists n in ZZ+ /\\ [2; +oo) : n^2 = 9", "True")] + [InlineData("forall n in ZZ+ /\\ [4; +oo) : sum(1 / (k (k + 1)), k, 1, n) = n / (n + 1)", "True")] + public void AnInequalityByInduction(string statement, string expected) + => Assert.Equal(expected.ToEntity(), statement.ToEntity().Evaled); + [Theory] // Not decided: a closed form with a case on a free parameter (q = 1 has its own), a wrong - // closed form with a free parameter, an inequality, and a term the induction cannot unfold. + // closed form with a free parameter, an inequality whose step is not a multiple of the + // hypothesis plus something of known sign, and a term the induction cannot unfold. [InlineData("forall n in ZZ+ : sum(q^k, k, 0, n - 1) = (q^n - 1) / (q - 1)")] [InlineData("forall n in ZZ+ : sum(k x^k, k, 1, n) = x (1 - (n + 1) x^n + n x^(n + 1)) / (1 - x)")] [InlineData("forall n in ZZ+ : sum(1 / k^2, k, 1, n) <= 2 - 1 / n")] [InlineData("forall n in ZZ+ : sum(1 / sqrt(k), k, 1, n) >= sqrt(n)")] + [InlineData("forall n in ZZ+ : 2^n >= n^2 - 3 n + 3")] // A denominator that is zero at a member: the identity is not claimed there. [InlineData("forall x in RR : x / (x - 1) - 1 / (x - 1) = 1")] [InlineData("forall n in ZZ : n / (n + 1) + 1 / ((n + 1) (n + 2)) = (n + 1) / (n + 2)")] From f2dd604f07f896bcdff2df8c2b30bd3e556e9286 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 08:58:18 +0000 Subject: [PATCH 3/5] The proofs book is named where it is cited, not called "the reference" There will be more references; Sullivan and Mackey is named in every comment, test summary and BREAKING-CHANGES entry that cites it, as the maintainer asked on #1446. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- BREAKING-CHANGES.md | 10 +++++----- .../Core/Entity/Discrete/Entity.Discrete.Classes.cs | 2 +- .../Core/Transformations/Matching/MatchedRules.cs | 4 ++-- Sources/AngouriMath/Functions/Boolean/Quantifiers.cs | 10 +++++----- .../Evaluation.Discrete/Evaluation.Discrete.Classes.cs | 2 +- .../Functions/NumberTheory/ResidueClasses.cs | 2 +- .../Tests/UnitTests/Algebra/MembershipSolvingTest.cs | 4 ++-- Sources/Tests/UnitTests/Core/BinomialIdentityTest.cs | 2 +- .../Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs | 2 +- .../UnitTests/Core/Sets/IndexedSetOperationTest.cs | 4 ++-- Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 418ef7fcd..f29d8c30a 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -665,7 +665,7 @@ solved now — the members of a listed set each as an equation, an interval as i strict or not as the end is — and a statement that is not read is the set of `x` with the property, left as written. A quantifier that put the negated body to the solver read that emptiness as a proof: `forall x in RR : x^2 in ZZ` was `True` -([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's pre-images). +([#1409](https://github.com/asc-community/AngouriMath/issues/1409), Sullivan and Mackey's pre-images). | Input | Was (2.5.0) | Now | |---|---|---| @@ -716,7 +716,7 @@ of [#1409](https://github.com/asc-community/AngouriMath/issues/1409) — is `Tru `A`, an interval by interval arithmetic where `x` occurs once in `f`, and a membership object otherwise; `preimage(f(x), x in A, Y)` is `{ x in A : f(x) in Y }`, and a set builder of that shape is solved on evaluation where the membership is read (a listed `Y`, an interval) -([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's §7.3). Both +([#1409](https://github.com/asc-community/AngouriMath/issues/1409), Sullivan and Mackey's §7.3). Both names are keywords now, and were names. | Input | Was (2.5.0) | Now | @@ -731,7 +731,7 @@ names are keywords now, and were names. `(-oo)^(-1)`, while `(+oo)^2` was `+oo`: the finite-base arms did not apply and the polar form had nothing to say. They are the extended reals' powers now, `-oo`, `+oo` and `0`, so the image of `(-oo; +oo)` under a cube is `(-oo; +oo)`; and `forall b in B : exists a in A : f(a) = b` — surjectivity -onto `B`, Def 7.4.1 of the reference of [#1409](https://github.com/asc-community/AngouriMath/issues/1409) +onto `B`, Sullivan and Mackey's Def 7.4.1, [#1409](https://github.com/asc-community/AngouriMath/issues/1409) — is decided as `B` lying in the image of `A` under `f` where that image evaluates. | Input | Was (2.5.0) | Now | @@ -750,7 +750,7 @@ theorem read backwards, as the factorial spelling already was (`sum(binomial(n, is `(x + y)^n` for `n >= 0`). **Wrong answer fixed** in the alternating sum, in both spellings: `sum(binomial(n, k) (-1)^k, k, 0, n)` is `1` at `n = 0` and `0` above, and the closed form `0^n` carried a condition the piecewise read as no value, so the sum was `0` at `n = 0` -([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's §8.4). +([#1409](https://github.com/asc-community/AngouriMath/issues/1409), Sullivan and Mackey's §8.4). | Input | Was (2.5.0) | Now | |---|---|---| @@ -773,7 +773,7 @@ a multiple of the hypothesis (`P(n + 1) = c P(n) + D` with `c >= 0` and `D >= 0` calculus), and the whole numbers from `m` are read as `ZZ*` shifted by `m`. A statement that fails at the least member is `False`; a closed form with a case on a free parameter is left as written -([#1409](https://github.com/asc-community/AngouriMath/issues/1409), the reference's chapter 5). +([#1409](https://github.com/asc-community/AngouriMath/issues/1409), Sullivan and Mackey's chapter 5). | Input | Was (2.5.0) | Now | |---|---|---| diff --git a/Sources/AngouriMath/Core/Entity/Discrete/Entity.Discrete.Classes.cs b/Sources/AngouriMath/Core/Entity/Discrete/Entity.Discrete.Classes.cs index 4725c1c5f..b98e38abb 100644 --- a/Sources/AngouriMath/Core/Entity/Discrete/Entity.Discrete.Classes.cs +++ b/Sources/AngouriMath/Core/Entity/Discrete/Entity.Discrete.Classes.cs @@ -488,7 +488,7 @@ internal Cardf New(Entity argument) /// A quantified statement: forall x in S : P, exists x in S : P and /// exists! x in S : P. A binder, like a set builder: the name is bound throughout /// the body and the set, and the statement is a function of what else the body mentions. - /// The quantification set is mandatory, as the reference this follows insists — a + /// The quantification set is mandatory, as Sullivan and Mackey's proofs book insists — a /// statement is quantified over something, and forall x : x^2 >= 0 is true of /// the reals and false of the complex numbers. /// https://github.com/asc-community/AngouriMath/issues/1409 diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index 383d1c03d..2b5031234 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -859,8 +859,8 @@ is var (divided, remainder) description: "(x + a)! * y = (x + a + 1)!, where y is the next term"), // The binomial coefficient's three identities, each in the direction that collects: - // Pascal's rule, the chairperson identity and the symmetry. The reference's - // Props 8.4.1-8.4.3 (Sullivan and Mackey), which it proves by counting in two ways; + // Pascal's rule, the chairperson identity and the symmetry. Sullivan and Mackey's + // Props 8.4.1-8.4.3, which it proves by counting in two ways; // here they are identities of the falling factorial for a whole lower index and of // the gamma function elsewhere. https://github.com/asc-community/AngouriMath/issues/1409 new MatchedRule( diff --git a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs index a19770335..bead63058 100644 --- a/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs +++ b/Sources/AngouriMath/Functions/Boolean/Quantifiers.cs @@ -22,7 +22,7 @@ namespace AngouriMath.Functions.Boolean /// /// /// - /// Three routes, in the order the reference teaches them. Over a finite set the body + /// Three routes, in the order Sullivan and Mackey's proofs book (#1409) teaches them. Over a finite set the body /// is evaluated at every member, which is the definition; a member the body cannot decide /// leaves the statement as written unless the members it can decide settle it, as one /// counterexample settles forall. Over an infinite set the first thing tried is a @@ -105,7 +105,7 @@ internal enum Kind { All, Some, Unique } } } // forall b in B : exists a in A : f(a) = b is the statement that B lies in the image - // of A under f -- surjectivity onto B (the reference's Def 7.4.1) -- and the image is + // of A under f -- surjectivity onto B (Sullivan and Mackey's Def 7.4.1) -- and the image is // a set the library computes: listed over a listed A, an interval by interval // arithmetic, so the subset decision settles it where the image evaluates. // https://github.com/asc-community/AngouriMath/issues/1409 @@ -126,7 +126,7 @@ internal enum Kind { All, Some, Unique } { // A statement about divisibility, or a congruence, in a polynomial of x with // whole coefficients repeats with the modulus, so the residues decide it: - // forall n in ZZ : 6 divides n^3 + 5 n is six cases. The reference's "case + // forall n in ZZ : 6 divides n^3 + 5 n is six cases. Sullivan and Mackey's "case // analysis over the classes" (Ex 6.5.14). if (Period(body, x) is { } period && period.CompareTo(EInteger.FromInt32(LargestPeriod)) <= 0) return OverResidues(kind, x, integers, body, period, isExact); @@ -139,12 +139,12 @@ internal enum Kind { All, Some, Unique } // A statement about a sum or a product up to x, over the whole numbers from some // least one, is proved by induction: it holds at the least member, and holding at // x it holds at x + 1, where the sum to x + 1 is the sum to x and one more term. - // The reference's chapter 5. https://github.com/asc-community/AngouriMath/issues/1409 + // Sullivan and Mackey's chapter 5. https://github.com/asc-community/AngouriMath/issues/1409 if (kind == Kind.All && LeastMember(set) is { } least && ByInduction(x, set, least, body, isExact) is { } byInduction) return byInduction; // And an inequality with an exponential or a factorial in x, by induction with the // step read off a multiple of the hypothesis: P(x + 1) = c P(x) + D with c >= 0 and - // D >= 0 keeps P >= 0 (Ex 5.3.2, Prob 5.7.2, 5.7.8 of the reference). + // D >= 0 keeps P >= 0 (Sullivan and Mackey's Ex 5.3.2, Prob 5.7.2, 5.7.8). if (kind == Kind.All && LeastMember(set) is { } first && ByInductionOnAnInequality(x, set, first, body, isExact) is { } byGrowth) return byGrowth; if (Witness(kind, x, set, body, isExact) is { } byWitness) diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Discrete/Evaluation.Discrete.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Discrete/Evaluation.Discrete.Classes.cs index e5f2cc30f..903177c55 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Discrete/Evaluation.Discrete.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Discrete/Evaluation.Discrete.Classes.cs @@ -512,7 +512,7 @@ protected override Entity InnerSimplify(bool isExact) // {x, 1} has two elements unless x is 1, so a set is counted once its // elements are numbers, which are distinct exactly when unequal -- or // listed sets of such, which are compared by their members: { 1, {} } - // has two members and { {} } has one (the reference's §3.3.7). + // has two members and { {} } has one (Sullivan and Mackey's §3.3.7). FiniteSet finite when finite.All(Countable) => Integer.Create(finite.Count), // A power set of a counted set has 2^n members. diff --git a/Sources/AngouriMath/Functions/NumberTheory/ResidueClasses.cs b/Sources/AngouriMath/Functions/NumberTheory/ResidueClasses.cs index 8430ef8d5..5eb88f4a3 100644 --- a/Sources/AngouriMath/Functions/NumberTheory/ResidueClasses.cs +++ b/Sources/AngouriMath/Functions/NumberTheory/ResidueClasses.cs @@ -15,7 +15,7 @@ namespace AngouriMath.Functions { /// - /// The residue classes modulo n as sets, and the arithmetic the reference does on them: + /// The residue classes modulo n as sets, and the arithmetic Sullivan and Mackey's proofs book does on them: /// a class is written { x in ZZ : x = r (mod n) }, with r in [0, n), and /// that is what solving a linear congruence answers, what two congruences intersect to by /// the Chinese remainder theorem, and what an interval cuts a finite set out of. diff --git a/Sources/Tests/UnitTests/Algebra/MembershipSolvingTest.cs b/Sources/Tests/UnitTests/Algebra/MembershipSolvingTest.cs index 93a66654d..f051f9325 100644 --- a/Sources/Tests/UnitTests/Algebra/MembershipSolvingTest.cs +++ b/Sources/Tests/UnitTests/Algebra/MembershipSolvingTest.cs @@ -17,8 +17,8 @@ namespace AngouriMath.Tests.Algebra /// an interval as its bounds. It answered the empty set for every one of these, and /// for every statement it had no arm for -- a claim that no x exists, made about /// x^2 in (0; 1). A statement the solver cannot read is the set of x with the - /// property now, left as written. The reference's pre-images (Sullivan and Mackey, - /// Ex 7.3.10, §7.3.5 Try 1) are this. + /// property now, left as written. Sullivan and Mackey's pre-images + /// (Ex 7.3.10, §7.3.5 Try 1) are this. /// /// [Trait("Area", "Algebra")] diff --git a/Sources/Tests/UnitTests/Core/BinomialIdentityTest.cs b/Sources/Tests/UnitTests/Core/BinomialIdentityTest.cs index 3331bf1a7..9effaabcc 100644 --- a/Sources/Tests/UnitTests/Core/BinomialIdentityTest.cs +++ b/Sources/Tests/UnitTests/Core/BinomialIdentityTest.cs @@ -15,7 +15,7 @@ namespace AngouriMath.Tests.Core /// /// The binomial coefficient's identities: Pascal's rule, the chairperson identity and the /// symmetry as rewrite rules, and the binomial theorem read backwards for a sum written - /// with binomial(n, k). Item 7 of the reference's docket (Sullivan and Mackey, + /// with binomial(n, k). Item 7 of the #1409 docket (Sullivan and Mackey, /// §8.4: Props 8.4.1–8.4.4, Thm 8.4.8, Ex 8.4.9, §8.4.5 Try 3). /// /// diff --git a/Sources/Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs b/Sources/Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs index 87c53cc1e..93a0843a7 100644 --- a/Sources/Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs +++ b/Sources/Tests/UnitTests/Core/Sets/ImageAndPreImageTest.cs @@ -13,7 +13,7 @@ namespace AngouriMath.Tests.Core.Sets { /// - /// The image and the pre-image of a set under an expression: item 6 of the reference's docket + /// The image and the pre-image of a set under an expression: item 6 of the #1409 docket /// (Sullivan and Mackey, §7.3), the half that needs no pair. image(f(x), x in A) is /// { f(x) : x in A }, an indexed union of singletons; preimage(f(x), x in A, Y) /// is { x in A : f(x) in Y }, solved where the membership is read. diff --git a/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs b/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs index dc5922a40..ff3df98af 100644 --- a/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs +++ b/Sources/Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs @@ -14,8 +14,8 @@ namespace AngouriMath.Tests.Core.Sets { /// /// Indexed unions and intersections, the complement relative to a universe, and the - /// integer range [n] = ZZ+ /\ [1; n] the reference writes them over (Sullivan and - /// Mackey, §§3.5–3.6 and Problem 3.11.21), with its examples as the rows. An index name is + /// integer range [n] = ZZ+ /\ [1; n] Sullivan and Mackey write them over + /// (§§3.5–3.6 and Problem 3.11.21), with its examples as the rows. An index name is /// k or n below where the book writes i, which is the imaginary unit here. /// /// diff --git a/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs b/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs index 224ea7fde..20c62ffe2 100644 --- a/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs +++ b/Sources/Tests/UnitTests/Core/Sets/SubsetTest.cs @@ -15,8 +15,8 @@ namespace AngouriMath.Tests.Core.Sets { /// /// A subset B, set equality by double containment, and powerset(A): the set - /// statements and constructions of the reference's chapter 3 (Sullivan and Mackey, An - /// Introduction to Proofs, §§3.3–3.5), with its examples and exercises as the rows. + /// statements and constructions of chapter 3 of Sullivan and Mackey's An + /// Introduction to Proofs (§§3.3–3.5), with its examples and exercises as the rows. /// /// [Trait("Area", "Sets")] From 7169cd156d9b9cf47f74509cdcdcac1d2bdeecc7 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 08:58:49 +0000 Subject: [PATCH 4/5] AGENTS.md: a reference is named where it is cited Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- AGENTS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index fe7520c39..ab2991600 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -413,6 +413,11 @@ exists to stop, and it has happened: the first pass over [#1409](https://github.com/asc-community/AngouriMath/issues/1409)'s book was a table of contents turned into a feature list. +**And name it where you cite it.** A comment, a test summary or a changelog entry that says +"the reference's Ex 5.3.2" names nothing once a second reference exists, and there will be a +second one. Write the authors — *Sullivan and Mackey's Ex 5.3.2* — or the title, the way a paper +is cited, at every citation and not only the first. + ## Working practice **A plan belongs in an issue, not in a comment.** When work splits into separable pieces — or when From ce2594b9601181442a47fe318bae6112e09896ae Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Mon, 21 Sep 2026 09:15:35 +0000 Subject: [PATCH 5/5] Docs/References.md: the works the code and its tests draw on, with links, as the credits Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- AGENTS.md | 4 ++- Sources/AngouriMath/Docs/References.md | 49 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Sources/AngouriMath/Docs/References.md diff --git a/AGENTS.md b/AGENTS.md index ab2991600..c5b11a605 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -416,7 +416,8 @@ turned into a feature list. **And name it where you cite it.** A comment, a test summary or a changelog entry that says "the reference's Ex 5.3.2" names nothing once a second reference exists, and there will be a second one. Write the authors — *Sullivan and Mackey's Ex 5.3.2* — or the title, the way a paper -is cited, at every citation and not only the first. +is cited, at every citation and not only the first, and put the work with its link in +[`Docs/References.md`](Sources/AngouriMath/Docs/References.md), which is the credits. ## Working practice @@ -646,6 +647,7 @@ are short, and a stale one is worse than none — if you change what a file desc | [`Docs/Usage/Syntax.md`](Sources/AngouriMath/Docs/Usage/Syntax.md) | what the parser accepts. The grammar was the only statement of it until [#706](https://github.com/asc-community/AngouriMath/pull/706) | | [`Docs/Usage/Exceptions.md`](Sources/AngouriMath/Docs/Usage/Exceptions.md) | the exception hierarchy under `AngouriMathBaseException` | | [`Docs/Usage/Comparison.md`](Sources/AngouriMath/Docs/Usage/Comparison.md) | how we measure against Math.NET Symbolics, Symbolism and SymPy, with the versions and what each comparison does not establish | +| [`Docs/References.md`](Sources/AngouriMath/Docs/References.md) | the books, papers, corpora and reference works the code and its tests draw on, with the link and what each is used for. Add a work there when it is first cited | | [`Docs/Contributing/`](Sources/AngouriMath/Docs/Contributing/README.md) | the index of the contributor docs | | [`Contributing/General.md`](Sources/AngouriMath/Docs/Contributing/General.md) | the `Entity` hierarchy, in a paragraph | | [`Contributing/AddingNode.cs`](Sources/AngouriMath/Docs/Contributing/AddingNode.cs) | every place a new node has to be taught about. Read it *before* adding one | diff --git a/Sources/AngouriMath/Docs/References.md b/Sources/AngouriMath/Docs/References.md new file mode 100644 index 000000000..52aded799 --- /dev/null +++ b/Sources/AngouriMath/Docs/References.md @@ -0,0 +1,49 @@ +# References + +The books, papers, corpora and libraries this code and its tests draw on, with what each is used +for. A citation in a comment, a test summary or a changelog entry names the work as it is named +here — *Sullivan and Mackey's Ex 5.3.2*, *Bronstein §2.2* — and this page carries the full title +and the link. Add a work here when it is first cited. + +## Textbooks + +- **Sullivan, Brendan W., with Mackey, John.** *Everything You Always Wanted To Know About + Mathematics (But didn't even know to ask): A Guided Journey Into the World of Abstract + Mathematics and the Writing of Proofs.* Carnegie Mellon University, 2013. + . + The proofs book of [#1409](https://github.com/asc-community/AngouriMath/issues/1409): sets, + subsets and power sets, indexed unions and intersections, the integer range `[n]`, quantified + statements, congruences and residue classes, image and pre-image, injectivity and surjectivity, + binomial identities, and induction — its examples and exercises are the rows of + `QuantifierTest`, `SubsetTest`, `IndexedSetOperationTest`, `ImageAndPreImageTest`, + `BinomialIdentityTest`, `InductionTest` and `ThresholdSetTest`. +- **Bronstein, Manuel.** *Symbolic Integration I: Transcendental Functions.* 2nd ed., Springer, + 2005. The Hermite reduction, the rational and logarithmic parts, and the Risch structure the + integrator follows. +- **von zur Gathen, Joachim, and Gerhard, Jürgen.** *Modern Computer Algebra.* 3rd ed., Cambridge + University Press, 2013. The polynomial layer: gcds, factorisation, resultants. +- **Gruntz, Dominik.** *On Computing Limits in a Symbolic Manipulation System.* PhD thesis, ETH + Zürich, 1996. The limit algorithm. +- **Timofeev, A. F.** *Integration of Functions* (Интегрирование функций). 1948. Its integrals are + a family of Rubi's test suite, and are cited by his name where one of them is the row. + +## Corpora + +- **Rubi — Rule-based Integration** (Albert D. Rich et al.), , + and its test problems, : the integration + corpus the integrator is measured against + ([#718](https://github.com/asc-community/AngouriMath/issues/718)). +- **Wester, Michael.** *A Critique of the Mathematical Abilities of CA Systems*, in *Computer + Algebra Systems: A Practical Guide*, Wiley, 1999. The Wester problems of `Docs/Usage/Comparison.md`. + +## Reference works + +- **NIST Digital Library of Mathematical Functions (DLMF)**, : the + identities and branch cuts of the special functions, cited by section (`DLMF 4.23`). +- **Wolfram MathWorld**, : conventions and the names of things, + where a convention is chosen and the choice recorded. +- **mathlib4**, : the hypotheses of an + identity, machine-checked, which is what a rewrite rule's contract is checked against + (`Contributing/SimplificationContract.md`). +- **SymPy**, : readable reference implementations of Risch, Gruntz and + Gröbner, with the papers cited in the docstrings; the target of `ToSympyCode`.