def _inverse_set(a, b, pm, elements):
    """
    returns: set of values z such that az = b is a possible mapping
    """
    inv = set()
    for z in elements:
        if b in pm[frozenset({a, z})]:
            inv.add(z)
    return inv
