symbolic computation in C++
Asked Answered
S

3

17

I need to do analytical integration in C++. For example, I should integrate expressions like this: exp[I(x-y)], I is an imaginary number.

How can I do this in C++?

I tried GiNaC but it can just integrate polynomials. I also tried SymbolicC++. It can integrate functions like sine, cosine or exp(x) and ln(x), but it is not very powerful. For example, it can not integrate x*ln(x) which can be easily obtained by use of Mathematica or by integration by parts.

Are there any other tools or libraries which are able to do symbolic computation like analytical integration in C++?

Selemas answered 4/7, 2012 at 8:43 Comment(7)
Did you already try Maxima?Fulfillment
is using Matlab an option? Matlab's symbolic toolbox should be able to do these things. Using the C Matlab Engine you can call it from your C++ code?Foeticide
I do not have Matlab's licence so i can not use it. Does Maxima use c++ syntax? I prefer some library in c++. if i wanted to use other programs like maxima or Matlab i would use Mathematica instead. actually i have wrote my program in mathematica. It is a simple program to silve Integro-defferential equations but the problem is that Mathematica is not efficient in terms of time required for computation. So i decided to write my program in c++.Selemas
Despite the fact that probably there is nothing like you are asking for as a native C++ library, your question, even in principle has many subtleties. To begin with, what do you want to integrate in the first place, you have to be able to define such an expression, is that a runtime expression (e.g. an expression tree) or a compile time expression (e.g. a la Boost.Phoenix)? What kind of result do you want a (runbtime/compiletime) callable function? Your question is very valid, the problem is that a solution will have to resolve this subtleties first.Variole
@Variole Is there any library, that allows to perform symbolic computations at runtime?Sweetener
@Dukales, GiNaC, SymbolicC++, and libmatheval gnu.org/software/libmatheval . In my opinion none of them makes the cut.Variole
GiNaC can integrate sine, cosine, etc on newer versionsInstanter
R
7

If you need to do symbolic integration, then you're probably not going to get anything faster than running it in mathematica or maxima - they're already highly optimised. So unless your equations have a very specific formulae that you can exploit in a way that Mathematica or Maxima can not then you're probably out of luck -- and at very least you're not going to get that kind of custom manipulation from an off-the-shelf library.

You may be justified in writing your own code to get a speed boost if you needed to do numerical solutions. ( I know that I did for generating numerical solutions to PDEs).

Rapeseed answered 5/7, 2012 at 2:30 Comment(5)
My code written in Mathematica is in this link : mediafire.com/?cw9s3ne7jz8fq7s This code is about a recuursion relation. I give it the 0th term and it obtains the first term then it uses the first term to obtain the second one and so on. For the first 4 term it doesn't take so much time but for further terms it takes a lot lot time and acually i have never obtained those higher terms. this code is supposed to solve an integro-differential equation so i need a lot of terms to be obtained. At least i think 50 terms is necessary.Selemas
So beacuse it takes alot of time in Mathematica i decided to write it by c++Selemas
Can you add a picture of the equation, I can't open the mathematica notebook (no mathematica available to me these days...)Rapeseed
MAxima is not written in C++ but in LispSuperfamily
@DamienMattei agreed, I've removed the comment that suggested it was.Rapeseed
G
6

The other C++ libraries I am aware of that do symbolic computation are

If I am not mistaken, SymEngine does not yet support integration; however, Piranha does. The documentation for Piranha is somewhat limited at the moment and is under development, but you can see the integration function here. Note that the second link uses the syntax for the Python wrapper Piranha. However, Piranha "is a computer-algebra library for the symbolic manipulation of sparse multivariate polynomials and other closely-related symbolic objects (such as Poisson series)", so I do not think it can integrate the particular functions in which you may be interested.

Though it is not C++, you may also be interested in SymPy for Python, which can perform some of the more complicated symbolic integration you may be interested in. The documentation for SymPy's integrate is here.

Granville answered 20/7, 2017 at 19:57 Comment(0)
A
4

A couple of days ago, I was searching for a symbolic math library like SymPy for C++, because I bedazzled by its speed comparing to Python or most of the other programming languages.

I found Vienna Math Library, an awesome library with very modern syntax, and SymPy's features to the best of my knowledge. This library also has an integral function that can be used for your problem.

It was good enough for solving IK (Inverse Kinematics) of 3 degrees of freedom articulated manipulator.

Atom answered 5/5, 2020 at 19:33 Comment(1)
It looks like Vienna only supports analytic integration of very simple functions. "Analytical integration is in ViennaMath 1.0.0 available for compiletime types and polynomials as integrands only. " (compiletime types look like they're only binary ops, constants and independent variables)Rapeseed

© 2022 - 2024 — McMap. All rights reserved.