[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Math parser



On Tue, Feb 08, 2000 at 03:52:22AM +0000, Aaron Lehmann wrote:
> I got to thinking about math parsing for the plots. I'm thinking that it
> would be a good idea to use the genius parser to let people use genius'
> powerfull functions that they may already be comfortable with. a few
> questions (in order of expected difficulty):

I thought that was the whole idea of integration :)

> 1) how hard would it be to have genius eval an expression and return a
> double value?

Fairly easy, HOWEVER the library interface to the gel engine is in a state of
flux right now.  However it should be just a call similiar to:

GelExecCtx *ctx = gel_exec_ctx_new(global_ctx);
double result = gel_exec_ctx_eval_string_to_double(ctx, "f(88)");
gel_exec_ctx_unref(ctx);

Of course it would be faster to build the GelETree representation for
evaluating functions rather then strings, and there has in the past been a
function evaluation wrapper.  Also this is somewhat theoretical as the
interface to the engine isn't done yet, but it should be ready in a month or
two I bet.  I don't think I'm that far from basic functionality of the
interface.

> 2) how hard would it be to have genius parse an expression, and then fill
> in different values for X and Y and reevaluate many times without
> reparsing? mp_equation in canvas/ does this by parsing expressions into
> RPN and evaluating them on demand, don't know if genius can do something
> like this

Dead simple (once the interface is done of course).  All you need to do is

1) make exec context
2) parse expression to GelETree
3) push dictionary context
4) define a new function (say 'f') to be the parsed GelETree
5) evaluate f with different arguments many times
6) pop dictionary context
7) free GelETree
8) unref exec context

> 3) can genius either do all of its calculations with doubles, or force gmp
> to do so? for plotting arbitrary precision is really overkill and speed is
> nice when doing large 3d plots. is this just a matter of setting the
> precision in gmp or is it harder?

Right now only with gmp but doubles should not be too hard and in fact I plan
to do that soon.  It is always going a lot slower then handcoded C routines
because it's interpretted, but that's the price you pay for flexibility.

Also I will want in the future to be able to manipulate plots from gel, so
there should also be gel interface for the canvas part.

> thanks, as soon as this is working all it should take is a GtkEntry and a
> connected signal to allow a user to plot whatever function they want
> to .. actually i could already do that just as easilly with mathparse but
> i want to figure out the interface specifics first.

Yes, this should be very simple.  Same thing is needed in dr geo.

George