Квадратный корень

Проверка good-enough? , которую мы использовали для вычисления квадратных корней, будет довольно неэффективна для поиска квадратных корней от очень маленьких чисел. Кроме того, в настоящих компьютерах арифметические операции почти всегда вычисляются с ограниченной точностью. Поэтому наш тест оказывается неадекватным и для очень больших чисел. Альтернативный подход к реализации good-enough? состоит в том, чтобы следить, как от одной итерации к другой изменяется guess , и остановиться, когда изменение оказывается небольшой долей значения приближения. Разработайте процедуру вычисления квадратного корня square-root , которая использует такой вариант проверки на завершение. Верно ли, что на больших и маленьких числах она работает лучше?


    # Brian Hagerty
    1 год назад

    The problem with small numbers is easy enough to understand: the tolerance of .001 is arbitrary, and does not scale with the number whose square we are seeking, so with very small numbers, the resolution is insufficiently fine to improve the guess. The problem with large numbers is not intuitive, and the text does not prepare us to explain the problem.

    # Brian Hagerty Ответил Brian Hagerty #
    1 год назад
    The problem with small numbers is easy enough to understand: the tolerance of .001 is arbitrary, and does not scale with the number whose square we are seeking, so with very small numbers, the resolution is insufficiently fine to improve the guess. The problem with large numbers is not intuitive, and the text does not prepare us to explain the problem.

    Here's one explanation: "For large radicands, the procedure sqrt-iter enters an infinite recursion because the tolerance is not scaled up to the large radicands and floating-point numbers are represented with limited precision so the absolute error at that scale is always greater than the tolerance."

    # Brian Hagerty
    1 год назад

    The "solution" given is NOT a solution to the actual problem. In a correct solution, the good-enough? procedure should be modified to test against "a very small fraction of the guess," e.g., (.0000001 * guess). Instead of doing this, the "solution" just substitutes a smaller, still absolute, tolerance for .001, using 0.0000001. This improves the resolution for small numbers but doesn't work for large numbers and is not what is asked for.

    # Anton Burenkov
    1 год назад

    Thanks, fixed.

    # Дмитрий
    1 год назад

    Good day! For me it looks like good-enough? procedure from the provided solution is still not good enough. I think we should check that |guess - next_guess| / guess is small. In the provided solution procedure checks that |guess^2 - x| is less then small portion of guess which is not what we asked.

Необходима авторизация

Вы должны авторизоваться для создания комментария.

Вход