GSoC 16: Solvers

435 views
Skip to first unread message

Kshitij Saraogi

unread,
Feb 23, 2016, 9:26:31 AM2/23/16
to sympy

Hello,


I am Kshitij Saraogi and I will be a GSoC applicant this year under SymPy.


I wanted to discuss about the Solvers project.[1]

After going through the discussions mentioned on the Ideas page, I would like to get inputs on a few ideas for this project:


  1. Search based Solvers [2]:

      I find this idea quite intriguing. I understand only an abstract view of the idea was presented there.

      I think we should try to implement this as it would make the API cleaner and robust.

      Since, not much has been written about this, I would like to know more about it.

   - What is the methodology we are thinking to use for ranking solutions (if any)?
   - What would be the parameters on which the cost function of different sets depend ?
      So, I would appreciate guidance in this direction.


   2.  Simplifying solutions returned from equations involving trigonometric expressions:

        The solveset module needs improvement with regards to the trignometric equation solver.

        An equation,as simple as, sin(x)=0 gives an output which should be simplified.

        This should be a big concern.

        What would be some good starting points to get an overview of the issue and possibly a few ideas to resolve this ?


   3. Implementing more equation solvers: [3]

  • System of  multivariate linear equations.

  • Nonlinear multivariate equation solver.

  • Equations solvable by LamberW function (Transcendental equation solver)

  • Nested trignometric expressions.

 As Amit pointed out here[4], that we need (ii) and (iii) to make solveset at par with solve.

         I found this paper [5] which talks about implementing a parallel Gauss method for solving this issue. Is it relevant ?

         While fixing an issue [6], I came to know that we need a more reliable multivariate nonlinear equation solver.

         I would like to know more about these solvers with respect to their immediate need and the possible methods of their implementation.

    

   4.  Solving f(x + a) - f(x) = 0 equations: [7]

         While going through some issues, I found that the current solvers can’t handle these type of equations.

       

   5. Building the set infrastructure:

  • Implementing functions to handle multidimensional ImageSet

      Can we be more elaborate on what other features are we expecting ?

I would really appreciate if someone can point out the issues I may have missed.

Also, any relevant resources or links for further readings would help too.


Thanks,

Kshitij Saraogi

AMiT Kumar

unread,
Feb 29, 2016, 2:05:27 AM2/29/16
to sympy
Hi Kshitij,

Good to hear that you want to work on solvers. Here are my comments on your queries.

1. Search Based Solvers:

This idea is currently vague, we need to figure out how exactly
we can develop this. It would be ambitious to develop this idea and It should be
accompanied with lot of research. Currently an abstract is written in the docs:

2. Simplifying solutions returned from equations involving trigonometric expressions:

With the Introduction of solveset an important problem of representing infinite solution
has been solved to some extent, but still there are some issues with ImageSet Union,
due to which a lot of simpler results are not displayed properly. This needs to be figured
out to get better ImageSet Union.

In [10]: solveset(sin(x), x)
Out[10]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

In [11]: solveset(sin(3*x), x)
Out[11]: 
                                        ⎧        2⋅π        ⎫   ⎧        2⋅π  
{2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ} ∪ ⎨2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── |
                                        ⎩         3         ⎭   ⎩         3   

      ⎫   ⎧        π        ⎫   ⎧        π        ⎫
 n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π - ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬
      ⎭   ⎩        3        ⎭   ⎩        3        ⎭


Here is a previous approach on fixing this: https://github.com/sympy/sympy/pull/7673

3. Implementing more Equation solvers

A lot of thing which needs to be done is already done in old solve, like the
solving of multivariate equation solver, you need to figure out how that works
and how you can port those in solveset following the principles of solveset.

I found this paper [5] which talks about implementing a parallel Gauss method for solving this issue. Is it relevant ?

This paper seems like implementing linear system solver, which is already implemented as linsolve.

4.  Solving f(x + a) - f(x) = 0 equations: [7]

This needs to figured out.



   5. Building the set infrastructure:
Implementing functions to handle multidimensional ImageSet
      Can we be more elaborate on what other features are we expecting ? 




Best Regards,
Amit Kumar

Aaron Meurer

unread,
Feb 29, 2016, 2:17:34 AM2/29/16
to sy...@googlegroups.com
Also https://github.com/sympy/sympy/pull/9500/files#r39220151.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/98d1cacd-0ff4-45ef-a0b7-d4b1b2a47c28%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Kshitij Saraogi

unread,
Feb 29, 2016, 3:28:19 PM2/29/16
to sympy


On Monday, February 29, 2016 at 12:35:27 PM UTC+5:30, AMiT Kumar wrote:

1. Search Based Solvers:

This idea is currently vague, we need to figure out how exactly
we can develop this. It would be ambitious to develop this idea and It should be
accompanied with lot of research. Currently an abstract is written in the docs:

I hope we must have some helpful resource for this idea.
If not, do we need to build this from scratch ?

   
2. Simplifying solutions returned from equations involving trigonometric expressions:

With the Introduction of solveset an important problem of representing infinite solution
has been solved to some extent, but still there are some issues with ImageSet Union,
due to which a lot of simpler results are not displayed properly. This needs to be figured
out to get better ImageSet Union.

In [10]: solveset(sin(x), x)
Out[10]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

In [11]: solveset(sin(3*x), x)
Out[11]: 
                                        ⎧        2⋅π        ⎫   ⎧        2⋅π  
{2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ} ∪ ⎨2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── |
                                        ⎩         3         ⎭   ⎩         3   

      ⎫   ⎧        π        ⎫   ⎧        π        ⎫
 n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π - ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬
      ⎭   ⎩        3        ⎭   ⎩        3        ⎭


Here is a previous approach on fixing this: https://github.com/sympy/sympy/pull/7673

I will look into the union of ImageSet.
Moreover, I think there need to be some improvements to the Diophantine solver as it breaks for the intersection of ImageSets.

3. Implementing more Equation solvers

A lot of thing which needs to be done is already done in old solve, like the
solving of multivariate equation solver, you need to figure out how that works
and how you can port those in solveset following the principles of solveset.
Okay. 
I will work on this.
 
4.  Solving f(x + a) - f(x) = 0 equations: [7]

This needs to figured out.


Any ideas how to do so ? 

   5. Building the set infrastructure:
Implementing functions to handle multidimensional ImageSet
      Can we be more elaborate on what other features are we expecting ? 



Thanks for all your help and support. 

-------------------
Kshitij Saraogi

Kshitij Saraogi

unread,
Feb 29, 2016, 3:33:59 PM2/29/16
to sympy
Thanks a lot Aaron.
I will try to attempt the interlacing you suggested.

-------------------
Kshitij Saraogi

Kshitij Saraogi

unread,
Mar 1, 2016, 4:37:36 AM3/1/16
to sympy
Hello,

Another point I would like to know about is the state of inequality handling by solveset.
Recently, I was looking at issue #10140.
It seems that the current solveset gives incomplete as well as an incorrect result.

In []: solveset(sin(x)<0, x, domain=S.Reals)
Out[]: (-∞, 0)

In []: solveset(sin(x)>0, x, domain=S.Reals)
Out[]: (0, π)

There is a fix suggested by Harsh #10022.
I would like to continue from where he left. 

What is the status of implementing trigonometric inequality solvers ? 
Shouldn't this be a high priority issue for improving solveset ?

---------
Kshitij

AMiT Kumar

unread,
Mar 1, 2016, 5:57:12 AM3/1/16
to sympy
There are a lot of equations which are not solved the solveset or solve in
general, the equation you mentioned could just be one of them, It doesn't
denotes a well known type of equation which could be targeted, I would like
to know if there is a special case which you are interested in? Also If that's
not solved by solve as well? If that's solved by solve, you can get a grasp of
the algorithm which could be implemented in solveset.

AMiT Kumar

unread,
Mar 1, 2016, 6:03:30 AM3/1/16
to sympy
In general solving inequality is not a big deal if we are able to 
solve the equality first. After solving the equality if just a matter
of returning the solution in a restricted interval. So, I would
first like to see the equality being solved then inequality would
work for most of the cases, as inequality solvers calls solve/solveset
internally. So we need to make sure the solveset returns the correct
results. 


Amit Kumar

Kshitij Saraogi

unread,
Mar 1, 2016, 6:37:41 AM3/1/16
to sympy

On Tuesday, March 1, 2016 at 4:27:12 PM UTC+5:30, AMiT Kumar wrote:

There are a lot of equations which are not solved the solveset or solve in
general, the equation you mentioned could just be one of them, It doesn't
denotes a well known type of equation which could be targeted, I would like
to know if there is a special case which you are interested in? Also If that's
not solved by solve as well? If that's solved by solve, you can get a grasp of
the algorithm which could be implemented in solveset.
 
 
No. I am not interested in any special case.
I was just giving an instance where I think solveset needs improving.
Also, we are hard coding a lot of solvers for specific equations like _solve_real_trig, _solve_abs etc.
I think adding a search based solver will add flexibility to the equations solveset can handle.

What are your thoughts on this ?

--------
Kshitij

Kshitij Saraogi

unread,
Mar 1, 2016, 6:52:16 AM3/1/16
to sympy
On Tuesday, March 1, 2016 at 4:33:30 PM UTC+5:30, AMiT Kumar wrote:
In general solving inequality is not a big deal if we are able to 
solve the equality first. After solving the equality if just a matter
of returning the solution in a restricted interval. So, I would
first like to see the equality being solved then inequality would
work for most of the cases, as inequality solvers calls solve/solveset
internally. So we need to make sure the solveset returns the correct
results. 

I understand your point.
But I raised this issue for the same reason.

In []: solveset(sin(x), x)
Out[]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

In []: solveset(sin(x)>0, x, domain=S.Reals)
Out[]: (0, π)

In []: solveset(sin(x)<0, x, domain=S.Reals)
Out[]: (-∞, 0)


We are able to solve the equality but solving for the inequalities give the wrong results.
There seems to be some issue with the solve_univariate_inequality function.
I will work on Harsh's branch and try to fix these.

---------
Kshitij

AMiT Kumar

unread,
Mar 1, 2016, 6:56:09 AM3/1/16
to sympy
If you are planning to implement search based solver, then I would
recommend you to work on a concrete plan soon. As It would take a
lot of time to have a consensus from the community on something
which has not been explored much and frankly speaking I am skeptical
about it currently. For the case you mentioned, I am not able to make much
sense from it for implementing a special case solver. Though, when you
would write your plan of execution, It may get more clear then.

> There seems to be some issue with the solve_univariate_inequality function.

It seems like a bug.


Amit Kumar

Kshitij Saraogi

unread,
Mar 1, 2016, 7:33:38 AM3/1/16
to sympy
On Tuesday, March 1, 2016 at 5:26:09 PM UTC+5:30, AMiT Kumar wrote:
If you are planning to implement search based solver, then I would
recommend you to work on a concrete plan soon.

I will think about some possible implementation of a search based solver.
And I would appreciate if you can share how you would like it to be implemented.
 
As It would take a
lot of time to have a consensus from the community on something
which has not been explored much and frankly speaking I am skeptical
about it currently.
I totally understand that there is not much time left for the proposal drafting period to begin.
So I will work on it and with your inputs, maybe we will find a good methodology to implement.
 
For the case you mentioned, I am not able to make much
sense from it for implementing a special case solver.

I am thinking of an overhead checker which can check solutions returned via different solvers.
For example,
In []: solveset(sin(x), x)
Out[]: {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ}

In []: solveset((sin(x)).rewrite(exp), x)
Out[]: {n⋅π | n ∊ ℤ}


Both the results are correct and mathematically identical.
However, they are treated as being different from each other.
For this, we can implement a `union` method for ImageSet class.
Alternately, we can work up a checker which compares these solutions and returns the optimal one.
This is one of the use-cases of a search based solver. 

Though, when you would write your plan of execution, It may get more clear then.

I will start making a rough application draft right away to get a better overview of things.

Thanks,
Kshitij

Kshitij Saraogi

unread,
Mar 2, 2016, 10:37:53 AM3/2/16
to sympy
While looking at the ``solver`` module, I came across the ``nsolve`` method which solves a nonlinear equation system numerically.

I researched for possible ways of solving such a system for exact solutions and I find these papers particularly interesting:

[1]: A General Solver based on Sparse Resultants

[2]: Solving Polynomial Equations Using Linear Algebra
 
From what I understood, this method transforms the problem of simultaneously solving a system of polynomials into a linear algebra problem
which can then be solved without the regular iterative method.

Since, the solutions returned by the ``solveset`` module must be complete and correct. I think that this algorithm might just as well do that. 
I would like to know if this approach is ideal for implementation.
Please share your thoughts on this.

-------------------
Kshitij Saraogi

Kshitij Saraogi

unread,
Mar 3, 2016, 1:39:18 PM3/3/16
to sympy
This post is with regards to the Set Infrastructure part of the project idea.

After reading a few resources and the ``sets`` module, I would like to know about a few of these points:
  • Handling multidimensional sets 
    The Ideas Page states that we need to implement few functions to handle multidimensional set objects.
    We have a ProductSet class which represents Cartesian Product of Sets.
    Shouldn't a n-ary ProductSet object represent a n-dimensional set object ?
    If not, I would like to know more about this topic.

    While reading Harsh's GSoC Application Proposal, I came across a few points that I think need to be addressed.
  • Sets need to get more powerful to deal with countable infinite sets. I think this needs to be implemented as it enhances over power to deal with ImageSet objects. I will read the relevant resources and try to implement them. Harsh's PR #2904 might come in handy as well.
  • Better imageset evaluator I would like to know what exactly is the inspiration behind this ?
  • More general set to native type converters, they include Bool to Set and Set to Bool conversion for multidimensional sets and bools.

    I read that we already have Boolean to Set converters in SymPy but I am not able to find them.
    Do we still have them in our codebase or has it been removed ?
    Moreover, I would like to know a good usecase for this.

Feel free to add the points I might have overlooked here.

-------------------
Kshitij Saraogi

AMiT Kumar

unread,
Mar 4, 2016, 6:01:05 AM3/4/16
to sympy


On Friday, March 4, 2016 at 12:09:18 AM UTC+5:30, Kshitij Saraogi wrote:
This post is with regards to the Set Infrastructure part of the project idea.

After reading a few resources and the ``sets`` module, I would like to know about a few of these points:
  • Handling multidimensional sets 
    The Ideas Page states that we need to implement few functions to handle multidimensional set objects.
    We have a ProductSet class which represents Cartesian Product of Sets.
    Shouldn't a n-ary ProductSet object represent a n-dimensional set object ?
    If not, I would like to know more about this topic.

Yes, that can work as well. See the implementation of ComplexRegion for Two-Dimensional representation of the argand plane.
 

    While reading Harsh's GSoC Application Proposal, I came across a few points that I think need to be addressed.
  • Sets need to get more powerful to deal with countable infinite sets. I think this needs to be implemented as it enhances over power to deal with ImageSet objects. I will read the relevant resources and try to implement them. Harsh's PR #2904 might come in handy as well.
  • Better imageset evaluator I would like to know what exactly is the inspiration behind this ?

The following could be much simplified with a better Imageset evaluator.

In [11]: solveset(sin(3*x), x)
Out[11]:
                                               2⋅π                  2⋅π  
{2n⋅π | n ℤ} {2n⋅π + π | n ℤ} 2n⋅π - ─── | n ℤ⎬ 2n⋅π + ─── |
                                                3                   3  

               π                  π        
n ℤ⎬ 2n⋅π - | n ℤ⎬ 2n⋅π + | n ℤ⎬
               3                  3        

  • More general set to native type converters, they include Bool to Set and Set to Bool conversion for multidimensional sets and bools.

    I read that we already have Boolean to Set converters in SymPy but I am not able to find them.

as_relational and as_set functions are implemented.

In [18]: bool = Interval(3, 5).as_relational(x)

In [19]: bool
Out[19]: 3 ≤ x ∧ x ≤ 5

In [20]: bool.as_set()
Out[20]: [3, 5]


 
  • Do we still have them in our codebase or has it been removed ?
    Moreover, I would like to know a good usecase for this.

Feel free to add the points I might have overlooked here.

-------------------
Kshitij Saraogi


Amit Kumar

 

Kshitij Saraogi

unread,
Mar 4, 2016, 9:18:52 AM3/4/16
to sympy
  • Handling multidimensional sets 
    The Ideas Page states that we need to implement few functions to handle multidimensional set objects.
    We have a ProductSet class which represents Cartesian Product of Sets.
    Shouldn't a n-ary ProductSet object represent a n-dimensional set object ?
    If not, I would like to know more about this topic.

Yes, that can work as well. See the implementation of ComplexRegion for Two-Dimensional representation of the argand plane.

I see that we have used a ProductSet object to define the desired region on the Argand Plane.
   
 

    While reading Harsh's GSoC Application Proposal, I came across a few points that I think need to be addressed.
  • Sets need to get more powerful to deal with countable infinite sets. I think this needs to be implemented as it enhances over power to deal with ImageSet objects. I will read the relevant resources and try to implement them. Harsh's PR #2904 might come in handy as well.
  • Better imageset evaluator I would like to know what exactly is the inspiration behind this ?

The following could be much simplified with a better Imageset evaluator.

In [11]: solveset(sin(3*x), x)
Out[11]:
                                               2⋅π                  2⋅π  
{2n⋅π | n ℤ} {2n⋅π + π | n ℤ} 2n⋅π - ─── | n ℤ⎬ 2n⋅π + ─── |
                                                3                   3  

               π                  π        
n ℤ⎬ 2n⋅π - | n ℤ⎬ 2n⋅π + | n ℤ⎬
               3                  3        

Thanks for this. I will continue Harsh's work and then we can compare these results with that of a heuristic implementation.
Would this be a decent enough approach ?  
  • More general set to native type converters, they include Bool to Set and Set to Bool conversion for multidimensional sets and bools.

    I read that we already have Boolean to Set converters in SymPy but I am not able to find them.

as_relational and as_set functions are implemented.

In [18]: bool = Interval(3, 5).as_relational(x)

In [19]: bool
Out[19]: 3 ≤ x ∧ x ≤ 5

In [20]: bool.as_set()
Out[20]: [3, 5]


Thanks. I must have overlooked it.
Should we not extend this functionality to ProductSet and Boolean class objects respectively ?

-------------------
Kshitij Saraogi

AMiT Kumar

unread,
Mar 4, 2016, 9:25:50 AM3/4/16
to sympy


On Friday, March 4, 2016 at 7:48:52 PM UTC+5:30, Kshitij Saraogi wrote:
  • Handling multidimensional sets 
    The Ideas Page states that we need to implement few functions to handle multidimensional set objects.
    We have a ProductSet class which represents Cartesian Product of Sets.
    Shouldn't a n-ary ProductSet object represent a n-dimensional set object ?
    If not, I would like to know more about this topic.

Yes, that can work as well. See the implementation of ComplexRegion for Two-Dimensional representation of the argand plane.

I see that we have used a ProductSet object to define the desired region on the Argand Plane.
   
 

    While reading Harsh's GSoC Application Proposal, I came across a few points that I think need to be addressed.
  • Sets need to get more powerful to deal with countable infinite sets. I think this needs to be implemented as it enhances over power to deal with ImageSet objects. I will read the relevant resources and try to implement them. Harsh's PR #2904 might come in handy as well.
  • Better imageset evaluator I would like to know what exactly is the inspiration behind this ?

The following could be much simplified with a better Imageset evaluator.

In [11]: solveset(sin(3*x), x)
Out[11]:
                                               2⋅π                  2⋅π  
{2n⋅π | n ℤ} {2n⋅π + π | n ℤ} 2n⋅π - ─── | n ℤ⎬ 2n⋅π + ─── |
                                                3                   3  

               π                  π        
n ℤ⎬ 2n⋅π - | n ℤ⎬ 2n⋅π + | n ℤ⎬
               3                  3        

Thanks for this. I will continue Harsh's work and then we can compare these results with that of a heuristic implementation.
Would this be a decent enough approach ?  

You can also have a look at Aaron's suggestion: https://github.com/sympy/sympy/pull/9500/files#r39220151 
Message has been deleted

Kshitij Saraogi

unread,
Mar 18, 2016, 7:05:51 AM3/18/16
to sympy

The current implementation of solving a system of polynomials is based on the reduced Groebner basis of the input polynomials.
However, it is limited by the root finding algorithm implemented in SymPy.
If no result is returned, we cannot assure that no solution exists. [1]

In order to incorporate it in the `solveset` module, we need to ensure that all solutions of the system are returned.
 
I have thought of 2 ways of tackling this problem:
  • Implement a better root finding algorithm. However, this will always be limited to some order.
  • Implement a new solver using different techniques. 
    I find the method used in this paper[2] quite interesting for our case.

    So, I would like to discuss the issues related to this approach and possible complexities in implementing it.
-------------------
Kshitij Saraogi

nishant shreshth

unread,
Mar 21, 2016, 4:00:19 PM3/21/16
to sympy
Hello I am Nishant and I would like to work on the Solveset api of Sympy.
As there are many things on which we can work. The way we are handling solve till now must be improved firstly as i have seen in solve we get a list . it must be either object or a tuple.
There are many statistical and differential functions that we can implement.
There are many more things that we can discuss and work on.

Harsh Gupta

unread,
Mar 21, 2016, 4:10:25 PM3/21/16
to sy...@googlegroups.com
> The way we are handling solve till now must be improved firstly as i have seen in solve we get a list . it must be either object or a tuple.

Please go through
https://github.com/sympy/sympy/blob/master/doc/src/modules/solvers/solveset.rst

On 22 March 2016 at 01:20, nishant shreshth
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/7177ab92-a4e4-4241-a8ac-e50eba2a95dc%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Harsh
Sent from a GNU/Linux

Kshitij Saraogi

unread,
Mar 23, 2016, 5:07:41 PM3/23/16
to sympy
Minutes of the meeting
------------------------------

I had a conversation with Harsh about some of the issues I face in my proposal.
Here is a gist of the topics we discussed:

  1. Need for Indexed Unions and Intersection
    In order to represent a union (or intersection) of a collection of countably infinite sets, we need to implement an Indexed Union (or Intersection) class. Earlier I was thinking of using ImageSet for handling this but Harsh suggested that indexed Union is more suitable here.
    There is an issue #9815 for the same. 

  2. Use of Pow instead of the proposed MDSet ( I agree its not the best name given to a multidimensional set. )
    Harsh suggested using Pow instead.
    I was a bit reluctant to use Pow, primarily because its docs explicitly state
    `Defines the expression x**y as "x raised to a power y"`
    Here, `x**y` should represent `x X x X .... X x` (y times) i.e y-ary Cartesian Product of Set `x`.
Reply all
Reply to author
Forward
0 new messages