Coverage for /usr/lib/python3/dist-packages/sympy/plotting/intervalmath/interval_membership.py: 34%

41 statements  

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

1from sympy.core.logic import fuzzy_and, fuzzy_or, fuzzy_not, fuzzy_xor 

2 

3 

4class intervalMembership: 

5 """Represents a boolean expression returned by the comparison of 

6 the interval object. 

7 

8 Parameters 

9 ========== 

10 

11 (a, b) : (bool, bool) 

12 The first value determines the comparison as follows: 

13 - True: If the comparison is True throughout the intervals. 

14 - False: If the comparison is False throughout the intervals. 

15 - None: If the comparison is True for some part of the intervals. 

16 

17 The second value is determined as follows: 

18 - True: If both the intervals in comparison are valid. 

19 - False: If at least one of the intervals is False, else 

20 - None 

21 """ 

22 def __init__(self, a, b): 

23 self._wrapped = (a, b) 

24 

25 def __getitem__(self, i): 

26 try: 

27 return self._wrapped[i] 

28 except IndexError: 

29 raise IndexError( 

30 "{} must be a valid indexing for the 2-tuple." 

31 .format(i)) 

32 

33 def __len__(self): 

34 return 2 

35 

36 def __iter__(self): 

37 return iter(self._wrapped) 

38 

39 def __str__(self): 

40 return "intervalMembership({}, {})".format(*self) 

41 __repr__ = __str__ 

42 

43 def __and__(self, other): 

44 if not isinstance(other, intervalMembership): 

45 raise ValueError( 

46 "The comparison is not supported for {}.".format(other)) 

47 

48 a1, b1 = self 

49 a2, b2 = other 

50 return intervalMembership(fuzzy_and([a1, a2]), fuzzy_and([b1, b2])) 

51 

52 def __or__(self, other): 

53 if not isinstance(other, intervalMembership): 

54 raise ValueError( 

55 "The comparison is not supported for {}.".format(other)) 

56 

57 a1, b1 = self 

58 a2, b2 = other 

59 return intervalMembership(fuzzy_or([a1, a2]), fuzzy_and([b1, b2])) 

60 

61 def __invert__(self): 

62 a, b = self 

63 return intervalMembership(fuzzy_not(a), b) 

64 

65 def __xor__(self, other): 

66 if not isinstance(other, intervalMembership): 

67 raise ValueError( 

68 "The comparison is not supported for {}.".format(other)) 

69 

70 a1, b1 = self 

71 a2, b2 = other 

72 return intervalMembership(fuzzy_xor([a1, a2]), fuzzy_and([b1, b2])) 

73 

74 def __eq__(self, other): 

75 return self._wrapped == other 

76 

77 def __ne__(self, other): 

78 return self._wrapped != other