Coverage for /usr/lib/python3/dist-packages/sympy/sets/handlers/comparison.py: 57%

35 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1from sympy.core.relational import Eq, is_eq 

2from sympy.core.basic import Basic 

3from sympy.core.logic import fuzzy_and, fuzzy_bool 

4from sympy.logic.boolalg import And 

5from sympy.multipledispatch import dispatch 

6from sympy.sets.sets import tfn, ProductSet, Interval, FiniteSet, Set 

7 

8 

9@dispatch(Interval, FiniteSet) # type:ignore 

10def _eval_is_eq(lhs, rhs): # noqa: F811 

11 return False 

12 

13 

14@dispatch(FiniteSet, Interval) # type:ignore 

15def _eval_is_eq(lhs, rhs): # noqa: F811 

16 return False 

17 

18 

19@dispatch(Interval, Interval) # type:ignore 

20def _eval_is_eq(lhs, rhs): # noqa: F811 

21 return And(Eq(lhs.left, rhs.left), 

22 Eq(lhs.right, rhs.right), 

23 lhs.left_open == rhs.left_open, 

24 lhs.right_open == rhs.right_open) 

25 

26@dispatch(FiniteSet, FiniteSet) # type:ignore 

27def _eval_is_eq(lhs, rhs): # noqa: F811 

28 def all_in_both(): 

29 s_set = set(lhs.args) 

30 o_set = set(rhs.args) 

31 yield fuzzy_and(lhs._contains(e) for e in o_set - s_set) 

32 yield fuzzy_and(rhs._contains(e) for e in s_set - o_set) 

33 

34 return tfn[fuzzy_and(all_in_both())] 

35 

36 

37@dispatch(ProductSet, ProductSet) # type:ignore 

38def _eval_is_eq(lhs, rhs): # noqa: F811 

39 if len(lhs.sets) != len(rhs.sets): 

40 return False 

41 

42 eqs = (is_eq(x, y) for x, y in zip(lhs.sets, rhs.sets)) 

43 return tfn[fuzzy_and(map(fuzzy_bool, eqs))] 

44 

45 

46@dispatch(Set, Basic) # type:ignore 

47def _eval_is_eq(lhs, rhs): # noqa: F811 

48 return False 

49 

50 

51@dispatch(Set, Set) # type:ignore 

52def _eval_is_eq(lhs, rhs): # noqa: F811 

53 return tfn[fuzzy_and(a.is_subset(b) for a, b in [(lhs, rhs), (rhs, lhs)])]