Opened 19 months ago
Last modified 18 months ago
#24142 new enhancement
Improve interface to SymPy solvers
Reported by: | rws | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.1 |
Component: | symbolics | Keywords: | |
Cc: | mforets | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #22322, #24171 | Stopgaps: |
Description
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 ConditionSet
s.
Change History (9)
comment:1 Changed 19 months ago by
- Dependencies set to #22322
comment:2 follow-up: ↓ 6 Changed 19 months ago by
comment:3 Changed 19 months ago by
Should we translate to sage.set
as optional output?
comment:4 Changed 19 months ago by
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.
comment:5 Changed 19 months ago by
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 assage.set
. This would make it necessary to improvesage.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).
comment:6 in reply to: ↑ 2 Changed 19 months ago by
Replying to rws:
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.
comment:7 Changed 19 months ago by
- Dependencies changed from #22322 to #22322, #24171
comment:8 Changed 19 months ago by
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}
comment:9 Changed 18 months ago by
- Cc mforets added
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 translateFiniteSet
,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 nodomain=
option given, and RR is implicated with any inequality as condition).