def __init__(self): super().__init__('slia') self.lia_instantiator = semantics_lia.LIAInstantiator() self.function_types = { 'str.++': (exprtypes.StringType(), exprtypes.StringType()), 'str.replace': (exprtypes.StringType(), exprtypes.StringType(), exprtypes.StringType()), 'str.at': (exprtypes.StringType(), exprtypes.IntType()), 'int.to.str': (exprtypes.IntType(), ), 'str.substr': (exprtypes.StringType(), exprtypes.IntType(), exprtypes.IntType()), 'str.len': (exprtypes.StringType(), ), 'str.to.int': (exprtypes.StringType(), ), 'str.indexof': (exprtypes.StringType(), exprtypes.StringType(), exprtypes.IntType()), 'str.prefixof': (exprtypes.StringType(), exprtypes.StringType()), 'str.suffixof': (exprtypes.StringType(), exprtypes.StringType()), 'str.contains': (exprtypes.StringType(), exprtypes.StringType()) } self.function_instances = { 'str.++': StrConcat(), 'str.replace': StrReplace(), 'str.at': StrAt(), 'int.to.str': IntToStr(), 'str.substr': Substr(), 'str.len': StrLen(), 'str.to.int': StrToInt(), 'str.indexof': StrIndexOf(), 'str.prefixof': StrPrefixOf(), 'str.suffixof': StrSuffixOf(), 'str.contains': StrContains() }
def test_cnf_conversion(): from core import synthesis_context from semantics import semantics_core from semantics import semantics_lia syn_ctx = synthesis_context.SynthesisContext( semantics_core.CoreInstantiator(), semantics_lia.LIAInstantiator()) var_exprs = [ syn_ctx.make_variable_expr(exprtypes.IntType(), 'x%d' % i) for i in range(10) ] max_fun = syn_ctx.make_synth_function('max', [exprtypes.IntType()] * 10, exprtypes.IntType()) max_app = syn_ctx.make_function_expr(max_fun, *var_exprs) max_ge_vars = [ syn_ctx.make_function_expr('ge', max_app, var_expr) for var_expr in var_exprs ] max_eq_vars = [ syn_ctx.make_function_expr('eq', max_app, var_expr) for var_expr in var_exprs ] formula1 = syn_ctx.make_ac_function_expr('or', *max_eq_vars) formula2 = syn_ctx.make_ac_function_expr('and', *max_ge_vars) formula = syn_ctx.make_ac_function_expr('and', formula1, formula2) cnf_converter = CNFConverter() cnf_clauses, cnf_expr = cnf_converter.apply(formula, syn_ctx) # print(exprs.expression_to_string(cnf_expr)) # print([exprs.expression_to_string(cnf_clause) for cnf_clause in cnf_clauses]) # print(check_single_invocation_property(formula, syn_ctx)) binary_max = syn_ctx.make_synth_function( 'max2', [exprtypes.IntType(), exprtypes.IntType()], exprtypes.IntType()) binary_max_app = syn_ctx.make_function_expr(binary_max, var_exprs[0], var_exprs[1]) binary_max_app_rev = syn_ctx.make_function_expr(binary_max, var_exprs[1], var_exprs[0]) # non_separable = syn_ctx.make_function_expr('eq', binary_max_app, binary_max_app_rev) # print(check_single_invocation_property(non_separable, syn_ctx)) # max_rec = syn_ctx.make_function_expr(binary_max, binary_max_app, binary_max_app) # non_separable2 = syn_ctx.make_function_expr('eq', max_rec, binary_max_app) # print(check_single_invocation_property(non_separable2, syn_ctx)) canonicalize_specification(formula, syn_ctx) separable1 = syn_ctx.make_function_expr('ge', binary_max_app, var_exprs[0]) separable2 = syn_ctx.make_function_expr('ge', binary_max_app_rev, var_exprs[0]) separable3 = syn_ctx.make_ac_function_expr( 'or', syn_ctx.make_function_expr('eq', binary_max_app, var_exprs[0]), syn_ctx.make_function_expr('eq', binary_max_app, var_exprs[1])) separable = syn_ctx.make_ac_function_expr('and', separable1, separable2, separable3) # print(check_single_invocation_property(separable, syn_ctx)) canonicalize_specification(separable, syn_ctx)
def get_theory_instantiator(theory): if theory == "LIA": return semantics_lia.LIAInstantiator() elif theory == "BV": return semantics_bv.BVInstantiator() elif theory == "SLIA": return semantics_slia.SLIAInstantiator() else: raise Exception("Unknown theory")
def _generate_test_generators(): from core import synthesis_context from semantics import semantics_core from semantics import semantics_lia syn_ctx = synthesis_context.SynthesisContext( semantics_core.CoreInstantiator(), semantics_lia.LIAInstantiator()) var_a_info = syn_ctx.make_variable(exprtypes.IntType(), 'varA', 0) var_b_info = syn_ctx.make_variable(exprtypes.IntType(), 'varB', 1) var_c_info = syn_ctx.make_variable(exprtypes.IntType(), 'varC', 2) var_a = exprs.VariableExpression(var_a_info) var_b = exprs.VariableExpression(var_b_info) var_c = exprs.VariableExpression(var_c_info) zero_value = exprs.Value(0, exprtypes.IntType()) one_value = exprs.Value(1, exprtypes.IntType()) zero_exp = exprs.ConstantExpression(zero_value) one_exp = exprs.ConstantExpression(one_value) var_generator = LeafGenerator([var_a, var_b, var_c], 'Variable Generator') const_generator = LeafGenerator([zero_exp, one_exp], 'Constant Generator') leaf_generator = AlternativesGenerator([var_generator, const_generator], 'Leaf Term Generator') generator_factory = RecursiveGeneratorFactory() start_generator_ph = generator_factory.make_placeholder('Start') start_bool_generator_ph = generator_factory.make_placeholder('StartBool') add_fun = syn_ctx.make_function('add', exprtypes.IntType(), exprtypes.IntType()) sub_fun = syn_ctx.make_function('sub', exprtypes.IntType(), exprtypes.IntType()) ite_fun = syn_ctx.make_function('ite', exprtypes.BoolType(), exprtypes.IntType(), exprtypes.IntType()) and_fun = syn_ctx.make_function('and', exprtypes.BoolType(), exprtypes.BoolType()) or_fun = syn_ctx.make_function('or', exprtypes.BoolType(), exprtypes.BoolType()) not_fun = syn_ctx.make_function('not', exprtypes.BoolType()) le_fun = syn_ctx.make_function('le', exprtypes.IntType(), exprtypes.IntType()) ge_fun = syn_ctx.make_function('ge', exprtypes.IntType(), exprtypes.IntType()) eq_fun = syn_ctx.make_function('eq', exprtypes.IntType(), exprtypes.IntType()) start_generator = \ generator_factory.make_generator('Start', AlternativesGenerator, ([leaf_generator] + [FunctionalGenerator(add_fun, [start_generator_ph, start_generator_ph]), FunctionalGenerator(sub_fun, [start_generator_ph, start_generator_ph]), FunctionalGenerator(ite_fun, [start_bool_generator_ph, start_generator_ph, start_generator_ph])],)) generator_factory.make_generator('StartBool', AlternativesGenerator, ([ FunctionalGenerator( and_fun, [start_bool_generator_ph, start_bool_generator_ph]), FunctionalGenerator( or_fun, [start_bool_generator_ph, start_bool_generator_ph]), FunctionalGenerator(not_fun, [start_bool_generator_ph]), FunctionalGenerator(le_fun, [start_generator_ph, start_generator_ph]), FunctionalGenerator(eq_fun, [start_generator_ph, start_generator_ph]), FunctionalGenerator(ge_fun, [start_generator_ph, start_generator_ph]) ], )) return start_generator