import math


def _bartlett_formula(r, m, length) -> float:
    """
    Computes the standard error of `r` at order `m` with respect to `length` according to Bartlett's formula.

    :param r: The array whose standard error is to be computed.
    :param m: The order of the standard error.
    :param length: The size of the underlying sample to be used.
    :return: The standard error of `r` with order `m`.
    """
    if m == 1:
        return math.sqrt(1/length)
    else:
        return math.sqrt((1 + 2 * sum(map(lambda x: x ** 2, r[:m-1]))) / length)