-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.44.rkt
More file actions
26 lines (26 loc) · 706 Bytes
/
1.44.rkt
File metadata and controls
26 lines (26 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#lang scheme
; 工具函数
(define (square x) (* x x))
(define (average a b c) (/ (+ a b c) 3))
; from 1.42
(define (compose f1 f2)
(lambda (x) (f1 (f2 x))))
; from 1.43
(define (repeated f n)
(cond ((= n 0) (lambda (x) (f x)))
((even? n) (repeated (compose f f)
(- n 2)))
(else (compose f
(repeated f
(- n 1))))))
; 题目要求的函数
(define dx 0.00001)
(define (smooth f)
(lambda (x) (average (f (- x dx))
(f x)
(f (+ x dx)))))
(define (n-fold-smoothed f n)
((repeated smooth n) f))
; test
((smooth square) 2)
((n-fold-smoothed square 1) 2)