On Fri, 23 Dec 2022 at 07:27, Kevin Moore <kevin...@gmail.com> wrote: > > Hello! I'm trying to get my head wrapped around how to use SolveSet (and > whether I should be using solve or some other method instead), and I ran into > the following problem.
The question is why you are trying to compare these sets. I suspect that whatever you are trying to do here would be better approached in a different way. Also this is unlikely to be a reason for wanting to choose between solve and solveset. > I have two sets: > > Solution_Set=solveset(Eq(y,x+x/2),y,S.Reals) > Solution_Set2=solveset(Eq(y,1.5*x),y,S.Reals) > > Now I want to compare these sets and I was expecting the sets to be > equivalent. I know they're not "equal" (different forms), but I was expecting > them to be the same set. Note that SymPy does not in general consider that 3/2 and 1.5 are equivalent because one is exact and the other is not. This is not always handled consistently though. > I don't see how I can use simplify here, so I tried the following: > > Contains(Solution_Set,Solution_Set2) > False > Contains(Solution_Set2,Solution_Set) > False I think you've misunderstood what Contains means. It is not for testing if one set is a subset of another but rather for testing if some object is an element of some set e.g.: In [15]: Contains(1, Reals) Out[15]: True In [16]: Contains(x, Reals) Out[16]: x ∈ ℝ You're asking if set1 is an element of set2 but it is not since the elements of set2 are real numbers rather than sets. There is no symbolic analogue of Contains for testing subsets but there is the issubset method of Set: In [22]: set1.issubset(set2) # returns None, indeterminate In [23]: set2.issubset(set1) Out[23]: True > Intersection(Solution_Set,Solution_Set2) > [25]: R∩{1.5x} > > Solution_Set2-Solution_Set > [37]: ∅ > Solution_Set-Solution_Set2 > [38]: (R∩{3x2})∖(R∩{1.5x}) > > It would appear that solveset(Eq(y,x+x/2),y,S.Reals) is a superset of > solveset(Eq(y,1.5*x),y,S.Reals) solveset(Eq(y,1.5*x),y,S.Reals), but Contains > didn't work! I'm not sure that you can expect the difference/equivalence between rationals and floats to be handled consistently with operations like this. Better to convert the float to rational or vice-versa: In [20]: nsimplify(set2) == set1 Out[20]: True In [21]: set1.evalf() == set2 Out[21]: True > Is there another way that I should be doing this, or a better way to do this > comparison? Note that I can't just simplify 3*x/2-1.5*x for a variety of > reasons - the application might not make it that simple (I've simplified my > issue to this test case). Rather than looking for another way to do the comparison, take a step back and consider why you are trying to do this comparison at all. You've suggested that this is only a simple example and that you want something to work more generally in more complicated cases but you haven't specified anything about how those other cases might be more complicated. You need to say something specific about the sets or the equations involved to be able to determine an appropriate method. Given some constraints on what you are trying to do e.g. if you happen to know that your equations will always be linear or polynomial etc then it can be possible to do something but you need to specify those constraints. With no constraints on the nature of the equations or sets etc the task that you are asking to solve is algorithmically impossible in full generality due to e.g. Richardson's Theorem: https://en.wikipedia.org/wiki/Richardson%27s_theorem -- Oscar -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxRscfqOWP1JO7O0B%2BUsfsZMFWkSgfGYjqFYC52s0y82pQ%40mail.gmail.com.