Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

练习 1.7 goodenough 的判断 #50

Open
jtr109 opened this issue May 15, 2017 · 0 comments · May be fixed by #51
Open

练习 1.7 goodenough 的判断 #50

jtr109 opened this issue May 15, 2017 · 0 comments · May be fixed by #51

Comments

@jtr109
Copy link

jtr109 commented May 15, 2017

其中 goodenough 的判断应该是 <.

goodenoughtrue 的条件应该是 old-guessnew-guess 足够接近, 所以应该是差的绝对值越小越好. 而且如果使用 >, 大部分情况下, 例如 x = 2, 在第一轮判断中, old-guess = 1, new-guess = 1.5. 则绝对值的差为 0.5, 大于 0.01, 直接跳出递归.

(define (good-enough? old-guess new-guess)
    (< 0.01
       (/ (abs (- new-guess old-guess))
          old-guess)))

考虑到不对原有定义的破坏, 我建议将 old-guess 和 new-guess 的比较放在 goodenough 中处理, 如下:

(define (goodenough? guess x)
  (< (/ (abs (- guess
		(improve guess x)))
        guess)
     (expt 0.1 4)))

完整的代码可以点击这里, 供参考.

jtr109 added a commit to jtr109/SICP-answers that referenced this issue May 15, 2017
I want to resolve huangzworks#50 issue.
The predicate should be "less than".
@jtr109 jtr109 linked a pull request May 15, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant