def autodetect_transitive(self):
        import logic as lg
        from ivy_logic_utils import Clauses
        from ivy_solver import clauses_imply
        from concept import Concept

        #        self.edge_display_checkboxes['=']['transitive'].value = True
        #        self.edge_display_checkboxes['=']['all_to_all'].value = True

        self.transitive_relations = []
        self.transitive_relation_concepts = []

        axioms = im.module.background_theory()
        for c in il.all_symbols():
            if (type(c.sort) is lg.FunctionSort and c.sort.arity == 2
                    and c.sort.domain[0] == c.sort.domain[1]
                    and c.sort.range == lg.Boolean):
                X = lg.Var('X', c.sort.domain[0])
                Y = lg.Var('Y', c.sort.domain[0])
                Z = lg.Var('Z', c.sort.domain[0])
                transitive = lg.ForAll([X, Y, Z],
                                       lg.Or(lg.Not(c(X, Y)), lg.Not(c(Y, Z)),
                                             c(X, Z)))
                defined_symmetry = lg.ForAll([X, Y],
                                             lg.Or(c(X, X), lg.Not(c(Y, Y))))
                t = Clauses([transitive, defined_symmetry])
                if clauses_imply(axioms, t):
                    self.transitive_relations.append(c.name)
                    concept = self.current_concept_graph.g.formula_to_concept(
                        c(X, Y))
                    self.transitive_relation_concepts.append(concept)
                    self.current_concept_graph.show_relation(concept, 'T')
        if self.transitive_relations:
            self.current_concept_graph.update()
Пример #2
0
    def autodetect_transitive(self):
        import logic as lg
        from ivy_logic_utils import Clauses
        from ivy_solver import clauses_imply
        from concept import Concept

#        self.edge_display_checkboxes['=']['transitive'].value = True
#        self.edge_display_checkboxes['=']['all_to_all'].value = True

        self.transitive_relations = []
        self.transitive_relation_concepts = []

                    
        axioms = im.module.background_theory()
        for c in il.all_symbols():
            if (type(c.sort) is lg.FunctionSort and
                c.sort.arity == 2 and
                c.sort.domain[0] == c.sort.domain[1] and
                c.sort.range == lg.Boolean):
                X = lg.Var('X', c.sort.domain[0])
                Y = lg.Var('Y', c.sort.domain[0])
                Z = lg.Var('Z', c.sort.domain[0])
                transitive = lg.ForAll([X, Y, Z], lg.Or(lg.Not(c(X,Y)), lg.Not(c(Y,Z)), c(X,Z)))
                defined_symmetry = lg.ForAll([X, Y], lg.Or(c(X,X), lg.Not(c(Y,Y))))
                t = Clauses([transitive, defined_symmetry])
                if clauses_imply(axioms, t):
                    self.transitive_relations.append(c.name)
                    concept = self.current_concept_graph.g.formula_to_concept(c(X,Y))
                    self.transitive_relation_concepts.append(concept)
                    self.current_concept_graph.show_relation(concept,'T')
        if self.transitive_relations:
            self.current_concept_graph.update()
Пример #3
0
def main():
    with im.Module():
        ivy_init.ivy_init(create_isolate=False)
        emit(preamble)
        for sym in il.all_symbols():
            emit_symbol_def(sym)
        emit('def P := (PL.prog.letrec')
        emit_eol()
        for name, act in im.module.actions.iteritems():
            emit('  (@bndng.cons PL.pterm ("' + name + '",\n')
            emit_action(act)
            emit_eol()
            emit('    ) ')
            emit_eol()
        emit('  (bndng.default PL.pterm.skip)')
        for name, act in im.module.actions.iteritems():
            emit(')')
        emit_eol()
        exports = sorted(list(im.module.public_actions))
        if len(exports) == 0:
            emit('PL.pterm.skip')
        else:
            emit('((' + ' + '.join('(PL.pterm.call "' + x + '")'
                                   for x in exports) + ')**))')
        emit(postamble)
        basename = im.module.name
        f = open(basename + '.lean', 'w')
        f.write("".join(things))
        f.close()
Пример #4
0
 def state_changed(self,recomp=True):
     cs = self.concept_session
     cs.cache.clear()
     vocab = list(ilu.used_symbols_asts([c.formula for c in self.nodes]))
     fsyms = list(s for s in ilu.used_symbols_ast(cs._to_formula()) if not s.is_skolem())
     vocab += list(all_symbols()) + fsyms
     cs.domain = replace_concept_domain_vocabulary(cs.domain,set(vocab))
     for concept in self.new_relations:
         add_domain_concept(self.concept_domain.concepts,concept)
     if recomp:
         self.recompute()
Пример #5
0
 def state_changed(self, recomp=True):
     cs = self.concept_session
     cs.cache.clear()
     vocab = list(ilu.used_symbols_asts([c.formula for c in self.nodes]))
     fsyms = list(s for s in ilu.used_symbols_ast(cs._to_formula())
                  if not s.is_skolem())
     vocab += list(all_symbols()) + fsyms
     cs.domain = replace_concept_domain_vocabulary(cs.domain, set(vocab))
     for concept in self.new_relations:
         add_domain_concept(self.concept_domain.concepts, concept)
     if recomp:
         self.recompute()
Пример #6
0
def get_sort_arcs(assumes, asserts):
    for sym in il.all_symbols():
        name = sym.name
        sort = sym.sort
        rng = sort.rng
        if il.is_uninterpreted_sort(rng):
            for ds in sort.dom:
                if il.is_uninterpreted_sort(ds):
                    yield (ds, rng, sym)

    for fmla, ast in assumes + asserts:
        for a in get_qa_arcs(fmla, ast, True, list(lu.free_variables(fmla))):
            yield a

    for fmla, ast in asserts:
        for a in get_qa_arcs(fmla, ast, False, []):
            yield a
Пример #7
0
def get_sort_arcs(assumes, asserts):
    for sym in il.all_symbols():
        name = sym.name
        sort = sym.sort
        rng = sort.rng
        if il.is_uninterpreted_sort(rng):
            for ds in sort.dom:
                if il.is_uninterpreted_sort(ds):
                    yield (ds, rng, sym)

    for fmla, ast in assumes + asserts:
        for a in get_qa_arcs(fmla, ast, True, list(lu.free_variables(fmla))):
            yield a

    for fmla, ast in asserts:
        for a in get_qa_arcs(fmla, ast, False, []):
            yield a
Пример #8
0
def initial_concept_domain(sorts):

    concepts = OrderedDict()

    concepts['nodes'] = []
    concepts['node_labels'] = []
    concepts['edges'] = []

    # add the requested nodes
    for sort in sorts:
        X = Variable('X', sort)
        add_domain_concept(concepts,Equals(X,X),name=sort.name,kind='nodes')

    # add equality concept
    if False:
        X = Variable('X', TopSort())
        Y = Variable('Y', TopSort())
        concepts['='] = co.Concept([X, Y], Equals(X, Y))

    # add concepts from the signature
    for c in sorted(all_symbols(),key=str):

        dom,rng = c.sort.dom,c.sort.rng

        if il.is_enumerated_sort(rng):
            # TODO: we have no way to display enumerated constants
            if len(dom) in [1,2]:
                for cons in rng.constructors:
                    vs = [Variable(n,s) for n,s in zip(['X','Y'],dom)]
                    add_domain_concept(concepts,Equals(c(*vs),cons))

        elif il.is_boolean_sort(rng):
            # TODO: we have no way to display boolean constants
            if len(dom) in [1,2]:
                vs = [Variable(n,s) for n,s in zip(['X','Y'],dom)]
                add_domain_concept(concepts,c(*vs))

        elif il.is_first_order_sort(rng):
            if len(dom) == 0:
                add_domain_concept(concepts,Equals(Variable('X', rng),c))
            elif len(dom == 1):
                fmla = Equals(c(Variable('X', dom[0])),Variable('Y', rng))
                add_domain_concept(concepts,fmla)
                
    return co.ConceptDomain(concepts, co.get_standard_combiners(), co.get_standard_combinations())
Пример #9
0
def all_state_symbols():
    return [s for s in il.all_symbols() if s not in il.sig.constructors]
Пример #10
0
def all_state_symbols():
    return [s for s in il.all_symbols() if s not in il.sig.constructors]