My first contribution to SymPy!

I wonder why more open source users do not actively participate in the open source community and become committers or contributors.


After understanding a project’s capabilities and roadmap, anyone is able to start directly hacking the source code and contributing useful extensions. Because open source is a distributed, participatory meritocracy, the upside benefit is high and the barrier to entry is low—you don’t have to move, be employed by a Valley startup, give up your day job, or wait to obtain a 4 years for a degree.


I made my first contribution to sympy (a Python library for symbolic mathematics) in which I contributed a simpler and easier technique to calculate the determinant of a 3×3 matrix which I have learned in Dr. Bhadrachalam sir’s Math class.  In SymPy, they were using Bareiss fraction free algorithm which was running on O(n**3) time complexity where as the proposed one runs on O(1). Which is indeed efficient than the Laplace expansion which we have learned in our classroom \latex{ C_{i,j} = (-1)^{i+j} \times M_{i,j}} with time complexity O(n!).

This is how it works.
Lets say we have a matrix A

     [00 01 02]
A =  [10 11 12]
     [20 21 22]

We copy column  1 and column 2 of A to the right side of the augmented matrix A. Such that it turns into a 3×5 matrix.

         |00 01 02|....|00 01 02 00 01|
det(A) = |10 11 12| => |10 11 12 10 11|
         |20 21 22| ...|20 21 22 20 21|

det(A) = Sum of the products of the diagonal elements from left to right – sum of the products of the diagonal elements from right to left

det = (00*11*22 + 01*12*20 + 02*10*21) - (02*11*20 + 00*12*21 + 01*10*22)

These are the corresponding 3 lines of code of the above mentioned method which I have contributed to SymPy:

elif n == 3:
    det = (M[0, 0]*M[1, 1]*M[2, 2] + M[0, 1]*M[1, 2]*M[2, 0] + M[0, 2]*M[1, 0]*M[2, 1]) - \
          (M[0, 2]*M[1, 1]*M[2, 0] + M[0, 0]*M[1, 2]*M[2, 1] + M[0, 1]*M[1, 0]*M[2, 2])

It is also about 100X faster than using bareiss and the correctness is easily confirmed (as per the comment by the developer)

This is the pull request of mine which was merged by one of the developers in Sympy ->
Even they have added me to the contributors list ->

I was very weak in Math during my bachelor’s degree (I even had a backlog in vector Calculus and ODE, which is related to this contribution :-p) . Recently (after joining for master’s degree), I started liking math. I would like to thank my Math teacher Bhadrachalam sir for invoking my interests in the same. I came to know about SymPy through Vipin sir. As I didn’t had any previous knowledge in Python, I started learning it from PySchools, two weeks ago. Then I started looking into the code of SymPy on last Friday and I made my first contribution yesterday!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s