Math expression applet

Andrew Coles andrew_coles at yahoo.co.uk
Tue Apr 13 00:13:02 BST 2004


>    If you are looking for a parser and interpreter, we have one in Kst
too,
> and it's mostly self-contained.  I recently rewrote it to be much faster,
and
> it contains an optimizer that can already do simple refactoring to
increase
> performance of consecutive evaluations.

Nice.  For the applet I just grabbed a parser I knew existed and it works
well enough for what it does (one-off evaluations).

I've had a quick look at the KST expression code and it has lead to a few
ideas....
- Perhaps the refactoring code could be reworked as a visitor to help
abstract out how it is done from the implementation of the expression tree:
this could also lead to further work in the refactoring direction (first
idea: taking out common factors, e.g. x^3 - x^2 +1 ->  x(x - 1) + 1) by just
tweaking the visitor; also, another visitor could make an optimised
stack-based evaluator for a specific function.  If you like I'll look into
this next week.
- If we do come up with a nice, generalised, expression class it could be
used in a souped-up kcalc as well: use the calculator normally; enter
expressions; define reusable functions....  In fact, looking at the TODO,
kcalc is down to get some extra modes (logic, stats) and this could no-doubt
help, as well as make KCalc more versatile.

> > I've not yet looked at it, but I guess it may be considered as a
component
> > for Kexi, and for many more apps? ...we've adding/reusing such a
component
> > in our FAR TODO list...

Arbitrary functions for Kexi shouldn't be too difficult: define a custom
function node and pop it in the expression tree :)

Andrew





More information about the kde-core-devel mailing list