From ae392f661189631a72ac5e4a9cbd80b2fb14140e Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 4 Sep 2026 18:52:15 +0000 Subject: [PATCH 1/5] Four more, and two that sit beside them and cannot k - k = 0 loses everything it matched for one node, and the operand was matched twice, so the delta is -2|k|. sgn(a) * abs(a) = a keeps one copy of three nodes around two, for -(3 + |a|). c / (d * a) = (c / d) / a folds its two numbers into one as the replacement is built, for exactly -2. And (f + a) + g = f + g + a regroups three operands without adding or dropping anything. Two rules in the same sets look like the ones above and are not. k + k = 2 * k is 1 - |k|, and a + (a + b) = 2 * a + b is the same figure: a sum of two copies becomes a product with a literal, which is one node shorter where the operand is a leaf and longer where it is anything else. The corpus measures the first of them between -2 and 0, which is the shape of a rule that has no growth to declare rather than one nobody has looked at. Verified with the targeted tests: 320 green. Part of #825. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Transformations/Matching/MatchedRules.cs | 20 +++++++++++++++---- .../Docs/Contributing/WritingARule.md | 2 +- .../Transformations/RuleAuthoringGuideTest.cs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index ae170f2cc..9b731130c 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -3211,7 +3211,10 @@ is var (divided, remainder) MatchPattern.Commutative(MatchPattern.Node(MatchPattern.Any("f"), MatchPattern.Any("a")), MatchPattern.Any("g")), bound => bound["f"] + bound["g"] + bound["a"], Soundness.SoundUnderAssumptions, - description: "(f + a) + g = f + g + a, for functions f and g"), + description: "(f + a) + g = f + g + a, for functions f and g", + // The three operands are regrouped and nothing else moves: two sums stay two sums + // and each hole is used once on both sides. + growth: RewriteRuleGrowth.Rearranges), new MatchedRule( "a-variable-times-a-number-puts-the-number-first", MatchPattern.Node(MatchPattern.Any("v"), MatchPattern.Any("c")), @@ -3312,7 +3315,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Any("a"), MatchPattern.Any("a")), bound => Integer.Zero, Soundness.Sound, - description: "k - k = 0"), + description: "k - k = 0", + // Everything the pattern matched goes and one node arrives, and the operand was + // matched twice: the delta is -2|k|, at most -2 and further the larger it is. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-factor-shared-by-a-quotient-and-a-product-added-comes-out", MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("a"), MatchPattern.Any("b")), MatchPattern.Commutative(MatchPattern.Any("a"), MatchPattern.Any("c"))), @@ -3412,7 +3418,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Commutative(MatchPattern.Any("d"), MatchPattern.Any("a"))), bound => (Number)bound["c"] / (Number)bound["d"] / bound["a"], Soundness.SoundUnderAssumptions, - description: "c / (d * a) = (c / d) / a, for numeric c and d"), + description: "c / (d * a) = (c / d) / a, for numeric c and d", + // The two numbers are folded into one as the replacement is built, so four nodes + // around the remaining hole become two: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "two-numbers-around-a-factor-collect", MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Node(MatchPattern.Any("d"), MatchPattern.Any("a"))), @@ -3519,7 +3528,10 @@ is var (divided, remainder) MatchPattern.Commutative(MatchPattern.Node(MatchPattern.Any("a")), MatchPattern.Node(MatchPattern.Any("a"))), bound => bound["a"], Soundness.SoundUnderAssumptions, - description: "sgn(a) * abs(a) = a"), + description: "sgn(a) * abs(a) = a", + // Three nodes around two copies of the operand become the one copy that is left, so + // the delta is -(3 + |a|): at most -4. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-reciprocal-rational-factor-is-a-division", MatchPattern.Commutative(MatchPattern.Any("r", one => Functions.Patterns.IsWholeReciprocal(one, 1)), MatchPattern.Any("a")), diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index 3d9625c69..0bd8ce941 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -133,7 +133,7 @@ A pattern replacement gets: - **an exact growth**, counted from the two patterns rather than declared. A code replacement gets neither, and its growth is `Unknown` unless you declare one. That is the -honest default — **175** rules sit at `Unknown` — but declare it where you can justify it: +honest default — **171** rules sit at `Unknown` — but declare it where you can justify it: ```csharp // The Chebyshev expansion of sin(n * a) is a sum of n terms where the pattern is one node, diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs index aeb19d45e..28c465bf4 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs @@ -84,7 +84,7 @@ public void ReplacementAPatternOrCode() "how many rules have a pattern on both sides"); Stated(33, rules.Count(rule => rule.Reversed is not null), "how many two-sided rules have a direction"); - Stated(175, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), + Stated(171, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), "how many rules sit at Unknown growth"); // And the two the document names. By their own names rather than by what the prose From f8ff2d9361f1ed4abada9fbb63cfdfeca788f57d Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 4 Sep 2026 19:05:24 +0000 Subject: [PATCH 2/5] Six more, and two shapes that make the counting easier A pattern that binds nothing has a fixed size on both sides, so the delta is a number and there is nothing to argue: arctan(sqrt(3)) = pi/3 is four nodes to three, arctan(1 / sqrt(3)) = pi/6 is six to three, and { True, False } becomes the one node of the boolean domain. The unbounded interval is the same, its bounds being matched exactly rather than bound. x in {a} = (x = a) drops the singleton and turns the membership into an equality, one node for one, for exactly -1. (c * f) * (d * g) folds its two numbers into one as the replacement is built, for exactly -2. Both of those shapes are written into WritingARule.md, the folding especially: `(c * v) * d` collects where the same rule written without the cast would only rearrange, and that is a difference a reader will not see unless told to look for it. Five more were read and left alone. The family that gathers a repeated operand into a doubling -- a + (a - b), a - (b - a), (b - a) - a and k + k -- is all 1 - |a|, and the two rules that cancel a shared factor out of a quotient attach a Provided sized by that factor. Verified with the targeted tests: 320 green. Part of #825. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Transformations/Matching/MatchedRules.cs | 30 +++++++++++++++---- .../Docs/Contributing/WritingARule.md | 8 +++-- .../Transformations/RuleAuthoringGuideTest.cs | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index 9b731130c..8ac4ad17e 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -1594,14 +1594,20 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Node(MatchPattern.Exact(Integer.Create(3)), MatchPattern.Exact(Rational.Create(1, 2)))), bound => MathS.pi / 3, Soundness.Sound, - description: "arctan(sqrt(3)) = pi/3"), + description: "arctan(sqrt(3)) = pi/3", + // The pattern binds nothing, so both sides are a fixed size and the delta is a + // number rather than an expression in the operands. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "the-arctangent-of-one-over-root-three", MatchPattern.Node(MatchPattern.Node(MatchPattern.Exact(Integer.Create(1)), MatchPattern.Node(MatchPattern.Exact(Integer.Create(3)), MatchPattern.Exact(Rational.Create(1, 2))))), bound => MathS.pi / 6, Soundness.Sound, - description: "arctan(1 / sqrt(3)) = pi/6"), + description: "arctan(1 / sqrt(3)) = pi/6", + // The pattern binds nothing, so both sides are a fixed size and the delta is a + // number rather than an expression in the operands. + growth: RewriteRuleGrowth.Collects), // The cosecant's own condition has to be carried: 2cos(u) is a number where // sin(u) is zero and sin(2u) csc(u) is not. @@ -1967,7 +1973,10 @@ is var (divided, remainder) MatchPattern.Any("s", finite => finite.Count == 1)), bound => bound["x"].EqualTo(((Set.FiniteSet)bound["s"]).First()), Soundness.Sound, - description: "x in {a} = (x = a)"), + description: "x in {a} = (x = a)", + // The singleton set goes and the membership becomes an equality, one node for one, + // so exactly -1. `EqualTo` is a bare `Equalsf` and does not chain. + growth: RewriteRuleGrowth.Collects), // x in (a; b) is written out as the inequalities it stands for new MatchedRule( @@ -1992,7 +2001,10 @@ is var (divided, remainder) "s", finite => finite == Functions.Patterns.FullBooleanSet), bound => Set.SpecialSet.Create(Domain.Boolean), Soundness.Sound, - description: "{ True, False } = the boolean domain"), + description: "{ True, False } = the boolean domain", + // The pattern binds nothing, so both sides are a fixed size and the delta is a + // number rather than an expression in the operands. + growth: RewriteRuleGrowth.Collects), // (-oo; +oo) is the domain it is an interval of, where that domain names a set. // The Any case is refused in the condition rather than left to the replacement: @@ -2008,7 +2020,10 @@ is var (divided, remainder) && interval.Codomain is not Domain.Any), bound => Set.SpecialSet.Create(((Set.Interval)bound["i"]).Codomain), Soundness.Sound, - description: "(-oo; +oo) = the domain it is an interval of")); + description: "(-oo; +oo) = the domain it is an interval of", + // The interval and its two bounds become the one node of a special set, and the + // bounds are matched exactly rather than bound, so the delta is a number. + growth: RewriteRuleGrowth.Collects)); /// /// , as data — one set per sort level. @@ -3205,7 +3220,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("f")), MatchPattern.Node(MatchPattern.Any("d"), MatchPattern.Any("g"))), bound => bound["f"] * bound["g"] * ((Number)bound["c"] * (Number)bound["d"]), Soundness.SoundUnderAssumptions, - description: "(c * f) * (d * g) = f * g * (c * d), for numeric c and d"), + description: "(c * f) * (d * g) = f * g * (c * d), for numeric c and d", + // The two numbers are folded into one as the replacement is built, so five nodes + // around the two functions become three: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "two-functions-in-a-sum-come-together", MatchPattern.Commutative(MatchPattern.Node(MatchPattern.Any("f"), MatchPattern.Any("a")), MatchPattern.Any("g")), diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index 0bd8ce941..baac74923 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -133,7 +133,7 @@ A pattern replacement gets: - **an exact growth**, counted from the two patterns rather than declared. A code replacement gets neither, and its growth is `Unknown` unless you declare one. That is the -honest default — **171** rules sit at `Unknown` — but declare it where you can justify it: +honest default — **165** rules sit at `Unknown` — but declare it where you can justify it: ```csharp // The Chebyshev expansion of sin(n * a) is a sum of n terms where the pattern is one node, @@ -157,7 +157,11 @@ cannot argue the claim from the code, leave it `Unknown`. of a few shapes. A hole matched twice and written once gives `-(1 + |a|)`, which is a `Collects` stronger than the corpus will show you, since the corpus fills its holes with single nodes. A replacement holding no hole at all — a constant, or `pi/2` — collects by the whole of the pattern. -Operators mapping one for one with every hole used once is `Rearranges`. +Operators mapping one for one with every hole used once is `Rearranges`. A pattern that binds +nothing — `arctan(sqrt(3)) = pi/3`, `{ True, False }` — has a fixed size on both sides, so its delta +is a number and there is nothing to argue. And two numbers combined with `Number` arithmetic **fold +into one node** as the replacement is built, which is worth two on its own: `(c * v) * d` collects +where the same rule written without the cast would only rearrange. **Four shapes look declarable and are not.** Each of these measured a clean, constant delta over the corpus, and each is false: diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs index 28c465bf4..af9c616b6 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs @@ -84,7 +84,7 @@ public void ReplacementAPatternOrCode() "how many rules have a pattern on both sides"); Stated(33, rules.Count(rule => rule.Reversed is not null), "how many two-sided rules have a direction"); - Stated(171, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), + Stated(165, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), "how many rules sit at Unknown growth"); // And the two the document names. By their own names rather than by what the prose From cdf947bf5707c2da7343597ce09d825caab2e424 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 4 Sep 2026 19:26:50 +0000 Subject: [PATCH 3/5] The inverse-of-a-function rules collect, and a test outlives its premise arcsin(sin(a)), arccos(cos(a)), arctan(tan(a)) and arccotan(cotan(a)) each drop a function and its inverse and hand the angle back untouched: exactly -2, whatever the angle is. (c * f) * g = c * (f * g) moves the numeric factor outside and brings the two functions together, which is two products either way round. MostSoundRulesHaveNoJudgedGrowth is renamed rather than loosened. It asserted a fact about the library -- that the great majority of sound rules are unjudged, 69 of 324 when it was written -- and the declarations of #825 have made that false: 164 of 324 now carry a judged growth. Its threshold was already moved once, from a quarter to a half; moving it a second time would be keeping a name that says the opposite of what the library does. What is still true and still worth guarding is that the ceiling is doing something. TheGrowthCeilingStillLeavesASubstantialPartOut asserts that the Rearranges ceiling the transformation catalogue actually uses leaves more than a quarter of the sound rules out, and that not every rule is judged -- either of which failing would mean RulesUpTo has stopped being a dial and a caller asking for the narrow set is paying for a distinction that is gone. Verified with the targeted tests: 320 green. Part of #825. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Transformations/Matching/MatchedRules.cs | 25 ++++++++++--- .../Docs/Contributing/WritingARule.md | 2 +- .../CanonicalExtractionTest.cs | 37 +++++++++++++------ .../Transformations/RuleAuthoringGuideTest.cs | 2 +- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index 8ac4ad17e..a23a18ecb 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -1635,7 +1635,10 @@ is var (divided, remainder) bound => bound["a"], Soundness.SoundUnderAssumptions, when: bound => Functions.Patterns.WithinHalfPi(bound["a"], closed: true), - description: "arcsin(sin(a)) = a, for a in [-pi/2; pi/2]"), + description: "arcsin(sin(a)) = a, for a in [-pi/2; pi/2]", + // The function and its inverse both go and the angle is handed back untouched, so + // two nodes disappear whatever the angle is: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "arccosine-of-a-cosine-inside-its-own-interval", @@ -1643,7 +1646,10 @@ is var (divided, remainder) bound => bound["a"], Soundness.SoundUnderAssumptions, when: bound => Functions.Patterns.WithinZeroAndPi(bound["a"], closed: true), - description: "arccos(cos(a)) = a, for a in [0; pi]"), + description: "arccos(cos(a)) = a, for a in [0; pi]", + // The function and its inverse both go and the angle is handed back untouched, so + // two nodes disappear whatever the angle is: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "arctangent-of-a-tangent-inside-its-own-interval", @@ -1651,7 +1657,10 @@ is var (divided, remainder) bound => bound["a"], Soundness.SoundUnderAssumptions, when: bound => Functions.Patterns.WithinHalfPi(bound["a"], closed: false), - description: "arctan(tan(a)) = a, for a in (-pi/2; pi/2)"), + description: "arctan(tan(a)) = a, for a in (-pi/2; pi/2)", + // The function and its inverse both go and the angle is handed back untouched, so + // two nodes disappear whatever the angle is: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "arccotangent-of-a-cotangent-inside-its-own-range", @@ -1659,7 +1668,10 @@ is var (divided, remainder) bound => bound["a"], Soundness.SoundUnderAssumptions, when: bound => Functions.Patterns.WithinArccotanRange(bound["a"]), - description: "arccotan(cotan(a)) = a, for a in arccotan's own range"), + description: "arccotan(cotan(a)) = a, for a in arccotan's own range", + // The function and its inverse both go and the angle is handed back untouched, so + // two nodes disappear whatever the angle is: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-sine-of-an-arcsine", @@ -3150,7 +3162,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("f")), MatchPattern.Any("g")), bound => bound["f"] * bound["g"] * bound["c"], Soundness.SoundUnderAssumptions, - description: "(c * f) * g = c * (f * g), for a numeric c"), + description: "(c * f) * g = c * (f * g), for a numeric c", + // The numeric factor moves to the outside of the product and the two functions come + // together, which is two products either way round: the same size for every input. + growth: RewriteRuleGrowth.Rearranges), new MatchedRule( "a-product-of-two-quotients-is-one-quotient", MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("a"), MatchPattern.Any("b")), MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("d"))), diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index baac74923..eebd2da1d 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -133,7 +133,7 @@ A pattern replacement gets: - **an exact growth**, counted from the two patterns rather than declared. A code replacement gets neither, and its growth is `Unknown` unless you declare one. That is the -honest default — **165** rules sit at `Unknown` — but declare it where you can justify it: +honest default — **160** rules sit at `Unknown` — but declare it where you can justify it: ```csharp // The Chebyshev expansion of sin(n * a) is a sum of n terms where the pattern is one node, diff --git a/Sources/Tests/UnitTests/Core/Transformations/CanonicalExtractionTest.cs b/Sources/Tests/UnitTests/Core/Transformations/CanonicalExtractionTest.cs index 49ea334af..5f92948f7 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/CanonicalExtractionTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/CanonicalExtractionTest.cs @@ -417,24 +417,37 @@ public void AWiderCeilingIsASuperset() /// /// Where the rules actually are, asserted rather than described — the fact that decides - /// what the growth ceiling is worth. The great majority are unjudged, because their - /// replacement is code rather than a written pattern, so a ceiling below the widest - /// leaves most of the library out. + /// what the growth ceiling is worth. /// + /// + /// + /// This used to say that the great majority are unjudged and to guard the share at under + /// a quarter: 69 of 324 when it was written. The declarations of + /// #825 took it past + /// half — 164 of 324 — so the old premise is spent rather than merely out of date, and + /// the test is renamed instead of having its number loosened again. + /// + /// + /// What is worth guarding now is that the ceiling is still doing something. It is the + /// Rearranges one that the transformation catalogue actually uses, and if it ever + /// admits nearly everything then has stopped being a + /// dial and the caller who asks for the narrow set is paying for a distinction that is no + /// longer there. + /// + /// [Fact] - public void MostSoundRulesHaveNoJudgedGrowth() + public void TheGrowthCeilingStillLeavesASubstantialPartOut() { + var used = Saturation.RulesUpTo(RewriteRuleGrowth.Rearranges).Count; var judged = Saturation.RulesUpTo(RewriteRuleGrowth.Expands).Count; var all = Saturation.RulesUpTo(RewriteRuleGrowth.Unknown).Count; - // It was under a quarter and is now about a quarter: 69 of 324 when this was first - // measured, 85 as the declarations of #825 land. The share is meant to rise, so the - // guard is that it has not become the majority -- at which point the ceiling would - // be excluding little and this test's premise would be gone rather than merely - // out of date. - Assert.True(all > 2 * judged, - $"{judged} of {all} sound rules have a judged growth, which is more than half " - + "-- the ceiling now excludes so little that it is worth asking what it is for"); + Assert.True(all > judged, + $"every one of the {all} sound rules now has a judged growth, so the ceiling " + + "excludes nothing at all and is no longer a dial"); + Assert.True(all - used > all / 4, + $"the ceiling the catalogue uses admits {used} of {all} sound rules, leaving " + + $"{all - used} out -- less than a quarter, so it has stopped being a dial"); } #endregion diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs index af9c616b6..d9834c948 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs @@ -84,7 +84,7 @@ public void ReplacementAPatternOrCode() "how many rules have a pattern on both sides"); Stated(33, rules.Count(rule => rule.Reversed is not null), "how many two-sided rules have a direction"); - Stated(165, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), + Stated(160, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), "how many rules sit at Unknown growth"); // And the two the document names. By their own names rather than by what the prose From b55f6c7b47193a23d2a79ae1894d63453327ce6e Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 4 Sep 2026 19:39:42 +0000 Subject: [PATCH 4/5] Six more, and the exponent-raising family is settled as Unknown arctan(a) + arctan(b) matches both operands as Real, so both are leaves, and folds the tangent formula to a single one through the InnerSimplified on it: five nodes become two, exactly -3. a ^ (c * n) / b ^ n and its mirror match the exponent twice and write it once, for -(1 + |n|). a / b^n / b^m does the same with the base, for -(2 + |b|). (c * f) * d folds its two numbers into one, for exactly -2. And a ^ (n / log(c, a)) = c ^ n matches its base twice -- once as the base and once inside the logarithm -- and writes it not at all. The family that raises or lowers an exponent by one is settled the other way, and it is large: a^n * a, a^n / a, a / a^n, a / b^n / b, a / b / b^n, a^n * (a * rest), a / b / b, a * a, and the sums and differences that gather a repeated operand into a doubling. Every one of them is 1 - |a|: the pattern holds the operand twice and the replacement once, but the replacement pays a literal for it, so the two cancel exactly where the operand is a leaf and the rule shrinks only where it is larger. There is no label that is true of all of them, and the corpus measures each as a clean constant because the operands it generates are single nodes. The two rules that bring a factor out of a sum of a product and a quotient are the same figure, 1 - |a|. Verified with the targeted tests: 320 green. Part of #825. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- .../Transformations/Matching/MatchedRules.cs | 32 +++++++++++++++---- .../Docs/Contributing/WritingARule.md | 2 +- .../Transformations/RuleAuthoringGuideTest.cs | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index a23a18ecb..0002010e7 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -1587,7 +1587,11 @@ is var (divided, remainder) / (1 - (Real)bound["a"] * (Real)bound["b"])).InnerSimplified), Soundness.SoundUnderAssumptions, when: bound => ((Real)bound["a"] * (Real)bound["b"]).Evaled is Real product && product < 1, - description: "arctan(a) + arctan(b) = arctan((a + b) / (1 - a*b)), while a*b < 1"), + description: "arctan(a) + arctan(b) = arctan((a + b) / (1 - a*b)), while a*b < 1", + // Both operands are matched as Real and so are leaves, and the tangent formula is + // folded to a single one by the InnerSimplified on it, so five nodes become two: + // exactly -3, for every pair the `when` admits. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "the-arctangent-of-root-three", @@ -2724,7 +2728,11 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("a")))), bound => new Powf(bound["c"], bound["n"]), Soundness.SoundUnderAssumptions, - description: "a ^ (n / log(c, a)) = c ^ n"), + description: "a ^ (n / log(c, a)) = c ^ n", + // The base is matched twice -- once as the base and once inside the logarithm -- and + // written not at all, and the quotient and the logarithm go with it: the delta is + // -(3 + 2|a|), at most -5. + growth: RewriteRuleGrowth.Collects), // Both orientations are written out in the `switch`, so one commutative rule fires // exactly where the pair did. @@ -2827,7 +2835,10 @@ is var (divided, remainder) MatchPattern.Any("n")))), bound => new Powf(bound["a"] / new Powf(bound["b"], bound["c"]), bound["n"]), Soundness.SoundUnderAssumptions, - description: "a ^ n / b ^ (c * n) = (a / b ^ c) ^ n, for a positive whole c"), + description: "a ^ n / b ^ (c * n) = (a / b ^ c) ^ n, for a positive whole c", + // The exponent is matched twice and written once, and one power node goes: the delta + // is -(1 + |n|), at most -2 and further the larger the exponent is. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-quotient-of-powers-whose-exponents-differ-by-a-whole-factor-takes-it-into-the-dividend", @@ -2840,7 +2851,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Any("b"), MatchPattern.Any("n"))), bound => new Powf(new Powf(bound["a"], bound["c"]) / bound["b"], bound["n"]), Soundness.SoundUnderAssumptions, - description: "a ^ (c * n) / b ^ n = (a ^ c / b) ^ n, for a positive whole c"), + description: "a ^ (c * n) / b ^ n = (a ^ c / b) ^ n, for a positive whole c", + // The exponent is matched twice and written once, and one power node goes with it: + // the delta is -(1 + |n|), the mirror of the rule that takes it into the divisor. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-thing-over-a-power-of-itself-is-one-power", @@ -2997,7 +3011,10 @@ is var (divided, remainder) MatchPattern.Node(MatchPattern.Any("b"), MatchPattern.Any("n"))), bound => bound["a"] / new Powf(bound["b"], bound["n"] + bound["m"]), Soundness.SoundUnderAssumptions, - description: "a / b ^ n / b ^ m = a / b ^ (n + m)"), + description: "a / b ^ n / b ^ m = a / b ^ (n + m)", + // The base is matched twice and written once, and one quotient and one power go: + // the delta is -(2 + |b|), at most -3. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "a-variable-times-a-power-puts-the-power-first", @@ -3229,7 +3246,10 @@ is var (divided, remainder) MatchPattern.Commutative(MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("f")), MatchPattern.Any("d")), bound => (Number)bound["c"] * (Number)bound["d"] * bound["f"], Soundness.SoundUnderAssumptions, - description: "(c * f) * d = (c * d) * f, for numeric c and d"), + description: "(c * f) * d = (c * d) * f, for numeric c and d", + // The two numbers are folded into one as the replacement is built, so four nodes + // around the function become two: exactly -2. + growth: RewriteRuleGrowth.Collects), new MatchedRule( "two-numeric-multiples-of-functions-collect-their-numbers", MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("f")), MatchPattern.Node(MatchPattern.Any("d"), MatchPattern.Any("g"))), diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index eebd2da1d..572354fa5 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -133,7 +133,7 @@ A pattern replacement gets: - **an exact growth**, counted from the two patterns rather than declared. A code replacement gets neither, and its growth is `Unknown` unless you declare one. That is the -honest default — **160** rules sit at `Unknown` — but declare it where you can justify it: +honest default — **154** rules sit at `Unknown` — but declare it where you can justify it: ```csharp // The Chebyshev expansion of sin(n * a) is a sum of n terms where the pattern is one node, diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs index d9834c948..6b4825002 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs @@ -84,7 +84,7 @@ public void ReplacementAPatternOrCode() "how many rules have a pattern on both sides"); Stated(33, rules.Count(rule => rule.Reversed is not null), "how many two-sided rules have a direction"); - Stated(160, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), + Stated(154, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), "how many rules sit at Unknown growth"); // And the two the document names. By their own names rather than by what the prose From 874a4355ded14f1a28af65e31f69c39695503259 Mon Sep 17 00:00:00 2001 From: Rafael Vuijk Date: Fri, 4 Sep 2026 19:42:25 +0000 Subject: [PATCH 5/5] Every rule still at Unknown has been looked at The backlog is walked to the end. Of the hundred and fifty-three rules that remain undeclared, ninety-nine compute their answer through a helper and so have no size countable from the pattern; sixteen build a comparison and chain; ten attach a Provided sized by their own operands; and the last twenty-eight are the repeated hole that pays a literal to be gathered -- a ^ n * a, a / b / b, a * a, k + k and their relatives, every one of them 1 - |a|. So Unknown in this file is now a finding rather than a gap, and the document says so, which is the part that matters to whoever writes the next rule: a new Unknown should be one too, and if it is not, the shapes above say which of the three answers it has. Getting the list right needed the rules' own SourceLine rather than a regular expression over the file. Reading the source for a lambda misses the ones written across several lines and quietly counts the pattern-replacement rules, whose growth is derived and never Unknown, so the first three attempts at this census disagreed with each other. The rules know where they were written and the compiler fills it in; asking them is exact. Verified with the targeted tests: 325 green. Part of #825. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura --- Sources/AngouriMath/Docs/Contributing/WritingARule.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index 572354fa5..283559f10 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -173,6 +173,13 @@ corpus, and each is false: | a hole can be filled by two spellings of one thing | `IsWholeReciprocal` takes the literal `1/3`, which is one node, and a written `1 / c`, which is three — so the delta is 0 in one and −2 in the other | | a hole is repeated and the replacement squares it | `a * (a * b) = a^2 * b` is `1 - |a|`: zero for a leaf and negative for anything bigger | +**Every rule still at `Unknown` has been looked at, and each falls into one of the shapes above.** +Most of them compute their answer through a helper, so there is nothing to count; the rest either +build a comparison, attach a `Provided` sized by their own operands, or are the repeated hole that +pays a literal to be gathered — `a ^ n * a`, `a / b / b`, `a * a`, `k + k` and their two dozen +relatives, every one of them `1 - |a|`. So `Unknown` here is a finding rather than a gap, and a new +`Unknown` should be one too. + **The comparison set is settled, and settled as `Unknown`.** Its sixty-odd rules were gone through one at a time and all but seven fall into the shapes above: most build their replacement with `<` or `>` and so chain; the rest either attach a `Provided` sized by their own operands — the chain