def extendSubst(var, expr, sub):
    """ Given a variable and an expression it should be substituted for, extend
        the substitution with that mapping.

        This exists as a non-stateful way to extend substitutions. That is,
        this creates a new substitution, rather than modifying an existing one.
    """
    subp = sub.copy()
    subp[var.string] = expr
    return subp