def unfold(system, body): """Unfold the head variables in body via definitions in system. Note that due to JOIN terms, there may be multiple head variables. """ assert isinstance(system, System) assert isinstance(body, Term) if is_atom(body) or is_ivar(body): return body if is_nvar(body): return system[body[1]] # Get a linear normal form. if is_app(body): body = bohm.app(unfold(system, body[1]), body[2]) # Only unfold head. elif is_abs(body): body = bohm.abstract(unfold(system, body[1])) elif is_join(body): parts = sorted(bohm.iter_join(body), key=bohm.priority) for i, part in enumerate(parts): if is_unfoldable(part): parts[i] = unfold(system, part) break body = bohm.join_set(set(parts)) else: raise ValueError(body) # Reduce. return bohm.reduce(body, budget=1234567890)
def test_unabstract(term): assert bohm.abstract(bohm.unabstract(term)) is term
def test_app_abstract(term): hypothesis.assume(i0 not in quoted_vars(term)) assert app(bohm.increment_rank(bohm.abstract(term)), i0) is term
def test_abstract_eta(term): assert bohm.abstract(app(bohm.increment_rank(term), i0)) is term
def test_abstract(term, expected): assert bohm.abstract(term) is expected
def test_unabstract(code): assert abstract(unabstract(code)) is code
def test_abstract_eta(code): hypothesis.assume(is_const(code)) assert abstract(app(code, IVAR(0))) is decrement_rank(code)
def test_abstract(code, expected): assert abstract(code) is expected