Formula parser

java gurus,
i am searching for a parser which should evaluate formulas. so if i have something in a string like "4/4+4/4" it should return 2.
any ideas where to find that?
thanx a lot and please also reply to my email [email protected]
regards,
richard

Try ANTLR at http://www.antlr.org
but then for simple formulas this might be overkill.

Similar Messages

  • Does anyone know if there is a list of the functions/statements that can be used in the formula parsing (used in the VI Eval Formula String)? I

    have figured out a few already (ln(x), log(x), x^y, sin(x), asin(x), sinh(x), asinh(x), sqrt(x), pi(x), exp(x) ) but a complete list would be very useful. At the moment I am trying to figure out if it can handle factorials (x!). Any ideas? I am using LV6i.

    have figured out a few already (ln(x), log(x), x^y, sin(x), asin(x), sinh(x), asinh(x), sqrt(x), pi(x), exp(x) ) but a complete list would be very useful. At the moment I am trying to figure out if it can handle factorials (x!). Any ideas? I am using LV6i.Such a list is in Chapter 1 of the "G Math Toolkit Reference Manual". Please note that there are some differences to the formula node. Therefore, the help on the formula node lists some functions, that do not work with the Parser VIs.
    You can get the G Math manual from: www.ni.com/manuals
    Just search for "math".
    Hope this helps!
    Robert Buhrke, Systems Engineer
    Contact: [email protected]

  • Maths formula parser

    Hi,
    Does oracle provide any function that parses and evaluets a math formula/expression by resolving the operator precedence in it.
    e.g. I have a math formula in the form of a string variable '(2+3)*(4+5)'
    Does oracle have a function that will resolve this and return answer 45.
    OR
    Does anyone have a stored proc/func for this that I can use.
    Any help is appreciated.
    Thanks in advance.

    I created this a long time ago in response to a post on this forum. Someone wanted an IIF() construct.
    CREATE FUNCTION iif (p_expr IN VARCHAR2,
                         p_true_result IN VARCHAR2,
                         p_false_result IN VARCHAR2) RETURN VARCHAR2 IS
       l_sqlstr VARCHAR2(4000);
       l_result PLS_INTEGER;
    BEGIN
       l_sqlstr := 'SELECT 1 FROM dual WHERE '||REPLACE(p_expr,'"','''');
       BEGIN
          EXECUTE IMMEDIATE l_sqlstr INTO l_result;
          RETURN p_true_result;
       EXCEPTION WHEN NO_DATA_FOUND THEN
          RETURN p_false_result;
       END;
    END;{code}
    or, for a strictky PL/SQL version (i.e. you can't call it in sql)
    {code}CREATE FUNCTION iif (p_expr IN VARCHAR2) RETURN BOOLEAN IS
       l_sqlstr VARCHAR2(4000);
       l_result PLS_INTEGER;
    BEGIN
       l_sqlstr := 'SELECT 1 FROM dual WHERE '||REPLACE(p_expr,'"','''');
       BEGIN
          EXECUTE IMMEDIATE l_sqlstr INTO l_result;
          RETURN TRUE;
       EXCEPTION WHEN NO_DATA_FOUND THEN
          RETURN FALSE;
       END;
    END;The first version would be called like:
    SELECT IIF('"A" in ("A","B","C") and 3 > 2 and 4 between 2 and 5','TRUE','FALSE') FROM dual;The second something like:
    IF IIF('"A" in ("A","B","C") and 3 > 2 and 4 between 2 and 5') THEN
    END IF;Just keep in mind Brian's comments about SQL injection from earlier in this thread
    John

  • How to implement mathematical formula parsing

    how can i implement mathematical expression parsing...
    A expression like (a*b)-((sin(-2a)))
    1.A=-2*a
    2.sinA
    3.B=a*b
    4.C=B-A
    The answer is C
    like that i need for any given expression...
    Thanks..

    Rams_India --
    The original posted question was how can i implement mathematical expression parsing..and not if such type of parsing is possible in j2me or not.
    With such an attitude, you're sure to scare away people that may be of help to you.
    You really need to read [code of conduct|http://wikis.sun.com/display/SunForums/Sun+Forums+Code+of+Conduct] of this forum.

  • How to parse an equation?

    Here's my problem:
    The user enters an equation into a TextField. The app reads the TextField and records the equation into a String.
    Say the user enters 3x + 5. Now, I need to convert the String into an algorithm that will be able to calculate the value of 3x + 5 for any x.
    It might sound simple for 3x + 5, but consider an equation like this:
    (sin(x)^2 * 3cos(x)) / (e^(tan(x)) * sinh(4x) - x^x^x^345.55)
    How would I parse something like that?

    Well, I looked at the source code, and it uses several
    dozen classes with some kind of nodes and so forth
    I need something simple. Effective, but simple.
    The programme I am writing will be working as an
    applet, so I wouldn't want to have people first
    download Jep, then run the applet ...Just how simple is your "simple"?
    Every mathematical formula parser requires nodes and stuff to represent the equation in a tree and so forth; you'd be re-writing all that and that is effectively much more complex than just using a parser that is there. You don't have to know how or why JEP works to use it.
    JEP is fairly simple to use... did happen to you see the sample applet and its source?
    http://jep.sourceforge.net/sampleapplet.htm
    what about the usage doc: http://jep.sourceforge.net/doc_usage.htm
    Doesn't seem that complex to me... but if you really want to build a parser of your own, be my guest... btw, if you're into that, I know a great open source expression parser from which you might want to pick ideas! :)

  • Importing SUMPRODUCT formula from XL into Numbers

    Hello all,
    I am having some challenges converting a SUMPRODUCT function from Excel/LibreOffice.  After browsing the support postings, it seemed as if rewriting the formula as a COUNTIF(S) or SUMIF(S) function could get the job done, but I haven't met with success going those routes.
    The file I'm working with is difficult for me to explain, so I have posted a small example here:
    https://www.iwork.com/document/?d=Reso_book.numbers&a=p205658906
    The basic application of the file is a reservation book; the formulas in question are in cells D5-L13 on the Availability sheet.  They are still in their original, non-Numbers syntax.
    The Availability sheet would effectively look up a table number from the Reservation sheet and return "1" if booked, "0" if not, or "-1" if doubled.
    In the posted file, D5-G5 would return 1, while H5-L5 would return 0.
    If anyone would be willing to take a look, I'd greatly appreciate any advice or insight for how to rework these formulas.

    I never use excel but something seems to be wrong in your original formula.
    =1-SUMPRODUCT((Reservation::Table 1::$D$2:$D$10<=D$4)*(Reservation::Table 1::$E$2:$E$10>=D$4)*(Reservation::Table 1::$F$2:$F$10=$B5))
    Given what I read in several pages found thru Google, the last component of your formula :
    (Reservation::Table 1::$F$2:$F$10=$B5)
    must not be a condition
    In fact, the embedded condition appears as dropped by the formula parser.
    When I reproduced you document in LibreOffice, removing the component =$B5 in the last component changes nothing.
    So I built the Numbers document without it (Table YK).
    In the edited table, the formula in D5 is :
    =1-SUMIFS((Reservation::Table 1::$F$2:$F$10),Reservation::Table 1::$D$2:$D$10,"<="&D$4,Reservation::Table 1::$E$2:$E$10,">="&D$4)
    Apply FillDown then Fill_to_right.
    I'm not sure that it's what you need but it return the same values than the originla ones in LibreOffice.
    Yvan KOENIG (VALLAURIS, France) samedi 29 octobre 2011 17:49:47
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • Password to formula node

    I´m doing a VI which will be protected. My problem is that, can i protect my formula node so, that only the formula can be changed or modified with the right password, without a possibility to see or modify the whole block diagram?
    -Balle-

    Hi, you can put the forumula in the front panel. In the fuction menu, goto "Mathematics", choose "formula" and then choose "Advance Formula Parsing". From there you will see several function which you are looking for. Look at the attached vi for protecting your formula. Thats the basic idea and I am sure you can enhance it to your application. May be better idea would come out in a few moments. Hope my suggestion would help you.
    When you feel sad, laugh
    Attachments:
    formula_node.vi ‏38 KB

  • Numbers: Cell time calculation not adding the correct time

    Greetings,
    First, thank you in advance for your assistance. I have searched the board and where there are many great formulas, I have not found the answer to this challenge.
    Cell A1 has a time for example 5:45 PM
    Cell C1 has an amount of minutes for example 40
    Cell B1 should be adding 40 minutes to 5:45 PM for result of 6:25 PM
    Cell A2 picks up the value of Cell B1 as its starting value so that it can calculate the same formula for the next line.
    This document is a schedule so that it adjusts the times based on the amount of minutes a segment is. I can post an excel file if that will assist, the excel formula for this in the B cell is A1+TIME(0,C1,0)
    Again thank you in advance for any assistance in solving this challenge.
    John

    =TIME(HOUR(A),MINUTE(A)+C,0)
    • Every time I may use them, I uses the "short references", those with no row num embedded.
    • The TIME function requires three parameters,
    a number of hours,
    a number of minutes
    a number of seconds
    but the formula parser is fair enough to understand that, when the given number of minutes is greater than 59, it means some hours + some minutes.
    And of course, mutatis mutandis, it's the same for the number of seconds.
    This is why, when I want to display with the current format hh:mm:ss a decimal time value as those resulting of calculations, I don't spent time to isolate the number of hours, the number of minutes, the number of seconds. I just calculate the total number of seconds.
    if cell B2 contains 0.1234490740741
    I type =TIME(0,0,B24*6060) in cell C2
    Then, applying the yy:mm:ss format I get 02:57:46
    inserting =TIMEVALUE(C) in D2, I get 0.1234490740741
    I know that this behavior is not described in the Help.
    I don't feel that it's a sin.
    It's for passing this kind of details that the forum exists.
    I feel perfectly odd questions whose response is available in the Help but it's always a pleasure to help users to discover features which are only available "between the lines".
    Yvan KOENIG (from FRANCE vendredi 4 juillet 2008 14:48:21)

  • Evaluating an arbitrary length boolean logic expression

    Is it possible to have labview evaluate a boolean expression of arbitrary length and complexity, which would be input by the user. Storage format of the expression isn't necessarily important. Use of the attached vi might provide some help for evaluating the expressions.
    Attachments:
    Test_Comparator.vi ‏28 KB

    There are a couple of ways to go about this. You may want to look into the Mathmatics&#0187Formula&#0187Advanced Formula Parsing pallet for some useful VIs.
    One way to do it would be to parse a string for expresions and perform the oppertation specified. Attached is a first step in doing this. Note that it returns an array of results...the code for anding and oring still needs to be added.
    Hope this helps,
    Amaury Rolin
    NI Applications Engineer
    Attachments:
    multi_compare.llb ‏41 KB

  • RGB Color Curve

    YES - there is a custom tone curve - finally, it works great. I don't miss the old sliders a bit.
    But still missing is the color curve tool, complete with color picker like in competing products.
    Right now the only way to color an image is the split toning - that works a bit like a color curve but it is very restricted.
    With the color curve You can produce color changes very easily and very intuitively.
    I hope Adobe can implement it.
    PS.: Another thing I find useful is a RGB channel tool where you can type in formulas. The implementation is rather simple, it just needs a formula parser. With 3 formulas a unique development reciepy could be created:
    Example:
    R =  0.9*R + 0.1 * G
    G = 1*G
    B = 1*B + 0.1
    But I guess this is too technical for a product like Lightroom.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    Which program has the color formulas you proposed? - or is that an original invention .
    For Bibble 5 there is a plugin available called  MathBox by Baruchel. It uses the public formula interpreter muparser.
    The input variables are r (red), g (green), b (blue) and also h (hue), s (saturation), v (value) and l (luminance) which all values beeing between 0 and 1, except for h, which is between 0 and 2pi. The plugin also implements 3 sliders which control the value of user variables x, y and z.As You can imagine, that tool is extremely powerful for example to do film simulation.
    Even if Adobe does not want to show such formulas to "the public", it would be nice to select certain recepies from a drop downlist plus one slider for a user variable. The recepies could be loaded from an XML file which can be edited by the adventurous. That would be really a great addon!
    Julian

  • Webi Report (Drilldown report)

    Hi All,
    I have created a Webi Drill down report, now my 1st column is 'Supplier Name' when i click on 'Supplier name', it's showing 'Costcenter Name' in a column, but I want when i click on 'Supplier Name' then it's label is also change into 'Costcenter Name'.
    Could anyone tell me how to use 'Alerter' condition for this (label)??
    Regards,

    Thanks for reply, I have already used drillfilter like: "=If(DrillFilters()=[L01 Brand Family (PHier3)]) Then DrillFilters() ElseIf(DrillFilters()=[L01 Pricing Brand (PHier4)]) Then DrillFilters() Else("Product Line")". Formula parsing sucessfully, but this is not working.
    Can you please checl & let me know?
    Regards,

  • How to evaluate Expression??

    Is it possible to change the expression in “Expression Node” in run-time?
    For example: User enters the expression as a string. I need to evaluate it and give the result.
    Is it possible to do that?
    Any ideas how to sole this problem??

    The expression in a formula node cannot be changed at run-time. Instead, use Eval Formula Node (Analyze>Mathematics>Formula palette) or the Advanced Formula Parsing functions on the sub-palette under there. These functions are not in the LabVIEW base package.

  • Complicated easy question - ray tracing

    Hello,
    i am working currently on one project - i have an optical system (some prisms, some lenses etc) and i want to make a VI to calculate propagation of a light ray - something like ray tracing.
    I know that labview is not the perfect platform to deal with this issue, however i still would like to try.
    My problem is as following: i want to calculate the propagation of a ray through a lens. I have the ray with some coordinate (y=const) and a plano convex lens - the front of a lens is a piece of a sphere. To calculate the propagation (using snell law) I have to find an angle between the ray and the line which is tangent to this lens-sphere in the point where my light beam hits the lens.
    My procedure (on the piece of paper):
    1.i know the coordinates of a center of a sphere (let's take (0,0)) and its radius r (x^2+y^2=r^2). I know the value of y=y_0 for which the ray enters the lens.
    then i can calculate the x_0: x_0^2+y_0^2=r^2. Now i know the point where light enters the lens (x_0,y_0)
    2.then just the usual procedure of finding equation for a line tangent to sphere (y=a*x+b):
    i put y_0 and x_0 to this equation:
    y_0=a*x_0+b
    and i can remove one unknown value (for example b): y=a*(x-y_0)+x_0
    3.then i put such equation into the equation for sphere (x^2+y^2=r^2) and this is the quadratic equation which has only one unknown value x and one free parameter: a.
    4.beacause i want to have tangent line, so it should have only one common point with sphere - so the quadratic equation should have determinant equal to zero (only one solution for x). This gives me an equation for a. I should find the value of a which satisfy this equation and then i know this tangent line and have the solution! uf....
    Unfortunately i still didn't find a solution to implement this in labview (and i'm motivated beacuse most of the work for this project is already done). I was trying with the formula parsing and so on, but i didn't succeeded. 
    I will be really grateful for any hints or help!
    Solved!
    Go to Solution.

    helmik,
    LabVIEW does not do symbolic math.  Once you have the equations solved on paper or reduced to a set which can be solved numerically, tehn you can program it in LV.
    When I look at your math in the first post, I see that in (3) you describe an equation in x and a. However, this is not a quadratic equation but a fourth order polynomial with terms like a^2*x^2 and 2*a^2*x*y_0. So this is not so easily solved.
    Is not the tangent to the sphere at right angles to the radius at that point? The angle of the radius can be calculated from x_0 and y_0 and the center of the sphere. Then add 90 degrees. One arctangent and no complicated equations.
    Lynn

  • HowTo: Business User defining Planning Functions?

    Hi all,
    does anybody have experience with allowing Business users Defining Planning Functions (e.g. account A = account B - account C) and could share a rough concept? I basically think about Fox-Formulas, but this includes issues with authorization in productive system.
    Are there any solutions with translating free-text-Formulas (e.g. defined in an Attribut or flatfile, see scenario below) into ABAP or FOX Code?
    Thanks for sharing your ideas and experiences,
    Best regards,
    Michael
    Our scenario:
    - Business users are responsible (and authorized) for specific local Companies.
    - Values of the Chart of accounts are typed in into a input-ready query.
    - for Dummy accounts (e.g. Z01) of the local companies no planning is allowed in the plan version, but business users should be allowed to define a specific formula, such as:
    =  + *
    - these functions run at the end of the planning process in a separate planning version for translating local data into global accounts
    - At best these functions should be maintained as an attribut of the dummy accounts or as free text in a text field next to the account in the plan query, but how to translate the formula into a Fox or ABAP formula without great effort?
    - When using FOX, the issue is, that it is a different GUI and there would have to be a function for each company (there will come new companies) and so on....

    Hi Matthias,
    thanks for the post. The problem isnt of keying in the formula isn't that big, this can for example be done in an attribute Char 60 with Flatfile upload for each planning process.
    My problem is more
    a) if I use FOX Formulas - the usage of fox formulas in productive system for Business User
    I still think that using FOX formulas is the easiest thing to implement, but probably the hardest to run and maintain life. Are there any best practises / how tos about authorization and IP architecture for that?
    b) if I use formulas as Text - the formula parsing itself and the communication with the planning function
    Here you gave me the hint of using customer defined planning functions. That's probably the best thing. I first thought about about a formula parser that is called by fox. Still, parsing free text into structured formulas isn't easy, is it? Are there any how-tows?
    best regards,
    Michael

  • Solving nonlinear equation with VI

    Hi,
    I want to use LabView to solve a nonlinear equation. I read forums and figured out that I can use Nonlinear System Solver. vi and I noticed there are two options to write the equation: 1) F(X) is formula and 2) F(X) is VI. I could use the first option and write the equation with that but I did not understand how to use a sub-Vi to provide the equation. Would any one please tell me how to do that?
    Thank you 

    Soran,
    Read the detailed help for the solver VI. 
    The VI usually executes much faster than the formula parser/evaluator. Since solvers (and curve fitters, which have the same options) may need to evaluate the function many times while solving, that time can become significant.
    In the help is a link to a template for the VI you need. You must use the exact connector pane and reference type. While you can create your own VI, it is much easier to use the template. On the block diagram create the code to generate your equation values in the configuration required by the solver. Be careful to put the parameters in the correcto order.
    Lynn

Maybe you are looking for