factor out boolean ops
This commit is contained in:
parent
eecb2d409a
commit
5fc2145622
1 changed files with 12 additions and 10 deletions
|
|
@ -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):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue