def successors_typed(self, gamma, n): alpha, n1 = new_var(self.typ, n) typ_f = TypTerm.make_arrow(alpha, self.typ) ret = [(App(UnfinishedLeaf(typ_f), UnfinishedLeaf(alpha), self.typ), sub.Sub(), n1)] for ctx_declaration in gamma.ctx.values(): fresh_res = fresh(ctx_declaration.typ, self.typ, n) mu = sub.mgu(self.typ, fresh_res.typ) if not mu.is_failed(): sigma = mu.restrict(self.typ) leaf = Leaf(ctx_declaration.sym, sigma(self.typ)) ret.append((leaf, sigma, fresh_res.n)) return ret
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
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
def gen_one_app_uf(self, uf_tree, ball, k, typ, n): alpha, n1 = new_var(typ, n) typ_f = TypTerm.make_arrow(alpha, typ) f_uf, x_uf = uf_tree.fun, uf_tree.arg for i in range(1, k): j = k - i 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): num_fx = res_x.num * res_f.num if ball < num_fx: return self.gen_one_app_core_uf( f_uf, x_uf, i, j, typ, typ_f, typ_x, res_f, res_x) ball -= num_fx assert False
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
def gen_one_app(self, ball, k, typ, n): # todo potvrdit zefunguje # Tady se da zapnout stara implementace (nahrazeno momoci gen_one_product) # if TypTerm.is_internal_pair_typ(typ): # return self.gen_one_internal_pair(ball, k, typ, n) alpha, n1 = new_var(typ, n) typ_f = TypTerm.make_arrow(alpha, typ) for i in range(1, k): j = k - i 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): num_fx = res_x.num * res_f.num if ball < num_fx: return self.gen_one_app_core(i, j, typ, typ_f, typ_x, res_f, res_x) ball -= num_fx assert False