Sympy: Definite Integration via Integration in the Complex Plane Proposal

Rizgar Mella March 29, 2008
Abstract Symbolic packages become far more powerful when able to solve definite integrals. A majority of these problems can be solved in the complex plane. A straightforward and effective method done by hand is very powerful, but translation to code may be problematic. Definite integrals are very important in many scientific fields such as quantum mechanics, combined with the importance of open source software in academic circles. Expansion of the Sympy package to include complex variable analysis, through the inclusion of Laplace Transforms and calculation of residues of contours this is achieved from analysis of its poles (residue calculus). The residues allow almost definite integrals to be resolved after reformatting into an appropriate contour, where the sum of residues is the solution. Continuing expansion to include Inverse Laplacians to aid the solution of partial differential equations.



Detailed Description

The proposed addition I would like to implement for finding the solution for definite integration and integration on complex plane using residues, is to begin with an implementation of finding the residues of an arbitrary contour. The difficulty in finding the residue is to find code that detects the poles (easy for humans, must be cautious when dealing with computers). Pole detection can be found by decomposing the function into a tree structure, poles can be found from a set of rules for traversing the tree e.g.( [/s(s+a)], is two single poles one when s=0 and one when s=-a). For more complicated examples the computer program must be more robust. Finding of the residues with reformatting of a definite integral to an appropriate contour, will allow almost every definite integral to become solvable. With the use of the Bromwich Contour, the Inverse Laplacian function can be implemented. The Bromwich Contour/Integral easily produces a contour where the sum of the residues is the Inverse Laplacian, a very useful mathematical operation. BromwichContour = F (t) = 1 2πi

est f (s)ds


The finding of residues, Laplacian transform and inverse Laplacian Tranform have many other applications such as solving partial differential equations, this is done by running a Laplace Transform on the partial differential equation to produce an ordinary differential equation, when solved just apply the inverse Laplacian transform in order to arrive at the correct solution. I hope to write a Residue finding, Laplacian Transform and Inverse Laplacian Transform in python for sympy project.



I have currently completed my third year of Masters of Science in Theoretical Physics at Royal Holloway University of London. With an interest in computational modeling with emphasis on symbolic methods, there are far too many numerical methods that offer no insight into the behavioral properties of similar systems. There are also no commercial packages that are not substandard. Mathematica fails repeatedly at problems that on pen and paper are quite simple to solve; I suppose this comes from the difficulty of conveying human intuition into code. Previously I have wanted to join open source project to offer help but, I could offer nothing but testing as a user. Now I hope I can use what university has so far taught me to contribute, at least in an area I enjoyed which is complex analysis.



First target would be set of functions that allow for definite integrals to be solved. Second target is expansion on the complex analysis done in target one to attempt to solve differential equation.


Functions to be created listed below, these most probably have to change over the course of the project, but for now they will serve as a starting point.


First Target

PoleFinder (contour) : Produces an array of, three element vectors e.g. (Order of pole, Value, Is this contour dependent).Residue (contour) : for each pole by using PoleFinder(contour) within the contour calculates its residue producing an array of residues. SumResidues (contour) : symbolic summation of array from Residue(contour) components with end simplification, some residues may be rejected if they fall outside the contour. SolveContour (contour): symbolically solves contour by applying SumResidues(contour). ContourChangeVariable (Integral) : This imposes a change of variable on the integral to make it an integral around a unit circle also corrects boundarys to allow all definite integrals to be solved. ContourStudy (Integral) : This function evaluates the correct contour for the Integral based on if it is even or odd also considering branching and to insure you are not integrating though poles. Also evaluates what makes the sum of residues differ from the wanted solution. This outputs an array of information on the contour, which can be used by other functions.


Second Target

LaplaceTransform (expression) : Transforms functions and operators. InverseLaplaceTransform(expression) : places in Bromwich contour and finds sum of residues. PartialDifferentialEqnSolver: Converts partial differential to ordinary differential equation through Laplace Transform, then solve and Inverse Laplace transform with InverseLaplace().


Proposed Schedule of work

Beginning of programming 26th of May and ending at the 18th of August, the deliverables should be completed within that time frame, however there is the intension to continue after to ensure that that my allocated section, is something that can be completely integrated with the rest of the sympy project. It is also important to remain as a bug fixer on this module to protect its position in the project. • The first week of this project, is to continue my exploration of the sympy source code, so that I can follow the standards for code and documentation. Also to profile the behavior of some functions that may be used in the potential Definite Integration module (this may require discussions with the community). This is to ensure no duplication of code. The week should be completed with a test database for proposed functions, possibly randomly generated questions from Mathematica with solutions some checked by hand. 3

• Week 2 to 5: is the development of pseudo-code for the deliverables (First Target Functions). Ensuring that issues are covered such as functions interfacing together properly and errors handled. Then the movement to python, with each function completion the associated test will then be applied. • Week 6: some over flow time for smaller issues. Discussion with the community, to evaluate if changes are needed or if any enhancements can be suggested. Start preparations of code and documentation for delivery to be evaluated. • Week 7-8: Mid-Term Evaluation, stand ready for questions. • Week 9 to 11: is the development of pseudo-code for second set of deliverables (Second Target). Checking that functions are interfacing together properly and errors are handled. Then the movement to python, with each function completion the associated test will then be applied. • Full system testing and documentation finalization. • Week 12: Final Evaluation • Week 13 +: Bug search and fix



Testing is an important step in the development of any computational implementation of a mathematical method. Evaluation of most (e.g some number to some number) definite integrals can be validated, by first numerically evaluating the result of the algorithm to be tested, then separately evaluating the integral with numerical methods (well tested and trusted). Both results can be tested to an arbitrary number of decimal places. The sympy nitegrate function can serve as the comparison; obviously the test integrals will then have to be wellbehaved integrals. There are ways of testing non well behaved integrals, which is to symbolically evaluate the integral over many finite domains where if the domains are small enough, a majority will seem well behaved to the numerical integrate method and the confidence in the symbolic method for that integral can then be evaluated in terms of the number of successful domains evaluated over the unsuccessful domains. The test files in sympy contain ’test xxx’ functions filled with asserts, which is a simple enough framework to include my proposed testing method. A random integral generator would be an excellent extreme test, but such a piece of code would require substantial testing on its own, only would be attempted if time permitted.


Curriculum Vitae
• Name: Rizgar Mella • Born the fourth of December 1986, in London in the United Kingdom.


• Completed Secondary School education at Burlington Danes Church of England. • College education received at St. Charles Roman Catholic Sixth Form 2003-2005. • University education at Royal Holloway University of London studying Masters Of Theoretical physics 2005 2009. By the completion of the third year, a strong mathematical grounding was created, allowing for computational modeling. Modeling techniques such as Monte Carlo and self-consistent models like Hartree fock approximation. Most simulation work done in java, Mathematica and Matlab. Over the last year have been fielding python for some simulations. Even though most of the listed programming experience is in an academic arena. There has always been the interest in working on the development of open source software. With trust in my mathematical ability I believe I can make a contribution to the sympy project.



Thank you for you time in evaluation. Any further questions please feel free to contact me. E-mail:




Figure 1: Finding Residue Example

Figure 2: Definite Integration, with the use of residues. First Example



Example of Integration taken from: 6

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.