def type_of( self, term: Term, ) -> Type: if term.token() == '__v': assert type(term.right.value) is Type return term.right.value if term.token() == '__c': assert type(term.right.value) is Type return term.right.value if term.token() == '__C': ty = self.type_of(term.left) assert ty.token() == '__c' assert ty.left.token() == 'fun' assert ty.right.token() == '__a' assert ty.right.right.token() == '__a' assert ty.right.right.left is not None return ty.right.right.left if term.token() == '__A': return self.fun_type( self.type_of(term.left), self.type_of(term.right), )
def ABS( self, idx1: int, v: Term, fake: bool = False, ) -> Thm: assume(v.token() == '__v') assume(idx1 in self._theorems) thm1 = self._theorems[idx1] c1 = thm1.concl() assume(c1.token() == '__C') assume(c1.left.token() == '__C') assume(c1.left.left.token() == '__c') assume(c1.left.left.left.token() == '=') l1 = c1.left.right r1 = c1.right assume(len(list(filter( lambda t: self.free_in(v, t), thm1.hyp(), ))) == 0) return self._theorem( thm1.hyp(), self.safe_mk_eq( Term(1, v, l1, '__A'), Term(1, v, r1, '__A'), ), fake, )
def free_in( self, v: Term, term: Term, ) -> bool: assume(v.token() == '__v') def vfree_in(v, tm): if tm.token() == '__A': return v.term_string() != tm.left.term_string() and \ vfree_in(v, tm.right) if tm.token() == '__C': return vfree_in(v, tm.left) or vfree_in(v, tm.right) return v.term_string() == tm.term_string() return vfree_in(v, term)
def BETA( self, term: Term, fake: bool = False, ) -> Thm: assume(term.token() == '__C') assume(term.left.token() == '__A') v = term.left.left bod = term.left.right arg = term.right assume(v.term_string() == arg.term_string()) return self._theorem( [], self.safe_mk_eq(term, bod), fake, )
def variant( self, avoid: typing.List[Term], v: Term, ): assume(v.token() == '__v') if len(list(filter( lambda t: self.free_in(v, t), avoid, ))) == 0: return v token = v.left.token() + '\'' if token not in self._t._term_tokens: self._t._term_tokens[token] = len(self._t._term_tokens) return self.variant( avoid, Term(3, Term( self._t._term_tokens[token], None, None, token ), v.right, '__v'), )