# Sympy: Deﬁnite Integration via Integration in the Complex Plane Proposal

Rizgar Mella March 29, 2008
Abstract Symbolic packages become far more powerful when able to solve deﬁnite integrals. A majority of these problems can be solved in the complex plane. A straightforward and eﬀective method done by hand is very powerful, but translation to code may be problematic. Deﬁnite integrals are very important in many scientiﬁc ﬁelds 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 deﬁnite 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 diﬀerential equations.

1

1

Detailed Description

The proposed addition I would like to implement for ﬁnding the solution for deﬁnite integration and integration on complex plane using residues, is to begin with an implementation of ﬁnding the residues of an arbitrary contour. The diﬃculty in ﬁnding the residue is to ﬁnd 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 deﬁnite integral to an appropriate contour, will allow almost every deﬁnite 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
γ+i∞

est f (s)ds
γ−i∞

(1)

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

2

Motivation

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 oﬀer 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 diﬃculty of conveying human intuition into code. Previously I have wanted to join open source project to oﬀer help but, I could oﬀer 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.

3

Deliverables

First target would be set of functions that allow for deﬁnite integrals to be solved. Second target is expansion on the complex analysis done in target one to attempt to solve diﬀerential equation.

2

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.

3.1

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 simpliﬁcation, 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 deﬁnite 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 diﬀer from the wanted solution. This outputs an array of information on the contour, which can be used by other functions.

3.2

Second Target

LaplaceTransform (expression) : Transforms functions and operators. InverseLaplaceTransform(expression) : places in Bromwich contour and ﬁnds sum of residues. PartialDiﬀerentialEqnSolver: Converts partial diﬀerential to ordinary differential equation through Laplace Transform, then solve and Inverse Laplace transform with InverseLaplace().

4

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 ﬁxer on this module to protect its position in the project. • The ﬁrst 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 proﬁle the behavior of some functions that may be used in the potential Deﬁnite 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 ﬂow 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 ﬁnalization. • Week 12: Final Evaluation • Week 13 +: Bug search and ﬁx

5

Testing

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) deﬁnite integrals can be validated, by ﬁrst 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 ﬁnite domains where if the domains are small enough, a majority will seem well behaved to the numerical integrate method and the conﬁdence 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 ﬁles in sympy contain ’test xxx’ functions ﬁlled 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.

6

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

4

• 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 ﬁelding 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.

7

Conclusion

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

5

8

Appendix

Figure 1: Finding Residue Example

Figure 2: Deﬁnite Integration, with the use of residues. First Example

9

References

Example of Integration taken from: www.exampleproblems.com/wiki/index.php/CVRC1 6