

def _briggs_helper_function(a, k):
    '\n    Computes r = a^(1 / (2^k)) - 1.\n\n    This is algorithm (2) of [1]_.\n    The purpose is to avoid a danger of subtractive cancellation.\n    For more computational efficiency it should probably be cythonized.\n\n    Parameters\n    ----------\n    a : complex\n        A complex number preferably belonging to the closed negative real axis.\n    k : integer\n        A nonnegative integer.\n\n    Returns\n    -------\n    r : complex\n        The value r = a^(1 / (2^k)) - 1 computed with less cancellation.\n\n    Notes\n    -----\n    The algorithm as written in the publication does not handle k=0 or k=1\n    correctly, so these are special-cased in this implementation.\n    This function is intended to not allow `a` to belong to the closed\n    negative real axis, but this is constraint is relaxed.\n\n    References\n    ----------\n    .. [1] Awad H. Al-Mohy (2012)\n           "A more accurate Briggs method for the logarithm",\n           Numerical Algorithms, 59 : 393--402.\n\n    '
    if ((k < 0) or (int(k) != k)):
        raise ValueError('expected a nonnegative integer k')
    if (k == 0):
        return (a - 1)
    elif (k == 1):
        return (np.sqrt(k) - 1)
    else:
        k_hat = k
        if (np.angle(a) >= (np.pi / 2)):
            a = np.sqrt(a)
            k_hat = (k - 1)
        z0 = (a - 1)
        a = np.sqrt(a)
        r = (1 + a)
        for j in range(1, k_hat):
            a = np.sqrt(a)
            r = (r * (1 + a))
        r = (z0 / r)
        return r

dataset/ETHPy150Open scipy/scipy/scipy/linalg/_matfuncs_inv_ssq.py _briggs_helper_function/VarMisuse@73/498 `a`->`k`