Skip to content
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

Improve interface to SymPy solvers #24142

Open
rwst opened this issue Nov 2, 2017 · 11 comments
Open

Improve interface to SymPy solvers #24142

rwst opened this issue Nov 2, 2017 · 11 comments

Comments

@rwst
Copy link

rwst commented Nov 2, 2017

At the moment with solve(...,algorithm='sympy') the SymPy function solveset is called for single expressions, and solve for systems. However, it turns out that solve can handle some single-expression tasks where solveset fails. This ticket should add code that analyzes solveset output and calls solve in case no solution was found. This probably includes simplifying the returned ConditionSets.

References:

Depends on #24171

CC: @mforets

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/24142

@rwst rwst added this to the sage-8.1 milestone Nov 2, 2017
@rwst
Copy link
Author

rwst commented Nov 2, 2017

Dependencies: #22322

@rwst
Copy link
Author

rwst commented Nov 5, 2017

comment:2

These sets can be returned by solveset: FiniteSet, EmptySet, Interval, Intersection, Union, ConditionSet, ImageSet, Complement, plus the algebraic sets of numbers like ZZ, RR, CC. We can directly translate FiniteSet, EmptySet, Interval. ConditionSet is a AND-combination of a relation and a set, so this can be translated into list format too if the set is finite/interval. Often RR/CC are given as set, and they may be redundant (CC is default with no domain= option given, and RR is implicated with any inequality as condition).

@rwst
Copy link
Author

rwst commented Nov 5, 2017

comment:3

Should we translate to sage.set as optional output?

@rwst
Copy link
Author

rwst commented Nov 5, 2017

comment:4

Let's use sage.set when we can't express the solveset result as list, and later support an option to always use sage.set. As to calling solve do this when EmptySet or the original expression is returned.

@rwst
Copy link
Author

rwst commented Nov 5, 2017

comment:5

Possibilities:

  • translate SymPy's result if possible to list or dict notation; if not possible leave it as is. Disadvantages are that new classes are introduced from SymPy.
  • translate SymPy's result to a sage.set and then, if possible, to list or dict notation; if not possible leave it as sage.set. This would make it necessary to improve sage.set with at least image sets and complex regions.
  • always translate SymPy's result to a sage.set like above, making set notation the default even for the Maxima solver.

A further problem is that output is different between SymPy's solve and solveset. The relation/boolean notation of solve can be translated to set notation for the reals however (see #24156).

@rwst
Copy link
Author

rwst commented Nov 7, 2017

comment:6

Replying to @rwst:

ConditionSet is a AND-combination of a relation and a set, so this can be translated into list format too if the set is finite/interval.

Not so, it is a AND-combination of a relation and an element statement, i.e. symbol in set. This means it cannot be expressed in list format.

@rwst
Copy link
Author

rwst commented Nov 7, 2017

Changed dependencies from #22322 to #22322, #24171

@rwst
Copy link
Author

rwst commented Nov 8, 2017

comment:8

As an example this result set from SymPy:

In [9]: solveset(abs(x) - n, x, S.Reals)
Out[9]: ([0, ∞) ∩ {n}) ∪ ((-∞, 0] ∩ {-n})

is with #24156 and #24171 constructible in Sage:

sage: from sage.sets.set import Set_object_union, Set_object_intersection
sage: _ = var('n')
sage: Set_object_union(Set_object_intersection(RealSet(x>=0),Set([n])), Set_obje
....: ct_intersection(RealSet(x<=0),Set([-n])))
Set-theoretic union of Set-theoretic intersection of [0, +oo) and {n} and Set-theoretic intersection of (-oo, 0] and {-n}

@kcrisman
Copy link
Member

kcrisman commented Jun 9, 2021

comment:10

See possibly also #31926 or some of its constituent tickets.

@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 9, 2021

Changed dependencies from #22322, #24171 to #24171

@mkoeppe mkoeppe modified the milestones: sage-8.1, sage-9.4 Jun 9, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Jul 19, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 14, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 Apr 1, 2022
@mkoeppe

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Aug 31, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants