diff --git a/AbMath/AbMath.dll b/AbMath/AbMath.dll index a28caec..6cc04e2 100644 Binary files a/AbMath/AbMath.dll and b/AbMath/AbMath.dll differ diff --git a/AbMath/Calculator/AST.cs b/AbMath/Calculator/AST.cs index 963e773..9b7aa5f 100644 --- a/AbMath/Calculator/AST.cs +++ b/AbMath/Calculator/AST.cs @@ -288,6 +288,32 @@ private void GenerateExponentSimplifications() private void GenerateTrigSimplifications() { + //TODO: + //[f(x) * cos(x)]/[g(x) * sin(x)] -> [f(x) * cot(x)]/g(x) + //[f(x) * sin(x)]/cos(x) -> f(x) * tan(x) + //sin(x)/[f(x) * cos(x)] -> tan(x)/f(x) + //[f(x) * sin(x)]/[g(x) * cos(x)] -> [f(x) * tan(x)]/g(x) + + //TODO: [1 + tan(f(x))^2] -> sec(f(x))^2 + //TODO: [cot(f(x))^2 + 1] -> csc(f(x))^2 + + //These will probably violate domain constraints ? + //TODO: sec(x)^2 - tan(x)^2 = 1 + //TODO: cot(x)^2 + 1 = csc(x)^2 + //TODO: csc(x)^2 - cot(x)^2 = 1 + + //TODO: Double Angle + //[cos(x)^2 - sin(x)^2] = cos(2x) + //1 - 2sin(x)^2 = cos(2x) + //2cos(x)^2 - 1 = cos(2x) + //2sin(x)cos(x) = sin(2x) + //[2tan(x)]/1 - tan(x)^2] = tan(2x) + + //TODO: Power Reducing + //[1 - cos(2x)]/2 = sin(x)^2 + //[1 + cos(2x)]/2 = cos(x)^2 + //[1 - cos(2x)]/[1 + cos(2x)] = tan(x)^2 + } @@ -637,32 +663,6 @@ private void Simplify(RPN.Node node, SimplificationMode mode) RPN.Node division = new RPN.Node(new[] { node[0, 1], cot }, new RPN.Token("/", 2, RPN.Type.Operator)); Assign(node, division); } - //TODO: - //[f(x) * cos(x)]/[g(x) * sin(x)] -> [f(x) * cot(x)]/g(x) - - //[f(x) * sin(x)]/cos(x) -> f(x) * tan(x) - //sin(x)/[f(x) * cos(x)] -> tan(x)/f(x) - //[f(x) * sin(x)]/[g(x) * cos(x)] -> [f(x) * tan(x)]/g(x) - - //TODO: [1 + tan(f(x))^2] -> sec(f(x))^2 - //TODO: [cot(f(x))^2 + 1] -> csc(f(x))^2 - - //These will probably violate domain constraints ? - //TODO: sec(x)^2 - tan(x)^2 = 1 - //TODO: cot(x)^2 + 1 = csc(x)^2 - //TODO: csc(x)^2 - cot(x)^2 = 1 - - //TODO: Double Angle - //[cos(x)^2 - sin(x)^2] = cos(2x) - //1 - 2sin(x)^2 = cos(2x) - //2cos(x)^2 - 1 = cos(2x) - //2sin(x)cos(x) = sin(2x) - //[2tan(x)]/1 - tan(x)^2] = tan(2x) - - //TODO: Power Reducing - //[1 - cos(2x)]/2 = sin(x)^2 - //[1 + cos(2x)]/2 = cos(x)^2 - //[1 - cos(2x)]/[1 + cos(2x)] = tan(x)^2 } else if (mode == SimplificationMode.Swap) { @@ -1943,8 +1943,9 @@ private void Derive(RPN.Node foo, RPN.Node variable) RPN.Node subtraction = new RPN.Node(new[] { new RPN.Node(1), exponent }, new RPN.Token("-", 2, RPN.Type.Operator)); RPN.Node sqrt = new RPN.Node(new[] { subtraction }, new RPN.Token("sqrt", 1, RPN.Type.Function)); + RPN.Node abs = new RPN.Node(new[] { body.Clone() }, new RPN.Token("abs", 1, RPN.Type.Function)); RPN.Node denominator = - new RPN.Node(new[] { sqrt, Clone(body) }, new RPN.Token("*", 2, RPN.Type.Operator)); + new RPN.Node(new[] { sqrt, abs }, new RPN.Token("*", 2, RPN.Type.Operator)); RPN.Node division = new RPN.Node(new[] { denominator, bodyDerive }, new RPN.Token("/", 2, RPN.Type.Operator)); @@ -1975,8 +1976,9 @@ private void Derive(RPN.Node foo, RPN.Node variable) RPN.Node subtraction = new RPN.Node(new[] { new RPN.Node(1), exponent }, new RPN.Token("-", 2, RPN.Type.Operator)); RPN.Node sqrt = new RPN.Node(new[] { subtraction }, new RPN.Token("sqrt", 1, RPN.Type.Function)); + RPN.Node abs = new RPN.Node(new[] { body.Clone() }, new RPN.Token("abs", 1, RPN.Type.Function)); RPN.Node denominator = - new RPN.Node(new[] { sqrt, Clone(body) }, new RPN.Token("*", 2, RPN.Type.Operator)); + new RPN.Node(new[] { sqrt, abs }, new RPN.Token("*", 2, RPN.Type.Operator)); RPN.Node multiplication = new RPN.Node(new[] { new RPN.Node(-1), bodyDerive }, new RPN.Token("*", 2, RPN.Type.Operator)); RPN.Node division = new RPN.Node(new[] { denominator, multiplication }, diff --git a/Unit Tester/Apportionment/Calculator/Derivative.cs b/Unit Tester/Apportionment/Calculator/Derivative.cs index 2d10eb0..a382df6 100644 --- a/Unit Tester/Apportionment/Calculator/Derivative.cs +++ b/Unit Tester/Apportionment/Calculator/Derivative.cs @@ -220,20 +220,20 @@ public void ArcCot() public void ArcSec() { RPN test = new RPN("derivative( arcsec(x), x)").Compute(); - Assert.AreEqual("1 x x 2 ^ 1 - sqrt * /", test.Polish.Print()); + Assert.AreEqual("1 x abs x 2 ^ 1 - sqrt * /", test.Polish.Print()); test.SetEquation("derivative( arcsec(x^2), x)").Compute(); - Assert.AreEqual("2 x * x 2 ^ x 4 ^ 1 - sqrt * /", test.Polish.Print()); + Assert.AreEqual("2 x * x 2 ^ abs x 4 ^ 1 - sqrt * /", test.Polish.Print()); } [Test] public void ArcCsc() { RPN test = new RPN("derivative( arccsc(x), x)").Compute(); - Assert.AreEqual("-1 x x 2 ^ 1 - sqrt * /", test.Polish.Print()); + Assert.AreEqual("-1 x abs x 2 ^ 1 - sqrt * /", test.Polish.Print()); test.SetEquation("derivative( arccsc(x^2), x)").Compute(); - Assert.AreEqual("-2 x * x 2 ^ x 4 ^ 1 - sqrt * /", test.Polish.Print()); + Assert.AreEqual("-2 x * x 2 ^ abs x 4 ^ 1 - sqrt * /", test.Polish.Print()); } [Test]