New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documenting Solveset #9500

Merged
merged 34 commits into from Oct 11, 2015

Conversation

Projects
None yet
9 participants
@aktech
Copy link
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?

TODO (Comments to Address)

@aktech aktech force-pushed the aktech:document-solveset branch 2 times, most recently from 077abbe to ed758eb Jun 10, 2015


TODO

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

This comment has been minimized.

@gxyd

gxyd Jun 10, 2015

Member

one 'are' is to be removed

This comment has been minimized.

@aktech

aktech Jun 10, 2015

Author Member

Thanks!

@aktech aktech force-pushed the aktech:document-solveset branch from 416d276 to 4c6715b 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

This comment has been minimized.

@gxyd

gxyd Jun 10, 2015

Member

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

This comment has been minimized.

@aktech

aktech Jun 13, 2015

Author Member

Yes, thanks!

This comment has been minimized.

@Upabjojr

Upabjojr Jul 25, 2015

Contributor

they makes ===> they make

* 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

This comment has been minimized.

@gxyd

gxyd Jun 10, 2015

Member

'parameters' i guess

@aktech aktech changed the title Documenting Solveset [WIP] Documenting Solveset Jun 10, 2015

@flacjacket flacjacket added the GSoC label Jun 14, 2015

@aktech aktech self-assigned this Jul 7, 2015

@moorepants

This comment has been minimized.

Copy link
Member

moorepants commented Jul 24, 2015

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

@certik

This comment has been minimized.

Copy link
Member

certik commented Jul 24, 2015

Thanks for writing this up @aktech.

@asmeurer

This comment has been minimized.

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

* 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`

This comment has been minimized.

@asmeurer

asmeurer Jul 24, 2015

Member

You stopped using colons here.

* 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"

This comment has been minimized.

@asmeurer

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.

This comment has been minimized.

@hargup

hargup Jul 26, 2015

Member

@aktech Please take a note of this.

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`

This comment has been minimized.

@asmeurer

asmeurer Jul 24, 2015

Member

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

This comment has been minimized.

@aktech

aktech Jul 26, 2015

Author Member

Yes, Indeed.

* 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

This comment has been minimized.

@asmeurer

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.

This comment has been minimized.

@aktech

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.

This comment has been minimized.

@hargup

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.

returned.

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

This comment has been minimized.

@asmeurer

asmeurer Jul 24, 2015

Member

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

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Jul 24, 2015

How are symbolic parameters handled in solveset?

@hargup

This comment has been minimized.

Copy link
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?

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Jul 26, 2015

Thanks for writing this up @aktech.

Thanks to @hargup

@hargup

This comment has been minimized.

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

@hargup

This comment has been minimized.

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

@gxyd gxyd referenced this pull request Jul 27, 2015

Closed

solve(x-oo) now returns [] #9454

@moorepants

This comment has been minimized.

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

@hargup

This comment has been minimized.

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

@moorepants

This comment has been minimized.

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

@gxyd gxyd referenced this pull request Aug 1, 2015

Merged

Add domain argument in solveset #9762

2 of 2 tasks complete
@Upabjojr

This comment has been minimized.

Copy link
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>
Add some references
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Explain search based solver
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Modify Answer for what will you do with the old solve
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>

@aktech aktech force-pushed the aktech:document-solveset branch from 63cb732 to b4d0690 Sep 3, 2015

aktech added some commits Sep 3, 2015

Rewrite: Why not use dicts as output?
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
Explain working of `invert_foo`
Signed-off-by: AMiT Kumar <dtu.amit@gmail.com>
@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Sep 8, 2015

@asmeurer @hargup Please have a look, all comments addressed.

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}\}`,

This comment has been minimized.

@thisch

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 ?

This comment has been minimized.

@aktech

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

This comment has been minimized.

@asmeurer

asmeurer Sep 8, 2015

Member

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

This comment has been minimized.

@aktech

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.

This comment has been minimized.

@asmeurer

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.

This comment has been minimized.

@aktech

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])

@aktech aktech changed the title [WIP] Documenting Solveset Documenting Solveset Sep 13, 2015

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Sep 17, 2015

ping @asmeurer

@asmeurer

This comment has been minimized.

Copy link
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)?

@aktech

This comment has been minimized.

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

@aktech

This comment has been minimized.

Copy link
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

@certik certik merged commit 858fc32 into sympy:master Oct 11, 2015

1 check passed

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

This comment has been minimized.

Copy link
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 !

@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Oct 11, 2015

Thanks everyone, for helping in improving this.

@hargup

This comment has been minimized.

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

@aktech aktech deleted the aktech:document-solveset branch Oct 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment