Skip to content

Commit

Permalink
Fixed some derivative errors.
Browse files Browse the repository at this point in the history
Improved expression formatting.
Renamed namespaces.
  • Loading branch information
KvanTTT committed Feb 13, 2014
1 parent a19001c commit fb36d35
Show file tree
Hide file tree
Showing 39 changed files with 106 additions and 102 deletions.
4 changes: 2 additions & 2 deletions MathExpressions.NET.GUI/MathExpressions.NET.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{2C0616FA-AAC1-4F22-9655-731F308FE4F2}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MathExpressions.NET.GUI</RootNamespace>
<AssemblyName>MathFunctions.GUI</AssemblyName>
<RootNamespace>MathExpressionsNET.GUI</RootNamespace>
<AssemblyName>MathExpressions.NET.GUI</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Windows.Forms;

namespace MathExpressions.NET.GUI
namespace MathExpressionsNET.GUI
{
static class Program
{
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.GUI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MathExpressions.NET.GUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 10 additions & 35 deletions MathExpressions.NET.GUI/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions MathExpressions.NET.GUI/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
using System.Windows.Forms;
using System.IO;
using GOLD;
using MathExpressions.NET.GUI.Properties;
using MathExpressionsNET.GUI.Properties;
using System.Globalization;
using System.Threading;

namespace MathExpressions.NET.GUI
namespace MathExpressionsNET.GUI
{
public partial class frmMain : Form
{
Expand Down Expand Up @@ -130,10 +130,11 @@ private void UpdateResult()

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

string input = tbInput.Text.Replace(Environment.NewLine, "");
MathFunc simplifiedFunc = null;
try
{
simplifiedFunc = new MathFunc(tbInput.Text, tbVar.Text).Simplify();
simplifiedFunc = new MathFunc(input, tbVar.Text).Simplify();
tbSimplification.Text = simplifiedFunc.ToString();
tbSimplifiedOpt.Text = simplifiedFunc.GetPrecompilied().ToString();
}
Expand All @@ -152,7 +153,7 @@ private void UpdateResult()

try
{
var compileFunc = new MathFunc(tbInput.Text, tbVar.Text, true, true);
var compileFunc = new MathFunc(input, tbVar.Text, true, true);
compileFunc.Compile(Assembly, "Func");

var sb = new StringBuilder();
Expand All @@ -170,7 +171,7 @@ private void UpdateResult()
MathFunc derivativeFunc = null;
try
{
derivativeFunc = new MathFunc(tbInput.Text, tbVar.Text).GetDerivative();
derivativeFunc = new MathFunc(input, tbVar.Text).GetDerivative();
tbDerivative.Text = derivativeFunc.ToString();
tbDerivativeOpt.Text = derivativeFunc.GetPrecompilied().ToString();
}
Expand All @@ -187,7 +188,6 @@ private void UpdateResult()
try
{
var compileDerivativeFunc = new MathFunc(tbDerivative.Text, tbVar.Text, true, true);
compileDerivativeFunc.DerivativeDelta = double.Parse(tbDerivativeDelta.Text);
compileDerivativeFunc.Compile(Assembly, "FuncDerivative");
var sb = new StringBuilder();
compileDerivativeFunc.Instructions.ToList().ForEach(instr => sb.AppendLine(instr.ToString().Replace("IL_0000: ", "")));
Expand Down
4 changes: 2 additions & 2 deletions MathExpressions.NET.Tests/MathExpressions.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{BF78CC00-AB67-4D51-8B47-5A6DA94984AC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MathExpressions.NET.Tests</RootNamespace>
<AssemblyName>MathFunctions.Tests</AssemblyName>
<RootNamespace>MathExpressionsNET.Tests</RootNamespace>
<AssemblyName>MathExpressions.NET.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions MathExpressions.NET.Tests/MathFuncCompilationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Security.Policy;
using System.IO;

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

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

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

Expand All @@ -70,7 +70,7 @@ public void CompileSampleFunc()
if (!double.IsNaN(dotnet))
{
var correct = WolframAlphaUtils.GetValue(exprString, new KeyValuePair<string, double>("x", x));
var actual = mathAssembly.SimpleFunc(x);
var actual = mathAssembly.Func(x);
Assert.LessOrEqual(Math.Abs(correct - actual), Math.Abs(dotnet - actual));
i++;
}
Expand Down
14 changes: 11 additions & 3 deletions MathExpressions.NET.Tests/MathFuncDerivativeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using NUnit.Framework;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class MathFuncDerivativeTest
Expand Down Expand Up @@ -42,7 +42,7 @@ public void OneDivOneDerivativeTest()
[Test]
public void DerivativeDerivativeTest()
{
var f = new MathFunc("diff(x ^ 3)");
var f = new MathFunc("diff(x ^ 3, x)");
var derivative = f.GetDerivative();
Assert.IsTrue(derivative == "x * 6");
}
Expand All @@ -60,7 +60,15 @@ public void UnknownFuncDerivativeTest()
{
var f = new MathFunc("f(x)");
var derivative = f.GetDerivative();
Assert.IsTrue(derivative == "diff(f(x))");
Assert.IsTrue(derivative == "diff(f(x), x)");
}

[Test]
public void UnknownFuncThirdDerivativeTest()
{
var f = new MathFunc("f(x)");
var derivative = f.GetDerivative().GetDerivative().GetDerivative();
Assert.IsTrue(derivative == "diff(diff(diff(f(x), x), x), x)");
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/MathFuncPrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using System.Threading;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class MathFuncPrecompileTests
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/MathFuncSimplificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using NUnit.Framework;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class MathFuncSimplificationTests
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/MathFuncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using NUnit.Framework;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class MathFuncTests
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using NUnit.Framework;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class MiscTests
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/RationalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using NUnit.Framework;
using System.Numerics;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
[TestFixture]
public class RationalTests
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET.Tests/WolframAlphaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using WolframAlphaNET.Objects;
using System.Globalization;

namespace MathExpressions.NET.Tests
namespace MathExpressionsNET.Tests
{
public static class WolframAlphaUtils
{
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;

namespace MathExpressions.NET
namespace MathExpressionsNET
{
public static class Helper
{
Expand Down
6 changes: 5 additions & 1 deletion MathExpressions.NET/KnownFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Mono.Cecil;
using System.Reflection;

namespace MathExpressions.NET
namespace MathExpressionsNET
{
public class KnownFunc
{
Expand Down Expand Up @@ -75,6 +75,10 @@ public class KnownFunc
KnownFuncType.Add, KnownFuncType.Sub, KnownFuncType.Mult, KnownFuncType.Div, KnownFuncType.Exp
};

public static KnownFuncType[] NegKnownFuncs = new KnownFuncType[] {
KnownFuncType.Add, KnownFuncType.Sub, KnownFuncType.Mult, KnownFuncType.Div, KnownFuncType.Exp, KnownFuncType.Neg
};

public static Dictionary<KnownFuncType, string> UnaryFuncsNames = new Dictionary<KnownFuncType, string>();

public static Dictionary<KnownFuncType, string> BinaryFuncsNames = new Dictionary<KnownFuncType, string>();
Expand Down
2 changes: 1 addition & 1 deletion MathExpressions.NET/KnownFuncType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;

namespace MathExpressions.NET
namespace MathExpressionsNET
{
public enum KnownFuncType
{
Expand Down
Loading

0 comments on commit fb36d35

Please sign in to comment.