def transitive_closure(implications):
    full_implications = set(implications)
    literals = set().union(*map(set, full_implications))

    for k in literals:
        for i in literals:
            if (i, k) in full_implications:
                for j in literals:
                    if (k, j) in full_implications:
                        full_implications.add((i, j))

    return full_implications
Computes the transitive closure of a list of implications
dataset/ETHPy150Open sympy/sympy/sympy/core/facts.py/transitive_closure