Equational Programming
Introduction
Equational programming is
a programming paradigm that specifies functions via conditional equations.
EP is both a programming language for equational programming and a translator that generates
Java classes from conditional equations.
The fact that EP generates Java makes it easy to combine equational programs with
ordinary Java programs and furthermore guarantees an efficient execution of
equational programs.
The spirit of EP is best demonstrated with an example. The following set of conditional equations
specifies symbolic differentiation.
Expr = Number(Double value)
+ Variable(String name)
+ Sum(Expr lhs, Expr rhs)
+ Difference(Expr lhs, Expr rhs)
+ Product(Expr lhs, Expr rhs)
+ Quotient(Expr lhs, Expr rhs);
diff: Expr * String -> Expr;
Number(value).diff(x) = Number(0.0);
v.equals(x) -> Variable(v).diff(x) = Number(1.0);
Variable(v).diff(x) = Number(0.0);
Sum(lhs, rhs).diff(x) = Sum(lhs.diff(x), rhs.diff(x));
Difference(lhs, rhs).diff(x) = Difference(lhs.diff(x), rhs.diff(x));
Product(lhs, rhs).diff(x) = Sum(Product(lhs.diff(x), rhs), Product(lhs, rhs.diff(x)));
Quotient(lhs, rhs).diff(x) = Quotient( Difference(Product(lhs.diff(x), rhs),
Product(lhs, rhs.diff(x))), Product(rhs, rhs) );
This file is translated into the following Java classes:
Expr.java,
Number.java,
Variable.java,
Sum.java,
Difference.java,
Product.java, and
Quotient.java.
To test these classes, use the class
Main.java.
The tutorial gives a short overview of EP.
Download and Installation
The software EP can be downloaded as ep.tar.gz.
EP is implemented in Java 5.0 and should therefore run with any operating
system but the following description assumes that you are working with either Linux or
Unix.
Let us assume that there is a directory called Software which is a
subdirectory of your home directory and that EP should be installed into this directory.
If it is to be installed somewhere else, simply change every occurrence of
the string ~/Software in the following description accordingly.
- Start a shell in the directory containing the file ep.tar.gz and
move the file ep.tar.gz
to the directory ~/Software by issuing the commands
% mv ep.tar.gz ~/Software
- Change to the directory ~/Software
cd ~/Software
- Unzip the file ep.tar.gz
gunzip ep.tar.gz
This command should create the file ep.tar.
- Untar the file ep.tar:
untar xf ep.tar
This command should produce the directory EP as a subdirectory of the
directory ~/Software. The directory EP contains
three subdirectories:
- src contains the Java sources together with the class
files.
- doc contains the documentation.
- examples contains the example file expr.ep
that specifies symbolic differentiation using equational programming.
The directory EP also contains the file antlr-2.7.5.jar. This
file contains Antlr which
is a parser generator written by Terence Parr.
There are two more files in the directory EP: The file
copyright.txt informs you that EP is subject to the
Gnu General Public License. For your convenience, this license
is reproduced in the file gpl.txt.
- To test EP, change to the directory examples and start EP using the commands:
cd ~/Software/EP/examples
export CLASSPATH=~/Software/EP/antlr-2.7.5.jar:/Software/EP/src
java EP expr
This invocation of EP will generate a number of Java files implementing
symbolic differentiation. To test these generated files, first compile them using
the command
javac *.java
Next, execute the command
java Main
This should produce the result
Product(Variable(x), Variable(x))/dx = Sum(Product(Number(1.0), Variable(x)), Product(Variable(x), Number(1.0)))
Karl Stroetmann
Last modified: Fri Mar 3 17:46:56 CET 2006