Results 1 to 5 of 5

Thread: How to interpret a mathematical formula entered by user

  1. #1
    Join Date
    Nov 2009
    Posts
    47

    How to interpret a mathematical formula entered by user

    I'm just a beginner in Java but I do not lack any motivation, proof, I'll learn to master the best possible language. Currently, I lean on a program whose role is to interpret a mathematical formula input by the user (formula comprised of various functions applied to variables), using also the values entered by the user.

    Example:

    The user enters the formula y = 5x + 3 or y = ax + b (knowing that he knows the values of a and b). He wants the value of y for x = 3. So he tells the value of variables contained in formula. Finally, the program recognizes "the mathematical formula and applies the values of variables entered by user.

    I do not know how to develop this program? For recognition of mathematical formulas, there is no class that can "recognize" a mathematical formula or "tracks" formula?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to interpret a mathematical formula entered by user

    There are parsers of language (including mathematics). Look for example on the side of the library Antlr (go to antlr.org). Attention: it is powerful, but tricky to understand. As part of your exercise, the goal may be to recode yourself a "minimalist parser" meeting only the needed statement.

  3. #3
    Join Date
    Nov 2009
    Posts
    47

    Re: How to interpret a mathematical formula entered by user

    This seems the best approach because these parsers if I recode a minimalist parser, it will be huge because the user should be no limits on the performance of his susceptible capture. For example, there will be exponential root log of the division of two variables. What I mean is that level of recognition formulas, my program should be able to recognize the possible if not all. The parser would it not be more appropriate? I have not looked Antlr (I am familiar with Java)

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to interpret a mathematical formula entered by user

    The two solutions are possible. If you want to code your own parser, nothing prevents you to consider the case that you cite: it is enough to encode object recursively. Here's an idea of the algorithm of the method "eval" before such a formula:
    eval ( "exp (sqrt (log (a / b )))")
    - it detects that it is necessary to calculate an exponential (without looking closer) is applied to calculate the exponential result of the eval method internally.
    - exp (eval ( "root (log (a / b ))"))
    - etc..

    In the subject, with classes and interfaces "Literal", "Operation", "variable", etc this stuff is pretty good code in a generic manner. This is the kind of exercise that helps to understand the mechanisms of inheritance (classes "Addition", "Multiplication", etc.. Implements the interface "OperationBinary" for example).

  5. #5
    Join Date
    Nov 2009
    Posts
    47

    Re: How to interpret a mathematical formula entered by user

    I have to explicitly use a parser and not repeat myself. It is up this mini project as quickly as possible. So I inquired about Antlr but I really do not see how it all works! How do you do for a program with Antlr? What are parser lexer grammar? Can we integrate the snippet Antlr done with a Java program and how? I am a bit lost. I have not found any tutorials so if you know then please explain me.

Similar Threads

  1. Replies: 5
    Last Post: 23-12-2010, 01:13 PM
  2. GTA IV: Product key entered is invalid
    By Teucer in forum Video Games
    Replies: 5
    Last Post: 02-12-2010, 03:30 PM
  3. Unable to evaluate mathematical expression in string
    By Conraad in forum Software Development
    Replies: 4
    Last Post: 04-03-2010, 10:28 PM
  4. build a software which will interpret screen
    By pinga123 in forum Software Development
    Replies: 1
    Last Post: 23-02-2010, 11:19 AM
  5. Decode and interpret a Wi-Fi signal at the mail.
    By RoadRunner in forum Technology & Internet
    Replies: 3
    Last Post: 26-02-2009, 02:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,447,201.21794 seconds with 17 queries