Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

MathCore design issues

Memory structure of math data
Global design choices


Memory structure of math data

Every math expression can be considered a tree where the leaves are the smallest units (numbers, parameters, unknowns) and the other nodes are the containers of the leaves (brackets, fractions, radicals). This tree-structure is well-suited for a math library because it allows the creation of complex expressions using recursion (an example is shown later). Other approaches (like reverse polish notation) has already been tried, but they revealed to be too complex to handle or too complex to edit by math functions.

The following picture sums up the relations among main MathCore classes:

inherit__graph__0.png

For each class of this graph, there are four other classes deriving from mcElementData, mcElementGUI, mcElementMath and mcElementIO; they contain the data, the GUI, the math and the input-output stuff of the element. These classes are referred to as "helper classes": in fact, they are like subsections of the same element. This division is required especially to keep math and GUI functions separed (in a first approach, the mcElement-derived classes contained all GUI, math & IO stuff, but that approach revealed to be really buggy and difficult to handle).
As you can see in the main inheritance graph, some elements, like mcAddOp and mcSubOp, doesn't implement all the helper classes. In fact, this is not required, because mcAddOp and mcSubOp uses all the GUI, Math and IO stuff implemented in mcOperator.
For more info about this structure, you can read the tutorial.

To understand how mathematical data is stored in MathCore classes, I prepared a graph I hope will help you.

example2-1.gif

On the left there is the graphical representation of the structure showed below.

example2-2.gif

If this graph did not help you, I'll show you the output of the 'View.data_Debug Info' menu command, showed by an application which uses MathCore, when compiled in debug mode (of course, you can use it to get more examples):

example3.gif


As you can see a lot of work is done by mcPolynomial and mcMonomial classes; in fact mcElementArray (the base class of mcPolynomial and mcMonomial) plays a key role in MathCore and it is the most complex class.


Global design choices

MathCore is divided in some main parts; the following graph shows their relations with other software and hardware components of the machine where it runs:

ms-structure.gif

As you can see, wxWidgets framework cares about the graphical output while CINT (planned to be used from version 0.8) and LibXML2 is used in the input system. To get more info about these libraries, please go to http://www.wxWidgets.org, http://root.cern.ch/root/Cint.html, http://xmlsoft.org/.

During the development of MathCore, many design choices have been done:

  • Why the math, IO, GUI subsystems are not kept as three separate libraries, each one specialized in its particular task ?

    The three "subsections" of MathCore are all packed in a single library because, for example, it's very easier to create a flexible math library if we can create the math tree just sendind to the library a string representation of an inlined expression (that is, something like "4x+5^x-sin(x)")... in short, all the subsystem cooperates and make reciprocal tasks easier.

  • Why the sign operators (+ and -) are outside monomials ?

    Keeping the mcAddOp and mcSubOp OUTSIDE mcMonomials, we can make very very easier mcMonomial GUI input system and, in addition, we can make the most of the mcElementArray class, which is designed as an array containing elements interleaved by operators (and if we keep the sign operators _inside_ monomials, we would not take advatange of this for mcPolynomials, which would contain only mcMonomials...). For math aspects, then it's true: the sign should be stored inside the monomials to make everything easier. To make a little sample: when mcPolynomials adds two mcMonomials then it should always check its sign to update accordingly the operator

  • Why do we use polynomials containing monomials and not directly polynomials containing elements ?

    Polynomials containing directly the various elements like mcFractions, mcNumbers... was the first approach but, even if this solution makes input system easier to code, it was a real trouble for math system.

  • Why mcMathCore contains a lot of functions and variables which could be kept inside mcElementGUI as static elements ?

    mcMathCore is planned to be only an allocator and the general mcElement class handler. Every other variable and function which can be placed as STATIC in mcElementGUI, mcElementMath, mcElementIO will be placed there.



Documentation generated with Doxygen on Sun Feb 6 17:13:19 2005
Visit MathStudio home page for more info

[ Top ]