Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>();
void Gather(Entity condition)
Expand Down
21 changes: 21 additions & 0 deletions Sources/Tests/UnitTests/Common/ForcedConditionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ public void AConjunctAnotherForcesIsNotStated(string written, string expected)
public void ConjunctsThatForceNothingAreKept(string written)
=> Assert.Equal(written.ToEntity(), written.ToEntity().InnerSimplified);

/// <summary>
/// Two operands carrying the same condition, or one forcing the other's, give a result that
/// states it once. A second derivative of <c>1/sqrt(x^2 + 13)</c> stated
/// <c>not x ^ 2 + 13 = 0</c> three times.
/// </summary>
[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<Entity.Providedf>(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"));
Expand Down
Loading