Skip to content

Commit 4503c5e

Browse files
committed
Add another test for expanding nested nots
1 parent f7706dc commit 4503c5e

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.EqualityInequality.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ private static bool OppositeSigns(ComparisonSign left, ComparisonSign right)
6161
// For complexity to not increase, maximum one AND/OR component can be something other than a comparison operator to propagate NOT into.
6262
// e.g. not (a > b and b = c) becomes (a <= b or not b = c)
6363
// Note that Notf(Equalsf) has the same complexity as Equalsf in ComplexityCriteria, so it can be treated as a comparison operator here.
64-
Notf(Andf a) when Andf.LinearChildren(a).Count(n => n is not (ComparisonSign or Notf(Equalsf) or Orf)) <= 1 =>
64+
Notf(Andf a) when Andf.LinearChildren(a).Count(n => n is not (ComparisonSign or Notf or Orf)) <= 1 =>
6565
Andf.LinearChildren(a).Select(e => InequalityEqualityRules(e switch { Notf(var n) => n, var n => new Notf(n) })).Aggregate((a, b) => a | b),
66-
Notf(Orf a) when Orf.LinearChildren(a).Count(n => n is not (ComparisonSign or Notf(Equalsf) or Andf)) <= 1 =>
66+
Notf(Orf a) when Orf.LinearChildren(a).Count(n => n is not (ComparisonSign or Notf or Andf)) <= 1 =>
6767
Orf.LinearChildren(a).Select(e => InequalityEqualityRules(e switch { Notf(var n) => n, var n => new Notf(n) })).Aggregate((a, b) => a & b),
6868

6969
Impliesf(Andf(Greaterf(var any1, var any2), Greaterf(var any2a, var any3)), Greaterf(var any1a, var any3a))

Sources/Tests/UnitTests/PatternsTest/BooleanSimplify.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,26 @@ public void TestProvided(string expr, string? expected)
127127
var act = expr.ToEntity();
128128
Assert.Equal(exp, act.Simplify());
129129
}
130+
[Theory]
131+
[InlineData("not (not x)", "x")]
132+
[InlineData("not (a = b and b = c)", "not a = b or not b = c")]
133+
[InlineData("not (a <= b and b < c)", "a > b or b >= c")]
134+
[InlineData("not (a > b and b >= c)", "a <= b or b < c")]
135+
[InlineData("not (a <= b and b <= c and 1)", "not (1 and a <= b and b <= c)")]
136+
[InlineData("not (a = b or b = c)", "not a = b and not b = c")]
137+
[InlineData("not (a <= b or b < c)", "a > b and b >= c")]
138+
[InlineData("not (a > b or b >= c)", "a <= b and b < c")]
139+
[InlineData("not (a <= b or b <= c or 1)", "not (1 or a <= b or b <= c)")]
140+
[InlineData("not (a < b or c > d and e = f)", "a >= b and (c <= d or not e = f)")]
141+
[InlineData("not (not (a > b and b >= c) and y)", "a > b and b >= c or not y")]
142+
[InlineData("not (not (a = b and b = c) and y)", "a = b and b = c or not y")]
143+
[InlineData("not (not (not a = b and not b = c) and y)", "not ((a = b or b = c) and y)")]
144+
[InlineData("not (a < b and b < c and not c = d and not d and not (e and not (f or g = h)))", "a >= b or b >= c or c = d or d or e and not f and not g = h")]
145+
public void NestedNot(string expr, string expected)
146+
{
147+
var exp = expected.ToEntity();
148+
var act = expr.ToEntity();
149+
Assert.Equal(exp, act.Simplify());
150+
}
130151
}
131152
}

Sources/Tests/UnitTests/PatternsTest/SimplifyTest.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,6 @@ [Fact] public void BigSimple1() => AssertSimplifyToString(
161161
[InlineData("ln(a) - ln(b)", "ln(a / b)")]
162162
[InlineData("log(2, a) + ln(b)", "log(2, a) + ln(b)")]
163163
public void PowerRulesTest(string input, string output) => AssertSimplifyToString(input, output);
164-
[Theory]
165-
[InlineData("not (not x)", "x")]
166-
[InlineData("not (a = b and b = c)", "not a = b or not b = c")]
167-
[InlineData("not (a <= b and b < c)", "a > b or b >= c")]
168-
[InlineData("not (a > b and b >= c)", "a <= b or b < c")]
169-
[InlineData("not (a <= b and b <= c and 1)", "not (1 and a <= b and b <= c)")]
170-
[InlineData("not (a = b or b = c)", "not a = b and not b = c")]
171-
[InlineData("not (a <= b or b < c)", "a > b and b >= c")]
172-
[InlineData("not (a > b or b >= c)", "a <= b and b < c")]
173-
[InlineData("not (a <= b or b <= c or 1)", "not (1 or a <= b or b <= c)")]
174-
[InlineData("not (a < b or c > d and e = f)", "a >= b and (c <= d or not e = f)")]
175-
[InlineData("not (not (a > b and b >= c) and y)", "a > b and b >= c or not y")]
176-
[InlineData("not (not (a = b and b = c) and y)", "a = b and b = c or not y")]
177-
[InlineData("not (not (not a = b and not b = c) and y)", "not ((a = b or b = c) and y)")]
178-
public void Boolean(string input, string output) => AssertSimplifyToString(input, output);
179164
}
180165
}
181166

0 commit comments

Comments
 (0)