Coverage for src/SymbSyntDec/closure.py: 52%
62 statements
« prev ^ index » next coverage.py v7.5.4, created at 2024-08-11 18:00 +0200
« prev ^ index » next coverage.py v7.5.4, created at 2024-08-11 18:00 +0200
1from functools import singledispatch
3from pylogics_modalities.syntax.base import (
4 And as PLTLAnd,
5 Or as PLTLOr,
6 Formula,
7 Not as PLTLNot,
8 _UnaryOp
9)
10from pylogics_modalities.syntax.pltl import (
11 Atomic as PLTLAtomic,
12 Before,
13 WeakBefore,
14 PropositionalFalse,
15 PropositionalTrue,
16 Since,
17 Triggers
18)
19from functools import singledispatch
21Closure_set = set()
22sigma = set()
25def closure_unaryop(formula: _UnaryOp):
26 return closure_operands(formula.argument)
29def closure(formula: object, sigma_input: set) -> set:
30 global sigma
31 sigma = sigma_input
32 return closure_call(formula)
35def closure_call(formula: object) -> set:
36 Closure_set.add(formula)
37 closure_operands(formula)
38 return set(Closure_set)
41@ singledispatch
42def closure_operands(formula: object) -> Formula:
43 raise NotImplementedError(
44 f"Closure not implemented for object of type {type(formula)}"
45 )
48@closure_operands.register
49def closure_prop_true(formula: PropositionalTrue) -> Formula:
50 True
53@closure_operands.register
54def closure_prop_false(formula: PropositionalFalse) -> Formula:
55 True
58@closure_operands.register
59def closure_atomic(formula: PLTLAtomic) -> Formula:
60 global sigma
61 if formula in sigma:
62 Closure_set.add(formula)
63 Closure_set.add(PLTLNot(formula))
66@closure_operands.register
67def closure_and(formula: PLTLAnd) -> Formula:
68 Closure_set.add(formula)
69 [closure_operands(f) for f in formula.operands]
72@closure_operands.register
73def closure_or(formula: PLTLOr) -> Formula:
74 Closure_set.add(formula)
75 [closure_operands(f) for f in formula.operands]
78@closure_operands.register
79def closure_not(formula: PLTLNot) -> Formula:
80 Closure_set.add(formula)
81 closure_unaryop(formula)
84@closure_operands.register
85def closure_yesterday(formula: Before) -> Formula:
86 Closure_set.add(formula)
87 """Compute the base formula for a Before (Yesterday) formula."""
88 closure_unaryop(formula)
91@closure_operands.register
92def 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)
98@closure_operands.register
99def 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)
106@closure_operands.register
107def closure_since(formula: Triggers) -> Formula:
108 Closure_set.add(WeakBefore(formula))
109 for form in formula.operands:
110 closure_operands(form)
113'''
114# Once and Historically are undefined in the Closure definition we are using
115# Examples:
116formula_str = "!a S H(a)" # a T (Y b)
117print(formula_str)
118formula_pltl = parse_pltl(formula_str)
119print(formula_pltl)
120# should be modifies to ( !a S (false T a))
121# (since (not a) (triggers false a))
122formula_modified = modify(formula_pltl)
123print(formula_modified)
124# should return: {a, !a, b, !b, a T (Y b) , Y b, Z (a T (Y b) ) }
125closure_set_return = closure(formula_mogdified)
127'''