Created
June 28, 2021 06:36
-
-
Save yanfeng42/d89b122c7cc390688390c0189d04e32f to your computer and use it in GitHub Desktop.
sicp 1.39 用单独符号, 还是用 系数 表达 "+" 和 "-"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 我的答案: | |
; 递归写法. | |
(define (cont-frac-full n d k calculator) | |
(define (iterator i) | |
(if (< i k) | |
(/ (n i) (calculator (d i) (iterator (+ i 1)))) | |
(/ (n i) (d i)) | |
) | |
) | |
(iterator 1) | |
) | |
; 迭代写法. | |
(define (cont-frac-full n d k calculator) | |
(define (iterator i product) | |
(if (= i 0) | |
product | |
(iterator (- i 1) (/ (n i) (calculator (d i) product))) | |
) | |
) | |
(iterator k 0) | |
) | |
(define (square x) (* x x)) | |
(define (tan-cf x k) | |
(cont-frac-full | |
(lambda (i) (if (= i 1) x (square x))) | |
(lambda (i) (- (* 2 i) 1)) | |
k | |
- | |
) | |
) | |
#| | |
> (tan-cf (/ 3.14 4) 100) | |
0.9992039901050428 | |
|# | |
#| 社区答案: | |
> (tan-cf (/ 3.14 4) 100) | |
0.9992039901050428 | |
|# | |
(define (tan-cf x k) | |
(cont-frac (lambda (i) | |
(if (= i 1) x (- (* x x)))) | |
(lambda (i) | |
(- (* i 2) 1)) | |
k)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
核心区别是:
(- (* x x)