Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symbolic computation

Tags:

c++

math

Does anyone know a good approach/libs for doing algebraic computations in C++?

I have an application being developed in c++ which needs to do algebraic computation. For now I built a C++ parser that accepts expressions in form of strings like "5 + (2 - MYFUNC(3))" which get tokenized into structs and then converted into postfix notation using the Shunting Yard algorithm and evaluated.

The MYFUNC in these expression are my own defined functions that may do some complex computations.

This is a high performance app, the expressions also have variables that are dynamically replaced with values and the expression is re-evaluated

e.g. var1 + (2 - MYFUNC(var2)) -> with var1 and var2 replaced by some values during the course of the run and re-evaluated

I'm using Linux and so far found Giac library but not sure if it's good, any feedback would be welcome.

How do people generally approach this problem? The main language in this case is C++.

like image 901
Maksim Kneller Avatar asked Dec 28 '10 03:12

Maksim Kneller


People also ask

What is symbolic computation used for?

Symbolic computation lets you express and solve mathematical problems the way you think about mathematical problems-using variables, mathematical formulas, symbols such as π and ∞, and mathematical functions.

What is the difference between symbolic and numerical computation?

In numeric arithmetic, you represent numbers in floating-point format using either double precision or variable precision. In symbolic arithmetic, you represent numbers in their exact form.

What is symbolic computation in MATLAB?

Symbolic variables, expressions, functions, conversions between symbolic and numeric. Symbolic Math Toolbox™ enables you to perform symbolic computations from the MATLAB® command line by defining a special data type — symbolic objects.

What is meant by symbolic mathematics?

symbolic mathematics - (Or "symbolic math") The use of computers to manipulate mathematical equations and expressions in symbolic form, as opposed to manipulating the numerical quantities represented by those symbols.


2 Answers

Have a look on Bison and Flex Parser. The basic idea here is that a grammar file would be written and converted into C code which can be integrated into you application. Any book on Flex and Bison (http://www.amazon.com/Flex-Bison-Text-Processing-Tools/dp/0596155972) is good enough for initial reading.

May be this helps you.!

like image 51
kumar_m_kiran Avatar answered Oct 20 '22 21:10

kumar_m_kiran


Probably the fastest way to handle this is to generate a compiled, optimized function at runtime for the defined function, and evaluate it for the different variable values that you may have. You can do this with LLVM, probably other tools.

like image 43
ergosys Avatar answered Oct 20 '22 22:10

ergosys