Beispiel #1
0
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)
Beispiel #2
0
def test_unabstract(term):
    assert bohm.abstract(bohm.unabstract(term)) is term
Beispiel #3
0
def test_app_abstract(term):
    hypothesis.assume(i0 not in quoted_vars(term))
    assert app(bohm.increment_rank(bohm.abstract(term)), i0) is term
Beispiel #4
0
def test_abstract_eta(term):
    assert bohm.abstract(app(bohm.increment_rank(term), i0)) is term
Beispiel #5
0
def test_abstract(term, expected):
    assert bohm.abstract(term) is expected
Beispiel #6
0
def test_unabstract(code):
    assert abstract(unabstract(code)) is code
Beispiel #7
0
def test_abstract_eta(code):
    hypothesis.assume(is_const(code))
    assert abstract(app(code, IVAR(0))) is decrement_rank(code)
Beispiel #8
0
def test_abstract(code, expected):
    assert abstract(code) is expected