Exercises 2.5 2.6

Exercises 2.5

Question

  • Represent a number using pairs.

  • Math module

  • The wiki explains the math theory Fundamental theorem of arithmetic

    • Any number can represent by the product of primes.
  • We represent the number by using cons, and the car, cdr will extract a, b

    (cons a b) -- 2a3b

    (car integer) -- a

    (cdr integer) -- b

Math Formulate

  1. We need to calculate the exponent and product.
  2. We need to calculate how many 'a' when divided by 2
  3. And 'b' also divided by 3

Algorithm

(cons a b)

(car integer)

  • we need to calculate every integer divided by 2 and count how many '2' is there.

(cdr integer)

  • The same as (car integer)
  • We need to write a common procedure "(calculate how many n in m)"
  • (calculate n m) -- k
  • Use n to divide m, n/m, if (mod n m) > m, count++, if not, return count

conclusion after check the answer online

use the (reaminder n m) as an alternative option if the remainder is zero, then continue divided by 2, if not return count

Exercises 2.6

Meaning of the question

The question wants to show us that it can represent concept 'zero' and 'add' with out numbers.

Analyse the code of zero and add-1

  1. zero
  • Zero is a procedure.

  • paramenter is a procedure

  • return value is a procedure

    • Return the parameter of zero's paramenter
    • (zero (procedure-name parameter)) -- parameter
  • Meaning of zero

    • The zero is somthing that return it self.
    • Apply the 四則運(yùn)算 to the function (zero) only the multiply will be fine.
    • What if we apply for the other operators?
  1. (add-1 n)
  • Parameter is a procedure named n
  • return a procedure
  • [ ] What is the meaning of the add on procedure?
  • [ ] what is the f meaning in the procedure
  1. Analyse (add-1 zero)
  • [ ] Is this a procedure or value?

  • progress of this procedure

    1. (add-1 zero)
    2. (lambda (f) (lambda (x) (f ((zero f) x))))
    3. (lambda (f) (lambda (x) (f x)))
  • This procedure will return a procedure.

  • The parameter of (add-1 zero) is a procedure too.

  • This procedure is aiming at return the parameter(a procedure) it self.

  • [ ] What is the usage of this kind of procedure?

    • It is a abstract procedure, use procedure to return procedure but do nothing.
    • Is it the meaning of 'add zero' which means add nothing.

Church numeral

Church numeral is a meethod aiming to represent natural only using lambda.

For example when we want to represent 0

(add-1 zero)

(one)

(lambda (f) (lambda (x) (f ((zero f) x))))

(lambda (f) (lambda (x) (f x)))

(add-1 one)

(two)

(lambda (f) (lambda (x) (f ((one f) x))))

(lambda (f) (lambda (x) (f (f x))))

requierments

  • Write two procedure one two

  • Not in terms of zero and add-1

  • search the internet for the answer.

    1. What is the meaning of add?
    2. How to define one and two ?
    3. What is the usage of these things?

    One and Two

    When we try to use the substitution model we can get one and two directly

    '''

    (define one (lambda (f) (lambda (x) (f x))))

    (define two (lambda (f) (lambda (x) (f (f x)))))

    '''

    Define plus of Church Numeral

    We represent natrural number n with nth f, f^n Then the question is changed to how to implement the times concept in church numeral As we can imagine the procedure should be something like

    (plus int1 int2) -- (int 3)

    "it seems that we should use the recursive procedure to generate"

    Compare to the (add-1 n) procedure

    Examine (add-1 n) I find that

    (f ((n f) x)) -- (f n)

    n is the number represent in church numeral form, it takes f^n(x) = f...f(x)

    And the parameter of n is f, aprocedure, after that it need a 'x' to be the parameter for the return value which is '((n f) x)'

    So the ((n f) x) is just the number of church numeral. And the add procedure become (f n), which equals to f^n+1(x).

    Write the procedure of Plus

    The plus should be like f ((n m) x)

    As we dicover that (n f x) is f^n(x), (m f x) is f^m(x)

    What we want is f^m+n (x), which is f^m f^n(x)

    So here is a question, which one is right (m f (n f x)) or (m (n f x) x)

    • (m f (n f x))

    • (m f f^n(x))

    • fm(fn(x))

    • (m (n f x) x)

    • (m f^n(x) x)

    • (fn(x))m(x)

    • This one is wrong.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子叽讳,更是在濱河造成了極大的恐慌羡洁,老刑警劉巖陌知,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件宏浩,死亡現(xiàn)場離奇詭異昆雀,居然都是意外死亡辨液,警方通過查閱死者的電腦和手機(jī)虐急,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來滔迈,“玉大人止吁,你說我怎么就攤上這事×呛罚” “怎么了敬惦?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長谈山。 經(jīng)常有香客問我俄删,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任畴椰,我火速辦了婚禮臊诊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘斜脂。我一直安慰自己抓艳,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布帚戳。 她就那樣靜靜地躺著壶硅,像睡著了一般。 火紅的嫁衣襯著肌膚如雪销斟。 梳的紋絲不亂的頭發(fā)上庐椒,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天,我揣著相機(jī)與錄音蚂踊,去河邊找鬼约谈。 笑死,一個(gè)胖子當(dāng)著我的面吹牛犁钟,可吹牛的內(nèi)容都是我干的棱诱。 我是一名探鬼主播,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼涝动,長吁一口氣:“原來是場噩夢啊……” “哼迈勋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起醋粟,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤靡菇,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后米愿,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體厦凤,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年育苟,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了较鼓。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,722評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡违柏,死狀恐怖博烂,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情漱竖,我是刑警寧澤辈毯,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布工窍,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧脚仔,春花似錦、人聲如沸舆绎。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽吕朵。三九已至猎醇,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間努溃,已是汗流浹背硫嘶。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留梧税,地道東北人沦疾。 一個(gè)月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像第队,于是被迫代替她去往敵國和親哮塞。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內(nèi)容