Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shekharrajak/09bcad490a49336d5bb45410be40ae18 to your computer and use it in GitHub Desktop.
Save Shekharrajak/09bcad490a49336d5bb45410be40ae18 to your computer and use it in GitHub Desktop.
def _extract_main_soln(sol, soln_imageset):
"""separate the Complements, Intersections, ImageSet lambda expr
and it's base_set.
"""
# if there is union, then need to check
# complement, intersection, Imageset
# order should not be changed.
if isinstance(sol, Complement):
# extract solution and complement
complements[sym] = sol.args[1]
sol = sol.args[0]
# complement will be added at the end
if isinstance(sol, Intersection):
# Interval will be at 0th index always
if sol.args[0] != Interval(-oo, oo):
# sometimes solveset returns soln
# with intersection S.Reals, to confirm that
# soln is in domain=S.Reals
intersections[sym] = sol.args[0]
sol = sol.args[1]
# after intersection and complement Imageset should
# be checked.
if isinstance(sol, ImageSet):
soln_imagest = sol
sol = FiniteSet(sol.lamda.expr)
soln_imageset[sol] = soln_imagest
# if there is union of Imageset in soln
# no testcase is written for this if block
if isinstance(sol, Union):
sol_args = sol.args
sol = []
# put FiniteSet, ImageSet in the soln list.
for sol_arg2 in sol_args:
if isinstance(sol_arg2, FiniteSet):
list_finiteset = list(
[sol_1 for sol_1 in sol_arg2])
sol += list_finiteset
else:
# ImageSet or Intersection or complement
# append them directly
sol.append(sol_arg2)
return sol, soln_imageset
# end of def _extract_main_soln
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment