Esempio n. 1
0
 def replace_unfinished_leafs_raw(self, new_subtrees):
     fun_new1, fun_sub = self.fun.replace_unfinished_leafs_raw(new_subtrees)
     arg_new1 = self.arg.apply_sub(fun_sub)
     arg_new2, arg_sub = arg_new1.replace_unfinished_leafs_raw(new_subtrees)
     fun_new2 = fun_new1.apply_sub(arg_sub)
     sigma = sub.dot(arg_sub, fun_sub)
     return App(fun_new2, arg_new2, sigma(self.typ)), sigma
Esempio n. 2
0
    def subs_product(self, k, typ, n):
        assert TypTerm.is_internal_pair_typ(typ)
        assert k >= 1
        if k == 1:
            return []

        ret = []
        typ_a, typ_b_0 = TypTerm.split_internal_pair_typ(typ)
        n = typ_b_0.get_next_var_id(
            n)  # todo zvážit jestli rači nepocitat z celýho typu

        for i in range(2, k):
            j = k - i
            i_without_cons = i - 1
            assert i_without_cons > 0

            results_a = self.subs(i_without_cons, typ_a, n)
            for res_a in results_a:

                typ_b = res_a.sub(typ_b_0)
                n = res_a.n

                results_b = self.recursive_subs_call_for_product_tail(
                    j, typ_b, n)
                for res_b in results_b:
                    num_ab = res_b.num * res_a.num
                    sigma_ab = sub.dot(res_b.sub, res_a.sub).restrict(typ)
                    ret.append(sub.PreSubRes(num_ab, sigma_ab))

        return pack(typ, n, ret)
Esempio n. 3
0
    def gen_one_app_core_uf(self, f_uf, x_uf, i, j, typ, typ_f, typ_x, res_f,
                            res_x):
        typ_fs, deskolem_sub_f = res_f.sub(typ_f).skolemize()
        typ_xs, deskolem_sub_x = res_x.sub(typ_x).skolemize()

        s_tree_f, n = self.gen_one_random_uf(f_uf, i, typ_fs, res_x.n)
        s_tree_x, n = self.gen_one_random_uf(x_uf, j, typ_xs, n)

        assert s_tree_f is not None
        assert s_tree_x is not None

        tree_f = s_tree_f.apply_sub(sub.dot(res_x.sub, deskolem_sub_f))
        tree_x = s_tree_x.apply_sub(deskolem_sub_x)

        sigma_fx = sub.dot(res_x.sub, res_f.sub)  # not needed: .restrict(typ)
        tree_fx = App(tree_f, tree_x, sigma_fx(typ))

        return tree_fx, n
Esempio n. 4
0
    def gen_one_app_core(self, i, j, typ, typ_f, typ_x, res_f, res_x):
        typ_fs, deskolem_sub_f = res_f.sub(typ_f).skolemize()
        typ_xs, deskolem_sub_x = res_x.sub(typ_x).skolemize()

        n = res_x.n
        s_tree_f, n = self.gen_one_random(i, typ_fs, n)
        s_tree_x, n = self.gen_one_random(j, typ_xs, n)

        assert s_tree_f is not None
        assert s_tree_x is not None

        assert s_tree_f.is_well_typed(self.gamma)
        assert s_tree_x.is_well_typed(self.gamma)

        tree_f = s_tree_f.apply_sub(sub.dot(res_x.sub, deskolem_sub_f))
        tree_x = s_tree_x.apply_sub(deskolem_sub_x)

        sigma_fx = sub.dot(res_x.sub, res_f.sub)  # not needed: .restrict(typ)
        tree_fx = App(tree_f, tree_x, sigma_fx(typ))

        assert tree_fx.is_well_typed(self.gamma)

        return tree_fx, n
Esempio n. 5
0
    def subs_uf_ij(self, f_uf, x_uf, i, j, typ, n):
        ret = []
        alpha, n1 = new_var(typ, n)
        typ_f = TypTerm.make_arrow(alpha, typ)

        for res_f in self.subs_uf(f_uf, i, typ_f, n1):
            typ_x = res_f.sub(alpha)
            for res_x in self.subs_uf(x_uf, j, typ_x, res_f.n):
                sigma_fx = sub.dot(res_x.sub, res_f.sub).restrict(typ)
                num_fx = res_x.num * res_f.num

                ret.append(sub.PreSubRes(num_fx, sigma_fx))

        return ret
Esempio n. 6
0
def ts_ij(gamma, i, j, typ, n):
    ret = []
    alpha, n1 = new_var(typ, n)
    typ_f = TypTerm.make_arrow(alpha, typ)

    for res_f in ts(gamma, i, typ_f, n1):
        typ_x = res_f.sub(alpha)
        for res_x in ts(gamma, j, typ_x, res_f.n):
            sigma_fx = sub.dot(res_x.sub, res_f.sub).restrict(typ)
            tree_f = res_f.tree.apply_sub(res_x.sub)
            tree_fx = App(tree_f, res_x.tree, sigma_fx(typ))
            ret.append(TsRes(tree_fx, sigma_fx, res_x.n))

    return ret
Esempio n. 7
0
    def gen_one_internal_pair_core(self, i_without_cons, j, typ, typ_a, typ_b,
                                   res_a, res_b):
        typ_as, deskolem_sub_a = res_a.sub(typ_a).skolemize()
        typ_bs, deskolem_sub_b = res_b.sub(typ_b).skolemize()

        n = res_a.n
        s_tree_a, n = self.gen_one_random(i_without_cons, typ_as, n)
        s_tree_b, n = self.gen_one_random(j, typ_bs, n)

        assert s_tree_a is not None
        assert s_tree_b is not None

        assert s_tree_a.is_well_typed(self.gamma)
        assert s_tree_b.is_well_typed(self.gamma)

        tree_a = s_tree_a.apply_sub(sub.dot(res_b.sub, deskolem_sub_a))
        tree_b = s_tree_b.apply_sub(deskolem_sub_b)

        sigma_ab = sub.dot(res_b.sub, res_a.sub)  # not needed: .restrict(typ)
        tree_ab_typ = sigma_ab(typ)

        assert tree_ab_typ == TypTerm.make_internal_pair(
            tree_a.typ, tree_b.typ)

        partial_pair_typ = TypTerm.make_arrow(tree_b.typ, tree_ab_typ)
        cons_typ = TypTerm.make_arrow(tree_a.typ, partial_pair_typ)

        cons = Leaf(INTERNAL_PAIR_CONSTRUCTOR_SYM, cons_typ)
        partial_pair = App(cons, tree_a, partial_pair_typ)
        tree_ab = App(partial_pair, tree_b, tree_ab_typ)

        assert tree_a.is_well_typed(self.gamma)
        assert tree_b.is_well_typed(self.gamma)
        assert tree_ab.is_well_typed(self.gamma)

        return tree_ab, n
Esempio n. 8
0
    def subs_ij(self, i, j, typ, n):

        # todo potvrdit ze funguje
        # tady se da zapnout stara implementace productu (nahrazeno pomoci subs_product volaneho v subs_compute)
        # if TypTerm.is_internal_pair_typ(typ):
        #    return self.subs_internal_pair(i, j, typ, n)

        ret = []
        alpha, n1 = new_var(typ, n)
        typ_f = TypTerm.make_arrow(alpha, typ)

        for res_f in self.subs(i, typ_f, n1):
            typ_x = res_f.sub(alpha)
            for res_x in self.subs(j, typ_x, res_f.n):
                sigma_fx = sub.dot(res_x.sub, res_f.sub).restrict(typ)
                num_fx = res_x.num * res_f.num

                ret.append(sub.PreSubRes(num_fx, sigma_fx))
        return ret
Esempio n. 9
0
    def subs_internal_pair(self, i, j, typ, n):

        i_without_cons = i - 1
        if i_without_cons == 0:
            return []

        ret = []
        typ_a, typ_b_0 = TypTerm.split_internal_pair_typ(typ)
        n = typ_b_0.get_next_var_id(n)

        for res_a in self.subs(i_without_cons, typ_a, n):
            typ_b = res_a.sub(typ_b_0)
            for res_b in self.subs(j, typ_b, res_a.n):
                sigma_ab = sub.dot(res_b.sub, res_a.sub).restrict(typ)
                num_ab = res_b.num * res_a.num

                ret.append(sub.PreSubRes(num_ab, sigma_ab))

        return ret