def get_by_path(expr, path):
    """ Retrieve a subexpression by giving its path

    Parameters
    ----------
    expr: sympy expression
        The expression from which to retrieve the subexpression.
    path: list of ints
        The indices of the args tuples, see example.

    Returns
    -------
    sympy expression for given path


    Examples
    --------
    get_by_path(expr, [1, 0, 3, 1])
       is equivalent to
    expr.args[1].args[0].args[3].args[1]

    """
    subexpr = expr
    for idx in path:
        subexpr = subexpr.args[idx]
    return subexpr