# HG changeset patch
# User Punarbasu Purkayastha <ppurka@gmail.com>
# Date 1362489000 -28800
# Node ID cfeb4bb4548c8ae6be5a96535dffabbb4034b362
# Parent be4962cdd100d0521c00f2469aa014e2a124ca5c
remove vacuous solutions from solve
diff --git a/sage/symbolic/relation.py b/sage/symbolic/relation.py
a
|
b
|
|
313 | 313 | import operator |
314 | 314 | from sage.calculus.calculus import maxima |
315 | 315 | |
| 316 | def _test_solution(solution_list): |
| 317 | """ |
| 318 | Test if the list of symbolic expressions in ``solution_list`` have an |
| 319 | expression which can never be ``True``, like ``0 != 0``. It returns |
| 320 | ``False`` if some expression in the ``solution_list`` evaluates to |
| 321 | ``False``, and otherwise returns ``True``. |
| 322 | |
| 323 | INPUT: |
| 324 | |
| 325 | - ``solution_list`` - a list of symbolic expressions, or a symbolic |
| 326 | expression. It may be an equality or inequality. |
| 327 | |
| 328 | EXAMPLES:: |
| 329 | |
| 330 | sage: from sage.symbolic.relation import _test_solution |
| 331 | sage: from sage.symbolic.ring import SR |
| 332 | sage: _test_solution([x > 2, SR(0) != SR(0)]) |
| 333 | False |
| 334 | sage: _test_solution(x > 2) |
| 335 | True |
| 336 | sage: _test_solution([x > 2, x < 4]) |
| 337 | True |
| 338 | sage: _test_solution(SR(0) != SR(0)) |
| 339 | False |
| 340 | sage: _test_solution([]) |
| 341 | False |
| 342 | |
| 343 | """ |
| 344 | if isinstance(solution_list, list): |
| 345 | if not solution_list: # empty list |
| 346 | return False |
| 347 | for s in solution_list: |
| 348 | if (not s.variables()) and (not bool(s)): |
| 349 | return False |
| 350 | return True |
| 351 | elif (not solution_list.variables()) and (not bool(solution_list)): |
| 352 | return False |
| 353 | return True |
| 354 | |
316 | 355 | def test_relation_maxima(relation): |
317 | 356 | """ |
318 | 357 | Return True if this (in)equality is definitely true. Return False |
… |
… |
|
750 | 789 | except StandardError: # if that gives an error, stick with no solutions |
751 | 790 | s = [] |
752 | 791 | |
753 | | sol_list = string_to_list_of_solutions(repr(s)) |
| 792 | maxima_sol_list = string_to_list_of_solutions(repr(s)) |
| 793 | sol_list = [] |
| 794 | for s in maxima_sol_list: |
| 795 | if _test_solution(s): |
| 796 | sol_list.append(s) |
754 | 797 | |
755 | 798 | # Relaxed form suggested by Mike Hansen (#8553): |
756 | 799 | if kwds.get('solution_dict', False): |