diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index e4ccd9325..a299b30d2 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -103,6 +103,28 @@ mpmath's at 4500 digits. | `Ci(exp(300))` | `0` | `NaN` | below `1e-130`, sign unknown | | `cos(10^150/3)` | `-0.44819…` | `0.80881903093981837173…` | `0.80881903093981837173…` | +### Simplify's answer is its own answer + +**Silent: same values, shorter forms.** `Simplify` gave answers that a second `Simplify` shortened. Numbers in a +product were left unmultiplied, a factor over something was left beside the product, a factor shared by a +quotient was cancelled only in one order of the divisor, and `c ^ (k log(c, a))` became `a ^ k` only where the +logarithm was one of the top two factors of the exponent. Every changed answer has the value it had. A symbolic base +of the logarithm carries `not a = 0 and not a = 1`, as the existing rule does. Of 16,684 generated and random +expressions, 333 gave answers that changed when simplified again; now 11 do, and each of those is the search finding +a different candidate. Measured on master `2a7247653` and on this branch +([#2725](https://github.com/asc-community/AngouriMath/issues/2725)). + +| `Simplify` | Was | Now | +|---|---|---| +| `e - (2 * y) * 2` | `e - 2 * 2 * y` | `e - 4 * y` | +| `((-1) - y / 3)^(-1)` | `(-3) * 1 / (3 + y)` | `(-3) / (3 + y)` | +| `((x * 3) * (-1)) / (x * x - 3)` | `3 * (-1) * x / (x ^ 2 - 3)` | `(-3) * x / (x ^ 2 - 3)` | +| `x * ((5 * 3) / pi)` | `x * 15 / pi` | `15 * x / pi` | +| `(e^2)^(1/2) / ((5 - e) * e)` | `e / (e * (5 - e))` | `1 / (5 - e)` | +| `cosh(y * ln(y))` | `(e ^ (-y * ln(y)) + y ^ y) / 2` | `(y ^ y + y ^ (-y)) / 2` | +| `e^(-x * ln(y))` | `e ^ (-x * ln(y))` | `y ^ (-x)` | +| `a^(-x * log(a, y))` | `a ^ (-x * log(a, y))` | `y ^ (-x) provided not a = 0 and not a = 1` | + ### A complex value past 10^50 keeps every part of it **Silent: wrong numbers become right ones.** The complex paths of the exponential, the trigonometric functions and the diff --git a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs index 4199d4066..cf476e0c7 100644 --- a/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs +++ b/Sources/AngouriMath/Core/Transformations/Matching/MatchedRules.cs @@ -3262,6 +3262,19 @@ is var (divided, remainder) // product and the logarithm that go. growth: RewriteRuleGrowth.Expands), + // The same three, with the logarithm a factor further down the product, as the sort + // leaves it: e ^ (-ln(y) * y) is e ^ ((-1 * ln(y)) * y). + // https://github.com/asc-community/AngouriMath/issues/2725 + new MatchedRule( + "a-base-raised-to-a-product-holding-a-logarithm-of-itself-is-a-power-of-the-antilogarithm", + MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Any("p")), + bound => Functions.Patterns.PowerOfALogarithmAmongFactors(bound["c"], (Mulf)bound["p"])!, + Soundness.SoundUnderAssumptions, + when: bound => Functions.Patterns.PowerOfALogarithmAmongFactors(bound["c"], (Mulf)bound["p"]) is not null, + // Left Unknown: the helper rebuilds the multiplier from however many factors the + // product has, and a symbolic base adds a condition. + description: "a ^ ((m * log(a, b)) * n) = b ^ (m * n)"), + // Four `switch` arms: the power on either side of a product, and the shared base in // either position inside it. A commutative pattern says both halves at once. new MatchedRule( @@ -3927,6 +3940,18 @@ is var (divided, remainder) // Left Unknown: the condition attached carries a copy of c, so the delta is // 2 - |c| -- larger at a leaf, smaller from three nodes up. description: "(num * c) / (c * den) = num / den, provided c is not zero"), + new MatchedRule( + "a-factor-cancels-out-of-a-product-it-divides", + MatchPattern.Node(MatchPattern.Any("c"), MatchPattern.Commutative(MatchPattern.Any("c"), MatchPattern.Any("den"))), + // The same two assumptions as (keep * c) / c. Without it the cancellation depended + // on the order of the divisor's factors. + // https://github.com/asc-community/AngouriMath/issues/2725 + bound => (1 / bound["den"]).Provided( + !bound["c"].EqualTo(Integer.Zero) & bound["c"].DomainCondition), + Soundness.SoundUnderAssumptions, + // Left Unknown: the condition attached carries a copy of c and c's own domain + // condition, whose size nothing here bounds. + description: "c / (c * den) = 1 / den, provided c is not zero and is defined"), new MatchedRule( "a-difference-over-its-own-reverse-is-minus-one", MatchPattern.Node(MatchPattern.Node(MatchPattern.Any("a"), MatchPattern.Any("b")), MatchPattern.Node(MatchPattern.Any("b"), MatchPattern.Any("a"))), diff --git a/Sources/AngouriMath/Docs/Contributing/WritingARule.md b/Sources/AngouriMath/Docs/Contributing/WritingARule.md index e4792ef04..451517d9e 100644 --- a/Sources/AngouriMath/Docs/Contributing/WritingARule.md +++ b/Sources/AngouriMath/Docs/Contributing/WritingARule.md @@ -18,7 +18,7 @@ effect". This is how to supply those seven things. ## Where a rule goes `Core/Transformations/Matching/MatchedRules.cs`, as a value in a `MatchedRuleSet`. **33** sets and -**343** rules live there today. +**345** rules live there today. The `switch` statements in `Functions/Simplification/Patterns` are the older form. **All thirty registered sets now run as data and describe what they run**; none executes its `switch` any more. @@ -64,7 +64,7 @@ in a name and putting the identity in brackets after it: 2. Tangent is sine over cosine (tan(a) = sin(a) / cos(a)), so tan(x) becomes sin(x) / cos(x). ``` -So the name has to be a clause that survives being read that way. **All 314 distinct rule names are, +So the name has to be a clause that survives being read that way. **All 316 distinct rule names are, and `StepAsASentenceTest` holds them to it** — a name with a capital, a bracket or an underscore fails that test rather than degrading the prose quietly. @@ -91,7 +91,7 @@ debugged for an afternoon. | `Left.ToString()` | `Divf(var a, Divf(var b, var c))` — how the matcher spells it | Write the identity with `=`, not `->`: it is an equality, and the arrow belongs to the direction the -rule happens to be applied in. **340** rules carry one today; a new rule should. +rule happens to be applied in. **342** rules carry one today; a new rule should. ## The pattern language @@ -123,7 +123,7 @@ matches and silently builds nothing. `BuildableNodeTypesTest` is the list. ## Replacement: a pattern, or code -**42** of the 343 rules have a pattern on both sides. The rest build their answer in code, and both +**42** of the 345 rules have a pattern on both sides. The rest build their answer in code, and both are legitimate — but the choice costs two things, so make it deliberately. A pattern replacement gets: @@ -138,7 +138,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 — **126** rules sit at `Unknown` — but declare it where you can justify it: +honest default — **128** 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, @@ -227,7 +227,7 @@ limit, against nothing for handing the node over. | `SoundUnderAssumptions` | holds given something the rule does not check | | `Heuristic` | usually right | -**192** of the 343 rules are `Sound` and **151** are conditional. Every one of the thirty registered +**192** of the 345 rules are `Sound` and **153** are conditional. Every one of the thirty registered *sets* declares `SoundUnderAssumptions`, because a set's tier is the **minimum** over its rules — so the set grain says nothing and the rule grain says everything. A derivation reports the rule's tier (`RewriteStep.Soundness`), which is why getting it right matters beyond the label. @@ -244,7 +244,7 @@ first decides the answer**. Two cases, and only one of them is a decision: everything `Mulf(Divf(a, b), Divf(c, d))` matches and more, so the general rule would swallow the special one and the special one would never fire. `MatchPattern.Subsumes` computes this and `MatchedRuleSet.RulesByPriority` applies it: the specific rule is tried first because of what the two -patterns *are*, not because of where you typed them. **30** rule pairs are ordered that way. +patterns *are*, not because of where you typed them. **33** rule pairs are ordered that way. **Where neither subsumes the other, the order is a bare choice and nothing but your placement makes it.** There are **39** such conflicts, and `RulePriorityTest` records every one by name. If your rule diff --git a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs index 98ba11865..bdee8041b 100644 --- a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs +++ b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs @@ -228,6 +228,16 @@ internal static Integer DenominatorOf(Entity entity) Divf(Mulf(var any2, var any1), Mulf(var any2a, var any3)) when any2 == any2a => (any1 / any3).Provided(!any2.EqualTo(Integer.Zero)), Divf(Mulf(var any2, var any1), Mulf(var any3, var any2a)) when any2 == any2a => (any1 / any3).Provided(!any2.EqualTo(Integer.Zero)), + // c / (c * d) and c / (d * c): the factor shared with the whole numerator, under the + // same two assumptions as (a * c) / c. Without it the cancellation depended on the + // order the divisor's factors came in, and Simplify left pi / ((5 - pi) * pi) as it + // was and cancelled pi / (pi * (5 - pi)), which is the same tree in print order. + // https://github.com/asc-community/AngouriMath/issues/2725 + Divf(var any2, Mulf(var any2a, var any1)) when any2 == any2a => + (1 / any1).Provided(!any2.EqualTo(Integer.Zero) & any2.DomainCondition), + Divf(var any2, Mulf(var any1, var any2a)) when any2 == any2a => + (1 / any1).Provided(!any2.EqualTo(Integer.Zero) & any2.DomainCondition), + // ({1} - {2}) / ({2} - {1}) Divf(Minusf(var any1, var any2), Minusf(var any2a, var any1a) denom) when (any1, any2) == (any1a, any2a) => new Providedf(-1, !denom.EqualTo(0)), diff --git a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Power.cs b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Power.cs index 5094066d6..73395791a 100644 --- a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Power.cs +++ b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Power.cs @@ -207,6 +207,9 @@ internal static bool IsWholeOrAnOddRoot(Number n) => Powf(var base1, Mulf(Logf(var base1a, var any1), var k)) when base1 == base1a && base1 is not Number and not Constant => new Powf(any1, k).Provided(!base1.EqualTo(0) & !base1.EqualTo(1)), + // And with the logarithm a factor further down the product, as the sort leaves it: + // e ^ (-ln(y) * y) is (-1 * ln(y)) * y. https://github.com/asc-community/AngouriMath/issues/2725 + Powf(var base1, Mulf exponent) when PowerOfALogarithmAmongFactors(base1, exponent) is { } power => power, Mulf(Powf(var any1, var any3), Mulf(var any1a, var any2)) when any1 == any1a => new Powf(any1, any3 + 1) * any2, Mulf(Powf(var any1, var any3), Mulf(var any2, var any1a)) when any1 == any1a => new Powf(any1, any3 + 1) * any2, @@ -450,6 +453,51 @@ internal static Entity GatherPowersOfOneBase(Entity x) private static bool IsPositiveReal(Entity entity) => entity.Evaled is Real { EDecimal.IsFinite: true } value && value.IsPositive; + /// + /// c ^ (k * log(c, a)) written a ^ k where the logarithm is a factor of the + /// product below its top, as in (m * log(c, a)) * n: the arms above read it only as + /// one of the top two operands. where it is one of those, where no + /// factor or more than one is a logarithm to the base c, and where c is 0 or + /// 1. A symbolic base carries c neither 0 nor 1 as the answer's condition, as the + /// arms above do. https://github.com/asc-community/AngouriMath/issues/2725 + /// + internal static Entity? PowerOfALogarithmAmongFactors(Entity @base, Mulf exponent) + { + if (exponent.Multiplier is Logf || exponent.Multiplicand is Logf + || @base is Number number && (number == Integer.Zero || number == Integer.One)) + return null; + var factors = new System.Collections.Generic.List(); + Gather(exponent, factors); + var at = -1; + for (var i = 0; i < factors.Count; i++) + if (factors[i] is Logf(var logBase, _) && logBase == @base) + { + if (at >= 0) + return null; + at = i; + } + if (at < 0) + return null; + var antilogarithm = ((Logf)factors[at]).Antilogarithm; + factors.RemoveAt(at); + var k = factors[0]; + for (var i = 1; i < factors.Count; i++) + k *= factors[i]; + var power = new Powf(antilogarithm, k); + return @base is Number or Constant ? power : power.Provided(!@base.EqualTo(0) & !@base.EqualTo(1)); + + static void Gather(Entity node, System.Collections.Generic.List into) + { + if (node is Mulf(var left, var right)) + { + Gather(left, into); + Gather(right, into); + } + else + into.Add(node); + } + } + /// /// Whether lies strictly between 0 and 1, so that its logarithm /// is minus that of its reciprocal. https://github.com/asc-community/AngouriMath/issues/2617 diff --git a/Sources/AngouriMath/Functions/Simplification/Simplificator.cs b/Sources/AngouriMath/Functions/Simplification/Simplificator.cs index f21dd7618..b99371057 100644 --- a/Sources/AngouriMath/Functions/Simplification/Simplificator.cs +++ b/Sources/AngouriMath/Functions/Simplification/Simplificator.cs @@ -199,39 +199,63 @@ internal static Entity InPrintOrder(Entity expression) private static Entity FactorsInPrintOrder(Entity.Mulf product) { // Read before anything is built: this runs on every answer, and most products are - // in order already. + // in order already, with one number at most and no quotient by a number's worth. var highest = 0; - if (InOrder(product, ref highest)) + var numbers = 0; + if (InOrder(product, ref highest, ref numbers)) return product; var factors = new System.Collections.Generic.List(); Gather(product, factors); // A product with a transpose or a vector product in it, or a factor built from one, is a product of // matrices, which do not commute. https://github.com/asc-community/AngouriMath/issues/2147 - if (factors.Exists(static factor => factor is Entity.Transposef or Entity.Powf(Entity.Transposef, _) - || ProductsOfMatrices.IsAMatrixNotWrittenOut(factor))) + if (factors.Exists(static factor => IsAMatrixFactor(factor) + || factor is Entity.Divf(var dividend, var divisor) && (IsAMatrixFactor(dividend) || IsAMatrixFactor(divisor)))) return product; - var ordered = new System.Collections.Generic.List(factors.Count); + // The numbers multiplied together, and a factor over something taken as a division by + // it: 2 * y * 2 is 4 y, and 3 * (1 / s) is 3 / s. Both are the same value with the + // same domain in fewer nodes, which is what the search would have preferred had it met + // that shape; it met the factors apart, or a quotient beside them, and only this pass + // brings them together. Left as they were, Simplify asked again of its own answer + // gave a different one. https://github.com/asc-community/AngouriMath/issues/2725 + Entity? coefficient = null; + var divisors = new System.Collections.Generic.List(); + var rest = new System.Collections.Generic.List(factors.Count); + foreach (var factor in factors) + { + var numerator = factor; + if (factor is Entity.Divf(var dividend, var divisor) && dividend is Entity.Number) + { + divisors.Add(divisor); + numerator = dividend; + } + if (numerator is Entity.Number number) + coefficient = coefficient is null ? number : (coefficient * number).InnerSimplified; + else + rest.Add(numerator); + } + var ordered = new System.Collections.Generic.List(rest.Count + 1); + if (coefficient is not null && (coefficient != Entity.Number.Integer.One || rest.Count == 0)) + ordered.Add(coefficient); for (var rank = 0; rank <= 2; rank++) - foreach (var factor in factors) + foreach (var factor in rest) if (FactorRank(factor) == rank) ordered.Add(factor); - // A number brought to the front of a quotient over a number is that quotient's - // numerator: 2 * (1 / s) is written 2 / s rather than 2 * 1 / s. - if (ordered.Count > 1 && ordered[0] is Entity.Number number - && ordered[1] is Entity.Divf(Entity.Number numerator, var divisor)) - { - ordered[1] = new Entity.Divf((number * numerator).InnerSimplified, divisor); - ordered.RemoveAt(0); - } Entity rebuilt = ordered[0]; for (var j = 1; j < ordered.Count; j++) rebuilt = new Entity.Mulf(rebuilt, ordered[j]); + foreach (var divisor in divisors) + rebuilt = new Entity.Divf(rebuilt, divisor); return rebuilt; - static bool InOrder(Entity node, ref int highest) + static bool IsAMatrixFactor(Entity factor) + => factor is Entity.Transposef or Entity.Powf(Entity.Transposef, _) || ProductsOfMatrices.IsAMatrixNotWrittenOut(factor); + + static bool InOrder(Entity node, ref int highest, ref int numbers) { if (node is Entity.Mulf(var left, var right)) - return InOrder(left, ref highest) && InOrder(right, ref highest); + return InOrder(left, ref highest, ref numbers) && InOrder(right, ref highest, ref numbers); + if (node is Entity.Divf(Entity.Number, _) || node is Entity.Number && ++numbers > 1) + return false; var rank = FactorRank(node); if (rank < highest) return false; diff --git a/Sources/Tests/UnitTests/Common/SimplificationRegressionTest.cs b/Sources/Tests/UnitTests/Common/SimplificationRegressionTest.cs index 4286b5347..1db9bfff8 100644 --- a/Sources/Tests/UnitTests/Common/SimplificationRegressionTest.cs +++ b/Sources/Tests/UnitTests/Common/SimplificationRegressionTest.cs @@ -1066,5 +1066,50 @@ public void TheLogarithmsDomainOverTheRealsStillRefusesANegativeBase(string at, Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition.Substitute("x", at.ToEntity()).Evaled); } + + // https://github.com/asc-community/AngouriMath/issues/2725 + // Simplify gave answers that a second Simplify shortened. The pass that puts the answer's + // products in print order left their numbers apart and a quotient by a number's worth + // beside them -- e - 2 * 2 * y, (-3) * 1 / (3 + y) -- a factor shared by a quotient was + // cancelled only where it came first in the divisor, and e ^ (k ln(a)) became a ^ k only + // where the logarithm was one of the top two factors of the exponent. Each row is checked + // by value against its input, and its answer must be Simplify's own answer to itself. + [Theory] + [InlineData("e - (2 * y) * 2")] + [InlineData("1/2 - (2 * y) * 5")] + [InlineData("(e^2)^(1/2) / ((5 - e) * e)")] + [InlineData("((-1) - y / 3)^(-1)")] + [InlineData("((x * 3) * (-1)) / (x * x - 3)")] + [InlineData("e / ((x * 2) * (pi * (-1)))")] + [InlineData("cosh(y * ln(y))")] + [InlineData("pi / ((5 - pi) * pi)")] + [InlineData("e ^ (-x * ln(y))")] + [InlineData("sqrt(2) - (3 * x) * (-2)")] + public void Issue2725_SimplifyIsItsOwnAnswerToItsAnswer(string input) + { + var simplified = input.Simplify(); + Assert.Equal(simplified, simplified.Simplify()); + foreach (var (x, y) in new[] { (7, 3), (-2, 5) }) + { + var expected = input.ToEntity().Substitute("x", x).Substitute("y", y).EvalNumerical(); + var actual = simplified.Substitute("x", x).Substitute("y", y).EvalNumerical(); + Assert.True(MathS.Abs(expected - actual).EvalNumerical() is Entity.Number.Real difference + && difference.EDecimal.Abs().CompareTo(PeterO.Numbers.EDecimal.FromString("1e-20")) < 0, + $"{input} is {expected} at x = {x}, y = {y}; its answer {simplified} is {actual}"); + } + } + + // And the numbers of the answer's products are one number, with nothing divided by a + // number's worth left as a factor beside the rest. + [Theory] + [InlineData("e - (2 * y) * 2", "e - 4 * y")] + [InlineData("1/2 - (2 * y) * 5", "1/2 - 10 * y")] + [InlineData("((-1) - y / 3)^(-1)", "(-3) / (3 + y)")] + [InlineData("((x * 3) * (-1)) / (x * x - 3)", "(-3) * x / (x ^ 2 - 3)")] + [InlineData("e / ((x * 2) * (pi * (-1)))", "e / ((-2) * x * pi)")] + [InlineData("(e^2)^(1/2) / ((5 - e) * e)", "1 / (5 - e)")] + [InlineData("cosh(y * ln(y))", "(y ^ y + y ^ (-y)) / 2")] + public void Issue2725_TheAnswerIsTheShorterForm(string input, string expected) + => Assert.Equal(expected.ToEntity().Complexity, input.Simplify().Complexity); } } diff --git a/Sources/Tests/UnitTests/Core/Transformations/AddressableRulesTest.cs b/Sources/Tests/UnitTests/Core/Transformations/AddressableRulesTest.cs index 7ecaa676c..ee4058ec9 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/AddressableRulesTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/AddressableRulesTest.cs @@ -299,7 +299,7 @@ public void TheRegistryIsAddressableAsFarAsItSaysItIs() // are thirty-three; NumericNeat's sixteen are eleven, six of them being three rules // written once per side a negative factor can sit on; and the two factorial sets are // eight arms each written as three. Every other repointed set is one arm for one rule. - Assert.Equal(336, withRules.Sum(set => set.Rules.Count)); + Assert.Equal(338, withRules.Sum(set => set.Rules.Count)); } /// diff --git a/Sources/Tests/UnitTests/Core/Transformations/ReversibleRuleTest.cs b/Sources/Tests/UnitTests/Core/Transformations/ReversibleRuleTest.cs index 79c444a9c..effc79bd8 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/ReversibleRuleTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/ReversibleRuleTest.cs @@ -123,6 +123,7 @@ public void EveryDataRuleIsClassifiedAsWritten() Assert.Equal( new[] { + "a-base-raised-to-a-product-holding-a-logarithm-of-itself-is-a-power-of-the-antilogarithm: ReplacementIsCode", "a-binomial-coefficient-whose-lower-index-is-the-complement-is-the-symmetric-one: ReplacementIsCode", "a-chain-of-greaters-implies-its-own-ends: ReplacementIsCode", "a-chain-of-lesss-implies-its-own-ends: ReplacementIsCode", @@ -158,6 +159,7 @@ public void EveryDataRuleIsClassifiedAsWritten() "a-doubled-sine-times-a-cosecant-is-twice-the-cosine: ReplacementIsCode", "a-equals-with-a-number-on-the-left-turns-round: ReplacementIsCode", "a-equals-with-zero-on-the-left-turns-round: ReplacementIsCode", + "a-factor-cancels-out-of-a-product-it-divides: ReplacementIsCode", "a-factor-repeated-across-a-product-squares: ReplacementIsCode", "a-factor-shared-by-a-product-and-a-quotient-added-comes-out: ReplacementIsCode", "a-factor-shared-by-a-quotient-and-a-product-added-comes-out: ReplacementIsCode", diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs index c208a21f8..523dbfd44 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleAuthoringGuideTest.cs @@ -43,7 +43,7 @@ private static void Stated(int stated, int measured, string claim) public void WhereARuleGoes() { Stated(33, MatchedRules.All.Count, "the number of rule sets written as data"); - Stated(343, MatchedRules.All.Sum(set => set.Rules.Count), "the number of rules written as data"); + Stated(345, MatchedRules.All.Sum(set => set.Rules.Count), "the number of rules written as data"); Stated(30, RewriteRules.All.Count, "the number of registered sets"); // Two families register under one name and run a data set under another -- // CommonDenominator over MatchedRules.CommonDenominator(level), CanonicalOrder over @@ -64,7 +64,7 @@ public void TheNameIsASentence() { var names = MatchedRules.All.SelectMany(set => set.Rules) .Select(rule => rule.Name).Distinct(StringComparer.Ordinal).ToList(); - Stated(314, names.Count, "the number of distinct rule names"); + Stated(316, names.Count, "the number of distinct rule names"); var words = names.Select(name => name.Split('-').Length).ToList(); Stated(4, words.Min(), "the shortest rule name in words"); @@ -73,7 +73,7 @@ public void TheNameIsASentence() [Fact] public void TheIdentityIsNotTheName() - => Stated(340, + => Stated(342, MatchedRules.All.SelectMany(set => set.Rules).Count(rule => rule.Description is not null), "how many rules carry an identity"); @@ -89,7 +89,7 @@ public void ReplacementAPatternOrCode() "how many rules have a pattern on both sides"); Stated(36, rules.Count(rule => rule.Reversed is not null), "how many two-sided rules have a direction"); - Stated(126, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), + Stated(128, rules.Count(rule => rule.Growth is RewriteRuleGrowth.Unknown), "how many rules sit at Unknown growth"); // The rest of the census, because `Saturation.RulesUpTo` argues from it in prose and @@ -136,7 +136,7 @@ public void SoundnessIsPerRule() var rules = MatchedRules.All.SelectMany(set => set.Rules).ToList(); Stated(192, rules.Count(rule => rule.Soundness is Soundness.Sound), "how many rules are Sound"); - Stated(151, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions), + Stated(153, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions), "how many rules are SoundUnderAssumptions"); Assert.All(RewriteRules.All, set => Assert.Equal(Soundness.SoundUnderAssumptions, set.Soundness)); @@ -163,7 +163,7 @@ public void OrderAndWhenItIsYoursToChoose() subsuming++; } } - Stated(30, subsuming, "how many rule pairs are ordered by subsumption"); + Stated(33, subsuming, "how many rule pairs are ordered by subsumption"); } /// diff --git a/Sources/Tests/UnitTests/Core/Transformations/RuleMetadataTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RuleMetadataTest.cs index 223033394..657052172 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RuleMetadataTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RuleMetadataTest.cs @@ -88,9 +88,9 @@ public void AddressableGrowthIsTheRulesOwnAnswer() public void SoundnessIsFinerPerRuleThanPerSet() { var rules = MatchedRules.All.SelectMany(set => set.Rules).ToList(); - Assert.Equal(343, rules.Count); + Assert.Equal(345, rules.Count); Assert.Equal(192,rules.Count(rule => rule.Soundness is Soundness.Sound)); - Assert.Equal(151, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions)); + Assert.Equal(153, rules.Count(rule => rule.Soundness is Soundness.SoundUnderAssumptions)); // And every set still reports the weakest of them, which is what makes the set grain // uninformative rather than wrong. @@ -174,7 +174,7 @@ public void EveryRuleOfARepointedSetCarriesItsIdentity() var repointed = RewriteRules.All .Where(set => set.Rules.Count > 0 && set.Rules.All(rule => rule.Soundness is not null)) .ToList(); - Assert.Equal(336, repointed.Sum(set => set.Rules.Count)); + Assert.Equal(338, repointed.Sum(set => set.Rules.Count)); Assert.All(repointed, set => Assert.All(set.Rules, rule => Assert.NotNull(rule.Description))); } diff --git a/Sources/Tests/UnitTests/Core/Transformations/RulePriorityTest.cs b/Sources/Tests/UnitTests/Core/Transformations/RulePriorityTest.cs index 879c402cd..dce571325 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/RulePriorityTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/RulePriorityTest.cs @@ -144,8 +144,8 @@ private static SortedSet Subsumptions() /// /// /// Over every rule rather than within a set, because the relation is about patterns and - /// nothing about it stops at a set boundary: 976 ordered pairs claim subsumption, - /// 502 of them (501 before the constant antilogarithm rule of #994 subsumed the symbolic one) are put to the test by the corpus containing something the narrower + /// nothing about it stops at a set boundary: 988 ordered pairs claim subsumption, + /// 511 of them (501 before the constant antilogarithm rule of #994 subsumed the symbolic one, 502 before the two rules of #2725) are put to the test by the corpus containing something the narrower /// pattern matches, and none is contradicted across 85,153 nodes. All three counts /// are asserted — a corpus that stopped reaching these shapes would otherwise turn this /// into a test that passes by asking nothing, and a witnessed count means nothing without @@ -205,8 +205,8 @@ public void SubsumptionIsNeverContradictedByMatching() if (put) witnessed++; } - Assert.Equal(976, claims.Count); - Assert.Equal(502, witnessed); + Assert.Equal(988, claims.Count); + Assert.Equal(511, witnessed); // Asserted so the two figures in the remark above cannot go stale in silence: the // whole point of `witnessed` is that it is a coverage number, and it means nothing // without knowing what it was measured over. @@ -284,6 +284,12 @@ public void TheRecordedSubsumptionsAreTheOnesThereAre() // https://github.com/asc-community/AngouriMath/issues/994 "Power: a-constant-raised-to-a-logarithm-of-itself-is-the-antilogarithm before a-symbol-raised-to-a-logarithm-of-itself-is-the-antilogarithm-where-defined", "Power: a-constant-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm before a-symbol-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm-where-defined", + // The logarithm as one of the top two factors is read by the three arms above; a + // product holding it further down, by the arm after them, whose helper declines + // the top-level shape. https://github.com/asc-community/AngouriMath/issues/2725 + "Power: a-constant-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm before a-base-raised-to-a-product-holding-a-logarithm-of-itself-is-a-power-of-the-antilogarithm", + "Power: a-number-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm before a-base-raised-to-a-product-holding-a-logarithm-of-itself-is-a-power-of-the-antilogarithm", + "Power: a-symbol-raised-to-a-multiple-of-a-logarithm-of-itself-is-a-power-of-the-antilogarithm-where-defined before a-base-raised-to-a-product-holding-a-logarithm-of-itself-is-a-power-of-the-antilogarithm", }; Assert.Equal(recorded.OrderBy(name => name, StringComparer.Ordinal), Subsumptions()); } diff --git a/Sources/Tests/UnitTests/Core/Transformations/StepAsASentenceTest.cs b/Sources/Tests/UnitTests/Core/Transformations/StepAsASentenceTest.cs index 4fda3c725..5984e8f13 100644 --- a/Sources/Tests/UnitTests/Core/Transformations/StepAsASentenceTest.cs +++ b/Sources/Tests/UnitTests/Core/Transformations/StepAsASentenceTest.cs @@ -59,7 +59,7 @@ public void EveryRuleWrittenAsDataIsNamedInProse() { var names = MatchedRules.All.SelectMany(set => set.Rules).Select(rule => rule.Name) .Distinct(StringComparer.Ordinal).ToList(); - Assert.Equal(314, names.Count); + Assert.Equal(316, names.Count); Assert.All(names, name => Assert.True(Explanation.IsProse(name), $"'{name}' is a rule name that does not read as a phrase in English"));