GSoc'16 Solver and Solveset

585 views
Skip to first unread message

Shekhar Prasad Rajak

unread,
Feb 3, 2016, 2:10:34 PM2/3/16
to sympy

Hello, 
my name is Shekhar Prasad Rajak.I want to discuss about Solver and Solveset module
https://github.com/sympy/sympy/wiki/GSoC-2016-Ideas#solvers .I am going to apply for GSoc'16, so trying to know
what sympy community expecting.
Solveset came to Replace all internal solve() calls https://github.com/sympy/sympy/issues/8711
So I should focus on Solveset,right?
I have some questions :
1.What are the main problems/issues in Solver and Solveset right now?
2.Is Solveset module done?If not,what are the main features, that should be added ?
It seems, these need some works :
-functions solvable by LambertW
  -functions that can be recast as polynomials with a change of variables this, for example; this can be 
  factored out of solve  where multiple generators are handled
  to handle the XFAILed test test_real_imag_splitting1, this will be handled in the set module.

3.This is list of Issues/ Discussions I found. 
but I don't know, whether they are solved or not.
Issues which are still open in github repo, need solutions.
There are also links of pdf and research papers, I am not sure whether they are implemented or not.

4.Can we use python library multiprocessing,Synchronization for the faster execution?one issue was opened for the same,which is closed now.But it is always better to take less time.


--
Shekhar Prasad Rajak

Aaron Meurer

unread,
Feb 3, 2016, 2:21:39 PM2/3/16
to sy...@googlegroups.com
Another good resource for what's there and what doesn't work yet is https://github.com/sympy/sympy/blob/master/doc/src/modules/solvers/solveset.rst.

Personally, I'd like to see solutions from equations involving trigonometric expressions improved. Right now you will often get an answer but it is not as simple as it could be (maybe this is more an issue of simplifying set expressions). For example, solveset(sin(x), domain=S.Reals) gives {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ} but it would be better if it gave {n⋅π | n ∊ ℤ}.  I suggested a potential way to fix this at https://github.com/sympy/sympy/pull/9500#discussion_r39220151. Fixing this by improving simplifying set expressions would be nice because then it would work even for set expressions that don't come directly from solveset. 

A related use-case I found where solveset fails is solving f(x) = f(x + a) for a not dependent on x. The ability to solve this in the positive or the negative would tell you if f(x) is periodic (and its period if it is). This currently fails even for sin(x) (https://github.com/sympy/sympy/issues/10426). 

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/33a1b294-4a48-413a-a96f-90899291c1b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shekhar Prasad Rajak

unread,
Feb 4, 2016, 12:07:52 PM2/4/16
to sympy
Thanks for sharing the links, Aaron.
this PR is able to give solutions in simple form in many cases.
When I was trying to solve this issue, I found that solveset converts all the trigonometric equations into exponential form then 
solve them using solveset_complex . 
I haven't find any method that solves trig equations using fu module. fu module also need more simplify expression in different terms.
that contains simple formulas only.

Right now solveset directly convert any trig expression to it's corresponding exponential form.
then we get simplified trig equations.Then solve them using solveset_complex , This may increase number of solutions.Isn't it ? 
Other way can be implement a different algorithms.

--
Shekhar Prasad Rajak

Aaron Meurer

unread,
Feb 4, 2016, 12:15:35 PM2/4/16
to sy...@googlegroups.com
On Thu, Feb 4, 2016 at 12:07 PM, Shekhar Prasad Rajak <shekharr...@gmail.com> wrote:
Thanks for sharing the links, Aaron.
this PR is able to give solutions in simple form in many cases.
When I was trying to solve this issue, I found that solveset converts all the trigonometric equations into exponential form then 
solve them using solveset_complex . 
I haven't find any method that solves trig equations using fu module. fu module also need more simplify expression in different terms.
that contains simple formulas only.

Right now solveset directly convert any trig expression to it's corresponding exponential form.
then we get simplified trig equations.Then solve them using solveset_complex , This may increase number of solutions.Isn't it ? 
Other way can be implement a different algorithms.

I don't see how it would add solutions, other than maybe canceling out singularities (like cos(x)*sec(x)).

I think it's also worthwhile to look into other algorithms.  

By the way, I still think the solving module should be organized around the abstractions of rewriting and decomposition (see https://groups.google.com/forum/#!msg/sympy/42GdMJ9ssyM/swC6bHVunP8J). That was written before solveset so I can't say for sure to what degree solveset already follows this pattern.

Aaron Meurer

Shekhar Prasad Rajak

unread,
Feb 9, 2016, 4:49:32 AM2/9/16
to sympy
Thanks a lot Aaron for sharing the above link, it contain a lot of information.It took me long time 
to go through the attached PR,Issues, and discussions.
Right now I come across the solution that can solve the trigonometric equation g = 0 where g is a trigonometric polynomial. We can convert that into a polynomial system by expanding the sines and cosines in it, replacing sin(x) and cos(x) by two new variables s and c.
before that need to check arguments are same or not.It should not be like sin(x) and cos(x**2).
So now we have two variables and 1 equation another equation we know  : s**2 + c**2 − 1 = 0.Means sin(x)**2 + cos(x)**2 =1.
Similarly we can solve others like tan,sec ; cot,cosec .But I think it will be better if we convert all the trigonometric functions into sin and cos ,and solve them for all cases .Then we don't need to add same types of codes.
It need another method solveset_trig which converts the trigonometric equation to only sin, cos form then polynomial system replacing sin(x) and cos(x) by two new variables s and c.Then need to solve linear or non linear system equation.
Now replacing s -> sin and c-> cos and then solveset_real can easily solve Eq(sin(x),<constant>) types of expressions.
If we have equations like : 
sin(x)**3 + cos(3*x) = 0
then using fu module and trigsimp method we can get :
s**3 + 4*(c**3) - 3*c =0 (cos(3*x) expand)
and s**2 + c**2 − 1 = 0
Similat things can be applied for hyperbolic functions.
Failure case may happen we have nested elements.

equations like :

1 − 2cosθ1 + 2cosθ2 − 2cosθ3 = −0.8

1 − 2cos(5*θ1) + 2cos(5*θ2) − 2cos(5*θ3) = 0

1 − 2cos(7*θ1) + 2cos(7*θ2) − 2cos(7*θ3) = 0

I am not sure how to solve this,yet.
To solve non linear equation I found newton's method : https://www.math.ohiou.edu/courses/math3600/lecture13.pdf

--
Shekhar Prasad Rajak.

Shekhar Prasad Rajak

unread,
Feb 10, 2016, 3:49:17 PM2/10/16
to sympy
I also found that solveset is not able to solve simple tri equations like 
eq = sin(2*x)*cos(x) + cos(2*x)*sin(x)-1
print solveset(eq,x, S.Reals)
Issue: 7914

Even it is not returing correct answer for :
solveset(sin(3*x),x, S.Reals) types of simple equations.

 >>> print solveset(sin(3*x)-1,x, S.Reals)
ImageSet(Lambda(_n, 2*_n*pi - pi/2), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + 5*pi/6), Integers())
 that is also correct answer with incorrect answer :  (2*_n*pi - pi/2) this is wrorng.
solving this type of equation is easy with exp form that sympy do, but before rewriting them into exp form need better expression in sin, cos form
so that sympy can handle exp form of this and return exact answer ,that is needed.
>>> solveset(sin(x)-1/2,x,S.Reals)
Here we need to make sure we write solveset(sin(x)-S(1)/2,x,S.Reals) , that most of the people don't use generally.Is there any way tha
t we dont need to write like this  S(1)/2.


I also found problem in inverse trigonometric functions like :
>>> solveset(acos(-1/2)-x ,x)
{2.0943951023932}
which is not correct and also all the solution is not in radian/degree (in the form of pi) , which is expected.

If solveset is able to solve all types of inverse trig equations then using this we may get a way to solve  solveset(sin(3*x)-1,x, S.Reals) this types of 
problem without converting them into exp form. also using fu module we can convert Mul, divide sin ,cos equation to single argument then it's inverse may lead to
proper answer.


--
Shekhar Prasad Rajak

Shekhar Prasad Rajak

unread,
Feb 11, 2016, 10:58:44 PM2/11/16
to sympy
After checking old `solver` and finding ways to solve non linear system ,I found that one of the good way may 
be substitution method (for simple cases : http://www.purplemath.com/modules/syseqgen5.htm)and Using the Quadratic Formula(some complicated cases: http://www.purplemath.com/modules/syseqgen6.htm).

There are other ways also but to solve all types of Non linear system this method will be usefull and
I have checked that many times we get multiple solution in non linear system and sympy is able to solve
any type of equtaion that we get after the substitution.

Please give your valuable suggestion.

--
Shekhar Prasad Rajak

Harsh Gupta

unread,
Feb 12, 2016, 12:30:26 PM2/12/16
to sy...@googlegroups.com
> >>> solveset(sin(x)-1/2,x,S.Reals)
> ∅ Here we need to make sure we write solveset(sin(x)-S(1)/2,x,S.Reals) , that
> most of the people don't use generally.Is there any way tha t we dont need to
> write like this  S(1)/2.

The issue is because of the rules of the python language. Trying to solve this
issue can too hard or might bring about a lot of unexpected behavior. An easier
things you can do is issuing a warning if you see a float in the input
equation.



> After checking old `solver` and finding ways to solve non linear system ,I
> found that one of the good way may be substitution method (for simple cases :

> Formula(some complicated cases:
> http://www.purplemath.com/modules/syseqgen6.htm).

As far as I remember this methods are already implemented as radical solver.



> Right now I come across the solution that can solve the trigonometric equation
> g = 0 where g is a trigonometric polynomial. We can convert that into a
> polynomial system by expanding the sines and cosines in it, replacing sin(x)
> and cos(x) by two new variables s and c. before that need to check arguments
> are same or not.It should not be like sin(x) and cos(x**2). So now we have two
> variables and 1 equation another equation we know  : s**2 + c**2 − 1 = 0.Means
> sin(x)**2 + cos(x)**2 =1. Similarly we can solve others like tan,sec ;
> cot,cosec .But I think it will be better if we convert all the trigonometric
> functions into sin and cos ,and solve them for all cases .Then we don't need to
> add same types of codes. It need another method solveset_trig which converts
> the trigonometric equation to only sin, cos form then polynomial system
> replacing sin(x) and cos(x) by two new variables s and c.Then need to solve
> linear or non linear system equation. Now replacing s -> sin and c-> cos and
> then solveset_real can easily solve

You can as well solve trig equations by writing them in form of sines or
cosines, as you recognized the current method works by writing them in exp. You
should go ahead and implement it. There is no clear cut "better" method and
the answer depends on the case at hand, which is also the case other techniques
and sub solvers. I was thinking about a "search" on the solving techniques and
I have described the idea in the solveset doc[1] but at this stage the idea is too vauge to
go ahead with the implementation.


> it contain a lot of information.It took me long time to go through the
> attached PR,Issues, and discussions.

I appreciate you effort, I wanted to point out that you can use the SymPy wiki
[2] to maintain your notes about your solvers and other modules. It would be
helpful to you and other people who would want to work on solvers in future.



[1]: https://github.com/sympy/sympy/blob/master/doc/src/modules/solvers/solveset.rst#search-based-solver-and-step-by-step-solution
[2]: https://github.com/sympy/sympy/wiki


--
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.

For more options, visit https://groups.google.com/d/optout.



--
Harsh
Sent from a GNU/Linux

Shekhar Prasad Rajak

unread,
Feb 13, 2016, 8:47:35 AM2/13/16
to sympy
Thanks a lot Harsh, for the suggestions and reviewing the ideas.

After going through many issues ,I found that the main issues on trigonometric  are 
(nested expressions)
and right now solveset can't solve this types of equation system :

1 − 2cosθ1 + 2cosθ2 − 2cosθ3 = −0.8

1 − 2cos(5*θ1) + 2cos(5*θ2) − 2cos(5*θ3) = 0

1 − 2cos(7*θ1) + 2cos(7*θ2) − 2cos(7*θ3) = 0

and simple linear system having trig functions instead fo `x`

One of the good way may be using general function decomposition https://github.com/sympy/sympy/pull/9831 

     >>> decompogen(sin(cos(x)), x)
    [sin(x), cos(x)]
    >>> decompogen(sin(x)**2 + sin(x) + 1, x)
    [x**2 + x + 1, sin(x)]
    >>> decompogen(sqrt(6*x**2 - 5), x)
    [sqrt(x), 6*x**2 - 5]
    >>> decompogen(sin(sqrt(cos(x**2 + 1))), x)
    [sin(x), sqrt(x), cos(x), x**2 + 1]
  

so now we get the expressions in `x` and functions also.By solving these functions top to bottom recursively ,will lead to final result. 
This may solve all types of nested equations (right now solveset can't solve nested modulo/Trig equations properly ) problems.

but to solve this 
1 − 2cosθ1 + 2cosθ2 − 2cosθ3 = −0.8

1 − 2cos(5*θ1) + 2cos(5*θ2) − 2cos(5*θ3) = 0

1 − 2cos(7*θ1) + 2cos(7*θ2) − 2cos(7*θ3) = 0

need some work with deocompogen and function solvers ,I found that docs have some examples to solve simple functions like:
>>> solve(f(x) - x, f(x))
[x]

but it can solve only simple equations.Still I need some more idea to solve this types of complicated equation system.

> After checking old `solver` and finding ways to solve non linear system ,I
> found that one of the good way may be substitution method (for simple cases :
http://www.purplemath.com/modules/syseqgen5.htm) and Using the Quadratic

> Formula(some complicated cases:
http://www.purplemath.com/modules/syseqgen6.htm).

  > As far as I remember this methods are already implemented as radical solver.

I didn't find about radical solver in sympy docs ,Please anyone share a link regarding this.
Right now solveset can handle single equation for a single variable, in any domain either real or complex.
So there is need of non linear system in solveset ,isn't it ? or using old solve for solving non linear system?

--
Shekhar Prasad Rajak

Shekhar Prasad Rajak

unread,
Feb 15, 2016, 12:50:21 PM2/15/16
to sympy
 >I appreciate you effort, I wanted to point out that you can use the SymPy wiki 
 >[2] to maintain your notes about your solvers and other modules. It would be 
 >helpful to you and other people who would want to work on solvers in future.

I have shifted some discussions in sympy wiki page ,please have a look

--
Shekhar Prasad Rajak

Shekhar Prasad Rajak

unread,
Feb 29, 2016, 2:13:04 AM2/29/16
to sympy
Right now `Sympy` returns not simplified general form.If you paste this `solveset(cos(x) + cos(3*x) + cos(5*x),x)` then you will get 

`ImageSet(Lambda(_n, 2*_n*pi + pi/2), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - pi/2), Integers()) U                       ImageSet(Lambda(_n, 2*_n*pi - 2*pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + 2*pi/3), Integers()) U    ImageSet(Lambda(_n, 2*_n*pi - pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - 5*pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + 5*pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi/6), Integers())`

which can be simplified as `(2*n +1)*pi/6`, `(2*n -1)*pi/6`. Similarly many other solutions can be simplified.
I found a solution for this after some discussion in Quora, thanks to active Mathematicians in Quora: 

If we have terms like  `pi/6`, `pi/2`, `5*pi/6`, `7*pi/6`, `3*pi/2`.

  • Take differences until the differences are all equal. In this case, the first differences are all pi/3. This indicates that you can fit a linear function in nn . If it had been necessary to calculate the second differences then one would have had to fit a quadratic function in n . And so on. Very often one can calculate all possible differences without reaching equal differences. Then it's necessary to try something else.
  • Since a linear function will work fit a*n+b , where a and b are arbitrary constants. To do this, set: pi/6=a+b (using the first term) and pi/2=2*a+b (using the second term), then solve for a and b . Now you have a function that should represent all of the terms.
.

So actually we need a method that can make general from from the given terms.


I have updated the wiki page of solvers and solveset , please have a look and give your valuable suggestions.
On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Shekhar Prasad Rajak

unread,
Mar 8, 2016, 4:50:52 AM3/8/16
to sympy
Right now solveset can't solve multivariate polynomial equation system .
For example : 
    
       >>> solve([x*y -1 , 4*x**2 + y**2 -5],(x,y))
      [(1/2, 2), (1, 1)]

 Even solve also don't give two more solutions 
`(-1/2 , -2) and (-1,-1) `

I found a good way to solve these types of equations, after reading some good books  on this topic.  
Link is :  (page 9 example 2.2)

So here we need to construct a `Res(f1,f2 )` matrix.I hope this method will work for most of the equation.

Please share your view on this approach.

I also updated the Solveset and solver wiki, please have a look : 


--
Shekhar Prasad Rajak

On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Harsh Gupta

unread,
Mar 8, 2016, 9:57:46 AM3/8/16
to sy...@googlegroups.com
Some comments on your wiki entry,
https://github.com/sympy/sympy/wiki/Solveset-and-Solver-Discussion

* As you noticed there exists a diophantine equation solver written by
Thilina, that work was done before solveset was developed and imageset
weren't well developed at that time either. It will be totally a
worthwhile project to interface the diophantine solver with solveset.
I think you should think more on this direction.

* I like the direction of your idea on simplifying unions but I need
to think more on it. One of the issue I feel is, how do determine the
points between which you are talking the difference? Also can you
provide a link to the original Quora discussion.

* You can also try to implement the collapsing constants paper [1]
mentioned in the professor Fateman's paper on solvers. Though it is
not immediately useful it will help us simplfiy imagesets like {n + k,
n \in Integers, k \in Integers} and also be useful in solutions of
PDEs.

* You need not worry about "Handling large expression and nested
operation", at least for now. It will be premature optimization.

* The method to solve system of polynomial equations above looks good,
the book also mentions that they have discussed an alternate technique
in Chapter 4 using Grober Basis. Have a look at it and let us know.

* The checksol for inequalities is not required as, we can substitute
a number in the inequalities to see if it satisfies it or not, for
example you can do (2*(x-5) <= 4*x).subs(x, 0)



[1]: http://www.cs.berkeley.edu/~fateman/papers/CollapsingConstants-Soiffer.pdf

On 8 March 2016 at 15:20, Shekhar Prasad Rajak
> --
> 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/31ad019e-e223-4211-8060-697e99cac725%40googlegroups.com.

Aaron Meurer

unread,
Mar 8, 2016, 10:04:15 PM3/8/16
to sy...@googlegroups.com
Algorithms to solve multivariate polynomials are already implemented
(although there are definitely places where they can be improved). See
solve_poly_system.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADN8iupQY3LSPFjG%3DT%3DEsWkH6z1Ad%3Dt19FkhwpPjBav8zASc2w%40mail.gmail.com.

Shekhar Prasad Rajak

unread,
Mar 9, 2016, 1:09:11 PM3/9/16
to sympy
Thanks Harsh and aaron for your reply , this will help a lot.

 One of the issue I feel is, how do determine the 
points between which you are talking the difference? Also can you 
provide a link to the original Quora discussion. 

The original answer is mostly taken from here : http://qr.ae/R921PM
I am also little confused about taking difference, but since here we are going to handle only linear function. So I didn't think about this.
I implemented some parts of this, here : https://github.com/sympy/sympy/pull/10713

I will discuss about diophantine solver with solveset,  implement the collapsing constants paper , solve_poly_system and multivariate polynomials
 equation system ,after  reading about them thoroughly (with some good ideas, questions) as soon as possible.

I am getting some difficulty in implementation of `LambertW` in solveset. 
We can implement this using bivariate.py , right ?
But it is handled through list and old methods.If we want this in solveset then need some good changes in file (or need to rewrite).
Please share your thinking regarding this.
Thanks.


--
Shekhar Prasad Rajak

On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Shekhar Prasad Rajak

unread,
Mar 11, 2016, 1:00:26 AM3/11/16
to sympy
we can't solve these using solveset ?

solve_for_functions_derivatives https://github.com/sympy/sympy/blob/master/sympy/solvers/tests/test_solvers.py#L435

How to solve ordinary differential equations, partial differential equations using solveset ? I haven't found any testcase for that and not in the solveset.py.


--
Shekhar Prasad Rajak.

On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

AMiT Kumar

unread,
Mar 12, 2016, 9:57:28 AM3/12/16
to sympy


On Wednesday, March 9, 2016 at 11:39:11 PM UTC+5:30, Shekhar Prasad Rajak wrote:
Thanks Harsh and aaron for your reply , this will help a lot.

 One of the issue I feel is, how do determine the 
points between which you are talking the difference? Also can you 
provide a link to the original Quora discussion. 

The original answer is mostly taken from here : http://qr.ae/R921PM
I am also little confused about taking difference, but since here we are going to handle only linear function. So I didn't think about this.
I implemented some parts of this, here : https://github.com/sympy/sympy/pull/10713

I will discuss about diophantine solver with solveset,  implement the collapsing constants paper , solve_poly_system and multivariate polynomials
 equation system ,after  reading about them thoroughly (with some good ideas, questions) as soon as possible.

I am getting some difficulty in implementation of `LambertW` in solveset. 
We can implement this using bivariate.py , right ?
But it is handled through list and old methods.If we want this in solveset then need some good changes in file (or need to rewrite).
Please share your thinking regarding this.
Thanks.


Hi Shekhar

Sorry for the late reply.

To solve transcendental equations using LambertW, we need to rewrite
the _tsolve function from old solve() in the new solveset module. _tsolve
does a very good job in solving a large space of transcendental equations,
though the problem lies in the fact that it's very messy and not very extensible. It is 
difficult to add solving of more class of transcendental equations, so it's very
important to write a more modular and extensible transcendental equation
solver. _tsolve also uses bivariate.py for most of the processing, though
you can note that there aren't many direct calls to solve() in the bivariate.py
except one or two, So it would be great if we could directly use (call) bivariate.py for
writing transcendental equation solver in solveset.


Amit Kumar

Shekhar Prasad Rajak

unread,
Mar 12, 2016, 4:46:35 PM3/12/16
to sympy
To solve transcendental equations using LambertW, we need to rewrite
the _tsolve function from old solve in the new solveset module. _tsolve

does a very good job in solving a large space of transcendental equations,
though the problem lies in the fact that it's very messy and not very extensible. It is 
difficult to add solving of more class of transcendental equations, so it's very
important to write a more modular and extensible transcendental equation
solver. _tsolve also uses bivariate.py for most of the processing, though
you can note that there aren't many direct calls to solve() in the bivariate.py
except one or two, So it would be great if we could directly use (call) bivariate.py for
writing transcendental equation solver in solveset.

Thanks Amit , this is really helpful. Now I can go ahead for the todo part of https://github.com/sympy/sympy/pull/10764

So now I am finalizing the problems on which I want to work on:

  1. System of trig equation solver(my 3rd post), improved solve_trig, _invert methods, general form for inverse trig functions.
  2. Simplified general form solution for trig equations.
  3. Implementing Non-linear multivariate system using solve_poly_system and non linear system equation solver using substitution method following solvers method.
  4. Transcendental equation solver like _tsolve in solver.
  5. Diophantine in solveset to get integer solutions.
  6. Fixing XFAIL test-cases ,I have started these work here : https://github.com/sympy/sympy/pull/10733

Basically I want to close this https://github.com/sympy/sympy/issues/10006 in this summer.
I tried to solve equation having nested (trig) expression here : https://github.com/sympy/sympy/pull/10764/files#diff-eec0422923e8f100745c015cd8fdd6cfR193

After discussing in gitter chat with Amit , I got the answers  :
  • Hint system is implemented in ODE and diophantine,but in solveset it is difficult. The idea of hint system was dropped, as per the recommendation from Chris Smith. solveset does a lot things.
  • I wanted to write y' to represent (d/dx)(y(x)) where y is function of x. But it seems difficult for higher order.Not sure.

If anyone expecting that some particular thing should be implemented in this summer. Please let me know.
Thanks.
--
Shekhar Prasad Rajak
 

On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Shekhar Prasad Rajak

unread,
Mar 15, 2016, 7:49:17 AM3/15/16
to sympy
Hello,

Student application for GSoc 2016 is already started.Because of the very tight schedule of the present and next week, I am trying to complete my
 proposal as soon as possible.
 So I have shared the draft of my application named
 `GSoc 2016 Application Shekhar Prasad Rajak: Solvers- Completing Solveset` in the GSoc dashboard https://summerofcode.withgoogle.com/


This is the same link I shared in the GSoc site : 


I have added the wiki page also : 



Please review and comment on draft with your suggestions, it will be really helpful.


Thank you
--
Shekhar Prasad Rajak



On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Aaron Meurer

unread,
Mar 17, 2016, 12:05:30 PM3/17/16
to sy...@googlegroups.com
solveset should only be for solving equations algebraically. Actually
solving an ODE or PDE should be left to dsolve and pdsolve. The way
this is handled in solve is that something like solve(f(x).diff(x) -
f(x), f(x).diff(x)) gives [f(x)], in other words, f(x) and
f(x).diff(x) are considered to be independent of one another.

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/a9e65c58-1947-4e55-bbb8-fa01a5d57254%40googlegroups.com.

Shekhar Prasad Rajak

unread,
Mar 17, 2016, 12:35:23 PM3/17/16
to sympy
Thanks Aaron. 
After the discussion in gitter chat I got similar response, so I didn't added these things in proposal.

Right now I am little confused about solve_univariate_inequality_
This method is used in solveset and it uses `solver` to get critical point.
It will be helpful if someone share something about this PR and related issues to this PR.

if there is trigonometric inequalities then need to add `2*n*pi` in interval boundry (or period after which the interval solution is repeating) to get general solution.
I added some idea regarding this in my proposal.
Please give your valuable time to read the proposal once and  comment/suggestions are highly appreciated:  shared draft.

Thanks.
--
Shekhar Prasad Rajak
On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Aaron Meurer

unread,
Mar 17, 2016, 5:54:18 PM3/17/16
to sy...@googlegroups.com
I apologize if I missed this in the application, but have you figured
out what the format of the solutions for systems of equations will
look like?

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/ff9a0087-b89b-4c52-a37f-9d0048ed7041%40googlegroups.com.

Shekhar Prasad Rajak

unread,
Mar 18, 2016, 2:06:38 PM3/18/16
to sympy
Thanks Aaron for reviewing the application.
For system of non linear equations the format can be similar to `linsolve` means :` FiniteSet(tuple(solution))`
For trig equations solutions would be in  `imageset`. Would there be more cases ?
These are the good ways, right?  

--
Shekhar Prasad Rajak.


On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Harsh Gupta

unread,
Mar 20, 2016, 7:02:56 AM3/20/16
to sy...@googlegroups.com
Some general comments on your proposal:

* Sometimes is it hard to understand what you are trying to say in the
proposal. Check for grammar, revise text to see if you can explain things in
a better way. For section where you are proposing an algorithm explain in it in
step by step manner using bullet points.

More specific comments:

* Expand on how you'll "connect" solveset and diophantine solver, take an
overview of the diophantine solver, study its input and output api, and
propose how you'll do the actual "connection".

* I don't think your gen solve method is correct, I've written my comments on
#10713 and haven't recieved satisfactory answer.

* For the time-line you don't need to say "Submit PR/commits in each 3-4 days
and make required changes", also you have not mentioned when will your
college restart after the summer.

On 18 March 2016 at 23:36, Shekhar Prasad Rajak
> --
> 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/2e8df2bd-d472-4fc1-b250-d50389e14dd7%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



Shekhar Prasad Rajak

unread,
Mar 23, 2016, 1:13:23 PM3/23/16
to sympy
Thanks Harsh for reviewing and suggestions.

Sometimes is it hard to understand what you are trying to say in the 
  proposal. Check for grammar, revise text to see if you can explain things in 
a better way. For section where you are proposing an algorithm explain in it in 
step by step manner using bullet points. 

I have added some more examples and in the shared docs . Feel free to add more comments wherever there is confusion.

* Expand on how you'll "connect" solveset and diophantine solver, take an 
  overview of the diophantine solver, study its input and output api, and 
propose how you'll do the actual "connection". 

Solveset will get answer from diophantine.py methods and then solveset will change the format accordingly. I have added some examples in `Integer solution` section to show how solveset will return solution in conditionset and imageset.

* I don't think your gen solve method is correct, I've written my comments on 
  #10713 and haven't recieved satisfactory answer.

The current idea can give general form for two expressions.  
It seems if we can get more `poly_solution ` (means if solution for exp form of trig eq is : -I and I  => then we get two solutions 2n*pi + pi/2 and 2n*pi + 3*pi/2 .But it can be  pi*(n+1)/2 ) ) ( here I am taking 3*pi/2 instead of -pi/2 ). The number of `exp` terms more than number of solution will be more (union). If anyhow we make all the `exp` present  in the expression; into one `exp` (means exp(I*x) +exp(-I*x)  = > exp(-I*x) * ( exp(2*I*x) +1)  then exp(-I*x) = 0 have no solution and solution of exp(2*I*x) +1= 0 contribute for final solution which is pi*(n+1)/2  ) so in this way we can get more simplified solution. This is what I was trying to say using example `sin(x) = 0` in the PR#10713 comments.

So to follow this steps we need to improve PR #10733 in the `_invert` method , imageset evaluate, reduce union part.I hope within 1-2 weeks I will be able to make a PR with this implementation, if I am correct.

* For the time-line you don't need to say "Submit PR/commits in each 3-4 days 
  and make required changes", also you have not mentioned when will your 
college restart after the summer.

I have added/modified the docs.


 
--
Shekhar Prasad Rajak.


On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Shekhar Prasad Rajak

unread,
Mar 23, 2016, 1:16:50 PM3/23/16
to sympy, kshitij...@gmail.com
Regarding mail : 
Harsh Gupta mentioned you in a comment on GSoC 16: Extending solveset
You do not have commenting rights to GSoC 16: Extending solveset.
It will be good ,if kshitij will give me right to see this docs and comments. 

--
Shekhar Prasad Rajak.

On Thursday, 4 February 2016 00:40:34 UTC+5:30, Shekhar Prasad Rajak wrote:

Shekhar Prasad Rajak

unread,
Mar 23, 2016, 2:32:56 PM3/23/16
to sympy
Thanks Harsh for reviewing and suggestions.

Sometimes is it hard to understand what you are trying to say in the 
  proposal. Check for grammar, revise text to see if you can explain things in 
a better way. For section where you are proposing an algorithm explain in it in 
step by step manner using bullet points. 

I have added some more examples and in the shared docs . Feel free to add more comments if any confusion.

* Expand on how you'll "connect" solveset and diophantine solver, take an 
  overview of the diophantine solver, study its input and output api, and 
propose how you'll do the actual "connection". 

Solveset will get answer from diophantine.py methods and then solveset will change the format accordingly. I have added some examples in `Integer solution` section to show how solveset will return solution in conditionset and imageset.

>>> diop_solve(18*x + 5*y-48)

(5t + 96, -18t - 336)


>>> solveset(18*x + 5*y-48, x, S.Integers)

ConditionSet(ImageSet(Lambda(n, 5*n + 96), S.Integers), Eq(y, ImageSet(Lambda(n, -18*n - 336), S.Integers)), True)


>>> solveset(18*x + 5*y-48, y, S.Integers)

ConditionSet(ImageSet(Lambda(n, -18*n - 336), S.Integers), Eq(x, ImageSet(Lambda(n, 5*n + 96), S.Integers)), True)

I also found that we can implement system of linear diophantine equation solver in diophantine. I have added a section in the shared docs for this.

* I don't think your gen solve method is correct, I've written my comments on 
  #10713 and haven't recieved satisfactory answer.

The current idea can give general form for two expressions.  
It seems if we can get more simplified `poly_solution ` (means if solution for `exp` form ( simplified trig eq exp form) is ( solution for exp(any_args *x ) is  )  -I and I  => then we get two solutions 2*n*pi + pi/2 and 2*n*pi + 3*pi/2 .But it can be  pi*(n+1)/2 ) ) ( here I am taking 3*pi/2 instead of -pi/2 ). The number of `exp` terms are more then number of solutions will be more (union). If somehow we make all the `exp` present  in the expression; into one `exp` (means exp(I*x) +exp(-I*x)  = > exp(-I*x) * ( exp(2*I*x) +1)  then exp(-I*x) = 0 have no solution and solution of exp(2*I*x) +1= 0 contribute for final solution which is pi*(n+1)/2  ) so in this way we can get more simplified solution with less terms and unions. This is what I was trying to say using example `sin(x) = 0` in the PR#10713 comments.

So to follow this steps we need to improve PR #10733 in the `_invert` method (`exp` section) , imageset evaluate, reduce args union part.I hope within 1-2 weeks I will be able to make a PR with this implementation, if I am correct.

* For the time-line you don't need to say "Submit PR/commits in each 3-4 days 
  and make required changes", also you have not mentioned when will your 
college restart after the summer.

I have added/modified the docs.


 

Kshitij Saraogi

unread,
Mar 23, 2016, 2:34:38 PM3/23/16
to Shekhar Prasad Rajak, sympy
Hey Shekhar,

I had given you the needed access.

---------
Kshitij

Shekhar Prasad Rajak

unread,
Mar 24, 2016, 5:16:57 AM3/24/16
to sympy
I tried to follow the steps I proposed in shared docs and https://github.com/sympy/sympy/wiki/Solveset-and-Solver-Discussion#simplified-general-form-for-trigonometric-solution

Right now we don't have much testcase for simplified solution. I changed one testcase which is simplifed one now.

From current master branch :  
```
>>> print solveset(cos(x) + cos(3*x) + cos(5*x),x,S.Reals)
ImageSet(Lambda(_n, 2*_n*pi + pi/2), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - pi/2), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - 2*pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + 2*pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi/3), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - 5*pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + 5*pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi - pi/6), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi/6), Integers())

```
```
>>> print solveset(cos(x) + cos(3*x) + cos(5*x),x,S.Reals)
ImageSet(Lambda(_n, _n*pi/6), Integers())
```

This implementaton may have some defects , but I hope if I get more testcase then I can improve this PR.

Please review once.

--
Shekhar Prasad Rajak

Shekhar Prasad Rajak

unread,
Mar 24, 2016, 12:56:24 PM3/24/16
to sympy
Summery of today's call discussion with Amit :


1. Confirming the idea to get integer solution using solveset, need to check domain= S.Integer . Call the diophantine methods (mostly need diop_solve method), this will return solution in terms of t0 . Now we can convert the solution tuple into Finiteset and return.

2. Similarly we can use solve_poly_system and bivariate.py methods for multivariate and transcendental equation solver . Extend the solveset to get solution for more than one symbols.

3. For simplified general solution of trigonometric equation need more discussion, https://github.com/sympy/sympy/pull/10898 and another idea that is : 
The number of `exp` terms more than number of solution will be more (union). If somehow we make single exp term then only one imageset that may give overall solution, that is general form.
Reply all
Reply to author
Forward
0 new messages