This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libevaluator library and GSL


On Thu, Sep 04, 2003 at 02:26:30PM -0400, Martin Jansche wrote:
> On Thu, 4 Sep 2003, Aleksandar B. Samardzic wrote:
> 
> > I've written a library
> > (http://savannah.nongnu.org/projects/libevaluator/) that makes
> > possible to parse strings representing mathematical functions over
> > single or multiple variables and later to evaluate these functions
> > for different variable values (also to create representation of
> > function derivative over specified variable etc.).
> 
> I'm only speaking for myself here: I'd like to have some of this
> functionality available, but in a different form.  Specifically, I'd
> prefer a formula-to-code translator which, given a symbolic formula,
> would generate C code with calls to GSL functions (and could possibly
> have other backends in addition).  That way, I can manually change the
> generated code if necessary, plus it would presumably speed things up
> if one were to use optimized compiled code instead of formulas that
> need to be interpreted online.
> 
> Could you tell us more about what your evaluator does?  How does it
> compute derivatives?  Symbolically or numerically?  Does it simplify
> formulas?  Does it look for common subexpressions?  A number of the
> optimizations one might want to do could be done by a compiler
> (another reason to generate C source code).

My library is parsing string and creating tree representation of it in
memory.  For example, after parsing string "x+2", following tree is
created in memory:

      +
     / \
    /   \
   x     2

When evaluating function for given variable values (e.g. x=1), subtree
of each node is evaluated recursively and then node operation is
applied (in above example, leaf containing variable x is evaluated to 1
and leaf containing constant is evaluated to 2 and then in plus node
addition is performed giving result 3.

Derivatives are computed symbolically, again applying recursion.  For
example, from above tree, following tree representing derivative of
function over variable x is created:

      +
     / \
    /   \
   1     0

Basic tree simplifications are also implemented, so for example library
is able to simplify above tree to tree containing only one constant leaf
with value 1.  Common subexpressions and other advanced simplifications
are not implemented yet, but this is something I'd be willing to work
on.

 
> For me, what it boils down to is this: if I want to quickly optimize
> or integrate a symbolic function, I use Mathematica or some other
> symbolic algebra system.  I use GSL for fixed, narrow tasks that have
> to be run many times; in that case I need the code to be as efficient
> as possible.  Now if there were a forumla translator that could read
> Mathematica formulas (it uses a nice XML encoding) or Octave formulas
> etc. and spit out GSL C code, that would be very useful.

It would be certainly possible to implement back-end generating C code
from tree representation of function.  For now, only simple mathematical
functions are allowed in expressions (exp, ln, sqrt, sin, cos, tan,
ctan, arcsin, arcsin, arctan, arcctan, sh, ch, th, cth, arsh, arch,
arth, arcth, abs), but parser and whole library could be easily extended
to recognize any function (it is only necessary for function to have
symbolic derivative defined).  Also, I can imagine a front-end that
could parse XML encoded Mathematica formulas you mentioned; I'm using
Lex-Yacc for parsing now, but SAX XML parser could be used for alike
input. So - there are certainly many ways to extend and improve existing
library and sure I'd be willing to further work along some of them, but
as first step I'm asking is there interest to incorporate libevaluator
in GSL as-is?

Regards,
Alex


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]