Skip to content

C# expressions' symbolic calculator. Can calculate derivative function and simplify expressions.

Notifications You must be signed in to change notification settings

markshevchenko/sysharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SySharp

SySharp is simple library to symbolic calcualtions to demonstrate the power of expressions trees in C#.

The library can produce derivative function and simplify expressions.

Demo

To start the experiments you can clone the repository into your projects' directory:

cd $home/source
git clone https://github.com/markshevchenko/sysharp
cd sysharp
dotnet build -c Release

Open "C# Interactive" window in Visual Studio. Please note that csi.exe hasn't been supported the core mode, so you need Visual Studio.

Type these commands:

#reset core
#r "source/sysharp/SySharp/bin/Release/net5.0/SySharp.dll"
using SySharp;

Don't forget to check the path. source/sysharp/SySharp/bin/Release/net5.0 will be valid, if you have cloned the repository to the $home/source directory.

Now we can experiment with the library. Let's' find out the derivative of the function x2:

Symbolic.Derivative(x => x * x)

The answer is x => ((x * 1) + (1 * x)). To see it clearly we need call the ToString() method:

Symbolic.Derivative(x => x * x).ToString()

It's too complicated, isn't it?

We can simplify expressions with the help of the method Simplify():

Symbolic.Derivative(x => x * x).Simplify().ToString()

Now the anwer is x => (2 * x). Much better.

At the end we can calculate the value of derivative function:

var d = (Func<double, double>)Symbolic.Derivative(x => Math.Sin(Math.Pow(x, 3))).Compile();
d(3)

The value of the function (sin x3)' at x = 3 will be equal to -7.887747835813577.

About

C# expressions' symbolic calculator. Can calculate derivative function and simplify expressions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages