def solve_mec_nested(th0, th1, fnl):
    R = .61803399
    C = 1 - R
    ax, cx = .6, .85
    bx = .5 * (ax + cx)

    x0, x3 = ax, cx
    if abs(cx - bx) > abs(bx - ax):
        x1, x2 = bx, bx + C * (cx - bx)
    else:
        x1, x2 = bx - C * (bx - ax), bx
    f1, p = solve_mec_nested_inner(th0, th1, x1, fnl)
    f2, p = solve_mec_nested_inner(th0, th1, x2, fnl)
    for i in range(10):
        print '%', x0, x1, x2, x3, ':', f1, f2
        if f2 < f1:
            x0, x1, x2 = x1, x2, R * x2 + C * x3
            f1 = f2
            f2, p = solve_mec_nested_inner(th0, th1, x2, fnl)
        else:
            x1, x2, x3 = R * x1 + C * x0, x1, x2
            f2 = f1
            f1, p = solve_mec_nested_inner(th0, th1, x1, fnl)
    if f1 < f2:
        x = x1
    else:
        x = x2
    cc, p = solve_mec_nested_inner(th0, th1, x, fnl)
    return p
dataset/ETHPy150Open google/roboto/third_party/spiro/curves/mecsolve.py/solve_mec_nested/original