Esempio n. 1
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. 2
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. 3
0
    def subs_uf_smart(self, uf_tree, k, n):

        uf_leafs = uf_tree.get_unfinished_leafs()

        num_uf_leafs = len(uf_leafs)
        num_fin_leafs = uf_tree.size()

        if num_fin_leafs + num_uf_leafs > k:
            return []

        if num_uf_leafs > 0:
            hax_typ = TypTerm.make_internal_tuple(
                [uf_leaf.typ for uf_leaf in uf_leafs])
            hax_k = k - num_fin_leafs + num_uf_leafs - 1
            return self.subs(hax_k, hax_typ, n)
        elif num_fin_leafs == k:
            return [sub.PreSubRes(1, sub.Sub())]
        else:
            return []
Esempio n. 4
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. 5
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
Esempio n. 6
0
def subs_1(gamma, typ, n):
    pre_ts1_res = ts1_static(gamma, typ, n)
    pre_sub_results_unpacked = (sub.PreSubRes(1, res.sub) for res in pre_ts1_res)
    return pack(typ, n, pre_sub_results_unpacked)