def checkMathPredicates(name, atom, subst = None): args = get_args(atom) if is_variable(args[0]) or is_variable(args[1]): return False a = get_value(args[0]) b = get_value(args[1]) if name == 'isBigger': return a >= b elif name == 'isSmaller': return a < b elif name == 'equal': return a == b elif name == 'sum': if is_constant(args[2]) and (a + b == get_value(args[2])): return True elif is_variable(args[2]): subst[get_name(args[2])] = make_const(a + b) return True elif name == 'dif': if is_constant(args[2]) and (a - b == get_value(args[2])): return True elif is_variable(args[2]): subst[get_name(args[2])] = make_const(a - b) return True return False
def checkMathPredicates(name, atom): args = get_args(atom) if is_variable(args[0]) or is_variable(args[1]): return False a = get_value(args[0]) b = get_value(args[1]) if name == 'isBigger': return a >= b elif name == 'equal': return a == b elif name == 'sum': if is_constant(args[2]) and (a + b == get_value(args[2])): return True elif is_variable(args[2]): args[2] = substitute(args[2], {get_name(args[2]): make_const(a + b)}) return True elif name == 'dif': if is_constant(args[2]) and (a - b == get_value(args[2])): return True elif is_variable(args[2]): args[2] = substitute(args[2], {get_name(args[2]): make_const(a - b)}) return True return False
def equal_terms(t1, t2): if is_constant(t1) and is_constant(t2): return get_value(t1) == get_value(t2) if is_variable(t1) and is_variable(t2): return get_name(t1) == get_name(t2) if is_function_call(t1) and is_function(t2): if get_head(t1) != get_head(t2): return all([equal_terms(get_args(t1)[i], get_args(t2)[i]) for i in range(len(get_args(t1)))]) return False