def minimize_redundant_relations(relations: list[tuple[cl.Relation, r.Domain]]):
    """
    Given a list of relations that must be true, use the first as a constraint to tighten the remaining relations
    """

    assert len(relations) > 0

    # TODO Hacky: moves AnyRelations to the back so _hopefully_ they get implied before we get to them
    relations = sorted(
        relations, key=lambda r: isinstance(r[0], cl.AnyRelation), reverse=True
    )

    (rel, dom), *rest = relations

    # Force all remaining relations to be compatible with (rel, dom), thereby reducing their search space
    remaining_relations = []
    for r_later, d_later in rest:
        logger.debug(f"Inspecting {r_later=} {d_later=}")

        if d_later.intersects(dom):
            logger.debug(f"Intersecting {d_later} with {dom}")
            d_later = d_later.intersection(dom)

        if r.reldom_implies((rel, dom), (r_later, d_later)):
            # (rlater, dlater) is guaranteed true so long as we satisfied (rel, dom), we dont need to separately assign it
            logger.debug("Discarding since rlater,dlater it is implied")
            continue
        else:
            logger.debug(
                f"Keeping {r_later, d_later} since it is not implied by {rel, dom} "
            )
            remaining_relations.append((r_later, d_later))

    implied = any(
        r.reldom_implies(reldom_later, (rel, dom))
        for reldom_later in remaining_relations
    )

    return (rel, dom), remaining_relations, implied

    Given a list of relations that must be true, use the first as a constraint to tighten the remaining relations
    
infinigen/core/constraints/example_solver/propose_relations.py