A Powerful Function Parser

.

The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like

"cos(x)-7*x/(1+x)"
and you want to compute some values, maybe for displaying the graph of the function. You can write code like this:

CFunction<long double>* fkt = 
  CFunction<long double>::Parse("cos(x)-7*x/(1+x)");

long double y = fkt->Execute(1.5);

There are lots of definitions in the background, but the result is easy and fast! There is a one-time pasing step to construct the function tree, and function evaluations are only calls of standard math functions like sin, +, *, sqrt. When you want to know details about the implementaion, you should look into the source code. It would be too complex to describe the parsing algorithm here.

Downloads

Download demo source - 50 Kb
Download demo application - 32 Kb


Comments

  • Can I Take Shilajit Capsules To Cure Erectile Dysfunction?

    Posted by afoeffifielm on 06/21/2013 02:12am

    Natural Impotence Cure- Naturally Curing Your Erectile Dysfunction Can Help To Conserve Your Life? If you opt for discretion, you can fill the prescription at a reliable on-line pharmacy [url=http://rxhealth.pw ] countries where you can buy viagra over the counter [/url] see far more Lifelike Cures for Erectile Dysfunction Explained

    Reply
  • Just OK

    Posted by Legacy on 01/14/2004 12:00am

    Originally posted by: Gerhalt

    very ok!

    Reply
  • Very good, but ...

    Posted by Legacy on 10/16/2003 12:00am

    Originally posted by: Alexander Magola

    My english is not good, but i want to say that this code is very good. I like idea of this author, but this code is not very fast. My own similar code is faster three times more than it. Although, my code is not fastest. ;)
    Best regards.

    Reply
  • How about adding new functions to this as plug-ins

    Posted by Legacy on 07/03/2003 12:00am

    Originally posted by: Harshdeep Singh

    Great Job
    I was thinking about giving option of adding new functions as plug-ins (dll?)
    That would make it cooler.
    And I would love to see an explanation of the code.
    Harshdeep

    Reply
  • Vergleich Fl�chenberechnungen

    Posted by Legacy on 03/15/2003 12:00am

    Originally posted by: Oswald Ruckriegel

    Zun�chst: ein Spitzenprogramm. Meine Gratulation
    Habe es in mein Programm (VC++5.0) eingebaut.
    Stelle fest: am genauesten rechnet
    1. Mittelpunktsregel
    2. Integration mit Trapezregel
    3. Simpson ( hier Abweichungen von 1) bis zu 10 %.
    Beispiel: sin(x)/x ( f�r x= 0 bis x = 3)
    nur 1) berechnet richtig, 2) und 3) keine Berechnung m�glich.

    Warum ?

    Reply
  • The console app closes immediately

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: The Big Cat

    Hi there may not be a bug in the program but when i type the
    
    f(x)=_ in the console demo application then
    when i enter x and then press enter the console application closes .
    how am i to verify the results?Maybe the code should be
    modified to ask another f(x) at the end so the window wouldn't close and the user can test another function.
    You could just put in a prompt ,say 'Quit Y?N ?'..
    Otherwise good ,i've gotto see the code..

    Reply
  • Error using sqrt

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: Holger

    There is an error in the GetDerivate() Method of the class CSqrt1Function. The "1/2" expression becomes 0. For correct behaviour replace it with "1.0/2.0" or with "0.5" (see code below).
    
    

    Thanks for this great piece of code.

    Regards, Holger.


    template <class T>
    class CSqrt1Function : public CFunction<T>
    {
    ...
    virtual CFunction<T>* GetDerivate() const {return new CDivL0Function<T>(1/2, new CSqrt1Function<T>);};
    };

    Reply
  • Found an error

    Posted by Legacy on 08/20/2002 12:00am

    Originally posted by: Lee


    The expression: x^2+3x-5

    was parsed to: x^2+3-5

    Reply
  • few

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: few

    So fucking cool thing!

    Reply
  • A Powerful Function Parser

    Posted by Legacy on 04/10/2002 12:00am

    Originally posted by: Nikhil

    Impressive....but comments are not clear
    and extensive....Comments in English would be a definite help!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds