def gradient_descent2(f, df, x):
    while True:
        yield x
        x = min(
            (partial(gradient_step, df, -alpha)(x) for alpha in [100, 10, 1, 0.7, 0.01, 0.001, 0.0001, 0.00001]),
            key=safe(f),
        )
def gradient_descent3(f, df, x):
    return accumulate(
        lambda fx, _: min(
            (partial(gradient_step, df, -alpha)(fx) for alpha in [100, 10, 1, 0.7, 0.01, 0.001, 0.0001, 0.00001]),
            key=safe(f),
        ),
        repeat(x),
    )
def gradient_descent3(f, df, x):
    return accumulate(
        lambda fx, _: min(
            (partial(gradient_step, df, -alpha)(fx)
             for alpha in [100, 10, 1, 0.7, 0.01, 0.001, 0.0001, 0.00001]),
            key=safe(f)), repeat(x))
def gradient_descent2(f, df, x):
    while True:
        yield x
        x = min((partial(gradient_step, df, -alpha)(x)
                 for alpha in [100, 10, 1, 0.7, 0.01, 0.001, 0.0001, 0.00001]),
                key=safe(f))