Ejemplo n.º 1
0
def get_smt_body(formula):
    #print '-----need to tans formula is:', formula
    formula = __logicSym_to_smtSym(formula)
    fluents = context_operator.get_fluents()
    fluent_sub = '|'.join([r"(?:(%s)\(([\w,\s]*)\))" % fun for fun in fluents])
    #print fluents
    fluent_sub_pattern = re.compile(fluent_sub)

    temp_formula = ""
    while temp_formula != formula:
        temp_formula = formula
        #formula = fluent_sub_pattern.sub(__mrepl_fluent, formula)
        formula = Util.repeat_replace_inner_with_pattern(
            fluent_sub_pattern, __mrepl_fluent, formula)
        #print "repl_fluent---",formula
        #formula = Util.repeat_replace_inner_with_pattern(most_inner_pattern, __mrepl_no_inner_formula, formula)
        formula = most_inner_pattern.sub(__mrepl_no_inner_formula, formula)
        #print "inner_pattern---",formula
        formula = Util.repeat_replace_inner_with_pattern(
            quantifier_pattern, __mrepl_quntifier, formula)
        #formula = quantifier_pattern.sub(__mrepl_quntifier, formula)
    formula = re.sub(r'.*', __mrepl_no_inner_formula, formula)

    repl_list = context_operator.get_replace_list()
    repl_list.reverse()
    #print repl_list
    formula = Util.repeat_do_function(Util.sub_lambda_exp, repl_list, formula)
    #print formula
    context_operator.clear_replace_list()
    return formula
Ejemplo n.º 2
0
def generate_sort_from_formula(formula):
    #logger.debug("get sort from formula:%s\n"%formula)
    #print "get sort from formula:%s\n"%formula
    formula = Util.repeat_replace_inner_with_pattern(Util.rename_pattern,
                                                     __mrepl_getsort_fol,
                                                     formula)
    __get_sort_from_qf_formula(formula)
Ejemplo n.º 3
0
def transform_entailment(formula):
    old_formula = ""
    while old_formula != formula:
        old_formula = formula
        formula = Util.repeat_replace_inner_with_pattern(
            quantifier_pattern, __mrepl_entailment_quantifier, old_formula)
    return Util.endecode_string(__eliminate_bracket(formula), encode_pair[1],
                                encode_pair[0])
Ejemplo n.º 4
0
def ____add_sort_forall(rule_list):
    for e, rule in enumerate(rule_list):
        new_formula = Util.repeat_replace_inner_with_pattern(
            addsort_pattern, ______mrepl_addsort_forall, rule[2])
        new_formula = Util.endecode_string(new_formula,
                                           Util.encode_pair_forall[1],
                                           Util.encode_pair_forall[0])
        rule_list[e] = (rule[0], rule[1], new_formula)
    return rule_list
Ejemplo n.º 5
0
def __eliminate_bracket(formula):
    old_formula = ""
    while old_formula != formula:
        old_formula = formula
        #print '1',formula
        formula = Util.repeat_replace_inner_with_pattern(
            most_inner_pattern, ____mrepl_entailment_inner, old_formula)
        #print '2',formula
    return ____eliminate_entailment(formula)
Ejemplo n.º 6
0
def __normalize_formula(formula):
	encoded_normal_str = Util.repeat_replace_inner_with_pattern(forall_pattern, __mrepl_handle_forall, formula)
	context_operator.use_local_dict() 
	encoded_normal_str = __normalize_fluents(encoded_normal_str)
	
	add_formula = __get_formula_from_local_dict()
	#add_formula = Util.endecode_string(add_formula, Util.encode_pair[1], Util.encode_pair[0])
	#--(***)---
	encoded_normal_str = add_formula+ "&( " + encoded_normal_str + ")}" if add_formula!="" else encoded_normal_str

	normal_str = Util.endecode_string(encoded_normal_str,encode_pair_forall[1],encode_pair_forall[0])
	return normal_str
Ejemplo n.º 7
0
def __normalize_fluents(encoded_str):
	encoded_str = " "+encoded_str+" " # in order to detect fun_pre and fun_pos (sometimes fails)
	new_encoded_str = encoded_str
	while True:
		if context_operator.get_nregx_function_patterns() ==list():
			break
		#for nreg_fluent_pattern in nreg_fluent_pattern_list:
		for nreg_fluent_pattern in context_operator.get_nregx_function_patterns():
			new_encoded_str = Util.repeat_replace_inner_with_pattern(nreg_fluent_pattern, __mrepl_detect_fluent, encoded_str)
			encoded_str = new_encoded_str
			#print '---',encoded_str 
		if new_encoded_str == encoded_str:
			new_encoded_str = re.sub(pattern.inner_parenth, __mrepl_encode, encoded_str)
			#print "replace () -> []", new_encoded_str
			if encoded_str == new_encoded_str:
				break
		encoded_str = new_encoded_str
	return Util.endecode_string(encoded_str, encode_pair[1], encode_pair[0]).strip()
Ejemplo n.º 8
0
def __get_sort_from_qf_formula(qf_formula):
    expressions = re.split(r'\&|\||\=\>', qf_formula)
    expressions = [
        Util.eliminate_unmatched(expression) for expression in expressions
    ]
    #logger.debug("get sort from expressions: %s"%expressions)
    #print("get sort from expressions: %s"%expressions)
    for expression in expressions:
        #logger.debug("get sort from expression: %s"%expression)
        #print("get sort from expression: %s"%expression)
        while True:
            expression = Util.repeat_replace_inner_with_pattern(
                inner_function_pattern, __mrepl_getsort_exp, expression)
            new_expression = re.sub(r"\((?P<exp>[^\(\)]*)\)", r"\g<exp>",
                                    expression)
            if new_expression == expression:
                break
            else:
                expression = new_expression
        sort_symbol_list, symbol_group = __get_sort_from_basic_expression(
            expression)
        #logger.debug("get sort from basic expression: %s result: %s %s"%(expression,sort_symbol_list,symbol_group))
        context_operator.add_symbol_to_sort_list(sort_symbol_list)
        context_operator.add_symbols_equal_list(symbol_group)
Ejemplo n.º 9
0
def grounding(formula, model):
    context_operator.set_current_model(model)
    return Util.repeat_replace_inner_with_pattern(grounding_pattern,
                                                  __mrepl_ground, formula)