Rewriting the core library

The core library currently targets the .NET framework, which makes it possible to use all of the functionality in Windows, Windows Phone, and Linux (through Mono). However, it would be great if the core library could have bindings in other programming languages too (see the post).

Since most of the code is currently written in C#, it would not be difficult to convert some or all of it to say Java or C++. In this way, the functionality will be accessible from many high level languages, for example Python. By doing this, it will be quite easy to use the functionality in both Windows and Linux environments, and there won't be any need to install additional software such as .NET or Mono. Moreover, the code will be faster!

Both me and Ethan are up for this, so if you would like to join this initiative, it would be good if we could have a virtual conference next week. Please send me a message directly as soon as possible so that we can pick the time that will be suitable for all of us.


A letter to all contributors

A new summary letter for September and October can be found below:

Stern-Brocot system - spotting patterns easier

Mathos Core Library has some new functionality in the Fraction class. Here are some of the new methods:

All these methods are thought to be used to spot different kinds of patterns in numbers. Let's take a look at a some simple examples.

Simple fraction representation and conversion

When you use ToSternBrocotSystem on fraction, you will get an expression in terms of L's and R's. For example,

  • 3/2 ⇒ RL
  • 28/9 ⇒ RRRLLLLLLLL

You can use From SternBrocotSystem to convert it back to the actual fraction. In our Ruby Interpreter, this can be achieved by the following lines of code:

Approximation of real numbers (transcendental and non-transcendental)

The static method ToSternBrocotSystem has two functions. Either it approximates any real number such as e, or real numbers that can be expressed as a fraction for instance 0.66666.....  6/9=2/3.

When you approximate a number, you must assign the number of times it should iterate. If you know in advance that it is a continuous fraction, iteration count does not have to be specified. For example,


If you know that the number is continuous, you can find an equivalent fraction:

  • 1.9.... ⇒ R
  • R ⇒ 2

NOTE: 0 and 1 cannot be expressed with Stern Brocot notation. This also means that 0.9.... cannot be expressed since it's 1.

In Ruby Interpreter,

Spotting the pattern with condensed form

In order to make it easier to spot the pattern, there is a method called ToCondensedSternBrocot System. Instead of having a long array of L's and R's, this function will put a number that will tell you how many of each L and R there are in the string. For example,

  • e ⇒ R(2)L(1)R(2)L(1)R(1)L(4)R(1)L(1)R(6)
  • sqrt(3)/2 ⇒ L(1)R(6)L(2)R(6)L(2)R(6)L(2)R(6)L(2)R(6)

The Ruby Interpreter code that was used is:


In order to access these functions, you will have to download the latest changeset of the library. If you would have any questions, please feel free to ask at

Integral Approximation app is now available

Mathos Project provides three ways of approximating integrals. Using a Windows application, Web application, or Windows Phone app. The third option was released yesterday, and it is based on the IntegralCalculus package and Mathos Parser. The app uses the optimization technique pre-scanned expressions for faster integral evaluations. This is a paid app, which is intended to cover some of the hosting/domain name fees. Some screenshots:


Main screen (several integration methods)


Approximation methods


Main screen (one integration method)

New layout for Laboratory website

Some days ago, Mathos Laboratory website layout was entirely replaced by a new layout constructed by Diego Belli, Lead Developer of Mathos Laboratory.


The list of modules


The home page

This layout is much better than the one we had before since: 1) it is unique (the one before was a default one) 2) it is easier to use (it uses the entire screen rather than a small bit) 3) its colour scheme contains bright colours (before it was dark blueish and grayish). Also, the modules are better organized, which again makes it easier for a target user to navigate the website.

If you have any suggestions, please post them here:

For support requests, please use this website (you can log in using an external account):


Mathos Parser is now an expression compiler

[This article was firstly published here]

The requirement of performing several thousands of calculations (for example, during integration) led to the optimization with pre-scanned expressions. But the aim to make Mathos Parser even faster still remained. Now, I would like to introduce you to a new project of Mathos Project - Mathos Expression Compiler, based on the math tokenizer and parser logic of Mathos Parser.

This API allows you to parse an expression and "store" it as CIL code. Then, using ILAsm, you can generate a new assembly that will contain your expression entirely parsed. The only operation that occurs at runtime is the insertion of values into the variables that you declared and the operation on that variable value. To make it even faster, most of the calculations are already done before the runtime, for example, x+3+5 would be stored as x+8.

In this scenario, the time consideration can be important. Even if it is faster to execute CIL instructions, the compilation process can take some time. This has not been tested yet. The process is illustrated below:


This is a very simplified way of looking at it but the point is to always test Mathos Parser together with Mathos Expression Compiler and make an estimate of how much time would be saved in different scenarios. It all depends on the context. But note, that

A performance hit is incurred only the first time the method is called. All subsequent calls to the method execute at the full speed of the native code because verification and compilation to native code don't need to be performed again. //p. 12. Jeffrey Richter. CLR via C# 3rd Edition

So, if you plan to execute the function trillion times, it might be a good a idea to keep in mind the Expression Compiler as a better alternative, because at that point, the compilation time will be negligible.

Now, back to the features. It was mentioned in the beginning that it is based on the Mathos Parser. Note, in terms of features, Mathos Expression Compiler has at this point only a subset of those of Mathos Parser. At this point, you cannot have functions as sincos, and your own custom functions, but this will be changed in the nearest future.

There are also some changes to the way operators work. To declare an operator properly, you should use the variables OperatorListOperatorAction, and OperatorActionIL. Below, a simple example of addition operator:

Comparison operators are a bit more tricky. An example of greater than operator is shown below:

For those who understand IL, the @ sign might seem a bit strange. It is simply a way to tell the stack count to the if statement (in the compilation process).

When you actually generate an expression, this is how your IL code for that expression might look:

Will return (only IL for the expression):

When you have the IL code, you should name the output executable(or dll) as MathosILParser, otherwise, you might get an error. In future, an option will be added to customize the name of the output file, but at this point, please use RegEx (or replace option) to change the MathosILParser.exe to something else (in the IL code).

Your function can later by called as shown below. Note, I am not using reflection at all.

I hope this short guide was helpful, even if it might be a bit messy. If you have performed any testing related to speed or if you want to show some examples, please feel free to comment or contact me.

Advantages of the new GetTokens feature - Mathos Parser

Read the entire article here.

mp2 mp_separatly

Mathos Parser is available

Please read more here!

Early version of Mathos Core Library Interpreter

Mathos Core Library Interpreter, or Iron Ruby Based Mathos Core Library Interpreter, is a project with one of the aims:

/../ to allow non-programmers to easily access the computation power of Mathos Core Library.

For those who would like to try out this app, please download the alpha version here.

At this point, there are only short commands for integration, function and expression evalution, saving and loading data object. The remaining features can be included into the interpreter in the same way as it would be done using other .NET targeting languages, for example C#. If you have some experience with Ruby, why not try out some calculations through this interface instead? API Documentation for the Core Library can be found here.

There is a video available that describes some basics of the interpreter. Please feel to write articles with examples of how Mathos Core Library modules can be used and send us a link. Or, why not record a video? If you are a developer, why not join us at this early stage when many of decisions are being made?

Links & Downlods:

Benchmark Utility - Testing Algorithms

Sometimes, there are many solutions to one problem. In terms of algorithms, there can exist several algorithms that will be able to come to the same result. At this stage, the execution time can be used as a comparison.

In Mathos Test project, there is a class called BenchmarkUtil with a single function Benchmark. It was developed by Masoud Shokri. This algorithm is very useful when the execution speed is to be calculated and compared to another algorithm. An example of the way it can be used is shown below:

Relative execution time can also be compared, as shown below:

The iter specifies the number of executions of a specific Action. This allows an average time to be calculated. The first parameter takes an action, which can be a method or a function (make sure to use the lambda expression as shown in the examples above).