Skip to content

Commit fb36d35

Browse files
committed
Fixed some derivative errors.
Improved expression formatting. Renamed namespaces.
1 parent a19001c commit fb36d35

39 files changed

+106
-102
lines changed

MathExpressions.NET.GUI/MathExpressions.NET.GUI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<ProjectGuid>{2C0616FA-AAC1-4F22-9655-731F308FE4F2}</ProjectGuid>
99
<OutputType>WinExe</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>MathExpressions.NET.GUI</RootNamespace>
12-
<AssemblyName>MathFunctions.GUI</AssemblyName>
11+
<RootNamespace>MathExpressionsNET.GUI</RootNamespace>
12+
<AssemblyName>MathExpressions.NET.GUI</AssemblyName>
1313
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1414
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
1515
<FileAlignment>512</FileAlignment>

MathExpressions.NET.GUI/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Windows.Forms;
55

6-
namespace MathExpressions.NET.GUI
6+
namespace MathExpressionsNET.GUI
77
{
88
static class Program
99
{

MathExpressions.NET.GUI/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MathExpressions.NET.GUI/Properties/Settings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MathExpressions.NET.GUI/frmMain.Designer.cs

Lines changed: 10 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MathExpressions.NET.GUI/frmMain.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
using System.Windows.Forms;
99
using System.IO;
1010
using GOLD;
11-
using MathExpressions.NET.GUI.Properties;
11+
using MathExpressionsNET.GUI.Properties;
1212
using System.Globalization;
1313
using System.Threading;
1414

15-
namespace MathExpressions.NET.GUI
15+
namespace MathExpressionsNET.GUI
1616
{
1717
public partial class frmMain : Form
1818
{
@@ -130,10 +130,11 @@ private void UpdateResult()
130130

131131
var variable = string.IsNullOrEmpty(tbVar.Text) ? null : new VarNode(tbVar.Text.ToLowerInvariant());
132132

133+
string input = tbInput.Text.Replace(Environment.NewLine, "");
133134
MathFunc simplifiedFunc = null;
134135
try
135136
{
136-
simplifiedFunc = new MathFunc(tbInput.Text, tbVar.Text).Simplify();
137+
simplifiedFunc = new MathFunc(input, tbVar.Text).Simplify();
137138
tbSimplification.Text = simplifiedFunc.ToString();
138139
tbSimplifiedOpt.Text = simplifiedFunc.GetPrecompilied().ToString();
139140
}
@@ -152,7 +153,7 @@ private void UpdateResult()
152153

153154
try
154155
{
155-
var compileFunc = new MathFunc(tbInput.Text, tbVar.Text, true, true);
156+
var compileFunc = new MathFunc(input, tbVar.Text, true, true);
156157
compileFunc.Compile(Assembly, "Func");
157158

158159
var sb = new StringBuilder();
@@ -170,7 +171,7 @@ private void UpdateResult()
170171
MathFunc derivativeFunc = null;
171172
try
172173
{
173-
derivativeFunc = new MathFunc(tbInput.Text, tbVar.Text).GetDerivative();
174+
derivativeFunc = new MathFunc(input, tbVar.Text).GetDerivative();
174175
tbDerivative.Text = derivativeFunc.ToString();
175176
tbDerivativeOpt.Text = derivativeFunc.GetPrecompilied().ToString();
176177
}
@@ -187,7 +188,6 @@ private void UpdateResult()
187188
try
188189
{
189190
var compileDerivativeFunc = new MathFunc(tbDerivative.Text, tbVar.Text, true, true);
190-
compileDerivativeFunc.DerivativeDelta = double.Parse(tbDerivativeDelta.Text);
191191
compileDerivativeFunc.Compile(Assembly, "FuncDerivative");
192192
var sb = new StringBuilder();
193193
compileDerivativeFunc.Instructions.ToList().ForEach(instr => sb.AppendLine(instr.ToString().Replace("IL_0000: ", "")));

MathExpressions.NET.Tests/MathExpressions.NET.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<ProjectGuid>{BF78CC00-AB67-4D51-8B47-5A6DA94984AC}</ProjectGuid>
99
<OutputType>Library</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>MathExpressions.NET.Tests</RootNamespace>
12-
<AssemblyName>MathFunctions.Tests</AssemblyName>
11+
<RootNamespace>MathExpressionsNET.Tests</RootNamespace>
12+
<AssemblyName>MathExpressions.NET.Tests</AssemblyName>
1313
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
</PropertyGroup>

MathExpressions.NET.Tests/MathFuncCompilationTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Security.Policy;
88
using System.IO;
99

10-
namespace MathExpressions.NET.Tests
10+
namespace MathExpressionsNET.Tests
1111
{
1212
[TestFixture]
1313
public class MathFuncCompilationTests
@@ -25,7 +25,7 @@ public void CompileFunc()
2525
using (var mathAssembly = new MathAssembly("Sin(x) + x ^ (Ln(5 * x) - 10 / x)", "x"))
2626
{
2727
for (int i = 1; i < 10; i++)
28-
Assert.AreEqual(expectedFunc(i), mathAssembly.SimpleFunc(i));
28+
Assert.AreEqual(expectedFunc(i), mathAssembly.Func(i));
2929
}
3030
}
3131

@@ -36,7 +36,7 @@ public void CompileFuncWithParameter()
3636
Math.Cos(x * b) * b - Math.Log(a) / Math.Pow(Math.Log(x), 2) / x); // derivative of log(x, a) + sin(x * b)
3737
using (var mathAssembly = new MathAssembly(new MathFunc("log(x, a) + sin(x * b)", "x").GetDerivative().ToString(), "x"))
3838
{
39-
Assert.AreEqual(expectedFunc(5, 3, 4), mathAssembly.Func.Invoke(null, new object[] { 5, 3, 4 }));
39+
Assert.AreEqual(expectedFunc(5, 3, 4), mathAssembly.Func(5, 3, 4));
4040
}
4141
}
4242

@@ -49,7 +49,7 @@ public void CompileFuncWithUnknownFunc()
4949
using (var mathAssembly = new MathAssembly("sin(a(x))", "x"))
5050
{
5151
var func = new Func<double, double>(x => x * x);
52-
Assert.AreEqual(expectedFunc(5, func), mathAssembly.FuncDerivative.Invoke(null, new object[] { 5, func }));
52+
Assert.AreEqual(expectedFunc(5, func), mathAssembly.FuncDerivative(5, func));
5353
}
5454
}
5555

@@ -70,7 +70,7 @@ public void CompileSampleFunc()
7070
if (!double.IsNaN(dotnet))
7171
{
7272
var correct = WolframAlphaUtils.GetValue(exprString, new KeyValuePair<string, double>("x", x));
73-
var actual = mathAssembly.SimpleFunc(x);
73+
var actual = mathAssembly.Func(x);
7474
Assert.LessOrEqual(Math.Abs(correct - actual), Math.Abs(dotnet - actual));
7575
i++;
7676
}

MathExpressions.NET.Tests/MathFuncDerivativeTest.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using NUnit.Framework;
66

7-
namespace MathExpressions.NET.Tests
7+
namespace MathExpressionsNET.Tests
88
{
99
[TestFixture]
1010
public class MathFuncDerivativeTest
@@ -42,7 +42,7 @@ public void OneDivOneDerivativeTest()
4242
[Test]
4343
public void DerivativeDerivativeTest()
4444
{
45-
var f = new MathFunc("diff(x ^ 3)");
45+
var f = new MathFunc("diff(x ^ 3, x)");
4646
var derivative = f.GetDerivative();
4747
Assert.IsTrue(derivative == "x * 6");
4848
}
@@ -60,7 +60,15 @@ public void UnknownFuncDerivativeTest()
6060
{
6161
var f = new MathFunc("f(x)");
6262
var derivative = f.GetDerivative();
63-
Assert.IsTrue(derivative == "diff(f(x))");
63+
Assert.IsTrue(derivative == "diff(f(x), x)");
64+
}
65+
66+
[Test]
67+
public void UnknownFuncThirdDerivativeTest()
68+
{
69+
var f = new MathFunc("f(x)");
70+
var derivative = f.GetDerivative().GetDerivative().GetDerivative();
71+
Assert.IsTrue(derivative == "diff(diff(diff(f(x), x), x), x)");
6472
}
6573

6674
[Test]

MathExpressions.NET.Tests/MathFuncPrecompileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text;
77
using System.Threading;
88

9-
namespace MathExpressions.NET.Tests
9+
namespace MathExpressionsNET.Tests
1010
{
1111
[TestFixture]
1212
public class MathFuncPrecompileTests

0 commit comments

Comments
 (0)