Coverage for src/SymbSyntDec/closure.py: 52%

1 from functools import singledispatch

2

3 from pylogics_modalities.syntax.base import (

4 And as PLTLAnd,

5 Or as PLTLOr,

6 Formula,

7 Not as PLTLNot,

8 _UnaryOp

9)

10 from pylogics_modalities.syntax.pltl import (

11 Atomic as PLTLAtomic,

12 Before,

13 WeakBefore,

14 PropositionalFalse,

15 PropositionalTrue,

16 Since,

17 Triggers

18)

19 from functools import singledispatch

20

21 Closure_set = set()

22 sigma = set()

23

24

25 def closure_unaryop(formula: _UnaryOp):

26 return closure_operands(formula.argument)

27

28

29 def closure(formula: object, sigma_input: set) -> set:

30 global sigma

31 sigma = sigma_input

32 return closure_call(formula)

33

34

35 def closure_call(formula: object) -> set:

36 Closure_set.add(formula)

37 closure_operands(formula)

38 return set(Closure_set)

39

40

41@ singledispatch

42 def closure_operands(formula: object) -> Formula:

43 raise NotImplementedError(

44 f"Closure not implemented for object of type {type(formula)}"

45 )

46

47

48@closure_operands.register

49 def closure_prop_true(formula: PropositionalTrue) -> Formula:

50 True

51

52

53@closure_operands.register

54 def closure_prop_false(formula: PropositionalFalse) -> Formula:

55 True

56

57

58@closure_operands.register

59 def closure_atomic(formula: PLTLAtomic) -> Formula:

60 global sigma

61 if formula in sigma:

62 Closure_set.add(formula)

63 Closure_set.add(PLTLNot(formula))

64

65

66@closure_operands.register

67 def closure_and(formula: PLTLAnd) -> Formula:

68 Closure_set.add(formula)

69 [closure_operands(f) for f in formula.operands]

70

71

72@closure_operands.register

73 def closure_or(formula: PLTLOr) -> Formula:

74 Closure_set.add(formula)

75 [closure_operands(f) for f in formula.operands]

76

77

78@closure_operands.register

79 def closure_not(formula: PLTLNot) -> Formula:

80 Closure_set.add(formula)

81 closure_unaryop(formula)

82

83

84@closure_operands.register

85 def closure_yesterday(formula: Before) -> Formula:

86 Closure_set.add(formula)

87 """Compute the base formula for a Before (Yesterday) formula."""

88 closure_unaryop(formula)

89

90

91@closure_operands.register

92 def closure_weak_yesterday(formula: WeakBefore) -> Formula:

93 Closure_set.add(formula)

94 """Compute the base formula for a WeakBefore (Weak Yesterday) formula."""

95 closure_unaryop(formula)

96

97

98@closure_operands.register

99 def closure_since(formula: Since) -> Formula:

100 """Compute the base formula for a Since formulas."""

101 Closure_set.add(Before(formula))

102 for form in formula.operands:

103 closure_operands(form)

104

105

106@closure_operands.register

107 def closure_since(formula: Triggers) -> Formula:

108 Closure_set.add(WeakBefore(formula))

109 for form in formula.operands:

110 closure_operands(form)

111

112

113'''

114# Once and Historically are undefined in the Closure definition we are using

115# Examples:

116 formula_str = "!a S H(a)" # a T (Y b)

117 print(formula_str)

118 formula_pltl = parse_pltl(formula_str)

119 print(formula_pltl)

120# should be modifies to ( !a S (false T a))

121# (since (not a) (triggers false a))

122 formula_modified = modify(formula_pltl)

123 print(formula_modified)

124# should return: {a, !a, b, !b, a T (Y b) , Y b, Z (a T (Y b) ) }

125 closure_set_return = closure(formula_mogdified)

126

127'''