GSoC 2013 Application Angus Griffith: Assumptions - sympy/sympy GitHub Wiki

Name: Angus Griffith

Enrolment: 4th year Mathematics at the Australian National University.

Contact details:

Email: [email protected]

IRC Nick: sn6uv

Github: sn6uv

Email is probably the best way to contact me since I'm not always on IRC. Living in Australia, I'll also probably be sleeping when the rest of the world awake.

Short Bio / Background overview

The majority of my university courses are in mathematics with focuses on real/complex analysis and computational maths, I've also done some courses and research projects in theoretical physics and computational chemistry. I'm currently the main developer and maintainer of Mathics (an open source Mathematica clone written in Python),

Me the Person

  • I've been using Linux as my primary desktop OS for 5 years now. Arch Linux is my distro of choice.
  • Editor: vim, because I find it much faster to code with and it's preinstalled on most of the platforms I use. In particular I like the syntax highlighting, and macros. my vimrc.
  • My programming knowledge is mostly self-taught after and I'm familiar with C/C++, Javascript, Fortran90/95, Mathematica, but Python is by far my favourite language. One project I'm proud of is the Plotting in Mathics live demo. In particular the adaptive sampling algorithm and the interactive 3D plot.
  • I've contributed almost 30K lines of (mostly Python) code (see here) to Mathics including the Mathics parser, PyPy compatibility, and various other improvements.
  • One feature of Python I really like is list comprehension.
  • Cool example: Sympy's integrate function allows Mathics to perform an integral Mathematica can't live demo.
  • I've used svn, cvs and git. I prefer git over the others.

Me and the Project

  • I'd like to introduce some new functionality into Sympy that makes the assumptions module easier to use. I'd also like to make the assumptions module much more powerful.
  • The more a CAS knows about a particular problem, the simpler the solutions can be. Consider the simple expression x ** n. Sympy, among other CAS, has trouble with this because the expressions has very different behaviour depending the value of n.
>>> from sympy import Symbol, integrate, limit, oo
>>> x, n = Symbol('x'), Symbol('n')
## Example 1 (consider n = -1):
>>> integrate(x ** n, (x, 0, 1))
>>> -0**(n + 1)/(n + 1) + 1/(n + 1)
## Example 2:
>>> limit(x ** n, x, oo)
NotImplementedError: Result depends on the sign of sign(n)
>>> limit(x ** n, x, 0)
NotImplementedError: Result depends on the sign of -sign(n)
## Example 3: (what if n != 0)
>>> (x ** n) ** (1 / n)
(x**n)**(1/n)

But by telling the CAS your assumptions these problems can all be solved. Improvements to the assumptions module will allow sympy to solve such problems. In particular I'm attracted to the challenge of developing a robust solution to a high priority issue.

  • The maths needed to understand this project is fairly limited. What's more important is writing fast, readable, and maintainable code. I think my experience with Mathics will be invaluable in this regard.
  • Sympy already has a working assumptions module, which is the result of many individuals working and contributing over a large period of time. There are too many issues to list them all here, but I plan to construct an extensive list of issues this project will solve (see rough timeline for June below). There is a blog post here describing one particular major change to the assumptions module which is followed by a discussion of some of issues to consider when planning this new module.
  • I'll be moving house in mid July which may impact my progress for that week only. I will be returning to university part time from the 27th of July. Through prior experience (working 20+ hrs/week on Mathics while studying full time) I am confident that I will be able to maintain the 40 hours a week required of me throughout the entire project's duration.
  • Rough Timeline:
    • June - Compile a list of relevant issues and plan the new assumptions system. Generate feedback from the Sympy community on the proposed new behaviour (through discussions with mentor and Sympy mailing list). Start working on a base class for assumptions holder (i.e. like assumptions.AssumptionsContext). Implement and test the with assuming (possible test-driven development).
    • July - Adapt the existing Sympy methods which use assumptions to use the new assumption system (possible PR here). Evaluate how many issues remain and work on closing those. Possibly many PRs for individual functions / issues.
    • August / September - Extend other sympy functions to use the new assumptions module (e.g. simplify, limit). Continue closing as many issues as possible.
  • Prior Sympy successful PRs: #1582, #1512.

Project Ideas

Idea1

Maintain a 'global' assumptions list (similar to global_assumptions, but perhaps renamed to just assumptions) which onto which assumptions can pushed/popped using the with assuming construct:

>>> from sympy import assumptions, assuming, Symbol
>>> x, y = Symbol('x'), Symbol('y')
>>> # assumptions behaves just like global_assumptions
>>> print assumptions
AssumptionsContext([])
>>> assumptions.add(y < 0)
>>> print assumptions
AssumptionsContext([y < 0])
>>> with assuming(x > 0):    # modifies the assumptions
       print assumptions
AssumptionsContext([x > 0, y < 0])
>>> print assumptions
AssumptionsContext([y < 0])

Important things to consider:

  • assuming something already in assumptions, in particular not removing it when assuming.__exit__ is called.
  • How assumptions can be used effectively by other sympy functions e.g. Refine, Integrate, etc.