Esempio n. 1
0
def expr_sub_dict(e,d):
    args = FOL_translation.expr_args(e)
    args1 = list(expr_sub_dict(x,d) for x in args)
    if FOL_translation.expr_op(e) in d:
        return expr_sub_var_list(d[FOL_translation.expr_op(e)],list(expres('_x'+str(i+1)) for i in range(len(args))),args1)
    else:
        return expres(FOL_translation.expr_op(e),args1)
Esempio n. 2
0
def getAllVarFun(e,map_fun,map_var):
    args=FOL_translation.expr_args(e)
    op=FOL_translation.expr_op(e)
    if len(args)==0:
        if op.startswith('_n')==True or op.startswith('_x')==True:
            map_var[op]=op
    else:
        if op=='and' or op=='or':
            
            if len(args)==1:
                getAllVarFun(args[0],map_fun,map_var)
            else:
                for x in args:
                    getAllVarFun(x,map_fun,map_var)
        elif op=='not' and len(args)==1:
            getAllVarFun(args[0],map_fun,map_var)
        elif op=='implies' and len(args)==2:
            getAllVarFun(args[0],map_fun,map_var)
            getAllVarFun(args[1],map_fun,map_var)
        elif op in _infix_op and len(args)==2:
            getAllVarFun(args[0],map_fun,map_var)
            getAllVarFun(args[1],map_fun,map_var)
        else:
            if op !='ite' and '__VERIFIER_' not in op:
                map_fun[op]=op
            for x in args:
                getAllVarFun(x,map_fun,map_var)
Esempio n. 3
0
def isFunctionPresent(e):
    args=FOL_translation.expr_args(e)
    op=FOL_translation.expr_op(e)
    if len(args)==0:
        if op.startswith('_n')==True or op.startswith('_x')==True:
            return None
    else:
        if op=='and' or op=='or':
            
            if len(args)==1:
                if isFunctionPresent(args[0])==True:
                    return True
            else:
                status=False
                for x in args:
                    if isFunctionPresent(x)==True:
                        return True
        elif op=='not' and len(args)==1:
            return isFunctionPresent(args[0])
        elif op=='implies' and len(args)==2:
             if isFunctionPresent(args[0])==True or isFunctionPresent(args[1])==True:
                 return True
        elif op in _infix_op and len(args)==2:
            if isFunctionPresent(args[0])==True or isFunctionPresent(args[1])==True:
                return True
        else:
            if op !='ite' :
                return True

    return None
Esempio n. 4
0
def expr_func(e,v): #e - expr
    ret = []
    f = FOL_translation.expr_op(e)
    if is_program_var(f,v) or '__VERIFIER_nondet' in f:
        ret.append(f)
    for e1 in FOL_translation.expr_args(e):
        ret = ret + expr_func(e1,v)
    return ret
Esempio n. 5
0
def expr2simplified(e,flag):
    args=FOL_translation.expr_args(e)
    op=FOL_translation.expr_op(e)
    if len(args)==0:
        return op,flag
    else:
	if op in _infix_op and len(args)==2:
	    expr1,flag=expr2simplified(args[0],flag)
	    if flag==True:
	    	expr2,flag=expr2simplified(args[1],flag)
	    	flag=True
	    else:
	    	expr2,flag=expr2simplified(args[1],flag)
	    if op=='*' and FOL_translation.expr_op(args[0])=='/':
	    	n,d=fraction(expr1)
	    	if gcd(d,expr2)!=1:
	    		flag=True
	    elif op=='/' and FOL_translation.expr_op(args[0])=='*':
	    	n,d=fraction(expr2)
	    	if gcd(expr1,d)!=1:
	    		flag=True
            if flag==True:
            	expression= '(' + expr1+ op + expr2 +')' 
            else:
            	expression= '((' + str(pow_to_mul(powsimp(expr1)))+ ')'+ op + '('+ str(pow_to_mul(powsimp(expr2)))+'))' 
            return expression,flag
        else:
            return op +'('+ ','.join(list(FOL_translation.trim_p(FOL_translation.expr2string1(x)) for x in args))+ ')',flag
Esempio n. 6
0
def expr2varlist(e,variable_list):
    args=FOL_translation.expr_args(e)    
    op=FOL_translation.expr_op(e)
    if len(args)==0:
    	if '_n' not in op and is_number(op)==False:
    		variable_list.append(op)
    else:
        if op=='and' or op=='or':
            if len(args)==1:
               expr2varlist(args[0],variable_list)
            else:
                for x in args:
                    expr2varlist(x,variable_list)
        elif op=='not' and len(args)==1:
            expr2varlist(args[0],variable_list)
        elif op=='implies' and len(args)==2:
        	expr2varlist(args[0],variable_list)
        	expr2varlist(args[1],variable_list)
        elif op in _infix_op and len(args)==2:
        	expr2varlist(args[0],variable_list)
        	expr2varlist(args[1],variable_list)
        else:
            for x in args:
        	expr2varlist(x,variable_list)
Esempio n. 7
0
def extend(e,n,excl,v):
    op = FOL_translation.expr_op(e)
    x = [n] if (is_program_var(op,v) and not (op in excl)) or '__VERIFIER_nondet' in op else []
    return expres(op, list(extend(e1,n,excl,v) for e1 in FOL_translation.expr_args(e)) + x)
Esempio n. 8
0
def expr_complement(e): #e,e1,e2: expres
    if e[:1]==['!']:
        return e[1:][0]
    elif e[:1]==['<']:
    	e[:1]=['>=']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['>']:
    	e[:1]=['<=']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['>=']:
        e[:1]=['<']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['<=']:
        e[:1]=['>']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['==']:
        e[:1]=['!=']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['!=']:
        e[:1]=['==']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['&&']:
        e[:1]=['||']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['||']:
        e[:1]=['&&']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['and']:
        e[:1]=['or']
        return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    elif e[:1]==['or']:
        e[:1]=['and']
    	return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
    else:
        return e[:1]+list(expr_complement(x) for x in FOL_translation.expr_args(e))
Esempio n. 9
0
def expr_replace(e,e1,e2): #e,e1,e2: expr
    if e==e1:
        return e2
    else:
        return e[:1]+list(expr_replace(x,e1,e2) for x in FOL_translation.expr_args(e))