1

Hi as part of my project I have been working on evaluation of arithmetic expression using reg-ex in java.

expressions are like this : 2+3/4(5+7)

first I will modify it to this : 2+3/4*(5+7)

and convert it to postfix

postfix: 23457+*/+

The procedure I have adopted is parsing all of the tokens (i.e. Integers,Operators,Open Paren,Close Paren) using Reg-Ex and then sorting by the i-th position of their occurrence. After that I converted that array of token into post-fix expression and then solved that expression, Until this point every thing is working fine.

Now I would like to extend it to solving differentiation,integration or solving quadratic equation.

foe ex: differentiate or integrate expression x^2+2*x+2

similar to http://integrals.wolfram.com/index.jsp

Is it possible? because right now I dont have any clue how to proceed with that?

Max
  • 9,100
  • 25
  • 72
  • 109
  • What is the question? How to calculate the integrals (for example)? How to parse them? – amit Aug 16 '12 at 07:30
  • 1
    Well, for one thing you shouldn't be relying on regexes for parsing your expression. The example you just gave wouldn't work if the numbers would be more than one digit long. You should be defining your grammar and use a parser generating tool such as antlr (http://www.antlr.org/) – Ioan Alexandru Cucu Aug 16 '12 at 07:32
  • @amit yes that is exactly what my question is.. – Max Aug 16 '12 at 07:34
  • Do you want to evaluate integrals and derivatives at particular points? Or do you want to [symbolically compute](http://en.wikipedia.org/wiki/Symbolic_computation) integrals and derivatives? – Josh Rosen Aug 16 '12 at 07:41
  • Perhaps in other words, you're looking for a "typographical" symbolic differentiator/integrator using regex. If it's allowable to run regex substitutions in a loop (i.e. until there is no more substitution to make), then yes, I suppose it's possible, although ridiculously impractical. You would have to recreate the mechanics of algebra via typographical operations a la Godel Escher Bach... :p – Andrew Cheong Aug 16 '12 at 08:08
  • `postfix: 23457+*/+` Correct? – BLUEPIXY Aug 16 '12 at 21:16
  • @BLUEPIXY I have taken the precedence of * higher than / – Max Aug 17 '12 at 07:16

2 Answers2

1

Most calculators I am aware of - calculating equations/differentions and integrals using numerical analysis. This allows one to find a close solution to the exact (analytical one) solution, sometimes even for unsolveable equations (This is how we got the standard normal table, for the unsolveable normal density function)

For example, solving integrals - gaussian quardature is very common and efficeint way.
For solving equations - regula-falsi method is a simple and intuitive one

amit
  • 175,853
  • 27
  • 231
  • 333
  • Computer Algebra Systems, such as Mathematica, can solve integrals symbolically; http://integrals.wolfram.com/ is a cool example. – Josh Rosen Aug 16 '12 at 07:43
  • @JoshRosen: This is a good comment, I meant something different, but I am lacking the ability to express it in English I am afraid. Mathlab can solve integrals symbolically as well. I fixed the first sentence to "most" - I think it is accurate enough. – amit Aug 16 '12 at 07:51
1

I think that most integral computation engines use the numerical approach just as amit said, however there's a way to compute it symbolically, but it's heuristic more than algorithmic, it's done by pattern matching. I think that Mathematica follows this approach.

Mokhtar Ashour
  • 600
  • 2
  • 9
  • 21
  • Can you give a concrete example of it or any tutorial for the same? – Max Aug 17 '12 at 09:04
  • @Batman actually I don't have a specific tutorial, but with little search you may find a way to do it, however the heuristic approach will require a lot of study and solid mathematical background. – Mokhtar Ashour Aug 17 '12 at 11:49