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
14 changes: 14 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,20 @@ coefficient that is zero now answers the whole line or nothing.
| `"x^2 < x^2 - 2".Solve("x")` | `InvalidCastException` | `{ }` |
| `forall x in RR : x + 1 > x` | `UnhandledParseException` (`InvalidCastException` since quantifiers arrived) | `True` |

### A statement equal to a truth value is solved as the statement or its negation

**Wrong answer fixed.** `"(x > 2) = (3 > 1)".Solve("x")` was `{ }`, and so was every equation
between a statement and a truth value: the arm for an equation of numbers subtracted the two
sides, which claimed there was no root. A statement equal to `True` is the statement, equal to
`False` its negation, and two statements equal are equivalent
([#1549](https://github.com/asc-community/AngouriMath/issues/1549)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"(x > 2) = (3 > 1)".Solve("x")` | `{ }` — wrong | `(2; +oo)` |
| `"(x = 1) = true".Solve("x")` | `{ }` — wrong | `{ 1 }` |
| `"(x > 0) = (x > 1)".Solve("x")` | `UncompilableNodeException` | `(1; +oo) \/ (-oo; 0]` |

### An infinite base has its whole powers, and surjectivity is decided through the image

`(-oo)^3` was `NaN` — a claim that the value does not exist — and so were `(-oo)^2` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ private static Set AsWritten(Set solved, Entity difference, Entity equation, Var
? new ConditionalSet(x, equation)
: solved;

/// <summary>
/// <c>a = b</c> between two statements, as the statement it is: <c>a</c> where <c>b</c> is
/// <c>True</c>, <c>not a</c> where it is <c>False</c>, and the two agreeing otherwise.
/// </summary>
private static Entity Equivalent(Entity left, Entity right)
=> (left, right) switch
{
(_, Entity.Boolean truth) => truth == Entity.Boolean.True ? left : !left,
(Entity.Boolean truth, _) => truth == Entity.Boolean.True ? right : !right,
_ => (left & right) | (!left & !right),
};

/// <summary>
/// The solution set as <see cref="Entity.Solve(Variable)"/> gives it, simplified, or
/// <see langword="null"/> where the solver declines the statement: an inequality it
Expand All @@ -342,6 +354,12 @@ private static Set AsWritten(Set solved, Entity difference, Entity equation, Var
internal static Set? Solve(Entity expr, Variable x)
=> expr switch
{
// A statement equal to a truth value is the statement or its negation, and two
// statements equal are equivalent: (x > 2) = (3 > 1) holds where x > 2 does. The
// arm for an equation of numbers subtracted them, and answered { }.
// https://github.com/asc-community/AngouriMath/issues/1549
Equalsf(Statement left, Statement right) => Solve(Equivalent(left, right), x),

Equalsf(var left, var right) when left is Set || right is Set
=> AnalyticalSetSolver.Solve(left, right, x),

Expand Down
24 changes: 24 additions & 0 deletions Sources/Tests/UnitTests/Algebra/SolveTest/SolveStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,29 @@ public void TestStatementSolver(string statement, string expectedRaw)
var actual = expr.Solve("x");
Assert.Equal(expected, actual);
}

/// <summary>
/// A statement equal to a truth value is solved as the statement or its negation, and two
/// statements equal as their equivalence, compared at points. Each was solved to the
/// empty set. https://github.com/asc-community/AngouriMath/issues/1549
/// </summary>
[Theory]
[InlineData("(x > 2) = (3 > 1)", "3 5/2", "2 0")]
[InlineData("(x = 1) = true", "1", "2 0")]
[InlineData("true = (x in {1, 2})", "1 2", "3")]
[InlineData("(x > 2) = false", "2 0", "3")]
[InlineData("(2 divides x) = true", "4 -2", "3")]
[InlineData("(x = 1 (mod 3)) = true", "1 4 -2", "2 3")]
[InlineData("(x > 0) = (x > 1)", "2 -1 0", "1/2 1")]
public void AStatementEqualToATruthValueIsSolved(string statement, string inside, string outside)
{
var solved = MathS.FromString(statement, useCache: false).Solve("x");
foreach (var (points, expected) in new[] { (inside, true), (outside, false) })
foreach (var point in points.Split(' '))
{
Assert.True(solved.TryContains(MathS.FromString(point), out var contains), $"{solved} does not decide {point}");
Assert.Equal(expected, contains);
}
}
}
}
Loading