def test_unifier():
    from pymbolic import var
    from pymbolic.mapper.unifier import UnidirectionalUnifier
    (a, b, c, d, e, f) = [var(s) for s in 'abcdef']

    def match_found(records, eqns):
        for record in records:
            if (eqns <= set(record.equations)):
                return True
        return False
    recs = UnidirectionalUnifier('abc')((a + (b * c)), (d + (e * f)))
    assert (len(recs) == 2)
    assert match_found(recs, {(a, d), (b, e), (c, f)})
    assert match_found(recs, {(a, d), (b, f), (c, e)})
    recs = UnidirectionalUnifier('abc')((a + b), ((d + e) + f))
    assert (len(recs) == 6)
    assert match_found(recs, {(a, d), (b, (e + f))})
    assert match_found(recs, {(a, e), (b, (d + f))})
    assert match_found(recs, {(a, f), (b, (d + e))})
    assert match_found(recs, {(b, d), (a, (e + f))})
    assert match_found(recs, {(b, e), (a, (d + f))})
    assert match_found(recs, {(b, f), (a, (d + e))})
    vals = [var(('v' + str(i))) for i in range(100)]
    recs = UnidirectionalUnifier('a')((sum(vals[1:]) + a), sum(vals))
    assert (len(recs) == 1)
    assert match_found(recs, {(a, var('v0'))})
    recs = UnidirectionalUnifier('abc')(((a + b) + c), (d + e))
    assert (len(recs) == 0)
    recs = UnidirectionalUnifier('abc')(f((a + b), f((a + c))), f((b + c), f((b + d))))
    assert (len(recs) == 1)
    assert match_found(recs, {(a, b), (b, c), (c, d)})
def test_unifier():
    from pymbolic import var
    from pymbolic.mapper.unifier import UnidirectionalUnifier
    (a, b, c, d, e, f) = [var(s) for s in 'abcdef']

    def match_found(records, eqns):
        for record in records:
            if (eqns <= set(record.equations)):
                return True
        return False
    recs = UnidirectionalUnifier('abc')((a + (b * c)), (d + (e * f)))
    assert (len(recs) == 2)
    assert match_found(recs, {(a, d), (b, e), (c, f)})
    assert match_found(recs, {(a, d), (b, f), (c, e)})
    recs = UnidirectionalUnifier('abc')((a + b), ((d + e) + f))
    assert (len(recs) == 6)
    assert match_found(recs, {(a, d), (b, (e + f))})
    assert match_found(recs, {(a, e), (b, (d + f))})
    assert match_found(recs, {(a, f), (b, (d + e))})
    assert match_found(recs, {(b, d), (a, (e + f))})
    assert match_found(recs, {(b, e), (a, (d + f))})
    assert match_found(recs, {(b, f), (a, (d + e))})
    vals = [var(('v' + str(i))) for i in range(100)]
    recs = UnidirectionalUnifier('a')((sum(vals[1:]) + a), sum(vals))
    assert (len(recs) == 1)
    assert match_found(recs, {(a, var('v0'))})
    recs = UnidirectionalUnifier('abc')(((a + b) + c), (d + e))
    assert (len(recs) == 0)
    recs = UnidirectionalUnifier('abc')(f((a + b), f((a + c))), f((b + c), f((b + d))))
    assert (len(recs) == 1)
    assert match_found(recs, {(a, b), (b, c), (c, d)})