MathEclipse Development

Contents


CVS source code

The latest source code is available in CVS:

The open source tools used by MathEclipse are listed in the MathEclipse Credits page. Some of these open source tools are modified and integrated in the org.matheclipse.basic CVS module.

Setting up a development environment

Requirements

  • MathEclipse works with Eclipse Version 3.3
  • MathEclipse requires a Java 6.0 SDK (especially for the JSR 223 scripting engine integration)

CVS Modules

For the source code of the basic APIs, please check-out the following core modules in your Eclipse IDE:

  • org.matheclipse.basic - the basic libraries used by MathEclipse (Meditor, Javolution, JScience, FunctionalJ,...)
  • org.matheclipse.parser - the matheclipse expression parser API
  • org.matheclipse.core - the core of the symbolic math engine
  • org.matheclipse.generics - common generic algorithms for nested lists

For interactively testing these modules you can

  • run the org.matheclipse.parser.util.Console application, which tests the simple double and Complex expression evaluator (no symbolic evaluation!), which is included in the Parser package.
  • run the org.matheclipse.core.eval.Console application, which lets you interactively evaluate symbolic computations like D[Sin[x],x].

To test this basic modules you can also check out the associated JUnit tests:

  • org.matheclipse.parser.test - the matheclipse expression parser tests
  • org.matheclipse.core.test - the matheclipse core tests (especially org.matheclipse.core.system.SystemTestCase is interesting)

These are the Eclipse IDE related plugins:

  • org.matheclipse - the core Eclipse plugin
  • org.matheclipse.eval - the MathEclipse EvaluationProvider for the core plugin

Only these 6 modules are required for a basic setup. All required libraries can be found in the folder /org.matheclipse.eval/lib

Additional the source code for the online servlet can be found in this CVS module

JUnit Tests
The JUnit tests can be found in these modules:

  • org.matheclipse.parser.test - the math expression parser tests
  • org.matheclipse.core.test - the symbolic math engine tests

Object oriented design of the expression tree representation

In the following image you can see the design of the classes, which represent the expression tree in a MathEclipse formula:

An expression is organized in a tree-like structure. Every node in the tree implements a symbol (i.e. variable or constant), a pattern, a string, a number (i.e. integer, fraction, complex, double or double complex) or a function (i.e. root of subtree). The IExpr interface is the main type for the formula representation and implemented for every node in the expression tree.

A function is represented by an AST (abstract syntax tree). The AST class implements the java.util.List interface. The elements of the list represent the function in the following way:

  • the 0-th element is the head of the Function (i.e. Cos, Sin, Expand, Factor,...)
  • the first to n-th element in the list represent the arguments of the function. The arguments itself can contain a function as a subtree

Example:

f[x, Sin[y]] is represented as a nested java.util.List: (f, x, (Sin, y) )

FAQ

How can I start a simple evaluation console?

Run the main method in the org.matheclipse.core.eval.Console class and an input screen similar to the following output should appear

Options: 
  -h or -help                  print this message
  -f or -file <filename>       use given file as input
To stop the program type: 
exit<RETURN>
To continue an input line type '\' at the end of the line.
****+****+****+****+****+****+****+****+****+****+****+****+
>>> D[Sin[x],x]
Cos[x]
>>> 2^128
340282366920938463463374607431768211456
>>> 
 

How can I evaluate a given String?

The following snippet shows a simple example:

package org.matheclipse.core.test.examples;

import org.matheclipse.core.eval.EvalEngine;
import org.matheclipse.core.eval.EvalUtilities;
import org.matheclipse.core.form.output.OutputFormFactory;
import org.matheclipse.core.form.output.StringBufferWriter;
import org.matheclipse.parser.SyntaxError;
import org.matheclipse.parser.interfaces.IExpr;

public class SimpleExample {
	public static void main(String[] args) {
		try {

			// get the thread local evaluation engine
			EvalEngine engine = EvalEngine.get();
			EvalUtilities util = new EvalUtilities(engine, false);
			// evaluate an expression
			IExpr result = util.evaluate("D[Sin[x]*Cos[x],x]");
			StringBufferWriter buf = new StringBufferWriter();
			OutputFormFactory.convert(buf, result);
			// print the result in the console
			System.out.println(buf.toString());

		} catch (SyntaxError e) {
			// catch parser errors here
			System.out.println(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Where can I find the most interesting JUnit Tests ?

In the SystemTestCase.java file.

Where are all built-in functions implemented?

You can find all implementations of the built-in functions in the package org.matheclipse.core.reflection.system