30

I'm searching for a good open source Math Library which can do things like:

  • Parse math. expressions "1+1*(3/5)"
  • Integration

Does anybody know something like this?

Flexo
  • 87,323
  • 22
  • 191
  • 272
murtek
  • 611
  • 2
  • 8
  • 6
  • 1
    expression parsing and integration are rather different, depending on how complex the integration you need – Martin Beckett Nov 01 '10 at 17:59
  • Some free Java and C++ implementations of the Shunting Yard Algorithm for converting expressions to Reverse Polish Notation and then evaluating these can be found here: http://www.technical-recipes.com/2011/a-mathematical-expression-parser-in-java-and-cpp/ – AndyUK Jul 27 '13 at 15:06
  • 1
    example parsing of math expressions: https://stackoverflow.com/a/32853177 – Lucinda Rigetti Apr 06 '17 at 10:52

7 Answers7

7

There's also GNU libmatheval, which does evaluation and differentiation. Integration is a much harder problem, even for innocent-looking integrands.

lhf
  • 70,581
  • 9
  • 108
  • 149
5

Octave can do this and can be called from within a C++ program. You can even call C++ code from octave easily using SWIG to generate the interface.

Flexo
  • 87,323
  • 22
  • 191
  • 272
3

I've always used muParser, written in C++, for parsing. You're not going to get a library which can do integration; simply too difficult without a serious heavyweight library. Open source symbolic integrators like Maxima, Octave, etc. exist, but they are hard to interface with, and that functionality can't easily be separated from the rest of the project.

Victor Liu
  • 3,545
  • 2
  • 24
  • 37
2

Try my ae library, which is based on Lua. See also Evaluating Mathematical Expressions using Lua

Community
  • 1
  • 1
lhf
  • 70,581
  • 9
  • 108
  • 149
1

Another approach is to embed an interpreted language in your app and use that langauge's maths parser.

LUA is becoming popular for this - see How to embed lua in c++ via SWIG

Community
  • 1
  • 1
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
1

I had a similar programing need where I used the Shunting yard algorithm. Useful for parsing infix notation like you have.

SuperJames
  • 767
  • 4
  • 14
0

There's MathPresso library which is parser and also JIT compiler of math expressions, I use it when the performance is important.

Some tests: evaluating expression "x / y + (x * x * y + 18.243 * y) / z" - where the variables are double precision floating point numbers.

  • C++ function: 144.1 millions of evaluations per second
  • MathPresso: 133.8 millions of evaluations per second
tartakynov
  • 2,768
  • 3
  • 26
  • 23