factor out boolean ops

This commit is contained in:
Marcell Vazquez-Chanlatte 2016-12-09 11:07:23 -08:00
parent eecb2d409a
commit 5fc2145622

View file

@ -1,4 +1,6 @@
from functools import singledispatch from functools import singledispatch
from operator import and_, or_
from bitarray import bitarray from bitarray import bitarray
import stl.ast import stl.ast
@ -8,25 +10,25 @@ from stl.boolean_eval import eval_terms, op_lookup
def pointwise_satf(stl): def pointwise_satf(stl):
raise NotImplementedError raise NotImplementedError
def bool_op(stl, conjunction=False):
@pointwise_satf.register(stl.Or) f = and_ if conjunction else or_
def _(stl):
def sat_comp(x,t): def sat_comp(x,t):
sat = bitarray(len(t)) sat = bitarray(len(t))
for arg in stl.args: for arg in stl.args:
sat = pointwise_satf(arg)(x, t) | sat sat = f(pointwise_satf(arg)(x, t), sat)
return sat return sat
return sat_comp return sat_comp
@pointwise_satf.register(stl.Or)
def _(stl):
return bool_op(stl, conjunction=False)
@pointwise_satf.register(stl.And) @pointwise_satf.register(stl.And)
def _(stl): def _(stl):
def sat_comp(x,t): return bool_op(stl, conjunction=True)
sat = ~bitarray(len(t))
for arg in stl.args:
sat = ~(~pointwise_satf(arg)(x, t) | ~sat)
return sat
return sat_comp
def temporal_op(stl, lo, hi, conjunction=False): def temporal_op(stl, lo, hi, conjunction=False):