Exemplo n.º 1
0
    def __init__(self, operations, after, **kwargs):
        DialogWindow.__init__(self, modal=True, close=True)
        self.formula = Formula([])
        self.after = after
        if "type" in kwargs:
            self.type = kwargs["type"]
        else:
            self.type = 'rel'

        self.set_styles()

        def op_button_click(op):
            def aio():
                self.add_op(op)

            return aio

        self.ops_with_buttons = [{
            "op": op,
            "button": Button(op.name, op_button_click(op))
        } for op in operations]

        for owb in self.ops_with_buttons:
            self.add_button(owb["button"])

        self.var = list()
        self.is_clicked = list()
        self.textbox = list()

        self.set_variables((0 if self.type == 'exp' else 5))
Exemplo n.º 2
0
def split_apply(formulas, after):
    if formulas[0].body[0] == IF:
        after(Formula(
            formulas[0].body[1:formulas[0].start_of_child(0, 2)]).negation(),
              type=ProofElement.SPLIT,
              second_formula=Formula(
                  formulas[0].body[formulas[0].start_of_child(0, 2):]).
              simplify(),
              rule_name=split.name)
    else:
        after(Formula(formulas[0].body[1:formulas[0].start_of_child(0, 2)]),
              type=ProofElement.SPLIT,
              second_formula=Formula(
                  formulas[0].body[formulas[0].start_of_child(0, 2):]).
              simplify(),
              rule_name=split.name)
Exemplo n.º 3
0
def deduction_is_applicable(formulas):
    if not check_number(formulas, 2):
        return False
    if len(formulas[0].body) > len(formulas[1].body):
        a = formulas[1]
        b = formulas[0]
    else:
        a = formulas[0]
        b = formulas[1]
    if b.body[0] not in [EQUI, OR, IF]:
        return False
    k = b.start_of_child(0, 2)
    if b.body[0] == EQUI:
        return a == Formula(b.body[1:k]) or \
               a.is_negation_of(Formula(b.body[1:k])) or \
               a == Formula(b.body[k:]) or \
               a.is_negation_of(Formula(b.body[k:]))
    if b.body[0] == OR:
        return a.is_negation_of(Formula(b.body[1:k])) or \
               a.is_negation_of(Formula(b.body[k:]))
    if b.body[0] == IF:
        return a == Formula(b.body[1:k]) or \
               a.is_negation_of(Formula(b.body[k:]))
Exemplo n.º 4
0
 def after1(f):
     self.after(theorem.formula.substitute_definition(
         Formula([theorem.operations[0]] + constants), f),
                predecessors=[],
                rule_name="insert")
Exemplo n.º 5
0
 def from_dict(dic):
     vars = [Operation(k, 0, dic["var_print_schemes"][k], k, Operation.VARIABLE) for k in dic["var_print_schemes"]]
     spec_ops = [Operation.from_dict(k) for k in dic["spec_ops"]]
     return Theorem(Formula.from_list(dic["formula"], Operation.get_globals() + vars + spec_ops),
                    dic["id"], dic["folder"], operations=spec_ops)
Exemplo n.º 6
0
class FormulaBuilder(DialogWindow):
    def __init__(self, operations, after, **kwargs):
        DialogWindow.__init__(self, modal=True, close=True)
        self.formula = Formula([])
        self.after = after
        if "type" in kwargs:
            self.type = kwargs["type"]
        else:
            self.type = 'rel'

        self.set_styles()

        def op_button_click(op):
            def aio():
                self.add_op(op)

            return aio

        self.ops_with_buttons = [{
            "op": op,
            "button": Button(op.name, op_button_click(op))
        } for op in operations]

        for owb in self.ops_with_buttons:
            self.add_button(owb["button"])

        self.var = list()
        self.is_clicked = list()
        self.textbox = list()

        self.set_variables((0 if self.type == 'exp' else 5))

    def set_variables(self, no_of_vars, x=True):
        def name(n):
            return "var" + str(n)

        def print_scheme(n):
            return ["\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon"][n]

        def button_click(n):
            def sopa():
                if not self.is_clicked[n]:
                    v = Operation(name(n), 0, self.textbox[n].getText(),
                                  name(n), Operation.VARIABLE)
                    self.var[n] = v
                    self.textbox[n].setEnabled(False)
                    self.is_clicked[n] = True
                self.add_op(self.var[n])

            return sopa

        for i in range(no_of_vars):
            h = HorizontalPanel()
            b = Button("variable", button_click(i))
            h.add(b)
            self.is_clicked.append(False)
            self.var.append(None)
            t = TextBox()
            self.textbox.append(t)
            t.setText(print_scheme(i))
            h.add(t)
            self.add_button(h)

    def set_styles(self):
        self.dock = DockPanel()
        self.dock.setSpacing(3)

        self.dock.setWidth("300")

        self.image = Image(
            latex_to_url(self.formula.fill_with_placeholders().to_latex()))
        self.dock.add(self.image, DockPanel.EAST)
        self.dock.setCellHorizontalAlignment(self.image,
                                             HasAlignment.ALIGN_TOP)

        self.backspaceButton_add()
        self.doneButton_add()

        self.dock.add(HTML(""), DockPanel.CENTER)
        left = 100
        top = 100

        self.setText("opkop")
        self.setPopupPosition(left, top)
        self.setStyleAttribute("background-color", "#ffffff")
        self.setStyleAttribute("color", "blue")
        self.setStyleAttribute("border-width", "5px")
        self.setStyleAttribute("border-style", "solid")

        self.setWidget(self.dock)

    def doneButton_add(self):
        def doneButton_click():
            self.hide()
            self.after(self.formula)

        self.doneButton = Button("Done", doneButton_click)
        self.doneButton.setEnabled(False)
        self.dock.add(self.doneButton, DockPanel.SOUTH)

    def backspaceButton_add(self):
        def backspaceButton_click():
            self.formula = Formula(self.formula.body[:-1])
            self.refresh()

        self.backspaceButton = Button("Backspace", backspaceButton_click)
        self.backspaceButton.setEnabled(False)
        self.dock.add(self.backspaceButton, DockPanel.SOUTH)

    def refresh(self):
        self.image.setUrl(
            latex_to_url(self.formula.fill_with_placeholders().to_latex()))
        self.doneButton.setEnabled(self.formula.is_closed())
        self.backspaceButton.setEnabled(len(self.formula.body) >= 0)

    def add_button(self, b):
        self.dock.add(b, DockPanel.NORTH)

    def add_op(self, op):
        if not self.formula.is_closed():
            self.formula.add_one_op(op, self.type)
            self.refresh()
Exemplo n.º 7
0
 def backspaceButton_click():
     self.formula = Formula(self.formula.body[:-1])
     self.refresh()
Exemplo n.º 8
0
            self.apply_rule(rules["exists"], [n], pok)
            self.hide_formulas([n])
            after()
        elif k[n].body[0] == FORALL:
            self.apply_rule(rules["gen"], [n], after)
        else:
            return


proof = Proof()

if __name__ == "__main__":
    A = Operation("var1", 0, "a", "a", Operation.VARIABLE)
    B = Operation("var2", 0, "b", "b", Operation.VARIABLE)
    C = Operation("var3", 0, "c", "c", Operation.VARIABLE)
    f = Formula([A])
    for i in range(1):
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([B]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([C]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(Formula([]), type=ProofElement.CONTRA, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([B]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2], rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(f, second_formula=Formula([C]), type=ProofElement.SPLIT, skao=123, predecessors=[1, 2],
                  rule_name="opj")
        proof.add(f, predecessors=[1, 2], rule_name="opj")
        proof.add(Formula([]), type=ProofElement.CONTRA, predecessors=[1, 2], rule_name="opj")

    # print([x.dump() for x in proof.get_formula_list()])
    # print([proof.body[proof.list_index_to_proof_index(i)].formula.dump() for i in range(4)])
Exemplo n.º 9
0
def and_second_apply(formulas, after):
    after(Formula(formulas[0].body[formulas[0].start_of_child(0, 2):]),
          rule_name=and_second.name)
Exemplo n.º 10
0
def and_first_apply(formulas, after):
    after(Formula(formulas[0].body[1:formulas[0].start_of_child(0, 2)]),
          rule_name=and_first.name)
Exemplo n.º 11
0
def exist_apply(formulas, after):
    const = Operation.get_new_expression(proof.get_operations(), 0)
    f = formulas[0]
    f = Formula(f.body[2:]).substitute(Formula([f.body[1]]), Formula([const]))
    after(f, rule_name=exist.name, additional_info=const)
Exemplo n.º 12
0
 def after1(formula):
     f = formulas[0]
     f = Formula(f.body[2:]).substitute(Formula([f.body[1]]), formula)
     after(f, rule_name=gen.name, additional_info=formula)
Exemplo n.º 13
0
def deduction_apply(formulas, after):
    if len(formulas[0].body) > len(formulas[1].body):
        a = formulas[1]
        b = formulas[0]
    else:
        a = formulas[0]
        b = formulas[1]
    k = b.start_of_child(0, 2)
    if b.body[0] == EQUI:
        if a == Formula(b.body[1:k]):
            f = Formula(b.body[k:])
        if a.is_negation_of(Formula(b.body[1:k])):
            f = Formula(b.body[k:]).negation()
        if a == Formula(b.body[k:]):
            f = Formula(b.body[1:k])
        if a.is_negation_of(Formula(b.body[k:])):
            f = Formula(b.body[1:k]).negation()
    if b.body[0] == OR:
        if a.is_negation_of(Formula(b.body[1:k])):
            f = Formula(b.body[k:])
        if a.is_negation_of(Formula(b.body[k:])):
            f = Formula(b.body[1:k])
    if b.body[0] == IF:
        if a == Formula(b.body[1:k]):
            f = Formula(b.body[k:])
        if a.is_negation_of(Formula(b.body[k:])):
            f = Formula(b.body[1:k]).negation()
    after(f, rule_name=deduction.name)
Exemplo n.º 14
0
def contra_apply(formulas, after):
    after(Formula([]), type=ProofElement.CONTRA, rule_name=contra.name)
Exemplo n.º 15
0
            f = Formula(b.body[k:])
        if a.is_negation_of(Formula(b.body[k:])):
            f = Formula(b.body[1:k])
    if b.body[0] == IF:
        if a == Formula(b.body[1:k]):
            f = Formula(b.body[k:])
        if a.is_negation_of(Formula(b.body[k:])):
            f = Formula(b.body[1:k]).negation()
    after(f, rule_name=deduction.name)


deduction.is_applicable = deduction_is_applicable
deduction.apply = deduction_apply

Rules = [
    gen, exist, and_first, and_second, split, contra, assumption, deduction
]

if __name__ == '__main__':
    A = Operation("var1", 0, "a", "a", Operation.VARIABLE)
    B = Operation("var2", 0, "b", "b", Operation.VARIABLE)
    fa = Formula([OR, A, B])
    g = Formula([B])

    def pok(p):
        print(p.dump())

    print(deduction_is_applicable([fa, g]))
    if deduction_is_applicable([fa, g]):
        deduction.apply([fa, g], pok)