mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2024-11-26 22:23:58 -05:00
Only Discard Subalgebras with T in Right or B in Left
This commit is contained in:
commit
6317dc054f
2 changed files with 17 additions and 27 deletions
26
model.py
26
model.py
|
@ -219,7 +219,7 @@ def satisfiable(logic: Logic, model: Model, interpretation: Dict[Operation, Mode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction], top: Optional[ModelValue], bottom: Optional[ModelValue]) -> Set[ModelValue]:
|
def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction], forbidden_element: Optional[ModelValue]) -> Set[ModelValue]:
|
||||||
"""
|
"""
|
||||||
Given an initial set of model values and a set of model functions,
|
Given an initial set of model values and a set of model functions,
|
||||||
compute the complete set of model values that are closed
|
compute the complete set of model values that are closed
|
||||||
|
@ -230,7 +230,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction],
|
||||||
closure_set: Set[ModelValue] = initial_set
|
closure_set: Set[ModelValue] = initial_set
|
||||||
last_new: Set[ModelValue] = initial_set
|
last_new: Set[ModelValue] = initial_set
|
||||||
changed: bool = True
|
changed: bool = True
|
||||||
topbottom_found = False
|
forbidden_found = False
|
||||||
|
|
||||||
while changed:
|
while changed:
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -256,14 +256,11 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction],
|
||||||
|
|
||||||
# Optimization: Break out of computation
|
# Optimization: Break out of computation
|
||||||
# early when top or bottom element is foun
|
# early when top or bottom element is foun
|
||||||
if top is not None and element == top:
|
if forbidden_element is not None and element == forbidden_element:
|
||||||
topbottom_found = True
|
forbidden_found = True
|
||||||
if bottom is not None and element == bottom:
|
|
||||||
topbottom_found = True
|
|
||||||
if topbottom_found:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if topbottom_found:
|
if forbidden_found:
|
||||||
break
|
break
|
||||||
|
|
||||||
# We don't need to compute the arguments
|
# We don't need to compute the arguments
|
||||||
|
@ -291,17 +288,14 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction],
|
||||||
|
|
||||||
# Optimization: Break out of computation
|
# Optimization: Break out of computation
|
||||||
# early when top or bottom element is foun
|
# early when top or bottom element is foun
|
||||||
if top is not None and element == top:
|
if forbidden_element is not None and element == forbidden_element:
|
||||||
topbottom_found = True
|
forbidden_found = True
|
||||||
if bottom is not None and element == bottom:
|
|
||||||
topbottom_found = True
|
|
||||||
if topbottom_found:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if topbottom_found:
|
if forbidden_found:
|
||||||
break
|
break
|
||||||
|
|
||||||
if topbottom_found:
|
if forbidden_found:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,7 +303,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction],
|
||||||
changed = len(new_elements) > 0
|
changed = len(new_elements) > 0
|
||||||
last_new = new_elements
|
last_new = new_elements
|
||||||
|
|
||||||
if topbottom_found:
|
if forbidden_found:
|
||||||
break
|
break
|
||||||
|
|
||||||
return closure_set
|
return closure_set
|
||||||
|
|
18
vsp.py
18
vsp.py
|
@ -145,30 +145,28 @@ def has_vsp(model: Model, interpretation: Dict[Operation, ModelFunction]) -> VSP
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# NOTE: Optimization
|
# NOTE: Optimization
|
||||||
# if either subalgebra contains top or bottom, move
|
# If the left subalgebra contains bottom
|
||||||
# onto the next pair
|
# or the right subalgebra contains top
|
||||||
if top is not None and (top in xs or top in ys):
|
# skip this pair
|
||||||
|
if top is not None and top in ys:
|
||||||
continue
|
continue
|
||||||
if bottom is not None and (bottom in xs or bottom in ys):
|
if bottom is not None and bottom in xs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Compute the closure of all operations
|
# Compute the closure of all operations
|
||||||
# with just the xs
|
# with just the xs
|
||||||
carrier_set_left: Set[ModelValue] = model_closure(xs, model.logical_operations, top, bottom)
|
carrier_set_left: Set[ModelValue] = model_closure(xs, model.logical_operations, bottom)
|
||||||
|
|
||||||
# Save to cache
|
# Save to cache
|
||||||
if cached_xs[0] is not None and not cached_ys[1]:
|
if cached_xs[0] is not None and not cached_ys[1]:
|
||||||
closure_cache.append((orig_xs, carrier_set_left))
|
closure_cache.append((orig_xs, carrier_set_left))
|
||||||
|
|
||||||
if top is not None and top in carrier_set_left:
|
|
||||||
continue
|
|
||||||
if bottom is not None and bottom in carrier_set_left:
|
if bottom is not None and bottom in carrier_set_left:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# Compute the closure of all operations
|
# Compute the closure of all operations
|
||||||
# with just the ys
|
# with just the ys
|
||||||
carrier_set_right: Set[ModelValue] = model_closure(ys, model.logical_operations, top, bottom)
|
carrier_set_right: Set[ModelValue] = model_closure(ys, model.logical_operations, top)
|
||||||
|
|
||||||
# Save to cache
|
# Save to cache
|
||||||
if cached_ys[0] is not None and not cached_ys[1]:
|
if cached_ys[0] is not None and not cached_ys[1]:
|
||||||
|
@ -176,8 +174,6 @@ def has_vsp(model: Model, interpretation: Dict[Operation, ModelFunction]) -> VSP
|
||||||
|
|
||||||
if top is not None and top in carrier_set_right:
|
if top is not None and top in carrier_set_right:
|
||||||
continue
|
continue
|
||||||
if bottom is not None and bottom in carrier_set_right:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# If the carrier set intersects, then move on to the next
|
# If the carrier set intersects, then move on to the next
|
||||||
# subalgebra
|
# subalgebra
|
||||||
|
|
Loading…
Reference in a new issue