Skip to content
This repository was archived by the owner on Oct 9, 2022. It is now read-only.

Commit d392658

Browse files
committed
Merge branch 'release-0.1.4' for postfix 1.
2 parents 3125e47 + 7cafe5d commit d392658

File tree

12 files changed

+74
-71
lines changed

12 files changed

+74
-71
lines changed

flloat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__author__ = """Marco Favorito"""
66
__email__ = '[email protected]'
7-
__version__ = '0.1.4'
7+
__version__ = '0.1.4.post1'

flloat/base/Alphabet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _members(self):
1515

1616
def powerset(self):
1717
if self._powerset is None:
18-
self._powerset = powerset(self.symbols)
18+
self._powerset = _Alphabet(powerset(self.symbols))
1919
return self._powerset
2020

2121

@@ -25,7 +25,7 @@ def __call__(self, symbols: Set[Symbol]) -> _Alphabet:
2525
return super().__call__(f_symbols)
2626

2727
@classmethod
28-
def fromStrings(symbol_strings: Set[str]):
28+
def fromStrings(cls, symbol_strings: Set[str]):
2929
f_symbols = frozenset(Symbol(s) for s in symbol_strings)
3030
return alphabet_factory.new(f_symbols)
3131

flloat/base/Formula.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _popup(self):
8383
res = ()
8484
for child in self.formulas:
8585
if type(child) == type(self):
86-
superchilds = child._popup()
86+
superchilds = child.formulas
8787
res += superchilds
8888
else:
8989
res += (child, )
@@ -105,7 +105,7 @@ def __init__(self, formulas:OperatorChilds, idempotence=True):
105105
# remove duplicates -> set operation
106106
self.formulas_set = frozenset(self.formulas)
107107
# unique representation -> sorting
108-
self.members = tuple(sorted(self.formulas_set, key=lambda x: str(x)))
108+
self.members = tuple(sorted(self.formulas_set, key=lambda x: hash(x)))
109109

110110
def simplify(self):
111111
if self.idempotence:

flloat/base/nnf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
class NNF(ABC):
99

10-
def __init__(self):
11-
self._cache_id = None
12-
1310
@lru_cache(maxsize=MAX_CACHE_SIZE)
1411
def to_nnf(self):
1512
return self._to_nnf()
@@ -50,7 +47,7 @@ def Not(self):
5047

5148
@Not.setter
5249
def Not(self, x):
53-
self.Not= x
50+
self.Not = x
5451

5552
def _to_nnf(self):
5653
return type(self)(self.f.to_nnf())

flloat/flloat.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ def word_acceptance(self, action_set_list:List[PLInterpretation]):
180180
def is_true(self):
181181
return self._is_true(self.cur_state)
182182

183-
def _is_true(self, Q):
183+
@staticmethod
184+
def _is_true(Q):
184185
if frozenset() in Q:
185186
return True
186187
conj = [PLAnd([subf.delta(None, epsilon=True) for subf in q]) if len(q) >= 2 else
@@ -198,8 +199,8 @@ def get_current_state(self):
198199
def make_transition(self, i:PLInterpretation):
199200
self.cur_state = self._make_transition(self.cur_state, i)
200201

201-
202-
def _make_transition(self, Q, i: PLInterpretation):
202+
@staticmethod
203+
def _make_transition(Q, i: PLInterpretation):
203204
actions_set = i.true_propositions
204205
new_macrostate = set()
205206

@@ -247,18 +248,16 @@ def _make_transition(self, Q, i: PLInterpretation):
247248

248249

249250
def to_automaton(f, labels:Set[Symbol]=None, minimize=True):
250-
dfaotf = DFAOTF(f)
251-
252251

253-
initial_state = frozenset({frozenset({dfaotf.f})})
252+
initial_state = frozenset({frozenset({f.to_nnf()})})
254253
states = {initial_state}
255254
final_states = set()
256255
transition_function = {}
257256

258257
# the alphabet is the powerset of the set of fluents
259258
alphabet = powerset(labels)
260259

261-
if dfaotf.is_true():
260+
if DFAOTF._is_true(initial_state):
262261
final_states.add(initial_state)
263262

264263
visited = set()
@@ -269,7 +268,7 @@ def to_automaton(f, labels:Set[Symbol]=None, minimize=True):
269268
for q in list(to_be_visited):
270269
to_be_visited.remove(q)
271270
for actions_set in alphabet:
272-
new_state = dfaotf._make_transition(q, PLInterpretation(actions_set))
271+
new_state = DFAOTF._make_transition(q, PLInterpretation(actions_set))
273272
if not new_state in states:
274273
states.add(new_state)
275274
to_be_visited.add(new_state)
@@ -278,7 +277,7 @@ def to_automaton(f, labels:Set[Symbol]=None, minimize=True):
278277

279278
if new_state not in visited:
280279
visited.add(new_state)
281-
if dfaotf._is_true(new_state): final_states.add(new_state)
280+
if DFAOTF._is_true(new_state): final_states.add(new_state)
282281

283282

284283
new_alphabet = PythomataAlphabet({PLInterpretation(set(sym)) for sym in alphabet})

flloat/parser/pl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def t_ATOM(self, t):
4444
return t
4545

4646

47-
# Yacc example
4847
class PLParser(Parser):
4948

5049
def __init__(self):

flloat/semantics/pl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import FrozenSet, Set
1+
from typing import FrozenSet, Set, List
22

33
from flloat.base.Interpretation import Interpretation
44
from flloat.base.Symbol import Symbol
@@ -49,6 +49,9 @@ def __call__(self, true_propositions:Set[Symbol]):
4949
f_sym = frozenset(true_propositions)
5050
return super().__call__(f_sym)
5151

52+
def fromStrings(self, strings:List[str]):
53+
return self(set(Symbol(s) for s in strings))
54+
5255

5356

5457
plinterpretation_factory = ObjFactory(_PLInterpretation)

flloat/syntax/ldlf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class RegExpTruth(Truth):
2222
@abstractmethod
23-
def truth(self, tr: FiniteTrace, start: int, end: int):
23+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
2424
raise NotImplementedError
2525

2626
class LDLfFormula(Formula, FiniteTraceTruth, NNF, Delta):
@@ -190,7 +190,7 @@ class LDLfEquivalence(EquivalenceDeltaConvertible, LDLfCommBinaryOperator):
190190
class LDLfDiamond(LDLfTemporalFormulaNNF, FiniteTraceTruth):
191191
temporal_brackets = "<>"
192192

193-
def truth(self, i: FiniteTrace, pos: int):
193+
def truth(self, i: FiniteTrace, pos: int=0):
194194
return any(self.r.truth(i, pos, j) and self.f.truth(i, j) for j in range(pos, i.last()+1))
195195
# last + 1 in order to include the last step
196196

@@ -204,7 +204,7 @@ class LDLfBox(ConvertibleFormula, LDLfTemporalFormulaNNF):
204204
def _convert(self):
205205
return LDLfNot(LDLfDiamond(self.r, LDLfNot(self.f)))
206206

207-
def truth(self, i: FiniteTrace, pos: int):
207+
def truth(self, i: FiniteTrace, pos: int=0):
208208
return self._convert().truth(i, pos)
209209

210210
def _delta(self, i:PLInterpretation, epsilon=False):
@@ -217,7 +217,7 @@ def __init__(self, pl_formula:PLFormula):
217217
RegExpFormula.__init__(self)
218218
self.pl_formula = pl_formula
219219

220-
def truth(self, tr: FiniteTrace, start: int, end: int):
220+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
221221
return end == start + 1 \
222222
and end <= tr.last() \
223223
and self.pl_formula.truth(tr.get(start))
@@ -265,7 +265,7 @@ class RegExpTest(UnaryOperator, RegExpFormula):
265265
# RegExpFormula.__init__(self)
266266
# UnaryOperator.__init__(self, f)
267267

268-
def truth(self, tr: FiniteTrace, start: int, end: int):
268+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
269269
return start == end and self.f.truth(tr, start)
270270

271271
def __str__(self):
@@ -294,7 +294,7 @@ def __init__(self, formulas):
294294
RegExpFormula.__init__(self)
295295
CommutativeBinaryOperator.__init__(self, formulas)
296296

297-
def truth(self, tr: FiniteTrace, start: int, end: int):
297+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
298298
return any(f.truth(tr, start, end) for f in self.formulas_set)
299299

300300
def _to_nnf(self):
@@ -313,7 +313,7 @@ def __init__(self, formulas: OperatorChilds):
313313
RegExpFormula.__init__(self)
314314
BinaryOperator.__init__(self, formulas)
315315

316-
def truth(self, tr: FiniteTrace, start: int, end: int):
316+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
317317
f1 = self.formulas[0]
318318
if len(self.formulas) == 2:
319319
f2 = self.formulas[1]
@@ -346,7 +346,7 @@ class RegExpStar(UnaryOperator, RegExpFormula):
346346
# UnaryOperator.__init__(self, f)
347347
# RegExpFormula.__init__(self)
348348

349-
def truth(self, tr: FiniteTrace, start: int, end: int):
349+
def truth(self, tr: FiniteTrace, start: int=0, end: int=0):
350350
return start == end \
351351
or any(self.f.truth(tr, start, k) and self.truth(tr, k, end)
352352
for k in range(start, end + 1))

flloat/syntax/ltlf.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import lru_cache
33
from typing import Set
44

5-
from flloat.base.Formula import Formula, CommutativeBinaryOperator, AtomicFormula, BinaryOperator
5+
from flloat.base.Formula import Formula, CommutativeBinaryOperator, AtomicFormula, BinaryOperator, UnaryOperator
66
from flloat.base.Symbol import Symbol
77
from flloat.base.Symbols import Symbols
88
from flloat.base.convertible import ImpliesDeltaConvertible, EquivalenceDeltaConvertible, ConvertibleFormula, \
@@ -20,7 +20,7 @@
2020

2121
class LTLfTruth(Truth):
2222
@abstractmethod
23-
def truth(self, i: FiniteTrace, pos: int):
23+
def truth(self, i: FiniteTrace, pos: int = 0):
2424
raise NotImplementedError
2525

2626

@@ -35,7 +35,7 @@ def delta(self, i: PLInterpretation, epsilon=False):
3535
# By definition, if epsilon=True, then the result must be either PLTrue or PLFalse
3636
# Now, the output is a Propositional Formula with only PLTrue or PLFalse as atomics
3737
# Hence, we just evaluate the formula with a dummy PLInterpretation
38-
d = PLTrue() if d.truth(PLFalseInterpretation()) else PLFalse()
38+
d = PLTrue() if d.truth(None) else PLFalse()
3939
return d
4040

4141
@abstractmethod
@@ -91,7 +91,7 @@ def _delta(self, i:PLInterpretation, epsilon=False):
9191
return PLFalse()
9292
return PLTrue() if self.a.truth(i) else PLFalse()
9393

94-
def truth(self, i: FiniteTrace, pos: int):
94+
def truth(self, i: FiniteTrace, pos: int=0):
9595
return self.a.truth(i.get(pos))
9696

9797
def find_labels(self):
@@ -171,7 +171,7 @@ class LTLfNext(DualUnaryOperatorNNF, LTLfTemporalFormula):
171171
operator_symbol = "X"
172172
Not = LTLfNot
173173

174-
def truth(self, i: FiniteTrace, pos: int):
174+
def truth(self, i: FiniteTrace, pos: int=0):
175175
return pos < i.last() and self.f.truth(i, pos + 1)
176176

177177
def _delta(self, i: PLInterpretation, epsilon=False):
@@ -191,7 +191,7 @@ class LTLfWeakNext(DualUnaryOperatorNNF, ConvertibleFormula, LTLfTemporalFormula
191191
def _convert(self):
192192
return LTLfNot(LTLfNext(LTLfNot(self.f)))
193193

194-
def truth(self, i: FiniteTrace, pos: int):
194+
def truth(self, i: FiniteTrace, pos: int=0):
195195
return self._convert().truth(i, pos)
196196

197197
def _delta(self, i: PLInterpretation, epsilon=False):
@@ -218,7 +218,7 @@ def _to_nnf(self):
218218
def negate(self):
219219
return LTLfRelease([LTLfNot(f) for f in self.formulas])
220220

221-
def truth(self, i: FiniteTrace, pos: int):
221+
def truth(self, i: FiniteTrace, pos: int=0):
222222
f1 = self.formulas[0]
223223
f2 = LTLfUntil(self.formulas[1:]) if len(self.formulas)>2 else self.formulas[1]
224224

@@ -246,36 +246,37 @@ def to_LDLf(self):
246246
return LDLfDiamond(RegExpStar(RegExpSequence([RegExpTest(f1), RegExpPropositional(PLTrue())])), LDLfAnd([f2, LDLfNot(LDLfEnd())]))
247247

248248

249-
class LTLfEventually(DualUnaryOperatorNNF, BaseConvertibleFormula, LTLfTemporalFormula):
249+
class LTLfEventually(UnaryOperator, DeltaConvertibleFormula, LTLfTemporalFormula):
250250
operator_symbol = "F"
251251
Not = LTLfNot
252252

253253
def _convert(self):
254254
return LTLfUntil([LTLfTrue(), self.f])
255255

256-
def _delta(self, i:PLInterpretation, epsilon=False):
257-
if epsilon:
258-
return PLFalse()
259-
else:
260-
return PLOr([self.f._delta(i, epsilon), LTLfNext(self)._delta(i, epsilon)])
256+
# def _delta(self, i:PLInterpretation, epsilon=False):
257+
# if epsilon:
258+
# return PLFalse()
259+
# else:
260+
# return PLOr([self.f._delta(i, epsilon), LTLfNext(self)._delta(i, epsilon)])
261+
261262

262263
def to_LDLf(self):
263264
# return self._convert().to_LDLf()
264265
return LDLfDiamond(RegExpStar(RegExpPropositional(PLTrue())), LDLfAnd([self.f.to_LDLf(), LDLfNot(LDLfEnd())]))
265266

266267

267-
class LTLfAlways(DualUnaryOperatorNNF, BaseConvertibleFormula, LTLfTemporalFormula):
268+
class LTLfAlways(UnaryOperator, DeltaConvertibleFormula, LTLfTemporalFormula):
268269
operator_symbol = "G"
269270
Not = LTLfNot
270271

271272
def _convert(self):
272-
return LTLfNot(LTLfEventually(LTLfNot(self.f)))
273+
return LTLfNot(LTLfEventually(LTLfNot(self.f))._convert())
273274

274-
def _delta(self, i:PLInterpretation, epsilon=False):
275-
if epsilon:
276-
return PLTrue()
277-
else:
278-
return PLAnd([self.f._delta(i, epsilon), LTLfWeakNext(self)._delta(i, epsilon)])
275+
# def _delta(self, i:PLInterpretation, epsilon=False):
276+
# if epsilon:
277+
# return PLTrue()
278+
# else:
279+
# return PLAnd([self.f._delta(i, epsilon), LTLfWeakNext(self)._delta(i, epsilon)])
279280

280281
def to_LDLf(self):
281282
return self._convert().to_LDLf()
@@ -313,10 +314,10 @@ def _members(self):
313314
return (self.s, )
314315

315316
def _convert(self):
316-
return LTLfAlways(LTLfFalse())
317+
return LTLfAlways(LTLfFalse()).to_nnf()
317318

318319
def negate(self):
319-
return LTLfEventually(LTLfTrue())
320+
return LTLfEventually(LTLfTrue()).to_nnf()
320321

321322
def __str__(self):
322323
return "_".join(map(str, self._members()))

flloat/syntax/pl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Set
44

55

6-
from flloat.base.Alphabet import _Alphabet
6+
from flloat.base.Alphabet import _Alphabet, Alphabet
77
from flloat.base.Formula import Formula, CommutativeBinaryOperator, BinaryOperator, AtomicFormula
88
from flloat.base.Symbol import Symbol
99
from flloat.base.Symbols import Symbols
@@ -19,7 +19,7 @@ class PLTruth(Truth):
1919
def truth(self, i: PLInterpretation, *args):
2020
raise NotImplementedError
2121

22-
class PLFormula(Formula, Truth, NNF):
22+
class PLFormula(Formula, PLTruth, NNF):
2323
def __init__(self):
2424
Formula.__init__(self)
2525

@@ -30,7 +30,7 @@ def __init__(self):
3030
def all_models(self, alphabet: _Alphabet) -> Set[PLInterpretation]:
3131
"""Find all the possible interpretations given a set of symbols"""
3232

33-
all_possible_interpretations = alphabet.powerset()
33+
all_possible_interpretations = alphabet.powerset().symbols
3434
all_models = set()
3535
for i in all_possible_interpretations:
3636
# compute current Interpretation, considering False
@@ -84,7 +84,6 @@ def _find_atomics(self):
8484
res.add(subf)
8585
return res
8686

87-
8887
class PLCommBinaryOperator(DualCommutativeOperatorNNF, PLFormula):
8988
# def __init__(self, formulas):
9089
# PLFormula.__init__(self)
@@ -157,10 +156,10 @@ def _find_atomics(self):
157156
return self.f.find_atomics()
158157

159158

160-
161159
class PLOr(PLCommBinaryOperator, OrTruth):
162160
pass
163161

162+
164163
class PLAnd(PLCommBinaryOperator, AndTruth):
165164
pass
166165

@@ -170,6 +169,7 @@ class PLImplies(PLBinaryOperator, ImpliesConvertible):
170169
Or = PLOr
171170
Not = PLNot
172171

172+
173173
class PLEquivalence(PLCommBinaryOperator, EquivalenceConvertible):
174174
And = PLAnd
175175
Or = PLOr

0 commit comments

Comments
 (0)