def add_to_fv(expr, FV, e2fi):
    """Add expression expr to factor vector FV and expr->FVindex mapping e2fi."""
    fi = e2fi.get(expr)
    if fi is None:
        fi = len(e2fi)
        FV.append(expr)
        e2fi[expr] = fi
    return fi
