diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index e225fe99c..c064cc2a7 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -87,7 +87,8 @@ as before, and `|p| > 1` needs no condition, since every value is then a power. while it is solved, as a provided expression is differentiated: a value known to be real, or declared real, has the half-line for its sector, one known to lie on it needs no condition, and one known to lie off it has no root. A conjunct of a condition that another conjunct already forces is not stated, so `a > -5 and a >= 0` is `a >= 0`, and a condition stated twice is -stated once, as a system's rows carried theirs once a substitution +stated once, as a system's rows carried theirs once a substitution, and as two operands carrying one condition +carried it once combined: a second derivative of `1/sqrt(x^2 + 13)` stated `not x ^ 2 + 13 = 0` three times ([#212](https://github.com/asc-community/AngouriMath/issues/212)). | Input | Was (2.6.0) | Now | @@ -101,6 +102,7 @@ stated once, as a system's rows carried theirs once a substitution | `"(sqrt(x) = a) provided a > -5".ToEntity().Solve("x")` | `{ a ^ 2 provided a > -5 }` | `{ a ^ 2 provided a >= 0 }` | | `"x provided a > 1 and a > 2".ToEntity().InnerSimplified` | `x provided a > 1 and a > 2` | `x provided a > 2` | | `"(x provided a > 0) provided a >= 0".ToEntity().InnerSimplified` | `x provided a >= 0 and a > 0` | `x provided a > 0` | +| `"(a provided b > 0) + (c provided b > 0)".ToEntity().InnerSimplified` | `a + c provided b > 0 and b > 0` | `a + c provided b > 0` | | `MathS.Equations("sqrt(y) - x", "y - a").Solve("x", "y")` | `[[sqrt(a), (sqrt(a)) ^ 2], [-sqrt(a), (-sqrt(a)) ^ 2]]` | `[[sqrt(a) provided C(sqrt(a)), (sqrt(a)) ^ 2 provided C(sqrt(a))], [-sqrt(a) provided C(-sqrt(a)), (-sqrt(a)) ^ 2 provided C(-sqrt(a))]]`, `C(v)` being `v = 0 or -1/2 * pi < arg(v) and arg(v) <= 1/2 * pi` | ### A system with a product equation is solved branch by branch diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Classes.cs index d8c6ba35d..b5d0ccfa7 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Classes.cs @@ -158,7 +158,9 @@ Entity ops(Entity a, Entity b) return (left, right) switch { - (Providedf a, Providedf b) => ops(a.Expression, b.Expression).Provided(a.Predicate & b.Predicate), + // A condition both operands carry is stated once: (a provided b > 0) + (c provided b > 0) + // is a + c provided b > 0. https://github.com/asc-community/AngouriMath/issues/212 + (Providedf a, Providedf b) => ops(a.Expression, b.Expression).Provided(Providedf.Both(a.Predicate, b.Predicate)), (Providedf a, var b) => ExpandOnTwoArguments(a.Expression, b, operation, defaultCtor, isExact).Provided(a.Predicate), (var a, Providedf b) => ExpandOnTwoArguments(a, b.Expression, operation, defaultCtor, isExact).Provided(b.Predicate), (Piecewise a, Piecewise b) => CombinedCaseByCase(a, b, operation, defaultCtor, isExact), @@ -449,7 +451,7 @@ Entity ops(Entity a, Entity b) return (left, right, third) switch { - (Providedf a, Providedf b, _) => ops(a.Expression, b.Expression).Provided(a.Predicate & b.Predicate), + (Providedf a, Providedf b, _) => ops(a.Expression, b.Expression).Provided(Providedf.Both(a.Predicate, b.Predicate)), (Providedf a, var b, _) => ExpandOnTwoAndTArguments(a.Expression, b, third, operation, defaultCtor, isExact).Provided(a.Predicate), (var a, Providedf b, _) => ExpandOnTwoAndTArguments(a, b.Expression, third, operation, defaultCtor, isExact).Provided(b.Predicate), (Piecewise a, Piecewise b, _) => diff --git a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs index 2146530eb..fa3b14bb6 100644 --- a/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs +++ b/Sources/AngouriMath/Functions/Evaluation/Evaluation.Omni/Evaluation.Omni.Classes.cs @@ -470,7 +470,7 @@ protected override Entity InnerSimplify(bool isExact) => // the first is kept. The conjunction is rebuilt only where something goes, so every // other condition keeps its shape. // https://github.com/asc-community/AngouriMath/issues/212 - private static Entity Both(Entity first, Entity second) + internal static Entity Both(Entity first, Entity second) { var conjuncts = new List(); void Gather(Entity condition) diff --git a/Sources/Tests/UnitTests/Common/ForcedConditionTest.cs b/Sources/Tests/UnitTests/Common/ForcedConditionTest.cs index ba0bd897a..8985a9b46 100644 --- a/Sources/Tests/UnitTests/Common/ForcedConditionTest.cs +++ b/Sources/Tests/UnitTests/Common/ForcedConditionTest.cs @@ -36,6 +36,27 @@ public void AConjunctAnotherForcesIsNotStated(string written, string expected) public void ConjunctsThatForceNothingAreKept(string written) => Assert.Equal(written.ToEntity(), written.ToEntity().InnerSimplified); + /// + /// Two operands carrying the same condition, or one forcing the other's, give a result that + /// states it once. A second derivative of 1/sqrt(x^2 + 13) stated + /// not x ^ 2 + 13 = 0 three times. + /// + [Theory] + [InlineData("(a provided b > 0) + (c provided b > 0)", "a + c provided b > 0")] + [InlineData("(a provided b > 0) * (c provided b > 1)", "a * c provided b > 1")] + [InlineData("(a provided b > 0) + (c provided b > 0) + (d provided b > 0)", "a + c + d provided b > 0")] + [InlineData("log(a provided b > 0, c provided b > 0)", "log(a, c) provided b > 0")] + public void OperandsConditionsAreJoinedOnce(string written, string expected) + => Assert.Equal(expected.ToEntity().InnerSimplified, written.ToEntity().InnerSimplified); + + [Fact] + public void ASecondDerivativeStatesItsConditionOnce() + { + var derivative = "derivative(1 / sqrt(x^2 + 13), x, 2)".ToEntity().InnerSimplified; + var condition = Assert.IsType(derivative).Predicate; + Assert.Equal("not x ^ 2 + 13 = 0".ToEntity(), condition); + } + [Fact] public void ASolvedRootStatesItOnce() => Assert.Equal("{ a ^ 2 provided a >= 0 }".ToEntity(), "(sqrt(x) = a) provided a > -5".ToEntity().Solve("x"));