GithubHelp home page GithubHelp logo

sicpexercise's Introduction

SicpExercise

Sicp练习解答

1.1

10 12 8 3 -2 6 19 0 b=4 16 6 16


1.2

1.2答案


1.3

1.3答案


1.4

1.4过程的行为是 a + |b|

a加上b的绝对值


1.5

(define (p) (p))
(define (text x y)
	(if (= x 0)
	    0
	    y))

(text 0 (p))

首先对于 (define (p) (p)) 来说,无论是应用序或者正则序只要调用这个函数都会进入无限循环递归中

应用序会先对函数的各个参数求值,然后应用到函数中,对于 (text 0 (p)) 来说,应用序会先运算 (p) 直接把运算后的 (p) 应用到 (text x y) 的过程中,这样就会导致程序进入无限递归中去。

正则序则不一样,先不求参数的值,直到需要值的时候再求值,因为第一个参数是0,程序不会用到 (p) 所以直接返回0

Scheme 的解释器进入到无限递归中因此属于应用序


1.6

代码

由于 Scheme 的解释器属于应用序,所以会先对传入 new-if 的两个参数进行求值,如果第二个参数不是理想值,所以 new-if 会无限递归下去,从而不能出正确值


1.7

在该方法中判断求值是否完成的充要条件是 “猜测的数的平方与被开方的数的差小于0.001” 转变为条件表达式

|guess^2 - x| < 0.001

-0.001 < guess^2 - x < 0.001

guess^2 - 0.001 < x < guess^2 + 0.001

0.0009 < x < 1.0001

对于 x > 1.0001 经过 (improve guess x) 之后会趋近于正确值


1.8

代码


1.9

第一个计算过程:

(+ 4 5)
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(inc (inc (inc (inc (+ 0 5)))))
(inc (inc (inc (inc 5))))
(inc (inc (inc 6)))
(inc (inc 7))
(inc 8)
9

该过程属于递归

第二个计算过程:

(+ 4 5)
(+ 3 6)
(+ 2 7)
(+ 1 8)
(+ 0 9)
9

该过程属于迭代


1.10

(A 1 10)
(A 0 (A 1 9))
(A 0 (A 0 (A 1 8)))
(A 0 (A 0 (A 0 (A 1 7))))
(A 0 (A 0 (A 0 (A 0 (A 1 6)))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 1 5))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 4)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 3))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 16))))))
(A 0 (A 0 (A 0 (A 0 (A 0 32)))))
(A 0 (A 0 (A 0 (A 0 64))))
(A 0 (A 0 (A 0 128)))
(A 0 (A 0 256))
(A 0 512)
1024

(A 1 10) = 2^10 = 1024
(A 1 n) = 2^n

(A 2 4)
(A 1 (A 2 3))
(A 1 (A 1 (A 2 2)))
(A 1 (A 1 (A 1 (A 2 1))))
(A 1 (A 1 (A 1 2)))
(A 1 (A 1 2^2))
(A 1 2^2^2)
2^2^2^2
65536

(A 2 4) = 2^2^2^2 = 2^16 = 65535
(A 2 n)相当于求2的n次幂

(A 3 3)
(A 2 (A 3 2))
(A 2 (A 2 (A 3 1)))
(A 2 (A 2 2))
(A 2 2^2)
(A 2 4)
2^2^2^2
65536

(A 3 3) = 2^2^2^2 = 2^16 = 65535

所以(f n) = 2 * n
(g n) = 2^n
(h n) = 2^2···^2

sicpexercise's People

Contributors

zyfoolboy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.