Ejemplo n.º 1
0
def prove(qvq, queue):
	fitted = [double_fit(qvq, t) for t in initial_list]
	if any(fitted):
	    return True

	for t in initial_list:
		node = to_node(t, alphabet)
		(left, right), root = node.children, node.symbol.drawing
		if root == '⇒':
			if double_fit(qvq, right):
				heappush(queue, (scorer.score(left), left))
Ejemplo n.º 2
0
def play(logic, times):
    logic.theorems = [choice(logic.theorems)]  # We select one axiom at random

    for i in range(times):
        alphabet = get_logic_alphabet()
        theorem = logic.theorems[-1]
        fariables = get_fariables(to_node(theorem, alphabet))
        fariable = str(choice(fariables))
        formula = fariable
        while formula == fariable:
            formula = str(get_random_logic_formula())
        logic.run_rule('replace_fariable', theorem, fariable, formula)
def replace_fariable(game, theorem, fariable, formula):
    from tree.functions.to_node import to_node
    from tree.alphabets.logic   import get_logic_alphabet

    alphabet = get_logic_alphabet()

    if not theorem in game.theorems:
        return False

    far_as_node = to_node(fariable, alphabet)

    if not far_as_node:
        return False

    if not to_node(formula, alphabet):
        return False

    if not far_as_node.symbol.equals(alphabet['fariable']):
        return False

    return theorem.replace(fariable, formula)
Ejemplo n.º 4
0
def fit(t1, t2, values1, values2, double_fit):
    alphabet = get_logic_alphabet()
    t1 = to_node(t1, alphabet) if type(t1) == str else t1
    t2 = to_node(t2, alphabet) if type(t2) == str else t2
    root1, root2 = t1.symbol.drawing, t2.symbol.drawing

    if root1 == root2 and root1 != 'F':
        if len(t1.children) == 1:
            return fit(t1.children[0], t2.children[0], values1, values2,
                       double_fit)
        else:
            return fit(t1.children[0], t2.children[0], values1, values2, double_fit) \
               and fit(t1.children[1], t2.children[1], values1, values2, double_fit)
    elif root1 == 'F' and double_fit:
        values1.append((to_string(t1), to_string(t2)))
        return True
    elif root2 == 'F':
        values2.append((to_string(t2), to_string(t1)))
        return True
    else:
        return False
Ejemplo n.º 5
0
def play(logic, times = 1):
    alphabet = get_logic_alphabet()

    graph = {
        '⇒(F_0, ⇒(F_1, F_0))': [],
        '⇒(⇒(F_0, ⇒(F_1, F_2)), ⇒(⇒(F_0, F_1), ⇒(F_0, F_2)))': [],
        '⇒(⇒(¬(F_0), ¬(F_1)), ⇒(F_1, F_0))': []
    }

    for i in range(0, times):
        rule_name = choice(['replace_fariable', 'then'])

        if rule_name == 'then':
            for theorem in logic.theorems:
                first_len = len(logic.theorems)
                logic.run_rule(rule_name, theorem)
                # print('from then', logic.theorems[-1], '|||', theorem, first_len, len(logic.theorems))
                if first_len != len(logic.theorems):
                    if not logic.theorems[-1] in graph.keys():
                        graph[logic.theorems[-1]] = []

                    a = str(to_node(theorem, alphabet).children[0])
                    graph[logic.theorems[-1]] += [theorem, a]

        elif rule_name == 'replace_fariable':
            weights = get_weights_from_lens(logic.theorems)
            theorem = choice(logic.theorems, p=weights)
            fariables = get_fariables(to_node(theorem, alphabet))
            fariable = str(choice(fariables))
            formula = str(get_random_logic_formula())
            first_len = len(logic.theorems)
            logic.run_rule(rule_name, theorem, fariable, formula)
            # print('from replace', logic.theorems[-1], '|||', theorem, first_len, len(logic.theorems))
            if first_len != len(logic.theorems):
                if not logic.theorems[-1] in graph.keys():
                    graph[logic.theorems[-1]] = []
                graph[logic.theorems[-1]].append(theorem)

    return graph
def play(times = 1):
    alphabet = get_logic_alphabet()
    logic = Saver.load_game('logic')

    for i in range(0, times):
        rule_name = choice(['replace_fariable', 'then'])

        if rule_name == 'then':
            for theorem in logic.theorems:
                logic.run_rule(rule_name, theorem)
        elif rule_name == 'replace_fariable':
            weights = get_weights_from_lens(logic.theorems)
            theorem = choice(logic.theorems, p=weights)
            fariables = get_fariables(to_node(theorem, alphabet))
            fariable = str(choice(fariables))
            formula = str(get_random_logic_formula())
            logic.run_rule(rule_name, theorem, fariable, formula)

    Saver.save_game(logic, 'logic')
Ejemplo n.º 7
0
def then(game, string):
    from tree.functions.to_node import to_node
    from tree.alphabets.logic import get_logic_alphabet

    alphabet = get_logic_alphabet()
    node = to_node(string, alphabet)

    if not node.symbol.equals(alphabet['implies']):
        return False

    if not string in game.theorems:
        return False

    if len(node.children) < 2:
        return False

    if not str(node.children[0]) in game.theorems:
        return False

    return str(node.children[1])
Ejemplo n.º 8
0
 def to_logic_node(string):
     return to_node(string, alphabet)