Open rwst opened 6 years ago
Dependencies: #22322
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).
Should we translate to sage.set
as optional output?
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.
Possibilities:
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.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).
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.
Changed dependencies from #22322 to #22322, #24171
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}
See possibly also #31926 or some of its constituent tickets.
Changed dependencies from #22322, #24171 to #24171
Description changed:
---
+++
@@ -1 +1,4 @@
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.
+
+References:
+- https://groups.google.com/g/sympy/c/v_YLkX4QuRY/m/50uHEGbHBAAJ (Mar 2022)
At the moment with
solve(...,algorithm='sympy')
the SymPy functionsolveset
is called for single expressions, andsolve
for systems. However, it turns out thatsolve
can handle some single-expression tasks wheresolveset
fails. This ticket should add code that analyzessolveset
output and callssolve
in case no solution was found. This probably includes simplifying the returnedConditionSet
s.References:
Depends on #24171
CC: @mforets
Component: symbolics
Issue created by migration from https://trac.sagemath.org/ticket/24142