Exercises 2.5 2.6

2017-05-12  本文已影响0人  挖矿的菜鸡

Exercises 2.5

Question

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)

(cdr integer)

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
  1. (add-1 n)
  1. Analyse (add-1 zero)

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

上一篇 下一篇

猜你喜欢

热点阅读