GSoC 2015 Application AMiT Kumar Solvers : Extending Solveset - paramsingh/sympy GitHub Wiki

About Me

Basic Information

Name: AMiT Kumar

Email: [email protected]

University: Delhi Technological University, India

Github/IRC: aktech

Website/Blog: iamit.in | blog.iamit.in

Personal Background

I am a 3rd year undergraduate pursuing Bachelor of Technology in Mathematics and Computing Engineering at Delhi Technological University, India. I have been a consistent admirer of Mathematics since my high school, and have taken courses in Higher Mathematics including Abstract Algebra, Linear Algebra, Real Analysis, Discrete Mathematics, Advanced Engineering Mathematics - I,II & III as well as in Computer Science including Data Structures and Algorithm Design & Analysis in my Graduation.

Programming Details

I work on Ubuntu 14.04 LTS machine with Sublime text 3 as my primary text editor because of it's user-friendliness and quick learning curve. I am very much familiar with version control system and been using Git(command line) and Github for quite some time now. I have been programming for over 3 years now, I started with C/C++ and then learnt some Object Oriented Concepts and tried Java and Python. I switched to Python over an year ago due to the fact that there is little difference between Pseudo Code and Python code, which makes the life of a Programmer much easier.

Favorite Features of Python: Extended unpacking (Python 3) & Zipping/unzipping of iterables. In SymPy my Favorite feature is the Solvers & Integral Modules, since it implements the things which are often pretty tough doing Manually, that's the prime reason I am extremely Interested in the Solvers Module.

Contributions to SymPy

I started playing with SymPy in mid November 2014 & made my first contribution in December 2014, Since then I have been consistently contributing and learning from the great community.

  • (Merged) PR #8647 : Fix sign Error in Unrad Function in Solvers unrad is used to simplify radicals, it had a minor sign error, for some type of Equations like: (root(x + 1, 5) - root(x, 3)) which returned wrong answer. It was quite easy to fix. Fix Issue #8622.

  • (Merged) PR #8684 : Solve return solution for Equation where denominator becomes 0 in cases where equal terms cancel out on both sides of equation, For Equations like: For Equations like: x + 1/x == 1/x or x**2 - 1/(x**2 - 4) == 4 - 1/(x**2 - 4): Earlier it returned +/- 2 as the solution, which is wrong as it makes the denominator Zero Fixed that by unevaluating the expression, while processing the Equation. Fix Issue #8666

  • (Merged) PR #8700 : Function to Rewrite gamma as Factorial, Rewrite of this kind is very useful in case of combinatorial simplification. Earlier we could only rewrite factorial in terms of gamma, but with the help of this PR, we can do vice-versa also. Fix #8621

  • (Merged) PR #8706 : Add is_real functionality for factorial, Fix issue #8658

  • (Closed) PR #8719 : closed for the need of better patch, later this was Fixed in #8519

  • (Merged) PR #8723 : Improve real assumption helper for factorial function, there was some logical error in the earlier implementation, since earlier factorial(x) was not known to be real when x is a noninteger. Fix #8722

  • (Merged) PR #8741 : Add Support for negative numbers in round function, as round function didn't expected negative arguments: round function was behaving unexpectedly for negative values (as reported in mailing list), sometimes it returned right answer and sometimes wrong. Fixed that by creating different case for negatives. Fix Issue #8720

  • (Merged) PR #8750 : Add is_composite for factorial function, Earlier If n is a nonnegative integer, factorial(n+3).is_composite returns None, but that was wrong since composite asumption helper was not implemented for Factorial. Fix 8724

  • (Merged) PR #8765 : Rewrite Factorial as Product, >>> factorial(k).rewrite(Product) Fix Issue #8757

  • (Merged) PR #8784 : Fix solve(x < oo) & Handle infinity for converting a relational to Sets,
    There is some discussion needed to handle some cases, i.e. disallow oo as solution (i.e. we search for solutions over real/complex domains, not in extended reals) as pointed by Sergey. Fix Issue #8783 , #8777, #8613, #8252.

  • (Merged) PR #8835 : Add Interval convenience Methods, such as Interval.Ropen(0, 1) : [0, 1) Interval.Lopen(0, 1) : (0, 1] Interval.open(0, 1) : (0, 1) : This was suggested by Chris.

  • (Merged) PR #8519 : Fix floor(x -/+ S.Half).is_even for negative even x & Fix is_positive for gamma. Closes #8519

  • (Merged) PR #8846 : Add Sphinx docs for solveset Closes #8725

  • (Merged) PR #9013: Remove C from sympy.solvers for non-cylic imports, This was in continuation of Joachim's effort to remove C.

  • (Merged) PR #9008: Extend Catalan number to negative numbers

  • (Merged) PR #8976: Fix solve_univariate_inequality to handle infinity : This was an improvement for my previous attempt at improving handling of infinity for inequalities, which was the culprit for wrong results in as_set as well.

Bugs/issues reported:

  • Issue #8783 : solve(x < oo) and solve(x > -oo) returns False, Caught and Fixed.
  • Issue #8777 : And(x > 2,x < oo).as_set() returns EmptySet() , Caught and Fixed.
  • Issue #8716 : solve(x, sqrt(x**2)) returns None.
  • Issue #8715 : solve(x + 1/x > -2 + 1/x) inequality returns solution making denominator 0.
  • Issue #8853 : floor(x - S.Half).is_even returns True for negative even 'x'
  • Issue #8666 : solve(Eq(x**2 - 1/(x**2 - 4), 4 - 1/(x**2 - 4))) returns a set of solution for Equation making denominator 0. Caught and Fixed.

The Project

Brief Overview

SymPy already has a pretty powerful solve function. But it has a lot of major issues.

Last year, Harsh Gupta, did a Google Summer of Code project to improve Solvers. Instead of making changes in the current solve function a new submodule named solveset was written. The goal of writing solveset was to eventually replace solve, by the time solveset fixes all the mess around solve. Harsh rewrote the univariate solver, and built the basic Set infrastructure to support the solutions returned for solveset. I, on my part have to extend the solveset module to support solving Multivariate and System of Equations and Transcendental Equations. The solveset is still in the sandbox, I need to make it fully functional, since, solvers are central to any Computer Algebra System.

My Project Introduction Mail (from SymPy Mailing List )

Starting Point for My Application

The Plan

The Current solve needs to be broken into various sub-modules, to make the code more robust, modular, and approachable for developers, moving in lines of the new API, as developed in solveset. Currently the new API is implemented for univarate Equations (single equation, single variable) only, we need to incorporate it for linear systems and multivariate equations, transcendental by rewriting the solvers for these in the new solveset.

The Problem Sets that can be incorporated at once:

  • Linear systems

  • Single Multivariate Equations

  • Transcendental Equations

  • Misc Equations

  1. Multivariate Equation solving:
  • For solving multivariate equations, the order of variables should be given as input, so that we don't need to return dict of variable and value and, we can have a consistent output by using Product Set.
  1. Linear System of Equation:
  • The Linear system of Equation is comparatively easier to tackle.
  • TODO (More Details)
  1. Transcendental Equations
  • A Major class of Transcendental Equations can be solved by the LambertW Function, currently only the principal branch of LambertW is implemented, which is one of the reasons for loss of Solutions.
  1. Complex Set(Plane) Infrastructure
  • Complex set Infrastructure is also not there, and yes we also need to see what other set capabilities we need to implement to support various other kinds of solutions. TODO
  1. Implementing new Algorithms (In sympy.calculus)
  • Singularities

  • General Methods in Differential Calculus

  • We also need to extend the set - boolean (relational) conversion methods to handle multivariate variables.

  • Also for inequality solver (or for solvers in general), singularities module would be useful, so as to prevent getting wrong results, caused due to incorrect simplification of expression, as we saw in this issue: https://github.com/sympy/sympy/issues/8715 , Example: x + 1/x > -2 + 1/x this inequality is written as expr = expr. lhs - expr.rhs , which cancels 1/x and gives wrong result, by including singular point in the solution.

  • Inequality solver in solveset currently uses inequalities.py (dependent on solve) (some discussion here: https://groups.google.com/forum/#!topic/sympy/Yp5NqrXmp2U). It should rather use solveset.

  • All internal solve() calls needs to be replaced with solveset() , this is very important for bringing out the solveset from sandbox to eventually replace solve(). (we need to consider the output API (return type) also while replacing).

Execution

I. Complex Set(Plane) Infrastructure

  • Complex set Infrastructure is also not there, and yes we also need to see what other set capabilities we need to implement to support various other kinds of solutions. TODO

II. Multivariate Equation solving:

  • For solving multivariate equations, the order of variables should be given as input, so that we don't need to return dict of variable and value and, we can return Product Set.

1). Multivariate functions with non point solution: (solvemv)

In [0] solveset((x - 1)*(y - 2), (x, y))
Out[1] {{1} x (-oo, oo), (-oo, oo) x {2}}  # set of ProductSets.

2). Multivariate functions with point solutions:

In []: solveset(x**2 + y**2, (x, y))
Out[]: {(1/2, 1/2)}  # FinteSet set of ordered tuple.
  1. System of Multivariate Equations.
In []: solve([x**2 + 2*y - 9, 2*x - y - 1 ], (x, y))
Out[]: {(-2 + sqrt(15), -5 + 2*sqrt(15)), (-sqrt(15) - 2, -2*sqrt(15) - 5)}   # FinteSet set of ordered tuple.
  • We also need to extend the set - boolean (relational) conversion methods to handle multivariate variables.

III. Solving Linear Systems:

(For system of Equation, we can have this):

In [0] solveset([x + y == 1, x - y == 0], (x,y))
Out[1] {(1/2, 1/2)}   # FinteSet set of ordered tuple.

IV. 'Solving Transcedental Equations'

(Equations solvable by LambertW function)

In []: solveset(x + log(x))
Out[]: {LambertW(1)}

In []: solveset(x + exp(x**2), x)
Out[]: {I*sqrt(LambertW(-2)/2)}

V. Implementing new Algorithms

In sympy.calculus

1. Singularities

In general, a singularity is a point at which an equation, surface, etc., blows up or becomes degenerate. Singularities are often also called singular points.

TODO

2. General Methods in Differential Calculus

  • is_monotonic

A monotonic function is a function which is either entirely nonincreasing or nondecreasing.

In [1]: (log(x)).is_monotonic
Out[1]: True

In [1]: ((x - 1)**2).is_monotonic
Out[1]: False
  • is_increasing TODO

A function f(x) increases on an interval I if f(b)>=f(a) for all b>a, where a,b in I.

In [1]: Eq.is_increasing
Out[1]: True

In [1]: Eq.is_increasing
Out[1]: False
  • is_strictly_increasing TODO

If f(b)>f(a) for all b>a, the function is said to be strictly increasing.

In [1]: Eq.is_strictly_increasing
Out[1]: True

In [1]: Eq.is_strictly_increasing
Out[1]: False
  • is_decreasing TODO

A function f(x) decreases on an interval I if f(b)<=f(a) for all b>a, where a,b in I.

In [1]: Eq.is_decreasing
Out[1]: True

In [1]: Eq.is_decreasing
Out[1]: False
  • is_strictly_decreasing TODO

If f(b)<f(a) for all b>a, the function is said to be strictly decreasing.

In [1]: Eq.is_strictly_decreasing
Out[1]: True

In [1]: Eq.is_strictly_decreasing
Out[1]: False

Timeline

I will have my exams till the 3rd week of May, thereafter I will start right away. My college restarts on the second week of August, So I will have no problem in contributing full time during this period.

Community Bonding Period & Week 1 & 2

  • Create Complex Set (Plane) Class.
  • Add Methods for Intersection and Union
  • Write tests.
  • Submit the first PR.

Week 3

Implement

  • sets to Boolean &
  • Boolean to set Transformations for multivariate sets and Boolean.
  • Write tests.
  • Submit a PR.

Week 4 & 5

Start working on

  • Multivariate Equation solver in solveset
    • Single Multivariate Equation
    • System of Multivariate Equation

Week 6

  • Start working on solving system of Equations in solveset.
  • Submit a combined PR for Multivariate and system of equation solver.

Week 7 & 8

  • Implement Equations solver by LambertW function.
  • Submit a PR.

Week 9

Since solveset is still in sandbox mode, to finally help it end up as a default solver in the sympy.solvers, we need to replace all solve internal calls with solveset. There over 400 solve calls currently, thanks to Harsh for finding this.

  • Relevant Issue: #8711
  • Submit a PR.

Week 10 & 11

  • Creating a Singularity Finder.
  • Submit a PR.

Week 12

  • Work on Creating General Differential Calculus Methods
    • is_monotonic
    • is_increasing
    • is_strictly_increasing
    • is_decreasing
    • is_strictly_decreasing

Week 13

  • Buffer Period.
  • Fix Bugs.
  • Report Issue for further work on solvers.

Any Plans/Commitment (During GSoC)

  • I have no major commitments for this summer and I am positive that I will be able to contribute for about 40-50 hours a week for the project. This project at will form the core of all my working and learning throughout the Summer.
  • I will be maintaining a Blog(weekly) at blog.iamit.in, to keep track of my progress & also to get feedback from the community.

Future Plans (After GSoC)

  • Sympy is pretty close to my Interests as well as my Academics, I am looking forward for a long term association with Sympy Community.
  • I plan to actively maintain my code and do Bug-fixing/Reviewing in SymPy even after my GSoC time period is over.

References