Ejemplo n.º 1
0
 def add_definition(self, string):
     term = self.parse(string)
     assert qterm.is_combination(term)
     assert qterm.is_combination(term.operator)
     assert term.operator.operator.name == '='
     assert qterm.is_variable(term.operator.operand) \
         or qterm.is_constant(term.operator.operand)
     name = term.operator.operand.name
     self.definitions[name] = term
Ejemplo n.º 2
0
def beta_reduce(term):
    if not qterm.is_combination(term):
        return term
    
    if qterm.is_abstraction(term.operator):
        return substitute(term.operand, term.operator.bound, term.operator.body)
    return term
Ejemplo n.º 3
0
 def apply_to_term(self, term):
     if qterm.is_atom(term):
         return self.apply_to_atom(term)
     elif qterm.is_combination(term):
         return self.apply_to_combination(term)
     elif qterm.is_abstraction(term):
         return self.apply_to_abstraction(term)
     else:
         raise Exception('unrecognized term')
Ejemplo n.º 4
0
 def uncurry(term):
     if not qterm.is_combination(term):
         return term, []
     operator, operands = uncurry(term.operator)
     return operator, operands + [term.operand]