def preimage_func(f, x):
    """Pre-image a funcation at a set of input points.

    Parameters
    ----------
    f : typing.Callable
        The function we would like to pre-image. The output type must be hashable.
    x : typing.Iterable
        Input points we would like to evaluate `f`. `x` must be of a type acceptable by `f`.

    Returns
    -------
    D : dict(object, list(object))
        This dictionary maps the output of `f` to the list of `x` values that produce it.
    """
    D = {}
    for xx in x:
        D.setdefault(f(xx), []).append(xx)
    return D