CS代考程序代写 ;some functions

;some functions
(define (square x)(* x x))
(define (sos x y)(+ (square x)(square y)))
(define (f a)(sos (+ a 1)(* a 2)))

;substitution model (applicative order)
;(f 5)
;(sos (+ 5 1)(* 5 2))
;(sos 6 10)
;(+ (square 6)(square 10))
;(+ (* 6 6)(* 10 10))
;(+ 36 100)
;136

;substitution model (normal order)
;(f 5)
;(sos (+ 5 1)(* 5 2))
;(+ (square (+ 5 1))(square (* 5 2))
;(+ (* (+ 5 1)(+ 5 1)) (square (* 5 2)))
;(+ (* 6 6) (square (* 5 2)))
;(+ 36 (square (* 5 2)))
;(+ 36 (* (* 5 2)(* 5 2)))
;(+ 36 (* 10 10))
;(+ 36 100)
;136

;(f 5)
;(sos (+ 5 1)(* 5 2))
;(+ (square (+ 5 1))(square (* 5 2)))
;(+ (* (+ 5 1)(+ 5 1)) (* (* 5 2)(* 5 2)))
;(+ (* 6 6)(* 10 10))
;(+ 36 100)
;136

Leave a Reply

Your email address will not be published. Required fields are marked *