Archive

Archive for November, 2012

Jace.NET 0.6 released with WinRT support

November 22, 2012 Leave a comment

A new version of Jace.NET is released. Version 0.6 adds support for WinRT. The API remains fully backwards compatible with 0.5. Both the regular .NET build and the WinRT build offer the same API. You can find the latest version in the official NuGet repository:

https://www.nuget.org/packages/Jace

No user visible changes have been done for the 0.6 release. All changes are under the hood to add support for WinRT.

Because the WinRT lacks support for Reflection.Emit, the entire dynamic compiler had to be rewritten to take advantage of Expression Trees. The new dynamic compiler offers the same performance as the existing implementation. No special user actions are required, on WinRT Jace will automatically use the new dynamic compiler.

Future version of Jace.NET will add support for WP7 and WP8. Besides support for new platforms, additional mathematical formulas are planned to be added combined with improvements to the API. The goal is to keep the API backwards compatible with the current implementation.

More information about the architecture of Jace.NET can found at:

https://pieterderycke.wordpress.com/2012/11/04/jace-net-just-another-calculation-engine-for-net/

Categories: Jace.NET

Jace.NET published on NuGet

November 10, 2012 Leave a comment

A couple of days ago, I have released the first version of my mathematical calculation engine for the .NET framework: Jace.NET. This build includes support for all the standard mathematical operations and a number of mathematical functions like: sin, cos, loge, logn, …

https://www.nuget.org/packages/Jace

You can also download a demo application, that gives a visual insight into the parsing and execution steps of Jace.NET:

http://sdrv.ms/UfyWXj

image

More information about the architecture of Jace.NET can found at:

https://pieterderycke.wordpress.com/2012/11/04/jace-net-just-another-calculation-engine-for-net/

https://github.com/pieterderycke/Jace

Categories: C#, Jace.NET

Why Windows Phone 8 will succeed

November 8, 2012 1 comment

Windows Phone 7 was a great operating system, but the adaption rates were not superbly good. Microsoft had to abandon its old Windows Mobile operating system and had to play catch-up with IOS and Android who appeared years earlier on the mobile OS scene. This resulted in a niche market share for Microsoft.

At the BUILD conference, Microsoft unveiled its newest mobile OS: Windows Phone 8. It looks like an incremental update of the platform point of view GUI, but under the hoods it is a revolutionary update. The internals of WP8 are completely different: based on a NT kernel instead of the CE kernel.

In this article I will explain why I believe WP8 will be able to succeed were WP7 failed to deliver. Why it will be the OS that will allow Microsoft to retake market share in the mobile OS scene.

Let’s start by looking at the Metro GUI … euhm I mean: “Microsoft design language”. Metro is a refreshing and intuitive new design language. When WP7 was released, it was the only platform were Metro was used. Today it has become commonplace, Metro is used on the desktop, on the server, on tablets, on the phone, on the Xbox, on the web, … All of Microsoft offerings are standardizing on the Metro look & feel, offering an integrated end-user experience.

If we look under the hoods, we see the same kernel and the same Windows RT APIs as for the desktop and the tablets. This makes it easier for developers to build applications targeting all platforms. And although a lot of people claim to end of the PC is near, PCs are still used a lot and Windows is the OS that powers most of these machines. In the next couple of months all new PCs will start shipping with Windows 8 installed. Making Windows 8 an important platform for any serious App developer. Windows Phone 8 will also benefit from this.

We should also not forget the enormous catalogue of games available for Windows and powered by DirectX. The availability of C++ and DirectX on WP8 unlocks this catalogue for easy porting to phones. This is a great opportunity for WP8. In the end, the type of applications that matter the most are games. They are the best-selling applications for all (mobile) platforms. And who would not want to play the games of his teenage years like Grand Theft Auto Vice City, Call of Duty 2, Oblivion, … on his mobile when they would become available?

Finally, I am noticing that the media is very positive about the various Windows Phone devices being released. The designs of the new devices are very nice looking and making it great devices to own.

Will my predictions be correct? Only the future can tell 🙂

Categories: Windows Phone 8

Jace.NET – Just another calculation engine for .NET

November 4, 2012 33 comments

I work as a .NET technical architect in the financial industry and I get in touch with all sorts of mathematical formulas representing insurance or banking products. Most of the time, these formulas are hard coded by programmers and are thus not very flexible to be change dynamically at runtime by end-users.

This inspired me to start developing a calculation engine for the .NET platform that can execute any mathematical formula stored as a string both with or without variables. I wiped the dust of my university book: “Modern compiler implementations” and started the development a couple of weeks ago. I decided to name the calculation engine Jace.NET: Just another calculation engine for .NET.

Jace.NET is designed to run on .NET 4.0, Windows Phone 7, Windows Phone 8 and Windows RT.

How to use it

Jace.NET can be used in a couple of ways:

By directly executing a given mathematical function using the provided variables:

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("var1*var2", variables);

By building a .NET Func accepting a dictionary as input containing the values for each variable:

CalculationEngine engine = new CalculationEngine();
Func<Dictionary<string, double>, double> function = engine.Build("var1+2/(3*otherVariable)");

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2);
variables.Add("otherVariable", 4.2);

double result = function(variables);

By building a typed .NET Func:

CalculationEngine engine = new CalculationEngine();
Func<int, double, double> function = (Func<int, double, double>)engine.Function("var1+2/(3*otherVariable)")
    .Parameter("var1", DataType.Integer)
    .Parameter("otherVariable", DataType.FloatingPoint)
    .Result(DataType.FloatingPoint)
    .Build();

double result = function(2, 4.2);

Architecture

Jace.NET has an architecture similar to the one of modern compilers: interpretation and execution are performed in a number of steps. Each step focuses on one aspect of the parsing and interpretation of the formula. This keeps the overall complexity manageable.

clip_image002

The process starts with the tokenizing phase. During this phase the input string is converted into the various allowed tokens: integers, doubles, operations and variables. If a part of the input string contains text that does not match with any type of token, an exception is thrown and Jace will halt.

When tokenizing is successfully finished, an abstract syntax tree (AST) is constructed. This abstract syntax tree is a tree like data model that unambiguously represents the mathematical formula in memory. All mathematical precedence rules are taking into account when constructing the abstract syntax tree. Jace uses an algorithm inspired by the shunting-yard algorithm of Dijkstra to create this AST.

clip_image004

After AST creation, the optimizer will try to simplify the abstract syntax tree: if a part of the formula does not depend on variables but solely on constants. This part of the tree is already calculated and replaced by a constant in the tree.

clip_image006

The final phase is the OpCode generation. During this phase, a .NET dynamic method is created and the necessary MSIL is generated to execute the formula. This dynamic method is cached in memory. If the same formula is executed again in the future with other values for the variables. The interpretation steps are skipped and the dynamic method is directly executed. If the formulas of the calculations are frequently reoccurring, Jace.NET has near compiled code performance.

GitHub

If you are interested in the source code, please have a look at:

http://github.com/pieterderycke/Jace

Categories: C#, Jace.NET