mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2024-11-08 21:20:33 -05:00
Small cleanup
This commit is contained in:
parent
f3c82f090f
commit
ff666c326e
3 changed files with 14 additions and 18 deletions
14
R.py
14
R.py
|
@ -117,13 +117,15 @@ interpretation = {
|
||||||
|
|
||||||
# Generate models of R of a given size
|
# Generate models of R of a given size
|
||||||
|
|
||||||
# model_size = 2
|
model_size = 2
|
||||||
# solutions = generate_model(R_logic, model_size, print_model=True)
|
solutions = generate_model(R_logic, model_size, print_model=True)
|
||||||
|
|
||||||
# print(f"There are {len(solutions)} satisfiable models of element length {model_size}")
|
print(f"There are {len(solutions)} satisfiable models of element length {model_size}")
|
||||||
|
|
||||||
# for model, interpretation in solutions:
|
for model, interpretation in solutions:
|
||||||
# print(has_vsp(model, interpretation))
|
print("Has VSP?", has_vsp(model, interpretation))
|
||||||
|
|
||||||
|
print("-" * 5)
|
||||||
|
|
||||||
######
|
######
|
||||||
|
|
||||||
|
@ -293,6 +295,8 @@ interpretation = {
|
||||||
Implication: mimplication
|
Implication: mimplication
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(R_model_6)
|
||||||
|
|
||||||
print("Satisfiable", satisfiable(R_logic, R_model_6, interpretation))
|
print("Satisfiable", satisfiable(R_logic, R_model_6, interpretation))
|
||||||
|
|
||||||
print("Has VSP?", has_vsp(R_model_6, interpretation))
|
print("Has VSP?", has_vsp(R_model_6, interpretation))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
File which generates all the models
|
File which generates all the models
|
||||||
"""
|
"""
|
||||||
from common import set_to_str
|
from common import set_to_str
|
||||||
from logic import Logic, Operation, Rule, get_operations_from_term, PropositionalVariable
|
from logic import Logic, Operation, Rule, get_operations_from_term
|
||||||
from model import ModelValue, Model, satisfiable, ModelFunction, ModelOrderConstraint
|
from model import ModelValue, Model, satisfiable, ModelFunction, ModelOrderConstraint
|
||||||
from itertools import combinations, chain, product
|
from itertools import combinations, chain, product
|
||||||
from typing import Set, List, Dict, Tuple
|
from typing import Set, List, Dict, Tuple
|
||||||
|
@ -15,8 +15,8 @@ def possible_designations(iterable):
|
||||||
def possible_functions(operation, carrier_set):
|
def possible_functions(operation, carrier_set):
|
||||||
arity = operation.arity
|
arity = operation.arity
|
||||||
|
|
||||||
inputs = list(product(*(carrier_set for _ in range(arity))))
|
inputs = list(product(carrier_set, repeat=arity))
|
||||||
possible_outputs = product(*(carrier_set for _ in range(len(inputs))))
|
possible_outputs = product(carrier_set, repeat=len(inputs))
|
||||||
for outputs in possible_outputs:
|
for outputs in possible_outputs:
|
||||||
assert len(inputs) == len(outputs)
|
assert len(inputs) == len(outputs)
|
||||||
new_function = dict()
|
new_function = dict()
|
||||||
|
|
12
model.py
12
model.py
|
@ -120,8 +120,7 @@ def all_model_valuations(
|
||||||
pvars: Tuple[PropositionalVariable],
|
pvars: Tuple[PropositionalVariable],
|
||||||
mvalues: Tuple[ModelValue]):
|
mvalues: Tuple[ModelValue]):
|
||||||
|
|
||||||
possible_valuations = [mvalues for _ in pvars]
|
all_possible_values = product(mvalues, repeat=len(pvars))
|
||||||
all_possible_values = product(*possible_valuations)
|
|
||||||
|
|
||||||
for valuation in all_possible_values:
|
for valuation in all_possible_values:
|
||||||
mapping: Dict[PropositionalVariable, ModelValue] = dict()
|
mapping: Dict[PropositionalVariable, ModelValue] = dict()
|
||||||
|
@ -207,7 +206,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction]):
|
||||||
for mfun in mfunctions:
|
for mfun in mfunctions:
|
||||||
# Get output for every possible input configuration
|
# Get output for every possible input configuration
|
||||||
# from last_set
|
# from last_set
|
||||||
for args in product(*(last_set for _ in range(mfun.arity))):
|
for args in product(last_set, repeat=mfun.arity):
|
||||||
current_set.add(mfun(*args))
|
current_set.add(mfun(*args))
|
||||||
|
|
||||||
return current_set
|
return current_set
|
||||||
|
@ -228,8 +227,6 @@ def has_vsp(model: Model, interpretation: Dict[Operation, ModelFunction]) -> boo
|
||||||
if impfunction(x, y) not in model.designated_values:
|
if impfunction(x, y) not in model.designated_values:
|
||||||
I.add((x, y))
|
I.add((x, y))
|
||||||
|
|
||||||
print("I", [(str(x), str(y)) for (x, y) in I])
|
|
||||||
|
|
||||||
# Construct the powerset without the empty set
|
# Construct the powerset without the empty set
|
||||||
s = list(I)
|
s = list(I)
|
||||||
I_power = chain.from_iterable(combinations(s, r) for r in range(1, len(s) + 1))
|
I_power = chain.from_iterable(combinations(s, r) for r in range(1, len(s) + 1))
|
||||||
|
@ -249,15 +246,10 @@ def has_vsp(model: Model, interpretation: Dict[Operation, ModelFunction]) -> boo
|
||||||
# If the carrier set intersects, then we violate VSP
|
# If the carrier set intersects, then we violate VSP
|
||||||
if len(carrier_set_left & carrier_set_right) > 0:
|
if len(carrier_set_left & carrier_set_right) > 0:
|
||||||
continue
|
continue
|
||||||
# print("FAIL: Carrier sets intersect")
|
|
||||||
# print(xys)
|
|
||||||
# return True
|
|
||||||
|
|
||||||
for (x2, y2) in product(carrier_set_left, carrier_set_right):
|
for (x2, y2) in product(carrier_set_left, carrier_set_right):
|
||||||
if impfunction(x2, y2) in model.designated_values:
|
if impfunction(x2, y2) in model.designated_values:
|
||||||
continue
|
continue
|
||||||
print(f"({x2}, {y2}) take on a designated value")
|
|
||||||
return True
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue