From ff666c326e2e0dc9b2c859e7abd50b594647249d Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Sat, 4 May 2024 16:51:49 -0400 Subject: [PATCH] Small cleanup --- R.py | 14 +++++++++----- generate_model.py | 6 +++--- model.py | 12 ++---------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/R.py b/R.py index 0e565bf..fcd6d4a 100644 --- a/R.py +++ b/R.py @@ -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)) diff --git a/generate_model.py b/generate_model.py index 88b9bc9..2048b6e 100644 --- a/generate_model.py +++ b/generate_model.py @@ -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() diff --git a/model.py b/model.py index 10c69fb..43cd83a 100644 --- a/model.py +++ b/model.py @@ -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