Serving the Quantitative Finance Community

 
User avatar
hjs

Mathematica and Integration

August 30th, 2012, 5:15 pm

Here's one I recently found - Mathematica can integrate Exp[quadratic] * quadratic, but doesn't always recognize that the integrand is of that form. For example, it can integrate the above expression with general coefficients:In[263]:= Integrate[Exp[c1 + c2 t + c3 t^2] (d1 + d2 t + d3 t^2), t]Out[263]= (E^( c1 - c2^2/( 4 c3)) (2 Sqrt[c3] E^((c2 + 2 c3 t)^2/( 4 c3)) (-c2 d3 + 2 c3 (d2 + d3 t)) + (4 c3^2 d1 + c2^2 d3 - 2 c3 (c2 d2 + d3)) Sqrt[\[Pi]] Erfi[(c2 + 2 c3 t)/(2 Sqrt[c3])]))/(8 c3^(5/2))Change each coefficient to a sum of 3 variable (which should be an irrelevant transformation) and it succeeds as well, although it takes a lot longer:In[262]:= Integrate[ Exp[(c11 + c12 + c13 ) + (c21 + c22 + c23 ) t + (c31 + c32 + c33 ) t^2] (d11 + d12 t + d13 t^2), t]Out[262]= (1/(4 (c31 + c32 + c33)^2)) E^(c11 + c12 + c13 + (c21 + c22 + c23) t + (c31 + c32 + c33) t^2) (2 c33 d12 - c21 d13 - c22 d13 - c23 d13 + 2 c33 d13 t + 2 c31 (d12 + d13 t) + 2 c32 (d12 + d13 t)) + (1/( 8 (c31 + c32 + c33)^( 5/2)))(4 c31^2 d11 + 4 c32^2 d11 + 4 c33^2 d11 - 2 c21 c33 d12 - 2 c22 c33 d12 - 2 c23 c33 d12 + c21^2 d13 + 2 c21 c22 d13 + c22^2 d13 + 2 c21 c23 d13 + 2 c22 c23 d13 + c23^2 d13 - 2 c33 d13 - 2 c32 (-4 c33 d11 + c21 d12 + c22 d12 + c23 d12 + d13) - 2 c31 (-4 c32 d11 - 4 c33 d11 + c21 d12 + c22 d12 + c23 d12 + d13)) E^( c11 + c12 + c13 - (c21 + c22 + c23)^2/(4 (c31 + c32 + c33))) Sqrt[\[Pi]] Erfi[(c21 + c22 + c23 + 2 c31 t + 2 c32 t + 2 c33 t)/( 2 Sqrt[c31 + c32 + c33])]Add a 4th variable to the coefficient of t^2 in the exponent, and it fails:In[264]:= Integrate[ Exp[(c11 + c12 + c13 ) + (c21 + c22 + c23 ) t + (c31 + c32 + c33 + c34 ) t^2] (d11 + d12 t + d13 t^2), t]Out[264]= \[Integral]E^( c11 + c12 + c13 + (c21 + c22 + c23) t + (c31 + c32 + c33 + c34) t^2) (d11 + d12 t + d13 t^2) \[DifferentialD]tThe bottom line is that Mathematica's ability to integrate hinges on it's ability to simplify and recognize functional forms. I believe the latter is uncomputable, so there will always be functions whose integrals have a closed form but which Mathematica (or for that matter any symbolic integration package) will unable to integrate. Although I do find it surprising that it fails in this case.
 
User avatar
bojan
Posts: 0
Joined: August 8th, 2008, 5:35 am

Mathematica and Integration

August 31st, 2012, 11:35 am

Works I think in Maxima, see the listing below. And Maxima has the advantage that we can collectively make it better as it is open-source...
 
User avatar
Cuchulainn
Posts: 22926
Joined: July 16th, 2004, 7:38 am

Mathematica and Integration

August 31st, 2012, 7:12 pm

Maxima Link fixed.Can it do Taylor expansions, e.g. compute truncation errors symbolically for FD schemes?
Last edited by Cuchulainn on August 30th, 2012, 10:00 pm, edited 1 time in total.
 
User avatar
bojan
Posts: 0
Joined: August 8th, 2008, 5:35 am

Mathematica and Integration

September 3rd, 2012, 5:58 am

It can do Taylor expansions, but I have not myself much exercised this functionality.