diff --git a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs index 90018e841..fc6c0e74b 100644 --- a/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs +++ b/Sources/AngouriMath/Functions/Simplification/Patterns/Patterns.Common.cs @@ -227,6 +227,16 @@ internal static partial class Patterns Mulf(Rational(var mOne, var den), var any1) when mOne == -1 && den != 1 => -(any1 / den), Mulf(var any1, Rational(var mOne, var den)) when mOne == -1 && den != 1 => -(any1 / den), + // a xor false = a + Xorf(var any1, Entity.Boolean any2) when any2 == false => any1, + Xorf(var any2, var any1) when any2 == false => any1, + Xorf(var any1, Integer any2) when any2 == 0 => any1, + Xorf(Integer any2, var any1) when any2 == 0 => any1, + + // a xor true = not a + Xorf(var any1, var any2) when any2 == true => new Notf(any1), + Xorf(var any2, var any1) when any2 == true => new Notf(any1), + _ => x }; } diff --git a/Sources/Tests/UnitTests/PatternsTest/SimplifyTest.cs b/Sources/Tests/UnitTests/PatternsTest/SimplifyTest.cs index c05be2161..4fa29b858 100644 --- a/Sources/Tests/UnitTests/PatternsTest/SimplifyTest.cs +++ b/Sources/Tests/UnitTests/PatternsTest/SimplifyTest.cs @@ -95,6 +95,12 @@ [Fact] public void Patt2() => AssertSimplify( // TODO: Smart factorizer [Fact] public void Divide2() => AssertSimplifyToString("(x3 + 3 x 2 y + 3 x y 2 + y3) / (x + y)", "x ^ 2 + 2 * x * y + y ^ 2"); [Fact] public void Divide3() => AssertSimplifyToString("(x2 + 2 x y + y2 + 1) / (x + y)", "x + 1 / (x + y) + y"); + [Fact] public void Xor1() => AssertSimplify(new Entity.Xorf(x, 0), x); + [Fact] public void Xor2() => AssertSimplify(new Entity.Xorf(0, x), x); + [Fact] public void Xor3() => AssertSimplify(new Entity.Xorf(false, x), x); + [Fact] public void Xor4() => AssertSimplify(new Entity.Xorf(x, false), x); + [Fact] public void Xor5() => AssertSimplify(new Entity.Xorf(x, true), new Entity.Notf(x)); + [Fact] public void Xor6() => AssertSimplify(new Entity.Xorf(true, x), new Entity.Notf(x)); [Fact] public void BigSimple1() => AssertSimplifyToString( "1+2x*-1+2x*2+x^2+2x+2x*-4+2x*4+2x*2x*-1+2x*2x*2+2x*x^2+x^2+x^2*-4+x^2*4+x^2*2*x*-1+x^2*2x*2+x^2*x^2",