# Documenting Solveset #9500

Merged
merged 34 commits into from Oct 11, 2015

## Conversation

Projects
None yet
9 participants
Member

### aktech commented Jun 10, 2015

As lot of people are not aware of the purpose of solveset , to answer questions like why we are doing, what we are doing, We decided to open a PR , to document it. Where the community can participate and give their views and suggestions.

TODO

• Move docs to sphinx docs

The documentation should answer the following questions either explicitly or implicitly:

• What was the need of a new solvers module?
• Why do we use sets as an output type?
• What is this domain argument about?
• What will you do with the old solve?
• What are the general design principles behind the development of solveset?
• What are the general methods employed by solveset to solve an equation?
• How do we manipulate and return an infinite solutions?
• How does solveset ensures that it is not returning any wrong solution?
• How are symbolic parameters handled in solveset?
• What is future direction of the development of solveset?
• How do we deal with cases where only some of the solutions are known?

### gxyd reviewed Jun 10, 2015

 TODO Note: For the time being, we are are simply using a markdown file placed

#### gxyd Jun 10, 2015

Member

one 'are' is to be removed

Author Member

Thanks!

### gxyd reviewed Jun 10, 2015

 2. The input API is also a mess, there are a lot of parameter. Many of them are not needed and they makes it hard for the user and the developers to

#### gxyd Jun 10, 2015

Member

'that makes it' or 'they make it' i guess

Author Member

Yes, thanks!

#### Upabjojr Jul 25, 2015

Contributor

they makes ===> they make

### gxyd reviewed Jun 10, 2015

 * And the most important case "We don't Know" 2. The input API is also a mess, there are a lot of parameter. Many of them

#### gxyd Jun 10, 2015

Member

'parameters' i guess

Member

### moorepants commented Jul 24, 2015

 I'm interested in "What will you do with the old solve?"
Member

### certik commented Jul 24, 2015

 Thanks for writing this up @aktech.
Member

### asmeurer commented Jul 24, 2015

 Any reason that shouldn't just go in the docs themselves? I think a document like this would be of general interest to SymPy users.

### asmeurer reviewed Jul 24, 2015

 * No Solution: x**2 + 1 == 0; x is real * Interval of solution: floor(x) == 0 * Infinitely many solutions: sin(x) == 0 * Multivariate functions with point solutions x**2 + y**2 == 0

#### asmeurer Jul 24, 2015

Member

You stopped using colons here.

### asmeurer reviewed Jul 24, 2015

 * Multivariate functions with non point solution x**2 + y**2 == 1 * System of equations x + y == 1 and x - y == 0 * Relational x > 0 * And the most important case "We don't Know"

#### asmeurer Jul 24, 2015

Member

I would put this as a separate point. More generally, there is no distinction between "we know we found all the solutions" and "we only found some solutions, but there could be more". This is particularly evident when no solutions are returned, but it applies in every case.

#### hargup Jul 26, 2015

Member

@aktech Please take a note of this.

### asmeurer reviewed Jul 24, 2015

 has to be solved. * solveset can return infinitely many solutions. For example solving for sin(x) = 0 returns {2⋅n⋅π | n ∊ ℤ} ∪ {2⋅n⋅π + π | n ∊ ℤ} Whereas solve

#### asmeurer Jul 24, 2015

Member

Also if you put this in Sphinx you can just make this LaTeX math.

Author Member

Yes, Indeed.

### asmeurer reviewed Jul 24, 2015

 * There is a clear code level and interface level separation between solvers for equations in complex domain and equations in real domain. For example solving exp(x) = 1 when x is complex returns the set of all solutions that is {2⋅n⋅ⅈ⋅π | n ∊ ℤ} . Whereas if x is a real symbol then only {0} is

#### asmeurer Jul 24, 2015

Member

"x is a real symbol" makes it sound like it works like solve, i.e., it behaves differently if you have x = Symbol('x') vs. x = Symbol('x', real=True). But my understanding is that this separation is done by having separate solve functions, not by looking at assumptions.

#### aktech Jul 26, 2015

Author Member

it behaves differently if you have x = Symbol('x') vs. x = Symbol('x', real=True)

It looks for the initial assumption on the symbol to solve for, (by default it assumes complex):

• real = (symbol.is_real is True)

If real is True, then it dispatches the function to solveset_real otherwise solveset_complex is used.

#### hargup Jul 26, 2015

Member

We are adding a domain argument to solveset to decide which solver to call after that solveset should have same behavior with x = Symbol('x', real=True) and x = Symbol('x').
And I should add that solveset_real and solveset_complex "almost" independent of assumptions on the variables, some of the internal transformations are dependent on assumptions and will try to fix such inconsistencies. Interplay between assumptions and domains is something we should think about in future for now solveset tries to not to get involved with assumptions as much as possible.

### asmeurer reviewed Jul 24, 2015

 returned. * solveset returns a solution only when it can guarantee that it is returning all the solutions.

#### asmeurer Jul 24, 2015

Member

So my question then, is, what is the strategy for heuristic solvers that may give all the solutions?

Member

### asmeurer commented Jul 24, 2015

 How are symbolic parameters handled in solveset?
Member

### hargup commented Jul 26, 2015

 I'm interested in "What will you do with the old solve?" We haven't thought a lot about it, a possible approach is doing the following: Replace all internal instances of solve by solveset (by next release) Advertise solveset in solvers doc. Issue an deprecation warning with solve calls (from next release to next to next release) Close all solve issues and open corresponding solveset issues (if needed). (maybe?) Remove solve code.(in next to next release) @asmeurer do you have tenative release dates?
Member Author

### aktech commented Jul 26, 2015

 Thanks for writing this up @aktech. Thanks to @hargup
Member

### hargup commented Jul 26, 2015

 How are symbolic parameters handled in solveset? This is a part of new developements we have made this summer. For example, earlier result for solveset_real(Abs(x) - y, x) was {-y, y} but this answer is valid only when y is positive and we needed to give away this information somehow. Now, we return {-y∩(-oo, 0], y∩[0, oo)}, (-oo, 0] and [0, oo) are the intervals in which these solutions are valid so if substitute a negative y we get an EmptySet and if we substitute a positive value for y, say 2 then we get {-2, 2}. We also plan to write methods to get the set of values for the parameter for which at least one solution exists.
Member

### hargup commented Jul 26, 2015

 @aktech add "How do we deal with cases where only some of the solutions are known?", we discussed that in our last meeting.

Closed

Member

### moorepants commented Jul 29, 2015

 Is there really no way to have the deprecation result in us only having a solve function and no function named solveset? It seems silly to me to remove the solve function and introduce one called solveset in it's place. "solve" is the best function name and if the current solveset function is the best function for solving, we should call it "solve" before SymPy 1.0.
Member

### hargup commented Jul 29, 2015

 solve and solveset are different in both their input and output API(s). The output API of solve (which is list in some cases and dictionaries in other) cannot emulate the output of solveset, a simple example would be cases where solveset returns the Real line or returns all the solutions of sin(x) = 1. For simple cases where solveset returns a finiteset of numbers, the result can be converted to list and here solve can call solveset from backend but cases solveset provides no signifcant advantage over solve. The easiest way to keep backword compatibility with the current solve will be to letting it remain in the code, and encouraging our new users to move to solveset. "solve" is the best function name and if the current solveset function is the best function for solving, we should call it "solve" before SymPy 1.0. This seems like a fair idea but I'm not sure how will this work. If our next release is going to 1.0 then this means removing (current)solve and renaming solveset as solve just before the release. We can't remove solve during active development because we need to refer to it and see how solveset compares. This will also mean total backward compatibility break with 0.7.6. This might be as big issue as backward incompatibillity between python 2 and python 3, first because we are not as big as the python language and second because most of yours use SymPy as a symbolic calculator than a library, so I don't think there is a lot of third party code which depends on solve.
Member

### moorepants commented Jul 29, 2015

 I think for good reasons we can break backwards compatibility for SymPy 1.0. Making solveset replace solve (by function and name) may be one of these good reasons.

Merged

Contributor

### Upabjojr commented Aug 2, 2015

 This is a bit out of topic, but I think that solveset outputs should be supported as integration ranges. Currently, Interval is accepted, but not the union of intervals: In [1]: from sympy import * In [2]: from sympy.solvers.solveset import solveset In [3]: var('x', real=True) Out[3]: x In [4]: intv = solveset(x**2 - 1 > 0, x) In [5]: intv Out[5]: (-oo, -1) U (1, oo) In [6]: integrate(1/x**3, (x, intv)) AttributeError: 'EmptySet' object has no attribute 'as_coeff_Mul' 

### aktech added some commits Aug 19, 2015

 Use double backtick for code 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 fd4cee6 
 Add some references 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 9daa68d 
 Fix Sphinx error: inconsistent whitespace 
 a87066c 
 Mention about method 
 ec1c0f8 
 Explain search based solver 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 d85e09b 
 Modify Answer for what will you do with the old solve 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 0c6de62 
 Fix grammer typo 
 519ecde 
 Fix code formatting 
 96936ef 
 Fix formatting, grammar and typo 
 100e906 
 Minor Formatting 
 b4d0690 

### aktech added some commits Sep 3, 2015

 Fix failing test, pretty printing 
 a2ad89a 
 Fix unicode printing 
 6159459 
 Rewrite: Why not use dicts as output? 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 acfacbc 
 Explain working of invert_foo 
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
 6910205 
 Improve formatting 
 c31aab8 
 Fix ConditionSet reference and edit minor text 
 b4dc604 
Member Author

### thisch reviewed Sep 8, 2015

 be solved. * solveset can return infinitely many solutions. For example solving for \sin{(x)} = 0 returns \{2 n \pi | n \in \mathbb{Z}\} \cup \{2 n \pi + \pi | n \in \mathbb{Z}\},

#### thisch Sep 8, 2015

Contributor

Why doesn't it return \{n \pi | n \in \mathbb{Z}\}? Is it possible to get this solution using sth like simplify ?

#### aktech Sep 8, 2015

Author Member

Why doesn't it return {n \pi | n \in \mathbb{Z}}?

Yeah, it should. Currently it's an issue with ImageSet simplification.

Is it possible to get this solution using sth like simplify ?

No. It doesn't works for ImageSet

#### asmeurer Sep 8, 2015

Member

This can't be fixed in solveset directly? How is sin(x) = 0 solved?

#### aktech Sep 9, 2015

Author Member

This can't be fixed in solveset directly?

Yes, this can be. PR #9750 fixes this. Though ImageSet union simplification is an important issue (PR #7673) to consider for simplifying results in more complex cases.

#### asmeurer Sep 10, 2015

Member

Any thoughts on how to do that? I guess we can do interlacing, like {2*n*pi | n in Z} U {2*m*pi + pi | m in Z} -> {((-1)**k + 1)/2*2*(k/2)*pi + ((-1)**(k + 1) + 1)/2*(2*(k - 1)/2*pi + pi) | k in Z} (i.e., when k is even it represents the first set and when k is odd it represents the second set). It looks like simplify can even simplify this expression to k*pi.

Probably we should open a new issue for this.

#### aktech Sep 11, 2015

Author Member

I think that may work, though not sure how far it would go. We have to see that, since we are using ImageSet for manipulating infinite solutions. In solveset trigonometric and hyperbolic equations are solved by rewriting them into exp form and solving them using polys. exp is inverted as follows:

    if isinstance(f, exp):
if isinstance(g_ys, FiniteSet):
exp_invs = Union(*[imageset(Lambda(n, I*(2*n*pi + arg(g_y)) +
log(Abs(g_y))), S.Integers)
for g_y in g_ys if g_y != 0])

Member Author

### aktech commented Sep 17, 2015

 ping @asmeurer
Member

### asmeurer commented Sep 17, 2015

 I don't have time to give this a full readthrough again. Did you fix the issues I raised (esp. the high level ones)?
Member Author

### aktech commented Sep 18, 2015

 I don't have time to give this a full readthrough again. Did you fix the issues I raised (esp. the high level ones)? Yes, I have fixed them. I have referenced all your comments in the TODO at the top, you can simply check those in the documentation if they are fixed, and do let me know if you are satisfied with them or not.
Member Author

### aktech commented Oct 10, 2015

 Can we merge this? @asmeurer @hargup @flacjacket

### certik added a commit that referenced this pull request Oct 11, 2015

 Merge pull request #9500 from aktech/document-solveset 
Documenting Solveset
 858fc32 

### certik merged commit 858fc32 into sympy:master Oct 11, 2015 1 check passed

#### 1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Member

### certik commented Oct 11, 2015

 It looks good to me. I think the feedback was addressed, and we can improve upon it in master if needed. I just merged it. Thanks for the work @aktech !
Member Author

### aktech commented Oct 11, 2015

 Thanks everyone, for helping in improving this.
Member

### hargup commented Oct 14, 2015

 @aktech Thanks a lot for this work! I encourage other GSoCers and developers to document the design decision and the inner workings of their projects and not just the input/output interface.