Small cleanup

This commit is contained in:
Brandon Rozek 2024-05-04 16:51:49 -04:00
parent f3c82f090f
commit ff666c326e
No known key found for this signature in database
GPG key ID: 26E457DA82C9F480
3 changed files with 14 additions and 18 deletions

14
R.py
View file

@ -117,13 +117,15 @@ interpretation = {
# Generate models of R of a given size
# model_size = 2
# solutions = generate_model(R_logic, model_size, print_model=True)
model_size = 2
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:
# print(has_vsp(model, interpretation))
for model, interpretation in solutions:
print("Has VSP?", has_vsp(model, interpretation))
print("-" * 5)
######
@ -293,6 +295,8 @@ interpretation = {
Implication: mimplication
}
print(R_model_6)
print("Satisfiable", satisfiable(R_logic, R_model_6, interpretation))
print("Has VSP?", has_vsp(R_model_6, interpretation))

View file

@ -2,7 +2,7 @@
File which generates all the models
"""
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 itertools import combinations, chain, product
from typing import Set, List, Dict, Tuple
@ -15,8 +15,8 @@ def possible_designations(iterable):
def possible_functions(operation, carrier_set):
arity = operation.arity
inputs = list(product(*(carrier_set for _ in range(arity))))
possible_outputs = product(*(carrier_set for _ in range(len(inputs))))
inputs = list(product(carrier_set, repeat=arity))
possible_outputs = product(carrier_set, repeat=len(inputs))
for outputs in possible_outputs:
assert len(inputs) == len(outputs)
new_function = dict()

View file

@ -120,8 +120,7 @@ def all_model_valuations(
pvars: Tuple[PropositionalVariable],
mvalues: Tuple[ModelValue]):
possible_valuations = [mvalues for _ in pvars]
all_possible_values = product(*possible_valuations)
all_possible_values = product(mvalues, repeat=len(pvars))
for valuation in all_possible_values:
mapping: Dict[PropositionalVariable, ModelValue] = dict()
@ -207,7 +206,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction]):
for mfun in mfunctions:
# Get output for every possible input configuration
# 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))
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:
I.add((x, y))
print("I", [(str(x), str(y)) for (x, y) in I])
# Construct the powerset without the empty set
s = list(I)
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 len(carrier_set_left & carrier_set_right) > 0:
continue
# print("FAIL: Carrier sets intersect")
# print(xys)
# return True
for (x2, y2) in product(carrier_set_left, carrier_set_right):
if impfunction(x2, y2) in model.designated_values:
continue
print(f"({x2}, {y2}) take on a designated value")
return True
return True