Sunday, May 20, 2007

The expression parser

While the Expression Parser is not technically fundamental in Matrex (one can use the Function Editor instead), it has become more and more central in the last versions.

The reason is simple: if you have a long expression (or formula as it is called in a classical spreadsheet) to write, opening the Function Editor for each function in the formula can be time consuming and potentially irritating.

Using the Expression Parser is much faster: you write the expression, as it is, in a text editor and in a few steps all the required functions and matrices are added to your project.

The first thing to do to use the Expression Parser is to select the Expression Parser menu in the function tree (or press Ctrl-X).



This opens the Expression Parser wizard:


In the text editor you write the expression to add to the project. The expression is written as a combination of function templates, operators (+,-,*,/,^) and matrices, like:

cos(sin(x) + sin(y))

where x and y are matrices names.

You just need to write the names of the expression parts, their packages are not required.

If you don't remember the name of a function template or a matrix, the Insert.. buttons allow you to add templates and matrices to the expression selecting them.


The expression is first parsed to a tree:




Then the templates repository and the project are queried to determine the complete name-package of each part of the expression:





At the end the name of the target matrix and function are requested. All the intermediate matrices and functions are written in special packages.




Summarizing, entering an expression in Matrex is different from entering a formula in a classic spreadsheet because:
  • Spreadsheet formulas work on single cells, Matrex expressions on vectors/matrices.
  • Therefore, spreadsheet formulas must be copied for each result cell, Matrex expressions must be written only once.
  • Spreadsheet formulas are attached to cells, Matrex expressions are used to generate functions and matrices in the project.
  • Therefore spreadsheet formulas can be updated as whole (each cell), whether in Matrex the single generated functions and matrices must be updated individually.

This last point is not always an advantage for Matrex. Once functions and matrices are generated, the original expression that generated them is lost.

To solve this potential problem, Matrex version 1.2 will have the following new features:
  • It will be possible to see the origin of a matrix as an expression: the functions and matrices of which the matrix is directly or indirecly a result. This feature will be object of an article on this blog.
  • It will be possible to remove multiple items from a project in one shot. In this way it will be possible to easily remove all functions and matrices generated by an expression.
  • The last step of the expression parser will display all the functions and matrices that will be generated. This will reduce the risk of generating functions and matrices from a wrong expression.

No comments: