BlogAll Blog Posts | Next Post | Previous Post
Monday, January 7, 2019TMS Analytics & Physics developing library contains many algorithms for manipulating with symbolic math expressions. For example, it is able to evaluate symbolic derivatives of complicated expressions, approximate functions with symbolic, user-defined basis and so on. The result of any such manipulation is another symbolic expression. Many efforts in last versions has been spent for simplifying result expressions. The expression simplification required for presenting the result in shorted and readable form. For example, the derivative of y^(x+1) by x can be formally written as (x+1)*y^(x+1-1) and this is correct answer, but after simplification it would be simpler for reading (x+1)*y^x.
Nevertheless, all symbolic algorithms manipulate with math expressions, presented as plain Unicode strings. The main reason for this is providing simple interface for using math formulae inside Delphi programs. Presenting math expressions as plain strings requires using special syntax for different math structures. For example, power expression written with power operator x^y, vector expression written with brackets [x y z] and so on. Such syntax is not natural for math formula notation and so, result expressions are not suitable for human reading.
New version 2.7 of TMS Analytics and Physics pack contains new tools to convert symbolic expressions, generated with the library, to TeX format (https://en.wikibooks.org/wiki/LaTeX/Mathematics). This format is widely used for creating scientific articles and documents. There are many free tools for drawing math formula, presented in TeX format in desktop and Web applications, converting documents to PDF or DOC format and so on.
Let us consider as symbolic expressions, generated with the library, can be drawn with Web browser as math formulae. First, we need to convert the expression to the TeX format. Here is an example of code for converting expressions:
In the code above an instance of the TAnalyticsTeXConverter class created. This class has the Convert method for converting symbolic expressions to the TeX format. For the expression, result string in TeX format is the following:
var f, texf: string; converter: TAnalyticsConverter; begin f:= 'A*sin(n*x)+B/2*e^(m*y)'; converter:= TAnalyticsTeXConverter.Create; try texf:= converter.Convert(f); except on E: Exception do // Show exception message... end; // Using formula in TeX format... end;
Expression in TeX format can be then drawn in Web browser using, for example, MathJax CDN service (https://en.wikipedia.org/wiki/MathJax). For doing this we can generate a file with the following HTML code:
where XXX must be replaced with the TeX formula. Launching browser for the generated HTML file the formula will be drawn. For the formula above, we get:
The converter to TeX format supports all formulae, satisfying the syntax of the library. All types of expressions can be converted and rendered, including implicit derivative operators, special functions and operators (sum, square root and so on).
There are some other examples of complicated formula, rendered in Web browser with the described approach.
- Implicit derivative expression:
- Expression with indexed data:
- Matrix/vector expression:
- Special function/operator expression:
As can be seen from the pictures above, all rendered formulae presented in natural math format and are easy to read and understand. Thus, all symbolic results, evaluated with the library, can be shown to the user as math formulae.
The version 2.7 is already available. Source code of the example application can be downloaded from here.
This blog post has received 8 comments.
All Blog Posts | Next Post | Previous Post